blob: 87528af5cacb409f085d91bac7ff1e0163b1cba2 [file] [log] [blame]
Stefan Reinauere1ae4b22012-04-27 23:20:58 +02001/*
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 Reinauere1ae4b22012-04-27 23:20:58 +020015 */
16
17#include <stdint.h>
18#include <string.h>
19#include <lib.h>
20#include <timestamp.h>
21#include <arch/io.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020022#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älkki6722f8d2014-06-16 09:14:49 +030026#include <arch/acpi.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020027#include <cbmem.h>
28#include <console/console.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030029#include <bootmode.h>
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100030#include <superio/ite/common/ite.h>
31#include <superio/ite/it8772f/it8772f.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110032#include <northbridge/intel/sandybridge/sandybridge.h>
33#include <northbridge/intel/sandybridge/raminit.h>
34#include <southbridge/intel/bd82x6x/pch.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020035#include <arch/cpu.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020036#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010037#include <halt.h>
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020038#include <tpm.h>
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020039#if CONFIG_DRIVERS_UART_8250IO
Edward O'Callaghan74834e02015-01-04 04:17:35 +110040#include <superio/smsc/lpc47n207/lpc47n207.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020041#endif
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020042
43/* Stumpy USB Reset Disable defined in cmos.layout */
44#if CONFIG_USE_OPTION_TABLE
45#include "option_table.h"
46#define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3)
47#else
48#define CMOS_USB_RESET_DISABLE (400 >> 3)
49#endif
50#define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */
51
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +100052#define DUMMY_DEV PNP_DEV(0x2e, 0)
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100053#define SERIAL_DEV PNP_DEV(0x2e, IT8772F_SP1)
54#define GPIO_DEV PNP_DEV(0x2e, IT8772F_GPIO)
55
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010056void pch_enable_lpc(void)
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020057{
58 /* Set COM1/COM2 decode range */
59 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
60
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020061#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020062 /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/
63 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\
64 CNF2_LPC_EN | COMA_LPC_EN);
65
66 /* map full 256 bytes at 0x1600 to the LPC bus */
67 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
68
69 try_enabling_LPC47N207_uart();
70#else
71 /* Enable SuperIO + PS/2 Keyboard/Mouse */
72 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN);
73#endif
74}
75
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010076void rcba_config(void)
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020077{
78 u32 reg32;
79
Kyösti Mälkki6f499062015-06-06 11:52:24 +030080 /*
81 * GFX INTA -> PIRQA (MSI)
82 * D28IP_P1IP WLAN INTA -> PIRQB
83 * D28IP_P4IP ETH0 INTB -> PIRQC
84 * D29IP_E1P EHCI1 INTA -> PIRQD
85 * D26IP_E2P EHCI2 INTA -> PIRQE
86 * D31IP_SIP SATA INTA -> PIRQF (MSI)
87 * D31IP_SMIP SMBUS INTB -> PIRQG
88 * D31IP_TTIP THRT INTC -> PIRQH
89 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
90 */
91
92 /* Device interrupt pin register (board specific) */
93 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
94 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
95 RCBA32(D30IP) = (NOINT << D30IP_PIP);
96 RCBA32(D29IP) = (INTA << D29IP_E1P);
97 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
98 (INTB << D28IP_P4IP);
99 RCBA32(D27IP) = (INTA << D27IP_ZIP);
100 RCBA32(D26IP) = (INTA << D26IP_E2P);
101 RCBA32(D25IP) = (NOINT << D25IP_LIP);
102 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
103
104 /* Device interrupt route registers */
105 DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA);
106 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
107 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
108 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
109 DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH);
110 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
111 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
112
113 /* Enable IOAPIC (generic) */
114 RCBA16(OIC) = 0x0100;
115 /* PCH BWG says to read back the IOAPIC enable register */
116 (void) RCBA16(OIC);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200117
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200118 /* Disable unused devices (board specific) */
119 reg32 = RCBA32(FD);
120 reg32 |= PCH_DISABLE_ALWAYS;
121 RCBA32(FD) = reg32;
122}
123
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200124static void setup_sio_gpios(void)
125{
126 /*
127 * GPIO10 as USBPWRON12#
128 * GPIO12 as USBPWRON13#
129 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000130 it8772f_gpio_setup(DUMMY_DEV, 1, 0x05, 0x05, 0x00, 0x05, 0x05);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200131
132 /*
133 * GPIO22 as wake SCI#
134 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000135 it8772f_gpio_setup(DUMMY_DEV, 2, 0x04, 0x04, 0x00, 0x04, 0x04);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200136
137 /*
138 * GPIO32 as EXTSMI#
139 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000140 it8772f_gpio_setup(DUMMY_DEV, 3, 0x04, 0x04, 0x00, 0x04, 0x04);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200141
142 /*
143 * GPIO45 as LED_POWER#
144 */
david80ef7b72015-01-19 17:11:36 +0800145 it8772f_gpio_led(DUMMY_DEV, 4 /* set */, (0x1<<5) /* select */,
146 0x00 /* polarity: non-inverting */, 0x00 /* 0=pulldown */,
147 (0x1<<5) /* output */, (0x1<<5) /* 1=Simple IO function */,
148 SIO_GPIO_BLINK_GPIO45, IT8772F_GPIO_BLINK_FREQUENCY_1_HZ);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200149
150 /*
151 * GPIO51 as USBPWRON8#
152 * GPIO52 as USBPWRON1#
153 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000154 it8772f_gpio_setup(DUMMY_DEV, 5, 0x06, 0x06, 0x00, 0x06, 0x06);
155 it8772f_gpio_setup(DUMMY_DEV, 6, 0x00, 0x00, 0x00, 0x00, 0x00);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200156}
157
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100158void mainboard_fill_pei_data(struct pei_data *pei_data)
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200159{
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100160 struct pei_data pei_data_template = {
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000161 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800162 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
163 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000164 .epbar = DEFAULT_EPBAR,
165 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
166 .smbusbar = SMBUS_IO_BASE,
167 .wdbbar = 0x4000000,
168 .wdbsize = 0x1000,
169 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800170 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000171 .pmbase = DEFAULT_PMBASE,
172 .gpiobase = DEFAULT_GPIOBASE,
173 .thermalbase = 0xfed08000,
174 .system_type = 0, // 0 Mobile, 1 Desktop/Server
175 .tseg_size = CONFIG_SMM_TSEG_SIZE,
176 .spd_addresses = { 0xa0, 0x00,0xa4,0x00 },
177 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
178 .ec_present = 0,
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200179 // 0 = leave channel enabled
180 // 1 = disable dimm 0 on channel
181 // 2 = disable dimm 1 on channel
182 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000183 .dimm_channel0_disabled = 2,
184 .dimm_channel1_disabled = 2,
185 .max_ddr3_freq = 1333,
186 .usb_port_config = {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200187 { 1, 0, 0x0080 }, /* P0: Front port (OC0) */
188 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
189 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
190 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
191 { 1, 2, 0x0080 }, /* P4: Front port (OC2) */
192 { 0, 0, 0x0000 }, /* P5: Empty */
193 { 0, 0, 0x0000 }, /* P6: Empty */
194 { 0, 0, 0x0000 }, /* P7: Empty */
195 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
196 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
197 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
198 { 0, 4, 0x0000 }, /* P11: Empty */
199 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
200 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
201 },
202 };
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100203 *pei_data = pei_data_template;
204}
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200205
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100206void mainboard_early_init(int s3resume)
207{
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300208 init_bootmode_straps();
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100209}
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200210
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100211int mainboard_should_reset_usb(int s3resume)
212{
213 if (s3resume) {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200214 /*
215 * For Stumpy the back USB ports are reset on resume
216 * so default to resetting the controller to make the
217 * kernel happy. There is a CMOS flag to disable the
218 * controller reset in case the kernel can tolerate
219 * the device power loss better in the future.
220 */
221 u8 magic = cmos_read(CMOS_USB_RESET_DISABLE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200222 if (magic == USB_RESET_DISABLE_MAGIC) {
223 printk(BIOS_DEBUG, "USB Controller Reset Disabled\n");
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100224 return 0;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200225 } else {
226 printk(BIOS_DEBUG, "USB Controller Reset Enabled\n");
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100227 return 1;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200228 }
229 } else {
230 /* Ensure USB reset on resume is enabled at boot */
231 cmos_write(0, CMOS_USB_RESET_DISABLE);
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100232 return 1;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200233 }
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100234}
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200235
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100236void mainboard_config_superio(void)
237{
238 setup_sio_gpios();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200239
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100240 /* Early SuperIO setup */
241 it8772f_ac_resume_southbridge(DUMMY_DEV);
242 ite_kill_watchdog(GPIO_DEV);
243 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200244}