ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / 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 = 0x0;     /* Enable LAN (Disable LCD) */
120         platform_add_devices (lpd7a40x_devs, ARRAY_SIZE (lpd7a40x_devs));
121 }
122
123 static void lh7a40x_ack_cpld_irq (u32 irq)
124 {
125         /* CPLD doesn't have ack capability */
126 }
127
128 static void lh7a40x_mask_cpld_irq (u32 irq)
129 {
130         switch (irq) {
131         case IRQ_LPD7A40X_ETH_INT:
132                 CPLD_INTERRUPTS = CPLD_INTERRUPTS | 0x4;
133                 break;
134         case IRQ_LPD7A400_TS:
135                 CPLD_INTERRUPTS = CPLD_INTERRUPTS | 0x8;
136                 break;
137         }
138 }
139
140 static void lh7a40x_unmask_cpld_irq (u32 irq)
141 {
142         switch (irq) {
143         case IRQ_LPD7A40X_ETH_INT:
144                 CPLD_INTERRUPTS = CPLD_INTERRUPTS & ~ 0x4;
145                 break;
146         case IRQ_LPD7A400_TS:
147                 CPLD_INTERRUPTS = CPLD_INTERRUPTS & ~ 0x8;
148                 break;
149         }
150 }
151
152 static struct irqchip lpd7a40x_cpld_chip = {
153         .ack    = lh7a40x_ack_cpld_irq,
154         .mask   = lh7a40x_mask_cpld_irq,
155         .unmask = lh7a40x_unmask_cpld_irq,
156 };
157
158 #define IRQ_DISPATCH(irq) irq_desc[irq].handle ((irq), &irq_desc[irq], regs)
159
160 static void lpd7a40x_cpld_handler (unsigned int irq, struct irqdesc *desc,
161                                   struct pt_regs *regs)
162 {
163         unsigned int mask = CPLD_INTERRUPTS;
164
165         desc->chip->ack (irq);
166
167         if ((mask & 0x1) == 0)  /* WLAN */
168                 IRQ_DISPATCH (IRQ_LPD7A40X_ETH_INT);
169
170         if ((mask & 0x2) == 0)  /* Touch */
171                 IRQ_DISPATCH (IRQ_LPD7A400_TS);
172
173         desc->chip->unmask (irq); /* Level-triggered need this */
174 }
175
176
177 void __init lh7a40x_init_board_irq (void)
178 {
179         int irq;
180
181                 /* Rev A (v2.8): PF0, PF1, PF2, and PF3 are available IRQs.
182                                  PF7 supports the CPLD.
183                    Rev B (v3.4): PF0, PF1, and PF2 are available IRQs.
184                                  PF3 supports the CPLD.
185                    (Some) LPD7A404 prerelease boards report a version
186                    number of 0x16, but we force an override since the
187                    hardware is of the newer variety.
188                 */
189
190         unsigned char cpld_version = CPLD_REVISION;
191         int pinCPLD = (cpld_version == 0x28) ? 7 : 3;
192
193 #if defined CONFIG_MACH_LPD7A404
194         cpld_version = 0x34;    /* Override, for now */
195 #endif
196
197                 /* First, configure user controlled GPIOF interrupts  */
198
199         GPIO_PFDD       &= ~0x0f; /* PF0-3 are inputs */
200         GPIO_INTTYPE1   &= ~0x0f; /* PF0-3 are level triggered */
201         GPIO_INTTYPE2   &= ~0x0f; /* PF0-3 are active low */
202         barrier ();
203         GPIO_GPIOFINTEN |=  0x0f; /* Enable PF0, PF1, PF2, and PF3 IRQs */
204
205                 /* Then, configure CPLD interrupt */
206
207         CPLD_INTERRUPTS =   0x0c; /* Disable all CPLD interrupts */
208         GPIO_PFDD       &= ~(1 << pinCPLD); /* Make input */
209         GPIO_INTTYPE1   |=  (1 << pinCPLD); /* Edge triggered */
210         GPIO_INTTYPE2   &= ~(1 << pinCPLD); /* Active low */
211         barrier ();
212         GPIO_GPIOFINTEN |=  (1 << pinCPLD); /* Enable */
213
214                 /* Cascade CPLD interrupts */
215
216         for (irq = IRQ_BOARD_START;
217              irq < IRQ_BOARD_START + NR_IRQ_BOARD; ++irq) {
218                 set_irq_chip (irq, &lpd7a40x_cpld_chip);
219                 set_irq_handler (irq, do_edge_IRQ);
220                 set_irq_flags (irq, IRQF_VALID);
221         }
222
223         set_irq_chained_handler ((cpld_version == 0x28)
224                                  ? IRQ_CPLD_V28
225                                  : IRQ_CPLD_V34,
226                                  lpd7a40x_cpld_handler);
227 }
228
229 static struct map_desc lpd7a400_io_desc[] __initdata = {
230         {     IO_VIRT,      IO_PHYS,        IO_SIZE,    MT_DEVICE },
231         /* Mapping added to work around chip select problems */
232         { IOBARRIER_VIRT, IOBARRIER_PHYS, IOBARRIER_SIZE, MT_DEVICE },
233         { CF_VIRT,      CF_PHYS,        CF_SIZE,        MT_DEVICE },
234         /* This mapping is redundant since the smc driver performs another. */
235 /*      { CPLD00_VIRT,  CPLD00_PHYS,    CPLD00_SIZE,    MT_DEVICE }, */
236         { CPLD02_VIRT,  CPLD02_PHYS,    CPLD02_SIZE,    MT_DEVICE },
237         { CPLD06_VIRT,  CPLD06_PHYS,    CPLD06_SIZE,    MT_DEVICE },
238         { CPLD08_VIRT,  CPLD08_PHYS,    CPLD08_SIZE,    MT_DEVICE },
239         { CPLD0C_VIRT,  CPLD0C_PHYS,    CPLD0C_SIZE,    MT_DEVICE },
240         { CPLD0E_VIRT,  CPLD0E_PHYS,    CPLD0E_SIZE,    MT_DEVICE },
241         { CPLD10_VIRT,  CPLD10_PHYS,    CPLD10_SIZE,    MT_DEVICE },
242         { CPLD12_VIRT,  CPLD12_PHYS,    CPLD12_SIZE,    MT_DEVICE },
243         { CPLD14_VIRT,  CPLD14_PHYS,    CPLD14_SIZE,    MT_DEVICE },
244         { CPLD16_VIRT,  CPLD16_PHYS,    CPLD16_SIZE,    MT_DEVICE },
245         { CPLD18_VIRT,  CPLD18_PHYS,    CPLD18_SIZE,    MT_DEVICE },
246         { CPLD1A_VIRT,  CPLD1A_PHYS,    CPLD1A_SIZE,    MT_DEVICE },
247 };
248
249 void __init
250 lpd7a400_map_io(void)
251 {
252         iotable_init (lpd7a400_io_desc, ARRAY_SIZE (lpd7a400_io_desc));
253
254                 /* Fixup (improve) Static Memory Controller settings */
255         SMC_BCR0 = 0x200039af;  /* Boot Flash */
256         SMC_BCR6 = 0x1000fbe0;  /* CPLD */
257         SMC_BCR7 = 0x1000b2c2;  /* Compact Flash */
258 }
259
260 #ifdef CONFIG_MACH_LPD7A400
261
262 extern void lh7a400_init_irq (void);
263
264 MACHINE_START (LPD7A400, "Logic Product Development LPD7A400-10")
265         MAINTAINER ("Marc Singer")
266         BOOT_MEM (0xc0000000, 0x80000000, io_p2v (0x80000000))
267         BOOT_PARAMS (0xc0000100)
268         MAPIO (lpd7a400_map_io)
269         INITIRQ (lh7a400_init_irq)
270         INIT_MACHINE (lpd7a40x_init)
271 MACHINE_END
272
273 #endif
274
275 #ifdef CONFIG_MACH_LPD7A404
276
277 extern void lh7a404_init_irq (void);
278
279 MACHINE_START (LPD7A404, "Logic Product Development LPD7A404-10")
280         MAINTAINER ("Marc Singer")
281         BOOT_MEM (0xc0000000, 0x80000000, io_p2v (0x80000000))
282         BOOT_PARAMS (0xc0000100)
283         MAPIO (lpd7a400_map_io)
284         INITIRQ (lh7a404_init_irq)
285         INIT_MACHINE (lpd7a40x_init)
286 MACHINE_END
287
288 #endif