]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/powerpc/cpu/mpc8xxx/fdt.c
powerpc/8xxx: Add fdt_fixup_phy_connection helper
[karo-tx-uboot.git] / arch / powerpc / cpu / mpc8xxx / fdt.c
1 /*
2  * Copyright 2009-2010 Freescale Semiconductor, Inc.
3  *
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
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 #include <asm/mp.h>
30 #include <asm/fsl_enet.h>
31
32 #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx))
33 static int ft_del_cpuhandle(void *blob, int cpuhandle)
34 {
35         int off, ret = -FDT_ERR_NOTFOUND;
36
37         /* if we find a match, we'll delete at it which point the offsets are
38          * invalid so we start over from the beginning
39          */
40         off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
41                                                 &cpuhandle, 4);
42         while (off != -FDT_ERR_NOTFOUND) {
43                 fdt_delprop(blob, off, "cpu-handle");
44                 ret = 1;
45                 off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle",
46                                 &cpuhandle, 4);
47         }
48
49         return ret;
50 }
51
52 void ft_fixup_num_cores(void *blob) {
53         int off, num_cores, del_cores;
54
55         del_cores = 0;
56         num_cores = cpu_numcores();
57
58         off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
59         while (off != -FDT_ERR_NOTFOUND) {
60                 u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
61
62                 if ((*reg > num_cores-1) || (is_core_disabled(*reg))) {
63                         int ph = fdt_get_phandle(blob, off);
64
65                         /* Delete the cpu node once there are no cpu handles */
66                         if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) {
67                                 fdt_del_node(blob, off);
68                                 del_cores++;
69                         }
70                         /* either we deleted some cpu handles or the cpu node
71                          * so we reset the offset back to the start since we
72                          * can't trust the offsets anymore
73                          */
74                         off = -1;
75                 }
76                 off = fdt_node_offset_by_prop_value(blob, off,
77                                 "device_type", "cpu", 4);
78         }
79         debug ("%x core system found\n", num_cores);
80         debug ("deleted %d extra core entry entries from device tree\n",
81                                                                 del_cores);
82 }
83 #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */
84
85 #ifdef CONFIG_HAS_FSL_DR_USB
86 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
87 {
88         char *mode;
89         char *type;
90         const char *compat = "fsl-usb2-dr";
91         const char *prop_mode = "dr_mode";
92         const char *prop_type = "phy_type";
93         int node_offset;
94         int err;
95
96         mode = getenv("usb_dr_mode");
97         type = getenv("usb_phy_type");
98         if (!mode && !type)
99                 return;
100
101         node_offset = fdt_node_offset_by_compatible(blob, 0, compat);
102         if (node_offset < 0) {
103                 printf("WARNING: could not find compatible node %s: %s.\n",
104                         compat, fdt_strerror(node_offset));
105                 return;
106         }
107
108         if (mode) {
109                 err = fdt_setprop(blob, node_offset, prop_mode, mode,
110                                   strlen(mode) + 1);
111                 if (err < 0)
112                         printf("WARNING: could not set %s for %s: %s.\n",
113                                prop_mode, compat, fdt_strerror(err));
114         }
115
116         if (type) {
117                 err = fdt_setprop(blob, node_offset, prop_type, type,
118                                   strlen(type) + 1);
119                 if (err < 0)
120                         printf("WARNING: could not set %s for %s: %s.\n",
121                                prop_type, compat, fdt_strerror(err));
122         }
123 }
124 #endif /* CONFIG_HAS_FSL_DR_USB */
125
126 /*
127  * update crypto node properties to a specified revision of the SEC
128  * called with sec_rev == 0 if not on an E processor
129  */
130 #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
131 void fdt_fixup_crypto_node(void *blob, int sec_rev)
132 {
133         const struct sec_rev_prop {
134                 u32 sec_rev;
135                 u32 num_channels;
136                 u32 channel_fifo_len;
137                 u32 exec_units_mask;
138                 u32 descriptor_types_mask;
139         } sec_rev_prop_list [] = {
140                 { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
141                 { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
142                 { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
143                 { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
144                 { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
145                 { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
146                 { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
147         };
148         char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
149                             sizeof("fsl,secX.Y")];
150         int crypto_node, sec_idx, err;
151         char *p;
152         u32 val;
153
154         /* locate crypto node based on lowest common compatible */
155         crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
156         if (crypto_node == -FDT_ERR_NOTFOUND)
157                 return;
158
159         /* delete it if not on an E-processor */
160         if (crypto_node > 0 && !sec_rev) {
161                 fdt_del_node(blob, crypto_node);
162                 return;
163         }
164
165         /* else we got called for possible uprev */
166         for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
167                 if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
168                         break;
169
170         if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
171                 puts("warning: unknown SEC revision number\n");
172                 return;
173         }
174
175         val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
176         err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
177         if (err < 0)
178                 printf("WARNING: could not set crypto property: %s\n",
179                        fdt_strerror(err));
180
181         val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
182         err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4);
183         if (err < 0)
184                 printf("WARNING: could not set crypto property: %s\n",
185                        fdt_strerror(err));
186
187         val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
188         err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
189         if (err < 0)
190                 printf("WARNING: could not set crypto property: %s\n",
191                        fdt_strerror(err));
192
193         val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
194         err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
195         if (err < 0)
196                 printf("WARNING: could not set crypto property: %s\n",
197                        fdt_strerror(err));
198
199         val = 0;
200         while (sec_idx >= 0) {
201                 p = compat_strlist + val;
202                 val += sprintf(p, "fsl,sec%d.%d",
203                         (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
204                         sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
205                 sec_idx--;
206         }
207         err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val);
208         if (err < 0)
209                 printf("WARNING: could not set crypto property: %s\n",
210                        fdt_strerror(err));
211 }
212 #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4  /* SEC4 */
213 void fdt_fixup_crypto_node(void *blob, int sec_rev)
214 {
215         if (!sec_rev)
216                 fdt_del_node_and_alias(blob, "crypto");
217 }
218 #endif
219
220 int fdt_fixup_phy_connection(void *blob, int offset, enum fsl_phy_enet_if phyc)
221 {
222         static const char *fsl_phy_enet_if_str[] = {
223                 [MII]           = "mii",
224                 [RMII]          = "rmii",
225                 [GMII]          = "gmii",
226                 [RGMII]         = "rgmii",
227                 [RGMII_ID]      = "rgmii-id",
228                 [RGMII_RXID]    = "rgmii-rxid",
229                 [SGMII]         = "sgmii",
230                 [TBI]           = "tbi",
231                 [RTBI]          = "rtbi",
232                 [XAUI]          = "xgmii",
233                 [FSL_ETH_IF_NONE] = "",
234         };
235
236         if (phyc > ARRAY_SIZE(fsl_phy_enet_if_str))
237                 return fdt_setprop_string(blob, offset, "phy-connection-type", "");
238
239         return fdt_setprop_string(blob, offset, "phy-connection-type",
240                                          fsl_phy_enet_if_str[phyc]);
241 }