Skip to content

Commit

Permalink
pwm: sun4i: Properly check current state
Browse files Browse the repository at this point in the history
Correctly extract the prescaler value from CTRL_REG before comparing it
to PWM_PRESCAL_MASK.

Also, check that both PWM_CLK_GATING and PWM_EN to ensure the PWM is
enabled instead of relying on only one of those.

Fixes: 93e0dfb ("pwm: sun4i: Improve hardware read out")
Signed-off-by: Alexandre Belloni <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
  • Loading branch information
alexandrebelloni authored and thierryreding committed Mar 27, 2018
1 parent 120cc2f commit 989ae7a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/pwm/pwm-sun4i.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip,

val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);

if ((val == PWM_PRESCAL_MASK) && sun4i_pwm->data->has_prescaler_bypass)
if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) &&
sun4i_pwm->data->has_prescaler_bypass)
prescaler = 1;
else
prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
Expand All @@ -130,7 +131,8 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip,
else
state->polarity = PWM_POLARITY_INVERSED;

if (val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm))
if ((val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) ==
BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm))
state->enabled = true;
else
state->enabled = false;
Expand Down

0 comments on commit 989ae7a

Please sign in to comment.