Lines Matching +full:vled +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2018-20 Texas Instruments Incorporated - https://www.ti.com/
17 #include <linux/led-class-multicolor.h>
173 * struct lp50xx_chip_info -
273 * struct lp50xx -
275 * @regulator: LED supply regulator pointer
306 const struct lp50xx_chip_info *led_chip = led->priv->chip_info; in lp50xx_brightness_set()
311 mutex_lock(&led->priv->lock); in lp50xx_brightness_set()
312 if (led->ctrl_bank_enabled) in lp50xx_brightness_set()
313 reg_val = led_chip->bank_brt_reg; in lp50xx_brightness_set()
315 reg_val = led_chip->led_brightness0_reg + in lp50xx_brightness_set()
316 led->led_number; in lp50xx_brightness_set()
318 ret = regmap_write(led->priv->regmap, reg_val, brightness); in lp50xx_brightness_set()
320 dev_err(led->priv->dev, in lp50xx_brightness_set()
325 for (i = 0; i < led->mc_cdev.num_colors; i++) { in lp50xx_brightness_set()
326 if (led->ctrl_bank_enabled) { in lp50xx_brightness_set()
327 reg_val = led_chip->bank_mix_reg + i; in lp50xx_brightness_set()
329 led_offset = (led->led_number * 3) + i; in lp50xx_brightness_set()
330 reg_val = led_chip->mix_out0_reg + led_offset; in lp50xx_brightness_set()
333 ret = regmap_write(led->priv->regmap, reg_val, in lp50xx_brightness_set()
334 mc_dev->subled_info[i].intensity); in lp50xx_brightness_set()
336 dev_err(led->priv->dev, in lp50xx_brightness_set()
342 mutex_unlock(&led->priv->lock); in lp50xx_brightness_set()
353 for (i = 0; i < priv->chip_info->max_modules; i++) { in lp50xx_set_banks()
361 ret = regmap_write(priv->regmap, LP50XX_LED_CFG0, led_config_lo); in lp50xx_set_banks()
365 if (priv->chip_info->model_id >= LP5030) in lp50xx_set_banks()
366 ret = regmap_write(priv->regmap, LP5036_LED_CFG1, led_config_hi); in lp50xx_set_banks()
373 return regmap_write(priv->regmap, priv->chip_info->reset_reg, LP50XX_SW_RESET); in lp50xx_reset()
380 ret = gpiod_direction_output(priv->enable_gpio, enable_disable); in lp50xx_enable_disable()
385 return regmap_write(priv->regmap, LP50XX_DEV_CFG0, LP50XX_CHIP_EN); in lp50xx_enable_disable()
387 return regmap_write(priv->regmap, LP50XX_DEV_CFG0, 0); in lp50xx_enable_disable()
399 if (num_leds > priv->chip_info->max_modules) { in lp50xx_probe_leds()
400 dev_err(priv->dev, "reg property is invalid\n"); in lp50xx_probe_leds()
401 return -EINVAL; in lp50xx_probe_leds()
406 dev_err(priv->dev, "reg property is missing\n"); in lp50xx_probe_leds()
412 dev_err(priv->dev, "Cannot setup banked LEDs\n"); in lp50xx_probe_leds()
416 led->ctrl_bank_enabled = 1; in lp50xx_probe_leds()
420 dev_err(priv->dev, "led reg property missing\n"); in lp50xx_probe_leds()
424 if (led_number > priv->chip_info->num_leds) { in lp50xx_probe_leds()
425 dev_err(priv->dev, "led-sources property is invalid\n"); in lp50xx_probe_leds()
426 return -EINVAL; in lp50xx_probe_leds()
429 led->led_number = led_number; in lp50xx_probe_leds()
443 int ret = -EINVAL; in lp50xx_probe_dt()
448 priv->enable_gpio = devm_gpiod_get_optional(priv->dev, "enable", GPIOD_OUT_LOW); in lp50xx_probe_dt()
449 if (IS_ERR(priv->enable_gpio)) in lp50xx_probe_dt()
450 return dev_err_probe(priv->dev, PTR_ERR(priv->enable_gpio), in lp50xx_probe_dt()
453 priv->regulator = devm_regulator_get(priv->dev, "vled"); in lp50xx_probe_dt()
454 if (IS_ERR(priv->regulator)) in lp50xx_probe_dt()
455 priv->regulator = NULL; in lp50xx_probe_dt()
457 device_for_each_child_node(priv->dev, child) { in lp50xx_probe_dt()
458 led = &priv->leds[i]; in lp50xx_probe_dt()
461 dev_err(priv->dev, "reg property is invalid\n"); in lp50xx_probe_dt()
476 mc_led_info = devm_kcalloc(priv->dev, LP50XX_LEDS_PER_MODULE, in lp50xx_probe_dt()
479 ret = -ENOMEM; in lp50xx_probe_dt()
488 dev_err(priv->dev, "Cannot read color\n"); in lp50xx_probe_dt()
496 led->priv = priv; in lp50xx_probe_dt()
497 led->mc_cdev.num_colors = num_colors; in lp50xx_probe_dt()
498 led->mc_cdev.subled_info = mc_led_info; in lp50xx_probe_dt()
499 led_cdev = &led->mc_cdev.led_cdev; in lp50xx_probe_dt()
500 led_cdev->brightness_set_blocking = lp50xx_brightness_set; in lp50xx_probe_dt()
502 ret = devm_led_classdev_multicolor_register_ext(priv->dev, in lp50xx_probe_dt()
503 &led->mc_cdev, in lp50xx_probe_dt()
506 dev_err(priv->dev, "led register err: %d\n", ret); in lp50xx_probe_dt()
525 count = device_get_child_node_count(&client->dev); in lp50xx_probe()
527 dev_err(&client->dev, "LEDs are not defined in device tree!"); in lp50xx_probe()
528 return -ENODEV; in lp50xx_probe()
531 led = devm_kzalloc(&client->dev, struct_size(led, leds, count), in lp50xx_probe()
534 return -ENOMEM; in lp50xx_probe()
536 mutex_init(&led->lock); in lp50xx_probe()
537 led->client = client; in lp50xx_probe()
538 led->dev = &client->dev; in lp50xx_probe()
539 led->chip_info = device_get_match_data(&client->dev); in lp50xx_probe()
541 led->regmap = devm_regmap_init_i2c(client, in lp50xx_probe()
542 led->chip_info->lp50xx_regmap_config); in lp50xx_probe()
543 if (IS_ERR(led->regmap)) { in lp50xx_probe()
544 ret = PTR_ERR(led->regmap); in lp50xx_probe()
545 dev_err(&client->dev, "Failed to allocate register map: %d\n", in lp50xx_probe()
568 dev_err(led->dev, "Failed to disable chip\n"); in lp50xx_remove()
570 if (led->regulator) { in lp50xx_remove()
571 ret = regulator_disable(led->regulator); in lp50xx_remove()
573 dev_err(led->dev, "Failed to disable regulator\n"); in lp50xx_remove()
576 mutex_destroy(&led->lock); in lp50xx_remove()