blob: b5246373d16bde19b832d49f2acb02b395ab2622 [file] [log] [blame]
Thomas Bogendoerferc066a322006-12-28 18:22:32 +01001/*
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 Howellsca4d3e672010-10-07 14:08:54 +010013#include <linux/irq.h>
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010014#include <linux/pci.h>
15#include <linux/serial_8250.h>
16
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010017#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
31static struct plat_serial8250_port pcit_data[] = {
32 PORT(0x3f8, 0),
33 PORT(0x2f8, 3),
34 { },
35};
36
37static struct platform_device pcit_serial8250_device = {
38 .name = "serial8250",
39 .id = PLAT8250_DEV_PLATFORM,
40 .dev = {
41 .platform_data = pcit_data,
42 },
43};
44
45static struct plat_serial8250_port pcit_cplus_data[] = {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +020046 PORT(0x3f8, 0),
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010047 PORT(0x2f8, 3),
48 PORT(0x3e8, 4),
49 PORT(0x2e8, 3),
50 { },
51};
52
53static 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 Bogendoerfer06cf5582007-06-20 23:36:47 +020061static struct resource pcit_cmos_rsrc[] = {
62 {
63 .start = 0x70,
64 .end = 0x71,
65 .flags = IORESOURCE_IO
66 },
67 {
68 .start = 8,
69 .end = 8,
70 .flags = IORESOURCE_IRQ
71 }
72};
73
74static struct platform_device pcit_cmos_device = {
75 .name = "rtc_cmos",
76 .num_resources = ARRAY_SIZE(pcit_cmos_rsrc),
77 .resource = pcit_cmos_rsrc
78};
79
Ralf Baechle19388fb2008-01-29 10:14:57 +000080static struct platform_device pcit_pcspeaker_pdev = {
81 .name = "pcspkr",
82 .id = -1,
83};
84
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010085static struct resource sni_io_resource = {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +020086 .start = 0x00000000UL,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010087 .end = 0x03bfffffUL,
Thomas Bogendoerferbea77172007-04-08 13:34:57 +020088 .name = "PCIT IO",
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010089 .flags = IORESOURCE_IO,
90};
91
92static 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 Bogendoerferbea77172007-04-08 13:34:57 +0200119 .start = 0xcf8,
120 .end = 0xcfb,
121 .name = "PCI config addr",
122 .flags = IORESOURCE_BUSY
123 }, {
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100124 .start = 0xcfc,
125 .end = 0xcff,
126 .name = "PCI config data",
127 .flags = IORESOURCE_BUSY
128 }
129};
130
131static struct resource sni_mem_resource = {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200132 .start = 0x18000000UL,
133 .end = 0x1fbfffffUL,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100134 .name = "PCIT PCI MEM",
135 .flags = IORESOURCE_MEM
136};
137
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100138static void __init sni_pcit_resource_init(void)
139{
140 int i;
141
142 /* request I/O space for devices used on all i[345]86 PCs */
143 for (i = 0; i < ARRAY_SIZE(pcit_io_resources); i++)
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200144 request_resource(&sni_io_resource, pcit_io_resources + i);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100145}
146
147
148extern struct pci_ops sni_pcit_ops;
149
150static struct pci_controller sni_pcit_controller = {
151 .pci_ops = &sni_pcit_ops,
152 .mem_resource = &sni_mem_resource,
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200153 .mem_offset = 0x00000000UL,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100154 .io_resource = &sni_io_resource,
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200155 .io_offset = 0x00000000UL,
156 .io_map_base = SNI_PORT_BASE
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100157};
158
Thomas Gleixner0b888c72011-03-23 21:09:15 +0000159static void enable_pcit_irq(struct irq_data *d)
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100160{
Thomas Gleixner0b888c72011-03-23 21:09:15 +0000161 u32 mask = 1 << (d->irq - SNI_PCIT_INT_START + 24);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100162
163 *(volatile u32 *)SNI_PCIT_INT_REG |= mask;
164}
165
Thomas Gleixner0b888c72011-03-23 21:09:15 +0000166void disable_pcit_irq(struct irq_data *d)
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100167{
Thomas Gleixner0b888c72011-03-23 21:09:15 +0000168 u32 mask = 1 << (d->irq - SNI_PCIT_INT_START + 24);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100169
170 *(volatile u32 *)SNI_PCIT_INT_REG &= ~mask;
171}
172
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100173static struct irq_chip pcit_irq_type = {
Thomas Gleixner8922f792009-11-17 22:51:03 +0000174 .name = "PCIT",
Thomas Gleixner0b888c72011-03-23 21:09:15 +0000175 .irq_mask = disable_pcit_irq,
176 .irq_unmask = enable_pcit_irq,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100177};
178
179static void pcit_hwint1(void)
180{
181 u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
182 int irq;
183
184 clear_c0_status(IE_IRQ1);
185 irq = ffs((pending >> 16) & 0x7f);
186
187 if (likely(irq > 0))
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100188 do_IRQ(irq + SNI_PCIT_INT_START - 1);
189 set_c0_status(IE_IRQ1);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100190}
191
192static void pcit_hwint0(void)
193{
194 u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
195 int irq;
196
197 clear_c0_status(IE_IRQ0);
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200198 irq = ffs((pending >> 16) & 0x3f);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100199
200 if (likely(irq > 0))
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100201 do_IRQ(irq + SNI_PCIT_INT_START - 1);
202 set_c0_status(IE_IRQ0);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100203}
204
205static void sni_pcit_hwint(void)
206{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000207 u32 pending = read_c0_cause() & read_c0_status();
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100208
209 if (pending & C_IRQ1)
210 pcit_hwint1();
211 else if (pending & C_IRQ2)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100212 do_IRQ(MIPS_CPU_IRQ_BASE + 4);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100213 else if (pending & C_IRQ3)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100214 do_IRQ(MIPS_CPU_IRQ_BASE + 5);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100215 else if (pending & C_IRQ5)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100216 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100217}
218
219static void sni_pcit_hwint_cplus(void)
220{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000221 u32 pending = read_c0_cause() & read_c0_status();
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100222
223 if (pending & C_IRQ0)
224 pcit_hwint0();
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200225 else if (pending & C_IRQ1)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100226 do_IRQ(MIPS_CPU_IRQ_BASE + 3);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100227 else if (pending & C_IRQ2)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100228 do_IRQ(MIPS_CPU_IRQ_BASE + 4);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100229 else if (pending & C_IRQ3)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100230 do_IRQ(MIPS_CPU_IRQ_BASE + 5);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100231 else if (pending & C_IRQ5)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100232 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100233}
234
235void __init sni_pcit_irq_init(void)
236{
237 int i;
238
239 mips_cpu_irq_init();
240 for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200241 irq_set_chip_and_handler(i, &pcit_irq_type, handle_level_irq);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100242 *(volatile u32 *)SNI_PCIT_INT_REG = 0;
243 sni_hwint = sni_pcit_hwint;
244 change_c0_status(ST0_IM, IE_IRQ1);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100245 setup_irq(SNI_PCIT_INT_START + 6, &sni_isa_irq);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100246}
247
248void __init sni_pcit_cplus_irq_init(void)
249{
250 int i;
251
252 mips_cpu_irq_init();
253 for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200254 irq_set_chip_and_handler(i, &pcit_irq_type, handle_level_irq);
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200255 *(volatile u32 *)SNI_PCIT_INT_REG = 0x40000000;
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100256 sni_hwint = sni_pcit_hwint_cplus;
257 change_c0_status(ST0_IM, IE_IRQ0);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100258 setup_irq(MIPS_CPU_IRQ_BASE + 3, &sni_isa_irq);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100259}
260
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +0200261void __init sni_pcit_init(void)
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100262{
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200263 ioport_resource.end = sni_io_resource.end;
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100264#ifdef CONFIG_PCI
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200265 PCIBIOS_MIN_IO = 0x9000;
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100266 register_pci_controller(&sni_pcit_controller);
267#endif
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200268 sni_pcit_resource_init();
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100269}
270
271static int __init snirm_pcit_setup_devinit(void)
272{
273 switch (sni_brd_type) {
274 case SNI_BRD_PCI_TOWER:
275 platform_device_register(&pcit_serial8250_device);
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +0200276 platform_device_register(&pcit_cmos_device);
Ralf Baechle19388fb2008-01-29 10:14:57 +0000277 platform_device_register(&pcit_pcspeaker_pdev);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100278 break;
279
280 case SNI_BRD_PCI_TOWER_CPLUS:
281 platform_device_register(&pcit_cplus_serial8250_device);
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +0200282 platform_device_register(&pcit_cmos_device);
Ralf Baechle19388fb2008-01-29 10:14:57 +0000283 platform_device_register(&pcit_pcspeaker_pdev);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100284 break;
285 }
286 return 0;
287}
288
289device_initcall(snirm_pcit_setup_devinit);