pwm: atmel: Fix incorrect CDTY value after enabling

CUPD is not flushed before enabling the channel so it will update
CDTY/CPRD just after one period. So we always set CUPD, even when the
channel is not enabled.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
Alexandre Belloni 2015-05-25 15:19:55 +02:00 committed by Thierry Reding
parent cccb94543c
commit 4c027f7ba8
1 changed files with 18 additions and 17 deletions

View File

@ -155,24 +155,25 @@ static void atmel_pwm_config_v1(struct pwm_chip *chip, struct pwm_device *pwm,
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
unsigned int val; unsigned int val;
if (test_bit(PWMF_ENABLED, &pwm->flags)) {
/*
* If the PWM channel is enabled, using the update register,
* it needs to set bit 10 of CMR to 0
*/
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CUPD, dty);
val = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CUPD, dty);
val &= ~PWM_CMR_UPD_CDTY;
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val); val = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR);
} else { val &= ~PWM_CMR_UPD_CDTY;
/* atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val);
* If the PWM channel is disabled, write value to duty and
* period registers directly. /*
*/ * If the PWM channel is enabled, only update CDTY by using the update
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CDTY, dty); * register, it needs to set bit 10 of CMR to 0
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CPRD, prd); */
} if (test_bit(PWMF_ENABLED, &pwm->flags))
return;
/*
* If the PWM channel is disabled, write value to duty and period
* registers directly.
*/
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CDTY, dty);
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CPRD, prd);
} }
static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm, static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,