Lines Matching +full:gpio +full:- +full:leds

1 // SPDX-License-Identifier: GPL-2.0-only
3 * LEDs driver for GPIOs
12 #include <linux/gpio.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/leds.h>
24 #include "leds.h"
51 if (led_dat->blinking) { in gpio_led_set()
52 led_dat->platform_gpio_blink_set(led_dat->gpiod, level, in gpio_led_set()
54 led_dat->blinking = 0; in gpio_led_set()
56 if (led_dat->can_sleep) in gpio_led_set()
57 gpiod_set_value_cansleep(led_dat->gpiod, level); in gpio_led_set()
59 gpiod_set_value(led_dat->gpiod, level); in gpio_led_set()
75 led_dat->blinking = 1; in gpio_blink_set()
76 return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK, in gpio_blink_set()
88 led_dat->cdev.default_trigger = template->default_trigger; in create_gpio_led()
89 led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod); in create_gpio_led()
90 if (!led_dat->can_sleep) in create_gpio_led()
91 led_dat->cdev.brightness_set = gpio_led_set; in create_gpio_led()
93 led_dat->cdev.brightness_set_blocking = gpio_led_set_blocking; in create_gpio_led()
94 led_dat->blinking = 0; in create_gpio_led()
96 led_dat->platform_gpio_blink_set = blink_set; in create_gpio_led()
97 led_dat->cdev.blink_set = gpio_blink_set; in create_gpio_led()
99 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) { in create_gpio_led()
100 state = gpiod_get_value_cansleep(led_dat->gpiod); in create_gpio_led()
104 state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); in create_gpio_led()
106 led_dat->cdev.brightness = state; in create_gpio_led()
107 led_dat->cdev.max_brightness = 1; in create_gpio_led()
108 if (!template->retain_state_suspended) in create_gpio_led()
109 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; in create_gpio_led()
110 if (template->panic_indicator) in create_gpio_led()
111 led_dat->cdev.flags |= LED_PANIC_INDICATOR; in create_gpio_led()
112 if (template->retain_state_shutdown) in create_gpio_led()
113 led_dat->cdev.flags |= LED_RETAIN_AT_SHUTDOWN; in create_gpio_led()
115 ret = gpiod_direction_output(led_dat->gpiod, state); in create_gpio_led()
119 if (template->name) { in create_gpio_led()
120 led_dat->cdev.name = template->name; in create_gpio_led()
121 ret = devm_led_classdev_register(parent, &led_dat->cdev); in create_gpio_led()
124 ret = devm_led_classdev_register_ext(parent, &led_dat->cdev, in create_gpio_led()
131 pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev); in create_gpio_led()
133 /* pinctrl-%d not present, not an error */ in create_gpio_led()
134 if (ret == -ENODEV) in create_gpio_led()
137 dev_warn(led_dat->cdev.dev, "Failed to select %pfw pinctrl: %d\n", in create_gpio_led()
146 struct gpio_led_data leds[] __counted_by(num_leds);
157 return ERR_PTR(-ENODEV); in gpio_leds_create()
159 priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL); in gpio_leds_create()
161 return ERR_PTR(-ENOMEM); in gpio_leds_create()
162 priv->num_leds = count; in gpio_leds_create()
166 struct gpio_led_data *led_dat = &priv->leds[used]; in gpio_leds_create()
177 dev_err_probe(dev, PTR_ERR(led.gpiod), "Failed to get GPIO '%pfw'\n", in gpio_leds_create()
183 led_dat->gpiod = led.gpiod; in gpio_leds_create()
187 if (fwnode_property_present(child, "retain-state-suspended")) in gpio_leds_create()
189 if (fwnode_property_present(child, "retain-state-shutdown")) in gpio_leds_create()
191 if (fwnode_property_present(child, "panic-indicator")) in gpio_leds_create()
200 gpiod_set_consumer_name(led_dat->gpiod, in gpio_leds_create()
201 led_dat->cdev.dev->kobj.name); in gpio_leds_create()
204 priv->num_leds = used; in gpio_leds_create()
210 { .compatible = "gpio-leds", },
227 * the GPIO from there. in gpio_led_get_gpiod()
233 gpiod_set_consumer_name(gpiod, template->name); in gpio_led_get_gpiod()
239 * still uses GPIO numbers. Ultimately we would like to get in gpio_led_get_gpiod()
243 /* skip leds that aren't available */ in gpio_led_get_gpiod()
244 if (!gpio_is_valid(template->gpio)) in gpio_led_get_gpiod()
245 return ERR_PTR(-ENOENT); in gpio_led_get_gpiod()
247 if (template->active_low) in gpio_led_get_gpiod()
250 ret = devm_gpio_request_one(dev, template->gpio, flags, in gpio_led_get_gpiod()
251 template->name); in gpio_led_get_gpiod()
255 gpiod = gpio_to_desc(template->gpio); in gpio_led_get_gpiod()
257 return ERR_PTR(-EINVAL); in gpio_led_get_gpiod()
264 struct device *dev = &pdev->dev; in gpio_led_probe()
269 if (pdata && pdata->num_leds) { in gpio_led_probe()
270 priv = devm_kzalloc(dev, struct_size(priv, leds, pdata->num_leds), GFP_KERNEL); in gpio_led_probe()
272 return -ENOMEM; in gpio_led_probe()
274 priv->num_leds = pdata->num_leds; in gpio_led_probe()
275 for (i = 0; i < priv->num_leds; i++) { in gpio_led_probe()
276 const struct gpio_led *template = &pdata->leds[i]; in gpio_led_probe()
277 struct gpio_led_data *led_dat = &priv->leds[i]; in gpio_led_probe()
279 if (template->gpiod) in gpio_led_probe()
280 led_dat->gpiod = template->gpiod; in gpio_led_probe()
282 led_dat->gpiod = in gpio_led_probe()
284 if (IS_ERR(led_dat->gpiod)) { in gpio_led_probe()
285 dev_info(dev, "Skipping unavailable LED gpio %d (%s)\n", in gpio_led_probe()
286 template->gpio, template->name); in gpio_led_probe()
291 pdata->gpio_blink_set); in gpio_led_probe()
311 for (i = 0; i < priv->num_leds; i++) { in gpio_led_shutdown()
312 struct gpio_led_data *led = &priv->leds[i]; in gpio_led_shutdown()
314 if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN)) in gpio_led_shutdown()
315 gpio_led_set(&led->cdev, LED_OFF); in gpio_led_shutdown()
323 .name = "leds-gpio",
331 MODULE_DESCRIPTION("GPIO LED driver");
333 MODULE_ALIAS("platform:leds-gpio");