Lines Matching +full:regulator +full:- +full:led
1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI LP8860 4-Channel LED Driver
14 #include <linux/regulator/consumer.h>
90 * @led_dev: led class device pointer
94 * @regulator: LED supply regulator pointer
103 struct regulator *regulator; member
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()
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()
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()
247 "Failed to enable regulator\n"); 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()
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()
301 "Failed to disable regulator\n"); in lp8860_init()
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()
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()
455 "Failed to disable regulator\n"); in lp8860_remove()
458 mutex_destroy(&led->lock); in lp8860_remove()
484 MODULE_DESCRIPTION("Texas Instruments LP8860 LED driver");