blob: ee7e720188dd7a8a8111f6310e814b82dd903c1c [file] [log] [blame]
Graeme Russ85cc39f2009-02-24 21:14:32 +11001/*
2 * (C) Copyright 2002
3 * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/* stuff specific for the sc520, but independent of implementation */
25
26#include <common.h>
27#include <pci.h>
Graeme Russ0c5ced72010-04-24 00:05:37 +100028#include <asm/io.h>
Graeme Russ85cc39f2009-02-24 21:14:32 +110029#include <asm/pci.h>
30#include <asm/ic/sc520.h>
31
32static struct {
33 u8 priority;
34 u16 level_reg;
35 u8 level_bit;
36} sc520_irq[] = {
Graeme Russ1d977dc2009-08-23 12:59:56 +100037 { SC520_IRQ0, 0, 0x01 },
38 { SC520_IRQ1, 0, 0x02 },
39 { SC520_IRQ2, 1, 0x02 },
40 { SC520_IRQ3, 0, 0x08 },
41 { SC520_IRQ4, 0, 0x10 },
42 { SC520_IRQ5, 0, 0x20 },
43 { SC520_IRQ6, 0, 0x40 },
44 { SC520_IRQ7, 0, 0x80 },
Graeme Russ85cc39f2009-02-24 21:14:32 +110045
Graeme Russ1d977dc2009-08-23 12:59:56 +100046 { SC520_IRQ8, 1, 0x01 },
47 { SC520_IRQ9, 1, 0x02 },
48 { SC520_IRQ10, 1, 0x04 },
49 { SC520_IRQ11, 1, 0x08 },
50 { SC520_IRQ12, 1, 0x10 },
51 { SC520_IRQ13, 1, 0x20 },
52 { SC520_IRQ14, 1, 0x40 },
53 { SC520_IRQ15, 1, 0x80 }
Graeme Russ85cc39f2009-02-24 21:14:32 +110054};
55
56
57/* The interrupt used for PCI INTA-INTD */
58int sc520_pci_ints[15] = {
59 -1, -1, -1, -1, -1, -1, -1, -1,
60 -1, -1, -1, -1, -1, -1, -1
61};
62
63/* utility function to configure a pci interrupt */
64int pci_sc520_set_irq(int pci_pin, int irq)
65{
66 int i;
Graeme Russ0c5ced72010-04-24 00:05:37 +100067 u8 tmpb;
68 u16 tmpw;
Graeme Russ85cc39f2009-02-24 21:14:32 +110069
70# if 1
71 printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
72#endif
73 if (irq < 0 || irq > 15) {
74 return -1; /* illegal irq */
75 }
76
77 if (pci_pin < 0 || pci_pin > 15) {
78 return -1; /* illegal pci int pin */
79 }
80
81 /* first disable any non-pci interrupt source that use
82 * this level */
Graeme Russ1d977dc2009-08-23 12:59:56 +100083
84 /* PCI interrupt mapping (A through D)*/
85 for (i=0; i<=3 ;i++) {
Graeme Russ0c5ced72010-04-24 00:05:37 +100086 if (readb(&sc520_mmcr->pci_int_map[i]) == sc520_irq[irq].priority)
87 writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[i]);
Graeme Russ1d977dc2009-08-23 12:59:56 +100088 }
89
90 /* GP IRQ interrupt mapping */
91 for (i=0; i<=10 ;i++) {
Graeme Russ0c5ced72010-04-24 00:05:37 +100092 if (readb(&sc520_mmcr->gp_int_map[i]) == sc520_irq[irq].priority)
93 writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_int_map[i]);
Graeme Russ85cc39f2009-02-24 21:14:32 +110094 }
95
96 /* Set the trigger to level */
Graeme Russ0c5ced72010-04-24 00:05:37 +100097 tmpb = readb(&sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]);
98 tmpb |= sc520_irq[irq].level_bit;
99 writeb(tmpb, &sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100100
101
102 if (pci_pin < 4) {
103 /* PCI INTA-INTD */
104 /* route the interrupt */
Graeme Russ0c5ced72010-04-24 00:05:37 +1000105 writeb(sc520_irq[irq].priority, &sc520_mmcr->pci_int_map[pci_pin]);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100106 } else {
107 /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
Graeme Russ0c5ced72010-04-24 00:05:37 +1000108 writeb(sc520_irq[irq].priority, &sc520_mmcr->gp_int_map[pci_pin - 4]);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100109
110 /* also set the polarity in this case */
Graeme Russ0c5ced72010-04-24 00:05:37 +1000111 tmpw = readw(&sc520_mmcr->intpinpol);
112 tmpw |= (1 << (pci_pin-4));
113 writew(tmpw, &sc520_mmcr->intpinpol);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100114 }
115
116 /* register the pin */
117 sc520_pci_ints[pci_pin] = irq;
118
119
120 return 0; /* OK */
121}
122
123void pci_sc520_init(struct pci_controller *hose)
124{
125 hose->first_busno = 0;
126 hose->last_busno = 0xff;
127
128 /* System memory space */
129 pci_set_region(hose->regions + 0,
130 SC520_PCI_MEMORY_BUS,
131 SC520_PCI_MEMORY_PHYS,
132 SC520_PCI_MEMORY_SIZE,
Graeme Russd0811ab2009-08-23 12:59:50 +1000133 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100134
135 /* PCI memory space */
136 pci_set_region(hose->regions + 1,
137 SC520_PCI_MEM_BUS,
138 SC520_PCI_MEM_PHYS,
139 SC520_PCI_MEM_SIZE,
140 PCI_REGION_MEM);
141
142 /* ISA/PCI memory space */
143 pci_set_region(hose->regions + 2,
144 SC520_ISA_MEM_BUS,
145 SC520_ISA_MEM_PHYS,
146 SC520_ISA_MEM_SIZE,
147 PCI_REGION_MEM);
148
149 /* PCI I/O space */
150 pci_set_region(hose->regions + 3,
151 SC520_PCI_IO_BUS,
152 SC520_PCI_IO_PHYS,
153 SC520_PCI_IO_SIZE,
154 PCI_REGION_IO);
155
156 /* ISA/PCI I/O space */
157 pci_set_region(hose->regions + 4,
158 SC520_ISA_IO_BUS,
159 SC520_ISA_IO_PHYS,
160 SC520_ISA_IO_SIZE,
161 PCI_REGION_IO);
162
163 hose->region_count = 5;
164
165 pci_setup_type1(hose,
166 SC520_REG_ADDR,
167 SC520_REG_DATA);
168
169 pci_register_hose(hose);
170
171 hose->last_busno = pci_hose_scan(hose);
172
173 /* enable target memory acceses on host brige */
174 pci_write_config_word(0, PCI_COMMAND,
175 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
176
177}