blob: 79d3cdfa64217909e1b424d7df9056fd13fb9f07 [file] [log] [blame]
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +05301/*
Kim Phillips6578bae2010-05-28 08:00:14 +00002 * Copyright 2009-2010 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>
29
Kim Phillips6578bae2010-05-28 08:00:14 +000030#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053031void ft_fixup_num_cores(void *blob) {
32 int off, num_cores, del_cores;
33
34 del_cores = 0;
35 num_cores = cpu_numcores();
36
37 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
38 while (off != -FDT_ERR_NOTFOUND) {
39 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
40
41 /* if we find a cpu node outside of what we expect delete it
42 * and reset the offset back to the start since we can't
43 * trust the offsets anymore
44 */
45 if (*reg > num_cores-1) {
46 fdt_del_node(blob, off);
47 del_cores++;
48 off = -1;
49 }
50 off = fdt_node_offset_by_prop_value(blob, off,
51 "device_type", "cpu", 4);
52 }
53 debug ("%x core system found\n", num_cores);
54 debug ("deleted %d extra core entry entries from device tree\n",
55 del_cores);
56}
Kim Phillips6578bae2010-05-28 08:00:14 +000057#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
58
59#ifdef CONFIG_HAS_FSL_DR_USB
60void fdt_fixup_dr_usb(void *blob, bd_t *bd)
61{
62 char *mode;
63 char *type;
64 const char *compat = "fsl-usb2-dr";
65 const char *prop_mode = "dr_mode";
66 const char *prop_type = "phy_type";
67 int node_offset;
68 int err;
69
70 mode = getenv("usb_dr_mode");
71 type = getenv("usb_phy_type");
72 if (!mode && !type)
73 return;
74
75 node_offset = fdt_node_offset_by_compatible(blob, 0, compat);
76 if (node_offset < 0) {
77 printf("WARNING: could not find compatible node %s: %s.\n",
78 compat, fdt_strerror(node_offset));
79 return;
80 }
81
82 if (mode) {
83 err = fdt_setprop(blob, node_offset, prop_mode, mode,
84 strlen(mode) + 1);
85 if (err < 0)
86 printf("WARNING: could not set %s for %s: %s.\n",
87 prop_mode, compat, fdt_strerror(err));
88 }
89
90 if (type) {
91 err = fdt_setprop(blob, node_offset, prop_type, type,
92 strlen(type) + 1);
93 if (err < 0)
94 printf("WARNING: could not set %s for %s: %s.\n",
95 prop_type, compat, fdt_strerror(err));
96 }
97}
98#endif /* CONFIG_HAS_FSL_DR_USB */
99
100#if defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx)
101/*
102 * update crypto node properties to a specified revision of the SEC
103 * called with sec_rev == 0 if not on an mpc8xxxE processor
104 */
105void fdt_fixup_crypto_node(void *blob, int sec_rev)
106{
107 const struct sec_rev_prop {
108 u32 sec_rev;
109 u32 num_channels;
110 u32 channel_fifo_len;
111 u32 exec_units_mask;
112 u32 descriptor_types_mask;
113 } sec_rev_prop_list [] = {
114 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
115 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
116 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
117 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
118 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
119 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
120 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
121 };
122 char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
123 sizeof("fsl,secX.Y")];
124 int crypto_node, sec_idx, err;
125 char *p;
126 u32 val;
127
128 /* locate crypto node based on lowest common compatible */
129 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
130 if (crypto_node == -FDT_ERR_NOTFOUND)
131 return;
132
133 /* delete it if not on an E-processor */
134 if (crypto_node > 0 && !sec_rev) {
135 fdt_del_node(blob, crypto_node);
136 return;
137 }
138
139 /* else we got called for possible uprev */
140 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
141 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
142 break;
143
144 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
145 puts("warning: unknown SEC revision number\n");
146 return;
147 }
148
149 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
150 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
151 if (err < 0)
152 printf("WARNING: could not set crypto property: %s\n",
153 fdt_strerror(err));
154
155 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
156 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
157 if (err < 0)
158 printf("WARNING: could not set crypto property: %s\n",
159 fdt_strerror(err));
160
161 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
162 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
163 if (err < 0)
164 printf("WARNING: could not set crypto property: %s\n",
165 fdt_strerror(err));
166
167 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
168 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
169 if (err < 0)
170 printf("WARNING: could not set crypto property: %s\n",
171 fdt_strerror(err));
172
173 val = 0;
174 while (sec_idx >= 0) {
175 p = compat_strlist + val;
176 val += sprintf(p, "fsl,sec%d.%d",
177 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
178 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
179 sec_idx--;
180 }
181 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
182 if (err < 0)
183 printf("WARNING: could not set crypto property: %s\n",
184 fdt_strerror(err));
185}
186#endif /* defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx) */