Lines Matching +full:imx23 +full:- +full:pwm
1 // SPDX-License-Identifier: GPL-2.0+
13 #include <linux/pwm.h>
49 static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in mxs_pwm_apply() argument
60 * If the PWM channel is disabled, make sure to turn on the in mxs_pwm_apply()
64 if (!pwm_is_enabled(pwm)) { in mxs_pwm_apply()
65 ret = clk_prepare_enable(mxs->clk); in mxs_pwm_apply()
70 if (!state->enabled && pwm_is_enabled(pwm)) in mxs_pwm_apply()
71 writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR); in mxs_pwm_apply()
73 rate = clk_get_rate(mxs->clk); in mxs_pwm_apply()
76 c = c * state->period; in mxs_pwm_apply()
82 return -EINVAL; in mxs_pwm_apply()
86 c *= state->duty_cycle; in mxs_pwm_apply()
87 do_div(c, state->period); in mxs_pwm_apply()
97 pol_bits = state->polarity == PWM_POLARITY_NORMAL ? in mxs_pwm_apply()
100 mxs->base + PWM_ACTIVE0 + pwm->hwpwm * 0x20); in mxs_pwm_apply()
102 mxs->base + PWM_PERIOD0 + pwm->hwpwm * 0x20); in mxs_pwm_apply()
104 if (state->enabled) { in mxs_pwm_apply()
105 if (!pwm_is_enabled(pwm)) { in mxs_pwm_apply()
110 writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + SET); in mxs_pwm_apply()
113 clk_disable_unprepare(mxs->clk); in mxs_pwm_apply()
124 struct device_node *np = pdev->dev.of_node; in mxs_pwm_probe()
130 ret = of_property_read_u32(np, "fsl,pwm-number", &npwm); in mxs_pwm_probe()
132 dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); in mxs_pwm_probe()
136 chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*mxs)); in mxs_pwm_probe()
141 mxs->base = devm_platform_ioremap_resource(pdev, 0); in mxs_pwm_probe()
142 if (IS_ERR(mxs->base)) in mxs_pwm_probe()
143 return PTR_ERR(mxs->base); in mxs_pwm_probe()
145 mxs->clk = devm_clk_get(&pdev->dev, NULL); in mxs_pwm_probe()
146 if (IS_ERR(mxs->clk)) in mxs_pwm_probe()
147 return PTR_ERR(mxs->clk); in mxs_pwm_probe()
149 chip->ops = &mxs_pwm_ops; in mxs_pwm_probe()
151 /* FIXME: Only do this if the PWM isn't already running */ in mxs_pwm_probe()
152 ret = stmp_reset_block(mxs->base); in mxs_pwm_probe()
154 return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n"); in mxs_pwm_probe()
156 ret = devm_pwmchip_add(&pdev->dev, chip); in mxs_pwm_probe()
158 dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret); in mxs_pwm_probe()
166 { .compatible = "fsl,imx23-pwm", },
173 .name = "mxs-pwm",
180 MODULE_ALIAS("platform:mxs-pwm");
182 MODULE_DESCRIPTION("Freescale MXS PWM Driver");