summaryrefslogtreecommitdiff
path: root/drivers/led
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/led')
-rw-r--r--drivers/led/Kconfig24
-rw-r--r--drivers/led/Makefile2
-rw-r--r--drivers/led/led-uclass.c162
-rw-r--r--drivers/led/led_sw_blink.c17
4 files changed, 202 insertions, 3 deletions
diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index bee74b25751..c98cbf92fab 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -9,6 +9,30 @@ config LED
can provide access to board-specific LEDs. Use of the device tree
for configuration is encouraged.
+config LED_BOOT
+ bool "Enable LED boot support"
+ help
+ Enable LED boot support.
+
+ LED boot is a specific LED assigned to signal boot operation status.
+ Defined in Device Tree /options/u-boot node. Refer here for the supported
+ options [1].
+
+ [1] dtschema/schemas/options/u-boot.yaml
+
+config LED_ACTIVITY
+ bool "Enable LED activity support"
+ help
+ Enable LED activity support.
+
+ LED activity is a specific LED assigned to signal activity operation
+ like file trasnfer, flash write/erase...
+
+ Defined in Device Tree /options/u-boot node. Refer here for the supported
+ options [1].
+
+ [1] dtschema/schemas/options/u-boot.yaml
+
config LED_BCM6328
bool "LED Support for BCM6328"
depends on LED && ARCH_BMIPS
diff --git a/drivers/led/Makefile b/drivers/led/Makefile
index e27aa488482..aa64a38b4e1 100644
--- a/drivers/led/Makefile
+++ b/drivers/led/Makefile
@@ -10,6 +10,6 @@ obj-$(CONFIG_LED_BCM6358) += led_bcm6358.o
obj-$(CONFIG_LED_BCM6753) += led_bcm6753.o
obj-$(CONFIG_LED_BCM6858) += led_bcm6858.o
obj-$(CONFIG_LED_PWM) += led_pwm.o
-obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o
+obj-$(CONFIG_$(XPL_)LED_GPIO) += led_gpio.o
obj-$(CONFIG_LED_CORTINA) += led_cortina.o
obj-$(CONFIG_LED_LP5562) += led_lp5562.o
diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index 199d68bc25a..05e09909b7d 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -94,6 +94,144 @@ int led_set_period(struct udevice *dev, int period_ms)
return -ENOSYS;
}
+#ifdef CONFIG_LED_BOOT
+static int led_boot_get(struct udevice **devp, int *period_ms)
+{
+ struct led_uc_priv *priv;
+ struct uclass *uc;
+ int ret;
+
+ ret = uclass_get(UCLASS_LED, &uc);
+ if (ret)
+ return ret;
+
+ priv = uclass_get_priv(uc);
+ if (!priv->boot_led_label)
+ return -ENOENT;
+
+ if (period_ms)
+ *period_ms = priv->boot_led_period;
+
+ return led_get_by_label(priv->boot_led_label, devp);
+}
+
+int led_boot_on(void)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = led_boot_get(&dev, NULL);
+ if (ret)
+ return ret;
+
+ return led_set_state(dev, LEDST_ON);
+}
+
+int led_boot_off(void)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = led_boot_get(&dev, NULL);
+ if (ret)
+ return ret;
+
+ return led_set_state(dev, LEDST_OFF);
+}
+
+#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK)
+int led_boot_blink(void)
+{
+ struct udevice *dev;
+ int period_ms, ret;
+
+ ret = led_boot_get(&dev, &period_ms);
+ if (ret)
+ return ret;
+
+ ret = led_set_period(dev, period_ms);
+ if (ret) {
+ if (ret != -ENOSYS)
+ return ret;
+
+ /* fallback to ON with no set_period and no SW_BLINK */
+ return led_set_state(dev, LEDST_ON);
+ }
+
+ return led_set_state(dev, LEDST_BLINK);
+}
+#endif
+#endif
+
+#ifdef CONFIG_LED_ACTIVITY
+static int led_activity_get(struct udevice **devp, int *period_ms)
+{
+ struct led_uc_priv *priv;
+ struct uclass *uc;
+ int ret;
+
+ ret = uclass_get(UCLASS_LED, &uc);
+ if (ret)
+ return ret;
+
+ priv = uclass_get_priv(uc);
+ if (!priv->activity_led_label)
+ return -ENOENT;
+
+ if (period_ms)
+ *period_ms = priv->activity_led_period;
+
+ return led_get_by_label(priv->activity_led_label, devp);
+}
+
+int led_activity_on(void)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = led_activity_get(&dev, NULL);
+ if (ret)
+ return ret;
+
+ return led_set_state(dev, LEDST_ON);
+}
+
+int led_activity_off(void)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = led_activity_get(&dev, NULL);
+ if (ret)
+ return ret;
+
+ return led_set_state(dev, LEDST_OFF);
+}
+
+#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK)
+int led_activity_blink(void)
+{
+ struct udevice *dev;
+ int period_ms, ret;
+
+ ret = led_activity_get(&dev, &period_ms);
+ if (ret)
+ return ret;
+
+ ret = led_set_period(dev, period_ms);
+ if (ret) {
+ if (ret != -ENOSYS)
+ return ret;
+
+ /* fallback to ON with no set_period and no SW_BLINK */
+ return led_set_state(dev, LEDST_ON);
+ }
+
+ return led_set_state(dev, LEDST_BLINK);
+}
+#endif
+#endif
+
static int led_post_bind(struct udevice *dev)
{
struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev);
@@ -158,10 +296,34 @@ static int led_post_probe(struct udevice *dev)
return ret;
}
+#if defined(CONFIG_LED_BOOT) || defined(CONFIG_LED_ACTIVITY)
+static int led_init(struct uclass *uc)
+{
+ struct led_uc_priv *priv = uclass_get_priv(uc);
+
+#ifdef CONFIG_LED_BOOT
+ priv->boot_led_label = ofnode_options_read_str("boot-led");
+ priv->boot_led_period = ofnode_options_read_int("boot-led-period", 250);
+#endif
+
+#ifdef CONFIG_LED_ACTIVITY
+ priv->activity_led_label = ofnode_options_read_str("activity-led");
+ priv->activity_led_period = ofnode_options_read_int("activity-led-period",
+ 250);
+#endif
+
+ return 0;
+}
+#endif
+
UCLASS_DRIVER(led) = {
.id = UCLASS_LED,
.name = "led",
.per_device_plat_auto = sizeof(struct led_uc_plat),
.post_bind = led_post_bind,
.post_probe = led_post_probe,
+#if defined(CONFIG_LED_BOOT) || defined(CONFIG_LED_ACTIVITY)
+ .init = led_init,
+ .priv_auto = sizeof(struct led_uc_priv),
+#endif
};
diff --git a/drivers/led/led_sw_blink.c b/drivers/led/led_sw_blink.c
index 9e36edbee47..06a43db340c 100644
--- a/drivers/led/led_sw_blink.c
+++ b/drivers/led/led_sw_blink.c
@@ -103,8 +103,21 @@ bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state)
return false;
if (state == LEDST_BLINK) {
- /* start blinking on next led_sw_blink() call */
- sw_blink->state = LED_SW_BLINK_ST_OFF;
+ struct led_ops *ops = led_get_ops(dev);
+
+ /*
+ * toggle LED initially and start blinking on next
+ * led_sw_blink() call.
+ */
+ switch (ops->get_state(dev)) {
+ case LEDST_ON:
+ ops->set_state(dev, LEDST_OFF);
+ sw_blink->state = LED_SW_BLINK_ST_OFF;
+ default:
+ ops->set_state(dev, LEDST_ON);
+ sw_blink->state = LED_SW_BLINK_ST_ON;
+ }
+
return true;
}