leds.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * LED driver for KS8695-based boards.
  3. *
  4. * Copyright (C) Andrew Victor
  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. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <asm/leds.h>
  14. #include <mach/devices.h>
  15. #include <mach/gpio.h>
  16. static inline void ks8695_led_on(unsigned int led)
  17. {
  18. gpio_set_value(led, 0);
  19. }
  20. static inline void ks8695_led_off(unsigned int led)
  21. {
  22. gpio_set_value(led, 1);
  23. }
  24. static inline void ks8695_led_toggle(unsigned int led)
  25. {
  26. unsigned long is_off = gpio_get_value(led);
  27. if (is_off)
  28. ks8695_led_on(led);
  29. else
  30. ks8695_led_off(led);
  31. }
  32. /*
  33. * Handle LED events.
  34. */
  35. static void ks8695_leds_event(led_event_t evt)
  36. {
  37. unsigned long flags;
  38. local_irq_save(flags);
  39. switch(evt) {
  40. case led_start: /* System startup */
  41. ks8695_led_on(ks8695_leds_cpu);
  42. break;
  43. case led_stop: /* System stop / suspend */
  44. ks8695_led_off(ks8695_leds_cpu);
  45. break;
  46. #ifdef CONFIG_LEDS_TIMER
  47. case led_timer: /* Every 50 timer ticks */
  48. ks8695_led_toggle(ks8695_leds_timer);
  49. break;
  50. #endif
  51. #ifdef CONFIG_LEDS_CPU
  52. case led_idle_start: /* Entering idle state */
  53. ks8695_led_off(ks8695_leds_cpu);
  54. break;
  55. case led_idle_end: /* Exit idle state */
  56. ks8695_led_on(ks8695_leds_cpu);
  57. break;
  58. #endif
  59. default:
  60. break;
  61. }
  62. local_irq_restore(flags);
  63. }
  64. static int __init leds_init(void)
  65. {
  66. if ((ks8695_leds_timer == -1) || (ks8695_leds_cpu == -1))
  67. return -ENODEV;
  68. leds_event = ks8695_leds_event;
  69. leds_event(led_start);
  70. return 0;
  71. }
  72. __initcall(leds_init);