xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc8xxx/fdt.c (revision 0e00a84cdedf7a1949486746225b35984b351eca)
1a47a12beSStefan Roese /*
2e628c8f7Sramneek mehresh  * Copyright 2009-2014 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  *
4a47a12beSStefan Roese  * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
5a47a12beSStefan Roese  * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
6a47a12beSStefan Roese  * cpu specific common code for 85xx/86xx processors.
71a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
8a47a12beSStefan Roese  */
9a47a12beSStefan Roese 
10a47a12beSStefan Roese #include <common.h>
11*0e00a84cSMasahiro Yamada #include <linux/libfdt.h>
12a47a12beSStefan Roese #include <fdt_support.h>
138f3a7fa4SKumar Gala #include <asm/mp.h>
14a09b9b68SKumar Gala #include <asm/fsl_serdes.h>
15865ff856SAndy Fleming #include <phy.h>
1672f4980bSRamneek Mehresh #include <hwconfig.h>
1757567361SKumar Gala 
18f1810d85Sramneek mehresh #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
19f1810d85Sramneek mehresh #define CONFIG_USB_MAX_CONTROLLER_COUNT	1
20f1810d85Sramneek mehresh #endif
21a47a12beSStefan Roese 
228f3a7fa4SKumar Gala #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
ft_del_cpuhandle(void * blob,int cpuhandle)2311beefa3SKumar Gala static int ft_del_cpuhandle(void *blob, int cpuhandle)
2411beefa3SKumar Gala {
2511beefa3SKumar Gala 	int off, ret = -FDT_ERR_NOTFOUND;
2611beefa3SKumar Gala 
2711beefa3SKumar Gala 	/* if we find a match, we'll delete at it which point the offsets are
2811beefa3SKumar Gala 	 * invalid so we start over from the beginning
2911beefa3SKumar Gala 	 */
3011beefa3SKumar Gala 	off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
3111beefa3SKumar Gala 						&cpuhandle, 4);
3211beefa3SKumar Gala 	while (off != -FDT_ERR_NOTFOUND) {
3311beefa3SKumar Gala 		fdt_delprop(blob, off, "cpu-handle");
3411beefa3SKumar Gala 		ret = 1;
3511beefa3SKumar Gala 		off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
3611beefa3SKumar Gala 				&cpuhandle, 4);
3711beefa3SKumar Gala 	}
3811beefa3SKumar Gala 
3911beefa3SKumar Gala 	return ret;
4011beefa3SKumar Gala }
4111beefa3SKumar Gala 
ft_fixup_num_cores(void * blob)42a47a12beSStefan Roese void ft_fixup_num_cores(void *blob) {
43a47a12beSStefan Roese 	int off, num_cores, del_cores;
44a47a12beSStefan Roese 
45a47a12beSStefan Roese 	del_cores = 0;
46a47a12beSStefan Roese 	num_cores = cpu_numcores();
47a47a12beSStefan Roese 
48a47a12beSStefan Roese 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
49a47a12beSStefan Roese 	while (off != -FDT_ERR_NOTFOUND) {
50a47a12beSStefan Roese 		u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
51709389b6SYork Sun 		u32 phys_cpu_id = thread_to_core(*reg);
52a47a12beSStefan Roese 
53709389b6SYork Sun 		if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
5411beefa3SKumar Gala 			int ph = fdt_get_phandle(blob, off);
5511beefa3SKumar Gala 
5611beefa3SKumar Gala 			/* Delete the cpu node once there are no cpu handles */
5711beefa3SKumar Gala 			if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
58a47a12beSStefan Roese 				fdt_del_node(blob, off);
59a47a12beSStefan Roese 				del_cores++;
6011beefa3SKumar Gala 			}
6111beefa3SKumar Gala 			/* either we deleted some cpu handles or the cpu node
6211beefa3SKumar Gala 			 * so we reset the offset back to the start since we
6311beefa3SKumar Gala 			 * can't trust the offsets anymore
6411beefa3SKumar Gala 			 */
65a47a12beSStefan Roese 			off = -1;
66a47a12beSStefan Roese 		}
67a47a12beSStefan Roese 		off = fdt_node_offset_by_prop_value(blob, off,
68a47a12beSStefan Roese 				"device_type", "cpu", 4);
69a47a12beSStefan Roese 	}
70a47a12beSStefan Roese 	debug ("%x core system found\n", num_cores);
71a47a12beSStefan Roese 	debug ("deleted %d extra core entry entries from device tree\n",
72a47a12beSStefan Roese 								del_cores);
73a47a12beSStefan Roese }
745d0c3b57SKim Phillips #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
755d0c3b57SKim Phillips 
fdt_fixup_phy_connection(void * blob,int offset,phy_interface_t phyc)76865ff856SAndy Fleming int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
77a1964ea5SKumar Gala {
78a1964ea5SKumar Gala 	return fdt_setprop_string(blob, offset, "phy-connection-type",
79865ff856SAndy Fleming 					 phy_string_for_interface(phyc));
80a1964ea5SKumar Gala }
81a09b9b68SKumar Gala 
82a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO
ft_disable_srio_port(void * blob,int srio_off,int port)839c42ef61SKumar Gala static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
849c42ef61SKumar Gala {
859c42ef61SKumar Gala 	int off = fdt_node_offset_by_prop_value(blob, srio_off,
869c42ef61SKumar Gala 			"cell-index", &port, 4);
879c42ef61SKumar Gala 	if (off >= 0) {
889c42ef61SKumar Gala 		off = fdt_setprop_string(blob, off, "status", "disabled");
899c42ef61SKumar Gala 		if (off > 0)
909c42ef61SKumar Gala 			printf("WARNING unable to set status for fsl,srio "
919c42ef61SKumar Gala 				"port %d: %s\n", port, fdt_strerror(off));
929c42ef61SKumar Gala 	}
939c42ef61SKumar Gala }
949c42ef61SKumar Gala 
ft_disable_rman(void * blob)959c42ef61SKumar Gala static inline void ft_disable_rman(void *blob)
969c42ef61SKumar Gala {
979c42ef61SKumar Gala 	int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
989c42ef61SKumar Gala 	if (off >= 0) {
999c42ef61SKumar Gala 		off = fdt_setprop_string(blob, off, "status", "disabled");
1009c42ef61SKumar Gala 		if (off > 0)
1019c42ef61SKumar Gala 			printf("WARNING unable to set status for fsl,rman %s\n",
1029c42ef61SKumar Gala 				fdt_strerror(off));
1039c42ef61SKumar Gala 	}
1049c42ef61SKumar Gala }
1059c42ef61SKumar Gala 
ft_disable_rmu(void * blob)1069c42ef61SKumar Gala static inline void ft_disable_rmu(void *blob)
1079c42ef61SKumar Gala {
1089c42ef61SKumar Gala 	int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
1099c42ef61SKumar Gala 	if (off >= 0) {
1109c42ef61SKumar Gala 		off = fdt_setprop_string(blob, off, "status", "disabled");
1119c42ef61SKumar Gala 		if (off > 0)
1129c42ef61SKumar Gala 			printf("WARNING unable to set status for "
1139c42ef61SKumar Gala 				"fsl,srio-rmu %s\n", fdt_strerror(off));
1149c42ef61SKumar Gala 	}
1159c42ef61SKumar Gala }
1169c42ef61SKumar Gala 
ft_srio_setup(void * blob)117a09b9b68SKumar Gala void ft_srio_setup(void *blob)
118a09b9b68SKumar Gala {
1199c42ef61SKumar Gala 	int srio1_used = 0, srio2_used = 0;
1209c42ef61SKumar Gala 	int srio_off;
1219c42ef61SKumar Gala 
1229c42ef61SKumar Gala 	/* search for srio node, if doesn't exist just return - nothing todo */
1239c42ef61SKumar Gala 	srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
1249c42ef61SKumar Gala 	if (srio_off < 0)
1259c42ef61SKumar Gala 		return ;
1269c42ef61SKumar Gala 
127a09b9b68SKumar Gala #ifdef CONFIG_SRIO1
1289c42ef61SKumar Gala 	if (is_serdes_configured(SRIO1))
1299c42ef61SKumar Gala 		srio1_used = 1;
130a09b9b68SKumar Gala #endif
131a09b9b68SKumar Gala #ifdef CONFIG_SRIO2
1329c42ef61SKumar Gala 	if (is_serdes_configured(SRIO2))
1339c42ef61SKumar Gala 		srio2_used = 1;
134a09b9b68SKumar Gala #endif
1359c42ef61SKumar Gala 
1369c42ef61SKumar Gala 	/* mark port1 disabled */
1379c42ef61SKumar Gala 	if (!srio1_used)
1389c42ef61SKumar Gala 		ft_disable_srio_port(blob, srio_off, 1);
1399c42ef61SKumar Gala 
1409c42ef61SKumar Gala 	/* mark port2 disabled */
1419c42ef61SKumar Gala 	if (!srio2_used)
1429c42ef61SKumar Gala 		ft_disable_srio_port(blob, srio_off, 2);
1439c42ef61SKumar Gala 
1449c42ef61SKumar Gala 	/* if both ports not used, disable controller, rmu and rman */
1459c42ef61SKumar Gala 	if (!srio1_used && !srio2_used) {
1469c42ef61SKumar Gala 		fdt_setprop_string(blob, srio_off, "status", "disabled");
1479c42ef61SKumar Gala 
1489c42ef61SKumar Gala 		ft_disable_rman(blob);
1499c42ef61SKumar Gala 		ft_disable_rmu(blob);
1509c42ef61SKumar Gala 	}
151a09b9b68SKumar Gala }
152a09b9b68SKumar Gala #endif
153