From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Cosmin-Gabriel Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>,
"biju.das.au" <biju.das.au@gmail.com>,
"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
"linux-renesas-soc@vger.kernel.org"
<linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH v5 4/9] pwm: rzg2l-gpt: Convert to waveform callbacks
Date: Sun, 17 May 2026 18:57:40 +0200 [thread overview]
Message-ID: <agnynFUowrOA6oqH@monoceros> (raw)
In-Reply-To: <TY3PR01MB11346D2A5AD3D030E806594CF862B2@TY3PR01MB11346.jpnprd01.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 3500 bytes --]
Hello Biju,
On Fri, Apr 24, 2026 at 09:01:51AM +0000, Biju Das wrote:
> > -----Original Message-----
> > From: Uwe Kleine-König <ukleinek@kernel.org>
> > Sent: 21 April 2026 09:41
> > Subject: Re: [PATCH v5 4/9] pwm: rzg2l-gpt: Convert to waveform callbacks
> >
> > On Mon, Apr 20, 2026 at 05:55:07PM +0000, Cosmin-Gabriel Tanislav wrote:
> > > > @@ -291,21 +286,26 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, struct pwm_device *pwm,
> > > > if (rzg2l_gpt->channel_request_count[ch] > 1) {
> > > > u8 sibling_ch = rzg2l_gpt_sibling(pwm->hwpwm);
> > > >
> > > > - if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch)) {
> > > > + if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch, NULL)) {
> > > > if (period_ticks < rzg2l_gpt->period_ticks[ch])
> > > > - return -EBUSY;
> > > > + is_small_second_period = true;
> > > >
> > > > period_ticks = rzg2l_gpt->period_ticks[ch];
> > > > }
> > > > }
> > > >
> > > > - prescale = rzg2l_gpt_calculate_prescale(period_ticks);
> > > > - pv = rzg2l_gpt_calculate_pv_or_dc(period_ticks, prescale);
> > > > + wfhw->prescale = rzg2l_gpt_calculate_prescale(period_ticks);
> > > > + pv = rzg2l_gpt_calculate_pv_or_dc(period_ticks, wfhw->prescale);
> > > > + wfhw->gtpr = pv;
> > > > + wfhw->gtccr = 0;
> > > > + if (is_small_second_period)
> > > > + return 1;
> > > >
> > > > - duty_ticks = mul_u64_u64_div_u64(state->duty_cycle, rzg2l_gpt->rate_khz, USEC_PER_SEC);
> > > > - if (duty_ticks > period_ticks)
> > > > - duty_ticks = period_ticks;
> > > > - dc = rzg2l_gpt_calculate_pv_or_dc(duty_ticks, prescale);
> > > > + duty_ticks = mul_u64_u64_div_u64(wf->duty_length_ns, rzg2l_gpt->rate_khz, USEC_PER_SEC);
> > > > + if (duty_ticks > RZG2L_MAX_TICKS)
> > > > + duty_ticks = RZG2L_MAX_TICKS;
> > >
> > > I know this change from > period_ticks to > RZG2L_MAX_TICKS has been
> > > suggested by you, Uwe, but is this correct if period_ticks was set to
> > > a smaller value in the earlier sibling channel condition?
> >
> > Indeed this is irritating. I assume I missed that and take the blame for the wrong suggestions.
> > Depending on how hardware copes with such a configuration it might be ok to keep the code as is, but a
> > comment would be justified in this case.
>
> Please confirm
>
> /*
> * duty_ticks were clampled to match either period_ticks of this
I think it's "clamped"
> * channel or an active sibling channel's period_ticks.
> */
> if (duty_ticks > period_ticks)
> duty_ticks = period_ticks;
I think the comment is not needed in this case. (I only wanted a comment
if the comparison against RZG2L_MAX_TICKS was kept.)
> > > > /*
> > > > * GPT counter is shared by multiple channels, we cache the period
> > > > ticks @@ -314,6 +314,61 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, struct pwm_device
> > *pwm,
> > > > */
> > > > rzg2l_gpt->period_ticks[ch] = period_ticks;
> > > >
> > >
> > > This should be part of rzg2l_gpt_write_waveform().
>
> Also, if we move this to rzg2l_gpt_write_waveform() there is a rounding
> error possible as we need to use hardware register to calculate
> rzg2l_gpt->period_ticks[ch].
>
> Can you please confirm, is it ok for you?
I don't understand that. Why is there a rounding error possible? The
relevant thing here is that a call to the two rounding callbacks is not
supposed to change internal state of the driver or even the hardware.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-05-17 16:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 10:43 [PATCH v5 0/9] Add Renesas RZ/G3E GPT support Biju
2026-04-20 10:43 ` [PATCH v5 1/9] dt-bindings: pwm: rzg2l-gpt: Document renesas,poegs property Biju
2026-04-20 10:43 ` [PATCH v5 2/9] pwm: rzg2l-gpt: Add support for gpt linking with poeg Biju
2026-04-20 10:43 ` [PATCH v5 3/9] pwm: rzg2l-gpt: Drop unused rzg2l_gpt_chip parameter from rzg2l_gpt_calculate_prescale() Biju
2026-04-20 10:43 ` [PATCH v5 4/9] pwm: rzg2l-gpt: Convert to waveform callbacks Biju
2026-04-20 17:55 ` Cosmin-Gabriel Tanislav
2026-04-21 8:40 ` Uwe Kleine-König
2026-04-24 9:01 ` Biju Das
2026-05-17 16:57 ` Uwe Kleine-König [this message]
2026-06-03 13:12 ` Biju Das
2026-04-20 10:43 ` [PATCH v5 5/9] pwm: rzg2l-gpt: Add info variable to struct rzg2l_gpt_chip Biju
2026-04-20 10:43 ` [PATCH v5 6/9] pwm: rzg2l-gpt: Add prescale_mult variable to struct rzg2l_gpt_info Biju
2026-04-20 17:52 ` Biju Das
2026-04-20 10:43 ` [PATCH v5 7/9] pwm: rzg2l-gpt: Add calculate_prescale() callback " Biju
2026-04-20 10:43 ` [PATCH v5 8/9] dt-bindings: pwm: Document RZ/G3E GPT support Biju
2026-04-20 10:43 ` [PATCH v5 9/9] pwm: rzg2l-gpt: Add RZ/G3E support Biju
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=agnynFUowrOA6oqH@monoceros \
--to=ukleinek@kernel.org \
--cc=biju.das.au@gmail.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=cosmin-gabriel.tanislav.xa@renesas.com \
--cc=geert+renesas@glider.be \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.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