blob: 4cec5e118ffc7d6666fde11e988cd3f7bbf02aa2 [file] [log] [blame]
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05301/*
ramneek mehresh67b5c992014-08-22 10:56:05 +05302 * Copyright 2009-2014 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.
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05308 */
9
10#include <common.h>
11#include <libfdt.h>
12#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
ramneek mehresh800c2062012-02-10 00:36:43 +000076#if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +053077static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
78 const char *phy_type, int start_offset)
Kim Phillips6578bae2010-05-28 08:00:14 +000079{
ramneek mehresh800c2062012-02-10 00:36:43 +000080 const char *compat_dr = "fsl-usb2-dr";
81 const char *compat_mph = "fsl-usb2-mph";
Kim Phillips6578bae2010-05-28 08:00:14 +000082 const char *prop_mode = "dr_mode";
83 const char *prop_type = "phy_type";
ramneek mehresh800c2062012-02-10 00:36:43 +000084 const char *node_type = NULL;
Kim Phillips6578bae2010-05-28 08:00:14 +000085 int node_offset;
86 int err;
87
Ramneek Mehresh7f548e02011-06-08 17:14:20 +053088 node_offset = fdt_node_offset_by_compatible(blob,
ramneek mehresh800c2062012-02-10 00:36:43 +000089 start_offset, compat_mph);
Kim Phillips6578bae2010-05-28 08:00:14 +000090 if (node_offset < 0) {
ramneek mehresh800c2062012-02-10 00:36:43 +000091 node_offset = fdt_node_offset_by_compatible(blob,
92 start_offset, compat_dr);
93 if (node_offset < 0) {
94 printf("WARNING: could not find compatible"
95 " node %s or %s: %s.\n", compat_mph,
96 compat_dr, fdt_strerror(node_offset));
97 return -1;
98 } else
99 node_type = compat_dr;
100 } else
101 node_type = compat_mph;
Kim Phillips6578bae2010-05-28 08:00:14 +0000102
103 if (mode) {
104 err = fdt_setprop(blob, node_offset, prop_mode, mode,
105 strlen(mode) + 1);
106 if (err < 0)
107 printf("WARNING: could not set %s for %s: %s.\n",
ramneek mehresh800c2062012-02-10 00:36:43 +0000108 prop_mode, node_type, fdt_strerror(err));
Kim Phillips6578bae2010-05-28 08:00:14 +0000109 }
110
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530111 if (phy_type) {
112 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
113 strlen(phy_type) + 1);
Kim Phillips6578bae2010-05-28 08:00:14 +0000114 if (err < 0)
115 printf("WARNING: could not set %s for %s: %s.\n",
ramneek mehresh800c2062012-02-10 00:36:43 +0000116 prop_type, node_type, fdt_strerror(err));
Kim Phillips6578bae2010-05-28 08:00:14 +0000117 }
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530118
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530119 return node_offset;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530120}
121
122void fdt_fixup_dr_usb(void *blob, bd_t *bd)
123{
124 const char *modes[] = { "host", "peripheral", "otg" };
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530125 const char *phys[] = { "ulpi", "utmi" };
Ramneek Mehresh8cab6eb2011-11-08 13:09:20 +0530126 int usb_mode_off = -1;
127 int usb_phy_off = -1;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530128 char str[5];
129 int i, j;
130
ramneek mehreshd04f8fe2013-10-18 17:40:17 +0530131 for (i = 1; i <= CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
ramneek mehresh67b5c992014-08-22 10:56:05 +0530132 const char *dr_mode_type = NULL;
133 const char *dr_phy_type = NULL;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530134 int mode_idx = -1, phy_idx = -1;
ramneek mehresh6bce6112012-02-06 19:17:29 +0000135 snprintf(str, 5, "%s%d", "usb", i);
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530136 if (hwconfig(str)) {
ramneek mehresh6bce6112012-02-06 19:17:29 +0000137 for (j = 0; j < ARRAY_SIZE(modes); j++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530138 if (hwconfig_subarg_cmp(str, "dr_mode",
139 modes[j])) {
140 mode_idx = j;
141 break;
142 }
143 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000144
ramneek mehresh6bce6112012-02-06 19:17:29 +0000145 for (j = 0; j < ARRAY_SIZE(phys); j++) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530146 if (hwconfig_subarg_cmp(str, "phy_type",
147 phys[j])) {
148 phy_idx = j;
149 break;
150 }
151 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000152
ramneek mehreshff6a0242012-09-18 22:28:51 +0000153 if (mode_idx < 0 && phy_idx < 0) {
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530154 printf("WARNING: invalid phy or mode\n");
ramneek mehreshff6a0242012-09-18 22:28:51 +0000155 return;
156 }
ramneek mehresh67b5c992014-08-22 10:56:05 +0530157
158 if (mode_idx > -1)
159 dr_mode_type = modes[mode_idx];
160
161 if (phy_idx > -1)
162 dr_phy_type = phys[phy_idx];
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530163 }
ramneek mehreshff6a0242012-09-18 22:28:51 +0000164
165 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
166 dr_mode_type, NULL, usb_mode_off);
167
168 if (usb_mode_off < 0)
169 return;
170
171 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
172 NULL, dr_phy_type, usb_phy_off);
173
174 if (usb_phy_off < 0)
175 return;
Ramneek Mehresh7f548e02011-06-08 17:14:20 +0530176 }
Kim Phillips6578bae2010-05-28 08:00:14 +0000177}
ramneek mehresh800c2062012-02-10 00:36:43 +0000178#endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */
Kim Phillips6578bae2010-05-28 08:00:14 +0000179
Kim Phillips6578bae2010-05-28 08:00:14 +0000180/*
181 * update crypto node properties to a specified revision of the SEC
Kim Phillipsdef125f2010-06-01 12:24:27 -0500182 * called with sec_rev == 0 if not on an E processor
Kim Phillips6578bae2010-05-28 08:00:14 +0000183 */
Kim Phillipsdef125f2010-06-01 12:24:27 -0500184#if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
Kim Phillips6578bae2010-05-28 08:00:14 +0000185void fdt_fixup_crypto_node(void *blob, int sec_rev)
186{
Kim Phillips82eac672012-10-31 11:09:26 +0000187 static const struct sec_rev_prop {
Kim Phillips6578bae2010-05-28 08:00:14 +0000188 u32 sec_rev;
189 u32 num_channels;
190 u32 channel_fifo_len;
191 u32 exec_units_mask;
192 u32 descriptor_types_mask;
193 } sec_rev_prop_list [] = {
194 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
195 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
196 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
197 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
198 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
199 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
200 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
201 };
Kim Phillips82eac672012-10-31 11:09:26 +0000202 static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
203 sizeof("fsl,secX.Y")];
Kim Phillips6578bae2010-05-28 08:00:14 +0000204 int crypto_node, sec_idx, err;
205 char *p;
206 u32 val;
207
208 /* locate crypto node based on lowest common compatible */
209 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
210 if (crypto_node == -FDT_ERR_NOTFOUND)
211 return;
212
213 /* delete it if not on an E-processor */
214 if (crypto_node > 0 && !sec_rev) {
215 fdt_del_node(blob, crypto_node);
216 return;
217 }
218
219 /* else we got called for possible uprev */
220 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
221 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
222 break;
223
224 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
225 puts("warning: unknown SEC revision number\n");
226 return;
227 }
228
229 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
230 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
231 if (err < 0)
232 printf("WARNING: could not set crypto property: %s\n",
233 fdt_strerror(err));
234
235 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
236 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
237 if (err < 0)
238 printf("WARNING: could not set crypto property: %s\n",
239 fdt_strerror(err));
240
241 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
242 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
243 if (err < 0)
244 printf("WARNING: could not set crypto property: %s\n",
245 fdt_strerror(err));
246
247 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
248 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
249 if (err < 0)
250 printf("WARNING: could not set crypto property: %s\n",
251 fdt_strerror(err));
252
253 val = 0;
254 while (sec_idx >= 0) {
255 p = compat_strlist + val;
256 val += sprintf(p, "fsl,sec%d.%d",
257 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
258 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
259 sec_idx--;
260 }
261 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
262 if (err < 0)
263 printf("WARNING: could not set crypto property: %s\n",
264 fdt_strerror(err));
265}
Kim Phillips1b625492010-06-01 12:24:34 -0500266#elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
Vakul Garg90a7f9f2013-01-23 22:52:31 +0000267static u8 caam_get_era(void)
268{
269 static const struct {
270 u16 ip_id;
271 u8 maj_rev;
272 u8 era;
273 } caam_eras[] = {
274 {0x0A10, 1, 1},
275 {0x0A10, 2, 2},
276 {0x0A12, 1, 3},
277 {0x0A14, 1, 3},
278 {0x0A14, 2, 4},
279 {0x0A16, 1, 4},
280 {0x0A10, 3, 4},
281 {0x0A11, 1, 4},
282 {0x0A18, 1, 4},
283 {0x0A11, 2, 5},
284 {0x0A12, 2, 5},
285 {0x0A13, 1, 5},
286 {0x0A1C, 1, 5}
287 };
288
289 ccsr_sec_t __iomem *sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
290 u32 secvid_ms = in_be32(&sec->secvid_ms);
291 u32 ccbvid = in_be32(&sec->ccbvid);
292 u16 ip_id = (secvid_ms & SEC_SECVID_MS_IPID_MASK) >>
293 SEC_SECVID_MS_IPID_SHIFT;
294 u8 maj_rev = (secvid_ms & SEC_SECVID_MS_MAJ_REV_MASK) >>
295 SEC_SECVID_MS_MAJ_REV_SHIFT;
296 u8 era = (ccbvid & SEC_CCBVID_ERA_MASK) >> SEC_CCBVID_ERA_SHIFT;
297
298 int i;
299
300 if (era) /* This is '0' prior to CAAM ERA-6 */
301 return era;
302
303 for (i = 0; i < ARRAY_SIZE(caam_eras); i++)
304 if (caam_eras[i].ip_id == ip_id &&
305 caam_eras[i].maj_rev == maj_rev)
306 return caam_eras[i].era;
307
308 return 0;
309}
310
311static void fdt_fixup_crypto_era(void *blob, u32 era)
312{
313 int err;
314 int crypto_node;
315
316 crypto_node = fdt_path_offset(blob, "crypto");
317 if (crypto_node < 0) {
318 printf("WARNING: Missing crypto node\n");
319 return;
320 }
321
322 err = fdt_setprop(blob, crypto_node, "fsl,sec-era", &era,
323 sizeof(era));
324 if (err < 0) {
325 printf("ERROR: could not set fsl,sec-era property: %s\n",
326 fdt_strerror(err));
327 }
328}
329
Kim Phillips1b625492010-06-01 12:24:34 -0500330void fdt_fixup_crypto_node(void *blob, int sec_rev)
331{
Vakul Garg90a7f9f2013-01-23 22:52:31 +0000332 u8 era;
333
334 if (!sec_rev) {
Kim Phillips1b625492010-06-01 12:24:34 -0500335 fdt_del_node_and_alias(blob, "crypto");
Vakul Garg90a7f9f2013-01-23 22:52:31 +0000336 return;
337 }
338
339 /* Add SEC ERA information in compatible */
340 era = caam_get_era();
341 if (era) {
342 fdt_fixup_crypto_era(blob, era);
343 } else {
344 printf("WARNING: Unable to get ERA for CAAM rev: %d\n",
345 sec_rev);
346 }
Kim Phillips1b625492010-06-01 12:24:34 -0500347}
Kim Phillipsdef125f2010-06-01 12:24:27 -0500348#endif
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500349
Andy Fleming7832a462011-04-13 00:37:12 -0500350int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500351{
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500352 return fdt_setprop_string(blob, offset, "phy-connection-type",
Andy Fleming7832a462011-04-13 00:37:12 -0500353 phy_string_for_interface(phyc));
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500354}
Kumar Gala8975d7a2010-12-30 12:09:53 -0600355
356#ifdef CONFIG_SYS_SRIO
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500357static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
358{
359 int off = fdt_node_offset_by_prop_value(blob, srio_off,
360 "cell-index", &port, 4);
361 if (off >= 0) {
362 off = fdt_setprop_string(blob, off, "status", "disabled");
363 if (off > 0)
364 printf("WARNING unable to set status for fsl,srio "
365 "port %d: %s\n", port, fdt_strerror(off));
366 }
367}
368
369static inline void ft_disable_rman(void *blob)
370{
371 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
372 if (off >= 0) {
373 off = fdt_setprop_string(blob, off, "status", "disabled");
374 if (off > 0)
375 printf("WARNING unable to set status for fsl,rman %s\n",
376 fdt_strerror(off));
377 }
378}
379
380static inline void ft_disable_rmu(void *blob)
381{
382 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
383 if (off >= 0) {
384 off = fdt_setprop_string(blob, off, "status", "disabled");
385 if (off > 0)
386 printf("WARNING unable to set status for "
387 "fsl,srio-rmu %s\n", fdt_strerror(off));
388 }
389}
390
Kumar Gala8975d7a2010-12-30 12:09:53 -0600391void ft_srio_setup(void *blob)
392{
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500393 int srio1_used = 0, srio2_used = 0;
394 int srio_off;
395
396 /* search for srio node, if doesn't exist just return - nothing todo */
397 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
398 if (srio_off < 0)
399 return ;
400
Kumar Gala8975d7a2010-12-30 12:09:53 -0600401#ifdef CONFIG_SRIO1
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500402 if (is_serdes_configured(SRIO1))
403 srio1_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600404#endif
405#ifdef CONFIG_SRIO2
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500406 if (is_serdes_configured(SRIO2))
407 srio2_used = 1;
Kumar Gala8975d7a2010-12-30 12:09:53 -0600408#endif
Kumar Gala0e7ccae2011-10-14 00:03:58 -0500409
410 /* mark port1 disabled */
411 if (!srio1_used)
412 ft_disable_srio_port(blob, srio_off, 1);
413
414 /* mark port2 disabled */
415 if (!srio2_used)
416 ft_disable_srio_port(blob, srio_off, 2);
417
418 /* if both ports not used, disable controller, rmu and rman */
419 if (!srio1_used && !srio2_used) {
420 fdt_setprop_string(blob, srio_off, "status", "disabled");
421
422 ft_disable_rman(blob);
423 ft_disable_rmu(blob);
424 }
Kumar Gala8975d7a2010-12-30 12:09:53 -0600425}
426#endif