Lines Matching +full:led +full:-
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>
39 * and the LED can be turned on and off. in led_regulator_get_max_brightness()
52 return -EINVAL; in led_regulator_get_voltage()
54 return regulator_list_voltage(supply, brightness - 1); in led_regulator_get_voltage()
58 static void regulator_led_enable(struct regulator_led *led) in regulator_led_enable() argument
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()
74 static void regulator_led_disable(struct regulator_led *led) in regulator_led_disable() argument
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()
93 struct regulator_led *led = to_regulator_led(led_cdev); in regulator_led_brightness_set() local
97 mutex_lock(&led->mutex); in regulator_led_brightness_set()
100 regulator_led_disable(led); 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()
115 regulator_led_enable(led); 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()
126 struct regulator_led *led; in regulator_led_probe() local
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()
142 if (led == NULL) 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()
163 platform_set_drvdata(pdev, led); 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()
172 /* Set the default led status */ in regulator_led_probe()
173 regulator_led_brightness_set(&led->cdev, led->cdev.brightness); in regulator_led_probe()
180 struct regulator_led *led = platform_get_drvdata(pdev); in regulator_led_remove() local
182 led_classdev_unregister(&led->cdev); in regulator_led_remove()
183 regulator_led_disable(led); in regulator_led_remove()
189 .name = "leds-regulator",
198 MODULE_DESCRIPTION("Regulator driven LED driver");
200 MODULE_ALIAS("platform:leds-regulator");