leds-h2p2-debug.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * linux/arch/arm/mach-omap1/leds-h2p2-debug.c
  3. *
  4. * Copyright 2003 by Texas Instruments Incorporated
  5. *
  6. * There are 16 LEDs on the debug board (all green); four may be used
  7. * for logical 'green', 'amber', 'red', and 'blue' (after "claiming").
  8. *
  9. * The "surfer" expansion board and H2 sample board also have two-color
  10. * green+red LEDs (in parallel), used here for timer and idle indicators.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/sched.h>
  15. #include <linux/io.h>
  16. #include <mach/hardware.h>
  17. #include <asm/leds.h>
  18. #include <asm/system.h>
  19. #include <asm/mach-types.h>
  20. #include <plat/fpga.h>
  21. #include <mach/gpio.h>
  22. #include "leds.h"
  23. #define GPIO_LED_RED 3
  24. #define GPIO_LED_GREEN OMAP_MPUIO(4)
  25. #define LED_STATE_ENABLED 0x01
  26. #define LED_STATE_CLAIMED 0x02
  27. #define LED_TIMER_ON 0x04
  28. #define GPIO_IDLE GPIO_LED_GREEN
  29. #define GPIO_TIMER GPIO_LED_RED
  30. void h2p2_dbg_leds_event(led_event_t evt)
  31. {
  32. unsigned long flags;
  33. static struct h2p2_dbg_fpga __iomem *fpga;
  34. static u16 led_state, hw_led_state;
  35. local_irq_save(flags);
  36. if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
  37. goto done;
  38. switch (evt) {
  39. case led_start:
  40. if (!fpga)
  41. fpga = ioremap(H2P2_DBG_FPGA_START,
  42. H2P2_DBG_FPGA_SIZE);
  43. if (fpga) {
  44. led_state |= LED_STATE_ENABLED;
  45. __raw_writew(~0, &fpga->leds);
  46. }
  47. break;
  48. case led_stop:
  49. case led_halted:
  50. /* all leds off during suspend or shutdown */
  51. if (! machine_is_omap_perseus2()) {
  52. gpio_set_value(GPIO_TIMER, 0);
  53. gpio_set_value(GPIO_IDLE, 0);
  54. }
  55. __raw_writew(~0, &fpga->leds);
  56. led_state &= ~LED_STATE_ENABLED;
  57. if (evt == led_halted) {
  58. iounmap(fpga);
  59. fpga = NULL;
  60. }
  61. goto done;
  62. case led_claim:
  63. led_state |= LED_STATE_CLAIMED;
  64. hw_led_state = 0;
  65. break;
  66. case led_release:
  67. led_state &= ~LED_STATE_CLAIMED;
  68. break;
  69. #ifdef CONFIG_LEDS_TIMER
  70. case led_timer:
  71. led_state ^= LED_TIMER_ON;
  72. if (machine_is_omap_perseus2())
  73. hw_led_state ^= H2P2_DBG_FPGA_P2_LED_TIMER;
  74. else {
  75. gpio_set_value(GPIO_TIMER, led_state & LED_TIMER_ON);
  76. goto done;
  77. }
  78. break;
  79. #endif
  80. #ifdef CONFIG_LEDS_CPU
  81. case led_idle_start:
  82. if (machine_is_omap_perseus2())
  83. hw_led_state |= H2P2_DBG_FPGA_P2_LED_IDLE;
  84. else {
  85. gpio_set_value(GPIO_IDLE, 1);
  86. goto done;
  87. }
  88. break;
  89. case led_idle_end:
  90. if (machine_is_omap_perseus2())
  91. hw_led_state &= ~H2P2_DBG_FPGA_P2_LED_IDLE;
  92. else {
  93. gpio_set_value(GPIO_IDLE, 0);
  94. goto done;
  95. }
  96. break;
  97. #endif
  98. case led_green_on:
  99. hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
  100. break;
  101. case led_green_off:
  102. hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
  103. break;
  104. case led_amber_on:
  105. hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
  106. break;
  107. case led_amber_off:
  108. hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
  109. break;
  110. case led_red_on:
  111. hw_led_state |= H2P2_DBG_FPGA_LED_RED;
  112. break;
  113. case led_red_off:
  114. hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
  115. break;
  116. case led_blue_on:
  117. hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
  118. break;
  119. case led_blue_off:
  120. hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
  121. break;
  122. default:
  123. break;
  124. }
  125. /*
  126. * Actually burn the LEDs
  127. */
  128. if (led_state & LED_STATE_ENABLED)
  129. __raw_writew(~hw_led_state, &fpga->leds);
  130. done:
  131. local_irq_restore(flags);
  132. }