From 564ead1280d7590f0015d8225637d546e9fa94eb Mon Sep 17 00:00:00 2001 From: Marek BehĂșn Date: Sun, 20 Sep 2020 02:25:00 +0200 Subject: leds: pca963x: use struct led_init_data when registering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Peter Meerwald Cc: Ricardo Ribalda Cc: Zahari Petkov Signed-off-by: Pavel Machek --- drivers/leds/leds-pca963x.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'drivers/leds/leds-pca963x.c') diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c index 5083ccce1a51..00aecd67e348 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", ®); 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); -- cgit v1.2.3