Re: [PATCH v2] leds: lp5860: Add I2C interface support

From: Peter LaDow

Date: Mon Nov 30 2026 - 11:52:02 EST


Before submitting an updated patch, I have some questions on the feedback.

On Fri, Nov 27, 2026 at 6:30 AM Lee Jones <lee@xxxxxxxxxx> wrote:
> On Fri, 20 Nov 2026, Peter LaDow via B4 Relay wrote:

> > Changes include:
> > - Adding the leds-lp5860-i2c bus driver module to handle the LP5860's
> > 10-bit register addressing scheme over I2C.
> > - Updating Kconfig and Makefile so I2C and SPI bus support can be built
> > independently or together.
>
> This is also not expected / wanted.

This is unclear. What is expected? What is wanted? This device can
operate in either SPI or I2C mode. And it is possible to have both in
the same system. Or are you thinking it better to do so through the
device tree? That is, the driver would support both SPI _and_ I2C
mode simultaneously?

> Take a look at the Git history to see how we usually describe changes.

Or is this a commenting issue?

> > +static int lp5860_i2c_reg_read(void *context, unsigned int reg, unsigned int *val)
> > +{
> > + struct lp5860_i2c *i2c = context;
> > + int ret;
> > +
> > + ret = i2c_smbus_read_byte_data(i2c->clients[reg >> 8], reg & 0xff);
>
> What prevents 'reg >> 8' from exceeding 'LP5860_I2C_NUM_PAGES - 1' if a caller
> or debugfs passes an out-of-range register? Setting 'max_register' in
> 'lp5860_i2c_regmap_config' bounds normal regmap accesses as long as
> 'LP5860_MAX_REG' is strictly less than 0x400, but guarding or masking the page
> index (or checking 'LP5860_MAX_REG') makes the invariant explicit.
>
> Also, no magic numbers. You should define these.

I went too far here. I was debugging things through debugfs and left
this in. I will remove it as it is not necessary.

> > + if (ret < 0)
> > + return ret;
> > +
> > + *val = ret;
> > + return 0;
> > +}
> > +
> > +static int lp5860_i2c_reg_write(void *context, unsigned int reg, unsigned int val)
> > +{
> > + struct lp5860_i2c *i2c = context;
> > +
> > + return i2c_smbus_write_byte_data(i2c->clients[reg >> 8], reg & 0xff, val);
> > +}
> > +
> > +static const struct regmap_bus lp5860_i2c_regmap_bus = {
> > + .reg_read = lp5860_i2c_reg_read,
> > + .reg_write = lp5860_i2c_reg_write,
> > +};
> > +
> > +static const struct regmap_config lp5860_i2c_regmap_config = {
> > + .name = "lp5860",
> > + .reg_bits = 16,
> > + .val_bits = 8,
> > + .max_register = LP5860_MAX_REG,
> > +};
> > +
> > +static int lp5860_i2c_probe(struct i2c_client *client)
> > +{
> > + struct device *dev = &client->dev;
> > + struct lp5860_i2c *i2c;
>
> 'i2c' makes this sound like it's part of the I2C API, and it only
> contains an array of i2c_clients, making the whole thing superfluous.
>
> Why not just:
>
> clients = devm_kcalloc(dev, LP5860_I2C_NUM_PAGES, sizeof(*clients), GFP_KERNEL);
>
> > + struct lp5860 *lp5860;
> > + unsigned int multi_leds;
> > + unsigned int page;
> > + int ret;
> > +
> > + if ((client->flags & I2C_CLIENT_TEN) ||
> > + client->addr < 0x40 || client->addr > 0x4c || (client->addr & 0x03))
>
> Please define the magic numbers.
>
> Use tabs not spaces - and they are 8 not 4.
>
> > + return dev_err_probe(dev, -EINVAL,
> > + "Use the page-zero I2C address (0x40, 0x44, 0x48 or 0x4c).\n");
>
> Don't list out raw values in user-facing documentation like this.
>
> > + 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;
> > +
> > + i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
> > + if (!i2c)
> > + return -ENOMEM;
> > +
> > + i2c->clients[0] = client;
> > + for (page = 1; page < LP5860_I2C_NUM_PAGES; page++) {
>
> for (int page = 1; ...
>
> > + i2c->clients[page] = devm_i2c_new_dummy_device(dev, client->adapter,
> > + client->addr | page);
>
> This last part needs a comment.
>
> > + if (IS_ERR(i2c->clients[page]))
> > + return dev_err_probe(dev, PTR_ERR(i2c->clients[page]),
> > + "Failed to reserve I2C register page %u.\n", page);
> > + }
> > +
> > + lp5860->regmap = devm_regmap_init(dev, &lp5860_i2c_regmap_bus, i2c,
> > + &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: c016466c8c8b01af27ac66d97b64fa9c9e431a3d
> > change-id: 20261120-add-i2c-support-for-lp5860-97f38b2ebe1c
> >
> > Best regards,
> > --
> > Peter LaDow <pladow@xxxxxxxxx>
> >
> >
>
> --
> Lee Jones



--
To love for the sake of being loved is human, but to love for the sake
of loving is angelic. -- Alphonse de Lamartine.