]> git.sur5r.net Git - u-boot/blobdiff - arch/x86/cpu/ivybridge/cpu.c
Merge git://git.denx.de/u-boot-net
[u-boot] / arch / x86 / cpu / ivybridge / cpu.c
index 0aca2f02a7f23c69ca903908b53f6e09b6d74c3f..343bfb4e98e264a7e5fa91f7e9f58c89427f73f3 100644 (file)
@@ -4,6 +4,7 @@
  * Graeme Russ, graeme.russ@gmail.com.
  *
  * Some portions from coreboot src/mainboard/google/link/romstage.c
+ * and src/cpu/intel/model_206ax/bootblock.c
  * Copyright (C) 2007-2010 coresystems GmbH
  * Copyright (C) 2011 Google Inc.
  *
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <asm/cpu.h>
 #include <asm/io.h>
+#include <asm/lapic.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
 #include <asm/pci.h>
@@ -23,6 +26,7 @@
 #include <asm/arch/model_206ax.h>
 #include <asm/arch/microcode.h>
 #include <asm/arch/pch.h>
+#include <asm/arch/sandybridge.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -46,27 +50,6 @@ static void enable_spi_prefetch(struct pci_controller *hose, pci_dev_t dev)
        pci_hose_write_config_byte(hose, dev, 0xdc, reg8);
 }
 
-static void set_var_mtrr(
-       unsigned reg, unsigned base, unsigned size, unsigned type)
-
-{
-       /* Bit Bit 32-35 of MTRRphysMask should be set to 1 */
-       /* FIXME: It only support 4G less range */
-       wrmsr(MTRRphysBase_MSR(reg), base | type, 0);
-       wrmsr(MTRRphysMask_MSR(reg), ~(size - 1) | MTRRphysMaskValid,
-             (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1);
-}
-
-static void enable_rom_caching(void)
-{
-       disable_caches();
-       set_var_mtrr(1, 0xffc00000, 4 << 20, MTRR_TYPE_WRPROT);
-       enable_caches();
-
-       /* Enable Variable MTRRs */
-       wrmsr(MTRRdefType_MSR, 0x800, 0);
-}
-
 static int set_flex_ratio_to_tdp_nominal(void)
 {
        msr_t flex_ratio, msr;
@@ -109,7 +92,7 @@ static int set_flex_ratio_to_tdp_nominal(void)
 
        /* Issue warm reset, will be "CPU only" due to soft reset data */
        outb(0x0, PORT_RESET);
-       outb(0x6, PORT_RESET);
+       outb(SYS_RST | RST_CPU, PORT_RESET);
        cpu_hlt();
 
        /* Not reached */
@@ -133,24 +116,32 @@ static void set_spi_speed(void)
 }
 
 int arch_cpu_init(void)
+{
+       post_code(POST_CPU_INIT);
+
+       return x86_cpu_init_f();
+}
+
+int arch_cpu_init_dm(void)
 {
        const void *blob = gd->fdt_blob;
        struct pci_controller *hose;
+       struct udevice *bus;
        int node;
        int ret;
 
-       post_code(POST_CPU_INIT);
-       timer_set_base(rdtsc());
-
-       ret = x86_cpu_init_f();
+       post_code(0x70);
+       ret = uclass_get_device(UCLASS_PCI, 0, &bus);
+       post_code(0x71);
        if (ret)
                return ret;
+       post_code(0x72);
+       hose = dev_get_uclass_priv(bus);
 
-       ret = pci_early_init_hose(&hose);
-       if (ret)
-               return ret;
+       /* TODO(sjg@chromium.org): Get rid of gd->hose */
+       gd->hose = hose;
 
-       node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_LPC);
+       node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_PCH);
        if (node < 0)
                return -ENOENT;
        ret = lpc_early_init(gd->fdt_blob, node, PCH_LPC_DEV);
@@ -162,10 +153,6 @@ int arch_cpu_init(void)
        /* This is already done in start.S, but let's do it in C */
        enable_port80_on_lpc(hose, PCH_LPC_DEV);
 
-       /* already done in car.S */
-       if (false)
-               enable_rom_caching();
-
        set_spi_speed();
 
        /*
@@ -180,9 +167,87 @@ int arch_cpu_init(void)
        return 0;
 }
 
+static int enable_smbus(void)
+{
+       pci_dev_t dev;
+       uint16_t value;
+
+       /* Set the SMBus device statically. */
+       dev = PCI_BDF(0x0, 0x1f, 0x3);
+
+       /* Check to make sure we've got the right device. */
+       value = x86_pci_read_config16(dev, 0x0);
+       if (value != 0x8086) {
+               printf("SMBus controller not found\n");
+               return -ENOSYS;
+       }
+
+       /* Set SMBus I/O base. */
+       x86_pci_write_config32(dev, SMB_BASE,
+                              SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
+
+       /* Set SMBus enable. */
+       x86_pci_write_config8(dev, HOSTC, HST_EN);
+
+       /* Set SMBus I/O space enable. */
+       x86_pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
+
+       /* Disable interrupt generation. */
+       outb(0, SMBUS_IO_BASE + SMBHSTCTL);
+
+       /* Clear any lingering errors, so transactions can run. */
+       outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
+       debug("SMBus controller enabled\n");
+
+       return 0;
+}
+
+#define PCH_EHCI0_TEMP_BAR0 0xe8000000
+#define PCH_EHCI1_TEMP_BAR0 0xe8000400
+#define PCH_XHCI_TEMP_BAR0  0xe8001000
+
+/*
+ * Setup USB controller MMIO BAR to prevent the reference code from
+ * resetting the controller.
+ *
+ * The BAR will be re-assigned during device enumeration so these are only
+ * temporary.
+ *
+ * This is used to speed up the resume path.
+ */
+static void enable_usb_bar(void)
+{
+       pci_dev_t usb0 = PCH_EHCI1_DEV;
+       pci_dev_t usb1 = PCH_EHCI2_DEV;
+       pci_dev_t usb3 = PCH_XHCI_DEV;
+       u32 cmd;
+
+       /* USB Controller 1 */
+       x86_pci_write_config32(usb0, PCI_BASE_ADDRESS_0,
+                              PCH_EHCI0_TEMP_BAR0);
+       cmd = x86_pci_read_config32(usb0, PCI_COMMAND);
+       cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
+       x86_pci_write_config32(usb0, PCI_COMMAND, cmd);
+
+       /* USB Controller 1 */
+       x86_pci_write_config32(usb1, PCI_BASE_ADDRESS_0,
+                              PCH_EHCI1_TEMP_BAR0);
+       cmd = x86_pci_read_config32(usb1, PCI_COMMAND);
+       cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
+       x86_pci_write_config32(usb1, PCI_COMMAND, cmd);
+
+       /* USB3 Controller */
+       x86_pci_write_config32(usb3, PCI_BASE_ADDRESS_0,
+                              PCH_XHCI_TEMP_BAR0);
+       cmd = x86_pci_read_config32(usb3, PCI_COMMAND);
+       cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
+       x86_pci_write_config32(usb3, PCI_COMMAND, cmd);
+}
+
 static int report_bist_failure(void)
 {
        if (gd->arch.bist != 0) {
+               post_code(POST_BIST_FAILURE);
                printf("BIST failed: %08x\n", gd->arch.bist);
                return -EFAULT;
        }
@@ -192,8 +257,11 @@ static int report_bist_failure(void)
 
 int print_cpuinfo(void)
 {
+       enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
        char processor_name[CPU_MAX_NAME_LEN];
        const char *name;
+       uint32_t pm1_cnt;
+       uint16_t pm1_sts;
        int ret;
 
        /* Halt if there was a built in self test failure */
@@ -201,13 +269,71 @@ int print_cpuinfo(void)
        if (ret)
                return ret;
 
+       enable_lapic();
+
        ret = microcode_update_intel();
-       if (ret && ret != -ENOENT && ret != -EEXIST)
+       if (ret)
+               return ret;
+
+       /* Enable upper 128bytes of CMOS */
+       writel(1 << 2, RCB_REG(RC));
+
+       /* TODO: cmos_post_init() */
+       if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
+               debug("soft reset detected\n");
+               boot_mode = PEI_BOOT_SOFT_RESET;
+
+               /* System is not happy after keyboard reset... */
+               debug("Issuing CF9 warm reset\n");
+               reset_cpu(0);
+       }
+
+       /* Early chipset init required before RAM init can work */
+       sandybridge_early_init(SANDYBRIDGE_MOBILE);
+
+       /* Check PM1_STS[15] to see if we are waking from Sx */
+       pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
+
+       /* Read PM1_CNT[12:10] to determine which Sx state */
+       pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
+
+       if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
+               debug("Resume from S3 detected, but disabled.\n");
+       } else {
+               /*
+                * TODO: An indication of life might be possible here (e.g.
+                * keyboard light)
+                */
+       }
+       post_code(POST_EARLY_INIT);
+
+       /* Enable SPD ROMs and DDR-III DRAM */
+       ret = enable_smbus();
+       if (ret)
                return ret;
 
+       /* Prepare USB controller early in S3 resume */
+       if (boot_mode == PEI_BOOT_RESUME)
+               enable_usb_bar();
+
+       gd->arch.pei_boot_mode = boot_mode;
+
+       /* TODO: Move this to the board or driver */
+       x86_pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE | 1);
+       x86_pci_write_config32(PCH_LPC_DEV, GPIO_CNTL, 0x10);
+
        /* Print processor name */
        name = cpu_get_name(processor_name);
        printf("CPU:   %s\n", name);
 
+       post_code(POST_CPU_INFO);
+
        return 0;
 }
+
+void board_debug_uart_init(void)
+{
+       /* This enables the debug UART */
+       pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN,
+                            PCI_SIZE_16);
+}