3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
7 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
10 * Texas Instruments, <www.ti.com>
11 * Kshitij Gupta <Kshitij@ti.com>
15 * Philippe Robin, <philippe.robin@arm.com>
17 * See file CREDITS for list of people who contributed to this
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of
23 * the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
40 * Initialize PCI Devices, report devices found.
43 #ifndef CONFIG_PCI_PNP
44 static 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
,
48 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
}},
51 #endif /* CONFIG_PCI_PNP */
53 /* V3 access routines */
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)))
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)))
60 /* Compute address necessary to access PCI config space for the given */
62 #define PCI_CONFIG_ADDRESS( __bus, __devfn, __offset ) ({ \
63 unsigned int __address, __devicebit; \
64 unsigned short __mapaddress; \
65 unsigned int __dev = PCI_DEV (__devfn); /* FIXME to check!! (slot?) */ \
68 /* local bus segment so need a type 0 config cycle */ \
69 /* build the PCI configuration "address" with one-hot in A31-A11 */ \
70 __address = PCI_CONFIG_BASE; \
71 __address |= ((__devfn & 0x07) << 8); \
72 __address |= __offset & 0xFF; \
73 __mapaddress = 0x000A; /* 101=>config cycle, 0=>A1=A0=0 */ \
74 __devicebit = (1 << (__dev + 11)); \
76 if ((__devicebit & 0xFF000000) != 0) { \
77 /* high order bits are handled by the MAP register */ \
78 __mapaddress |= (__devicebit >> 16); \
80 /* low order bits handled directly in the address */ \
81 __address |= __devicebit; \
83 } else { /* bus !=0 */ \
84 /* not the local bus segment so need a type 1 config cycle */ \
85 /* A31-A24 are don't care (so clear to 0) */ \
86 __mapaddress = 0x000B; /* 101=>config cycle, 1=>A1&A0 from PCI_CFG */ \
87 __address = PCI_CONFIG_BASE; \
88 __address |= ((__bus & 0xFF) << 16); /* bits 23..16 = bus number */ \
89 __address |= ((__dev & 0x1F) << 11); /* bits 15..11 = device number */ \
90 __address |= ((__devfn & 0x07) << 8); /* bits 10..8 = function number */ \
91 __address |= __offset & 0xFF; /* bits 7..0 = register number */ \
93 _V3Write16 (V3_LB_MAP1, __mapaddress); \
97 /* _V3OpenConfigWindow - open V3 configuration window */
98 #define _V3OpenConfigWindow() { \
99 /* Set up base0 to see all 512Mbytes of memory space (not */ \
100 /* prefetchable), this frees up base1 for re-use by configuration*/ \
103 _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
104 0x90 | V3_LB_BASE_M_ENABLE)); \
105 /* Set up base1 to point into configuration space, note that MAP1 */ \
106 /* register is set up by pciMakeConfigAddress(). */ \
108 _V3Write32 (V3_LB_BASE1, ((CPU_PCI_CNFG_ADRS & 0xFFF00000) | \
109 0x40 | V3_LB_BASE_M_ENABLE)); \
112 /* _V3CloseConfigWindow - close V3 configuration window */
113 #define _V3CloseConfigWindow() { \
114 /* Reassign base1 for use by prefetchable PCI memory */ \
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); \
120 /* And shrink base0 back to a 256M window (NOTE: MAP0 already correct) */ \
122 _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
123 0x80 | V3_LB_BASE_M_ENABLE)); \
126 static int pci_integrator_read_byte (struct pci_controller
*hose
, pci_dev_t dev
,
127 int offset
, unsigned char *val
)
129 _V3OpenConfigWindow ();
130 *val
= *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
133 _V3CloseConfigWindow ();
138 static int pci_integrator_read__word (struct pci_controller
*hose
,
139 pci_dev_t dev
, int offset
,
142 _V3OpenConfigWindow ();
143 *val
= *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
146 _V3CloseConfigWindow ();
151 static int pci_integrator_read_dword (struct pci_controller
*hose
,
152 pci_dev_t dev
, int offset
,
155 _V3OpenConfigWindow ();
156 *val
= *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
159 *val
|= (*(volatile unsigned int *)
160 PCI_CONFIG_ADDRESS (PCI_BUS (dev
), PCI_FUNC (dev
),
161 (offset
+ 2))) << 16;
162 _V3CloseConfigWindow ();
167 static int pci_integrator_write_byte (struct pci_controller
*hose
,
168 pci_dev_t dev
, int offset
,
171 _V3OpenConfigWindow ();
172 *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
175 _V3CloseConfigWindow ();
180 static int pci_integrator_write_word (struct pci_controller
*hose
,
181 pci_dev_t dev
, int offset
,
184 _V3OpenConfigWindow ();
185 *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
188 _V3CloseConfigWindow ();
193 static int pci_integrator_write_dword (struct pci_controller
*hose
,
194 pci_dev_t dev
, int offset
,
197 _V3OpenConfigWindow ();
198 *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
200 offset
) = (val
& 0xFFFF);
201 *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev
),
203 (offset
+ 2)) = ((val
>> 16) & 0xFFFF);
204 _V3CloseConfigWindow ();
208 /******************************
210 ******************************/
212 struct pci_controller integrator_hose
= {
213 #ifndef CONFIG_PCI_PNP
214 config_table
: pci_integrator_config_table
,
218 void pci_init_board (void)
221 struct pci_controller
*hose
= &integrator_hose
;
223 /* setting this register will take the V3 out of reset */
225 *(volatile unsigned int *) (INTEGRATOR_SC_PCIENABLE
) = 1;
227 /* wait a few usecs to settle the device and the PCI bus */
229 for (i
= 0; i
< 100; i
++)
232 /* Now write the Base I/O Address Word to V3_BASE + 0x6C */
234 *(volatile unsigned short *) (V3_BASE
+ V3_LB_IO_BASE
) =
235 (unsigned short) (V3_BASE
>> 16);
238 *(volatile unsigned char *) (V3_BASE
+ V3_MAIL_DATA
) = 0xAA;
239 *(volatile unsigned char *) (V3_BASE
+ V3_MAIL_DATA
+ 4) =
241 } while (*(volatile unsigned char *) (V3_BASE
+ V3_MAIL_DATA
) != 0xAA
242 || *(volatile unsigned char *) (V3_BASE
+ V3_MAIL_DATA
+
245 /* Make sure that V3 register access is not locked, if it is, unlock it */
247 if ((*(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
) &
250 *(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
) = 0xA05F;
252 /* Ensure that the slave accesses from PCI are disabled while we */
255 *(volatile unsigned short *) (V3_BASE
+ V3_PCI_CMD
) &=
256 ~(V3_COMMAND_M_MEM_EN
| V3_COMMAND_M_IO_EN
);
258 /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */
260 *(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
) &=
261 ~V3_SYSTEM_M_RST_OUT
;
263 /* Make all accesses from PCI space retry until we're ready for them */
265 *(volatile unsigned short *) (V3_BASE
+ V3_PCI_CFG
) |=
266 V3_PCI_CFG_M_RETRY_EN
;
268 /* Set up any V3 PCI Configuration Registers that we absolutely have to */
269 /* LB_CFG controls Local Bus protocol. */
270 /* Enable LocalBus byte strobes for READ accesses too. */
271 /* set bit 7 BE_IMODE and bit 6 BE_OMODE */
273 *(volatile unsigned short *) (V3_BASE
+ V3_LB_CFG
) |= 0x0C0;
275 /* PCI_CMD controls overall PCI operation. */
276 /* Enable PCI bus master. */
278 *(volatile unsigned short *) (V3_BASE
+ V3_PCI_CMD
) |= 0x04;
280 /* PCI_MAP0 controls where the PCI to CPU memory window is on Local Bus */
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
);
287 /* PCI_BASE0 is the PCI address of the start of the window */
289 *(volatile unsigned int *) (V3_BASE
+ V3_PCI_BASE0
) =
290 INTEGRATOR_BOOT_ROM_BASE
;
292 /* PCI_MAP1 is LOCAL address of the start of the window */
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
);
299 /* PCI_BASE1 is the PCI address of the start of the window */
301 *(volatile unsigned int *) (V3_BASE
+ V3_PCI_BASE1
) =
302 INTEGRATOR_HDR0_SDRAM_BASE
;
304 /* Set up the windows from local bus memory into PCI configuration, */
305 /* I/O and Memory. */
306 /* PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. */
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;
312 /* PCI Configuration, use LB_BASE1/LB_MAP1. */
314 /* PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 */
315 /* Map first 256Mbytes as non-prefetchable via BASE0/MAP0 */
316 /* (INTEGRATOR_PCI_BASE == PCI_MEM_BASE) */
318 *(volatile unsigned int *) (V3_BASE
+ V3_LB_BASE0
) =
319 INTEGRATOR_PCI_BASE
| (0x80 | V3_LB_BASE_M_ENABLE
);
321 *(volatile unsigned short *) (V3_BASE
+ V3_LB_MAP0
) =
322 ((INTEGRATOR_PCI_BASE
>> 20) << 0x4) | 0x0006;
324 /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */
326 *(volatile unsigned int *) (V3_BASE
+ V3_LB_BASE1
) =
327 INTEGRATOR_PCI_BASE
| (0x84 | V3_LB_BASE_M_ENABLE
);
329 *(volatile unsigned short *) (V3_BASE
+ V3_LB_MAP1
) =
330 (((INTEGRATOR_PCI_BASE
+ 0x10000000) >> 20) << 4) | 0x0006;
332 /* Allow accesses to PCI Configuration space */
333 /* and set up A1, A0 for type 1 config cycles */
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
;
340 /* now we can allow in PCI MEMORY accesses */
342 *(volatile unsigned short *) (V3_BASE
+ V3_PCI_CMD
) =
343 (*(volatile unsigned short *) (V3_BASE
+ V3_PCI_CMD
)) |
346 /* Set RST_OUT to take the PCI bus is out of reset, PCI devices can */
347 /* initialise and lock the V3 system register so that no one else */
348 /* can play with it */
350 *(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
) =
351 (*(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
)) |
354 *(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
) =
355 (*(volatile unsigned short *) (V3_BASE
+ V3_SYSTEM
)) |
361 hose
->first_busno
= 0;
362 hose
->last_busno
= 0xff;
364 /* System memory space */
365 pci_set_region (hose
->regions
+ 0,
366 0x00000000, 0x40000000, 0x01000000,
367 PCI_REGION_MEM
| PCI_REGION_SYS_MEMORY
);
369 /* PCI Memory - config space */
370 pci_set_region (hose
->regions
+ 1,
371 0x00000000, 0x62000000, 0x01000000, PCI_REGION_MEM
);
374 pci_set_region (hose
->regions
+ 2,
375 0x00000000, 0x61000000, 0x00080000, PCI_REGION_MEM
);
378 pci_set_region (hose
->regions
+ 3,
379 0x00000000, 0x60000000, 0x00010000, PCI_REGION_IO
);
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
);
388 hose
->region_count
= 4;
390 pci_register_hose (hose
);
392 pciauto_config_init (hose
);
393 pciauto_config_device (hose
, 0);
395 hose
->last_busno
= pci_hose_scan (hose
);