Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpigen.h> |
Raul E Rangel | 6fce9cd | 2021-04-06 15:42:51 -0600 | [diff] [blame] | 5 | #include <amdblocks/acpimmio.h> |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 6 | #include <amdblocks/amd_pci_util.h> |
Raul E Rangel | d1a42b6 | 2022-08-10 15:28:15 -0600 | [diff] [blame] | 7 | #include <amdblocks/psp.h> |
Robert Zieba | dd40122 | 2022-10-04 12:34:40 -0600 | [diff] [blame] | 8 | #include <amdblocks/xhci.h> |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 9 | #include <baseboard/variants.h> |
Kyösti Mälkki | 89a5f0f | 2021-06-15 07:22:22 +0300 | [diff] [blame] | 10 | #include <console/console.h> |
Robert Zieba | dd40122 | 2022-10-04 12:34:40 -0600 | [diff] [blame] | 11 | #include <cpu/x86/smm.h> |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 12 | #include <device/device.h> |
Raul E Rangel | d1a42b6 | 2022-08-10 15:28:15 -0600 | [diff] [blame] | 13 | #include <drivers/i2c/tpm/chip.h> |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 14 | #include <gpio.h> |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 15 | #include <soc/acpi.h> |
Mathew King | ad83023 | 2021-02-23 13:08:15 -0700 | [diff] [blame] | 16 | #include <variant/ec.h> |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 17 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 18 | #define BACKLIGHT_GPIO GPIO_129 |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame] | 19 | #define WWAN_AUX_RST_GPIO GPIO_18 |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 20 | #define METHOD_BACKLIGHT_ENABLE "\\_SB.BKEN" |
| 21 | #define METHOD_BACKLIGHT_DISABLE "\\_SB.BKDS" |
| 22 | #define METHOD_MAINBOARD_INI "\\_SB.MINI" |
| 23 | #define METHOD_MAINBOARD_WAK "\\_SB.MWAK" |
| 24 | #define METHOD_MAINBOARD_PTS "\\_SB.MPTS" |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame] | 25 | #define METHOD_MAINBOARD_S0X "\\_SB.MS0X" |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 26 | |
Felix Held | cf92ecf | 2022-10-26 00:59:13 +0200 | [diff] [blame] | 27 | /* The IRQ mapping in fch_irq_map ends up getting written to the indirect address space that is |
| 28 | accessed via I/O ports 0xc00/0xc01. */ |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * This controls the device -> IRQ routing. |
| 32 | * |
| 33 | * Hardcoded IRQs: |
| 34 | * 0: timer < soc/amd/common/acpi/lpc.asl |
| 35 | * 1: i8042 - Keyboard |
| 36 | * 2: cascade |
| 37 | * 8: rtc0 <- soc/amd/common/acpi/lpc.asl |
| 38 | * 9: acpi <- soc/amd/common/acpi/lpc.asl |
| 39 | */ |
Felix Held | 067f703 | 2022-10-25 23:30:43 +0200 | [diff] [blame] | 40 | static const struct fch_irq_routing fch_irq_map[] = { |
Raul E Rangel | 6d9a0ea | 2021-05-04 14:29:09 -0600 | [diff] [blame] | 41 | { PIRQ_A, 12, PIRQ_NC }, |
| 42 | { PIRQ_B, 14, PIRQ_NC }, |
| 43 | { PIRQ_C, 15, PIRQ_NC }, |
| 44 | { PIRQ_D, 12, PIRQ_NC }, |
| 45 | { PIRQ_E, 14, PIRQ_NC }, |
| 46 | { PIRQ_F, 15, PIRQ_NC }, |
| 47 | { PIRQ_G, 12, PIRQ_NC }, |
| 48 | { PIRQ_H, 14, PIRQ_NC }, |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 49 | |
| 50 | { PIRQ_SCI, ACPI_SCI_IRQ, ACPI_SCI_IRQ }, |
| 51 | { PIRQ_SD, PIRQ_NC, PIRQ_NC }, |
| 52 | { PIRQ_SDIO, PIRQ_NC, PIRQ_NC }, |
| 53 | { PIRQ_SATA, PIRQ_NC, PIRQ_NC }, |
| 54 | { PIRQ_EMMC, PIRQ_NC, PIRQ_NC }, |
Raul E Rangel | cce7d82 | 2021-03-30 15:50:43 -0600 | [diff] [blame] | 55 | { PIRQ_GPIO, 11, 11 }, |
| 56 | { PIRQ_I2C0, 10, 10 }, |
| 57 | { PIRQ_I2C1, 7, 7 }, |
| 58 | { PIRQ_I2C2, 6, 6 }, |
| 59 | { PIRQ_I2C3, 5, 5 }, |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 60 | { PIRQ_UART0, 4, 4 }, |
| 61 | { PIRQ_UART1, 3, 3 }, |
| 62 | |
| 63 | /* The MISC registers are not interrupt numbers */ |
| 64 | { PIRQ_MISC, 0xfa, 0x00 }, |
| 65 | { PIRQ_MISC0, 0x91, 0x00 }, |
| 66 | { PIRQ_HPET_L, 0x00, 0x00 }, |
| 67 | { PIRQ_HPET_H, 0x00, 0x00 }, |
| 68 | }; |
| 69 | |
Felix Held | cf92ecf | 2022-10-26 00:59:13 +0200 | [diff] [blame] | 70 | const struct fch_irq_routing *mb_get_fch_irq_mapping(size_t *length) |
Felix Held | df14a02 | 2022-10-25 23:42:15 +0200 | [diff] [blame] | 71 | { |
| 72 | *length = ARRAY_SIZE(fch_irq_map); |
| 73 | return fch_irq_map; |
| 74 | } |
| 75 | |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 76 | static void mainboard_configure_gpios(void) |
| 77 | { |
| 78 | size_t base_num_gpios, override_num_gpios; |
| 79 | const struct soc_amd_gpio *base_gpios, *override_gpios; |
| 80 | |
Matt DeVillier | 2f4b31f | 2022-09-23 13:28:05 -0500 | [diff] [blame] | 81 | base_gpios = baseboard_gpio_table(&base_num_gpios); |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 82 | override_gpios = variant_override_gpio_table(&override_num_gpios); |
| 83 | |
| 84 | gpio_configure_pads_with_override(base_gpios, base_num_gpios, override_gpios, |
| 85 | override_num_gpios); |
| 86 | } |
| 87 | |
Karthikeyan Ramasubramanian | b418298 | 2021-10-26 16:55:35 -0600 | [diff] [blame] | 88 | void __weak variant_devtree_update(void) |
| 89 | { |
| 90 | } |
| 91 | |
Raul E Rangel | d1a42b6 | 2022-08-10 15:28:15 -0600 | [diff] [blame] | 92 | static void configure_psp_tpm_gpio(void) |
| 93 | { |
| 94 | const struct device *cr50_dev = DEV_PTR(cr50); |
| 95 | struct drivers_i2c_tpm_config *cfg = config_of(cr50_dev); |
| 96 | |
| 97 | psp_set_tpm_irq_gpio(cfg->irq_gpio.pins[0]); |
| 98 | } |
| 99 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 100 | static void mainboard_init(void *chip_info) |
| 101 | { |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 102 | mainboard_configure_gpios(); |
Mathew King | ad83023 | 2021-02-23 13:08:15 -0700 | [diff] [blame] | 103 | mainboard_ec_init(); |
Karthikeyan Ramasubramanian | b418298 | 2021-10-26 16:55:35 -0600 | [diff] [blame] | 104 | variant_devtree_update(); |
Raul E Rangel | d1a42b6 | 2022-08-10 15:28:15 -0600 | [diff] [blame] | 105 | |
| 106 | /* Run this after variant_devtree_update so the IRQ is correct. */ |
| 107 | configure_psp_tpm_gpio(); |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 110 | static void mainboard_write_blken(void) |
| 111 | { |
| 112 | acpigen_write_method(METHOD_BACKLIGHT_ENABLE, 0); |
| 113 | acpigen_soc_clear_tx_gpio(BACKLIGHT_GPIO); |
| 114 | acpigen_pop_len(); |
| 115 | } |
| 116 | |
| 117 | static void mainboard_write_blkdis(void) |
| 118 | { |
| 119 | acpigen_write_method(METHOD_BACKLIGHT_DISABLE, 0); |
| 120 | acpigen_soc_set_tx_gpio(BACKLIGHT_GPIO); |
| 121 | acpigen_pop_len(); |
| 122 | } |
| 123 | |
| 124 | static void mainboard_write_mini(void) |
| 125 | { |
| 126 | acpigen_write_method(METHOD_MAINBOARD_INI, 0); |
| 127 | acpigen_emit_namestring(METHOD_BACKLIGHT_ENABLE); |
| 128 | acpigen_pop_len(); |
| 129 | } |
| 130 | |
| 131 | static void mainboard_write_mwak(void) |
| 132 | { |
| 133 | acpigen_write_method(METHOD_MAINBOARD_WAK, 0); |
| 134 | acpigen_emit_namestring(METHOD_BACKLIGHT_ENABLE); |
| 135 | acpigen_pop_len(); |
| 136 | } |
| 137 | |
| 138 | static void mainboard_write_mpts(void) |
| 139 | { |
| 140 | acpigen_write_method(METHOD_MAINBOARD_PTS, 0); |
| 141 | acpigen_emit_namestring(METHOD_BACKLIGHT_DISABLE); |
| 142 | acpigen_pop_len(); |
| 143 | } |
| 144 | |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame] | 145 | static void mainboard_assert_wwan_aux_reset(void) |
| 146 | { |
| 147 | if (variant_has_pcie_wwan()) |
| 148 | acpigen_soc_clear_tx_gpio(WWAN_AUX_RST_GPIO); |
| 149 | } |
| 150 | |
| 151 | static void mainboard_deassert_wwan_aux_reset(void) |
| 152 | { |
| 153 | if (variant_has_pcie_wwan()) |
| 154 | acpigen_soc_set_tx_gpio(WWAN_AUX_RST_GPIO); |
| 155 | } |
| 156 | |
| 157 | static void mainboard_write_ms0x(void) |
| 158 | { |
| 159 | acpigen_write_method_serialized(METHOD_MAINBOARD_S0X, 1); |
| 160 | /* S0ix Entry */ |
| 161 | acpigen_write_if_lequal_op_int(ARG0_OP, 1); |
| 162 | mainboard_assert_wwan_aux_reset(); |
| 163 | /* S0ix Exit */ |
| 164 | acpigen_write_else(); |
| 165 | mainboard_deassert_wwan_aux_reset(); |
| 166 | acpigen_pop_len(); |
| 167 | acpigen_pop_len(); |
| 168 | } |
| 169 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 170 | static void mainboard_fill_ssdt(const struct device *dev) |
| 171 | { |
| 172 | mainboard_write_blken(); |
| 173 | mainboard_write_blkdis(); |
| 174 | mainboard_write_mini(); |
| 175 | mainboard_write_mpts(); |
| 176 | mainboard_write_mwak(); |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame] | 177 | mainboard_write_ms0x(); |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 178 | } |
| 179 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 180 | static void mainboard_enable(struct device *dev) |
| 181 | { |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 182 | dev->ops->acpi_fill_ssdt = mainboard_fill_ssdt; |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 183 | |
Raul E Rangel | 6fce9cd | 2021-04-06 15:42:51 -0600 | [diff] [blame] | 184 | /* TODO: b/184678786 - Move into espi_config */ |
| 185 | /* Unmask eSPI IRQ 1 (Keyboard) */ |
| 186 | pm_write32(PM_ESPI_INTR_CTRL, PM_ESPI_DEV_INTR_MASK & ~(BIT(1))); |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Robert Zieba | dd40122 | 2022-10-04 12:34:40 -0600 | [diff] [blame] | 189 | void smm_mainboard_pci_resource_store_init(struct smm_pci_resource_info *slots, size_t size) |
| 190 | { |
| 191 | soc_xhci_store_resources(slots, size); |
| 192 | } |
| 193 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 194 | struct chip_operations mainboard_ops = { |
| 195 | .init = mainboard_init, |
| 196 | .enable_dev = mainboard_enable, |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 197 | }; |