[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6gvpdndagee54h7gr3uqm37rfu4yk2owffxwtszyjvnic2vqvl@pbp3jqcfrzox>
Date: Fri, 12 Sep 2025 14:32:24 +0200
From: Uwe Kleine-König <ukleinek@...nel.org>
To: Biju Das <biju.das.jz@...renesas.com>
Cc: "biju.das.au" <biju.das.au@...il.com>,
"linux-pwm@...r.kernel.org" <linux-pwm@...r.kernel.org>, "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Geert Uytterhoeven <geert+renesas@...der.be>, Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@...renesas.com>,
"linux-renesas-soc@...r.kernel.org" <linux-renesas-soc@...r.kernel.org>
Subject: Re: [PATCH v2] pwm: rzg2l-gpt: Implementation of the waveform
callbacks
Hello Biju,
On Thu, Sep 11, 2025 at 09:46:38AM +0000, Biju Das wrote:
> > -----Original Message-----
> > From: Uwe Kleine-König <ukleinek@...nel.org>
> > Sent: 09 September 2025 16:19
> > On Thu, Aug 14, 2025 at 12:50:20PM +0100, Biju wrote:
> > > -/* Caller holds the lock while calling rzg2l_gpt_config() */ -static
> > > int rzg2l_gpt_config(struct pwm_chip *chip, struct pwm_device *pwm,
> > > - const struct pwm_state *state)
> > > +static int rzg2l_gpt_round_waveform_tohw(struct pwm_chip *chip,
> > > + struct pwm_device *pwm,
> > > + const struct pwm_waveform *wf,
> > > + void *_wfhw)
> > > +
> > > {
> > > struct rzg2l_gpt_chip *rzg2l_gpt = to_rzg2l_gpt_chip(chip);
> > > - u8 sub_ch = rzg2l_gpt_subchannel(pwm->hwpwm);
> > > + struct rzg2l_gpt_waveform *wfhw = _wfhw;
> > > u8 ch = RZG2L_GET_CH(pwm->hwpwm);
> > > u64 period_ticks, duty_ticks;
> > > unsigned long pv, dc;
> > > - u8 prescale;
> > > +
> > > + guard(mutex)(&rzg2l_gpt->lock);
> > > + if (wf->period_length_ns == 0) {
> > > + *wfhw = (struct rzg2l_gpt_waveform){
> > > + .gtpr = 0,
> > > + .gtccr = 0,
> > > + .prescale = 0,
> > > + };
> > > +
> > > + return 0;
> > > + }
> > >
> > > /* Limit period/duty cycle to max value supported by the HW */
> > > - period_ticks = mul_u64_u64_div_u64(state->period, rzg2l_gpt->rate_khz, USEC_PER_SEC);
> > > + period_ticks = mul_u64_u64_div_u64(wf->period_length_ns,
> > > +rzg2l_gpt->rate_khz, USEC_PER_SEC);
> > > if (period_ticks > RZG2L_MAX_TICKS)
> > > period_ticks = RZG2L_MAX_TICKS;
> > > /*
> >
> > The code that follows here needs adaption. Other than .apply(),
> > .round_waveform_tohw() is supposed to not fail if the requested period is too small but use the
> > smallest possible value then (and return 1).
>
>
> You mean something like below
>
> if (rzg2l_gpt->channel_request_count[ch] > 1) {
> if (period_ticks < rzg2l_gpt->period_ticks[ch])
> - return -EBUSY;
> + is_small_second_period = true;
> else
> period_ticks = rzg2l_gpt->period_ticks[ch];
> }
> @@ -272,6 +276,9 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chip *chip,
> wfhw->prescale = rzg2l_gpt_calculate_prescale(rzg2l_gpt, period_ticks);
> pv = rzg2l_gpt_calculate_pv_or_dc(period_ticks, wfhw->prescale);
> wfhw->gtpr = pv;
> + if (is_small_second_period)
> + return 1;
Just locking at the diff: Yes, that looks about right. I guess you also
need `period_ticks = rzg2l_gpt->period_ticks[ch]` in the
is_small_second_period==true case.
Best regards
Uwe
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists