debug-leds.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * linux/arch/arm/plat-omap/debug-leds.c
  3. *
  4. * Copyright 2011 by Bryan Wu <bryan.wu@canonical.com>
  5. * Copyright 2003 by Texas Instruments Incorporated
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/leds.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_data/gpio-omap.h>
  17. #include <linux/slab.h>
  18. #include <asm/mach-types.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. /* NOTE: most boards don't have a static mapping for the FPGA ... */
  24. struct h2p2_dbg_fpga {
  25. /* offset 0x00 */
  26. u16 smc91x[8];
  27. /* offset 0x10 */
  28. u16 fpga_rev;
  29. u16 board_rev;
  30. u16 gpio_outputs;
  31. u16 leds;
  32. /* offset 0x18 */
  33. u16 misc_inputs;
  34. u16 lan_status;
  35. u16 lan_reset;
  36. u16 reserved0;
  37. /* offset 0x20 */
  38. u16 ps2_data;
  39. u16 ps2_ctrl;
  40. /* plus also 4 rs232 ports ... */
  41. };
  42. static struct h2p2_dbg_fpga __iomem *fpga;
  43. static u16 fpga_led_state;
  44. struct dbg_led {
  45. struct led_classdev cdev;
  46. u16 mask;
  47. };
  48. static const struct {
  49. const char *name;
  50. const char *trigger;
  51. } dbg_leds[] = {
  52. { "dbg:d4", "heartbeat", },
  53. { "dbg:d5", "cpu0", },
  54. { "dbg:d6", "default-on", },
  55. { "dbg:d7", },
  56. { "dbg:d8", },
  57. { "dbg:d9", },
  58. { "dbg:d10", },
  59. { "dbg:d11", },
  60. { "dbg:d12", },
  61. { "dbg:d13", },
  62. { "dbg:d14", },
  63. { "dbg:d15", },
  64. { "dbg:d16", },
  65. { "dbg:d17", },
  66. { "dbg:d18", },
  67. { "dbg:d19", },
  68. };
  69. /*
  70. * The triggers lines up below will only be used if the
  71. * LED triggers are compiled in.
  72. */
  73. static void dbg_led_set(struct led_classdev *cdev,
  74. enum led_brightness b)
  75. {
  76. struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
  77. u16 reg;
  78. reg = readw_relaxed(&fpga->leds);
  79. if (b != LED_OFF)
  80. reg |= led->mask;
  81. else
  82. reg &= ~led->mask;
  83. writew_relaxed(reg, &fpga->leds);
  84. }
  85. static enum led_brightness dbg_led_get(struct led_classdev *cdev)
  86. {
  87. struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
  88. u16 reg;
  89. reg = readw_relaxed(&fpga->leds);
  90. return (reg & led->mask) ? LED_FULL : LED_OFF;
  91. }
  92. static int fpga_probe(struct platform_device *pdev)
  93. {
  94. struct resource *iomem;
  95. int i;
  96. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  97. if (!iomem)
  98. return -ENODEV;
  99. fpga = ioremap(iomem->start, resource_size(iomem));
  100. writew_relaxed(0xff, &fpga->leds);
  101. for (i = 0; i < ARRAY_SIZE(dbg_leds); i++) {
  102. struct dbg_led *led;
  103. led = kzalloc(sizeof(*led), GFP_KERNEL);
  104. if (!led)
  105. break;
  106. led->cdev.name = dbg_leds[i].name;
  107. led->cdev.brightness_set = dbg_led_set;
  108. led->cdev.brightness_get = dbg_led_get;
  109. led->cdev.default_trigger = dbg_leds[i].trigger;
  110. led->mask = BIT(i);
  111. if (led_classdev_register(NULL, &led->cdev) < 0) {
  112. kfree(led);
  113. break;
  114. }
  115. }
  116. return 0;
  117. }
  118. static int fpga_suspend_noirq(struct device *dev)
  119. {
  120. fpga_led_state = readw_relaxed(&fpga->leds);
  121. writew_relaxed(0xff, &fpga->leds);
  122. return 0;
  123. }
  124. static int fpga_resume_noirq(struct device *dev)
  125. {
  126. writew_relaxed(~fpga_led_state, &fpga->leds);
  127. return 0;
  128. }
  129. static const struct dev_pm_ops fpga_dev_pm_ops = {
  130. .suspend_noirq = fpga_suspend_noirq,
  131. .resume_noirq = fpga_resume_noirq,
  132. };
  133. static struct platform_driver led_driver = {
  134. .driver.name = "omap_dbg_led",
  135. .driver.pm = &fpga_dev_pm_ops,
  136. .probe = fpga_probe,
  137. };
  138. static int __init fpga_init(void)
  139. {
  140. if (machine_is_omap_h4()
  141. || machine_is_omap_h3()
  142. || machine_is_omap_h2()
  143. || machine_is_omap_perseus2()
  144. )
  145. return platform_driver_register(&led_driver);
  146. return 0;
  147. }
  148. fs_initcall(fpga_init);