1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <common.h>
37#include <pci.h>
38
39
40
41
42
43#ifndef CONFIG_PCI_PNP
44static struct pci_config_table pci_integrator_config_table[] = {
45 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
46 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
47 PCI_ENET0_MEMADDR,
48 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
49 { }
50};
51#endif
52
53
54#define _V3Write16(o,v) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned short)(v))
55#define _V3Read16(o) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)))
56
57#define _V3Write32(o,v) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned int)(v))
58#define _V3Read32(o) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)))
59
60
61
62#define PCI_CONFIG_ADDRESS( __bus, __devfn, __offset ) ({ \
63 unsigned int __address, __devicebit; \
64 unsigned short __mapaddress; \
65 unsigned int __dev = PCI_DEV (__devfn); \
66 \
67 if (__bus == 0) { \
68 \
69 \
70 __address = PCI_CONFIG_BASE; \
71 __address |= ((__devfn & 0x07) << 8); \
72 __address |= __offset & 0xFF; \
73 __mapaddress = 0x000A; \
74 __devicebit = (1 << (__dev + 11)); \
75 \
76 if ((__devicebit & 0xFF000000) != 0) { \
77 \
78 __mapaddress |= (__devicebit >> 16); \
79 } else { \
80 \
81 __address |= __devicebit; \
82 } \
83 } else { \
84 \
85 \
86 __mapaddress = 0x000B; \
87 __address = PCI_CONFIG_BASE; \
88 __address |= ((__bus & 0xFF) << 16); \
89 __address |= ((__dev & 0x1F) << 11); \
90 __address |= ((__devfn & 0x07) << 8); \
91 __address |= __offset & 0xFF; \
92 } \
93 _V3Write16 (V3_LB_MAP1, __mapaddress); \
94 __address; \
95})
96
97
98#define _V3OpenConfigWindow() { \
99 \
100 \
101 \
102 \
103 _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
104 0x90 | V3_LB_BASE_M_ENABLE)); \
105 \
106 \
107 \
108 _V3Write32 (V3_LB_BASE1, ((CPU_PCI_CNFG_ADRS & 0xFFF00000) | \
109 0x40 | V3_LB_BASE_M_ENABLE)); \
110}
111
112
113#define _V3CloseConfigWindow() { \
114 \
115 _V3Write32 (V3_LB_BASE1, (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) \
116 | 0x84 | V3_LB_BASE_M_ENABLE)); \
117 _V3Write16 (V3_LB_MAP1, \
118 (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) >> 16) | 0x0006); \
119 \
120 \
121 \
122 _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
123 0x80 | V3_LB_BASE_M_ENABLE)); \
124}
125
126static int pci_integrator_read_byte (struct pci_controller *hose, pci_dev_t dev,
127 int offset, unsigned char *val)
128{
129 _V3OpenConfigWindow ();
130 *val = *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
131 PCI_FUNC (dev),
132 offset);
133 _V3CloseConfigWindow ();
134
135 return 0;
136}
137
138static int pci_integrator_read__word (struct pci_controller *hose,
139 pci_dev_t dev, int offset,
140 unsigned short *val)
141{
142 _V3OpenConfigWindow ();
143 *val = *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
144 PCI_FUNC (dev),
145 offset);
146 _V3CloseConfigWindow ();
147
148 return 0;
149}
150
151static int pci_integrator_read_dword (struct pci_controller *hose,
152 pci_dev_t dev, int offset,
153 unsigned int *val)
154{
155 _V3OpenConfigWindow ();
156 *val = *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
157 PCI_FUNC (dev),
158 offset);
159 *val |= (*(volatile unsigned int *)
160 PCI_CONFIG_ADDRESS (PCI_BUS (dev), PCI_FUNC (dev),
161 (offset + 2))) << 16;
162 _V3CloseConfigWindow ();
163
164 return 0;
165}
166
167static int pci_integrator_write_byte (struct pci_controller *hose,
168 pci_dev_t dev, int offset,
169 unsigned char val)
170{
171 _V3OpenConfigWindow ();
172 *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
173 PCI_FUNC (dev),
174 offset) = val;
175 _V3CloseConfigWindow ();
176
177 return 0;
178}
179
180static int pci_integrator_write_word (struct pci_controller *hose,
181 pci_dev_t dev, int offset,
182 unsigned short val)
183{
184 _V3OpenConfigWindow ();
185 *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
186 PCI_FUNC (dev),
187 offset) = val;
188 _V3CloseConfigWindow ();
189
190 return 0;
191}
192
193static int pci_integrator_write_dword (struct pci_controller *hose,
194 pci_dev_t dev, int offset,
195 unsigned int val)
196{
197 _V3OpenConfigWindow ();
198 *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
199 PCI_FUNC (dev),
200 offset) = (val & 0xFFFF);
201 *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
202 PCI_FUNC (dev),
203 (offset + 2)) = ((val >> 16) & 0xFFFF);
204 _V3CloseConfigWindow ();
205
206 return 0;
207}
208
209
210
211
212struct pci_controller integrator_hose = {
213#ifndef CONFIG_PCI_PNP
214 config_table: pci_integrator_config_table,
215#endif
216};
217
218void pci_init_board (void)
219{
220 volatile int i, j;
221 struct pci_controller *hose = &integrator_hose;
222
223
224
225 *(volatile unsigned int *) (INTEGRATOR_SC_PCIENABLE) = 1;
226
227
228
229 for (i = 0; i < 100; i++)
230 j = i + 1;
231
232
233
234 *(volatile unsigned short *) (V3_BASE + V3_LB_IO_BASE) =
235 (unsigned short) (V3_BASE >> 16);
236
237 do {
238 *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA) = 0xAA;
239 *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA + 4) =
240 0x55;
241 } while (*(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA) != 0xAA
242 || *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA +
243 4) != 0x55);
244
245
246
247 if ((*(volatile unsigned short *) (V3_BASE + V3_SYSTEM) &
248 V3_SYSTEM_M_LOCK)
249 == V3_SYSTEM_M_LOCK)
250 *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) = 0xA05F;
251
252
253
254
255 *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) &=
256 ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN);
257
258
259
260 *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) &=
261 ~V3_SYSTEM_M_RST_OUT;
262
263
264
265 *(volatile unsigned short *) (V3_BASE + V3_PCI_CFG) |=
266 V3_PCI_CFG_M_RETRY_EN;
267
268
269
270
271
272
273 *(volatile unsigned short *) (V3_BASE + V3_LB_CFG) |= 0x0C0;
274
275
276
277
278 *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) |= 0x04;
279
280
281
282 *(volatile unsigned int *) (V3_BASE + V3_PCI_MAP0) =
283 (INTEGRATOR_BOOT_ROM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_512M |
284 V3_PCI_MAP_M_REG_EN |
285 V3_PCI_MAP_M_ENABLE);
286
287
288
289 *(volatile unsigned int *) (V3_BASE + V3_PCI_BASE0) =
290 INTEGRATOR_BOOT_ROM_BASE;
291
292
293
294 *(volatile unsigned int *) (V3_BASE + V3_PCI_MAP1) =
295 (INTEGRATOR_HDR0_SDRAM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_1024M |
296 V3_PCI_MAP_M_REG_EN |
297 V3_PCI_MAP_M_ENABLE);
298
299
300
301 *(volatile unsigned int *) (V3_BASE + V3_PCI_BASE1) =
302 INTEGRATOR_HDR0_SDRAM_BASE;
303
304
305
306
307
308 *(volatile unsigned short *) (V3_BASE + V3_LB_BASE2) =
309 ((CPU_PCI_IO_ADRS >> 24) << 8) | V3_LB_BASE_M_ENABLE;
310 *(volatile unsigned short *) (V3_BASE + V3_LB_MAP2) = 0;
311
312
313
314
315
316
317
318 *(volatile unsigned int *) (V3_BASE + V3_LB_BASE0) =
319 INTEGRATOR_PCI_BASE | (0x80 | V3_LB_BASE_M_ENABLE);
320
321 *(volatile unsigned short *) (V3_BASE + V3_LB_MAP0) =
322 ((INTEGRATOR_PCI_BASE >> 20) << 0x4) | 0x0006;
323
324
325
326 *(volatile unsigned int *) (V3_BASE + V3_LB_BASE1) =
327 INTEGRATOR_PCI_BASE | (0x84 | V3_LB_BASE_M_ENABLE);
328
329 *(volatile unsigned short *) (V3_BASE + V3_LB_MAP1) =
330 (((INTEGRATOR_PCI_BASE + 0x10000000) >> 20) << 4) | 0x0006;
331
332
333
334
335 *(volatile unsigned short *) (V3_BASE + V3_PCI_CFG) =
336 ((*(volatile unsigned short *) (V3_BASE + V3_PCI_CFG)) &
337 ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1)) |
338 V3_PCI_CFG_M_AD_LOW0;
339
340
341
342 *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) =
343 (*(volatile unsigned short *) (V3_BASE + V3_PCI_CMD)) |
344 V3_COMMAND_M_MEM_EN;
345
346
347
348
349
350 *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) =
351 (*(volatile unsigned short *) (V3_BASE + V3_SYSTEM)) |
352 V3_SYSTEM_M_RST_OUT;
353
354 *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) =
355 (*(volatile unsigned short *) (V3_BASE + V3_SYSTEM)) |
356 V3_SYSTEM_M_LOCK;
357
358
359
360
361 hose->first_busno = 0;
362 hose->last_busno = 0xff;
363
364
365 pci_set_region (hose->regions + 0,
366 0x00000000, 0x40000000, 0x01000000,
367 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
368
369
370 pci_set_region (hose->regions + 1,
371 0x00000000, 0x62000000, 0x01000000, PCI_REGION_MEM);
372
373
374 pci_set_region (hose->regions + 2,
375 0x00000000, 0x61000000, 0x00080000, PCI_REGION_MEM);
376
377
378 pci_set_region (hose->regions + 3,
379 0x00000000, 0x60000000, 0x00010000, PCI_REGION_IO);
380
381 pci_set_ops (hose,
382 pci_integrator_read_byte,
383 pci_integrator_read__word,
384 pci_integrator_read_dword,
385 pci_integrator_write_byte,
386 pci_integrator_write_word, pci_integrator_write_dword);
387
388 hose->region_count = 4;
389
390 pci_register_hose (hose);
391
392 pciauto_config_init (hose);
393 pciauto_config_device (hose, 0);
394
395 hose->last_busno = pci_hose_scan (hose);
396}
397