All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: linux-pwm@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	Duc Nguyen <duc.nguyen.ub@renesas.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee.jones@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] pwm: renesas-tpu: don't allow no duty if duty_ns is given
Date: Thu, 16 Sep 2021 18:47:46 +0200	[thread overview]
Message-ID: <20210916164746.rujqwpnrm4i6lf7z@pengutronix.de> (raw)
In-Reply-To: <20210915065542.1897-3-wsa+renesas@sang-engineering.com>

[-- Attachment #1: Type: text/plain, Size: 1665 bytes --]

On Wed, Sep 15, 2021 at 08:55:41AM +0200, Wolfram Sang wrote:
> From: Duc Nguyen <duc.nguyen.ub@renesas.com>
> 
> We have special code if duty_ns is 0. But if non-zero is given, then the
> calculation should not result in zero duty.

Why not? Assuming a PWM that supports multiples of say 100 ns for
duty_cycle, rounding a request for 550 ns down to 500 ns isn't worse
than rounding down a request for 50 ns to 0 ns is it?
 
> Signed-off-by: Duc Nguyen <duc.nguyen.ub@renesas.com>
> [wsa: split and reworded commit message]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/pwm/pwm-renesas-tpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c
> index 754440194650..bb51156e4bda 100644
> --- a/drivers/pwm/pwm-renesas-tpu.c
> +++ b/drivers/pwm/pwm-renesas-tpu.c
> @@ -275,7 +275,7 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
>  	if (duty_ns) {
>  		duty = clk_rate / prescalers[prescaler]
>  		     / (NSEC_PER_SEC / duty_ns);

Unrelated to the change under discussion here: Dividing by the result of
a division is bad. 

Consider:
	clk_rate = 1333333333
	prescalers[prescaler] = 43
	duty_ns = 500000001

The exact result is 15503875.996124031, with the above formula you get
31007751 which is off by nearly a factor of two.

These numbers are probably not relevant, but they show the problem.

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 --]

      reply	other threads:[~2021-09-16 18:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15  6:55 [PATCH 0/2] pwm: renesas-tpu: minor improvements Wolfram Sang
2021-09-15  6:55 ` [PATCH 1/2] pwm: renesas-tpu: better errno for impossible rates Wolfram Sang
2021-09-15  9:36   ` Sergei Shtylyov
2021-09-17  8:25   ` Uwe Kleine-König
2021-09-20  9:08     ` Wolfram Sang
2021-09-15  6:55 ` [PATCH 2/2] pwm: renesas-tpu: don't allow no duty if duty_ns is given Wolfram Sang
2021-09-16 16:47   ` Uwe Kleine-König [this message]

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=20210916164746.rujqwpnrm4i6lf7z@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=duc.nguyen.ub@renesas.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=wsa+renesas@sang-engineering.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.