mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] leds: tps6131x: Fix torch-to-flash transitions
@ 2026-11-20  7:58 Jie Gu
  2026-11-20  7:58 ` [PATCH v2 1/2] leds: tps6131x: Cancel torch refresh on flash mode switch Jie Gu
  2026-11-20  7:58 ` [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover Jie Gu
  0 siblings, 2 replies; 4+ messages in thread
From: Jie Gu @ 2026-11-20  7:58 UTC (permalink / raw)
  To: Matthias Fend, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, Jie Gu

This series fixes torch-to-flash transitions in the TPS6131x driver
by cancelling pending torch refresh work and clearing the cached
torch brightness when flash control takes over.

Matthias Fend reviewed and tested v1 on an i.MX8MP-EVK with a
TPS61310EVM. Thanks to Matthias for reviewing and testing, and to Lee
Jones for the review comments.

Changes in v2:
- Use my full name in the author and Signed-off-by fields.
- Capitalize the commit subjects after the driver prefix.
- Update the cached torch brightness directly at the call sites
  instead of using a helper.
- Add Fixes tags.
- Carry forward Matthias Fend's Reviewed-by and Tested-by tags.
 
v1: https://lore.kernel.org/linux-leds/20261117064328.4096518-1-jie.gu@leica-geosystems.com/T/

Jie Gu (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 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] leds: tps6131x: Cancel torch refresh on flash mode switch
  2026-11-20  7:58 [PATCH v2 0/2] leds: tps6131x: Fix torch-to-flash transitions Jie Gu
@ 2026-11-20  7:58 ` Jie Gu
  2026-11-20  7:58 ` [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover Jie Gu
  1 sibling, 0 replies; 4+ messages in thread
From: Jie Gu @ 2026-11-20  7:58 UTC (permalink / raw)
  To: Matthias Fend, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, Jie Gu

From: Jie Gu <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.

Fixes: b338a2ae9b31 ("leds: tps6131x: Add support for Texas Instruments TPS6131X flash LED driver")

Reviewed-by: Matthias Fend <matthias.fend@emfend.at>
Tested-by: Matthias Fend <matthias.fend@emfend.at>
Signed-off-by: Jie Gu <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] 4+ messages in thread

* [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover
  2026-11-20  7:58 [PATCH v2 0/2] leds: tps6131x: Fix torch-to-flash transitions Jie Gu
  2026-11-20  7:58 ` [PATCH v2 1/2] leds: tps6131x: Cancel torch refresh on flash mode switch Jie Gu
@ 2026-11-20  7:58 ` Jie Gu
  2026-11-27  9:47   ` Lee Jones
  1 sibling, 1 reply; 4+ messages in thread
From: Jie Gu @ 2026-11-20  7:58 UTC (permalink / raw)
  To: Matthias Fend, Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, Jie Gu

From: Jie Gu <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.

Fixes: b338a2ae9b31 ("leds: tps6131x: Add support for Texas Instruments TPS6131X flash LED driver")

Reviewed-by: Matthias Fend <matthias.fend@emfend.at>
Tested-by: Matthias Fend <matthias.fend@emfend.at>
Signed-off-by: Jie Gu <jie.gu@leica-geosystems.com.cn>
---
 drivers/leds/flash/leds-tps6131x.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
index 823e0462939c..21957e4e3db4 100644
--- a/drivers/leds/flash/leds-tps6131x.c
+++ b/drivers/leds/flash/leds-tps6131x.c
@@ -398,6 +398,8 @@ static int tps6131x_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
 	if (ret)
 		return ret;
 
+	fled_cdev->led_cdev.brightness = LED_OFF;
+
 	return 0;
 }
 
@@ -697,12 +699,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;
+
+	fled_cdev->led_cdev.brightness = LED_OFF;
+
+	return 0;
 }
 
 static const struct v4l2_flash_ops tps6131x_v4l2_flash_ops = {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover
  2026-11-20  7:58 ` [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover Jie Gu
@ 2026-11-27  9:47   ` Lee Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2026-11-27  9:47 UTC (permalink / raw)
  To: Jie Gu; +Cc: Matthias Fend, Pavel Machek, linux-leds, linux-kernel, Jie Gu

On Fri, 20 Nov 2026, Jie Gu wrote:

> From: Jie Gu <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.
> 
> Fixes: b338a2ae9b31 ("leds: tps6131x: Add support for Texas Instruments TPS6131X flash LED driver")
> 

Nit: The trailers should not have blank lines.

> Reviewed-by: Matthias Fend <matthias.fend@emfend.at>
> Tested-by: Matthias Fend <matthias.fend@emfend.at>
> Signed-off-by: Jie Gu <jie.gu@leica-geosystems.com.cn>
> ---
>  drivers/leds/flash/leds-tps6131x.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
> index 823e0462939c..21957e4e3db4 100644
> --- a/drivers/leds/flash/leds-tps6131x.c
> +++ b/drivers/leds/flash/leds-tps6131x.c
> @@ -398,6 +398,8 @@ static int tps6131x_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
>  	if (ret)
>  		return ret;
>  
> +	fled_cdev->led_cdev.brightness = LED_OFF;
> +
>  	return 0;
>  }
>  
> @@ -697,12 +699,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;
> +
> +	fled_cdev->led_cdev.brightness = LED_OFF;
> +
> +	return 0;
>  }
>  
>  static const struct v4l2_flash_ops tps6131x_v4l2_flash_ops = {
> -- 
> 2.43.0
> 

-- 
Lee Jones

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-27  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  7:58 [PATCH v2 0/2] leds: tps6131x: Fix torch-to-flash transitions Jie Gu
2026-11-20  7:58 ` [PATCH v2 1/2] leds: tps6131x: Cancel torch refresh on flash mode switch Jie Gu
2026-11-20  7:58 ` [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover Jie Gu
2026-11-27  9:47   ` Lee Jones

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®