1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
11 #include <dm/device-internal.h>
13 #include <dm/uclass-internal.h>
15 int led_get_by_label(const char *label, struct udevice **devp)
21 ret = uclass_get(UCLASS_LED, &uc);
24 uclass_foreach_dev(dev, uc) {
25 struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
27 /* Ignore the top-level LED node */
28 if (uc_plat->label && !strcmp(label, uc_plat->label))
29 return uclass_get_device_tail(dev, 0, devp);
35 int led_set_state(struct udevice *dev, enum led_state_t state)
37 struct led_ops *ops = led_get_ops(dev);
42 return ops->set_state(dev, state);
45 enum led_state_t led_get_state(struct udevice *dev)
47 struct led_ops *ops = led_get_ops(dev);
52 return ops->get_state(dev);
55 #ifdef CONFIG_LED_BLINK
56 int led_set_period(struct udevice *dev, int period_ms)
58 struct led_ops *ops = led_get_ops(dev);
63 return ops->set_period(dev, period_ms);
67 int led_default_state(void)
71 const char *default_state;
74 ret = uclass_get(UCLASS_LED, &uc);
77 for (uclass_find_first_device(UCLASS_LED, &dev);
79 uclass_find_next_device(&dev)) {
80 default_state = dev_read_string(dev, "default-state");
83 ret = device_probe(dev);
86 if (!strncmp(default_state, "on", 2))
87 led_set_state(dev, LEDST_ON);
88 else if (!strncmp(default_state, "off", 3))
89 led_set_state(dev, LEDST_OFF);
90 /* default-state = "keep" : device is only probed */
96 UCLASS_DRIVER(led) = {
99 .per_device_platdata_auto_alloc_size = sizeof(struct led_uc_plat),