Skip to content

Commit 2cb5cd9

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: imx27: Ensure clocks being on iff the PWM is on
Up to now the .probe() function didn't enable clocks and relied on the core to call the .get_state() callback to have the clock running. The latter enabled the needed clocks and kept them running if the PWM wass enabled. This only works correctly if the .get_state() callback is called exactly once and this single call happens before unused clocks are disabled by the clk core. The former wasn't true for a short period while commit 01ccf90 ("pwm: Let pwm_get_state() return the last implemented state") applied and not reverted yet and might become wrong in the future. The latter isn't true any more since commit cfc4c18 ("pwm: Read initial hardware state at request time") which results in a running PWM being stopped at boot time if for example the consumer lives in a kernel module that is only loaded after the clk core disabled unused clocks. So ensure .probe() is left with the clocks on if the PWM is running and .get_state() disables everything it enabled. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 4563654 commit 2cb5cd9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/pwm/pwm-imx27.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ static void pwm_imx27_get_state(struct pwm_chip *chip,
171171
tmp = NSEC_PER_SEC * (u64)(val);
172172
state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk);
173173

174-
if (!state->enabled)
175-
pwm_imx27_clk_disable_unprepare(imx);
174+
pwm_imx27_clk_disable_unprepare(imx);
176175
}
177176

178177
static void pwm_imx27_sw_reset(struct pwm_chip *chip)
@@ -307,6 +306,8 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids);
307306
static int pwm_imx27_probe(struct platform_device *pdev)
308307
{
309308
struct pwm_imx27_chip *imx;
309+
int ret;
310+
u32 pwmcr;
310311

311312
imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL);
312313
if (imx == NULL)
@@ -349,6 +350,15 @@ static int pwm_imx27_probe(struct platform_device *pdev)
349350
if (IS_ERR(imx->mmio_base))
350351
return PTR_ERR(imx->mmio_base);
351352

353+
ret = pwm_imx27_clk_prepare_enable(imx);
354+
if (ret)
355+
return ret;
356+
357+
/* keep clks on if pwm is running */
358+
pwmcr = readl(imx->mmio_base + MX3_PWMCR);
359+
if (!(pwmcr & MX3_PWMCR_EN))
360+
pwm_imx27_clk_disable_unprepare(imx);
361+
352362
return pwmchip_add(&imx->chip);
353363
}
354364

0 commit comments

Comments
 (0)