leds.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * LED driver for Atmel AT91-based boards.
  3. *
  4. * Copyright (C) SAN People (Pty) Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <asm/mach-types.h>
  15. #include <asm/leds.h>
  16. #include <asm/arch/board.h>
  17. #include <asm/arch/gpio.h>
  18. static inline void at91_led_on(unsigned int led)
  19. {
  20. at91_set_gpio_value(led, 0);
  21. }
  22. static inline void at91_led_off(unsigned int led)
  23. {
  24. at91_set_gpio_value(led, 1);
  25. }
  26. static inline void at91_led_toggle(unsigned int led)
  27. {
  28. unsigned long is_off = at91_get_gpio_value(led);
  29. if (is_off)
  30. at91_led_on(led);
  31. else
  32. at91_led_off(led);
  33. }
  34. /*
  35. * Handle LED events.
  36. */
  37. static void at91_leds_event(led_event_t evt)
  38. {
  39. unsigned long flags;
  40. local_irq_save(flags);
  41. switch(evt) {
  42. case led_start: /* System startup */
  43. at91_led_on(at91_leds_cpu);
  44. break;
  45. case led_stop: /* System stop / suspend */
  46. at91_led_off(at91_leds_cpu);
  47. break;
  48. #ifdef CONFIG_LEDS_TIMER
  49. case led_timer: /* Every 50 timer ticks */
  50. at91_led_toggle(at91_leds_timer);
  51. break;
  52. #endif
  53. #ifdef CONFIG_LEDS_CPU
  54. case led_idle_start: /* Entering idle state */
  55. at91_led_off(at91_leds_cpu);
  56. break;
  57. case led_idle_end: /* Exit idle state */
  58. at91_led_on(at91_leds_cpu);
  59. break;
  60. #endif
  61. default:
  62. break;
  63. }
  64. local_irq_restore(flags);
  65. }
  66. static int __init leds_init(void)
  67. {
  68. if (!at91_leds_timer || !at91_leds_cpu)
  69. return -ENODEV;
  70. leds_event = at91_leds_event;
  71. leds_event(led_start);
  72. return 0;
  73. }
  74. __initcall(leds_init);