leds-fsg.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * LED Driver for the Freecom FSG-3
  3. *
  4. * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
  5. *
  6. * Author: Rod Whitby <rod@whitby.id.au>
  7. *
  8. * Based on leds-spitz.c
  9. * Copyright 2005-2006 Openedhand Ltd.
  10. * Author: Richard Purdie <rpurdie@openedhand.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/leds.h>
  20. #include <linux/module.h>
  21. #include <linux/io.h>
  22. #include <mach/hardware.h>
  23. #define FSG_LED_WLAN_BIT 0
  24. #define FSG_LED_WAN_BIT 1
  25. #define FSG_LED_SATA_BIT 2
  26. #define FSG_LED_USB_BIT 4
  27. #define FSG_LED_RING_BIT 5
  28. #define FSG_LED_SYNC_BIT 7
  29. static short __iomem *latch_address;
  30. static unsigned short latch_value;
  31. static void fsg_led_wlan_set(struct led_classdev *led_cdev,
  32. enum led_brightness value)
  33. {
  34. if (value) {
  35. latch_value &= ~(1 << FSG_LED_WLAN_BIT);
  36. *latch_address = latch_value;
  37. } else {
  38. latch_value |= (1 << FSG_LED_WLAN_BIT);
  39. *latch_address = latch_value;
  40. }
  41. }
  42. static void fsg_led_wan_set(struct led_classdev *led_cdev,
  43. enum led_brightness value)
  44. {
  45. if (value) {
  46. latch_value &= ~(1 << FSG_LED_WAN_BIT);
  47. *latch_address = latch_value;
  48. } else {
  49. latch_value |= (1 << FSG_LED_WAN_BIT);
  50. *latch_address = latch_value;
  51. }
  52. }
  53. static void fsg_led_sata_set(struct led_classdev *led_cdev,
  54. enum led_brightness value)
  55. {
  56. if (value) {
  57. latch_value &= ~(1 << FSG_LED_SATA_BIT);
  58. *latch_address = latch_value;
  59. } else {
  60. latch_value |= (1 << FSG_LED_SATA_BIT);
  61. *latch_address = latch_value;
  62. }
  63. }
  64. static void fsg_led_usb_set(struct led_classdev *led_cdev,
  65. enum led_brightness value)
  66. {
  67. if (value) {
  68. latch_value &= ~(1 << FSG_LED_USB_BIT);
  69. *latch_address = latch_value;
  70. } else {
  71. latch_value |= (1 << FSG_LED_USB_BIT);
  72. *latch_address = latch_value;
  73. }
  74. }
  75. static void fsg_led_sync_set(struct led_classdev *led_cdev,
  76. enum led_brightness value)
  77. {
  78. if (value) {
  79. latch_value &= ~(1 << FSG_LED_SYNC_BIT);
  80. *latch_address = latch_value;
  81. } else {
  82. latch_value |= (1 << FSG_LED_SYNC_BIT);
  83. *latch_address = latch_value;
  84. }
  85. }
  86. static void fsg_led_ring_set(struct led_classdev *led_cdev,
  87. enum led_brightness value)
  88. {
  89. if (value) {
  90. latch_value &= ~(1 << FSG_LED_RING_BIT);
  91. *latch_address = latch_value;
  92. } else {
  93. latch_value |= (1 << FSG_LED_RING_BIT);
  94. *latch_address = latch_value;
  95. }
  96. }
  97. static struct led_classdev fsg_wlan_led = {
  98. .name = "fsg:blue:wlan",
  99. .brightness_set = fsg_led_wlan_set,
  100. .flags = LED_CORE_SUSPENDRESUME,
  101. };
  102. static struct led_classdev fsg_wan_led = {
  103. .name = "fsg:blue:wan",
  104. .brightness_set = fsg_led_wan_set,
  105. .flags = LED_CORE_SUSPENDRESUME,
  106. };
  107. static struct led_classdev fsg_sata_led = {
  108. .name = "fsg:blue:sata",
  109. .brightness_set = fsg_led_sata_set,
  110. .flags = LED_CORE_SUSPENDRESUME,
  111. };
  112. static struct led_classdev fsg_usb_led = {
  113. .name = "fsg:blue:usb",
  114. .brightness_set = fsg_led_usb_set,
  115. .flags = LED_CORE_SUSPENDRESUME,
  116. };
  117. static struct led_classdev fsg_sync_led = {
  118. .name = "fsg:blue:sync",
  119. .brightness_set = fsg_led_sync_set,
  120. .flags = LED_CORE_SUSPENDRESUME,
  121. };
  122. static struct led_classdev fsg_ring_led = {
  123. .name = "fsg:blue:ring",
  124. .brightness_set = fsg_led_ring_set,
  125. .flags = LED_CORE_SUSPENDRESUME,
  126. };
  127. static int fsg_led_probe(struct platform_device *pdev)
  128. {
  129. int ret;
  130. /* Map the LED chip select address space */
  131. latch_address = (unsigned short *) devm_ioremap(&pdev->dev,
  132. IXP4XX_EXP_BUS_BASE(2), 512);
  133. if (!latch_address)
  134. return -ENOMEM;
  135. latch_value = 0xffff;
  136. *latch_address = latch_value;
  137. ret = devm_led_classdev_register(&pdev->dev, &fsg_wlan_led);
  138. if (ret < 0)
  139. return ret;
  140. ret = devm_led_classdev_register(&pdev->dev, &fsg_wan_led);
  141. if (ret < 0)
  142. return ret;
  143. ret = devm_led_classdev_register(&pdev->dev, &fsg_sata_led);
  144. if (ret < 0)
  145. return ret;
  146. ret = devm_led_classdev_register(&pdev->dev, &fsg_usb_led);
  147. if (ret < 0)
  148. return ret;
  149. ret = devm_led_classdev_register(&pdev->dev, &fsg_sync_led);
  150. if (ret < 0)
  151. return ret;
  152. ret = devm_led_classdev_register(&pdev->dev, &fsg_ring_led);
  153. if (ret < 0)
  154. return ret;
  155. return ret;
  156. }
  157. static struct platform_driver fsg_led_driver = {
  158. .probe = fsg_led_probe,
  159. .driver = {
  160. .name = "fsg-led",
  161. },
  162. };
  163. module_platform_driver(fsg_led_driver);
  164. MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
  165. MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
  166. MODULE_LICENSE("GPL");