[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <mdrr6ko2zqsf2osdkecjac6ollnuvlv4irkkiyn4ihkq5fioxx@nm6677kkih4h>
Date: Fri, 26 Jan 2024 08:30:39 +0100
From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To: Wenhua Lin <Wenhua.Lin@...soc.com>
Cc: Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>, Conor Dooley <conor+dt@...nel.org>,
Orson Zhai <orsonzhai@...il.com>, Baolin Wang <baolin.wang@...ux.alibaba.com>,
Chunyan Zhang <zhang.lyra@...il.com>, linux-pwm@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, wenhua lin <wenhua.lin1994@...il.com>,
Xiongpeng Wu <xiongpeng.wu@...soc.com>, zhaochen su <zhaochen.su29@...il.com>,
Zhaochen Su <Zhaochen.Su@...soc.com>, Xiaolong Wang <Xiaolong.Wang@...soc.com>
Subject: Re: [PATCH V2 3/6] pwm: sprd: Optimize the calculation method of duty
Hello,
On Thu, Jan 25, 2024 at 10:55:30AM +0800, Wenhua Lin wrote:
> diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
> index cc54aa77c7e6..8de3f9e154ce 100644
> --- a/drivers/pwm/pwm-sprd.c
> +++ b/drivers/pwm/pwm-sprd.c
> @@ -156,7 +156,8 @@ static int sprd_pwm_config(struct sprd_pwm_chip *spc, struct pwm_device *pwm,
> * given settings (MOD and input clock).
> */
> mod = spc->mod[pwm->hwpwm];
> - duty = duty_ns * mod / period_ns;
> + tmp = (u64)duty_ns * mod;
> + duty = DIV_ROUND_CLOSEST_ULL(tmp, period_ns);
Please stick to rounding down in .apply() (and so sprd_pwm_config()).
Given that duty_ns is an u64 in .apply(), you're loosing precision
anyhow. Look at how the microchip-core driver uses mul_u64_u64_div_u64()
for how to do that properly.
You tested your patch with CONFIG_PWM_DEBUG enabled, right?
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists