xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc8xxx/srio.c (revision 1221ce459d04a428f8880f58581f671b736c3c27)
1a09b9b68SKumar Gala /*
2a09b9b68SKumar Gala  * Copyright 2011 Freescale Semiconductor, Inc.
3a09b9b68SKumar Gala  *
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
5a09b9b68SKumar Gala  */
6a09b9b68SKumar Gala 
7a09b9b68SKumar Gala #include <common.h>
8a09b9b68SKumar Gala #include <config.h>
9a09b9b68SKumar Gala #include <asm/fsl_law.h>
10a09b9b68SKumar Gala #include <asm/fsl_serdes.h>
115ffa88ecSLiu Gang #include <asm/fsl_srio.h>
12*1221ce45SMasahiro Yamada #include <linux/errno.h>
135ffa88ecSLiu Gang 
14c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
155ffa88ecSLiu Gang #define SRIO_PORT_ACCEPT_ALL 0x10000001
165ffa88ecSLiu Gang #define SRIO_IB_ATMU_AR 0x80f55000
175056c8e0SLiu Gang #define SRIO_OB_ATMU_AR_MAINT 0x80077000
185056c8e0SLiu Gang #define SRIO_OB_ATMU_AR_RW 0x80045000
195056c8e0SLiu Gang #define SRIO_LCSBA1CSR_OFFSET 0x5c
205056c8e0SLiu Gang #define SRIO_MAINT_WIN_SIZE 0x1000000 /* 16M */
215056c8e0SLiu Gang #define SRIO_RW_WIN_SIZE 0x100000 /* 1M */
225056c8e0SLiu Gang #define SRIO_LCSBA1CSR 0x60000000
2319e4a009SLiu Gang #endif
24a09b9b68SKumar Gala 
25a09b9b68SKumar Gala #if defined(CONFIG_FSL_CORENET)
269e758758SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
279e758758SYork Sun 	#define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR3_SRIO1
289e758758SYork Sun 	#define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR3_SRIO2
299e758758SYork Sun #else
30a09b9b68SKumar Gala 	#define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
31a09b9b68SKumar Gala 	#define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
329e758758SYork Sun #endif
33a09b9b68SKumar Gala 	#define _DEVDISR_RMU   FSL_CORENET_DEVDISR_RMU
34a09b9b68SKumar Gala 	#define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
35a09b9b68SKumar Gala #elif defined(CONFIG_MPC85xx)
36a09b9b68SKumar Gala 	#define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
37a09b9b68SKumar Gala 	#define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
38a09b9b68SKumar Gala 	#define _DEVDISR_RMU   MPC85xx_DEVDISR_RMSG
39a09b9b68SKumar Gala 	#define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
40a09b9b68SKumar Gala #elif defined(CONFIG_MPC86xx)
41a09b9b68SKumar Gala 	#define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
42a09b9b68SKumar Gala 	#define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
43a09b9b68SKumar Gala 	#define _DEVDISR_RMU   MPC86xx_DEVDISR_RMSG
44a09b9b68SKumar Gala 	#define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
45a09b9b68SKumar Gala 		(&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
46a09b9b68SKumar Gala #else
47a09b9b68SKumar Gala #error "No defines for DEVDISR_SRIO"
48a09b9b68SKumar Gala #endif
49a09b9b68SKumar Gala 
50d59c5570SLiu Gang #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
51d59c5570SLiu Gang /*
52d59c5570SLiu Gang  * Erratum A-004034
53d59c5570SLiu Gang  * Affects: SRIO
54d59c5570SLiu Gang  * Description: During port initialization, the SRIO port performs
55d59c5570SLiu Gang  * lane synchronization (detecting valid symbols on a lane) and
56d59c5570SLiu Gang  * lane alignment (coordinating multiple lanes to receive valid data
57d59c5570SLiu Gang  * across lanes). Internal errors in lane synchronization and lane
58d59c5570SLiu Gang  * alignment may cause failure to achieve link initialization at
59d59c5570SLiu Gang  * the configured port width.
60d59c5570SLiu Gang  * An SRIO port configured as a 4x port may see one of these scenarios:
61d59c5570SLiu Gang  * 1. One or more lanes fails to achieve lane synchronization. Depending
62d59c5570SLiu Gang  * on which lanes fail, this may result in downtraining from 4x to 1x
63d59c5570SLiu Gang  * on lane 0, 4x to 1x on lane R (redundant lane).
64d59c5570SLiu Gang  * 2. The link may fail to achieve lane alignment as a 4x, even though
65d59c5570SLiu Gang  * all 4 lanes achieve lane synchronization, and downtrain to a 1x.
66d59c5570SLiu Gang  * An SRIO port configured as a 1x port may fail to complete port
67d59c5570SLiu Gang  * initialization (PnESCSR[PU] never deasserts) because of scenario 1.
68d59c5570SLiu Gang  * Impact: SRIO port may downtrain to 1x, or may fail to complete
69d59c5570SLiu Gang  * link initialization. Once a port completes link initialization
70d59c5570SLiu Gang  * successfully, it will operate normally.
71d59c5570SLiu Gang  */
srio_erratum_a004034(u8 port)72d59c5570SLiu Gang static int srio_erratum_a004034(u8 port)
73d59c5570SLiu Gang {
74d59c5570SLiu Gang 	serdes_corenet_t *srds_regs;
75d59c5570SLiu Gang 	u32 conf_lane;
76d59c5570SLiu Gang 	u32 init_lane;
77d59c5570SLiu Gang 	int idx, first, last;
78d59c5570SLiu Gang 	u32 i;
79d59c5570SLiu Gang 	unsigned long long end_tick;
80d59c5570SLiu Gang 	struct ccsr_rio *srio_regs = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
81d59c5570SLiu Gang 
82d59c5570SLiu Gang 	srds_regs = (void *)(CONFIG_SYS_FSL_CORENET_SERDES_ADDR);
83d59c5570SLiu Gang 	conf_lane = (in_be32((void *)&srds_regs->srdspccr0)
84d59c5570SLiu Gang 			>> (12 - port * 4)) & 0x3;
85d59c5570SLiu Gang 	init_lane = (in_be32((void *)&srio_regs->lp_serial
86d59c5570SLiu Gang 			.port[port].pccsr) >> 27) & 0x7;
87d59c5570SLiu Gang 
88d59c5570SLiu Gang 	/*
89d59c5570SLiu Gang 	 * Start a counter set to ~2 ms after the SERDES reset is
90d59c5570SLiu Gang 	 * complete (SERDES SRDSBnRSTCTL[RST_DONE]=1 for n
91d59c5570SLiu Gang 	 * corresponding to the SERDES bank/PLL for the SRIO port).
92d59c5570SLiu Gang 	 */
93d59c5570SLiu Gang 	 if (in_be32((void *)&srds_regs->bank[0].rstctl)
94d59c5570SLiu Gang 		& SRDS_RSTCTL_RSTDONE) {
95d59c5570SLiu Gang 		/*
96d59c5570SLiu Gang 		 * Poll the port uninitialized status (SRIO PnESCSR[PO]) until
97d59c5570SLiu Gang 		 * PO=1 or the counter expires. If the counter expires, the
98d59c5570SLiu Gang 		 * port has failed initialization: go to recover steps. If PO=1
99d59c5570SLiu Gang 		 * and the desired port width is 1x, go to normal steps. If
100d59c5570SLiu Gang 		 * PO = 1 and the desired port width is 4x, go to recover steps.
101d59c5570SLiu Gang 		 */
102d59c5570SLiu Gang 		end_tick = usec2ticks(2000) + get_ticks();
103d59c5570SLiu Gang 		do {
104d59c5570SLiu Gang 			if (in_be32((void *)&srio_regs->lp_serial
105d59c5570SLiu Gang 				.port[port].pescsr) & 0x2) {
106d59c5570SLiu Gang 				if (conf_lane == 0x1)
107d59c5570SLiu Gang 					goto host_ok;
108d59c5570SLiu Gang 				else {
109d59c5570SLiu Gang 					if (init_lane == 0x2)
110d59c5570SLiu Gang 						goto host_ok;
111d59c5570SLiu Gang 					else
112d59c5570SLiu Gang 						break;
113d59c5570SLiu Gang 				}
114d59c5570SLiu Gang 			}
115d59c5570SLiu Gang 		} while (end_tick > get_ticks());
116d59c5570SLiu Gang 
117d59c5570SLiu Gang 		/* recover at most 3 times */
118d59c5570SLiu Gang 		for (i = 0; i < 3; i++) {
119d59c5570SLiu Gang 			/* Set SRIO PnCCSR[PD]=1 */
120d59c5570SLiu Gang 			setbits_be32((void *)&srio_regs->lp_serial
121d59c5570SLiu Gang 					.port[port].pccsr,
122d59c5570SLiu Gang 					0x800000);
123d59c5570SLiu Gang 			/*
124d59c5570SLiu Gang 			* Set SRIO PnPCR[OBDEN] on the host to
125d59c5570SLiu Gang 			* enable the discarding of any pending packets.
126d59c5570SLiu Gang 			*/
127d59c5570SLiu Gang 			setbits_be32((void *)&srio_regs->impl.port[port].pcr,
128d59c5570SLiu Gang 				0x04);
129d59c5570SLiu Gang 			/* Wait 50 us */
130d59c5570SLiu Gang 			udelay(50);
131d59c5570SLiu Gang 			/* Run sync command */
132d59c5570SLiu Gang 			isync();
133d59c5570SLiu Gang 
134d59c5570SLiu Gang 			if (port)
135d59c5570SLiu Gang 				first = serdes_get_first_lane(SRIO2);
136d59c5570SLiu Gang 			else
137d59c5570SLiu Gang 				first = serdes_get_first_lane(SRIO1);
138d59c5570SLiu Gang 			if (unlikely(first < 0))
139d59c5570SLiu Gang 				return -ENODEV;
140d59c5570SLiu Gang 			if (conf_lane == 0x1)
141d59c5570SLiu Gang 				last = first;
142d59c5570SLiu Gang 			else
143d59c5570SLiu Gang 				last = first + 3;
144d59c5570SLiu Gang 			/*
145d59c5570SLiu Gang 			 * Set SERDES BnGCRm0[RRST]=0 for each SRIO
146d59c5570SLiu Gang 			 * bank n and lane m.
147d59c5570SLiu Gang 			 */
148d59c5570SLiu Gang 			for (idx = first; idx <= last; idx++)
149d59c5570SLiu Gang 				clrbits_be32(&srds_regs->lane[idx].gcr0,
150d59c5570SLiu Gang 				SRDS_GCR0_RRST);
151d59c5570SLiu Gang 			/*
152d59c5570SLiu Gang 			 * Read SERDES BnGCRm0 for each SRIO
153d59c5570SLiu Gang 			 * bank n and lane m
154d59c5570SLiu Gang 			 */
155d59c5570SLiu Gang 			for (idx = first; idx <= last; idx++)
156d59c5570SLiu Gang 				in_be32(&srds_regs->lane[idx].gcr0);
157d59c5570SLiu Gang 			/* Run sync command */
158d59c5570SLiu Gang 			isync();
159d59c5570SLiu Gang 			/* Wait >= 100 ns */
160d59c5570SLiu Gang 			udelay(1);
161d59c5570SLiu Gang 			/*
162d59c5570SLiu Gang 			 * Set SERDES BnGCRm0[RRST]=1 for each SRIO
163d59c5570SLiu Gang 			 * bank n and lane m.
164d59c5570SLiu Gang 			 */
165d59c5570SLiu Gang 			for (idx = first; idx <= last; idx++)
166d59c5570SLiu Gang 				setbits_be32(&srds_regs->lane[idx].gcr0,
167d59c5570SLiu Gang 				SRDS_GCR0_RRST);
168d59c5570SLiu Gang 			/*
169d59c5570SLiu Gang 			 * Read SERDES BnGCRm0 for each SRIO
170d59c5570SLiu Gang 			 * bank n and lane m
171d59c5570SLiu Gang 			 */
172d59c5570SLiu Gang 			for (idx = first; idx <= last; idx++)
173d59c5570SLiu Gang 				in_be32(&srds_regs->lane[idx].gcr0);
174d59c5570SLiu Gang 			/* Run sync command */
175d59c5570SLiu Gang 			isync();
176d59c5570SLiu Gang 			/* Wait >= 300 ns */
177d59c5570SLiu Gang 			udelay(1);
178d59c5570SLiu Gang 
179d59c5570SLiu Gang 			/* Write 1 to clear all bits in SRIO PnSLCSR */
180d59c5570SLiu Gang 			out_be32((void *)&srio_regs->impl.port[port].slcsr,
181d59c5570SLiu Gang 				0xffffffff);
182d59c5570SLiu Gang 			/* Clear SRIO PnPCR[OBDEN] on the host */
183d59c5570SLiu Gang 			clrbits_be32((void *)&srio_regs->impl.port[port].pcr,
184d59c5570SLiu Gang 				0x04);
185d59c5570SLiu Gang 			/* Set SRIO PnCCSR[PD]=0 */
186d59c5570SLiu Gang 			clrbits_be32((void *)&srio_regs->lp_serial
187d59c5570SLiu Gang 				.port[port].pccsr,
188d59c5570SLiu Gang 				0x800000);
189d59c5570SLiu Gang 			/* Wait >= 24 ms */
190d59c5570SLiu Gang 			udelay(24000);
191d59c5570SLiu Gang 			/* Poll the state of the port again */
192d59c5570SLiu Gang 			init_lane =
193d59c5570SLiu Gang 				(in_be32((void *)&srio_regs->lp_serial
194d59c5570SLiu Gang 					.port[port].pccsr) >> 27) & 0x7;
195d59c5570SLiu Gang 			if (in_be32((void *)&srio_regs->lp_serial
196d59c5570SLiu Gang 				.port[port].pescsr) & 0x2) {
197d59c5570SLiu Gang 				if (conf_lane == 0x1)
198d59c5570SLiu Gang 					goto host_ok;
199d59c5570SLiu Gang 				else {
200d59c5570SLiu Gang 					if (init_lane == 0x2)
201d59c5570SLiu Gang 						goto host_ok;
202d59c5570SLiu Gang 				}
203d59c5570SLiu Gang 			}
204d59c5570SLiu Gang 			if (i == 2)
205d59c5570SLiu Gang 				return -ENODEV;
206d59c5570SLiu Gang 		}
207d59c5570SLiu Gang 	} else
208d59c5570SLiu Gang 		return -ENODEV;
209d59c5570SLiu Gang 
210d59c5570SLiu Gang host_ok:
211d59c5570SLiu Gang 	/* Poll PnESCSR[OES] on the host until it is clear */
212d59c5570SLiu Gang 	end_tick = usec2ticks(1000000) + get_ticks();
213d59c5570SLiu Gang 	do {
214d59c5570SLiu Gang 		if (!(in_be32((void *)&srio_regs->lp_serial.port[port].pescsr)
215d59c5570SLiu Gang 			& 0x10000)) {
216d59c5570SLiu Gang 			out_be32(((void *)&srio_regs->lp_serial
217d59c5570SLiu Gang 				.port[port].pescsr), 0xffffffff);
218d59c5570SLiu Gang 			out_be32(((void *)&srio_regs->phys_err
219d59c5570SLiu Gang 				.port[port].edcsr), 0);
220d59c5570SLiu Gang 			out_be32(((void *)&srio_regs->logical_err.ltledcsr), 0);
221d59c5570SLiu Gang 			return 0;
222d59c5570SLiu Gang 		}
223d59c5570SLiu Gang 	} while (end_tick > get_ticks());
224d59c5570SLiu Gang 
225d59c5570SLiu Gang 	return -ENODEV;
226d59c5570SLiu Gang }
227d59c5570SLiu Gang #endif
228d59c5570SLiu Gang 
srio_init(void)229a09b9b68SKumar Gala void srio_init(void)
230a09b9b68SKumar Gala {
231a09b9b68SKumar Gala 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
232a09b9b68SKumar Gala 	int srio1_used = 0, srio2_used = 0;
2339e758758SYork Sun 	u32 *devdisr;
234a09b9b68SKumar Gala 
2359e758758SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
2369e758758SYork Sun 	devdisr = &gur->devdisr3;
2379e758758SYork Sun #else
2389e758758SYork Sun 	devdisr = &gur->devdisr;
2399e758758SYork Sun #endif
240a09b9b68SKumar Gala 	if (is_serdes_configured(SRIO1)) {
241a09b9b68SKumar Gala 		set_next_law(CONFIG_SYS_SRIO1_MEM_PHYS,
242a09b9b68SKumar Gala 				law_size_bits(CONFIG_SYS_SRIO1_MEM_SIZE),
243a09b9b68SKumar Gala 				LAW_TRGT_IF_RIO_1);
244a09b9b68SKumar Gala 		srio1_used = 1;
245d59c5570SLiu Gang #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
246d59c5570SLiu Gang 		if (srio_erratum_a004034(0) < 0)
247d59c5570SLiu Gang 			printf("SRIO1: enabled but port error\n");
248d59c5570SLiu Gang 		else
249d59c5570SLiu Gang #endif
250a09b9b68SKumar Gala 		printf("SRIO1: enabled\n");
251a09b9b68SKumar Gala 	} else {
252a09b9b68SKumar Gala 		printf("SRIO1: disabled\n");
253a09b9b68SKumar Gala 	}
254a09b9b68SKumar Gala 
255a09b9b68SKumar Gala #ifdef CONFIG_SRIO2
256a09b9b68SKumar Gala 	if (is_serdes_configured(SRIO2)) {
257a09b9b68SKumar Gala 		set_next_law(CONFIG_SYS_SRIO2_MEM_PHYS,
258a09b9b68SKumar Gala 				law_size_bits(CONFIG_SYS_SRIO2_MEM_SIZE),
259a09b9b68SKumar Gala 				LAW_TRGT_IF_RIO_2);
260a09b9b68SKumar Gala 		srio2_used = 1;
261d59c5570SLiu Gang #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
262d59c5570SLiu Gang 		if (srio_erratum_a004034(1) < 0)
263d59c5570SLiu Gang 			printf("SRIO2: enabled but port error\n");
264d59c5570SLiu Gang 		else
265d59c5570SLiu Gang #endif
266a09b9b68SKumar Gala 		printf("SRIO2: enabled\n");
267d59c5570SLiu Gang 
268a09b9b68SKumar Gala 	} else {
269a09b9b68SKumar Gala 		printf("SRIO2: disabled\n");
270a09b9b68SKumar Gala 	}
271a09b9b68SKumar Gala #endif
272a09b9b68SKumar Gala 
273a09b9b68SKumar Gala #ifdef CONFIG_FSL_CORENET
274a09b9b68SKumar Gala 	/* On FSL_CORENET devices we can disable individual ports */
275a09b9b68SKumar Gala 	if (!srio1_used)
2769e758758SYork Sun 		setbits_be32(devdisr, _DEVDISR_SRIO1);
277a09b9b68SKumar Gala 	if (!srio2_used)
2789e758758SYork Sun 		setbits_be32(devdisr, _DEVDISR_SRIO2);
279a09b9b68SKumar Gala #endif
280a09b9b68SKumar Gala 
281a09b9b68SKumar Gala 	/* neither port is used - disable everything */
282a09b9b68SKumar Gala 	if (!srio1_used && !srio2_used) {
2839e758758SYork Sun 		setbits_be32(devdisr, _DEVDISR_SRIO1);
2849e758758SYork Sun 		setbits_be32(devdisr, _DEVDISR_SRIO2);
2859e758758SYork Sun 		setbits_be32(devdisr, _DEVDISR_RMU);
286a09b9b68SKumar Gala 	}
287a09b9b68SKumar Gala }
2885ffa88ecSLiu Gang 
289c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
srio_boot_master(int port)290ff65f126SLiu Gang void srio_boot_master(int port)
2915ffa88ecSLiu Gang {
2925ffa88ecSLiu Gang 	struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
2935ffa88ecSLiu Gang 
2945ffa88ecSLiu Gang 	/* set port accept-all */
295ff65f126SLiu Gang 	out_be32((void *)&srio->impl.port[port - 1].ptaacr,
2965ffa88ecSLiu Gang 				SRIO_PORT_ACCEPT_ALL);
2975ffa88ecSLiu Gang 
298ff65f126SLiu Gang 	debug("SRIOBOOT - MASTER: Master port [ %d ] for srio boot.\n", port);
2993f1af81bSLiu Gang 	/* configure inbound window for slave's u-boot image */
3003f1af81bSLiu Gang 	debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
3015ffa88ecSLiu Gang 			"Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
302b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
303b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
304b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
305ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwtar,
306b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
307ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwbar,
308b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1 >> 12);
309ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwar,
3105ffa88ecSLiu Gang 			SRIO_IB_ATMU_AR
311b5f7c873SLiu Gang 			| atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
3125ffa88ecSLiu Gang 
3133f1af81bSLiu Gang 	/* configure inbound window for slave's u-boot image */
3143f1af81bSLiu Gang 	debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
3155ffa88ecSLiu Gang 			"Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
316b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
317b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
318b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
319ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwtar,
320b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
321ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwbar,
322b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2 >> 12);
323ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwar,
3245ffa88ecSLiu Gang 			SRIO_IB_ATMU_AR
325b5f7c873SLiu Gang 			| atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
3263f1af81bSLiu Gang 
327ff65f126SLiu Gang 	/* configure inbound window for slave's ucode and ENV */
328ff65f126SLiu Gang 	debug("SRIOBOOT - MASTER: Inbound window for slave's ucode and ENV; "
3293f1af81bSLiu Gang 			"Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
330b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
331b5f7c873SLiu Gang 			(u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
332b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
333ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwtar,
334b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS >> 12);
335ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwbar,
336b5f7c873SLiu Gang 			CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS >> 12);
337ff65f126SLiu Gang 	out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwar,
3383f1af81bSLiu Gang 			SRIO_IB_ATMU_AR
339b5f7c873SLiu Gang 			| atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE));
3405ffa88ecSLiu Gang }
3415056c8e0SLiu Gang 
srio_boot_master_release_slave(int port)342ff65f126SLiu Gang void srio_boot_master_release_slave(int port)
3435056c8e0SLiu Gang {
3445056c8e0SLiu Gang 	struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
3455056c8e0SLiu Gang 	u32 escsr;
3465056c8e0SLiu Gang 	debug("SRIOBOOT - MASTER: "
3475056c8e0SLiu Gang 			"Check the port status and release slave core ...\n");
3485056c8e0SLiu Gang 
349ff65f126SLiu Gang 	escsr = in_be32((void *)&srio->lp_serial.port[port - 1].pescsr);
3505056c8e0SLiu Gang 	if (escsr & 0x2) {
3515056c8e0SLiu Gang 		if (escsr & 0x10100) {
3525056c8e0SLiu Gang 			debug("SRIOBOOT - MASTER: Port [ %d ] is error.\n",
353ff65f126SLiu Gang 				port);
3545056c8e0SLiu Gang 		} else {
3555056c8e0SLiu Gang 			debug("SRIOBOOT - MASTER: "
3565056c8e0SLiu Gang 				"Port [ %d ] is ready, now release slave's core ...\n",
357ff65f126SLiu Gang 				port);
3585056c8e0SLiu Gang 			/*
3595056c8e0SLiu Gang 			 * configure outbound window
3605056c8e0SLiu Gang 			 * with maintenance attribute to set slave's LCSBA1CSR
3615056c8e0SLiu Gang 			 */
362ff65f126SLiu Gang 			out_be32((void *)&srio->atmu.port[port - 1]
3635056c8e0SLiu Gang 				.outbw[1].rowtar, 0);
364ff65f126SLiu Gang 			out_be32((void *)&srio->atmu.port[port - 1]
3655056c8e0SLiu Gang 				.outbw[1].rowtear, 0);
366ff65f126SLiu Gang 			if (port - 1)
367ff65f126SLiu Gang 				out_be32((void *)&srio->atmu.port[port - 1]
3685056c8e0SLiu Gang 					.outbw[1].rowbar,
3695056c8e0SLiu Gang 					CONFIG_SYS_SRIO2_MEM_PHYS >> 12);
3705056c8e0SLiu Gang 			else
371ff65f126SLiu Gang 				out_be32((void *)&srio->atmu.port[port - 1]
3725056c8e0SLiu Gang 					.outbw[1].rowbar,
3735056c8e0SLiu Gang 					CONFIG_SYS_SRIO1_MEM_PHYS >> 12);
374ff65f126SLiu Gang 			out_be32((void *)&srio->atmu.port[port - 1]
3755056c8e0SLiu Gang 					.outbw[1].rowar,
3765056c8e0SLiu Gang 					SRIO_OB_ATMU_AR_MAINT
3775056c8e0SLiu Gang 					| atmu_size_mask(SRIO_MAINT_WIN_SIZE));
3785056c8e0SLiu Gang 
3795056c8e0SLiu Gang 			/*
3805056c8e0SLiu Gang 			 * configure outbound window
3815056c8e0SLiu Gang 			 * with R/W attribute to set slave's BRR
3825056c8e0SLiu Gang 			 */
383ff65f126SLiu Gang 			out_be32((void *)&srio->atmu.port[port - 1]
3845056c8e0SLiu Gang 				.outbw[2].rowtar,
3855056c8e0SLiu Gang 				SRIO_LCSBA1CSR >> 9);
386ff65f126SLiu Gang 			out_be32((void *)&srio->atmu.port[port - 1]
3875056c8e0SLiu Gang 				.outbw[2].rowtear, 0);
388ff65f126SLiu Gang 			if (port - 1)
389ff65f126SLiu Gang 				out_be32((void *)&srio->atmu.port[port - 1]
3905056c8e0SLiu Gang 					.outbw[2].rowbar,
3915056c8e0SLiu Gang 					(CONFIG_SYS_SRIO2_MEM_PHYS
3925056c8e0SLiu Gang 					+ SRIO_MAINT_WIN_SIZE) >> 12);
3935056c8e0SLiu Gang 			else
394ff65f126SLiu Gang 				out_be32((void *)&srio->atmu.port[port - 1]
3955056c8e0SLiu Gang 					.outbw[2].rowbar,
3965056c8e0SLiu Gang 					(CONFIG_SYS_SRIO1_MEM_PHYS
3975056c8e0SLiu Gang 					+ SRIO_MAINT_WIN_SIZE) >> 12);
398ff65f126SLiu Gang 			out_be32((void *)&srio->atmu.port[port - 1]
3995056c8e0SLiu Gang 				.outbw[2].rowar,
4005056c8e0SLiu Gang 				SRIO_OB_ATMU_AR_RW
4015056c8e0SLiu Gang 				| atmu_size_mask(SRIO_RW_WIN_SIZE));
4025056c8e0SLiu Gang 
4035056c8e0SLiu Gang 			/*
4045056c8e0SLiu Gang 			 * Set the LCSBA1CSR register in slave
4055056c8e0SLiu Gang 			 * by the maint-outbound window
4065056c8e0SLiu Gang 			 */
407ff65f126SLiu Gang 			if (port - 1) {
4085056c8e0SLiu Gang 				out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
4095056c8e0SLiu Gang 					+ SRIO_LCSBA1CSR_OFFSET,
4105056c8e0SLiu Gang 					SRIO_LCSBA1CSR);
4115056c8e0SLiu Gang 				while (in_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
4125056c8e0SLiu Gang 					+ SRIO_LCSBA1CSR_OFFSET)
4135056c8e0SLiu Gang 					!= SRIO_LCSBA1CSR)
4145056c8e0SLiu Gang 					;
4155056c8e0SLiu Gang 				/*
4165056c8e0SLiu Gang 				 * And then set the BRR register
4175056c8e0SLiu Gang 				 * to release slave core
4185056c8e0SLiu Gang 				 */
4195056c8e0SLiu Gang 				out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
4205056c8e0SLiu Gang 					+ SRIO_MAINT_WIN_SIZE
421b5f7c873SLiu Gang 					+ CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
422b5f7c873SLiu Gang 					CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
4235056c8e0SLiu Gang 			} else {
4245056c8e0SLiu Gang 				out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
4255056c8e0SLiu Gang 					+ SRIO_LCSBA1CSR_OFFSET,
4265056c8e0SLiu Gang 					SRIO_LCSBA1CSR);
4275056c8e0SLiu Gang 				while (in_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
4285056c8e0SLiu Gang 					+ SRIO_LCSBA1CSR_OFFSET)
4295056c8e0SLiu Gang 					!= SRIO_LCSBA1CSR)
4305056c8e0SLiu Gang 					;
4315056c8e0SLiu Gang 				/*
4325056c8e0SLiu Gang 				 * And then set the BRR register
4335056c8e0SLiu Gang 				 * to release slave core
4345056c8e0SLiu Gang 				 */
4355056c8e0SLiu Gang 				out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
4365056c8e0SLiu Gang 					+ SRIO_MAINT_WIN_SIZE
437b5f7c873SLiu Gang 					+ CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
438b5f7c873SLiu Gang 					CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
4395056c8e0SLiu Gang 			}
4405056c8e0SLiu Gang 			debug("SRIOBOOT - MASTER: "
4415056c8e0SLiu Gang 					"Release slave successfully! Now the slave should start up!\n");
4425056c8e0SLiu Gang 		}
4435056c8e0SLiu Gang 	} else
444ff65f126SLiu Gang 		debug("SRIOBOOT - MASTER: Port [ %d ] is not ready.\n", port);
4455056c8e0SLiu Gang }
4465056c8e0SLiu Gang #endif
447