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