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

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/arch/arm/mach-footbridge/ebsa285-leds.c
  3.  *
  4.  *  Copyright (C) 1998-1999 Russell King
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  * EBSA-285 control routines.
  10.  *
  11.  * The EBSA-285 uses the leds as follows:
  12.  *  - Green - toggles state every 50 timer interrupts
  13.  *  - Amber - On if system is not idle
  14.  *  - Red   - currently unused
  15.  *
  16.  * Changelog:
  17.  *   02-05-1999 RMK Various cleanups
  18.  */
  19. #include <linux/config.h>
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/spinlock.h>
  24. #include <asm/hardware.h>
  25. #include <asm/leds.h>
  26. #include <asm/mach-types.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 char hw_led_state;
  32. static spinlock_t leds_lock = SPIN_LOCK_UNLOCKED;
  33. static void ebsa285_leds_event(led_event_t evt)
  34. {
  35. unsigned long flags;
  36. spin_lock_irqsave(&leds_lock, flags);
  37. switch (evt) {
  38. case led_start:
  39. hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN;
  40. #ifndef CONFIG_LEDS_CPU
  41. hw_led_state |= XBUS_LED_AMBER;
  42. #endif
  43. led_state |= LED_STATE_ENABLED;
  44. break;
  45. case led_stop:
  46. led_state &= ~LED_STATE_ENABLED;
  47. break;
  48. case led_claim:
  49. led_state |= LED_STATE_CLAIMED;
  50. hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN | XBUS_LED_AMBER;
  51. break;
  52. case led_release:
  53. led_state &= ~LED_STATE_CLAIMED;
  54. hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN | XBUS_LED_AMBER;
  55. break;
  56. #ifdef CONFIG_LEDS_TIMER
  57. case led_timer:
  58. if (!(led_state & LED_STATE_CLAIMED))
  59. hw_led_state ^= XBUS_LED_GREEN;
  60. break;
  61. #endif
  62. #ifdef CONFIG_LEDS_CPU
  63. case led_idle_start:
  64. if (!(led_state & LED_STATE_CLAIMED))
  65. hw_led_state |= XBUS_LED_AMBER;
  66. break;
  67. case led_idle_end:
  68. if (!(led_state & LED_STATE_CLAIMED))
  69. hw_led_state &= ~XBUS_LED_AMBER;
  70. break;
  71. #endif
  72. case led_halted:
  73. if (!(led_state & LED_STATE_CLAIMED))
  74. hw_led_state &= ~XBUS_LED_RED;
  75. break;
  76. case led_green_on:
  77. if (led_state & LED_STATE_CLAIMED)
  78. hw_led_state &= ~XBUS_LED_GREEN;
  79. break;
  80. case led_green_off:
  81. if (led_state & LED_STATE_CLAIMED)
  82. hw_led_state |= XBUS_LED_GREEN;
  83. break;
  84. case led_amber_on:
  85. if (led_state & LED_STATE_CLAIMED)
  86. hw_led_state &= ~XBUS_LED_AMBER;
  87. break;
  88. case led_amber_off:
  89. if (led_state & LED_STATE_CLAIMED)
  90. hw_led_state |= XBUS_LED_AMBER;
  91. break;
  92. case led_red_on:
  93. if (led_state & LED_STATE_CLAIMED)
  94. hw_led_state &= ~XBUS_LED_RED;
  95. break;
  96. case led_red_off:
  97. if (led_state & LED_STATE_CLAIMED)
  98. hw_led_state |= XBUS_LED_RED;
  99. break;
  100. default:
  101. break;
  102. }
  103. if  (led_state & LED_STATE_ENABLED)
  104. *XBUS_LEDS = hw_led_state;
  105. spin_unlock_irqrestore(&leds_lock, flags);
  106. }
  107. static int __init leds_init(void)
  108. {
  109. if (machine_is_ebsa285() || machine_is_co285())
  110. leds_event = ebsa285_leds_event;
  111. leds_event(led_start);
  112. return 0;
  113. }
  114. __initcall(leds_init);