For current U-Boot to initialize status LEDs via status_led_init(), it is required to have both CONFIG_STATUS_LED and STATUS_LED_BOOT defined. This may be a particular concern with GPIO LEDs, where __led_init() is required to correctly set up the GPIO (gpio_request and gpio_direction_output). Without STATUS_LED_BOOT the initialization isn't called, which could leave the user with a non-functional "led" command - due to the fact that the LED routines in gpio_led.c use gpio_set_value() just fine, but the GPIO never got set up properly in the first place.

I think having CONFIG_STATUS_LED is sufficient to justify a corresponding call to status_led_init(), even with no STATUS_LED_BOOT defined. To do so, common/board_r.c needs some way to call that routine either directly (which probably requires exposing it via status_led.h) or indirectly. For the latter, I've attached a patch that (ab)uses an invalid LED id in status_led_set() to enforce the init.

Regards, B. Nortmann


---
 common/board_r.c          | 10 +++++++---
 drivers/misc/status_led.c |  7 ++++---
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index 0335f6b..c67f459 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -547,11 +547,15 @@ static int initr_kgdb(void)
 }
 #endif

-#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
+#ifdef CONFIG_STATUS_LED
 static int initr_status_led(void)
 {
+#ifdef STATUS_LED_BOOT
     status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
-
+#else
+    /* use invalid LED id to enforce status_led_init() */
+    status_led_set(-1, 0);
+#endif
     return 0;
 }
 #endif
@@ -838,7 +842,7 @@ init_fnc_t init_sequence_r[] = {
     || defined(CONFIG_M68K)
     timer_init,        /* initialize timer */
 #endif
-#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
+#ifdef CONFIG_STATUS_LED
     initr_status_led,
 #endif
     /* PPC has a udelay(20) here dating from 2002. Why? */
diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c
index ed9adb2..4751c8d 100644
--- a/drivers/misc/status_led.c
+++ b/drivers/misc/status_led.c
@@ -94,12 +94,13 @@ void status_led_set (int led, int state)
 {
     led_dev_t *ld;

-    if (led < 0 || led >= MAX_LED_DEV)
-        return;
-
+    /* reordered, allows using invalid led ID to enforce init */
     if (!status_led_init_done)
         status_led_init ();

+    if (led < 0 || led >= MAX_LED_DEV)
+        return;
+
     ld = &led_dev[led];

     ld->state = state;
--
2.0.5

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to