xref: /openbmc/u-boot/arch/powerpc/cpu/mpc85xx/pci.c (revision e8f80a5a)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3a47a12beSStefan Roese  * Copyright 2004 Freescale Semiconductor.
4a47a12beSStefan Roese  * Copyright (C) 2003 Motorola Inc.
5a47a12beSStefan Roese  * Xianghua Xiao (x.xiao@motorola.com)
6a47a12beSStefan Roese  */
7a47a12beSStefan Roese 
8a47a12beSStefan Roese /*
9a47a12beSStefan Roese  * PCI Configuration space access support for MPC85xx PCI Bridge
10a47a12beSStefan Roese  */
11a47a12beSStefan Roese #include <common.h>
12a47a12beSStefan Roese #include <asm/cpm_85xx.h>
13a47a12beSStefan Roese #include <pci.h>
14a47a12beSStefan Roese 
15a47a12beSStefan Roese #if !defined(CONFIG_FSL_PCI_INIT)
16a47a12beSStefan Roese 
17a47a12beSStefan Roese #ifndef CONFIG_SYS_PCI1_MEM_BUS
18a47a12beSStefan Roese #define CONFIG_SYS_PCI1_MEM_BUS CONFIG_SYS_PCI1_MEM_BASE
19a47a12beSStefan Roese #endif
20a47a12beSStefan Roese 
21a47a12beSStefan Roese #ifndef CONFIG_SYS_PCI1_IO_BUS
22a47a12beSStefan Roese #define CONFIG_SYS_PCI1_IO_BUS CONFIG_SYS_PCI1_IO_BASE
23a47a12beSStefan Roese #endif
24a47a12beSStefan Roese 
25a47a12beSStefan Roese #ifndef CONFIG_SYS_PCI2_MEM_BUS
26a47a12beSStefan Roese #define CONFIG_SYS_PCI2_MEM_BUS CONFIG_SYS_PCI2_MEM_BASE
27a47a12beSStefan Roese #endif
28a47a12beSStefan Roese 
29a47a12beSStefan Roese #ifndef CONFIG_SYS_PCI2_IO_BUS
30a47a12beSStefan Roese #define CONFIG_SYS_PCI2_IO_BUS CONFIG_SYS_PCI2_IO_BASE
31a47a12beSStefan Roese #endif
32a47a12beSStefan Roese 
33a47a12beSStefan Roese static struct pci_controller *pci_hose;
34a47a12beSStefan Roese 
35a47a12beSStefan Roese void
pci_mpc85xx_init(struct pci_controller * board_hose)36a47a12beSStefan Roese pci_mpc85xx_init(struct pci_controller *board_hose)
37a47a12beSStefan Roese {
38a47a12beSStefan Roese 	u16 reg16;
39a47a12beSStefan Roese 	u32 dev;
40a47a12beSStefan Roese 
41a47a12beSStefan Roese 	volatile ccsr_pcix_t *pcix = (void *)(CONFIG_SYS_MPC85xx_PCIX_ADDR);
42a47a12beSStefan Roese #ifdef CONFIG_MPC85XX_PCI2
43a47a12beSStefan Roese 	volatile ccsr_pcix_t *pcix2 = (void *)(CONFIG_SYS_MPC85xx_PCIX2_ADDR);
44a47a12beSStefan Roese #endif
45a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
46a47a12beSStefan Roese 	struct pci_controller * hose;
47a47a12beSStefan Roese 
48a47a12beSStefan Roese 	pci_hose = board_hose;
49a47a12beSStefan Roese 
50a47a12beSStefan Roese 	hose = &pci_hose[0];
51a47a12beSStefan Roese 
52a47a12beSStefan Roese 	hose->first_busno = 0;
53a47a12beSStefan Roese 	hose->last_busno = 0xff;
54a47a12beSStefan Roese 
55a47a12beSStefan Roese 	pci_setup_indirect(hose,
56a47a12beSStefan Roese 			   (CONFIG_SYS_IMMR+0x8000),
57a47a12beSStefan Roese 			   (CONFIG_SYS_IMMR+0x8004));
58a47a12beSStefan Roese 
59a47a12beSStefan Roese 	/*
60a47a12beSStefan Roese 	 * Hose scan.
61a47a12beSStefan Roese 	 */
62a47a12beSStefan Roese 	dev = PCI_BDF(hose->first_busno, 0, 0);
63a47a12beSStefan Roese 	pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
64a47a12beSStefan Roese 	reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
65a47a12beSStefan Roese 	pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
66a47a12beSStefan Roese 
67a47a12beSStefan Roese 	/*
68a47a12beSStefan Roese 	 * Clear non-reserved bits in status register.
69a47a12beSStefan Roese 	 */
70a47a12beSStefan Roese 	pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
71a47a12beSStefan Roese 
72a47a12beSStefan Roese 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
73a47a12beSStefan Roese 		/* PCI-X init */
74a47a12beSStefan Roese 		if (CONFIG_SYS_CLK_FREQ < 66000000)
75a47a12beSStefan Roese 			printf("PCI-X will only work at 66 MHz\n");
76a47a12beSStefan Roese 
77a47a12beSStefan Roese 		reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
78a47a12beSStefan Roese 			| PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
79a47a12beSStefan Roese 		pci_hose_write_config_word(hose, dev, PCIX_COMMAND, reg16);
80a47a12beSStefan Roese 	}
81a47a12beSStefan Roese 
82a47a12beSStefan Roese 	pcix->potar1   = (CONFIG_SYS_PCI1_MEM_BUS >> 12) & 0x000fffff;
83a47a12beSStefan Roese 	pcix->potear1  = 0x00000000;
84a47a12beSStefan Roese 	pcix->powbar1  = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & 0x000fffff;
85a47a12beSStefan Roese 	pcix->powbear1 = 0x00000000;
86a47a12beSStefan Roese 	pcix->powar1 = (POWAR_EN | POWAR_MEM_READ |
87a47a12beSStefan Roese 			POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI1_MEM_SIZE) - 1));
88a47a12beSStefan Roese 
89a47a12beSStefan Roese 	pcix->potar2  = (CONFIG_SYS_PCI1_IO_BUS >> 12) & 0x000fffff;
90a47a12beSStefan Roese 	pcix->potear2  = 0x00000000;
91a47a12beSStefan Roese 	pcix->powbar2  = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & 0x000fffff;
92a47a12beSStefan Roese 	pcix->powbear2 = 0x00000000;
93a47a12beSStefan Roese 	pcix->powar2 = (POWAR_EN | POWAR_IO_READ |
94a47a12beSStefan Roese 			POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI1_IO_SIZE) - 1));
95a47a12beSStefan Roese 
96a47a12beSStefan Roese 	pcix->pitar1 = 0x00000000;
97a47a12beSStefan Roese 	pcix->piwbar1 = 0x00000000;
98a47a12beSStefan Roese 	pcix->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
99a47a12beSStefan Roese 			PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
100a47a12beSStefan Roese 
101a47a12beSStefan Roese 	pcix->powar3 = 0;
102a47a12beSStefan Roese 	pcix->powar4 = 0;
103a47a12beSStefan Roese 	pcix->piwar2 = 0;
104a47a12beSStefan Roese 	pcix->piwar3 = 0;
105a47a12beSStefan Roese 
106a47a12beSStefan Roese 	pci_set_region(hose->regions + 0,
107a47a12beSStefan Roese 		       CONFIG_SYS_PCI1_MEM_BUS,
108a47a12beSStefan Roese 		       CONFIG_SYS_PCI1_MEM_PHYS,
109a47a12beSStefan Roese 		       CONFIG_SYS_PCI1_MEM_SIZE,
110a47a12beSStefan Roese 		       PCI_REGION_MEM);
111a47a12beSStefan Roese 
112a47a12beSStefan Roese 	pci_set_region(hose->regions + 1,
113a47a12beSStefan Roese 		       CONFIG_SYS_PCI1_IO_BUS,
114a47a12beSStefan Roese 		       CONFIG_SYS_PCI1_IO_PHYS,
115a47a12beSStefan Roese 		       CONFIG_SYS_PCI1_IO_SIZE,
116a47a12beSStefan Roese 		       PCI_REGION_IO);
117a47a12beSStefan Roese 
118a47a12beSStefan Roese 	hose->region_count = 2;
119a47a12beSStefan Roese 
120a47a12beSStefan Roese 	pci_register_hose(hose);
121a47a12beSStefan Roese 
1222f2d54b7SYork Sun #if defined(CONFIG_TARGET_MPC8555CDS) || defined(CONFIG_TARGET_MPC8541CDS)
123a47a12beSStefan Roese 	/*
124a47a12beSStefan Roese 	 * This is a SW workaround for an apparent HW problem
125a47a12beSStefan Roese 	 * in the PCI controller on the MPC85555/41 CDS boards.
126a47a12beSStefan Roese 	 * The first config cycle must be to a valid, known
127a47a12beSStefan Roese 	 * device on the PCI bus in order to trick the PCI
128a47a12beSStefan Roese 	 * controller state machine into a known valid state.
129a47a12beSStefan Roese 	 * Without this, the first config cycle has the chance
130a47a12beSStefan Roese 	 * of hanging the controller permanently, just leaving
131a47a12beSStefan Roese 	 * it in a semi-working state, or leaving it working.
132a47a12beSStefan Roese 	 *
133a47a12beSStefan Roese 	 * Pick on the Tundra, Device 17, to get it right.
134a47a12beSStefan Roese 	 */
135a47a12beSStefan Roese 	{
136a47a12beSStefan Roese 		u8 header_type;
137a47a12beSStefan Roese 
138a47a12beSStefan Roese 		pci_hose_read_config_byte(hose,
139a47a12beSStefan Roese 					  PCI_BDF(0,BRIDGE_ID,0),
140a47a12beSStefan Roese 					  PCI_HEADER_TYPE,
141a47a12beSStefan Roese 					  &header_type);
142a47a12beSStefan Roese 	}
143a47a12beSStefan Roese #endif
144a47a12beSStefan Roese 
145a47a12beSStefan Roese 	hose->last_busno = pci_hose_scan(hose);
146a47a12beSStefan Roese 
147a47a12beSStefan Roese #ifdef CONFIG_MPC85XX_PCI2
148a47a12beSStefan Roese 	hose = &pci_hose[1];
149a47a12beSStefan Roese 
150a47a12beSStefan Roese 	hose->first_busno = pci_hose[0].last_busno + 1;
151a47a12beSStefan Roese 	hose->last_busno = 0xff;
152a47a12beSStefan Roese 
153a47a12beSStefan Roese 	pci_setup_indirect(hose,
154a47a12beSStefan Roese 			   (CONFIG_SYS_IMMR+0x9000),
155a47a12beSStefan Roese 			   (CONFIG_SYS_IMMR+0x9004));
156a47a12beSStefan Roese 
157a47a12beSStefan Roese 	dev = PCI_BDF(hose->first_busno, 0, 0);
158a47a12beSStefan Roese 	pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
159a47a12beSStefan Roese 	reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
160a47a12beSStefan Roese 	pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
161a47a12beSStefan Roese 
162a47a12beSStefan Roese 	/*
163a47a12beSStefan Roese 	 * Clear non-reserved bits in status register.
164a47a12beSStefan Roese 	 */
165a47a12beSStefan Roese 	pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
166a47a12beSStefan Roese 
167a47a12beSStefan Roese 	pcix2->potar1   = (CONFIG_SYS_PCI2_MEM_BUS >> 12) & 0x000fffff;
168a47a12beSStefan Roese 	pcix2->potear1  = 0x00000000;
169a47a12beSStefan Roese 	pcix2->powbar1  = (CONFIG_SYS_PCI2_MEM_PHYS >> 12) & 0x000fffff;
170a47a12beSStefan Roese 	pcix2->powbear1 = 0x00000000;
171a47a12beSStefan Roese 	pcix2->powar1 = (POWAR_EN | POWAR_MEM_READ |
172a47a12beSStefan Roese 			POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI2_MEM_SIZE) - 1));
173a47a12beSStefan Roese 
174a47a12beSStefan Roese 	pcix2->potar2  = (CONFIG_SYS_PCI2_IO_BUS >> 12) & 0x000fffff;
175a47a12beSStefan Roese 	pcix2->potear2  = 0x00000000;
176a47a12beSStefan Roese 	pcix2->powbar2  = (CONFIG_SYS_PCI2_IO_PHYS >> 12) & 0x000fffff;
177a47a12beSStefan Roese 	pcix2->powbear2 = 0x00000000;
178a47a12beSStefan Roese 	pcix2->powar2 = (POWAR_EN | POWAR_IO_READ |
179a47a12beSStefan Roese 			POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI2_IO_SIZE) - 1));
180a47a12beSStefan Roese 
181a47a12beSStefan Roese 	pcix2->pitar1 = 0x00000000;
182a47a12beSStefan Roese 	pcix2->piwbar1 = 0x00000000;
183a47a12beSStefan Roese 	pcix2->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
184a47a12beSStefan Roese 			PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
185a47a12beSStefan Roese 
186a47a12beSStefan Roese 	pcix2->powar3 = 0;
187a47a12beSStefan Roese 	pcix2->powar4 = 0;
188a47a12beSStefan Roese 	pcix2->piwar2 = 0;
189a47a12beSStefan Roese 	pcix2->piwar3 = 0;
190a47a12beSStefan Roese 
191a47a12beSStefan Roese 	pci_set_region(hose->regions + 0,
192a47a12beSStefan Roese 		       CONFIG_SYS_PCI2_MEM_BUS,
193a47a12beSStefan Roese 		       CONFIG_SYS_PCI2_MEM_PHYS,
194a47a12beSStefan Roese 		       CONFIG_SYS_PCI2_MEM_SIZE,
195a47a12beSStefan Roese 		       PCI_REGION_MEM);
196a47a12beSStefan Roese 
197a47a12beSStefan Roese 	pci_set_region(hose->regions + 1,
198a47a12beSStefan Roese 		       CONFIG_SYS_PCI2_IO_BUS,
199a47a12beSStefan Roese 		       CONFIG_SYS_PCI2_IO_PHYS,
200a47a12beSStefan Roese 		       CONFIG_SYS_PCI2_IO_SIZE,
201a47a12beSStefan Roese 		       PCI_REGION_IO);
202a47a12beSStefan Roese 
203a47a12beSStefan Roese 	hose->region_count = 2;
204a47a12beSStefan Roese 
205a47a12beSStefan Roese 	/*
206a47a12beSStefan Roese 	 * Hose scan.
207a47a12beSStefan Roese 	 */
208a47a12beSStefan Roese 	pci_register_hose(hose);
209a47a12beSStefan Roese 
210a47a12beSStefan Roese 	hose->last_busno = pci_hose_scan(hose);
211a47a12beSStefan Roese #endif
212a47a12beSStefan Roese }
213a47a12beSStefan Roese #endif /* !CONFIG_FSL_PCI_INIT */
214