blob: 300429024878139daf7b3b39418025ffc764c98e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05302/*
ramneek mehresh67b5c992014-08-22 10:56:05 +05303 * Copyright 2009-2014 Freescale Semiconductor, Inc.
Florinel Iordachea618a5a2020-03-16 15:35:59 +02004 * Copyright 2020 NXP
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05305 *
Stefan Roese88fbf932010-04-15 16:07:28 +02006 * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
7 * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
Peter Tyser29514c72010-04-12 22:28:09 -05008 * cpu specific common code for 85xx/86xx processors.
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05309 */
10
11#include <common.h>
Simon Glass33d1e702019-11-14 12:57:32 -070012#include <cpu_func.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053014#include <fdt_support.h>
Kumar Gala819a4792010-06-09 22:33:53 -050015#include <asm/mp.h>
Kumar Gala8975d7a2010-12-30 12:09:53 -060016#include <asm/fsl_serdes.h>
Andy Fleming7832a462011-04-13 00:37:12 -050017#include <phy.h>
Ramneek Mehresh7f548e02011-06-08 17:14:20 +053018#include <hwconfig.h>
Kumar Gala3725f552011-07-29 08:51:26 -050019
Kumar Gala819a4792010-06-09 22:33:53 -050020#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050021static int ft_del_cpuhandle(void *blob, int cpuhandle)
22{
23 int off, ret = -FDT_ERR_NOTFOUND;
24
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
27 */
28 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
29 &cpuhandle, 4);
30 while (off != -FDT_ERR_NOTFOUND) {
31 fdt_delprop(blob, off, "cpu-handle");
32 ret = 1;
33 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
34 &cpuhandle, 4);
35 }
36
37 return ret;
38}
39
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053040void ft_fixup_num_cores(void *blob) {
41 int off, num_cores, del_cores;
42
43 del_cores = 0;
44 num_cores = cpu_numcores();
45
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);
York Sun2adf2ce2012-08-17 08:20:26 +000049 u32 phys_cpu_id = thread_to_core(*reg);
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053050
York Sun2adf2ce2012-08-17 08:20:26 +000051 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
Kumar Galaa24926d2010-06-09 13:14:28 -050052 int ph = fdt_get_phandle(blob, off);
53
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);
57 del_cores++;
58 }
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
62 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053063 off = -1;
64 }
65 off = fdt_node_offset_by_prop_value(blob, off,
66 "device_type", "cpu", 4);
67 }
68 debug ("%x core system found\n", num_cores);
69 debug ("deleted %d extra core entry entries from device tree\n",
70 del_cores);
71}
Kim Phillips6578bae2010-05-28 08:00:14 +000072#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
73
Andy Fleming7832a462011-04-13 00:37:12 -050074int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -050075{
Florinel Iordachea618a5a2020-03-16 15:35:59 +020076 const char *conn;
77
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))
82 return 0;
83 }
Kumar Gala6bc9fd52010-09-30 09:15:03 -050084 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -050085 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -050086}
Kumar Gala8975d7a2010-12-30 12:09:53 -060087
88#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -050089static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
90{
91 int off = fdt_node_offset_by_prop_value(blob, srio_off,
92 "cell-index", &port, 4);
93 if (off >= 0) {
94 off = fdt_setprop_string(blob, off, "status", "disabled");
95 if (off > 0)
96 printf("WARNING unable to set status for fsl,srio "
97 "port %d: %s\n", port, fdt_strerror(off));
98 }
99}
100
101static inline void ft_disable_rman(void *blob)
102{
103 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
104 if (off >= 0) {
105 off = fdt_setprop_string(blob, off, "status", "disabled");
106 if (off > 0)
107 printf("WARNING unable to set status for fsl,rman %s\n",
108 fdt_strerror(off));
109 }
110}
111
112static inline void ft_disable_rmu(void *blob)
113{
114 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
115 if (off >= 0) {
116 off = fdt_setprop_string(blob, off, "status", "disabled");
117 if (off > 0)
118 printf("WARNING unable to set status for "
119 "fsl,srio-rmu %s\n", fdt_strerror(off));
120 }
121}
122
Kumar Gala8975d7a2010-12-30 12:09:53 -0600123void ft_srio_setup(void *blob)
124{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500125 int srio1_used = 0, srio2_used = 0;
126 int srio_off;
127
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");
130 if (srio_off < 0)
Bin Meng75a6a372022-10-26 12:40:07 +0800131 return;
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500132
Kumar Gala8975d7a2010-12-30 12:09:53 -0600133#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500134 if (is_serdes_configured(SRIO1))
135 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600136#endif
137#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500138 if (is_serdes_configured(SRIO2))
139 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600140#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500141
142 /* mark port1 disabled */
143 if (!srio1_used)
144 ft_disable_srio_port(blob, srio_off, 1);
145
146 /* mark port2 disabled */
147 if (!srio2_used)
148 ft_disable_srio_port(blob, srio_off, 2);
149
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");
153
154 ft_disable_rman(blob);
155 ft_disable_rmu(blob);
156 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600157}
158#endif