linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting
@ 2025-07-29  4:51 Fenglin Wu via B4 Relay
  2025-07-29  4:51 ` [PATCH v2 1/2] " Fenglin Wu via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Fenglin Wu via B4 Relay @ 2025-07-29  4:51 UTC (permalink / raw)
  To: kernel, Lee Jones, Pavel Machek, Konrad Dybcio
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel, Fenglin Wu

There is a current clamp register needs to be updated when enabling
torch LED, and the register address is different between different
PMIC flash LED modules. Add changes to address it.

Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
---
Changes in v2:
- Update the register mapping to use designated initializers and ensure
  they are sorted by register address.
- Update the 'msb' of 'status1' register to 5 for pmi8998 flash LED
  module
- Link to v1: https://lore.kernel.org/r/20250725-fix-torch-clamp-issue-v1-0-4cf3ebaa4c67@oss.qualcomm.com

---
Fenglin Wu (2):
      leds: flash: leds-qcom-flash: update torch current clamp setting
      leds: flash: leds-qcom-flash: add a separate register map for PMI8998

 drivers/leds/flash/leds-qcom-flash.c | 87 +++++++++++++++++++++++++-----------
 1 file changed, 60 insertions(+), 27 deletions(-)
---
base-commit: 4903924ac7ef31fbbe48b3261b1bc86ce6cd7e97
change-id: 20250725-fix-torch-clamp-issue-ca25212aa224

Best regards,
-- 
Fenglin Wu <fenglin.wu@oss.qualcomm.com>



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

* [PATCH v2 1/2] leds: flash: leds-qcom-flash: update torch current clamp setting
  2025-07-29  4:51 [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Fenglin Wu via B4 Relay
@ 2025-07-29  4:51 ` Fenglin Wu via B4 Relay
  2025-07-29 11:01   ` Konrad Dybcio
  2025-07-29  4:51 ` [PATCH v2 2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998 Fenglin Wu via B4 Relay
  2025-07-31 13:53 ` [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Lee Jones
  2 siblings, 1 reply; 8+ messages in thread
From: Fenglin Wu via B4 Relay @ 2025-07-29  4:51 UTC (permalink / raw)
  To: kernel, Lee Jones, Pavel Machek, Konrad Dybcio
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel, Fenglin Wu

From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>

There is a register to clamp the flash current per LED channel when
safety timer is disabled. It needs to be updated according to the
maximum torch LED current setting to ensure the torch current won't
be clamped unexpectedly.

Fixes: 96a2e242a5dc ("leds: flash: Add driver to support flash LED module in QCOM PMICs")
Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
---
 drivers/leds/flash/leds-qcom-flash.c | 62 +++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 26 deletions(-)

diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c
index 89cf5120f5d55bbb7e24faa8c3a946416f8fed46..db7c2c743adc755244f387febce663738bf3c0bd 100644
--- a/drivers/leds/flash/leds-qcom-flash.c
+++ b/drivers/leds/flash/leds-qcom-flash.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022, 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/bitfield.h>
@@ -114,36 +114,39 @@ enum {
 	REG_THERM_THRSH1,
 	REG_THERM_THRSH2,
 	REG_THERM_THRSH3,
+	REG_TORCH_CLAMP,
 	REG_MAX_COUNT,
 };
 
 static const struct reg_field mvflash_3ch_regs[REG_MAX_COUNT] = {
-	REG_FIELD(0x08, 0, 7),			/* status1	*/
-	REG_FIELD(0x09, 0, 7),                  /* status2	*/
-	REG_FIELD(0x0a, 0, 7),                  /* status3	*/
-	REG_FIELD_ID(0x40, 0, 7, 3, 1),         /* chan_timer	*/
-	REG_FIELD_ID(0x43, 0, 6, 3, 1),         /* itarget	*/
-	REG_FIELD(0x46, 7, 7),                  /* module_en	*/
-	REG_FIELD(0x47, 0, 5),                  /* iresolution	*/
-	REG_FIELD_ID(0x49, 0, 2, 3, 1),         /* chan_strobe	*/
-	REG_FIELD(0x4c, 0, 2),                  /* chan_en	*/
-	REG_FIELD(0x56, 0, 2),			/* therm_thrsh1 */
-	REG_FIELD(0x57, 0, 2),			/* therm_thrsh2 */
-	REG_FIELD(0x58, 0, 2),			/* therm_thrsh3 */
+	[REG_STATUS1]		= REG_FIELD(0x08, 0, 7),
+	[REG_STATUS2]		= REG_FIELD(0x09, 0, 7),
+	[REG_STATUS3]		= REG_FIELD(0x0a, 0, 7),
+	[REG_CHAN_TIMER]	= REG_FIELD_ID(0x40, 0, 7, 3, 1),
+	[REG_ITARGET]		= REG_FIELD_ID(0x43, 0, 6, 3, 1),
+	[REG_MODULE_EN]		= REG_FIELD(0x46, 7, 7),
+	[REG_IRESOLUTION]	= REG_FIELD(0x47, 0, 5),
+	[REG_CHAN_STROBE]	= REG_FIELD_ID(0x49, 0, 2, 3, 1),
+	[REG_CHAN_EN]		= REG_FIELD(0x4c, 0, 2),
+	[REG_THERM_THRSH1]	= REG_FIELD(0x56, 0, 2),
+	[REG_THERM_THRSH2]	= REG_FIELD(0x57, 0, 2),
+	[REG_THERM_THRSH3]	= REG_FIELD(0x58, 0, 2),
+	[REG_TORCH_CLAMP]	= REG_FIELD(0xec, 0, 6),
 };
 
 static const struct reg_field mvflash_4ch_regs[REG_MAX_COUNT] = {
-	REG_FIELD(0x06, 0, 7),			/* status1	*/
-	REG_FIELD(0x07, 0, 6),			/* status2	*/
-	REG_FIELD(0x09, 0, 7),			/* status3	*/
-	REG_FIELD_ID(0x3e, 0, 7, 4, 1),		/* chan_timer	*/
-	REG_FIELD_ID(0x42, 0, 6, 4, 1),		/* itarget	*/
-	REG_FIELD(0x46, 7, 7),			/* module_en	*/
-	REG_FIELD(0x49, 0, 3),			/* iresolution	*/
-	REG_FIELD_ID(0x4a, 0, 6, 4, 1),		/* chan_strobe	*/
-	REG_FIELD(0x4e, 0, 3),			/* chan_en	*/
-	REG_FIELD(0x7a, 0, 2),			/* therm_thrsh1 */
-	REG_FIELD(0x78, 0, 2),			/* therm_thrsh2 */
+	[REG_STATUS1]		= REG_FIELD(0x06, 0, 7),
+	[REG_STATUS2]		= REG_FIELD(0x07, 0, 6),
+	[REG_STATUS3]		= REG_FIELD(0x09, 0, 7),
+	[REG_CHAN_TIMER]	= REG_FIELD_ID(0x3e, 0, 7, 4, 1),
+	[REG_ITARGET]		= REG_FIELD_ID(0x42, 0, 6, 4, 1),
+	[REG_MODULE_EN]		= REG_FIELD(0x46, 7, 7),
+	[REG_IRESOLUTION]	= REG_FIELD(0x49, 0, 3),
+	[REG_CHAN_STROBE]	= REG_FIELD_ID(0x4a, 0, 6, 4, 1),
+	[REG_CHAN_EN]		= REG_FIELD(0x4e, 0, 3),
+	[REG_THERM_THRSH1]	= REG_FIELD(0x7a, 0, 2),
+	[REG_THERM_THRSH2]	= REG_FIELD(0x78, 0, 2),
+	[REG_TORCH_CLAMP]	= REG_FIELD(0xed, 0, 6),
 };
 
 struct qcom_flash_data {
@@ -156,6 +159,7 @@ struct qcom_flash_data {
 	u8			max_channels;
 	u8			chan_en_bits;
 	u8			revision;
+	u8			torch_clamp;
 };
 
 struct qcom_flash_led {
@@ -702,6 +706,7 @@ static int qcom_flash_register_led_device(struct device *dev,
 	u32 current_ua, timeout_us;
 	u32 channels[4];
 	int i, rc, count;
+	u8 torch_clamp;
 
 	count = fwnode_property_count_u32(node, "led-sources");
 	if (count <= 0) {
@@ -751,6 +756,12 @@ static int qcom_flash_register_led_device(struct device *dev,
 	current_ua = min_t(u32, current_ua, TORCH_CURRENT_MAX_UA * led->chan_count);
 	led->max_torch_current_ma = current_ua / UA_PER_MA;
 
+	torch_clamp = (current_ua / led->chan_count) / TORCH_IRES_UA;
+	if (torch_clamp != 0)
+		torch_clamp--;
+
+	flash_data->torch_clamp = max_t(u8, flash_data->torch_clamp, torch_clamp);
+
 	if (fwnode_property_present(node, "flash-max-microamp")) {
 		flash->led_cdev.flags |= LED_DEV_CAP_FLASH;
 
@@ -917,8 +928,7 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
 		flash_data->leds_count++;
 	}
 
-	return 0;
-
+	return regmap_field_write(flash_data->r_fields[REG_TORCH_CLAMP], flash_data->torch_clamp);
 release:
 	while (flash_data->v4l2_flash[flash_data->leds_count] && flash_data->leds_count)
 		v4l2_flash_release(flash_data->v4l2_flash[flash_data->leds_count--]);

-- 
2.34.1



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

* [PATCH v2 2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998
  2025-07-29  4:51 [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Fenglin Wu via B4 Relay
  2025-07-29  4:51 ` [PATCH v2 1/2] " Fenglin Wu via B4 Relay
@ 2025-07-29  4:51 ` Fenglin Wu via B4 Relay
  2025-07-29 11:01   ` Konrad Dybcio
  2025-07-31 13:53 ` [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Lee Jones
  2 siblings, 1 reply; 8+ messages in thread
From: Fenglin Wu via B4 Relay @ 2025-07-29  4:51 UTC (permalink / raw)
  To: kernel, Lee Jones, Pavel Machek, Konrad Dybcio
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel, Fenglin Wu

From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>

The 3-channel flash module in PMI8998 has several registers different
than the others, such as: torch_clamp. Add different register fields
for it.

Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
---
 drivers/leds/flash/leds-qcom-flash.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c
index db7c2c743adc755244f387febce663738bf3c0bd..b03a6833e3e3a076980bfcb46d5bbde4f4183a19 100644
--- a/drivers/leds/flash/leds-qcom-flash.c
+++ b/drivers/leds/flash/leds-qcom-flash.c
@@ -118,6 +118,22 @@ enum {
 	REG_MAX_COUNT,
 };
 
+static const struct reg_field mvflash_3ch_pmi8998_regs[REG_MAX_COUNT] = {
+	[REG_STATUS1]		= REG_FIELD(0x08, 0, 5),
+	[REG_STATUS2]		= REG_FIELD(0x09, 0, 7),
+	[REG_STATUS3]		= REG_FIELD(0x0a, 0, 7),
+	[REG_CHAN_TIMER]	= REG_FIELD_ID(0x40, 0, 7, 3, 1),
+	[REG_ITARGET]		= REG_FIELD_ID(0x43, 0, 6, 3, 1),
+	[REG_MODULE_EN]		= REG_FIELD(0x46, 7, 7),
+	[REG_IRESOLUTION]	= REG_FIELD(0x47, 0, 5),
+	[REG_CHAN_STROBE]	= REG_FIELD_ID(0x49, 0, 2, 3, 1),
+	[REG_CHAN_EN]		= REG_FIELD(0x4c, 0, 2),
+	[REG_THERM_THRSH1]	= REG_FIELD(0x56, 0, 2),
+	[REG_THERM_THRSH2]	= REG_FIELD(0x57, 0, 2),
+	[REG_THERM_THRSH3]	= REG_FIELD(0x58, 0, 2),
+	[REG_TORCH_CLAMP]	= REG_FIELD(0xea, 0, 6),
+};
+
 static const struct reg_field mvflash_3ch_regs[REG_MAX_COUNT] = {
 	[REG_STATUS1]		= REG_FIELD(0x08, 0, 7),
 	[REG_STATUS2]		= REG_FIELD(0x09, 0, 7),
@@ -862,13 +878,20 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
 		return rc;
 	}
 
-	if (val == FLASH_SUBTYPE_3CH_PM8150_VAL || val == FLASH_SUBTYPE_3CH_PMI8998_VAL) {
+	if (val == FLASH_SUBTYPE_3CH_PM8150_VAL) {
 		flash_data->hw_type = QCOM_MVFLASH_3CH;
 		flash_data->max_channels = 3;
 		regs = devm_kmemdup(dev, mvflash_3ch_regs, sizeof(mvflash_3ch_regs),
 				    GFP_KERNEL);
 		if (!regs)
 			return -ENOMEM;
+	} else if (val == FLASH_SUBTYPE_3CH_PMI8998_VAL) {
+		flash_data->hw_type = QCOM_MVFLASH_3CH;
+		flash_data->max_channels = 3;
+		regs = devm_kmemdup(dev, mvflash_3ch_pmi8998_regs,
+				    sizeof(mvflash_3ch_pmi8998_regs), GFP_KERNEL);
+		if (!regs)
+			return -ENOMEM;
 	} else if (val == FLASH_SUBTYPE_4CH_VAL) {
 		flash_data->hw_type = QCOM_MVFLASH_4CH;
 		flash_data->max_channels = 4;

-- 
2.34.1



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

* Re: [PATCH v2 1/2] leds: flash: leds-qcom-flash: update torch current clamp setting
  2025-07-29  4:51 ` [PATCH v2 1/2] " Fenglin Wu via B4 Relay
@ 2025-07-29 11:01   ` Konrad Dybcio
  2025-07-31  1:43     ` Fenglin Wu
  0 siblings, 1 reply; 8+ messages in thread
From: Konrad Dybcio @ 2025-07-29 11:01 UTC (permalink / raw)
  To: fenglin.wu, kernel, Lee Jones, Pavel Machek
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel

On 7/29/25 6:51 AM, Fenglin Wu via B4 Relay wrote:
> From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> 
> There is a register to clamp the flash current per LED channel when
> safety timer is disabled. It needs to be updated according to the
> maximum torch LED current setting to ensure the torch current won't
> be clamped unexpectedly.
> 
> Fixes: 96a2e242a5dc ("leds: flash: Add driver to support flash LED module in QCOM PMICs")
> Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> ---

I'd prefer the regfield change was done in a separate commit,
but it's not groundbreaking so I don't mind that much

[...]

>  struct qcom_flash_led {
> @@ -702,6 +706,7 @@ static int qcom_flash_register_led_device(struct device *dev,
>  	u32 current_ua, timeout_us;
>  	u32 channels[4];
>  	int i, rc, count;
> +	u8 torch_clamp;
>  
>  	count = fwnode_property_count_u32(node, "led-sources");
>  	if (count <= 0) {
> @@ -751,6 +756,12 @@ static int qcom_flash_register_led_device(struct device *dev,
>  	current_ua = min_t(u32, current_ua, TORCH_CURRENT_MAX_UA * led->chan_count);
>  	led->max_torch_current_ma = current_ua / UA_PER_MA;
>  
> +	torch_clamp = (current_ua / led->chan_count) / TORCH_IRES_UA;
> +	if (torch_clamp != 0)
> +		torch_clamp--;
> +
> +	flash_data->torch_clamp = max_t(u8, flash_data->torch_clamp, torch_clamp);

Please confirm if I understand correctly, we may have N flash LEDs 
connected, and this additional safety hardware can only compare any
individual LED's current draw against a single maximum value, which
we're setting here

Konrad

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

* Re: [PATCH v2 2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998
  2025-07-29  4:51 ` [PATCH v2 2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998 Fenglin Wu via B4 Relay
@ 2025-07-29 11:01   ` Konrad Dybcio
  0 siblings, 0 replies; 8+ messages in thread
From: Konrad Dybcio @ 2025-07-29 11:01 UTC (permalink / raw)
  To: fenglin.wu, kernel, Lee Jones, Pavel Machek
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel

On 7/29/25 6:51 AM, Fenglin Wu via B4 Relay wrote:
> From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> 
> The 3-channel flash module in PMI8998 has several registers different
> than the others, such as: torch_clamp. Add different register fields
> for it.
> 
> Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> ---

Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Konrad

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

* Re: [PATCH v2 1/2] leds: flash: leds-qcom-flash: update torch current clamp setting
  2025-07-29 11:01   ` Konrad Dybcio
@ 2025-07-31  1:43     ` Fenglin Wu
  2025-07-31  9:33       ` Konrad Dybcio
  0 siblings, 1 reply; 8+ messages in thread
From: Fenglin Wu @ 2025-07-31  1:43 UTC (permalink / raw)
  To: Konrad Dybcio, kernel, Lee Jones, Pavel Machek
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel


On 7/29/2025 7:01 PM, Konrad Dybcio wrote:
>> +	torch_clamp = (current_ua / led->chan_count) / TORCH_IRES_UA;
>> +	if (torch_clamp != 0)
>> +		torch_clamp--;
>> +
>> +	flash_data->torch_clamp = max_t(u8, flash_data->torch_clamp, torch_clamp);
> Please confirm if I understand correctly, we may have N flash LEDs
> connected, and this additional safety hardware can only compare any
> individual LED's current draw against a single maximum value, which
> we're setting here
Yes, your understanding is correct!

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

* Re: [PATCH v2 1/2] leds: flash: leds-qcom-flash: update torch current clamp setting
  2025-07-31  1:43     ` Fenglin Wu
@ 2025-07-31  9:33       ` Konrad Dybcio
  0 siblings, 0 replies; 8+ messages in thread
From: Konrad Dybcio @ 2025-07-31  9:33 UTC (permalink / raw)
  To: Fenglin Wu, kernel, Lee Jones, Pavel Machek
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel

On 7/31/25 3:43 AM, Fenglin Wu wrote:
> 
> On 7/29/2025 7:01 PM, Konrad Dybcio wrote:
>>> +    torch_clamp = (current_ua / led->chan_count) / TORCH_IRES_UA;
>>> +    if (torch_clamp != 0)
>>> +        torch_clamp--;
>>> +
>>> +    flash_data->torch_clamp = max_t(u8, flash_data->torch_clamp, torch_clamp);
>> Please confirm if I understand correctly, we may have N flash LEDs
>> connected, and this additional safety hardware can only compare any
>> individual LED's current draw against a single maximum value, which
>> we're setting here
> Yes, your understanding is correct!

Great, thank you for confirming

Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Konrad

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

* Re: [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting
  2025-07-29  4:51 [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Fenglin Wu via B4 Relay
  2025-07-29  4:51 ` [PATCH v2 1/2] " Fenglin Wu via B4 Relay
  2025-07-29  4:51 ` [PATCH v2 2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998 Fenglin Wu via B4 Relay
@ 2025-07-31 13:53 ` Lee Jones
  2 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2025-07-31 13:53 UTC (permalink / raw)
  To: kernel, Lee Jones, Pavel Machek, Konrad Dybcio, Fenglin Wu
  Cc: Subbaraman Narayanamurthy, linux-leds, linux-kernel

On Tue, 29 Jul 2025 12:51:21 +0800, Fenglin Wu wrote:
> There is a current clamp register needs to be updated when enabling
> torch LED, and the register address is different between different
> PMIC flash LED modules. Add changes to address it.
> 
> 

Applied, thanks!

[1/2] leds: flash: leds-qcom-flash: update torch current clamp setting
      commit: f1b908cc8c7110872064e4a55a88b34938b4054a
[2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998
      commit: 82f1f0522cad9193a42593b9e9622433efcf5f26

--
Lee Jones [李琼斯]


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

end of thread, other threads:[~2025-07-31 13:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29  4:51 [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Fenglin Wu via B4 Relay
2025-07-29  4:51 ` [PATCH v2 1/2] " Fenglin Wu via B4 Relay
2025-07-29 11:01   ` Konrad Dybcio
2025-07-31  1:43     ` Fenglin Wu
2025-07-31  9:33       ` Konrad Dybcio
2025-07-29  4:51 ` [PATCH v2 2/2] leds: flash: leds-qcom-flash: add a separate register map for PMI8998 Fenglin Wu via B4 Relay
2025-07-29 11:01   ` Konrad Dybcio
2025-07-31 13:53 ` [PATCH v2 0/2] leds: flash: leds-qcom-flash: update torch current clamp setting Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).