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 * SPDX-License-Identifier: GPL-2.0+
12 #include <fdt_support.h>
14 #include <asm/fsl_serdes.h>
18 #define FSL_MAX_NUM_USB_CTRLS 2
20 #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
21 static int ft_del_cpuhandle(void *blob, int cpuhandle)
23 int off, ret = -FDT_ERR_NOTFOUND;
25 /* if we find a match, we'll delete at it which point the offsets are
26 * invalid so we start over from the beginning
28 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
30 while (off != -FDT_ERR_NOTFOUND) {
31 fdt_delprop(blob, off, "cpu-handle");
33 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
40 void ft_fixup_num_cores(void *blob) {
41 int off, num_cores, del_cores;
44 num_cores = cpu_numcores();
46 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
47 while (off != -FDT_ERR_NOTFOUND) {
48 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
49 u32 phys_cpu_id = thread_to_core(*reg);
51 if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) {
52 int ph = fdt_get_phandle(blob, off);
54 /* Delete the cpu node once there are no cpu handles */
55 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
56 fdt_del_node(blob, off);
59 /* either we deleted some cpu handles or the cpu node
60 * so we reset the offset back to the start since we
61 * can't trust the offsets anymore
65 off = fdt_node_offset_by_prop_value(blob, off,
66 "device_type", "cpu", 4);
68 debug ("%x core system found\n", num_cores);
69 debug ("deleted %d extra core entry entries from device tree\n",
72 #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
74 #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
75 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
76 const char *phy_type, int start_offset)
78 const char *compat_dr = "fsl-usb2-dr";
79 const char *compat_mph = "fsl-usb2-mph";
80 const char *prop_mode = "dr_mode";
81 const char *prop_type = "phy_type";
82 const char *node_type = NULL;
86 node_offset = fdt_node_offset_by_compatible(blob,
87 start_offset, compat_mph);
88 if (node_offset < 0) {
89 node_offset = fdt_node_offset_by_compatible(blob,
90 start_offset, compat_dr);
91 if (node_offset < 0) {
92 printf("WARNING: could not find compatible"
93 " node %s or %s: %s.\n", compat_mph,
94 compat_dr, fdt_strerror(node_offset));
97 node_type = compat_dr;
99 node_type = compat_mph;
102 err = fdt_setprop(blob, node_offset, prop_mode, mode,
105 printf("WARNING: could not set %s for %s: %s.\n",
106 prop_mode, node_type, fdt_strerror(err));
110 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
111 strlen(phy_type) + 1);
113 printf("WARNING: could not set %s for %s: %s.\n",
114 prop_type, node_type, fdt_strerror(err));
120 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
122 const char *modes[] = { "host", "peripheral", "otg" };
123 const char *phys[] = { "ulpi", "utmi" };
124 const char *dr_mode_type = NULL;
125 const char *dr_phy_type = NULL;
126 int usb_mode_off = -1;
127 int usb_phy_off = -1;
131 for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
132 int mode_idx = -1, phy_idx = -1;
133 snprintf(str, 5, "%s%d", "usb", i);
135 for (j = 0; j < ARRAY_SIZE(modes); j++) {
136 if (hwconfig_subarg_cmp(str, "dr_mode",
143 for (j = 0; j < ARRAY_SIZE(phys); j++) {
144 if (hwconfig_subarg_cmp(str, "phy_type",
151 if (mode_idx < 0 || phy_idx < 0) {
152 puts("ERROR: wrong usb mode/phy defined!!\n");
156 dr_mode_type = modes[mode_idx];
157 dr_phy_type = phys[phy_idx];
159 if (mode_idx < 0 && phy_idx < 0) {
160 printf("WARNING: invalid phy or mode\n");
165 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
166 dr_mode_type, NULL, usb_mode_off);
168 if (usb_mode_off < 0)
171 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
172 NULL, dr_phy_type, usb_phy_off);
178 #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */
181 * update crypto node properties to a specified revision of the SEC
182 * called with sec_rev == 0 if not on an E processor
184 #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
185 void fdt_fixup_crypto_node(void *blob, int sec_rev)
187 static const struct sec_rev_prop {
190 u32 channel_fifo_len;
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 */
202 static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
203 sizeof("fsl,secX.Y")];
204 int crypto_node, sec_idx, err;
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)
213 /* delete it if not on an E-processor */
214 if (crypto_node > 0 && !sec_rev) {
215 fdt_del_node(blob, crypto_node);
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)
224 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
225 puts("warning: unknown SEC revision number\n");
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);
232 printf("WARNING: could not set crypto property: %s\n",
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);
238 printf("WARNING: could not set crypto property: %s\n",
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);
244 printf("WARNING: could not set crypto property: %s\n",
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);
250 printf("WARNING: could not set crypto property: %s\n",
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;
261 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
263 printf("WARNING: could not set crypto property: %s\n",
266 #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
267 static u8 caam_get_era(void)
269 static const struct {
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;
300 if (era) /* This is '0' prior to CAAM ERA-6 */
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;
311 static void fdt_fixup_crypto_era(void *blob, u32 era)
316 crypto_node = fdt_path_offset(blob, "crypto");
317 if (crypto_node < 0) {
318 printf("WARNING: Missing crypto node\n");
322 err = fdt_setprop(blob, crypto_node, "fsl,sec-era", &era,
325 printf("ERROR: could not set fsl,sec-era property: %s\n",
330 void fdt_fixup_crypto_node(void *blob, int sec_rev)
335 fdt_del_node_and_alias(blob, "crypto");
339 /* Add SEC ERA information in compatible */
340 era = caam_get_era();
342 fdt_fixup_crypto_era(blob, era);
344 printf("WARNING: Unable to get ERA for CAAM rev: %d\n",
350 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
352 return fdt_setprop_string(blob, offset, "phy-connection-type",
353 phy_string_for_interface(phyc));
356 #ifdef CONFIG_SYS_SRIO
357 static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
359 int off = fdt_node_offset_by_prop_value(blob, srio_off,
360 "cell-index", &port, 4);
362 off = fdt_setprop_string(blob, off, "status", "disabled");
364 printf("WARNING unable to set status for fsl,srio "
365 "port %d: %s\n", port, fdt_strerror(off));
369 static inline void ft_disable_rman(void *blob)
371 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
373 off = fdt_setprop_string(blob, off, "status", "disabled");
375 printf("WARNING unable to set status for fsl,rman %s\n",
380 static inline void ft_disable_rmu(void *blob)
382 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
384 off = fdt_setprop_string(blob, off, "status", "disabled");
386 printf("WARNING unable to set status for "
387 "fsl,srio-rmu %s\n", fdt_strerror(off));
391 void ft_srio_setup(void *blob)
393 int srio1_used = 0, srio2_used = 0;
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");
402 if (is_serdes_configured(SRIO1))
406 if (is_serdes_configured(SRIO2))
410 /* mark port1 disabled */
412 ft_disable_srio_port(blob, srio_off, 1);
414 /* mark port2 disabled */
416 ft_disable_srio_port(blob, srio_off, 2);
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");
422 ft_disable_rman(blob);
423 ft_disable_rmu(blob);