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