Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PCI Tower specific code |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
| 8 | * Copyright (C) 2006 Thomas Bogendoerfer (tsbogend@alpha.franken.de) |
| 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/interrupt.h> |
David Howells | ca4d3e67 | 2010-10-07 14:08:54 +0100 | [diff] [blame] | 13 | #include <linux/irq.h> |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 14 | #include <linux/pci.h> |
| 15 | #include <linux/serial_8250.h> |
| 16 | |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 17 | #include <asm/sni.h> |
| 18 | #include <asm/time.h> |
| 19 | #include <asm/irq_cpu.h> |
| 20 | |
| 21 | |
| 22 | #define PORT(_base,_irq) \ |
| 23 | { \ |
| 24 | .iobase = _base, \ |
| 25 | .irq = _irq, \ |
| 26 | .uartclk = 1843200, \ |
| 27 | .iotype = UPIO_PORT, \ |
| 28 | .flags = UPF_BOOT_AUTOCONF, \ |
| 29 | } |
| 30 | |
| 31 | static struct plat_serial8250_port pcit_data[] = { |
| 32 | PORT(0x3f8, 0), |
| 33 | PORT(0x2f8, 3), |
| 34 | { }, |
| 35 | }; |
| 36 | |
| 37 | static struct platform_device pcit_serial8250_device = { |
| 38 | .name = "serial8250", |
| 39 | .id = PLAT8250_DEV_PLATFORM, |
| 40 | .dev = { |
| 41 | .platform_data = pcit_data, |
| 42 | }, |
| 43 | }; |
| 44 | |
| 45 | static struct plat_serial8250_port pcit_cplus_data[] = { |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 46 | PORT(0x3f8, 0), |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 47 | PORT(0x2f8, 3), |
| 48 | PORT(0x3e8, 4), |
| 49 | PORT(0x2e8, 3), |
| 50 | { }, |
| 51 | }; |
| 52 | |
| 53 | static struct platform_device pcit_cplus_serial8250_device = { |
| 54 | .name = "serial8250", |
| 55 | .id = PLAT8250_DEV_PLATFORM, |
| 56 | .dev = { |
| 57 | .platform_data = pcit_cplus_data, |
| 58 | }, |
| 59 | }; |
| 60 | |
Thomas Bogendoerfer | 06cf558 | 2007-06-20 23:36:47 +0200 | [diff] [blame] | 61 | static struct resource pcit_cmos_rsrc[] = { |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 62 | { |
| 63 | .start = 0x70, |
| 64 | .end = 0x71, |
| 65 | .flags = IORESOURCE_IO |
| 66 | }, |
| 67 | { |
| 68 | .start = 8, |
| 69 | .end = 8, |
| 70 | .flags = IORESOURCE_IRQ |
| 71 | } |
Thomas Bogendoerfer | 06cf558 | 2007-06-20 23:36:47 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static struct platform_device pcit_cmos_device = { |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 75 | .name = "rtc_cmos", |
| 76 | .num_resources = ARRAY_SIZE(pcit_cmos_rsrc), |
| 77 | .resource = pcit_cmos_rsrc |
Thomas Bogendoerfer | 06cf558 | 2007-06-20 23:36:47 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
Ralf Baechle | 19388fb | 2008-01-29 10:14:57 +0000 | [diff] [blame] | 80 | static struct platform_device pcit_pcspeaker_pdev = { |
| 81 | .name = "pcspkr", |
| 82 | .id = -1, |
| 83 | }; |
| 84 | |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 85 | static struct resource sni_io_resource = { |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 86 | .start = 0x00000000UL, |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 87 | .end = 0x03bfffffUL, |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 88 | .name = "PCIT IO", |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 89 | .flags = IORESOURCE_IO, |
| 90 | }; |
| 91 | |
| 92 | static struct resource pcit_io_resources[] = { |
| 93 | { |
| 94 | .start = 0x00, |
| 95 | .end = 0x1f, |
| 96 | .name = "dma1", |
| 97 | .flags = IORESOURCE_BUSY |
| 98 | }, { |
| 99 | .start = 0x40, |
| 100 | .end = 0x5f, |
| 101 | .name = "timer", |
| 102 | .flags = IORESOURCE_BUSY |
| 103 | }, { |
| 104 | .start = 0x60, |
| 105 | .end = 0x6f, |
| 106 | .name = "keyboard", |
| 107 | .flags = IORESOURCE_BUSY |
| 108 | }, { |
| 109 | .start = 0x80, |
| 110 | .end = 0x8f, |
| 111 | .name = "dma page reg", |
| 112 | .flags = IORESOURCE_BUSY |
| 113 | }, { |
| 114 | .start = 0xc0, |
| 115 | .end = 0xdf, |
| 116 | .name = "dma2", |
| 117 | .flags = IORESOURCE_BUSY |
| 118 | }, { |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 119 | .start = 0xcf8, |
| 120 | .end = 0xcfb, |
| 121 | .name = "PCI config addr", |
| 122 | .flags = IORESOURCE_BUSY |
| 123 | }, { |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 124 | .start = 0xcfc, |
| 125 | .end = 0xcff, |
| 126 | .name = "PCI config data", |
| 127 | .flags = IORESOURCE_BUSY |
| 128 | } |
| 129 | }; |
| 130 | |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 131 | static void __init sni_pcit_resource_init(void) |
| 132 | { |
| 133 | int i; |
| 134 | |
| 135 | /* request I/O space for devices used on all i[345]86 PCs */ |
| 136 | for (i = 0; i < ARRAY_SIZE(pcit_io_resources); i++) |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 137 | request_resource(&sni_io_resource, pcit_io_resources + i); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
| 141 | extern struct pci_ops sni_pcit_ops; |
| 142 | |
Ralf Baechle | 6a72015 | 2013-06-25 17:10:28 +0200 | [diff] [blame] | 143 | #ifdef CONFIG_PCI |
| 144 | static struct resource sni_mem_resource = { |
| 145 | .start = 0x18000000UL, |
| 146 | .end = 0x1fbfffffUL, |
| 147 | .name = "PCIT PCI MEM", |
| 148 | .flags = IORESOURCE_MEM |
| 149 | }; |
| 150 | |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 151 | static struct pci_controller sni_pcit_controller = { |
| 152 | .pci_ops = &sni_pcit_ops, |
| 153 | .mem_resource = &sni_mem_resource, |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 154 | .mem_offset = 0x00000000UL, |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 155 | .io_resource = &sni_io_resource, |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 156 | .io_offset = 0x00000000UL, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 157 | .io_map_base = SNI_PORT_BASE |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 158 | }; |
Ralf Baechle | 6a72015 | 2013-06-25 17:10:28 +0200 | [diff] [blame] | 159 | #endif /* CONFIG_PCI */ |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 160 | |
Thomas Gleixner | 0b888c7 | 2011-03-23 21:09:15 +0000 | [diff] [blame] | 161 | static void enable_pcit_irq(struct irq_data *d) |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 162 | { |
Thomas Gleixner | 0b888c7 | 2011-03-23 21:09:15 +0000 | [diff] [blame] | 163 | u32 mask = 1 << (d->irq - SNI_PCIT_INT_START + 24); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 164 | |
| 165 | *(volatile u32 *)SNI_PCIT_INT_REG |= mask; |
| 166 | } |
| 167 | |
Thomas Gleixner | 0b888c7 | 2011-03-23 21:09:15 +0000 | [diff] [blame] | 168 | void disable_pcit_irq(struct irq_data *d) |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 169 | { |
Thomas Gleixner | 0b888c7 | 2011-03-23 21:09:15 +0000 | [diff] [blame] | 170 | u32 mask = 1 << (d->irq - SNI_PCIT_INT_START + 24); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 171 | |
| 172 | *(volatile u32 *)SNI_PCIT_INT_REG &= ~mask; |
| 173 | } |
| 174 | |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 175 | static struct irq_chip pcit_irq_type = { |
Thomas Gleixner | 8922f79 | 2009-11-17 22:51:03 +0000 | [diff] [blame] | 176 | .name = "PCIT", |
Thomas Gleixner | 0b888c7 | 2011-03-23 21:09:15 +0000 | [diff] [blame] | 177 | .irq_mask = disable_pcit_irq, |
| 178 | .irq_unmask = enable_pcit_irq, |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | static void pcit_hwint1(void) |
| 182 | { |
| 183 | u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG; |
| 184 | int irq; |
| 185 | |
| 186 | clear_c0_status(IE_IRQ1); |
| 187 | irq = ffs((pending >> 16) & 0x7f); |
| 188 | |
| 189 | if (likely(irq > 0)) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 190 | do_IRQ(irq + SNI_PCIT_INT_START - 1); |
| 191 | set_c0_status(IE_IRQ1); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void pcit_hwint0(void) |
| 195 | { |
| 196 | u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG; |
| 197 | int irq; |
| 198 | |
| 199 | clear_c0_status(IE_IRQ0); |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 200 | irq = ffs((pending >> 16) & 0x3f); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 201 | |
| 202 | if (likely(irq > 0)) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 203 | do_IRQ(irq + SNI_PCIT_INT_START - 1); |
| 204 | set_c0_status(IE_IRQ0); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void sni_pcit_hwint(void) |
| 208 | { |
Thiemo Seufer | 119537c | 2007-03-19 00:13:37 +0000 | [diff] [blame] | 209 | u32 pending = read_c0_cause() & read_c0_status(); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 210 | |
| 211 | if (pending & C_IRQ1) |
| 212 | pcit_hwint1(); |
| 213 | else if (pending & C_IRQ2) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 214 | do_IRQ(MIPS_CPU_IRQ_BASE + 4); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 215 | else if (pending & C_IRQ3) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 216 | do_IRQ(MIPS_CPU_IRQ_BASE + 5); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 217 | else if (pending & C_IRQ5) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 218 | do_IRQ(MIPS_CPU_IRQ_BASE + 7); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static void sni_pcit_hwint_cplus(void) |
| 222 | { |
Thiemo Seufer | 119537c | 2007-03-19 00:13:37 +0000 | [diff] [blame] | 223 | u32 pending = read_c0_cause() & read_c0_status(); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 224 | |
| 225 | if (pending & C_IRQ0) |
| 226 | pcit_hwint0(); |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 227 | else if (pending & C_IRQ1) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 228 | do_IRQ(MIPS_CPU_IRQ_BASE + 3); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 229 | else if (pending & C_IRQ2) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 230 | do_IRQ(MIPS_CPU_IRQ_BASE + 4); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 231 | else if (pending & C_IRQ3) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 232 | do_IRQ(MIPS_CPU_IRQ_BASE + 5); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 233 | else if (pending & C_IRQ5) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 234 | do_IRQ(MIPS_CPU_IRQ_BASE + 7); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void __init sni_pcit_irq_init(void) |
| 238 | { |
| 239 | int i; |
| 240 | |
| 241 | mips_cpu_irq_init(); |
| 242 | for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++) |
Thomas Gleixner | e4ec798 | 2011-03-27 15:19:28 +0200 | [diff] [blame] | 243 | irq_set_chip_and_handler(i, &pcit_irq_type, handle_level_irq); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 244 | *(volatile u32 *)SNI_PCIT_INT_REG = 0; |
| 245 | sni_hwint = sni_pcit_hwint; |
| 246 | change_c0_status(ST0_IM, IE_IRQ1); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 247 | setup_irq(SNI_PCIT_INT_START + 6, &sni_isa_irq); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void __init sni_pcit_cplus_irq_init(void) |
| 251 | { |
| 252 | int i; |
| 253 | |
| 254 | mips_cpu_irq_init(); |
| 255 | for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++) |
Thomas Gleixner | e4ec798 | 2011-03-27 15:19:28 +0200 | [diff] [blame] | 256 | irq_set_chip_and_handler(i, &pcit_irq_type, handle_level_irq); |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 257 | *(volatile u32 *)SNI_PCIT_INT_REG = 0x40000000; |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 258 | sni_hwint = sni_pcit_hwint_cplus; |
| 259 | change_c0_status(ST0_IM, IE_IRQ0); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 260 | setup_irq(MIPS_CPU_IRQ_BASE + 3, &sni_isa_irq); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Thomas Bogendoerfer | 06cf558 | 2007-06-20 23:36:47 +0200 | [diff] [blame] | 263 | void __init sni_pcit_init(void) |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 264 | { |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 265 | ioport_resource.end = sni_io_resource.end; |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 266 | #ifdef CONFIG_PCI |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 267 | PCIBIOS_MIN_IO = 0x9000; |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 268 | register_pci_controller(&sni_pcit_controller); |
| 269 | #endif |
Thomas Bogendoerfer | bea7717 | 2007-04-08 13:34:57 +0200 | [diff] [blame] | 270 | sni_pcit_resource_init(); |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static int __init snirm_pcit_setup_devinit(void) |
| 274 | { |
| 275 | switch (sni_brd_type) { |
| 276 | case SNI_BRD_PCI_TOWER: |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 277 | platform_device_register(&pcit_serial8250_device); |
| 278 | platform_device_register(&pcit_cmos_device); |
Ralf Baechle | 19388fb | 2008-01-29 10:14:57 +0000 | [diff] [blame] | 279 | platform_device_register(&pcit_pcspeaker_pdev); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 280 | break; |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 281 | |
| 282 | case SNI_BRD_PCI_TOWER_CPLUS: |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 283 | platform_device_register(&pcit_cplus_serial8250_device); |
| 284 | platform_device_register(&pcit_cmos_device); |
Ralf Baechle | 19388fb | 2008-01-29 10:14:57 +0000 | [diff] [blame] | 285 | platform_device_register(&pcit_pcspeaker_pdev); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 286 | break; |
Thomas Bogendoerfer | c066a32 | 2006-12-28 18:22:32 +0100 | [diff] [blame] | 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | device_initcall(snirm_pcit_setup_devinit); |