leds.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * arch/arm/mach-shark/leds.c
  3. * by Alexander Schulz
  4. *
  5. * derived from:
  6. * arch/arm/kernel/leds-footbridge.c
  7. * Copyright (C) 1998-1999 Russell King
  8. *
  9. * DIGITAL Shark LED control routines.
  10. *
  11. * The leds use is as follows:
  12. * - Green front - toggles state every 50 timer interrupts
  13. * - Amber front - Unused, this is a dual color led (Amber/Green)
  14. * - Amber back - On if system is not idle
  15. *
  16. * Changelog:
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/ioport.h>
  23. #include <linux/io.h>
  24. #include <asm/leds.h>
  25. #include <asm/system.h>
  26. #define LED_STATE_ENABLED 1
  27. #define LED_STATE_CLAIMED 2
  28. #define SEQUOIA_LED_GREEN (1<<6)
  29. #define SEQUOIA_LED_AMBER (1<<5)
  30. #define SEQUOIA_LED_BACK (1<<7)
  31. static char led_state;
  32. static short hw_led_state;
  33. static short saved_state;
  34. static DEFINE_SPINLOCK(leds_lock);
  35. short sequoia_read(int addr) {
  36. outw(addr,0x24);
  37. return inw(0x26);
  38. }
  39. void sequoia_write(short value,short addr) {
  40. outw(addr,0x24);
  41. outw(value,0x26);
  42. }
  43. static void sequoia_leds_event(led_event_t evt)
  44. {
  45. unsigned long flags;
  46. spin_lock_irqsave(&leds_lock, flags);
  47. hw_led_state = sequoia_read(0x09);
  48. switch (evt) {
  49. case led_start:
  50. hw_led_state |= SEQUOIA_LED_GREEN;
  51. hw_led_state |= SEQUOIA_LED_AMBER;
  52. #ifdef CONFIG_LEDS_CPU
  53. hw_led_state |= SEQUOIA_LED_BACK;
  54. #else
  55. hw_led_state &= ~SEQUOIA_LED_BACK;
  56. #endif
  57. led_state |= LED_STATE_ENABLED;
  58. break;
  59. case led_stop:
  60. hw_led_state &= ~SEQUOIA_LED_BACK;
  61. hw_led_state |= SEQUOIA_LED_GREEN;
  62. hw_led_state |= SEQUOIA_LED_AMBER;
  63. led_state &= ~LED_STATE_ENABLED;
  64. break;
  65. case led_claim:
  66. led_state |= LED_STATE_CLAIMED;
  67. saved_state = hw_led_state;
  68. hw_led_state &= ~SEQUOIA_LED_BACK;
  69. hw_led_state |= SEQUOIA_LED_GREEN;
  70. hw_led_state |= SEQUOIA_LED_AMBER;
  71. break;
  72. case led_release:
  73. led_state &= ~LED_STATE_CLAIMED;
  74. hw_led_state = saved_state;
  75. break;
  76. #ifdef CONFIG_LEDS_TIMER
  77. case led_timer:
  78. if (!(led_state & LED_STATE_CLAIMED))
  79. hw_led_state ^= SEQUOIA_LED_GREEN;
  80. break;
  81. #endif
  82. #ifdef CONFIG_LEDS_CPU
  83. case led_idle_start:
  84. if (!(led_state & LED_STATE_CLAIMED))
  85. hw_led_state &= ~SEQUOIA_LED_BACK;
  86. break;
  87. case led_idle_end:
  88. if (!(led_state & LED_STATE_CLAIMED))
  89. hw_led_state |= SEQUOIA_LED_BACK;
  90. break;
  91. #endif
  92. case led_green_on:
  93. if (led_state & LED_STATE_CLAIMED)
  94. hw_led_state &= ~SEQUOIA_LED_GREEN;
  95. break;
  96. case led_green_off:
  97. if (led_state & LED_STATE_CLAIMED)
  98. hw_led_state |= SEQUOIA_LED_GREEN;
  99. break;
  100. case led_amber_on:
  101. if (led_state & LED_STATE_CLAIMED)
  102. hw_led_state &= ~SEQUOIA_LED_AMBER;
  103. break;
  104. case led_amber_off:
  105. if (led_state & LED_STATE_CLAIMED)
  106. hw_led_state |= SEQUOIA_LED_AMBER;
  107. break;
  108. case led_red_on:
  109. if (led_state & LED_STATE_CLAIMED)
  110. hw_led_state |= SEQUOIA_LED_BACK;
  111. break;
  112. case led_red_off:
  113. if (led_state & LED_STATE_CLAIMED)
  114. hw_led_state &= ~SEQUOIA_LED_BACK;
  115. break;
  116. default:
  117. break;
  118. }
  119. if (led_state & LED_STATE_ENABLED)
  120. sequoia_write(hw_led_state,0x09);
  121. spin_unlock_irqrestore(&leds_lock, flags);
  122. }
  123. static int __init leds_init(void)
  124. {
  125. extern void (*leds_event)(led_event_t);
  126. short temp;
  127. leds_event = sequoia_leds_event;
  128. /* Make LEDs independent of power-state */
  129. request_region(0x24,4,"sequoia");
  130. temp = sequoia_read(0x09);
  131. temp |= 1<<10;
  132. sequoia_write(temp,0x09);
  133. leds_event(led_start);
  134. return 0;
  135. }
  136. __initcall(leds_init);