Re: [PATCH v9] leds: add support for TI LP5860 LED driver chip
From: Jacek Anaszewski
Date: Sun Apr 26 2026 - 08:41:25 EST
Hi Steffen,
On 4/24/26 3:28 PM, Steffen Trumtrar wrote:
Add support for the Texas Instruments LP5860 LED driver chip[...]
via SPI interfaces.
The LP5860 is an LED matrix driver for up to 196 LEDs, which supports
short and open detection of the individual channel select lines.
It can be connected to SPI or I2C bus. For now add support for SPI only.
Signed-off-by: Steffen Trumtrar <s.trumtrar@xxxxxxxxxxxxxx>
---
diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
new file mode 100644
index 0000000000000..648bf168f94bf
--- /dev/null
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2025 Pengutronix
+ *
+ * Author: Steffen Trumtrar <kernel@xxxxxxxxxxxxxx>
+ */
+
+#include <linux/led-class-multicolor.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+#include "leds-lp5860.h"
+
+static struct lp5860_led *mcled_cdev_to_led(struct led_classdev_mc *mc_cdev)
+{
+ return container_of(mc_cdev, struct lp5860_led, mc_cdev);
+}
+
+static int lp5860_set_dot_onoff(struct lp5860_led *led, unsigned int dot, bool enable)
+{
+ 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)
+ return -EINVAL;
+
+ return regmap_update_bits(led->chip->regmap,
+ LP5860_REG_DOT_ONOFF_START + offset, mask,
+ enable ? LP5860_DOT_ALL_ON : LP5860_DOT_ALL_OFF);
+}
+
+static int lp5860_set_mc_brightness(struct led_classdev *cdev,
+ enum led_brightness brightness)
+{
+ struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev);
+ struct lp5860_led *led = mcled_cdev_to_led(mc_cdev);
You need mutex locking while accessing hw to avoid leaving the
device in an inconsistent state in case of two parallel requests from
different processes.
+ led_mc_calc_color_components(mc_cdev, brightness);
+
+ for (int i = 0; i < led->mc_cdev.num_colors; i++) {
+ unsigned int channel = mc_cdev->subled_info[i].channel;
+ unsigned int led_brightness = mc_cdev->subled_info[i].brightness;
+ int ret;
+
+ ret = lp5860_set_dot_onoff(led, channel, !!led_brightness);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(led->chip->regmap,
+ LP5860_REG_PWM_BRI_START + channel, led_brightness);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int lp5860_chip_enable(struct lp5860 *lp, bool enable)
+{
+ return regmap_write(lp->regmap, LP5860_REG_CHIP_EN, enable);
--
Best regards,
Jacek Anaszewski