xref: /linux/drivers/leds/leds-lp50xx.c (revision 41f7adb676f6c4aef439d78b15c7e1119216bc2b)
1 // SPDX-License-Identifier: GPL-2.0
2 // TI LP50XX LED chip family driver
3 // Copyright (C) 2018-20 Texas Instruments Incorporated - https://www.ti.com/
4 
5 #include <linux/gpio/consumer.h>
6 #include <linux/i2c.h>
7 #include <linux/init.h>
8 #include <linux/leds.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/module.h>
11 #include <linux/mutex.h>
12 #include <linux/regmap.h>
13 #include <linux/regulator/consumer.h>
14 #include <linux/slab.h>
15 #include <uapi/linux/uleds.h>
16 
17 #include <linux/led-class-multicolor.h>
18 
19 #include "leds.h"
20 
21 #define LP50XX_DEV_CFG0		0x00
22 #define LP50XX_DEV_CFG1		0x01
23 #define LP50XX_LED_CFG0		0x02
24 
25 /* LP5009 and LP5012 registers */
26 #define LP5012_BNK_BRT		0x03
27 #define LP5012_BNKA_CLR		0x04
28 #define LP5012_BNKB_CLR		0x05
29 #define LP5012_BNKC_CLR		0x06
30 #define LP5012_LED0_BRT		0x07
31 #define LP5012_OUT0_CLR		0x0b
32 #define LP5012_RESET		0x17
33 
34 /* LP5018 and LP5024 registers */
35 #define LP5024_BNK_BRT		0x03
36 #define LP5024_BNKA_CLR		0x04
37 #define LP5024_BNKB_CLR		0x05
38 #define LP5024_BNKC_CLR		0x06
39 #define LP5024_LED0_BRT		0x07
40 #define LP5024_OUT0_CLR		0x0f
41 #define LP5024_RESET		0x27
42 
43 /* LP5030 and LP5036 registers */
44 #define LP5036_LED_CFG1		0x03
45 #define LP5036_BNK_BRT		0x04
46 #define LP5036_BNKA_CLR		0x05
47 #define LP5036_BNKB_CLR		0x06
48 #define LP5036_BNKC_CLR		0x07
49 #define LP5036_LED0_BRT		0x08
50 #define LP5036_OUT0_CLR		0x14
51 #define LP5036_RESET		0x38
52 
53 #define LP50XX_SW_RESET		0xff
54 #define LP50XX_CHIP_EN		BIT(6)
55 
56 /* There are 3 LED outputs per bank */
57 #define LP50XX_LEDS_PER_MODULE	3
58 
59 #define LP5009_MAX_LED_MODULES	2
60 #define LP5012_MAX_LED_MODULES	4
61 #define LP5018_MAX_LED_MODULES	6
62 #define LP5024_MAX_LED_MODULES	8
63 #define LP5030_MAX_LED_MODULES	10
64 #define LP5036_MAX_LED_MODULES	12
65 
66 static const struct reg_default lp5012_reg_defs[] = {
67 	{LP50XX_DEV_CFG0, 0x0},
68 	{LP50XX_DEV_CFG1, 0x3c},
69 	{LP50XX_LED_CFG0, 0x0},
70 	{LP5012_BNK_BRT, 0xff},
71 	{LP5012_BNKA_CLR, 0x0f},
72 	{LP5012_BNKB_CLR, 0x0f},
73 	{LP5012_BNKC_CLR, 0x0f},
74 	{LP5012_LED0_BRT, 0x0f},
75 	/* LEDX_BRT registers are all 0xff for defaults */
76 	{0x08, 0xff}, {0x09, 0xff}, {0x0a, 0xff},
77 	{LP5012_OUT0_CLR, 0x0f},
78 	/* OUTX_CLR registers are all 0x0 for defaults */
79 	{0x0c, 0x00}, {0x0d, 0x00}, {0x0e, 0x00}, {0x0f, 0x00}, {0x10, 0x00},
80 	{0x11, 0x00}, {0x12, 0x00}, {0x13, 0x00}, {0x14, 0x00},	{0x15, 0x00},
81 	{0x16, 0x00},
82 	{LP5012_RESET, 0x00}
83 };
84 
85 static const struct reg_default lp5024_reg_defs[] = {
86 	{LP50XX_DEV_CFG0, 0x0},
87 	{LP50XX_DEV_CFG1, 0x3c},
88 	{LP50XX_LED_CFG0, 0x0},
89 	{LP5024_BNK_BRT, 0xff},
90 	{LP5024_BNKA_CLR, 0x0f},
91 	{LP5024_BNKB_CLR, 0x0f},
92 	{LP5024_BNKC_CLR, 0x0f},
93 	{LP5024_LED0_BRT, 0x0f},
94 	/* LEDX_BRT registers are all 0xff for defaults */
95 	{0x08, 0xff}, {0x09, 0xff}, {0x0a, 0xff}, {0x0b, 0xff}, {0x0c, 0xff},
96 	{0x0d, 0xff}, {0x0e, 0xff},
97 	{LP5024_OUT0_CLR, 0x0f},
98 	/* OUTX_CLR registers are all 0x0 for defaults */
99 	{0x10, 0x00}, {0x11, 0x00}, {0x12, 0x00}, {0x13, 0x00}, {0x14, 0x00},
100 	{0x15, 0x00}, {0x16, 0x00}, {0x17, 0x00}, {0x18, 0x00}, {0x19, 0x00},
101 	{0x1a, 0x00}, {0x1b, 0x00}, {0x1c, 0x00}, {0x1d, 0x00}, {0x1e, 0x00},
102 	{0x1f, 0x00}, {0x20, 0x00}, {0x21, 0x00}, {0x22, 0x00}, {0x23, 0x00},
103 	{0x24, 0x00}, {0x25, 0x00}, {0x26, 0x00},
104 	{LP5024_RESET, 0x00}
105 };
106 
107 static const struct reg_default lp5036_reg_defs[] = {
108 	{LP50XX_DEV_CFG0, 0x0},
109 	{LP50XX_DEV_CFG1, 0x3c},
110 	{LP50XX_LED_CFG0, 0x0},
111 	{LP5036_LED_CFG1, 0x0},
112 	{LP5036_BNK_BRT, 0xff},
113 	{LP5036_BNKA_CLR, 0x0f},
114 	{LP5036_BNKB_CLR, 0x0f},
115 	{LP5036_BNKC_CLR, 0x0f},
116 	{LP5036_LED0_BRT, 0x0f},
117 	/* LEDX_BRT registers are all 0xff for defaults */
118 	{0x08, 0xff}, {0x09, 0xff}, {0x0a, 0xff}, {0x0b, 0xff}, {0x0c, 0xff},
119 	{0x0d, 0xff}, {0x0e, 0xff}, {0x0f, 0xff}, {0x10, 0xff}, {0x11, 0xff},
120 	{0x12, 0xff}, {0x13, 0xff},
121 	{LP5036_OUT0_CLR, 0x0f},
122 	/* OUTX_CLR registers are all 0x0 for defaults */
123 	{0x15, 0x00}, {0x16, 0x00}, {0x17, 0x00}, {0x18, 0x00}, {0x19, 0x00},
124 	{0x1a, 0x00}, {0x1b, 0x00}, {0x1c, 0x00}, {0x1d, 0x00}, {0x1e, 0x00},
125 	{0x1f, 0x00}, {0x20, 0x00}, {0x21, 0x00}, {0x22, 0x00}, {0x23, 0x00},
126 	{0x24, 0x00}, {0x25, 0x00}, {0x26, 0x00}, {0x27, 0x00}, {0x28, 0x00},
127 	{0x29, 0x00}, {0x2a, 0x00}, {0x2b, 0x00}, {0x2c, 0x00}, {0x2d, 0x00},
128 	{0x2e, 0x00}, {0x2f, 0x00}, {0x30, 0x00}, {0x31, 0x00}, {0x32, 0x00},
129 	{0x33, 0x00}, {0x34, 0x00}, {0x35, 0x00}, {0x36, 0x00}, {0x37, 0x00},
130 	{LP5036_RESET, 0x00}
131 };
132 
133 static const struct regmap_config lp5012_regmap_config = {
134 	.reg_bits = 8,
135 	.val_bits = 8,
136 
137 	.max_register = LP5012_RESET,
138 	.reg_defaults = lp5012_reg_defs,
139 	.num_reg_defaults = ARRAY_SIZE(lp5012_reg_defs),
140 	.cache_type = REGCACHE_FLAT,
141 };
142 
143 static const struct regmap_config lp5024_regmap_config = {
144 	.reg_bits = 8,
145 	.val_bits = 8,
146 
147 	.max_register = LP5024_RESET,
148 	.reg_defaults = lp5024_reg_defs,
149 	.num_reg_defaults = ARRAY_SIZE(lp5024_reg_defs),
150 	.cache_type = REGCACHE_FLAT,
151 };
152 
153 static const struct regmap_config lp5036_regmap_config = {
154 	.reg_bits = 8,
155 	.val_bits = 8,
156 
157 	.max_register = LP5036_RESET,
158 	.reg_defaults = lp5036_reg_defs,
159 	.num_reg_defaults = ARRAY_SIZE(lp5036_reg_defs),
160 	.cache_type = REGCACHE_FLAT,
161 };
162 
163 enum lp50xx_model {
164 	LP5009,
165 	LP5012,
166 	LP5018,
167 	LP5024,
168 	LP5030,
169 	LP5036,
170 };
171 
172 /**
173  * struct lp50xx_chip_info -
174  * @lp50xx_regmap_config: regmap register configuration
175  * @model_id: LED device model
176  * @max_modules: total number of supported LED modules
177  * @num_leds: number of LED outputs available on the device
178  * @led_brightness0_reg: first brightness register of the device
179  * @mix_out0_reg: first color mix register of the device
180  * @bank_brt_reg: bank brightness register
181  * @bank_mix_reg: color mix register
182  * @reset_reg: device reset register
183  */
184 struct lp50xx_chip_info {
185 	const struct regmap_config *lp50xx_regmap_config;
186 	int model_id;
187 	u8 max_modules;
188 	u8 num_leds;
189 	u8 led_brightness0_reg;
190 	u8 mix_out0_reg;
191 	u8 bank_brt_reg;
192 	u8 bank_mix_reg;
193 	u8 reset_reg;
194 };
195 
196 static const struct lp50xx_chip_info lp50xx_chip_info_tbl[] = {
197 	[LP5009] = {
198 		.model_id = LP5009,
199 		.max_modules = LP5009_MAX_LED_MODULES,
200 		.num_leds = LP5009_MAX_LED_MODULES * LP50XX_LEDS_PER_MODULE,
201 		.led_brightness0_reg = LP5012_LED0_BRT,
202 		.mix_out0_reg = LP5012_OUT0_CLR,
203 		.bank_brt_reg = LP5012_BNK_BRT,
204 		.bank_mix_reg = LP5012_BNKA_CLR,
205 		.reset_reg = LP5012_RESET,
206 		.lp50xx_regmap_config = &lp5012_regmap_config,
207 	},
208 	[LP5012] = {
209 		.model_id = LP5012,
210 		.max_modules = LP5012_MAX_LED_MODULES,
211 		.num_leds = LP5012_MAX_LED_MODULES * LP50XX_LEDS_PER_MODULE,
212 		.led_brightness0_reg = LP5012_LED0_BRT,
213 		.mix_out0_reg = LP5012_OUT0_CLR,
214 		.bank_brt_reg = LP5012_BNK_BRT,
215 		.bank_mix_reg = LP5012_BNKA_CLR,
216 		.reset_reg = LP5012_RESET,
217 		.lp50xx_regmap_config = &lp5012_regmap_config,
218 	},
219 	[LP5018] = {
220 		.model_id = LP5018,
221 		.max_modules = LP5018_MAX_LED_MODULES,
222 		.num_leds = LP5018_MAX_LED_MODULES * LP50XX_LEDS_PER_MODULE,
223 		.led_brightness0_reg = LP5024_LED0_BRT,
224 		.mix_out0_reg = LP5024_OUT0_CLR,
225 		.bank_brt_reg = LP5024_BNK_BRT,
226 		.bank_mix_reg = LP5024_BNKA_CLR,
227 		.reset_reg = LP5024_RESET,
228 		.lp50xx_regmap_config = &lp5024_regmap_config,
229 	},
230 	[LP5024] = {
231 		.model_id = LP5024,
232 		.max_modules = LP5024_MAX_LED_MODULES,
233 		.num_leds = LP5024_MAX_LED_MODULES * LP50XX_LEDS_PER_MODULE,
234 		.led_brightness0_reg = LP5024_LED0_BRT,
235 		.mix_out0_reg = LP5024_OUT0_CLR,
236 		.bank_brt_reg = LP5024_BNK_BRT,
237 		.bank_mix_reg = LP5024_BNKA_CLR,
238 		.reset_reg = LP5024_RESET,
239 		.lp50xx_regmap_config = &lp5024_regmap_config,
240 	},
241 	[LP5030] = {
242 		.model_id = LP5030,
243 		.max_modules = LP5030_MAX_LED_MODULES,
244 		.num_leds = LP5030_MAX_LED_MODULES * LP50XX_LEDS_PER_MODULE,
245 		.led_brightness0_reg = LP5036_LED0_BRT,
246 		.mix_out0_reg = LP5036_OUT0_CLR,
247 		.bank_brt_reg = LP5036_BNK_BRT,
248 		.bank_mix_reg = LP5036_BNKA_CLR,
249 		.reset_reg = LP5036_RESET,
250 		.lp50xx_regmap_config = &lp5036_regmap_config,
251 	},
252 	[LP5036] = {
253 		.model_id = LP5036,
254 		.max_modules = LP5036_MAX_LED_MODULES,
255 		.num_leds = LP5036_MAX_LED_MODULES * LP50XX_LEDS_PER_MODULE,
256 		.led_brightness0_reg = LP5036_LED0_BRT,
257 		.mix_out0_reg = LP5036_OUT0_CLR,
258 		.bank_brt_reg = LP5036_BNK_BRT,
259 		.bank_mix_reg = LP5036_BNKA_CLR,
260 		.reset_reg = LP5036_RESET,
261 		.lp50xx_regmap_config = &lp5036_regmap_config,
262 	},
263 };
264 
265 struct lp50xx_led {
266 	struct led_classdev_mc mc_cdev;
267 	struct lp50xx *priv;
268 	u8 ctrl_bank_enabled;
269 	int led_number;
270 };
271 
272 /**
273  * struct lp50xx -
274  * @enable_gpio: hardware enable gpio
275  * @regulator: LED supply regulator pointer
276  * @client: pointer to the I2C client
277  * @regmap: device register map
278  * @dev: pointer to the devices device struct
279  * @lock: lock for reading/writing the device
280  * @chip_info: chip specific information (ie num_leds)
281  * @leds: array of LED strings
282  */
283 struct lp50xx {
284 	struct gpio_desc *enable_gpio;
285 	struct regulator *regulator;
286 	struct i2c_client *client;
287 	struct regmap *regmap;
288 	struct device *dev;
289 	struct mutex lock;
290 	const struct lp50xx_chip_info *chip_info;
291 
292 	/* This needs to be at the end of the struct */
293 	struct lp50xx_led leds[];
294 };
295 
296 static struct lp50xx_led *mcled_cdev_to_led(struct led_classdev_mc *mc_cdev)
297 {
298 	return container_of(mc_cdev, struct lp50xx_led, mc_cdev);
299 }
300 
301 static int lp50xx_brightness_set(struct led_classdev *cdev,
302 			     enum led_brightness brightness)
303 {
304 	struct led_classdev_mc *mc_dev = lcdev_to_mccdev(cdev);
305 	struct lp50xx_led *led = mcled_cdev_to_led(mc_dev);
306 	const struct lp50xx_chip_info *led_chip = led->priv->chip_info;
307 	u8 led_offset, reg_val;
308 	int ret = 0;
309 	int i;
310 
311 	mutex_lock(&led->priv->lock);
312 	if (led->ctrl_bank_enabled)
313 		reg_val = led_chip->bank_brt_reg;
314 	else
315 		reg_val = led_chip->led_brightness0_reg +
316 			  led->led_number;
317 
318 	ret = regmap_write(led->priv->regmap, reg_val, brightness);
319 	if (ret) {
320 		dev_err(led->priv->dev,
321 			"Cannot write brightness value %d\n", ret);
322 		goto out;
323 	}
324 
325 	for (i = 0; i < led->mc_cdev.num_colors; i++) {
326 		if (led->ctrl_bank_enabled) {
327 			reg_val = led_chip->bank_mix_reg + i;
328 		} else {
329 			led_offset = (led->led_number * 3) + i;
330 			reg_val = led_chip->mix_out0_reg + led_offset;
331 		}
332 
333 		ret = regmap_write(led->priv->regmap, reg_val,
334 				   mc_dev->subled_info[i].intensity);
335 		if (ret) {
336 			dev_err(led->priv->dev,
337 				"Cannot write intensity value %d\n", ret);
338 			goto out;
339 		}
340 	}
341 out:
342 	mutex_unlock(&led->priv->lock);
343 	return ret;
344 }
345 
346 static int lp50xx_set_banks(struct lp50xx *priv, u32 led_banks[])
347 {
348 	u8 led_config_lo, led_config_hi;
349 	u32 bank_enable_mask = 0;
350 	int ret;
351 	int i;
352 
353 	for (i = 0; i < priv->chip_info->max_modules; i++) {
354 		if (led_banks[i])
355 			bank_enable_mask |= (1 << led_banks[i]);
356 	}
357 
358 	led_config_lo = bank_enable_mask;
359 	led_config_hi = bank_enable_mask >> 8;
360 
361 	ret = regmap_write(priv->regmap, LP50XX_LED_CFG0, led_config_lo);
362 	if (ret)
363 		return ret;
364 
365 	if (priv->chip_info->model_id >= LP5030)
366 		ret = regmap_write(priv->regmap, LP5036_LED_CFG1, led_config_hi);
367 
368 	return ret;
369 }
370 
371 static int lp50xx_reset(struct lp50xx *priv)
372 {
373 	return regmap_write(priv->regmap, priv->chip_info->reset_reg, LP50XX_SW_RESET);
374 }
375 
376 static int lp50xx_enable_disable(struct lp50xx *priv, int enable_disable)
377 {
378 	int ret;
379 
380 	ret = gpiod_direction_output(priv->enable_gpio, enable_disable);
381 	if (ret)
382 		return ret;
383 
384 	if (enable_disable)
385 		return regmap_write(priv->regmap, LP50XX_DEV_CFG0, LP50XX_CHIP_EN);
386 	else
387 		return regmap_write(priv->regmap, LP50XX_DEV_CFG0, 0);
388 
389 }
390 
391 static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
392 			     struct lp50xx_led *led, int num_leds)
393 {
394 	u32 led_banks[LP5036_MAX_LED_MODULES] = {0};
395 	int led_number;
396 	int ret;
397 
398 	if (num_leds > 1) {
399 		if (num_leds > priv->chip_info->max_modules) {
400 			dev_err(priv->dev, "reg property is invalid\n");
401 			return -EINVAL;
402 		}
403 
404 		ret = fwnode_property_read_u32_array(child, "reg", led_banks, num_leds);
405 		if (ret) {
406 			dev_err(priv->dev, "reg property is missing\n");
407 			return ret;
408 		}
409 
410 		ret = lp50xx_set_banks(priv, led_banks);
411 		if (ret) {
412 			dev_err(priv->dev, "Cannot setup banked LEDs\n");
413 			return ret;
414 		}
415 
416 		led->ctrl_bank_enabled = 1;
417 	} else {
418 		ret = fwnode_property_read_u32(child, "reg", &led_number);
419 		if (ret) {
420 			dev_err(priv->dev, "led reg property missing\n");
421 			return ret;
422 		}
423 
424 		if (led_number > priv->chip_info->num_leds) {
425 			dev_err(priv->dev, "led-sources property is invalid\n");
426 			return -EINVAL;
427 		}
428 
429 		led->led_number = led_number;
430 	}
431 
432 	return 0;
433 }
434 
435 static int lp50xx_probe_dt(struct lp50xx *priv)
436 {
437 	struct fwnode_handle *child = NULL;
438 	struct fwnode_handle *led_node = NULL;
439 	struct led_init_data init_data = {};
440 	struct led_classdev *led_cdev;
441 	struct mc_subled *mc_led_info;
442 	struct lp50xx_led *led;
443 	int ret = -EINVAL;
444 	int num_colors;
445 	u32 color_id;
446 	int i = 0;
447 
448 	priv->enable_gpio = devm_gpiod_get_optional(priv->dev, "enable", GPIOD_OUT_LOW);
449 	if (IS_ERR(priv->enable_gpio))
450 		return dev_err_probe(priv->dev, PTR_ERR(priv->enable_gpio),
451 				     "Failed to get enable GPIO\n");
452 
453 	priv->regulator = devm_regulator_get(priv->dev, "vled");
454 	if (IS_ERR(priv->regulator))
455 		priv->regulator = NULL;
456 
457 	device_for_each_child_node(priv->dev, child) {
458 		led = &priv->leds[i];
459 		ret = fwnode_property_count_u32(child, "reg");
460 		if (ret < 0) {
461 			dev_err(priv->dev, "reg property is invalid\n");
462 			goto child_out;
463 		}
464 
465 		ret = lp50xx_probe_leds(child, priv, led, ret);
466 		if (ret)
467 			goto child_out;
468 
469 		init_data.fwnode = child;
470 		num_colors = 0;
471 
472 		/*
473 		 * There are only 3 LEDs per module otherwise they should be
474 		 * banked which also is presented as 3 LEDs.
475 		 */
476 		mc_led_info = devm_kcalloc(priv->dev, LP50XX_LEDS_PER_MODULE,
477 					   sizeof(*mc_led_info), GFP_KERNEL);
478 		if (!mc_led_info) {
479 			ret = -ENOMEM;
480 			goto child_out;
481 		}
482 
483 		fwnode_for_each_child_node(child, led_node) {
484 			ret = fwnode_property_read_u32(led_node, "color",
485 						       &color_id);
486 			if (ret) {
487 				fwnode_handle_put(led_node);
488 				dev_err(priv->dev, "Cannot read color\n");
489 				goto child_out;
490 			}
491 
492 			mc_led_info[num_colors].color_index = color_id;
493 			num_colors++;
494 		}
495 
496 		led->priv = priv;
497 		led->mc_cdev.num_colors = num_colors;
498 		led->mc_cdev.subled_info = mc_led_info;
499 		led_cdev = &led->mc_cdev.led_cdev;
500 		led_cdev->brightness_set_blocking = lp50xx_brightness_set;
501 
502 		ret = devm_led_classdev_multicolor_register_ext(priv->dev,
503 						       &led->mc_cdev,
504 						       &init_data);
505 		if (ret) {
506 			dev_err(priv->dev, "led register err: %d\n", ret);
507 			goto child_out;
508 		}
509 		i++;
510 	}
511 
512 	return 0;
513 
514 child_out:
515 	fwnode_handle_put(child);
516 	return ret;
517 }
518 
519 static int lp50xx_probe(struct i2c_client *client)
520 {
521 	struct lp50xx *led;
522 	int count;
523 	int ret;
524 
525 	count = device_get_child_node_count(&client->dev);
526 	if (!count) {
527 		dev_err(&client->dev, "LEDs are not defined in device tree!");
528 		return -ENODEV;
529 	}
530 
531 	led = devm_kzalloc(&client->dev, struct_size(led, leds, count),
532 			   GFP_KERNEL);
533 	if (!led)
534 		return -ENOMEM;
535 
536 	mutex_init(&led->lock);
537 	led->client = client;
538 	led->dev = &client->dev;
539 	led->chip_info = device_get_match_data(&client->dev);
540 	i2c_set_clientdata(client, led);
541 	led->regmap = devm_regmap_init_i2c(client,
542 					led->chip_info->lp50xx_regmap_config);
543 	if (IS_ERR(led->regmap)) {
544 		ret = PTR_ERR(led->regmap);
545 		dev_err(&client->dev, "Failed to allocate register map: %d\n",
546 			ret);
547 		return ret;
548 	}
549 
550 	ret = lp50xx_reset(led);
551 	if (ret)
552 		return ret;
553 
554 	ret = lp50xx_enable_disable(led, 1);
555 	if (ret)
556 		return ret;
557 
558 	return lp50xx_probe_dt(led);
559 }
560 
561 static void lp50xx_remove(struct i2c_client *client)
562 {
563 	struct lp50xx *led = i2c_get_clientdata(client);
564 	int ret;
565 
566 	ret = lp50xx_enable_disable(led, 0);
567 	if (ret)
568 		dev_err(led->dev, "Failed to disable chip\n");
569 
570 	if (led->regulator) {
571 		ret = regulator_disable(led->regulator);
572 		if (ret)
573 			dev_err(led->dev, "Failed to disable regulator\n");
574 	}
575 
576 	mutex_destroy(&led->lock);
577 }
578 
579 static const struct i2c_device_id lp50xx_id[] = {
580 	{ "lp5009", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5009] },
581 	{ "lp5012", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5012] },
582 	{ "lp5018", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5018] },
583 	{ "lp5024", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5024] },
584 	{ "lp5030", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5030] },
585 	{ "lp5036", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5036] },
586 	{ }
587 };
588 MODULE_DEVICE_TABLE(i2c, lp50xx_id);
589 
590 static const struct of_device_id of_lp50xx_leds_match[] = {
591 	{ .compatible = "ti,lp5009", .data = &lp50xx_chip_info_tbl[LP5009] },
592 	{ .compatible = "ti,lp5012", .data = &lp50xx_chip_info_tbl[LP5012] },
593 	{ .compatible = "ti,lp5018", .data = &lp50xx_chip_info_tbl[LP5018] },
594 	{ .compatible = "ti,lp5024", .data = &lp50xx_chip_info_tbl[LP5024] },
595 	{ .compatible = "ti,lp5030", .data = &lp50xx_chip_info_tbl[LP5030] },
596 	{ .compatible = "ti,lp5036", .data = &lp50xx_chip_info_tbl[LP5036] },
597 	{}
598 };
599 MODULE_DEVICE_TABLE(of, of_lp50xx_leds_match);
600 
601 static struct i2c_driver lp50xx_driver = {
602 	.driver = {
603 		.name	= "lp50xx",
604 		.of_match_table = of_lp50xx_leds_match,
605 	},
606 	.probe		= lp50xx_probe,
607 	.remove		= lp50xx_remove,
608 	.id_table	= lp50xx_id,
609 };
610 module_i2c_driver(lp50xx_driver);
611 
612 MODULE_DESCRIPTION("Texas Instruments LP50XX LED driver");
613 MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com>");
614 MODULE_LICENSE("GPL v2");
615