blob: bc1c30e44c2c0262e0a0a02c666875fa9f4ab5f2 [file] [log] [blame]
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05301/*
ramneek mehresh6bce6112012-02-06 19:17:29 +00002 * Copyright 2009-2012 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>
Ramneek Mehresh7f548e02011-06-08 17:14:20 +053032#include <hwconfig.h>
Kumar Gala3725f552011-07-29 08:51:26 -050033
34#define FSL_MAX_NUM_USB_CTRLS 2
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053035
Kumar Gala819a4792010-06-09 22:33:53 -050036#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050037static int ft_del_cpuhandle(void *blob, int cpuhandle)
38{
39 int off, ret = -FDT_ERR_NOTFOUND;
40
41 /* if we find a match, we'll delete at it which point the offsets are
42 * invalid so we start over from the beginning
43 */
44 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
45 &cpuhandle, 4);
46 while (off != -FDT_ERR_NOTFOUND) {
47 fdt_delprop(blob, off, "cpu-handle");
48 ret = 1;
49 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
50 &cpuhandle, 4);
51 }
52
53 return ret;
54}
55
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053056void ft_fixup_num_cores(void *blob) {
57 int off, num_cores, del_cores;
58
59 del_cores = 0;
60 num_cores = cpu_numcores();
61
62 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
63 while (off != -FDT_ERR_NOTFOUND) {
64 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
65
Timur Tabi47289422011-08-05 16:15:24 -050066 if (!is_core_valid(*reg) || is_core_disabled(*reg)) {
Kumar Galaa24926d2010-06-09 13:14:28 -050067 int ph = fdt_get_phandle(blob, off);
68
69 /* Delete the cpu node once there are no cpu handles */
70 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
71 fdt_del_node(blob, off);
72 del_cores++;
73 }
74 /* either we deleted some cpu handles or the cpu node
75 * so we reset the offset back to the start since we
76 * can't trust the offsets anymore
77 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053078 off = -1;
79 }
80 off = fdt_node_offset_by_prop_value(blob, off,
81 "device_type", "cpu", 4);
82 }
83 debug ("%x core system found\n", num_cores);
84 debug ("deleted %d extra core entry entries from device tree\n",
85 del_cores);
86}
Kim Phillips6578bae2010-05-28 08:00:14 +000087#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
88
89#ifdef CONFIG_HAS_FSL_DR_USB
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +053090static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
91 const char *phy_type, int start_offset)
Kim Phillips6578bae2010-05-28 08:00:14 +000092{
Kim Phillips6578bae2010-05-28 08:00:14 +000093 const char *compat = "fsl-usb2-dr";
94 const char *prop_mode = "dr_mode";
95 const char *prop_type = "phy_type";
96 int node_offset;
97 int err;
98
Ramneek Mehresh7f548e02011-06-08 17:14:20 +053099 node_offset = fdt_node_offset_by_compatible(blob,
100 start_offset, compat);
Kim Phillips6578bae2010-05-28 08:00:14 +0000101 if (node_offset < 0) {
102 printf("WARNING: could not find compatible node %s: %s.\n",
103 compat, fdt_strerror(node_offset));
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530104 return -1;
Kim Phillips6578bae2010-05-28 08:00:14 +0000105 }
106
107 if (mode) {
108 err = fdt_setprop(blob, node_offset, prop_mode, mode,
109 strlen(mode) + 1);
110 if (err < 0)
111 printf("WARNING: could not set %s for %s: %s.\n",
112 prop_mode, compat, fdt_strerror(err));
113 }
114
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530115 if (phy_type) {
116 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
117 strlen(phy_type) + 1);
Kim Phillips6578bae2010-05-28 08:00:14 +0000118 if (err < 0)
119 printf("WARNING: could not set %s for %s: %s.\n",
120 prop_type, compat, fdt_strerror(err));
121 }
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530122
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530123 return node_offset;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530124}
125
126void fdt_fixup_dr_usb(void *blob, bd_t *bd)
127{
128 const char *modes[] = { "host", "peripheral", "otg" };
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530129 const char *phys[] = { "ulpi", "utmi" };
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530130 const char *mode = NULL;
131 const char *phy_type = NULL;
132 char usb1_defined = 0;
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530133 int usb_mode_off = -1;
134 int usb_phy_off = -1;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530135 char str[5];
136 int i, j;
137
Kumar Gala3725f552011-07-29 08:51:26 -0500138 for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530139 int mode_idx = -1, phy_idx = -1;
ramneek mehresh6bce6112012-02-06 19:17:29 +0000140 snprintf(str, 5, "%s%d", "usb", i);
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530141 if (hwconfig(str)) {
ramneek mehresh6bce6112012-02-06 19:17:29 +0000142 for (j = 0; j < ARRAY_SIZE(modes); j++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530143 if (hwconfig_subarg_cmp(str, "dr_mode",
144 modes[j])) {
145 mode_idx = j;
146 break;
147 }
148 }
ramneek mehresh6bce6112012-02-06 19:17:29 +0000149 for (j = 0; j < ARRAY_SIZE(phys); j++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530150 if (hwconfig_subarg_cmp(str, "phy_type",
151 phys[j])) {
152 phy_idx = j;
153 break;
154 }
155 }
ramneek mehresh6bce6112012-02-06 19:17:29 +0000156 if (mode_idx >= 0) {
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530157 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
158 modes[mode_idx], NULL, usb_mode_off);
ramneek mehresh6bce6112012-02-06 19:17:29 +0000159 if (usb_mode_off < 0)
160 return;
161 }
162 if (phy_idx >= 0) {
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530163 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
164 NULL, phys[phy_idx], usb_phy_off);
ramneek mehresh6bce6112012-02-06 19:17:29 +0000165 if (usb_phy_off < 0)
166 return;
167 }
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530168 if (!strcmp(str, "usb1"))
169 usb1_defined = 1;
170 if (mode_idx < 0 && phy_idx < 0)
171 printf("WARNING: invalid phy or mode\n");
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530172 }
173 }
174 if (!usb1_defined) {
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530175 int usb_off = -1;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530176 mode = getenv("usb_dr_mode");
177 phy_type = getenv("usb_phy_type");
178 if (!mode && !phy_type)
179 return;
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530180 fdt_fixup_usb_mode_phy_type(blob, mode, phy_type, usb_off);
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530181 }
Kim Phillips6578bae2010-05-28 08:00:14 +0000182}
183#endif /* CONFIG_HAS_FSL_DR_USB */
184
Kim Phillips6578bae2010-05-28 08:00:14 +0000185/*
186 * update crypto node properties to a specified revision of the SEC
Kim Phillipsdef125f2010-06-01 12:24:27 -0500187 * called with sec_rev == 0 if not on an E processor
Kim Phillips6578bae2010-05-28 08:00:14 +0000188 */
Kim Phillipsdef125f2010-06-01 12:24:27 -0500189#if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
Kim Phillips6578bae2010-05-28 08:00:14 +0000190void fdt_fixup_crypto_node(void *blob, int sec_rev)
191{
192 const struct sec_rev_prop {
193 u32 sec_rev;
194 u32 num_channels;
195 u32 channel_fifo_len;
196 u32 exec_units_mask;
197 u32 descriptor_types_mask;
198 } sec_rev_prop_list [] = {
199 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
200 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
201 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
202 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
203 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
204 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
205 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
206 };
207 char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
208 sizeof("fsl,secX.Y")];
209 int crypto_node, sec_idx, err;
210 char *p;
211 u32 val;
212
213 /* locate crypto node based on lowest common compatible */
214 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
215 if (crypto_node == -FDT_ERR_NOTFOUND)
216 return;
217
218 /* delete it if not on an E-processor */
219 if (crypto_node > 0 && !sec_rev) {
220 fdt_del_node(blob, crypto_node);
221 return;
222 }
223
224 /* else we got called for possible uprev */
225 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
226 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
227 break;
228
229 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
230 puts("warning: unknown SEC revision number\n");
231 return;
232 }
233
234 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
235 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
236 if (err < 0)
237 printf("WARNING: could not set crypto property: %s\n",
238 fdt_strerror(err));
239
240 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
241 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
242 if (err < 0)
243 printf("WARNING: could not set crypto property: %s\n",
244 fdt_strerror(err));
245
246 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
247 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
248 if (err < 0)
249 printf("WARNING: could not set crypto property: %s\n",
250 fdt_strerror(err));
251
252 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
253 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
254 if (err < 0)
255 printf("WARNING: could not set crypto property: %s\n",
256 fdt_strerror(err));
257
258 val = 0;
259 while (sec_idx >= 0) {
260 p = compat_strlist + val;
261 val += sprintf(p, "fsl,sec%d.%d",
262 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
263 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
264 sec_idx--;
265 }
266 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
267 if (err < 0)
268 printf("WARNING: could not set crypto property: %s\n",
269 fdt_strerror(err));
270}
Kim Phillips1b625492010-06-01 12:24:34 -0500271#elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
272void fdt_fixup_crypto_node(void *blob, int sec_rev)
273{
274 if (!sec_rev)
275 fdt_del_node_and_alias(blob, "crypto");
276}
Kim Phillipsdef125f2010-06-01 12:24:27 -0500277#endif
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500278
Andy Fleming7832a462011-04-13 00:37:12 -0500279int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500280{
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500281 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -0500282 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500283}
Kumar Gala8975d7a2010-12-30 12:09:53 -0600284
285#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500286static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
287{
288 int off = fdt_node_offset_by_prop_value(blob, srio_off,
289 "cell-index", &port, 4);
290 if (off >= 0) {
291 off = fdt_setprop_string(blob, off, "status", "disabled");
292 if (off > 0)
293 printf("WARNING unable to set status for fsl,srio "
294 "port %d: %s\n", port, fdt_strerror(off));
295 }
296}
297
298static inline void ft_disable_rman(void *blob)
299{
300 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
301 if (off >= 0) {
302 off = fdt_setprop_string(blob, off, "status", "disabled");
303 if (off > 0)
304 printf("WARNING unable to set status for fsl,rman %s\n",
305 fdt_strerror(off));
306 }
307}
308
309static inline void ft_disable_rmu(void *blob)
310{
311 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
312 if (off >= 0) {
313 off = fdt_setprop_string(blob, off, "status", "disabled");
314 if (off > 0)
315 printf("WARNING unable to set status for "
316 "fsl,srio-rmu %s\n", fdt_strerror(off));
317 }
318}
319
Kumar Gala8975d7a2010-12-30 12:09:53 -0600320void ft_srio_setup(void *blob)
321{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500322 int srio1_used = 0, srio2_used = 0;
323 int srio_off;
324
325 /* search for srio node, if doesn't exist just return - nothing todo */
326 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
327 if (srio_off < 0)
328 return ;
329
Kumar Gala8975d7a2010-12-30 12:09:53 -0600330#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500331 if (is_serdes_configured(SRIO1))
332 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600333#endif
334#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500335 if (is_serdes_configured(SRIO2))
336 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600337#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500338
339 /* mark port1 disabled */
340 if (!srio1_used)
341 ft_disable_srio_port(blob, srio_off, 1);
342
343 /* mark port2 disabled */
344 if (!srio2_used)
345 ft_disable_srio_port(blob, srio_off, 2);
346
347 /* if both ports not used, disable controller, rmu and rman */
348 if (!srio1_used && !srio2_used) {
349 fdt_setprop_string(blob, srio_off, "status", "disabled");
350
351 ft_disable_rman(blob);
352 ft_disable_rmu(blob);
353 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600354}
355#endif