Merge git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-linus
[linux-2.6] / 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/f75375s.h>
20 #include <linux/leds-pca9532.h>
21 #include <linux/delay.h>
22 #include <linux/kernel.h>
23 #include <linux/pci.h>
24 #include <linux/pm.h>
25 #include <linux/string.h>
26 #include <linux/slab.h>
27 #include <linux/serial_core.h>
28 #include <linux/serial_8250.h>
29 #include <linux/mtd/physmap.h>
30 #include <linux/i2c.h>
31 #include <linux/platform_device.h>
32 #include <linux/reboot.h>
33 #include <linux/io.h>
34 #include <mach/hardware.h>
35 #include <asm/irq.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/map.h>
38 #include <asm/mach/pci.h>
39 #include <asm/mach/time.h>
40 #include <asm/mach-types.h>
41 #include <asm/page.h>
42 #include <asm/pgtable.h>
43 #include <mach/time.h>
44
45 /*
46  * N2100 timer tick configuration.
47  */
48 static void __init n2100_timer_init(void)
49 {
50         /* 33.000 MHz crystal.  */
51         iop_init_time(198000000);
52 }
53
54 static struct sys_timer n2100_timer = {
55         .init           = n2100_timer_init,
56         .offset         = iop_gettimeoffset,
57 };
58
59
60 /*
61  * N2100 I/O.
62  */
63 static struct map_desc n2100_io_desc[] __initdata = {
64         {       /* on-board devices */
65                 .virtual        = N2100_UART,
66                 .pfn            = __phys_to_pfn(N2100_UART),
67                 .length         = 0x00100000,
68                 .type           = MT_DEVICE
69         },
70 };
71
72 void __init n2100_map_io(void)
73 {
74         iop3xx_map_io();
75         iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
76 }
77
78
79 /*
80  * N2100 PCI.
81  */
82 static int __init
83 n2100_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
84 {
85         int irq;
86
87         if (PCI_SLOT(dev->devfn) == 1) {
88                 /* RTL8110SB #1 */
89                 irq = IRQ_IOP32X_XINT0;
90         } else if (PCI_SLOT(dev->devfn) == 2) {
91                 /* RTL8110SB #2 */
92                 irq = IRQ_IOP32X_XINT3;
93         } else if (PCI_SLOT(dev->devfn) == 3) {
94                 /* Sil3512 */
95                 irq = IRQ_IOP32X_XINT2;
96         } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
97                 /* VT6212 INTA */
98                 irq = IRQ_IOP32X_XINT1;
99         } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
100                 /* VT6212 INTB */
101                 irq = IRQ_IOP32X_XINT0;
102         } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
103                 /* VT6212 INTC */
104                 irq = IRQ_IOP32X_XINT2;
105         } else if (PCI_SLOT(dev->devfn) == 5) {
106                 /* Mini-PCI slot */
107                 irq = IRQ_IOP32X_XINT3;
108         } else {
109                 printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
110                         "device PCI:%d:%d:%d\n", dev->bus->number,
111                         PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
112                 irq = -1;
113         }
114
115         return irq;
116 }
117
118 static struct hw_pci n2100_pci __initdata = {
119         .swizzle        = pci_std_swizzle,
120         .nr_controllers = 1,
121         .setup          = iop3xx_pci_setup,
122         .preinit        = iop3xx_pci_preinit,
123         .scan           = iop3xx_pci_scan_bus,
124         .map_irq        = n2100_pci_map_irq,
125 };
126
127 /*
128  * Both r8169 chips on the n2100 exhibit PCI parity problems.  Set
129  * the ->broken_parity_status flag for both ports so that the r8169
130  * driver knows it should ignore error interrupts.
131  */
132 static void n2100_fixup_r8169(struct pci_dev *dev)
133 {
134         if (dev->bus->number == 0 &&
135             (dev->devfn == PCI_DEVFN(1, 0) ||
136              dev->devfn == PCI_DEVFN(2, 0)))
137                 dev->broken_parity_status = 1;
138 }
139 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
140
141 static int __init n2100_pci_init(void)
142 {
143         if (machine_is_n2100())
144                 pci_common_init(&n2100_pci);
145
146         return 0;
147 }
148
149 subsys_initcall(n2100_pci_init);
150
151
152 /*
153  * N2100 machine initialisation.
154  */
155 static struct physmap_flash_data n2100_flash_data = {
156         .width          = 2,
157 };
158
159 static struct resource n2100_flash_resource = {
160         .start          = 0xf0000000,
161         .end            = 0xf0ffffff,
162         .flags          = IORESOURCE_MEM,
163 };
164
165 static struct platform_device n2100_flash_device = {
166         .name           = "physmap-flash",
167         .id             = 0,
168         .dev            = {
169                 .platform_data  = &n2100_flash_data,
170         },
171         .num_resources  = 1,
172         .resource       = &n2100_flash_resource,
173 };
174
175
176 static struct plat_serial8250_port n2100_serial_port[] = {
177         {
178                 .mapbase        = N2100_UART,
179                 .membase        = (char *)N2100_UART,
180                 .irq            = 0,
181                 .flags          = UPF_SKIP_TEST,
182                 .iotype         = UPIO_MEM,
183                 .regshift       = 0,
184                 .uartclk        = 1843200,
185         },
186         { },
187 };
188
189 static struct resource n2100_uart_resource = {
190         .start          = N2100_UART,
191         .end            = N2100_UART + 7,
192         .flags          = IORESOURCE_MEM,
193 };
194
195 static struct platform_device n2100_serial_device = {
196         .name           = "serial8250",
197         .id             = PLAT8250_DEV_PLATFORM,
198         .dev            = {
199                 .platform_data          = n2100_serial_port,
200         },
201         .num_resources  = 1,
202         .resource       = &n2100_uart_resource,
203 };
204
205 static struct f75375s_platform_data n2100_f75375s = {
206         .pwm            = { 255, 255 },
207         .pwm_enable = { 0, 0 },
208 };
209
210 static struct pca9532_platform_data n2100_leds = {
211         .leds = {
212         {       .name = "n2100:red:satafail0",
213                 .state = PCA9532_OFF,
214                 .type = PCA9532_TYPE_LED,
215         },
216         {       .name = "n2100:red:satafail1",
217                 .state = PCA9532_OFF,
218                 .type = PCA9532_TYPE_LED,
219         },
220         {       .name = "n2100:blue:usb",
221                 .state = PCA9532_OFF,
222                 .type = PCA9532_TYPE_LED,
223         },
224         {       .type = PCA9532_TYPE_NONE },
225
226         {       .type = PCA9532_TYPE_NONE },
227         {       .type = PCA9532_TYPE_NONE },
228         {       .type = PCA9532_TYPE_NONE },
229         {       .name = "n2100:red:usb",
230                 .state = PCA9532_OFF,
231                 .type = PCA9532_TYPE_LED,
232         },
233
234         {       .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
235         {       .type = PCA9532_TYPE_NONE }, /* reset gpio */
236         {       .type = PCA9532_TYPE_NONE },
237         {       .type = PCA9532_TYPE_NONE },
238
239         {       .type = PCA9532_TYPE_NONE },
240         {       .name = "n2100:orange:system",
241                 .state = PCA9532_OFF,
242                 .type = PCA9532_TYPE_LED,
243         },
244         {       .name = "n2100:red:system",
245                 .state = PCA9532_OFF,
246                 .type = PCA9532_TYPE_LED,
247         },
248         {       .name = "N2100 beeper"  ,
249                 .state =  PCA9532_OFF,
250                 .type = PCA9532_TYPE_N2100_BEEP,
251         },
252         },
253         .psc = { 0, 0 },
254         .pwm = { 0, 0 },
255 };
256
257 static struct i2c_board_info __initdata n2100_i2c_devices[] = {
258         {
259                 I2C_BOARD_INFO("rs5c372b", 0x32),
260         },
261         {
262                 I2C_BOARD_INFO("f75375", 0x2e),
263                 .platform_data = &n2100_f75375s,
264         },
265         {
266                 I2C_BOARD_INFO("pca9532", 0x60),
267                 .platform_data = &n2100_leds,
268         },
269 };
270
271 /*
272  * Pull PCA9532 GPIO #8 low to power off the machine.
273  */
274 static void n2100_power_off(void)
275 {
276         local_irq_disable();
277
278         /* Start condition, I2C address of PCA9532, write transaction.  */
279         *IOP3XX_IDBR0 = 0xc0;
280         *IOP3XX_ICR0 = 0xe9;
281         mdelay(1);
282
283         /* Write address 0x08.  */
284         *IOP3XX_IDBR0 = 0x08;
285         *IOP3XX_ICR0 = 0xe8;
286         mdelay(1);
287
288         /* Write data 0x01, stop condition.  */
289         *IOP3XX_IDBR0 = 0x01;
290         *IOP3XX_ICR0 = 0xea;
291
292         while (1)
293                 ;
294 }
295
296
297 static struct timer_list power_button_poll_timer;
298
299 static void power_button_poll(unsigned long dummy)
300 {
301         if (gpio_line_get(N2100_POWER_BUTTON) == 0) {
302                 ctrl_alt_del();
303                 return;
304         }
305
306         power_button_poll_timer.expires = jiffies + (HZ / 10);
307         add_timer(&power_button_poll_timer);
308 }
309
310
311 static void __init n2100_init_machine(void)
312 {
313         platform_device_register(&iop3xx_i2c0_device);
314         platform_device_register(&n2100_flash_device);
315         platform_device_register(&n2100_serial_device);
316         platform_device_register(&iop3xx_dma_0_channel);
317         platform_device_register(&iop3xx_dma_1_channel);
318
319         i2c_register_board_info(0, n2100_i2c_devices,
320                 ARRAY_SIZE(n2100_i2c_devices));
321
322         pm_power_off = n2100_power_off;
323
324         init_timer(&power_button_poll_timer);
325         power_button_poll_timer.function = power_button_poll;
326         power_button_poll_timer.expires = jiffies + (HZ / 10);
327         add_timer(&power_button_poll_timer);
328 }
329
330 MACHINE_START(N2100, "Thecus N2100")
331         /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
332         .phys_io        = N2100_UART,
333         .io_pg_offst    = ((N2100_UART) >> 18) & 0xfffc,
334         .boot_params    = 0xa0000100,
335         .map_io         = n2100_map_io,
336         .init_irq       = iop32x_init_irq,
337         .timer          = &n2100_timer,
338         .init_machine   = n2100_init_machine,
339 MACHINE_END