Lines Matching +full:vled +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-only
3 * leds-regulator.c - LED class driver for regulator driven LEDs.
7 * Inspired by leds-wm8350 driver.
15 #include <linux/leds-regulator.h>
30 static inline int led_regulator_get_max_brightness(struct regulator *supply) in led_regulator_get_max_brightness() argument
33 int voltage = regulator_list_voltage(supply, 0); in led_regulator_get_max_brightness()
42 ret = regulator_set_voltage(supply, voltage, voltage); in led_regulator_get_max_brightness()
46 return regulator_count_voltages(supply); in led_regulator_get_max_brightness()
49 static int led_regulator_get_voltage(struct regulator *supply, in led_regulator_get_voltage() argument
53 return -EINVAL; in led_regulator_get_voltage()
55 return regulator_list_voltage(supply, brightness - 1); in led_regulator_get_voltage()
63 if (led->enabled) in regulator_led_enable()
66 ret = regulator_enable(led->vcc); in regulator_led_enable()
68 dev_err(led->cdev.dev, "Failed to enable vcc: %d\n", ret); in regulator_led_enable()
72 led->enabled = 1; in regulator_led_enable()
79 if (!led->enabled) in regulator_led_disable()
82 ret = regulator_disable(led->vcc); in regulator_led_disable()
84 dev_err(led->cdev.dev, "Failed to disable vcc: %d\n", ret); in regulator_led_disable()
88 led->enabled = 0; in regulator_led_disable()
98 mutex_lock(&led->mutex); in regulator_led_brightness_set()
105 if (led->cdev.max_brightness > 1) { in regulator_led_brightness_set()
106 voltage = led_regulator_get_voltage(led->vcc, value); in regulator_led_brightness_set()
107 dev_dbg(led->cdev.dev, "brightness: %d voltage: %d\n", in regulator_led_brightness_set()
110 ret = regulator_set_voltage(led->vcc, voltage, voltage); in regulator_led_brightness_set()
112 dev_err(led->cdev.dev, "Failed to set voltage %d: %d\n", in regulator_led_brightness_set()
119 mutex_unlock(&led->mutex); in regulator_led_brightness_set()
126 dev_get_platdata(&pdev->dev); in regulator_led_probe()
127 struct device *dev = &pdev->dev; in regulator_led_probe()
133 vcc = devm_regulator_get_exclusive(dev, "vled"); in regulator_led_probe()
141 return -ENOMEM; in regulator_led_probe()
143 init_data.fwnode = dev->fwnode; in regulator_led_probe()
145 led->cdev.max_brightness = led_regulator_get_max_brightness(vcc); in regulator_led_probe()
148 if (pdata->brightness > led->cdev.max_brightness) { in regulator_led_probe()
150 pdata->brightness); in regulator_led_probe()
151 return -EINVAL; in regulator_led_probe()
153 led->cdev.brightness = pdata->brightness; in regulator_led_probe()
154 init_data.default_label = pdata->name; in regulator_led_probe()
157 led->cdev.brightness_set_blocking = regulator_led_brightness_set; in regulator_led_probe()
158 led->cdev.flags |= LED_CORE_SUSPENDRESUME; in regulator_led_probe()
159 led->vcc = vcc; in regulator_led_probe()
162 if (regulator_is_enabled(led->vcc)) in regulator_led_probe()
163 led->enabled = 1; in regulator_led_probe()
165 mutex_init(&led->mutex); in regulator_led_probe()
169 ret = led_classdev_register_ext(dev, &led->cdev, &init_data); in regulator_led_probe()
180 led_classdev_unregister(&led->cdev); in regulator_led_remove()
185 { .compatible = "regulator-led", },
192 .name = "leds-regulator",
204 MODULE_ALIAS("platform:leds-regulator");