Commit a08b318a authored by Andre Przywara's avatar Andre Przywara Committed by Thierry Reding

pwm: sun4i: Propagate errors in .get_state() to the caller

.get_state() can return an error indication now. Make use of it to
propagate an impossible prescaler encoding, should that have sneaked in
somehow.
Also check the return value of clk_get_rate(). That's unlikely to fail,
but we use that in two divide operations down in the code, so let's
avoid a divide-by-zero condition on the way.
Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
Reviewed-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: default avatarSamuel Holland <samuel@sholland.org>
Reviewed-by: default avatarJernej Skrabec <jernej.skrabec@gmail.com>
Link: https://lore.kernel.org/r/20221201152223.3133-1-andre.przywara@arm.comSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent c73a3107
...@@ -118,6 +118,8 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip, ...@@ -118,6 +118,8 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip,
unsigned int prescaler; unsigned int prescaler;
clk_rate = clk_get_rate(sun4i_pwm->clk); clk_rate = clk_get_rate(sun4i_pwm->clk);
if (!clk_rate)
return -EINVAL;
val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
...@@ -142,7 +144,7 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip, ...@@ -142,7 +144,7 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip,
prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)]; prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
if (prescaler == 0) if (prescaler == 0)
return 0; return -EINVAL;
if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm)) if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm))
state->polarity = PWM_POLARITY_NORMAL; state->polarity = PWM_POLARITY_NORMAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment