[PATCH RFC] backlight: pwm_bl: Read back PWM period from provider
Sebastian Reichel
sre at kernel.org
Thu Feb 27 03:06:47 UTC 2025
Hi,
On Wed, Feb 26, 2025 at 05:34:50PM +0100, Uwe Kleine-König wrote:
> On Wed, Feb 26, 2025 at 05:31:08PM +0200, Abel Vesa wrote:
> > The current implementation assumes that the PWM provider will be able to
> > meet the requested period, but that is not always the case. Some PWM
> > providers have limited HW configuration capabilities and can only
> > provide a period that is somewhat close to the requested one. This
> > simply means that the duty cycle requested might either be above the
> > PWM's maximum value or the 100% duty cycle is never reached.
>
> If you request a state with 100% relative duty cycle you should get 100%
> unless the hardware cannot do that. Which PWM hardware are you using?
> Which requests are you actually doing that don't match your expectation?
drivers/leds/rgb/leds-qcom-lpg.c (which probably should at least get
a MAINTAINERS entry to have you CC'd considering all the PWM bits in
it). See the following discussion (I point you to my message in the
middle of a thread, which has a summary and probably is a good
starting point):
https://lore.kernel.org/all/vc7irlp7nuy5yvkxwb5m7wy7j7jzgpg73zmajbmq2zjcd67pd2@cz2dcracta6w/
Greetings,
-- Sebastian
> > This could be easily fixed if the pwm_apply*() API family would allow
> > overriding the period within the PWM state that's used for providing the
> > duty cycle. But that is currently not the case.
>
> I don't understand what you mean here.
>
> > So easiest fix here is to read back the period from the PWM provider via
> > the provider's ->get_state() op, if implemented, which should provide the
> > best matched period. Do this on probe after the first ->pwm_apply() op has
> > been done, which will allow the provider to determine the best match
> > period based on available configuration knobs. From there on, the
> > backlight will use the best matched period, since the driver's internal
> > PWM state is now synced up with the one from provider.
> > [...]
> > diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> > index 237d3d3f3bb1a6d713c5f6ec3198af772bf1268c..71a3e9cd8844095e85c01b194d7466978f1ca78e 100644
> > --- a/drivers/video/backlight/pwm_bl.c
> > +++ b/drivers/video/backlight/pwm_bl.c
> > @@ -525,6 +525,17 @@ static int pwm_backlight_probe(struct platform_device *pdev)
> > goto err_alloc;
> > }
> >
> > + /*
> > + * The actual period might differ from the requested one due to HW
> > + * limitations, so sync up the period with one determined by the
> > + * provider driver.
> > + */
> > + ret = pwm_get_state_hw(pb->pwm, &pb->pwm->state);
>
> As a consumer you're not supposed to write to &pb->pwm->state. That's a
> layer violation. Please call pwm_get_state_hw() with a struct pwm_state
> that you own and save the relevant parts in your driver data.
>
> > + if (ret && ret != -EOPNOTSUPP) {
> > + dev_err(&pdev->dev, "failed to get PWM HW state");
> > + goto err_alloc;
> > + }
> > +
> > memset(&props, 0, sizeof(struct backlight_properties));
> >
> > if (data->levels) {
>
> Best regards
> Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20250227/496756a6/attachment.sig>
More information about the dri-devel
mailing list