status_led.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000-2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <status_led.h>
  8. /*
  9. * The purpose of this code is to signal the operational status of a
  10. * target which usually boots over the network; while running in
  11. * U-Boot, a status LED is blinking. As soon as a valid BOOTP reply
  12. * message has been received, the LED is turned off. The Linux
  13. * kernel, once it is running, will start blinking the LED again,
  14. * with another frequency.
  15. */
  16. /* ------------------------------------------------------------------------- */
  17. typedef struct {
  18. led_id_t mask;
  19. int state;
  20. int period;
  21. int cnt;
  22. } led_dev_t;
  23. led_dev_t led_dev[] = {
  24. { CONFIG_LED_STATUS_BIT,
  25. CONFIG_LED_STATUS_STATE,
  26. LED_STATUS_PERIOD,
  27. 0,
  28. },
  29. #if defined(CONFIG_LED_STATUS1)
  30. { CONFIG_LED_STATUS_BIT1,
  31. CONFIG_LED_STATUS_STATE1,
  32. LED_STATUS_PERIOD1,
  33. 0,
  34. },
  35. #endif
  36. #if defined(CONFIG_LED_STATUS2)
  37. { CONFIG_LED_STATUS_BIT2,
  38. CONFIG_LED_STATUS_STATE2,
  39. LED_STATUS_PERIOD2,
  40. 0,
  41. },
  42. #endif
  43. #if defined(CONFIG_LED_STATUS3)
  44. { CONFIG_LED_STATUS_BIT3,
  45. CONFIG_LED_STATUS_STATE3,
  46. LED_STATUS_PERIOD3,
  47. 0,
  48. },
  49. #endif
  50. #if defined(CONFIG_LED_STATUS4)
  51. { CONFIG_LED_STATUS_BIT4,
  52. CONFIG_LED_STATUS_STATE4,
  53. LED_STATUS_PERIOD4,
  54. 0,
  55. },
  56. #endif
  57. #if defined(CONFIG_LED_STATUS5)
  58. { CONFIG_LED_STATUS_BIT5,
  59. CONFIG_LED_STATUS_STATE5,
  60. LED_STATUS_PERIOD5,
  61. 0,
  62. },
  63. #endif
  64. };
  65. #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
  66. static int status_led_init_done = 0;
  67. void status_led_init(void)
  68. {
  69. led_dev_t *ld;
  70. int i;
  71. for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++)
  72. __led_init (ld->mask, ld->state);
  73. status_led_init_done = 1;
  74. }
  75. void status_led_tick(ulong timestamp)
  76. {
  77. led_dev_t *ld;
  78. int i;
  79. if (!status_led_init_done)
  80. status_led_init();
  81. for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
  82. if (ld->state != CONFIG_LED_STATUS_BLINKING)
  83. continue;
  84. if (++ld->cnt >= ld->period) {
  85. __led_toggle (ld->mask);
  86. ld->cnt -= ld->period;
  87. }
  88. }
  89. }
  90. void status_led_set(int led, int state)
  91. {
  92. led_dev_t *ld;
  93. if (led < 0 || led >= MAX_LED_DEV)
  94. return;
  95. if (!status_led_init_done)
  96. status_led_init();
  97. ld = &led_dev[led];
  98. ld->state = state;
  99. if (state == CONFIG_LED_STATUS_BLINKING) {
  100. ld->cnt = 0; /* always start with full period */
  101. state = CONFIG_LED_STATUS_ON; /* always start with LED _ON_ */
  102. }
  103. __led_set (ld->mask, state);
  104. }