[PATCH v2 4/4] leds: lp50xx: add setting of default intensity from DT

From: Sven Schuchmann
Date: Thu Feb 04 2021 - 09:44:51 EST


In order to use a multicolor-led together with a trigger
the led needs to have an intensity set to see something.
The trigger changes the brightness of the led but if there
is no intensity we actually see nothing.

This patch adds the ability to set the default intensity
of each multi-led node so that it is turned on from DT.
If no intensity is given the led will be initialized
with full intensity.

Part 1 updates the documentation.
Part 2 removes an unused variable.
Part 3 sets the initial intensity to full.
Part 4 reads the default intensity from DT

changes in v1
- fix dt_binding_check errors

changes in v2
- sets default intensity to full
- adds the property to the multi-led node

Signed-off-by: Sven Schuchmann <schuchmann@xxxxxxxxxxxxxxxxx>
---
drivers/leds/leds-lp50xx.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 79bc071c31fb..e8aa36c7e963 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -504,6 +504,24 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
num_colors++;
}

+ if (fwnode_property_count_u32(child, "default-intensity")
+ == num_colors) {
+
+ int j, def_int[LP50XX_LEDS_PER_MODULE];
+
+ ret = fwnode_property_read_u32_array(child,
+ "default-intensity", def_int, num_colors);
+ if (ret) {
+ dev_err(&priv->client->dev,
+ "Cannot read default-intensity: %d\n",
+ ret);
+ goto child_out;
+ }
+
+ for (j = 0; j < num_colors; j++)
+ mc_led_info[j].intensity = def_int[j];
+ }
+
led->priv = priv;
led->mc_cdev.num_colors = num_colors;
led->mc_cdev.subled_info = mc_led_info;
--
2.17.1