netwinder-leds.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * linux/arch/arm/mach-footbridge/netwinder-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. *
  10. * NetWinder LED control routines.
  11. *
  12. * The Netwinder uses the leds as follows:
  13. * - Green - toggles state every 50 timer interrupts
  14. * - Red - On if the system is not idle
  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 DEFINE_SPINLOCK(leds_lock);
  33. extern spinlock_t gpio_lock;
  34. static void netwinder_leds_event(led_event_t evt)
  35. {
  36. unsigned long flags;
  37. spin_lock_irqsave(&leds_lock, flags);
  38. switch (evt) {
  39. case led_start:
  40. led_state |= LED_STATE_ENABLED;
  41. hw_led_state = GPIO_GREEN_LED;
  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 = 0;
  49. break;
  50. case led_release:
  51. led_state &= ~LED_STATE_CLAIMED;
  52. hw_led_state = 0;
  53. break;
  54. #ifdef CONFIG_LEDS_TIMER
  55. case led_timer:
  56. if (!(led_state & LED_STATE_CLAIMED))
  57. hw_led_state ^= GPIO_GREEN_LED;
  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 &= ~GPIO_RED_LED;
  64. break;
  65. case led_idle_end:
  66. if (!(led_state & LED_STATE_CLAIMED))
  67. hw_led_state |= GPIO_RED_LED;
  68. break;
  69. #endif
  70. case led_halted:
  71. if (!(led_state & LED_STATE_CLAIMED))
  72. hw_led_state |= GPIO_RED_LED;
  73. break;
  74. case led_green_on:
  75. if (led_state & LED_STATE_CLAIMED)
  76. hw_led_state |= GPIO_GREEN_LED;
  77. break;
  78. case led_green_off:
  79. if (led_state & LED_STATE_CLAIMED)
  80. hw_led_state &= ~GPIO_GREEN_LED;
  81. break;
  82. case led_amber_on:
  83. if (led_state & LED_STATE_CLAIMED)
  84. hw_led_state |= GPIO_GREEN_LED | GPIO_RED_LED;
  85. break;
  86. case led_amber_off:
  87. if (led_state & LED_STATE_CLAIMED)
  88. hw_led_state &= ~(GPIO_GREEN_LED | GPIO_RED_LED);
  89. break;
  90. case led_red_on:
  91. if (led_state & LED_STATE_CLAIMED)
  92. hw_led_state |= GPIO_RED_LED;
  93. break;
  94. case led_red_off:
  95. if (led_state & LED_STATE_CLAIMED)
  96. hw_led_state &= ~GPIO_RED_LED;
  97. break;
  98. default:
  99. break;
  100. }
  101. spin_unlock_irqrestore(&leds_lock, flags);
  102. if (led_state & LED_STATE_ENABLED) {
  103. spin_lock_irqsave(&gpio_lock, flags);
  104. gpio_modify_op(GPIO_RED_LED | GPIO_GREEN_LED, hw_led_state);
  105. spin_unlock_irqrestore(&gpio_lock, flags);
  106. }
  107. }
  108. static int __init leds_init(void)
  109. {
  110. if (machine_is_netwinder())
  111. leds_event = netwinder_leds_event;
  112. leds_event(led_start);
  113. return 0;
  114. }
  115. __initcall(leds_init);