debug-leds.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * linux/arch/arm/plat-omap/debug-leds.c
  3. *
  4. * Copyright 2003 by Texas Instruments Incorporated
  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/gpio.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/leds.h>
  14. #include <linux/io.h>
  15. #include <mach/hardware.h>
  16. #include <asm/leds.h>
  17. #include <asm/mach-types.h>
  18. #include <plat/fpga.h>
  19. /* Many OMAP development platforms reuse the same "debug board"; these
  20. * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the
  21. * debug board (all green), accessed through FPGA registers.
  22. *
  23. * The "surfer" expansion board and H2 sample board also have two-color
  24. * green+red LEDs (in parallel), used here for timer and idle indicators
  25. * in preference to the ones on the debug board, for a "Disco LED" effect.
  26. *
  27. * This driver exports either the original ARM LED API, the new generic
  28. * one, or both.
  29. */
  30. static spinlock_t lock;
  31. static struct h2p2_dbg_fpga __iomem *fpga;
  32. static u16 led_state, hw_led_state;
  33. #ifdef CONFIG_OMAP_DEBUG_LEDS
  34. #define new_led_api() 1
  35. #else
  36. #define new_led_api() 0
  37. #endif
  38. /*-------------------------------------------------------------------------*/
  39. /* original ARM debug LED API:
  40. * - timer and idle leds (some boards use non-FPGA leds here);
  41. * - up to 4 generic leds, easily accessed in-kernel (any context)
  42. */
  43. #define GPIO_LED_RED 3
  44. #define GPIO_LED_GREEN OMAP_MPUIO(4)
  45. #define LED_STATE_ENABLED 0x01
  46. #define LED_STATE_CLAIMED 0x02
  47. #define LED_TIMER_ON 0x04
  48. #define GPIO_IDLE GPIO_LED_GREEN
  49. #define GPIO_TIMER GPIO_LED_RED
  50. static void h2p2_dbg_leds_event(led_event_t evt)
  51. {
  52. unsigned long flags;
  53. spin_lock_irqsave(&lock, flags);
  54. if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
  55. goto done;
  56. switch (evt) {
  57. case led_start:
  58. if (fpga)
  59. led_state |= LED_STATE_ENABLED;
  60. break;
  61. case led_stop:
  62. case led_halted:
  63. /* all leds off during suspend or shutdown */
  64. if (!(machine_is_omap_perseus2() || machine_is_omap_h4())) {
  65. gpio_set_value(GPIO_TIMER, 0);
  66. gpio_set_value(GPIO_IDLE, 0);
  67. }
  68. __raw_writew(~0, &fpga->leds);
  69. led_state &= ~LED_STATE_ENABLED;
  70. goto done;
  71. case led_claim:
  72. led_state |= LED_STATE_CLAIMED;
  73. hw_led_state = 0;
  74. break;
  75. case led_release:
  76. led_state &= ~LED_STATE_CLAIMED;
  77. break;
  78. #ifdef CONFIG_LEDS_TIMER
  79. case led_timer:
  80. led_state ^= LED_TIMER_ON;
  81. if (machine_is_omap_perseus2() || machine_is_omap_h4())
  82. hw_led_state ^= H2P2_DBG_FPGA_P2_LED_TIMER;
  83. else {
  84. gpio_set_value(GPIO_TIMER,
  85. led_state & LED_TIMER_ON);
  86. goto done;
  87. }
  88. break;
  89. #endif
  90. #ifdef CONFIG_LEDS_CPU
  91. /* LED lit iff busy */
  92. case led_idle_start:
  93. if (machine_is_omap_perseus2() || machine_is_omap_h4())
  94. hw_led_state &= ~H2P2_DBG_FPGA_P2_LED_IDLE;
  95. else {
  96. gpio_set_value(GPIO_IDLE, 1);
  97. goto done;
  98. }
  99. break;
  100. case led_idle_end:
  101. if (machine_is_omap_perseus2() || machine_is_omap_h4())
  102. hw_led_state |= H2P2_DBG_FPGA_P2_LED_IDLE;
  103. else {
  104. gpio_set_value(GPIO_IDLE, 0);
  105. goto done;
  106. }
  107. break;
  108. #endif
  109. case led_green_on:
  110. hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
  111. break;
  112. case led_green_off:
  113. hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
  114. break;
  115. case led_amber_on:
  116. hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
  117. break;
  118. case led_amber_off:
  119. hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
  120. break;
  121. case led_red_on:
  122. hw_led_state |= H2P2_DBG_FPGA_LED_RED;
  123. break;
  124. case led_red_off:
  125. hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
  126. break;
  127. case led_blue_on:
  128. hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
  129. break;
  130. case led_blue_off:
  131. hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
  132. break;
  133. default:
  134. break;
  135. }
  136. /*
  137. * Actually burn the LEDs
  138. */
  139. if (led_state & LED_STATE_ENABLED)
  140. __raw_writew(~hw_led_state, &fpga->leds);
  141. done:
  142. spin_unlock_irqrestore(&lock, flags);
  143. }
  144. /*-------------------------------------------------------------------------*/
  145. /* "new" LED API
  146. * - with syfs access and generic triggering
  147. * - not readily accessible to in-kernel drivers
  148. */
  149. struct dbg_led {
  150. struct led_classdev cdev;
  151. u16 mask;
  152. };
  153. static struct dbg_led dbg_leds[] = {
  154. /* REVISIT at least H2 uses different timer & cpu leds... */
  155. #ifndef CONFIG_LEDS_TIMER
  156. { .mask = 1 << 0, .cdev.name = "d4:green",
  157. .cdev.default_trigger = "heartbeat", },
  158. #endif
  159. #ifndef CONFIG_LEDS_CPU
  160. { .mask = 1 << 1, .cdev.name = "d5:green", }, /* !idle */
  161. #endif
  162. { .mask = 1 << 2, .cdev.name = "d6:green", },
  163. { .mask = 1 << 3, .cdev.name = "d7:green", },
  164. { .mask = 1 << 4, .cdev.name = "d8:green", },
  165. { .mask = 1 << 5, .cdev.name = "d9:green", },
  166. { .mask = 1 << 6, .cdev.name = "d10:green", },
  167. { .mask = 1 << 7, .cdev.name = "d11:green", },
  168. { .mask = 1 << 8, .cdev.name = "d12:green", },
  169. { .mask = 1 << 9, .cdev.name = "d13:green", },
  170. { .mask = 1 << 10, .cdev.name = "d14:green", },
  171. { .mask = 1 << 11, .cdev.name = "d15:green", },
  172. #ifndef CONFIG_LEDS
  173. { .mask = 1 << 12, .cdev.name = "d16:green", },
  174. { .mask = 1 << 13, .cdev.name = "d17:green", },
  175. { .mask = 1 << 14, .cdev.name = "d18:green", },
  176. { .mask = 1 << 15, .cdev.name = "d19:green", },
  177. #endif
  178. };
  179. static void
  180. fpga_led_set(struct led_classdev *cdev, enum led_brightness value)
  181. {
  182. struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
  183. unsigned long flags;
  184. spin_lock_irqsave(&lock, flags);
  185. if (value == LED_OFF)
  186. hw_led_state &= ~led->mask;
  187. else
  188. hw_led_state |= led->mask;
  189. __raw_writew(~hw_led_state, &fpga->leds);
  190. spin_unlock_irqrestore(&lock, flags);
  191. }
  192. static void __init newled_init(struct device *dev)
  193. {
  194. unsigned i;
  195. struct dbg_led *led;
  196. int status;
  197. for (i = 0, led = dbg_leds; i < ARRAY_SIZE(dbg_leds); i++, led++) {
  198. led->cdev.brightness_set = fpga_led_set;
  199. status = led_classdev_register(dev, &led->cdev);
  200. if (status < 0)
  201. break;
  202. }
  203. return;
  204. }
  205. /*-------------------------------------------------------------------------*/
  206. static int /* __init */ fpga_probe(struct platform_device *pdev)
  207. {
  208. struct resource *iomem;
  209. spin_lock_init(&lock);
  210. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  211. if (!iomem)
  212. return -ENODEV;
  213. fpga = ioremap(iomem->start, H2P2_DBG_FPGA_SIZE);
  214. __raw_writew(~0, &fpga->leds);
  215. #ifdef CONFIG_LEDS
  216. leds_event = h2p2_dbg_leds_event;
  217. leds_event(led_start);
  218. #endif
  219. if (new_led_api()) {
  220. newled_init(&pdev->dev);
  221. }
  222. return 0;
  223. }
  224. static int fpga_suspend_noirq(struct device *dev)
  225. {
  226. __raw_writew(~0, &fpga->leds);
  227. return 0;
  228. }
  229. static int fpga_resume_noirq(struct device *dev)
  230. {
  231. __raw_writew(~hw_led_state, &fpga->leds);
  232. return 0;
  233. }
  234. static const struct dev_pm_ops fpga_dev_pm_ops = {
  235. .suspend_noirq = fpga_suspend_noirq,
  236. .resume_noirq = fpga_resume_noirq,
  237. };
  238. static struct platform_driver led_driver = {
  239. .driver.name = "omap_dbg_led",
  240. .driver.pm = &fpga_dev_pm_ops,
  241. .probe = fpga_probe,
  242. };
  243. static int __init fpga_init(void)
  244. {
  245. if (machine_is_omap_h4()
  246. || machine_is_omap_h3()
  247. || machine_is_omap_h2()
  248. || machine_is_omap_perseus2()
  249. )
  250. return platform_driver_register(&led_driver);
  251. return 0;
  252. }
  253. fs_initcall(fpga_init);