Message ID | 20230907161242.67190-6-ben.dooks@codethink.co.uk |
---|---|
State | New |
Headers | show |
Series | None | expand |
Hello, [again dropped William Salmon and Jude Onyenegecha from Cc:] On Thu, Sep 07, 2023 at 05:12:41PM +0100, Ben Dooks wrote: > As suggested, round up the counter variables to ensure we > always produce a longer period calculation. > > Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> > Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> > --- > drivers/pwm/pwm-dwc-core.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/pwm/pwm-dwc-core.c b/drivers/pwm/pwm-dwc-core.c > index 3b856685029d..6358e3345210 100644 > --- a/drivers/pwm/pwm-dwc-core.c > +++ b/drivers/pwm/pwm-dwc-core.c > @@ -50,13 +50,13 @@ static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc, > * 2^32 periods. > */ > tmp = state->duty_cycle * dwc->clk_rate; > - tmp = DIV_ROUND_CLOSEST_ULL(tmp, NSEC_PER_SEC); > + tmp = DIV_ROUND_UP_ULL(tmp, NSEC_PER_SEC); > if (tmp < 1 || tmp > (1ULL << 32)) > return -ERANGE; > low = tmp - 1; > > tmp = (state->period - state->duty_cycle) * dwc->clk_rate; > - tmp = DIV_ROUND_CLOSEST_ULL(tmp, NSEC_PER_SEC); > + tmp = DIV_ROUND_UP_ULL(tmp, NSEC_PER_SEC); > if (tmp < 1 || tmp > (1ULL << 32)) > return -ERANGE; > high = tmp - 1; Ah, I asked for that in the reply I just sent out to patch #4. Maybe move this before the change from #4?! I think .get_state needs to be adapted accoringly (to round up). Best regards Uwe
diff --git a/drivers/pwm/pwm-dwc-core.c b/drivers/pwm/pwm-dwc-core.c index 3b856685029d..6358e3345210 100644 --- a/drivers/pwm/pwm-dwc-core.c +++ b/drivers/pwm/pwm-dwc-core.c @@ -50,13 +50,13 @@ static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc, * 2^32 periods. */ tmp = state->duty_cycle * dwc->clk_rate; - tmp = DIV_ROUND_CLOSEST_ULL(tmp, NSEC_PER_SEC); + tmp = DIV_ROUND_UP_ULL(tmp, NSEC_PER_SEC); if (tmp < 1 || tmp > (1ULL << 32)) return -ERANGE; low = tmp - 1; tmp = (state->period - state->duty_cycle) * dwc->clk_rate; - tmp = DIV_ROUND_CLOSEST_ULL(tmp, NSEC_PER_SEC); + tmp = DIV_ROUND_UP_ULL(tmp, NSEC_PER_SEC); if (tmp < 1 || tmp > (1ULL << 32)) return -ERANGE; high = tmp - 1;
As suggested, round up the counter variables to ensure we always produce a longer period calculation. Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> --- drivers/pwm/pwm-dwc-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)