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>
This commit is contained in:
parent
a448fcf19c
commit
1aeef38c6a
1 changed files with 25 additions and 17 deletions
|
@ -66,12 +66,11 @@ static int lm36274_init(struct lm36274 *chip)
|
||||||
return regmap_write(chip->regmap, LM36274_REG_BL_EN, enable_val);
|
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;
|
struct device *dev = &chip->pdev->dev;
|
||||||
const char *name;
|
struct fwnode_handle *child;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* There should only be 1 node */
|
/* 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);
|
child = device_get_next_child_node(dev, NULL);
|
||||||
|
|
||||||
ret = fwnode_property_read_string(child, "label", &name);
|
init_data->fwnode = child;
|
||||||
if (ret)
|
init_data->devicename = chip->pdev->name;
|
||||||
snprintf(label, sizeof(label), "%s::", chip->pdev->name);
|
/* for backwards compatibility when `label` property is not present */
|
||||||
else
|
init_data->default_label = ":";
|
||||||
snprintf(label, sizeof(label), "%s:%s", chip->pdev->name, name);
|
|
||||||
|
|
||||||
chip->num_leds = fwnode_property_count_u32(child, "led-sources");
|
chip->num_leds = fwnode_property_count_u32(child, "led-sources");
|
||||||
if (chip->num_leds <= 0)
|
if (chip->num_leds <= 0) {
|
||||||
return -ENODEV;
|
ret = -ENODEV;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
ret = fwnode_property_read_u32_array(child, "led-sources",
|
ret = fwnode_property_read_u32_array(child, "led-sources",
|
||||||
chip->led_sources, chip->num_leds);
|
chip->led_sources, chip->num_leds);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "led-sources property missing\n");
|
dev_err(dev, "led-sources property missing\n");
|
||||||
return ret;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwnode_property_read_string(child, "linux,default-trigger",
|
fwnode_property_read_string(child, "linux,default-trigger",
|
||||||
&chip->led_dev.default_trigger);
|
&chip->led_dev.default_trigger);
|
||||||
|
|
||||||
fwnode_handle_put(child);
|
|
||||||
|
|
||||||
chip->lmu_data.regmap = chip->regmap;
|
chip->lmu_data.regmap = chip->regmap;
|
||||||
chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
|
chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
|
||||||
chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
|
chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
|
||||||
chip->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;
|
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.max_brightness = MAX_BRIGHTNESS_11BIT;
|
||||||
chip->led_dev.brightness_set_blocking = lm36274_brightness_set;
|
chip->led_dev.brightness_set_blocking = lm36274_brightness_set;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
err:
|
||||||
|
fwnode_handle_put(child);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lm36274_probe(struct platform_device *pdev)
|
static int lm36274_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
|
struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
|
||||||
|
struct led_init_data init_data = {};
|
||||||
struct lm36274 *chip;
|
struct lm36274 *chip;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ static int lm36274_probe(struct platform_device *pdev)
|
||||||
chip->regmap = lmu->regmap;
|
chip->regmap = lmu->regmap;
|
||||||
platform_set_drvdata(pdev, chip);
|
platform_set_drvdata(pdev, chip);
|
||||||
|
|
||||||
ret = lm36274_parse_dt(chip);
|
ret = lm36274_parse_dt(chip, &init_data);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(chip->dev, "Failed to parse DT node\n");
|
dev_err(chip->dev, "Failed to parse DT node\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -141,7 +142,14 @@ static int lm36274_probe(struct platform_device *pdev)
|
||||||
return ret;
|
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)
|
static int lm36274_remove(struct platform_device *pdev)
|
||||||
|
|
Loading…
Add table
Reference in a new issue