blob: b69af780656bf2e3424b68d4f5d02be341c4ee19 [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>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -07008#include <amdblocks/agesawrapper.h>
Richard Spiegel2bbc3dc2017-12-06 16:14:58 -07009#include <amdblocks/amd_pci_util.h>
Felix Helda5a52952020-12-01 18:14:01 +010010#include <amdblocks/smi.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>
Richard Spiegel9dc56002017-12-18 16:25:42 -070014#include <soc/pci_devs.h>
Marc Jonesdf6b51b2017-11-29 20:07:46 -070015#include <soc/southbridge.h>
Marshall Dawson251d3052019-05-02 17:27:57 -060016#include <soc/smi.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060017#include <amdblocks/acpimmio.h>
Martin Roth6c623ca2017-11-16 22:14:53 -070018#include <variant/ec.h>
Marc Jones067031e2017-11-02 11:36:53 -060019#include <variant/thermal.h>
Marc Jones0a15ed52017-06-22 22:22:20 -060020#include <vendorcode/google/chromeos/chromeos.h>
Marc Jones2d79f162017-05-22 21:35:16 -060021
22/***********************************************************
23 * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01.
24 * This table is responsible for physically routing the PIC and
25 * IOAPIC IRQs to the different PCI devices on the system. It
26 * is read and written via registers 0xC00/0xC01 as an
27 * Index/Data pair. These values are chipset and mainboard
28 * dependent and should be updated accordingly.
29 *
30 * These values are used by the PCI configuration space,
31 * MP Tables. TODO: Make ACPI use these values too.
32 */
Martin Roth6c14cd32018-01-11 16:25:28 -080033
Kyösti Mälkkie1e32892019-12-22 09:49:56 +020034static const u8 mainboard_picr_data[] = {
Martin Roth6c14cd32018-01-11 16:25:28 -080035 [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x1F, 0x1F, 0x1F,
36 [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
Richard Spiegel8f825e02018-02-12 08:36:10 -070037 [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03,
Martin Roth6c14cd32018-01-11 16:25:28 -080038 [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
40 [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05,
42 [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Richard Spiegel8f825e02018-02-12 08:36:10 -070043 [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Martin Roth6c14cd32018-01-11 16:25:28 -080044 [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F,
46 [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
47 [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
48 [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
49 [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
50 [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
51};
Marc Jones2d79f162017-05-22 21:35:16 -060052
Kyösti Mälkkie1e32892019-12-22 09:49:56 +020053static const u8 mainboard_intr_data[] = {
Martin Roth6c14cd32018-01-11 16:25:28 -080054 [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x1F, 0x16, 0x17,
55 [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
56 [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10,
57 [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
58 [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
59 [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00,
61 [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00,
65 [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
67 [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
69 [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70};
Richard Spiegel9dc56002017-12-18 16:25:42 -070071
72/*
73 * This table defines the index into the picr/intr_data tables for each
74 * device. Any enabled device and slot that uses hardware interrupts should
75 * have an entry in this table to define its index into the FCH PCI_INTR
76 * register 0xC00/0xC01. This index will define the interrupt that it should
77 * use. Putting PIRQ_A into the PIN A index for a device will tell that
78 * device to use PIC IRQ 10 if it uses PIN A for its hardware INT.
79 */
80static const struct pirq_struct mainboard_pirq_data[] = {
81 { PCIE0_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } },
82 { PCIE1_DEVFN, { PIRQ_B, PIRQ_C, PIRQ_D, PIRQ_A } },
83 { PCIE2_DEVFN, { PIRQ_C, PIRQ_D, PIRQ_A, PIRQ_B } },
84 { PCIE3_DEVFN, { PIRQ_D, PIRQ_A, PIRQ_B, PIRQ_C } },
85 { PCIE4_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } },
86 { HDA0_DEVFN, { PIRQ_NC, PIRQ_HDA, PIRQ_NC, PIRQ_NC } },
87 { SD_DEVFN, { PIRQ_SD, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
88 { SMBUS_DEVFN, { PIRQ_SMBUS, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
89 { SATA_DEVFN, { PIRQ_SATA, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
90 { EHCI1_DEVFN, { PIRQ_EHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
91 { XHCI_DEVFN, { PIRQ_XHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } },
92};
93
Marc Jones2d79f162017-05-22 21:35:16 -060094/* PIRQ Setup */
95static void pirq_setup(void)
96{
Richard Spiegel9dc56002017-12-18 16:25:42 -070097 pirq_data_ptr = mainboard_pirq_data;
98 pirq_data_size = ARRAY_SIZE(mainboard_pirq_data);
Marc Jones2d79f162017-05-22 21:35:16 -060099 intr_data_ptr = mainboard_intr_data;
100 picr_data_ptr = mainboard_picr_data;
101}
102
Marc Jones9ad593b2017-06-22 22:19:55 -0600103static void mainboard_init(void *chip_info)
104{
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600105 const struct sci_source *gpes;
106 size_t num;
Marc Jones71f7f0a2017-11-21 23:29:55 -0700107 int boardid = board_id();
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700108 size_t num_gpios;
Richard Spiegel6fcb9b02018-04-18 08:06:33 -0700109 const struct soc_amd_gpio *gpios;
Marc Jones71f7f0a2017-11-21 23:29:55 -0700110
111 printk(BIOS_INFO, "Board ID: %d\n", boardid);
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600112
Marc Jones9ad593b2017-06-22 22:19:55 -0600113 mainboard_ec_init();
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600114
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700115 gpios = variant_gpio_table(&num_gpios);
Marshall Dawson251d3052019-05-02 17:27:57 -0600116 program_gpios(gpios, num_gpios);
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700117
Richard Spiegel2db06bb2018-04-20 16:50:12 -0700118 /*
119 * Some platforms use SCI not generated by a GPIO pin (event above 23).
120 * For these boards, gpe_configure_sci() is still needed, but all GPIO
121 * generated events (23-0) must be removed from gpe_table[].
122 * For boards that only have GPIO generated events, table gpe_table[]
123 * must be removed, and get_gpe_table() should return NULL.
124 */
Marc Jonesb6ac3a22017-10-05 21:57:33 -0600125 gpes = get_gpe_table(&num);
Richard Spiegel2db06bb2018-04-20 16:50:12 -0700126 if (gpes != NULL)
127 gpe_configure_sci(gpes, num);
Martin Roth6c14cd32018-01-11 16:25:28 -0800128
Daniel Kurtzf5e37752018-02-01 15:58:40 -0700129 /* Initialize i2c busses that were not initialized in bootblock */
130 i2c_soc_init();
131
Martin Roth6c14cd32018-01-11 16:25:28 -0800132 /* Set GenIntDisable so that GPIO 90 is configured as a GPIO. */
Martin Rothb250b232018-06-02 21:30:21 -0600133 pm_write8(PM_PCIB_CFG, pm_read8(PM_PCIB_CFG) | PM_GENINT_DISABLE);
Simon Glass4f160492018-05-23 15:34:04 -0600134
135 /* Set low-power mode for BayHub eMMC bridge's PCIe clock. */
Kyösti Mälkki5b672d52019-11-25 21:23:37 +0200136 clrsetbits32(acpimmio_misc + GPP_CLK_CNTRL,
Julius Werner55009af2019-12-02 22:03:27 -0800137 GPP_CLK2_REQ_MAP_MASK,
138 GPP_CLK2_REQ_MAP_CLK_REQ2 <<
139 GPP_CLK2_REQ_MAP_SHIFT);
Simon Glasse5771682018-07-11 15:51:27 -0600140
141 /* Same for the WiFi */
Kyösti Mälkki5b672d52019-11-25 21:23:37 +0200142 clrsetbits32(acpimmio_misc + GPP_CLK_CNTRL,
Julius Werner55009af2019-12-02 22:03:27 -0800143 GPP_CLK0_REQ_MAP_MASK,
144 GPP_CLK0_REQ_MAP_CLK_REQ0 <<
145 GPP_CLK0_REQ_MAP_SHIFT);
Marc Jones9ad593b2017-06-22 22:19:55 -0600146}
Marc Jones2d79f162017-05-22 21:35:16 -0600147
148/*************************************************
Marshall Dawsonbeb12882017-05-23 18:57:47 -0600149 * Dedicated mainboard function
Marc Jones2d79f162017-05-22 21:35:16 -0600150 *************************************************/
Kyösti Mälkki813b2f02021-02-22 06:03:08 +0200151static void mainboard_enable(struct device *dev)
Marc Jones2d79f162017-05-22 21:35:16 -0600152{
153 printk(BIOS_INFO, "Mainboard "
154 CONFIG_MAINBOARD_PART_NUMBER " Enable.\n");
155
156 /* Initialize the PIRQ data structures for consumption */
157 pirq_setup();
Marc Jones0a15ed52017-06-22 22:22:20 -0600158
Nico Huber68680dd2020-03-31 17:34:52 +0200159 dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator;
Marc Jones2d79f162017-05-22 21:35:16 -0600160}
161
Marc Jonesdf6b51b2017-11-29 20:07:46 -0700162int mainboard_get_xhci_oc_map(uint16_t *map)
163{
164 return variant_get_xhci_oc_map(map);
165}
166
167int mainboard_get_ehci_oc_map(uint16_t *map)
168{
169 return variant_get_ehci_oc_map(map);
170}
171
Marc Jonesf3dc6592018-07-14 17:27:35 -0600172void mainboard_suspend_resume(void)
173{
174 variant_mainboard_suspend_resume();
175}
Marc Jonesf3dc6592018-07-14 17:27:35 -0600176
Marc Jones2d79f162017-05-22 21:35:16 -0600177struct chip_operations mainboard_ops = {
Marc Jones9ad593b2017-06-22 22:19:55 -0600178 .init = mainboard_init,
Kyösti Mälkki813b2f02021-02-22 06:03:08 +0200179 .enable_dev = mainboard_enable,
Marc Jones2d79f162017-05-22 21:35:16 -0600180};
Simon Glassb5c51772018-03-05 12:18:40 -0700181
Marc Jonesf3dc6592018-07-14 17:27:35 -0600182/* Variants may override these functions so see definitions in variants/ */
Aaron Durbin64031672018-04-21 14:45:32 -0600183uint8_t __weak variant_board_sku(void)
Simon Glassb5c51772018-03-05 12:18:40 -0700184{
185 return 0;
186}
187
Marc Jonesf3dc6592018-07-14 17:27:35 -0600188void __weak variant_mainboard_suspend_resume(void)
189{
190}
Marc Jonesf3dc6592018-07-14 17:27:35 -0600191
Nico Huberebd8a4f2017-11-01 09:49:16 +0100192const char *smbios_system_sku(void)
Simon Glassb5c51772018-03-05 12:18:40 -0700193{
194 static char sku_str[7]; /* sku{0..255} */
195
196 snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku());
197
198 return sku_str;
199}