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