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> |
| 33 | #ifdef CONFIG_HAS_FSL_DR_USB |
| 34 | #include <usb.h> |
| 35 | #endif |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 36 | |
Kumar Gala | 8f3a7fa | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 37 | #if defined(CONFIG_MP) && (defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)) |
Kumar Gala | 11beefa | 2010-06-09 13:14:28 -0500 | [diff] [blame] | 38 | static int ft_del_cpuhandle(void *blob, int cpuhandle) |
| 39 | { |
| 40 | int off, ret = -FDT_ERR_NOTFOUND; |
| 41 | |
| 42 | /* if we find a match, we'll delete at it which point the offsets are |
| 43 | * invalid so we start over from the beginning |
| 44 | */ |
| 45 | off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle", |
| 46 | &cpuhandle, 4); |
| 47 | while (off != -FDT_ERR_NOTFOUND) { |
| 48 | fdt_delprop(blob, off, "cpu-handle"); |
| 49 | ret = 1; |
| 50 | off = fdt_node_offset_by_prop_value(blob, -1, "cpu-handle", |
| 51 | &cpuhandle, 4); |
| 52 | } |
| 53 | |
| 54 | return ret; |
| 55 | } |
| 56 | |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 57 | void ft_fixup_num_cores(void *blob) { |
| 58 | int off, num_cores, del_cores; |
| 59 | |
| 60 | del_cores = 0; |
| 61 | num_cores = cpu_numcores(); |
| 62 | |
| 63 | off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); |
| 64 | while (off != -FDT_ERR_NOTFOUND) { |
| 65 | u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); |
| 66 | |
Kumar Gala | 8f3a7fa | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 67 | if ((*reg > num_cores-1) || (is_core_disabled(*reg))) { |
Kumar Gala | 11beefa | 2010-06-09 13:14:28 -0500 | [diff] [blame] | 68 | int ph = fdt_get_phandle(blob, off); |
| 69 | |
| 70 | /* Delete the cpu node once there are no cpu handles */ |
| 71 | if (-FDT_ERR_NOTFOUND == ft_del_cpuhandle(blob, ph)) { |
| 72 | fdt_del_node(blob, off); |
| 73 | del_cores++; |
| 74 | } |
| 75 | /* either we deleted some cpu handles or the cpu node |
| 76 | * so we reset the offset back to the start since we |
| 77 | * can't trust the offsets anymore |
| 78 | */ |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 79 | off = -1; |
| 80 | } |
| 81 | off = fdt_node_offset_by_prop_value(blob, off, |
| 82 | "device_type", "cpu", 4); |
| 83 | } |
| 84 | debug ("%x core system found\n", num_cores); |
| 85 | debug ("deleted %d extra core entry entries from device tree\n", |
| 86 | del_cores); |
| 87 | } |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 88 | #endif /* defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) */ |
| 89 | |
| 90 | #ifdef CONFIG_HAS_FSL_DR_USB |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 91 | static void fdt_fixup_usb_mode_phy_type(void *blob, const char *mode, |
| 92 | const char *phy_type) |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 93 | { |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 94 | const char *compat = "fsl-usb2-dr"; |
| 95 | const char *prop_mode = "dr_mode"; |
| 96 | const char *prop_type = "phy_type"; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 97 | static int start_offset = -1; |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 98 | int node_offset; |
| 99 | int err; |
| 100 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 101 | node_offset = fdt_node_offset_by_compatible(blob, |
| 102 | start_offset, compat); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 103 | if (node_offset < 0) { |
| 104 | printf("WARNING: could not find compatible node %s: %s.\n", |
| 105 | compat, fdt_strerror(node_offset)); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (mode) { |
| 110 | err = fdt_setprop(blob, node_offset, prop_mode, mode, |
| 111 | strlen(mode) + 1); |
| 112 | if (err < 0) |
| 113 | printf("WARNING: could not set %s for %s: %s.\n", |
| 114 | prop_mode, compat, fdt_strerror(err)); |
| 115 | } |
| 116 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 117 | if (phy_type) { |
| 118 | err = fdt_setprop(blob, node_offset, prop_type, phy_type, |
| 119 | strlen(phy_type) + 1); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 120 | if (err < 0) |
| 121 | printf("WARNING: could not set %s for %s: %s.\n", |
| 122 | prop_type, compat, fdt_strerror(err)); |
| 123 | } |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 124 | |
| 125 | start_offset = node_offset; |
| 126 | } |
| 127 | |
| 128 | void fdt_fixup_dr_usb(void *blob, bd_t *bd) |
| 129 | { |
| 130 | const char *modes[] = { "host", "peripheral", "otg" }; |
| 131 | const char *phys[] = { "ulpi", "umti" }; |
| 132 | const char *mode = NULL; |
| 133 | const char *phy_type = NULL; |
| 134 | char usb1_defined = 0; |
| 135 | char str[5]; |
| 136 | int i, j; |
| 137 | |
| 138 | for (i = 1; i <= USB_MAX_DEVICE; i++) { |
| 139 | int mode_idx = -1, phy_idx = -1; |
| 140 | sprintf(str, "%s%d", "usb", i); |
| 141 | if (hwconfig(str)) { |
| 142 | for (j = 0; j < sizeof(modes); j++) { |
| 143 | if (hwconfig_subarg_cmp(str, "dr_mode", |
| 144 | modes[j])) { |
| 145 | mode_idx = j; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | for (j = 0; j < sizeof(phys); j++) { |
| 150 | if (hwconfig_subarg_cmp(str, "phy_type", |
| 151 | phys[j])) { |
| 152 | phy_idx = j; |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | if (mode_idx >= 0) |
| 157 | fdt_fixup_usb_mode_phy_type(blob, |
| 158 | modes[mode_idx], NULL); |
| 159 | if (phy_idx >= 0) |
| 160 | fdt_fixup_usb_mode_phy_type(blob, |
| 161 | NULL, phys[phy_idx]); |
| 162 | if (!strcmp(str, "usb1")) |
| 163 | usb1_defined = 1; |
| 164 | if (mode_idx < 0 && phy_idx < 0) |
| 165 | printf("WARNING: invalid phy or mode\n"); |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | if (!usb1_defined) { |
| 169 | mode = getenv("usb_dr_mode"); |
| 170 | phy_type = getenv("usb_phy_type"); |
| 171 | if (!mode && !phy_type) |
| 172 | return; |
| 173 | fdt_fixup_usb_mode_phy_type(blob, mode, phy_type); |
| 174 | } |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 175 | } |
| 176 | #endif /* CONFIG_HAS_FSL_DR_USB */ |
| 177 | |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 178 | /* |
| 179 | * update crypto node properties to a specified revision of the SEC |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 180 | * called with sec_rev == 0 if not on an E processor |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 181 | */ |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 182 | #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */ |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 183 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 184 | { |
| 185 | const struct sec_rev_prop { |
| 186 | u32 sec_rev; |
| 187 | u32 num_channels; |
| 188 | u32 channel_fifo_len; |
| 189 | u32 exec_units_mask; |
| 190 | u32 descriptor_types_mask; |
| 191 | } sec_rev_prop_list [] = { |
| 192 | { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */ |
| 193 | { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */ |
| 194 | { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */ |
| 195 | { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */ |
| 196 | { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */ |
| 197 | { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */ |
| 198 | { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */ |
| 199 | }; |
| 200 | char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) * |
| 201 | sizeof("fsl,secX.Y")]; |
| 202 | int crypto_node, sec_idx, err; |
| 203 | char *p; |
| 204 | u32 val; |
| 205 | |
| 206 | /* locate crypto node based on lowest common compatible */ |
| 207 | crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0"); |
| 208 | if (crypto_node == -FDT_ERR_NOTFOUND) |
| 209 | return; |
| 210 | |
| 211 | /* delete it if not on an E-processor */ |
| 212 | if (crypto_node > 0 && !sec_rev) { |
| 213 | fdt_del_node(blob, crypto_node); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | /* else we got called for possible uprev */ |
| 218 | for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++) |
| 219 | if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev) |
| 220 | break; |
| 221 | |
| 222 | if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) { |
| 223 | puts("warning: unknown SEC revision number\n"); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels); |
| 228 | err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4); |
| 229 | if (err < 0) |
| 230 | printf("WARNING: could not set crypto property: %s\n", |
| 231 | fdt_strerror(err)); |
| 232 | |
| 233 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask); |
| 234 | err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4); |
| 235 | if (err < 0) |
| 236 | printf("WARNING: could not set crypto property: %s\n", |
| 237 | fdt_strerror(err)); |
| 238 | |
| 239 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask); |
| 240 | err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4); |
| 241 | if (err < 0) |
| 242 | printf("WARNING: could not set crypto property: %s\n", |
| 243 | fdt_strerror(err)); |
| 244 | |
| 245 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len); |
| 246 | err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4); |
| 247 | if (err < 0) |
| 248 | printf("WARNING: could not set crypto property: %s\n", |
| 249 | fdt_strerror(err)); |
| 250 | |
| 251 | val = 0; |
| 252 | while (sec_idx >= 0) { |
| 253 | p = compat_strlist + val; |
| 254 | val += sprintf(p, "fsl,sec%d.%d", |
| 255 | (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8, |
| 256 | sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1; |
| 257 | sec_idx--; |
| 258 | } |
| 259 | err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val); |
| 260 | if (err < 0) |
| 261 | printf("WARNING: could not set crypto property: %s\n", |
| 262 | fdt_strerror(err)); |
| 263 | } |
Kim Phillips | 22f292c | 2010-06-01 12:24:34 -0500 | [diff] [blame] | 264 | #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */ |
| 265 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 266 | { |
| 267 | if (!sec_rev) |
| 268 | fdt_del_node_and_alias(blob, "crypto"); |
| 269 | } |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 270 | #endif |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 271 | |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 272 | 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] | 273 | { |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 274 | return fdt_setprop_string(blob, offset, "phy-connection-type", |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 275 | phy_string_for_interface(phyc)); |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 276 | } |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 277 | |
| 278 | #ifdef CONFIG_SYS_SRIO |
| 279 | void ft_srio_setup(void *blob) |
| 280 | { |
| 281 | #ifdef CONFIG_SRIO1 |
| 282 | if (!is_serdes_configured(SRIO1)) { |
| 283 | fdt_del_node_and_alias(blob, "rio0"); |
| 284 | } |
| 285 | #else |
| 286 | fdt_del_node_and_alias(blob, "rio0"); |
| 287 | #endif |
| 288 | #ifdef CONFIG_SRIO2 |
| 289 | if (!is_serdes_configured(SRIO2)) { |
| 290 | fdt_del_node_and_alias(blob, "rio1"); |
| 291 | } |
| 292 | #else |
| 293 | fdt_del_node_and_alias(blob, "rio1"); |
| 294 | #endif |
| 295 | } |
| 296 | #endif |