blob: 968cd7ce699db800f6875aa12955f6b05a52a4ca [file] [log] [blame]
Marc Jones2d79f162017-05-22 21:35:16 -06001/*
2 * This file is part of the coreboot project.
3 *
Marc Jones2d79f162017-05-22 21:35:16 -06004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
Simon Glassb5c51772018-03-05 12:18:40 -070015#include <string.h>
Marc Jones2d79f162017-05-22 21:35:16 -060016#include <console/console.h>
17#include <device/device.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Marc Jones2d79f162017-05-22 21:35:16 -060019#include <arch/acpi.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070020#include <amdblocks/agesawrapper.h>
Richard Spiegel2bbc3dc2017-12-06 16:14:58 -070021#include <amdblocks/amd_pci_util.h>
Marc Jones067031e2017-11-02 11:36:53 -060022#include <cbmem.h>
Martin Rothb77bc6f2017-11-11 14:33:47 -070023#include <baseboard/variants.h>
Marc Jones71f7f0a2017-11-21 23:29:55 -070024#include <boardid.h>
Simon Glassb5c51772018-03-05 12:18:40 -070025#include <smbios.h>
Marc Jones067031e2017-11-02 11:36:53 -060026#include <soc/nvs.h>
Richard Spiegel9dc56002017-12-18 16:25:42 -070027#include <soc/pci_devs.h>
Marc Jonesdf6b51b2017-11-29 20:07:46 -070028#include <soc/southbridge.h>
Marshall Dawson251d3052019-05-02 17:27:57 -060029#include <soc/smi.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060030#include <amdblocks/acpimmio.h>
Martin Roth6c623ca2017-11-16 22:14:53 -070031#include <variant/ec.h>
Marc Jones067031e2017-11-02 11:36:53 -060032#include <variant/thermal.h>
Marc Jones0a15ed52017-06-22 22:22:20 -060033#include <vendorcode/google/chromeos/chromeos.h>
Marc Jones2d79f162017-05-22 21:35:16 -060034
35/***********************************************************
36 * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01.
37 * This table is responsible for physically routing the PIC and
38 * IOAPIC IRQs to the different PCI devices on the system. It
39 * is read and written via registers 0xC00/0xC01 as an
40 * Index/Data pair. These values are chipset and mainboard
41 * dependent and should be updated accordingly.
42 *
43 * These values are used by the PCI configuration space,
44 * MP Tables. TODO: Make ACPI use these values too.
45 */
Martin Roth6c14cd32018-01-11 16:25:28 -080046
Kyösti Mälkkie1e32892019-12-22 09:49:56 +020047static const u8 mainboard_picr_data[] = {
Martin Roth6c14cd32018-01-11 16:25:28 -080048 [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x1F, 0x1F, 0x1F,
49 [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
Richard Spiegel8f825e02018-02-12 08:36:10 -070050 [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03,
Martin Roth6c14cd32018-01-11 16:25:28 -080051 [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
53 [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05,
55 [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Richard Spiegel8f825e02018-02-12 08:36:10 -070056 [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Martin Roth6c14cd32018-01-11 16:25:28 -080057 [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F,
59 [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
60 [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
61 [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
62 [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
63 [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
64};
Marc Jones2d79f162017-05-22 21:35:16 -060065
Kyösti Mälkkie1e32892019-12-22 09:49:56 +020066static const u8 mainboard_intr_data[] = {
Martin Roth6c14cd32018-01-11 16:25:28 -080067 [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x1F, 0x16, 0x17,
68 [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
69 [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10,
70 [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
71 [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
72 [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00,
74 [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75 [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00,
78 [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
80 [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
82 [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83};
Richard Spiegel9dc56002017-12-18 16:25:42 -070084
85/*
86 * This table defines the index into the picr/intr_data tables for each
87 * device. Any enabled device and slot that uses hardware interrupts should
88 * have an entry in this table to define its index into the FCH PCI_INTR
89 * register 0xC00/0xC01. This index will define the interrupt that it should
90 * use. Putting PIRQ_A into the PIN A index for a device will tell that
91 * device to use PIC IRQ 10 if it uses PIN A for its hardware INT.
92 */
93static const struct pirq_struct mainboard_pirq_data[] = {
94 { PCIE0_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } },
95 { PCIE1_DEVFN, { PIRQ_B, PIRQ_C, PIRQ_D, PIRQ_A } },
96 { PCIE2_DEVFN, { PIRQ_C, PIRQ_D, PIRQ_A, PIRQ_B } },
97 { PCIE3_DEVFN, { PIRQ_D, PIRQ_A, PIRQ_B, PIRQ_C } },
98 { PCIE4_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } },
99 { HDA0_DEVFN, { PIRQ_NC, PIRQ_HDA, PIRQ_NC, PIRQ_NC } },
100 { SD_DEVFN, { PIRQ_SD, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
101 { SMBUS_DEVFN, { PIRQ_SMBUS, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
102 { SATA_DEVFN, { PIRQ_SATA, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
103 { EHCI1_DEVFN, { PIRQ_EHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
104 { XHCI_DEVFN, { PIRQ_XHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
105};
106
Marc Jones2d79f162017-05-22 21:35:16 -0600107/* PIRQ Setup */
108static void pirq_setup(void)
109{
Richard Spiegel9dc56002017-12-18 16:25:42 -0700110 pirq_data_ptr = mainboard_pirq_data;
111 pirq_data_size = ARRAY_SIZE(mainboard_pirq_data);
Marc Jones2d79f162017-05-22 21:35:16 -0600112 intr_data_ptr = mainboard_intr_data;
113 picr_data_ptr = mainboard_picr_data;
114}
115
Marc Jones9ad593b2017-06-22 22:19:55 -0600116static void mainboard_init(void *chip_info)
117{
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600118 const struct sci_source *gpes;
119 size_t num;
Marc Jones71f7f0a2017-11-21 23:29:55 -0700120 int boardid = board_id();
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700121 size_t num_gpios;
Richard Spiegel6fcb9b02018-04-18 08:06:33 -0700122 const struct soc_amd_gpio *gpios;
Marc Jones71f7f0a2017-11-21 23:29:55 -0700123
124 printk(BIOS_INFO, "Board ID: %d\n", boardid);
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600125
Marc Jones9ad593b2017-06-22 22:19:55 -0600126 mainboard_ec_init();
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600127
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700128 gpios = variant_gpio_table(&num_gpios);
Marshall Dawson251d3052019-05-02 17:27:57 -0600129 program_gpios(gpios, num_gpios);
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700130
Richard Spiegel2db06bb2018-04-20 16:50:12 -0700131 /*
132 * Some platforms use SCI not generated by a GPIO pin (event above 23).
133 * For these boards, gpe_configure_sci() is still needed, but all GPIO
134 * generated events (23-0) must be removed from gpe_table[].
135 * For boards that only have GPIO generated events, table gpe_table[]
136 * must be removed, and get_gpe_table() should return NULL.
137 */
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600138 gpes = get_gpe_table(&num);
Richard Spiegel2db06bb2018-04-20 16:50:12 -0700139 if (gpes != NULL)
140 gpe_configure_sci(gpes, num);
Martin Roth6c14cd32018-01-11 16:25:28 -0800141
Daniel Kurtzf5e37752018-02-01 15:58:40 -0700142 /* Initialize i2c busses that were not initialized in bootblock */
143 i2c_soc_init();
144
Martin Roth6c14cd32018-01-11 16:25:28 -0800145 /* Set GenIntDisable so that GPIO 90 is configured as a GPIO. */
Martin Rothb250b232018-06-02 21:30:21 -0600146 pm_write8(PM_PCIB_CFG, pm_read8(PM_PCIB_CFG) | PM_GENINT_DISABLE);
Simon Glass4f160492018-05-23 15:34:04 -0600147
148 /* Set low-power mode for BayHub eMMC bridge's PCIe clock. */
Julius Werner55009af2019-12-02 22:03:27 -0800149 clrsetbits32((uint32_t *)(ACPIMMIO_MISC_BASE + GPP_CLK_CNTRL),
150 GPP_CLK2_REQ_MAP_MASK,
151 GPP_CLK2_REQ_MAP_CLK_REQ2 <<
152 GPP_CLK2_REQ_MAP_SHIFT);
Simon Glasse5771682018-07-11 15:51:27 -0600153
154 /* Same for the WiFi */
Julius Werner55009af2019-12-02 22:03:27 -0800155 clrsetbits32((uint32_t *)(ACPIMMIO_MISC_BASE + GPP_CLK_CNTRL),
156 GPP_CLK0_REQ_MAP_MASK,
157 GPP_CLK0_REQ_MAP_CLK_REQ0 <<
158 GPP_CLK0_REQ_MAP_SHIFT);
Marc Jones9ad593b2017-06-22 22:19:55 -0600159}
Marc Jones2d79f162017-05-22 21:35:16 -0600160
161/*************************************************
Marshall Dawsonbeb12882017-05-23 18:57:47 -0600162 * Dedicated mainboard function
Marc Jones2d79f162017-05-22 21:35:16 -0600163 *************************************************/
Elyes HAOUASd129d432018-05-04 20:23:33 +0200164static void kahlee_enable(struct device *dev)
Marc Jones2d79f162017-05-22 21:35:16 -0600165{
166 printk(BIOS_INFO, "Mainboard "
167 CONFIG_MAINBOARD_PART_NUMBER " Enable.\n");
168
169 /* Initialize the PIRQ data structures for consumption */
170 pirq_setup();
Marc Jones0a15ed52017-06-22 22:22:20 -0600171
Nico Huber68680dd2020-03-31 17:34:52 +0200172 dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator;
Marc Jones2d79f162017-05-22 21:35:16 -0600173}
174
Marc Jones067031e2017-11-02 11:36:53 -0600175
176static void mainboard_final(void *chip_info)
177{
178 struct global_nvs_t *gnvs;
179
180 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
181
182 if (gnvs) {
183 gnvs->tmps = CTL_TDP_SENSOR_ID;
184 gnvs->tcrt = CRITICAL_TEMPERATURE;
185 gnvs->tpsv = PASSIVE_TEMPERATURE;
186 }
187}
188
Marc Jonesdf6b51b2017-11-29 20:07:46 -0700189int mainboard_get_xhci_oc_map(uint16_t *map)
190{
191 return variant_get_xhci_oc_map(map);
192}
193
194int mainboard_get_ehci_oc_map(uint16_t *map)
195{
196 return variant_get_ehci_oc_map(map);
197}
198
Marc Jonesf3dc6592018-07-14 17:27:35 -0600199void mainboard_suspend_resume(void)
200{
201 variant_mainboard_suspend_resume();
202}
Marc Jonesf3dc6592018-07-14 17:27:35 -0600203
Marc Jones2d79f162017-05-22 21:35:16 -0600204struct chip_operations mainboard_ops = {
Marc Jones9ad593b2017-06-22 22:19:55 -0600205 .init = mainboard_init,
Marc Jones2d79f162017-05-22 21:35:16 -0600206 .enable_dev = kahlee_enable,
Marc Jones067031e2017-11-02 11:36:53 -0600207 .final = mainboard_final,
Marc Jones2d79f162017-05-22 21:35:16 -0600208};
Simon Glassb5c51772018-03-05 12:18:40 -0700209
Marc Jonesf3dc6592018-07-14 17:27:35 -0600210/* Variants may override these functions so see definitions in variants/ */
Aaron Durbin64031672018-04-21 14:45:32 -0600211uint8_t __weak variant_board_sku(void)
Simon Glassb5c51772018-03-05 12:18:40 -0700212{
213 return 0;
214}
215
Marc Jonesf3dc6592018-07-14 17:27:35 -0600216void __weak variant_mainboard_suspend_resume(void)
217{
218}
Marc Jonesf3dc6592018-07-14 17:27:35 -0600219
Nico Huberebd8a4f2017-11-01 09:49:16 +0100220const char *smbios_system_sku(void)
Simon Glassb5c51772018-03-05 12:18:40 -0700221{
222 static char sku_str[7]; /* sku{0..255} */
223
224 snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku());
225
226 return sku_str;
227}