1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2009-2014 Freescale Semiconductor, Inc.
5 * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
6 * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
7 * cpu specific common code for 85xx/86xx processors.
11 #include <linux/libfdt.h>
12 #include <fdt_support.h>
14 #include <asm/fsl_serdes.h>
18 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
19 #define CONFIG_USB_MAX_CONTROLLER_COUNT 1
22 #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
23 static int ft_del_cpuhandle(void *blob, int cpuhandle)
25 int off, ret = -FDT_ERR_NOTFOUND;
27 /* if we find a match, we'll delete at it which point the offsets are
28 * invalid so we start over from the beginning
30 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
32 while (off != -FDT_ERR_NOTFOUND) {
33 fdt_delprop(blob, off, "cpu-handle");
35 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
42 void ft_fixup_num_cores(void *blob) {
43 int off, num_cores, del_cores;
46 num_cores = cpu_numcores();
48 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
49 while (off != -FDT_ERR_NOTFOUND) {
50 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
51 u32 phys_cpu_id = thread_to_core(*reg);
53 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
54 int ph = fdt_get_phandle(blob, off);
56 /* Delete the cpu node once there are no cpu handles */
57 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
58 fdt_del_node(blob, off);
61 /* either we deleted some cpu handles or the cpu node
62 * so we reset the offset back to the start since we
63 * can't trust the offsets anymore
67 off = fdt_node_offset_by_prop_value(blob, off,
68 "device_type", "cpu", 4);
70 debug ("%x core system found\n", num_cores);
71 debug ("deleted %d extra core entry entries from device tree\n",
74 #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
76 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
78 return fdt_setprop_string(blob, offset, "phy-connection-type",
79 phy_string_for_interface(phyc));
82 #ifdef CONFIG_SYS_SRIO
83 static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
85 int off = fdt_node_offset_by_prop_value(blob, srio_off,
86 "cell-index", &port, 4);
88 off = fdt_setprop_string(blob, off, "status", "disabled");
90 printf("WARNING unable to set status for fsl,srio "
91 "port %d: %s\n", port, fdt_strerror(off));
95 static inline void ft_disable_rman(void *blob)
97 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
99 off = fdt_setprop_string(blob, off, "status", "disabled");
101 printf("WARNING unable to set status for fsl,rman %s\n",
106 static inline void ft_disable_rmu(void *blob)
108 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
110 off = fdt_setprop_string(blob, off, "status", "disabled");
112 printf("WARNING unable to set status for "
113 "fsl,srio-rmu %s\n", fdt_strerror(off));
117 void ft_srio_setup(void *blob)
119 int srio1_used = 0, srio2_used = 0;
122 /* search for srio node, if doesn't exist just return - nothing todo */
123 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
128 if (is_serdes_configured(SRIO1))
132 if (is_serdes_configured(SRIO2))
136 /* mark port1 disabled */
138 ft_disable_srio_port(blob, srio_off, 1);
140 /* mark port2 disabled */
142 ft_disable_srio_port(blob, srio_off, 2);
144 /* if both ports not used, disable controller, rmu and rman */
145 if (!srio1_used && !srio2_used) {
146 fdt_setprop_string(blob, srio_off, "status", "disabled");
148 ft_disable_rman(blob);
149 ft_disable_rmu(blob);