Skip to contentSkip to conversation

leds: add new LED driver for TI LP5812

PATCH Superseded Nam Tran 2 participants 7 messages Jul 14, 2025 – Jul 23, 2025

Subsystems (4)

v11 of 22 Superseded Latest is v22 →

lore
Share & tools
lore

Nam Tran

author maintainer
#0 lore raw

v11 cover leds: add new LED driver for TI LP5812

This patch series adds initial support for the TI LP5812, a 4x3 matrix RGB LED driver with autonomous engine control. This version provides a minimal, clean implementation focused on core functionality only. The goal is to upstream a solid foundation, with the expectation that additional features can be added incrementally in future patches.

The driver integrates with the LED multicolor framework and supports a set of basic sysfs interfaces for LED control and chip management.

---
Changes in v11:
- Drop autonomous animation and other advanced features; reduce driver to core functionality only.
- Simplify LED parsing to use a unified path.
- Clean up and streamline code
- Use alphabetically ordered includes
- Remove redundant comments
- Fix style issues (e.g., comment capitalization, code placement)
- Update ABI documentation to reflect reduced feature set.
- Link to v10: https://lore.kernel.org/lkml/[email protected]/

Changes in v10:
- Address feedback on v9 regarding missing Reviewed-by tag
- Added explanation: binding structure changed significantly to integrate with the standard leds-class-multicolor.yaml schema and support multi-led@ nodes with nested led@ subnodes. This change introduced a new patternProperties hierarchy and removed the previous flat led@ layout used in the earlier versions. So the Reviewed-by tag was dropped out of caution.
- Address binding document feedback
- Use consistent quotes
- Replace 'max-cur' with the standard 'led-max-microamp'
- Remove 'led-cur' property
- Fix mixed indentation
- Updated core driver to align with the updated binding schema.
- Address core driver feedback
- Use for_each_available_child_of_node_scoped() to simplify the code
- Add a return checks for lp5812_write() and lp5812_read()
- Remove unneeded trailing commas
- Fix unsafe usage of stack-allocated strings
- Link to v9: https://lore.kernel.org/lkml/[email protected]/

Changes in v9:
- Move driver back to drivers/leds/rgb/
- Integrate with LED multicolor framework
- Refactor and simplify custom sysfs handling
- Extend Device Tree binding to support multi-led@ nodes using leds-class-multicolor.yaml
- Update documentation to reflect the updated sysfs.
- Link to v8: https://lore.kernel.org/lkml/[email protected]/

Changes in v8:
- Move driver to drivers/auxdisplay/ instead of drivers/leds/.
- Rename files from leds-lp5812.c/.h to lp5812.c/.h.
- Move ti,lp5812.yaml binding to auxdisplay/ directory,
and update the title and $id to match new path.
- No functional changes to the binding itself (keep Reviewed-by).
- Update commit messages and patch titles to reflect the move.
- Link to v7: https://lore.kernel.org/linux-leds/[email protected]/

Changes in v7:
- Mark chip_leds_map as const.
- Use consistent ret initialization.
- Simplify the function set_mix_sel_led().
- Refactor dev_config_show() and led_auto_animation_show() to avoid temp buffer, malloc/free.
- Simplify the code and ensure consistent use of mutex lock/unlock in show/store functions.
- Remove total_leds and total_aeu.
- Link to v6: https://lore.kernel.org/linux-leds/[email protected]/

Changes in v6:
- Add vcc-supply property to describe the LP5812 power supply.
- Remove chan-name property and entire LED subnodes, as they are not needed.
- Update LP5812 LED driver node to Raspberry Pi 4 B Device Tree, based on updated binding.
- Link to v5: https://lore.kernel.org/linux-leds/[email protected]/

Changes in v5:
- Rebase on v6.15-rc2
- Removed unused functions (lp5812_dump_regs, lp5812_update_bit).
- Address Krzysztof's review comments
- Link to v4: https://lore.kernel.org/linux-leds/[email protected]/
---

Nam Tran (4):
dt-bindings: leds: add TI/National Semiconductor LP5812 LED Driver
leds: add basic support for TI/National Semiconductor LP5812 LED
Driver
docs: ABI: Document LP5812 LED sysfs interfaces
docs: leds: Document TI LP5812 LED driver

 .../ABI/testing/sysfs-bus-i2c-devices-lp5812  |   40 +
 .../ABI/testing/sysfs-class-led-lp5812        |  120 ++
 .../devicetree/bindings/leds/ti,lp5812.yaml   |  229 ++++
 Documentation/leds/index.rst                  |    1 +
 Documentation/leds/leds-lp5812.rst            |   84 ++
 MAINTAINERS                                   |   13 +
 drivers/leds/rgb/Kconfig                      |   13 +
 drivers/leds/rgb/Makefile                     |    1 +
 drivers/leds/rgb/leds-lp5812.c                | 1147 +++++++++++++++++
 drivers/leds/rgb/leds-lp5812.h                |  164 +++
 10 files changed, 1812 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-lp5812
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-lp5812
 create mode 100644 Documentation/devicetree/bindings/leds/ti,lp5812.yaml
 create mode 100644 Documentation/leds/leds-lp5812.rst
 create mode 100644 drivers/leds/rgb/leds-lp5812.c
 create mode 100644 drivers/leds/rgb/leds-lp5812.h

base-commit: f09079bd04a924c72d555cd97942d5f8d7eca98c

Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v11 1/4 dt-bindings: leds: add TI/National Semiconductor LP5812 LED Driver

The LP5812 is a 4x3 RGB LED driver with an autonomous animation engine and time-cross-multiplexing (TCM) support for up to 12 LEDs or 4 RGB LEDs. It supports both analog (256 levels) and PWM (8-bit) dimming, including exponential PWM for smooth brightness control.

---
 .../devicetree/bindings/leds/ti,lp5812.yaml   | 229 ++++++++++++++++++
 MAINTAINERS                                   |   6 +
 2 files changed, 235 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/ti,lp5812.yaml
Documentation/devicetree/bindings/leds/ti,lp5812.yaml new file +229 -0
new file mode 100644
index 000000000000..848cd4f51901
@@ -0,0 +1,229 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/ti,lp5812.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI LP5812 4x3 Matrix RGB LED Driver with Autonomous Control
+
+maintainers:
+  - Nam Tran <[email protected]>
+
+description: |
+  The LP5812 is a 4x3 matrix RGB LED driver with I2C interface
+  and autonomous animation engine control.
+  For more product information please see the link below:
+  https://www.ti.com/product/LP5812#tech-docs
+
+properties:
+  compatible:
+    const: ti,lp5812
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description: Regulator providing power to the 'VCC' pin.
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^led@[0-3]$":
+    type: object
+    $ref: common.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3
+
+    required:
+      - reg
+
+  "^multi-led@[4-7]$":
+    type: object
+    $ref: leds-class-multicolor.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        minimum: 4
+        maximum: 7
+
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
+      "^led@[4-9a-f]$":
+        type: object
+        $ref: common.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            minimum: 4
+            maximum: 15
+
+        required:
+          - reg
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led-controller@1b {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "ti,lp5812";
+            reg = <0x1b>;
+            vcc-supply = <&vdd_3v3_reg>;
+
+            led@0 {
+                reg = <0x0>;
+                label = "LED0";
+                led-max-microamp = <25500>;
+            };
+
+            led@1 {
+                reg = <0x1>;
+                label = "LED1";
+                led-max-microamp = <25500>;
+            };
+
+            led@2 {
+                reg = <0x2>;
+                label = "LED2";
+                led-max-microamp = <25500>;
+            };
+
+            led@3 {
+                reg = <0x3>;
+                label = "LED3";
+                led-max-microamp = <25500>;
+            };
+
+            multi-led@4 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x4>;
+                color = <LED_COLOR_ID_RGB>;
+                label = "LED_A";
+
+                led@4 {
+                    reg = <0x4>;
+                    color = <LED_COLOR_ID_GREEN>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@5 {
+                    reg = <0x5>;
+                    color = <LED_COLOR_ID_RED>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@6 {
+                    reg = <0x6>;
+                    color = <LED_COLOR_ID_BLUE>;
+                    led-max-microamp = <25500>;
+                };
+            };
+
+            multi-led@5 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x5>;
+                color = <LED_COLOR_ID_RGB>;
+                label = "LED_B";
+
+                led@7 {
+                    reg = <0x7>;
+                    color = <LED_COLOR_ID_GREEN>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@8 {
+                    reg = <0x8>;
+                    color = <LED_COLOR_ID_RED>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@9 {
+                    reg = <0x9>;
+                    color = <LED_COLOR_ID_BLUE>;
+                    led-max-microamp = <25500>;
+                };
+            };
+
+            multi-led@6 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x6>;
+                color = <LED_COLOR_ID_RGB>;
+                label = "LED_C";
+
+                led@a {
+                    reg = <0xa>;
+                    color = <LED_COLOR_ID_GREEN>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@b {
+                    reg = <0xb>;
+                    color = <LED_COLOR_ID_RED>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@c {
+                    reg = <0xc>;
+                    color = <LED_COLOR_ID_BLUE>;
+                    led-max-microamp = <25500>;
+                };
+            };
+
+            multi-led@7 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x7>;
+                color = <LED_COLOR_ID_RGB>;
+                label = "LED_D";
+
+                led@d {
+                    reg = <0xd>;
+                    color = <LED_COLOR_ID_GREEN>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@e {
+                    reg = <0xe>;
+                    color = <LED_COLOR_ID_RED>;
+                    led-max-microamp = <25500>;
+                };
+
+                led@f {
+                    reg = <0xf>;
+                    color = <LED_COLOR_ID_BLUE>;
+                    led-max-microamp = <25500>;
+                };
+            };
+        };
+    };
+
+...
MAINTAINERS +6 -0
index a92290fffa16..83a779dc9bcd 100644
@@ -24561,6 +24561,12 @@ S:	Supported
 F:	Documentation/devicetree/bindings/iio/dac/ti,dac7612.yaml
 F:	drivers/iio/dac/ti-dac7612.c
 
+TEXAS INSTRUMENTS' LP5812 RGB LED DRIVER
+M:	Nam Tran <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/leds/ti,lp5812.yaml
+
 TEXAS INSTRUMENTS' LB8864 LED BACKLIGHT DRIVER
 M:	Alexander Sverdlin <[email protected]>
 L:	[email protected]
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v11 2/4 leds: add basic support for TI/National Semiconductor LP5812 LED Driver

In reply to Nam Tran

The LP5812 is a 4x3 matrix RGB LED driver with an autonomous animation engine and time-cross-multiplexing (TCM) support for up to 12 LEDs or 4 RGB LEDs. Each LED can be configured through the related registers to realize vivid and fancy lighting effects.

This patch adds minimal driver support for the LP5812, implementing only the essential functionality: I2C communication with the device, LED registration, brightness control in manual mode, and basic sysfs interfaces for LED configuration and fault monitoring.

---
 MAINTAINERS                    |    4 +
 drivers/leds/rgb/Kconfig       |   13 +
 drivers/leds/rgb/Makefile      |    1 +
 drivers/leds/rgb/leds-lp5812.c | 1147 ++++++++++++++++++++++++++++++++
 drivers/leds/rgb/leds-lp5812.h |  164 +++++
 5 files changed, 1329 insertions(+)
 create mode 100644 drivers/leds/rgb/leds-lp5812.c
 create mode 100644 drivers/leds/rgb/leds-lp5812.h
MAINTAINERS +4 -0
index 83a779dc9bcd..b4eb3265c800 100644
@@ -24566,6 +24566,10 @@ M:	Nam Tran <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/leds/ti,lp5812.yaml
+F:	drivers/leds/rgb/Kconfig
+F:	drivers/leds/rgb/Makefile
+F:	drivers/leds/rgb/leds-lp5812.c
+F:	drivers/leds/rgb/leds-lp5812.h
 
 TEXAS INSTRUMENTS' LB8864 LED BACKLIGHT DRIVER
 M:	Alexander Sverdlin <[email protected]>
drivers/leds/rgb/Kconfig +13 -0
index 222d943d826a..28ef4c487367 100644
@@ -26,6 +26,19 @@ config LEDS_KTD202X
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-ktd202x.
 
+config LEDS_LP5812
+	tristate "LED support for Texas Instruments LP5812"
+	depends on I2C
+	help
+	  If you say Y here you get support for TI LP5812 LED driver.
+	  The LP5812 is a 4x3 matrix RGB LED driver with autonomous
+	  animation engine control.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-lp5812.
+
+	  If unsure, say N.
+
 config LEDS_NCP5623
 	tristate "LED support for NCP5623"
 	depends on I2C
drivers/leds/rgb/Makefile +1 -0
index a501fd27f179..be45991f63f5 100644
@@ -2,6 +2,7 @@
 
 obj-$(CONFIG_LEDS_GROUP_MULTICOLOR)	+= leds-group-multicolor.o
 obj-$(CONFIG_LEDS_KTD202X)		+= leds-ktd202x.o
+obj-$(CONFIG_LEDS_LP5812)		+= leds-lp5812.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
drivers/leds/rgb/leds-lp5812.c new file +1147 -0

1,147 lines not on this page · raw message

drivers/leds/rgb/leds-lp5812.h new file +164 -0

164 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v11 2/4] leds: add basic support for TI/National Semiconductor LP5812 LED Driver

drivers/leds/rgb/leds-lp5812.c line 128

Quoted 9 lines · Nam Tran
Quoted 1 line

+static int lp5812_parse_led(struct device_node *np,

drivers/leds/rgb/leds-lp5812.c new file +8 -0
+			    struct lp5812_led_config *cfg,
+			    int led_index)
+{
+	int num_colors = 0, ret;
+
+	of_property_read_string(np, "label", &cfg[led_index].name);
+
+	ret = of_property_read_u32(np, "reg", &cfg[led_index].chan_nr);

You mix code for probe with code for regular operation. This is not expected and confusing. All functions related to probe must be before the probe function is defined.

Quoted 46 lines
drivers/leds/rgb/leds-lp5812.c new file +46 -0
+	if (ret)
+		return ret;
+
+	for_each_available_child_of_node_scoped(np, child) {
+		ret = lp5812_parse_led_channel(child, cfg, led_index, num_colors);
+		if (ret)
+			return ret;
+		num_colors++;
+	}
+
+	if (num_colors == 0) {
+		ret = lp5812_parse_led_channel(np, cfg, led_index, 0);
+		if (ret)
+			return ret;
+		num_colors = 1;
+		cfg[led_index].is_sc_led = true;
+	} else {
+		cfg[led_index].is_sc_led = false;
+	}
+
+	cfg[led_index].num_colors = num_colors;
+
+	return 0;
+}
+
+static int lp5812_of_populate_pdata(struct device *dev,
+				    struct device_node *np,
+				    struct lp5812_chip *chip)
+{
+	struct lp5812_led_config *cfg;
+	int num_channels, i = 0, ret;
+
+	num_channels = of_get_available_child_count(np);
+	if (num_channels == 0) {
+		dev_err(dev, "no LED channels\n");
+		return -EINVAL;
+	}
+
+	cfg = devm_kcalloc(dev, num_channels, sizeof(*cfg), GFP_KERNEL);
+	if (!cfg)
+		return -ENOMEM;
+
+	chip->led_config = &cfg[0];
+	chip->num_channels = num_channels;
+
+	for_each_available_child_of_node_scoped(np, child) {

drivers/leds/rgb/leds-lp5812.c line 184

Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+		ret = lp5812_parse_led(child, cfg, i);
+		if (ret)
+			return -EINVAL;
+		i++;
+	}
+
+	of_property_read_string(np, "label", &chip->label);
+	return 0;
+}
+

This is a messy driver :/

....

drivers/leds/rgb/leds-lp5812.c line 480

Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+
+static struct lp5812_led *lp5812_dev_to_led(struct device *dev)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	const char *name = dev->platform_data;
+
+	if (strcmp(name, LP5812_SC_LED) == 0)
+		return container_of(cdev, struct lp5812_led, cdev);
+
+	return container_of((struct led_classdev_mc *)cdev, struct lp5812_led, mc_cdev);

No, just pass correct pointer to platform data, no need with strcmp and then different container of...

...

Quoted 57 lines
drivers/leds/rgb/leds-lp5812.c new file +57 -0
+
+static int lp5812_init_led(struct lp5812_led *led, struct lp5812_chip *chip, int chan)
+{
+	struct device *dev = &chip->client->dev;
+	struct mc_subled *mc_led_info;
+	struct led_classdev *led_cdev;
+	int i, ret = 0;
+
+	if (chip->led_config[chan].name) {
+		led->cdev.name = chip->led_config[chan].name;
+	} else {
+		led->cdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s:channel%d",
+						chip->label ? : chip->client->name, chan);
+		if (!led->cdev.name)
+			return -ENOMEM;
+	}
+
+	if (!chip->led_config[chan].is_sc_led) {
+		mc_led_info = devm_kcalloc(dev,
+					   chip->led_config[chan].num_colors,
+					   sizeof(*mc_led_info), GFP_KERNEL);
+		if (!mc_led_info)
+			return -ENOMEM;
+
+		led_cdev = &led->mc_cdev.led_cdev;
+		led_cdev->name = led->cdev.name;
+		led_cdev->brightness_set_blocking = lp5812_set_mc_brightness;
+		led->mc_cdev.num_colors = chip->led_config[chan].num_colors;
+		for (i = 0; i < led->mc_cdev.num_colors; i++) {
+			mc_led_info[i].color_index =
+				chip->led_config[chan].color_id[i];
+			mc_led_info[i].channel =
+					chip->led_config[chan].led_id[i];
+		}
+
+		led->mc_cdev.subled_info = mc_led_info;
+	} else {
+		led->cdev.brightness_set_blocking = lp5812_set_brightness;
+	}
+
+	led->cdev.groups = lp5812_led_groups;
+	led->chan_nr = chan;
+
+	if (chip->led_config[chan].is_sc_led) {
+		ret = devm_led_classdev_register(dev, &led->cdev);
+		if (ret == 0) {
+			led->cdev.dev->platform_data = devm_kstrdup(dev, LP5812_SC_LED, GFP_KERNEL);
+			if (!led->cdev.dev->platform_data)
+				return -ENOMEM;
+		}
+	} else {
+		ret = devm_led_classdev_multicolor_register(dev, &led->mc_cdev);
+		if (ret == 0) {
+			led->mc_cdev.led_cdev.dev->platform_data =
+				devm_kstrdup(dev, LP5812_MC_LED, GFP_KERNEL);
+			if (!led->mc_cdev.led_cdev.dev->platform_data)
+				return -ENOMEM;

drivers/leds/rgb/leds-lp5812.c line 873

Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+
+			ret = sysfs_create_groups(&led->mc_cdev.led_cdev.dev->kobj,
+						  lp5812_led_groups);
+			if (ret)
+				dev_err(dev, "sysfs_create_groups failed\n");
+		}
+	}
+
+	if (ret) {
+		dev_err(dev, "led register err: %d\n", ret);

Why are you printing same error multiple times?

Quoted 79 lines
drivers/leds/rgb/leds-lp5812.c new file +79 -0
+		return ret;
+	}
+
+	return 0;
+}
+
+static int lp5812_register_leds(struct lp5812_led *led, struct lp5812_chip *chip)
+{
+	struct lp5812_led *each;
+	int num_channels = chip->num_channels;
+	int ret, i, j;
+
+	for (i = 0; i < num_channels; i++) {
+		each = led + i;
+		ret = lp5812_init_led(each, chip, i);
+		if (ret)
+			goto err_init_led;
+
+		each->chip = chip;
+
+		for (j = 0; j < chip->led_config[i].num_colors; j++) {
+			ret = lp5812_auto_dc(chip, chip->led_config[i].led_id[j],
+					     chip->led_config[i].led_id[j]);
+			if (ret)
+				goto err_init_led;
+
+			ret = lp5812_set_led_mode(chip, chip->led_config[i].led_id[j],
+						  LP5812_MODE_MANUAL);
+			if (ret)
+				goto err_init_led;
+		}
+	}
+
+	return 0;
+
+err_init_led:
+	return ret;
+}
+
+static int lp5812_register_sysfs(struct lp5812_chip *chip)
+{
+	struct device *dev = &chip->client->dev;
+	const struct lp5812_device_config *cfg = chip->cfg;
+	int ret;
+
+	ret = sysfs_create_group(&dev->kobj, cfg->dev_attr_group);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static void lp5812_unregister_sysfs(struct lp5812_led *led, struct lp5812_chip *chip)
+{
+	struct device *dev = &chip->client->dev;
+	const struct lp5812_device_config *cfg = chip->cfg;
+	struct lp5812_led *each;
+	int i;
+
+	sysfs_remove_group(&dev->kobj, cfg->dev_attr_group);
+
+	for (i = 0; i < chip->num_channels; i++) {
+		if (!chip->led_config[i].is_sc_led) {
+			each = led + i;
+			sysfs_remove_groups(&each->mc_cdev.led_cdev.dev->kobj, lp5812_led_groups);
+		}
+	}
+}
+
+static int lp5812_probe(struct i2c_client *client)
+{
+	struct lp5812_chip *chip;
+	const struct i2c_device_id *id = i2c_client_get_device_id(client);
+	struct device_node *np = dev_of_node(&client->dev);
+	struct lp5812_led *led;
+	int ret;
+
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)

drivers/leds/rgb/leds-lp5812.c line 962

Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+		return -ENOMEM;
+
+	chip->cfg = i2c_get_match_data(client);
+
+	if (np) {
+		ret = lp5812_of_populate_pdata(&client->dev, np, chip);
+		if (ret)
+			goto err_init;
+	} else {
+		return dev_err_probe(&client->dev, -EINVAL, "No platform data\n");

This is confusing syntax. Expected is:
if (!missing something)
return -EINVAL

The other problem is that you claim this can match and bind without OF, but here you say it is a requirement. So either this code is wrong or your I2C ID table should be removed.

Quoted 7 lines
drivers/leds/rgb/leds-lp5812.c new file +7 -0
+	}
+
+	led = devm_kcalloc(&client->dev, chip->num_channels, sizeof(*led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+
+	chip->client = client;

drivers/leds/rgb/leds-lp5812.c line 979

Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+
+	mutex_init(&chip->lock);
+
+	i2c_set_clientdata(client, led);
+
+	ret = lp5812_init_device(chip);
+	if (ret)
+		goto err_init;
+
+	dev_info(&client->dev, "%s Programmable led chip found\n", id->name);

Drop. You have only one device type (look at your binding), so you cannot "find" devices.

Quoted 17 lines
drivers/leds/rgb/leds-lp5812.c new file +17 -0
+
+	ret = lp5812_register_leds(led, chip);
+	if (ret)
+		goto err_out;
+
+	ret = lp5812_register_sysfs(chip);
+	if (ret) {
+		dev_err_probe(&client->dev, ret, "Registering sysfs failed\n");
+		goto err_out;
+	}
+
+	return 0;
+
+err_out:
+	lp5812_deinit_device(chip);
+err_init:
+	return ret;

drivers/leds/rgb/leds-lp5812.c line 1006

Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+}
+
+static void lp5812_remove(struct i2c_client *client)
+{
+	struct lp5812_led *led = i2c_get_clientdata(client);
+
+	lp5812_unregister_sysfs(led, led->chip);
+	lp5812_deinit_device(led->chip);
+
+	dev_info(&client->dev, "Removed driver\n");

No, drop, useless.

Best regards,
Krzysztof

author maintainer
#4 lore raw

Re: [PATCH v11 2/4] leds: add basic support for TI/National Semiconductor LP5812 LED Driver

Quoted 14 lines · Krzysztof Kozlowski

drivers/leds/rgb/leds-lp5812.c line 128

Quoted 9 lines · Nam Tran
Quoted 1 line

+static int lp5812_parse_led(struct device_node *np,

drivers/leds/rgb/leds-lp5812.c new file +8 -0
+			    struct lp5812_led_config *cfg,
+			    int led_index)
+{
+	int num_colors = 0, ret;
+
+	of_property_read_string(np, "label", &cfg[led_index].name);
+
+	ret = of_property_read_u32(np, "reg", &cfg[led_index].chan_nr);

You mix code for probe with code for regular operation. This is not expected and confusing. All functions related to probe must be before the probe function is defined.

I will restructured the code to move all probe-related helpers above the lp5812_probe() function.

Quoted 6 lines
Quoted 6 lines
drivers/leds/rgb/leds-lp5812.c new file +6 -0
+
+static struct lp5812_led *lp5812_dev_to_led(struct device *dev)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	const char *name = dev->platform_data;
+
Quoted 8 lines

drivers/leds/rgb/leds-lp5812.c line 480

Quoted 4 lines
drivers/leds/rgb/leds-lp5812.c new file +4 -0
+	if (strcmp(name, LP5812_SC_LED) == 0)
+		return container_of(cdev, struct lp5812_led, cdev);
+
+	return container_of((struct led_classdev_mc *)cdev, struct lp5812_led, mc_cdev);

No, just pass correct pointer to platform data, no need with strcmp and then different container of...

I will remove the string-based platform_data handling and now store a direct pointer to struct lp5812_led in dev->platform_data.
This allows simplifying lp5812_dev_to_led() without the need for strcmp() or multiple container_of() usages.

Quoted 60 lines
Quoted 60 lines
drivers/leds/rgb/leds-lp5812.c new file +60 -0
+static int lp5812_init_led(struct lp5812_led *led, struct lp5812_chip *chip, int chan)
+{
+	struct device *dev = &chip->client->dev;
+	struct mc_subled *mc_led_info;
+	struct led_classdev *led_cdev;
+	int i, ret = 0;
+
+	if (chip->led_config[chan].name) {
+		led->cdev.name = chip->led_config[chan].name;
+	} else {
+		led->cdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s:channel%d",
+						chip->label ? : chip->client->name, chan);
+		if (!led->cdev.name)
+			return -ENOMEM;
+	}
+
+	if (!chip->led_config[chan].is_sc_led) {
+		mc_led_info = devm_kcalloc(dev,
+					   chip->led_config[chan].num_colors,
+					   sizeof(*mc_led_info), GFP_KERNEL);
+		if (!mc_led_info)
+			return -ENOMEM;
+
+		led_cdev = &led->mc_cdev.led_cdev;
+		led_cdev->name = led->cdev.name;
+		led_cdev->brightness_set_blocking = lp5812_set_mc_brightness;
+		led->mc_cdev.num_colors = chip->led_config[chan].num_colors;
+		for (i = 0; i < led->mc_cdev.num_colors; i++) {
+			mc_led_info[i].color_index =
+				chip->led_config[chan].color_id[i];
+			mc_led_info[i].channel =
+					chip->led_config[chan].led_id[i];
+		}
+
+		led->mc_cdev.subled_info = mc_led_info;
+	} else {
+		led->cdev.brightness_set_blocking = lp5812_set_brightness;
+	}
+
+	led->cdev.groups = lp5812_led_groups;
+	led->chan_nr = chan;
+
+	if (chip->led_config[chan].is_sc_led) {
+		ret = devm_led_classdev_register(dev, &led->cdev);
+		if (ret == 0) {
+			led->cdev.dev->platform_data = devm_kstrdup(dev, LP5812_SC_LED, GFP_KERNEL);
+			if (!led->cdev.dev->platform_data)
+				return -ENOMEM;
+		}
+	} else {
+		ret = devm_led_classdev_multicolor_register(dev, &led->mc_cdev);
+		if (ret == 0) {
+			led->mc_cdev.led_cdev.dev->platform_data =
+				devm_kstrdup(dev, LP5812_MC_LED, GFP_KERNEL);
+			if (!led->mc_cdev.led_cdev.dev->platform_data)
+				return -ENOMEM;
+
+			ret = sysfs_create_groups(&led->mc_cdev.led_cdev.dev->kobj,
+						  lp5812_led_groups);
+			if (ret)
Quoted 8 lines

drivers/leds/rgb/leds-lp5812.c line 873

Quoted 6 lines
drivers/leds/rgb/leds-lp5812.c new file +6 -0
+				dev_err(dev, "sysfs_create_groups failed\n");
+		}
+	}
+
+	if (ret) {
+		dev_err(dev, "led register err: %d\n", ret);

Why are you printing same error multiple times?

I will remove the redundant error message at the end of lp5812_init_led() to avoid double-printing.
Now only the specific failure points log detailed errors.

Quoted 16 lines
Quoted 16 lines
drivers/leds/rgb/leds-lp5812.c new file +16 -0
+static int lp5812_probe(struct i2c_client *client)
+{
+	struct lp5812_chip *chip;
+	const struct i2c_device_id *id = i2c_client_get_device_id(client);
+	struct device_node *np = dev_of_node(&client->dev);
+	struct lp5812_led *led;
+	int ret;
+
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+
+	chip->cfg = i2c_get_match_data(client);
+
+	if (np) {
+		ret = lp5812_of_populate_pdata(&client->dev, np, chip);
Quoted 8 lines

drivers/leds/rgb/leds-lp5812.c line 962

Quoted 4 lines
drivers/leds/rgb/leds-lp5812.c new file +4 -0
+		if (ret)
+			goto err_init;
+	} else {
+		return dev_err_probe(&client->dev, -EINVAL, "No platform data\n");

This is confusing syntax. Expected is:
if (!missing something)
return -EINVAL

I will update it.

Quoted 3 lines

The other problem is that you claim this can match and bind without OF, but here you say it is a requirement. So either this code is wrong or your I2C ID table should be removed.

I will update the probe logic for clarity and removed the i2c_device_id table and .id_table field.

Quoted 10 lines
Quoted 10 lines
drivers/leds/rgb/leds-lp5812.c new file +10 -0
+	led = devm_kcalloc(&client->dev, chip->num_channels, sizeof(*led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+
+	chip->client = client;
+
+	mutex_init(&chip->lock);
+
+	i2c_set_clientdata(client, led);
+
Quoted 8 lines

drivers/leds/rgb/leds-lp5812.c line 979

Quoted 5 lines
drivers/leds/rgb/leds-lp5812.c new file +5 -0
+	ret = lp5812_init_device(chip);
+	if (ret)
+		goto err_init;
+
+	dev_info(&client->dev, "%s Programmable led chip found\n", id->name);

Drop. You have only one device type (look at your binding), so you cannot "find" devices.

I will drop it.

Quoted 10 lines

drivers/leds/rgb/leds-lp5812.c line 1006

Quoted 8 lines
drivers/leds/rgb/leds-lp5812.c new file +8 -0
+static void lp5812_remove(struct i2c_client *client)
+{
+	struct lp5812_led *led = i2c_get_clientdata(client);
+
+	lp5812_unregister_sysfs(led, led->chip);
+	lp5812_deinit_device(led->chip);
+
+	dev_info(&client->dev, "Removed driver\n");

No, drop, useless.

I will remove it.

Thank you for your thorough review and helpful suggestions.

Best regards,
Nam Tran

author maintainer
#5 lore raw

PATCH v11 3/4 docs: ABI: Document LP5812 LED sysfs interfaces

In reply to Nam Tran

The LP5812 is a 4x3 matrix RGB LED driver with autonomous animation engine control.

The driver provides interfaces to configure LED modes manual/autonomous, set PWM/DC values, and manage autonomous animation engines.

---
 .../ABI/testing/sysfs-bus-i2c-devices-lp5812  |  40 ++++++
 .../ABI/testing/sysfs-class-led-lp5812        | 120 ++++++++++++++++++
 MAINTAINERS                                   |   2 +
 3 files changed, 162 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-lp5812
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-lp5812
Documentation/ABI/testing/sysfs-bus-i2c-devices-lp5812 new file +40 -0
new file mode 100644
index 000000000000..a8b1d5c52a82
@@ -0,0 +1,40 @@
+What:		/sys/bus/i2c/devices/.../lp5812_chip_setup/dev_config
+Date:		July 2025
+KernelVersion:	6.17
+Contact:	Nam Tran <[email protected]>
+Description:
+		Configures drive mode and scan order. (WO)
+		Some valid values: tcmscan:4:0:1:2:3 (default), tcmscan:3:0:1:2, mixscan:2:2:0:3, mixscan:3:0:1:2:3
+
+What:		/sys/bus/i2c/devices/.../lp5812_chip_setup/device_command
+Date:		July 2025
+KernelVersion:	6.17
+Contact:	Nam Tran <[email protected]>
+Description:
+		Issues device-level commands. (WO)
+		Valid values: "update", "start", "stop", "pause", "continue"
+
+What:		/sys/bus/i2c/devices/.../lp5812_chip_setup/sw_reset
+Date:		July 2025
+KernelVersion:	6.17
+Contact:	Nam Tran <[email protected]>
+Description:
+		Triggers a software reset of the device. (WO)
+		1 - resets device
+		0 - does not reset device
+
+What:		/sys/bus/i2c/devices/.../lp5812_chip_setup/fault_clear
+Date:		July 2025
+KernelVersion:	6.17
+Contact:	Nam Tran <[email protected]>
+Description:
+		Clears fault status. (WO)
+		1 - clears fault status
+		0 - does not clear fault status
+
+What:		/sys/bus/i2c/devices/.../lp5812_chip_setup/tsd_config_status
+Date:		July 2025
+KernelVersion:	6.17
+Contact:	Nam Tran <[email protected]>
+Description:
+		Report the current thermal shutdown config status. (RO)
Documentation/ABI/testing/sysfs-class-led-lp5812 new file +120 -0

120 lines not on this page · raw message

MAINTAINERS +2 -0
index b4eb3265c800..cdba86f1768b 100644
@@ -24565,6 +24565,8 @@ TEXAS INSTRUMENTS' LP5812 RGB LED DRIVER
 M:	Nam Tran <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/ABI/testing/sysfs-bus-i2c-devices-lp5812
+F:	Documentation/ABI/testing/sysfs-class-led-lp5812
 F:	Documentation/devicetree/bindings/leds/ti,lp5812.yaml
 F:	drivers/leds/rgb/Kconfig
 F:	drivers/leds/rgb/Makefile
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH v11 4/4 docs: leds: Document TI LP5812 LED driver

In reply to Nam Tran

The driver provides sysfs interfaces to control and configure the LP5812 device and its LED channels.

The documetation describes the chip's capabilities, sysfs interface, and usage examples.

---
 Documentation/leds/index.rst       |  1 +
 Documentation/leds/leds-lp5812.rst | 84 ++++++++++++++++++++++++++++++
 MAINTAINERS                        |  1 +
 3 files changed, 86 insertions(+)
 create mode 100644 Documentation/leds/leds-lp5812.rst
Documentation/leds/index.rst +1 -0
index 76fae171039c..bebf44004278 100644
@@ -25,6 +25,7 @@ LEDs
    leds-lp5523
    leds-lp5562
    leds-lp55xx
+   leds-lp5812
    leds-mlxcpld
    leds-mt6370-rgb
    leds-sc27xx
Documentation/leds/leds-lp5812.rst new file +84 -0

84 lines not on this page · raw message

MAINTAINERS +1 -0
index cdba86f1768b..4fefc7fb7a9a 100644
@@ -24568,6 +24568,7 @@ S:	Maintained
 F:	Documentation/ABI/testing/sysfs-bus-i2c-devices-lp5812
 F:	Documentation/ABI/testing/sysfs-class-led-lp5812
 F:	Documentation/devicetree/bindings/leds/ti,lp5812.yaml
+F:	Documentation/leds/leds-lp5812.rst
 F:	drivers/leds/rgb/Kconfig
 F:	drivers/leds/rgb/Makefile
 F:	drivers/leds/rgb/leds-lp5812.c
Signature · 1 line
2.25.1