mirror of https://github.com/torvalds/linux.git
pwm: tiehrpwm: Fix corner case in clock divisor calculation
The function set_prescale_div() is responsible for calculating the clock
divisor settings such that the input clock rate is divided down such that
the required period length is at most 0x10000 clock ticks. If period_cycles
is an integer multiple of 0x10000, the divisor period_cycles / 0x10000 is
good enough. So round up in the calculation of the required divisor and
compare it using >= instead of >.
Fixes: 19891b20e7 ("pwm: pwm-tiehrpwm: PWM driver support for EHRPWM")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/85488616d7bfcd9c32717651d0be7e330e761b9c.1754927682.git.u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
This commit is contained in:
parent
bc7ce5bfc5
commit
00f83f0e07
|
|
@ -161,7 +161,7 @@ static int set_prescale_div(unsigned long rqst_prescaler, u16 *prescale_div,
|
||||||
|
|
||||||
*prescale_div = (1 << clkdiv) *
|
*prescale_div = (1 << clkdiv) *
|
||||||
(hspclkdiv ? (hspclkdiv * 2) : 1);
|
(hspclkdiv ? (hspclkdiv * 2) : 1);
|
||||||
if (*prescale_div > rqst_prescaler) {
|
if (*prescale_div >= rqst_prescaler) {
|
||||||
*tb_clk_div = (clkdiv << TBCTL_CLKDIV_SHIFT) |
|
*tb_clk_div = (clkdiv << TBCTL_CLKDIV_SHIFT) |
|
||||||
(hspclkdiv << TBCTL_HSPCLKDIV_SHIFT);
|
(hspclkdiv << TBCTL_HSPCLKDIV_SHIFT);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -224,7 +224,7 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
pc->period_cycles[pwm->hwpwm] = period_cycles;
|
pc->period_cycles[pwm->hwpwm] = period_cycles;
|
||||||
|
|
||||||
/* Configure clock prescaler to support Low frequency PWM wave */
|
/* Configure clock prescaler to support Low frequency PWM wave */
|
||||||
if (set_prescale_div(period_cycles/PERIOD_MAX, &ps_divval,
|
if (set_prescale_div(DIV_ROUND_UP(period_cycles, PERIOD_MAX), &ps_divval,
|
||||||
&tb_divval)) {
|
&tb_divval)) {
|
||||||
dev_err(pwmchip_parent(chip), "Unsupported values\n");
|
dev_err(pwmchip_parent(chip), "Unsupported values\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue