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