Blame view

drivers/leds/leds-fsg.c 5.12 KB
3b2e46f8c   Rod Whitby   leds: Add new dri...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  /*
   * LED Driver for the Freecom FSG-3
   *
   * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
   *
   * Author: Rod Whitby <rod@whitby.id.au>
   *
   * Based on leds-spitz.c
   * Copyright 2005-2006 Openedhand Ltd.
   * Author: Richard Purdie <rpurdie@openedhand.com>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   */
  
  #include <linux/kernel.h>
  #include <linux/init.h>
  #include <linux/platform_device.h>
  #include <linux/leds.h>
54f4dedb5   Paul Gortmaker   drivers/leds: Add...
22
  #include <linux/module.h>
a09e64fbc   Russell King   [ARM] Move includ...
23
  #include <mach/hardware.h>
3b2e46f8c   Rod Whitby   leds: Add new dri...
24
  #include <asm/io.h>
914e7bc28   Krzysztof HaƂasa   IXP4xx: move FSG ...
25
26
27
28
29
30
  #define FSG_LED_WLAN_BIT	0
  #define FSG_LED_WAN_BIT		1
  #define FSG_LED_SATA_BIT	2
  #define FSG_LED_USB_BIT		4
  #define FSG_LED_RING_BIT	5
  #define FSG_LED_SYNC_BIT	7
3b2e46f8c   Rod Whitby   leds: Add new dri...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  static short __iomem *latch_address;
  static unsigned short latch_value;
  
  
  static void fsg_led_wlan_set(struct led_classdev *led_cdev,
  			     enum led_brightness value)
  {
  	if (value) {
  		latch_value &= ~(1 << FSG_LED_WLAN_BIT);
  		*latch_address = latch_value;
  	} else {
  		latch_value |=  (1 << FSG_LED_WLAN_BIT);
  		*latch_address = latch_value;
  	}
  }
  
  static void fsg_led_wan_set(struct led_classdev *led_cdev,
  			    enum led_brightness value)
  {
  	if (value) {
  		latch_value &= ~(1 << FSG_LED_WAN_BIT);
  		*latch_address = latch_value;
  	} else {
  		latch_value |=  (1 << FSG_LED_WAN_BIT);
  		*latch_address = latch_value;
  	}
  }
  
  static void fsg_led_sata_set(struct led_classdev *led_cdev,
  			     enum led_brightness value)
  {
  	if (value) {
  		latch_value &= ~(1 << FSG_LED_SATA_BIT);
  		*latch_address = latch_value;
  	} else {
  		latch_value |=  (1 << FSG_LED_SATA_BIT);
  		*latch_address = latch_value;
  	}
  }
  
  static void fsg_led_usb_set(struct led_classdev *led_cdev,
  			    enum led_brightness value)
  {
  	if (value) {
  		latch_value &= ~(1 << FSG_LED_USB_BIT);
  		*latch_address = latch_value;
  	} else {
  		latch_value |=  (1 << FSG_LED_USB_BIT);
  		*latch_address = latch_value;
  	}
  }
  
  static void fsg_led_sync_set(struct led_classdev *led_cdev,
  			     enum led_brightness value)
  {
  	if (value) {
  		latch_value &= ~(1 << FSG_LED_SYNC_BIT);
  		*latch_address = latch_value;
  	} else {
  		latch_value |=  (1 << FSG_LED_SYNC_BIT);
  		*latch_address = latch_value;
  	}
  }
  
  static void fsg_led_ring_set(struct led_classdev *led_cdev,
  			     enum led_brightness value)
  {
  	if (value) {
  		latch_value &= ~(1 << FSG_LED_RING_BIT);
  		*latch_address = latch_value;
  	} else {
  		latch_value |=  (1 << FSG_LED_RING_BIT);
  		*latch_address = latch_value;
  	}
  }
3b2e46f8c   Rod Whitby   leds: Add new dri...
106
107
108
  static struct led_classdev fsg_wlan_led = {
  	.name			= "fsg:blue:wlan",
  	.brightness_set		= fsg_led_wlan_set,
859cb7f2a   Richard Purdie   leds: Add suspend...
109
  	.flags			= LED_CORE_SUSPENDRESUME,
3b2e46f8c   Rod Whitby   leds: Add new dri...
110
111
112
113
114
  };
  
  static struct led_classdev fsg_wan_led = {
  	.name			= "fsg:blue:wan",
  	.brightness_set		= fsg_led_wan_set,
859cb7f2a   Richard Purdie   leds: Add suspend...
115
  	.flags			= LED_CORE_SUSPENDRESUME,
3b2e46f8c   Rod Whitby   leds: Add new dri...
116
117
118
119
120
  };
  
  static struct led_classdev fsg_sata_led = {
  	.name			= "fsg:blue:sata",
  	.brightness_set		= fsg_led_sata_set,
859cb7f2a   Richard Purdie   leds: Add suspend...
121
  	.flags			= LED_CORE_SUSPENDRESUME,
3b2e46f8c   Rod Whitby   leds: Add new dri...
122
123
124
125
126
  };
  
  static struct led_classdev fsg_usb_led = {
  	.name			= "fsg:blue:usb",
  	.brightness_set		= fsg_led_usb_set,
859cb7f2a   Richard Purdie   leds: Add suspend...
127
  	.flags			= LED_CORE_SUSPENDRESUME,
3b2e46f8c   Rod Whitby   leds: Add new dri...
128
129
130
131
132
  };
  
  static struct led_classdev fsg_sync_led = {
  	.name			= "fsg:blue:sync",
  	.brightness_set		= fsg_led_sync_set,
859cb7f2a   Richard Purdie   leds: Add suspend...
133
  	.flags			= LED_CORE_SUSPENDRESUME,
3b2e46f8c   Rod Whitby   leds: Add new dri...
134
135
136
137
138
  };
  
  static struct led_classdev fsg_ring_led = {
  	.name			= "fsg:blue:ring",
  	.brightness_set		= fsg_led_ring_set,
859cb7f2a   Richard Purdie   leds: Add suspend...
139
  	.flags			= LED_CORE_SUSPENDRESUME,
3b2e46f8c   Rod Whitby   leds: Add new dri...
140
  };
3b2e46f8c   Rod Whitby   leds: Add new dri...
141
142
143
  static int fsg_led_probe(struct platform_device *pdev)
  {
  	int ret;
07f696c77   Sven Wegener   leds-fsg: change ...
144
145
146
147
148
149
150
151
152
  	/* Map the LED chip select address space */
  	latch_address = (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
  	if (!latch_address) {
  		ret = -ENOMEM;
  		goto failremap;
  	}
  
  	latch_value = 0xffff;
  	*latch_address = latch_value;
3b2e46f8c   Rod Whitby   leds: Add new dri...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  	ret = led_classdev_register(&pdev->dev, &fsg_wlan_led);
  	if (ret < 0)
  		goto failwlan;
  
  	ret = led_classdev_register(&pdev->dev, &fsg_wan_led);
  	if (ret < 0)
  		goto failwan;
  
  	ret = led_classdev_register(&pdev->dev, &fsg_sata_led);
  	if (ret < 0)
  		goto failsata;
  
  	ret = led_classdev_register(&pdev->dev, &fsg_usb_led);
  	if (ret < 0)
  		goto failusb;
  
  	ret = led_classdev_register(&pdev->dev, &fsg_sync_led);
  	if (ret < 0)
  		goto failsync;
  
  	ret = led_classdev_register(&pdev->dev, &fsg_ring_led);
  	if (ret < 0)
  		goto failring;
3b2e46f8c   Rod Whitby   leds: Add new dri...
176
  	return ret;
3b2e46f8c   Rod Whitby   leds: Add new dri...
177
178
179
180
181
182
183
184
185
186
187
   failring:
  	led_classdev_unregister(&fsg_sync_led);
   failsync:
  	led_classdev_unregister(&fsg_usb_led);
   failusb:
  	led_classdev_unregister(&fsg_sata_led);
   failsata:
  	led_classdev_unregister(&fsg_wan_led);
   failwan:
  	led_classdev_unregister(&fsg_wlan_led);
   failwlan:
07f696c77   Sven Wegener   leds-fsg: change ...
188
189
  	iounmap(latch_address);
   failremap:
3b2e46f8c   Rod Whitby   leds: Add new dri...
190
191
192
193
194
195
  
  	return ret;
  }
  
  static int fsg_led_remove(struct platform_device *pdev)
  {
3b2e46f8c   Rod Whitby   leds: Add new dri...
196
197
198
199
200
201
  	led_classdev_unregister(&fsg_wlan_led);
  	led_classdev_unregister(&fsg_wan_led);
  	led_classdev_unregister(&fsg_sata_led);
  	led_classdev_unregister(&fsg_usb_led);
  	led_classdev_unregister(&fsg_sync_led);
  	led_classdev_unregister(&fsg_ring_led);
07f696c77   Sven Wegener   leds-fsg: change ...
202
  	iounmap(latch_address);
3b2e46f8c   Rod Whitby   leds: Add new dri...
203
204
205
206
207
208
209
  	return 0;
  }
  
  
  static struct platform_driver fsg_led_driver = {
  	.probe		= fsg_led_probe,
  	.remove		= fsg_led_remove,
3b2e46f8c   Rod Whitby   leds: Add new dri...
210
211
212
213
  	.driver		= {
  		.name		= "fsg-led",
  	},
  };
892a8843f   Axel Lin   leds: convert led...
214
  module_platform_driver(fsg_led_driver);
3b2e46f8c   Rod Whitby   leds: Add new dri...
215
216
217
218
  
  MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
  MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
  MODULE_LICENSE("GPL");