leds.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:3k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * arch/arm/kernel/leds-shark.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/config.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/ioport.h>
  24. #include <asm/hardware.h>
  25. #include <asm/leds.h>
  26. #include <asm/io.h>
  27. #include <asm/system.h>
  28. #define LED_STATE_ENABLED 1
  29. #define LED_STATE_CLAIMED 2
  30. static char led_state;
  31. static short hw_led_state;
  32. static short saved_state;
  33. static spinlock_t leds_lock = SPIN_LOCK_UNLOCKED;
  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. 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. 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);