ebsa285-leds.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/spinlock.h>
  23. #include <asm/hardware.h>
  24. #include <asm/leds.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/system.h>
  27. #define LED_STATE_ENABLED 1
  28. #define LED_STATE_CLAIMED 2
  29. static char led_state;
  30. static char hw_led_state;
  31. static DEFINE_SPINLOCK(leds_lock);
  32. static void ebsa285_leds_event(led_event_t evt)
  33. {
  34. unsigned long flags;
  35. spin_lock_irqsave(&leds_lock, flags);
  36. switch (evt) {
  37. case led_start:
  38. hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN;
  39. #ifndef CONFIG_LEDS_CPU
  40. hw_led_state |= XBUS_LED_AMBER;
  41. #endif
  42. led_state |= LED_STATE_ENABLED;
  43. break;
  44. case led_stop:
  45. led_state &= ~LED_STATE_ENABLED;
  46. break;
  47. case led_claim:
  48. led_state |= LED_STATE_CLAIMED;
  49. hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN | XBUS_LED_AMBER;
  50. break;
  51. case led_release:
  52. led_state &= ~LED_STATE_CLAIMED;
  53. hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN | XBUS_LED_AMBER;
  54. break;
  55. #ifdef CONFIG_LEDS_TIMER
  56. case led_timer:
  57. if (!(led_state & LED_STATE_CLAIMED))
  58. hw_led_state ^= XBUS_LED_GREEN;
  59. break;
  60. #endif
  61. #ifdef CONFIG_LEDS_CPU
  62. case led_idle_start:
  63. if (!(led_state & LED_STATE_CLAIMED))
  64. hw_led_state |= XBUS_LED_AMBER;
  65. break;
  66. case led_idle_end:
  67. if (!(led_state & LED_STATE_CLAIMED))
  68. hw_led_state &= ~XBUS_LED_AMBER;
  69. break;
  70. #endif
  71. case led_halted:
  72. if (!(led_state & LED_STATE_CLAIMED))
  73. hw_led_state &= ~XBUS_LED_RED;
  74. break;
  75. case led_green_on:
  76. if (led_state & LED_STATE_CLAIMED)
  77. hw_led_state &= ~XBUS_LED_GREEN;
  78. break;
  79. case led_green_off:
  80. if (led_state & LED_STATE_CLAIMED)
  81. hw_led_state |= XBUS_LED_GREEN;
  82. break;
  83. case led_amber_on:
  84. if (led_state & LED_STATE_CLAIMED)
  85. hw_led_state &= ~XBUS_LED_AMBER;
  86. break;
  87. case led_amber_off:
  88. if (led_state & LED_STATE_CLAIMED)
  89. hw_led_state |= XBUS_LED_AMBER;
  90. break;
  91. case led_red_on:
  92. if (led_state & LED_STATE_CLAIMED)
  93. hw_led_state &= ~XBUS_LED_RED;
  94. break;
  95. case led_red_off:
  96. if (led_state & LED_STATE_CLAIMED)
  97. hw_led_state |= XBUS_LED_RED;
  98. break;
  99. default:
  100. break;
  101. }
  102. if (led_state & LED_STATE_ENABLED)
  103. *XBUS_LEDS = hw_led_state;
  104. spin_unlock_irqrestore(&leds_lock, flags);
  105. }
  106. static int __init leds_init(void)
  107. {
  108. if (machine_is_ebsa285() || machine_is_co285())
  109. leds_event = ebsa285_leds_event;
  110. leds_event(led_start);
  111. return 0;
  112. }
  113. __initcall(leds_init);