From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796329044; b=cKuMUkEcVURzJ9XuQPs0O9r0N92jRlIVjiGdcjg3ZwW3DRHI7RnDYlK5qLJDuRagsIbW 6qgxyncDIH14cYDaX5rXnnHc4xHoN9lVruUX0k7LRRS2RAPhndGAIbmXAbCdUzN0QZgWZ khmzEJDTF2W/xf2Bx0/bWs0xPe8pjHVOCiCEUSex7355lAlCdsfS7EoHwH1ipzz2fdH+T 0mvy5b0GEfE7E1hfGsBw6jR7A2e9j/6+cdvUyUDdVfEnUy39wJWMvAelzHJVtwRSHQmY+ 6PsrRP33B+vdQwncL5nxH1Sptl8M37VNEeyfLy5YhhSSx9z9jWjfyzRpi+Bk+dw6iag== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329044; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=04x0PNyZfq1ETHTHqwAvFaXOui7ueRsezeaV28j0ZGM=; b=qLBU+m4rpMDZFIWznrgYIfcaUbzCmcRV4DtWBue4//2PPPMqbwVkgpqkEHHJYV7FdJE1 c2XMyqHs33l3fewV/WBuGCInyFi+bI5wmRIbhQeW7x3eusO8rTqgUNDFsXsEPtJ40dY2w JlROec6Lbd8NLpVII2JGtViQwa+6Ol4F9NnSjZuj4hK529mEeIPYvISfmFn6lRbby4nxp N0wFShwlq4+iE0In5vYlz7Jg/UwAJi3RWViVFohvDWDw7N8qMhaeYn2RDHbtX/D1BE/H4 g8hlUD4YYez5AfEi+WVuTlKv5ctJNNoMtOrhFGweAai78XV/zsLVolI6wW4sSqO+mHg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="UPMuc/9H"; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5E47606A322; Thu, 3 Dec 2026 20:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UPMuc/9H Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796329043; b=ulCaxTddkWD+t21is1oEDf6qClkabFTajq4mgo+tg6U8YfM6/09vTVzO1A4H8sVb9xkM wrN1FPOseJmMxG+hkjXLs0b2T2VNcj8TA2txOsy5dPqLttfHpaxJVR2URLCTADABNeHTh j0VMPzihVxpIDy2ftqq2o0ciy4zLAmqdXz46EQ+XiOsrCnz4WLHRa4pfzDtbGQkq8fROI FmnQFaRodL59BeL8C8+GF2Y3BSKRAuYDD5EkRhxNWlg8/pgVUWHNxcgB4yv/7TZxMadhk +62gDVFauoDKtoD1K04FG2vOo5ieIlHMk13N4rPIlodruE3DJlH7rveQPLplEOhAT4A== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796329043; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To: Content-Transfer-Encoding; bh=04x0PNyZfq1ETHTHqwAvFaXOui7ueRsezeaV28j0ZGM=; b=p91yzM2nqnGT/4fcS/vejcXc+LU+9GZOp6Y6IJ0+lwxx0Xu0wZP/cVs317J5IIfN146B sepyMtoKwdqM16kLMm4kgzRy04ITXKVK/1EHXQ7btcwxU7m3m+5jygYHA5UYuaE/XiGSR V8vUGjSyJcYP5K49cBads4yCNiWiwGd3F4Y5zWBqIOQG15spdz2f6Ls5Enm7/a/IF1L7c GFEStyWJZBgnqq3iGSb1MlDbLliCXLLqeG5JiMg3TduUZN9/7/2g31sqWjQWcOJThXY8N JpC5kTYzRw/Ds8hyShkawrkVkpbO+7VvP/X+cPbKtwa17dktgguplD84W4yN3VBSp8Q== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id A5F2F1F0092B; Thu, 3 Dec 2026 20:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329043; bh=04x0PNyZfq1ETHTHqwAvFaXOui7ueRsezeaV28j0ZGM=; h=From:Date:Subject:To:Cc:Reply-To; b=UPMuc/9HzMvRX+urX/YBSFSDB+JEWH7HHy0BfKY/t3bZ3LEcddkAHV4mp56lTgjBD COYXFJ9xIvcdTf5uqD3oMNbXOJ33bOMB39XNtg0QDNpcBjh+Sgz/JeHIH6jcL6IEoh EQNIiB2DPxcxtYtNDYY4kt8Tgyq+m5fWFiDNA82lcP10pXYTFiNiXwuOk6X9igTn3I WyAMisY7xHneXu9jjshtzquuSS4IbcJXHUplQigZRlOqwcE0GZNoyJVHLn5hvmCpqE qsyKd8s9jAVqFxXM0T2bmlhz3czqR8f+fnOkrnt+KZw3jcgoE3AY/cW11AsnNMMQSG 3KJmjx+xBQhug== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 08F634FAD3; Thu, 3 Dec 2026 20:17:22 +0000 (UTC) From: Peter LaDow via B4 Relay Date: Thu, 03 Dec 2026 12:17:21 -0800 Subject: [PATCH v3] leds: rgb: lp5860: Add I2C interface support X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261203-add-i2c-support-for-lp5860-v3-1-eb466df3300a@gmail.com> X-B4-Tracking: v=1; b=H4sIAFDOEWsC/43NSw6DIBSF4a0Yxr0NYHx11H00HcjlojQqBtS0M e69aCcdOvyTk++sLJC3FNgtWZmnxQbrhhjpJWHY1kNDYHVsJrnMhZAcaq3BSoQwj6PzExjnoRu zMudQFSYtlSRFAlkERk/Gvg/88fx1mNWLcNrFfdHaMDn/Od4Xse9OHS0CBKRcYVVoVKYo701f2 +6Krmf70SLPUzJSCpVE4rwuTPZPbdv2BYrRW1EhAQAA To: Nam Tran , Lee Jones , Pavel Machek , Griffin Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Peter LaDow X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796329041; l=7753; i=pladow@gmail.com; s=20261120; h=from:subject:message-id; bh=O44Df30tCcflP3XuVjki7GkGHde/EmUX8ua36/lEWNE=; b=suULdd4YHF4CTFQc5VHrq+JOE5iaaAd6N8aeWX/QKrdf1lRI1ToMutrfWnw3RPI1Q7LmEB4Z2 2mTYumXZNVjCCGB2rAKaI3ZgGzOjhD3K2Lg5VDLqQjM6y0ZgyJrOFFv X-Developer-Key: i=pladow@gmail.com; a=ed25519; pk=GEdL9uXOAV0PnykeFpXX87oqKs0/Ac0qAUc4Oow7WN4= X-Endpoint-Received: by B4 Relay for pladow@gmail.com/20261120 with auth_id=1585 X-Original-From: Peter LaDow Reply-To: pladow@gmail.com Content-Transfer-Encoding: 7bit From: Peter LaDow 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 --- 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 To: Lee Jones To: Pavel Machek To: Griffin Kroah-Hartman 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 +#include +#include +#include +#include +#include +#include + +#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