Lines Matching +full:led +full:- +full:8
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2007 8D Technologies inc.
6 * Raphael Assenat <raph@8d.com>
45 if (led_dat->blinking) { in gpio_led_set()
46 led_dat->platform_gpio_blink_set(led_dat->gpiod, level, in gpio_led_set()
48 led_dat->blinking = 0; in gpio_led_set()
50 if (led_dat->can_sleep) in gpio_led_set()
51 gpiod_set_value_cansleep(led_dat->gpiod, level); in gpio_led_set()
53 gpiod_set_value(led_dat->gpiod, level); in gpio_led_set()
69 led_dat->blinking = 1; in gpio_blink_set()
70 return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK, in gpio_blink_set()
81 led_dat->cdev.default_trigger = template->default_trigger; in create_gpio_led()
82 led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod); in create_gpio_led()
83 if (!led_dat->can_sleep) in create_gpio_led()
84 led_dat->cdev.brightness_set = gpio_led_set; in create_gpio_led()
86 led_dat->cdev.brightness_set_blocking = gpio_led_set_blocking; in create_gpio_led()
87 led_dat->blinking = 0; in create_gpio_led()
89 led_dat->platform_gpio_blink_set = blink_set; in create_gpio_led()
90 led_dat->cdev.blink_set = gpio_blink_set; in create_gpio_led()
92 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) { in create_gpio_led()
93 state = gpiod_get_value_cansleep(led_dat->gpiod); in create_gpio_led()
97 state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); in create_gpio_led()
99 led_dat->cdev.brightness = state ? LED_FULL : LED_OFF; in create_gpio_led()
100 if (!template->retain_state_suspended) in create_gpio_led()
101 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; in create_gpio_led()
102 if (template->panic_indicator) in create_gpio_led()
103 led_dat->cdev.flags |= LED_PANIC_INDICATOR; in create_gpio_led()
104 if (template->retain_state_shutdown) in create_gpio_led()
105 led_dat->cdev.flags |= LED_RETAIN_AT_SHUTDOWN; in create_gpio_led()
107 ret = gpiod_direction_output(led_dat->gpiod, state); in create_gpio_led()
111 if (template->name) { in create_gpio_led()
112 led_dat->cdev.name = template->name; in create_gpio_led()
113 ret = devm_led_classdev_register(parent, &led_dat->cdev); in create_gpio_led()
116 ret = devm_led_classdev_register_ext(parent, &led_dat->cdev, in create_gpio_led()
130 struct device *dev = &pdev->dev; in gpio_leds_create()
137 return ERR_PTR(-ENODEV); in gpio_leds_create()
141 return ERR_PTR(-ENOMEM); in gpio_leds_create()
144 struct gpio_led_data *led_dat = &priv->leds[priv->num_leds]; in gpio_leds_create()
145 struct gpio_led led = {}; in gpio_leds_create() local
150 * will be updated after LED class device is registered, in gpio_leds_create()
151 * Only then the final LED name is known. in gpio_leds_create()
153 led.gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, child, in gpio_leds_create()
156 if (IS_ERR(led.gpiod)) { in gpio_leds_create()
158 return ERR_CAST(led.gpiod); in gpio_leds_create()
161 led_dat->gpiod = led.gpiod; in gpio_leds_create()
163 if (!fwnode_property_read_string(child, "default-state", in gpio_leds_create()
166 led.default_state = LEDS_GPIO_DEFSTATE_KEEP; in gpio_leds_create()
168 led.default_state = LEDS_GPIO_DEFSTATE_ON; in gpio_leds_create()
170 led.default_state = LEDS_GPIO_DEFSTATE_OFF; in gpio_leds_create()
173 if (fwnode_property_present(child, "retain-state-suspended")) in gpio_leds_create()
174 led.retain_state_suspended = 1; in gpio_leds_create()
175 if (fwnode_property_present(child, "retain-state-shutdown")) in gpio_leds_create()
176 led.retain_state_shutdown = 1; in gpio_leds_create()
177 if (fwnode_property_present(child, "panic-indicator")) in gpio_leds_create()
178 led.panic_indicator = 1; in gpio_leds_create()
180 ret = create_gpio_led(&led, led_dat, dev, child, NULL); in gpio_leds_create()
185 /* Set gpiod label to match the corresponding LED name. */ in gpio_leds_create()
186 gpiod_set_consumer_name(led_dat->gpiod, in gpio_leds_create()
187 led_dat->cdev.dev->kobj.name); in gpio_leds_create()
188 priv->num_leds++; in gpio_leds_create()
195 { .compatible = "gpio-leds", },
209 * This means the LED does not come from the device tree in gpio_led_get_gpiod()
216 gpiod_set_consumer_name(gpiod, template->name); in gpio_led_get_gpiod()
219 if (PTR_ERR(gpiod) != -ENOENT) in gpio_led_get_gpiod()
229 if (!gpio_is_valid(template->gpio)) in gpio_led_get_gpiod()
230 return ERR_PTR(-ENOENT); in gpio_led_get_gpiod()
232 if (template->active_low) in gpio_led_get_gpiod()
235 ret = devm_gpio_request_one(dev, template->gpio, flags, in gpio_led_get_gpiod()
236 template->name); in gpio_led_get_gpiod()
240 gpiod = gpio_to_desc(template->gpio); in gpio_led_get_gpiod()
242 return ERR_PTR(-EINVAL); in gpio_led_get_gpiod()
249 struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev); in gpio_led_probe()
253 if (pdata && pdata->num_leds) { in gpio_led_probe()
254 priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, pdata->num_leds), in gpio_led_probe()
257 return -ENOMEM; in gpio_led_probe()
259 priv->num_leds = pdata->num_leds; in gpio_led_probe()
260 for (i = 0; i < priv->num_leds; i++) { in gpio_led_probe()
261 const struct gpio_led *template = &pdata->leds[i]; in gpio_led_probe()
262 struct gpio_led_data *led_dat = &priv->leds[i]; in gpio_led_probe()
264 if (template->gpiod) in gpio_led_probe()
265 led_dat->gpiod = template->gpiod; in gpio_led_probe()
267 led_dat->gpiod = in gpio_led_probe()
268 gpio_led_get_gpiod(&pdev->dev, in gpio_led_probe()
270 if (IS_ERR(led_dat->gpiod)) { in gpio_led_probe()
271 dev_info(&pdev->dev, "Skipping unavailable LED gpio %d (%s)\n", in gpio_led_probe()
272 template->gpio, template->name); in gpio_led_probe()
277 &pdev->dev, NULL, in gpio_led_probe()
278 pdata->gpio_blink_set); in gpio_led_probe()
298 for (i = 0; i < priv->num_leds; i++) { in gpio_led_shutdown()
299 struct gpio_led_data *led = &priv->leds[i]; in gpio_led_shutdown() local
301 if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN)) in gpio_led_shutdown()
302 gpio_led_set(&led->cdev, LED_OFF); in gpio_led_shutdown()
310 .name = "leds-gpio",
317 MODULE_AUTHOR("Raphael Assenat <raph@8d.com>, Trent Piepho <tpiepho@freescale.com>");
318 MODULE_DESCRIPTION("GPIO LED driver");
320 MODULE_ALIAS("platform:leds-gpio");