Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh...
[pandora-kernel.git] / arch / arm / mach-iop32x / n2100.c
1 /*
2  * arch/arm/mach-iop32x/n2100.c
3  *
4  * Board support code for the Thecus N2100 platform.
5  *
6  * Author: Rory Bolt <rorybolt@pacbell.net>
7  * Copyright (C) 2002 Rory Bolt
8  * Copyright 2003 (c) MontaVista, Software, Inc.
9  * Copyright (C) 2004 Intel Corp.
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the
13  * Free Software Foundation; either version 2 of the License, or (at your
14  * option) any later version.
15  */
16
17 #include <linux/mm.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/pm.h>
23 #include <linux/string.h>
24 #include <linux/slab.h>
25 #include <linux/serial_core.h>
26 #include <linux/serial_8250.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/platform_device.h>
29 #include <linux/reboot.h>
30 #include <asm/hardware.h>
31 #include <asm/io.h>
32 #include <asm/irq.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/pci.h>
36 #include <asm/mach/time.h>
37 #include <asm/mach-types.h>
38 #include <asm/page.h>
39 #include <asm/pgtable.h>
40
41 /*
42  * N2100 timer tick configuration.
43  */
44 static void __init n2100_timer_init(void)
45 {
46         /* 33.000 MHz crystal.  */
47         iop3xx_init_time(198000000);
48 }
49
50 static struct sys_timer n2100_timer = {
51         .init           = n2100_timer_init,
52         .offset         = iop3xx_gettimeoffset,
53 };
54
55
56 /*
57  * N2100 I/O.
58  */
59 static struct map_desc n2100_io_desc[] __initdata = {
60         {       /* on-board devices */
61                 .virtual        = N2100_UART,
62                 .pfn            = __phys_to_pfn(N2100_UART),
63                 .length         = 0x00100000,
64                 .type           = MT_DEVICE
65         },
66 };
67
68 void __init n2100_map_io(void)
69 {
70         iop3xx_map_io();
71         iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
72 }
73
74
75 /*
76  * N2100 PCI.
77  */
78 static inline int __init
79 n2100_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
80 {
81         int irq;
82
83         if (PCI_SLOT(dev->devfn) == 1) {
84                 /* RTL8110SB #1 */
85                 irq = IRQ_IOP32X_XINT0;
86         } else if (PCI_SLOT(dev->devfn) == 2) {
87                 /* RTL8110SB #2 */
88                 irq = IRQ_IOP32X_XINT3;
89         } else if (PCI_SLOT(dev->devfn) == 3) {
90                 /* Sil3512 */
91                 irq = IRQ_IOP32X_XINT2;
92         } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
93                 /* VT6212 INTA */
94                 irq = IRQ_IOP32X_XINT1;
95         } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
96                 /* VT6212 INTB */
97                 irq = IRQ_IOP32X_XINT0;
98         } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
99                 /* VT6212 INTC */
100                 irq = IRQ_IOP32X_XINT2;
101         } else if (PCI_SLOT(dev->devfn) == 5) {
102                 /* Mini-PCI slot */
103                 irq = IRQ_IOP32X_XINT3;
104         } else {
105                 printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
106                         "device PCI:%d:%d:%d\n", dev->bus->number,
107                         PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
108                 irq = -1;
109         }
110
111         return irq;
112 }
113
114 static struct hw_pci n2100_pci __initdata = {
115         .swizzle        = pci_std_swizzle,
116         .nr_controllers = 1,
117         .setup          = iop3xx_pci_setup,
118         .preinit        = iop3xx_pci_preinit,
119         .scan           = iop3xx_pci_scan_bus,
120         .map_irq        = n2100_pci_map_irq,
121 };
122
123 /*
124  * Both r8169 chips on the n2100 exhibit PCI parity problems.  Set
125  * the ->broken_parity_status flag for both ports so that the r8169
126  * driver knows it should ignore error interrupts.
127  */
128 static void n2100_fixup_r8169(struct pci_dev *dev)
129 {
130         if (dev->bus->number == 0 &&
131             (dev->devfn == PCI_DEVFN(1, 0) ||
132              dev->devfn == PCI_DEVFN(2, 0)))
133                 dev->broken_parity_status = 1;
134 }
135 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
136
137 static int __init n2100_pci_init(void)
138 {
139         if (machine_is_n2100())
140                 pci_common_init(&n2100_pci);
141
142         return 0;
143 }
144
145 subsys_initcall(n2100_pci_init);
146
147
148 /*
149  * N2100 machine initialisation.
150  */
151 static struct physmap_flash_data n2100_flash_data = {
152         .width          = 2,
153 };
154
155 static struct resource n2100_flash_resource = {
156         .start          = 0xf0000000,
157         .end            = 0xf0ffffff,
158         .flags          = IORESOURCE_MEM,
159 };
160
161 static struct platform_device n2100_flash_device = {
162         .name           = "physmap-flash",
163         .id             = 0,
164         .dev            = {
165                 .platform_data  = &n2100_flash_data,
166         },
167         .num_resources  = 1,
168         .resource       = &n2100_flash_resource,
169 };
170
171
172 static struct plat_serial8250_port n2100_serial_port[] = {
173         {
174                 .mapbase        = N2100_UART,
175                 .membase        = (char *)N2100_UART,
176                 .irq            = 0,
177                 .flags          = UPF_SKIP_TEST,
178                 .iotype         = UPIO_MEM,
179                 .regshift       = 0,
180                 .uartclk        = 1843200,
181         },
182         { },
183 };
184
185 static struct resource n2100_uart_resource = {
186         .start          = N2100_UART,
187         .end            = N2100_UART + 7,
188         .flags          = IORESOURCE_MEM,
189 };
190
191 static struct platform_device n2100_serial_device = {
192         .name           = "serial8250",
193         .id             = PLAT8250_DEV_PLATFORM,
194         .dev            = {
195                 .platform_data          = n2100_serial_port,
196         },
197         .num_resources  = 1,
198         .resource       = &n2100_uart_resource,
199 };
200
201
202 /*
203  * Pull PCA9532 GPIO #8 low to power off the machine.
204  */
205 static void n2100_power_off(void)
206 {
207         local_irq_disable();
208
209         /* Start condition, I2C address of PCA9532, write transaction.  */
210         *IOP3XX_IDBR0 = 0xc0;
211         *IOP3XX_ICR0 = 0xe9;
212         mdelay(1);
213
214         /* Write address 0x08.  */
215         *IOP3XX_IDBR0 = 0x08;
216         *IOP3XX_ICR0 = 0xe8;
217         mdelay(1);
218
219         /* Write data 0x01, stop condition.  */
220         *IOP3XX_IDBR0 = 0x01;
221         *IOP3XX_ICR0 = 0xea;
222
223         while (1)
224                 ;
225 }
226
227
228 static struct timer_list power_button_poll_timer;
229
230 static void power_button_poll(unsigned long dummy)
231 {
232         if (gpio_line_get(N2100_POWER_BUTTON) == 0) {
233                 ctrl_alt_del();
234                 return;
235         }
236
237         power_button_poll_timer.expires = jiffies + (HZ / 10);
238         add_timer(&power_button_poll_timer);
239 }
240
241
242 static void __init n2100_init_machine(void)
243 {
244         platform_device_register(&iop3xx_i2c0_device);
245         platform_device_register(&n2100_flash_device);
246         platform_device_register(&n2100_serial_device);
247
248         pm_power_off = n2100_power_off;
249
250         init_timer(&power_button_poll_timer);
251         power_button_poll_timer.function = power_button_poll;
252         power_button_poll_timer.expires = jiffies + (HZ / 10);
253         add_timer(&power_button_poll_timer);
254 }
255
256 MACHINE_START(N2100, "Thecus N2100")
257         /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
258         .phys_io        = N2100_UART,
259         .io_pg_offst    = ((N2100_UART) >> 18) & 0xfffc,
260         .boot_params    = 0xa0000100,
261         .map_io         = n2100_map_io,
262         .init_irq       = iop32x_init_irq,
263         .timer          = &n2100_timer,
264         .init_machine   = n2100_init_machine,
265 MACHINE_END