leds-fsg.c 5.6 KB

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