leds-h2p2-debug.c 2.9 KB

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