blob: ccb79888dca5bf2d5818461c8d3d01d1af854ac6 [file] [log] [blame]
Graeme Russf50b6192009-08-23 12:59:57 +10001/*
2 *
3 * (C) Copyright 2002
4 * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <pci.h>
27#include <asm/io.h>
28#include <asm/pci.h>
29#include <asm/ic/sc520.h>
30#include <asm/ic/pci.h>
31
32DECLARE_GLOBAL_DATA_PTR;
33
34#undef SC520_CDP_DEBUG
35
36#ifdef SC520_CDP_DEBUG
37#define PRINTF(fmt,args...) printf (fmt ,##args)
38#else
39#define PRINTF(fmt,args...)
40#endif
41
42static void pci_sc520_cdp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
43{
44 /* a configurable lists of irqs to steal
45 * when we need one (a board with more pci interrupt pins
46 * would use a larger table */
47 static int irq_list[] = {
48 CONFIG_SYS_FIRST_PCI_IRQ,
49 CONFIG_SYS_SECOND_PCI_IRQ,
50 CONFIG_SYS_THIRD_PCI_IRQ,
51 CONFIG_SYS_FORTH_PCI_IRQ
52 };
53 static int next_irq_index=0;
54
55 uchar tmp_pin;
56 int pin;
57
58 pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
59 pin = tmp_pin;
60
61 pin-=1; /* pci config space use 1-based numbering */
62 if (-1 == pin) {
63 return; /* device use no irq */
64 }
65
66
67 /* map device number + pin to a pin on the sc520 */
68 switch (PCI_DEV(dev)) {
69 case 20:
70 pin+=SC520_PCI_INTA;
71 break;
72
73 case 19:
74 pin+=SC520_PCI_INTB;
75 break;
76
77 case 18:
78 pin+=SC520_PCI_INTC;
79 break;
80
81 case 17:
82 pin+=SC520_PCI_INTD;
83 break;
84
85 default:
86 return;
87 }
88
89 pin&=3; /* wrap around */
90
91 if (sc520_pci_ints[pin] == -1) {
92 /* re-route one interrupt for us */
93 if (next_irq_index > 3) {
94 return;
95 }
96 if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) {
97 return;
98 }
99 next_irq_index++;
100 }
101
102
103 if (-1 != sc520_pci_ints[pin]) {
104 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
105 sc520_pci_ints[pin]);
106 }
107 PRINTF("fixup_irq: device %d pin %c irq %d\n",
108 PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
109}
110
111static struct pci_controller sc520_cdp_hose = {
112 fixup_irq: pci_sc520_cdp_fixup_irq,
113};
114
115void pci_init_board(void)
116{
117 pci_sc520_init(&sc520_cdp_hose);
118}
119
120/*
121 * This function should map a chunk of size bytes
122 * of the system address space to the ISA bus
123 *
124 * The function will return the memory address
125 * as seen by the host (which may very will be the
126 * same as the bus address)
127 */
128u32 isa_map_rom(u32 bus_addr, int size)
129{
130 u32 par;
131
132 PRINTF("isa_map_rom asked to map %d bytes at %x\n",
133 size, bus_addr);
134
135 par = size;
136 if (par < 0x80000) {
137 par = 0x80000;
138 }
139 par >>= 12;
140 par--;
141 par&=0x7f;
142 par <<= 18;
143 par |= (bus_addr>>12);
144 par |= 0x50000000;
145
146 PRINTF ("setting PAR11 to %x\n", par);
147
148 /* Map rom 0x10000 with PAR1 */
149 sc520_mmcr->par[11] = par;
150
151 return bus_addr;
152}
153
154/*
155 * this function removed any mapping created
156 * with pci_get_rom_window()
157 */
158void isa_unmap_rom(u32 addr)
159{
160 PRINTF("isa_unmap_rom asked to unmap %x", addr);
161 if ((addr>>12) == (sc520_mmcr->par[11] & 0x3ffff)) {
162 sc520_mmcr->par[11] = 0;
163 PRINTF(" done\n");
164 return;
165 }
166 PRINTF(" not ours\n");
167}
168
169#define PCI_ROM_TEMP_SPACE 0x10000
170/*
171 * This function should map a chunk of size bytes
172 * of the system address space to the PCI bus,
173 * suitable to map PCI ROMS (bus address < 16M)
174 * the function will return the host memory address
175 * which should be converted into a bus address
176 * before used to configure the PCI rom address
177 * decoder
178 */
179u32 pci_get_rom_window(struct pci_controller *hose, int size)
180{
181 u32 par;
182
183 par = size;
184 if (par < 0x80000) {
185 par = 0x80000;
186 }
187 par >>= 16;
188 par--;
189 par&=0x7ff;
190 par <<= 14;
191 par |= (PCI_ROM_TEMP_SPACE>>16);
192 par |= 0x72000000;
193
194 PRINTF ("setting PAR1 to %x\n", par);
195
196 /* Map rom 0x10000 with PAR1 */
197 sc520_mmcr->par[1] = par;
198
199 return PCI_ROM_TEMP_SPACE;
200}
201
202/*
203 * this function removed any mapping created
204 * with pci_get_rom_window()
205 */
206void pci_remove_rom_window(struct pci_controller *hose, u32 addr)
207{
208 PRINTF("pci_remove_rom_window: %x", addr);
209 if (addr == PCI_ROM_TEMP_SPACE) {
210 sc520_mmcr->par[1] = 0;
211 PRINTF(" done\n");
212 return;
213 }
214 PRINTF(" not ours\n");
215
216}
217
218/*
219 * This function is called in order to provide acces to the
220 * legacy video I/O ports on the PCI bus.
221 * After this function accesses to I/O ports 0x3b0-0x3bb and
222 * 0x3c0-0x3df shuld result in transactions on the PCI bus.
223 *
224 */
225int pci_enable_legacy_video_ports(struct pci_controller *hose)
226{
227 /* Map video memory to 0xa0000*/
228 sc520_mmcr->par[0] = 0x7200400a;
229
230 /* forward all I/O accesses to PCI */
231 sc520_mmcr->adddecctl = sc520_mmcr->adddecctl | IO_HOLE_DEST_PCI;
232
233
234 /* so we map away all io ports to pci (only way to access pci io
235 * below 0x400. But then we have to map back the portions that we dont
236 * use so that the generate cycles on the GPIO bus where the sio and
237 * ISA slots are connected, this requre the use of several PAR registers
238 */
239
240 /* bring 0x100 - 0x1ef back to ISA using PAR5 */
241 sc520_mmcr->par[5] = 0x30ef0100;
242
243 /* IDE use 1f0-1f7 */
244
245 /* bring 0x1f8 - 0x2f7 back to ISA using PAR6 */
246 sc520_mmcr->par[6] = 0x30ff01f8;
247
248 /* com2 use 2f8-2ff */
249
250 /* bring 0x300 - 0x3af back to ISA using PAR7 */
251 sc520_mmcr->par[7] = 0x30af0300;
252
253 /* vga use 3b0-3bb */
254
255 /* bring 0x3bc - 0x3bf back to ISA using PAR8 */
256 sc520_mmcr->par[8] = 0x300303bc;
257
258 /* vga use 3c0-3df */
259
260 /* bring 0x3e0 - 0x3f5 back to ISA using PAR9 */
261 sc520_mmcr->par[9] = 0x301503e0;
262
263 /* ide use 3f6 */
264
265 /* bring 0x3f7 back to ISA using PAR10 */
266 sc520_mmcr->par[10] = 0x300003f7;
267
268 /* com1 use 3f8-3ff */
269
270 return 0;
271}