This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / arm / mach-ixp2000 / ixdp2x01.c
1 /*
2  * arch/arm/mach-ixp2000/ixdp2x01.c
3  *
4  * Code common to Intel IXDP2401 and IXDP2801 platforms
5  *
6  * Original Author: Andrzej Mialwoski <andrzej.mialwoski@intel.com>
7  * Maintainer: Deepak Saxena <dsaxena@plexity.net>
8  *
9  * Copyright (C) 2002-2003 Intel Corp.
10  * Copyright (C) 2003-2004 MontaVista Software, Inc.
11  *
12  *  This program is free software; you can redistribute  it and/or modify it
13  *  under  the terms of  the GNU General  Public License as published by the
14  *  Free Software Foundation;  either version 2 of the  License, or (at your
15  *  option) any later version.
16  */
17
18 #include <linux/config.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/mm.h>
22 #include <linux/sched.h>
23 #include <linux/interrupt.h>
24 #include <linux/bitops.h>
25 #include <linux/pci.h>
26 #include <linux/interrupt.h>
27 #include <linux/mm.h>
28 #include <linux/init.h>
29 #include <linux/ioport.h>
30 #include <linux/slab.h>
31 #include <linux/delay.h>
32 #include <linux/serial.h>
33 #include <linux/tty.h>
34 #include <linux/serial_core.h>
35 #include <linux/device.h>
36
37 #include <asm/io.h>
38 #include <asm/irq.h>
39 #include <asm/pgtable.h>
40 #include <asm/page.h>
41 #include <asm/system.h>
42 #include <asm/hardware.h>
43 #include <asm/mach-types.h>
44
45 #include <asm/mach/pci.h>
46 #include <asm/mach/map.h>
47 #include <asm/mach/irq.h>
48 #include <asm/mach/time.h>
49 #include <asm/mach/arch.h>
50 #include <asm/mach/flash.h>
51
52 /*************************************************************************
53  * IXDP2x01 IRQ Handling
54  *************************************************************************/
55 static void ixdp2x01_irq_mask(unsigned int irq)
56 {
57         *IXDP2X01_INT_MASK_SET_REG = IXP2000_BOARD_IRQ_MASK(irq);
58 }
59
60 static void ixdp2x01_irq_unmask(unsigned int irq)
61 {
62         *IXDP2X01_INT_MASK_CLR_REG = IXP2000_BOARD_IRQ_MASK(irq);
63 }
64
65 static u32 valid_irq_mask;
66
67 static void ixdp2x01_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
68 {
69         u32 ex_interrupt;
70         int i;
71
72         desc->chip->mask(irq);
73
74         ex_interrupt = *IXDP2X01_INT_STAT_REG & valid_irq_mask;
75
76         if (!ex_interrupt) {
77                 printk(KERN_ERR "Spurious IXDP2X01 CPLD interrupt!\n");
78                 return;
79         }
80
81         for (i = 0; i < IXP2000_BOARD_IRQS; i++) {
82                 if (ex_interrupt & (1 << i)) {
83                         struct irqdesc *cpld_desc;
84                         int cpld_irq = IXP2000_BOARD_IRQ(0) + i;
85                         cpld_desc = irq_desc + cpld_irq;
86                         cpld_desc->handle(cpld_irq, cpld_desc, regs);
87                 }
88         }
89
90         desc->chip->unmask(irq);
91 }
92
93 static struct irqchip ixdp2x01_irq_chip = {
94         .mask   = ixdp2x01_irq_mask,
95         .ack    = ixdp2x01_irq_mask,
96         .unmask = ixdp2x01_irq_unmask
97 };
98
99 /*
100  * We only do anything if we are the master NPU on the board.
101  * The slave NPU only has the ethernet chip going directly to
102  * the PCIB interrupt input.
103  */
104 void __init ixdp2x01_init_irq(void)
105 {
106         int irq = 0;
107
108         /* initialize chip specific interrupts */
109         ixp2000_init_irq();
110
111         if (machine_is_ixdp2401())
112                 valid_irq_mask = IXDP2401_VALID_IRQ_MASK;
113         else
114                 valid_irq_mask = IXDP2801_VALID_IRQ_MASK;
115
116         /* Mask all interrupts from CPLD, disable simulation */
117         *IXDP2X01_INT_MASK_SET_REG = 0xffffffff;
118         *IXDP2X01_INT_SIM_REG = 0;
119
120         for (irq = NR_IXP2000_IRQS; irq < NR_IXDP2X01_IRQS; irq++) {
121                 if (irq & valid_irq_mask) {
122                         set_irq_chip(irq, &ixdp2x01_irq_chip);
123                         set_irq_handler(irq, do_level_IRQ);
124                         set_irq_flags(irq, IRQF_VALID);
125                 } else {
126                         set_irq_flags(irq, 0);
127                 }
128         }
129
130         /* Hook into PCI interrupts */
131         set_irq_chained_handler(IRQ_IXP2000_PCIB, &ixdp2x01_irq_handler);
132 }
133
134
135 /*************************************************************************
136  * IXDP2x01 memory map and serial ports
137  *************************************************************************/
138 static struct map_desc ixdp2x01_io_desc __initdata = {
139         .virtual        = IXDP2X01_VIRT_CPLD_BASE, 
140         .physical       = IXDP2X01_PHYS_CPLD_BASE,
141         .length         = IXDP2X01_CPLD_REGION_SIZE,
142         .type           = MT_DEVICE
143 };
144
145 static struct uart_port ixdp2x01_serial_ports[2] = {
146         {
147                 .membase        = (char *)(IXDP2X01_UART1_VIRT_BASE),
148                 .mapbase        = (unsigned long)IXDP2X01_UART1_PHYS_BASE,
149                 .irq            = IRQ_IXDP2X01_UART1,
150                 .flags          = UPF_SKIP_TEST,
151                 .iotype         = UPIO_MEM32,
152                 .regshift       = 2,
153                 .uartclk        = IXDP2X01_UART_CLK,
154                 .line           = 1,
155                 .type           = PORT_16550A,
156                 .fifosize       = 16
157         }, {
158                 .membase        = (char *)(IXDP2X01_UART2_VIRT_BASE),
159                 .mapbase        = (unsigned long)IXDP2X01_UART2_PHYS_BASE,
160                 .irq            = IRQ_IXDP2X01_UART2,
161                 .flags          = UPF_SKIP_TEST,
162                 .iotype         = UPIO_MEM32,
163                 .regshift       = 2,
164                 .uartclk        = IXDP2X01_UART_CLK,
165                 .line           = 2,
166                 .type           = PORT_16550A,
167                 .fifosize       = 16
168         }, 
169 };
170
171 static void __init ixdp2x01_map_io(void)
172 {
173         ixp2000_map_io();       
174
175         iotable_init(&ixdp2x01_io_desc, 1);
176
177         early_serial_setup(&ixdp2x01_serial_ports[0]);
178         early_serial_setup(&ixdp2x01_serial_ports[1]);
179 }
180
181
182 /*************************************************************************
183  * IXDP2x01 timer tick configuration
184  *************************************************************************/
185 static unsigned int ixdp2x01_clock;
186
187 static int __init ixdp2x01_clock_setup(char *str)
188 {
189         ixdp2x01_clock = simple_strtoul(str, NULL, 10);
190
191         return 1;
192 }
193
194 __setup("ixdp2x01_clock=", ixdp2x01_clock_setup);
195
196 static void __init ixdp2x01_init_time(void)
197 {
198         if (!ixdp2x01_clock)
199                 ixdp2x01_clock = 50000000;
200
201         ixp2000_init_time(ixdp2x01_clock);
202 }
203
204 /*************************************************************************
205  * IXDP2x01 PCI
206  *************************************************************************/
207 void __init ixdp2x01_pci_preinit(void)
208 {
209         ixp2000_reg_write(IXP2000_PCI_ADDR_EXT, 0x00000000);
210         ixp2000_pci_preinit();
211 }
212
213 #define DEVPIN(dev, pin) ((pin) | ((dev) << 3))
214
215 static int __init ixdp2x01_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
216 {
217         u8 bus = dev->bus->number;
218         u32 devpin = DEVPIN(PCI_SLOT(dev->devfn), pin);
219         struct pci_bus *tmp_bus = dev->bus;
220
221         /* Primary bus, no interrupts here */
222         if (bus == 0) {
223                 return -1;
224         }
225
226         /* Lookup first leaf in bus tree */
227         while ((tmp_bus->parent != NULL) && (tmp_bus->parent->parent != NULL)) {
228                 tmp_bus = tmp_bus->parent;
229         }
230
231         /* Select between known bridges */
232         switch (tmp_bus->self->devfn | (tmp_bus->self->bus->number << 8)) {
233         /* Device is located after first MB bridge */
234         case 0x0008:
235                 if (tmp_bus == dev->bus) {
236                         /* Device is located directy after first MB bridge */
237                         switch (devpin) {
238                         case DEVPIN(1, 1):      /* Onboard 82546 ch 0 */
239                                 if (machine_is_ixdp2401())
240                                         return IRQ_IXDP2401_INTA_82546;
241                                 return -1;
242                         case DEVPIN(1, 2):      /* Onboard 82546 ch 1 */
243                                 if (machine_is_ixdp2401())
244                                         return IRQ_IXDP2401_INTB_82546;
245                                 return -1;
246                         case DEVPIN(0, 1):      /* PMC INTA# */
247                                 return IRQ_IXDP2X01_SPCI_PMC_INTA;
248                         case DEVPIN(0, 2):      /* PMC INTB# */
249                                 return IRQ_IXDP2X01_SPCI_PMC_INTB;
250                         case DEVPIN(0, 3):      /* PMC INTC# */
251                                 return IRQ_IXDP2X01_SPCI_PMC_INTC;
252                         case DEVPIN(0, 4):      /* PMC INTD# */
253                                 return IRQ_IXDP2X01_SPCI_PMC_INTD;
254                         }
255                 }
256                 break;
257         case 0x0010:
258                 if (tmp_bus == dev->bus) {
259                         /* Device is located directy after second MB bridge */
260                         /* Secondary bus of second bridge */
261                         switch (devpin) {
262                         case DEVPIN(0, 1):      /* DB#0 */
263                                 return IRQ_IXDP2X01_SPCI_DB_0;
264                         case DEVPIN(1, 1):      /* DB#1 */
265                                 return IRQ_IXDP2X01_SPCI_DB_1;
266                         }
267                 } else {
268                         /* Device is located indirectly after second MB bridge */
269                         /* Not supported now */
270                 }
271                 break;
272         }
273
274         return -1;
275 }
276
277
278 static int ixdp2x01_pci_setup(int nr, struct pci_sys_data *sys)
279 {
280         sys->mem_offset = 0xe0000000;
281
282         if (machine_is_ixdp2801())
283                 sys->mem_offset -= ((*IXP2000_PCI_ADDR_EXT & 0xE000) << 16);
284
285         return ixp2000_pci_setup(nr, sys);
286 }
287
288 struct hw_pci ixdp2x01_pci __initdata = {
289         .nr_controllers = 1,
290         .setup          = ixdp2x01_pci_setup,
291         .preinit        = ixdp2x01_pci_preinit,
292         .scan           = ixp2000_pci_scan_bus,
293         .map_irq        = ixdp2x01_pci_map_irq,
294 };
295
296 int __init ixdp2x01_pci_init(void)
297 {
298
299         pci_common_init(&ixdp2x01_pci);
300         return 0;
301 }
302
303 subsys_initcall(ixdp2x01_pci_init);
304
305 /*************************************************************************
306  * IXDP2x01 Machine Intialization
307  *************************************************************************/
308 static struct flash_platform_data ixdp2x01_flash_platform_data = {
309         .map_name       = "cfi_probe",
310         .width          = 1,
311 };
312
313 static unsigned long ixdp2x01_flash_bank_setup(unsigned long ofs)
314 {
315         *IXDP2X01_CPLD_FLASH_REG = 
316                 ((ofs >> IXDP2X01_FLASH_WINDOW_BITS) | IXDP2X01_CPLD_FLASH_INTERN);
317         return (ofs & IXDP2X01_FLASH_WINDOW_MASK);
318 }
319
320 static struct ixp2000_flash_data ixdp2x01_flash_data = {
321         .platform_data  = &ixdp2x01_flash_platform_data,
322         .bank_setup     = ixdp2x01_flash_bank_setup
323 };
324
325 static struct resource ixdp2x01_flash_resource = {
326         .start          = 0xc4000000,
327         .end            = 0xc4000000 + 0x01ffffff,
328         .flags          = IORESOURCE_MEM,
329 };
330
331 static struct platform_device ixdp2x01_flash = {
332         .name           = "IXP2000-Flash",
333         .id             = 0,
334         .dev            = {
335                 .platform_data = &ixdp2x01_flash_data,
336         },
337         .num_resources  = 1,
338         .resource       = &ixdp2x01_flash_resource,
339 };
340
341 static struct platform_device *ixdp2x01_devices[] __initdata = {
342         &ixdp2x01_flash
343 };
344
345 static void __init ixdp2x01_init_machine(void)
346 {
347         *IXDP2X01_CPLD_FLASH_REG = 
348                 (IXDP2X01_CPLD_FLASH_BANK_MASK | IXDP2X01_CPLD_FLASH_INTERN);
349         
350         ixdp2x01_flash_data.nr_banks =
351                 ((*IXDP2X01_CPLD_FLASH_REG & IXDP2X01_CPLD_FLASH_BANK_MASK) + 1);
352
353         platform_add_devices(ixdp2x01_devices, ARRAY_SIZE(ixdp2x01_devices));
354 }
355
356
357 #ifdef CONFIG_ARCH_IXDP2401
358 MACHINE_START(IXDP2401, "Intel IXDP2401 Development Platform")
359         MAINTAINER("MontaVista Software, Inc.")
360         BOOT_MEM(0x00000000, IXP2000_UART_PHYS_BASE, IXP2000_UART_VIRT_BASE)
361         BOOT_PARAMS(0x00000100)
362         MAPIO(ixdp2x01_map_io)
363         INITIRQ(ixdp2x01_init_irq)
364         INITTIME(ixdp2x01_init_time)
365         INIT_MACHINE(ixdp2x01_init_machine)
366 MACHINE_END
367 #endif
368
369 #ifdef CONFIG_ARCH_IXDP2801
370 MACHINE_START(IXDP2801, "Intel IXDP2801 Development Platform")
371         MAINTAINER("MontaVista Software, Inc.")
372         BOOT_MEM(0x00000000, IXP2000_UART_PHYS_BASE, IXP2000_UART_VIRT_BASE)
373         BOOT_PARAMS(0x00000100)
374         MAPIO(ixdp2x01_map_io)
375         INITIRQ(ixdp2x01_init_irq)
376         INITTIME(ixdp2x01_init_time)
377         INIT_MACHINE(ixdp2x01_init_machine)
378 MACHINE_END
379 #endif
380
381