public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Abel Vesa <abel.vesa@linaro.org>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: Sebastian Reichel <sre@kernel.org>, Lee Jones <lee@kernel.org>,
	Pavel Machek <pavel@kernel.org>,
	Anjelique Melendez <quic_amelende@quicinc.com>,
	Kamal Wadhwa <quic_kamalw@quicinc.com>,
	Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konradybcio@kernel.org>,
	Johan Hovold <johan@kernel.org>, Pavel Machek <pavel@ucw.cz>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] leds: rgb: leds-qcom-lpg: Fix pwm resolution for Hi-Res PWMs
Date: Thu, 27 Feb 2025 19:05:14 +0200	[thread overview]
Message-ID: <Z8CbSvlG856oxQRw@linaro.org> (raw)
In-Reply-To: <Z8CTqdFafLY17C25@linaro.org>

On 25-02-27 18:32:41, Abel Vesa wrote:
> On 25-02-27 17:44:35, Abel Vesa wrote:
> > On 25-02-27 16:25:06, Uwe Kleine-König wrote:
> > > Hello Abel,
> > > 
> > > On Thu, Feb 27, 2025 at 04:26:14PM +0200, Abel Vesa wrote:
> > > > On 25-02-27 10:58:47, Uwe Kleine-König wrote:
> > > > > Can you please enable CONFIG_PWM_DEBUG, enable pwm tracing (
> > > > > 
> > > > > 	echo 1 > /sys/kernel/debug/tracing/events/pwm/enable
> > > > > 
> > > > > ) then reproduce the problem and provide the output of
> > > > > 
> > > > > 	cat /sys/kernel/debug/tracing/trace
> > > > > 
> > > > > .
> > > > 
> > > > $ cat trace
> > > > # tracer: nop
> > > > #
> > > > # entries-in-buffer/entries-written: 13/13   #P:12
> > > > #
> > > > #                                _-----=> irqs-off/BH-disabled
> > > > #                               / _----=> need-resched
> > > > #                              | / _---=> hardirq/softirq
> > > > #                              || / _--=> preempt-depth
> > > > #                              ||| / _-=> migrate-disable
> > > > #                              |||| /     delay
> > > > #           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
> > > > #              | |         |   |||||     |         |
> > > >         modprobe-203     [000] .....     0.938668: pwm_get: pwmchip0.0: period=1066407 duty_cycle=533334 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.938775: pwm_apply: pwmchip0.0: period=5000000 duty_cycle=0 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.938821: pwm_get: pwmchip0.0: period=4266537 duty_cycle=0 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.938936: pwm_apply: pwmchip0.0: period=4266537 duty_cycle=0 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.938982: pwm_get: pwmchip0.0: period=4266537 duty_cycle=0 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.939274: pwm_apply: pwmchip0.0: period=5000000 duty_cycle=921458 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.939320: pwm_get: pwmchip0.0: period=4266537 duty_cycle=921355 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.939434: pwm_apply: pwmchip0.0: period=4266537 duty_cycle=921355 polarity=0 enabled=1 err=0
> > > >         modprobe-203     [000] .....     0.939480: pwm_get: pwmchip0.0: period=4266537 duty_cycle=921355 polarity=0 enabled=1 err=0
> > > >  systemd-backlig-724     [006] .....     9.079538: pwm_apply: pwmchip0.0: period=5000000 duty_cycle=5000000 polarity=0 enabled=1 err=0
> > > >  systemd-backlig-724     [006] .....     9.079585: pwm_get: pwmchip0.0: period=4266537 duty_cycle=4266537 polarity=0 enabled=1 err=0
> > > >  systemd-backlig-724     [006] .....     9.079698: pwm_apply: pwmchip0.0: period=4266537 duty_cycle=4266537 polarity=0 enabled=1 err=0
> > > >  systemd-backlig-724     [006] .....     9.079750: pwm_get: pwmchip0.0: period=4266537 duty_cycle=4266537 polarity=0 enabled=1 err=0
> > > > $
> > > > 
> > > > > 
> > > > > I didn't take a deeper dive in this driver combination, but here is a
> > > > > description about what *should* happen:
> > > > > 
> > > > > You're talking about period in MHz, the PWM abstraction uses
> > > > > nanoseconds. So your summary translated to the PWM wording is (to the
> > > > > best of my understanding):
> > > > > 
> > > > >   1. PWM backlight driver requests PWM with .period = 200 ns and
> > > > >      .duty_cycle = 200 ns.
> > > > > 
> > > > >   2. leds-qcom-lpg cannot pick 200 ns exactly and then chooses .period =
> > > > >      1000000000 / 4.26666 MHz = 234.375 ns
> > > > >      
> > > > >   3. leds-qcom-lpg then determines setting for requested .duty_cycle
> > > > >      based on .period = 200 ns which then ends up with something bogus.
> > > 
> > > The trace looks better than what I expected. 2. is fine here because it
> > > seems when Sebastian wrote "driver requests PWM with 5 MHz period" that
> > > meant period = 5000000 ns. That was then rounded down to 4266537 ns. And
> > > the request for period = 5000000 ns + duty_cycle = 5000000 ns was
> > > serviced by configuring period = 4266537 ns + duty_cycle = 4266537 ns.
> > > So that's a 100 % relative duty configuration as intended.
> > > 
> > > So just from the traces I don't spot a problem. Do these logs not match
> > > what actually happens on the signal?
> > 
> > What I do not get is why do we expect 2 pwm_get() and 2 pwm_apply()
> > calls each time ?
> 
> OK, so the second pwm_apply() is due to CONFIG_PWM_DEBUG.
> 
> But still, the first pwm_apply() requests duty cycle of 5MHz:
> 
> systemd-backlig-724     [006] .....     9.079538: pwm_apply: pwmchip0.0: period=5000000 duty_cycle=5000000 polarity=0 enabled=1 err=0
> 
> So since the period is 4.26MHz, due to the knobs selected by the
> provider, this duty cycle will result in a PWM value that is above the
> selected resolution, as I already mentioned.
> 

On top of that, the duty cycle in debugfs is also reported as 5000000ns
when in fact it is 4266666ns, as the trace shows.

> > 
> > Need to dig a bit further.
> > 
> > But meanwhile, if the first pwm_apply() call goes all the way to the
> > provider, then the duty cycle value, when translated to the actual PWM
> > value that gets written to reg, will overflow. So this is what is wrong.
> > And this is what actually happens.
> > 
> > > 
> > > Best regards
> > > Uwe
> > 
> > 
> > 
> 

  reply	other threads:[~2025-02-27 17:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 10:31 [PATCH] leds: rgb: leds-qcom-lpg: Fix pwm resolution for Hi-Res PWMs Abel Vesa
2025-02-20 23:35 ` Sebastian Reichel
2025-02-24 20:24   ` Abel Vesa
2025-02-25  0:09     ` Sebastian Reichel
2025-02-25  8:09       ` Abel Vesa
2025-02-27  9:58         ` Uwe Kleine-König
2025-02-27 14:26           ` Abel Vesa
2025-02-27 15:25             ` Uwe Kleine-König
2025-02-27 15:44               ` Abel Vesa
2025-02-27 16:32                 ` Abel Vesa
2025-02-27 17:05                   ` Abel Vesa [this message]
2025-02-27 18:09                     ` Uwe Kleine-König
2025-02-28  8:59                       ` Abel Vesa
2025-02-28 11:16                         ` Uwe Kleine-König
2025-02-21 19:34 ` Konrad Dybcio
2025-02-28 16:00 ` Bjorn Andersson

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=Z8CbSvlG856oxQRw@linaro.org \
    --to=abel.vesa@linaro.org \
    --cc=andersson@kernel.org \
    --cc=jishnu.prakash@oss.qualcomm.com \
    --cc=johan@kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=quic_amelende@quicinc.com \
    --cc=quic_kamalw@quicinc.com \
    --cc=sre@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.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