Skip to contentSkip to conversation

leds: Introduce Texas Instruments LP5816 LED driver

PATCH In review Alistair Bell 4 participants 8 messages Jul 12 – Jul 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover leds: Introduce Texas Instruments LP5816 LED driver

The patch series adds support for the Texas Instruments LP5816 4-channel I2C interface RGBW LED driver.

Provides sysfs control of fade, fade duration, fade profile and control of maximum output current.

Tested on: Qualcomm's QCS615 arm64 platform via a daughter board display adapter.

Alistair Bell (2):
leds: Texas Instruments LP5816 driver
dt-bindings: leds: Add binding for ti,lp5816

 .../ABI/testing/sysfs-class-leds-lp5816       | 123 +++++
 .../devicetree/bindings/leds/ti,lp5816.yaml   |  45 ++
 MAINTAINERS                                   |  10 +
 drivers/leds/Kconfig                          |  12 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/leds-lp5816.c                    | 443 ++++++++++++++++++
 6 files changed, 634 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-leds-lp5816
 create mode 100644 Documentation/devicetree/bindings/leds/ti,lp5816.yaml
 create mode 100644 drivers/leds/leds-lp5816.c
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 leds: Texas Instruments LP5816 driver

Add support for Texas Instruments LP5816 4-channel I2C device, the driver provides:

- Independent 4-channel control via the multicolor sysfs class
- Configurable fade effects, duration, fade profile and maximum operating current via sysfs

---
 MAINTAINERS                |   8 +
 drivers/leds/Kconfig       |  12 +
 drivers/leds/Makefile      |   1 +
 drivers/leds/leds-lp5816.c | 443 +++++++++++++++++++++++++++++++++++++
 4 files changed, 464 insertions(+)
 create mode 100644 drivers/leds/leds-lp5816.c
MAINTAINERS +8 -0
index f37a81950..b6a8c812a 100644
@@ -26761,6 +26761,14 @@ F:	drivers/leds/rgb/Makefile
 F:	drivers/leds/rgb/leds-lp5812.c
 F:	drivers/leds/rgb/leds-lp5812.h
 
+TEXAS INSTRUMENTS' LP5816 RGBW LED DRIVER
+M:	Alistair Bell <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/leds/Kconfig
+F:	drivers/leds/Makefile
+F:	drivers/leds/leds-lp5816.c
+
 TEXAS INSTRUMENTS' LB8864 LED BACKLIGHT DRIVER
 M:	Alexander Sverdlin <[email protected]>
 L:	[email protected]
drivers/leds/Kconfig +12 -0
index f4a0a3c8c..ce3776adf 100644
@@ -541,6 +541,18 @@ config LEDS_LP8864
 	  To compile this driver as a module, choose M here: the
 	  module will be called leds-lp8864.
 
+config LEDS_LP5816
+    tristate "LED driver for LP5816 chip"
+    depends on I2C
+    depends on LEDS_CLASS && LEDS_CLASS_MULTICOLOR
+	select REGMAP_I2C
+    help
+      Say Y to enable support for the Texas Instruments LP5816
+      RGBW LED connected via I2C.
+
+      To compile this driver as a module, choose M here:
+      the module will be called lp5816.
+
 config LEDS_CLEVO_MAIL
 	tristate "Mail LED on Clevo notebook"
 	depends on LEDS_CLASS && BROKEN
drivers/leds/Makefile +1 -0
index 7db376891..5ba7de099 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP5523)		+= leds-lp5523.o
 obj-$(CONFIG_LEDS_LP5562)		+= leds-lp5562.o
 obj-$(CONFIG_LEDS_LP5569)		+= leds-lp5569.o
 obj-$(CONFIG_LEDS_LP55XX_COMMON)	+= leds-lp55xx-common.o
+obj-$(CONFIG_LEDS_LP5816)   	+= leds-lp5816.o
 obj-$(CONFIG_LEDS_LP8501)		+= leds-lp8501.o
 obj-$(CONFIG_LEDS_LP8788)		+= leds-lp8788.o
 obj-$(CONFIG_LEDS_LP8860)		+= leds-lp8860.o
drivers/leds/leds-lp5816.c new file +443 -0

443 lines not on this page · raw message

Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH 1/2] leds: Texas Instruments LP5816 driver

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [Critical] The driver overwrites its initialized mutex with zeroes via a struct compound literal…

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [Critical] The driver overwrites its initialized mutex with zeroes via a struct compound literal assignment.
- [High] The lp5816_brightness_set function ignores the requested global brightness and writes unscaled relative intensities.
- [High] The LED classdev is registered and sysfs groups are added before hardware startup, creating initialization races.
- [High] The lp5816_brightness_set() function fails to latch updated PWM values because it omits the required UPDATE_CMD.
- [Medium] lp5816_brightness_get incorrectly calculates and returns the maximum relative color intensity instead of the global brightness.
- [Medium] Hardware is reset in .remove() while the devm_-managed LED classdev is still active, causing a teardown race.
- [Low] The driver hardcodes the LED device name, violating standard Device Tree naming guidelines.
- [Low] The commit message prefix does not follow the standard naming convention for the LED subsystem.
--

--- Patch [1]: [PATCH 1/2] leds: Texas Instruments LP5816 driver --- commit e41d9f624b4be8a22f82da1e0e301eeb37f92003
Author: Alistair Bell <[email protected]>
leds: Texas Instruments LP5816 driver

This patch adds support for the Texas Instruments LP5816 4-channel I2C RGBW LED driver. It provides independent 4-channel control via the multicolor sysfs class, as well as configurable fade effects and current limits.

Quoted 1 line

leds: Texas Instruments LP5816 driver

[Severity: Low]
This isn't a bug, but does this commit message prefix follow the standard naming convention for the LED subsystem? The guidelines usually mandate a capitalized format like leds: lp5816: Add support for ...

Quoted 5 lines
drivers/leds/leds-lp5816.c new file +0 -0
new file mode 100644
index 0000000000000..584c348a7fdb2

[ ... ]

Quoted 5 lines
drivers/leds/leds-lp5816.c new file +5 -0
+static enum led_brightness lp5816_brightness_get(struct led_classdev *cdev)
+{
+	struct mc_subled *leds;
+	struct lp5816 *chip;
+	int intensity;

drivers/leds/leds-lp5816.c line 325

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	mutex_lock(&chip->mtx);
+	leds = lcdev_to_mccdev(cdev)->subled_info;
+	intensity = MAX(leds[0].intensity, leds[1].intensity);
+	intensity = MAX(intensity, MAX(leds[2].intensity, leds[3].intensity));
+	mutex_unlock(&chip->mtx);
+	return intensity & 0xff;
+}

[Severity: Medium]
Does this return the actual global LED brightness state? It appears to calculate and return the maximum of the relative sub-LED color weights instead of returning the overall brightness level.

Quoted 11 lines
drivers/leds/leds-lp5816.c new file +11 -0
+static int lp5816_brightness_set(struct led_classdev *cdev, enum led_brightness br)
+{
+	struct lp5816 *chip;
+	struct led_classdev_mc *mc;
+	u8 vals[4];
+
+	mc = lcdev_to_mccdev(cdev);
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	vals[0] = mc->subled_info[0].intensity & 0xff;
+	vals[1] = mc->subled_info[1].intensity & 0xff;

drivers/leds/leds-lp5816.c line 347

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+	vals[2] = mc->subled_info[2].intensity & 0xff;
+	vals[3] = mc->subled_info[3].intensity & 0xff;
+
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	mutex_lock(&chip->mtx);
+	regmap_bulk_write(chip->regmap, REG_OUT0_MANUAL_PWM, vals, ARRAY_SIZE(vals));
+	mutex_unlock(&chip->mtx);
+	return 0;
+}

[Severity: High]
Does lp5816_brightness_set() ignore the requested global brightness parameter br? It looks like it assigns the unscaled relative intensity weights directly instead of calling led_mc_calc_color_components() to compute the correct brightness values.

[Severity: High]
Are these updated PWM values actually applied to the hardware output? It appears this function writes to the holding registers but does not send the UPDATE_CMD to REG_UPDATE_CMD to latch the changes, which might leave the hardware output entirely unchanged.

Quoted 8 lines
drivers/leds/leds-lp5816.c new file +8 -0
+static int lp5816_probe(struct i2c_client *client)
+{
+	struct lp5816 *chip;
+	char *name;
+	int res;
+
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)

drivers/leds/leds-lp5816.c line 366

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+		return dev_err_probe(&client->dev, -ENOMEM,
+			"failed to allocate lp5816 internal structure\n");
+
+	i2c_set_clientdata(client, chip);
+	mutex_init(&chip->mtx);
+
+	(*chip) = (struct lp5816) {
+		.dev = &client->dev,
+		.regmap = devm_regmap_init_i2c(client, &lp5816_regmap_config),
+		.subleds = {

[Severity: Critical]
Does this compound literal assignment overwrite the mutex that was just initialized? Since the assignment explicitly zeroes out all unlisted fields in the struct, it seems this will wipe out the mutex state and could lead to a panic or lockdep warning on the first attempt to acquire chip->mtx.

[ ... ]

drivers/leds/leds-lp5816.c line 378

Quoted 5 lines
drivers/leds/leds-lp5816.c new file +5 -0
+	if (IS_ERR(chip->regmap))
+		return dev_err_probe(&client->dev, PTR_ERR(chip->regmap),
+				"failed to allocate register map\n");
+
+	name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s:rgbw", dev_name(&client->dev));

[Severity: Low]
Is hardcoding the LED device name to end in :rgbw recommended here? This might prevent standard userspace tools from correctly identifying the LED by parsing Device Tree color and function properties per the LED subsystem rules.

Quoted 13 lines
drivers/leds/leds-lp5816.c new file +13 -0
+	if (!name)
+		return dev_err_probe(&client->dev, -ENOMEM,
+				"failed to allocate led-classdev name\n");
+
+	chip->mcdev = (struct led_classdev_mc){
+		.led_cdev = (struct led_classdev){
+			.brightness_set_blocking = lp5816_brightness_set,
+			.brightness_get = lp5816_brightness_get,
+			.name = name,
+		},
+		.num_colors = ARRAY_SIZE(chip->subleds),
+		.subled_info = chip->subleds,
+	};

drivers/leds/leds-lp5816.c line 401

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+
+	res = devm_led_classdev_multicolor_register(&client->dev, &chip->mcdev);
+	if (res < 0)
+		return dev_err_probe(&client->dev, res, "failed to register classdev multicolor\n");
+
+	res = devm_device_add_group(chip->mcdev.led_cdev.dev, &lp5816_group);
+	if (res < 0)
+		return dev_err_probe(&client->dev, res, "failed to add led device group\n");
+
+	res = lp5816_startup(chip);

[Severity: High]
Could this registration sequence cause initialization races?
By registering the LED classdev and firing uevents before adding the custom sysfs groups and before the hardware is actually powered on in lp5816_startup(), udev might miss the custom groups. Additionally, any immediate userspace writes could be wiped out when lp5816_startup() subsequently issues a hard reset.

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+	if (res < 0)
+		return dev_err_probe(&client->dev, res,
+				"failed to execute chip startup procedure\n");
+	return 0;
+}
+
+static void lp5816_remove(struct i2c_client *client)
+{
+	struct lp5816 *chip;
+

drivers/leds/leds-lp5816.c line 421

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+	chip = i2c_get_clientdata(client);
+	if (!chip)
+		return;
+
+	mutex_lock(&chip->mtx);
+	regmap_multi_reg_write(chip->regmap, (const struct reg_sequence[]) {
+		{ .reg = REG_RESET_CMD, .def = RESET_CMD },
+		{ .reg = REG_UPDATE_CMD, .def = UPDATE_CMD }}, 2);
+	mutex_unlock(&chip->mtx);
+}

[Severity: Medium]
Can this manual hardware reset race with the managed teardown? Because the LED class device is registered via devres, it is still active when lp5816_remove() resets the chip. The LED core might attempt to set the brightness to 0 during its unregistration phase later, writing to a reset and sleeping chip.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH 1/2] leds: Texas Instruments LP5816 driver

In reply to Alistair Bell

Hello Alistair,

Quoted 1 line · Alistair Bell

+#include <linux/mod_devicetable.h>

Please don't add new users for this header file. Only use those <linux/device-id/*.h> that you actually need (if any).

Thanks
Uwe

#4 lore raw

Re: [PATCH 1/2] leds: Texas Instruments LP5816 driver

In reply to Alistair Bell
Quoted 44 lines · Alistair Bell

Add support for Texas Instruments LP5816 4-channel I2C device, the driver provides:

- Independent 4-channel control via the multicolor sysfs class
- Configurable fade effects, duration, fade profile and maximum operating current via sysfs

---
 MAINTAINERS                |   8 +
 drivers/leds/Kconfig       |  12 +
 drivers/leds/Makefile      |   1 +
 drivers/leds/leds-lp5816.c | 443 +++++++++++++++++++++++++++++++++++++
 4 files changed, 464 insertions(+)
 create mode 100644 drivers/leds/leds-lp5816.c
MAINTAINERS +8 -0
index f37a81950..b6a8c812a 100644
@@ -26761,6 +26761,14 @@ F:	drivers/leds/rgb/Makefile
 F:	drivers/leds/rgb/leds-lp5812.c
 F:	drivers/leds/rgb/leds-lp5812.h
 
+TEXAS INSTRUMENTS' LP5816 RGBW LED DRIVER
+M:	Alistair Bell <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/leds/Kconfig
+F:	drivers/leds/Makefile
+F:	drivers/leds/leds-lp5816.c
+
 TEXAS INSTRUMENTS' LB8864 LED BACKLIGHT DRIVER
 M:	Alexander Sverdlin <[email protected]>
 L:	[email protected]
drivers/leds/Kconfig +1 -0
index f4a0a3c8c..ce3776adf 100644
@@ -541,6 +541,18 @@ config LEDS_LP8864
 	  To compile this driver as a module, choose M here: the
 	  module will be called leds-lp8864.
 
+config LEDS_LP5816

drivers/leds/Kconfig config LEDS_LP8864 · line 554

Quoted 10 lines
drivers/leds/Kconfig +10 -0
+    tristate "LED driver for LP5816 chip"
+    depends on I2C
+    depends on LEDS_CLASS && LEDS_CLASS_MULTICOLOR
+	select REGMAP_I2C
+    help
+      Say Y to enable support for the Texas Instruments LP5816
+      RGBW LED connected via I2C.
+
+      To compile this driver as a module, choose M here:
+      the module will be called lp5816.

Messed indentation. Please be sure you are sending consistent code, not something written completely different than the rest.

Quoted 7 lines
drivers/leds/Kconfig +1 -0
+
 config LEDS_CLEVO_MAIL
 	tristate "Mail LED on Clevo notebook"
 	depends on LEDS_CLASS && BROKEN
drivers/leds/Makefile +0 -1
index 7db376891..5ba7de099 100644
--- a/drivers/leds/Makefile

...

Quoted 13 lines
drivers/leds/Makefile +13 -0
+
+static ssize_t max_current_store(struct device *dev,
+				 struct device_attribute *attr,
+								const char *buf, size_t count)
+{
+	struct led_classdev *cdev;
+	struct lp5816 *chip;
+	int res, val;
+
+	cdev = dev_get_drvdata(dev);
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	res = kstrtoint(buf, 0, &val);

drivers/leds/Makefile

Quoted 10 lines
drivers/leds/Makefile +10 -0
+	if (res < 0)
+		return res;
+	if (val < 0 || val > 1)
+		return -EINVAL;
+
+	res = lp5816_multi_lock_write(chip, (const struct reg_sequence[]) {
+		{ .reg = REG_DEV_CONFIG0, .def = val },
+		{ .reg = REG_UPDATE_CMD, .def = UPDATE_CMD } }, 2);
+	return (res < 0) ? res : count;
+}

You cannot introduce own ABI duplicating existing sysfs interface.

drivers/leds/Makefile

Quoted 11 lines
drivers/leds/Makefile +11 -0
+
+static int lp5816_probe(struct i2c_client *client)
+{
+	struct lp5816 *chip;
+	char *name;
+	int res;
+
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return dev_err_probe(&client->dev, -ENOMEM,
+			"failed to allocate lp5816 internal structure\n");

Since when any driver has such error message?

Please look at most recently addedd and reviewed drivers and learn from them how typical code looks like.

Best regards,
Krzysztof

#5 lore raw

PATCH 2/2 dt-bindings: leds: Add binding for ti,lp5816

In reply to Alistair Bell

Add devicetree binding for Texas Instruments LP5816 4-channel I2C LED device.

---
 .../ABI/testing/sysfs-class-leds-lp5816       | 123 ++++++++++++++++++
 .../devicetree/bindings/leds/ti,lp5816.yaml   |  45 +++++++
 MAINTAINERS                                   |   2 +
 3 files changed, 170 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-leds-lp5816
 create mode 100644 Documentation/devicetree/bindings/leds/ti,lp5816.yaml
Documentation/ABI/testing/sysfs-class-leds-lp5816 new file +123 -0
new file mode 100644
index 000000000..2d1fd107a
@@ -0,0 +1,123 @@
+What: /sys/class/leds/<device>/fade
+Date: July 2026
+KernelVersion: 7.2
+Contact: <[email protected]>
+Description:
+	Enables/disables hardware fading of each individual LED and sets transition duration
+	between an old intensity and new intensity
+
+	Format: <enable_red> <enable_green> <enable_blue> <enable_white> <duration>
+
+	Possible values for <enable> are:
+
+	== =======
+	0  disable
+	1  enable
+	== =======
+
+	Disable: The LED intensity will change instantaneous
+	Enable: The LED intensity will transition between the old and new value either
+	linearly or exponentially based on their individual fade_mode over a period
+	specified by <duration>
+
+	Possible values for <duration> are:
+
+	==    =====
+	0     0.00s
+	1     0.05s
+	2     0.10s
+	3     0.15s
+	4     0.20s
+	5     0.25s
+	6     0.30s
+	7     0.35s
+	8     0.40s
+	9     0.45s
+	10    0.50s
+	12    2.00s
+	13    4.00s
+	14    6.00s
+	15    8.00s
+	==    =====
+
+	Reading this attribute returns the current fade configuration in the same
+	format as writing to it
+
+	Example:
+
+		$ echo 0 1 0 1 14 > /sys/class/leds/<device>/fade
+
+		Enables fade for the green and white channels whilst disabling red and blue.
+		Sets the duration to 6.0s
+
+		$ cat /sys/class/leds/<device>/fade
+		0 1 0 1 14
+
+		$ echo 0 1 0 0 > /sys/class/leds/<device>/multi_intensity
+		If the green LED is not already at full intensity you should notice it slowly getting
+		brighter until reaching 100% brightness after 6.0 seconds
+
+	Notes:
+		By default the driver initialises all fade modes to be disabled and a duration
+		of 0.0s
+
+
+What: /sys/class/leds/<device>/fade_mode
+Date: July 2026
+KernelVersion: 7.2
+Contact: <[email protected]>
+Description:
+	Sets the fade transition of each individual LED to either linear or exponential
+
+	Format: <mode_red> <mode_green> <mode_blue> <mode_white>
+
+	Possible values for <mode_> are:
+
+	== ===========
+	0  linear
+	1  exponential
+	== ===========
+
+	Linear:
+
+	100% |           x
+	 80% |         x
+	 60% |       x
+	 40% |     x
+	 20% |   x
+	  0% |_____________   Time
+		 0 1 2 3 ... D
+
+	Constant increase/decrease in LED intensity between 0.0s and <duration>
+
+	Exponential:
+
+	100% |
+	 80% |          x
+	 60% |         x
+	 40% |        x
+	 20% |  x x x
+	  0% |_____________   Time
+		 0 1 2 3 ... D
+
+	Initially only a small visible change from the initial intensity then
+	will appear to quickly and smoothly transition to the brightness target
+
+	Example:
+		$ cat /sys/class/leds/<device>/fade_mode
+		0 0 0 0
+
+		Notice the default configuration is all LEDs in linear mode
+
+		$ echo 1 1 0 0 > /sys/class/leds/<device>/fade_mode
+
+		Sets red and green to use exponential mode and blue and white to linear
+
+		$ cat /sys/class/leds/<device>/fade_mode
+		1 1 0 0
+
+		Configuration stored and returned in the same format as was written to
+
+	Note:
+		If /sys/class/leds/<device>/fade is disabled on a specific color this configuration will
+		be saved for when fading is enabled
Documentation/devicetree/bindings/leds/ti,lp5816.yaml new file +45 -0

45 lines not on this page · raw message

MAINTAINERS +2 -0
index b6a8c812a..5835f929d 100644
@@ -26765,6 +26765,8 @@ TEXAS INSTRUMENTS' LP5816 RGBW LED DRIVER
 M:	Alistair Bell <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/ABI/testing/sysfs-class-leds-lp5816
+F:	Documentation/devicetree/bindings/leds/ti,lp5816.yaml
 F:	drivers/leds/Kconfig
 F:	drivers/leds/Makefile
 F:	drivers/leds/leds-lp5816.c
Signature · 1 line
2.54.0
#6 lore raw

Re: [PATCH 2/2] dt-bindings: leds: Add binding for ti,lp5816

Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider: - [High] The driver overwrites the initialized mutex with zeroes during a compound struct assignment…

Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
- [High] The driver overwrites the initialized mutex with zeroes during a compound struct assignment, causing an inevitable crash on first use.
- [High] The driver ignores the master brightness parameter and fails to use the multi-color calculation helper.
- [High] The driver resets the hardware in remove() before the LED is unregistered, causing a use-after-disable window.
- [High] Missing register update command in brightness setter prevents hardware from applying new values.
- [Medium] The commit introduces custom, device-specific sysfs attributes (fade and fade_mode) that hardcode specific RGBW colors, bypassing standard LED subsystem mechanisms.
- [Medium] The device tree binding fails to define standard LED child nodes and omits common standard LED properties, breaking hardware description principles.
- [Medium] The device is exposed to user-space before its hardware is initialized.
- [Low] The device tree binding description explicitly references the operating system's software driver.
- [Low] Use of undeclared identifier MAX causes a compilation error.
- [Low] The patch commit message violates the LED subsystem naming convention.
--

--- Patch [2]: [PATCH 2/2] dt-bindings: leds: Add binding for ti,lp5816 --- commit b91ef8e4c561a1f06d4c4b39a848e64275caccbb
Author: Alistair Bell <[email protected]>

dt-bindings: leds: Add binding for ti,lp5816

Add devicetree binding for Texas Instruments LP5816 4-channel I2C LED device.

Quoted 1 line

dt-bindings: leds: Add binding for ti,lp5816

[Severity: Low]
Does this commit message subject violate the LED subsystem naming convention? The subsystem guidelines expect the prefix to follow the format:
leds: <Driver>: <Capitalized description>.

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-leds-lp5816 new file +0 -0
new file mode 100644
index 0000000000000..2d1fd107abf67

Documentation/ABI/testing/sysfs-class-leds-lp5816 line 9

Quoted 9 lines
Documentation/ABI/testing/sysfs-class-leds-lp5816 new file +9 -0
@@ -0,0 +1,123 @@
+What: /sys/class/leds/<device>/fade
+Date: July 2026
+KernelVersion: 7.2
+Contact: <[email protected]>
+Description:
+	Enables/disables hardware fading of each individual LED and sets transition duration
+	between an old intensity and new intensity
+
+	Format: <enable_red> <enable_green> <enable_blue> <enable_white> <duration>

[Severity: Medium]
Does introducing these custom, device-specific sysfs attributes that hardcode specific RGBW colors bypass the standard LED subsystem mechanisms? This forces user-space tools to implement custom string parsing for this specific chip.

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lp5816.yaml new file +0 -0
new file mode 100644
index 0000000000000..d33489c306dfc

[ ... ]

Documentation/devicetree/bindings/leds/ti,lp5816.yaml line 21

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lp5816.yaml new file +5 -0
+properties:
+  compatible:
+    const: ti,lp5816
+    description: |
+      Specifies device as LP5816 and the uses that kernel driver

[Severity: Low]
Does this description improperly reference the operating system's software driver?
Device tree bindings should be OS-agnostic hardware descriptions.

[ ... ]

Documentation/devicetree/bindings/leds/ti,lp5816.yaml line 32

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lp5816.yaml new file +5 -0
+required:
+  - compatible
+  - reg
+
+additionalProperties: false

[Severity: Medium]
Does this schema fail to define standard LED child nodes? By dropping child node specifications and omitting common standard LED properties, a device tree attempting to define standard LED properties like color or function will fail validation.

Quoted 5 lines
drivers/leds/leds-lp5816.c new file +0 -0
new file mode 100644
index 0000000000000..584c348a7fdb2

[ ... ]

drivers/leds/leds-lp5816.c

Quoted 11 lines
drivers/leds/leds-lp5816.c new file +11 -0
+static enum led_brightness lp5816_brightness_get(struct led_classdev *cdev)
+{
+	struct mc_subled *leds;
+	struct lp5816 *chip;
+	int intensity;
+
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	mutex_lock(&chip->mtx);
+	leds = lcdev_to_mccdev(cdev)->subled_info;
+	intensity = MAX(leds[0].intensity, leds[1].intensity);

[Severity: Low]
Will this result in a compilation error?
The uppercase MAX macro is undeclared; the standard kernel macro for maximum values is lowercase max().

[ ... ]

drivers/leds/leds-lp5816.c

Quoted 13 lines
drivers/leds/leds-lp5816.c new file +13 -0
+static int lp5816_brightness_set(struct led_classdev *cdev, enum led_brightness br)
+{
+	struct lp5816 *chip;
+	struct led_classdev_mc *mc;
+	u8 vals[4];
+
+	mc = lcdev_to_mccdev(cdev);
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	vals[0] = mc->subled_info[0].intensity & 0xff;
+	vals[1] = mc->subled_info[1].intensity & 0xff;
+	vals[2] = mc->subled_info[2].intensity & 0xff;
+	vals[3] = mc->subled_info[3].intensity & 0xff;

[Severity: High]
Does this ignore the master brightness parameter?
The core functionality of setting the LED brightness appears broken because the driver does not use led_mc_calc_color_components(mc, br) and ignores the requested master brightness, making it impossible to turn off the LED via the standard API.

drivers/leds/leds-lp5816.c

Quoted 5 lines
drivers/leds/leds-lp5816.c new file +5 -0
+
+	chip = container_of(cdev, struct lp5816, mcdev.led_cdev);
+
+	mutex_lock(&chip->mtx);
+	regmap_bulk_write(chip->regmap, REG_OUT0_MANUAL_PWM, vals, ARRAY_SIZE(vals));

[Severity: High]
Are we missing the register update command here?
Without issuing a REG_UPDATE_CMD after the bulk write, the brightness changes requested via the standard API will fail to take effect on the hardware.

Quoted 3 lines
drivers/leds/leds-lp5816.c new file +3 -0
+	mutex_unlock(&chip->mtx);
+	return 0;
+}

[ ... ]

Quoted 5 lines
drivers/leds/leds-lp5816.c new file +5 -0
+static int lp5816_probe(struct i2c_client *client)
+{
+	struct lp5816 *chip;
+	char *name;
+	int res;

drivers/leds/leds-lp5816.c

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return dev_err_probe(&client->dev, -ENOMEM,
+			"failed to allocate lp5816 internal structure\n");
+
+	i2c_set_clientdata(client, chip);
+	mutex_init(&chip->mtx);
+
+	(*chip) = (struct lp5816) {

[Severity: High]
Will this compound struct assignment overwrite the initialized mutex? Standard C semantics zero-initialize omitted members in a compound literal, which will wipe the internal state of chip->mtx and cause a kernel oops or deadlock on the first mutex_lock() call.

Quoted 9 lines
drivers/leds/leds-lp5816.c new file +9 -0
+		.dev = &client->dev,
+		.regmap = devm_regmap_init_i2c(client, &lp5816_regmap_config),
+		.subleds = {
+			{ .color_index = LED_COLOR_ID_RED, .intensity = 0 },
+			{ .color_index = LED_COLOR_ID_GREEN, .intensity = 0 },
+			{ .color_index = LED_COLOR_ID_BLUE, .intensity = 0 },
+			{ .color_index = LED_COLOR_ID_WHITE, .intensity = 0 },
+		},
+	};

[ ... ]

drivers/leds/leds-lp5816.c

Quoted 9 lines
drivers/leds/leds-lp5816.c new file +9 -0
+	res = devm_led_classdev_multicolor_register(&client->dev, &chip->mcdev);
+	if (res < 0)
+		return dev_err_probe(&client->dev, res, "failed to register classdev multicolor\n");
+
+	res = devm_device_add_group(chip->mcdev.led_cdev.dev, &lp5816_group);
+	if (res < 0)
+		return dev_err_probe(&client->dev, res, "failed to add led device group\n");
+
+	res = lp5816_startup(chip);

[Severity: Medium]
Is it safe to expose the device to user-space before its hardware is initialized? If udev or user-space accesses the device after devm_led_classdev_multicolor_register() but before lp5816_startup() finishes, the hardware reset in the startup sequence could destroy that state.

Quoted 8 lines
drivers/leds/leds-lp5816.c new file +8 -0
+	if (res < 0)
+		return dev_err_probe(&client->dev, res,
+				"failed to execute chip startup procedure\n");
+	return 0;
+}
+
+static void lp5816_remove(struct i2c_client *client)
+{

drivers/leds/leds-lp5816.c

Quoted 10 lines
drivers/leds/leds-lp5816.c new file +10 -0
+	struct lp5816 *chip;
+
+	chip = i2c_get_clientdata(client);
+	if (!chip)
+		return;
+
+	mutex_lock(&chip->mtx);
+	regmap_multi_reg_write(chip->regmap, (const struct reg_sequence[]) {
+		{ .reg = REG_RESET_CMD, .def = RESET_CMD },
+		{ .reg = REG_UPDATE_CMD, .def = UPDATE_CMD }}, 2);

[Severity: High]
Does resetting the hardware in remove() before the LED is unregistered cause a use-after-disable window?

Because the LED class device is registered using a devres API, it will be unregistered automatically after remove() returns. That automatic cleanup calls led_set_brightness() to turn off the LED, which will write I2C commands to a device that has already been reset.

Quoted 3 lines
drivers/leds/leds-lp5816.c new file +3 -0
+	mutex_unlock(&chip->mtx);
+}
+
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH 2/2] dt-bindings: leds: Add binding for ti,lp5816

In reply to Alistair Bell
Quoted 4 lines · Alistair Bell

Add devicetree binding for Texas Instruments LP5816 4-channel I2C LED device.

Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.

Please kindly resend and include all necessary To/Cc entries.

Please run scripts/checkpatch.pl on the patches and fix reported warnings. After that, run also 'scripts/checkpatch.pl --strict' on the patches and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

A nit, subject: drop second/last, redundant "bindings for". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Please organize the patch documenting the compatible (DT bindings) before the patch using that compatible.
See also:
https://elixir.bootlin.com/linux/v6.14-rc6/source/Documentation/devicetree/bindings/submitting-patches.rst#L46

Best regards,
Krzysztof