blob: bc6b420637d61eb9064d0d4a9ffd0b0768f71fdc [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Rod Whitby3b2e46f2008-04-24 23:43:09 +01002/*
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 Whitby3b2e46f2008-04-24 23:43:09 +010012 */
13
14#include <linux/kernel.h>
Rod Whitby3b2e46f2008-04-24 23:43:09 +010015#include <linux/platform_device.h>
16#include <linux/leds.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040017#include <linux/module.h>
Jingoo Hanaa2dcf92012-10-23 05:19:41 -070018#include <linux/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/hardware.h>
Rod Whitby3b2e46f2008-04-24 23:43:09 +010020
Krzysztof HaƂasa914e7bc2009-11-16 22:53:53 +010021#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 Whitby3b2e46f2008-04-24 23:43:09 +010028static short __iomem *latch_address;
29static unsigned short latch_value;
30
31
32static 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
44static 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
56static 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
68static 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
80static 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
92static 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 Whitby3b2e46f2008-04-24 23:43:09 +0100105static struct led_classdev fsg_wlan_led = {
106 .name = "fsg:blue:wlan",
107 .brightness_set = fsg_led_wlan_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000108 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100109};
110
111static struct led_classdev fsg_wan_led = {
112 .name = "fsg:blue:wan",
113 .brightness_set = fsg_led_wan_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000114 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100115};
116
117static struct led_classdev fsg_sata_led = {
118 .name = "fsg:blue:sata",
119 .brightness_set = fsg_led_sata_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000120 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100121};
122
123static struct led_classdev fsg_usb_led = {
124 .name = "fsg:blue:usb",
125 .brightness_set = fsg_led_usb_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000126 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100127};
128
129static struct led_classdev fsg_sync_led = {
130 .name = "fsg:blue:sync",
131 .brightness_set = fsg_led_sync_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000132 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100133};
134
135static struct led_classdev fsg_ring_led = {
136 .name = "fsg:blue:ring",
137 .brightness_set = fsg_led_ring_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000138 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100139};
140
141
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100142static int fsg_led_probe(struct platform_device *pdev)
143{
144 int ret;
145
Sven Wegener07f696c2008-10-03 15:23:47 -0700146 /* Map the LED chip select address space */
Jingoo Hanaa2dcf92012-10-23 05:19:41 -0700147 latch_address = (unsigned short *) devm_ioremap(&pdev->dev,
148 IXP4XX_EXP_BUS_BASE(2), 512);
149 if (!latch_address)
150 return -ENOMEM;
Sven Wegener07f696c2008-10-03 15:23:47 -0700151
152 latch_value = 0xffff;
153 *latch_address = latch_value;
154
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530155 ret = devm_led_classdev_register(&pdev->dev, &fsg_wlan_led);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100156 if (ret < 0)
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530157 return ret;
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100158
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530159 ret = devm_led_classdev_register(&pdev->dev, &fsg_wan_led);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100160 if (ret < 0)
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530161 return ret;
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100162
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530163 ret = devm_led_classdev_register(&pdev->dev, &fsg_sata_led);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100164 if (ret < 0)
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530165 return ret;
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100166
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530167 ret = devm_led_classdev_register(&pdev->dev, &fsg_usb_led);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100168 if (ret < 0)
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530169 return ret;
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100170
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530171 ret = devm_led_classdev_register(&pdev->dev, &fsg_sync_led);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100172 if (ret < 0)
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530173 return ret;
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100174
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530175 ret = devm_led_classdev_register(&pdev->dev, &fsg_ring_led);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100176 if (ret < 0)
Vaishali Thakkarc2d4af92015-08-18 19:50:16 +0530177 return ret;
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100178
179 return ret;
180}
181
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100182static struct platform_driver fsg_led_driver = {
183 .probe = fsg_led_probe,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100184 .driver = {
185 .name = "fsg-led",
186 },
187};
188
Axel Lin892a8842012-01-10 15:09:24 -0800189module_platform_driver(fsg_led_driver);
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100190
191MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
192MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
193MODULE_LICENSE("GPL");