Skip to content

Commit 729f477

Browse files
ukleinekUlrich Hecht
authored andcommitted
pwm: tiehrpwm: Fix corner case in clock divisor calculation
[ Upstream commit 00f83f0e07e44e2f1fb94b223e77ab7b18ee2d7d ] 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: 19891b2 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent bdb4361 commit 729f477

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/pwm/pwm-tiehrpwm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int set_prescale_div(unsigned long rqst_prescaler, u16 *prescale_div,
180180

181181
*prescale_div = (1 << clkdiv) *
182182
(hspclkdiv ? (hspclkdiv * 2) : 1);
183-
if (*prescale_div > rqst_prescaler) {
183+
if (*prescale_div >= rqst_prescaler) {
184184
*tb_clk_div = (clkdiv << TBCTL_CLKDIV_SHIFT) |
185185
(hspclkdiv << TBCTL_HSPCLKDIV_SHIFT);
186186
return 0;
@@ -279,7 +279,7 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
279279
pc->period_cycles[pwm->hwpwm] = period_cycles;
280280

281281
/* Configure clock prescaler to support Low frequency PWM wave */
282-
if (set_prescale_div(period_cycles/PERIOD_MAX, &ps_divval,
282+
if (set_prescale_div(DIV_ROUND_UP(period_cycles, PERIOD_MAX), &ps_divval,
283283
&tb_divval)) {
284284
dev_err(chip->dev, "Unsupported values\n");
285285
return -EINVAL;

0 commit comments

Comments
 (0)