Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 1 | /* |
Albert ARIBAUD | 340983d | 2011-04-22 19:41:02 +0200 | [diff] [blame] | 2 | * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net> |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 3 | * |
| 4 | * Based on original Kirkwood support which is |
| 5 | * (C) Copyright 2009 |
| 6 | * Marvell Semiconductor <www.marvell.com> |
| 7 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 25 | * MA 02110-1301 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <netdev.h> |
| 30 | #include <asm/cache.h> |
| 31 | #include <u-boot/md5.h> |
| 32 | #include <asm/arch/orion5x.h> |
| 33 | #include <hush.h> |
| 34 | |
| 35 | #define BUFLEN 16 |
| 36 | |
| 37 | void reset_cpu(unsigned long ignored) |
| 38 | { |
| 39 | struct orion5x_cpu_registers *cpureg = |
| 40 | (struct orion5x_cpu_registers *)ORION5X_CPU_REG_BASE; |
| 41 | |
| 42 | writel(readl(&cpureg->rstoutn_mask) | (1 << 2), |
| 43 | &cpureg->rstoutn_mask); |
| 44 | writel(readl(&cpureg->sys_soft_rst) | 1, |
| 45 | &cpureg->sys_soft_rst); |
| 46 | while (1) |
| 47 | ; |
| 48 | } |
| 49 | |
| 50 | /* |
Albert Aribaud | 787aba3 | 2010-10-07 20:19:53 +0530 | [diff] [blame] | 51 | * Compute Window Size field value from size expressed in bytes |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 52 | * Used with the Base register to set the address window size and location. |
| 53 | * Must be programmed from LSB to MSB as sequence of ones followed by |
| 54 | * sequence of zeros. The number of ones specifies the size of the window in |
Albert Aribaud | 787aba3 | 2010-10-07 20:19:53 +0530 | [diff] [blame] | 55 | * 64 KiB granularity (e.g., a value of 0x00FF specifies 256 = 16 MiB). |
| 56 | * NOTES: |
| 57 | * 1) A sizeval equal to 0x0 specifies 4 GiB. |
| 58 | * 2) A return value of 0x0 specifies 64 KiB. |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 59 | */ |
| 60 | unsigned int orion5x_winctrl_calcsize(unsigned int sizeval) |
| 61 | { |
Albert Aribaud | 787aba3 | 2010-10-07 20:19:53 +0530 | [diff] [blame] | 62 | /* |
| 63 | * Calculate the number of 64 KiB blocks needed minus one (rounding up). |
| 64 | * For sizeval > 0 this is equivalent to: |
| 65 | * sizeval = (u32) ceil((double) sizeval / 65536.0) - 1 |
| 66 | */ |
| 67 | sizeval = (sizeval - 1) >> 16; |
| 68 | |
| 69 | /* |
| 70 | * Propagate 'one' bits to the right by 'oring' them. |
| 71 | * We need only treat bits 15-0. |
| 72 | */ |
| 73 | sizeval |= sizeval >> 1; /* 'Or' bit 15 onto bit 14 */ |
| 74 | sizeval |= sizeval >> 2; /* 'Or' bits 15-14 onto bits 13-12 */ |
| 75 | sizeval |= sizeval >> 4; /* 'Or' bits 15-12 onto bits 11-8 */ |
| 76 | sizeval |= sizeval >> 8; /* 'Or' bits 15-8 onto bits 7-0*/ |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 77 | |
Albert Aribaud | 787aba3 | 2010-10-07 20:19:53 +0530 | [diff] [blame] | 78 | return sizeval; |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* |
| 82 | * orion5x_config_adr_windows - Configure address Windows |
| 83 | * |
| 84 | * There are 8 address windows supported by Orion5x Soc to addess different |
| 85 | * devices. Each window can be configured for size, BAR and remap addr |
| 86 | * Below configuration is standard for most of the cases |
| 87 | * |
| 88 | * If remap function not used, remap_lo must be set as base |
| 89 | * |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 90 | * NOTES: |
| 91 | * |
| 92 | * 1) in order to avoid windows with inconsistent control and base values |
| 93 | * (which could prevent access to BOOTCS and hence execution from FLASH) |
| 94 | * always disable window before writing the base value then reenable it |
| 95 | * by writing the control value. |
| 96 | * |
| 97 | * 2) in order to avoid losing access to BOOTCS when disabling window 7, |
| 98 | * first configure window 6 for BOOTCS, then configure window 7 for BOOTCS, |
| 99 | * then configure windows 6 for its own target. |
| 100 | * |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 101 | * Reference Documentation: |
| 102 | * Mbus-L to Mbus Bridge Registers Configuration. |
| 103 | * (Sec 25.1 and 25.3 of Datasheet) |
| 104 | */ |
| 105 | int orion5x_config_adr_windows(void) |
| 106 | { |
| 107 | struct orion5x_win_registers *winregs = |
| 108 | (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE; |
| 109 | |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 110 | /* Disable window 0, configure it for its intended target, enable it. */ |
| 111 | writel(0, &winregs[0].ctrl); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 112 | writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base); |
| 113 | writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo); |
| 114 | writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 115 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM, |
| 116 | ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM, |
| 117 | ORION5X_WIN_ENABLE), &winregs[0].ctrl); |
| 118 | /* Disable window 1, configure it for its intended target, enable it. */ |
| 119 | writel(0, &winregs[1].ctrl); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 120 | writel(ORION5X_ADR_PCIE_IO, &winregs[1].base); |
| 121 | writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo); |
| 122 | writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 123 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO, |
| 124 | ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO, |
| 125 | ORION5X_WIN_ENABLE), &winregs[1].ctrl); |
| 126 | /* Disable window 2, configure it for its intended target, enable it. */ |
| 127 | writel(0, &winregs[2].ctrl); |
| 128 | writel(ORION5X_ADR_PCI_MEM, &winregs[2].base); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 129 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM, |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 130 | ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM, |
| 131 | ORION5X_WIN_ENABLE), &winregs[2].ctrl); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 132 | /* Disable window 3, configure it for its intended target, enable it. */ |
| 133 | writel(0, &winregs[3].ctrl); |
| 134 | writel(ORION5X_ADR_PCI_IO, &winregs[3].base); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 135 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO, |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 136 | ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO, |
| 137 | ORION5X_WIN_ENABLE), &winregs[3].ctrl); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 138 | /* Disable window 4, configure it for its intended target, enable it. */ |
| 139 | writel(0, &winregs[4].ctrl); |
| 140 | writel(ORION5X_ADR_DEV_CS0, &winregs[4].base); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 141 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0, |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 142 | ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0, |
| 143 | ORION5X_WIN_ENABLE), &winregs[4].ctrl); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 144 | /* Disable window 5, configure it for its intended target, enable it. */ |
| 145 | writel(0, &winregs[5].ctrl); |
| 146 | writel(ORION5X_ADR_DEV_CS1, &winregs[5].base); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 147 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1, |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 148 | ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1, |
| 149 | ORION5X_WIN_ENABLE), &winregs[5].ctrl); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 150 | /* Disable window 6, configure it for FLASH, enable it. */ |
| 151 | writel(0, &winregs[6].ctrl); |
| 152 | writel(ORION5X_ADR_BOOTROM, &winregs[6].base); |
| 153 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM, |
| 154 | ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM, |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 155 | ORION5X_WIN_ENABLE), &winregs[6].ctrl); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 156 | /* Disable window 7, configure it for FLASH, enable it. */ |
| 157 | writel(0, &winregs[7].ctrl); |
| 158 | writel(ORION5X_ADR_BOOTROM, &winregs[7].base); |
Albert Aribaud | f4704d0 | 2010-07-13 09:04:26 +0200 | [diff] [blame] | 159 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM, |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 160 | ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM, |
| 161 | ORION5X_WIN_ENABLE), &winregs[7].ctrl); |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 162 | /* Disable window 6, configure it for its intended target, enable it. */ |
| 163 | writel(0, &winregs[6].ctrl); |
| 164 | writel(ORION5X_ADR_DEV_CS2, &winregs[6].base); |
| 165 | writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2, |
| 166 | ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2, |
| 167 | ORION5X_WIN_ENABLE), &winregs[6].ctrl); |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Orion5x identification is done through PCIE space. |
| 174 | */ |
| 175 | |
| 176 | u32 orion5x_device_id(void) |
| 177 | { |
| 178 | return readl(PCIE_DEV_ID_OFF) >> 16; |
| 179 | } |
| 180 | |
| 181 | u32 orion5x_device_rev(void) |
| 182 | { |
| 183 | return readl(PCIE_DEV_REV_OFF) & 0xff; |
| 184 | } |
| 185 | |
| 186 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 187 | |
| 188 | /* Display device and revision IDs. |
| 189 | * This function must cover all known device/revision |
| 190 | * combinations, not only the one for which u-boot is |
| 191 | * compiled; this way, one can identify actual HW in |
| 192 | * case of a mismatch. |
| 193 | */ |
| 194 | int print_cpuinfo(void) |
| 195 | { |
| 196 | char dev_str[] = "0x0000"; |
| 197 | char rev_str[] = "0x00"; |
| 198 | char *dev_name = NULL; |
| 199 | char *rev_name = NULL; |
| 200 | |
| 201 | u32 dev = orion5x_device_id(); |
| 202 | u32 rev = orion5x_device_rev(); |
| 203 | |
| 204 | if (dev == MV88F5181_DEV_ID) { |
| 205 | dev_name = "MV88F5181"; |
| 206 | if (rev == MV88F5181_REV_B1) |
| 207 | rev_name = "B1"; |
| 208 | else if (rev == MV88F5181L_REV_A1) { |
| 209 | dev_name = "MV88F5181L"; |
| 210 | rev_name = "A1"; |
| 211 | } else if (rev == MV88F5181L_REV_A0) { |
| 212 | dev_name = "MV88F5181L"; |
| 213 | rev_name = "A0"; |
| 214 | } |
| 215 | } else if (dev == MV88F5182_DEV_ID) { |
| 216 | dev_name = "MV88F5182"; |
| 217 | if (rev == MV88F5182_REV_A2) |
| 218 | rev_name = "A2"; |
| 219 | } else if (dev == MV88F5281_DEV_ID) { |
| 220 | dev_name = "MV88F5281"; |
| 221 | if (rev == MV88F5281_REV_D2) |
| 222 | rev_name = "D2"; |
| 223 | else if (rev == MV88F5281_REV_D1) |
| 224 | rev_name = "D1"; |
| 225 | else if (rev == MV88F5281_REV_D0) |
| 226 | rev_name = "D0"; |
| 227 | } else if (dev == MV88F6183_DEV_ID) { |
| 228 | dev_name = "MV88F6183"; |
| 229 | if (rev == MV88F6183_REV_B0) |
| 230 | rev_name = "B0"; |
| 231 | } |
| 232 | if (dev_name == NULL) { |
| 233 | sprintf(dev_str, "0x%04x", dev); |
| 234 | dev_name = dev_str; |
| 235 | } |
| 236 | if (rev_name == NULL) { |
| 237 | sprintf(rev_str, "0x%02x", rev); |
| 238 | rev_name = rev_str; |
| 239 | } |
| 240 | |
| 241 | printf("SoC: Orion5x %s-%s\n", dev_name, rev_name); |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
| 246 | |
| 247 | #ifdef CONFIG_ARCH_CPU_INIT |
| 248 | int arch_cpu_init(void) |
| 249 | { |
| 250 | /* Enable and invalidate L2 cache in write through mode */ |
| 251 | invalidate_l2_cache(); |
| 252 | |
| 253 | orion5x_config_adr_windows(); |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | #endif /* CONFIG_ARCH_CPU_INIT */ |
| 258 | |
| 259 | /* |
| 260 | * SOC specific misc init |
| 261 | */ |
| 262 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 263 | int arch_misc_init(void) |
| 264 | { |
| 265 | u32 temp; |
| 266 | |
| 267 | /*CPU streaming & write allocate */ |
| 268 | temp = readfr_extra_feature_reg(); |
| 269 | temp &= ~(1 << 28); /* disable wr alloc */ |
| 270 | writefr_extra_feature_reg(temp); |
| 271 | |
| 272 | temp = readfr_extra_feature_reg(); |
| 273 | temp &= ~(1 << 29); /* streaming disabled */ |
| 274 | writefr_extra_feature_reg(temp); |
| 275 | |
| 276 | /* L2Cache settings */ |
| 277 | temp = readfr_extra_feature_reg(); |
| 278 | /* Disable L2C pre fetch - Set bit 24 */ |
| 279 | temp |= (1 << 24); |
| 280 | /* enable L2C - Set bit 22 */ |
| 281 | temp |= (1 << 22); |
| 282 | writefr_extra_feature_reg(temp); |
| 283 | |
| 284 | icache_enable(); |
| 285 | /* Change reset vector to address 0x0 */ |
| 286 | temp = get_cr(); |
| 287 | set_cr(temp & ~CR_V); |
| 288 | |
| 289 | /* Set CPIOs and MPPs - values provided by board |
| 290 | include file */ |
Albert Aribaud | 65a236d | 2010-06-22 15:50:28 +0530 | [diff] [blame] | 291 | writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00); |
| 292 | writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04); |
| 293 | writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50); |
| 294 | writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04); |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 295 | |
Albert Aribaud | fd5f973 | 2010-09-23 21:49:23 +0200 | [diff] [blame] | 296 | /* initialize timer */ |
| 297 | timer_init_r(); |
Albert Aribaud | ac2ba9e | 2010-06-17 19:36:07 +0530 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | #endif /* CONFIG_ARCH_MISC_INIT */ |
Albert Aribaud | 8a99523 | 2010-07-12 22:24:29 +0200 | [diff] [blame] | 301 | |
| 302 | #ifdef CONFIG_MVGBE |
| 303 | int cpu_eth_init(bd_t *bis) |
| 304 | { |
| 305 | mvgbe_initialize(bis); |
| 306 | return 0; |
| 307 | } |
| 308 | #endif |