Angel Pons | b5a2a52 | 2020-04-05 13:21:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 2 | |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame] | 3 | #include <string.h> |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 6 | #include <device/mmio.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 7 | #include <acpi/acpi.h> |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 8 | #include <acpi/acpi_gnvs.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 9 | #include <amdblocks/agesawrapper.h> |
Richard Spiegel | 2bbc3dc | 2017-12-06 16:14:58 -0700 | [diff] [blame] | 10 | #include <amdblocks/amd_pci_util.h> |
Felix Held | a5a5295 | 2020-12-01 18:14:01 +0100 | [diff] [blame^] | 11 | #include <amdblocks/smi.h> |
Martin Roth | b77bc6f | 2017-11-11 14:33:47 -0700 | [diff] [blame] | 12 | #include <baseboard/variants.h> |
Marc Jones | 71f7f0a | 2017-11-21 23:29:55 -0700 | [diff] [blame] | 13 | #include <boardid.h> |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame] | 14 | #include <smbios.h> |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 15 | #include <soc/nvs.h> |
Richard Spiegel | 9dc5600 | 2017-12-18 16:25:42 -0700 | [diff] [blame] | 16 | #include <soc/pci_devs.h> |
Marc Jones | df6b51b | 2017-11-29 20:07:46 -0700 | [diff] [blame] | 17 | #include <soc/southbridge.h> |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 18 | #include <soc/smi.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 19 | #include <amdblocks/acpimmio.h> |
Martin Roth | 6c623ca | 2017-11-16 22:14:53 -0700 | [diff] [blame] | 20 | #include <variant/ec.h> |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 21 | #include <variant/thermal.h> |
Marc Jones | 0a15ed5 | 2017-06-22 22:22:20 -0600 | [diff] [blame] | 22 | #include <vendorcode/google/chromeos/chromeos.h> |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 23 | |
| 24 | /*********************************************************** |
| 25 | * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01. |
| 26 | * This table is responsible for physically routing the PIC and |
| 27 | * IOAPIC IRQs to the different PCI devices on the system. It |
| 28 | * is read and written via registers 0xC00/0xC01 as an |
| 29 | * Index/Data pair. These values are chipset and mainboard |
| 30 | * dependent and should be updated accordingly. |
| 31 | * |
| 32 | * These values are used by the PCI configuration space, |
| 33 | * MP Tables. TODO: Make ACPI use these values too. |
| 34 | */ |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 35 | |
Kyösti Mälkki | e1e3289 | 2019-12-22 09:49:56 +0200 | [diff] [blame] | 36 | static const u8 mainboard_picr_data[] = { |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 37 | [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x1F, 0x1F, 0x1F, |
| 38 | [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, |
Richard Spiegel | 8f825e0 | 2018-02-12 08:36:10 -0700 | [diff] [blame] | 39 | [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03, |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 40 | [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 41 | [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, |
| 42 | [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 43 | [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05, |
| 44 | [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Richard Spiegel | 8f825e0 | 2018-02-12 08:36:10 -0700 | [diff] [blame] | 45 | [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 46 | [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 47 | [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, |
| 48 | [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 49 | [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 50 | [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 51 | [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F, |
| 52 | [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 53 | }; |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 54 | |
Kyösti Mälkki | e1e3289 | 2019-12-22 09:49:56 +0200 | [diff] [blame] | 55 | static const u8 mainboard_intr_data[] = { |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 56 | [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x1F, 0x16, 0x17, |
| 57 | [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, |
| 58 | [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10, |
| 59 | [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 60 | [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, |
| 61 | [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 62 | [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00, |
| 63 | [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 64 | [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 65 | [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 66 | [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, |
| 67 | [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 68 | [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 69 | [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 70 | [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F, |
| 71 | [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 72 | }; |
Richard Spiegel | 9dc5600 | 2017-12-18 16:25:42 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * This table defines the index into the picr/intr_data tables for each |
| 76 | * device. Any enabled device and slot that uses hardware interrupts should |
| 77 | * have an entry in this table to define its index into the FCH PCI_INTR |
| 78 | * register 0xC00/0xC01. This index will define the interrupt that it should |
| 79 | * use. Putting PIRQ_A into the PIN A index for a device will tell that |
| 80 | * device to use PIC IRQ 10 if it uses PIN A for its hardware INT. |
| 81 | */ |
| 82 | static const struct pirq_struct mainboard_pirq_data[] = { |
| 83 | { PCIE0_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } }, |
| 84 | { PCIE1_DEVFN, { PIRQ_B, PIRQ_C, PIRQ_D, PIRQ_A } }, |
| 85 | { PCIE2_DEVFN, { PIRQ_C, PIRQ_D, PIRQ_A, PIRQ_B } }, |
| 86 | { PCIE3_DEVFN, { PIRQ_D, PIRQ_A, PIRQ_B, PIRQ_C } }, |
| 87 | { PCIE4_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } }, |
| 88 | { HDA0_DEVFN, { PIRQ_NC, PIRQ_HDA, PIRQ_NC, PIRQ_NC } }, |
| 89 | { SD_DEVFN, { PIRQ_SD, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 90 | { SMBUS_DEVFN, { PIRQ_SMBUS, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 91 | { SATA_DEVFN, { PIRQ_SATA, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 92 | { EHCI1_DEVFN, { PIRQ_EHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 93 | { XHCI_DEVFN, { PIRQ_XHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 94 | }; |
| 95 | |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 96 | /* PIRQ Setup */ |
| 97 | static void pirq_setup(void) |
| 98 | { |
Richard Spiegel | 9dc5600 | 2017-12-18 16:25:42 -0700 | [diff] [blame] | 99 | pirq_data_ptr = mainboard_pirq_data; |
| 100 | pirq_data_size = ARRAY_SIZE(mainboard_pirq_data); |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 101 | intr_data_ptr = mainboard_intr_data; |
| 102 | picr_data_ptr = mainboard_picr_data; |
| 103 | } |
| 104 | |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 105 | static void mainboard_init(void *chip_info) |
| 106 | { |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 107 | const struct sci_source *gpes; |
| 108 | size_t num; |
Marc Jones | 71f7f0a | 2017-11-21 23:29:55 -0700 | [diff] [blame] | 109 | int boardid = board_id(); |
Justin TerAvest | 3fe3f04 | 2018-02-14 19:10:15 -0700 | [diff] [blame] | 110 | size_t num_gpios; |
Richard Spiegel | 6fcb9b0 | 2018-04-18 08:06:33 -0700 | [diff] [blame] | 111 | const struct soc_amd_gpio *gpios; |
Marc Jones | 71f7f0a | 2017-11-21 23:29:55 -0700 | [diff] [blame] | 112 | |
| 113 | printk(BIOS_INFO, "Board ID: %d\n", boardid); |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 114 | |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 115 | mainboard_ec_init(); |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 116 | |
Justin TerAvest | 3fe3f04 | 2018-02-14 19:10:15 -0700 | [diff] [blame] | 117 | gpios = variant_gpio_table(&num_gpios); |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 118 | program_gpios(gpios, num_gpios); |
Justin TerAvest | 3fe3f04 | 2018-02-14 19:10:15 -0700 | [diff] [blame] | 119 | |
Richard Spiegel | 2db06bb | 2018-04-20 16:50:12 -0700 | [diff] [blame] | 120 | /* |
| 121 | * Some platforms use SCI not generated by a GPIO pin (event above 23). |
| 122 | * For these boards, gpe_configure_sci() is still needed, but all GPIO |
| 123 | * generated events (23-0) must be removed from gpe_table[]. |
| 124 | * For boards that only have GPIO generated events, table gpe_table[] |
| 125 | * must be removed, and get_gpe_table() should return NULL. |
| 126 | */ |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 127 | gpes = get_gpe_table(&num); |
Richard Spiegel | 2db06bb | 2018-04-20 16:50:12 -0700 | [diff] [blame] | 128 | if (gpes != NULL) |
| 129 | gpe_configure_sci(gpes, num); |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 130 | |
Daniel Kurtz | f5e3775 | 2018-02-01 15:58:40 -0700 | [diff] [blame] | 131 | /* Initialize i2c busses that were not initialized in bootblock */ |
| 132 | i2c_soc_init(); |
| 133 | |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 134 | /* Set GenIntDisable so that GPIO 90 is configured as a GPIO. */ |
Martin Roth | b250b23 | 2018-06-02 21:30:21 -0600 | [diff] [blame] | 135 | pm_write8(PM_PCIB_CFG, pm_read8(PM_PCIB_CFG) | PM_GENINT_DISABLE); |
Simon Glass | 4f16049 | 2018-05-23 15:34:04 -0600 | [diff] [blame] | 136 | |
| 137 | /* Set low-power mode for BayHub eMMC bridge's PCIe clock. */ |
Kyösti Mälkki | 5b672d5 | 2019-11-25 21:23:37 +0200 | [diff] [blame] | 138 | clrsetbits32(acpimmio_misc + GPP_CLK_CNTRL, |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 139 | GPP_CLK2_REQ_MAP_MASK, |
| 140 | GPP_CLK2_REQ_MAP_CLK_REQ2 << |
| 141 | GPP_CLK2_REQ_MAP_SHIFT); |
Simon Glass | e577168 | 2018-07-11 15:51:27 -0600 | [diff] [blame] | 142 | |
| 143 | /* Same for the WiFi */ |
Kyösti Mälkki | 5b672d5 | 2019-11-25 21:23:37 +0200 | [diff] [blame] | 144 | clrsetbits32(acpimmio_misc + GPP_CLK_CNTRL, |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 145 | GPP_CLK0_REQ_MAP_MASK, |
| 146 | GPP_CLK0_REQ_MAP_CLK_REQ0 << |
| 147 | GPP_CLK0_REQ_MAP_SHIFT); |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 148 | } |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 149 | |
| 150 | /************************************************* |
Marshall Dawson | beb1288 | 2017-05-23 18:57:47 -0600 | [diff] [blame] | 151 | * Dedicated mainboard function |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 152 | *************************************************/ |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 153 | static void kahlee_enable(struct device *dev) |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 154 | { |
| 155 | printk(BIOS_INFO, "Mainboard " |
| 156 | CONFIG_MAINBOARD_PART_NUMBER " Enable.\n"); |
| 157 | |
| 158 | /* Initialize the PIRQ data structures for consumption */ |
| 159 | pirq_setup(); |
Marc Jones | 0a15ed5 | 2017-06-22 22:22:20 -0600 | [diff] [blame] | 160 | |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 161 | dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator; |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 162 | } |
| 163 | |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 164 | static void mainboard_final(void *chip_info) |
| 165 | { |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 166 | struct global_nvs *gnvs; |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 167 | |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 168 | gnvs = acpi_get_gnvs(); |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 169 | |
| 170 | if (gnvs) { |
| 171 | gnvs->tmps = CTL_TDP_SENSOR_ID; |
| 172 | gnvs->tcrt = CRITICAL_TEMPERATURE; |
| 173 | gnvs->tpsv = PASSIVE_TEMPERATURE; |
| 174 | } |
| 175 | } |
| 176 | |
Marc Jones | df6b51b | 2017-11-29 20:07:46 -0700 | [diff] [blame] | 177 | int mainboard_get_xhci_oc_map(uint16_t *map) |
| 178 | { |
| 179 | return variant_get_xhci_oc_map(map); |
| 180 | } |
| 181 | |
| 182 | int mainboard_get_ehci_oc_map(uint16_t *map) |
| 183 | { |
| 184 | return variant_get_ehci_oc_map(map); |
| 185 | } |
| 186 | |
Marc Jones | f3dc659 | 2018-07-14 17:27:35 -0600 | [diff] [blame] | 187 | void mainboard_suspend_resume(void) |
| 188 | { |
| 189 | variant_mainboard_suspend_resume(); |
| 190 | } |
Marc Jones | f3dc659 | 2018-07-14 17:27:35 -0600 | [diff] [blame] | 191 | |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 192 | struct chip_operations mainboard_ops = { |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 193 | .init = mainboard_init, |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 194 | .enable_dev = kahlee_enable, |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 195 | .final = mainboard_final, |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 196 | }; |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame] | 197 | |
Marc Jones | f3dc659 | 2018-07-14 17:27:35 -0600 | [diff] [blame] | 198 | /* Variants may override these functions so see definitions in variants/ */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 199 | uint8_t __weak variant_board_sku(void) |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame] | 200 | { |
| 201 | return 0; |
| 202 | } |
| 203 | |
Marc Jones | f3dc659 | 2018-07-14 17:27:35 -0600 | [diff] [blame] | 204 | void __weak variant_mainboard_suspend_resume(void) |
| 205 | { |
| 206 | } |
Marc Jones | f3dc659 | 2018-07-14 17:27:35 -0600 | [diff] [blame] | 207 | |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 208 | const char *smbios_system_sku(void) |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame] | 209 | { |
| 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 | } |