Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +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. |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <string.h> |
| 19 | #include <lib.h> |
| 20 | #include <timestamp.h> |
| 21 | #include <arch/io.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 22 | #include <device/pci_def.h> |
| 23 | #include <device/pnp_def.h> |
| 24 | #include <cpu/x86/lapic.h> |
| 25 | #include <pc80/mc146818rtc.h> |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 26 | #include <arch/acpi.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 27 | #include <cbmem.h> |
| 28 | #include <console/console.h> |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 29 | #include <bootmode.h> |
Edward O'Callaghan | 1b3acb1 | 2014-06-01 18:04:05 +1000 | [diff] [blame] | 30 | #include <superio/ite/common/ite.h> |
| 31 | #include <superio/ite/it8772f/it8772f.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 32 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 33 | #include <northbridge/intel/sandybridge/raminit.h> |
Vladimir Serbinenko | d2990c9 | 2016-02-10 02:52:42 +0100 | [diff] [blame] | 34 | #include <northbridge/intel/sandybridge/raminit_native.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 35 | #include <southbridge/intel/bd82x6x/pch.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 36 | #include <arch/cpu.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 37 | #include <cpu/x86/msr.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 38 | #include <halt.h> |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame] | 39 | #include <tpm.h> |
Kyösti Mälkki | afa7b13 | 2014-02-13 17:16:22 +0200 | [diff] [blame] | 40 | #if CONFIG_DRIVERS_UART_8250IO |
Edward O'Callaghan | 74834e0 | 2015-01-04 04:17:35 +1100 | [diff] [blame] | 41 | #include <superio/smsc/lpc47n207/lpc47n207.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 42 | #endif |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 43 | |
| 44 | /* Stumpy USB Reset Disable defined in cmos.layout */ |
| 45 | #if CONFIG_USE_OPTION_TABLE |
| 46 | #include "option_table.h" |
| 47 | #define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3) |
| 48 | #else |
| 49 | #define CMOS_USB_RESET_DISABLE (400 >> 3) |
| 50 | #endif |
| 51 | #define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */ |
| 52 | |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 53 | #define DUMMY_DEV PNP_DEV(0x2e, 0) |
Edward O'Callaghan | 1b3acb1 | 2014-06-01 18:04:05 +1000 | [diff] [blame] | 54 | #define SERIAL_DEV PNP_DEV(0x2e, IT8772F_SP1) |
| 55 | #define GPIO_DEV PNP_DEV(0x2e, IT8772F_GPIO) |
| 56 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 57 | void pch_enable_lpc(void) |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 58 | { |
| 59 | /* Set COM1/COM2 decode range */ |
| 60 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 61 | |
Kyösti Mälkki | afa7b13 | 2014-02-13 17:16:22 +0200 | [diff] [blame] | 62 | #if CONFIG_DRIVERS_UART_8250IO |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 63 | /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/ |
| 64 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\ |
| 65 | CNF2_LPC_EN | COMA_LPC_EN); |
| 66 | |
| 67 | /* map full 256 bytes at 0x1600 to the LPC bus */ |
| 68 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601); |
| 69 | |
| 70 | try_enabling_LPC47N207_uart(); |
| 71 | #else |
| 72 | /* Enable SuperIO + PS/2 Keyboard/Mouse */ |
| 73 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN); |
| 74 | #endif |
| 75 | } |
| 76 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 77 | void rcba_config(void) |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 78 | { |
| 79 | u32 reg32; |
| 80 | |
Kyösti Mälkki | 6f49906 | 2015-06-06 11:52:24 +0300 | [diff] [blame] | 81 | /* |
| 82 | * GFX INTA -> PIRQA (MSI) |
| 83 | * D28IP_P1IP WLAN INTA -> PIRQB |
| 84 | * D28IP_P4IP ETH0 INTB -> PIRQC |
| 85 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 86 | * D26IP_E2P EHCI2 INTA -> PIRQE |
| 87 | * D31IP_SIP SATA INTA -> PIRQF (MSI) |
| 88 | * D31IP_SMIP SMBUS INTB -> PIRQG |
| 89 | * D31IP_TTIP THRT INTC -> PIRQH |
| 90 | * D27IP_ZIP HDA INTA -> PIRQG (MSI) |
| 91 | */ |
| 92 | |
| 93 | /* Device interrupt pin register (board specific) */ |
| 94 | RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 95 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 96 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 97 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 98 | RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) | |
| 99 | (INTB << D28IP_P4IP); |
| 100 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 101 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 102 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 103 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 104 | |
| 105 | /* Device interrupt route registers */ |
| 106 | DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA); |
| 107 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 108 | DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE); |
| 109 | DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB); |
| 110 | DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH); |
| 111 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 112 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 113 | |
| 114 | /* Enable IOAPIC (generic) */ |
| 115 | RCBA16(OIC) = 0x0100; |
| 116 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 117 | (void) RCBA16(OIC); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 118 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 119 | /* Disable unused devices (board specific) */ |
| 120 | reg32 = RCBA32(FD); |
| 121 | reg32 |= PCH_DISABLE_ALWAYS; |
| 122 | RCBA32(FD) = reg32; |
| 123 | } |
| 124 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 125 | static void setup_sio_gpios(void) |
| 126 | { |
| 127 | /* |
| 128 | * GPIO10 as USBPWRON12# |
| 129 | * GPIO12 as USBPWRON13# |
| 130 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 131 | it8772f_gpio_setup(DUMMY_DEV, 1, 0x05, 0x05, 0x00, 0x05, 0x05); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * GPIO22 as wake SCI# |
| 135 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 136 | it8772f_gpio_setup(DUMMY_DEV, 2, 0x04, 0x04, 0x00, 0x04, 0x04); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * GPIO32 as EXTSMI# |
| 140 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 141 | it8772f_gpio_setup(DUMMY_DEV, 3, 0x04, 0x04, 0x00, 0x04, 0x04); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * GPIO45 as LED_POWER# |
| 145 | */ |
david | 80ef7b7 | 2015-01-19 17:11:36 +0800 | [diff] [blame] | 146 | it8772f_gpio_led(DUMMY_DEV, 4 /* set */, (0x1<<5) /* select */, |
| 147 | 0x00 /* polarity: non-inverting */, 0x00 /* 0=pulldown */, |
| 148 | (0x1<<5) /* output */, (0x1<<5) /* 1=Simple IO function */, |
| 149 | SIO_GPIO_BLINK_GPIO45, IT8772F_GPIO_BLINK_FREQUENCY_1_HZ); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * GPIO51 as USBPWRON8# |
| 153 | * GPIO52 as USBPWRON1# |
| 154 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 155 | it8772f_gpio_setup(DUMMY_DEV, 5, 0x06, 0x06, 0x00, 0x06, 0x06); |
| 156 | it8772f_gpio_setup(DUMMY_DEV, 6, 0x00, 0x00, 0x00, 0x00, 0x00); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 159 | void mainboard_fill_pei_data(struct pei_data *pei_data) |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 160 | { |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 161 | struct pei_data pei_data_template = { |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 162 | .pei_version = PEI_VERSION, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 163 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 164 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 165 | .epbar = DEFAULT_EPBAR, |
| 166 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 167 | .smbusbar = SMBUS_IO_BASE, |
| 168 | .wdbbar = 0x4000000, |
| 169 | .wdbsize = 0x1000, |
| 170 | .hpet_address = CONFIG_HPET_ADDRESS, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 171 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 172 | .pmbase = DEFAULT_PMBASE, |
| 173 | .gpiobase = DEFAULT_GPIOBASE, |
| 174 | .thermalbase = 0xfed08000, |
| 175 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 176 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 177 | .spd_addresses = { 0xa0, 0x00,0xa4,0x00 }, |
| 178 | .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, |
| 179 | .ec_present = 0, |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 180 | // 0 = leave channel enabled |
| 181 | // 1 = disable dimm 0 on channel |
| 182 | // 2 = disable dimm 1 on channel |
| 183 | // 3 = disable dimm 0+1 on channel |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 184 | .dimm_channel0_disabled = 2, |
| 185 | .dimm_channel1_disabled = 2, |
| 186 | .max_ddr3_freq = 1333, |
| 187 | .usb_port_config = { |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 188 | { 1, 0, 0x0080 }, /* P0: Front port (OC0) */ |
| 189 | { 1, 1, 0x0040 }, /* P1: Back port (OC1) */ |
| 190 | { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */ |
| 191 | { 1, 0, 0x0040 }, /* P3: MMC (no OC) */ |
| 192 | { 1, 2, 0x0080 }, /* P4: Front port (OC2) */ |
| 193 | { 0, 0, 0x0000 }, /* P5: Empty */ |
| 194 | { 0, 0, 0x0000 }, /* P6: Empty */ |
| 195 | { 0, 0, 0x0000 }, /* P7: Empty */ |
| 196 | { 1, 4, 0x0040 }, /* P8: Back port (OC4) */ |
| 197 | { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */ |
| 198 | { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */ |
| 199 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 200 | { 1, 6, 0x0040 }, /* P12: Back port (OC6) */ |
| 201 | { 1, 5, 0x0040 }, /* P13: Back port (OC5) */ |
| 202 | }, |
| 203 | }; |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 204 | *pei_data = pei_data_template; |
| 205 | } |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 206 | |
Vladimir Serbinenko | d2990c9 | 2016-02-10 02:52:42 +0100 | [diff] [blame] | 207 | void mainboard_get_spd(spd_raw_data *spd) |
| 208 | { |
| 209 | read_spd(&spd[0], 0x50); |
| 210 | read_spd(&spd[2], 0x52); |
| 211 | } |
| 212 | |
| 213 | const struct southbridge_usb_port mainboard_usb_ports[] = { |
| 214 | /* enabled power usb oc pin */ |
| 215 | { 1, 1, 0 }, /* P0: Front port (OC0) */ |
| 216 | { 1, 0, 1 }, /* P1: Back port (OC1) */ |
| 217 | { 1, 0, -1 }, /* P2: MINIPCIE1 (no OC) */ |
| 218 | { 1, 0, -1 }, /* P3: MMC (no OC) */ |
| 219 | { 1, 1, 2 }, /* P4: Front port (OC2) */ |
| 220 | { 0, 0, -1 }, /* P5: Empty */ |
| 221 | { 0, 0, -1 }, /* P6: Empty */ |
| 222 | { 0, 0, -1 }, /* P7: Empty */ |
| 223 | { 1, 0, 4 }, /* P8: Back port (OC4) */ |
| 224 | { 1, 0, -1 }, /* P9: MINIPCIE3 (no OC) */ |
| 225 | { 1, 0, -1 }, /* P10: BLUETOOTH (no OC) */ |
| 226 | { 0, 0, -1 }, /* P11: Empty */ |
| 227 | { 1, 0, 6 }, /* P12: Back port (OC6) */ |
| 228 | { 1, 0, 5 }, /* P13: Back port (OC5) */ |
| 229 | }; |
| 230 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 231 | void mainboard_early_init(int s3resume) |
| 232 | { |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 233 | init_bootmode_straps(); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 234 | } |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 235 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 236 | int mainboard_should_reset_usb(int s3resume) |
| 237 | { |
| 238 | if (s3resume) { |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 239 | /* |
| 240 | * For Stumpy the back USB ports are reset on resume |
| 241 | * so default to resetting the controller to make the |
| 242 | * kernel happy. There is a CMOS flag to disable the |
| 243 | * controller reset in case the kernel can tolerate |
| 244 | * the device power loss better in the future. |
| 245 | */ |
| 246 | u8 magic = cmos_read(CMOS_USB_RESET_DISABLE); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 247 | if (magic == USB_RESET_DISABLE_MAGIC) { |
| 248 | printk(BIOS_DEBUG, "USB Controller Reset Disabled\n"); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 249 | return 0; |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 250 | } else { |
| 251 | printk(BIOS_DEBUG, "USB Controller Reset Enabled\n"); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 252 | return 1; |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 253 | } |
| 254 | } else { |
| 255 | /* Ensure USB reset on resume is enabled at boot */ |
| 256 | cmos_write(0, CMOS_USB_RESET_DISABLE); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 257 | return 1; |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 258 | } |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 259 | } |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 260 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 261 | void mainboard_config_superio(void) |
| 262 | { |
| 263 | setup_sio_gpios(); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 264 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 265 | /* Early SuperIO setup */ |
| 266 | it8772f_ac_resume_southbridge(DUMMY_DEV); |
| 267 | ite_kill_watchdog(GPIO_DEV); |
| 268 | ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 269 | } |