debug-leds.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <mach/hardware.h>
  19. #include <asm/mach-types.h>
  20. #include <plat/fpga.h>
  21. /* Many OMAP development platforms reuse the same "debug board"; these
  22. * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the
  23. * debug board (all green), accessed through FPGA registers.
  24. */
  25. static struct h2p2_dbg_fpga __iomem *fpga;
  26. static u16 fpga_led_state;
  27. struct dbg_led {
  28. struct led_classdev cdev;
  29. u16 mask;
  30. };
  31. static const struct {
  32. const char *name;
  33. const char *trigger;
  34. } dbg_leds[] = {
  35. { "dbg:d4", "heartbeat", },
  36. { "dbg:d5", "cpu0", },
  37. { "dbg:d6", "default-on", },
  38. { "dbg:d7", },
  39. { "dbg:d8", },
  40. { "dbg:d9", },
  41. { "dbg:d10", },
  42. { "dbg:d11", },
  43. { "dbg:d12", },
  44. { "dbg:d13", },
  45. { "dbg:d14", },
  46. { "dbg:d15", },
  47. { "dbg:d16", },
  48. { "dbg:d17", },
  49. { "dbg:d18", },
  50. { "dbg:d19", },
  51. };
  52. /*
  53. * The triggers lines up below will only be used if the
  54. * LED triggers are compiled in.
  55. */
  56. static void dbg_led_set(struct led_classdev *cdev,
  57. enum led_brightness b)
  58. {
  59. struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
  60. u16 reg;
  61. reg = __raw_readw(&fpga->leds);
  62. if (b != LED_OFF)
  63. reg |= led->mask;
  64. else
  65. reg &= ~led->mask;
  66. __raw_writew(reg, &fpga->leds);
  67. }
  68. static enum led_brightness dbg_led_get(struct led_classdev *cdev)
  69. {
  70. struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
  71. u16 reg;
  72. reg = __raw_readw(&fpga->leds);
  73. return (reg & led->mask) ? LED_FULL : LED_OFF;
  74. }
  75. static int fpga_probe(struct platform_device *pdev)
  76. {
  77. struct resource *iomem;
  78. int i;
  79. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  80. if (!iomem)
  81. return -ENODEV;
  82. fpga = ioremap(iomem->start, H2P2_DBG_FPGA_SIZE);
  83. __raw_writew(0xff, &fpga->leds);
  84. for (i = 0; i < ARRAY_SIZE(dbg_leds); i++) {
  85. struct dbg_led *led;
  86. led = kzalloc(sizeof(*led), GFP_KERNEL);
  87. if (!led)
  88. break;
  89. led->cdev.name = dbg_leds[i].name;
  90. led->cdev.brightness_set = dbg_led_set;
  91. led->cdev.brightness_get = dbg_led_get;
  92. led->cdev.default_trigger = dbg_leds[i].trigger;
  93. led->mask = BIT(i);
  94. if (led_classdev_register(NULL, &led->cdev) < 0) {
  95. kfree(led);
  96. break;
  97. }
  98. }
  99. return 0;
  100. }
  101. static int fpga_suspend_noirq(struct device *dev)
  102. {
  103. fpga_led_state = __raw_readw(&fpga->leds);
  104. __raw_writew(0xff, &fpga->leds);
  105. return 0;
  106. }
  107. static int fpga_resume_noirq(struct device *dev)
  108. {
  109. __raw_writew(~fpga_led_state, &fpga->leds);
  110. return 0;
  111. }
  112. static const struct dev_pm_ops fpga_dev_pm_ops = {
  113. .suspend_noirq = fpga_suspend_noirq,
  114. .resume_noirq = fpga_resume_noirq,
  115. };
  116. static struct platform_driver led_driver = {
  117. .driver.name = "omap_dbg_led",
  118. .driver.pm = &fpga_dev_pm_ops,
  119. .probe = fpga_probe,
  120. };
  121. static int __init fpga_init(void)
  122. {
  123. if (machine_is_omap_h4()
  124. || machine_is_omap_h3()
  125. || machine_is_omap_h2()
  126. || machine_is_omap_perseus2()
  127. )
  128. return platform_driver_register(&led_driver);
  129. return 0;
  130. }
  131. fs_initcall(fpga_init);