1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2009-2014 Freescale Semiconductor, Inc.
6 * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
7 * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
8 * cpu specific common code for 85xx/86xx processors.
13 #include <linux/libfdt.h>
14 #include <fdt_support.h>
16 #include <asm/fsl_serdes.h>
20 #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
21 static int ft_del_cpuhandle(void *blob, int cpuhandle)
23 int off, ret = -FDT_ERR_NOTFOUND;
25 /* if we find a match, we'll delete at it which point the offsets are
26 * invalid so we start over from the beginning
28 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
30 while (off != -FDT_ERR_NOTFOUND) {
31 fdt_delprop(blob, off, "cpu-handle");
33 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
40 void ft_fixup_num_cores(void *blob) {
41 int off, num_cores, del_cores;
44 num_cores = cpu_numcores();
46 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
47 while (off != -FDT_ERR_NOTFOUND) {
48 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
49 u32 phys_cpu_id = thread_to_core(*reg);
51 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
52 int ph = fdt_get_phandle(blob, off);
54 /* Delete the cpu node once there are no cpu handles */
55 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
56 fdt_del_node(blob, off);
59 /* either we deleted some cpu handles or the cpu node
60 * so we reset the offset back to the start since we
61 * can't trust the offsets anymore
65 off = fdt_node_offset_by_prop_value(blob, off,
66 "device_type", "cpu", 4);
68 debug ("%x core system found\n", num_cores);
69 debug ("deleted %d extra core entry entries from device tree\n",
72 #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
74 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
78 /* Do NOT apply fixup for backplane modes specified in DT */
79 if (phyc == PHY_INTERFACE_MODE_XGMII) {
80 conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
81 if (is_backplane_mode(conn))
84 return fdt_setprop_string(blob, offset, "phy-connection-type",
85 phy_string_for_interface(phyc));
88 #ifdef CONFIG_SYS_SRIO
89 static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
91 int off = fdt_node_offset_by_prop_value(blob, srio_off,
92 "cell-index", &port, 4);
94 off = fdt_setprop_string(blob, off, "status", "disabled");
96 printf("WARNING unable to set status for fsl,srio "
97 "port %d: %s\n", port, fdt_strerror(off));
101 static inline void ft_disable_rman(void *blob)
103 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
105 off = fdt_setprop_string(blob, off, "status", "disabled");
107 printf("WARNING unable to set status for fsl,rman %s\n",
112 static inline void ft_disable_rmu(void *blob)
114 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
116 off = fdt_setprop_string(blob, off, "status", "disabled");
118 printf("WARNING unable to set status for "
119 "fsl,srio-rmu %s\n", fdt_strerror(off));
123 void ft_srio_setup(void *blob)
125 int srio1_used = 0, srio2_used = 0;
128 /* search for srio node, if doesn't exist just return - nothing todo */
129 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
134 if (is_serdes_configured(SRIO1))
138 if (is_serdes_configured(SRIO2))
142 /* mark port1 disabled */
144 ft_disable_srio_port(blob, srio_off, 1);
146 /* mark port2 disabled */
148 ft_disable_srio_port(blob, srio_off, 2);
150 /* if both ports not used, disable controller, rmu and rman */
151 if (!srio1_used && !srio2_used) {
152 fdt_setprop_string(blob, srio_off, "status", "disabled");
154 ft_disable_rman(blob);
155 ft_disable_rmu(blob);