status_led.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * (C) Copyright 2000-2002 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  3. * (C) Copyright 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * File: status_led.c
  25. *
  26. * Discription: Blink a board led to show boot progress. Led's
  27. * are connected via the MIOS module.
  28. */
  29. #include <common.h>
  30. #include <mpc5xx.h>
  31. #include <status_led.h>
  32. #ifdef CONFIG_STATUS_LED
  33. typedef struct {
  34. ulong mask;
  35. int state;
  36. int period;
  37. int cnt;
  38. } led_dev_t;
  39. led_dev_t led_dev[] = {
  40. { STATUS_LED_BIT,
  41. STATUS_LED_STATE,
  42. STATUS_LED_PERIOD,
  43. 0,
  44. },
  45. #if defined(STATUS_LED_BIT1)
  46. { STATUS_LED_BIT1,
  47. STATUS_LED_STATE1,
  48. STATUS_LED_PERIOD1,
  49. 0,
  50. },
  51. #endif
  52. #if defined(STATUS_LED_BIT2)
  53. { STATUS_LED_BIT2,
  54. STATUS_LED_STATE2,
  55. STATUS_LED_PERIOD2,
  56. 0,
  57. },
  58. #endif
  59. #if defined(STATUS_LED_BIT3)
  60. { STATUS_LED_BIT3,
  61. STATUS_LED_STATE3,
  62. STATUS_LED_PERIOD3,
  63. 0,
  64. },
  65. #endif
  66. };
  67. #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
  68. static int status_led_init_done = 0;
  69. static void status_led_init (void)
  70. {
  71. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  72. int i;
  73. for (i=0; i<MAX_LED_DEV; ++i) {
  74. led_dev_t *ld = &led_dev[i];
  75. immr->STATUS_LED_DIR = STATUS_LED_BIT;
  76. #if (STATUS_LED_ACTIVE == 0)
  77. if (ld->state == STATUS_LED_ON)
  78. immr->STATUS_LED_DAT &= ~(ld->mask);
  79. else
  80. immr->STATUS_LED_DAT |= ld->mask ;
  81. #else
  82. if (ld->state == STATUS_LED_ON)
  83. immr->STATUS_LED_DAT |= ld->mask ;
  84. else
  85. immr->STATUS_LED_DAT &= ~(ld->mask);
  86. #endif
  87. }
  88. status_led_init_done = 1;
  89. }
  90. void status_led_tick (ulong timestamp)
  91. {
  92. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  93. int i;
  94. if (!status_led_init_done)
  95. status_led_init();
  96. for (i=0; i<MAX_LED_DEV; ++i) {
  97. led_dev_t *ld = &led_dev[i];
  98. if (ld->state != STATUS_LED_BLINKING)
  99. continue;
  100. if (++(ld->cnt) >= ld->period) {
  101. immr->STATUS_LED_DAT ^= ld->mask;
  102. ld->cnt -= ld->period;
  103. }
  104. }
  105. }
  106. void status_led_set (int led, int state)
  107. {
  108. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  109. led_dev_t *ld;
  110. if (led < 0 || led >= MAX_LED_DEV)
  111. return;
  112. if (!status_led_init_done)
  113. status_led_init();
  114. ld = &led_dev[led];
  115. switch (state) {
  116. default:
  117. return;
  118. case STATUS_LED_BLINKING:
  119. ld->cnt = 0; /* always start with full period */
  120. /* fall through */ /* always start with LED _ON_ */
  121. case STATUS_LED_ON:
  122. #if (STATUS_LED_ACTIVE == 0)
  123. immr->STATUS_LED_DAT &= ~(ld->mask);
  124. #else
  125. immr->STATUS_LED_DAT |= ld->mask ;
  126. #endif
  127. break;
  128. case STATUS_LED_OFF:
  129. #if (STATUS_LED_ACTIVE == 0)
  130. immr->STATUS_LED_DAT |= ld->mask ;
  131. #else
  132. immr->STATUS_LED_DAT &= ~(ld->mask);
  133. #endif
  134. break;
  135. }
  136. ld->state = state;
  137. }
  138. #endif /* CONFIG_STATUS_LED */