xref: /OK3568_Linux_fs/u-boot/arch/powerpc/cpu/mpc8xxx/fdt.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2009-2014 Freescale Semiconductor, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
5*4882a593Smuzhiyun  * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
6*4882a593Smuzhiyun  * cpu specific common code for 85xx/86xx processors.
7*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <common.h>
11*4882a593Smuzhiyun #include <linux/libfdt.h>
12*4882a593Smuzhiyun #include <fdt_support.h>
13*4882a593Smuzhiyun #include <asm/mp.h>
14*4882a593Smuzhiyun #include <asm/fsl_serdes.h>
15*4882a593Smuzhiyun #include <phy.h>
16*4882a593Smuzhiyun #include <hwconfig.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
19*4882a593Smuzhiyun #define CONFIG_USB_MAX_CONTROLLER_COUNT	1
20*4882a593Smuzhiyun #endif
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
ft_del_cpuhandle(void * blob,int cpuhandle)23*4882a593Smuzhiyun static int ft_del_cpuhandle(void *blob, int cpuhandle)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	int off, ret = -FDT_ERR_NOTFOUND;
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun 	/* if we find a match, we'll delete at it which point the offsets are
28*4882a593Smuzhiyun 	 * invalid so we start over from the beginning
29*4882a593Smuzhiyun 	 */
30*4882a593Smuzhiyun 	off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
31*4882a593Smuzhiyun 						&cpuhandle, 4);
32*4882a593Smuzhiyun 	while (off != -FDT_ERR_NOTFOUND) {
33*4882a593Smuzhiyun 		fdt_delprop(blob, off, "cpu-handle");
34*4882a593Smuzhiyun 		ret = 1;
35*4882a593Smuzhiyun 		off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
36*4882a593Smuzhiyun 				&cpuhandle, 4);
37*4882a593Smuzhiyun 	}
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	return ret;
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun 
ft_fixup_num_cores(void * blob)42*4882a593Smuzhiyun void ft_fixup_num_cores(void *blob) {
43*4882a593Smuzhiyun 	int off, num_cores, del_cores;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	del_cores = 0;
46*4882a593Smuzhiyun 	num_cores = cpu_numcores();
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
49*4882a593Smuzhiyun 	while (off != -FDT_ERR_NOTFOUND) {
50*4882a593Smuzhiyun 		u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
51*4882a593Smuzhiyun 		u32 phys_cpu_id = thread_to_core(*reg);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 		if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
54*4882a593Smuzhiyun 			int ph = fdt_get_phandle(blob, off);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 			/* Delete the cpu node once there are no cpu handles */
57*4882a593Smuzhiyun 			if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
58*4882a593Smuzhiyun 				fdt_del_node(blob, off);
59*4882a593Smuzhiyun 				del_cores++;
60*4882a593Smuzhiyun 			}
61*4882a593Smuzhiyun 			/* either we deleted some cpu handles or the cpu node
62*4882a593Smuzhiyun 			 * so we reset the offset back to the start since we
63*4882a593Smuzhiyun 			 * can't trust the offsets anymore
64*4882a593Smuzhiyun 			 */
65*4882a593Smuzhiyun 			off = -1;
66*4882a593Smuzhiyun 		}
67*4882a593Smuzhiyun 		off = fdt_node_offset_by_prop_value(blob, off,
68*4882a593Smuzhiyun 				"device_type", "cpu", 4);
69*4882a593Smuzhiyun 	}
70*4882a593Smuzhiyun 	debug ("%x core system found\n", num_cores);
71*4882a593Smuzhiyun 	debug ("deleted %d extra core entry entries from device tree\n",
72*4882a593Smuzhiyun 								del_cores);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
75*4882a593Smuzhiyun 
fdt_fixup_phy_connection(void * blob,int offset,phy_interface_t phyc)76*4882a593Smuzhiyun int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun 	return fdt_setprop_string(blob, offset, "phy-connection-type",
79*4882a593Smuzhiyun 					 phy_string_for_interface(phyc));
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #ifdef CONFIG_SYS_SRIO
ft_disable_srio_port(void * blob,int srio_off,int port)83*4882a593Smuzhiyun static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun 	int off = fdt_node_offset_by_prop_value(blob, srio_off,
86*4882a593Smuzhiyun 			"cell-index", &port, 4);
87*4882a593Smuzhiyun 	if (off >= 0) {
88*4882a593Smuzhiyun 		off = fdt_setprop_string(blob, off, "status", "disabled");
89*4882a593Smuzhiyun 		if (off > 0)
90*4882a593Smuzhiyun 			printf("WARNING unable to set status for fsl,srio "
91*4882a593Smuzhiyun 				"port %d: %s\n", port, fdt_strerror(off));
92*4882a593Smuzhiyun 	}
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun 
ft_disable_rman(void * blob)95*4882a593Smuzhiyun static inline void ft_disable_rman(void *blob)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun 	int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
98*4882a593Smuzhiyun 	if (off >= 0) {
99*4882a593Smuzhiyun 		off = fdt_setprop_string(blob, off, "status", "disabled");
100*4882a593Smuzhiyun 		if (off > 0)
101*4882a593Smuzhiyun 			printf("WARNING unable to set status for fsl,rman %s\n",
102*4882a593Smuzhiyun 				fdt_strerror(off));
103*4882a593Smuzhiyun 	}
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun 
ft_disable_rmu(void * blob)106*4882a593Smuzhiyun static inline void ft_disable_rmu(void *blob)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
109*4882a593Smuzhiyun 	if (off >= 0) {
110*4882a593Smuzhiyun 		off = fdt_setprop_string(blob, off, "status", "disabled");
111*4882a593Smuzhiyun 		if (off > 0)
112*4882a593Smuzhiyun 			printf("WARNING unable to set status for "
113*4882a593Smuzhiyun 				"fsl,srio-rmu %s\n", fdt_strerror(off));
114*4882a593Smuzhiyun 	}
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun 
ft_srio_setup(void * blob)117*4882a593Smuzhiyun void ft_srio_setup(void *blob)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	int srio1_used = 0, srio2_used = 0;
120*4882a593Smuzhiyun 	int srio_off;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	/* search for srio node, if doesn't exist just return - nothing todo */
123*4882a593Smuzhiyun 	srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
124*4882a593Smuzhiyun 	if (srio_off < 0)
125*4882a593Smuzhiyun 		return ;
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun #ifdef CONFIG_SRIO1
128*4882a593Smuzhiyun 	if (is_serdes_configured(SRIO1))
129*4882a593Smuzhiyun 		srio1_used = 1;
130*4882a593Smuzhiyun #endif
131*4882a593Smuzhiyun #ifdef CONFIG_SRIO2
132*4882a593Smuzhiyun 	if (is_serdes_configured(SRIO2))
133*4882a593Smuzhiyun 		srio2_used = 1;
134*4882a593Smuzhiyun #endif
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	/* mark port1 disabled */
137*4882a593Smuzhiyun 	if (!srio1_used)
138*4882a593Smuzhiyun 		ft_disable_srio_port(blob, srio_off, 1);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	/* mark port2 disabled */
141*4882a593Smuzhiyun 	if (!srio2_used)
142*4882a593Smuzhiyun 		ft_disable_srio_port(blob, srio_off, 2);
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	/* if both ports not used, disable controller, rmu and rman */
145*4882a593Smuzhiyun 	if (!srio1_used && !srio2_used) {
146*4882a593Smuzhiyun 		fdt_setprop_string(blob, srio_off, "status", "disabled");
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 		ft_disable_rman(blob);
149*4882a593Smuzhiyun 		ft_disable_rmu(blob);
150*4882a593Smuzhiyun 	}
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun #endif
153