uboot/arch/arm/mach-mvebu/cpu.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
   4 */
   5
   6#include <common.h>
   7#include <ahci.h>
   8#include <cpu_func.h>
   9#include <init.h>
  10#include <linux/bitops.h>
  11#include <linux/delay.h>
  12#include <linux/mbus.h>
  13#include <asm/io.h>
  14#include <asm/pl310.h>
  15#include <asm/arch/cpu.h>
  16#include <asm/arch/soc.h>
  17#include <asm/spl.h>
  18#include <sdhci.h>
  19
  20#define DDR_BASE_CS_OFF(n)      (0x0000 + ((n) << 3))
  21#define DDR_SIZE_CS_OFF(n)      (0x0004 + ((n) << 3))
  22
  23static struct mbus_win windows[] = {
  24        /* SPI */
  25        { MBUS_SPI_BASE, MBUS_SPI_SIZE,
  26          CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
  27
  28        /* NOR */
  29        { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
  30          CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
  31
  32#ifdef CONFIG_ARMADA_MSYS
  33        /* DFX */
  34        { MBUS_DFX_BASE, MBUS_DFX_SIZE, CPU_TARGET_DFX, 0 },
  35#endif
  36};
  37
  38void lowlevel_init(void)
  39{
  40        /*
  41         * Dummy implementation, we only need LOWLEVEL_INIT
  42         * on Armada to configure CP15 in start.S / cpu_init_cp15()
  43         */
  44}
  45
  46void reset_cpu(void)
  47{
  48        struct mvebu_system_registers *reg =
  49                (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
  50
  51        writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
  52        writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
  53        while (1)
  54                ;
  55}
  56
  57int mvebu_soc_family(void)
  58{
  59        u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  60
  61        switch (devid) {
  62        case SOC_MV78230_ID:
  63        case SOC_MV78260_ID:
  64        case SOC_MV78460_ID:
  65                return MVEBU_SOC_AXP;
  66
  67        case SOC_88F6720_ID:
  68                return MVEBU_SOC_A375;
  69
  70        case SOC_88F6810_ID:
  71        case SOC_88F6820_ID:
  72        case SOC_88F6828_ID:
  73                return MVEBU_SOC_A38X;
  74
  75        case SOC_98DX3236_ID:
  76        case SOC_98DX3336_ID:
  77        case SOC_98DX4251_ID:
  78                return MVEBU_SOC_MSYS;
  79        }
  80
  81        return MVEBU_SOC_UNKNOWN;
  82}
  83
  84u32 get_boot_device(void)
  85{
  86        u32 val;
  87        u32 boot_device;
  88
  89        /*
  90         * First check, if UART boot-mode is active. This can only
  91         * be done, via the bootrom error register. Here the
  92         * MSB marks if the UART mode is active.
  93         */
  94        val = readl(BOOTROM_ERR_REG);
  95        boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
  96        debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
  97        if (boot_device == BOOTROM_ERR_MODE_UART)
  98                return BOOT_DEVICE_UART;
  99
 100#ifdef CONFIG_ARMADA_38X
 101        /*
 102         * If the bootrom error code contains any other than zeros it's an
 103         * error condition and the bootROM has fallen back to UART boot
 104         */
 105        boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
 106        if (boot_device)
 107                return BOOT_DEVICE_UART;
 108#endif
 109
 110        /*
 111         * Now check the SAR register for the strapped boot-device
 112         */
 113        val = readl(CONFIG_SAR_REG);    /* SAR - Sample At Reset */
 114        boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
 115        debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
 116        switch (boot_device) {
 117#ifdef BOOT_FROM_NAND
 118        case BOOT_FROM_NAND:
 119                return BOOT_DEVICE_NAND;
 120#endif
 121#ifdef BOOT_FROM_MMC
 122        case BOOT_FROM_MMC:
 123        case BOOT_FROM_MMC_ALT:
 124                return BOOT_DEVICE_MMC1;
 125#endif
 126        case BOOT_FROM_UART:
 127#ifdef BOOT_FROM_UART_ALT
 128        case BOOT_FROM_UART_ALT:
 129#endif
 130                return BOOT_DEVICE_UART;
 131#ifdef BOOT_FROM_SATA
 132        case BOOT_FROM_SATA:
 133        case BOOT_FROM_SATA_ALT:
 134                return BOOT_DEVICE_SATA;
 135#endif
 136        case BOOT_FROM_SPI:
 137                return BOOT_DEVICE_SPI;
 138        default:
 139                return BOOT_DEVICE_BOOTROM;
 140        };
 141}
 142
 143#if defined(CONFIG_DISPLAY_CPUINFO)
 144
 145#if defined(CONFIG_ARMADA_375)
 146/* SAR frequency values for Armada 375 */
 147static const struct sar_freq_modes sar_freq_tab[] = {
 148        {  0,  0x0,  266,  133,  266 },
 149        {  1,  0x0,  333,  167,  167 },
 150        {  2,  0x0,  333,  167,  222 },
 151        {  3,  0x0,  333,  167,  333 },
 152        {  4,  0x0,  400,  200,  200 },
 153        {  5,  0x0,  400,  200,  267 },
 154        {  6,  0x0,  400,  200,  400 },
 155        {  7,  0x0,  500,  250,  250 },
 156        {  8,  0x0,  500,  250,  334 },
 157        {  9,  0x0,  500,  250,  500 },
 158        { 10,  0x0,  533,  267,  267 },
 159        { 11,  0x0,  533,  267,  356 },
 160        { 12,  0x0,  533,  267,  533 },
 161        { 13,  0x0,  600,  300,  300 },
 162        { 14,  0x0,  600,  300,  400 },
 163        { 15,  0x0,  600,  300,  600 },
 164        { 16,  0x0,  666,  333,  333 },
 165        { 17,  0x0,  666,  333,  444 },
 166        { 18,  0x0,  666,  333,  666 },
 167        { 19,  0x0,  800,  400,  267 },
 168        { 20,  0x0,  800,  400,  400 },
 169        { 21,  0x0,  800,  400,  534 },
 170        { 22,  0x0,  900,  450,  300 },
 171        { 23,  0x0,  900,  450,  450 },
 172        { 24,  0x0,  900,  450,  600 },
 173        { 25,  0x0, 1000,  500,  500 },
 174        { 26,  0x0, 1000,  500,  667 },
 175        { 27,  0x0, 1000,  333,  500 },
 176        { 28,  0x0,  400,  400,  400 },
 177        { 29,  0x0, 1100,  550,  550 },
 178        { 0xff, 0xff,    0,   0,   0 }  /* 0xff marks end of array */
 179};
 180#elif defined(CONFIG_ARMADA_38X)
 181/* SAR frequency values for Armada 38x */
 182static const struct sar_freq_modes sar_freq_tab[] = {
 183        {  0x0,  0x0,  666,  333, 333 },
 184        {  0x2,  0x0,  800,  400, 400 },
 185        {  0x4,  0x0, 1066,  533, 533 },
 186        {  0x6,  0x0, 1200,  600, 600 },
 187        {  0x8,  0x0, 1332,  666, 666 },
 188        {  0xc,  0x0, 1600,  800, 800 },
 189        { 0x10,  0x0, 1866,  933, 933 },
 190        { 0x13,  0x0, 2000, 1000, 933 },
 191        { 0xff, 0xff,    0,    0,   0 } /* 0xff marks end of array */
 192};
 193#elif defined(CONFIG_ARMADA_MSYS)
 194static const struct sar_freq_modes sar_freq_tab[] = {
 195        {  0x0, 0x0,  400,  400, 400 },
 196        {  0x2, 0x0,  667,  333, 667 },
 197        {  0x3, 0x0,  800,  400, 800 },
 198        {  0x5, 0x0,  800,  400, 800 },
 199        { 0xff, 0xff,    0,   0,   0 }  /* 0xff marks end of array */
 200};
 201#else
 202/* SAR frequency values for Armada XP */
 203static const struct sar_freq_modes sar_freq_tab[] = {
 204        {  0xa,  0x5,  800, 400, 400 },
 205        {  0x1,  0x5, 1066, 533, 533 },
 206        {  0x2,  0x5, 1200, 600, 600 },
 207        {  0x2,  0x9, 1200, 600, 400 },
 208        {  0x3,  0x5, 1333, 667, 667 },
 209        {  0x4,  0x5, 1500, 750, 750 },
 210        {  0x4,  0x9, 1500, 750, 500 },
 211        {  0xb,  0x9, 1600, 800, 533 },
 212        {  0xb,  0xa, 1600, 800, 640 },
 213        {  0xb,  0x5, 1600, 800, 800 },
 214        { 0xff, 0xff,    0,   0,   0 }  /* 0xff marks end of array */
 215};
 216#endif
 217
 218void get_sar_freq(struct sar_freq_modes *sar_freq)
 219{
 220        u32 val;
 221        u32 freq;
 222        int i;
 223
 224#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
 225        val = readl(CONFIG_SAR2_REG);   /* SAR - Sample At Reset */
 226#else
 227        val = readl(CONFIG_SAR_REG);    /* SAR - Sample At Reset */
 228#endif
 229        freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
 230#if defined(SAR2_CPU_FREQ_MASK)
 231        /*
 232         * Shift CPU0 clock frequency select bit from SAR2 register
 233         * into correct position
 234         */
 235        freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
 236                 >> SAR2_CPU_FREQ_OFFS) << 3;
 237#endif
 238        for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
 239                if (sar_freq_tab[i].val == freq) {
 240#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
 241                        *sar_freq = sar_freq_tab[i];
 242                        return;
 243#else
 244                        int k;
 245                        u8 ffc;
 246
 247                        ffc = (val & SAR_FFC_FREQ_MASK) >>
 248                                SAR_FFC_FREQ_OFFS;
 249                        for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
 250                                if (sar_freq_tab[k].ffc == ffc) {
 251                                        *sar_freq = sar_freq_tab[k];
 252                                        return;
 253                                }
 254                        }
 255                        i = k;
 256#endif
 257                }
 258        }
 259
 260        /* SAR value not found, return 0 for frequencies */
 261        *sar_freq = sar_freq_tab[i - 1];
 262}
 263
 264int print_cpuinfo(void)
 265{
 266        u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
 267        u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
 268        struct sar_freq_modes sar_freq;
 269
 270        puts("SoC:   ");
 271
 272        switch (devid) {
 273        case SOC_MV78230_ID:
 274                puts("MV78230-");
 275                break;
 276        case SOC_MV78260_ID:
 277                puts("MV78260-");
 278                break;
 279        case SOC_MV78460_ID:
 280                puts("MV78460-");
 281                break;
 282        case SOC_88F6720_ID:
 283                puts("MV88F6720-");
 284                break;
 285        case SOC_88F6810_ID:
 286                puts("MV88F6810-");
 287                break;
 288        case SOC_88F6820_ID:
 289                puts("MV88F6820-");
 290                break;
 291        case SOC_88F6828_ID:
 292                puts("MV88F6828-");
 293                break;
 294        case SOC_98DX3236_ID:
 295                puts("98DX3236-");
 296                break;
 297        case SOC_98DX3336_ID:
 298                puts("98DX3336-");
 299                break;
 300        case SOC_98DX4251_ID:
 301                puts("98DX4251-");
 302                break;
 303        default:
 304                puts("Unknown-");
 305                break;
 306        }
 307
 308        if (mvebu_soc_family() == MVEBU_SOC_AXP) {
 309                switch (revid) {
 310                case 1:
 311                        puts("A0");
 312                        break;
 313                case 2:
 314                        puts("B0");
 315                        break;
 316                default:
 317                        printf("?? (%x)", revid);
 318                        break;
 319                }
 320        }
 321
 322        if (mvebu_soc_family() == MVEBU_SOC_A375) {
 323                switch (revid) {
 324                case MV_88F67XX_A0_ID:
 325                        puts("A0");
 326                        break;
 327                default:
 328                        printf("?? (%x)", revid);
 329                        break;
 330                }
 331        }
 332
 333        if (mvebu_soc_family() == MVEBU_SOC_A38X) {
 334                switch (revid) {
 335                case MV_88F68XX_Z1_ID:
 336                        puts("Z1");
 337                        break;
 338                case MV_88F68XX_A0_ID:
 339                        puts("A0");
 340                        break;
 341                case MV_88F68XX_B0_ID:
 342                        puts("B0");
 343                        break;
 344                default:
 345                        printf("?? (%x)", revid);
 346                        break;
 347                }
 348        }
 349
 350        if (mvebu_soc_family() == MVEBU_SOC_MSYS) {
 351                switch (revid) {
 352                case 3:
 353                        puts("A0");
 354                        break;
 355                case 4:
 356                        puts("A1");
 357                        break;
 358                default:
 359                        printf("?? (%x)", revid);
 360                        break;
 361                }
 362        }
 363
 364        get_sar_freq(&sar_freq);
 365        printf(" at %d MHz\n", sar_freq.p_clk);
 366
 367        return 0;
 368}
 369#endif /* CONFIG_DISPLAY_CPUINFO */
 370
 371/*
 372 * This function initialize Controller DRAM Fastpath windows.
 373 * It takes the CS size information from the 0x1500 scratch registers
 374 * and sets the correct windows sizes and base addresses accordingly.
 375 *
 376 * These values are set in the scratch registers by the Marvell
 377 * DDR3 training code, which is executed by the SPL before the
 378 * main payload (U-Boot) is executed.
 379 */
 380static void update_sdram_window_sizes(void)
 381{
 382        u64 base = 0;
 383        u32 size, temp;
 384        int i;
 385
 386        for (i = 0; i < SDRAM_MAX_CS; i++) {
 387                size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
 388                if (size != 0) {
 389                        size |= ~(SDRAM_ADDR_MASK);
 390
 391                        /* Set Base Address */
 392                        temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
 393                        writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
 394
 395                        /*
 396                         * Check if out of max window size and resize
 397                         * the window
 398                         */
 399                        temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
 400                                ~(SDRAM_ADDR_MASK)) | 1;
 401                        temp |= (size & SDRAM_ADDR_MASK);
 402                        writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
 403
 404                        base += ((u64)size + 1);
 405                } else {
 406                        /*
 407                         * Disable window if not used, otherwise this
 408                         * leads to overlapping enabled windows with
 409                         * pretty strange results
 410                         */
 411                        clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
 412                }
 413        }
 414}
 415
 416#ifdef CONFIG_ARCH_CPU_INIT
 417#define MV_USB_PHY_BASE                 (MVEBU_AXP_USB_BASE + 0x800)
 418#define MV_USB_PHY_PLL_REG(reg)         (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
 419#define MV_USB_X3_BASE(addr)            (MVEBU_AXP_USB_BASE | BIT(11) | \
 420                                         (((addr) & 0xF) << 6))
 421#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) |    \
 422                                         (((reg) & 0xF) << 2))
 423
 424static void setup_usb_phys(void)
 425{
 426        int dev;
 427
 428        /*
 429         * USB PLL init
 430         */
 431
 432        /* Setup PLL frequency */
 433        /* USB REF frequency = 25 MHz */
 434        clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
 435
 436        /* Power up PLL and PHY channel */
 437        setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
 438
 439        /* Assert VCOCAL_START */
 440        setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
 441
 442        mdelay(1);
 443
 444        /*
 445         * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
 446         */
 447
 448        for (dev = 0; dev < 3; dev++) {
 449                setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
 450
 451                /* Assert REG_RCAL_START in channel REG 1 */
 452                setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
 453                udelay(40);
 454                clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
 455        }
 456}
 457
 458/*
 459 * This function is not called from the SPL U-Boot version
 460 */
 461int arch_cpu_init(void)
 462{
 463        struct pl310_regs *const pl310 =
 464                (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
 465
 466        if (mvebu_soc_family() == MVEBU_SOC_A38X) {
 467                /*
 468                 * To fully release / unlock this area from cache, we need
 469                 * to flush all caches and disable the L2 cache.
 470                 */
 471                icache_disable();
 472                dcache_disable();
 473                clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
 474        }
 475
 476        /*
 477         * We need to call mvebu_mbus_probe() before calling
 478         * update_sdram_window_sizes() as it disables all previously
 479         * configured mbus windows and then configures them as
 480         * required for U-Boot. Calling update_sdram_window_sizes()
 481         * without this configuration will not work, as the internal
 482         * registers can't be accessed reliably because of potenial
 483         * double mapping.
 484         * After updating the SDRAM access windows we need to call
 485         * mvebu_mbus_probe() again, as this now correctly configures
 486         * the SDRAM areas that are later used by the MVEBU drivers
 487         * (e.g. USB, NETA).
 488         */
 489
 490        /*
 491         * First disable all windows
 492         */
 493        mvebu_mbus_probe(NULL, 0);
 494
 495        if (mvebu_soc_family() == MVEBU_SOC_AXP) {
 496                /*
 497                 * Now the SDRAM access windows can be reconfigured using
 498                 * the information in the SDRAM scratch pad registers
 499                 */
 500                update_sdram_window_sizes();
 501        }
 502
 503        /*
 504         * Finally the mbus windows can be configured with the
 505         * updated SDRAM sizes
 506         */
 507        mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
 508
 509        if (mvebu_soc_family() == MVEBU_SOC_AXP) {
 510                /* Enable GBE0, GBE1, LCD and NFC PUP */
 511                clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
 512                                GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
 513                                NAND_PUP_EN | SPI_PUP_EN);
 514
 515                /* Configure USB PLL and PHYs on AXP */
 516                setup_usb_phys();
 517        }
 518
 519        /* Enable NAND and NAND arbiter */
 520        clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
 521
 522        /* Disable MBUS error propagation */
 523        clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
 524
 525        return 0;
 526}
 527#endif /* CONFIG_ARCH_CPU_INIT */
 528
 529u32 mvebu_get_nand_clock(void)
 530{
 531        u32 reg;
 532
 533        if (mvebu_soc_family() == MVEBU_SOC_A38X)
 534                reg = MVEBU_DFX_DIV_CLK_CTRL(1);
 535        else if (mvebu_soc_family() == MVEBU_SOC_MSYS)
 536                reg = MVEBU_DFX_DIV_CLK_CTRL(8);
 537        else
 538                reg = MVEBU_CORE_DIV_CLK_CTRL(1);
 539
 540        return CONFIG_SYS_MVEBU_PLL_CLOCK /
 541                ((readl(reg) &
 542                  NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
 543}
 544
 545/*
 546 * SOC specific misc init
 547 */
 548#if defined(CONFIG_ARCH_MISC_INIT)
 549int arch_misc_init(void)
 550{
 551        /* Nothing yet, perhaps we need something here later */
 552        return 0;
 553}
 554#endif /* CONFIG_ARCH_MISC_INIT */
 555
 556#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
 557int board_mmc_init(struct bd_info *bis)
 558{
 559        mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
 560                    SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
 561
 562        return 0;
 563}
 564#endif
 565
 566#define AHCI_VENDOR_SPECIFIC_0_ADDR     0xa0
 567#define AHCI_VENDOR_SPECIFIC_0_DATA     0xa4
 568
 569#define AHCI_WINDOW_CTRL(win)           (0x60 + ((win) << 4))
 570#define AHCI_WINDOW_BASE(win)           (0x64 + ((win) << 4))
 571#define AHCI_WINDOW_SIZE(win)           (0x68 + ((win) << 4))
 572
 573static void ahci_mvebu_mbus_config(void __iomem *base)
 574{
 575        const struct mbus_dram_target_info *dram;
 576        int i;
 577
 578        /* mbus is not initialized in SPL; keep the ROM settings */
 579        if (IS_ENABLED(CONFIG_SPL_BUILD))
 580                return;
 581
 582        dram = mvebu_mbus_dram_info();
 583
 584        for (i = 0; i < 4; i++) {
 585                writel(0, base + AHCI_WINDOW_CTRL(i));
 586                writel(0, base + AHCI_WINDOW_BASE(i));
 587                writel(0, base + AHCI_WINDOW_SIZE(i));
 588        }
 589
 590        for (i = 0; i < dram->num_cs; i++) {
 591                const struct mbus_dram_window *cs = dram->cs + i;
 592
 593                writel((cs->mbus_attr << 8) |
 594                       (dram->mbus_dram_target_id << 4) | 1,
 595                       base + AHCI_WINDOW_CTRL(i));
 596                writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
 597                writel(((cs->size - 1) & 0xffff0000),
 598                       base + AHCI_WINDOW_SIZE(i));
 599        }
 600}
 601
 602static void ahci_mvebu_regret_option(void __iomem *base)
 603{
 604        /*
 605         * Enable the regret bit to allow the SATA unit to regret a
 606         * request that didn't receive an acknowlegde and avoid a
 607         * deadlock
 608         */
 609        writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
 610        writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
 611}
 612
 613int board_ahci_enable(void)
 614{
 615        ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
 616        ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
 617
 618        return 0;
 619}
 620
 621#ifdef CONFIG_SCSI_AHCI_PLAT
 622void scsi_init(void)
 623{
 624        printf("MVEBU SATA INIT\n");
 625        board_ahci_enable();
 626        ahci_init((void __iomem *)MVEBU_SATA0_BASE);
 627}
 628#endif
 629
 630#ifdef CONFIG_USB_XHCI_MVEBU
 631#define USB3_MAX_WINDOWS        4
 632#define USB3_WIN_CTRL(w)        (0x0 + ((w) * 8))
 633#define USB3_WIN_BASE(w)        (0x4 + ((w) * 8))
 634
 635static void xhci_mvebu_mbus_config(void __iomem *base,
 636                        const struct mbus_dram_target_info *dram)
 637{
 638        int i;
 639
 640        for (i = 0; i < USB3_MAX_WINDOWS; i++) {
 641                writel(0, base + USB3_WIN_CTRL(i));
 642                writel(0, base + USB3_WIN_BASE(i));
 643        }
 644
 645        for (i = 0; i < dram->num_cs; i++) {
 646                const struct mbus_dram_window *cs = dram->cs + i;
 647
 648                /* Write size, attributes and target id to control register */
 649                writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
 650                        (dram->mbus_dram_target_id << 4) | 1,
 651                        base + USB3_WIN_CTRL(i));
 652
 653                /* Write base address to base register */
 654                writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
 655        }
 656}
 657
 658int board_xhci_enable(fdt_addr_t base)
 659{
 660        const struct mbus_dram_target_info *dram;
 661
 662        printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
 663
 664        dram = mvebu_mbus_dram_info();
 665        xhci_mvebu_mbus_config((void __iomem *)base, dram);
 666
 667        return 0;
 668}
 669#endif
 670
 671void enable_caches(void)
 672{
 673        /* Avoid problem with e.g. neta ethernet driver */
 674        invalidate_dcache_all();
 675
 676        /*
 677         * Armada 375 still has some problems with d-cache enabled in the
 678         * ethernet driver (mvpp2). So lets keep the d-cache disabled
 679         * until this is solved.
 680         */
 681        if (mvebu_soc_family() != MVEBU_SOC_A375) {
 682                /* Enable D-cache. I-cache is already enabled in start.S */
 683                dcache_enable();
 684        }
 685}
 686
 687void v7_outer_cache_enable(void)
 688{
 689        if (mvebu_soc_family() == MVEBU_SOC_AXP) {
 690                struct pl310_regs *const pl310 =
 691                        (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
 692                u32 u;
 693
 694                /* The L2 cache is already disabled at this point */
 695
 696                /*
 697                 * For Aurora cache in no outer mode, enable via the CP15
 698                 * coprocessor broadcasting of cache commands to L2.
 699                 */
 700                asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
 701                u |= BIT(8);            /* Set the FW bit */
 702                asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
 703
 704                isb();
 705
 706                /* Enable the L2 cache */
 707                setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
 708        }
 709}
 710
 711void v7_outer_cache_disable(void)
 712{
 713        struct pl310_regs *const pl310 =
 714                (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
 715
 716        clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
 717}
 718