netwinder-leds.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/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. #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 netwinder_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. led_state |= LED_STATE_ENABLED;
  39. hw_led_state = GPIO_GREEN_LED;
  40. break;
  41. case led_stop:
  42. led_state &= ~LED_STATE_ENABLED;
  43. break;
  44. case led_claim:
  45. led_state |= LED_STATE_CLAIMED;
  46. hw_led_state = 0;
  47. break;
  48. case led_release:
  49. led_state &= ~LED_STATE_CLAIMED;
  50. hw_led_state = 0;
  51. break;
  52. #ifdef CONFIG_LEDS_TIMER
  53. case led_timer:
  54. if (!(led_state & LED_STATE_CLAIMED))
  55. hw_led_state ^= GPIO_GREEN_LED;
  56. break;
  57. #endif
  58. #ifdef CONFIG_LEDS_CPU
  59. case led_idle_start:
  60. if (!(led_state & LED_STATE_CLAIMED))
  61. hw_led_state &= ~GPIO_RED_LED;
  62. break;
  63. case led_idle_end:
  64. if (!(led_state & LED_STATE_CLAIMED))
  65. hw_led_state |= GPIO_RED_LED;
  66. break;
  67. #endif
  68. case led_halted:
  69. if (!(led_state & LED_STATE_CLAIMED))
  70. hw_led_state |= GPIO_RED_LED;
  71. break;
  72. case led_green_on:
  73. if (led_state & LED_STATE_CLAIMED)
  74. hw_led_state |= GPIO_GREEN_LED;
  75. break;
  76. case led_green_off:
  77. if (led_state & LED_STATE_CLAIMED)
  78. hw_led_state &= ~GPIO_GREEN_LED;
  79. break;
  80. case led_amber_on:
  81. if (led_state & LED_STATE_CLAIMED)
  82. hw_led_state |= GPIO_GREEN_LED | GPIO_RED_LED;
  83. break;
  84. case led_amber_off:
  85. if (led_state & LED_STATE_CLAIMED)
  86. hw_led_state &= ~(GPIO_GREEN_LED | GPIO_RED_LED);
  87. break;
  88. case led_red_on:
  89. if (led_state & LED_STATE_CLAIMED)
  90. hw_led_state |= GPIO_RED_LED;
  91. break;
  92. case led_red_off:
  93. if (led_state & LED_STATE_CLAIMED)
  94. hw_led_state &= ~GPIO_RED_LED;
  95. break;
  96. default:
  97. break;
  98. }
  99. spin_unlock_irqrestore(&leds_lock, flags);
  100. if (led_state & LED_STATE_ENABLED) {
  101. spin_lock_irqsave(&nw_gpio_lock, flags);
  102. nw_gpio_modify_op(GPIO_RED_LED | GPIO_GREEN_LED, hw_led_state);
  103. spin_unlock_irqrestore(&nw_gpio_lock, flags);
  104. }
  105. }
  106. static int __init leds_init(void)
  107. {
  108. if (machine_is_netwinder())
  109. leds_event = netwinder_leds_event;
  110. leds_event(led_start);
  111. return 0;
  112. }
  113. __initcall(leds_init);