Lines Matching +full:led +full:- +full:0

1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI LP8860 4-Channel LED Driver
21 #define LP8860_DISP_CL1_BRT_MSB 0x00
22 #define LP8860_DISP_CL1_BRT_LSB 0x01
23 #define LP8860_DISP_CL1_CURR_MSB 0x02
24 #define LP8860_DISP_CL1_CURR_LSB 0x03
25 #define LP8860_CL2_BRT_MSB 0x04
26 #define LP8860_CL2_BRT_LSB 0x05
27 #define LP8860_CL2_CURRENT 0x06
28 #define LP8860_CL3_BRT_MSB 0x07
29 #define LP8860_CL3_BRT_LSB 0x08
30 #define LP8860_CL3_CURRENT 0x09
31 #define LP8860_CL4_BRT_MSB 0x0a
32 #define LP8860_CL4_BRT_LSB 0x0b
33 #define LP8860_CL4_CURRENT 0x0c
34 #define LP8860_CONFIG 0x0d
35 #define LP8860_STATUS 0x0e
36 #define LP8860_FAULT 0x0f
37 #define LP8860_LED_FAULT 0x10
38 #define LP8860_FAULT_CLEAR 0x11
39 #define LP8860_ID 0x12
40 #define LP8860_TEMP_MSB 0x13
41 #define LP8860_TEMP_LSB 0x14
42 #define LP8860_DISP_LED_CURR_MSB 0x15
43 #define LP8860_DISP_LED_CURR_LSB 0x16
44 #define LP8860_DISP_LED_PWM_MSB 0x17
45 #define LP8860_DISP_LED_PWM_LSB 0x18
46 #define LP8860_EEPROM_CNTRL 0x19
47 #define LP8860_EEPROM_UNLOCK 0x1a
49 #define LP8860_EEPROM_REG_0 0x60
50 #define LP8860_EEPROM_REG_1 0x61
51 #define LP8860_EEPROM_REG_2 0x62
52 #define LP8860_EEPROM_REG_3 0x63
53 #define LP8860_EEPROM_REG_4 0x64
54 #define LP8860_EEPROM_REG_5 0x65
55 #define LP8860_EEPROM_REG_6 0x66
56 #define LP8860_EEPROM_REG_7 0x67
57 #define LP8860_EEPROM_REG_8 0x68
58 #define LP8860_EEPROM_REG_9 0x69
59 #define LP8860_EEPROM_REG_10 0x6a
60 #define LP8860_EEPROM_REG_11 0x6b
61 #define LP8860_EEPROM_REG_12 0x6c
62 #define LP8860_EEPROM_REG_13 0x6d
63 #define LP8860_EEPROM_REG_14 0x6e
64 #define LP8860_EEPROM_REG_15 0x6f
65 #define LP8860_EEPROM_REG_16 0x70
66 #define LP8860_EEPROM_REG_17 0x71
67 #define LP8860_EEPROM_REG_18 0x72
68 #define LP8860_EEPROM_REG_19 0x73
69 #define LP8860_EEPROM_REG_20 0x74
70 #define LP8860_EEPROM_REG_21 0x75
71 #define LP8860_EEPROM_REG_22 0x76
72 #define LP8860_EEPROM_REG_23 0x77
73 #define LP8860_EEPROM_REG_24 0x78
75 #define LP8860_LOCK_EEPROM 0x00
76 #define LP8860_UNLOCK_EEPROM 0x01
77 #define LP8860_PROGRAM_EEPROM 0x02
78 #define LP8860_EEPROM_CODE_1 0x08
79 #define LP8860_EEPROM_CODE_2 0xba
80 #define LP8860_EEPROM_CODE_3 0xef
82 #define LP8860_CLEAR_FAULTS 0x01
90 * @led_dev: led class device pointer
94 * @regulator: LED supply regulator pointer
112 { LP8860_EEPROM_REG_0, 0xed },
113 { LP8860_EEPROM_REG_1, 0xdf },
114 { LP8860_EEPROM_REG_2, 0xdc },
115 { LP8860_EEPROM_REG_3, 0xf0 },
116 { LP8860_EEPROM_REG_4, 0xdf },
117 { LP8860_EEPROM_REG_5, 0xe5 },
118 { LP8860_EEPROM_REG_6, 0xf2 },
119 { LP8860_EEPROM_REG_7, 0x77 },
120 { LP8860_EEPROM_REG_8, 0x77 },
121 { LP8860_EEPROM_REG_9, 0x71 },
122 { LP8860_EEPROM_REG_10, 0x3f },
123 { LP8860_EEPROM_REG_11, 0xb7 },
124 { LP8860_EEPROM_REG_12, 0x17 },
125 { LP8860_EEPROM_REG_13, 0xef },
126 { LP8860_EEPROM_REG_14, 0xb0 },
127 { LP8860_EEPROM_REG_15, 0x87 },
128 { LP8860_EEPROM_REG_16, 0xce },
129 { LP8860_EEPROM_REG_17, 0x72 },
130 { LP8860_EEPROM_REG_18, 0xe5 },
131 { LP8860_EEPROM_REG_19, 0xdf },
132 { LP8860_EEPROM_REG_20, 0x35 },
133 { LP8860_EEPROM_REG_21, 0x06 },
134 { LP8860_EEPROM_REG_22, 0xdc },
135 { LP8860_EEPROM_REG_23, 0x88 },
136 { LP8860_EEPROM_REG_24, 0x3E },
139 static int lp8860_unlock_eeprom(struct lp8860_led *led, int lock) in lp8860_unlock_eeprom() argument
143 mutex_lock(&led->lock); in lp8860_unlock_eeprom()
146 ret = regmap_write(led->regmap, in lp8860_unlock_eeprom()
150 dev_err(&led->client->dev, "EEPROM Unlock failed\n"); in lp8860_unlock_eeprom()
154 ret = regmap_write(led->regmap, in lp8860_unlock_eeprom()
158 dev_err(&led->client->dev, "EEPROM Unlock failed\n"); in lp8860_unlock_eeprom()
161 ret = regmap_write(led->regmap, in lp8860_unlock_eeprom()
165 dev_err(&led->client->dev, "EEPROM Unlock failed\n"); in lp8860_unlock_eeprom()
169 ret = regmap_write(led->regmap, in lp8860_unlock_eeprom()
175 mutex_unlock(&led->lock); in lp8860_unlock_eeprom()
179 static int lp8860_fault_check(struct lp8860_led *led) in lp8860_fault_check() argument
184 ret = regmap_read(led->regmap, LP8860_LED_FAULT, &read_buf); in lp8860_fault_check()
190 ret = regmap_read(led->regmap, LP8860_FAULT, &read_buf); in lp8860_fault_check()
198 ret = regmap_write(led->regmap, LP8860_FAULT_CLEAR, in lp8860_fault_check()
207 struct lp8860_led *led = in lp8860_brightness_set() local
212 mutex_lock(&led->lock); in lp8860_brightness_set()
214 ret = lp8860_fault_check(led); in lp8860_brightness_set()
216 dev_err(&led->client->dev, "Cannot read/clear faults\n"); in lp8860_brightness_set()
220 ret = regmap_write(led->regmap, LP8860_DISP_CL1_BRT_MSB, in lp8860_brightness_set()
221 (disp_brightness & 0xff00) >> 8); in lp8860_brightness_set()
223 dev_err(&led->client->dev, "Cannot write CL1 MSB\n"); in lp8860_brightness_set()
227 ret = regmap_write(led->regmap, LP8860_DISP_CL1_BRT_LSB, in lp8860_brightness_set()
228 disp_brightness & 0xff); in lp8860_brightness_set()
230 dev_err(&led->client->dev, "Cannot write CL1 LSB\n"); in lp8860_brightness_set()
234 mutex_unlock(&led->lock); in lp8860_brightness_set()
238 static int lp8860_init(struct lp8860_led *led) in lp8860_init() argument
243 if (led->regulator) { in lp8860_init()
244 ret = regulator_enable(led->regulator); in lp8860_init()
246 dev_err(&led->client->dev, in lp8860_init()
252 gpiod_direction_output(led->enable_gpio, 1); in lp8860_init()
254 ret = lp8860_fault_check(led); in lp8860_init()
258 ret = regmap_read(led->regmap, LP8860_STATUS, &read_buf); in lp8860_init()
262 ret = lp8860_unlock_eeprom(led, LP8860_UNLOCK_EEPROM); in lp8860_init()
264 dev_err(&led->client->dev, "Failed unlocking EEPROM\n"); in lp8860_init()
268 reg_count = ARRAY_SIZE(lp8860_eeprom_disp_regs) / sizeof(lp8860_eeprom_disp_regs[0]); in lp8860_init()
269 for (i = 0; i < reg_count; i++) { in lp8860_init()
270 ret = regmap_write(led->eeprom_regmap, in lp8860_init()
274 dev_err(&led->client->dev, "Failed writing EEPROM\n"); in lp8860_init()
279 ret = lp8860_unlock_eeprom(led, LP8860_LOCK_EEPROM); in lp8860_init()
283 ret = regmap_write(led->regmap, in lp8860_init()
287 dev_err(&led->client->dev, "Failed programming EEPROM\n"); in lp8860_init()
295 gpiod_direction_output(led->enable_gpio, 0); in lp8860_init()
297 if (led->regulator) { in lp8860_init()
298 ret = regulator_disable(led->regulator); in lp8860_init()
300 dev_err(&led->client->dev, in lp8860_init()
308 { LP8860_DISP_CL1_BRT_MSB, 0x00},
309 { LP8860_DISP_CL1_BRT_LSB, 0x00},
310 { LP8860_DISP_CL1_CURR_MSB, 0x00},
311 { LP8860_DISP_CL1_CURR_LSB, 0x00},
312 { LP8860_CL2_BRT_MSB, 0x00},
313 { LP8860_CL2_BRT_LSB, 0x00},
314 { LP8860_CL2_CURRENT, 0x00},
315 { LP8860_CL3_BRT_MSB, 0x00},
316 { LP8860_CL3_BRT_LSB, 0x00},
317 { LP8860_CL3_CURRENT, 0x00},
318 { LP8860_CL4_BRT_MSB, 0x00},
319 { LP8860_CL4_BRT_LSB, 0x00},
320 { LP8860_CL4_CURRENT, 0x00},
321 { LP8860_CONFIG, 0x00},
322 { LP8860_FAULT_CLEAR, 0x00},
323 { LP8860_EEPROM_CNTRL, 0x80},
324 { LP8860_EEPROM_UNLOCK, 0x00},
338 { LP8860_EEPROM_REG_0, 0x00 },
339 { LP8860_EEPROM_REG_1, 0x00 },
340 { LP8860_EEPROM_REG_2, 0x00 },
341 { LP8860_EEPROM_REG_3, 0x00 },
342 { LP8860_EEPROM_REG_4, 0x00 },
343 { LP8860_EEPROM_REG_5, 0x00 },
344 { LP8860_EEPROM_REG_6, 0x00 },
345 { LP8860_EEPROM_REG_7, 0x00 },
346 { LP8860_EEPROM_REG_8, 0x00 },
347 { LP8860_EEPROM_REG_9, 0x00 },
348 { LP8860_EEPROM_REG_10, 0x00 },
349 { LP8860_EEPROM_REG_11, 0x00 },
350 { LP8860_EEPROM_REG_12, 0x00 },
351 { LP8860_EEPROM_REG_13, 0x00 },
352 { LP8860_EEPROM_REG_14, 0x00 },
353 { LP8860_EEPROM_REG_15, 0x00 },
354 { LP8860_EEPROM_REG_16, 0x00 },
355 { LP8860_EEPROM_REG_17, 0x00 },
356 { LP8860_EEPROM_REG_18, 0x00 },
357 { LP8860_EEPROM_REG_19, 0x00 },
358 { LP8860_EEPROM_REG_20, 0x00 },
359 { LP8860_EEPROM_REG_21, 0x00 },
360 { LP8860_EEPROM_REG_22, 0x00 },
361 { LP8860_EEPROM_REG_23, 0x00 },
362 { LP8860_EEPROM_REG_24, 0x00 },
378 struct lp8860_led *led; in lp8860_probe() local
379 struct device_node *np = dev_of_node(&client->dev); in lp8860_probe()
383 led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); in lp8860_probe()
384 if (!led) in lp8860_probe()
385 return -ENOMEM; in lp8860_probe()
389 return -EINVAL; in lp8860_probe()
391 led->enable_gpio = devm_gpiod_get_optional(&client->dev, in lp8860_probe()
393 if (IS_ERR(led->enable_gpio)) { in lp8860_probe()
394 ret = PTR_ERR(led->enable_gpio); in lp8860_probe()
395 dev_err(&client->dev, "Failed to get enable gpio: %d\n", ret); in lp8860_probe()
399 led->regulator = devm_regulator_get(&client->dev, "vled"); in lp8860_probe()
400 if (IS_ERR(led->regulator)) in lp8860_probe()
401 led->regulator = NULL; in lp8860_probe()
403 led->client = client; in lp8860_probe()
404 led->led_dev.brightness_set_blocking = lp8860_brightness_set; in lp8860_probe()
406 mutex_init(&led->lock); in lp8860_probe()
408 i2c_set_clientdata(client, led); in lp8860_probe()
410 led->regmap = devm_regmap_init_i2c(client, &lp8860_regmap_config); in lp8860_probe()
411 if (IS_ERR(led->regmap)) { in lp8860_probe()
412 ret = PTR_ERR(led->regmap); in lp8860_probe()
413 dev_err(&client->dev, "Failed to allocate register map: %d\n", in lp8860_probe()
418 led->eeprom_regmap = devm_regmap_init_i2c(client, &lp8860_eeprom_regmap_config); in lp8860_probe()
419 if (IS_ERR(led->eeprom_regmap)) { in lp8860_probe()
420 ret = PTR_ERR(led->eeprom_regmap); in lp8860_probe()
421 dev_err(&client->dev, "Failed to allocate register map: %d\n", in lp8860_probe()
426 ret = lp8860_init(led); in lp8860_probe()
434 ret = devm_led_classdev_register_ext(&client->dev, &led->led_dev, in lp8860_probe()
437 dev_err(&client->dev, "led register err: %d\n", ret); in lp8860_probe()
441 return 0; in lp8860_probe()
446 struct lp8860_led *led = i2c_get_clientdata(client); in lp8860_remove() local
449 gpiod_direction_output(led->enable_gpio, 0); in lp8860_remove()
451 if (led->regulator) { in lp8860_remove()
452 ret = regulator_disable(led->regulator); in lp8860_remove()
454 dev_err(&led->client->dev, in lp8860_remove()
458 mutex_destroy(&led->lock); in lp8860_remove()
484 MODULE_DESCRIPTION("Texas Instruments LP8860 LED driver");