leds-fsg.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/leds.h>
  21. #include <linux/module.h>
  22. #include <mach/hardware.h>
  23. #include <asm/io.h>
  24. #define FSG_LED_WLAN_BIT 0
  25. #define FSG_LED_WAN_BIT 1
  26. #define FSG_LED_SATA_BIT 2
  27. #define FSG_LED_USB_BIT 4
  28. #define FSG_LED_RING_BIT 5
  29. #define FSG_LED_SYNC_BIT 7
  30. static short __iomem *latch_address;
  31. static unsigned short latch_value;
  32. static void fsg_led_wlan_set(struct led_classdev *led_cdev,
  33. enum led_brightness value)
  34. {
  35. if (value) {
  36. latch_value &= ~(1 << FSG_LED_WLAN_BIT);
  37. *latch_address = latch_value;
  38. } else {
  39. latch_value |= (1 << FSG_LED_WLAN_BIT);
  40. *latch_address = latch_value;
  41. }
  42. }
  43. static void fsg_led_wan_set(struct led_classdev *led_cdev,
  44. enum led_brightness value)
  45. {
  46. if (value) {
  47. latch_value &= ~(1 << FSG_LED_WAN_BIT);
  48. *latch_address = latch_value;
  49. } else {
  50. latch_value |= (1 << FSG_LED_WAN_BIT);
  51. *latch_address = latch_value;
  52. }
  53. }
  54. static void fsg_led_sata_set(struct led_classdev *led_cdev,
  55. enum led_brightness value)
  56. {
  57. if (value) {
  58. latch_value &= ~(1 << FSG_LED_SATA_BIT);
  59. *latch_address = latch_value;
  60. } else {
  61. latch_value |= (1 << FSG_LED_SATA_BIT);
  62. *latch_address = latch_value;
  63. }
  64. }
  65. static void fsg_led_usb_set(struct led_classdev *led_cdev,
  66. enum led_brightness value)
  67. {
  68. if (value) {
  69. latch_value &= ~(1 << FSG_LED_USB_BIT);
  70. *latch_address = latch_value;
  71. } else {
  72. latch_value |= (1 << FSG_LED_USB_BIT);
  73. *latch_address = latch_value;
  74. }
  75. }
  76. static void fsg_led_sync_set(struct led_classdev *led_cdev,
  77. enum led_brightness value)
  78. {
  79. if (value) {
  80. latch_value &= ~(1 << FSG_LED_SYNC_BIT);
  81. *latch_address = latch_value;
  82. } else {
  83. latch_value |= (1 << FSG_LED_SYNC_BIT);
  84. *latch_address = latch_value;
  85. }
  86. }
  87. static void fsg_led_ring_set(struct led_classdev *led_cdev,
  88. enum led_brightness value)
  89. {
  90. if (value) {
  91. latch_value &= ~(1 << FSG_LED_RING_BIT);
  92. *latch_address = latch_value;
  93. } else {
  94. latch_value |= (1 << FSG_LED_RING_BIT);
  95. *latch_address = latch_value;
  96. }
  97. }
  98. static struct led_classdev fsg_wlan_led = {
  99. .name = "fsg:blue:wlan",
  100. .brightness_set = fsg_led_wlan_set,
  101. .flags = LED_CORE_SUSPENDRESUME,
  102. };
  103. static struct led_classdev fsg_wan_led = {
  104. .name = "fsg:blue:wan",
  105. .brightness_set = fsg_led_wan_set,
  106. .flags = LED_CORE_SUSPENDRESUME,
  107. };
  108. static struct led_classdev fsg_sata_led = {
  109. .name = "fsg:blue:sata",
  110. .brightness_set = fsg_led_sata_set,
  111. .flags = LED_CORE_SUSPENDRESUME,
  112. };
  113. static struct led_classdev fsg_usb_led = {
  114. .name = "fsg:blue:usb",
  115. .brightness_set = fsg_led_usb_set,
  116. .flags = LED_CORE_SUSPENDRESUME,
  117. };
  118. static struct led_classdev fsg_sync_led = {
  119. .name = "fsg:blue:sync",
  120. .brightness_set = fsg_led_sync_set,
  121. .flags = LED_CORE_SUSPENDRESUME,
  122. };
  123. static struct led_classdev fsg_ring_led = {
  124. .name = "fsg:blue:ring",
  125. .brightness_set = fsg_led_ring_set,
  126. .flags = LED_CORE_SUSPENDRESUME,
  127. };
  128. static int fsg_led_probe(struct platform_device *pdev)
  129. {
  130. int ret;
  131. /* Map the LED chip select address space */
  132. latch_address = (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
  133. if (!latch_address) {
  134. ret = -ENOMEM;
  135. goto failremap;
  136. }
  137. latch_value = 0xffff;
  138. *latch_address = latch_value;
  139. ret = led_classdev_register(&pdev->dev, &fsg_wlan_led);
  140. if (ret < 0)
  141. goto failwlan;
  142. ret = led_classdev_register(&pdev->dev, &fsg_wan_led);
  143. if (ret < 0)
  144. goto failwan;
  145. ret = led_classdev_register(&pdev->dev, &fsg_sata_led);
  146. if (ret < 0)
  147. goto failsata;
  148. ret = led_classdev_register(&pdev->dev, &fsg_usb_led);
  149. if (ret < 0)
  150. goto failusb;
  151. ret = led_classdev_register(&pdev->dev, &fsg_sync_led);
  152. if (ret < 0)
  153. goto failsync;
  154. ret = led_classdev_register(&pdev->dev, &fsg_ring_led);
  155. if (ret < 0)
  156. goto failring;
  157. return ret;
  158. failring:
  159. led_classdev_unregister(&fsg_sync_led);
  160. failsync:
  161. led_classdev_unregister(&fsg_usb_led);
  162. failusb:
  163. led_classdev_unregister(&fsg_sata_led);
  164. failsata:
  165. led_classdev_unregister(&fsg_wan_led);
  166. failwan:
  167. led_classdev_unregister(&fsg_wlan_led);
  168. failwlan:
  169. iounmap(latch_address);
  170. failremap:
  171. return ret;
  172. }
  173. static int fsg_led_remove(struct platform_device *pdev)
  174. {
  175. led_classdev_unregister(&fsg_wlan_led);
  176. led_classdev_unregister(&fsg_wan_led);
  177. led_classdev_unregister(&fsg_sata_led);
  178. led_classdev_unregister(&fsg_usb_led);
  179. led_classdev_unregister(&fsg_sync_led);
  180. led_classdev_unregister(&fsg_ring_led);
  181. iounmap(latch_address);
  182. return 0;
  183. }
  184. static struct platform_driver fsg_led_driver = {
  185. .probe = fsg_led_probe,
  186. .remove = fsg_led_remove,
  187. .driver = {
  188. .name = "fsg-led",
  189. },
  190. };
  191. module_platform_driver(fsg_led_driver);
  192. MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
  193. MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
  194. MODULE_LICENSE("GPL");