Skip to content

Commit 1ab4531

Browse files
Jean-Jacques Hiblotpavelmachek
authored andcommitted
leds: tlc591xx: simplify driver by using the managed led API
Use the managed API of the LED class (devm_led_classdev_register() instead of led_classdev_register()). This allows us to remove the code used to track-and-destroy the LED devices. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Signed-off-by: Pavel Machek <pavel@ucw.cz>
1 parent 8b4423d commit 1ab4531

1 file changed

Lines changed: 22 additions & 62 deletions

File tree

‎drivers/leds/leds-tlc591xx.c‎

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -128,54 +128,6 @@ tlc591xx_brightness_set(struct led_classdev *led_cdev,
128128
return err;
129129
}
130130

131-
static void
132-
tlc591xx_destroy_devices(struct tlc591xx_priv *priv, unsigned int j)
133-
{
134-
int i = j;
135-
136-
while (--i >= 0) {
137-
if (priv->leds[i].active)
138-
led_classdev_unregister(&priv->leds[i].ldev);
139-
}
140-
}
141-
142-
static int
143-
tlc591xx_configure(struct device *dev,
144-
struct tlc591xx_priv *priv,
145-
const struct tlc591xx *tlc591xx)
146-
{
147-
unsigned int i;
148-
int err = 0;
149-
150-
err = tlc591xx_set_mode(priv->regmap, MODE2_DIM);
151-
if (err < 0)
152-
return err;
153-
154-
for (i = 0; i < TLC591XX_MAX_LEDS; i++) {
155-
struct tlc591xx_led *led = &priv->leds[i];
156-
157-
if (!led->active)
158-
continue;
159-
160-
led->priv = priv;
161-
led->led_no = i;
162-
led->ldev.brightness_set_blocking = tlc591xx_brightness_set;
163-
led->ldev.max_brightness = LED_FULL;
164-
err = led_classdev_register(dev, &led->ldev);
165-
if (err < 0) {
166-
dev_err(dev, "couldn't register LED %s\n",
167-
led->ldev.name);
168-
goto exit;
169-
}
170-
}
171-
172-
return 0;
173-
174-
exit:
175-
tlc591xx_destroy_devices(priv, i);
176-
return err;
177-
}
178-
179131
static const struct regmap_config tlc591xx_regmap = {
180132
.reg_bits = 8,
181133
.val_bits = 8,
@@ -228,7 +180,13 @@ tlc591xx_probe(struct i2c_client *client,
228180

229181
i2c_set_clientdata(client, priv);
230182

183+
err = tlc591xx_set_mode(priv->regmap, MODE2_DIM);
184+
if (err < 0)
185+
return err;
186+
231187
for_each_child_of_node(np, child) {
188+
struct tlc591xx_led *led;
189+
232190
err = of_property_read_u32(child, "reg", &reg);
233191
if (err) {
234192
of_node_put(child);
@@ -239,22 +197,25 @@ tlc591xx_probe(struct i2c_client *client,
239197
of_node_put(child);
240198
return -EINVAL;
241199
}
242-
priv->leds[reg].active = true;
243-
priv->leds[reg].ldev.name =
200+
led = &priv->leds[reg];
201+
202+
led->active = true;
203+
led->ldev.name =
244204
of_get_property(child, "label", NULL) ? : child->name;
245-
priv->leds[reg].ldev.default_trigger =
205+
led->ldev.default_trigger =
246206
of_get_property(child, "linux,default-trigger", NULL);
247-
}
248-
return tlc591xx_configure(dev, priv, tlc591xx);
249-
}
250-
251-
static int
252-
tlc591xx_remove(struct i2c_client *client)
253-
{
254-
struct tlc591xx_priv *priv = i2c_get_clientdata(client);
255-
256-
tlc591xx_destroy_devices(priv, TLC591XX_MAX_LEDS);
257207

208+
led->priv = priv;
209+
led->led_no = reg;
210+
led->ldev.brightness_set_blocking = tlc591xx_brightness_set;
211+
led->ldev.max_brightness = LED_FULL;
212+
err = devm_led_classdev_register(dev, &led->ldev);
213+
if (err < 0) {
214+
dev_err(dev, "couldn't register LED %s\n",
215+
led->ldev.name);
216+
return err;
217+
}
218+
}
258219
return 0;
259220
}
260221

@@ -271,7 +232,6 @@ static struct i2c_driver tlc591xx_driver = {
271232
.of_match_table = of_match_ptr(of_tlc591xx_leds_match),
272233
},
273234
.probe = tlc591xx_probe,
274-
.remove = tlc591xx_remove,
275235
.id_table = tlc591xx_id,
276236
};
277237

0 commit comments

Comments
 (0)