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. #define LED_STATE_ENABLED 1
  26. #define LED_STATE_CLAIMED 2
  27. #define SEQUOIA_LED_GREEN (1<<6)
  28. #define SEQUOIA_LED_AMBER (1<<5)
  29. #define SEQUOIA_LED_BACK (1<<7)
  30. static char led_state;
  31. static short hw_led_state;
  32. static short saved_state;
  33. static DEFINE_RAW_SPINLOCK(leds_lock);
  34. short sequoia_read(int addr) {
  35. outw(addr,0x24);
  36. return inw(0x26);
  37. }
  38. void sequoia_write(short value,short addr) {
  39. outw(addr,0x24);
  40. outw(value,0x26);
  41. }
  42. static void sequoia_leds_event(led_event_t evt)
  43. {
  44. unsigned long flags;
  45. raw_spin_lock_irqsave(&leds_lock, flags);
  46. hw_led_state = sequoia_read(0x09);
  47. switch (evt) {
  48. case led_start:
  49. hw_led_state |= SEQUOIA_LED_GREEN;
  50. hw_led_state |= SEQUOIA_LED_AMBER;
  51. #ifdef CONFIG_LEDS_CPU
  52. hw_led_state |= SEQUOIA_LED_BACK;
  53. #else
  54. hw_led_state &= ~SEQUOIA_LED_BACK;
  55. #endif
  56. led_state |= LED_STATE_ENABLED;
  57. break;
  58. case led_stop:
  59. hw_led_state &= ~SEQUOIA_LED_BACK;
  60. hw_led_state |= SEQUOIA_LED_GREEN;
  61. hw_led_state |= SEQUOIA_LED_AMBER;
  62. led_state &= ~LED_STATE_ENABLED;
  63. break;
  64. case led_claim:
  65. led_state |= LED_STATE_CLAIMED;
  66. saved_state = hw_led_state;
  67. hw_led_state &= ~SEQUOIA_LED_BACK;
  68. hw_led_state |= SEQUOIA_LED_GREEN;
  69. hw_led_state |= SEQUOIA_LED_AMBER;
  70. break;
  71. case led_release:
  72. led_state &= ~LED_STATE_CLAIMED;
  73. hw_led_state = saved_state;
  74. break;
  75. #ifdef CONFIG_LEDS_TIMER
  76. case led_timer:
  77. if (!(led_state & LED_STATE_CLAIMED))
  78. hw_led_state ^= SEQUOIA_LED_GREEN;
  79. break;
  80. #endif
  81. #ifdef CONFIG_LEDS_CPU
  82. case led_idle_start:
  83. if (!(led_state & LED_STATE_CLAIMED))
  84. hw_led_state &= ~SEQUOIA_LED_BACK;
  85. break;
  86. case led_idle_end:
  87. if (!(led_state & LED_STATE_CLAIMED))
  88. hw_led_state |= SEQUOIA_LED_BACK;
  89. break;
  90. #endif
  91. case led_green_on:
  92. if (led_state & LED_STATE_CLAIMED)
  93. hw_led_state &= ~SEQUOIA_LED_GREEN;
  94. break;
  95. case led_green_off:
  96. if (led_state & LED_STATE_CLAIMED)
  97. hw_led_state |= SEQUOIA_LED_GREEN;
  98. break;
  99. case led_amber_on:
  100. if (led_state & LED_STATE_CLAIMED)
  101. hw_led_state &= ~SEQUOIA_LED_AMBER;
  102. break;
  103. case led_amber_off:
  104. if (led_state & LED_STATE_CLAIMED)
  105. hw_led_state |= SEQUOIA_LED_AMBER;
  106. break;
  107. case led_red_on:
  108. if (led_state & LED_STATE_CLAIMED)
  109. hw_led_state |= SEQUOIA_LED_BACK;
  110. break;
  111. case led_red_off:
  112. if (led_state & LED_STATE_CLAIMED)
  113. hw_led_state &= ~SEQUOIA_LED_BACK;
  114. break;
  115. default:
  116. break;
  117. }
  118. if (led_state & LED_STATE_ENABLED)
  119. sequoia_write(hw_led_state,0x09);
  120. raw_spin_unlock_irqrestore(&leds_lock, flags);
  121. }
  122. static int __init leds_init(void)
  123. {
  124. extern void (*leds_event)(led_event_t);
  125. short temp;
  126. leds_event = sequoia_leds_event;
  127. /* Make LEDs independent of power-state */
  128. request_region(0x24,4,"sequoia");
  129. temp = sequoia_read(0x09);
  130. temp |= 1<<10;
  131. sequoia_write(temp,0x09);
  132. leds_event(led_start);
  133. return 0;
  134. }
  135. __initcall(leds_init);