Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2010 coresystems GmbH |
| 5 | * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <lib.h> |
| 24 | #include <timestamp.h> |
| 25 | #include <arch/io.h> |
| 26 | #include <device/pci_def.h> |
| 27 | #include <device/pnp_def.h> |
| 28 | #include <cpu/x86/lapic.h> |
| 29 | #include <pc80/mc146818rtc.h> |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 30 | #include <arch/acpi.h> |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 31 | #include <cbmem.h> |
| 32 | #include <console/console.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 33 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 34 | #include <northbridge/intel/sandybridge/raminit.h> |
| 35 | #include <southbridge/intel/bd82x6x/pch.h> |
| 36 | #include <southbridge/intel/bd82x6x/gpio.h> |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 37 | #include <arch/cpu.h> |
| 38 | #include <cpu/x86/bist.h> |
| 39 | #include <cpu/x86/msr.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 40 | #include <halt.h> |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 41 | #include "gpio.h" |
| 42 | |
| 43 | static void pch_enable_lpc(void) |
| 44 | { |
| 45 | /* Set COM3/COM1 decode ranges: 0x3e8/0x3f8 */ |
| 46 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0070); |
| 47 | |
| 48 | /* Enable KBC on 0x06/0x64 (KBC), |
| 49 | * EC on 0x62/0x66 (MC), |
| 50 | * EC on 0x20c-0x20f (GAMEH), |
| 51 | * Super I/O on 0x2e/0x2f (CNF1), |
| 52 | * COM1/COM3 decode ranges. */ |
| 53 | pci_write_config16(PCH_LPC_DEV, LPC_EN, |
| 54 | KBC_LPC_EN | MC_LPC_EN | |
| 55 | CNF1_LPC_EN | GAMEH_LPC_EN | |
| 56 | COMA_LPC_EN | COMB_LPC_EN); |
| 57 | } |
| 58 | |
| 59 | static void rcba_config(void) |
| 60 | { |
| 61 | u32 reg32; |
| 62 | |
Vladimir Serbinenko | 33b535f | 2014-10-19 10:13:14 +0200 | [diff] [blame] | 63 | southbridge_configure_default_intmap(); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 64 | |
| 65 | /* Disable unused devices (board specific) */ |
| 66 | reg32 = RCBA32(FD); |
| 67 | reg32 |= PCH_DISABLE_ALWAYS; |
| 68 | /* Disable PCI bridge so MRC does not probe this bus */ |
| 69 | reg32 |= PCH_DISABLE_P2P; |
| 70 | RCBA32(FD) = reg32; |
| 71 | } |
| 72 | |
| 73 | static void pnp_enter_ext_func_mode(device_t dev) |
| 74 | { |
| 75 | u16 port = dev >> 8; |
| 76 | outb(0x87, port); |
| 77 | outb(0x87, port); |
| 78 | } |
| 79 | |
| 80 | static void pnp_exit_ext_func_mode(device_t dev) |
| 81 | { |
| 82 | u16 port = dev >> 8; |
| 83 | outb(0xaa, port); |
| 84 | } |
| 85 | |
| 86 | static void superio_gpio_config(void) |
| 87 | { |
Nico Huber | 40f9ce9 | 2013-10-22 11:07:23 +0200 | [diff] [blame] | 88 | int lvds_3v = 0; // 0 (5V) or 1 (3V3) |
| 89 | int dis_bl_inv = 1; // backlight inversion: 1 = disabled, 0 = enabled |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 90 | device_t dev = PNP_DEV(0x2e, 0x9); |
| 91 | pnp_enter_ext_func_mode(dev); |
Nico Huber | 40f9ce9 | 2013-10-22 11:07:23 +0200 | [diff] [blame] | 92 | pnp_write_config(dev, 0x29, 0x02); /* Pins 119, 120 are GPIO21, 20 */ |
| 93 | pnp_write_config(dev, 0x30, 0x03); /* Enable GPIO2+3 */ |
| 94 | pnp_write_config(dev, 0x2a, 0x01); /* Pins 62, 63, 65, 66 are |
| 95 | GPIO27, 26, 25, 24 */ |
| 96 | pnp_write_config(dev, 0x2c, 0xc3); /* Pin 90 is GPIO32, |
| 97 | Pins 78~85 are UART B */ |
| 98 | pnp_write_config(dev, 0x2d, 0x00); /* Pins 67, 68, 70~73, 75, 77 are |
| 99 | GPIO57~50 */ |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 100 | pnp_set_logical_device(dev); |
| 101 | /* Values can only be changed, when devices are enabled. */ |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 102 | pnp_write_config(dev, 0xe3, 0xdd); /* GPIO2 bits 1, 5 are output */ |
Nico Huber | 40f9ce9 | 2013-10-22 11:07:23 +0200 | [diff] [blame] | 103 | pnp_write_config(dev, 0xe4, (dis_bl_inv << 5) | (lvds_3v << 1)); /* GPIO2 bits 1, 5 */ |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 104 | pnp_exit_ext_func_mode(dev); |
| 105 | } |
| 106 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 107 | #include <cpu/intel/romstage.h> |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 108 | void main(unsigned long bist) |
| 109 | { |
| 110 | int boot_mode = 0; |
| 111 | int cbmem_was_initted; |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 112 | |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 113 | struct pei_data pei_data = { |
Edward O'Callaghan | 6f49f69 | 2014-05-24 02:04:52 +1000 | [diff] [blame] | 114 | .pei_version = PEI_VERSION, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 115 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 116 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
Edward O'Callaghan | 6f49f69 | 2014-05-24 02:04:52 +1000 | [diff] [blame] | 117 | .epbar = DEFAULT_EPBAR, |
| 118 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 119 | .smbusbar = SMBUS_IO_BASE, |
| 120 | .wdbbar = 0x4000000, |
| 121 | .wdbsize = 0x1000, |
| 122 | .hpet_address = CONFIG_HPET_ADDRESS, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 123 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
Edward O'Callaghan | 6f49f69 | 2014-05-24 02:04:52 +1000 | [diff] [blame] | 124 | .pmbase = DEFAULT_PMBASE, |
| 125 | .gpiobase = DEFAULT_GPIOBASE, |
| 126 | .thermalbase = 0xfed08000, |
| 127 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 128 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 129 | .spd_addresses = { 0xA0, 0x00,0xA4,0x00 }, |
| 130 | .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, |
| 131 | .ec_present = 1, |
| 132 | .gbe_enable = 1, |
| 133 | .ddr3lv_support = 0, |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 134 | // 0 = leave channel enabled |
| 135 | // 1 = disable dimm 0 on channel |
| 136 | // 2 = disable dimm 1 on channel |
| 137 | // 3 = disable dimm 0+1 on channel |
Edward O'Callaghan | 6f49f69 | 2014-05-24 02:04:52 +1000 | [diff] [blame] | 138 | .dimm_channel0_disabled = 2, |
| 139 | .dimm_channel1_disabled = 2, |
| 140 | .max_ddr3_freq = 1600, |
| 141 | .usb_port_config = { |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 142 | /* enabled usb oc pin length */ |
| 143 | { 1, 0, 0x0040 }, /* P0: lower left USB 3.0 (OC0) */ |
| 144 | { 1, 0, 0x0040 }, /* P1: upper left USB 3.0 (OC0) */ |
| 145 | { 1, 0, 0x0040 }, /* P2: lower right USB 3.0 (OC0) */ |
| 146 | { 1, 0, 0x0040 }, /* P3: upper right USB 3.0 (OC0) */ |
| 147 | { 1, 0, 0x0040 }, /* P4: lower USB 2.0 (OC0) */ |
| 148 | { 1, 0, 0x0040 }, /* P5: upper USB 2.0 (OC0) */ |
| 149 | { 1, 0, 0x0040 }, /* P6: front panel USB 2.0 (OC0) */ |
| 150 | { 1, 0, 0x0040 }, /* P7: front panel USB 2.0 (OC0) */ |
| 151 | { 1, 4, 0x0040 }, /* P8: internal USB 2.0 (OC4) */ |
| 152 | { 1, 4, 0x0040 }, /* P9: internal USB 2.0 (OC4) */ |
| 153 | { 1, 4, 0x0040 }, /* P10: internal USB 2.0 (OC4) */ |
| 154 | { 1, 4, 0x0040 }, /* P11: internal USB 2.0 (OC4) */ |
| 155 | { 1, 4, 0x0040 }, /* P12: internal USB 2.0 (OC4) */ |
| 156 | { 1, 4, 0x0040 }, /* P13: internal USB 2.0 (OC4) */ |
| 157 | }, |
Edward O'Callaghan | 6f49f69 | 2014-05-24 02:04:52 +1000 | [diff] [blame] | 158 | .usb3 = { |
| 159 | .mode = 3, /* Smart Auto? */ |
| 160 | .hs_port_switch_mask = 0xf, /* All four ports. */ |
| 161 | .preboot_support = 1, /* preOS driver? */ |
| 162 | .xhci_streams = 1, /* Enable. */ |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 163 | }, |
Edward O'Callaghan | 6f49f69 | 2014-05-24 02:04:52 +1000 | [diff] [blame] | 164 | .pcie_init = 1, |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 167 | timestamp_init(get_initial_timestamp()); |
| 168 | timestamp_add_now(TS_START_ROMSTAGE); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 169 | |
| 170 | if (bist == 0) |
| 171 | enable_lapic(); |
| 172 | |
| 173 | pch_enable_lpc(); |
| 174 | |
| 175 | /* Enable GPIOs */ |
| 176 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 177 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 178 | setup_pch_gpios(&ktqm77_gpio_map); |
| 179 | superio_gpio_config(); |
| 180 | |
| 181 | /* Initialize console device(s) */ |
| 182 | console_init(); |
| 183 | |
| 184 | /* Halt if there was a built in self test failure */ |
| 185 | report_bist_failure(bist); |
| 186 | |
| 187 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 188 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 189 | boot_mode = 1; |
| 190 | |
| 191 | /* System is not happy after keyboard reset... */ |
| 192 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 193 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 194 | halt(); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* Perform some early chipset initialization required |
| 198 | * before RAM initialization can work |
| 199 | */ |
| 200 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 201 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 202 | |
| 203 | /* Enable PEG10 (1x16) */ |
| 204 | pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, |
| 205 | pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) | |
| 206 | DEVEN_PEG10); |
| 207 | |
Vladimir Serbinenko | 332f14b | 2014-09-05 16:29:41 +0200 | [diff] [blame] | 208 | boot_mode = southbridge_detect_s3_resume() ? 2 : 0; |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 209 | |
| 210 | post_code(0x38); |
| 211 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 212 | enable_smbus(); |
| 213 | |
| 214 | /* Prepare USB controller early in S3 resume */ |
| 215 | if (boot_mode == 2) |
| 216 | enable_usb_bar(); |
| 217 | |
| 218 | post_code(0x39); |
| 219 | |
| 220 | post_code(0x3a); |
| 221 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 222 | timestamp_add_now(TS_BEFORE_INITRAM); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 223 | sdram_initialize(&pei_data); |
| 224 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 225 | timestamp_add_now(TS_AFTER_INITRAM); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 226 | post_code(0x3c); |
| 227 | |
| 228 | rcba_config(); |
| 229 | post_code(0x3d); |
| 230 | |
| 231 | quick_ram_check(); |
| 232 | post_code(0x3e); |
| 233 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 234 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 235 | if (boot_mode!=2) |
| 236 | save_mrc_data(&pei_data); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 237 | |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 238 | if (boot_mode==2 && !cbmem_was_initted) { |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 239 | /* Failed S3 resume, reset to come up cleanly */ |
| 240 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 241 | halt(); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 242 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 243 | northbridge_romstage_finalize(boot_mode==2); |
| 244 | |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 245 | post_code(0x3f); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 246 | timestamp_add_now(TS_END_ROMSTAGE); |
Nico Huber | efe1fed | 2013-04-29 18:00:57 +0200 | [diff] [blame] | 247 | } |