From: Christian Marangi <ansuelsmth@gmail.com>
To: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
Benjamin Larsson <benjamin.larsson@genexis.eu>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Lorenzo Bianconi <lorenzo@kernel.org>
Subject: Re: [PATCH v12] pwm: airoha: Add support for EN7581 SoC
Date: Fri, 9 May 2025 21:51:29 +0200 [thread overview]
Message-ID: <681e5cc3.df0a0220.2f84eb.c5cf@mx.google.com> (raw)
In-Reply-To: <pbutokheq6zm4gzjzvhhmxvnse3uudb5obpuyd55z7emlm3pju@7l7hocoktu37>
On Fri, May 09, 2025 at 09:43:55PM +0200, Uwe Kleine-König wrote:
> Hello Christian,
>
> On Fri, May 09, 2025 at 03:03:23PM +0200, Christian Marangi wrote:
> > thanks a lot for the review. I was just starting reviewing some patch on
> > patchwork so I could remove some work from you but you were faster...
>
> You're still invited to comment ...
>
Ok will check!
> > On Fri, May 09, 2025 at 12:39:37PM +0200, Uwe Kleine-König wrote:
> > > On Mon, Apr 07, 2025 at 07:35:53PM +0200, Christian Marangi wrote:
> > > > +static void airoha_pwm_get_ticks_from_ns(u64 period_ns, u32 *period_tick,
> > > > + u64 duty_ns, u32 *duty_tick)
> > > > +{
> > > > + u64 tmp_duty_tick;
> > > > +
> > > > + *period_tick = div_u64(period_ns, AIROHA_PWM_PERIOD_TICK_NS);
> > > > +
> > > > + tmp_duty_tick = mul_u64_u64_div_u64(duty_ns, AIROHA_PWM_DUTY_FULL,
> > > > + period_ns);
> > >
> > > So period can be set to multiples of 4 ms. If you request
> > >
> > > .period_ns = 11999 ns
> > > .duty_ns = 4016 ns
> > >
> > > the hardware should configure
> > >
> > > .period = 8000 ns
> > > .duty_cycle = 4015.6862745098038 ns (i.e. 128/255 * period)
> > >
> > > corresponding to period_tick = 2 and duty_tick = 128.
> > >
> > > However you calculate duty_tick = 85.
> > >
> > > I would expect that with having PWM_DEBUG enabled you get a warning when
> > > you do:
> > >
> > > pwmset -P 8000 -D 4016
> > > pwmset -P 11999 -D 4016
> > >
> >
> > I addressed all the other comments but this is the only thing that I'm
> > confused about.
> >
> > Where 85 comes from?
>
> 4016 * 255 / 11999 -> 85. The problem I suspected is that duty_tick is
> calculated using the requested period value instead of the real one.
>
> > I tested your command and I can correctly observe the values getting
> > set to the expected tick.
>
> I didn't recheck in detail and now I'm unsure if that really happens
> because period_ns might be already round to a multiple of 4 ms?
>
Yes it it. And that was actually a problem I notice in v11 that was
causing idempotent problem.
It's done in .apply with
period_ns = rounddown(state->period, AIROHA_PWM_PERIOD_TICK_NS);
We normalize the value to 4ns step. Sooo with 11999, in
airoha_pwm_config the actual value used is 8000.
> > And I don't have the idempotent warning from PWM debug.
> >
> > With period = 8000 and duty to 4016, period tick is set to 0x2 and duty
> > is set to 0x80 (128)
> >
> > When PWM debug repply the configuration and read the state, it gets
> > period 0x8000 and duty 4015,687.
> >
> > And those are the expected values. Am I missing something here?
>
> If you don't get the warning, you most probably only miss that I
> misjudged the code :-)
I both tested with your combo values and with a loop and pwm-leds from 0
to 255 and no warning.
I will send v13, finger crossed everything is good!
>
> Best regards
> Uwe
--
Ansuel
prev parent reply other threads:[~2025-05-09 19:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 17:35 [PATCH v12] pwm: airoha: Add support for EN7581 SoC Christian Marangi
2025-04-22 17:21 ` Christian Marangi
2025-05-09 10:39 ` Uwe Kleine-König
2025-05-09 13:03 ` Christian Marangi
2025-05-09 19:43 ` Uwe Kleine-König
2025-05-09 19:51 ` Christian Marangi [this message]
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=681e5cc3.df0a0220.2f84eb.c5cf@mx.google.com \
--to=ansuelsmth@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=benjamin.larsson@genexis.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=ukleinek@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).