blob: 416f397c768bc5ee16351b16552ca93883f8e287 [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>
13#include <linux/pci.h>
14#include <linux/serial_8250.h>
15
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010016#include <asm/sni.h>
17#include <asm/time.h>
18#include <asm/irq_cpu.h>
19
20
21#define PORT(_base,_irq) \
22 { \
23 .iobase = _base, \
24 .irq = _irq, \
25 .uartclk = 1843200, \
26 .iotype = UPIO_PORT, \
27 .flags = UPF_BOOT_AUTOCONF, \
28 }
29
30static struct plat_serial8250_port pcit_data[] = {
31 PORT(0x3f8, 0),
32 PORT(0x2f8, 3),
33 { },
34};
35
36static struct platform_device pcit_serial8250_device = {
37 .name = "serial8250",
38 .id = PLAT8250_DEV_PLATFORM,
39 .dev = {
40 .platform_data = pcit_data,
41 },
42};
43
44static struct plat_serial8250_port pcit_cplus_data[] = {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +020045 PORT(0x3f8, 0),
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010046 PORT(0x2f8, 3),
47 PORT(0x3e8, 4),
48 PORT(0x2e8, 3),
49 { },
50};
51
52static struct platform_device pcit_cplus_serial8250_device = {
53 .name = "serial8250",
54 .id = PLAT8250_DEV_PLATFORM,
55 .dev = {
56 .platform_data = pcit_cplus_data,
57 },
58};
59
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +020060static struct resource pcit_cmos_rsrc[] = {
61 {
62 .start = 0x70,
63 .end = 0x71,
64 .flags = IORESOURCE_IO
65 },
66 {
67 .start = 8,
68 .end = 8,
69 .flags = IORESOURCE_IRQ
70 }
71};
72
73static struct platform_device pcit_cmos_device = {
74 .name = "rtc_cmos",
75 .num_resources = ARRAY_SIZE(pcit_cmos_rsrc),
76 .resource = pcit_cmos_rsrc
77};
78
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010079static struct resource sni_io_resource = {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +020080 .start = 0x00000000UL,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010081 .end = 0x03bfffffUL,
Thomas Bogendoerferbea77172007-04-08 13:34:57 +020082 .name = "PCIT IO",
Thomas Bogendoerferc066a322006-12-28 18:22:32 +010083 .flags = IORESOURCE_IO,
84};
85
86static struct resource pcit_io_resources[] = {
87 {
88 .start = 0x00,
89 .end = 0x1f,
90 .name = "dma1",
91 .flags = IORESOURCE_BUSY
92 }, {
93 .start = 0x40,
94 .end = 0x5f,
95 .name = "timer",
96 .flags = IORESOURCE_BUSY
97 }, {
98 .start = 0x60,
99 .end = 0x6f,
100 .name = "keyboard",
101 .flags = IORESOURCE_BUSY
102 }, {
103 .start = 0x80,
104 .end = 0x8f,
105 .name = "dma page reg",
106 .flags = IORESOURCE_BUSY
107 }, {
108 .start = 0xc0,
109 .end = 0xdf,
110 .name = "dma2",
111 .flags = IORESOURCE_BUSY
112 }, {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200113 .start = 0xcf8,
114 .end = 0xcfb,
115 .name = "PCI config addr",
116 .flags = IORESOURCE_BUSY
117 }, {
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100118 .start = 0xcfc,
119 .end = 0xcff,
120 .name = "PCI config data",
121 .flags = IORESOURCE_BUSY
122 }
123};
124
125static struct resource sni_mem_resource = {
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200126 .start = 0x18000000UL,
127 .end = 0x1fbfffffUL,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100128 .name = "PCIT PCI MEM",
129 .flags = IORESOURCE_MEM
130};
131
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100132static void __init sni_pcit_resource_init(void)
133{
134 int i;
135
136 /* request I/O space for devices used on all i[345]86 PCs */
137 for (i = 0; i < ARRAY_SIZE(pcit_io_resources); i++)
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200138 request_resource(&sni_io_resource, pcit_io_resources + i);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100139}
140
141
142extern struct pci_ops sni_pcit_ops;
143
144static struct pci_controller sni_pcit_controller = {
145 .pci_ops = &sni_pcit_ops,
146 .mem_resource = &sni_mem_resource,
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200147 .mem_offset = 0x00000000UL,
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100148 .io_resource = &sni_io_resource,
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200149 .io_offset = 0x00000000UL,
150 .io_map_base = SNI_PORT_BASE
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100151};
152
153static void enable_pcit_irq(unsigned int irq)
154{
155 u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
156
157 *(volatile u32 *)SNI_PCIT_INT_REG |= mask;
158}
159
160void disable_pcit_irq(unsigned int irq)
161{
162 u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
163
164 *(volatile u32 *)SNI_PCIT_INT_REG &= ~mask;
165}
166
167void end_pcit_irq(unsigned int irq)
168{
169 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
170 enable_pcit_irq(irq);
171}
172
173static struct irq_chip pcit_irq_type = {
174 .typename = "PCIT",
175 .ack = disable_pcit_irq,
176 .mask = disable_pcit_irq,
177 .mask_ack = disable_pcit_irq,
178 .unmask = enable_pcit_irq,
179 .end = end_pcit_irq,
180};
181
182static void pcit_hwint1(void)
183{
184 u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
185 int irq;
186
187 clear_c0_status(IE_IRQ1);
188 irq = ffs((pending >> 16) & 0x7f);
189
190 if (likely(irq > 0))
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100191 do_IRQ(irq + SNI_PCIT_INT_START - 1);
192 set_c0_status(IE_IRQ1);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100193}
194
195static void pcit_hwint0(void)
196{
197 u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
198 int irq;
199
200 clear_c0_status(IE_IRQ0);
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200201 irq = ffs((pending >> 16) & 0x3f);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100202
203 if (likely(irq > 0))
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100204 do_IRQ(irq + SNI_PCIT_INT_START - 1);
205 set_c0_status(IE_IRQ0);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100206}
207
208static void sni_pcit_hwint(void)
209{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000210 u32 pending = read_c0_cause() & read_c0_status();
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100211
212 if (pending & C_IRQ1)
213 pcit_hwint1();
214 else if (pending & C_IRQ2)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100215 do_IRQ(MIPS_CPU_IRQ_BASE + 4);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100216 else if (pending & C_IRQ3)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100217 do_IRQ(MIPS_CPU_IRQ_BASE + 5);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100218 else if (pending & C_IRQ5)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100219 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100220}
221
222static void sni_pcit_hwint_cplus(void)
223{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000224 u32 pending = read_c0_cause() & read_c0_status();
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100225
226 if (pending & C_IRQ0)
227 pcit_hwint0();
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200228 else if (pending & C_IRQ1)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100229 do_IRQ(MIPS_CPU_IRQ_BASE + 3);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100230 else if (pending & C_IRQ2)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100231 do_IRQ(MIPS_CPU_IRQ_BASE + 4);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100232 else if (pending & C_IRQ3)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100233 do_IRQ(MIPS_CPU_IRQ_BASE + 5);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100234 else if (pending & C_IRQ5)
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100235 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100236}
237
238void __init sni_pcit_irq_init(void)
239{
240 int i;
241
242 mips_cpu_irq_init();
243 for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
244 set_irq_chip(i, &pcit_irq_type);
245 *(volatile u32 *)SNI_PCIT_INT_REG = 0;
246 sni_hwint = sni_pcit_hwint;
247 change_c0_status(ST0_IM, IE_IRQ1);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100248 setup_irq(SNI_PCIT_INT_START + 6, &sni_isa_irq);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100249}
250
251void __init sni_pcit_cplus_irq_init(void)
252{
253 int i;
254
255 mips_cpu_irq_init();
256 for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
257 set_irq_chip(i, &pcit_irq_type);
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200258 *(volatile u32 *)SNI_PCIT_INT_REG = 0x40000000;
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100259 sni_hwint = sni_pcit_hwint_cplus;
260 change_c0_status(ST0_IM, IE_IRQ0);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100261 setup_irq(MIPS_CPU_IRQ_BASE + 3, &sni_isa_irq);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100262}
263
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +0200264void __init sni_pcit_init(void)
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100265{
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200266 ioport_resource.end = sni_io_resource.end;
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100267#ifdef CONFIG_PCI
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200268 PCIBIOS_MIN_IO = 0x9000;
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100269 register_pci_controller(&sni_pcit_controller);
270#endif
Thomas Bogendoerferbea77172007-04-08 13:34:57 +0200271 sni_pcit_resource_init();
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100272}
273
274static int __init snirm_pcit_setup_devinit(void)
275{
276 switch (sni_brd_type) {
277 case SNI_BRD_PCI_TOWER:
278 platform_device_register(&pcit_serial8250_device);
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +0200279 platform_device_register(&pcit_cmos_device);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100280 break;
281
282 case SNI_BRD_PCI_TOWER_CPLUS:
283 platform_device_register(&pcit_cplus_serial8250_device);
Thomas Bogendoerfer06cf5582007-06-20 23:36:47 +0200284 platform_device_register(&pcit_cmos_device);
Thomas Bogendoerferc066a322006-12-28 18:22:32 +0100285 break;
286 }
287 return 0;
288}
289
290device_initcall(snirm_pcit_setup_devinit);