leds.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/config.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <asm/mach-types.h>
  16. #include <asm/leds.h>
  17. #include <asm/arch/board.h>
  18. #include <asm/arch/gpio.h>
  19. static inline void at91_led_on(unsigned int led)
  20. {
  21. at91_set_gpio_value(led, 0);
  22. }
  23. static inline void at91_led_off(unsigned int led)
  24. {
  25. at91_set_gpio_value(led, 1);
  26. }
  27. static inline void at91_led_toggle(unsigned int led)
  28. {
  29. unsigned long is_off = at91_get_gpio_value(led);
  30. if (is_off)
  31. at91_led_on(led);
  32. else
  33. at91_led_off(led);
  34. }
  35. /*
  36. * Handle LED events.
  37. */
  38. static void at91_leds_event(led_event_t evt)
  39. {
  40. unsigned long flags;
  41. local_irq_save(flags);
  42. switch(evt) {
  43. case led_start: /* System startup */
  44. at91_led_on(at91_leds_cpu);
  45. break;
  46. case led_stop: /* System stop / suspend */
  47. at91_led_off(at91_leds_cpu);
  48. break;
  49. #ifdef CONFIG_LEDS_TIMER
  50. case led_timer: /* Every 50 timer ticks */
  51. at91_led_toggle(at91_leds_timer);
  52. break;
  53. #endif
  54. #ifdef CONFIG_LEDS_CPU
  55. case led_idle_start: /* Entering idle state */
  56. at91_led_off(at91_leds_cpu);
  57. break;
  58. case led_idle_end: /* Exit idle state */
  59. at91_led_on(at91_leds_cpu);
  60. break;
  61. #endif
  62. default:
  63. break;
  64. }
  65. local_irq_restore(flags);
  66. }
  67. static int __init leds_init(void)
  68. {
  69. if (!at91_leds_timer || !at91_leds_cpu)
  70. return -ENODEV;
  71. /* Enable PIO to access the LEDs */
  72. at91_set_gpio_output(at91_leds_timer, 1);
  73. at91_set_gpio_output(at91_leds_cpu, 1);
  74. leds_event = at91_leds_event;
  75. leds_event(led_start);
  76. return 0;
  77. }
  78. __initcall(leds_init);