]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/mips/sni/pcit.c
MIPS: Add missing #inclusions of <linux/irq.h>
[mirror_ubuntu-artful-kernel.git] / arch / mips / sni / pcit.c
CommitLineData
c066a32a
TB
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>
ca4d3e67 13#include <linux/irq.h>
c066a32a
TB
14#include <linux/pci.h>
15#include <linux/serial_8250.h>
16
c066a32a
TB
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
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[] = {
bea77175 46 PORT(0x3f8, 0),
c066a32a
TB
47 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
06cf5583
TB
61static 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
19388fb0
RB
80static struct platform_device pcit_pcspeaker_pdev = {
81 .name = "pcspkr",
82 .id = -1,
83};
84
c066a32a 85static struct resource sni_io_resource = {
bea77175 86 .start = 0x00000000UL,
c066a32a 87 .end = 0x03bfffffUL,
bea77175 88 .name = "PCIT IO",
c066a32a
TB
89 .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
bea77175
TB
118 }, {
119 .start = 0xcf8,
120 .end = 0xcfb,
121 .name = "PCI config addr",
122 .flags = IORESOURCE_BUSY
c066a32a
TB
123 }, {
124 .start = 0xcfc,
125 .end = 0xcff,
126 .name = "PCI config data",
127 .flags = IORESOURCE_BUSY
128 }
129};
130
131static struct resource sni_mem_resource = {
bea77175
TB
132 .start = 0x18000000UL,
133 .end = 0x1fbfffffUL,
c066a32a
TB
134 .name = "PCIT PCI MEM",
135 .flags = IORESOURCE_MEM
136};
137
c066a32a
TB
138static 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++)
bea77175 144 request_resource(&sni_io_resource, pcit_io_resources + i);
c066a32a
TB
145}
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,
bea77175 153 .mem_offset = 0x00000000UL,
c066a32a 154 .io_resource = &sni_io_resource,
bea77175
TB
155 .io_offset = 0x00000000UL,
156 .io_map_base = SNI_PORT_BASE
c066a32a
TB
157};
158
159static void enable_pcit_irq(unsigned int irq)
160{
161 u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
162
163 *(volatile u32 *)SNI_PCIT_INT_REG |= mask;
164}
165
166void disable_pcit_irq(unsigned int irq)
167{
168 u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
169
170 *(volatile u32 *)SNI_PCIT_INT_REG &= ~mask;
171}
172
173void end_pcit_irq(unsigned int irq)
174{
175 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
176 enable_pcit_irq(irq);
177}
178
179static struct irq_chip pcit_irq_type = {
8922f79e 180 .name = "PCIT",
c066a32a
TB
181 .ack = disable_pcit_irq,
182 .mask = disable_pcit_irq,
183 .mask_ack = disable_pcit_irq,
184 .unmask = enable_pcit_irq,
185 .end = end_pcit_irq,
186};
187
188static void pcit_hwint1(void)
189{
190 u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
191 int irq;
192
193 clear_c0_status(IE_IRQ1);
194 irq = ffs((pending >> 16) & 0x7f);
195
196 if (likely(irq > 0))
49a89efb
RB
197 do_IRQ(irq + SNI_PCIT_INT_START - 1);
198 set_c0_status(IE_IRQ1);
c066a32a
TB
199}
200
201static void pcit_hwint0(void)
202{
203 u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
204 int irq;
205
206 clear_c0_status(IE_IRQ0);
bea77175 207 irq = ffs((pending >> 16) & 0x3f);
c066a32a
TB
208
209 if (likely(irq > 0))
49a89efb
RB
210 do_IRQ(irq + SNI_PCIT_INT_START - 1);
211 set_c0_status(IE_IRQ0);
c066a32a
TB
212}
213
214static void sni_pcit_hwint(void)
215{
119537c0 216 u32 pending = read_c0_cause() & read_c0_status();
c066a32a
TB
217
218 if (pending & C_IRQ1)
219 pcit_hwint1();
220 else if (pending & C_IRQ2)
49a89efb 221 do_IRQ(MIPS_CPU_IRQ_BASE + 4);
c066a32a 222 else if (pending & C_IRQ3)
49a89efb 223 do_IRQ(MIPS_CPU_IRQ_BASE + 5);
c066a32a 224 else if (pending & C_IRQ5)
49a89efb 225 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
c066a32a
TB
226}
227
228static void sni_pcit_hwint_cplus(void)
229{
119537c0 230 u32 pending = read_c0_cause() & read_c0_status();
c066a32a
TB
231
232 if (pending & C_IRQ0)
233 pcit_hwint0();
bea77175 234 else if (pending & C_IRQ1)
49a89efb 235 do_IRQ(MIPS_CPU_IRQ_BASE + 3);
c066a32a 236 else if (pending & C_IRQ2)
49a89efb 237 do_IRQ(MIPS_CPU_IRQ_BASE + 4);
c066a32a 238 else if (pending & C_IRQ3)
49a89efb 239 do_IRQ(MIPS_CPU_IRQ_BASE + 5);
c066a32a 240 else if (pending & C_IRQ5)
49a89efb 241 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
c066a32a
TB
242}
243
244void __init sni_pcit_irq_init(void)
245{
246 int i;
247
248 mips_cpu_irq_init();
249 for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
c87e0909 250 set_irq_chip_and_handler(i, &pcit_irq_type, handle_level_irq);
c066a32a
TB
251 *(volatile u32 *)SNI_PCIT_INT_REG = 0;
252 sni_hwint = sni_pcit_hwint;
253 change_c0_status(ST0_IM, IE_IRQ1);
49a89efb 254 setup_irq(SNI_PCIT_INT_START + 6, &sni_isa_irq);
c066a32a
TB
255}
256
257void __init sni_pcit_cplus_irq_init(void)
258{
259 int i;
260
261 mips_cpu_irq_init();
262 for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
c87e0909 263 set_irq_chip_and_handler(i, &pcit_irq_type, handle_level_irq);
bea77175 264 *(volatile u32 *)SNI_PCIT_INT_REG = 0x40000000;
c066a32a
TB
265 sni_hwint = sni_pcit_hwint_cplus;
266 change_c0_status(ST0_IM, IE_IRQ0);
49a89efb 267 setup_irq(MIPS_CPU_IRQ_BASE + 3, &sni_isa_irq);
c066a32a
TB
268}
269
06cf5583 270void __init sni_pcit_init(void)
c066a32a 271{
bea77175 272 ioport_resource.end = sni_io_resource.end;
c066a32a 273#ifdef CONFIG_PCI
bea77175 274 PCIBIOS_MIN_IO = 0x9000;
c066a32a
TB
275 register_pci_controller(&sni_pcit_controller);
276#endif
bea77175 277 sni_pcit_resource_init();
c066a32a
TB
278}
279
280static int __init snirm_pcit_setup_devinit(void)
281{
282 switch (sni_brd_type) {
283 case SNI_BRD_PCI_TOWER:
284 platform_device_register(&pcit_serial8250_device);
06cf5583 285 platform_device_register(&pcit_cmos_device);
19388fb0 286 platform_device_register(&pcit_pcspeaker_pdev);
c066a32a
TB
287 break;
288
289 case SNI_BRD_PCI_TOWER_CPLUS:
290 platform_device_register(&pcit_cplus_serial8250_device);
06cf5583 291 platform_device_register(&pcit_cmos_device);
19388fb0 292 platform_device_register(&pcit_pcspeaker_pdev);
c066a32a
TB
293 break;
294 }
295 return 0;
296}
297
298device_initcall(snirm_pcit_setup_devinit);