leds.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 <mach/board.h>
  15. #include <mach/gpio.h>
  16. /* ------------------------------------------------------------------------- */
  17. #if defined(CONFIG_NEW_LEDS)
  18. #include <linux/platform_device.h>
  19. /*
  20. * New cross-platform LED support.
  21. */
  22. static struct gpio_led_platform_data led_data;
  23. static struct platform_device at91_leds = {
  24. .name = "leds-gpio",
  25. .id = -1,
  26. .dev.platform_data = &led_data,
  27. };
  28. void __init at91_gpio_leds(struct gpio_led *leds, int nr)
  29. {
  30. int i;
  31. if (!nr)
  32. return;
  33. for (i = 0; i < nr; i++)
  34. at91_set_gpio_output(leds[i].gpio, leds[i].active_low);
  35. led_data.leds = leds;
  36. led_data.num_leds = nr;
  37. platform_device_register(&at91_leds);
  38. }
  39. #else
  40. void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
  41. #endif
  42. /* ------------------------------------------------------------------------- */
  43. #if defined(CONFIG_LEDS)
  44. #include <asm/leds.h>
  45. /*
  46. * Old ARM-specific LED framework; not fully functional when generic time is
  47. * in use.
  48. */
  49. static u8 at91_leds_cpu;
  50. static u8 at91_leds_timer;
  51. static inline void at91_led_on(unsigned int led)
  52. {
  53. at91_set_gpio_value(led, 0);
  54. }
  55. static inline void at91_led_off(unsigned int led)
  56. {
  57. at91_set_gpio_value(led, 1);
  58. }
  59. static inline void at91_led_toggle(unsigned int led)
  60. {
  61. unsigned long is_off = at91_get_gpio_value(led);
  62. if (is_off)
  63. at91_led_on(led);
  64. else
  65. at91_led_off(led);
  66. }
  67. /*
  68. * Handle LED events.
  69. */
  70. static void at91_leds_event(led_event_t evt)
  71. {
  72. unsigned long flags;
  73. local_irq_save(flags);
  74. switch(evt) {
  75. case led_start: /* System startup */
  76. at91_led_on(at91_leds_cpu);
  77. break;
  78. case led_stop: /* System stop / suspend */
  79. at91_led_off(at91_leds_cpu);
  80. break;
  81. #ifdef CONFIG_LEDS_TIMER
  82. case led_timer: /* Every 50 timer ticks */
  83. at91_led_toggle(at91_leds_timer);
  84. break;
  85. #endif
  86. #ifdef CONFIG_LEDS_CPU
  87. case led_idle_start: /* Entering idle state */
  88. at91_led_off(at91_leds_cpu);
  89. break;
  90. case led_idle_end: /* Exit idle state */
  91. at91_led_on(at91_leds_cpu);
  92. break;
  93. #endif
  94. default:
  95. break;
  96. }
  97. local_irq_restore(flags);
  98. }
  99. static int __init leds_init(void)
  100. {
  101. if (!at91_leds_timer || !at91_leds_cpu)
  102. return -ENODEV;
  103. leds_event = at91_leds_event;
  104. leds_event(led_start);
  105. return 0;
  106. }
  107. __initcall(leds_init);
  108. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  109. {
  110. /* Enable GPIO to access the LEDs */
  111. at91_set_gpio_output(cpu_led, 1);
  112. at91_set_gpio_output(timer_led, 1);
  113. at91_leds_cpu = cpu_led;
  114. at91_leds_timer = timer_led;
  115. }
  116. #else
  117. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  118. #endif