backlight: qcom-wled: Fix OVP IRQ imbalance and start from the hardware state
v4 cover backlight: qcom-wled: Fix OVP IRQ imbalance and start from the hardware state
The qcom-wled OVP interrupt is enabled at probe whenever the module is already on, but the driver still believes the backlight is off, so the first brightness update re-enables the interrupt and trips "Unbalanced enable for IRQ". sdm845-mainline has carried a workaround for years and Joel posted a flag-based version last October [1], which Konrad and Daniel asked to be replaced by something that does not track the IRQ state by hand.
Patch 1 is the drvdata fix I said I would drop after v3. The objection was that it stored the wrong object, not that the fix was wrong, so it is back with the right one stored.
Patch 2 is unrelated too and fell out of writing the readback: the WLED3 brightness register stride has been one byte instead of two since the 2019 restructuring, so multi-string pm8941 boards only program one string correctly. Untested, I have no WLED3 board; it restores what pm8941-wled.c did and matches the downstream leds-qpnp.c layout.
---
Changes in v4:
- I applied the 0x10 fix too late, now it's fixed in the right commit. (Konrad)
- Right object stored in the drvdata. (Konrad)
- Set the drvdata next to the other wled fields instead of next to the backlight device registration.
- Reworded the drvdata commit, the NULL dereference is in wled_remove(),
the driver has no PM callbacks.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Fix typo 0x10 != 0b10. (Sashiko)
- Added fix for a unrelated issue, but since reported as critical, let's
squeeze it:
Missing platform_set_drvdata() in wled_probe() leads to a guaranteed NULL pointer dereference in wled_remove(). (Sashiko)
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Add a fix for the WLED3 brightness register stride.
- Add patch reading the programmed brightness back via backlight_ops.get_brightness. (Konrad)
- Note the brightness readback is done in the follow-up to the first
patch.
- Link to v1: https://patch.msgid.link/[email protected]
---
David Heidelberg (4):
backlight: qcom-wled: Fix NULL pointer dereference in wled_remove()
backlight: qcom-wled: Fix WLED3 brightness register stride
backlight: qcom-wled: Fix unbalanced OVP IRQ enable at probe
backlight: qcom-wled: Read back the programmed brightness at probe
drivers/video/backlight/qcom-wled.c | 89 +++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 13 deletions(-)
---
base-commit: 944a035ecca915ae947905dcfb03f2b9dc6d032c
change-id: 20260908-qcom-wled-backlight-fd9574027353
Best regards,
Signature · 1 line
David Heidelberg <[email protected]>
PATCH v4 1/4 backlight: qcom-wled: Fix NULL pointer dereference in wled_remove()
wled_probe() doesn't set the driver data for the platform device. As a result, platform_get_drvdata() in wled_remove() will return NULL, and the first dereference of it crashes on unbind.
Set the platform device driver data in wled_probe().
--- drivers/video/backlight/qcom-wled.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/backlight/qcom-wled.c +1 -0
@@ -1675,16 +1675,17 @@ static int wled_probe(struct platform_device *pdev) } wled =devm_kzalloc (&pdev->dev,sizeof (*wled),GFP_KERNEL );if (!wled)return -ENOMEM ; wled->regmap = regmap; wled->dev = &pdev->dev; +platform_set_drvdata (pdev, wled); wled->version = (uintptr_t )of_device_get_match_data (&pdev->dev);if (!wled->version) {dev_err (&pdev->dev,"Unknown device version\n" );return -ENODEV ; }mutex_init (&wled->lock);
Signature · 1 line
2.55.0
Re: [PATCH v4 1/4] backlight: qcom-wled: Fix NULL pointer dereference in wled_remove()
Quoted 6 lines · On 9/21/26 12:46 PM, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
wled_probe()doesn't set the driver data for the platform device. As a result,platform_get_drvdata()inwled_remove()will return NULL, and the first dereference of it crashes on unbind.
Quoted 6 lines
Set the platform device driver data in
wled_probe().Fixes feeab87b3072 ("backlight: qcom-wled: Add support for short circuit handling")Signed-off-by David Heidelberg <[email protected]>---
Konrad
Re: [PATCH v4 1/4] backlight: qcom-wled: Fix NULL pointer dereference in wled_remove()
In reply to David HeidelbergQuoted 11 lines · On Mon, Sep 21, 2026 at 12:46:22PM +0200, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
wled_probe()doesn't set the driver data for the platform device. As a result,platform_get_drvdata()inwled_remove()will return NULL, and the first dereference of it crashes on unbind.Set the platform device driver data in
wled_probe().Fixes feeab87b3072 ("backlight: qcom-wled: Add support for short circuit handling")Signed-off-by David Heidelberg <[email protected]>
Daniel.
PATCH v4 2/4 backlight: qcom-wled: Fix WLED3 brightness register stride
In reply to David HeidelbergWLED3 has a 16-bit brightness register pair per string, at 0x40 + 2*n, which is what the pm8941-wled driver wrote to:
rc = regmap_bulk_write(wled->regmap, wled->addr + WLED3_CTRL_REG_VAL_BASE + 2 * i, v, 2);
The restructuring for WLED3 turned that into WLED3_SINK_REG_BRIGHT(n), defined as 0x40 + n, so the two byte writes for consecutive strings
overlap: string 1 overwrites the MSB of string 0 with its own LSB, and with the default three strings only string 1 ends up with the requested value.
Use the 2 byte stride.
--- drivers/video/backlight/qcom-wled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/backlight/qcom-wled.c +1 -1
@@ -54,17 +54,17 @@#define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_CLEAR 0x00#define WLED3_SINK_REG_CURR_SINK 0x4f#define WLED3_SINK_REG_CURR_SINK_MASK GENMASK(7, 5)#define WLED3_SINK_REG_CURR_SINK_SHFT 5/* WLED3 specific per-'string' registers below */ -#define WLED3_SINK_REG_BRIGHT (n) (0x40 + n) +#define WLED3_SINK_REG_BRIGHT (n) (0x40 + (n * 0x2))#define WLED3_SINK_REG_STR_MOD_EN (n) (0x60 + (n * 0x10))#define WLED3_SINK_REG_STR_MOD_MASK BIT(7)#define WLED3_SINK_REG_STR_FULL_SCALE_CURR (n) (0x62 + (n * 0x10))#define WLED3_SINK_REG_STR_FULL_SCALE_CURR_MASK GENMASK(4, 0)#define WLED3_SINK_REG_STR_MOD_SRC (n) (0x63 + (n * 0x10))
Signature · 1 line
2.55.0
Re: [PATCH v4 2/4] backlight: qcom-wled: Fix WLED3 brightness register stride
Quoted 30 lines · On 9/21/26 12:46 PM, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
WLED3 has a 16-bit brightness register pair per string, at
0x40+ 2*n, which is what the pm8941-wled driver wrote to:rc = regmap_bulk_write(wled->regmap, wled->addr + WLED3_CTRL_REG_VAL_BASE + 2 * i, v, 2);The restructuring for WLED3 turned that into
WLED3_SINK_REG_BRIGHT(n), defined as0x40+ n, so the two byte writes for consecutive strings
overlap: string 1 overwrites the MSB of string 0 with its own LSB, and with the default three strings only string 1 ends up with the requested value.Use the 2 byte stride.
Fixes 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3")Assisted-by LLMSigned-off-by David Heidelberg <[email protected]>--- drivers/video/backlight/qcom-wled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/video/backlight/qcom-wled.c +0
-0
drivers/video/backlight/qcom-wled.c line 62
Quoted 10 lines
drivers/video/backlight/qcom-wled.c +1
-1@@ -54,17 +54,17 @@#define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_CLEAR 0x00#define WLED3_SINK_REG_CURR_SINK 0x4f#define WLED3_SINK_REG_CURR_SINK_MASK GENMASK(7, 5)#define WLED3_SINK_REG_CURR_SINK_SHFT 5/* WLED3 specific per-'string' registers below */ -#define WLED3_SINK_REG_BRIGHT (n) (0x40 + n) +#define WLED3_SINK_REG_BRIGHT (n) (0x40 + (n * 0x2))
Ideally n would be wrapped in its own parentheses (doesn't checkpatch warn against that?)
Konrad
Re: [PATCH v4 2/4] backlight: qcom-wled: Fix WLED3 brightness register stride
Quoted 38 lines · Konrad Dybcio
Quoted 37 lines · On 9/21/26 12:46 PM, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
WLED3 has a 16-bit brightness register pair per string, at
0x40+ 2*n, which is what the pm8941-wled driver wrote to:rc = regmap_bulk_write(wled->regmap, wled->addr + WLED3_CTRL_REG_VAL_BASE + 2 * i, v, 2);The restructuring for WLED3 turned that into
WLED3_SINK_REG_BRIGHT(n), defined as0x40+ n, so the two byte writes for consecutive strings
overlap: string 1 overwrites the MSB of string 0 with its own LSB, and with the default three strings only string 1 ends up with the requested value.Use the 2 byte stride.
Fixes 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3")Assisted-by LLMSigned-off-by David Heidelberg <[email protected]>--- drivers/video/backlight/qcom-wled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/video/backlight/qcom-wled.c +0
-0@@ -54,17 +54,17 @@#define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_CLEAR 0x00#define WLED3_SINK_REG_CURR_SINK 0x4f#define WLED3_SINK_REG_CURR_SINK_MASK GENMASK(7, 5)#define WLED3_SINK_REG_CURR_SINK_SHFT 5
Quoted 6 lines
drivers/video/backlight/qcom-wled.c line 62
Quoted 3 lines
drivers/video/backlight/qcom-wled.c +1
-1/* WLED3 specific per-'string' registers below */ -#define WLED3_SINK_REG_BRIGHT (n) (0x40 + n) +#define WLED3_SINK_REG_BRIGHT (n) (0x40 + (n * 0x2))Ideally n would be wrapped in its own parentheses (doesn't checkpatch warn against that?)
Yeah it does, thou not sure it make sense here. If needed, I'll send another version with it... :)
Thanks
David
Quoted 4 lines
Reviewed-by Konrad Dybcio <[email protected]>Konrad
Re: [PATCH v4 2/4] backlight: qcom-wled: Fix WLED3 brightness register stride
In reply to David HeidelbergQuoted 15 lines · On Mon, Sep 21, 2026 at 12:46:23PM +0200, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
WLED3 has a 16-bit brightness register pair per string, at
0x40+ 2*n, which is what the pm8941-wled driver wrote to:rc = regmap_bulk_write(wled->regmap, wled->addr + WLED3_CTRL_REG_VAL_BASE + 2 * i, v, 2);The restructuring for WLED3 turned that into
WLED3_SINK_REG_BRIGHT(n), defined as0x40+ n, so the two byte writes for consecutive strings
overlap: string 1 overwrites the MSB of string 0 with its own LSB, and with the default three strings only string 1 ends up with the requested value.
Quoted 6 lines
Use the 2 byte stride.
Fixes 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3")Assisted-by LLMSigned-off-by David Heidelberg <[email protected]>
Quoted 9 lines
--- drivers/video/backlight/qcom-wled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/video/backlight/qcom-wled.c +0
-0
drivers/video/backlight/qcom-wled.c line 62
Quoted 10 lines
drivers/video/backlight/qcom-wled.c +1
-1@@ -54,17 +54,17 @@#define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_CLEAR 0x00#define WLED3_SINK_REG_CURR_SINK 0x4f#define WLED3_SINK_REG_CURR_SINK_MASK GENMASK(7, 5)#define WLED3_SINK_REG_CURR_SINK_SHFT 5/* WLED3 specific per-'string' registers below */ -#define WLED3_SINK_REG_BRIGHT (n) (0x40 + n) +#define WLED3_SINK_REG_BRIGHT (n) (0x40 + (n * 0x2))
I saw the comment about (n).
I'd rather see that in the marcos... but since the new code matches the existing macros it has my R-b with or without change.
Daniel.
PATCH v4 3/4 backlight: qcom-wled: Fix unbalanced OVP IRQ enable at probe
In reply to David Heidelbergwled_configure_ovp_irq() derives the initial state of the OVP interrupt from the hardware:
/* Keep OVP irq disabled until module is enabled */
if (!(val & WLED3_CTRL_REG_MOD_EN_MASK))
disable_irq(wled->ovp_irq);but wled->brightness, which is what the rest of the driver uses to tell whether the module is on, is left at zero.
On boards where the bootloader hands the kernel a lit backlight the two disagree. MOD_EN is already set, so the interrupt is left enabled, while wled_update_status() still believes the backlight is off and takes
if (!!brightness != !!wled->brightness)
rc = wled_module_enable(wled, !!brightness);on the first backlight update. wled_module_enable() then schedules wled_ovp_work(), which calls enable_irq() on the already enabled interrupt:
Unbalanced enable for IRQ 176
WARNING: CPU: 0 PID: 160 at kernel/irq/manage.c:774 __enable_irq+0x50/0x80 Hardware name: Xiaomi Pocophone F1 (DT) Workqueue: events wled_ovp_work Call trace: __enable_irq+0x50/0x80 enable_irq+0x48/0xa0 wled_ovp_work+0x18/0x24 process_one_work+0x1d0/0x350 worker_thread+0x13c/0x460 kthread+0x110/0x114 ret_from_fork+0x10/0x20
The bootloader is not the only way to get there. The readback runs after wledN_setup(), and wled4_setup() sets MOD_EN itself on the path where the sink configuration does not already match, as does the tail of wled_auto_string_detection(), which all three setup paths can reach through wled_auto_detection_at_init(). A cold-booted board with a dark panel can therefore reach the same disagreement.
Move the MOD_EN readback into wled_probe() and use it to seed wled->brightness, so the driver starts out agreeing with the hardware, and key the OVP interrupt off wled->brightness instead. The first backlight update then only reprograms the brightness registers and leaves both the module and the interrupt alone. The OVP interrupt also stays armed from probe whenever the module is already enabled, rather than being disabled at probe and only enabled once something writes brightness.
Note that a backlight update requesting brightness 0 before any non-zero one now really does turn the module off wherever MOD_EN was already set, where before it was silently ignored.
wled->brightness is seeded with default-brightness rather than the level the bootloader actually programmed, so the first update can still step the brightness. Reading that level back is version specific and is done in a follow-up, to keep this fix small enough to backport.
--- drivers/video/backlight/qcom-wled.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/video/backlight/qcom-wled.c +21 -11
@@ -1622,54 +1622,49 @@ static int wled_configure_short_irq(struct wled *wled,return rc; }static int wled_configure_ovp_irq (struct wled *wled,struct platform_device *pdev) {int rc; -u32 val; wled->ovp_irq =platform_get_irq_byname (pdev,"ovp" );if (wled->ovp_irq <0 ) {dev_dbg (&pdev->dev,"OVP IRQ not found - disabling automatic string detection\n" );return 0 ; } rc =devm_request_threaded_irq (wled->dev, wled->ovp_irq,NULL , wled_ovp_irq_handler,IRQF_ONESHOT ,"wled_ovp_irq" , wled);if (rc <0 ) { wled->ovp_irq =0 ;return 0 ; } - rc =regmap_read (wled->regmap, wled->ctrl_addr + -WLED3_CTRL_REG_MOD_EN , &val); -if (rc <0 ) -return rc; - -/* Keep OVP irq disabled until module is enabled */ -if (!(val &WLED3_CTRL_REG_MOD_EN_MASK )) +/* Keep the OVP irq disabled until the module is enabled */ +if (!wled->brightness)disable_irq (wled->ovp_irq);return 0 ; }static const struct backlight_ops wled_ops = { .update_status = wled_update_status, };static int wled_probe (struct platform_device *pdev) {struct backlight_properties props;struct backlight_device *bl;struct wled *wled;struct regmap *regmap; +u32 mod_en;u32 val;int rc; regmap =dev_get_regmap (pdev->dev.parent,NULL );if (!regmap) {dev_err (&pdev->dev,"Unable to get regmap\n" );return -EINVAL ; }
@@ -1730,27 +1725,42 @@ static int wled_probe(struct platform_device *pdev)default :dev_err (wled->dev,"Invalid WLED version\n" );break ; }INIT_DELAYED_WORK (&wled->ovp_work, wled_ovp_work); + val =WLED_DEFAULT_BRIGHTNESS ; +of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val); + +/* +* The module may already be enabled, either by a bootloader that left +* the backlight lit or by the setup above. Record that, so that the +* first brightness update does not enable an already enabled module, +* and so that the OVP irq is armed from probe rather than from that +* first update. +*/ + rc =regmap_read (wled->regmap, wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , + &mod_en); +if (rc <0 ) +return rc; + +if (mod_en &WLED3_CTRL_REG_MOD_EN_MASK ) + wled->brightness = val; + rc =wled_configure_short_irq (wled, pdev);if (rc <0 )return rc; rc =wled_configure_ovp_irq (wled, pdev);if (rc <0 )return rc; - val =WLED_DEFAULT_BRIGHTNESS ; -of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val); -memset (&props,0 ,sizeof (struct backlight_properties )); props.type =BACKLIGHT_RAW ; props.brightness = val; props.max_brightness = wled->max_brightness; bl =devm_backlight_device_register (&pdev->dev, wled->name, &pdev->dev, wled, &wled_ops, &props);return PTR_ERR_OR_ZERO (bl);
Signature · 1 line
2.55.0
Re: [PATCH v4 3/4] backlight: qcom-wled: Fix unbalanced OVP IRQ enable at probe
Quoted 61 lines · On Mon, Sep 21, 2026 at 12:46:24PM +0200, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
wled_configure_ovp_irq()derives the initial state of the OVP interrupt from the hardware:/* Keep OVP irq disabled until module is enabled */ if (!(val & WLED3_CTRL_REG_MOD_EN_MASK)) disable_irq(wled->ovp_irq);but
wled->brightness, which is what the rest of the driver uses to tell whether the module is on, is left at zero.On boards where the bootloader hands the kernel a lit backlight the two disagree.
MOD_ENis already set, so the interrupt is left enabled, whilewled_update_status()still believes the backlight is off and takesif (!!brightness != !!wled->brightness) rc = wled_module_enable(wled, !!brightness);on the first backlight update.
wled_module_enable()then scheduleswled_ovp_work(), which callsenable_irq()on the already enabled interrupt:Unbalanced enable for IRQ 176
WARNING: CPU: 0 PID: 160 at kernel/irq/manage.c:774 __enable_irq+0x50/0x80 Hardware name: Xiaomi Pocophone F1 (DT) Workqueue: events wled_ovp_work Call trace: __enable_irq+0x50/0x80 enable_irq+0x48/0xa0 wled_ovp_work+0x18/0x24 process_one_work+0x1d0/0x350 worker_thread+0x13c/0x460 kthread+0x110/0x114 ret_from_fork+0x10/0x20The bootloader is not the only way to get there. The readback runs after
wledN_setup(), andwled4_setup()setsMOD_ENitself on the path where the sink configuration does not already match, as does the tail ofwled_auto_string_detection(), which all three setup paths can reach throughwled_auto_detection_at_init(). A cold-booted board with a dark panel can therefore reach the same disagreement.Move the
MOD_ENreadback intowled_probe()and use it to seedwled->brightness, so the driver starts out agreeing with the hardware, and key the OVP interrupt offwled->brightnessinstead. The first backlight update then only reprograms the brightness registers and leaves both the module and the interrupt alone. The OVP interrupt also stays armed from probe whenever the module is already enabled, rather than being disabled at probe and only enabled once something writes brightness.Note that a backlight update requesting brightness 0 before any non-zero one now really does turn the module off wherever
MOD_ENwas already set, where before it was silently ignored.
wled->brightnessis seeded with default-brightness rather than the level the bootloader actually programmed, so the first update can still step the brightness. Reading that level back is version specific and is done in a follow-up, to keep this fix small enough to backport.
Quoted 4 lines
Assisted-by LLMFixes 8663c188beea ("backlight: qcom-wled: Add auto string detection logic")Signed-off-by David Heidelberg <[email protected]>
Daniel.
PATCH v4 4/4 backlight: qcom-wled: Read back the programmed brightness at probe
In reply to David HeidelbergSince the previous change wled_probe() seeds wled->brightness from MOD_EN, but with default-brightness rather than the level the hardware is actually driving, so a backlight left lit by the bootloader still visibly steps on the first update, and actual_brightness reports the last value written rather than what the panel shows.
Add wled_read_brightness(), which returns 0 when MOD_EN is clear and otherwise reads the brightness register the matching wledN_set_brightness() writes: the first enabled string on WLED3 and WLED4, the selected modulator on WLED5. Use it to seed both wled->brightness and the initial backlight property, and expose it as backlight_ops.get_brightness so that actual_brightness reflects the hardware too.
A module that is enabled with the brightness registers at zero, which wled4_setup() and wled_auto_string_detection() can leave behind on a cold boot, now reads back as off. The OVP interrupt is then armed by the first brightness update rather than from probe, which is what happens on every other board where the module starts out disabled.
--- drivers/video/backlight/qcom-wled.c | 74 +++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 11 deletions(-)
drivers/video/backlight/qcom-wled.c +63 -11
@@ -285,16 +285,60 @@ static int wled5_set_brightness(struct wled *wled, u16 brightness) WLED5_SINK_REG_MOD_A_BRIGHTNESS_LSB :WLED5_SINK_REG_MOD_B_BRIGHTNESS_LSB ; rc =regmap_bulk_write (wled->regmap, wled->sink_addr + offset, &v,sizeof (v));return rc; } +static int wled_read_brightness (struct wled *wled) +{ +u16 addr, mask; +__le16 v; +u32 val; +int rc; + + rc =regmap_read (wled->regmap, wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , + &val); +if (rc <0 ) +return rc; + +if (!(val &WLED3_CTRL_REG_MOD_EN_MASK )) +return 0 ; + +switch (wled->version) { +case 3 : + addr = wled->sink_addr + +WLED3_SINK_REG_BRIGHT (wled->cfg.enabled_strings[0 ]); + mask =WLED3_SINK_REG_BRIGHT_MAX ; +break ; +case 4 : + addr = wled->sink_addr + +WLED4_SINK_REG_BRIGHT (wled->cfg.enabled_strings[0 ]); + mask =WLED3_SINK_REG_BRIGHT_MAX ; +break ; +case 5 : + addr = wled->sink_addr + (wled->cfg.mod_sel ==MOD_A ? +WLED5_SINK_REG_MOD_A_BRIGHTNESS_LSB : +WLED5_SINK_REG_MOD_B_BRIGHTNESS_LSB ); + mask =WLED5_SINK_REG_BRIGHT_MAX_15B ; +break ; +default : +dev_err (wled->dev,"Invalid WLED version\n" ); +return -EINVAL ; + } + + rc =regmap_bulk_read (wled->regmap, addr, &v,sizeof (v)); +if (rc <0 ) +return rc; + +return min_t (u32,le16_to_cpu (v) & mask, wled->max_brightness); +} +static void wled_ovp_work (struct work_struct *work) {struct wled *wled =container_of (work, struct wled, ovp_work.work);enable_irq (wled->ovp_irq); }static int wled_module_enable (struct wled *wled,int val)
@@ -475,16 +519,28 @@ static int wled_update_status(struct backlight_device *bl) wled->brightness = brightness; unlock_mutex:mutex_unlock (&wled->lock);return rc; } +static int wled_get_brightness (struct backlight_device *bl) +{ +struct wled *wled =bl_get_data (bl); +int rc; + +mutex_lock (&wled->lock); + rc =wled_read_brightness (wled); +mutex_unlock (&wled->lock); + +return rc; +} +static int wled4_cabc_config (struct wled *wled,bool enable) {int i, j, rc;u8 val;for (i =0 ; i < wled->cfg.num_strings; i++) { j = wled->cfg.enabled_strings[i];
@@ -1646,25 +1702,25 @@ static int wled_configure_ovp_irq(struct wled *wled,if (!wled->brightness)disable_irq (wled->ovp_irq);return 0 ; }static const struct backlight_ops wled_ops = { .update_status = wled_update_status, + .get_brightness = wled_get_brightness, };static int wled_probe (struct platform_device *pdev) {struct backlight_properties props;struct backlight_device *bl;struct wled *wled;struct regmap *regmap; -u32 mod_en;u32 val;int rc; regmap =dev_get_regmap (pdev->dev.parent,NULL );if (!regmap) {dev_err (&pdev->dev,"Unable to get regmap\n" );return -EINVAL ; }
@@ -1729,41 +1785,37 @@ static int wled_probe(struct platform_device *pdev) }INIT_DELAYED_WORK (&wled->ovp_work, wled_ovp_work); val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val);/* -* The module may already be enabled, either by a bootloader that left -* the backlight lit or by the setup above. Record that, so that the -* first brightness update does not enable an already enabled module, -* and so that the OVP irq is armed from probe rather than from that -* first update. +* The module may already be lit, either by the bootloader or by the +* setup above. Start from what the hardware is driving, so that the +* first brightness update does not step the brightness. */ - rc =regmap_read (wled->regmap, wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , - &mod_en); + rc =wled_read_brightness (wled);if (rc <0 )return rc; -if (mod_en &WLED3_CTRL_REG_MOD_EN_MASK ) - wled->brightness = val; + wled->brightness = rc; rc =wled_configure_short_irq (wled, pdev);if (rc <0 )return rc; rc =wled_configure_ovp_irq (wled, pdev);if (rc <0 )return rc;memset (&props,0 ,sizeof (struct backlight_properties )); props.type =BACKLIGHT_RAW ; - props.brightness = val; + props.brightness = wled->brightness ?: val; props.max_brightness = wled->max_brightness; bl =devm_backlight_device_register (&pdev->dev, wled->name, &pdev->dev, wled, &wled_ops, &props);return PTR_ERR_OR_ZERO (bl); };static void wled_remove (struct platform_device *pdev)
Signature · 1 line
2.55.0
Re: [PATCH v4 4/4] backlight: qcom-wled: Read back the programmed brightness at probe
Quoted 22 lines · On Mon, Sep 21, 2026 at 12:46:25PM +0200, David Heidelberg via B4 Relay wrote:
From: David Heidelberg <[email protected]>
Since the previous change
wled_probe()seedswled->brightnessfromMOD_EN, but with default-brightness rather than the level the hardware is actually driving, so a backlight left lit by the bootloader still visibly steps on the first update, andactual_brightnessreports the last value written rather than what the panel shows.Add
wled_read_brightness(), which returns 0 whenMOD_ENis clear and otherwise reads the brightness register the matchingwledN_set_brightness()writes: the first enabled string on WLED3 and WLED4, the selected modulator on WLED5. Use it to seed bothwled->brightnessand the initial backlight property, and expose it as backlight_ops.get_brightness so thatactual_brightnessreflects the hardware too.A module that is enabled with the brightness registers at zero, which
wled4_setup()andwled_auto_string_detection()can leave behind on a cold boot, now reads back as off. The OVP interrupt is then armed by the first brightness update rather than from probe, which is what happens on every other board where the module starts out disabled.
Quoted 3 lines
Suggested-by Konrad Dybcio <[email protected]>Assisted-by LLMSigned-off-by David Heidelberg <[email protected]>
Daniel.
Quoted 9 lines · David Heidelberg
The qcom-wled OVP interrupt is enabled at probe whenever the module is already on, but the driver still believes the backlight is off, so the first brightness update re-enables the interrupt and trips "Unbalanced enable for IRQ". sdm845-mainline has carried a workaround for years and Joel posted a flag-based version last October [1], which Konrad and Daniel asked to be replaced by something that does not track the IRQ state by hand.
[...]
Applied, thanks!
[1/4] backlight: qcom-wled: Fix NULL pointer dereference in wled_remove()
commit: 186fc521f211a207c323b753659f28d3dda7bc45
[2/4] backlight: qcom-wled: Fix WLED3 brightness register stride
commit: e60dc9c05e0f415ef8bc63b3179abdd49830a619
[3/4] backlight: qcom-wled: Fix unbalanced OVP IRQ enable at probe
commit: b32a8c32fea3855e707717155f198f03fdbf6f1e
[4/4] backlight: qcom-wled: Read back the programmed brightness at probe
commit: 2ffcac916578f4a57347e717786d1e07e85cbf2b--
Lee Jones [李琼斯]
Lee Jones
maintainerQuoted 13 lines · Lee Jones
Quoted 9 lines · David Heidelberg
The qcom-wled OVP interrupt is enabled at probe whenever the module is already on, but the driver still believes the backlight is off, so the first brightness update re-enables the interrupt and trips "Unbalanced enable for IRQ". sdm845-mainline has carried a workaround for years and Joel posted a flag-based version last October [1], which Konrad and Daniel asked to be replaced by something that does not track the IRQ state by hand.
[...]
Applied, thanks!
Quoted 8 lines
[1/4] backlight: qcom-wled: Fix NULL pointer dereference in
wled_remove()commit: 186fc521f211a207c323b753659f28d3dda7bc45 [2/4] backlight: qcom-wled: Fix WLED3 brightness register stride commit: e60dc9c05e0f415ef8bc63b3179abdd49830a619 [3/4] backlight: qcom-wled: Fix unbalanced OVP IRQ enable at probe commit: b32a8c32fea3855e707717155f198f03fdbf6f1e [4/4] backlight: qcom-wled: Read back the programmed brightness at probe commit: 2ffcac916578f4a57347e717786d1e07e85cbf2b
No idea what this is. The other one is the correct one.
Signature · 1 line
Lee Jones
Quoted 9 lines · David Heidelberg
The qcom-wled OVP interrupt is enabled at probe whenever the module is already on, but the driver still believes the backlight is off, so the first brightness update re-enables the interrupt and trips "Unbalanced enable for IRQ". sdm845-mainline has carried a workaround for years and Joel posted a flag-based version last October [1], which Konrad and Daniel asked to be replaced by something that does not track the IRQ state by hand.
[...]
Applied, thanks!
[1/4] backlight: qcom-wled: Fix NULL pointer dereference in wled_remove()
commit: 1dbd46d4b2fb416a8202b1a8e4ef9d0cadbe075f
[2/4] backlight: qcom-wled: Fix WLED3 brightness register stride
commit: 22672f81f0724cbabb272fd0228fa424d4306082
[3/4] backlight: qcom-wled: Fix unbalanced OVP IRQ enable at probe
commit: 5eda6b51461932f9fd835ef9e4574650c69c4fe8
[4/4] backlight: qcom-wled: Read back the programmed brightness at probe
commit: eacfbe6f9716d00536edc229a58895405e73c2e4--
Lee Jones [李琼斯]