[PATCH v5 4/4] leds: rgb: lp5860: Add I2C interface support
From: Peter LaDow via B4 Relay
Date: Fri Dec 04 2026 - 09:40:56 EST
From: Peter LaDow <pladow@xxxxxxxxx>
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@xxxxxxxxx>
---
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