From f718c54c1abab7171d375112bffd199046749953 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Fri, 13 May 2016 13:09:37 +0200 Subject: pwm: atmel: Fix disabling of PWM channels When disabling a PWM channel, the PWM clock was being stopped immediately after writing to PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level. Fix this by waiting for the channel to be effectively disabled (by checking the PWM_SR register) before disabling the clock. Signed-off-by: Guillermo Rodriguez Acked-by: Alexandre Belloni Signed-off-by: Thierry Reding --- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'drivers/pwm/pwm-atmel.c') diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index 0e4bd4e8e582..f3df529737f2 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) mutex_unlock(&atmel_pwm->isr_lock); atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm); + /* + * Wait for the PWM channel disable operation to be effective before + * stopping the clock. + */ + timeout = jiffies + 2 * HZ; + + while ((atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm)) && + time_before(jiffies, timeout)) + usleep_range(10, 100); + clk_disable(atmel_pwm->clk); } -- cgit v1.2.1 From 313b78efea71229e0c48d50ed5527a3c34f3e4eb Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Mon, 11 Jul 2016 12:14:34 +0200 Subject: pwm: atmel: Fix checkpatch warnings Avoid an overly long line by moving a comment around, and remove a use of else-after-return. Signed-off-by: Thierry Reding --- drivers/pwm/pwm-atmel.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'drivers/pwm/pwm-atmel.c') diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index f3df529737f2..8083015b8641 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -64,7 +64,8 @@ struct atmel_pwm_chip { void __iomem *base; unsigned int updated_pwms; - struct mutex isr_lock; /* ISR is cleared when read, ensure only one thread does that */ + /* ISR is cleared when read, ensure only one thread does that */ + struct mutex isr_lock; void (*config)(struct pwm_chip *chip, struct pwm_device *pwm, unsigned long dty, unsigned long prd); @@ -334,6 +335,8 @@ MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids); static inline const struct atmel_pwm_data * atmel_pwm_get_driver_data(struct platform_device *pdev) { + const struct platform_device_id *id; + if (pdev->dev.of_node) { const struct of_device_id *match; @@ -342,13 +345,11 @@ atmel_pwm_get_driver_data(struct platform_device *pdev) return NULL; return match->data; - } else { - const struct platform_device_id *id; + } - id = platform_get_device_id(pdev); + id = platform_get_device_id(pdev); - return (struct atmel_pwm_data *)id->driver_data; - } + return (struct atmel_pwm_data *)id->driver_data; } static int atmel_pwm_probe(struct platform_device *pdev) -- cgit v1.2.1 From 017bb04e846be82715769799aafa934feab0e443 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Mon, 11 Jul 2016 12:16:01 +0200 Subject: pwm: atmel: Use of_device_get_match_data() Use of_device_get_match_data() instead of an open-coded variant. Signed-off-by: Thierry Reding --- drivers/pwm/pwm-atmel.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'drivers/pwm/pwm-atmel.c') diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index 8083015b8641..e6b8b1b7e6ba 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -337,15 +337,8 @@ atmel_pwm_get_driver_data(struct platform_device *pdev) { const struct platform_device_id *id; - if (pdev->dev.of_node) { - const struct of_device_id *match; - - match = of_match_device(atmel_pwm_dt_ids, &pdev->dev); - if (!match) - return NULL; - - return match->data; - } + if (pdev->dev.of_node) + return of_device_get_match_data(&pdev->dev); id = platform_get_device_id(pdev); -- cgit v1.2.1