From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Jon Hunter <jonathanh@nvidia.com>
Cc: Thierry Reding <thierry.reding@gmail.com>,
linux-pwm@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH 1/2] pwm: tegra: Improve required rate calculation
Date: Wed, 26 Oct 2022 16:17:54 +0200 [thread overview]
Message-ID: <20221026141754.22ohncsbb3efhuqb@pengutronix.de> (raw)
In-Reply-To: <20221026101305.30670-1-jonathanh@nvidia.com>
[-- Attachment #1: Type: text/plain, Size: 1897 bytes --]
Hello,
On Wed, Oct 26, 2022 at 11:13:04AM +0100, Jon Hunter wrote:
> For the case where dev_pm_opp_set_rate() is called to set the PWM clock
> rate, the requested rate is calculated as ...
>
> required_clk_rate = (NSEC_PER_SEC / period_ns) << PWM_DUTY_WIDTH;
>
> The above calculation may lead to rounding errors because the
> NSEC_PER_SEC is divided by 'period_ns' before applying the
> PWM_DUTY_WIDTH multiplication factor. For example, if the period is
> 45334ns, the above calculation yields a rate of 5646848Hz instead of
> 5646976Hz. Fix this by applying the multiplication factor before
> dividing and using the DIV_ROUND_UP macro which yields the expected
> result of 5646976Hz.
>
> Fixes: 1d7796bdb63a ("pwm: tegra: Support dynamic clock frequency configuration")
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
> drivers/pwm/pwm-tegra.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index dad9978c9186..8a33c500f93b 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
> @@ -145,8 +145,8 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> * source clock rate as required_clk_rate, PWM controller will
> * be able to configure the requested period.
> */
> - required_clk_rate =
> - (NSEC_PER_SEC / period_ns) << PWM_DUTY_WIDTH;
> + required_clk_rate = DIV_ROUND_UP_ULL((NSEC_PER_SEC << PWM_DUTY_WIDTH),
> + period_ns);
This also has the nice side effect that required_clk_rate doesn't become
zero any more for big period_ns values.
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2022-10-26 14:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 10:13 [PATCH 1/2] pwm: tegra: Improve required rate calculation Jon Hunter
2022-10-26 10:13 ` [PATCH 2/2] pwm: tegra: Fix required rate when clock is lower than needed Jon Hunter
2022-10-26 14:23 ` Uwe Kleine-König
2022-10-26 20:17 ` Jon Hunter
2022-10-27 6:40 ` Uwe Kleine-König
2022-10-27 14:17 ` Jon Hunter
2022-10-27 15:40 ` Jon Hunter
2022-10-27 16:09 ` Uwe Kleine-König
2022-10-26 14:17 ` Uwe Kleine-König [this message]
2022-10-26 14:24 ` [PATCH 1/2] pwm: tegra: Improve required rate calculation Uwe Kleine-König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221026141754.22ohncsbb3efhuqb@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=jonathanh@nvidia.com \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox