leds-h2p2-debug.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * linux/arch/arm/mach-omap/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/arch/fpga.h>
  21. #include <asm/arch/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. omap_set_gpio_dataout(GPIO_TIMER, 0);
  52. omap_set_gpio_dataout(GPIO_IDLE, 0);
  53. __raw_writew(~0, &fpga->leds);
  54. led_state &= ~LED_STATE_ENABLED;
  55. if (evt == led_halted) {
  56. iounmap(fpga);
  57. fpga = NULL;
  58. }
  59. goto done;
  60. case led_claim:
  61. led_state |= LED_STATE_CLAIMED;
  62. hw_led_state = 0;
  63. break;
  64. case led_release:
  65. led_state &= ~LED_STATE_CLAIMED;
  66. break;
  67. #ifdef CONFIG_LEDS_TIMER
  68. case led_timer:
  69. led_state ^= LED_TIMER_ON;
  70. omap_set_gpio_dataout(GPIO_TIMER, led_state & LED_TIMER_ON);
  71. goto done;
  72. #endif
  73. #ifdef CONFIG_LEDS_CPU
  74. case led_idle_start:
  75. omap_set_gpio_dataout(GPIO_IDLE, 1);
  76. goto done;
  77. case led_idle_end:
  78. omap_set_gpio_dataout(GPIO_IDLE, 0);
  79. goto done;
  80. #endif
  81. case led_green_on:
  82. hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
  83. break;
  84. case led_green_off:
  85. hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
  86. break;
  87. case led_amber_on:
  88. hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
  89. break;
  90. case led_amber_off:
  91. hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
  92. break;
  93. case led_red_on:
  94. hw_led_state |= H2P2_DBG_FPGA_LED_RED;
  95. break;
  96. case led_red_off:
  97. hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
  98. break;
  99. case led_blue_on:
  100. hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
  101. break;
  102. case led_blue_off:
  103. hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
  104. break;
  105. default:
  106. break;
  107. }
  108. /*
  109. * Actually burn the LEDs
  110. */
  111. if (led_state & LED_STATE_CLAIMED)
  112. __raw_writew(~hw_led_state, &fpga->leds);
  113. done:
  114. local_irq_restore(flags);
  115. }