diff options
author | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-02-24 20:55:58 -0500 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2018-03-27 19:07:57 -0400 |
commit | 989ae7a5b2f965dc5e6de132f1d8c0ea8c23c3c5 (patch) | |
tree | 6021a938ed865b1f2008a78d0cd7c6347bb94b92 /drivers/pwm | |
parent | 120cc2fff40096fb99d96d8671ad7469dd44862f (diff) |
pwm: sun4i: Properly check current state
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: 93e0dfb2c52f ("pwm: sun4i: Improve hardware read out")
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/pwm-sun4i.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 334199c58f1d..42e6f0873d1c 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c | |||
@@ -117,7 +117,8 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, | |||
117 | 117 | ||
118 | val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); | 118 | val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); |
119 | 119 | ||
120 | if ((val == PWM_PRESCAL_MASK) && sun4i_pwm->data->has_prescaler_bypass) | 120 | if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) && |
121 | sun4i_pwm->data->has_prescaler_bypass) | ||
121 | prescaler = 1; | 122 | prescaler = 1; |
122 | else | 123 | else |
123 | prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)]; | 124 | prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)]; |
@@ -130,7 +131,8 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, | |||
130 | else | 131 | else |
131 | state->polarity = PWM_POLARITY_INVERSED; | 132 | state->polarity = PWM_POLARITY_INVERSED; |
132 | 133 | ||
133 | if (val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) | 134 | if ((val & BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) == |
135 | BIT_CH(PWM_CLK_GATING | PWM_EN, pwm->hwpwm)) | ||
134 | state->enabled = true; | 136 | state->enabled = true; |
135 | else | 137 | else |
136 | state->enabled = false; | 138 | state->enabled = false; |