Merge branch 'for-linus' of git://git.linaro.org/people/rmk/linux-arm
[pandora-kernel.git] / arch / arm / mach-ixp2000 / enp2611.c
1 /*
2  * arch/arm/mach-ixp2000/enp2611.c
3  *
4  * Radisys ENP-2611 support.
5  *
6  * Created 2004 by Lennert Buytenhek from the ixdp2x01 code.  The
7  * original version carries the following notices:
8  *
9  * Original Author: Andrzej Mialkowski <andrzej.mialkowski@intel.com>
10  * Maintainer: Deepak Saxena <dsaxena@plexity.net>
11  *
12  * Copyright (C) 2002-2003 Intel Corp.
13  * Copyright (C) 2003-2004 MontaVista Software, Inc.
14  *
15  *  This program is free software; you can redistribute  it and/or modify it
16  *  under  the terms of  the GNU General  Public License as published by the
17  *  Free Software Foundation;  either version 2 of the  License, or (at your
18  *  option) any later version.
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/mm.h>
24 #include <linux/sched.h>
25 #include <linux/interrupt.h>
26 #include <linux/bitops.h>
27 #include <linux/pci.h>
28 #include <linux/ioport.h>
29 #include <linux/delay.h>
30 #include <linux/serial.h>
31 #include <linux/tty.h>
32 #include <linux/serial_core.h>
33 #include <linux/platform_device.h>
34 #include <linux/io.h>
35
36 #include <asm/irq.h>
37 #include <asm/pgtable.h>
38 #include <asm/page.h>
39 #include <mach/hardware.h>
40 #include <asm/mach-types.h>
41
42 #include <asm/mach/pci.h>
43 #include <asm/mach/map.h>
44 #include <asm/mach/irq.h>
45 #include <asm/mach/time.h>
46 #include <asm/mach/arch.h>
47 #include <asm/mach/flash.h>
48
49 /*************************************************************************
50  * ENP-2611 timer tick configuration
51  *************************************************************************/
52 static void __init enp2611_timer_init(void)
53 {
54         ixp2000_init_time(50 * 1000 * 1000);
55 }
56
57 static struct sys_timer enp2611_timer = {
58         .init           = enp2611_timer_init,
59         .offset         = ixp2000_gettimeoffset,
60 };
61
62
63 /*************************************************************************
64  * ENP-2611 I/O
65  *************************************************************************/
66 static struct map_desc enp2611_io_desc[] __initdata = {
67         {
68                 .virtual        = ENP2611_CALEB_VIRT_BASE,
69                 .pfn            = __phys_to_pfn(ENP2611_CALEB_PHYS_BASE),
70                 .length         = ENP2611_CALEB_SIZE,
71                 .type           = MT_DEVICE,
72         }, {
73                 .virtual        = ENP2611_PM3386_0_VIRT_BASE,
74                 .pfn            = __phys_to_pfn(ENP2611_PM3386_0_PHYS_BASE),
75                 .length         = ENP2611_PM3386_0_SIZE,
76                 .type           = MT_DEVICE,
77         }, {
78                 .virtual        = ENP2611_PM3386_1_VIRT_BASE,
79                 .pfn            = __phys_to_pfn(ENP2611_PM3386_1_PHYS_BASE),
80                 .length         = ENP2611_PM3386_1_SIZE,
81                 .type           = MT_DEVICE,
82         }
83 };
84
85 void __init enp2611_map_io(void)
86 {
87         ixp2000_map_io();
88         iotable_init(enp2611_io_desc, ARRAY_SIZE(enp2611_io_desc));
89 }
90
91
92 /*************************************************************************
93  * ENP-2611 PCI
94  *************************************************************************/
95 static int enp2611_pci_setup(int nr, struct pci_sys_data *sys)
96 {
97         sys->mem_offset = 0xe0000000;
98         ixp2000_pci_setup(nr, sys);
99         return 1;
100 }
101
102 static void __init enp2611_pci_preinit(void)
103 {
104         ixp2000_reg_write(IXP2000_PCI_ADDR_EXT, 0x00100000);
105         ixp2000_pci_preinit();
106         pcibios_setup("firmware");
107 }
108
109 static inline int enp2611_pci_valid_device(struct pci_bus *bus,
110                                                 unsigned int devfn)
111 {
112         /* The 82559 ethernet controller appears at both PCI:1:0:0 and
113          * PCI:1:2:0, so let's pretend the second one isn't there.
114          */
115         if (bus->number == 0x01 && devfn == 0x10)
116                 return 0;
117
118         return 1;
119 }
120
121 static int enp2611_pci_read_config(struct pci_bus *bus, unsigned int devfn,
122                                         int where, int size, u32 *value)
123 {
124         if (enp2611_pci_valid_device(bus, devfn))
125                 return ixp2000_pci_read_config(bus, devfn, where, size, value);
126
127         return PCIBIOS_DEVICE_NOT_FOUND;
128 }
129
130 static int enp2611_pci_write_config(struct pci_bus *bus, unsigned int devfn,
131                                         int where, int size, u32 value)
132 {
133         if (enp2611_pci_valid_device(bus, devfn))
134                 return ixp2000_pci_write_config(bus, devfn, where, size, value);
135
136         return PCIBIOS_DEVICE_NOT_FOUND;
137 }
138
139 static struct pci_ops enp2611_pci_ops = {
140         .read   = enp2611_pci_read_config,
141         .write  = enp2611_pci_write_config
142 };
143
144 static int __init enp2611_pci_map_irq(const struct pci_dev *dev, u8 slot,
145         u8 pin)
146 {
147         int irq;
148
149         if (dev->bus->number == 0 && PCI_SLOT(dev->devfn) == 0) {
150                 /* IXP2400. */
151                 irq = IRQ_IXP2000_PCIA;
152         } else if (dev->bus->number == 0 && PCI_SLOT(dev->devfn) == 1) {
153                 /* 21555 non-transparent bridge.  */
154                 irq = IRQ_IXP2000_PCIB;
155         } else if (dev->bus->number == 0 && PCI_SLOT(dev->devfn) == 4) {
156                 /* PCI2050B transparent bridge.  */
157                 irq = -1;
158         } else if (dev->bus->number == 1 && PCI_SLOT(dev->devfn) == 0) {
159                 /* 82559 ethernet.  */
160                 irq = IRQ_IXP2000_PCIA;
161         } else if (dev->bus->number == 1 && PCI_SLOT(dev->devfn) == 1) {
162                 /* SPI-3 option board.  */
163                 irq = IRQ_IXP2000_PCIB;
164         } else {
165                 printk(KERN_ERR "enp2611_pci_map_irq() called for unknown "
166                                 "device PCI:%d:%d:%d\n", dev->bus->number,
167                                 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
168                 irq = -1;
169         }
170
171         return irq;
172 }
173
174 struct hw_pci enp2611_pci __initdata = {
175         .nr_controllers = 1,
176         .ops            = &enp2611_pci_ops,
177         .setup          = enp2611_pci_setup,
178         .preinit        = enp2611_pci_preinit,
179         .map_irq        = enp2611_pci_map_irq,
180 };
181
182 int __init enp2611_pci_init(void)
183 {
184         if (machine_is_enp2611())
185                 pci_common_init(&enp2611_pci);
186
187         return 0;
188 }
189
190 subsys_initcall(enp2611_pci_init);
191
192
193 /*************************************************************************
194  * ENP-2611 Machine Initialization
195  *************************************************************************/
196 static struct flash_platform_data enp2611_flash_platform_data = {
197         .map_name       = "cfi_probe",
198         .width          = 1,
199 };
200
201 static struct ixp2000_flash_data enp2611_flash_data = {
202         .platform_data  = &enp2611_flash_platform_data,
203         .nr_banks       = 1
204 };
205
206 static struct resource enp2611_flash_resource = {
207         .start          = 0xc4000000,
208         .end            = 0xc4000000 + 0x00ffffff,
209         .flags          = IORESOURCE_MEM,
210 };
211
212 static struct platform_device enp2611_flash = {
213         .name           = "IXP2000-Flash",
214         .id             = 0,
215         .dev            = {
216                 .platform_data = &enp2611_flash_data,
217         },
218         .num_resources  = 1,
219         .resource       = &enp2611_flash_resource,
220 };
221
222 static struct ixp2000_i2c_pins enp2611_i2c_gpio_pins = {
223         .sda_pin        = ENP2611_GPIO_SDA,
224         .scl_pin        = ENP2611_GPIO_SCL,
225 };
226
227 static struct platform_device enp2611_i2c_controller = {
228         .name           = "IXP2000-I2C",
229         .id             = 0,
230         .dev            = {
231                 .platform_data = &enp2611_i2c_gpio_pins
232         },
233         .num_resources  = 0
234 };
235
236 static struct platform_device *enp2611_devices[] __initdata = {
237         &enp2611_flash,
238         &enp2611_i2c_controller
239 };
240
241 static void __init enp2611_init_machine(void)
242 {
243         platform_add_devices(enp2611_devices, ARRAY_SIZE(enp2611_devices));
244         ixp2000_uart_init();
245 }
246
247
248 MACHINE_START(ENP2611, "Radisys ENP-2611 PCI network processor board")
249         /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
250         .atag_offset    = 0x100,
251         .map_io         = enp2611_map_io,
252         .init_irq       = ixp2000_init_irq,
253         .timer          = &enp2611_timer,
254         .init_machine   = enp2611_init_machine,
255         .restart        = ixp2000_restart,
256 MACHINE_END
257
258