xref: /OK3568_Linux_fs/u-boot/board/freescale/mpc8349emds/pci.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <asm/mmu.h>
8*4882a593Smuzhiyun #include <asm/io.h>
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun #include <mpc83xx.h>
11*4882a593Smuzhiyun #include <pci.h>
12*4882a593Smuzhiyun #include <i2c.h>
13*4882a593Smuzhiyun #include <asm/fsl_i2c.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun static struct pci_region pci1_regions[] = {
18*4882a593Smuzhiyun 	{
19*4882a593Smuzhiyun 		bus_start: CONFIG_SYS_PCI1_MEM_BASE,
20*4882a593Smuzhiyun 		phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
21*4882a593Smuzhiyun 		size: CONFIG_SYS_PCI1_MEM_SIZE,
22*4882a593Smuzhiyun 		flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
23*4882a593Smuzhiyun 	},
24*4882a593Smuzhiyun 	{
25*4882a593Smuzhiyun 		bus_start: CONFIG_SYS_PCI1_IO_BASE,
26*4882a593Smuzhiyun 		phys_start: CONFIG_SYS_PCI1_IO_PHYS,
27*4882a593Smuzhiyun 		size: CONFIG_SYS_PCI1_IO_SIZE,
28*4882a593Smuzhiyun 		flags: PCI_REGION_IO
29*4882a593Smuzhiyun 	},
30*4882a593Smuzhiyun 	{
31*4882a593Smuzhiyun 		bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
32*4882a593Smuzhiyun 		phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
33*4882a593Smuzhiyun 		size: CONFIG_SYS_PCI1_MMIO_SIZE,
34*4882a593Smuzhiyun 		flags: PCI_REGION_MEM
35*4882a593Smuzhiyun 	},
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #ifdef CONFIG_MPC83XX_PCI2
39*4882a593Smuzhiyun static struct pci_region pci2_regions[] = {
40*4882a593Smuzhiyun 	{
41*4882a593Smuzhiyun 		bus_start: CONFIG_SYS_PCI2_MEM_BASE,
42*4882a593Smuzhiyun 		phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
43*4882a593Smuzhiyun 		size: CONFIG_SYS_PCI2_MEM_SIZE,
44*4882a593Smuzhiyun 		flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
45*4882a593Smuzhiyun 	},
46*4882a593Smuzhiyun 	{
47*4882a593Smuzhiyun 		bus_start: CONFIG_SYS_PCI2_IO_BASE,
48*4882a593Smuzhiyun 		phys_start: CONFIG_SYS_PCI2_IO_PHYS,
49*4882a593Smuzhiyun 		size: CONFIG_SYS_PCI2_IO_SIZE,
50*4882a593Smuzhiyun 		flags: PCI_REGION_IO
51*4882a593Smuzhiyun 	},
52*4882a593Smuzhiyun 	{
53*4882a593Smuzhiyun 		bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
54*4882a593Smuzhiyun 		phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
55*4882a593Smuzhiyun 		size: CONFIG_SYS_PCI2_MMIO_SIZE,
56*4882a593Smuzhiyun 		flags: PCI_REGION_MEM
57*4882a593Smuzhiyun 	},
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun #endif
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun #ifndef CONFIG_PCISLAVE
pib_init(void)62*4882a593Smuzhiyun void pib_init(void)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun 	u8 val8, orig_i2c_bus;
65*4882a593Smuzhiyun 	/*
66*4882a593Smuzhiyun 	 * Assign PIB PMC slot to desired PCI bus
67*4882a593Smuzhiyun 	 */
68*4882a593Smuzhiyun 	/* Switch temporarily to I2C bus #2 */
69*4882a593Smuzhiyun 	orig_i2c_bus = i2c_get_bus_num();
70*4882a593Smuzhiyun 	i2c_set_bus_num(1);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	val8 = 0;
73*4882a593Smuzhiyun 	i2c_write(0x23, 0x6, 1, &val8, 1);
74*4882a593Smuzhiyun 	i2c_write(0x23, 0x7, 1, &val8, 1);
75*4882a593Smuzhiyun 	val8 = 0xff;
76*4882a593Smuzhiyun 	i2c_write(0x23, 0x2, 1, &val8, 1);
77*4882a593Smuzhiyun 	i2c_write(0x23, 0x3, 1, &val8, 1);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	val8 = 0;
80*4882a593Smuzhiyun 	i2c_write(0x26, 0x6, 1, &val8, 1);
81*4882a593Smuzhiyun 	val8 = 0x34;
82*4882a593Smuzhiyun 	i2c_write(0x26, 0x7, 1, &val8, 1);
83*4882a593Smuzhiyun #if defined(PCI_64BIT)
84*4882a593Smuzhiyun 	val8 = 0xf4;	/* PMC2:PCI1/64-bit */
85*4882a593Smuzhiyun #elif defined(PCI_ALL_PCI1)
86*4882a593Smuzhiyun 	val8 = 0xf3;	/* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
87*4882a593Smuzhiyun #elif defined(PCI_ONE_PCI1)
88*4882a593Smuzhiyun 	val8 = 0xf9;	/* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
89*4882a593Smuzhiyun #else
90*4882a593Smuzhiyun 	val8 = 0xf5;	/* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun 	i2c_write(0x26, 0x2, 1, &val8, 1);
93*4882a593Smuzhiyun 	val8 = 0xff;
94*4882a593Smuzhiyun 	i2c_write(0x26, 0x3, 1, &val8, 1);
95*4882a593Smuzhiyun 	val8 = 0;
96*4882a593Smuzhiyun 	i2c_write(0x27, 0x6, 1, &val8, 1);
97*4882a593Smuzhiyun 	i2c_write(0x27, 0x7, 1, &val8, 1);
98*4882a593Smuzhiyun 	val8 = 0xff;
99*4882a593Smuzhiyun 	i2c_write(0x27, 0x2, 1, &val8, 1);
100*4882a593Smuzhiyun 	val8 = 0xef;
101*4882a593Smuzhiyun 	i2c_write(0x27, 0x3, 1, &val8, 1);
102*4882a593Smuzhiyun 	asm("eieio");
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #if defined(PCI_64BIT)
105*4882a593Smuzhiyun 	printf("PCI1: 64-bit on PMC2\n");
106*4882a593Smuzhiyun #elif defined(PCI_ALL_PCI1)
107*4882a593Smuzhiyun 	printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
108*4882a593Smuzhiyun #elif defined(PCI_ONE_PCI1)
109*4882a593Smuzhiyun 	printf("PCI1: 32-bit on PMC1\n");
110*4882a593Smuzhiyun 	printf("PCI2: 32-bit on PMC2, PMC3\n");
111*4882a593Smuzhiyun #else
112*4882a593Smuzhiyun 	printf("PCI1: 32-bit on PMC1, PMC2\n");
113*4882a593Smuzhiyun 	printf("PCI2: 32-bit on PMC3\n");
114*4882a593Smuzhiyun #endif
115*4882a593Smuzhiyun 	/* Reset to original I2C bus */
116*4882a593Smuzhiyun 	i2c_set_bus_num(orig_i2c_bus);
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun 
pci_init_board(void)119*4882a593Smuzhiyun void pci_init_board(void)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
122*4882a593Smuzhiyun 	volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
123*4882a593Smuzhiyun 	volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
124*4882a593Smuzhiyun #ifndef CONFIG_MPC83XX_PCI2
125*4882a593Smuzhiyun 	struct pci_region *reg[] = { pci1_regions };
126*4882a593Smuzhiyun #else
127*4882a593Smuzhiyun 	struct pci_region *reg[] = { pci1_regions, pci2_regions };
128*4882a593Smuzhiyun #endif
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	/* initialize the PCA9555PW IO expander on the PIB board */
131*4882a593Smuzhiyun 	pib_init();
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	/* Enable all 8 PCI_CLK_OUTPUTS */
134*4882a593Smuzhiyun 	clk->occr = 0xff000000;
135*4882a593Smuzhiyun 	udelay(2000);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	/* Configure PCI Local Access Windows */
138*4882a593Smuzhiyun 	pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
139*4882a593Smuzhiyun 	pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
142*4882a593Smuzhiyun 	pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	udelay(2000);
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun #ifndef CONFIG_MPC83XX_PCI2
147*4882a593Smuzhiyun 	mpc83xx_pci_init(1, reg);
148*4882a593Smuzhiyun #else
149*4882a593Smuzhiyun 	mpc83xx_pci_init(2, reg);
150*4882a593Smuzhiyun #endif
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun #else
pci_init_board(void)154*4882a593Smuzhiyun void pci_init_board(void)
155*4882a593Smuzhiyun {
156*4882a593Smuzhiyun 	volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
157*4882a593Smuzhiyun 	volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
158*4882a593Smuzhiyun 	volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
159*4882a593Smuzhiyun 	struct pci_region *reg[] = { pci1_regions };
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	/* Configure PCI Local Access Windows */
162*4882a593Smuzhiyun 	pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
163*4882a593Smuzhiyun 	pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
166*4882a593Smuzhiyun 	pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	mpc83xx_pci_init(1, reg);
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	/* Configure PCI Inbound Translation Windows (3 1MB windows) */
171*4882a593Smuzhiyun 	pci_ctrl->pitar0 = 0x0;
172*4882a593Smuzhiyun 	pci_ctrl->pibar0 = 0x0;
173*4882a593Smuzhiyun 	pci_ctrl->piwar0 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
174*4882a593Smuzhiyun 			   PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	pci_ctrl->pitar1  = 0x0;
177*4882a593Smuzhiyun 	pci_ctrl->pibar1  = 0x0;
178*4882a593Smuzhiyun 	pci_ctrl->piebar1 = 0x0;
179*4882a593Smuzhiyun 	pci_ctrl->piwar1  = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
180*4882a593Smuzhiyun 			    PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	pci_ctrl->pitar2  = 0x0;
183*4882a593Smuzhiyun 	pci_ctrl->pibar2  = 0x0;
184*4882a593Smuzhiyun 	pci_ctrl->piebar2 = 0x0;
185*4882a593Smuzhiyun 	pci_ctrl->piwar2  = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
186*4882a593Smuzhiyun 			    PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	/* Unlock the configuration bit */
189*4882a593Smuzhiyun 	mpc83xx_pcislave_unlock(0);
190*4882a593Smuzhiyun 	printf("PCI:   Agent mode enabled\n");
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun #endif /* CONFIG_PCISLAVE */
193