blob: b3a57e0f3419dca561be776f112a39316129a90d [file] [log] [blame]
Lennert Buytenhekc4713072006-03-28 21:18:54 +01001/*
2 * arch/arm/mach-ixp23xx/ixdp2351.c
3 *
4 * IXDP2351 board-specific routines
5 *
6 * Author: Deepak Saxena <dsaxena@plexity.net>
7 *
8 * Copyright 2005 (c) MontaVista Software, Inc.
9 *
10 * Based on 2.4 code Copyright 2004 (c) Intel Corporation
11 *
12 * This file is licensed under the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
15 */
16
Lennert Buytenhekc4713072006-03-28 21:18:54 +010017#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/spinlock.h>
20#include <linux/sched.h>
21#include <linux/interrupt.h>
Thomas Gleixnerae71c422006-07-01 22:32:42 +010022#include <linux/irq.h>
Lennert Buytenhekc4713072006-03-28 21:18:54 +010023#include <linux/serial.h>
24#include <linux/tty.h>
25#include <linux/bitops.h>
26#include <linux/ioport.h>
Lennert Buytenhekc4713072006-03-28 21:18:54 +010027#include <linux/serial_8250.h>
28#include <linux/serial_core.h>
29#include <linux/device.h>
30#include <linux/mm.h>
31#include <linux/pci.h>
32#include <linux/mtd/physmap.h>
33
34#include <asm/types.h>
35#include <asm/setup.h>
36#include <asm/memory.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010037#include <mach/hardware.h>
Lennert Buytenhekc4713072006-03-28 21:18:54 +010038#include <asm/mach-types.h>
Lennert Buytenhekc4713072006-03-28 21:18:54 +010039#include <asm/system.h>
40#include <asm/tlbflush.h>
41#include <asm/pgtable.h>
42
43#include <asm/mach/map.h>
44#include <asm/mach/irq.h>
45#include <asm/mach/arch.h>
Lennert Buytenhekc4713072006-03-28 21:18:54 +010046#include <asm/mach/pci.h>
47
48/*
49 * IXDP2351 Interrupt Handling
50 */
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010051static void ixdp2351_inta_mask(struct irq_data *d)
Lennert Buytenhekc4713072006-03-28 21:18:54 +010052{
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010053 *IXDP2351_CPLD_INTA_MASK_SET_REG = IXDP2351_INTA_IRQ_MASK(d->irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010054}
55
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010056static void ixdp2351_inta_unmask(struct irq_data *d)
Lennert Buytenhekc4713072006-03-28 21:18:54 +010057{
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010058 *IXDP2351_CPLD_INTA_MASK_CLR_REG = IXDP2351_INTA_IRQ_MASK(d->irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010059}
60
Russell King10dd5ce2006-11-23 11:41:32 +000061static void ixdp2351_inta_handler(unsigned int irq, struct irq_desc *desc)
Lennert Buytenhekc4713072006-03-28 21:18:54 +010062{
63 u16 ex_interrupt =
64 *IXDP2351_CPLD_INTA_STAT_REG & IXDP2351_INTA_IRQ_VALID;
65 int i;
66
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010067 desc->irq_data.chip->irq_mask(&desc->irq_data);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010068
69 for (i = 0; i < IXDP2351_INTA_IRQ_NUM; i++) {
70 if (ex_interrupt & (1 << i)) {
Lennert Buytenhekc4713072006-03-28 21:18:54 +010071 int cpld_irq =
72 IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE + i);
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +010073 generic_handle_irq(cpld_irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010074 }
75 }
76
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010077 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010078}
79
Russell King10dd5ce2006-11-23 11:41:32 +000080static struct irq_chip ixdp2351_inta_chip = {
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010081 .irq_ack = ixdp2351_inta_mask,
82 .irq_mask = ixdp2351_inta_mask,
83 .irq_unmask = ixdp2351_inta_unmask
Lennert Buytenhekc4713072006-03-28 21:18:54 +010084};
85
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010086static void ixdp2351_intb_mask(struct irq_data *d)
Lennert Buytenhekc4713072006-03-28 21:18:54 +010087{
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010088 *IXDP2351_CPLD_INTB_MASK_SET_REG = IXDP2351_INTB_IRQ_MASK(d->irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010089}
90
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010091static void ixdp2351_intb_unmask(struct irq_data *d)
Lennert Buytenhekc4713072006-03-28 21:18:54 +010092{
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +010093 *IXDP2351_CPLD_INTB_MASK_CLR_REG = IXDP2351_INTB_IRQ_MASK(d->irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +010094}
95
Russell King10dd5ce2006-11-23 11:41:32 +000096static void ixdp2351_intb_handler(unsigned int irq, struct irq_desc *desc)
Lennert Buytenhekc4713072006-03-28 21:18:54 +010097{
98 u16 ex_interrupt =
99 *IXDP2351_CPLD_INTB_STAT_REG & IXDP2351_INTB_IRQ_VALID;
100 int i;
101
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +0100102 desc->irq_data.chip->irq_ack(&desc->irq_data);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100103
104 for (i = 0; i < IXDP2351_INTB_IRQ_NUM; i++) {
105 if (ex_interrupt & (1 << i)) {
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100106 int cpld_irq =
107 IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE + i);
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100108 generic_handle_irq(cpld_irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100109 }
110 }
111
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +0100112 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100113}
114
Russell King10dd5ce2006-11-23 11:41:32 +0000115static struct irq_chip ixdp2351_intb_chip = {
Lennert Buytenhekc1d065e2010-11-29 10:33:32 +0100116 .irq_ack = ixdp2351_intb_mask,
117 .irq_mask = ixdp2351_intb_mask,
118 .irq_unmask = ixdp2351_intb_unmask
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100119};
120
Russell Kingcdea4602007-05-30 17:48:45 +0100121void __init ixdp2351_init_irq(void)
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100122{
123 int irq;
124
125 /* Mask all interrupts from CPLD, disable simulation */
126 *IXDP2351_CPLD_INTA_MASK_SET_REG = (u16) -1;
127 *IXDP2351_CPLD_INTB_MASK_SET_REG = (u16) -1;
128 *IXDP2351_CPLD_INTA_SIM_REG = 0;
129 *IXDP2351_CPLD_INTB_SIM_REG = 0;
130
131 ixp23xx_init_irq();
132
133 for (irq = IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE);
134 irq <
135 IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE + IXDP2351_INTA_IRQ_NUM);
136 irq++) {
137 if (IXDP2351_INTA_IRQ_MASK(irq) & IXDP2351_INTA_IRQ_VALID) {
138 set_irq_flags(irq, IRQF_VALID);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100139 irq_set_chip_and_handler(irq, &ixdp2351_inta_chip,
140 handle_level_irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100141 }
142 }
143
144 for (irq = IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE);
145 irq <
146 IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE + IXDP2351_INTB_IRQ_NUM);
147 irq++) {
148 if (IXDP2351_INTB_IRQ_MASK(irq) & IXDP2351_INTB_IRQ_VALID) {
149 set_irq_flags(irq, IRQF_VALID);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100150 irq_set_chip_and_handler(irq, &ixdp2351_intb_chip,
151 handle_level_irq);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100152 }
153 }
154
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100155 irq_set_chained_handler(IRQ_IXP23XX_INTA, ixdp2351_inta_handler);
156 irq_set_chained_handler(IRQ_IXP23XX_INTB, ixdp2351_intb_handler);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100157}
158
159/*
160 * IXDP2351 PCI
161 */
162
163/*
164 * This board does not do normal PCI IRQ routing, or any
165 * sort of swizzling, so we just need to check where on the
166 * bus the device is and figure out what CPLD pin it is
167 * being routed to.
168 */
169#define DEVPIN(dev, pin) ((pin) | ((dev) << 3))
170
Ralf Baechled5341942011-06-10 15:30:21 +0100171static int __init ixdp2351_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100172{
173 u8 bus = dev->bus->number;
174 u32 devpin = DEVPIN(PCI_SLOT(dev->devfn), pin);
175 struct pci_bus *tmp_bus = dev->bus;
176
177 /* Primary bus, no interrupts here */
178 if (!bus)
179 return -1;
180
181 /* Lookup first leaf in bus tree */
182 while ((tmp_bus->parent != NULL) && (tmp_bus->parent->parent != NULL))
183 tmp_bus = tmp_bus->parent;
184
185 /* Select between known bridges */
186 switch (tmp_bus->self->devfn | (tmp_bus->self->bus->number << 8)) {
187 /* Device is located after first bridge */
188 case 0x0008:
189 if (tmp_bus == dev->bus) {
190 /* Device is located directy after first bridge */
191 switch (devpin) {
192 /* Onboard 82546 */
193 case DEVPIN(1, 1): /* Onboard 82546 ch 0 */
194 return IRQ_IXDP2351_INTA_82546;
195 case DEVPIN(1, 2): /* Onboard 82546 ch 1 */
196 return IRQ_IXDP2351_INTB_82546;
197 /* PMC SLOT */
198 case DEVPIN(0, 1): /* PMCP INTA# */
199 case DEVPIN(2, 4): /* PMCS INTD# */
200 return IRQ_IXDP2351_SPCI_PMC_INTA;
201 case DEVPIN(0, 2): /* PMCP INTB# */
202 case DEVPIN(2, 1): /* PMCS INTA# */
203 return IRQ_IXDP2351_SPCI_PMC_INTB;
204 case DEVPIN(0, 3): /* PMCP INTC# */
205 case DEVPIN(2, 2): /* PMCS INTB# */
206 return IRQ_IXDP2351_SPCI_PMC_INTC;
207 case DEVPIN(0, 4): /* PMCP INTD# */
208 case DEVPIN(2, 3): /* PMCS INTC# */
209 return IRQ_IXDP2351_SPCI_PMC_INTD;
210 }
211 } else {
212 /* Device is located indirectly after first bridge */
213 /* Not supported now */
214 return -1;
215 }
216 break;
217 case 0x0010:
218 if (tmp_bus == dev->bus) {
219 /* Device is located directy after second bridge */
220 /* Secondary bus of second bridge */
221 switch (devpin) {
222 case DEVPIN(0, 1): /* DB#0 */
223 case DEVPIN(0, 2):
224 case DEVPIN(0, 3):
225 case DEVPIN(0, 4):
226 return IRQ_IXDP2351_SPCI_DB_0;
227 case DEVPIN(1, 1): /* DB#1 */
228 case DEVPIN(1, 2):
229 case DEVPIN(1, 3):
230 case DEVPIN(1, 4):
231 return IRQ_IXDP2351_SPCI_DB_1;
232 case DEVPIN(2, 1): /* FIC1 */
233 case DEVPIN(2, 2):
234 case DEVPIN(2, 3):
235 case DEVPIN(2, 4):
236 case DEVPIN(3, 1): /* FIC2 */
237 case DEVPIN(3, 2):
238 case DEVPIN(3, 3):
239 case DEVPIN(3, 4):
240 return IRQ_IXDP2351_SPCI_FIC;
241 }
242 } else {
243 /* Device is located indirectly after second bridge */
244 /* Not supported now */
245 return -1;
246 }
247 break;
248 }
249
250 return -1;
251}
252
253struct hw_pci ixdp2351_pci __initdata = {
254 .nr_controllers = 1,
255 .preinit = ixp23xx_pci_preinit,
256 .setup = ixp23xx_pci_setup,
257 .scan = ixp23xx_pci_scan_bus,
258 .map_irq = ixdp2351_map_irq,
259};
260
261int __init ixdp2351_pci_init(void)
262{
263 if (machine_is_ixdp2351())
264 pci_common_init(&ixdp2351_pci);
265
266 return 0;
267}
268
269subsys_initcall(ixdp2351_pci_init);
270
271/*
272 * IXDP2351 Static Mapped I/O
273 */
274static struct map_desc ixdp2351_io_desc[] __initdata = {
275 {
276 .virtual = IXDP2351_NP_VIRT_BASE,
277 .pfn = __phys_to_pfn((u64)IXDP2351_NP_PHYS_BASE),
278 .length = IXDP2351_NP_PHYS_SIZE,
279 .type = MT_DEVICE
280 }, {
281 .virtual = IXDP2351_BB_BASE_VIRT,
282 .pfn = __phys_to_pfn((u64)IXDP2351_BB_BASE_PHYS),
283 .length = IXDP2351_BB_SIZE,
284 .type = MT_DEVICE
285 }
286};
287
288static void __init ixdp2351_map_io(void)
289{
290 ixp23xx_map_io();
291 iotable_init(ixdp2351_io_desc, ARRAY_SIZE(ixdp2351_io_desc));
292}
293
Lennert Buytenhek84b61f62006-06-22 10:30:52 +0100294static struct physmap_flash_data ixdp2351_flash_data = {
295 .width = 1,
296};
297
298static struct resource ixdp2351_flash_resource = {
299 .start = 0x90000000,
Lennert Buytenhek562ca1e2006-06-27 22:56:17 +0100300 .end = 0x93ffffff,
Lennert Buytenhek84b61f62006-06-22 10:30:52 +0100301 .flags = IORESOURCE_MEM,
302};
303
304static struct platform_device ixdp2351_flash = {
305 .name = "physmap-flash",
306 .id = 0,
307 .dev = {
308 .platform_data = &ixdp2351_flash_data,
309 },
310 .num_resources = 1,
311 .resource = &ixdp2351_flash_resource,
312};
313
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100314static void __init ixdp2351_init(void)
315{
Lennert Buytenhek84b61f62006-06-22 10:30:52 +0100316 platform_device_register(&ixdp2351_flash);
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100317
318 /*
319 * Mark flash as writeable
320 */
321 IXP23XX_EXP_CS0[0] |= IXP23XX_FLASH_WRITABLE;
322 IXP23XX_EXP_CS0[1] |= IXP23XX_FLASH_WRITABLE;
323 IXP23XX_EXP_CS0[2] |= IXP23XX_FLASH_WRITABLE;
324 IXP23XX_EXP_CS0[3] |= IXP23XX_FLASH_WRITABLE;
325
326 ixp23xx_sys_init();
327}
328
329MACHINE_START(IXDP2351, "Intel IXDP2351 Development Platform")
330 /* Maintainer: MontaVista Software, Inc. */
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100331 .map_io = ixdp2351_map_io,
332 .init_irq = ixdp2351_init_irq,
333 .timer = &ixp23xx_timer,
Nicolas Pitre36f7a1e2011-07-05 22:38:13 -0400334 .atag_offset = 0x100,
Lennert Buytenhekc4713072006-03-28 21:18:54 +0100335 .init_machine = ixdp2351_init,
336MACHINE_END