Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 2 | * Copyright (C) 2014-2015 Stefan Roese <sr@denx.de> |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <netdev.h> |
Stefan Roese | bb1c0bd | 2015-06-29 14:58:13 +0200 | [diff] [blame] | 9 | #include <ahci.h> |
| 10 | #include <linux/mbus.h> |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
Stefan Roese | 8aee4d3 | 2015-05-18 16:09:43 +0000 | [diff] [blame] | 12 | #include <asm/pl310.h> |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 13 | #include <asm/arch/cpu.h> |
| 14 | #include <asm/arch/soc.h> |
Stefan Roese | d3e3473 | 2015-06-29 14:58:10 +0200 | [diff] [blame] | 15 | #include <sdhci.h> |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 16 | |
| 17 | #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3)) |
| 18 | #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3)) |
| 19 | |
| 20 | static struct mbus_win windows[] = { |
| 21 | /* PCIE MEM address space */ |
Stefan Roese | 13b109f | 2015-07-01 12:55:07 +0200 | [diff] [blame^] | 22 | { MBUS_PCI_MEM_BASE, MBUS_PCI_MEM_SIZE, |
| 23 | CPU_TARGET_PCIE13, CPU_ATTR_PCIE_MEM }, |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 24 | |
| 25 | /* PCIE IO address space */ |
Stefan Roese | 13b109f | 2015-07-01 12:55:07 +0200 | [diff] [blame^] | 26 | { MBUS_PCI_IO_BASE, MBUS_PCI_IO_SIZE, |
| 27 | CPU_TARGET_PCIE13, CPU_ATTR_PCIE_IO }, |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 28 | |
| 29 | /* SPI */ |
Stefan Roese | 13b109f | 2015-07-01 12:55:07 +0200 | [diff] [blame^] | 30 | { MBUS_SPI_BASE, MBUS_SPI_SIZE, |
| 31 | CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH }, |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 32 | |
| 33 | /* NOR */ |
Stefan Roese | 13b109f | 2015-07-01 12:55:07 +0200 | [diff] [blame^] | 34 | { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE, |
| 35 | CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM }, |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | void reset_cpu(unsigned long ignored) |
| 39 | { |
| 40 | struct mvebu_system_registers *reg = |
| 41 | (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE; |
| 42 | |
| 43 | writel(readl(®->rstoutn_mask) | 1, ®->rstoutn_mask); |
| 44 | writel(readl(®->sys_soft_rst) | 1, ®->sys_soft_rst); |
| 45 | while (1) |
| 46 | ; |
| 47 | } |
| 48 | |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 49 | int mvebu_soc_family(void) |
| 50 | { |
| 51 | u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff; |
| 52 | |
| 53 | if (devid == SOC_MV78460_ID) |
| 54 | return MVEBU_SOC_AXP; |
| 55 | |
| 56 | if (devid == SOC_88F6810_ID || devid == SOC_88F6820_ID || |
| 57 | devid == SOC_88F6828_ID) |
| 58 | return MVEBU_SOC_A38X; |
| 59 | |
| 60 | return MVEBU_SOC_UNKNOWN; |
| 61 | } |
| 62 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 63 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 64 | int print_cpuinfo(void) |
| 65 | { |
| 66 | u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff; |
| 67 | u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff; |
| 68 | |
| 69 | puts("SoC: "); |
| 70 | |
| 71 | switch (devid) { |
| 72 | case SOC_MV78460_ID: |
| 73 | puts("MV78460-"); |
| 74 | break; |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 75 | case SOC_88F6810_ID: |
| 76 | puts("MV88F6810-"); |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 77 | break; |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 78 | case SOC_88F6820_ID: |
| 79 | puts("MV88F6820-"); |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 80 | break; |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 81 | case SOC_88F6828_ID: |
| 82 | puts("MV88F6828-"); |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 83 | break; |
| 84 | default: |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 85 | puts("Unknown-"); |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 86 | break; |
| 87 | } |
| 88 | |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 89 | if (mvebu_soc_family() == MVEBU_SOC_AXP) { |
| 90 | switch (revid) { |
| 91 | case 1: |
| 92 | puts("A0\n"); |
| 93 | break; |
| 94 | case 2: |
| 95 | puts("B0\n"); |
| 96 | break; |
| 97 | default: |
| 98 | printf("?? (%x)\n", revid); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if (mvebu_soc_family() == MVEBU_SOC_A38X) { |
| 104 | switch (revid) { |
| 105 | case MV_88F68XX_Z1_ID: |
| 106 | puts("Z1\n"); |
| 107 | break; |
| 108 | case MV_88F68XX_A0_ID: |
| 109 | puts("A0\n"); |
| 110 | break; |
| 111 | default: |
| 112 | printf("?? (%x)\n", revid); |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
| 120 | |
| 121 | /* |
| 122 | * This function initialize Controller DRAM Fastpath windows. |
| 123 | * It takes the CS size information from the 0x1500 scratch registers |
| 124 | * and sets the correct windows sizes and base addresses accordingly. |
| 125 | * |
| 126 | * These values are set in the scratch registers by the Marvell |
| 127 | * DDR3 training code, which is executed by the BootROM before the |
| 128 | * main payload (U-Boot) is executed. This training code is currently |
| 129 | * only available in the Marvell U-Boot version. It needs to be |
| 130 | * ported to mainline U-Boot SPL at some point. |
| 131 | */ |
| 132 | static void update_sdram_window_sizes(void) |
| 133 | { |
| 134 | u64 base = 0; |
| 135 | u32 size, temp; |
| 136 | int i; |
| 137 | |
| 138 | for (i = 0; i < SDRAM_MAX_CS; i++) { |
| 139 | size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK; |
| 140 | if (size != 0) { |
| 141 | size |= ~(SDRAM_ADDR_MASK); |
| 142 | |
| 143 | /* Set Base Address */ |
| 144 | temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF); |
| 145 | writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i)); |
| 146 | |
| 147 | /* |
| 148 | * Check if out of max window size and resize |
| 149 | * the window |
| 150 | */ |
| 151 | temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) & |
| 152 | ~(SDRAM_ADDR_MASK)) | 1; |
| 153 | temp |= (size & SDRAM_ADDR_MASK); |
| 154 | writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)); |
| 155 | |
| 156 | base += ((u64)size + 1); |
| 157 | } else { |
| 158 | /* |
| 159 | * Disable window if not used, otherwise this |
| 160 | * leads to overlapping enabled windows with |
| 161 | * pretty strange results |
| 162 | */ |
| 163 | clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Stefan Roese | 73acffe | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 168 | void mmu_disable(void) |
| 169 | { |
| 170 | asm volatile( |
| 171 | "mrc p15, 0, r0, c1, c0, 0\n" |
| 172 | "bic r0, #1\n" |
| 173 | "mcr p15, 0, r0, c1, c0, 0\n"); |
| 174 | } |
| 175 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 176 | #ifdef CONFIG_ARCH_CPU_INIT |
Kevin Smith | 1ddff02 | 2015-05-18 16:09:44 +0000 | [diff] [blame] | 177 | static void set_cbar(u32 addr) |
| 178 | { |
| 179 | asm("mcr p15, 4, %0, c15, c0" : : "r" (addr)); |
| 180 | } |
| 181 | |
| 182 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 183 | int arch_cpu_init(void) |
| 184 | { |
Stefan Roese | 73acffe | 2015-04-24 10:49:11 +0200 | [diff] [blame] | 185 | #ifndef CONFIG_SPL_BUILD |
| 186 | /* |
| 187 | * Only with disabled MMU its possible to switch the base |
| 188 | * register address on Armada 38x. Without this the SDRAM |
| 189 | * located at >= 0x4000.0000 is also not accessible, as its |
| 190 | * still locked to cache. |
| 191 | */ |
| 192 | mmu_disable(); |
| 193 | #endif |
| 194 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 195 | /* Linux expects the internal registers to be at 0xf1000000 */ |
| 196 | writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG); |
Kevin Smith | 1ddff02 | 2015-05-18 16:09:44 +0000 | [diff] [blame] | 197 | set_cbar(SOC_REGS_PHY_BASE + 0xC000); |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * We need to call mvebu_mbus_probe() before calling |
| 201 | * update_sdram_window_sizes() as it disables all previously |
| 202 | * configured mbus windows and then configures them as |
| 203 | * required for U-Boot. Calling update_sdram_window_sizes() |
| 204 | * without this configuration will not work, as the internal |
| 205 | * registers can't be accessed reliably because of potenial |
| 206 | * double mapping. |
| 207 | * After updating the SDRAM access windows we need to call |
| 208 | * mvebu_mbus_probe() again, as this now correctly configures |
| 209 | * the SDRAM areas that are later used by the MVEBU drivers |
| 210 | * (e.g. USB, NETA). |
| 211 | */ |
| 212 | |
| 213 | /* |
| 214 | * First disable all windows |
| 215 | */ |
| 216 | mvebu_mbus_probe(NULL, 0); |
| 217 | |
Stefan Roese | 174d23e | 2015-04-25 06:29:51 +0200 | [diff] [blame] | 218 | if (mvebu_soc_family() == MVEBU_SOC_AXP) { |
| 219 | /* |
| 220 | * Now the SDRAM access windows can be reconfigured using |
| 221 | * the information in the SDRAM scratch pad registers |
| 222 | */ |
| 223 | update_sdram_window_sizes(); |
| 224 | } |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * Finally the mbus windows can be configured with the |
| 228 | * updated SDRAM sizes |
| 229 | */ |
| 230 | mvebu_mbus_probe(windows, ARRAY_SIZE(windows)); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | #endif /* CONFIG_ARCH_CPU_INIT */ |
| 235 | |
| 236 | /* |
| 237 | * SOC specific misc init |
| 238 | */ |
| 239 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 240 | int arch_misc_init(void) |
| 241 | { |
| 242 | /* Nothing yet, perhaps we need something here later */ |
| 243 | return 0; |
| 244 | } |
| 245 | #endif /* CONFIG_ARCH_MISC_INIT */ |
| 246 | |
| 247 | #ifdef CONFIG_MVNETA |
| 248 | int cpu_eth_init(bd_t *bis) |
| 249 | { |
Stefan Roese | 44ffbe5 | 2015-04-25 06:29:52 +0200 | [diff] [blame] | 250 | u32 enet_base[] = { MVEBU_EGIGA0_BASE, MVEBU_EGIGA1_BASE, |
| 251 | MVEBU_EGIGA2_BASE, MVEBU_EGIGA3_BASE }; |
| 252 | u8 phy_addr[] = CONFIG_PHY_ADDR; |
| 253 | int i; |
| 254 | |
| 255 | /* |
| 256 | * Only Armada XP supports all 4 ethernet interfaces. A38x has |
| 257 | * slightly different base addresses for its 2-3 interfaces. |
| 258 | */ |
| 259 | if (mvebu_soc_family() != MVEBU_SOC_AXP) { |
| 260 | enet_base[1] = MVEBU_EGIGA2_BASE; |
| 261 | enet_base[2] = MVEBU_EGIGA3_BASE; |
| 262 | } |
| 263 | |
| 264 | for (i = 0; i < ARRAY_SIZE(phy_addr); i++) |
| 265 | mvneta_initialize(bis, enet_base[i], i, phy_addr[i]); |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | #endif |
| 270 | |
Stefan Roese | d3e3473 | 2015-06-29 14:58:10 +0200 | [diff] [blame] | 271 | #ifdef CONFIG_MV_SDHCI |
| 272 | int board_mmc_init(bd_t *bis) |
| 273 | { |
| 274 | mv_sdh_init(MVEBU_SDIO_BASE, 0, 0, |
| 275 | SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD); |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | #endif |
| 280 | |
Stefan Roese | bb1c0bd | 2015-06-29 14:58:13 +0200 | [diff] [blame] | 281 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 282 | #define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0 |
| 283 | #define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4 |
| 284 | |
| 285 | #define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4)) |
| 286 | #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4)) |
| 287 | #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4)) |
| 288 | |
| 289 | static void ahci_mvebu_mbus_config(void __iomem *base) |
| 290 | { |
| 291 | const struct mbus_dram_target_info *dram; |
| 292 | int i; |
| 293 | |
| 294 | dram = mvebu_mbus_dram_info(); |
| 295 | |
| 296 | for (i = 0; i < 4; i++) { |
| 297 | writel(0, base + AHCI_WINDOW_CTRL(i)); |
| 298 | writel(0, base + AHCI_WINDOW_BASE(i)); |
| 299 | writel(0, base + AHCI_WINDOW_SIZE(i)); |
| 300 | } |
| 301 | |
| 302 | for (i = 0; i < dram->num_cs; i++) { |
| 303 | const struct mbus_dram_window *cs = dram->cs + i; |
| 304 | |
| 305 | writel((cs->mbus_attr << 8) | |
| 306 | (dram->mbus_dram_target_id << 4) | 1, |
| 307 | base + AHCI_WINDOW_CTRL(i)); |
| 308 | writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i)); |
| 309 | writel(((cs->size - 1) & 0xffff0000), |
| 310 | base + AHCI_WINDOW_SIZE(i)); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | static void ahci_mvebu_regret_option(void __iomem *base) |
| 315 | { |
| 316 | /* |
| 317 | * Enable the regret bit to allow the SATA unit to regret a |
| 318 | * request that didn't receive an acknowlegde and avoid a |
| 319 | * deadlock |
| 320 | */ |
| 321 | writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR); |
| 322 | writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA); |
| 323 | } |
| 324 | |
| 325 | void scsi_init(void) |
| 326 | { |
| 327 | printf("MVEBU SATA INIT\n"); |
| 328 | ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE); |
| 329 | ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE); |
| 330 | ahci_init((void __iomem *)MVEBU_SATA0_BASE); |
| 331 | } |
| 332 | #endif |
| 333 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 334 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 335 | void enable_caches(void) |
| 336 | { |
Stefan Roese | 8aee4d3 | 2015-05-18 16:09:43 +0000 | [diff] [blame] | 337 | struct pl310_regs *const pl310 = |
| 338 | (struct pl310_regs *)CONFIG_SYS_PL310_BASE; |
| 339 | |
| 340 | /* First disable L2 cache - may still be enable from BootROM */ |
| 341 | if (mvebu_soc_family() == MVEBU_SOC_A38X) |
| 342 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
| 343 | |
Stefan Roese | 7a4a5ba | 2015-04-25 06:29:55 +0200 | [diff] [blame] | 344 | /* Avoid problem with e.g. neta ethernet driver */ |
| 345 | invalidate_dcache_all(); |
| 346 | |
Stefan Roese | 93e6bf4 | 2014-10-22 12:13:17 +0200 | [diff] [blame] | 347 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 348 | dcache_enable(); |
| 349 | } |
| 350 | #endif |