[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250226-pwm-bl-read-back-period-from-hw-v1-1-ccd1df656b23@linaro.org>
Date: Wed, 26 Feb 2025 17:31:08 +0200
From: Abel Vesa <abel.vesa@...aro.org>
To: Uwe Kleine-König <ukleinek@...nel.org>,
Lee Jones <lee@...nel.org>, Daniel Thompson <danielt@...nel.org>,
Jingoo Han <jingoohan1@...il.com>, Helge Deller <deller@....de>
Cc: Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konradybcio@...nel.org>, Johan Hovold <johan@...nel.org>,
Sebastian Reichel <sre@...nel.org>, linux-pwm@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linux-arm-msm@...r.kernel.org,
linux-fbdev@...r.kernel.org, linux-kernel@...r.kernel.org,
Abel Vesa <abel.vesa@...aro.org>
Subject: [PATCH RFC] backlight: pwm_bl: Read back PWM period from provider
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.
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.
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.
Signed-off-by: Abel Vesa <abel.vesa@...aro.org>
---
drivers/video/backlight/pwm_bl.c | 11 +++++++++++
1 file changed, 11 insertions(+)
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);
+ 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) {
---
base-commit: 8433c776e1eb1371f5cd40b5fd3a61f9c7b7f3ad
change-id: 20250226-pwm-bl-read-back-period-from-hw-08226cc2f920
Best regards,
--
Abel Vesa <abel.vesa@...aro.org>
Powered by blists - more mailing lists