blob: 67f8b1000183c104ba85c1b2684fd9c0ee408e69 [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
ramneek mehreshd04f8fe2013-10-18 17:40:17 +053020#ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
21#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
22#endif
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053023
Kumar Gala819a4792010-06-09 22:33:53 -050024#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050025static int ft_del_cpuhandle(void *blob, int cpuhandle)
26{
27 int off, ret = -FDT_ERR_NOTFOUND;
28
29 /* if we find a match, we'll delete at it which point the offsets are
30 * invalid so we start over from the beginning
31 */
32 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
33 &cpuhandle, 4);
34 while (off != -FDT_ERR_NOTFOUND) {
35 fdt_delprop(blob, off, "cpu-handle");
36 ret = 1;
37 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
38 &cpuhandle, 4);
39 }
40
41 return ret;
42}
43
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053044void ft_fixup_num_cores(void *blob) {
45 int off, num_cores, del_cores;
46
47 del_cores = 0;
48 num_cores = cpu_numcores();
49
50 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
51 while (off != -FDT_ERR_NOTFOUND) {
52 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
York Sun2adf2ce2012-08-17 08:20:26 +000053 u32 phys_cpu_id = thread_to_core(*reg);
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053054
York Sun2adf2ce2012-08-17 08:20:26 +000055 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
Kumar Galaa24926d2010-06-09 13:14:28 -050056 int ph = fdt_get_phandle(blob, off);
57
58 /* Delete the cpu node once there are no cpu handles */
59 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
60 fdt_del_node(blob, off);
61 del_cores++;
62 }
63 /* either we deleted some cpu handles or the cpu node
64 * so we reset the offset back to the start since we
65 * can't trust the offsets anymore
66 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053067 off = -1;
68 }
69 off = fdt_node_offset_by_prop_value(blob, off,
70 "device_type", "cpu", 4);
71 }
72 debug ("%x core system found\n", num_cores);
73 debug ("deleted %d extra core entry entries from device tree\n",
74 del_cores);
75}
Kim Phillips6578bae2010-05-28 08:00:14 +000076#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
77
Andy Fleming7832a462011-04-13 00:37:12 -050078int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -050079{
Florinel Iordachea618a5a2020-03-16 15:35:59 +020080 const char *conn;
81
82 /* Do NOT apply fixup for backplane modes specified in DT */
83 if (phyc == PHY_INTERFACE_MODE_XGMII) {
84 conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
85 if (is_backplane_mode(conn))
86 return 0;
87 }
Kumar Gala6bc9fd52010-09-30 09:15:03 -050088 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -050089 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -050090}
Kumar Gala8975d7a2010-12-30 12:09:53 -060091
92#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -050093static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
94{
95 int off = fdt_node_offset_by_prop_value(blob, srio_off,
96 "cell-index", &port, 4);
97 if (off >= 0) {
98 off = fdt_setprop_string(blob, off, "status", "disabled");
99 if (off > 0)
100 printf("WARNING unable to set status for fsl,srio "
101 "port %d: %s\n", port, fdt_strerror(off));
102 }
103}
104
105static inline void ft_disable_rman(void *blob)
106{
107 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
108 if (off >= 0) {
109 off = fdt_setprop_string(blob, off, "status", "disabled");
110 if (off > 0)
111 printf("WARNING unable to set status for fsl,rman %s\n",
112 fdt_strerror(off));
113 }
114}
115
116static inline void ft_disable_rmu(void *blob)
117{
118 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
119 if (off >= 0) {
120 off = fdt_setprop_string(blob, off, "status", "disabled");
121 if (off > 0)
122 printf("WARNING unable to set status for "
123 "fsl,srio-rmu %s\n", fdt_strerror(off));
124 }
125}
126
Kumar Gala8975d7a2010-12-30 12:09:53 -0600127void ft_srio_setup(void *blob)
128{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500129 int srio1_used = 0, srio2_used = 0;
130 int srio_off;
131
132 /* search for srio node, if doesn't exist just return - nothing todo */
133 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
134 if (srio_off < 0)
135 return ;
136
Kumar Gala8975d7a2010-12-30 12:09:53 -0600137#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500138 if (is_serdes_configured(SRIO1))
139 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600140#endif
141#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500142 if (is_serdes_configured(SRIO2))
143 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600144#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500145
146 /* mark port1 disabled */
147 if (!srio1_used)
148 ft_disable_srio_port(blob, srio_off, 1);
149
150 /* mark port2 disabled */
151 if (!srio2_used)
152 ft_disable_srio_port(blob, srio_off, 2);
153
154 /* if both ports not used, disable controller, rmu and rman */
155 if (!srio1_used && !srio2_used) {
156 fdt_setprop_string(blob, srio_off, "status", "disabled");
157
158 ft_disable_rman(blob);
159 ft_disable_rmu(blob);
160 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600161}
162#endif