Skip to content

Commit 265d313

Browse files
andy-shevlag-linaro
authored andcommitted
leds: syscon: Get rid of custom led_init_default_state_get()
LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Lee Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bf8a9a7 commit 265d313

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

drivers/leds/leds-syscon.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ static int syscon_led_probe(struct platform_device *pdev)
6161
struct device *parent;
6262
struct regmap *map;
6363
struct syscon_led *sled;
64-
const char *state;
64+
enum led_default_state state;
65+
u32 value;
6566
int ret;
6667

6768
parent = dev->parent;
@@ -86,34 +87,30 @@ static int syscon_led_probe(struct platform_device *pdev)
8687
if (of_property_read_u32(np, "mask", &sled->mask))
8788
return -EINVAL;
8889

89-
state = of_get_property(np, "default-state", NULL);
90-
if (state) {
91-
if (!strcmp(state, "keep")) {
92-
u32 val;
93-
94-
ret = regmap_read(map, sled->offset, &val);
95-
if (ret < 0)
96-
return ret;
97-
sled->state = !!(val & sled->mask);
98-
} else if (!strcmp(state, "on")) {
99-
sled->state = true;
100-
ret = regmap_update_bits(map, sled->offset,
101-
sled->mask,
102-
sled->mask);
103-
if (ret < 0)
104-
return ret;
105-
} else {
106-
sled->state = false;
107-
ret = regmap_update_bits(map, sled->offset,
108-
sled->mask, 0);
109-
if (ret < 0)
110-
return ret;
111-
}
90+
init_data.fwnode = of_fwnode_handle(np);
91+
92+
state = led_init_default_state_get(init_data.fwnode);
93+
switch (state) {
94+
case LEDS_DEFSTATE_ON:
95+
ret = regmap_update_bits(map, sled->offset, sled->mask, sled->mask);
96+
if (ret < 0)
97+
return ret;
98+
sled->state = true;
99+
break;
100+
case LEDS_DEFSTATE_KEEP:
101+
ret = regmap_read(map, sled->offset, &value);
102+
if (ret < 0)
103+
return ret;
104+
sled->state = !!(value & sled->mask);
105+
break;
106+
default:
107+
ret = regmap_update_bits(map, sled->offset, sled->mask, 0);
108+
if (ret < 0)
109+
return ret;
110+
sled->state = false;
112111
}
113112
sled->cdev.brightness_set = syscon_led_set;
114113

115-
init_data.fwnode = of_fwnode_handle(np);
116-
117114
ret = devm_led_classdev_register_ext(dev, &sled->cdev, &init_data);
118115
if (ret < 0)
119116
return ret;

0 commit comments

Comments
 (0)