919571a0b4a124f47afa45b7fad283bae414d47a
[15.05/openwrt.git] / target / linux / ixp4xx / patches-2.6.23 / 013-fsg3_support.patch
1 Index: linux-2.6.23.12/arch/arm/mach-ixp4xx/fsg-pci.c
2 ===================================================================
3 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.23.12/arch/arm/mach-ixp4xx/fsg-pci.c      2008-01-05 13:32:23.000000000 +1030
5 @@ -0,0 +1,71 @@
6 +/*
7 + * arch/arch/mach-ixp4xx/fsg-pci.c
8 + *
9 + * FSG board-level PCI initialization
10 + *
11 + * Author: Rod Whitby <rod@whitby.id.au>
12 + * Maintainer: http://www.nslu2-linux.org/
13 + *
14 + * based on ixdp425-pci.c:
15 + *     Copyright (C) 2002 Intel Corporation.
16 + *     Copyright (C) 2003-2004 MontaVista Software, Inc.
17 + *
18 + * This program is free software; you can redistribute it and/or modify
19 + * it under the terms of the GNU General Public License version 2 as
20 + * published by the Free Software Foundation.
21 + *
22 + */
23 +
24 +#include <linux/pci.h>
25 +#include <linux/init.h>
26 +#include <linux/irq.h>
27 +
28 +#include <asm/mach/pci.h>
29 +#include <asm/mach-types.h>
30 +
31 +void __init fsg_pci_preinit(void)
32 +{
33 +       set_irq_type(IRQ_FSG_PCI_INTA, IRQT_LOW);
34 +       set_irq_type(IRQ_FSG_PCI_INTB, IRQT_LOW);
35 +       set_irq_type(IRQ_FSG_PCI_INTC, IRQT_LOW);
36 +
37 +       ixp4xx_pci_preinit();
38 +}
39 +
40 +static int __init fsg_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
41 +{
42 +       static int pci_irq_table[FSG_PCI_IRQ_LINES] = {
43 +               IRQ_FSG_PCI_INTC,
44 +               IRQ_FSG_PCI_INTB,
45 +               IRQ_FSG_PCI_INTA,
46 +       };
47 +
48 +       int irq = -1;
49 +       slot = slot - 11;
50 +
51 +       if (slot >= 1 && slot <= FSG_PCI_MAX_DEV &&
52 +               pin >= 1 && pin <= FSG_PCI_IRQ_LINES) {
53 +                       irq = pci_irq_table[(slot - 1)];
54 +       }
55 +        printk("%s: Mapped slot %d pin %d to IRQ %d\n", __FUNCTION__,slot, pin, irq);
56 +
57 +        return irq;
58 +}
59 +
60 +struct hw_pci fsg_pci __initdata = {
61 +       .nr_controllers = 1,
62 +       .preinit =        fsg_pci_preinit,
63 +       .swizzle =        pci_std_swizzle,
64 +       .setup =          ixp4xx_setup,
65 +       .scan =           ixp4xx_scan_bus,
66 +       .map_irq =        fsg_map_irq,
67 +};
68 +
69 +int __init fsg_pci_init(void)
70 +{
71 +       if (machine_is_fsg())
72 +               pci_common_init(&fsg_pci);
73 +       return 0;
74 +}
75 +
76 +subsys_initcall(fsg_pci_init);
77 Index: linux-2.6.23.12/arch/arm/mach-ixp4xx/fsg-setup.c
78 ===================================================================
79 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
80 +++ linux-2.6.23.12/arch/arm/mach-ixp4xx/fsg-setup.c    2008-01-05 14:07:41.000000000 +1030
81 @@ -0,0 +1,148 @@
82 +/*
83 + * arch/arm/mach-ixp4xx/fsg-setup.c
84 + *
85 + * FSG board-setup
86 + *
87 + * based ixdp425-setup.c:
88 + *      Copyright (C) 2003-2004 MontaVista Software, Inc.
89 + *
90 + * Author: Rod Whitby <rod@whitby.id.au>
91 + * Maintainers: http://www.nslu2-linux.org/
92 + *
93 + */
94 +
95 +#include <linux/kernel.h>
96 +#include <linux/serial.h>
97 +#include <linux/serial_8250.h>
98 +#include <linux/leds.h>
99 +#include <linux/mtd/mtd.h>
100 +#include <linux/reboot.h>
101 +
102 +#include <asm/mach-types.h>
103 +#include <asm/mach/arch.h>
104 +#include <asm/mach/flash.h>
105 +
106 +static struct flash_platform_data fsg_flash_data = {
107 +       .map_name               = "cfi_probe",
108 +       .width                  = 2,
109 +};
110 +
111 +static struct resource fsg_flash_resource = {
112 +       .flags                  = IORESOURCE_MEM,
113 +};
114 +
115 +static struct platform_device fsg_flash = {
116 +       .name                   = "IXP4XX-Flash",
117 +       .id                     = 0,
118 +       .dev.platform_data      = &fsg_flash_data,
119 +       .num_resources          = 1,
120 +       .resource               = &fsg_flash_resource,
121 +};
122 +
123 +static struct ixp4xx_i2c_pins fsg_i2c_gpio_pins = {
124 +       .sda_pin                = FSG_SDA_PIN,
125 +       .scl_pin                = FSG_SCL_PIN,
126 +};
127 +
128 +static struct platform_device fsg_i2c_controller = {
129 +        .name                   = "IXP4XX-I2C",
130 +        .id                     = 0,
131 +        .dev.platform_data      = &fsg_i2c_gpio_pins,
132 +        .num_resources          = 0,
133 +};
134 +
135 +static struct resource fsg_uart_resources[] = {
136 +       {
137 +               .start          = IXP4XX_UART1_BASE_PHYS,
138 +               .end            = IXP4XX_UART1_BASE_PHYS + 0x0fff,
139 +               .flags          = IORESOURCE_MEM,
140 +       },
141 +       {
142 +               .start          = IXP4XX_UART2_BASE_PHYS,
143 +               .end            = IXP4XX_UART2_BASE_PHYS + 0x0fff,
144 +               .flags          = IORESOURCE_MEM,
145 +       }
146 +};
147 +
148 +static struct plat_serial8250_port fsg_uart_data[] = {
149 +       {
150 +               .mapbase        = IXP4XX_UART1_BASE_PHYS,
151 +               .membase        = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
152 +               .irq            = IRQ_IXP4XX_UART1,
153 +               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
154 +               .iotype         = UPIO_MEM,
155 +               .regshift       = 2,
156 +               .uartclk        = IXP4XX_UART_XTAL,
157 +       },
158 +       {
159 +               .mapbase        = IXP4XX_UART2_BASE_PHYS,
160 +               .membase        = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
161 +               .irq            = IRQ_IXP4XX_UART2,
162 +               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
163 +               .iotype         = UPIO_MEM,
164 +               .regshift       = 2,
165 +               .uartclk        = IXP4XX_UART_XTAL,
166 +       },
167 +       { }
168 +};
169 +
170 +static struct platform_device fsg_uart = {
171 +       .name                   = "serial8250",
172 +       .id                     = PLAT8250_DEV_PLATFORM,
173 +       .dev.platform_data      = fsg_uart_data,
174 +       .num_resources          = ARRAY_SIZE(fsg_uart_resources),
175 +       .resource               = fsg_uart_resources,
176 +};
177 +
178 +static struct platform_device fsg_leds = {
179 +       .name           = "fsg-led",
180 +       .id             = -1,
181 +};
182 +
183 +static struct platform_device *fsg_devices[] __initdata = {
184 +       &fsg_i2c_controller,
185 +       &fsg_flash,
186 +       &fsg_leds,
187 +};
188 +
189 +static void fsg_power_off(void)
190 +{
191 +       printk("Restarting system.\n");
192 +       machine_restart(NULL);
193 +}
194 +
195 +static void __init fsg_init(void)
196 +{
197 +       ixp4xx_sys_init();
198 +
199 +       fsg_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
200 +       fsg_flash_resource.end =
201 +               IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
202 +
203 +       pm_power_off = fsg_power_off;
204 +
205 +       *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
206 +       *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
207 +
208 +       /* Configure CS2 for operation, 8bit and writable */
209 +       *IXP4XX_EXP_CS2 = 0xbfff0002;
210 +
211 +       /* This is only useful on a modified machine, but it is valuable
212 +        * to have it first in order to see debug messages, and so that
213 +        * it does *not* get removed if platform_add_devices fails!
214 +        */
215 +       (void)platform_device_register(&fsg_uart);
216 +
217 +       platform_add_devices(fsg_devices, ARRAY_SIZE(fsg_devices));
218 +}
219 +
220 +MACHINE_START(FSG, "Freecom FSG-3")
221 +       .phys_io        = IXP4XX_PERIPHERAL_BASE_PHYS,
222 +       .io_pg_offst    = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xfffc,
223 +       .map_io         = ixp4xx_map_io,
224 +       .init_irq       = ixp4xx_init_irq,
225 +       .timer          = &ixp4xx_timer,
226 +       .boot_params    = 0x0100,
227 +       .init_machine   = fsg_init,
228 +MACHINE_END
229 +
230 Index: linux-2.6.23.12/arch/arm/mach-ixp4xx/Kconfig
231 ===================================================================
232 --- linux-2.6.23.12.orig/arch/arm/mach-ixp4xx/Kconfig   2008-01-05 13:29:20.000000000 +1030
233 +++ linux-2.6.23.12/arch/arm/mach-ixp4xx/Kconfig        2008-01-05 14:07:40.000000000 +1030
234 @@ -125,6 +125,15 @@
235         depends on ARCH_IXDP425 || MACH_IXDP465 || MACH_KIXRP435
236         default y
237  
238 +config MACH_FSG
239 +       bool
240 +       prompt "Freecom FSG-3"
241 +       select PCI
242 +       help
243 +         Say 'Y' here if you want your kernel to support Freecom's
244 +         FSG-3 device. For more information on this platform
245 +         see http://www.nslu2-linux.org/wiki/FSG3/HomePage
246 +
247  #
248  # Certain registers and IRQs are only enabled if supporting IXP465 CPUs
249  #
250 Index: linux-2.6.23.12/arch/arm/mach-ixp4xx/Makefile
251 ===================================================================
252 --- linux-2.6.23.12.orig/arch/arm/mach-ixp4xx/Makefile  2008-01-05 13:29:20.000000000 +1030
253 +++ linux-2.6.23.12/arch/arm/mach-ixp4xx/Makefile       2008-01-05 14:07:40.000000000 +1030
254 @@ -15,6 +15,7 @@
255  obj-pci-$(CONFIG_MACH_DSMG600)         += dsmg600-pci.o
256  obj-pci-$(CONFIG_MACH_GATEWAY7001)     += gateway7001-pci.o
257  obj-pci-$(CONFIG_MACH_WG302V2)         += wg302v2-pci.o
258 +obj-pci-$(CONFIG_MACH_FSG)             += fsg-pci.o
259  
260  obj-y  += common.o
261  
262 @@ -28,5 +29,6 @@
263  obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o dsmg600-power.o
264  obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
265  obj-$(CONFIG_MACH_WG302V2)     += wg302v2-setup.o
266 +obj-$(CONFIG_MACH_FSG)         += fsg-setup.o fsg-power.o
267  
268  obj-$(CONFIG_PCI)              += $(obj-pci-$(CONFIG_PCI)) common-pci.o
269 Index: linux-2.6.23.12/include/asm-arm/arch-ixp4xx/fsg.h
270 ===================================================================
271 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
272 +++ linux-2.6.23.12/include/asm-arm/arch-ixp4xx/fsg.h   2008-01-05 14:08:23.000000000 +1030
273 @@ -0,0 +1,58 @@
274 +/*
275 + * include/asm-arm/arch-ixp4xx/fsg.h
276 + *
277 + * Freecom FSG-3 platform specific definitions
278 + *
279 + * Author: Rod Whitby <rod@whitby.id.au>
280 + * Author: Tomasz Chmielewski <mangoo@wpkg.org>
281 + * Maintainers: http://www.nslu2-linux.org
282 + *
283 + * Based on coyote.h by
284 + * Copyright 2004 (c) MontaVista, Software, Inc.
285 + *
286 + * This file is licensed under  the terms of the GNU General Public
287 + * License version 2. This program is licensed "as is" without any
288 + * warranty of any kind, whether express or implied.
289 + */
290 +
291 +#ifndef __ASM_ARCH_HARDWARE_H__
292 +#error "Do not include this directly, instead #include <asm/hardware.h>"
293 +#endif
294 +
295 +#define FSG_SDA_PIN            12
296 +#define FSG_SCL_PIN            13
297 +
298 +/*
299 + * FSG PCI IRQs
300 + */
301 +#define FSG_PCI_MAX_DEV                3
302 +#define FSG_PCI_IRQ_LINES      3
303 +
304 +
305 +/* PCI controller GPIO to IRQ pin mappings */
306 +#define FSG_PCI_INTA_PIN       6
307 +#define FSG_PCI_INTB_PIN       7
308 +#define FSG_PCI_INTC_PIN       5
309 +
310 +/* Buttons */
311 +
312 +#define FSG_SB_GPIO            4
313 +#define FSG_RB_GPIO            9
314 +#define FSG_UB_GPIO            10
315 +
316 +#define FSG_SB_IRQ             IRQ_IXP4XX_GPIO4
317 +#define FSG_RB_IRQ             IRQ_IXP4XX_GPIO9
318 +#define FSG_UB_IRQ             IRQ_IXP4XX_GPIO10
319 +
320 +#define FSG_SB_BM              (1L << FSG_SB_GPIO)
321 +#define FSG_RB_BM              (1L << FSG_RB_GPIO)
322 +#define FSG_UB_BM              (1L << FSG_UB_GPIO)
323 +
324 +/* LEDs */
325 +
326 +#define FSG_LED_WLAN_BIT       0
327 +#define FSG_LED_WAN_BIT                1
328 +#define FSG_LED_SATA_BIT       2
329 +#define FSG_LED_USB_BIT                4
330 +#define FSG_LED_RING_BIT       5
331 +#define FSG_LED_SYNC_BIT       7
332 Index: linux-2.6.23.12/include/asm-arm/arch-ixp4xx/hardware.h
333 ===================================================================
334 --- linux-2.6.23.12.orig/include/asm-arm/arch-ixp4xx/hardware.h 2008-01-05 13:29:20.000000000 +1030
335 +++ linux-2.6.23.12/include/asm-arm/arch-ixp4xx/hardware.h      2008-01-05 14:07:39.000000000 +1030
336 @@ -45,5 +45,6 @@
337  #include "nslu2.h"
338  #include "nas100d.h"
339  #include "dsmg600.h"
340 +#include "fsg.h"
341  
342  #endif  /* _ASM_ARCH_HARDWARE_H */
343 Index: linux-2.6.23.12/include/asm-arm/arch-ixp4xx/irqs.h
344 ===================================================================
345 --- linux-2.6.23.12.orig/include/asm-arm/arch-ixp4xx/irqs.h     2008-01-05 13:29:20.000000000 +1030
346 +++ linux-2.6.23.12/include/asm-arm/arch-ixp4xx/irqs.h  2008-01-05 13:29:24.000000000 +1030
347 @@ -128,4 +128,17 @@
348  #define        IRQ_DSMG600_PCI_INTE    IRQ_IXP4XX_GPIO7
349  #define        IRQ_DSMG600_PCI_INTF    IRQ_IXP4XX_GPIO6
350  
351 +/*
352 + * Freecom FSG-3 Board IRQs
353 + */
354 +#define        IRQ_FSG_PCI_INTA        IRQ_IXP4XX_GPIO6
355 +#define        IRQ_FSG_PCI_INTB        IRQ_IXP4XX_GPIO7
356 +#define        IRQ_FSG_PCI_INTC        IRQ_IXP4XX_GPIO5
357 +
358 +/* %%% REMOVE %%%
359 +#define        IRQ_FSG_PCI_SLOT0       IRQ_IXP4XX_GPIO6
360 +#define        IRQ_FSG_PCI_SLOT1       IRQ_IXP4XX_GPIO7
361 +#define        IRQ_FSG_IDE             IRQ_IXP4XX_GPIO5
362 +*/
363 +
364  #endif
365 Index: linux-2.6.23.12/arch/arm/mach-ixp4xx/fsg-power.c
366 ===================================================================
367 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
368 +++ linux-2.6.23.12/arch/arm/mach-ixp4xx/fsg-power.c    2008-01-05 13:32:27.000000000 +1030
369 @@ -0,0 +1,87 @@
370 +/*
371 + * arch/arm/mach-ixp4xx/fsg-power.c
372 + *
373 + * FSG Power/Reset driver
374 + *
375 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
376 + *
377 + * based on nslu2-power.c
378 + *  Copyright (C) 2005 Tower Technologies
379 + *
380 + * This program is free software; you can redistribute it and/or modify
381 + * it under the terms of the GNU General Public License version 2 as
382 + * published by the Free Software Foundation.
383 + *
384 + */
385 +
386 +#include <linux/module.h>
387 +#include <linux/reboot.h>
388 +#include <linux/irq.h>
389 +#include <linux/interrupt.h>
390 +#include <linux/kernel.h>
391 +
392 +#include <asm/mach-types.h>
393 +
394 +static irqreturn_t fsg_power_handler(int irq, void *dev_id)
395 +{
396 +       /* Signal init to do the ctrlaltdel action, this will bypass init if
397 +        * it hasn't started and do a kernel_restart.
398 +        */
399 +       ctrl_alt_del();
400 +
401 +       return IRQ_HANDLED;
402 +}
403 +
404 +static irqreturn_t fsg_reset_handler(int irq, void *dev_id)
405 +{
406 +       /* This is the paper-clip reset, it shuts the machine down directly.
407 +        */
408 +       machine_power_off();
409 +
410 +       return IRQ_HANDLED;
411 +}
412 +
413 +static int __init fsg_power_init(void)
414 +{
415 +       if (!(machine_is_fsg()))
416 +               return 0;
417 +
418 +       set_irq_type(FSG_RB_IRQ, IRQT_LOW);
419 +       set_irq_type(FSG_SB_IRQ, IRQT_LOW);
420 +
421 +       if (request_irq(FSG_RB_IRQ, &fsg_reset_handler,
422 +               IRQF_DISABLED, "FSG reset button", NULL) < 0) {
423 +
424 +               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
425 +                       FSG_RB_IRQ);
426 +
427 +               return -EIO;
428 +       }
429 +
430 +       if (request_irq(FSG_SB_IRQ, &fsg_power_handler,
431 +               IRQF_DISABLED, "FSG power button", NULL) < 0) {
432 +
433 +               printk(KERN_DEBUG "Power Button IRQ %d not available\n",
434 +                       FSG_SB_IRQ);
435 +
436 +               return -EIO;
437 +       }
438 +
439 +       return 0;
440 +}
441 +
442 +static void __exit fsg_power_exit(void)
443 +{
444 +       if (!(machine_is_fsg()))
445 +               return;
446 +
447 +       free_irq(FSG_SB_IRQ, NULL);
448 +       free_irq(FSG_RB_IRQ, NULL);
449 +}
450 +
451 +module_init(fsg_power_init);
452 +module_exit(fsg_power_exit);
453 +
454 +MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
455 +MODULE_DESCRIPTION("FSG Power/Reset driver");
456 +MODULE_LICENSE("GPL");
457 Index: linux-2.6.23.12/drivers/leds/Kconfig
458 ===================================================================
459 --- linux-2.6.23.12.orig/drivers/leds/Kconfig   2008-01-05 13:31:05.000000000 +1030
460 +++ linux-2.6.23.12/drivers/leds/Kconfig        2008-01-05 13:33:48.000000000 +1030
461 @@ -48,6 +48,12 @@
462           particular board must have LEDs and they must be connected
463           to the GPIO lines.  If unsure, say Y.
464  
465 +config LEDS_FSG
466 +       tristate "LED Support for the Freecom FSG-3"
467 +       depends on LEDS_CLASS && MACH_FSG
468 +       help
469 +         This option enables support for the LEDs on the Freecom FSG-3.
470 +
471  config LEDS_TOSA
472         tristate "LED Support for the Sharp SL-6000 series"
473         depends on LEDS_CLASS && PXA_SHARPSL
474 Index: linux-2.6.23.12/drivers/leds/Makefile
475 ===================================================================
476 --- linux-2.6.23.12.orig/drivers/leds/Makefile  2008-01-05 13:31:04.000000000 +1030
477 +++ linux-2.6.23.12/drivers/leds/Makefile       2008-01-05 13:33:21.000000000 +1030
478 @@ -9,6 +9,7 @@
479  obj-$(CONFIG_LEDS_LOCOMO)              += leds-locomo.o
480  obj-$(CONFIG_LEDS_SPITZ)               += leds-spitz.o
481  obj-$(CONFIG_LEDS_IXP4XX)              += leds-ixp4xx-gpio.o
482 +obj-$(CONFIG_LEDS_FSG)                 += leds-fsg.o
483  obj-$(CONFIG_LEDS_TOSA)                        += leds-tosa.o
484  obj-$(CONFIG_LEDS_S3C24XX)             += leds-s3c24xx.o
485  obj-$(CONFIG_LEDS_AMS_DELTA)           += leds-ams-delta.o
486 Index: linux-2.6.23.12/drivers/leds/leds-fsg.c
487 ===================================================================
488 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
489 +++ linux-2.6.23.12/drivers/leds/leds-fsg.c     2008-01-05 13:31:52.000000000 +1030
490 @@ -0,0 +1,243 @@
491 +/*
492 + * LED Driver for the Freecom FSG-3
493 + *
494 + * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
495 + *
496 + * Author: Rod Whitby <rod@whitby.id.au>
497 + *
498 + * Based on leds-spitz.c
499 + * Copyright 2005-2006 Openedhand Ltd.
500 + * Author: Richard Purdie <rpurdie@openedhand.com>
501 + *
502 + * This program is free software; you can redistribute it and/or modify
503 + * it under the terms of the GNU General Public License version 2 as
504 + * published by the Free Software Foundation.
505 + *
506 + */
507 +
508 +#include <linux/kernel.h>
509 +#include <linux/init.h>
510 +#include <linux/platform_device.h>
511 +#include <linux/leds.h>
512 +#include <asm/arch/hardware.h>
513 +#include <asm/io.h>
514 +
515 +static short __iomem *latch_address;
516 +static unsigned short latch_value;
517 +
518 +
519 +static void fsg_led_wlan_set(struct led_classdev *led_cdev, enum led_brightness value)
520 +{
521 +       if (value) {
522 +               latch_value &= ~(1 << FSG_LED_WLAN_BIT);
523 +               *latch_address = latch_value;
524 +       }
525 +       else {
526 +               latch_value |=  (1 << FSG_LED_WLAN_BIT);
527 +               *latch_address = latch_value;
528 +       }
529 +}
530 +
531 +static void fsg_led_wan_set(struct led_classdev *led_cdev, enum led_brightness value)
532 +{
533 +       if (value) {
534 +               latch_value &= ~(1 << FSG_LED_WAN_BIT);
535 +               *latch_address = latch_value;
536 +       }
537 +       else {
538 +               latch_value |=  (1 << FSG_LED_WAN_BIT);
539 +               *latch_address = latch_value;
540 +       }
541 +}
542 +
543 +static void fsg_led_sata_set(struct led_classdev *led_cdev, enum led_brightness value)
544 +{
545 +       if (value) {
546 +               latch_value &= ~(1 << FSG_LED_SATA_BIT);
547 +               *latch_address = latch_value;
548 +       }
549 +       else {
550 +               latch_value |=  (1 << FSG_LED_SATA_BIT);
551 +               *latch_address = latch_value;
552 +       }
553 +}
554 +
555 +static void fsg_led_usb_set(struct led_classdev *led_cdev, enum led_brightness value)
556 +{
557 +       if (value) {
558 +               latch_value &= ~(1 << FSG_LED_USB_BIT);
559 +               *latch_address = latch_value;
560 +       }
561 +       else {
562 +               latch_value |=  (1 << FSG_LED_USB_BIT);
563 +               *latch_address = latch_value;
564 +       }
565 +}
566 +
567 +static void fsg_led_sync_set(struct led_classdev *led_cdev, enum led_brightness value)
568 +{
569 +       if (value) {
570 +               latch_value &= ~(1 << FSG_LED_SYNC_BIT);
571 +               *latch_address = latch_value;
572 +       }
573 +       else {
574 +               latch_value |=  (1 << FSG_LED_SYNC_BIT);
575 +               *latch_address = latch_value;
576 +       }
577 +}
578 +
579 +static void fsg_led_ring_set(struct led_classdev *led_cdev, enum led_brightness value)
580 +{
581 +       if (value) {
582 +               latch_value &= ~(1 << FSG_LED_RING_BIT);
583 +               *latch_address = latch_value;
584 +       }
585 +       else {
586 +               latch_value |=  (1 << FSG_LED_RING_BIT);
587 +               *latch_address = latch_value;
588 +       }
589 +}
590 +
591 +
592 +
593 +static struct led_classdev fsg_wlan_led = {
594 +       .name                   = "fsg:wlan",
595 +       .brightness_set         = fsg_led_wlan_set,
596 +};
597 +
598 +static struct led_classdev fsg_wan_led = {
599 +       .name                   = "fsg:wan",
600 +       .brightness_set         = fsg_led_wan_set,
601 +};
602 +
603 +static struct led_classdev fsg_sata_led = {
604 +       .name                   = "fsg:sata",
605 +       .brightness_set         = fsg_led_sata_set,
606 +};
607 +
608 +static struct led_classdev fsg_usb_led = {
609 +       .name                   = "fsg:usb",
610 +       .brightness_set         = fsg_led_usb_set,
611 +};
612 +
613 +static struct led_classdev fsg_sync_led = {
614 +       .name                   = "fsg:sync",
615 +       .brightness_set         = fsg_led_sync_set,
616 +};
617 +
618 +static struct led_classdev fsg_ring_led = {
619 +       .name                   = "fsg:ring",
620 +       .brightness_set         = fsg_led_ring_set,
621 +};
622 +
623 +
624 +
625 +#ifdef CONFIG_PM
626 +static int fsg_led_suspend(struct platform_device *dev, pm_message_t state)
627 +{
628 +       led_classdev_suspend(&fsg_wlan_led);
629 +       led_classdev_suspend(&fsg_wan_led);
630 +       led_classdev_suspend(&fsg_sata_led);
631 +       led_classdev_suspend(&fsg_usb_led);
632 +       led_classdev_suspend(&fsg_sync_led);
633 +       led_classdev_suspend(&fsg_ring_led);
634 +       return 0;
635 +}
636 +
637 +static int fsg_led_resume(struct platform_device *dev)
638 +{
639 +       led_classdev_resume(&fsg_wlan_led);
640 +       led_classdev_resume(&fsg_wan_led);
641 +       led_classdev_resume(&fsg_sata_led);
642 +       led_classdev_resume(&fsg_usb_led);
643 +       led_classdev_resume(&fsg_sync_led);
644 +       led_classdev_resume(&fsg_ring_led);
645 +       return 0;
646 +}
647 +#endif
648 +
649 +
650 +static int fsg_led_probe(struct platform_device *pdev)
651 +{
652 +       int ret;
653 +
654 +       /* FIXME: Need to work out how to handle failure below */
655 +
656 +       ret = led_classdev_register(&pdev->dev, &fsg_wlan_led);
657 +       if (ret < 0)
658 +               return ret;
659 +
660 +       ret = led_classdev_register(&pdev->dev, &fsg_wan_led);
661 +       if (ret < 0)
662 +               return ret;
663 +
664 +       ret = led_classdev_register(&pdev->dev, &fsg_sata_led);
665 +       if (ret < 0)
666 +               return ret;
667 +
668 +       ret = led_classdev_register(&pdev->dev, &fsg_usb_led);
669 +       if (ret < 0)
670 +               return ret;
671 +
672 +       ret = led_classdev_register(&pdev->dev, &fsg_sync_led);
673 +       if (ret < 0)
674 +               return ret;
675 +
676 +       ret = led_classdev_register(&pdev->dev, &fsg_ring_led);
677 +       if (ret < 0)
678 +               return ret;
679 +
680 +       return ret;
681 +}
682 +
683 +static int fsg_led_remove(struct platform_device *pdev)
684 +{
685 +       led_classdev_unregister(&fsg_wlan_led);
686 +       led_classdev_unregister(&fsg_wan_led);
687 +       led_classdev_unregister(&fsg_sata_led);
688 +       led_classdev_unregister(&fsg_usb_led);
689 +       led_classdev_unregister(&fsg_sync_led);
690 +       led_classdev_unregister(&fsg_ring_led);
691 +
692 +       return 0;
693 +}
694 +
695 +
696 +static struct platform_driver fsg_led_driver = {
697 +       .probe          = fsg_led_probe,
698 +       .remove         = fsg_led_remove,
699 +#ifdef CONFIG_PM
700 +       .suspend        = fsg_led_suspend,
701 +       .resume         = fsg_led_resume,
702 +#endif
703 +       .driver         = {
704 +               .name           = "fsg-led",
705 +       },
706 +};
707 +
708 +
709 +static int __init fsg_led_init(void)
710 +{
711 +       /* Map the LED chip select address space */
712 +       latch_address = (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
713 +       if (!latch_address)
714 +               return -ENOMEM;
715 +       latch_value = 0xffff;
716 +       *latch_address = latch_value;
717 +       /* FIXME: We leak memory if the next line fails */
718 +       return platform_driver_register(&fsg_led_driver);
719 +}
720 +
721 +static void __exit fsg_led_exit(void)
722 +{
723 +       platform_driver_unregister(&fsg_led_driver);
724 +       iounmap(latch_address);
725 +}
726 +
727 +
728 +module_init(fsg_led_init);
729 +module_exit(fsg_led_exit);
730 +
731 +MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
732 +MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
733 +MODULE_LICENSE("GPL");