blob: 1986fea030a4eaa25ea533c838f2d9d2810df63b [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);
York Sun2adf2ce2012-08-17 08:20:26 +000065 u32 phys_cpu_id = thread_to_core(*reg);
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053066
York Sun2adf2ce2012-08-17 08:20:26 +000067 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
Kumar Galaa24926d2010-06-09 13:14:28 -050068 int ph = fdt_get_phandle(blob, off);
69
70 /* Delete the cpu node once there are no cpu handles */
71 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
72 fdt_del_node(blob, off);
73 del_cores++;
74 }
75 /* either we deleted some cpu handles or the cpu node
76 * so we reset the offset back to the start since we
77 * can't trust the offsets anymore
78 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053079 off = -1;
80 }
81 off = fdt_node_offset_by_prop_value(blob, off,
82 "device_type", "cpu", 4);
83 }
84 debug ("%x core system found\n", num_cores);
85 debug ("deleted %d extra core entry entries from device tree\n",
86 del_cores);
87}
Kim Phillips6578bae2010-05-28 08:00:14 +000088#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
89
ramneek mehresh800c2062012-02-10 00:36:43 +000090#if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +053091static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
92 const char *phy_type, int start_offset)
Kim Phillips6578bae2010-05-28 08:00:14 +000093{
ramneek mehresh800c2062012-02-10 00:36:43 +000094 const char *compat_dr = "fsl-usb2-dr";
95 const char *compat_mph = "fsl-usb2-mph";
Kim Phillips6578bae2010-05-28 08:00:14 +000096 const char *prop_mode = "dr_mode";
97 const char *prop_type = "phy_type";
ramneek mehresh800c2062012-02-10 00:36:43 +000098 const char *node_type = NULL;
Kim Phillips6578bae2010-05-28 08:00:14 +000099 int node_offset;
100 int err;
101
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530102 node_offset = fdt_node_offset_by_compatible(blob,
ramneek mehresh800c2062012-02-10 00:36:43 +0000103 start_offset, compat_mph);
Kim Phillips6578bae2010-05-28 08:00:14 +0000104 if (node_offset < 0) {
ramneek mehresh800c2062012-02-10 00:36:43 +0000105 node_offset = fdt_node_offset_by_compatible(blob,
106 start_offset, compat_dr);
107 if (node_offset < 0) {
108 printf("WARNING: could not find compatible"
109 " node %s or %s: %s.\n", compat_mph,
110 compat_dr, fdt_strerror(node_offset));
111 return -1;
112 } else
113 node_type = compat_dr;
114 } else
115 node_type = compat_mph;
Kim Phillips6578bae2010-05-28 08:00:14 +0000116
117 if (mode) {
118 err = fdt_setprop(blob, node_offset, prop_mode, mode,
119 strlen(mode) + 1);
120 if (err < 0)
121 printf("WARNING: could not set %s for %s: %s.\n",
ramneek mehresh800c2062012-02-10 00:36:43 +0000122 prop_mode, node_type, fdt_strerror(err));
Kim Phillips6578bae2010-05-28 08:00:14 +0000123 }
124
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530125 if (phy_type) {
126 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
127 strlen(phy_type) + 1);
Kim Phillips6578bae2010-05-28 08:00:14 +0000128 if (err < 0)
129 printf("WARNING: could not set %s for %s: %s.\n",
ramneek mehresh800c2062012-02-10 00:36:43 +0000130 prop_type, node_type, fdt_strerror(err));
Kim Phillips6578bae2010-05-28 08:00:14 +0000131 }
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530132
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530133 return node_offset;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530134}
135
136void fdt_fixup_dr_usb(void *blob, bd_t *bd)
137{
138 const char *modes[] = { "host", "peripheral", "otg" };
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530139 const char *phys[] = { "ulpi", "utmi" };
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530140 const char *mode = NULL;
141 const char *phy_type = NULL;
ramneek mehreshff6a0242012-09-18 22:28:51 +0000142 const char *dr_mode_type = NULL;
143 const char *dr_phy_type = NULL;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530144 char usb1_defined = 0;
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530145 int usb_mode_off = -1;
146 int usb_phy_off = -1;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530147 char str[5];
148 int i, j;
149
Kumar Gala3725f552011-07-29 08:51:26 -0500150 for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530151 int mode_idx = -1, phy_idx = -1;
ramneek mehresh6bce6112012-02-06 19:17:29 +0000152 snprintf(str, 5, "%s%d", "usb", i);
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530153 if (hwconfig(str)) {
ramneek mehresh6bce6112012-02-06 19:17:29 +0000154 for (j = 0; j < ARRAY_SIZE(modes); j++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530155 if (hwconfig_subarg_cmp(str, "dr_mode",
156 modes[j])) {
157 mode_idx = j;
158 break;
159 }
160 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000161
ramneek mehresh6bce6112012-02-06 19:17:29 +0000162 for (j = 0; j < ARRAY_SIZE(phys); j++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530163 if (hwconfig_subarg_cmp(str, "phy_type",
164 phys[j])) {
165 phy_idx = j;
166 break;
167 }
168 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000169
170 dr_mode_type = modes[mode_idx];
171 dr_phy_type = phys[phy_idx];
172
173 /* use usb_dr_mode and usb_phy_type if
174 usb1_defined = 0; these variables are to
175 be deprecated */
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530176 if (!strcmp(str, "usb1"))
177 usb1_defined = 1;
ramneek mehreshff6a0242012-09-18 22:28:51 +0000178
179 if (mode_idx < 0 && phy_idx < 0) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530180 printf("WARNING: invalid phy or mode\n");
ramneek mehreshff6a0242012-09-18 22:28:51 +0000181 return;
182 }
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530183 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000184
185 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
186 dr_mode_type, NULL, usb_mode_off);
187
188 if (usb_mode_off < 0)
189 return;
190
191 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
192 NULL, dr_phy_type, usb_phy_off);
193
194 if (usb_phy_off < 0)
195 return;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530196 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000197
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530198 if (!usb1_defined) {
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530199 int usb_off = -1;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530200 mode = getenv("usb_dr_mode");
201 phy_type = getenv("usb_phy_type");
ramneek mehreshff6a0242012-09-18 22:28:51 +0000202 if (mode || phy_type) {
203 printf("WARNING: usb_dr_mode and usb_phy_type "
204 "are to be deprecated soon. Use "
205 "hwconfig to set these values instead!!\n");
206 fdt_fixup_usb_mode_phy_type(blob, mode,
207 phy_type, usb_off);
208 }
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530209 }
Kim Phillips6578bae2010-05-28 08:00:14 +0000210}
ramneek mehresh800c2062012-02-10 00:36:43 +0000211#endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */
Kim Phillips6578bae2010-05-28 08:00:14 +0000212
Kim Phillips6578bae2010-05-28 08:00:14 +0000213/*
214 * update crypto node properties to a specified revision of the SEC
Kim Phillipsdef125f2010-06-01 12:24:27 -0500215 * called with sec_rev == 0 if not on an E processor
Kim Phillips6578bae2010-05-28 08:00:14 +0000216 */
Kim Phillipsdef125f2010-06-01 12:24:27 -0500217#if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
Kim Phillips6578bae2010-05-28 08:00:14 +0000218void fdt_fixup_crypto_node(void *blob, int sec_rev)
219{
Kim Phillips82eac672012-10-31 11:09:26 +0000220 static const struct sec_rev_prop {
Kim Phillips6578bae2010-05-28 08:00:14 +0000221 u32 sec_rev;
222 u32 num_channels;
223 u32 channel_fifo_len;
224 u32 exec_units_mask;
225 u32 descriptor_types_mask;
226 } sec_rev_prop_list [] = {
227 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
228 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
229 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
230 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
231 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
232 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
233 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
234 };
Kim Phillips82eac672012-10-31 11:09:26 +0000235 static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
236 sizeof("fsl,secX.Y")];
Kim Phillips6578bae2010-05-28 08:00:14 +0000237 int crypto_node, sec_idx, err;
238 char *p;
239 u32 val;
240
241 /* locate crypto node based on lowest common compatible */
242 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
243 if (crypto_node == -FDT_ERR_NOTFOUND)
244 return;
245
246 /* delete it if not on an E-processor */
247 if (crypto_node > 0 && !sec_rev) {
248 fdt_del_node(blob, crypto_node);
249 return;
250 }
251
252 /* else we got called for possible uprev */
253 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
254 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
255 break;
256
257 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
258 puts("warning: unknown SEC revision number\n");
259 return;
260 }
261
262 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
263 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
264 if (err < 0)
265 printf("WARNING: could not set crypto property: %s\n",
266 fdt_strerror(err));
267
268 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
269 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
270 if (err < 0)
271 printf("WARNING: could not set crypto property: %s\n",
272 fdt_strerror(err));
273
274 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
275 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
276 if (err < 0)
277 printf("WARNING: could not set crypto property: %s\n",
278 fdt_strerror(err));
279
280 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
281 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
282 if (err < 0)
283 printf("WARNING: could not set crypto property: %s\n",
284 fdt_strerror(err));
285
286 val = 0;
287 while (sec_idx >= 0) {
288 p = compat_strlist + val;
289 val += sprintf(p, "fsl,sec%d.%d",
290 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
291 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
292 sec_idx--;
293 }
294 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
295 if (err < 0)
296 printf("WARNING: could not set crypto property: %s\n",
297 fdt_strerror(err));
298}
Kim Phillips1b625492010-06-01 12:24:34 -0500299#elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
300void fdt_fixup_crypto_node(void *blob, int sec_rev)
301{
302 if (!sec_rev)
303 fdt_del_node_and_alias(blob, "crypto");
304}
Kim Phillipsdef125f2010-06-01 12:24:27 -0500305#endif
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500306
Andy Fleming7832a462011-04-13 00:37:12 -0500307int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500308{
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500309 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -0500310 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500311}
Kumar Gala8975d7a2010-12-30 12:09:53 -0600312
313#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500314static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
315{
316 int off = fdt_node_offset_by_prop_value(blob, srio_off,
317 "cell-index", &port, 4);
318 if (off >= 0) {
319 off = fdt_setprop_string(blob, off, "status", "disabled");
320 if (off > 0)
321 printf("WARNING unable to set status for fsl,srio "
322 "port %d: %s\n", port, fdt_strerror(off));
323 }
324}
325
326static inline void ft_disable_rman(void *blob)
327{
328 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
329 if (off >= 0) {
330 off = fdt_setprop_string(blob, off, "status", "disabled");
331 if (off > 0)
332 printf("WARNING unable to set status for fsl,rman %s\n",
333 fdt_strerror(off));
334 }
335}
336
337static inline void ft_disable_rmu(void *blob)
338{
339 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
340 if (off >= 0) {
341 off = fdt_setprop_string(blob, off, "status", "disabled");
342 if (off > 0)
343 printf("WARNING unable to set status for "
344 "fsl,srio-rmu %s\n", fdt_strerror(off));
345 }
346}
347
Kumar Gala8975d7a2010-12-30 12:09:53 -0600348void ft_srio_setup(void *blob)
349{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500350 int srio1_used = 0, srio2_used = 0;
351 int srio_off;
352
353 /* search for srio node, if doesn't exist just return - nothing todo */
354 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
355 if (srio_off < 0)
356 return ;
357
Kumar Gala8975d7a2010-12-30 12:09:53 -0600358#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500359 if (is_serdes_configured(SRIO1))
360 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600361#endif
362#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500363 if (is_serdes_configured(SRIO2))
364 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600365#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500366
367 /* mark port1 disabled */
368 if (!srio1_used)
369 ft_disable_srio_port(blob, srio_off, 1);
370
371 /* mark port2 disabled */
372 if (!srio2_used)
373 ft_disable_srio_port(blob, srio_off, 2);
374
375 /* if both ports not used, disable controller, rmu and rman */
376 if (!srio1_used && !srio2_used) {
377 fdt_setprop_string(blob, srio_off, "status", "disabled");
378
379 ft_disable_rman(blob);
380 ft_disable_rmu(blob);
381 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600382}
383#endif