blob: 5e1bdf4c2d0c35b6c1a565d682a32b5fb5bbd420 [file] [log] [blame]
Angel Ponsb5a2a522020-04-05 13:21:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones2d79f162017-05-22 21:35:16 -06002
Simon Glassb5c51772018-03-05 12:18:40 -07003#include <string.h>
Marc Jones2d79f162017-05-22 21:35:16 -06004#include <console/console.h>
5#include <device/device.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02006#include <device/mmio.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07007#include <acpi/acpi.h>
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +03008#include <acpi/acpi_gnvs.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -07009#include <amdblocks/agesawrapper.h>
Richard Spiegel2bbc3dc2017-12-06 16:14:58 -070010#include <amdblocks/amd_pci_util.h>
Martin Rothb77bc6f2017-11-11 14:33:47 -070011#include <baseboard/variants.h>
Marc Jones71f7f0a2017-11-21 23:29:55 -070012#include <boardid.h>
Simon Glassb5c51772018-03-05 12:18:40 -070013#include <smbios.h>
Marc Jones067031e2017-11-02 11:36:53 -060014#include <soc/nvs.h>
Richard Spiegel9dc56002017-12-18 16:25:42 -070015#include <soc/pci_devs.h>
Marc Jonesdf6b51b2017-11-29 20:07:46 -070016#include <soc/southbridge.h>
Marshall Dawson251d3052019-05-02 17:27:57 -060017#include <soc/smi.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060018#include <amdblocks/acpimmio.h>
Martin Roth6c623ca2017-11-16 22:14:53 -070019#include <variant/ec.h>
Marc Jones067031e2017-11-02 11:36:53 -060020#include <variant/thermal.h>
Marc Jones0a15ed52017-06-22 22:22:20 -060021#include <vendorcode/google/chromeos/chromeos.h>
Marc Jones2d79f162017-05-22 21:35:16 -060022
23/***********************************************************
24 * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01.
25 * This table is responsible for physically routing the PIC and
26 * IOAPIC IRQs to the different PCI devices on the system. It
27 * is read and written via registers 0xC00/0xC01 as an
28 * Index/Data pair. These values are chipset and mainboard
29 * dependent and should be updated accordingly.
30 *
31 * These values are used by the PCI configuration space,
32 * MP Tables. TODO: Make ACPI use these values too.
33 */
Martin Roth6c14cd32018-01-11 16:25:28 -080034
Kyösti Mälkkie1e32892019-12-22 09:49:56 +020035static const u8 mainboard_picr_data[] = {
Martin Roth6c14cd32018-01-11 16:25:28 -080036 [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x1F, 0x1F, 0x1F,
37 [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
Richard Spiegel8f825e02018-02-12 08:36:10 -070038 [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03,
Martin Roth6c14cd32018-01-11 16:25:28 -080039 [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
41 [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05,
43 [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Richard Spiegel8f825e02018-02-12 08:36:10 -070044 [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Martin Roth6c14cd32018-01-11 16:25:28 -080045 [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F,
47 [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
48 [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
49 [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
50 [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
51 [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
52};
Marc Jones2d79f162017-05-22 21:35:16 -060053
Kyösti Mälkkie1e32892019-12-22 09:49:56 +020054static const u8 mainboard_intr_data[] = {
Martin Roth6c14cd32018-01-11 16:25:28 -080055 [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x1F, 0x16, 0x17,
56 [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
57 [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10,
58 [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
59 [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
60 [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00,
62 [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00,
66 [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
68 [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
70 [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71};
Richard Spiegel9dc56002017-12-18 16:25:42 -070072
73/*
74 * This table defines the index into the picr/intr_data tables for each
75 * device. Any enabled device and slot that uses hardware interrupts should
76 * have an entry in this table to define its index into the FCH PCI_INTR
77 * register 0xC00/0xC01. This index will define the interrupt that it should
78 * use. Putting PIRQ_A into the PIN A index for a device will tell that
79 * device to use PIC IRQ 10 if it uses PIN A for its hardware INT.
80 */
81static const struct pirq_struct mainboard_pirq_data[] = {
82 { PCIE0_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } },
83 { PCIE1_DEVFN, { PIRQ_B, PIRQ_C, PIRQ_D, PIRQ_A } },
84 { PCIE2_DEVFN, { PIRQ_C, PIRQ_D, PIRQ_A, PIRQ_B } },
85 { PCIE3_DEVFN, { PIRQ_D, PIRQ_A, PIRQ_B, PIRQ_C } },
86 { PCIE4_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } },
87 { HDA0_DEVFN, { PIRQ_NC, PIRQ_HDA, PIRQ_NC, PIRQ_NC } },
88 { SD_DEVFN, { PIRQ_SD, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
89 { SMBUS_DEVFN, { PIRQ_SMBUS, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
90 { SATA_DEVFN, { PIRQ_SATA, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
91 { EHCI1_DEVFN, { PIRQ_EHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
92 { XHCI_DEVFN, { PIRQ_XHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
93};
94
Marc Jones2d79f162017-05-22 21:35:16 -060095/* PIRQ Setup */
96static void pirq_setup(void)
97{
Richard Spiegel9dc56002017-12-18 16:25:42 -070098 pirq_data_ptr = mainboard_pirq_data;
99 pirq_data_size = ARRAY_SIZE(mainboard_pirq_data);
Marc Jones2d79f162017-05-22 21:35:16 -0600100 intr_data_ptr = mainboard_intr_data;
101 picr_data_ptr = mainboard_picr_data;
102}
103
Marc Jones9ad593b2017-06-22 22:19:55 -0600104static void mainboard_init(void *chip_info)
105{
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600106 const struct sci_source *gpes;
107 size_t num;
Marc Jones71f7f0a2017-11-21 23:29:55 -0700108 int boardid = board_id();
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700109 size_t num_gpios;
Richard Spiegel6fcb9b02018-04-18 08:06:33 -0700110 const struct soc_amd_gpio *gpios;
Marc Jones71f7f0a2017-11-21 23:29:55 -0700111
112 printk(BIOS_INFO, "Board ID: %d\n", boardid);
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600113
Marc Jones9ad593b2017-06-22 22:19:55 -0600114 mainboard_ec_init();
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600115
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700116 gpios = variant_gpio_table(&num_gpios);
Marshall Dawson251d3052019-05-02 17:27:57 -0600117 program_gpios(gpios, num_gpios);
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700118
Richard Spiegel2db06bb2018-04-20 16:50:12 -0700119 /*
120 * Some platforms use SCI not generated by a GPIO pin (event above 23).
121 * For these boards, gpe_configure_sci() is still needed, but all GPIO
122 * generated events (23-0) must be removed from gpe_table[].
123 * For boards that only have GPIO generated events, table gpe_table[]
124 * must be removed, and get_gpe_table() should return NULL.
125 */
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600126 gpes = get_gpe_table(&num);
Richard Spiegel2db06bb2018-04-20 16:50:12 -0700127 if (gpes != NULL)
128 gpe_configure_sci(gpes, num);
Martin Roth6c14cd32018-01-11 16:25:28 -0800129
Daniel Kurtzf5e37752018-02-01 15:58:40 -0700130 /* Initialize i2c busses that were not initialized in bootblock */
131 i2c_soc_init();
132
Martin Roth6c14cd32018-01-11 16:25:28 -0800133 /* Set GenIntDisable so that GPIO 90 is configured as a GPIO. */
Martin Rothb250b232018-06-02 21:30:21 -0600134 pm_write8(PM_PCIB_CFG, pm_read8(PM_PCIB_CFG) | PM_GENINT_DISABLE);
Simon Glass4f160492018-05-23 15:34:04 -0600135
136 /* Set low-power mode for BayHub eMMC bridge's PCIe clock. */
Kyösti Mälkki5b672d52019-11-25 21:23:37 +0200137 clrsetbits32(acpimmio_misc + GPP_CLK_CNTRL,
Julius Werner55009af2019-12-02 22:03:27 -0800138 GPP_CLK2_REQ_MAP_MASK,
139 GPP_CLK2_REQ_MAP_CLK_REQ2 <<
140 GPP_CLK2_REQ_MAP_SHIFT);
Simon Glasse5771682018-07-11 15:51:27 -0600141
142 /* Same for the WiFi */
Kyösti Mälkki5b672d52019-11-25 21:23:37 +0200143 clrsetbits32(acpimmio_misc + GPP_CLK_CNTRL,
Julius Werner55009af2019-12-02 22:03:27 -0800144 GPP_CLK0_REQ_MAP_MASK,
145 GPP_CLK0_REQ_MAP_CLK_REQ0 <<
146 GPP_CLK0_REQ_MAP_SHIFT);
Marc Jones9ad593b2017-06-22 22:19:55 -0600147}
Marc Jones2d79f162017-05-22 21:35:16 -0600148
149/*************************************************
Marshall Dawsonbeb12882017-05-23 18:57:47 -0600150 * Dedicated mainboard function
Marc Jones2d79f162017-05-22 21:35:16 -0600151 *************************************************/
Elyes HAOUASd129d432018-05-04 20:23:33 +0200152static void kahlee_enable(struct device *dev)
Marc Jones2d79f162017-05-22 21:35:16 -0600153{
154 printk(BIOS_INFO, "Mainboard "
155 CONFIG_MAINBOARD_PART_NUMBER " Enable.\n");
156
157 /* Initialize the PIRQ data structures for consumption */
158 pirq_setup();
Marc Jones0a15ed52017-06-22 22:22:20 -0600159
Nico Huber68680dd2020-03-31 17:34:52 +0200160 dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator;
Marc Jones2d79f162017-05-22 21:35:16 -0600161}
162
Marc Jones067031e2017-11-02 11:36:53 -0600163
164static void mainboard_final(void *chip_info)
165{
166 struct global_nvs_t *gnvs;
167
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +0300168 gnvs = acpi_get_gnvs();
Marc Jones067031e2017-11-02 11:36:53 -0600169
170 if (gnvs) {
171 gnvs->tmps = CTL_TDP_SENSOR_ID;
172 gnvs->tcrt = CRITICAL_TEMPERATURE;
173 gnvs->tpsv = PASSIVE_TEMPERATURE;
174 }
175}
176
Marc Jonesdf6b51b2017-11-29 20:07:46 -0700177int mainboard_get_xhci_oc_map(uint16_t *map)
178{
179 return variant_get_xhci_oc_map(map);
180}
181
182int mainboard_get_ehci_oc_map(uint16_t *map)
183{
184 return variant_get_ehci_oc_map(map);
185}
186
Marc Jonesf3dc6592018-07-14 17:27:35 -0600187void mainboard_suspend_resume(void)
188{
189 variant_mainboard_suspend_resume();
190}
Marc Jonesf3dc6592018-07-14 17:27:35 -0600191
Marc Jones2d79f162017-05-22 21:35:16 -0600192struct chip_operations mainboard_ops = {
Marc Jones9ad593b2017-06-22 22:19:55 -0600193 .init = mainboard_init,
Marc Jones2d79f162017-05-22 21:35:16 -0600194 .enable_dev = kahlee_enable,
Marc Jones067031e2017-11-02 11:36:53 -0600195 .final = mainboard_final,
Marc Jones2d79f162017-05-22 21:35:16 -0600196};
Simon Glassb5c51772018-03-05 12:18:40 -0700197
Marc Jonesf3dc6592018-07-14 17:27:35 -0600198/* Variants may override these functions so see definitions in variants/ */
Aaron Durbin64031672018-04-21 14:45:32 -0600199uint8_t __weak variant_board_sku(void)
Simon Glassb5c51772018-03-05 12:18:40 -0700200{
201 return 0;
202}
203
Marc Jonesf3dc6592018-07-14 17:27:35 -0600204void __weak variant_mainboard_suspend_resume(void)
205{
206}
Marc Jonesf3dc6592018-07-14 17:27:35 -0600207
Nico Huberebd8a4f2017-11-01 09:49:16 +0100208const char *smbios_system_sku(void)
Simon Glassb5c51772018-03-05 12:18:40 -0700209{
210 static char sku_str[7]; /* sku{0..255} */
211
212 snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku());
213
214 return sku_str;
215}