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