Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-ixp2000/ixdp2x00.c |
| 3 | * |
| 4 | * Code common to IXDP2400 and IXDP2800 platforms. |
| 5 | * |
| 6 | * Original Author: Naeem Afzal <naeem.m.afzal@intel.com> |
| 7 | * Maintainer: Deepak Saxena <dsaxena@plexity.net> |
| 8 | * |
| 9 | * Copyright (C) 2002 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 | */ |
Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 17 | #include <linux/gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/interrupt.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/bitops.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/delay.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/irq.h> |
| 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/page.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 33 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/mach-types.h> |
| 35 | |
| 36 | #include <asm/mach/pci.h> |
| 37 | #include <asm/mach/map.h> |
| 38 | #include <asm/mach/irq.h> |
| 39 | #include <asm/mach/time.h> |
| 40 | #include <asm/mach/flash.h> |
| 41 | #include <asm/mach/arch.h> |
| 42 | |
Linus Walleij | 87f911a | 2011-08-22 08:44:18 +0100 | [diff] [blame] | 43 | #include <mach/gpio-ixp2000.h> |
Lennert Buytenhek | 8144f56 | 2005-06-25 16:58:22 +0100 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /************************************************************************* |
| 46 | * IXDP2x00 IRQ Initialization |
| 47 | *************************************************************************/ |
| 48 | static volatile unsigned long *board_irq_mask; |
| 49 | static volatile unsigned long *board_irq_stat; |
| 50 | static unsigned long board_irq_count; |
| 51 | |
| 52 | #ifdef CONFIG_ARCH_IXDP2400 |
| 53 | /* |
| 54 | * Slowport configuration for accessing CPLD registers on IXDP2x00 |
| 55 | */ |
| 56 | static struct slowport_cfg slowport_cpld_cfg = { |
| 57 | .CCR = SLOWPORT_CCR_DIV_2, |
| 58 | .WTC = 0x00000070, |
| 59 | .RTC = 0x00000070, |
| 60 | .PCR = SLOWPORT_MODE_FLASH, |
| 61 | .ADC = SLOWPORT_ADDR_WIDTH_24 | SLOWPORT_DATA_WIDTH_8 |
| 62 | }; |
| 63 | #endif |
| 64 | |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 65 | static void ixdp2x00_irq_mask(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | unsigned long dummy; |
| 68 | static struct slowport_cfg old_cfg; |
| 69 | |
| 70 | /* |
| 71 | * This is ugly in common code but really don't know |
| 72 | * of a better way to handle it. :( |
| 73 | */ |
| 74 | #ifdef CONFIG_ARCH_IXDP2400 |
| 75 | if (machine_is_ixdp2400()) |
| 76 | ixp2000_acquire_slowport(&slowport_cpld_cfg, &old_cfg); |
| 77 | #endif |
| 78 | |
| 79 | dummy = *board_irq_mask; |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 80 | dummy |= IXP2000_BOARD_IRQ_MASK(d->irq); |
Lennert Buytenhek | e9b72e4 | 2005-11-01 19:44:26 +0000 | [diff] [blame] | 81 | ixp2000_reg_wrb(board_irq_mask, dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | #ifdef CONFIG_ARCH_IXDP2400 |
| 84 | if (machine_is_ixdp2400()) |
| 85 | ixp2000_release_slowport(&old_cfg); |
| 86 | #endif |
| 87 | } |
| 88 | |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 89 | static void ixdp2x00_irq_unmask(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | unsigned long dummy; |
| 92 | static struct slowport_cfg old_cfg; |
| 93 | |
| 94 | #ifdef CONFIG_ARCH_IXDP2400 |
| 95 | if (machine_is_ixdp2400()) |
| 96 | ixp2000_acquire_slowport(&slowport_cpld_cfg, &old_cfg); |
| 97 | #endif |
| 98 | |
| 99 | dummy = *board_irq_mask; |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 100 | dummy &= ~IXP2000_BOARD_IRQ_MASK(d->irq); |
Lennert Buytenhek | e9b72e4 | 2005-11-01 19:44:26 +0000 | [diff] [blame] | 101 | ixp2000_reg_wrb(board_irq_mask, dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | if (machine_is_ixdp2400()) |
| 104 | ixp2000_release_slowport(&old_cfg); |
| 105 | } |
| 106 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 107 | static void ixdp2x00_irq_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
| 109 | volatile u32 ex_interrupt = 0; |
| 110 | static struct slowport_cfg old_cfg; |
| 111 | int i; |
| 112 | |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 113 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | #ifdef CONFIG_ARCH_IXDP2400 |
| 116 | if (machine_is_ixdp2400()) |
| 117 | ixp2000_acquire_slowport(&slowport_cpld_cfg, &old_cfg); |
| 118 | #endif |
| 119 | ex_interrupt = *board_irq_stat & 0xff; |
| 120 | if (machine_is_ixdp2400()) |
| 121 | ixp2000_release_slowport(&old_cfg); |
| 122 | |
| 123 | if(!ex_interrupt) { |
| 124 | printk(KERN_ERR "Spurious IXDP2x00 CPLD interrupt!\n"); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | for(i = 0; i < board_irq_count; i++) { |
| 129 | if(ex_interrupt & (1 << i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | int cpld_irq = IXP2000_BOARD_IRQ(0) + i; |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 131 | generic_handle_irq(cpld_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 135 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 138 | static struct irq_chip ixdp2x00_cpld_irq_chip = { |
Lennert Buytenhek | 6e8f54f | 2010-11-29 10:32:55 +0100 | [diff] [blame] | 139 | .irq_ack = ixdp2x00_irq_mask, |
| 140 | .irq_mask = ixdp2x00_irq_mask, |
| 141 | .irq_unmask = ixdp2x00_irq_unmask |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Thomas Gleixner | 4b1135a | 2008-10-16 15:33:18 +0200 | [diff] [blame] | 144 | void __init ixdp2x00_init_irq(volatile unsigned long *stat_reg, volatile unsigned long *mask_reg, unsigned long nr_of_irqs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | unsigned int irq; |
| 147 | |
| 148 | ixp2000_init_irq(); |
| 149 | |
| 150 | if (!ixdp2x00_master_npu()) |
| 151 | return; |
| 152 | |
| 153 | board_irq_stat = stat_reg; |
| 154 | board_irq_mask = mask_reg; |
Thomas Gleixner | 4b1135a | 2008-10-16 15:33:18 +0200 | [diff] [blame] | 155 | board_irq_count = nr_of_irqs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | *board_irq_mask = 0xffffffff; |
| 158 | |
| 159 | for(irq = IXP2000_BOARD_IRQ(0); irq < IXP2000_BOARD_IRQ(board_irq_count); irq++) { |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 160 | irq_set_chip_and_handler(irq, &ixdp2x00_cpld_irq_chip, |
| 161 | handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | set_irq_flags(irq, IRQF_VALID); |
| 163 | } |
| 164 | |
| 165 | /* Hook into PCI interrupt */ |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 166 | irq_set_chained_handler(IRQ_IXP2000_PCIB, ixdp2x00_irq_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /************************************************************************* |
| 170 | * IXDP2x00 memory map |
| 171 | *************************************************************************/ |
| 172 | static struct map_desc ixdp2x00_io_desc __initdata = { |
| 173 | .virtual = IXDP2X00_VIRT_CPLD_BASE, |
Deepak Saxena | db0d087 | 2005-10-28 15:18:58 +0100 | [diff] [blame] | 174 | .pfn = __phys_to_pfn(IXDP2X00_PHYS_CPLD_BASE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | .length = IXDP2X00_CPLD_SIZE, |
| 176 | .type = MT_DEVICE |
| 177 | }; |
| 178 | |
| 179 | void __init ixdp2x00_map_io(void) |
| 180 | { |
| 181 | ixp2000_map_io(); |
| 182 | |
| 183 | iotable_init(&ixdp2x00_io_desc, 1); |
| 184 | } |
| 185 | |
| 186 | /************************************************************************* |
| 187 | * IXDP2x00-common PCI init |
| 188 | * |
| 189 | * The IXDP2[48]00 has a horrid PCI bus layout. Basically the board |
| 190 | * contains two NPUs (ingress and egress) connected over PCI, both running |
| 191 | * instances of the kernel. So far so good. Peers on the PCI bus running |
| 192 | * Linux is a common design in telecom systems. The problem is that instead |
| 193 | * of all the devices being controlled by a single host, different |
Simon Arlott | 6cbdc8c | 2007-05-11 20:40:30 +0100 | [diff] [blame] | 194 | * devices are controlled by different NPUs on the same bus, leading to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | * multiple hosts on the bus. The exact bus layout looks like: |
| 196 | * |
| 197 | * Bus 0 |
| 198 | * Master NPU <-------------------+-------------------> Slave NPU |
| 199 | * | |
| 200 | * | |
| 201 | * P2P |
| 202 | * | |
| 203 | * |
| 204 | * Bus 1 | |
| 205 | * <--+------+---------+---------+------+--> |
| 206 | * | | | | | |
| 207 | * | | | | | |
| 208 | * ... Dev PMC Media Eth0 Eth1 ... |
| 209 | * |
Simon Arlott | 6cbdc8c | 2007-05-11 20:40:30 +0100 | [diff] [blame] | 210 | * The master controls all but Eth1, which is controlled by the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | * slave. What this means is that the both the master and the slave |
| 212 | * have to scan the bus, but only one of them can enumerate the bus. |
| 213 | * In addition, after the bus is scanned, each kernel must remove |
| 214 | * the device(s) it does not control from the PCI dev list otherwise |
| 215 | * a driver on each NPU will try to manage it and we will have horrible |
| 216 | * conflicts. Oh..and the slave NPU needs to see the master NPU |
| 217 | * for Intel's drivers to work properly. Closed source drivers... |
| 218 | * |
| 219 | * The way we deal with this is fairly simple but ugly: |
| 220 | * |
| 221 | * 1) Let master scan and enumerate the bus completely. |
| 222 | * 2) Master deletes Eth1 from device list. |
| 223 | * 3) Slave scans bus and then deletes all but Eth1 (Eth0 on slave) |
| 224 | * from device list. |
| 225 | * 4) Find HW designers and LART them. |
| 226 | * |
| 227 | * The boards also do not do normal PCI IRQ routing, or any sort of |
| 228 | * sensical swizzling, so we just need to check where on the bus a |
| 229 | * device sits and figure out to which CPLD pin the interrupt is routed. |
| 230 | * See ixdp2[48]00.c files. |
| 231 | * |
| 232 | *************************************************************************/ |
| 233 | void ixdp2x00_slave_pci_postinit(void) |
| 234 | { |
| 235 | struct pci_dev *dev; |
| 236 | |
| 237 | /* |
| 238 | * Remove PMC device is there is one |
| 239 | */ |
Alan Cox | 7281c24 | 2006-10-16 16:49:50 +0100 | [diff] [blame] | 240 | if((dev = pci_get_bus_and_slot(1, IXDP2X00_PMC_DEVFN))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | pci_remove_bus_device(dev); |
Alan Cox | 7281c24 | 2006-10-16 16:49:50 +0100 | [diff] [blame] | 242 | pci_dev_put(dev); |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Alan Cox | 7281c24 | 2006-10-16 16:49:50 +0100 | [diff] [blame] | 245 | dev = pci_get_bus_and_slot(0, IXDP2X00_21555_DEVFN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | pci_remove_bus_device(dev); |
Alan Cox | 7281c24 | 2006-10-16 16:49:50 +0100 | [diff] [blame] | 247 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /************************************************************************** |
| 251 | * IXDP2x00 Machine Setup |
| 252 | *************************************************************************/ |
| 253 | static struct flash_platform_data ixdp2x00_platform_data = { |
| 254 | .map_name = "cfi_probe", |
| 255 | .width = 1, |
| 256 | }; |
| 257 | |
| 258 | static struct ixp2000_flash_data ixdp2x00_flash_data = { |
| 259 | .platform_data = &ixdp2x00_platform_data, |
| 260 | .nr_banks = 1 |
| 261 | }; |
| 262 | |
| 263 | static struct resource ixdp2x00_flash_resource = { |
| 264 | .start = 0xc4000000, |
| 265 | .end = 0xc4000000 + 0x00ffffff, |
| 266 | .flags = IORESOURCE_MEM, |
| 267 | }; |
| 268 | |
| 269 | static struct platform_device ixdp2x00_flash = { |
| 270 | .name = "IXP2000-Flash", |
| 271 | .id = 0, |
| 272 | .dev = { |
| 273 | .platform_data = &ixdp2x00_flash_data, |
| 274 | }, |
| 275 | .num_resources = 1, |
| 276 | .resource = &ixdp2x00_flash_resource, |
| 277 | }; |
| 278 | |
| 279 | static struct ixp2000_i2c_pins ixdp2x00_i2c_gpio_pins = { |
| 280 | .sda_pin = IXDP2X00_GPIO_SDA, |
| 281 | .scl_pin = IXDP2X00_GPIO_SCL, |
| 282 | }; |
| 283 | |
| 284 | static struct platform_device ixdp2x00_i2c_controller = { |
| 285 | .name = "IXP2000-I2C", |
| 286 | .id = 0, |
| 287 | .dev = { |
| 288 | .platform_data = &ixdp2x00_i2c_gpio_pins, |
| 289 | }, |
| 290 | .num_resources = 0 |
| 291 | }; |
| 292 | |
| 293 | static struct platform_device *ixdp2x00_devices[] __initdata = { |
| 294 | &ixdp2x00_flash, |
| 295 | &ixdp2x00_i2c_controller |
| 296 | }; |
| 297 | |
| 298 | void __init ixdp2x00_init_machine(void) |
| 299 | { |
| 300 | gpio_line_set(IXDP2X00_GPIO_I2C_ENABLE, 1); |
| 301 | gpio_line_config(IXDP2X00_GPIO_I2C_ENABLE, GPIO_OUT); |
| 302 | |
| 303 | platform_add_devices(ixdp2x00_devices, ARRAY_SIZE(ixdp2x00_devices)); |
Lennert Buytenhek | 28187f2 | 2005-07-10 19:44:53 +0100 | [diff] [blame] | 304 | ixp2000_uart_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |