All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support
@ 2026-08-10  7:11 Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 1/7] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron, Krzysztof Kozlowski, stable

The LiteON LTR-329ALS-01 chip is similar to the LTR-303ALS-01, except for
interrupt support and related registers, which LTR-329ALS-01 does not have.

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
Changes in v4:
- Split the duplicate error message removal into separate patch.
- Removed uneeded enum =0 assignment.
- Use dev_err_probe() instead of plain dev_err().
- Link to v3: https://patch.msgid.link/20260804-liteon-ltr329-v3-0-c6b768c7c745@geanix.com

Changes in v3:
- Removed duplicated error message on devm_request_threaded_irq() failure.
- Added Fixes: and Cc: stable tags to fix for error handling of
  devm_request_threaded_irq() failure.
- Added no_irq_support boolean to simplify checking for chip irq support.
- Moved check for no_irq_support from ltr501_read_intr_prst() and
  ltr501_write_intr_prst() to callers. Note: event functions are not
  registered for no_irq_support devices.
- Moved #include <linux/array_size.h> into its place according to
  alphabetical sorting order (although the rest is not really wel sorted).
- Restored alphanumerical ordering of compatible list in bindings
  documentation.
- Ordered device arrays and enum values according to alphanumerical sorting
  order.
- Link to v2: https://patch.msgid.link/20260715-liteon-ltr329-v2-0-d18af55edab5@geanix.com

Changes in v2:
- Fixed error handling when irq is defined for a chip that does not support
  irq, powering the chip down again.
- Added simlar fix to error handling of devm_request_threaded_irq() error
  handling, powering the chip down again on failure.
- Added explicit #include <linux/array_size.h>.
- Link to v1: https://patch.msgid.link/20260715-liteon-ltr329-v1-0-31f027051594@geanix.com

To: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
To: Nuno Sá <nuno.sa@analog.com>
To: Andy Shevchenko <andy@kernel.org>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Nikita Travkin <nikita@trvn.ru>
To: Maslov Dmitry <maslovdmitry@seeed.cc>
To: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
To: Thomas Gleixner <tglx@kernel.org>
To: Pan Chuang <panchuang@vivo.com>
To: Yangtao Li <frank.li@vivo.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: linux-iio@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

---
Esben Haabendal (7):
      dt-bindings: iio: light: ltr501: Sort compatible enum array
      dt-bindings: iio: light: ltr501: Add missing ltr303 compatible
      dt-bindings: iio: light: ltr501: Add ltr329 compatible
      iio: light: ltr501: Power down chip if request irq fails
      iio: light: ltr501: Fix duplicated error message
      iio: light: ltr501: Add ltr329 driver support
      iio: light: ltr501: Fix sorting order of device arrays

 .../bindings/iio/light/liteon,ltr501.yaml          |   4 +-
 drivers/iio/light/ltr501.c                         | 115 +++++++++++++--------
 2 files changed, 77 insertions(+), 42 deletions(-)
---
base-commit: 075b74841bd0065a3bda3440873c747938e69b68
change-id: 20260711-liteon-ltr329-a3eb12414866

Best regards,
--  
Esben Haabendal <esben@geanix.com>


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

* [PATCH v4 1/7] dt-bindings: iio: light: ltr501: Sort compatible enum array
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 2/7] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible Esben Haabendal
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron, Krzysztof Kozlowski

Restore alphabetical sorting of the properties.compatible.enum array.

Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index c8074f180a79..480523ca3750 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -15,9 +15,9 @@ allOf:
 properties:
   compatible:
     enum:
+      - liteon,ltr301
       - liteon,ltr501
       - liteon,ltr559
-      - liteon,ltr301
 
   reg:
     maxItems: 1

-- 
2.55.0


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

* [PATCH v4 2/7] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 1/7] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron, Krzysztof Kozlowski

When support for ltr303 was back in 2021, the bindings documentation was
not updated accordingly.

Fixes: 7d71d289e1ba ("iio: light: ltr501: Added ltr303 driver support")
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index 480523ca3750..6234e2eaec2e 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -16,6 +16,7 @@ properties:
   compatible:
     enum:
       - liteon,ltr301
+      - liteon,ltr303
       - liteon,ltr501
       - liteon,ltr559
 

-- 
2.55.0


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

* [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 1/7] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 2/7] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10  7:19   ` sashiko-bot
  2026-08-10 15:50   ` Rob Herring
  2026-08-10  7:11 ` [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron, Krzysztof Kozlowski

LTR-329ALS-01 is an ambient light sensor similar to LTR-303ALS-01, but
without interrupt support.

Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index 6234e2eaec2e..8c9d6cee55b4 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -17,6 +17,7 @@ properties:
     enum:
       - liteon,ltr301
       - liteon,ltr303
+      - liteon,ltr329
       - liteon,ltr501
       - liteon,ltr559
 

-- 
2.55.0


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

* [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
                   ` (2 preceding siblings ...)
  2026-08-10  7:11 ` [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10  7:23   ` sashiko-bot
  2026-08-10  7:11 ` [PATCH v4 5/7] iio: light: ltr501: Fix duplicated error message Esben Haabendal
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron, stable

In case devm_request_threaded_irq() failed, we were leaving the chip
powered instead of powering it down again. Power down the chip switching
ALS and PS modes to standby.

Fixes: 7ac702b3144b ("iio: ltr501: Add interrupt support")
Cc: stable@vger.kernel.org
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/iio/light/ltr501.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 7d045be78c6d..7746d374688f 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -1540,7 +1540,7 @@ static int ltr501_probe(struct i2c_client *client)
 		if (ret) {
 			dev_err(&client->dev, "request irq (%d) failed\n",
 				client->irq);
-			return ret;
+			goto powerdown_on_error;
 		}
 	} else {
 		indio_dev->info = data->chip_info->info_no_irq;

-- 
2.55.0


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

* [PATCH v4 5/7] iio: light: ltr501: Fix duplicated error message
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
                   ` (3 preceding siblings ...)
  2026-08-10  7:11 ` [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10  7:11 ` [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron, stable

The dev_err() message was causing duplicated error messages, as
devm_request_threaded_irq() calls dev_err_probe() on failure.

Fixes: 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()")
Cc: stable@vger.kernel.org
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/iio/light/ltr501.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 7746d374688f..b36bd10a0262 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -1537,11 +1537,8 @@ static int ltr501_probe(struct i2c_client *client)
 						IRQF_ONESHOT,
 						"ltr501_thresh_event",
 						indio_dev);
-		if (ret) {
-			dev_err(&client->dev, "request irq (%d) failed\n",
-				client->irq);
+		if (ret)
 			goto powerdown_on_error;
-		}
 	} else {
 		indio_dev->info = data->chip_info->info_no_irq;
 	}

-- 
2.55.0


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

* [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
                   ` (4 preceding siblings ...)
  2026-08-10  7:11 ` [PATCH v4 5/7] iio: light: ltr501: Fix duplicated error message Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10  7:24   ` sashiko-bot
  2026-08-10 19:57   ` Andy Shevchenko
  2026-08-10  7:11 ` [PATCH v4 7/7] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
  2026-08-10 19:59 ` [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Andy Shevchenko
  7 siblings, 2 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron

This adds support for the LTR-329ALS-01 chip, which is similar to
LTR-303ALS-01, except for interrupt, which LTR-329ALS-01 chip does not
have.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/iio/light/ltr501.c | 48 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index b36bd10a0262..cd5ff00ef5e2 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -9,6 +9,7 @@
  * TODO: IR LED characteristics
  */
 
+#include <linux/array_size.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/err.h>
@@ -94,6 +95,7 @@ enum {
 	ltr559,
 	ltr301,
 	ltr303,
+	ltr329,
 };
 
 struct ltr501_gain {
@@ -140,6 +142,7 @@ struct ltr501_chip_info {
 	u8 als_mode_active;
 	u8 als_gain_mask;
 	u8 als_gain_shift;
+	bool no_irq_support;
 	struct iio_chan_spec const *channels;
 	const int no_channels;
 	const struct iio_info *info;
@@ -178,6 +181,11 @@ static const struct ltr501_samp_table ltr501_ps_samp_table[] = {
 			{500000, 2000000}
 };
 
+static bool ltr501_has_irq_support(const struct ltr501_chip_info *info)
+{
+	return !info->no_irq_support;
+}
+
 static int ltr501_match_samp_freq(const struct ltr501_samp_table *tab,
 					   int len, int val, int val2)
 {
@@ -821,6 +829,9 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
 			if (ret < 0)
 				return ret;
 
+			if (!ltr501_has_irq_support(info))
+				return ret;
+
 			/* update persistence count when changing frequency */
 			ret = ltr501_write_intr_prst(data, chan->type,
 						     0, data->als_period);
@@ -840,6 +851,9 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
 			if (ret < 0)
 				return ret;
 
+			if (!ltr501_has_irq_support(info))
+				return ret;
+
 			/* update persistence count when changing frequency */
 			ret = ltr501_write_intr_prst(data, chan->type,
 						     0, data->ps_period);
@@ -1257,6 +1271,18 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
 		.channels = ltr301_channels,
 		.no_channels = ARRAY_SIZE(ltr301_channels),
 	},
+	[ltr329] = {
+		.partid = 0x0A,
+		.als_gain = ltr559_als_gain_tbl,
+		.als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+		.als_mode_active = BIT(0),
+		.als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+		.als_gain_shift = 2,
+		.no_irq_support = true,
+		.info_no_irq = &ltr301_info_no_irq,
+		.channels = ltr301_channels,
+		.no_channels = ARRAY_SIZE(ltr301_channels),
+	},
 };
 
 static int ltr501_write_contr(struct ltr501_data *data, u8 als_val, u8 ps_val)
@@ -1369,13 +1395,15 @@ static int ltr501_init(struct ltr501_data *data)
 
 	data->ps_contr = status | LTR501_CONTR_ACTIVE;
 
-	ret = ltr501_read_intr_prst(data, IIO_INTENSITY, &data->als_period);
-	if (ret < 0)
-		return ret;
+	if (ltr501_has_irq_support(data->chip_info)) {
+		ret = ltr501_read_intr_prst(data, IIO_INTENSITY, &data->als_period);
+		if (ret < 0)
+			return ret;
 
-	ret = ltr501_read_intr_prst(data, IIO_PROXIMITY, &data->ps_period);
-	if (ret < 0)
-		return ret;
+		ret = ltr501_read_intr_prst(data, IIO_PROXIMITY, &data->ps_period);
+		if (ret < 0)
+			return ret;
+	}
 
 	return ltr501_write_contr(data, data->als_contr, data->ps_contr);
 }
@@ -1531,6 +1559,12 @@ static int ltr501_probe(struct i2c_client *client)
 		return ret;
 
 	if (client->irq > 0) {
+		if (!ltr501_has_irq_support(data->chip_info)) {
+			ret = dev_err_probe(&client->dev, -EINVAL,
+					    "chip does not support irq\n");
+			goto powerdown_on_error;
+		}
+
 		ret = devm_request_threaded_irq(&client->dev, client->irq,
 						NULL, ltr501_interrupt_handler,
 						IRQF_TRIGGER_FALLING |
@@ -1601,6 +1635,7 @@ static const struct i2c_device_id ltr501_id[] = {
 	{ .name = "ltr559", .driver_data = ltr559 },
 	{ .name = "ltr301", .driver_data = ltr301 },
 	{ .name = "ltr303", .driver_data = ltr303 },
+	{ .name = "ltr329", .driver_data = ltr329 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, ltr501_id);
@@ -1610,6 +1645,7 @@ static const struct of_device_id ltr501_of_match[] = {
 	{ .compatible = "liteon,ltr559", },
 	{ .compatible = "liteon,ltr301", },
 	{ .compatible = "liteon,ltr303", },
+	{ .compatible = "liteon,ltr329", },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ltr501_of_match);

-- 
2.55.0


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

* [PATCH v4 7/7] iio: light: ltr501: Fix sorting order of device arrays
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
                   ` (5 preceding siblings ...)
  2026-08-10  7:11 ` [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
@ 2026-08-10  7:11 ` Esben Haabendal
  2026-08-10 19:59 ` [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Andy Shevchenko
  7 siblings, 0 replies; 14+ messages in thread
From: Esben Haabendal @ 2026-08-10  7:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
	Jonathan Cameron

Using alphanumerical sort order for these should help reduce merge
conflicts.

The 0 assignment to the first entry is not needed, as the first entry will
always be 0. The main thing is to keep the values here in sync with the
elements in ltr501_chip_info_tbl[].

Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/iio/light/ltr501.c | 68 +++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index cd5ff00ef5e2..c438b5818160 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -91,11 +91,11 @@ struct ltr501_samp_table {
 #define LTR501_RESERVED_GAIN -1
 
 enum {
-	ltr501 = 0,
-	ltr559,
 	ltr301,
 	ltr303,
 	ltr329,
+	ltr501,
+	ltr559,
 };
 
 struct ltr501_gain {
@@ -1219,34 +1219,6 @@ static const struct iio_info ltr301_info = {
 };
 
 static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
-	[ltr501] = {
-		.partid = 0x08,
-		.als_gain = ltr501_als_gain_tbl,
-		.als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
-		.ps_gain = ltr501_ps_gain_tbl,
-		.ps_gain_tbl_size = ARRAY_SIZE(ltr501_ps_gain_tbl),
-		.als_mode_active = BIT(0) | BIT(1),
-		.als_gain_mask = BIT(3),
-		.als_gain_shift = 3,
-		.info = &ltr501_info,
-		.info_no_irq = &ltr501_info_no_irq,
-		.channels = ltr501_channels,
-		.no_channels = ARRAY_SIZE(ltr501_channels),
-	},
-	[ltr559] = {
-		.partid = 0x09,
-		.als_gain = ltr559_als_gain_tbl,
-		.als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
-		.ps_gain = ltr559_ps_gain_tbl,
-		.ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
-		.als_mode_active = BIT(0),
-		.als_gain_mask = BIT(2) | BIT(3) | BIT(4),
-		.als_gain_shift = 2,
-		.info = &ltr501_info,
-		.info_no_irq = &ltr501_info_no_irq,
-		.channels = ltr501_channels,
-		.no_channels = ARRAY_SIZE(ltr501_channels),
-	},
 	[ltr301] = {
 		.partid = 0x08,
 		.als_gain = ltr501_als_gain_tbl,
@@ -1283,6 +1255,34 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
 		.channels = ltr301_channels,
 		.no_channels = ARRAY_SIZE(ltr301_channels),
 	},
+	[ltr501] = {
+		.partid = 0x08,
+		.als_gain = ltr501_als_gain_tbl,
+		.als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
+		.ps_gain = ltr501_ps_gain_tbl,
+		.ps_gain_tbl_size = ARRAY_SIZE(ltr501_ps_gain_tbl),
+		.als_mode_active = BIT(0) | BIT(1),
+		.als_gain_mask = BIT(3),
+		.als_gain_shift = 3,
+		.info = &ltr501_info,
+		.info_no_irq = &ltr501_info_no_irq,
+		.channels = ltr501_channels,
+		.no_channels = ARRAY_SIZE(ltr501_channels),
+	},
+	[ltr559] = {
+		.partid = 0x09,
+		.als_gain = ltr559_als_gain_tbl,
+		.als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+		.ps_gain = ltr559_ps_gain_tbl,
+		.ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
+		.als_mode_active = BIT(0),
+		.als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+		.als_gain_shift = 2,
+		.info = &ltr501_info,
+		.info_no_irq = &ltr501_info_no_irq,
+		.channels = ltr501_channels,
+		.no_channels = ARRAY_SIZE(ltr501_channels),
+	},
 };
 
 static int ltr501_write_contr(struct ltr501_data *data, u8 als_val, u8 ps_val)
@@ -1631,21 +1631,21 @@ static const struct acpi_device_id ltr_acpi_match[] = {
 MODULE_DEVICE_TABLE(acpi, ltr_acpi_match);
 
 static const struct i2c_device_id ltr501_id[] = {
-	{ .name = "ltr501", .driver_data = ltr501 },
-	{ .name = "ltr559", .driver_data = ltr559 },
 	{ .name = "ltr301", .driver_data = ltr301 },
 	{ .name = "ltr303", .driver_data = ltr303 },
 	{ .name = "ltr329", .driver_data = ltr329 },
+	{ .name = "ltr501", .driver_data = ltr501 },
+	{ .name = "ltr559", .driver_data = ltr559 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, ltr501_id);
 
 static const struct of_device_id ltr501_of_match[] = {
-	{ .compatible = "liteon,ltr501", },
-	{ .compatible = "liteon,ltr559", },
 	{ .compatible = "liteon,ltr301", },
 	{ .compatible = "liteon,ltr303", },
 	{ .compatible = "liteon,ltr329", },
+	{ .compatible = "liteon,ltr501", },
+	{ .compatible = "liteon,ltr559", },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ltr501_of_match);

-- 
2.55.0


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

* Re: [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible
  2026-08-10  7:11 ` [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
@ 2026-08-10  7:19   ` sashiko-bot
  2026-08-10 15:50   ` Rob Herring
  1 sibling, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-08-10  7:19 UTC (permalink / raw)
  To: Esben Haabendal; +Cc: robh, conor+dt, devicetree

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The schema allows the `interrupts` and `proximity-near-level` properties for `liteon,ltr329`, despite the hardware lacking support for both.
--

--- Patch [3]: [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible ---
commit 886ebb6ac5c09271398d18cea2c0a6d6d1bb9043
Author: Esben Haabendal <esben@geanix.com>

dt-bindings: iio: light: ltr501: Add ltr329 compatible

This commit adds a new compatible string for the LTR-329ALS-01 ambient
light sensor. The commit message notes that it is similar to LTR-303ALS-01
but without interrupt support.

> diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
> index 6234e2eaec2e4..8c9d6cee55b49 100644
> --- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
> +++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
> @@ -17,6 +17,7 @@ properties:
>      enum:
>        - liteon,ltr301
>        - liteon,ltr303
> +      - liteon,ltr329

[Severity: Medium]
Since the commit message explicitly states that the LTR-329ALS-01 does not
have interrupt support, should the schema actively disallow the interrupts
property for this specific compatible string?

Currently, because interrupts and proximity-near-level are defined globally
in this schema, validation will silently pass if a device tree node for
liteon,ltr329 incorrectly includes them.

Could an allOf rule be added to restrict these unsupported properties?

  allOf:
    - if:
        properties:
          compatible:
            contains:
              const: liteon,ltr329
      then:
        properties:
          interrupts: false
          proximity-near-level: false

>        - liteon,ltr501
>        - liteon,ltr559

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260810-liteon-ltr329-v4-0-8bd3dfd15280@geanix.com?part=3

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

* Re: [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails
  2026-08-10  7:11 ` [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
@ 2026-08-10  7:23   ` sashiko-bot
  0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-08-10  7:23 UTC (permalink / raw)
  To: Esben Haabendal; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Race condition leading to a Use-After-Free in the IRQ handler if `iio_device_register()` fails during probe.
- [High] Incorrect integer sizes passed to `regmap_bulk_read` and `regmap_bulk_write` cause uninitialized memory reads and incorrect hardware writes on big-endian architectures.
- [Medium] If `ltr501_init()` fails partially while writing the control registers, the ALS sensor is left powered on when probe fails.
--

--- Patch [4]: [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails ---
commit a19bda31a7e1d7988ac494947d945670f4024b2a
Author: Esben Haabendal <esben@geanix.com>

iio: light: ltr501: Power down chip if request irq fails

In case devm_request_threaded_irq() failed, we were leaving the chip
powered instead of powering it down again. Power down the chip switching
ALS and PS modes to standby.

> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 7d045be78c6df..7746d374688fa 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
> @@ -1540,7 +1540,7 @@ static int ltr501_probe(struct i2c_client *client)

[Severity: Medium]
This is a pre-existing issue, but does ltr501_probe() leak power if
ltr501_init() fails partially?

If the first I2C write in ltr501_init()->ltr501_write_contr() succeeds but
the second fails, ltr501_init() returns an error with the ALS sensor
powered on:

drivers/iio/light/ltr501.c:ltr501_probe() {
	...
	ret = ltr501_init(data);
	if (ret < 0)
		return ret;
	...
}

This returns directly instead of taking the powerdown_on_error path,
leaving the ALS sensor active.

[Severity: High]
This is also a pre-existing issue, but does using
devm_request_threaded_irq() here create a race condition if
iio_device_register() fails later in probe?

Since the IRQ is managed by devres, it remains active until ltr501_probe()
returns and devres cleans it up.

If iio_device_register() fails, its error path calls
iio_device_unregister_eventset(), which frees the event interface:

drivers/iio/industrialio-event.c:iio_device_unregister_eventset() {
	...
	kfree(ev_int);
	iio_dev_opaque->event_interface = NULL;
	...
}

If a concurrent hardware interrupt fires before devres disables the IRQ,
ltr501_interrupt_handler() will call iio_push_event(), which dereferences
the freed pointer:

drivers/iio/industrialio-event.c:iio_push_event() {
	struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;

	if (!ev_int)
		return 0;
	...
}

>  		if (ret) {
>  			dev_err(&client->dev, "request irq (%d) failed\n",
>  				client->irq);
> -			return ret;
> +			goto powerdown_on_error;
>  		}
>  	} else {
>  		indio_dev->info = data->chip_info->info_no_irq;

[Severity: High]
This is another pre-existing issue, but do the regmap_bulk_read() and
regmap_bulk_write() calls in this driver handle endianness correctly?

In functions like ltr501_read_thresh(), ltr501_trigger_handler(), and
ltr501_write_thresh(), 32-bit integer variables are passed by reference
with a 2-byte length:

drivers/iio/light/ltr501.c:ltr501_read_thresh() {
	...
	int thresh_data;
	...
			ret = regmap_bulk_read(data->regmap,
					       LTR501_ALS_THRESH_UP,
					       &thresh_data, 2);
	...
}

On big-endian architectures, this targets the most significant bytes,
leaving the lower bytes uninitialized.

When masked and returned, it yields stack garbage.

During writes, the upper bytes (which are 0) are sent to the sensor,
meaning 0x0000 is always written.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260810-liteon-ltr329-v4-0-8bd3dfd15280@geanix.com?part=4

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

* Re: [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support
  2026-08-10  7:11 ` [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
@ 2026-08-10  7:24   ` sashiko-bot
  2026-08-10 19:57   ` Andy Shevchenko
  1 sibling, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-08-10  7:24 UTC (permalink / raw)
  To: Esben Haabendal; +Cc: conor+dt, devicetree, robh

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Uninitialized kernel stack memory leak and functional corruption on big-endian systems due to regmap_bulk_read/write type mismatch.
--

--- Patch [6]: [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support ---
commit 1db9cef73562002d6e7e4eeeed1f2b197809ecbf
Author: Esben Haabendal <esben@geanix.com>

iio: light: ltr501: Add ltr329 driver support

This adds support for the LTR-329ALS-01 chip, which is similar to the
LTR-303ALS-01, except it does not have interrupt support.

> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index b36bd10a02624..cd5ff00ef5e26 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c

[ ... ]

> @@ -1257,6 +1271,18 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
>  		.channels = ltr301_channels,
>  		.no_channels = ARRAY_SIZE(ltr301_channels),
>  	},
> +	[ltr329] = {
> +		.partid = 0x0A,
> +		.als_gain = ltr559_als_gain_tbl,
> +		.als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
> +		.als_mode_active = BIT(0),
> +		.als_gain_mask = BIT(2) | BIT(3) | BIT(4),
> +		.als_gain_shift = 2,
> +		.no_irq_support = true,
> +		.info_no_irq = &ltr301_info_no_irq,
> +		.channels = ltr301_channels,
> +		.no_channels = ARRAY_SIZE(ltr301_channels),
> +	},
>  };

[Severity: High]
This is a pre-existing issue, but will this new ltr329 chip also be affected
by the big-endian stack leak in the driver's bulk read and write operations?

Looking at ltr501_trigger_handler() (and similarly in ltr501_read_thresh()
and ltr501_write_thresh()), the code uses regmap_bulk_read and 
regmap_bulk_write to read or write 2 bytes into a 4-byte integer variable:

drivers/iio/light/ltr501.c:ltr501_trigger_handler() {
    ...
    int psdata;
    ...
    ret = regmap_bulk_read(data->regmap, LTR501_PS_DATA, &psdata, 2);
    ...
    scan.channels[j++] = psdata & LTR501_PS_DATA_MASK;
    ...
}

On big-endian systems, wouldn't reading 2 bytes into the address of psdata
only populate the upper half of the 32-bit integer, leaving the lower half
uninitialized? 

Since the lower half contains uninitialized kernel stack memory,
doesn't masking and storing this in the IIO scan buffer leak stack memory to
userspace?

Similarly, wouldn't ltr501_write_thresh() corrupt the threshold configuration
by writing 2 bytes from the lowest address of val (which are 0x00 on
big-endian)?

Could we fix this driver-wide issue by using 16-bit variables (like __le16)
for these 2-byte regmap_bulk_read and regmap_bulk_write operations?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260810-liteon-ltr329-v4-0-8bd3dfd15280@geanix.com?part=6

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

* Re: [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible
  2026-08-10  7:11 ` [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
  2026-08-10  7:19   ` sashiko-bot
@ 2026-08-10 15:50   ` Rob Herring
  1 sibling, 0 replies; 14+ messages in thread
From: Rob Herring @ 2026-08-10 15:50 UTC (permalink / raw)
  To: Esben Haabendal
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Krzysztof Kozlowski, Conor Dooley, Nikita Travkin, Maslov Dmitry,
	Kuppuswamy Sathyanarayanan, Thomas Gleixner, Pan Chuang,
	Yangtao Li, linux-iio, devicetree, linux-kernel,
	Krzysztof Kozlowski

On Mon, Aug 10, 2026 at 09:11:13AM +0200, Esben Haabendal wrote:
> LTR-329ALS-01 is an ambient light sensor similar to LTR-303ALS-01, but
> without interrupt support.
> 
> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> Signed-off-by: Esben Haabendal <esben@geanix.com>
> ---
>  Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 +
>  1 file changed, 1 insertion(+)

sashiko issue should be addressed.

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

* Re: [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support
  2026-08-10  7:11 ` [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
  2026-08-10  7:24   ` sashiko-bot
@ 2026-08-10 19:57   ` Andy Shevchenko
  1 sibling, 0 replies; 14+ messages in thread
From: Andy Shevchenko @ 2026-08-10 19:57 UTC (permalink / raw)
  To: Esben Haabendal
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li, linux-iio, devicetree, linux-kernel

On Mon, Aug 10, 2026 at 09:11:16AM +0200, Esben Haabendal wrote:
> This adds support for the LTR-329ALS-01 chip, which is similar to
> LTR-303ALS-01, except for interrupt, which LTR-329ALS-01 chip does not
> have.

...

> static int ltr501_probe(struct i2c_client *client)

>  	if (client->irq > 0) {
> +		if (!ltr501_has_irq_support(data->chip_info)) {
> +			ret = dev_err_probe(&client->dev, -EINVAL,
> +					    "chip does not support irq\n");
> +			goto powerdown_on_error;
> +		}

Why making it fatal? Perhaps

	if (!ltr501_has_irq_support(data->chip_info) && client->irq > 0) {
		client->irq = 0;
		dev_warn(chip doesn't support IRQ);
	}


-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support
  2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
                   ` (6 preceding siblings ...)
  2026-08-10  7:11 ` [PATCH v4 7/7] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
@ 2026-08-10 19:59 ` Andy Shevchenko
  7 siblings, 0 replies; 14+ messages in thread
From: Andy Shevchenko @ 2026-08-10 19:59 UTC (permalink / raw)
  To: Esben Haabendal
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
	Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
	Pan Chuang, Yangtao Li, linux-iio, devicetree, linux-kernel,
	Krzysztof Kozlowski, stable

On Mon, Aug 10, 2026 at 09:11:10AM +0200, Esben Haabendal wrote:
> The LiteON LTR-329ALS-01 chip is similar to the LTR-303ALS-01, except for
> interrupt support and related registers, which LTR-329ALS-01 does not have.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
for patches 4, 5, and 7.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-08-10 19:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10  7:11 [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Esben Haabendal
2026-08-10  7:11 ` [PATCH v4 1/7] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
2026-08-10  7:11 ` [PATCH v4 2/7] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible Esben Haabendal
2026-08-10  7:11 ` [PATCH v4 3/7] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
2026-08-10  7:19   ` sashiko-bot
2026-08-10 15:50   ` Rob Herring
2026-08-10  7:11 ` [PATCH v4 4/7] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
2026-08-10  7:23   ` sashiko-bot
2026-08-10  7:11 ` [PATCH v4 5/7] iio: light: ltr501: Fix duplicated error message Esben Haabendal
2026-08-10  7:11 ` [PATCH v4 6/7] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
2026-08-10  7:24   ` sashiko-bot
2026-08-10 19:57   ` Andy Shevchenko
2026-08-10  7:11 ` [PATCH v4 7/7] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
2026-08-10 19:59 ` [PATCH v4 0/7] iio: light: ltr501: Add ltr329 support Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.