Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 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 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/leds.h> |
Paul Gortmaker | 54f4ded | 2011-07-03 13:56:03 -0400 | [diff] [blame] | 22 | #include <linux/module.h> |
Jingoo Han | aa2dcf9 | 2012-10-23 05:19:41 -0700 | [diff] [blame] | 23 | #include <linux/io.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 24 | #include <mach/hardware.h> |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 25 | |
Krzysztof HaĆasa | 914e7bc | 2009-11-16 22:53:53 +0100 | [diff] [blame] | 26 | #define FSG_LED_WLAN_BIT 0 |
| 27 | #define FSG_LED_WAN_BIT 1 |
| 28 | #define FSG_LED_SATA_BIT 2 |
| 29 | #define FSG_LED_USB_BIT 4 |
| 30 | #define FSG_LED_RING_BIT 5 |
| 31 | #define FSG_LED_SYNC_BIT 7 |
| 32 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 33 | static short __iomem *latch_address; |
| 34 | static unsigned short latch_value; |
| 35 | |
| 36 | |
| 37 | static void fsg_led_wlan_set(struct led_classdev *led_cdev, |
| 38 | enum led_brightness value) |
| 39 | { |
| 40 | if (value) { |
| 41 | latch_value &= ~(1 << FSG_LED_WLAN_BIT); |
| 42 | *latch_address = latch_value; |
| 43 | } else { |
| 44 | latch_value |= (1 << FSG_LED_WLAN_BIT); |
| 45 | *latch_address = latch_value; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static void fsg_led_wan_set(struct led_classdev *led_cdev, |
| 50 | enum led_brightness value) |
| 51 | { |
| 52 | if (value) { |
| 53 | latch_value &= ~(1 << FSG_LED_WAN_BIT); |
| 54 | *latch_address = latch_value; |
| 55 | } else { |
| 56 | latch_value |= (1 << FSG_LED_WAN_BIT); |
| 57 | *latch_address = latch_value; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | static void fsg_led_sata_set(struct led_classdev *led_cdev, |
| 62 | enum led_brightness value) |
| 63 | { |
| 64 | if (value) { |
| 65 | latch_value &= ~(1 << FSG_LED_SATA_BIT); |
| 66 | *latch_address = latch_value; |
| 67 | } else { |
| 68 | latch_value |= (1 << FSG_LED_SATA_BIT); |
| 69 | *latch_address = latch_value; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void fsg_led_usb_set(struct led_classdev *led_cdev, |
| 74 | enum led_brightness value) |
| 75 | { |
| 76 | if (value) { |
| 77 | latch_value &= ~(1 << FSG_LED_USB_BIT); |
| 78 | *latch_address = latch_value; |
| 79 | } else { |
| 80 | latch_value |= (1 << FSG_LED_USB_BIT); |
| 81 | *latch_address = latch_value; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static void fsg_led_sync_set(struct led_classdev *led_cdev, |
| 86 | enum led_brightness value) |
| 87 | { |
| 88 | if (value) { |
| 89 | latch_value &= ~(1 << FSG_LED_SYNC_BIT); |
| 90 | *latch_address = latch_value; |
| 91 | } else { |
| 92 | latch_value |= (1 << FSG_LED_SYNC_BIT); |
| 93 | *latch_address = latch_value; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void fsg_led_ring_set(struct led_classdev *led_cdev, |
| 98 | enum led_brightness value) |
| 99 | { |
| 100 | if (value) { |
| 101 | latch_value &= ~(1 << FSG_LED_RING_BIT); |
| 102 | *latch_address = latch_value; |
| 103 | } else { |
| 104 | latch_value |= (1 << FSG_LED_RING_BIT); |
| 105 | *latch_address = latch_value; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 110 | static struct led_classdev fsg_wlan_led = { |
| 111 | .name = "fsg:blue:wlan", |
| 112 | .brightness_set = fsg_led_wlan_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 113 | .flags = LED_CORE_SUSPENDRESUME, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static struct led_classdev fsg_wan_led = { |
| 117 | .name = "fsg:blue:wan", |
| 118 | .brightness_set = fsg_led_wan_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 119 | .flags = LED_CORE_SUSPENDRESUME, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static struct led_classdev fsg_sata_led = { |
| 123 | .name = "fsg:blue:sata", |
| 124 | .brightness_set = fsg_led_sata_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 125 | .flags = LED_CORE_SUSPENDRESUME, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | static struct led_classdev fsg_usb_led = { |
| 129 | .name = "fsg:blue:usb", |
| 130 | .brightness_set = fsg_led_usb_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 131 | .flags = LED_CORE_SUSPENDRESUME, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static struct led_classdev fsg_sync_led = { |
| 135 | .name = "fsg:blue:sync", |
| 136 | .brightness_set = fsg_led_sync_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 137 | .flags = LED_CORE_SUSPENDRESUME, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static struct led_classdev fsg_ring_led = { |
| 141 | .name = "fsg:blue:ring", |
| 142 | .brightness_set = fsg_led_ring_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 143 | .flags = LED_CORE_SUSPENDRESUME, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 147 | static int fsg_led_probe(struct platform_device *pdev) |
| 148 | { |
| 149 | int ret; |
| 150 | |
Sven Wegener | 07f696c | 2008-10-03 15:23:47 -0700 | [diff] [blame] | 151 | /* Map the LED chip select address space */ |
Jingoo Han | aa2dcf9 | 2012-10-23 05:19:41 -0700 | [diff] [blame] | 152 | latch_address = (unsigned short *) devm_ioremap(&pdev->dev, |
| 153 | IXP4XX_EXP_BUS_BASE(2), 512); |
| 154 | if (!latch_address) |
| 155 | return -ENOMEM; |
Sven Wegener | 07f696c | 2008-10-03 15:23:47 -0700 | [diff] [blame] | 156 | |
| 157 | latch_value = 0xffff; |
| 158 | *latch_address = latch_value; |
| 159 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 160 | ret = led_classdev_register(&pdev->dev, &fsg_wlan_led); |
| 161 | if (ret < 0) |
| 162 | goto failwlan; |
| 163 | |
| 164 | ret = led_classdev_register(&pdev->dev, &fsg_wan_led); |
| 165 | if (ret < 0) |
| 166 | goto failwan; |
| 167 | |
| 168 | ret = led_classdev_register(&pdev->dev, &fsg_sata_led); |
| 169 | if (ret < 0) |
| 170 | goto failsata; |
| 171 | |
| 172 | ret = led_classdev_register(&pdev->dev, &fsg_usb_led); |
| 173 | if (ret < 0) |
| 174 | goto failusb; |
| 175 | |
| 176 | ret = led_classdev_register(&pdev->dev, &fsg_sync_led); |
| 177 | if (ret < 0) |
| 178 | goto failsync; |
| 179 | |
| 180 | ret = led_classdev_register(&pdev->dev, &fsg_ring_led); |
| 181 | if (ret < 0) |
| 182 | goto failring; |
| 183 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 184 | return ret; |
| 185 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 186 | failring: |
| 187 | led_classdev_unregister(&fsg_sync_led); |
| 188 | failsync: |
| 189 | led_classdev_unregister(&fsg_usb_led); |
| 190 | failusb: |
| 191 | led_classdev_unregister(&fsg_sata_led); |
| 192 | failsata: |
| 193 | led_classdev_unregister(&fsg_wan_led); |
| 194 | failwan: |
| 195 | led_classdev_unregister(&fsg_wlan_led); |
| 196 | failwlan: |
| 197 | |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | static int fsg_led_remove(struct platform_device *pdev) |
| 202 | { |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 203 | led_classdev_unregister(&fsg_wlan_led); |
| 204 | led_classdev_unregister(&fsg_wan_led); |
| 205 | led_classdev_unregister(&fsg_sata_led); |
| 206 | led_classdev_unregister(&fsg_usb_led); |
| 207 | led_classdev_unregister(&fsg_sync_led); |
| 208 | led_classdev_unregister(&fsg_ring_led); |
| 209 | |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | |
| 214 | static struct platform_driver fsg_led_driver = { |
| 215 | .probe = fsg_led_probe, |
| 216 | .remove = fsg_led_remove, |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 217 | .driver = { |
| 218 | .name = "fsg-led", |
| 219 | }, |
| 220 | }; |
| 221 | |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 222 | module_platform_driver(fsg_led_driver); |
Rod Whitby | 3b2e46f | 2008-04-24 23:43:09 +0100 | [diff] [blame] | 223 | |
| 224 | MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>"); |
| 225 | MODULE_DESCRIPTION("Freecom FSG-3 LED driver"); |
| 226 | MODULE_LICENSE("GPL"); |