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.
14 #include <linux/leds-regulator.h>
29 static inline int led_regulator_get_max_brightness(struct regulator *supply) in led_regulator_get_max_brightness() argument
32 int voltage = regulator_list_voltage(supply, 0); in led_regulator_get_max_brightness()
41 ret = regulator_set_voltage(supply, voltage, voltage); in led_regulator_get_max_brightness()
45 return regulator_count_voltages(supply); in led_regulator_get_max_brightness()
48 static int led_regulator_get_voltage(struct regulator *supply, in led_regulator_get_voltage() argument
52 return -EINVAL; in led_regulator_get_voltage()
54 return regulator_list_voltage(supply, brightness - 1); in led_regulator_get_voltage()
62 if (led->enabled) in regulator_led_enable()
65 ret = regulator_enable(led->vcc); in regulator_led_enable()
67 dev_err(led->cdev.dev, "Failed to enable vcc: %d\n", ret); in regulator_led_enable()
71 led->enabled = 1; in regulator_led_enable()
78 if (!led->enabled) in regulator_led_disable()
81 ret = regulator_disable(led->vcc); in regulator_led_disable()
83 dev_err(led->cdev.dev, "Failed to disable vcc: %d\n", ret); in regulator_led_disable()
87 led->enabled = 0; in regulator_led_disable()
97 mutex_lock(&led->mutex); in regulator_led_brightness_set()
104 if (led->cdev.max_brightness > 1) { in regulator_led_brightness_set()
105 voltage = led_regulator_get_voltage(led->vcc, value); in regulator_led_brightness_set()
106 dev_dbg(led->cdev.dev, "brightness: %d voltage: %d\n", in regulator_led_brightness_set()
109 ret = regulator_set_voltage(led->vcc, voltage, voltage); in regulator_led_brightness_set()
111 dev_err(led->cdev.dev, "Failed to set voltage %d: %d\n", in regulator_led_brightness_set()
118 mutex_unlock(&led->mutex); in regulator_led_brightness_set()
125 dev_get_platdata(&pdev->dev); in regulator_led_probe()
131 dev_err(&pdev->dev, "no platform data\n"); in regulator_led_probe()
132 return -ENODEV; in regulator_led_probe()
135 vcc = devm_regulator_get_exclusive(&pdev->dev, "vled"); in regulator_led_probe()
137 dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name); in regulator_led_probe()
141 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); in regulator_led_probe()
143 return -ENOMEM; in regulator_led_probe()
145 led->cdev.max_brightness = led_regulator_get_max_brightness(vcc); in regulator_led_probe()
146 if (pdata->brightness > led->cdev.max_brightness) { in regulator_led_probe()
147 dev_err(&pdev->dev, "Invalid default brightness %d\n", in regulator_led_probe()
148 pdata->brightness); in regulator_led_probe()
149 return -EINVAL; in regulator_led_probe()
152 led->cdev.brightness_set_blocking = regulator_led_brightness_set; in regulator_led_probe()
153 led->cdev.name = pdata->name; in regulator_led_probe()
154 led->cdev.flags |= LED_CORE_SUSPENDRESUME; in regulator_led_probe()
155 led->vcc = vcc; in regulator_led_probe()
158 if (regulator_is_enabled(led->vcc)) in regulator_led_probe()
159 led->enabled = 1; in regulator_led_probe()
161 mutex_init(&led->mutex); in regulator_led_probe()
165 ret = led_classdev_register(&pdev->dev, &led->cdev); in regulator_led_probe()
170 led->cdev.brightness = pdata->brightness; in regulator_led_probe()
173 regulator_led_brightness_set(&led->cdev, led->cdev.brightness); in regulator_led_probe()
182 led_classdev_unregister(&led->cdev); in regulator_led_remove()
189 .name = "leds-regulator",
200 MODULE_ALIAS("platform:leds-regulator");