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