diff mbox series

[leds,7/7] leds: pca963x: use struct led_init_data when registering

Message ID 20200920002500.5851-8-marek.behun@nic.cz
State New
Headers show
Series leds: pca963x cleanup | expand

Commit Message

Marek BehĂșn Sept. 20, 2020, 12:25 a.m. UTC
By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Previously if the `label` DT property was not present, the code composed
name for the LED in the form
  "pca963x:%d:%.2x:%u"
For backwards compatibility we therefore set init_data->default_label
to this value so that the LED will not get a different name if `label`
property is not present, nor are `color` and `function`.

Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Cc: Peter Meerwald <p.meerwald@bct-electronic.com>
Cc: Ricardo Ribalda <ribalda@kernel.org>
Cc: Zahari Petkov <zahari@balena.io>
---
 drivers/leds/leds-pca963x.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

Comments

Pavel Machek Sept. 30, 2020, 5:04 p.m. UTC | #1
Hi!

> By using struct led_init_data when registering we do not need to parse
> `label` DT property. Moreover `label` is deprecated and if it is not
> present but `color` and `function` are, LED core will compose a name
> from these properties instead.
> 
> Previously if the `label` DT property was not present, the code composed
> name for the LED in the form
>   "pca963x:%d:%.2x:%u"
> For backwards compatibility we therefore set init_data->default_label
> to this value so that the LED will not get a different name if `label`
> property is not present, nor are `color` and `function`.

I took patches 6 and 7 of the series.

Thanks,
									Pavel
diff mbox series

Patch

diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 5083ccce1a519..00aecd67e3483 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -289,8 +289,6 @@  static int pca963x_register_leds(struct i2c_client *client,
 	struct pca963x_led *led = chip->leds;
 	struct device *dev = &client->dev;
 	struct fwnode_handle *child;
-	const char *name;
-	char label[64];
 	bool hw_blink;
 	s32 mode2;
 	u32 reg;
@@ -323,6 +321,9 @@  static int pca963x_register_leds(struct i2c_client *client,
 		return ret;
 
 	device_for_each_child_node(dev, child) {
+		struct led_init_data init_data = {};
+		char default_label[32];
+
 		ret = fwnode_property_read_u32(child, "reg", &reg);
 		if (ret || reg >= chipdef->n_leds) {
 			dev_err(dev, "Invalid 'reg' property for node %pfw\n",
@@ -331,23 +332,21 @@  static int pca963x_register_leds(struct i2c_client *client,
 			goto err;
 		}
 
-		ret = fwnode_property_read_string(child, "label", &name);
-		if (!fwnode_property_read_string(child, "label", &name))
-			snprintf(label, sizeof(label), "pca963x:%s", name);
-		else
-			snprintf(label, sizeof(label), "pca963x::");
-
-		fwnode_property_read_string(child, "linux,default-trigger",
-					    &led->led_cdev.default_trigger);
-
 		led->led_num = reg;
 		led->chip = chip;
-		led->led_cdev.name = label;
 		led->led_cdev.brightness_set_blocking = pca963x_led_set;
 		if (hw_blink)
 			led->led_cdev.blink_set = pca963x_blink_set;
 
-		ret = devm_led_classdev_register(dev, &led->led_cdev);
+		init_data.fwnode = child;
+		/* for backwards compatibility */
+		init_data.devicename = "pca963x";
+		snprintf(default_label, sizeof(default_label), "%d:%.2x:%u",
+			 client->adapter->nr, client->addr, reg);
+		init_data.default_label = default_label;
+
+		ret = devm_led_classdev_register_ext(dev, &led->led_cdev,
+						     &init_data);
 		if (ret) {
 			dev_err(dev, "Failed to register LED for node %pfw\n",
 				child);