Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 1 | /* |
ramneek mehresh | 5a52977 | 2012-02-06 19:17:29 +0000 | [diff] [blame] | 2 | * Copyright 2009-2012 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); |
York Sun | 709389b | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 65 | u32 phys_cpu_id = thread_to_core(*reg); |
Poonam Aggrwal | f8027f6 | 2009-09-02 19:40:36 +0530 | [diff] [blame] | 66 | |
York Sun | 709389b | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 67 | if (!is_core_valid(phys_cpu_id) || is_core_disabled(phys_cpu_id)) { |
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 | |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 90 | #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) |
Ramneek Mehresh | 4765fb7 | 2011-11-08 13:09:20 +0530 | [diff] [blame] | 91 | static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode, |
| 92 | const char *phy_type, int start_offset) |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 93 | { |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 94 | const char *compat_dr = "fsl-usb2-dr"; |
| 95 | const char *compat_mph = "fsl-usb2-mph"; |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 96 | const char *prop_mode = "dr_mode"; |
| 97 | const char *prop_type = "phy_type"; |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 98 | const char *node_type = NULL; |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 99 | int node_offset; |
| 100 | int err; |
| 101 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 102 | node_offset = fdt_node_offset_by_compatible(blob, |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 103 | start_offset, compat_mph); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 104 | if (node_offset < 0) { |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 105 | node_offset = fdt_node_offset_by_compatible(blob, |
| 106 | start_offset, compat_dr); |
| 107 | if (node_offset < 0) { |
| 108 | printf("WARNING: could not find compatible" |
| 109 | " node %s or %s: %s.\n", compat_mph, |
| 110 | compat_dr, fdt_strerror(node_offset)); |
| 111 | return -1; |
| 112 | } else |
| 113 | node_type = compat_dr; |
| 114 | } else |
| 115 | node_type = compat_mph; |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 116 | |
| 117 | if (mode) { |
| 118 | err = fdt_setprop(blob, node_offset, prop_mode, mode, |
| 119 | strlen(mode) + 1); |
| 120 | if (err < 0) |
| 121 | printf("WARNING: could not set %s for %s: %s.\n", |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 122 | prop_mode, node_type, fdt_strerror(err)); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 125 | if (phy_type) { |
| 126 | err = fdt_setprop(blob, node_offset, prop_type, phy_type, |
| 127 | strlen(phy_type) + 1); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 128 | if (err < 0) |
| 129 | printf("WARNING: could not set %s for %s: %s.\n", |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 130 | prop_type, node_type, fdt_strerror(err)); |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 131 | } |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 132 | |
Ramneek Mehresh | 4765fb7 | 2011-11-08 13:09:20 +0530 | [diff] [blame] | 133 | return node_offset; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void fdt_fixup_dr_usb(void *blob, bd_t *bd) |
| 137 | { |
| 138 | const char *modes[] = { "host", "peripheral", "otg" }; |
Ramneek Mehresh | 4765fb7 | 2011-11-08 13:09:20 +0530 | [diff] [blame] | 139 | const char *phys[] = { "ulpi", "utmi" }; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 140 | const char *mode = NULL; |
| 141 | const char *phy_type = NULL; |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 142 | const char *dr_mode_type = NULL; |
| 143 | const char *dr_phy_type = NULL; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 144 | char usb1_defined = 0; |
Ramneek Mehresh | 4765fb7 | 2011-11-08 13:09:20 +0530 | [diff] [blame] | 145 | int usb_mode_off = -1; |
| 146 | int usb_phy_off = -1; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 147 | char str[5]; |
| 148 | int i, j; |
| 149 | |
Kumar Gala | 5756736 | 2011-07-29 08:51:26 -0500 | [diff] [blame] | 150 | for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) { |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 151 | int mode_idx = -1, phy_idx = -1; |
ramneek mehresh | 5a52977 | 2012-02-06 19:17:29 +0000 | [diff] [blame] | 152 | snprintf(str, 5, "%s%d", "usb", i); |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 153 | if (hwconfig(str)) { |
ramneek mehresh | 5a52977 | 2012-02-06 19:17:29 +0000 | [diff] [blame] | 154 | for (j = 0; j < ARRAY_SIZE(modes); j++) { |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 155 | if (hwconfig_subarg_cmp(str, "dr_mode", |
| 156 | modes[j])) { |
| 157 | mode_idx = j; |
| 158 | break; |
| 159 | } |
| 160 | } |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 161 | |
ramneek mehresh | 5a52977 | 2012-02-06 19:17:29 +0000 | [diff] [blame] | 162 | for (j = 0; j < ARRAY_SIZE(phys); j++) { |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 163 | if (hwconfig_subarg_cmp(str, "phy_type", |
| 164 | phys[j])) { |
| 165 | phy_idx = j; |
| 166 | break; |
| 167 | } |
| 168 | } |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 169 | |
ramneek mehresh | dda48e8 | 2013-02-17 18:23:32 +0000 | [diff] [blame] | 170 | if (mode_idx < 0 || phy_idx < 0) { |
| 171 | puts("ERROR: wrong usb mode/phy defined!!\n"); |
| 172 | return; |
| 173 | } |
| 174 | |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 175 | dr_mode_type = modes[mode_idx]; |
| 176 | dr_phy_type = phys[phy_idx]; |
| 177 | |
| 178 | /* use usb_dr_mode and usb_phy_type if |
| 179 | usb1_defined = 0; these variables are to |
| 180 | be deprecated */ |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 181 | if (!strcmp(str, "usb1")) |
| 182 | usb1_defined = 1; |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 183 | |
| 184 | if (mode_idx < 0 && phy_idx < 0) { |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 185 | printf("WARNING: invalid phy or mode\n"); |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 186 | return; |
| 187 | } |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 188 | } |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 189 | |
| 190 | usb_mode_off = fdt_fixup_usb_mode_phy_type(blob, |
| 191 | dr_mode_type, NULL, usb_mode_off); |
| 192 | |
| 193 | if (usb_mode_off < 0) |
| 194 | return; |
| 195 | |
| 196 | usb_phy_off = fdt_fixup_usb_mode_phy_type(blob, |
| 197 | NULL, dr_phy_type, usb_phy_off); |
| 198 | |
| 199 | if (usb_phy_off < 0) |
| 200 | return; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 201 | } |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 202 | |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 203 | if (!usb1_defined) { |
Ramneek Mehresh | 4765fb7 | 2011-11-08 13:09:20 +0530 | [diff] [blame] | 204 | int usb_off = -1; |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 205 | mode = getenv("usb_dr_mode"); |
| 206 | phy_type = getenv("usb_phy_type"); |
ramneek mehresh | 9c889ec | 2012-09-18 22:28:51 +0000 | [diff] [blame] | 207 | if (mode || phy_type) { |
| 208 | printf("WARNING: usb_dr_mode and usb_phy_type " |
| 209 | "are to be deprecated soon. Use " |
| 210 | "hwconfig to set these values instead!!\n"); |
| 211 | fdt_fixup_usb_mode_phy_type(blob, mode, |
| 212 | phy_type, usb_off); |
| 213 | } |
Ramneek Mehresh | 72f4980 | 2011-06-08 17:14:20 +0530 | [diff] [blame] | 214 | } |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 215 | } |
ramneek mehresh | 79f4912 | 2012-02-10 00:36:43 +0000 | [diff] [blame] | 216 | #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */ |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 217 | |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 218 | /* |
| 219 | * update crypto node properties to a specified revision of the SEC |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 220 | * called with sec_rev == 0 if not on an E processor |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 221 | */ |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 222 | #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */ |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 223 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 224 | { |
Kim Phillips | 345d6ef | 2012-10-31 11:09:26 +0000 | [diff] [blame] | 225 | static const struct sec_rev_prop { |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 226 | u32 sec_rev; |
| 227 | u32 num_channels; |
| 228 | u32 channel_fifo_len; |
| 229 | u32 exec_units_mask; |
| 230 | u32 descriptor_types_mask; |
| 231 | } sec_rev_prop_list [] = { |
| 232 | { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */ |
| 233 | { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */ |
| 234 | { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */ |
| 235 | { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */ |
| 236 | { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */ |
| 237 | { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */ |
| 238 | { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */ |
| 239 | }; |
Kim Phillips | 345d6ef | 2012-10-31 11:09:26 +0000 | [diff] [blame] | 240 | static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) * |
| 241 | sizeof("fsl,secX.Y")]; |
Kim Phillips | 5d0c3b5 | 2010-05-28 08:00:14 +0000 | [diff] [blame] | 242 | int crypto_node, sec_idx, err; |
| 243 | char *p; |
| 244 | u32 val; |
| 245 | |
| 246 | /* locate crypto node based on lowest common compatible */ |
| 247 | crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0"); |
| 248 | if (crypto_node == -FDT_ERR_NOTFOUND) |
| 249 | return; |
| 250 | |
| 251 | /* delete it if not on an E-processor */ |
| 252 | if (crypto_node > 0 && !sec_rev) { |
| 253 | fdt_del_node(blob, crypto_node); |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | /* else we got called for possible uprev */ |
| 258 | for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++) |
| 259 | if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev) |
| 260 | break; |
| 261 | |
| 262 | if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) { |
| 263 | puts("warning: unknown SEC revision number\n"); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels); |
| 268 | err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4); |
| 269 | if (err < 0) |
| 270 | printf("WARNING: could not set crypto property: %s\n", |
| 271 | fdt_strerror(err)); |
| 272 | |
| 273 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask); |
| 274 | err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4); |
| 275 | if (err < 0) |
| 276 | printf("WARNING: could not set crypto property: %s\n", |
| 277 | fdt_strerror(err)); |
| 278 | |
| 279 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask); |
| 280 | err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4); |
| 281 | if (err < 0) |
| 282 | printf("WARNING: could not set crypto property: %s\n", |
| 283 | fdt_strerror(err)); |
| 284 | |
| 285 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len); |
| 286 | err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4); |
| 287 | if (err < 0) |
| 288 | printf("WARNING: could not set crypto property: %s\n", |
| 289 | fdt_strerror(err)); |
| 290 | |
| 291 | val = 0; |
| 292 | while (sec_idx >= 0) { |
| 293 | p = compat_strlist + val; |
| 294 | val += sprintf(p, "fsl,sec%d.%d", |
| 295 | (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8, |
| 296 | sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1; |
| 297 | sec_idx--; |
| 298 | } |
| 299 | err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val); |
| 300 | if (err < 0) |
| 301 | printf("WARNING: could not set crypto property: %s\n", |
| 302 | fdt_strerror(err)); |
| 303 | } |
Kim Phillips | 22f292c | 2010-06-01 12:24:34 -0500 | [diff] [blame] | 304 | #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */ |
Vakul Garg | 5e95e2d | 2013-01-23 22:52:31 +0000 | [diff] [blame] | 305 | static u8 caam_get_era(void) |
| 306 | { |
| 307 | static const struct { |
| 308 | u16 ip_id; |
| 309 | u8 maj_rev; |
| 310 | u8 era; |
| 311 | } caam_eras[] = { |
| 312 | {0x0A10, 1, 1}, |
| 313 | {0x0A10, 2, 2}, |
| 314 | {0x0A12, 1, 3}, |
| 315 | {0x0A14, 1, 3}, |
| 316 | {0x0A14, 2, 4}, |
| 317 | {0x0A16, 1, 4}, |
| 318 | {0x0A10, 3, 4}, |
| 319 | {0x0A11, 1, 4}, |
| 320 | {0x0A18, 1, 4}, |
| 321 | {0x0A11, 2, 5}, |
| 322 | {0x0A12, 2, 5}, |
| 323 | {0x0A13, 1, 5}, |
| 324 | {0x0A1C, 1, 5} |
| 325 | }; |
| 326 | |
| 327 | ccsr_sec_t __iomem *sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR; |
| 328 | u32 secvid_ms = in_be32(&sec->secvid_ms); |
| 329 | u32 ccbvid = in_be32(&sec->ccbvid); |
| 330 | u16 ip_id = (secvid_ms & SEC_SECVID_MS_IPID_MASK) >> |
| 331 | SEC_SECVID_MS_IPID_SHIFT; |
| 332 | u8 maj_rev = (secvid_ms & SEC_SECVID_MS_MAJ_REV_MASK) >> |
| 333 | SEC_SECVID_MS_MAJ_REV_SHIFT; |
| 334 | u8 era = (ccbvid & SEC_CCBVID_ERA_MASK) >> SEC_CCBVID_ERA_SHIFT; |
| 335 | |
| 336 | int i; |
| 337 | |
| 338 | if (era) /* This is '0' prior to CAAM ERA-6 */ |
| 339 | return era; |
| 340 | |
| 341 | for (i = 0; i < ARRAY_SIZE(caam_eras); i++) |
| 342 | if (caam_eras[i].ip_id == ip_id && |
| 343 | caam_eras[i].maj_rev == maj_rev) |
| 344 | return caam_eras[i].era; |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static void fdt_fixup_crypto_era(void *blob, u32 era) |
| 350 | { |
| 351 | int err; |
| 352 | int crypto_node; |
| 353 | |
| 354 | crypto_node = fdt_path_offset(blob, "crypto"); |
| 355 | if (crypto_node < 0) { |
| 356 | printf("WARNING: Missing crypto node\n"); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | err = fdt_setprop(blob, crypto_node, "fsl,sec-era", &era, |
| 361 | sizeof(era)); |
| 362 | if (err < 0) { |
| 363 | printf("ERROR: could not set fsl,sec-era property: %s\n", |
| 364 | fdt_strerror(err)); |
| 365 | } |
| 366 | } |
| 367 | |
Kim Phillips | 22f292c | 2010-06-01 12:24:34 -0500 | [diff] [blame] | 368 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 369 | { |
Vakul Garg | 5e95e2d | 2013-01-23 22:52:31 +0000 | [diff] [blame] | 370 | u8 era; |
| 371 | |
| 372 | if (!sec_rev) { |
Kim Phillips | 22f292c | 2010-06-01 12:24:34 -0500 | [diff] [blame] | 373 | fdt_del_node_and_alias(blob, "crypto"); |
Vakul Garg | 5e95e2d | 2013-01-23 22:52:31 +0000 | [diff] [blame] | 374 | return; |
| 375 | } |
| 376 | |
| 377 | /* Add SEC ERA information in compatible */ |
| 378 | era = caam_get_era(); |
| 379 | if (era) { |
| 380 | fdt_fixup_crypto_era(blob, era); |
| 381 | } else { |
| 382 | printf("WARNING: Unable to get ERA for CAAM rev: %d\n", |
| 383 | sec_rev); |
| 384 | } |
Kim Phillips | 22f292c | 2010-06-01 12:24:34 -0500 | [diff] [blame] | 385 | } |
Kim Phillips | 929a213 | 2010-06-01 12:24:27 -0500 | [diff] [blame] | 386 | #endif |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 387 | |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 388 | 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] | 389 | { |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 390 | return fdt_setprop_string(blob, offset, "phy-connection-type", |
Andy Fleming | 865ff85 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 391 | phy_string_for_interface(phyc)); |
Kumar Gala | a1964ea | 2010-09-30 09:15:03 -0500 | [diff] [blame] | 392 | } |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 393 | |
| 394 | #ifdef CONFIG_SYS_SRIO |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 395 | static inline void ft_disable_srio_port(void *blob, int srio_off, int port) |
| 396 | { |
| 397 | int off = fdt_node_offset_by_prop_value(blob, srio_off, |
| 398 | "cell-index", &port, 4); |
| 399 | if (off >= 0) { |
| 400 | off = fdt_setprop_string(blob, off, "status", "disabled"); |
| 401 | if (off > 0) |
| 402 | printf("WARNING unable to set status for fsl,srio " |
| 403 | "port %d: %s\n", port, fdt_strerror(off)); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | static inline void ft_disable_rman(void *blob) |
| 408 | { |
| 409 | int off = fdt_node_offset_by_compatible(blob, -1, "fsl,rman"); |
| 410 | if (off >= 0) { |
| 411 | off = fdt_setprop_string(blob, off, "status", "disabled"); |
| 412 | if (off > 0) |
| 413 | printf("WARNING unable to set status for fsl,rman %s\n", |
| 414 | fdt_strerror(off)); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | static inline void ft_disable_rmu(void *blob) |
| 419 | { |
| 420 | int off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio-rmu"); |
| 421 | if (off >= 0) { |
| 422 | off = fdt_setprop_string(blob, off, "status", "disabled"); |
| 423 | if (off > 0) |
| 424 | printf("WARNING unable to set status for " |
| 425 | "fsl,srio-rmu %s\n", fdt_strerror(off)); |
| 426 | } |
| 427 | } |
| 428 | |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 429 | void ft_srio_setup(void *blob) |
| 430 | { |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 431 | int srio1_used = 0, srio2_used = 0; |
| 432 | int srio_off; |
| 433 | |
| 434 | /* search for srio node, if doesn't exist just return - nothing todo */ |
| 435 | srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio"); |
| 436 | if (srio_off < 0) |
| 437 | return ; |
| 438 | |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 439 | #ifdef CONFIG_SRIO1 |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 440 | if (is_serdes_configured(SRIO1)) |
| 441 | srio1_used = 1; |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 442 | #endif |
| 443 | #ifdef CONFIG_SRIO2 |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 444 | if (is_serdes_configured(SRIO2)) |
| 445 | srio2_used = 1; |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 446 | #endif |
Kumar Gala | 9c42ef6 | 2011-10-14 00:03:58 -0500 | [diff] [blame] | 447 | |
| 448 | /* mark port1 disabled */ |
| 449 | if (!srio1_used) |
| 450 | ft_disable_srio_port(blob, srio_off, 1); |
| 451 | |
| 452 | /* mark port2 disabled */ |
| 453 | if (!srio2_used) |
| 454 | ft_disable_srio_port(blob, srio_off, 2); |
| 455 | |
| 456 | /* if both ports not used, disable controller, rmu and rman */ |
| 457 | if (!srio1_used && !srio2_used) { |
| 458 | fdt_setprop_string(blob, srio_off, "status", "disabled"); |
| 459 | |
| 460 | ft_disable_rman(blob); |
| 461 | ft_disable_rmu(blob); |
| 462 | } |
Kumar Gala | a09b9b6 | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 463 | } |
| 464 | #endif |