blob: 520cb90280967f5fa349c8f356aba3080f70ca61 [file] [log] [blame]
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05301/*
Kumar Gala8975d7a2010-12-30 12:09:53 -06002 * Copyright 2009-2011 Freescale Semiconductor, Inc.
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05303 *
Stefan Roese88fbf932010-04-15 16:07:28 +02004 * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
5 * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
Peter Tyser29514c72010-04-12 22:28:09 -05006 * cpu specific common code for 85xx/86xx processors.
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05307 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <libfdt.h>
28#include <fdt_support.h>
Kumar Gala819a4792010-06-09 22:33:53 -050029#include <asm/mp.h>
Kumar Gala8975d7a2010-12-30 12:09:53 -060030#include <asm/fsl_serdes.h>
Andy Fleming7832a462011-04-13 00:37:12 -050031#include <phy.h>
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053032
Kumar Gala819a4792010-06-09 22:33:53 -050033#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050034static int ft_del_cpuhandle(void *blob, int cpuhandle)
35{
36 int off, ret = -FDT_ERR_NOTFOUND;
37
38 /* if we find a match, we'll delete at it which point the offsets are
39 * invalid so we start over from the beginning
40 */
41 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
42 &cpuhandle, 4);
43 while (off != -FDT_ERR_NOTFOUND) {
44 fdt_delprop(blob, off, "cpu-handle");
45 ret = 1;
46 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
47 &cpuhandle, 4);
48 }
49
50 return ret;
51}
52
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053053void ft_fixup_num_cores(void *blob) {
54 int off, num_cores, del_cores;
55
56 del_cores = 0;
57 num_cores = cpu_numcores();
58
59 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
60 while (off != -FDT_ERR_NOTFOUND) {
61 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
62
Kumar Gala819a4792010-06-09 22:33:53 -050063 if ((*reg > num_cores-1) || (is_core_disabled(*reg))) {
Kumar Galaa24926d2010-06-09 13:14:28 -050064 int ph = fdt_get_phandle(blob, off);
65
66 /* Delete the cpu node once there are no cpu handles */
67 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
68 fdt_del_node(blob, off);
69 del_cores++;
70 }
71 /* either we deleted some cpu handles or the cpu node
72 * so we reset the offset back to the start since we
73 * can't trust the offsets anymore
74 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053075 off = -1;
76 }
77 off = fdt_node_offset_by_prop_value(blob, off,
78 "device_type", "cpu", 4);
79 }
80 debug ("%x core system found\n", num_cores);
81 debug ("deleted %d extra core entry entries from device tree\n",
82 del_cores);
83}
Kim Phillips6578bae2010-05-28 08:00:14 +000084#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
85
86#ifdef CONFIG_HAS_FSL_DR_USB
87void fdt_fixup_dr_usb(void *blob, bd_t *bd)
88{
89 char *mode;
90 char *type;
91 const char *compat = "fsl-usb2-dr";
92 const char *prop_mode = "dr_mode";
93 const char *prop_type = "phy_type";
94 int node_offset;
95 int err;
96
97 mode = getenv("usb_dr_mode");
98 type = getenv("usb_phy_type");
99 if (!mode && !type)
100 return;
101
102 node_offset = fdt_node_offset_by_compatible(blob, 0, compat);
103 if (node_offset < 0) {
104 printf("WARNING: could not find compatible node %s: %s.\n",
105 compat, fdt_strerror(node_offset));
106 return;
107 }
108
109 if (mode) {
110 err = fdt_setprop(blob, node_offset, prop_mode, mode,
111 strlen(mode) + 1);
112 if (err < 0)
113 printf("WARNING: could not set %s for %s: %s.\n",
114 prop_mode, compat, fdt_strerror(err));
115 }
116
117 if (type) {
118 err = fdt_setprop(blob, node_offset, prop_type, type,
119 strlen(type) + 1);
120 if (err < 0)
121 printf("WARNING: could not set %s for %s: %s.\n",
122 prop_type, compat, fdt_strerror(err));
123 }
124}
125#endif /* CONFIG_HAS_FSL_DR_USB */
126
Kim Phillips6578bae2010-05-28 08:00:14 +0000127/*
128 * update crypto node properties to a specified revision of the SEC
Kim Phillipsdef125f2010-06-01 12:24:27 -0500129 * called with sec_rev == 0 if not on an E processor
Kim Phillips6578bae2010-05-28 08:00:14 +0000130 */
Kim Phillipsdef125f2010-06-01 12:24:27 -0500131#if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
Kim Phillips6578bae2010-05-28 08:00:14 +0000132void fdt_fixup_crypto_node(void *blob, int sec_rev)
133{
134 const struct sec_rev_prop {
135 u32 sec_rev;
136 u32 num_channels;
137 u32 channel_fifo_len;
138 u32 exec_units_mask;
139 u32 descriptor_types_mask;
140 } sec_rev_prop_list [] = {
141 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
142 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
143 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
144 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
145 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
146 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
147 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
148 };
149 char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
150 sizeof("fsl,secX.Y")];
151 int crypto_node, sec_idx, err;
152 char *p;
153 u32 val;
154
155 /* locate crypto node based on lowest common compatible */
156 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
157 if (crypto_node == -FDT_ERR_NOTFOUND)
158 return;
159
160 /* delete it if not on an E-processor */
161 if (crypto_node > 0 && !sec_rev) {
162 fdt_del_node(blob, crypto_node);
163 return;
164 }
165
166 /* else we got called for possible uprev */
167 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
168 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
169 break;
170
171 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
172 puts("warning: unknown SEC revision number\n");
173 return;
174 }
175
176 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
177 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
178 if (err < 0)
179 printf("WARNING: could not set crypto property: %s\n",
180 fdt_strerror(err));
181
182 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
183 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
184 if (err < 0)
185 printf("WARNING: could not set crypto property: %s\n",
186 fdt_strerror(err));
187
188 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
189 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
190 if (err < 0)
191 printf("WARNING: could not set crypto property: %s\n",
192 fdt_strerror(err));
193
194 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
195 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
196 if (err < 0)
197 printf("WARNING: could not set crypto property: %s\n",
198 fdt_strerror(err));
199
200 val = 0;
201 while (sec_idx >= 0) {
202 p = compat_strlist + val;
203 val += sprintf(p, "fsl,sec%d.%d",
204 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
205 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
206 sec_idx--;
207 }
208 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
209 if (err < 0)
210 printf("WARNING: could not set crypto property: %s\n",
211 fdt_strerror(err));
212}
Kim Phillips1b625492010-06-01 12:24:34 -0500213#elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
214void fdt_fixup_crypto_node(void *blob, int sec_rev)
215{
216 if (!sec_rev)
217 fdt_del_node_and_alias(blob, "crypto");
218}
Kim Phillipsdef125f2010-06-01 12:24:27 -0500219#endif
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500220
Andy Fleming7832a462011-04-13 00:37:12 -0500221int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500222{
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500223 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -0500224 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500225}
Kumar Gala8975d7a2010-12-30 12:09:53 -0600226
227#ifdef CONFIG_SYS_SRIO
228void ft_srio_setup(void *blob)
229{
230#ifdef CONFIG_SRIO1
231 if (!is_serdes_configured(SRIO1)) {
232 fdt_del_node_and_alias(blob, "rio0");
233 }
234#else
235 fdt_del_node_and_alias(blob, "rio0");
236#endif
237#ifdef CONFIG_SRIO2
238 if (!is_serdes_configured(SRIO2)) {
239 fdt_del_node_and_alias(blob, "rio1");
240 }
241#else
242 fdt_del_node_and_alias(blob, "rio1");
243#endif
244}
245#endif