Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Google, Inc |
| 3 | * (C) Copyright 2008 |
| 4 | * Graeme Russ, graeme.russ@gmail.com. |
| 5 | * |
| 6 | * Some portions from coreboot src/mainboard/google/link/romstage.c |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 7 | * and src/cpu/intel/model_206ax/bootblock.c |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 8 | * Copyright (C) 2007-2010 coresystems GmbH |
| 9 | * Copyright (C) 2011 Google Inc. |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0 |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 16 | #include <errno.h> |
| 17 | #include <fdtdec.h> |
Simon Glass | a7b1d95 | 2016-01-17 16:11:13 -0700 | [diff] [blame] | 18 | #include <pch.h> |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 19 | #include <asm/cpu.h> |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 20 | #include <asm/cpu_common.h> |
Simon Glass | 5535730 | 2016-03-11 22:06:55 -0700 | [diff] [blame] | 21 | #include <asm/intel_regs.h> |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 22 | #include <asm/io.h> |
Simon Glass | d22f5c9 | 2014-11-12 22:42:27 -0700 | [diff] [blame] | 23 | #include <asm/lapic.h> |
Simon Glass | 2df6188 | 2016-03-11 22:06:54 -0700 | [diff] [blame] | 24 | #include <asm/microcode.h> |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 25 | #include <asm/msr.h> |
| 26 | #include <asm/mtrr.h> |
Simon Glass | 3274ae0 | 2014-11-12 22:42:13 -0700 | [diff] [blame] | 27 | #include <asm/pci.h> |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 28 | #include <asm/post.h> |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 29 | #include <asm/processor.h> |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 30 | #include <asm/arch/model_206ax.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 31 | #include <asm/arch/pch.h> |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 32 | #include <asm/arch/sandybridge.h> |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 36 | static int set_flex_ratio_to_tdp_nominal(void) |
| 37 | { |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 38 | /* Minimum CPU revision for configurable TDP support */ |
| 39 | if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID) |
| 40 | return -EINVAL; |
| 41 | |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 42 | return cpu_set_flex_ratio_to_tdp_nominal(); |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 45 | int arch_cpu_init(void) |
| 46 | { |
Simon Glass | 7567f46 | 2015-03-05 12:25:17 -0700 | [diff] [blame] | 47 | post_code(POST_CPU_INIT); |
Simon Glass | 7567f46 | 2015-03-05 12:25:17 -0700 | [diff] [blame] | 48 | |
| 49 | return x86_cpu_init_f(); |
| 50 | } |
| 51 | |
| 52 | int arch_cpu_init_dm(void) |
| 53 | { |
Simon Glass | 3274ae0 | 2014-11-12 22:42:13 -0700 | [diff] [blame] | 54 | struct pci_controller *hose; |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 55 | struct udevice *bus, *dev; |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 56 | int ret; |
| 57 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 58 | post_code(0x70); |
| 59 | ret = uclass_get_device(UCLASS_PCI, 0, &bus); |
| 60 | post_code(0x71); |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 61 | if (ret) |
| 62 | return ret; |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 63 | post_code(0x72); |
| 64 | hose = dev_get_uclass_priv(bus); |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 65 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 66 | /* TODO(sjg@chromium.org): Get rid of gd->hose */ |
| 67 | gd->hose = hose; |
Simon Glass | 3274ae0 | 2014-11-12 22:42:13 -0700 | [diff] [blame] | 68 | |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 69 | ret = uclass_first_device_err(UCLASS_LPC, &dev); |
| 70 | if (ret) |
| 71 | return ret; |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 72 | |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 73 | /* |
| 74 | * We should do as little as possible before the serial console is |
| 75 | * up. Perhaps this should move to later. Our next lot of init |
| 76 | * happens in print_cpuinfo() when we have a console |
| 77 | */ |
| 78 | ret = set_flex_ratio_to_tdp_nominal(); |
| 79 | if (ret) |
| 80 | return ret; |
| 81 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 85 | #define PCH_EHCI0_TEMP_BAR0 0xe8000000 |
| 86 | #define PCH_EHCI1_TEMP_BAR0 0xe8000400 |
| 87 | #define PCH_XHCI_TEMP_BAR0 0xe8001000 |
| 88 | |
| 89 | /* |
| 90 | * Setup USB controller MMIO BAR to prevent the reference code from |
| 91 | * resetting the controller. |
| 92 | * |
| 93 | * The BAR will be re-assigned during device enumeration so these are only |
| 94 | * temporary. |
| 95 | * |
| 96 | * This is used to speed up the resume path. |
| 97 | */ |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 98 | static void enable_usb_bar(struct udevice *bus) |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 99 | { |
| 100 | pci_dev_t usb0 = PCH_EHCI1_DEV; |
| 101 | pci_dev_t usb1 = PCH_EHCI2_DEV; |
| 102 | pci_dev_t usb3 = PCH_XHCI_DEV; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 103 | ulong cmd; |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 104 | |
| 105 | /* USB Controller 1 */ |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 106 | pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0, |
| 107 | PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32); |
| 108 | pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 109 | cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 110 | pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 111 | |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 112 | /* USB Controller 2 */ |
| 113 | pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0, |
| 114 | PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32); |
| 115 | pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 116 | cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 117 | pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 118 | |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 119 | /* USB3 Controller 1 */ |
| 120 | pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0, |
| 121 | PCH_XHCI_TEMP_BAR0, PCI_SIZE_32); |
| 122 | pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 123 | cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 124 | pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 127 | int print_cpuinfo(void) |
| 128 | { |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 129 | enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE; |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 130 | char processor_name[CPU_MAX_NAME_LEN]; |
Simon Glass | b20cf04 | 2016-01-17 16:11:19 -0700 | [diff] [blame] | 131 | struct udevice *dev, *lpc; |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 132 | const char *name; |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 133 | uint32_t pm1_cnt; |
| 134 | uint16_t pm1_sts; |
Simon Glass | 367077a | 2014-11-12 22:42:20 -0700 | [diff] [blame] | 135 | int ret; |
| 136 | |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 137 | /* TODO: cmos_post_init() */ |
| 138 | if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) { |
| 139 | debug("soft reset detected\n"); |
| 140 | boot_mode = PEI_BOOT_SOFT_RESET; |
| 141 | |
| 142 | /* System is not happy after keyboard reset... */ |
| 143 | debug("Issuing CF9 warm reset\n"); |
Simon Glass | 1375e9a | 2015-04-28 20:11:30 -0600 | [diff] [blame] | 144 | reset_cpu(0); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 147 | ret = cpu_common_init(); |
Simon Glass | a7b1d95 | 2016-01-17 16:11:13 -0700 | [diff] [blame] | 148 | if (ret) |
| 149 | return ret; |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 150 | |
| 151 | /* Check PM1_STS[15] to see if we are waking from Sx */ |
| 152 | pm1_sts = inw(DEFAULT_PMBASE + PM1_STS); |
| 153 | |
| 154 | /* Read PM1_CNT[12:10] to determine which Sx state */ |
| 155 | pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT); |
| 156 | |
| 157 | if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) { |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 158 | debug("Resume from S3 detected, but disabled.\n"); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 159 | } else { |
| 160 | /* |
| 161 | * TODO: An indication of life might be possible here (e.g. |
| 162 | * keyboard light) |
| 163 | */ |
| 164 | } |
| 165 | post_code(POST_EARLY_INIT); |
| 166 | |
| 167 | /* Enable SPD ROMs and DDR-III DRAM */ |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 168 | ret = uclass_first_device_err(UCLASS_I2C, &dev); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 169 | if (ret) |
| 170 | return ret; |
| 171 | |
| 172 | /* Prepare USB controller early in S3 resume */ |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 173 | if (boot_mode == PEI_BOOT_RESUME) { |
| 174 | uclass_first_device(UCLASS_LPC, &lpc); |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 175 | enable_usb_bar(pci_get_controller(lpc->parent)); |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 176 | } |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 177 | |
| 178 | gd->arch.pei_boot_mode = boot_mode; |
| 179 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 180 | /* Print processor name */ |
| 181 | name = cpu_get_name(processor_name); |
| 182 | printf("CPU: %s\n", name); |
| 183 | |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 184 | post_code(POST_CPU_INFO); |
| 185 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 186 | return 0; |
| 187 | } |
Simon Glass | f2dd470 | 2015-10-18 19:51:27 -0600 | [diff] [blame] | 188 | |
| 189 | void board_debug_uart_init(void) |
| 190 | { |
| 191 | /* This enables the debug UART */ |
| 192 | pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN, |
| 193 | PCI_SIZE_16); |
| 194 | } |