2 * Copyright 2009-2011 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);
66 if (!is_core_valid(*reg) || is_core_disabled(*reg)) {
67 int ph = fdt_get_phandle(blob, off);
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);
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
80 off = fdt_node_offset_by_prop_value(blob, off,
81 "device_type", "cpu", 4);
83 debug ("%x core system found\n", num_cores);
84 debug ("deleted %d extra core entry entries from device tree\n",
87 #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
89 #ifdef CONFIG_HAS_FSL_DR_USB
90 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
91 const char *phy_type, int start_offset)
93 const char *compat = "fsl-usb2-dr";
94 const char *prop_mode = "dr_mode";
95 const char *prop_type = "phy_type";
99 node_offset = fdt_node_offset_by_compatible(blob,
100 start_offset, compat);
101 if (node_offset < 0) {
102 printf("WARNING: could not find compatible node %s: %s.\n",
103 compat, fdt_strerror(node_offset));
108 err = fdt_setprop(blob, node_offset, prop_mode, mode,
111 printf("WARNING: could not set %s for %s: %s.\n",
112 prop_mode, compat, fdt_strerror(err));
116 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
117 strlen(phy_type) + 1);
119 printf("WARNING: could not set %s for %s: %s.\n",
120 prop_type, compat, fdt_strerror(err));
126 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
128 const char *modes[] = { "host", "peripheral", "otg" };
129 const char *phys[] = { "ulpi", "utmi" };
130 const char *mode = NULL;
131 const char *phy_type = NULL;
132 char usb1_defined = 0;
133 int usb_mode_off = -1;
134 int usb_phy_off = -1;
138 for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
139 int mode_idx = -1, phy_idx = -1;
140 sprintf(str, "%s%d", "usb", i);
142 for (j = 0; j < sizeof(modes); j++) {
143 if (hwconfig_subarg_cmp(str, "dr_mode",
149 for (j = 0; j < sizeof(phys); j++) {
150 if (hwconfig_subarg_cmp(str, "phy_type",
157 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
158 modes[mode_idx], NULL, usb_mode_off);
160 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
161 NULL, phys[phy_idx], usb_phy_off);
162 if (!strcmp(str, "usb1"))
164 if (mode_idx < 0 && phy_idx < 0)
165 printf("WARNING: invalid phy or mode\n");
170 mode = getenv("usb_dr_mode");
171 phy_type = getenv("usb_phy_type");
172 if (!mode && !phy_type)
174 fdt_fixup_usb_mode_phy_type(blob, mode, phy_type, usb_off);
177 #endif /* CONFIG_HAS_FSL_DR_USB */
180 * update crypto node properties to a specified revision of the SEC
181 * called with sec_rev == 0 if not on an E processor
183 #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
184 void fdt_fixup_crypto_node(void *blob, int sec_rev)
186 const struct sec_rev_prop {
189 u32 channel_fifo_len;
191 u32 descriptor_types_mask;
192 } sec_rev_prop_list [] = {
193 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
194 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
195 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
196 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
197 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
198 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
199 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
201 char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
202 sizeof("fsl,secX.Y")];
203 int crypto_node, sec_idx, err;
207 /* locate crypto node based on lowest common compatible */
208 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
209 if (crypto_node == -FDT_ERR_NOTFOUND)
212 /* delete it if not on an E-processor */
213 if (crypto_node > 0 && !sec_rev) {
214 fdt_del_node(blob, crypto_node);
218 /* else we got called for possible uprev */
219 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
220 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
223 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
224 puts("warning: unknown SEC revision number\n");
228 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
229 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
231 printf("WARNING: could not set crypto property: %s\n",
234 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
235 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
237 printf("WARNING: could not set crypto property: %s\n",
240 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
241 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
243 printf("WARNING: could not set crypto property: %s\n",
246 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
247 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
249 printf("WARNING: could not set crypto property: %s\n",
253 while (sec_idx >= 0) {
254 p = compat_strlist + val;
255 val += sprintf(p, "fsl,sec%d.%d",
256 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
257 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
260 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
262 printf("WARNING: could not set crypto property: %s\n",
265 #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
266 void fdt_fixup_crypto_node(void *blob, int sec_rev)
269 fdt_del_node_and_alias(blob, "crypto");
273 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
275 return fdt_setprop_string(blob, offset, "phy-connection-type",
276 phy_string_for_interface(phyc));
279 #ifdef CONFIG_SYS_SRIO
280 static inline void ft_disable_srio_port(void *blob, int srio_off, int port)
282 int off = fdt_node_offset_by_prop_value(blob, srio_off,
283 "cell-index", &port, 4);
285 off = fdt_setprop_string(blob, off, "status", "disabled");
287 printf("WARNING unable to set status for fsl,srio "
288 "port %d: %s\n", port, fdt_strerror(off));
292 static inline void ft_disable_rman(void *blob)
294 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman");
296 off = fdt_setprop_string(blob, off, "status", "disabled");
298 printf("WARNING unable to set status for fsl,rman %s\n",
303 static inline void ft_disable_rmu(void *blob)
305 int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu");
307 off = fdt_setprop_string(blob, off, "status", "disabled");
309 printf("WARNING unable to set status for "
310 "fsl,srio-rmu %s\n", fdt_strerror(off));
314 void ft_srio_setup(void *blob)
316 int srio1_used = 0, srio2_used = 0;
319 /* search for srio node, if doesn't exist just return - nothing todo */
320 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
325 if (is_serdes_configured(SRIO1))
329 if (is_serdes_configured(SRIO2))
333 /* mark port1 disabled */
335 ft_disable_srio_port(blob, srio_off, 1);
337 /* mark port2 disabled */
339 ft_disable_srio_port(blob, srio_off, 2);
341 /* if both ports not used, disable controller, rmu and rman */
342 if (!srio1_used && !srio2_used) {
343 fdt_setprop_string(blob, srio_off, "status", "disabled");
345 ft_disable_rman(blob);
346 ft_disable_rmu(blob);