2 * Copyright 2009-2012 Freescale Semiconductor, Inc.
4 * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and
5 * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains
6 * cpu specific common code for 85xx/86xx processors.
7 * See file CREDITS for list of people who contributed to this
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.
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.
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,
28 #include <fdt_support.h>
30 #include <asm/fsl_serdes.h>
34 #define FSL_MAX_NUM_USB_CTRLS 2
36 #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
37 static int ft_del_cpuhandle(void *blob, int cpuhandle)
39 int off, ret = -FDT_ERR_NOTFOUND;
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
44 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
46 while (off != -FDT_ERR_NOTFOUND) {
47 fdt_delprop(blob, off, "cpu-handle");
49 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
56 void ft_fixup_num_cores(void *blob) {
57 int off, num_cores, del_cores;
60 num_cores = cpu_numcores();
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 u32 phys_cpu_id = thread_to_core(*reg);
67 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
68 int ph = fdt_get_phandle(blob, off);
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);
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
81 off = fdt_node_offset_by_prop_value(blob, off,
82 "device_type", "cpu", 4);
84 debug ("%x core system found\n", num_cores);
85 debug ("deleted %d extra core entry entries from device tree\n",
88 #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
90 #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
91 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
92 const char *phy_type, int start_offset)
94 const char *compat_dr = "fsl-usb2-dr";
95 const char *compat_mph = "fsl-usb2-mph";
96 const char *prop_mode = "dr_mode";
97 const char *prop_type = "phy_type";
98 const char *node_type = NULL;
102 node_offset = fdt_node_offset_by_compatible(blob,
103 start_offset, compat_mph);
104 if (node_offset < 0) {
105 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));
113 node_type = compat_dr;
115 node_type = compat_mph;
118 err = fdt_setprop(blob, node_offset, prop_mode, mode,
121 printf("WARNING: could not set %s for %s: %s.\n",
122 prop_mode, node_type, fdt_strerror(err));
126 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
127 strlen(phy_type) + 1);
129 printf("WARNING: could not set %s for %s: %s.\n",
130 prop_type, node_type, fdt_strerror(err));
136 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
138 const char *modes[] = { "host", "peripheral", "otg" };
139 const char *phys[] = { "ulpi", "utmi" };
140 const char *mode = NULL;
141 const char *phy_type = NULL;
142 const char *dr_mode_type = NULL;
143 const char *dr_phy_type = NULL;
144 char usb1_defined = 0;
145 int usb_mode_off = -1;
146 int usb_phy_off = -1;
150 for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
151 int mode_idx = -1, phy_idx = -1;
152 snprintf(str, 5, "%s%d", "usb", i);
154 for (j = 0; j < ARRAY_SIZE(modes); j++) {
155 if (hwconfig_subarg_cmp(str, "dr_mode",
162 for (j = 0; j < ARRAY_SIZE(phys); j++) {
163 if (hwconfig_subarg_cmp(str, "phy_type",
170 dr_mode_type = modes[mode_idx];
171 dr_phy_type = phys[phy_idx];
173 /* use usb_dr_mode and usb_phy_type if
174 usb1_defined = 0; these variables are to
176 if (!strcmp(str, "usb1"))
179 if (mode_idx < 0 && phy_idx < 0) {
180 printf("WARNING: invalid phy or mode\n");
185 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
186 dr_mode_type, NULL, usb_mode_off);
188 if (usb_mode_off < 0)
191 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
192 NULL, dr_phy_type, usb_phy_off);
200 mode = getenv("usb_dr_mode");
201 phy_type = getenv("usb_phy_type");
202 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,
211 #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */
214 * update crypto node properties to a specified revision of the SEC
215 * called with sec_rev == 0 if not on an E processor
217 #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
218 void fdt_fixup_crypto_node(void *blob, int sec_rev)
220 static const struct sec_rev_prop {
223 u32 channel_fifo_len;
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 */
235 static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
236 sizeof("fsl,secX.Y")];
237 int crypto_node, sec_idx, err;
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)
246 /* delete it if not on an E-processor */
247 if (crypto_node > 0 && !sec_rev) {
248 fdt_del_node(blob, crypto_node);
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)
257 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
258 puts("warning: unknown SEC revision number\n");
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);
265 printf("WARNING: could not set crypto property: %s\n",
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);
271 printf("WARNING: could not set crypto property: %s\n",
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);
277 printf("WARNING: could not set crypto property: %s\n",
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);
283 printf("WARNING: could not set crypto property: %s\n",
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;
294 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
296 printf("WARNING: could not set crypto property: %s\n",
299 #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
300 static u8 caam_get_era(void)
302 static const struct {
322 ccsr_sec_t __iomem *sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
323 u32 secvid_ms = in_be32(&sec->secvid_ms);
324 u32 ccbvid = in_be32(&sec->ccbvid);
325 u16 ip_id = (secvid_ms & SEC_SECVID_MS_IPID_MASK) >>
326 SEC_SECVID_MS_IPID_SHIFT;
327 u8 maj_rev = (secvid_ms & SEC_SECVID_MS_MAJ_REV_MASK) >>
328 SEC_SECVID_MS_MAJ_REV_SHIFT;
329 u8 era = (ccbvid & SEC_CCBVID_ERA_MASK) >> SEC_CCBVID_ERA_SHIFT;
333 if (era) /* This is '0' prior to CAAM ERA-6 */
336 for (i = 0; i < ARRAY_SIZE(caam_eras); i++)
337 if (caam_eras[i].ip_id == ip_id &&
338 caam_eras[i].maj_rev == maj_rev)
339 return caam_eras[i].era;
344 static void fdt_fixup_crypto_era(void *blob, u32 era)
349 crypto_node = fdt_path_offset(blob, "crypto");
350 if (crypto_node < 0) {
351 printf("WARNING: Missing crypto node\n");
355 err = fdt_setprop(blob, crypto_node, "fsl,sec-era", &era,
358 printf("ERROR: could not set fsl,sec-era property: %s\n",
363 void fdt_fixup_crypto_node(void *blob, int sec_rev)
368 fdt_del_node_and_alias(blob, "crypto");
372 /* Add SEC ERA information in compatible */
373 era = caam_get_era();
375 fdt_fixup_crypto_era(blob, era);
377 printf("WARNING: Unable to get ERA for CAAM rev: %d\n",
383 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
385 return fdt_setprop_string(blob, offset, "phy-connection-type",
386 phy_string_for_interface(phyc));
389 #ifdef CONFIG_SYS_SRIO
390 static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
392 int off = fdt_node_offset_by_prop_value(blob, srio_off,
393 "cell-index", &port, 4);
395 off = fdt_setprop_string(blob, off, "status", "disabled");
397 printf("WARNING unable to set status for fsl,srio "
398 "port %d: %s\n", port, fdt_strerror(off));
402 static inline void ft_disable_rman(void *blob)
404 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
406 off = fdt_setprop_string(blob, off, "status", "disabled");
408 printf("WARNING unable to set status for fsl,rman %s\n",
413 static inline void ft_disable_rmu(void *blob)
415 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
417 off = fdt_setprop_string(blob, off, "status", "disabled");
419 printf("WARNING unable to set status for "
420 "fsl,srio-rmu %s\n", fdt_strerror(off));
424 void ft_srio_setup(void *blob)
426 int srio1_used = 0, srio2_used = 0;
429 /* search for srio node, if doesn't exist just return - nothing todo */
430 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
435 if (is_serdes_configured(SRIO1))
439 if (is_serdes_configured(SRIO2))
443 /* mark port1 disabled */
445 ft_disable_srio_port(blob, srio_off, 1);
447 /* mark port2 disabled */
449 ft_disable_srio_port(blob, srio_off, 2);
451 /* if both ports not used, disable controller, rmu and rman */
452 if (!srio1_used && !srio2_used) {
453 fdt_setprop_string(blob, srio_off, "status", "disabled");
455 ft_disable_rman(blob);
456 ft_disable_rmu(blob);