All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Biju Das <biju.das.au@gmail.com>,
	linux-pwm@vger.kernel.org,  kernel@pengutronix.de,
	Magnus Damm <magnus.damm@gmail.com>,
	 Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	 linux-renesas-soc@vger.kernel.org,
	Thierry Reding <thierry.reding@gmail.com>,
	 Philipp Zabel <p.zabel@pengutronix.de>,
	Biju Das <biju.das.jz@bp.renesas.com>
Subject: Re: [PATCH v18 3/4] pwm: Add support for RZ/G2L GPT
Date: Tue, 12 Mar 2024 10:27:51 +0100	[thread overview]
Message-ID: <fdbdfaaczwiqweoa6lot7rycjnhc3fsvsluwx3c5mwc6ic2dsv@m6foz6somnuz> (raw)
In-Reply-To: <CAMuHMdV8SnMgawrMspemJNfsAHW-wSboXeEOgZ6F37QqrmiLSA@mail.gmail.com>

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

Hello Geert,

On Tue, Mar 12, 2024 at 09:11:42AM +0100, Geert Uytterhoeven wrote:
> On Tue, Mar 12, 2024 at 8:20 AM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > On Tue, Feb 20, 2024 at 07:43:17PM +0000, Biju Das wrote:
> > > --- /dev/null
> > > +++ b/drivers/pwm/pwm-rzg2l-gpt.c
> > > +static u64 calculate_period_or_duty(struct rzg2l_gpt_chip *rzg2l_gpt, u32 val, u8 prescale)
> > > +{
> > > +     u64 tmp, d;
> > > +
> > > +     /*
> > > +      * Rate is in MHz and is always integer for peripheral clk
> > > +      * 2^32 * 2^10 (prescalar) * 10^9 > 2^64
> > > +      * 2^32 * 2^10 (prescalar) * 10^6 < 2^64
> > > +      * Multiply val with prescalar first, if the result is less than
> > > +      * 2^34, then multiply by 10^9. Otherwise divide nr and dr by 10^3
> > > +      * so that it will never overflow.
> > > +      */
> > > +
> > > +     tmp = (u64)val << (2 * prescale);
> > > +     if (tmp <= (1ULL << 34)) {
> >
> > I would have written that as:
> >
> >         if (tmp >> 34 == 0)
> >
> > (which implements tmp < (1ULL << 34), which doesn't matter much).
> >
> > > +             tmp *= NSEC_PER_SEC;
> > > +             d = rzg2l_gpt->rate;
> > > +     } else {
> > > +             tmp *= div64_u64(NSEC_PER_SEC, KILO);
> >
> > I don't know if the compiler is clever enough to not calculate that
> > every time?
> 
> Not on 32-bit when written that way.
> 
> > Also using div64_u64 is too heavy given that both values fit
> > into an u32.
> 
> Indeed, so "NSEC_PER_SEC / KILO" should be fine.

ack.

> I guess NSEC_PER_MSEC would be too obfuscating?

or USEC_PER_SEC? Not sure. Also I'm unsure if using KILO instead of 1000
is really an improvement.

If you know that the clkrate is a multiple of 1000 there is no reason to
not use clkrate / 1000 unconditionally. So maybe use
rzg2l_gpt->rate_kHz (and error out in .probe if the rate isn't a
multiple of 1000?)

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:[~2024-03-12  9:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 19:43 [PATCH v18 0/4] Add support for RZ/G2L GPT Biju Das
2024-02-20 19:43 ` [PATCH v18 1/4] dt-bindings: pwm: Add RZ/G2L GPT binding Biju Das
2024-02-20 19:43 ` [PATCH v18 2/4] dt-bindings: pwm: rzg2l-gpt: Document renesas,poegs property Biju Das
2024-02-20 19:43 ` [PATCH v18 3/4] pwm: Add support for RZ/G2L GPT Biju Das
2024-03-12  7:20   ` Uwe Kleine-König
2024-03-12  8:11     ` Geert Uytterhoeven
2024-03-12  9:27       ` Uwe Kleine-König [this message]
2024-03-14 18:10     ` Biju Das
2024-03-14 22:33       ` Uwe Kleine-König
2024-03-15  7:19         ` Biju Das
2024-02-20 19:43 ` [PATCH v18 4/4] pwm: rzg2l-gpt: Add support for gpt linking with poeg Biju Das

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=fdbdfaaczwiqweoa6lot7rycjnhc3fsvsluwx3c5mwc6ic2dsv@m6foz6somnuz \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=biju.das.au@gmail.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert@linux-m68k.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --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 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.