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