http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / arch / arm / mach-lh7a40x / arch-lpd7a40x.c
1 /* arch/arm/mach-lh7a40x/arch-lpd7a40x.c
2  *
3  *  Copyright (C) 2004 Logic Product Development
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  version 2 as published by the Free Software Foundation.
8  *
9  */
10
11 #include <linux/tty.h>
12 #include <linux/init.h>
13 #include <linux/device.h>
14
15 #include <asm/hardware.h>
16 #include <asm/setup.h>
17 #include <asm/mach-types.h>
18 #include <asm/mach/arch.h>
19 #include <asm/hardware.h>       /* io_p2v() */
20 #include <asm/irq.h>
21 #include <asm/mach/irq.h>
22 #include <asm/mach/map.h>
23
24 #include <linux/interrupt.h>
25
26 static struct resource smc91x_resources[] = {
27         [0] = {
28                 .start  = CPLD00_PHYS,
29                 .end    = CPLD00_PHYS + CPLD00_SIZE - 1, /* Only needs 16B */
30                 .flags  = IORESOURCE_MEM,
31         },
32
33         [1] = {
34                 .start  = IRQ_LPD7A40X_ETH_INT,
35                 .end    = IRQ_LPD7A40X_ETH_INT,
36                 .flags  = IORESOURCE_IRQ,
37         },
38
39 };
40
41 static struct platform_device smc91x_device = {
42         .name           = "smc91x",
43         .id             = 0,
44         .num_resources  = ARRAY_SIZE(smc91x_resources),
45         .resource       = smc91x_resources,
46 };
47
48 #if 0
49 static struct resource lh7a40x_usbclient_resources[] = {
50         [0] = {
51                 .start  = USB_PHYS,
52                 .end    = (USB_PHYS + 0xFF),
53                 .flags  = IORESOURCE_MEM,
54         },
55         [1] = {
56                 .start  = IRQ_USB,
57                 .end    = IRQ_USB,
58                 .flags  = IORESOURCE_IRQ,
59         },
60 };
61
62 static u64 lh7a40x_usbclient_dma_mask = 0xffffffffUL;
63
64 static struct platform_device lh7a40x_usbclient_device = {
65         .name           = "lh7a40x-udc",
66         .id             = 0,
67         .dev            = {
68                 .dma_mask = &lh7a40x_usbclient_dma_mask,
69                 .coherent_dma_mask = 0xffffffffUL,
70         },
71         .num_resources  = ARRAY_SIZE (lh7a40x_usbclient_resources),
72         .resource       = lh7a40x_usbclient_resources,
73 };
74 #endif
75
76 #if defined (CONFIG_ARCH_LH7A404)
77
78 static struct resource lh7a404_usbhost_resources [] = {
79         [0] = {
80                 .start  = USBH_PHYS,
81                 .end    = (USBH_PHYS + 0xFF),
82                 .flags  = IORESOURCE_MEM,
83         },
84         [1] = {
85                 .start  = IRQ_USHINTR,
86                 .end    = IRQ_USHINTR,
87                 .flags  = IORESOURCE_IRQ,
88         },
89 };
90
91 static u64 lh7a404_usbhost_dma_mask = 0xffffffffUL;
92
93 static struct platform_device lh7a404_usbhost_device = {
94         .name           = "lh7a404-ohci",
95         .id             = 0,
96         .dev            = {
97                 .dma_mask = &lh7a404_usbhost_dma_mask,
98                 .coherent_dma_mask = 0xffffffffUL,
99         },
100         .num_resources  = ARRAY_SIZE (lh7a404_usbhost_resources),
101         .resource       = lh7a404_usbhost_resources,
102 };
103
104 #endif
105
106 static struct platform_device *lpd7a40x_devs[] __initdata = {
107         &smc91x_device,
108 /*      &lh7a40x_usbclient_device, */
109
110 #if defined (CONFIG_ARCH_LH7A404)
111         &lh7a404_usbhost_device,
112 #endif
113 };
114
115 extern void lpd7a400_map_io (void);
116
117 static void __init lpd7a40x_init (void)
118 {
119         CPLD_CONTROL |=     (1<<6); /* Mask USB1 connection IRQ */
120         CPLD_CONTROL &= ~(0
121                           | (1<<1) /* Disable LCD */
122                           | (1<<0) /* Enable WLAN */
123                 );
124
125         platform_add_devices (lpd7a40x_devs, ARRAY_SIZE (lpd7a40x_devs));
126 }
127
128 static void lh7a40x_ack_cpld_irq (u32 irq)
129 {
130         /* CPLD doesn't have ack capability */
131 }
132
133 static void lh7a40x_mask_cpld_irq (u32 irq)
134 {
135         switch (irq) {
136         case IRQ_LPD7A40X_ETH_INT:
137                 CPLD_INTERRUPTS = CPLD_INTERRUPTS | 0x4;
138                 break;
139         case IRQ_LPD7A400_TS:
140                 CPLD_INTERRUPTS = CPLD_INTERRUPTS | 0x8;
141                 break;
142         }
143 }
144
145 static void lh7a40x_unmask_cpld_irq (u32 irq)
146 {
147         switch (irq) {
148         case IRQ_LPD7A40X_ETH_INT:
149                 CPLD_INTERRUPTS = CPLD_INTERRUPTS & ~ 0x4;
150                 break;
151         case IRQ_LPD7A400_TS:
152                 CPLD_INTERRUPTS = CPLD_INTERRUPTS & ~ 0x8;
153                 break;
154         }
155 }
156
157 static struct irqchip lpd7a40x_cpld_chip = {
158         .ack    = lh7a40x_ack_cpld_irq,
159         .mask   = lh7a40x_mask_cpld_irq,
160         .unmask = lh7a40x_unmask_cpld_irq,
161 };
162
163 #define IRQ_DISPATCH(irq) irq_desc[irq].handle ((irq), &irq_desc[irq], regs)
164
165 static void lpd7a40x_cpld_handler (unsigned int irq, struct irqdesc *desc,
166                                   struct pt_regs *regs)
167 {
168         unsigned int mask = CPLD_INTERRUPTS;
169
170         desc->chip->ack (irq);
171
172         if ((mask & 0x1) == 0)  /* WLAN */
173                 IRQ_DISPATCH (IRQ_LPD7A40X_ETH_INT);
174
175         if ((mask & 0x2) == 0)  /* Touch */
176                 IRQ_DISPATCH (IRQ_LPD7A400_TS);
177
178         desc->chip->unmask (irq); /* Level-triggered need this */
179 }
180
181
182 void __init lh7a40x_init_board_irq (void)
183 {
184         int irq;
185
186                 /* Rev A (v2.8): PF0, PF1, PF2, and PF3 are available IRQs.
187                                  PF7 supports the CPLD.
188                    Rev B (v3.4): PF0, PF1, and PF2 are available IRQs.
189                                  PF3 supports the CPLD.
190                    (Some) LPD7A404 prerelease boards report a version
191                    number of 0x16, but we force an override since the
192                    hardware is of the newer variety.
193                 */
194
195         unsigned char cpld_version = CPLD_REVISION;
196         int pinCPLD = (cpld_version == 0x28) ? 7 : 3;
197
198 #if defined CONFIG_MACH_LPD7A404
199         cpld_version = 0x34;    /* Coerce LPD7A404 to RevB */
200 #endif
201
202                 /* First, configure user controlled GPIOF interrupts  */
203
204         GPIO_PFDD       &= ~0x0f; /* PF0-3 are inputs */
205         GPIO_INTTYPE1   &= ~0x0f; /* PF0-3 are level triggered */
206         GPIO_INTTYPE2   &= ~0x0f; /* PF0-3 are active low */
207         barrier ();
208         GPIO_GPIOFINTEN |=  0x0f; /* Enable PF0, PF1, PF2, and PF3 IRQs */
209
210                 /* Then, configure CPLD interrupt */
211
212         CPLD_INTERRUPTS =   0x9c; /* Disable all CPLD interrupts */
213         GPIO_PFDD       &= ~(1 << pinCPLD); /* Make input */
214         GPIO_INTTYPE1   |=  (1 << pinCPLD); /* Edge triggered */
215         GPIO_INTTYPE2   &= ~(1 << pinCPLD); /* Active low */
216         barrier ();
217         GPIO_GPIOFINTEN |=  (1 << pinCPLD); /* Enable */
218
219                 /* Cascade CPLD interrupts */
220
221         for (irq = IRQ_BOARD_START;
222              irq < IRQ_BOARD_START + NR_IRQ_BOARD; ++irq) {
223                 set_irq_chip (irq, &lpd7a40x_cpld_chip);
224                 set_irq_handler (irq, do_edge_IRQ);
225                 set_irq_flags (irq, IRQF_VALID);
226         }
227
228         set_irq_chained_handler ((cpld_version == 0x28)
229                                  ? IRQ_CPLD_V28
230                                  : IRQ_CPLD_V34,
231                                  lpd7a40x_cpld_handler);
232 }
233
234 static struct map_desc lpd7a400_io_desc[] __initdata = {
235         {     IO_VIRT,      IO_PHYS,        IO_SIZE,    MT_DEVICE },
236         /* Mapping added to work around chip select problems */
237         { IOBARRIER_VIRT, IOBARRIER_PHYS, IOBARRIER_SIZE, MT_DEVICE },
238         { CF_VIRT,      CF_PHYS,        CF_SIZE,        MT_DEVICE },
239         /* This mapping is redundant since the smc driver performs another. */
240 /*      { CPLD00_VIRT,  CPLD00_PHYS,    CPLD00_SIZE,    MT_DEVICE }, */
241         { CPLD02_VIRT,  CPLD02_PHYS,    CPLD02_SIZE,    MT_DEVICE },
242         { CPLD06_VIRT,  CPLD06_PHYS,    CPLD06_SIZE,    MT_DEVICE },
243         { CPLD08_VIRT,  CPLD08_PHYS,    CPLD08_SIZE,    MT_DEVICE },
244         { CPLD0C_VIRT,  CPLD0C_PHYS,    CPLD0C_SIZE,    MT_DEVICE },
245         { CPLD0E_VIRT,  CPLD0E_PHYS,    CPLD0E_SIZE,    MT_DEVICE },
246         { CPLD10_VIRT,  CPLD10_PHYS,    CPLD10_SIZE,    MT_DEVICE },
247         { CPLD12_VIRT,  CPLD12_PHYS,    CPLD12_SIZE,    MT_DEVICE },
248         { CPLD14_VIRT,  CPLD14_PHYS,    CPLD14_SIZE,    MT_DEVICE },
249         { CPLD16_VIRT,  CPLD16_PHYS,    CPLD16_SIZE,    MT_DEVICE },
250         { CPLD18_VIRT,  CPLD18_PHYS,    CPLD18_SIZE,    MT_DEVICE },
251         { CPLD1A_VIRT,  CPLD1A_PHYS,    CPLD1A_SIZE,    MT_DEVICE },
252 };
253
254 void __init
255 lpd7a400_map_io(void)
256 {
257         iotable_init (lpd7a400_io_desc, ARRAY_SIZE (lpd7a400_io_desc));
258
259                 /* Fixup (improve) Static Memory Controller settings */
260         SMC_BCR0 = 0x200039af;  /* Boot Flash */
261         SMC_BCR6 = 0x1000fbe0;  /* CPLD */
262         SMC_BCR7 = 0x1000b2c2;  /* Compact Flash */
263 }
264
265 #ifdef CONFIG_MACH_LPD7A400
266
267 extern void lh7a400_init_irq (void);
268 extern void lh7a40x_init_time (void);
269
270 MACHINE_START (LPD7A400, "Logic Product Development LPD7A400-10")
271         MAINTAINER ("Marc Singer")
272         BOOT_MEM (0xc0000000, 0x80000000, io_p2v (0x80000000))
273         BOOT_PARAMS (0xc0000100)
274         MAPIO (lpd7a400_map_io)
275         INITIRQ (lh7a400_init_irq)
276         INITTIME (lh7a40x_init_time)
277         INIT_MACHINE (lpd7a40x_init)
278 MACHINE_END
279
280 #endif
281
282 #ifdef CONFIG_MACH_LPD7A404
283
284 extern void lh7a404_init_irq (void);
285 extern void lh7a40x_init_time (void);
286
287 MACHINE_START (LPD7A404, "Logic Product Development LPD7A404-10")
288         MAINTAINER ("Marc Singer")
289         BOOT_MEM (0xc0000000, 0x80000000, io_p2v (0x80000000))
290         BOOT_PARAMS (0xc0000100)
291         MAPIO (lpd7a400_map_io)
292         INITIRQ (lh7a404_init_irq)
293         INITTIME (lh7a40x_init_time)
294         INIT_MACHINE (lpd7a40x_init)
295 MACHINE_END
296
297 #endif