Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support
@ 2026-12-04 15:15 Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 1/4] leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels Peter LaDow via B4 Relay
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Peter LaDow via B4 Relay @ 2026-12-04 15:15 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Steffen Trumtrar, Nam Tran,
	Steffen Trumtrar
  Cc: Peter LaDow, linux-leds, devicetree, linux-kernel

This series adds I2C bus support for the Texas Instruments LP5860 RGB
LED matrix driver, documents the I2C Device Tree binding, and
consolidates common bus initialization logic into the core driver.

Signed-off-by: Peter LaDow <pladow@gmail.com>
---
Changes in v6:
- Call dev_err_probe() before fwnode_handle_put(led_node) in
  lp5860_iterate_subleds() to avoid a use-after-put when formatting
  %pfwP (1/4).
- Revert SPI example in leds-lp5860.yaml.
- Link to v5: https://patch.msgid.link/20261204-add-i2c-support-for-lp5860-v5-0-4cba58fe3c5b@gmail.com

Changes in v5:
- Split out off-by-one LED channel and dot bounds-check fixes into a
  standalone patch (1/4), and return -EINVAL instead of 0 when 'reg'
  exceeds LP5860_MAX_LED in lp5860_iterate_subleds().
- Remove redundant spi_setup() call in lp5860_probe() in the SPI probe
  consolidation patch (3/4).
- Link to v4: https://patch.msgid.link/20261203-add-i2c-support-for-lp5860-v4-0-dd84962336b1@gmail.com

Changes in v4:
- Add a dt-bindings patch documenting the LP5860 I2C 7-bit page-zero
  base address convention (0x40, 0x44, 0x48, or 0x4c) and adding an
  I2C example node to leds-lp5860.yaml.
- Consolidate common child-node validation, struct lp5860 allocation,
  mutex setup, and driver data assignment into lp5860_device_init().
- Simplify leds-lp5860-i2c to delegate common device initialization to
  lp5860_device_init(dev, regmap).

Changes in v3:
- Replace magic numbers with named defines for page shift, masks, and counts
- Drop struct lp5860_i2c wrapper and allocate struct i2c_client array directly
- Guard page index bounds explicitly in reg_read and reg_write callbacks
- Remove raw hex slave addresses from the probe error message
- Declare loop variable inline and document dummy client page addressing
- Link to v2: https://lore.kernel.org/r/20261120-add-i2c-support-for-lp5860-v2-1-bcb2ce00a7f5@gmail.com

Changes in v2:
- Use designated initializer (.name = "lp5860") in i2c_device_id table
- Link to v1: https://patch.msgid.link/20261120-add-i2c-support-for-lp5860-v1-1-30bc97dcbf78@gmail.com

To: Lee Jones <lee@kernel.org>
To: Pavel Machek <pavel@kernel.org>
To: Griffin Kroah-Hartman <griffin@kroah.com>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Steffen Trumtrar <kernel@pengutronix.de>
To: Nam Tran <trannamatk@gmail.com>
To: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: linux-leds@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

---
Peter LaDow (4):
      leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels
      dt-bindings: leds: ti,lp5860: Document I2C interface
      leds: rgb: lp5860: Consolidate common probe setup in lp5860_device_init()
      leds: rgb: lp5860: Add I2C interface support

 .../devicetree/bindings/leds/leds-lp5860.yaml      |  44 ++++++++
 drivers/leds/rgb/Kconfig                           |  12 ++
 drivers/leds/rgb/Makefile                          |   1 +
 drivers/leds/rgb/leds-lp5860-core.c                |  43 +++++++-
 drivers/leds/rgb/leds-lp5860-i2c.c                 | 121 +++++++++++++++++++++
 drivers/leds/rgb/leds-lp5860-spi.c                 |  40 +------
 drivers/leds/rgb/leds-lp5860.h                     |   2 +-
 7 files changed, 222 insertions(+), 41 deletions(-)
---
base-commit: 6881bcee6db3a7a3f9ff2b5ff01a1b43ee97bc83
change-id: 20261120-add-i2c-support-for-lp5860-97f38b2ebe1c

Best regards,
--  
Peter LaDow <pladow@gmail.com>



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

* [PATCH v6 1/4] leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels
  2026-12-04 15:15 [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support Peter LaDow via B4 Relay
@ 2026-12-04 15:15 ` Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 2/4] dt-bindings: leds: ti,lp5860: Document I2C interface Peter LaDow via B4 Relay
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Peter LaDow via B4 Relay @ 2026-12-04 15:15 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Steffen Trumtrar, Nam Tran,
	Steffen Trumtrar
  Cc: Peter LaDow, linux-leds, devicetree, linux-kernel

From: Peter LaDow <pladow@gmail.com>

Valid LP5860 dot indices and LED channel numbers are 0-indexed up to
LP5860_MAX_LED - 1 (197). Using '>' instead of '>=' allows an
out-of-bounds value equal to LP5860_MAX_LED to pass validation.

Additionally, in lp5860_iterate_subleds(), when fwnode_property_read_u32()
succeeds with an out-of-range channel, 'ret' is 0, causing the error
path to log and return 0 (success) while leaving the subled entry
uninitialized.

Change both bounds checks to '>=' and separate the out-of-range channel
check so it logs and returns -EINVAL.

Fixes: f0a66563aa2d ("leds: Add support for TI LP5860 LED driver chip")
Signed-off-by: Peter LaDow <pladow@gmail.com>
---
 drivers/leds/rgb/leds-lp5860-core.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index e21d5f2302be..e64bef73b843 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -24,7 +24,7 @@ static int lp5860_set_dot_onoff(struct lp5860_led *led, unsigned int dot, bool e
 	unsigned int offset = dot / LP5860_MAX_DOT_ONOFF_GROUP_NUM;
 	unsigned int mask = BIT(dot % LP5860_MAX_DOT_ONOFF_GROUP_NUM);
 
-	if (dot > LP5860_MAX_LED)
+	if (dot >= LP5860_MAX_LED)
 		return -EINVAL;
 
 	return regmap_update_bits(led->chip->regmap,
@@ -114,9 +114,18 @@ static int lp5860_iterate_subleds(struct lp5860_led *led, struct led_init_data *
 		}
 
 		ret = fwnode_property_read_u32(led_node, "reg", &channel);
-		if (ret < 0 || channel > LP5860_MAX_LED) {
-			dev_err_probe(led->chip->dev, ret,
-				      "%pfwP: 'reg' property is missing. Skipping.\n", led_node);
+		if (ret < 0) {
+			ret = dev_err_probe(led->chip->dev, ret,
+					     "%pfwP: 'reg' property is missing. Skipping.\n",
+					     led_node);
+			fwnode_handle_put(led_node);
+			return ret;
+		}
+
+		if (channel >= LP5860_MAX_LED) {
+			ret = dev_err_probe(led->chip->dev, -EINVAL,
+					     "%pfwP: invalid 'reg' channel %u\n",
+					     led_node, channel);
 			fwnode_handle_put(led_node);
 			return ret;
 		}

-- 
2.43.0



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

* [PATCH v6 2/4] dt-bindings: leds: ti,lp5860: Document I2C interface
  2026-12-04 15:15 [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 1/4] leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels Peter LaDow via B4 Relay
@ 2026-12-04 15:15 ` Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 3/4] leds: rgb: lp5860: Consolidate common probe setup in lp5860_device_init() Peter LaDow via B4 Relay
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Peter LaDow via B4 Relay @ 2026-12-04 15:15 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Steffen Trumtrar, Nam Tran,
	Steffen Trumtrar
  Cc: Peter LaDow, linux-leds, devicetree, linux-kernel

From: Peter LaDow <pladow@gmail.com>

Document the I2C 7-bit page-zero base address convention (0x40, 0x44,
0x48, or 0x4c) and add an I2C example node to the TI LP5860 binding.

Signed-off-by: Peter LaDow <pladow@gmail.com>
---
 .../devicetree/bindings/leds/leds-lp5860.yaml      | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/Documentation/devicetree/bindings/leds/leds-lp5860.yaml b/Documentation/devicetree/bindings/leds/leds-lp5860.yaml
index 710fec3738ed..a7bc59304a44 100644
--- a/Documentation/devicetree/bindings/leds/leds-lp5860.yaml
+++ b/Documentation/devicetree/bindings/leds/leds-lp5860.yaml
@@ -26,6 +26,11 @@ properties:
 
   reg:
     maxItems: 1
+    description: |
+      For SPI, the chip select number.
+      For I2C, the 7-bit page-zero base address (0x40, 0x44, 0x48, or 0x4c)
+      selected by ADDR1 and ADDR0. The device consumes four consecutive 7-bit
+      addresses (base through base + 3) to access its 10-bit register space.
 
   '#address-cells':
     const: 1
@@ -116,3 +121,42 @@ examples:
             };
         };
     };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/leds/common.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led-controller@40 {
+            compatible = "ti,lp5860";
+            reg = <0x40>;
+            enable-gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            multi-led@0 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x0>;
+                color = <LED_COLOR_ID_RGB>;
+
+                led@0 {
+                    reg = <0x0>;
+                    color = <LED_COLOR_ID_RED>;
+                };
+
+                led@1 {
+                    reg = <0x1>;
+                    color = <LED_COLOR_ID_GREEN>;
+                };
+
+                led@2 {
+                    reg = <0x2>;
+                    color = <LED_COLOR_ID_BLUE>;
+                };
+            };
+        };
+    };

-- 
2.43.0



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

* [PATCH v6 3/4] leds: rgb: lp5860: Consolidate common probe setup in lp5860_device_init()
  2026-12-04 15:15 [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 1/4] leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 2/4] dt-bindings: leds: ti,lp5860: Document I2C interface Peter LaDow via B4 Relay
@ 2026-12-04 15:15 ` Peter LaDow via B4 Relay
  2026-12-04 15:15 ` [PATCH v6 4/4] leds: rgb: lp5860: Add I2C interface support Peter LaDow via B4 Relay
  2026-12-04 15:30 ` [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support sashiko-bot
  4 siblings, 0 replies; 6+ messages in thread
From: Peter LaDow via B4 Relay @ 2026-12-04 15:15 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Steffen Trumtrar, Nam Tran,
	Steffen Trumtrar
  Cc: Peter LaDow, linux-leds, devicetree, linux-kernel

From: Peter LaDow <pladow@gmail.com>

Pass the initialized struct regmap pointer into lp5860_device_init() and
move child-node validation, struct lp5860 allocation, mutex setup, and
driver data assignment into the core initialization helper.

This avoids duplicating common probe boilerplate across bus front-ends in
preparation for adding I2C interface support.

Tested on ZynqMP (ZU3) via the I2C bus front-end; SPI changes were
compile-tested only.

Signed-off-by: Peter LaDow <pladow@gmail.com>
---
 drivers/leds/rgb/leds-lp5860-core.c | 26 ++++++++++++++++++++++--
 drivers/leds/rgb/leds-lp5860-spi.c  | 40 ++++++-------------------------------
 drivers/leds/rgb/leds-lp5860.h      |  2 +-
 3 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index e64bef73b843..f46a4dcde945 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/of_platform.h>
+#include <linux/overflow.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
 
@@ -197,11 +198,32 @@ static int lp5860_init_dt(struct lp5860 *lp)
 	return 0;
 }
 
-int lp5860_device_init(struct device *dev)
+int lp5860_device_init(struct device *dev, struct regmap *regmap)
 {
-	struct lp5860 *lp = dev_get_drvdata(dev);
+	struct lp5860 *lp;
+	unsigned int multi_leds;
 	int ret;
 
+	multi_leds = device_get_child_node_count(dev);
+	if (!multi_leds)
+		return dev_err_probe(dev, -ENODEV, "LEDs are not defined in Device Tree!\n");
+
+	if (multi_leds > LP5860_MAX_LED)
+		return dev_err_probe(dev, -EINVAL, "Too many LEDs specified.\n");
+
+	lp = devm_kzalloc(dev, struct_size(lp, leds, multi_leds), GFP_KERNEL);
+	if (!lp)
+		return -ENOMEM;
+
+	lp->dev = dev;
+	lp->regmap = regmap;
+
+	ret = devm_mutex_init(dev, &lp->lock);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(dev, lp);
+
 	ret = lp5860_chip_enable(lp, LP5860_CHIP_ENABLE);
 	if (ret)
 		return ret;
diff --git a/drivers/leds/rgb/leds-lp5860-spi.c b/drivers/leds/rgb/leds-lp5860-spi.c
index 6bf6a625c28a..1d9657da7958 100644
--- a/drivers/leds/rgb/leds-lp5860-spi.c
+++ b/drivers/leds/rgb/leds-lp5860-spi.c
@@ -7,9 +7,7 @@
 
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/mutex.h>
 #include <linux/of.h>
-#include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
 
@@ -36,40 +34,14 @@ static const struct regmap_config lp5860_regmap_config = {
 static int lp5860_probe(struct spi_device *spi)
 {
 	struct device *dev = &spi->dev;
-	struct lp5860 *lp5860;
-	unsigned int multi_leds;
-	int ret;
+	struct regmap *regmap;
 
-	multi_leds = device_get_child_node_count(dev);
-	if (!multi_leds) {
-		dev_err(dev, "LEDs are not defined in Device Tree!");
-		return -ENODEV;
-	}
+	regmap = devm_regmap_init_spi(spi, &lp5860_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap),
+				     "Failed to initialize regmap.\n");
 
-	if (multi_leds > LP5860_MAX_LED) {
-		dev_err(dev, "Too many LEDs specified.\n");
-		return -EINVAL;
-	}
-
-	lp5860 = devm_kzalloc(dev, struct_size(lp5860, leds, multi_leds),
-			      GFP_KERNEL);
-	if (!lp5860)
-		return -ENOMEM;
-
-	lp5860->regmap = devm_regmap_init_spi(spi, &lp5860_regmap_config);
-	if (IS_ERR(lp5860->regmap))
-		return dev_err_probe(&spi->dev, PTR_ERR(lp5860->regmap),
-				     "Failed to initialise Regmap.\n");
-
-	lp5860->dev = dev;
-
-	ret = devm_mutex_init(dev, &lp5860->lock);
-	if (ret)
-		return ret;
-
-	spi_set_drvdata(spi, lp5860);
-
-	return lp5860_device_init(dev);
+	return lp5860_device_init(dev, regmap);
 }
 
 static void lp5860_remove(struct spi_device *spi)
diff --git a/drivers/leds/rgb/leds-lp5860.h b/drivers/leds/rgb/leds-lp5860.h
index 940be0c6e8da..85f6a4d0f167 100644
--- a/drivers/leds/rgb/leds-lp5860.h
+++ b/drivers/leds/rgb/leds-lp5860.h
@@ -262,7 +262,7 @@ struct lp5860 {
 	DECLARE_FLEX_ARRAY(struct lp5860_led, leds);
 };
 
-int lp5860_device_init(struct device *dev);
+int lp5860_device_init(struct device *dev, struct regmap *regmap);
 void lp5860_device_remove(struct device *dev);
 
 #endif /* _DRIVERS_LEDS_RGB_LP5860_H */

-- 
2.43.0



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

* [PATCH v6 4/4] leds: rgb: lp5860: Add I2C interface support
  2026-12-04 15:15 [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support Peter LaDow via B4 Relay
                   ` (2 preceding siblings ...)
  2026-12-04 15:15 ` [PATCH v6 3/4] leds: rgb: lp5860: Consolidate common probe setup in lp5860_device_init() Peter LaDow via B4 Relay
@ 2026-12-04 15:15 ` Peter LaDow via B4 Relay
  2026-12-04 15:30 ` [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support sashiko-bot
  4 siblings, 0 replies; 6+ messages in thread
From: Peter LaDow via B4 Relay @ 2026-12-04 15:15 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Steffen Trumtrar, Nam Tran,
	Steffen Trumtrar
  Cc: Peter LaDow, linux-leds, devicetree, linux-kernel

From: Peter LaDow <pladow@gmail.com>

The Texas Instruments LP5860 RGB LED matrix driver supports both SPI and
I2C communication buses depending on the IFS pin state, but the
existing driver only implements the SPI bus interface.

Add an I2C bus front-end driver (leds-lp5860-i2c) that reserves the
four consecutive 7-bit I2C addresses used by the LP5860 to map its
10-bit register space across dummy I2C clients, initializes a custom
regmap, and delegates device setup to lp5860_device_init(). Update
Kconfig and Makefile so I2C and SPI support can be built independently
or together.

Tested on ZynqMP (ZU3) with an LP5860 connected over an AXI IIC at
base address 0x40 (A1=0, A0=0) at 400 kHz.

Signed-off-by: Peter LaDow <pladow@gmail.com>
---
 drivers/leds/rgb/Kconfig           |  12 ++++
 drivers/leds/rgb/Makefile          |   1 +
 drivers/leds/rgb/leds-lp5860-i2c.c | 121 +++++++++++++++++++++++++++++++++++++
 3 files changed, 134 insertions(+)

diff --git a/drivers/leds/rgb/Kconfig b/drivers/leds/rgb/Kconfig
index c27d7ed516ac..ea86c27e3cd9 100644
--- a/drivers/leds/rgb/Kconfig
+++ b/drivers/leds/rgb/Kconfig
@@ -79,6 +79,18 @@ config LEDS_LP5860_SPI
 	  To compile this driver as a module, choose M here: the
 	  module will be called leds-lp5860-spi.
 
+config LEDS_LP5860_I2C
+	tristate "LED Support for TI LP5860 I2C LED driver chip"
+	depends on I2C
+	depends on OF
+	select LEDS_LP5860_CORE
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  LP5860 LED driver for I2C bus connections.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-lp5860-i2c.
+
 config LEDS_NCP5623
 	tristate "LED support for NCP5623"
 	depends on I2C
diff --git a/drivers/leds/rgb/Makefile b/drivers/leds/rgb/Makefile
index a59c13396a22..0e35bf16d615 100644
--- a/drivers/leds/rgb/Makefile
+++ b/drivers/leds/rgb/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_LEDS_KTD202X)		+= leds-ktd202x.o
 obj-$(CONFIG_LEDS_LP5812)		+= leds-lp5812.o
 obj-$(CONFIG_LEDS_LP5860_CORE)		+= leds-lp5860-core.o
 obj-$(CONFIG_LEDS_LP5860_SPI)		+= leds-lp5860-spi.o
+obj-$(CONFIG_LEDS_LP5860_I2C)		+= leds-lp5860-i2c.o
 obj-$(CONFIG_LEDS_NCP5623)		+= leds-ncp5623.o
 obj-$(CONFIG_LEDS_PWM_MULTICOLOR)	+= leds-pwm-multicolor.o
 obj-$(CONFIG_LEDS_QCOM_LPG)		+= leds-qcom-lpg.o
diff --git a/drivers/leds/rgb/leds-lp5860-i2c.c b/drivers/leds/rgb/leds-lp5860-i2c.c
new file mode 100644
index 000000000000..adb61201cfb0
--- /dev/null
+++ b/drivers/leds/rgb/leds-lp5860-i2c.c
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+
+#include "leds-lp5860.h"
+
+#define LP5860_I2C_NUM_PAGES	4
+#define LP5860_I2C_PAGE_SHIFT	8
+#define LP5860_I2C_PAGE_MASK	0x03
+#define LP5860_I2C_REG_MASK	0xff
+
+static int lp5860_i2c_reg_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct i2c_client **clients = context;
+	unsigned int page = reg >> LP5860_I2C_PAGE_SHIFT;
+	int ret;
+
+	if (page >= LP5860_I2C_NUM_PAGES)
+		return -EINVAL;
+
+	ret = i2c_smbus_read_byte_data(clients[page], reg & LP5860_I2C_REG_MASK);
+	if (ret < 0)
+		return ret;
+
+	*val = ret;
+	return 0;
+}
+
+static int lp5860_i2c_reg_write(void *context, unsigned int reg, unsigned int val)
+{
+	struct i2c_client **clients = context;
+	unsigned int page = reg >> LP5860_I2C_PAGE_SHIFT;
+
+	if (page >= LP5860_I2C_NUM_PAGES)
+		return -EINVAL;
+
+	return i2c_smbus_write_byte_data(clients[page], reg & LP5860_I2C_REG_MASK, val);
+}
+
+static const struct regmap_config lp5860_i2c_regmap_config = {
+	.name = "lp5860",
+	.reg_bits = 10,
+	.val_bits = 8,
+	.max_register = LP5860_MAX_REG,
+	.reg_read = lp5860_i2c_reg_read,
+	.reg_write = lp5860_i2c_reg_write,
+};
+
+static int lp5860_i2c_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct i2c_client **clients;
+	struct regmap *regmap;
+
+	if ((client->flags & I2C_CLIENT_TEN) || (client->addr & LP5860_I2C_PAGE_MASK))
+		return dev_err_probe(dev, -EINVAL,
+				     "Invalid I2C address: must be a 7-bit page-zero base address.\n");
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+		return dev_err_probe(dev, -EOPNOTSUPP,
+				     "SMBus byte-data transactions are not supported.\n");
+
+	clients = devm_kcalloc(dev, LP5860_I2C_NUM_PAGES, sizeof(*clients), GFP_KERNEL);
+	if (!clients)
+		return -ENOMEM;
+
+	/*
+	 * The LP5860 encodes the upper two bits of its 10-bit register address
+	 * in the two least-significant bits of the 7-bit I2C slave address.
+	 * Reserve the three consecutive dummy addresses for register pages 1..3.
+	 */
+	clients[0] = client;
+	for (unsigned int page = 1; page < LP5860_I2C_NUM_PAGES; page++) {
+		clients[page] = devm_i2c_new_dummy_device(dev, client->adapter,
+							  client->addr | page);
+		if (IS_ERR(clients[page]))
+			return dev_err_probe(dev, PTR_ERR(clients[page]),
+					     "Failed to reserve I2C register page %u.\n", page);
+	}
+
+	regmap = devm_regmap_init(dev, NULL, clients, &lp5860_i2c_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap),
+				     "Failed to initialise Regmap.\n");
+
+	return lp5860_device_init(dev, regmap);
+}
+
+static void lp5860_i2c_remove(struct i2c_client *client)
+{
+	lp5860_device_remove(&client->dev);
+}
+
+static const struct of_device_id lp5860_i2c_of_match[] = {
+	{ .compatible = "ti,lp5860" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, lp5860_i2c_of_match);
+
+static const struct i2c_device_id lp5860_i2c_ids[] = {
+	{ .name = "lp5860" },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, lp5860_i2c_ids);
+
+static struct i2c_driver lp5860_i2c_driver = {
+	.driver = {
+		.name = "lp5860-i2c",
+		.of_match_table = lp5860_i2c_of_match,
+	},
+	.probe = lp5860_i2c_probe,
+	.remove = lp5860_i2c_remove,
+	.id_table = lp5860_i2c_ids,
+};
+module_i2c_driver(lp5860_i2c_driver);
+
+MODULE_DESCRIPTION("TI LP5860 RGB LED I2C driver");
+MODULE_LICENSE("GPL");

-- 
2.43.0



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

* Re: [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support
  2026-12-04 15:15 [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support Peter LaDow via B4 Relay
                   ` (3 preceding siblings ...)
  2026-12-04 15:15 ` [PATCH v6 4/4] leds: rgb: lp5860: Add I2C interface support Peter LaDow via B4 Relay
@ 2026-12-04 15:30 ` sashiko-bot
  4 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04 15:30 UTC (permalink / raw)
  To: Peter LaDow; +Cc: linux-leds, lee

Sashiko has reviewed this 4-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-add-i2c-support-for-lp5860-v6-0-08ab1f8f4039@gmail.com

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

end of thread, other threads:[~2026-12-04 15:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 15:15 [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support Peter LaDow via B4 Relay
2026-12-04 15:15 ` [PATCH v6 1/4] leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels Peter LaDow via B4 Relay
2026-12-04 15:15 ` [PATCH v6 2/4] dt-bindings: leds: ti,lp5860: Document I2C interface Peter LaDow via B4 Relay
2026-12-04 15:15 ` [PATCH v6 3/4] leds: rgb: lp5860: Consolidate common probe setup in lp5860_device_init() Peter LaDow via B4 Relay
2026-12-04 15:15 ` [PATCH v6 4/4] leds: rgb: lp5860: Add I2C interface support Peter LaDow via B4 Relay
2026-12-04 15:30 ` [PATCH v6 0/4] leds: rgb: lp5860: Add I2C support sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox