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