led.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <asm/io.h>
  23. #include <asm/arch/ep93xx.h>
  24. #include <config.h>
  25. #include <status_led.h>
  26. static uint8_t saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
  27. static uint32_t gpio_pin[2] = {1 << STATUS_LED_GREEN,
  28. 1 << STATUS_LED_RED};
  29. inline void switch_LED_on(uint8_t led)
  30. {
  31. register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
  32. writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr);
  33. saved_state[led] = STATUS_LED_ON;
  34. }
  35. inline void switch_LED_off(uint8_t led)
  36. {
  37. register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
  38. writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr);
  39. saved_state[led] = STATUS_LED_OFF;
  40. }
  41. void red_LED_on(void)
  42. {
  43. switch_LED_on(STATUS_LED_RED);
  44. }
  45. void red_LED_off(void)
  46. {
  47. switch_LED_off(STATUS_LED_RED);
  48. }
  49. void green_LED_on(void)
  50. {
  51. switch_LED_on(STATUS_LED_GREEN);
  52. }
  53. void green_LED_off(void)
  54. {
  55. switch_LED_off(STATUS_LED_GREEN);
  56. }
  57. void __led_init(led_id_t mask, int state)
  58. {
  59. __led_set(mask, state);
  60. }
  61. void __led_toggle(led_id_t mask)
  62. {
  63. if (STATUS_LED_RED == mask) {
  64. if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
  65. red_LED_off();
  66. else
  67. red_LED_on();
  68. } else if (STATUS_LED_GREEN == mask) {
  69. if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
  70. green_LED_off();
  71. else
  72. green_LED_on();
  73. }
  74. }
  75. void __led_set(led_id_t mask, int state)
  76. {
  77. if (STATUS_LED_RED == mask) {
  78. if (STATUS_LED_ON == state)
  79. red_LED_on();
  80. else
  81. red_LED_off();
  82. } else if (STATUS_LED_GREEN == mask) {
  83. if (STATUS_LED_ON == state)
  84. green_LED_on();
  85. else
  86. green_LED_off();
  87. }
  88. }