blob: 0d877c43be81aefb28a3f6af8b6f533646246731 [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.
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05304 *
Stefan Roese88fbf932010-04-15 16:07:28 +02005 * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
6 * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
Peter Tyser29514c72010-04-12 22:28:09 -05007 * cpu specific common code for 85xx/86xx processors.
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05308 */
9
10#include <common.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053012#include <fdt_support.h>
Kumar Gala819a4792010-06-09 22:33:53 -050013#include <asm/mp.h>
Kumar Gala8975d7a2010-12-30 12:09:53 -060014#include <asm/fsl_serdes.h>
Andy Fleming7832a462011-04-13 00:37:12 -050015#include <phy.h>
Ramneek Mehresh7f548e02011-06-08 17:14:20 +053016#include <hwconfig.h>
Kumar Gala3725f552011-07-29 08:51:26 -050017
ramneek mehreshd04f8fe2013-10-18 17:40:17 +053018#ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
19#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
20#endif
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053021
Kumar Gala819a4792010-06-09 22:33:53 -050022#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050023static int ft_del_cpuhandle(void *blob, int cpuhandle)
24{
25 int off, ret = -FDT_ERR_NOTFOUND;
26
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
29 */
30 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
31 &cpuhandle, 4);
32 while (off != -FDT_ERR_NOTFOUND) {
33 fdt_delprop(blob, off, "cpu-handle");
34 ret = 1;
35 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
36 &cpuhandle, 4);
37 }
38
39 return ret;
40}
41
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053042void ft_fixup_num_cores(void *blob) {
43 int off, num_cores, del_cores;
44
45 del_cores = 0;
46 num_cores = cpu_numcores();
47
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);
York Sun2adf2ce2012-08-17 08:20:26 +000051 u32 phys_cpu_id = thread_to_core(*reg);
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053052
York Sun2adf2ce2012-08-17 08:20:26 +000053 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
Kumar Galaa24926d2010-06-09 13:14:28 -050054 int ph = fdt_get_phandle(blob, off);
55
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);
59 del_cores++;
60 }
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
64 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053065 off = -1;
66 }
67 off = fdt_node_offset_by_prop_value(blob, off,
68 "device_type", "cpu", 4);
69 }
70 debug ("%x core system found\n", num_cores);
71 debug ("deleted %d extra core entry entries from device tree\n",
72 del_cores);
73}
Kim Phillips6578bae2010-05-28 08:00:14 +000074#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
75
Andy Fleming7832a462011-04-13 00:37:12 -050076int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -050077{
Kumar Gala6bc9fd52010-09-30 09:15:03 -050078 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -050079 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -050080}
Kumar Gala8975d7a2010-12-30 12:09:53 -060081
82#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -050083static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
84{
85 int off = fdt_node_offset_by_prop_value(blob, srio_off,
86 "cell-index", &port, 4);
87 if (off >= 0) {
88 off = fdt_setprop_string(blob, off, "status", "disabled");
89 if (off > 0)
90 printf("WARNING unable to set status for fsl,srio "
91 "port %d: %s\n", port, fdt_strerror(off));
92 }
93}
94
95static inline void ft_disable_rman(void *blob)
96{
97 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
98 if (off >= 0) {
99 off = fdt_setprop_string(blob, off, "status", "disabled");
100 if (off > 0)
101 printf("WARNING unable to set status for fsl,rman %s\n",
102 fdt_strerror(off));
103 }
104}
105
106static inline void ft_disable_rmu(void *blob)
107{
108 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
109 if (off >= 0) {
110 off = fdt_setprop_string(blob, off, "status", "disabled");
111 if (off > 0)
112 printf("WARNING unable to set status for "
113 "fsl,srio-rmu %s\n", fdt_strerror(off));
114 }
115}
116
Kumar Gala8975d7a2010-12-30 12:09:53 -0600117void ft_srio_setup(void *blob)
118{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500119 int srio1_used = 0, srio2_used = 0;
120 int srio_off;
121
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");
124 if (srio_off < 0)
125 return ;
126
Kumar Gala8975d7a2010-12-30 12:09:53 -0600127#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500128 if (is_serdes_configured(SRIO1))
129 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600130#endif
131#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500132 if (is_serdes_configured(SRIO2))
133 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600134#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500135
136 /* mark port1 disabled */
137 if (!srio1_used)
138 ft_disable_srio_port(blob, srio_off, 1);
139
140 /* mark port2 disabled */
141 if (!srio2_used)
142 ft_disable_srio_port(blob, srio_off, 2);
143
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");
147
148 ft_disable_rman(blob);
149 ft_disable_rmu(blob);
150 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600151}
152#endif