* [PATCH 0/2] leds: tps6131x: Fix torch-to-flash transitions
@ 2026-11-17 6:43 jiegu
2026-11-17 6:43 ` [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch jiegu
2026-11-17 6:43 ` [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover jiegu
0 siblings, 2 replies; 5+ messages in thread
From: jiegu @ 2026-11-17 6:43 UTC (permalink / raw)
To: Matthias Fend, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, jiegu
Our product uses the TI TPS61311 white flash LED controller.
The flashlight can be controlled in two modes: flash and torch.
Currently, there is a conflict when the torch is enabled and the
camera is opened. The torch is turned off while the camera is
active, but it is automatically re-enabled after the watchdog
timeout expires.
Also, When the device switches from torch mode to flash or
external strobe mode, the hardware torch output is disabled,
but the LED class brightness cache may still keep the previous
non-zero torch value.
This series fixes both issues by cancelling the pending torch refresh
work before switching modes and clearing the cached torch brightness
after a successful mode change.
Tested on a custom product board using the TI TPS61311.
gujie (2):
leds: tps6131x: cancel torch refresh on flash mode switch
leds: tps6131x: clear torch brightness cache on flash takeover
drivers/leds/flash/leds-tps6131x.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch
2026-11-17 6:43 [PATCH 0/2] leds: tps6131x: Fix torch-to-flash transitions jiegu
@ 2026-11-17 6:43 ` jiegu
2026-11-19 8:10 ` Matthias Fend
2026-11-17 6:43 ` [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover jiegu
1 sibling, 1 reply; 5+ messages in thread
From: jiegu @ 2026-11-17 6:43 UTC (permalink / raw)
To: Matthias Fend, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, gujie
From: gujie <jie.gu@leica-geosystems.com.cn>
The TPS6131X torch mode uses a delayed work item to refresh the watchdog
timer and keep torch mode active when driven over I2C. If userspace enables
torch and then the camera stack switches the LED into flash or external
strobe mode, the pending refresh work can still run later and force the
device back into torch mode.
Cancel the pending torch refresh work before switching into flash mode from
both the LED flash class strobe path and the V4L2 external strobe path.
Signed-off-by: gujie <jie.gu@leica-geosystems.com.cn>
---
drivers/leds/flash/leds-tps6131x.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
index 5c9a5af5af05..823e0462939c 100644
--- a/drivers/leds/flash/leds-tps6131x.c
+++ b/drivers/leds/flash/leds-tps6131x.c
@@ -378,6 +378,7 @@ static int tps6131x_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
struct tps6131x *tps6131x = fled_cdev_to_tps6131x(fled_cdev);
int ret;
+ cancel_delayed_work_sync(&tps6131x->torch_refresh_work);
guard(mutex)(&tps6131x->lock);
ret = tps6131x_set_mode(tps6131x, state ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
@@ -697,6 +698,7 @@ static int tps6131x_flash_external_strobe_set(struct v4l2_flash *v4l2_flash, boo
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct tps6131x *tps6131x = fled_cdev_to_tps6131x(fled_cdev);
+ cancel_delayed_work_sync(&tps6131x->torch_refresh_work);
guard(mutex)(&tps6131x->lock);
return tps6131x_set_mode(tps6131x, enable ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover
2026-11-17 6:43 [PATCH 0/2] leds: tps6131x: Fix torch-to-flash transitions jiegu
2026-11-17 6:43 ` [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch jiegu
@ 2026-11-17 6:43 ` jiegu
2026-11-19 8:10 ` Matthias Fend
1 sibling, 1 reply; 5+ messages in thread
From: jiegu @ 2026-11-17 6:43 UTC (permalink / raw)
To: Matthias Fend, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, gujie
From: gujie <jie.gu@leica-geosystems.com.cn>
When the device switches from torch mode to flash or external strobe
mode, the hardware torch output is disabled, but the LED class
brightness cache may still keep the previous non-zero torch value.
This leaves sysfs brightness reporting an enabled torch state even
though the light is already off.
Update the cached LED brightness to LED_OFF when flash control takes
over so userspace state matches the actual hardware state.
Signed-off-by: gujie <jie.gu@leica-geosystems.com.cn>
---
drivers/leds/flash/leds-tps6131x.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
index 823e0462939c..4f708cf56178 100644
--- a/drivers/leds/flash/leds-tps6131x.c
+++ b/drivers/leds/flash/leds-tps6131x.c
@@ -294,6 +294,11 @@ static int tps6131x_set_mode(struct tps6131x *tps6131x, enum tps6131x_mode mode,
NULL, false, force);
}
+static void tps6131x_sync_torch_brightness_off(struct tps6131x *tps6131x)
+{
+ tps6131x->fled_cdev.led_cdev.brightness = LED_OFF;
+}
+
static void tps6131x_torch_refresh_handler(struct work_struct *work)
{
struct tps6131x *tps6131x = container_of(work, struct tps6131x, torch_refresh_work.work);
@@ -398,6 +403,8 @@ static int tps6131x_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
if (ret)
return ret;
+ tps6131x_sync_torch_brightness_off(tps6131x);
+
return 0;
}
@@ -697,12 +704,19 @@ static int tps6131x_flash_external_strobe_set(struct v4l2_flash *v4l2_flash, boo
{
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
struct tps6131x *tps6131x = fled_cdev_to_tps6131x(fled_cdev);
+ int ret;
cancel_delayed_work_sync(&tps6131x->torch_refresh_work);
guard(mutex)(&tps6131x->lock);
- return tps6131x_set_mode(tps6131x, enable ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
- false);
+ ret = tps6131x_set_mode(tps6131x, enable ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
+ false);
+ if (ret)
+ return ret;
+
+ tps6131x_sync_torch_brightness_off(tps6131x);
+
+ return 0;
}
static const struct v4l2_flash_ops tps6131x_v4l2_flash_ops = {
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch
2026-11-17 6:43 ` [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch jiegu
@ 2026-11-19 8:10 ` Matthias Fend
0 siblings, 0 replies; 5+ messages in thread
From: Matthias Fend @ 2026-11-19 8:10 UTC (permalink / raw)
To: jiegu, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, gujie
Hi Jie,
Am 17.11.2026 um 07:43 schrieb jiegu:
> From: gujie <jie.gu@leica-geosystems.com.cn>
>
> The TPS6131X torch mode uses a delayed work item to refresh the watchdog
> timer and keep torch mode active when driven over I2C. If userspace enables
> torch and then the camera stack switches the LED into flash or external
> strobe mode, the pending refresh work can still run later and force the
> device back into torch mode.
>
> Cancel the pending torch refresh work before switching into flash mode from
> both the LED flash class strobe path and the V4L2 external strobe path.
>
> Signed-off-by: gujie <jie.gu@leica-geosystems.com.cn>
> ---
> drivers/leds/flash/leds-tps6131x.c | 2 ++
> 1 file changed, 2 insertions(+)
Tested with i.MX8MP-EVK and TPS61310EVM.
Reviewed-by: Matthias Fend <matthias.fend@emfend.at>
Tested-by: Matthias Fend <matthias.fend@emfend.at>
Best regards
~Matthias
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover
2026-11-17 6:43 ` [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover jiegu
@ 2026-11-19 8:10 ` Matthias Fend
0 siblings, 0 replies; 5+ messages in thread
From: Matthias Fend @ 2026-11-19 8:10 UTC (permalink / raw)
To: jiegu, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, gujie
Hi Jie,
Am 17.11.2026 um 07:43 schrieb jiegu:
> From: gujie <jie.gu@leica-geosystems.com.cn>
>
> When the device switches from torch mode to flash or external strobe
> mode, the hardware torch output is disabled, but the LED class
> brightness cache may still keep the previous non-zero torch value.
>
> This leaves sysfs brightness reporting an enabled torch state even
> though the light is already off.
>
> Update the cached LED brightness to LED_OFF when flash control takes
> over so userspace state matches the actual hardware state.
>
> Signed-off-by: gujie <jie.gu@leica-geosystems.com.cn>
> ---
> drivers/leds/flash/leds-tps6131x.c | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
> index 823e0462939c..4f708cf56178 100644
> --- a/drivers/leds/flash/leds-tps6131x.c
> +++ b/drivers/leds/flash/leds-tps6131x.c
> @@ -294,6 +294,11 @@ static int tps6131x_set_mode(struct tps6131x *tps6131x, enum tps6131x_mode mode,
> NULL, false, force);
> }
>
> +static void tps6131x_sync_torch_brightness_off(struct tps6131x *tps6131x)
> +{
> + tps6131x->fled_cdev.led_cdev.brightness = LED_OFF;
> +}
Nit: I don't think that we need a helper for this one-liner. But also
okay for me.
Tested with i.MX8MP-EVK and TPS61310EVM.
Reviewed-by: Matthias Fend <matthias.fend@emfend.at>
Tested-by: Matthias Fend <matthias.fend@emfend.at>
Best regards
~Matthias
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-19 8:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 6:43 [PATCH 0/2] leds: tps6131x: Fix torch-to-flash transitions jiegu
2026-11-17 6:43 ` [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch jiegu
2026-11-19 8:10 ` Matthias Fend
2026-11-17 6:43 ` [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover jiegu
2026-11-19 8:10 ` Matthias Fend
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®