aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/pwm-rockchip.c
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2016-06-14 05:13:13 -0400
committerThierry Reding <thierry.reding@gmail.com>2016-07-11 06:49:27 -0400
commit48cf973cae33488f84d7ab79a0f613383cff4de4 (patch)
tree9a990cee1a27949b156050525318553adf63c807 /drivers/pwm/pwm-rockchip.c
parent1ebb74cf3537135f157beddf1a4366070155edda (diff)
pwm: rockchip: Avoid glitches on already running PWMs
The current logic will disable the PWM clk even if the PWM was left enabled by the bootloader (because it's controlling a critical device like a regulator for example). Keep the PWM clk enabled if the PWM is enabled to avoid any glitches. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Reviewed-by: Brian Norris <briannorris@chromium.org> Tested-by: Brian Norris <briannorris@chromium.org> Tested-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-rockchip.c')
-rw-r--r--drivers/pwm/pwm-rockchip.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c
index c72b4192c7bf..dd8ca8663c24 100644
--- a/drivers/pwm/pwm-rockchip.c
+++ b/drivers/pwm/pwm-rockchip.c
@@ -319,7 +319,7 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
319 if (IS_ERR(pc->clk)) 319 if (IS_ERR(pc->clk))
320 return PTR_ERR(pc->clk); 320 return PTR_ERR(pc->clk);
321 321
322 ret = clk_prepare(pc->clk); 322 ret = clk_prepare_enable(pc->clk);
323 if (ret) 323 if (ret)
324 return ret; 324 return ret;
325 325
@@ -342,6 +342,10 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
342 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); 342 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
343 } 343 }
344 344
345 /* Keep the PWM clk enabled if the PWM appears to be up and running. */
346 if (!pwm_is_enabled(pc->chip.pwms))
347 clk_disable(pc->clk);
348
345 return ret; 349 return ret;
346} 350}
347 351
@@ -349,6 +353,20 @@ static int rockchip_pwm_remove(struct platform_device *pdev)
349{ 353{
350 struct rockchip_pwm_chip *pc = platform_get_drvdata(pdev); 354 struct rockchip_pwm_chip *pc = platform_get_drvdata(pdev);
351 355
356 /*
357 * Disable the PWM clk before unpreparing it if the PWM device is still
358 * running. This should only happen when the last PWM user left it
359 * enabled, or when nobody requested a PWM that was previously enabled
360 * by the bootloader.
361 *
362 * FIXME: Maybe the core should disable all PWM devices in
363 * pwmchip_remove(). In this case we'd only have to call
364 * clk_unprepare() after pwmchip_remove().
365 *
366 */
367 if (pwm_is_enabled(pc->chip.pwms))
368 clk_disable(pc->clk);
369
352 clk_unprepare(pc->clk); 370 clk_unprepare(pc->clk);
353 371
354 return pwmchip_remove(&pc->chip); 372 return pwmchip_remove(&pc->chip);