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