hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/leds/leds-tlc591xx.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2014 Belkin Inc.
34 * Copyright 2015 Andrew Lunn <andrew@lunn.ch>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; version 2 of the License.
85 */
96
107 #include <linux/i2c.h>
....@@ -16,6 +13,7 @@
1613 #include <linux/slab.h>
1714
1815 #define TLC591XX_MAX_LEDS 16
16
+#define TLC591XX_MAX_BRIGHTNESS 256
1917
2018 #define TLC591XX_REG_MODE1 0x00
2119 #define MODE1_RESPON_ADDR_MASK 0xF0
....@@ -115,11 +113,11 @@
115113 struct tlc591xx_priv *priv = led->priv;
116114 int err;
117115
118
- switch (brightness) {
116
+ switch ((int)brightness) {
119117 case 0:
120118 err = tlc591xx_set_ledout(priv, led, LEDOUT_OFF);
121119 break;
122
- case LED_FULL:
120
+ case TLC591XX_MAX_BRIGHTNESS:
123121 err = tlc591xx_set_ledout(priv, led, LEDOUT_ON);
124122 break;
125123 default:
....@@ -128,51 +126,6 @@
128126 err = tlc591xx_set_pwm(priv, led, brightness);
129127 }
130128
131
- return err;
132
-}
133
-
134
-static void
135
-tlc591xx_destroy_devices(struct tlc591xx_priv *priv, unsigned int j)
136
-{
137
- int i = j;
138
-
139
- while (--i >= 0) {
140
- if (priv->leds[i].active)
141
- led_classdev_unregister(&priv->leds[i].ldev);
142
- }
143
-}
144
-
145
-static int
146
-tlc591xx_configure(struct device *dev,
147
- struct tlc591xx_priv *priv,
148
- const struct tlc591xx *tlc591xx)
149
-{
150
- unsigned int i;
151
- int err = 0;
152
-
153
- tlc591xx_set_mode(priv->regmap, MODE2_DIM);
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);
176129 return err;
177130 }
178131
....@@ -195,22 +148,21 @@
195148 tlc591xx_probe(struct i2c_client *client,
196149 const struct i2c_device_id *id)
197150 {
198
- struct device_node *np = client->dev.of_node, *child;
151
+ struct device_node *np, *child;
199152 struct device *dev = &client->dev;
200
- const struct of_device_id *match;
201153 const struct tlc591xx *tlc591xx;
202154 struct tlc591xx_priv *priv;
203155 int err, count, reg;
204156
205
- match = of_match_device(of_tlc591xx_leds_match, dev);
206
- if (!match)
207
- return -ENODEV;
208
-
209
- tlc591xx = match->data;
157
+ np = dev_of_node(dev);
210158 if (!np)
211159 return -ENODEV;
212160
213
- count = of_get_child_count(np);
161
+ tlc591xx = device_get_match_data(dev);
162
+ if (!tlc591xx)
163
+ return -ENODEV;
164
+
165
+ count = of_get_available_child_count(np);
214166 if (!count || count > tlc591xx->max_leds)
215167 return -EINVAL;
216168
....@@ -228,7 +180,16 @@
228180
229181 i2c_set_clientdata(client, priv);
230182
231
- for_each_child_of_node(np, child) {
183
+ err = tlc591xx_set_mode(priv->regmap, MODE2_DIM);
184
+ if (err < 0)
185
+ return err;
186
+
187
+ for_each_available_child_of_node(np, child) {
188
+ struct tlc591xx_led *led;
189
+ struct led_init_data init_data = {};
190
+
191
+ init_data.fwnode = of_fwnode_handle(child);
192
+
232193 err = of_property_read_u32(child, "reg", &reg);
233194 if (err) {
234195 of_node_put(child);
....@@ -239,22 +200,22 @@
239200 of_node_put(child);
240201 return -EINVAL;
241202 }
242
- priv->leds[reg].active = true;
243
- priv->leds[reg].ldev.name =
244
- of_get_property(child, "label", NULL) ? : child->name;
245
- priv->leds[reg].ldev.default_trigger =
246
- of_get_property(child, "linux,default-trigger", NULL);
203
+ led = &priv->leds[reg];
204
+
205
+ led->active = true;
206
+ led->priv = priv;
207
+ led->led_no = reg;
208
+ led->ldev.brightness_set_blocking = tlc591xx_brightness_set;
209
+ led->ldev.max_brightness = TLC591XX_MAX_BRIGHTNESS;
210
+ err = devm_led_classdev_register_ext(dev, &led->ldev,
211
+ &init_data);
212
+ if (err < 0) {
213
+ of_node_put(child);
214
+ return dev_err_probe(dev, err,
215
+ "couldn't register LED %s\n",
216
+ led->ldev.name);
217
+ }
247218 }
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);
257
-
258219 return 0;
259220 }
260221
....@@ -271,7 +232,6 @@
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