Lines Matching +full:retain +full:- +full:state +full:- +full:shutdown

1 // SPDX-License-Identifier: GPL-2.0-only
46 if (led_dat->blinking) { in gpio_led_set()
47 led_dat->platform_gpio_blink_set(led_dat->gpiod, level, in gpio_led_set()
49 led_dat->blinking = 0; in gpio_led_set()
51 if (led_dat->can_sleep) in gpio_led_set()
52 gpiod_set_value_cansleep(led_dat->gpiod, level); in gpio_led_set()
54 gpiod_set_value(led_dat->gpiod, level); in gpio_led_set()
70 led_dat->blinking = 1; in gpio_blink_set()
71 return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK, in gpio_blink_set()
80 int ret, state; in create_gpio_led() local
82 led_dat->cdev.default_trigger = template->default_trigger; in create_gpio_led()
83 led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod); in create_gpio_led()
84 if (!led_dat->can_sleep) in create_gpio_led()
85 led_dat->cdev.brightness_set = gpio_led_set; in create_gpio_led()
87 led_dat->cdev.brightness_set_blocking = gpio_led_set_blocking; in create_gpio_led()
88 led_dat->blinking = 0; in create_gpio_led()
90 led_dat->platform_gpio_blink_set = blink_set; in create_gpio_led()
91 led_dat->cdev.blink_set = gpio_blink_set; in create_gpio_led()
93 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) { in create_gpio_led()
94 state = gpiod_get_value_cansleep(led_dat->gpiod); in create_gpio_led()
95 if (state < 0) in create_gpio_led()
96 return state; in create_gpio_led()
98 state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); in create_gpio_led()
100 led_dat->cdev.brightness = state; in create_gpio_led()
101 led_dat->cdev.max_brightness = 1; in create_gpio_led()
102 if (!template->retain_state_suspended) in create_gpio_led()
103 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; in create_gpio_led()
104 if (template->panic_indicator) in create_gpio_led()
105 led_dat->cdev.flags |= LED_PANIC_INDICATOR; in create_gpio_led()
106 if (template->retain_state_shutdown) in create_gpio_led()
107 led_dat->cdev.flags |= LED_RETAIN_AT_SHUTDOWN; in create_gpio_led()
109 ret = gpiod_direction_output(led_dat->gpiod, state); in create_gpio_led()
113 if (template->name) { in create_gpio_led()
114 led_dat->cdev.name = template->name; in create_gpio_led()
115 ret = devm_led_classdev_register(parent, &led_dat->cdev); in create_gpio_led()
118 ret = devm_led_classdev_register_ext(parent, &led_dat->cdev, in create_gpio_led()
132 struct device *dev = &pdev->dev; in gpio_leds_create()
139 return ERR_PTR(-ENODEV); in gpio_leds_create()
143 return ERR_PTR(-ENOMEM); in gpio_leds_create()
146 struct gpio_led_data *led_dat = &priv->leds[priv->num_leds]; in gpio_leds_create()
162 led_dat->gpiod = led.gpiod; in gpio_leds_create()
166 if (fwnode_property_present(child, "retain-state-suspended")) in gpio_leds_create()
168 if (fwnode_property_present(child, "retain-state-shutdown")) in gpio_leds_create()
170 if (fwnode_property_present(child, "panic-indicator")) in gpio_leds_create()
179 gpiod_set_consumer_name(led_dat->gpiod, in gpio_leds_create()
180 led_dat->cdev.dev->kobj.name); in gpio_leds_create()
181 priv->num_leds++; in gpio_leds_create()
188 { .compatible = "gpio-leds", },
209 gpiod_set_consumer_name(gpiod, template->name); in gpio_led_get_gpiod()
212 if (PTR_ERR(gpiod) != -ENOENT) in gpio_led_get_gpiod()
222 if (!gpio_is_valid(template->gpio)) in gpio_led_get_gpiod()
223 return ERR_PTR(-ENOENT); in gpio_led_get_gpiod()
225 if (template->active_low) in gpio_led_get_gpiod()
228 ret = devm_gpio_request_one(dev, template->gpio, flags, in gpio_led_get_gpiod()
229 template->name); in gpio_led_get_gpiod()
233 gpiod = gpio_to_desc(template->gpio); in gpio_led_get_gpiod()
235 return ERR_PTR(-EINVAL); in gpio_led_get_gpiod()
242 struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev); in gpio_led_probe()
246 if (pdata && pdata->num_leds) { in gpio_led_probe()
247 priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, pdata->num_leds), in gpio_led_probe()
250 return -ENOMEM; in gpio_led_probe()
252 priv->num_leds = pdata->num_leds; in gpio_led_probe()
253 for (i = 0; i < priv->num_leds; i++) { in gpio_led_probe()
254 const struct gpio_led *template = &pdata->leds[i]; in gpio_led_probe()
255 struct gpio_led_data *led_dat = &priv->leds[i]; in gpio_led_probe()
257 if (template->gpiod) in gpio_led_probe()
258 led_dat->gpiod = template->gpiod; in gpio_led_probe()
260 led_dat->gpiod = in gpio_led_probe()
261 gpio_led_get_gpiod(&pdev->dev, in gpio_led_probe()
263 if (IS_ERR(led_dat->gpiod)) { in gpio_led_probe()
264 dev_info(&pdev->dev, "Skipping unavailable LED gpio %d (%s)\n", in gpio_led_probe()
265 template->gpio, template->name); in gpio_led_probe()
270 &pdev->dev, NULL, in gpio_led_probe()
271 pdata->gpio_blink_set); in gpio_led_probe()
291 for (i = 0; i < priv->num_leds; i++) { in gpio_led_shutdown()
292 struct gpio_led_data *led = &priv->leds[i]; in gpio_led_shutdown()
294 if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN)) in gpio_led_shutdown()
295 gpio_led_set(&led->cdev, LED_OFF); in gpio_led_shutdown()
301 .shutdown = gpio_led_shutdown,
303 .name = "leds-gpio",
313 MODULE_ALIAS("platform:leds-gpio");