led.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2009 Wind River Systems, Inc.
  3. * Tom Rix <Tom.Rix@windriver.com>
  4. * (C) Copyright 2009
  5. * Eric Benard <eric@eukrea.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <status_led.h>
  27. #include <asm/arch/at91sam9260.h>
  28. #include <asm/arch/at91_pmc.h>
  29. #include <asm/arch/gpio.h>
  30. #include <asm/io.h>
  31. static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
  32. STATUS_LED_OFF, STATUS_LED_OFF};
  33. void coloured_LED_init(void)
  34. {
  35. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  36. /* Enable clock */
  37. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  38. at91_set_pio_output(CONFIG_RED_LED, 1);
  39. at91_set_pio_output(CONFIG_GREEN_LED, 1);
  40. at91_set_pio_output(CONFIG_YELLOW_LED, 1);
  41. at91_set_pio_output(CONFIG_BLUE_LED, 1);
  42. at91_set_pio_value(CONFIG_RED_LED, 1);
  43. at91_set_pio_value(CONFIG_GREEN_LED, 1);
  44. at91_set_pio_value(CONFIG_YELLOW_LED, 1);
  45. at91_set_pio_value(CONFIG_BLUE_LED, 1);
  46. }
  47. void red_led_off(void)
  48. {
  49. at91_set_pio_value(CONFIG_RED_LED, 1);
  50. saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
  51. }
  52. void green_led_off(void)
  53. {
  54. at91_set_pio_value(CONFIG_GREEN_LED, 1);
  55. saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
  56. }
  57. void yellow_led_off(void)
  58. {
  59. at91_set_pio_value(CONFIG_YELLOW_LED, 1);
  60. saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
  61. }
  62. void blue_led_off(void)
  63. {
  64. at91_set_pio_value(CONFIG_BLUE_LED, 1);
  65. saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
  66. }
  67. void red_led_on(void)
  68. {
  69. at91_set_pio_value(CONFIG_RED_LED, 0);
  70. saved_state[STATUS_LED_RED] = STATUS_LED_ON;
  71. }
  72. void green_led_on(void)
  73. {
  74. at91_set_pio_value(CONFIG_GREEN_LED, 0);
  75. saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
  76. }
  77. void yellow_led_on(void)
  78. {
  79. at91_set_pio_value(CONFIG_YELLOW_LED, 0);
  80. saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
  81. }
  82. void blue_led_on(void)
  83. {
  84. at91_set_pio_value(CONFIG_BLUE_LED, 0);
  85. saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
  86. }
  87. void __led_init(led_id_t mask, int state)
  88. {
  89. __led_set(mask, state);
  90. }
  91. void __led_toggle(led_id_t mask)
  92. {
  93. if (STATUS_LED_BLUE == mask) {
  94. if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
  95. blue_led_off();
  96. else
  97. blue_led_on();
  98. } else if (STATUS_LED_RED == mask) {
  99. if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
  100. red_led_off();
  101. else
  102. red_led_on();
  103. } else if (STATUS_LED_GREEN == mask) {
  104. if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
  105. green_led_off();
  106. else
  107. green_led_on();
  108. } else if (STATUS_LED_YELLOW == mask) {
  109. if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
  110. yellow_led_off();
  111. else
  112. yellow_led_on();
  113. }
  114. }
  115. void __led_set(led_id_t mask, int state)
  116. {
  117. if (STATUS_LED_BLUE == mask) {
  118. if (STATUS_LED_ON == state)
  119. blue_led_on();
  120. else
  121. blue_led_off();
  122. } else if (STATUS_LED_RED == mask) {
  123. if (STATUS_LED_ON == state)
  124. red_led_on();
  125. else
  126. red_led_off();
  127. } else if (STATUS_LED_GREEN == mask) {
  128. if (STATUS_LED_ON == state)
  129. green_led_on();
  130. else
  131. green_led_off();
  132. } else if (STATUS_LED_YELLOW == mask) {
  133. if (STATUS_LED_ON == state)
  134. yellow_led_on();
  135. else
  136. yellow_led_off();
  137. }
  138. }