blob: 88c47d1aedef5bfe41a137067bd124df8d0e89d8 [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>
Kumar Gala819a4792010-06-09 22:33:53 -050029#include <asm/mp.h>
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053030
Kumar Gala819a4792010-06-09 22:33:53 -050031#if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
Kumar Galaa24926d2010-06-09 13:14:28 -050032static int ft_del_cpuhandle(void *blob, int cpuhandle)
33{
34 int off, ret = -FDT_ERR_NOTFOUND;
35
36 /* if we find a match, we'll delete at it which point the offsets are
37 * invalid so we start over from the beginning
38 */
39 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
40 &cpuhandle, 4);
41 while (off != -FDT_ERR_NOTFOUND) {
42 fdt_delprop(blob, off, "cpu-handle");
43 ret = 1;
44 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
45 &cpuhandle, 4);
46 }
47
48 return ret;
49}
50
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053051void ft_fixup_num_cores(void *blob) {
52 int off, num_cores, del_cores;
53
54 del_cores = 0;
55 num_cores = cpu_numcores();
56
57 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
58 while (off != -FDT_ERR_NOTFOUND) {
59 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
60
Kumar Gala819a4792010-06-09 22:33:53 -050061 if ((*reg > num_cores-1) || (is_core_disabled(*reg))) {
Kumar Galaa24926d2010-06-09 13:14:28 -050062 int ph = fdt_get_phandle(blob, off);
63
64 /* Delete the cpu node once there are no cpu handles */
65 if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
66 fdt_del_node(blob, off);
67 del_cores++;
68 }
69 /* either we deleted some cpu handles or the cpu node
70 * so we reset the offset back to the start since we
71 * can't trust the offsets anymore
72 */
Poonam Aggrwal4ca72ae2009-09-02 19:40:36 +053073 off = -1;
74 }
75 off = fdt_node_offset_by_prop_value(blob, off,
76 "device_type", "cpu", 4);
77 }
78 debug ("%x core system found\n", num_cores);
79 debug ("deleted %d extra core entry entries from device tree\n",
80 del_cores);
81}
Kim Phillips6578bae2010-05-28 08:00:14 +000082#endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
83
84#ifdef CONFIG_HAS_FSL_DR_USB
85void fdt_fixup_dr_usb(void *blob, bd_t *bd)
86{
87 char *mode;
88 char *type;
89 const char *compat = "fsl-usb2-dr";
90 const char *prop_mode = "dr_mode";
91 const char *prop_type = "phy_type";
92 int node_offset;
93 int err;
94
95 mode = getenv("usb_dr_mode");
96 type = getenv("usb_phy_type");
97 if (!mode && !type)
98 return;
99
100 node_offset = fdt_node_offset_by_compatible(blob, 0, compat);
101 if (node_offset < 0) {
102 printf("WARNING: could not find compatible node %s: %s.\n",
103 compat, fdt_strerror(node_offset));
104 return;
105 }
106
107 if (mode) {
108 err = fdt_setprop(blob, node_offset, prop_mode, mode,
109 strlen(mode) + 1);
110 if (err < 0)
111 printf("WARNING: could not set %s for %s: %s.\n",
112 prop_mode, compat, fdt_strerror(err));
113 }
114
115 if (type) {
116 err = fdt_setprop(blob, node_offset, prop_type, type,
117 strlen(type) + 1);
118 if (err < 0)
119 printf("WARNING: could not set %s for %s: %s.\n",
120 prop_type, compat, fdt_strerror(err));
121 }
122}
123#endif /* CONFIG_HAS_FSL_DR_USB */
124
Kim Phillips6578bae2010-05-28 08:00:14 +0000125/*
126 * update crypto node properties to a specified revision of the SEC
Kim Phillipsdef125f2010-06-01 12:24:27 -0500127 * called with sec_rev == 0 if not on an E processor
Kim Phillips6578bae2010-05-28 08:00:14 +0000128 */
Kim Phillipsdef125f2010-06-01 12:24:27 -0500129#if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
Kim Phillips6578bae2010-05-28 08:00:14 +0000130void fdt_fixup_crypto_node(void *blob, int sec_rev)
131{
132 const struct sec_rev_prop {
133 u32 sec_rev;
134 u32 num_channels;
135 u32 channel_fifo_len;
136 u32 exec_units_mask;
137 u32 descriptor_types_mask;
138 } sec_rev_prop_list [] = {
139 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
140 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
141 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
142 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
143 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
144 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
145 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
146 };
147 char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
148 sizeof("fsl,secX.Y")];
149 int crypto_node, sec_idx, err;
150 char *p;
151 u32 val;
152
153 /* locate crypto node based on lowest common compatible */
154 crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
155 if (crypto_node == -FDT_ERR_NOTFOUND)
156 return;
157
158 /* delete it if not on an E-processor */
159 if (crypto_node > 0 && !sec_rev) {
160 fdt_del_node(blob, crypto_node);
161 return;
162 }
163
164 /* else we got called for possible uprev */
165 for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
166 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
167 break;
168
169 if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
170 puts("warning: unknown SEC revision number\n");
171 return;
172 }
173
174 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
175 err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
176 if (err < 0)
177 printf("WARNING: could not set crypto property: %s\n",
178 fdt_strerror(err));
179
180 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
181 err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
182 if (err < 0)
183 printf("WARNING: could not set crypto property: %s\n",
184 fdt_strerror(err));
185
186 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
187 err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
188 if (err < 0)
189 printf("WARNING: could not set crypto property: %s\n",
190 fdt_strerror(err));
191
192 val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
193 err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
194 if (err < 0)
195 printf("WARNING: could not set crypto property: %s\n",
196 fdt_strerror(err));
197
198 val = 0;
199 while (sec_idx >= 0) {
200 p = compat_strlist + val;
201 val += sprintf(p, "fsl,sec%d.%d",
202 (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
203 sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
204 sec_idx--;
205 }
206 err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
207 if (err < 0)
208 printf("WARNING: could not set crypto property: %s\n",
209 fdt_strerror(err));
210}
Kim Phillips1b625492010-06-01 12:24:34 -0500211#elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
212void fdt_fixup_crypto_node(void *blob, int sec_rev)
213{
214 if (!sec_rev)
215 fdt_del_node_and_alias(blob, "crypto");
216}
Kim Phillipsdef125f2010-06-01 12:24:27 -0500217#endif