Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 1 | /* |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 2 | * Copyright 2009-2011 Freescale Semiconductor, Inc. |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 3 | * |
Stefan Roese | a47a12b | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 4 | * This file is derived from arch/powerpc/cpu/mpc85xx/cpu.c and |
| 5 | * arch/powerpc/cpu/mpc86xx/cpu.c. Basically this file contains |
Peter Tyser | 8d1f268 | 2010-04-12 22:28:09 -0500 | [diff] [blame] | 6 | * cpu specific common code for 85xx/86xx processors. |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 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> |
Kumar Gala | 8f3a7fa | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 29 | #include <asm/mp.h> |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 30 | #include <asm/fsl_serdes.h> |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 31 | #include <phy.h> |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 32 | #include <hwconfig.h> |
Kumar Gala | 5756736 | 2011-07-29 08:51:26 -0500 | [diff] [blame] | 33 | |
| 34 | #define FSL_MAX_NUM_USB_CTRLS 2 |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 35 | |
Kumar Gala | 8f3a7fa | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 36 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)) |
Kumar Gala | 11beefa | 2010-06-09 13:14:28 -0500 | [diff] [blame] | 37 | static int ft_del_cpuhandle(void *blob, int cpuhandle) |
| 38 | { |
| 39 | int off, ret = -FDT_ERR_NOTFOUND; |
| 40 | |
| 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 |
| 43 | */ |
| 44 | off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle", |
| 45 | &cpuhandle, 4); |
| 46 | while (off != -FDT_ERR_NOTFOUND) { |
| 47 | fdt_delprop(blob, off, "cpu-handle"); |
| 48 | ret = 1; |
| 49 | off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle", |
| 50 | &cpuhandle, 4); |
| 51 | } |
| 52 | |
| 53 | return ret; |
| 54 | } |
| 55 | |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 56 | void ft_fixup_num_cores(void *blob) { |
| 57 | int off, num_cores, del_cores; |
| 58 | |
| 59 | del_cores = 0; |
| 60 | num_cores = cpu_numcores(); |
| 61 | |
| 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); |
| 65 | |
Timur Tabi | fbb9ecf | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 66 | if (!is_core_valid(*reg) || is_core_disabled(*reg)) { |
Kumar Gala | 11beefa | 2010-06-09 13:14:28 -0500 | [diff] [blame] | 67 | int ph = fdt_get_phandle(blob, off); |
| 68 | |
| 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); |
| 72 | del_cores++; |
| 73 | } |
| 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 |
| 77 | */ |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 78 | off = -1; |
| 79 | } |
| 80 | off = fdt_node_offset_by_prop_value(blob, off, |
| 81 | "device_type", "cpu", 4); |
| 82 | } |
| 83 | debug ("%x core system found\n", num_cores); |
| 84 | debug ("deleted %d extra core entry entries from device tree\n", |
| 85 | del_cores); |
| 86 | } |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 87 | #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */ |
| 88 | |
| 89 | #ifdef CONFIG_HAS_FSL_DR_USB |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 90 | static void fdt_fixup_usb_mode_phy_type(void *blob, const char *mode, |
| 91 | const char *phy_type) |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 92 | { |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 93 | const char *compat = "fsl-usb2-dr"; |
| 94 | const char *prop_mode = "dr_mode"; |
| 95 | const char *prop_type = "phy_type"; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 96 | static int start_offset = -1; |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 97 | int node_offset; |
| 98 | int err; |
| 99 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 100 | node_offset = fdt_node_offset_by_compatible(blob, |
| 101 | start_offset, compat); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 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 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 116 | if (phy_type) { |
| 117 | err = fdt_setprop(blob, node_offset, prop_type, phy_type, |
| 118 | strlen(phy_type) + 1); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 119 | if (err < 0) |
| 120 | printf("WARNING: could not set %s for %s: %s.\n", |
| 121 | prop_type, compat, fdt_strerror(err)); |
| 122 | } |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 123 | |
| 124 | start_offset = node_offset; |
| 125 | } |
| 126 | |
| 127 | void fdt_fixup_dr_usb(void *blob, bd_t *bd) |
| 128 | { |
| 129 | const char *modes[] = { "host", "peripheral", "otg" }; |
| 130 | const char *phys[] = { "ulpi", "umti" }; |
| 131 | const char *mode = NULL; |
| 132 | const char *phy_type = NULL; |
| 133 | char usb1_defined = 0; |
| 134 | char str[5]; |
| 135 | int i, j; |
| 136 | |
Kumar Gala | 5756736 | 2011-07-29 08:51:26 -0500 | [diff] [blame] | 137 | for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) { |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 138 | int mode_idx = -1, phy_idx = -1; |
| 139 | sprintf(str, "%s%d", "usb", i); |
| 140 | if (hwconfig(str)) { |
| 141 | for (j = 0; j < sizeof(modes); j++) { |
| 142 | if (hwconfig_subarg_cmp(str, "dr_mode", |
| 143 | modes[j])) { |
| 144 | mode_idx = j; |
| 145 | break; |
| 146 | } |
| 147 | } |
| 148 | for (j = 0; j < sizeof(phys); j++) { |
| 149 | if (hwconfig_subarg_cmp(str, "phy_type", |
| 150 | phys[j])) { |
| 151 | phy_idx = j; |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | if (mode_idx >= 0) |
| 156 | fdt_fixup_usb_mode_phy_type(blob, |
| 157 | modes[mode_idx], NULL); |
| 158 | if (phy_idx >= 0) |
| 159 | fdt_fixup_usb_mode_phy_type(blob, |
| 160 | NULL, phys[phy_idx]); |
| 161 | if (!strcmp(str, "usb1")) |
| 162 | usb1_defined = 1; |
| 163 | if (mode_idx < 0 && phy_idx < 0) |
| 164 | printf("WARNING: invalid phy or mode\n"); |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | if (!usb1_defined) { |
| 168 | mode = getenv("usb_dr_mode"); |
| 169 | phy_type = getenv("usb_phy_type"); |
| 170 | if (!mode && !phy_type) |
| 171 | return; |
| 172 | fdt_fixup_usb_mode_phy_type(blob, mode, phy_type); |
| 173 | } |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 174 | } |
| 175 | #endif /* CONFIG_HAS_FSL_DR_USB */ |
| 176 | |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 177 | /* |
| 178 | * update crypto node properties to a specified revision of the SEC |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 179 | * called with sec_rev == 0 if not on an E processor |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 180 | */ |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 181 | #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */ |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 182 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 183 | { |
| 184 | const struct sec_rev_prop { |
| 185 | u32 sec_rev; |
| 186 | u32 num_channels; |
| 187 | u32 channel_fifo_len; |
| 188 | u32 exec_units_mask; |
| 189 | u32 descriptor_types_mask; |
| 190 | } sec_rev_prop_list [] = { |
| 191 | { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */ |
| 192 | { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */ |
| 193 | { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */ |
| 194 | { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */ |
| 195 | { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */ |
| 196 | { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */ |
| 197 | { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */ |
| 198 | }; |
| 199 | char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) * |
| 200 | sizeof("fsl,secX.Y")]; |
| 201 | int crypto_node, sec_idx, err; |
| 202 | char *p; |
| 203 | u32 val; |
| 204 | |
| 205 | /* locate crypto node based on lowest common compatible */ |
| 206 | crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0"); |
| 207 | if (crypto_node == -FDT_ERR_NOTFOUND) |
| 208 | return; |
| 209 | |
| 210 | /* delete it if not on an E-processor */ |
| 211 | if (crypto_node > 0 && !sec_rev) { |
| 212 | fdt_del_node(blob, crypto_node); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | /* else we got called for possible uprev */ |
| 217 | for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++) |
| 218 | if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev) |
| 219 | break; |
| 220 | |
| 221 | if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) { |
| 222 | puts("warning: unknown SEC revision number\n"); |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels); |
| 227 | err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4); |
| 228 | if (err < 0) |
| 229 | printf("WARNING: could not set crypto property: %s\n", |
| 230 | fdt_strerror(err)); |
| 231 | |
| 232 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask); |
| 233 | err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4); |
| 234 | if (err < 0) |
| 235 | printf("WARNING: could not set crypto property: %s\n", |
| 236 | fdt_strerror(err)); |
| 237 | |
| 238 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask); |
| 239 | err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4); |
| 240 | if (err < 0) |
| 241 | printf("WARNING: could not set crypto property: %s\n", |
| 242 | fdt_strerror(err)); |
| 243 | |
| 244 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len); |
| 245 | err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4); |
| 246 | if (err < 0) |
| 247 | printf("WARNING: could not set crypto property: %s\n", |
| 248 | fdt_strerror(err)); |
| 249 | |
| 250 | val = 0; |
| 251 | while (sec_idx >= 0) { |
| 252 | p = compat_strlist + val; |
| 253 | val += sprintf(p, "fsl,sec%d.%d", |
| 254 | (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8, |
| 255 | sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1; |
| 256 | sec_idx--; |
| 257 | } |
| 258 | err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val); |
| 259 | if (err < 0) |
| 260 | printf("WARNING: could not set crypto property: %s\n", |
| 261 | fdt_strerror(err)); |
| 262 | } |
Kim Phillips | 22f292c | 2010-06-01 12:24:34 -0500 | [diff] [blame] | 263 | #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */ |
| 264 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 265 | { |
| 266 | if (!sec_rev) |
| 267 | fdt_del_node_and_alias(blob, "crypto"); |
| 268 | } |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 269 | #endif |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 270 | |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 271 | int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc) |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 272 | { |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 273 | return fdt_setprop_string(blob, offset, "phy-connection-type", |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 274 | phy_string_for_interface(phyc)); |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 275 | } |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 276 | |
| 277 | #ifdef CONFIG_SYS_SRIO |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 278 | static inline void ft_disable_srio_port(void *blob, int srio_off, int port) |
| 279 | { |
| 280 | int off = fdt_node_offset_by_prop_value(blob, srio_off, |
| 281 | "cell-index", &port, 4); |
| 282 | if (off >= 0) { |
| 283 | off = fdt_setprop_string(blob, off, "status", "disabled"); |
| 284 | if (off > 0) |
| 285 | printf("WARNING unable to set status for fsl,srio " |
| 286 | "port %d: %s\n", port, fdt_strerror(off)); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | static inline void ft_disable_rman(void *blob) |
| 291 | { |
| 292 | int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman"); |
| 293 | if (off >= 0) { |
| 294 | off = fdt_setprop_string(blob, off, "status", "disabled"); |
| 295 | if (off > 0) |
| 296 | printf("WARNING unable to set status for fsl,rman %s\n", |
| 297 | fdt_strerror(off)); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | static inline void ft_disable_rmu(void *blob) |
| 302 | { |
| 303 | int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu"); |
| 304 | if (off >= 0) { |
| 305 | off = fdt_setprop_string(blob, off, "status", "disabled"); |
| 306 | if (off > 0) |
| 307 | printf("WARNING unable to set status for " |
| 308 | "fsl,srio-rmu %s\n", fdt_strerror(off)); |
| 309 | } |
| 310 | } |
| 311 | |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 312 | void ft_srio_setup(void *blob) |
| 313 | { |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 314 | int srio1_used = 0, srio2_used = 0; |
| 315 | int srio_off; |
| 316 | |
| 317 | /* search for srio node, if doesn't exist just return - nothing todo */ |
| 318 | srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio"); |
| 319 | if (srio_off < 0) |
| 320 | return ; |
| 321 | |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 322 | #ifdef CONFIG_SRIO1 |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 323 | if (is_serdes_configured(SRIO1)) |
| 324 | srio1_used = 1; |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 325 | #endif |
| 326 | #ifdef CONFIG_SRIO2 |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 327 | if (is_serdes_configured(SRIO2)) |
| 328 | srio2_used = 1; |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 329 | #endif |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 330 | |
| 331 | /* mark port1 disabled */ |
| 332 | if (!srio1_used) |
| 333 | ft_disable_srio_port(blob, srio_off, 1); |
| 334 | |
| 335 | /* mark port2 disabled */ |
| 336 | if (!srio2_used) |
| 337 | ft_disable_srio_port(blob, srio_off, 2); |
| 338 | |
| 339 | /* if both ports not used, disable controller, rmu and rman */ |
| 340 | if (!srio1_used && !srio2_used) { |
| 341 | fdt_setprop_string(blob, srio_off, "status", "disabled"); |
| 342 | |
| 343 | ft_disable_rman(blob); |
| 344 | ft_disable_rmu(blob); |
| 345 | } |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 346 | } |
| 347 | #endif |