leds.c 2.9 KB

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