[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <68bf2509.050a0220.702b3.c003@mx.google.com>
Date: Mon, 8 Sep 2025 20:48:38 +0200
From: Christian Marangi <ansuelsmth@...il.com>
To: Uwe Kleine-König <ukleinek@...nel.org>
Cc: linux-kernel@...r.kernel.org, linux-pwm@...r.kernel.org,
Benjamin Larsson <benjamin.larsson@...exis.eu>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
Lorenzo Bianconi <lorenzo@...nel.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: Re: [PATCH v23] pwm: airoha: Add support for EN7581 SoC
On Fri, Aug 01, 2025 at 11:15:41AM +0200, Uwe Kleine-König wrote:
> Hello Christian,
>
> On Tue, Jul 08, 2025 at 04:50:52PM +0200, Christian Marangi wrote:
> > +static u32 airoha_pwm_get_period_ticks_from_ns(u32 period_ns)
> > +{
> > + return period_ns / AIROHA_PWM_PERIOD_TICK_NS;
> > +}
> > +
> > +static u32 airoha_pwm_get_duty_ticks_from_ns(u32 period_ns, u32 duty_ns)
> > +{
> > + return mul_u64_u32_div(duty_ns, AIROHA_PWM_DUTY_FULL, period_ns);
> > +}
> > +
> > [...]
> > +static int airoha_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> > + const struct pwm_state *state)
> > +{
> > [...]
> > + /*
> > + * Period goes at 4ns step, normalize it to check if we can
>
> 4 ms or 4 ns?
>
4ms you are right
> > + * share a generator.
> > + */
> > + period_ns = rounddown(period_ns, AIROHA_PWM_PERIOD_TICK_NS);
> > +
> > + /* Convert ns to ticks */
> > + period_ticks = airoha_pwm_get_period_ticks_from_ns(period_ns);
>
> Rounding down to the next multiple of 4ns isn't needed for
> airoha_pwm_get_period_ticks_from_ns() which is just a division by
> AIROHA_PWM_PERIOD_TICK_NS.
>
Ok will drop.
> > + duty_ticks = airoha_pwm_get_duty_ticks_from_ns(period_ns, duty_ns);
>
> As duty_ticks depends on the selected period_ticks, I think the bucket
> selection algorithm is still wrong.
>
> Consider a request to implement
>
> period_ns = 256 ms
> duty_ns = 128 ms
>
> which at first correctly results in
>
> period_ticks = 64
> duty_ticks = 127
>
> If however all buckets are used and we only find one with say 62 period
> ticks we get period_ns = 248 and with that duty_ticks should better be
> 131 and not 127.
>
Hi Uwe,
sorry for checking this only now and maybe we need to catch this again.
Maybe we are getting confused here but itsn't this already handled by
the upper condition?
/* Ignore bucket with invalid configs */
if (bucket_period_ticks > period_ticks ||
bucket_duty_ticks > duty_ticks)
continue;
/*
* Search for a bucket closer to the requested period/duty
* that has the maximal possible period that isn't bigger
* than the requested period. For that period pick the maximal
* duty cycle that isn't bigger than the requested duty_cycle.
*/
if (bucket_period_ticks > best_period_ticks ||
(bucket_period_ticks == best_period_ticks &&
bucket_duty_ticks > best_duty_ticks)) {
best_period_ticks = bucket_period_ticks;
best_duty_ticks = bucket_duty_ticks;
best = i;
}
We first limit for a bucket that doesn't got over both period and duty
and then we search for period and best duty. This should account for
never exceeding a duty since both period and duty are precalculated for
the current bucket and even if duty depends on period, again it's
precalculated. Am I missing something?
> > +
> > + return airoha_pwm_config(pc, pwm, period_ticks, duty_ticks);
> > +}
>
> Best regards
> Uwe
--
Ansuel
Powered by blists - more mailing lists