* [PATCH v3] leds: rgb: lp5860: Add I2C interface support
@ 2026-12-03 20:17 Peter LaDow via B4 Relay
2026-12-03 20:31 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Peter LaDow via B4 Relay @ 2026-12-03 20:17 UTC (permalink / raw)
To: Nam Tran, Lee Jones, Pavel Machek, Griffin Kroah-Hartman
Cc: linux-kernel, linux-leds, Peter LaDow
From: Peter LaDow <pladow@gmail.com>
Add I2C bus support for the Texas Instruments LP5860 RGB LED matrix
driver.
The LP5860 maps its 10-bit register space (0x000..0x38B) across four
consecutive 7-bit I2C slave addresses (base address + 0..3), where the
two least-significant bits of the slave address select the register
page. Allocate dummy I2C clients for the three secondary pages during
probe and route regmap accesses to the corresponding page client.
Tested on ZynqMP (ZU3) with an LP5860 connected over an AXI IIC
controller at base address 0x40 (A1=0, A0=0) at 400 kHz.
Signed-off-by: Peter LaDow <pladow@gmail.com>
---
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: Nam Tran <trannamatk@gmail.com>
To: Lee Jones <lee@kernel.org>
To: Pavel Machek <pavel@kernel.org>
To: Griffin Kroah-Hartman <griffin@kroah.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-leds@vger.kernel.org
---
drivers/leds/rgb/Kconfig | 12 +++
drivers/leds/rgb/Makefile | 1 +
drivers/leds/rgb/leds-lp5860-i2c.c | 145 +++++++++++++++++++++++++++++++++++++
3 files changed, 158 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..1fd08691d262
--- /dev/null
+++ b/drivers/leds/rgb/leds-lp5860-i2c.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/slab.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 lp5860 *lp5860;
+ unsigned int multi_leds;
+ int ret;
+
+ 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");
+
+ 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");
+
+ lp5860 = devm_kzalloc(dev, struct_size(lp5860, leds, multi_leds), GFP_KERNEL);
+ if (!lp5860)
+ return -ENOMEM;
+
+ 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 (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);
+ }
+
+ lp5860->regmap = devm_regmap_init(dev, NULL, clients, &lp5860_i2c_regmap_config);
+ if (IS_ERR(lp5860->regmap))
+ return dev_err_probe(dev, PTR_ERR(lp5860->regmap),
+ "Failed to initialise Regmap.\n");
+
+ lp5860->dev = dev;
+
+ ret = devm_mutex_init(dev, &lp5860->lock);
+ if (ret)
+ return ret;
+
+ i2c_set_clientdata(client, lp5860);
+
+ return lp5860_device_init(dev);
+}
+
+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");
---
base-commit: 6881bcee6db3a7a3f9ff2b5ff01a1b43ee97bc83
change-id: 20261120-add-i2c-support-for-lp5860-97f38b2ebe1c
Best regards,
--
Peter LaDow <pladow@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] leds: rgb: lp5860: Add I2C interface support
2026-12-03 20:17 [PATCH v3] leds: rgb: lp5860: Add I2C interface support Peter LaDow via B4 Relay
@ 2026-12-03 20:31 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 20:31 UTC (permalink / raw)
To: Peter LaDow; +Cc: linux-leds, lee
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] leds: lp5860: missing I2C interface and reg contract in DT
binding
- [Low] leds: lp5860: duplicate core probe setup in lp5860_i2c_probe()
--
commit 4d964912338fc686818afe035b061a2a5a66a794
Author: Peter LaDow <pladow@gmail.com>
leds: rgb: lp5860: Add I2C interface support
This commit adds an I2C bus front-end driver for the TI LP5860 RGB LED matrix
controller, mapping its 10-bit register space across four consecutive 7-bit
I2C addresses via dummy clients and a custom regmap.
> diff --git a/drivers/leds/rgb/leds-lp5860-i2c.c b/drivers/leds/rgb/leds-lp5860-i2c.c
> new file mode 100644
> index 0000000000000..1fd08691d2628
> --- /dev/null
> +++ b/drivers/leds/rgb/leds-lp5860-i2c.c
[ ... ]
> +static int lp5860_i2c_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + struct i2c_client **clients;
> + struct lp5860 *lp5860;
> + unsigned int multi_leds;
> + int ret;
> +
> + 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");
[Severity: Low]
Should Documentation/devicetree/bindings/leds/leds-lp5860.yaml be updated
alongside this driver to document I2C usage and the reg address contract?
The binding currently includes spi-peripheral-props.yaml unconditionally and
only has an SPI example. Since lp5860_i2c_probe() requires a 4-aligned 7-bit
base address whereas sibling ti,lp5812.yaml uses a 5-bit shifted address, the
I2C reg convention needs to be documented explicitly.
[ ... ]
> + 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");
> +
> + lp5860 = devm_kzalloc(dev, struct_size(lp5860, leds, multi_leds), GFP_KERNEL);
> + if (!lp5860)
> + return -ENOMEM;
[Severity: Low]
Could the child-node validation, struct lp5860 allocation, mutex setup,
and drvdata assignment be consolidated into lp5860_device_init() instead
of duplicating them from leds-lp5860-spi.c?
Passing the initialized struct regmap * directly into
lp5860_device_init(dev, regmap) in leds-lp5860-core.c would keep that
setup in one place for both bus front-ends.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-add-i2c-support-for-lp5860-v3-1-eb466df3300a@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 20:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:17 [PATCH v3] leds: rgb: lp5860: Add I2C interface support Peter LaDow via B4 Relay
2026-12-03 20:31 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox