[PATCH v2 11/20] backlight: pwm: Support enable guard period
From: H. Nikolaus Schaller
Date: Tue Nov 24 2026 - 02:28:44 EST
Some LED drivers distinguish PWM dimming from a one-wire control
mode during a startup detection window. For example, TI TPS61160/61
use the duration of low intervals on CTRL to detect EasyScale.
An initial guard interval can keep the waveform suitable for PWM
mode detection before normal dimming begins.
Add support for a new device tree property
"pwm-enable-guard-period-us". If set, the driver applies a full
duty cycle (duty_cycle == period) for the given duration whenever
the previous PWM state was disabled or had zero duty cycle.
This covers the
requirements of such devices generically, without introducing a
chip specific backlight driver.
The requested full duty need not produce an exact constant-high
output on hardware with limited duty-cycle resolution. The board
must ensure the resulting waveform meets the LED driver timing.
Suggested-by: Andreas Kemnade <andreas@xxxxxxxxxxxx>
Link: https://patchwork.kernel.org/project/linux-omap/patch/f897f695c0e1e128d7ebb41be8dfdce4d634f552.1783749722.git.hns@xxxxxxxxxxxxx/#27124981
Signed-off-by: H. Nikolaus Schaller <hns@xxxxxxxxxxxxx>
---
Notes:
Changes against V1:
- Andreas Kemnade proposed placing the TPS61161 PWM-mode
initialization in backlight support rather than in the PWM
controller. The enable guard is the generic V2 implementation.
- Add pwm-enable-guard-period-us support to pwm-backlight.
- Request full duty during the startup guard when the previously
cached PWM state was disabled or had zero duty cycle.
- Check the return value of the guard PWM update, while leaving
the normal pwm_apply_might_sleep() handling as in upstream.
- Retain the hardware-tested guard implementation from the working
series; do not incorporate the later review changes to power-on
ordering, guard triggering, duty limiting or rollback handling.
- Clarify that requesting full duty does not guarantee constant
HIGH on every PWM provider; actual waveform depends on hardware.
- Keep the existing Suggested-by attribution.
- Code and commit-message review assisted by ChatGPT.
drivers/video/backlight/pwm_bl.c | 37 +++++++++++++++++++++++++++++++-
include/linux/pwm_backlight.h | 1 +
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 3ad71ee3657af..1d0a463710926 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -7,6 +7,7 @@
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
@@ -18,6 +19,9 @@
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
+/* extra time added above enable_guard_period_us for usleep_range() */
+#define PWM_BL_GUARD_SLACK_US 2000
+
struct pwm_bl_data {
struct pwm_device *pwm;
struct device *dev;
@@ -26,6 +30,7 @@ struct pwm_bl_data {
bool enabled;
struct regulator *power_supply;
struct gpio_desc *enable_gpio;
+ unsigned int enable_guard_period_us;
unsigned int scale;
unsigned int post_pwm_on_delay;
unsigned int pwm_off_delay;
@@ -93,11 +98,39 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
struct pwm_bl_data *pb = bl_get_data(bl);
int brightness = backlight_get_brightness(bl);
struct pwm_state state;
+ int ret;
if (pb->notify)
brightness = pb->notify(pb->dev, brightness);
if (brightness > 0) {
+ pwm_get_state(pb->pwm, &state);
+
+ /*
+ * Some LED drivers detect a one-wire control mode during
+ * a startup window (e.g. TI TPS61160/TPS61161, using
+ * the duration of low intervals on CTRL). Request full
+ * duty for the guard interval before normal dimming.
+ * The PWM provider may approximate full duty.
+ *
+ * Apply the guard if the previous PWM state was disabled
+ * or had zero duty cycle.
+ */
+ if (pb->enable_guard_period_us &&
+ (!state.enabled || !state.duty_cycle)) {
+ struct pwm_state guard = state;
+
+ guard.duty_cycle = guard.period;
+ guard.enabled = true;
+ ret = pwm_apply_might_sleep(pb->pwm, &guard);
+ if (ret)
+ return ret;
+
+ usleep_range(pb->enable_guard_period_us,
+ pb->enable_guard_period_us +
+ PWM_BL_GUARD_SLACK_US);
+ }
+
pwm_get_state(pb->pwm, &state);
state.duty_cycle = compute_duty_cycle(pb, brightness, &state);
state.enabled = true;
@@ -239,7 +272,8 @@ static int pwm_backlight_parse_dt(struct device *dev,
of_property_read_u32(node, "post-pwm-on-delay-ms",
&data->post_pwm_on_delay);
of_property_read_u32(node, "pwm-off-delay-ms", &data->pwm_off_delay);
-
+ of_property_read_u32(node, "pwm-enable-guard-period-us",
+ &data->enable_guard_period_us);
/*
* Determine the number of brightness levels, if this property is not
* set a default table of brightness levels will be used.
@@ -467,6 +501,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
goto err_alloc;
}
+ pb->enable_guard_period_us = data->enable_guard_period_us;
pb->notify = data->notify;
pb->notify_after = data->notify_after;
pb->exit = data->exit;
diff --git a/include/linux/pwm_backlight.h b/include/linux/pwm_backlight.h
index 0bf80e98d5b40..35cf19b1e9768 100644
--- a/include/linux/pwm_backlight.h
+++ b/include/linux/pwm_backlight.h
@@ -13,6 +13,7 @@ struct platform_pwm_backlight_data {
unsigned int lth_brightness;
unsigned int pwm_period_ns;
unsigned int *levels;
+ unsigned int enable_guard_period_us;
unsigned int post_pwm_on_delay;
unsigned int pwm_off_delay;
int (*init)(struct device *dev);
--
2.56.0