public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Cosmin-Gabriel Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: "biju.das.au" <biju.das.au@gmail.com>,
	 Biju Das <biju.das.jz@bp.renesas.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: Tue, 21 Apr 2026 10:40:41 +0200	[thread overview]
Message-ID: <aec2GeV_aP6rOtFg@monoceros> (raw)
In-Reply-To: <TYRPR01MB156193428AFA2FE631556EEDA852F2@TYRPR01MB15619.jpnprd01.prod.outlook.com>

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

Hello Cosmin,

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.

> >  	/*
> >  	 * 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().
> 
> Otherwise, if pwm_round_waveform_might_sleep() is called without 
> pwm_set_waveform_might_sleep() being called immediately after with the
> rounded waveform, the software state will become out of sync with the
> hardware state.

Indeed, the tohw and fromhw callbacks must have no side effects.
There isn't a set_waveform call after each round_waveform.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-04-21  8:40 UTC|newest]

Thread overview: 13+ 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 [this message]
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=aec2GeV_aP6rOtFg@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