led.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/arch/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. /* Enable clock */
  36. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOC);
  37. at91_set_gpio_output(CONFIG_RED_LED, 1);
  38. at91_set_gpio_output(CONFIG_GREEN_LED, 1);
  39. at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
  40. at91_set_gpio_output(CONFIG_BLUE_LED, 1);
  41. at91_set_gpio_value(CONFIG_RED_LED, 1);
  42. at91_set_gpio_value(CONFIG_GREEN_LED, 1);
  43. at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
  44. at91_set_gpio_value(CONFIG_BLUE_LED, 1);
  45. }
  46. void red_LED_off(void)
  47. {
  48. at91_set_gpio_value(CONFIG_RED_LED, 1);
  49. saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
  50. }
  51. void green_LED_off(void)
  52. {
  53. at91_set_gpio_value(CONFIG_GREEN_LED, 1);
  54. saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
  55. }
  56. void yellow_LED_off(void)
  57. {
  58. at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
  59. saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
  60. }
  61. void blue_LED_off(void)
  62. {
  63. at91_set_gpio_value(CONFIG_BLUE_LED, 1);
  64. saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
  65. }
  66. void red_LED_on(void)
  67. {
  68. at91_set_gpio_value(CONFIG_RED_LED, 0);
  69. saved_state[STATUS_LED_RED] = STATUS_LED_ON;
  70. }
  71. void green_LED_on(void)
  72. {
  73. at91_set_gpio_value(CONFIG_GREEN_LED, 0);
  74. saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
  75. }
  76. void yellow_LED_on(void)
  77. {
  78. at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
  79. saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
  80. }
  81. void blue_LED_on(void)
  82. {
  83. at91_set_gpio_value(CONFIG_BLUE_LED, 0);
  84. saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
  85. }
  86. void __led_init(led_id_t mask, int state)
  87. {
  88. __led_set(mask, state);
  89. }
  90. void __led_toggle(led_id_t mask)
  91. {
  92. if (STATUS_LED_BLUE == mask) {
  93. if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
  94. blue_LED_off();
  95. else
  96. blue_LED_on();
  97. } else if (STATUS_LED_RED == mask) {
  98. if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
  99. red_LED_off();
  100. else
  101. red_LED_on();
  102. } else if (STATUS_LED_GREEN == mask) {
  103. if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
  104. green_LED_off();
  105. else
  106. green_LED_on();
  107. } else if (STATUS_LED_YELLOW == mask) {
  108. if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
  109. yellow_LED_off();
  110. else
  111. yellow_LED_on();
  112. }
  113. }
  114. void __led_set(led_id_t mask, int state)
  115. {
  116. if (STATUS_LED_BLUE == mask) {
  117. if (STATUS_LED_ON == state)
  118. blue_LED_on();
  119. else
  120. blue_LED_off();
  121. } else if (STATUS_LED_RED == mask) {
  122. if (STATUS_LED_ON == state)
  123. red_LED_on();
  124. else
  125. red_LED_off();
  126. } else if (STATUS_LED_GREEN == mask) {
  127. if (STATUS_LED_ON == state)
  128. green_LED_on();
  129. else
  130. green_LED_off();
  131. } else if (STATUS_LED_YELLOW == mask) {
  132. if (STATUS_LED_ON == state)
  133. yellow_LED_on();
  134. else
  135. yellow_LED_off();
  136. }
  137. }