2 * Copyright (c) 2014 Google, Inc
4 * Graeme Russ, graeme.russ@gmail.com.
6 * Some portions from coreboot src/mainboard/google/link/romstage.c
7 * and src/cpu/intel/model_206ax/bootblock.c
8 * Copyright (C) 2007-2010 coresystems GmbH
9 * Copyright (C) 2011 Google Inc.
11 * SPDX-License-Identifier: GPL-2.0
20 #include <asm/lapic.h>
25 #include <asm/processor.h>
26 #include <asm/arch/model_206ax.h>
27 #include <asm/arch/microcode.h>
28 #include <asm/arch/pch.h>
29 #include <asm/arch/sandybridge.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 static void enable_port80_on_lpc(struct pci_controller *hose, pci_dev_t dev)
35 /* Enable port 80 POST on LPC */
36 pci_hose_write_config_dword(hose, dev, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
37 clrbits_le32(RCB_REG(GCS), 4);
41 * Enable Prefetching and Caching.
43 static void enable_spi_prefetch(struct pci_controller *hose, pci_dev_t dev)
47 pci_hose_read_config_byte(hose, dev, 0xdc, ®8);
49 reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
50 pci_hose_write_config_byte(hose, dev, 0xdc, reg8);
53 static int set_flex_ratio_to_tdp_nominal(void)
55 msr_t flex_ratio, msr;
58 /* Minimum CPU revision for configurable TDP support */
59 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
62 /* Check for Flex Ratio support */
63 flex_ratio = msr_read(MSR_FLEX_RATIO);
64 if (!(flex_ratio.lo & FLEX_RATIO_EN))
67 /* Check for >0 configurable TDPs */
68 msr = msr_read(MSR_PLATFORM_INFO);
69 if (((msr.hi >> 1) & 3) == 0)
72 /* Use nominal TDP ratio for flex ratio */
73 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
74 nominal_ratio = msr.lo & 0xff;
76 /* See if flex ratio is already set to nominal TDP ratio */
77 if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
80 /* Set flex ratio to nominal TDP ratio */
81 flex_ratio.lo &= ~0xff00;
82 flex_ratio.lo |= nominal_ratio << 8;
83 flex_ratio.lo |= FLEX_RATIO_LOCK;
84 msr_write(MSR_FLEX_RATIO, flex_ratio);
86 /* Set flex ratio in soft reset data register bits 11:6 */
87 clrsetbits_le32(RCB_REG(SOFT_RESET_DATA), 0x3f << 6,
88 (nominal_ratio & 0x3f) << 6);
90 /* Set soft reset control to use register value */
91 setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
93 /* Issue warm reset, will be "CPU only" due to soft reset data */
94 outb(0x0, PORT_RESET);
95 outb(SYS_RST | RST_CPU, PORT_RESET);
102 static void set_spi_speed(void)
106 /* Observe SPI Descriptor Component Section 0 */
107 writel(0x1000, RCB_REG(SPI_DESC_COMP0));
109 /* Extract the1 Write/Erase SPI Frequency from descriptor */
110 fdod = readl(RCB_REG(SPI_FREQ_WR_ERA));
114 /* Set Software Sequence frequency to match */
115 clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod);
118 int arch_cpu_init(void)
120 post_code(POST_CPU_INIT);
122 return x86_cpu_init_f();
125 int arch_cpu_init_dm(void)
127 const void *blob = gd->fdt_blob;
128 struct pci_controller *hose;
129 struct udevice *bus, *dev;
134 ret = uclass_get_device(UCLASS_PCI, 0, &bus);
139 hose = dev_get_uclass_priv(bus);
141 /* TODO(sjg@chromium.org): Get rid of gd->hose */
144 ret = uclass_first_device(UCLASS_LPC, &dev);
148 node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_PCH);
151 ret = lpc_early_init(gd->fdt_blob, node, PCH_LPC_DEV);
155 enable_spi_prefetch(hose, PCH_LPC_DEV);
157 /* This is already done in start.S, but let's do it in C */
158 enable_port80_on_lpc(hose, PCH_LPC_DEV);
163 * We should do as little as possible before the serial console is
164 * up. Perhaps this should move to later. Our next lot of init
165 * happens in print_cpuinfo() when we have a console
167 ret = set_flex_ratio_to_tdp_nominal();
174 static int enable_smbus(void)
179 /* Set the SMBus device statically. */
180 dev = PCI_BDF(0x0, 0x1f, 0x3);
182 /* Check to make sure we've got the right device. */
183 value = x86_pci_read_config16(dev, 0x0);
184 if (value != 0x8086) {
185 printf("SMBus controller not found\n");
189 /* Set SMBus I/O base. */
190 x86_pci_write_config32(dev, SMB_BASE,
191 SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
193 /* Set SMBus enable. */
194 x86_pci_write_config8(dev, HOSTC, HST_EN);
196 /* Set SMBus I/O space enable. */
197 x86_pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
199 /* Disable interrupt generation. */
200 outb(0, SMBUS_IO_BASE + SMBHSTCTL);
202 /* Clear any lingering errors, so transactions can run. */
203 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
204 debug("SMBus controller enabled\n");
209 #define PCH_EHCI0_TEMP_BAR0 0xe8000000
210 #define PCH_EHCI1_TEMP_BAR0 0xe8000400
211 #define PCH_XHCI_TEMP_BAR0 0xe8001000
214 * Setup USB controller MMIO BAR to prevent the reference code from
215 * resetting the controller.
217 * The BAR will be re-assigned during device enumeration so these are only
220 * This is used to speed up the resume path.
222 static void enable_usb_bar(void)
224 pci_dev_t usb0 = PCH_EHCI1_DEV;
225 pci_dev_t usb1 = PCH_EHCI2_DEV;
226 pci_dev_t usb3 = PCH_XHCI_DEV;
229 /* USB Controller 1 */
230 x86_pci_write_config32(usb0, PCI_BASE_ADDRESS_0,
231 PCH_EHCI0_TEMP_BAR0);
232 cmd = x86_pci_read_config32(usb0, PCI_COMMAND);
233 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
234 x86_pci_write_config32(usb0, PCI_COMMAND, cmd);
236 /* USB Controller 1 */
237 x86_pci_write_config32(usb1, PCI_BASE_ADDRESS_0,
238 PCH_EHCI1_TEMP_BAR0);
239 cmd = x86_pci_read_config32(usb1, PCI_COMMAND);
240 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
241 x86_pci_write_config32(usb1, PCI_COMMAND, cmd);
243 /* USB3 Controller */
244 x86_pci_write_config32(usb3, PCI_BASE_ADDRESS_0,
246 cmd = x86_pci_read_config32(usb3, PCI_COMMAND);
247 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
248 x86_pci_write_config32(usb3, PCI_COMMAND, cmd);
251 static int report_bist_failure(void)
253 if (gd->arch.bist != 0) {
254 post_code(POST_BIST_FAILURE);
255 printf("BIST failed: %08x\n", gd->arch.bist);
262 int print_cpuinfo(void)
264 enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
265 char processor_name[CPU_MAX_NAME_LEN];
271 /* Halt if there was a built in self test failure */
272 ret = report_bist_failure();
278 ret = microcode_update_intel();
282 /* Enable upper 128bytes of CMOS */
283 writel(1 << 2, RCB_REG(RC));
285 /* TODO: cmos_post_init() */
286 if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
287 debug("soft reset detected\n");
288 boot_mode = PEI_BOOT_SOFT_RESET;
290 /* System is not happy after keyboard reset... */
291 debug("Issuing CF9 warm reset\n");
295 /* Early chipset init required before RAM init can work */
296 sandybridge_early_init(SANDYBRIDGE_MOBILE);
298 /* Check PM1_STS[15] to see if we are waking from Sx */
299 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
301 /* Read PM1_CNT[12:10] to determine which Sx state */
302 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
304 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
305 debug("Resume from S3 detected, but disabled.\n");
308 * TODO: An indication of life might be possible here (e.g.
312 post_code(POST_EARLY_INIT);
314 /* Enable SPD ROMs and DDR-III DRAM */
315 ret = enable_smbus();
319 /* Prepare USB controller early in S3 resume */
320 if (boot_mode == PEI_BOOT_RESUME)
323 gd->arch.pei_boot_mode = boot_mode;
325 /* TODO: Move this to the board or driver */
326 x86_pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE | 1);
327 x86_pci_write_config32(PCH_LPC_DEV, GPIO_CNTL, 0x10);
329 /* Print processor name */
330 name = cpu_get_name(processor_name);
331 printf("CPU: %s\n", name);
333 post_code(POST_CPU_INFO);
338 void board_debug_uart_init(void)
340 /* This enables the debug UART */
341 pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN,