Re: [PATCH v2 5/8] leds: pca995x: Make output gain configurable

From: Lee Jones

Date: Tue Sep 22 2026 - 12:35:13 EST


On Tue, 15 Sep 2026, Nora Schiffer wrote:

> The output gain linearly configures the LED current in 255 levels; the
> absolute current depends on both the gain value and the R_ext resistor
> connected to the LED driver. Make the gain configurable in the Device
> Tree instead of hardcoding it to 128, allowing to adjust the current
> for different hardware designs.
>
> Signed-off-by: Nora Schiffer <nora.schiffer@xxxxxxxxxxxxxxx>
> ---
>
> v2: Add nxp, vendor prefix
>
> drivers/leds/leds-pca995x.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/leds/leds-pca995x.c b/drivers/leds/leds-pca995x.c
> index 0c0ea57f3225a..9cd5702573b0d 100644
> --- a/drivers/leds/leds-pca995x.c
> +++ b/drivers/leds/leds-pca995x.c
> @@ -127,6 +127,7 @@ static int pca995x_probe(struct i2c_client *client)
> struct pca995x_chip *chip;
> struct pca995x_led *led;
> int i, j, reg, ret;
> + u32 iref;
>
> chipdef = device_get_match_data(&client->dev);
>
> @@ -154,6 +155,11 @@ static int pca995x_probe(struct i2c_client *client)
>
> i2c_set_clientdata(client, chip);
>
> + if (device_property_read_u32(dev, "nxp,output-gain", &iref))
> + iref = PCA995X_IREFALL_HALF_CFG;
> + else if (iref > PCA995X_IREFALL_FULL_CFG)
> + return dev_err_probe(dev, -EINVAL, "invalid nxp,output-gain\n");

As clever as is this, it's not that easy to follow.

I'd prefer:

u32 iref = PCA995X_IREFALL_HALF_CFG;

ret = device_property_read_u32(...);
if (!ret) {
if (val > PCA995X_IREFALL_FULL_CFG)
return dev_err_probe(dev, -EINVAL, "output-gain is out of range\n");
iref = val;
}

> device_for_each_child_node_scoped(dev, child) {
> ret = fwnode_property_read_u32(child, "reg", &reg);
> if (ret)
> @@ -196,7 +202,7 @@ static int pca995x_probe(struct i2c_client *client)
> return ret;
>
> /* IREF Output current value for all LEDn outputs */
> - return regmap_write(chip->regmap, chipdef->irefall, PCA995X_IREFALL_HALF_CFG);
> + return regmap_write(chip->regmap, chipdef->irefall, iref);
> }
>
> static const struct i2c_device_id pca995x_id[] = {
> --
> TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
> Amtsgericht München, HRB 105018
> Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
> https://www.tq-group.com/

--
Lee Jones