leds-hackkit.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * linux/arch/arm/mach-sa1100/leds-hackkit.c
  3. *
  4. * based on leds-lart.c
  5. *
  6. * (C) Erik Mouw (J.A.K.Mouw@its.tudelft.nl), April 21, 2000
  7. * (C) Stefan Eletzhofer <stefan.eletzhofer@eletztrick.de>, 2002
  8. *
  9. * The HackKit has two leds (GPIO 22/23). The red led (gpio 22) is used
  10. * as cpu led, the green one is used as timer led.
  11. */
  12. #include <linux/init.h>
  13. #include <mach/hardware.h>
  14. #include <asm/leds.h>
  15. #include <asm/system.h>
  16. #include "leds.h"
  17. #define LED_STATE_ENABLED 1
  18. #define LED_STATE_CLAIMED 2
  19. static unsigned int led_state;
  20. static unsigned int hw_led_state;
  21. #define LED_GREEN GPIO_GPIO23
  22. #define LED_RED GPIO_GPIO22
  23. #define LED_MASK (LED_RED | LED_GREEN)
  24. void hackkit_leds_event(led_event_t evt)
  25. {
  26. unsigned long flags;
  27. local_irq_save(flags);
  28. switch(evt) {
  29. case led_start:
  30. /* pin 22/23 are outputs */
  31. GPDR |= LED_MASK;
  32. hw_led_state = LED_MASK;
  33. led_state = LED_STATE_ENABLED;
  34. break;
  35. case led_stop:
  36. led_state &= ~LED_STATE_ENABLED;
  37. break;
  38. case led_claim:
  39. led_state |= LED_STATE_CLAIMED;
  40. hw_led_state = LED_MASK;
  41. break;
  42. case led_release:
  43. led_state &= ~LED_STATE_CLAIMED;
  44. hw_led_state = LED_MASK;
  45. break;
  46. #ifdef CONFIG_LEDS_TIMER
  47. case led_timer:
  48. if (!(led_state & LED_STATE_CLAIMED))
  49. hw_led_state ^= LED_GREEN;
  50. break;
  51. #endif
  52. #ifdef CONFIG_LEDS_CPU
  53. case led_idle_start:
  54. /* The LART people like the LED to be off when the
  55. system is idle... */
  56. if (!(led_state & LED_STATE_CLAIMED))
  57. hw_led_state &= ~LED_RED;
  58. break;
  59. case led_idle_end:
  60. /* ... and on if the system is not idle */
  61. if (!(led_state & LED_STATE_CLAIMED))
  62. hw_led_state |= LED_RED;
  63. break;
  64. #endif
  65. case led_red_on:
  66. if (led_state & LED_STATE_CLAIMED)
  67. hw_led_state &= ~LED_RED;
  68. break;
  69. case led_red_off:
  70. if (led_state & LED_STATE_CLAIMED)
  71. hw_led_state |= LED_RED;
  72. break;
  73. case led_green_on:
  74. if (led_state & LED_STATE_CLAIMED)
  75. hw_led_state &= ~LED_GREEN;
  76. break;
  77. case led_green_off:
  78. if (led_state & LED_STATE_CLAIMED)
  79. hw_led_state |= LED_GREEN;
  80. break;
  81. default:
  82. break;
  83. }
  84. /* Now set the GPIO state, or nothing will happen at all */
  85. if (led_state & LED_STATE_ENABLED) {
  86. GPSR = hw_led_state;
  87. GPCR = hw_led_state ^ LED_MASK;
  88. }
  89. local_irq_restore(flags);
  90. }