summaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lm36274.c
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2020-09-19 20:02:58 +0200
committerPavel Machek <pavel@ucw.cz>2020-09-26 21:56:43 +0200
commit1aeef38c6a4a87d04bf5fc596dbf91a15525c987 (patch)
tree29a7e8c218cbe8cbe00b930343b8367c1400d7a5 /drivers/leds/leds-lm36274.c
parenta448fcf19c9c5d3ddd9066accbd8d28c4950bb9f (diff)
downloadlinux-1aeef38c6a4a87d04bf5fc596dbf91a15525c987.tar.gz
linux-1aeef38c6a4a87d04bf5fc596dbf91a15525c987.tar.bz2
linux-1aeef38c6a4a87d04bf5fc596dbf91a15525c987.zip
leds: lm36274: use struct led_init_data when registering
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 "parent_name::" For backwards compatibility we therefore set init_data->default_label = ":"; 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> Tested-by: Dan Murphy <dmurphy@ti.com> Signed-off-by: Pavel Machek <pavel@ucw.cz>
Diffstat (limited to 'drivers/leds/leds-lm36274.c')
-rw-r--r--drivers/leds/leds-lm36274.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index e0fce74a7667..ee4f90f04f19 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -66,12 +66,11 @@ static int lm36274_init(struct lm36274 *chip)
return regmap_write(chip->regmap, LM36274_REG_BL_EN, enable_val);
}
-static int lm36274_parse_dt(struct lm36274 *chip)
+static int lm36274_parse_dt(struct lm36274 *chip,
+ struct led_init_data *init_data)
{
- struct fwnode_handle *child = NULL;
- char label[LED_MAX_NAME_SIZE];
struct device *dev = &chip->pdev->dev;
- const char *name;
+ struct fwnode_handle *child;
int ret;
/* There should only be 1 node */
@@ -80,43 +79,45 @@ static int lm36274_parse_dt(struct lm36274 *chip)
child = device_get_next_child_node(dev, NULL);
- ret = fwnode_property_read_string(child, "label", &name);
- if (ret)
- snprintf(label, sizeof(label), "%s::", chip->pdev->name);
- else
- snprintf(label, sizeof(label), "%s:%s", chip->pdev->name, name);
+ init_data->fwnode = child;
+ init_data->devicename = chip->pdev->name;
+ /* for backwards compatibility when `label` property is not present */
+ init_data->default_label = ":";
chip->num_leds = fwnode_property_count_u32(child, "led-sources");
- if (chip->num_leds <= 0)
- return -ENODEV;
+ if (chip->num_leds <= 0) {
+ ret = -ENODEV;
+ goto err;
+ }
ret = fwnode_property_read_u32_array(child, "led-sources",
chip->led_sources, chip->num_leds);
if (ret) {
dev_err(dev, "led-sources property missing\n");
- return ret;
+ goto err;
}
fwnode_property_read_string(child, "linux,default-trigger",
&chip->led_dev.default_trigger);
- fwnode_handle_put(child);
-
chip->lmu_data.regmap = chip->regmap;
chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
chip->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;
- chip->led_dev.name = label;
chip->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT;
chip->led_dev.brightness_set_blocking = lm36274_brightness_set;
return 0;
+err:
+ fwnode_handle_put(child);
+ return ret;
}
static int lm36274_probe(struct platform_device *pdev)
{
struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
+ struct led_init_data init_data = {};
struct lm36274 *chip;
int ret;
@@ -129,7 +130,7 @@ static int lm36274_probe(struct platform_device *pdev)
chip->regmap = lmu->regmap;
platform_set_drvdata(pdev, chip);
- ret = lm36274_parse_dt(chip);
+ ret = lm36274_parse_dt(chip, &init_data);
if (ret) {
dev_err(chip->dev, "Failed to parse DT node\n");
return ret;
@@ -141,7 +142,14 @@ static int lm36274_probe(struct platform_device *pdev)
return ret;
}
- return led_classdev_register(chip->dev, &chip->led_dev);
+ ret = led_classdev_register_ext(chip->dev, &chip->led_dev, &init_data);
+ if (ret)
+ dev_err(chip->dev, "Failed to register LED for node %pfw\n",
+ init_data.fwnode);
+
+ fwnode_handle_put(init_data.fwnode);
+
+ return ret;
}
static int lm36274_remove(struct platform_device *pdev)