blob: f1c1cbc1c3c60f4cbe08a47cbb4c4d02e69d6ff6 [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
Simon Glass33d1e702019-11-14 12:57:32 -070011#include <cpu_func.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090012#include <linux/libfdt.h>
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053013#include <fdt_support.h>
Kumar Gala819a4792010-06-09 22:33:53 -050014#include <asm/mp.h>
Kumar Gala8975d7a2010-12-30 12:09:53 -060015#include <asm/fsl_serdes.h>
Andy Fleming7832a462011-04-13 00:37:12 -050016#include <phy.h>
Ramneek Mehresh7f548e02011-06-08 17:14:20 +053017#include <hwconfig.h>
Kumar Gala3725f552011-07-29 08:51:26 -050018
Kumar Gala819a4792010-06-09 22:33:53 -050019#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050020static int ft_del_cpuhandle(void *blob, int cpuhandle)
21{
22 int off, ret = -FDT_ERR_NOTFOUND;
23
24 /* if we find a match, we'll delete at it which point the offsets are
25 * invalid so we start over from the beginning
26 */
27 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
28 &cpuhandle, 4);
29 while (off != -FDT_ERR_NOTFOUND) {
30 fdt_delprop(blob, off, "cpu-handle");
31 ret = 1;
32 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
33 &cpuhandle, 4);
34 }
35
36 return ret;
37}
38
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053039void ft_fixup_num_cores(void *blob) {
40 int off, num_cores, del_cores;
41
42 del_cores = 0;
43 num_cores = cpu_numcores();
44
45 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
46 while (off != -FDT_ERR_NOTFOUND) {
47 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
York Sun2adf2ce2012-08-17 08:20:26 +000048 u32 phys_cpu_id = thread_to_core(*reg);
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053049
York Sun2adf2ce2012-08-17 08:20:26 +000050 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
Kumar Galaa24926d2010-06-09 13:14:28 -050051 int ph = fdt_get_phandle(blob, off);
52
53 /* Delete the cpu node once there are no cpu handles */
54 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
55 fdt_del_node(blob, off);
56 del_cores++;
57 }
58 /* either we deleted some cpu handles or the cpu node
59 * so we reset the offset back to the start since we
60 * can't trust the offsets anymore
61 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053062 off = -1;
63 }
64 off = fdt_node_offset_by_prop_value(blob, off,
65 "device_type", "cpu", 4);
66 }
67 debug ("%x core system found\n", num_cores);
68 debug ("deleted %d extra core entry entries from device tree\n",
69 del_cores);
70}
Kim Phillips6578bae2010-05-28 08:00:14 +000071#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
72
Andy Fleming7832a462011-04-13 00:37:12 -050073int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -050074{
Florinel Iordachea618a5a2020-03-16 15:35:59 +020075 const char *conn;
76
77 /* Do NOT apply fixup for backplane modes specified in DT */
78 if (phyc == PHY_INTERFACE_MODE_XGMII) {
79 conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
80 if (is_backplane_mode(conn))
81 return 0;
82 }
Kumar Gala6bc9fd52010-09-30 09:15:03 -050083 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -050084 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -050085}
Kumar Gala8975d7a2010-12-30 12:09:53 -060086
87#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -050088static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
89{
90 int off = fdt_node_offset_by_prop_value(blob, srio_off,
91 "cell-index", &port, 4);
92 if (off >= 0) {
93 off = fdt_setprop_string(blob, off, "status", "disabled");
94 if (off > 0)
95 printf("WARNING unable to set status for fsl,srio "
96 "port %d: %s\n", port, fdt_strerror(off));
97 }
98}
99
100static inline void ft_disable_rman(void *blob)
101{
102 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
103 if (off >= 0) {
104 off = fdt_setprop_string(blob, off, "status", "disabled");
105 if (off > 0)
106 printf("WARNING unable to set status for fsl,rman %s\n",
107 fdt_strerror(off));
108 }
109}
110
111static inline void ft_disable_rmu(void *blob)
112{
113 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
114 if (off >= 0) {
115 off = fdt_setprop_string(blob, off, "status", "disabled");
116 if (off > 0)
117 printf("WARNING unable to set status for "
118 "fsl,srio-rmu %s\n", fdt_strerror(off));
119 }
120}
121
Kumar Gala8975d7a2010-12-30 12:09:53 -0600122void ft_srio_setup(void *blob)
123{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500124 int srio1_used = 0, srio2_used = 0;
125 int srio_off;
126
127 /* search for srio node, if doesn't exist just return - nothing todo */
128 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
129 if (srio_off < 0)
Bin Meng75a6a372022-10-26 12:40:07 +0800130 return;
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500131
Kumar Gala8975d7a2010-12-30 12:09:53 -0600132#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500133 if (is_serdes_configured(SRIO1))
134 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600135#endif
136#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500137 if (is_serdes_configured(SRIO2))
138 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600139#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500140
141 /* mark port1 disabled */
142 if (!srio1_used)
143 ft_disable_srio_port(blob, srio_off, 1);
144
145 /* mark port2 disabled */
146 if (!srio2_used)
147 ft_disable_srio_port(blob, srio_off, 2);
148
149 /* if both ports not used, disable controller, rmu and rman */
150 if (!srio1_used && !srio2_used) {
151 fdt_setprop_string(blob, srio_off, "status", "disabled");
152
153 ft_disable_rman(blob);
154 ft_disable_rmu(blob);
155 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600156}
157#endif