Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Tim Wawrzynczak | c0d7d6b | 2022-02-08 13:03:25 -0700 | [diff] [blame] | 3 | #include <acpi/acpigen.h> |
Eric Lai | af92d07 | 2022-03-14 15:08:27 +0800 | [diff] [blame] | 4 | #include <baseboard/gpio.h> |
Eric Lai | 5e053af | 2020-11-26 12:58:10 +0800 | [diff] [blame] | 5 | #include <baseboard/variants.h> |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 6 | #include <device/device.h> |
Tim Wawrzynczak | c0d7d6b | 2022-02-08 13:03:25 -0700 | [diff] [blame] | 7 | #include <drivers/tpm/cr50.h> |
| 8 | #include <drivers/wwan/fm/chip.h> |
Eric Lai | 78b6a1b | 2020-11-27 14:11:59 +0800 | [diff] [blame] | 9 | #include <ec/ec.h> |
Wisley Chen | b8461aa | 2021-08-25 18:13:59 +0600 | [diff] [blame] | 10 | #include <fw_config.h> |
Tim Wawrzynczak | c0d7d6b | 2022-02-08 13:03:25 -0700 | [diff] [blame] | 11 | #include <security/tpm/tss.h> |
| 12 | #include <soc/gpio.h> |
| 13 | #include <soc/ramstage.h> |
Tim Wawrzynczak | a46056f | 2022-02-17 11:40:54 -0700 | [diff] [blame] | 14 | #include <stdio.h> |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 15 | |
| 16 | WEAK_DEV_PTR(rp6_wwan); |
Tim Wawrzynczak | 52ccd29 | 2022-06-24 15:31:36 -0600 | [diff] [blame] | 17 | WEAK_DEV_PTR(dgpu); |
Wisley Chen | b8461aa | 2021-08-25 18:13:59 +0600 | [diff] [blame] | 18 | |
| 19 | static void add_fw_config_oem_string(const struct fw_config *config, void *arg) |
| 20 | { |
| 21 | struct smbios_type11 *t; |
| 22 | char buffer[64]; |
| 23 | |
| 24 | t = (struct smbios_type11 *)arg; |
| 25 | |
| 26 | snprintf(buffer, sizeof(buffer), "%s-%s", config->field_name, config->option_name); |
| 27 | t->count = smbios_add_string(t->eos, buffer); |
| 28 | } |
| 29 | |
| 30 | static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t) |
| 31 | { |
| 32 | fw_config_for_each_found(add_fw_config_oem_string, t); |
| 33 | } |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 34 | |
Sugnan Prabhu S | 061a93f | 2021-07-18 06:32:52 +0530 | [diff] [blame] | 35 | void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config) |
| 36 | { |
Tim Wawrzynczak | c0d7d6b | 2022-02-08 13:03:25 -0700 | [diff] [blame] | 37 | int ret; |
| 38 | |
| 39 | ret = tlcl_lib_init(); |
| 40 | if (ret != VB2_SUCCESS) { |
| 41 | printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | if (cr50_is_long_interrupt_pulse_enabled()) { |
| 46 | printk(BIOS_INFO, "Enabling GPIO PM b/c CR50 has long IRQ pulse support\n"); |
| 47 | config->gpio_override_pm = 0; |
| 48 | } else { |
| 49 | printk(BIOS_INFO, "Disabling GPIO PM b/c CR50 does not have long IRQ pulse " |
| 50 | "support\n"); |
| 51 | config->gpio_override_pm = 1; |
| 52 | config->gpio_pm[COMM_0] = 0; |
| 53 | config->gpio_pm[COMM_1] = 0; |
| 54 | config->gpio_pm[COMM_2] = 0; |
| 55 | config->gpio_pm[COMM_3] = 0; |
| 56 | config->gpio_pm[COMM_4] = 0; |
| 57 | config->gpio_pm[COMM_5] = 0; |
| 58 | } |
| 59 | |
Sugnan Prabhu S | 061a93f | 2021-07-18 06:32:52 +0530 | [diff] [blame] | 60 | variant_update_soc_chip_config(config); |
| 61 | } |
| 62 | |
Tim Wawrzynczak | 159520e | 2022-03-28 13:23:28 -0600 | [diff] [blame] | 63 | void __weak variant_update_soc_chip_config(struct soc_intel_alderlake_config *config) |
Sugnan Prabhu S | 061a93f | 2021-07-18 06:32:52 +0530 | [diff] [blame] | 64 | { |
| 65 | /* default implementation does nothing */ |
| 66 | } |
| 67 | |
Tim Wawrzynczak | 159520e | 2022-03-28 13:23:28 -0600 | [diff] [blame] | 68 | void __weak variant_init(void) |
Tim Wawrzynczak | a46056f | 2022-02-17 11:40:54 -0700 | [diff] [blame] | 69 | { |
| 70 | /* default implementation does nothing */ |
| 71 | } |
| 72 | |
Eric Lai | a8d2cb8 | 2022-05-27 09:43:43 +0800 | [diff] [blame] | 73 | void __weak fw_config_gpio_padbased_override(struct pad_config *padbased_table) |
| 74 | { |
| 75 | /* default implementation does nothing */ |
| 76 | } |
| 77 | |
Eric Lai | 7aef2b1 | 2022-05-27 09:32:06 +0800 | [diff] [blame] | 78 | void __weak variant_configure_pads(void) |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 79 | { |
Tim Wawrzynczak | 5fed159 | 2021-06-08 14:44:56 -0600 | [diff] [blame] | 80 | const struct pad_config *base_pads; |
| 81 | const struct pad_config *override_pads; |
| 82 | size_t base_num, override_num; |
| 83 | |
| 84 | base_pads = variant_gpio_table(&base_num); |
| 85 | override_pads = variant_gpio_override_table(&override_num); |
| 86 | gpio_configure_pads_with_override(base_pads, base_num, override_pads, override_num); |
Eric Lai | 7aef2b1 | 2022-05-27 09:32:06 +0800 | [diff] [blame] | 87 | } |
Sumeet Pawnikar | 582829d | 2021-07-23 15:50:17 +0530 | [diff] [blame] | 88 | |
Eric Lai | 7aef2b1 | 2022-05-27 09:32:06 +0800 | [diff] [blame] | 89 | static void mainboard_init(void *chip_info) |
| 90 | { |
| 91 | variant_configure_pads(); |
Tim Wawrzynczak | a46056f | 2022-02-17 11:40:54 -0700 | [diff] [blame] | 92 | variant_init(); |
Sumeet Pawnikar | 582829d | 2021-07-23 15:50:17 +0530 | [diff] [blame] | 93 | variant_devtree_update(); |
| 94 | } |
| 95 | |
| 96 | void __weak variant_devtree_update(void) |
| 97 | { |
| 98 | /* Override dev tree settings per board */ |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 99 | } |
| 100 | |
Eric Lai | 78b6a1b | 2020-11-27 14:11:59 +0800 | [diff] [blame] | 101 | static void mainboard_dev_init(struct device *dev) |
| 102 | { |
| 103 | mainboard_ec_init(); |
| 104 | } |
| 105 | |
Tim Wawrzynczak | 52ccd29 | 2022-06-24 15:31:36 -0600 | [diff] [blame] | 106 | static void mainboard_generate_wwan_shutdown(const struct device *dev) |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 107 | { |
| 108 | const struct drivers_wwan_fm_config *config = config_of(dev); |
| 109 | const struct device *parent = dev->bus->dev; |
| 110 | |
| 111 | if (!config) |
| 112 | return; |
| 113 | if (config->rtd3dev) { |
| 114 | acpigen_write_store(); |
| 115 | acpigen_emit_namestring(acpi_device_path_join(parent, "RTD3._STA")); |
| 116 | acpigen_emit_byte(LOCAL0_OP); |
| 117 | acpigen_write_if_lequal_op_int(LOCAL0_OP, ONE_OP); |
| 118 | { |
| 119 | acpigen_emit_namestring(acpi_device_path_join(dev, "DPTS")); |
| 120 | acpigen_emit_byte(ARG0_OP); |
| 121 | } |
| 122 | acpigen_write_if_end(); |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Tim Wawrzynczak | 52ccd29 | 2022-06-24 15:31:36 -0600 | [diff] [blame] | 126 | static void mainboard_generate_dgpu_shutdown(const struct device *dev) |
| 127 | { |
| 128 | /* Call `_OFF` from the Power Resource associated with the dGPU's PEG port. */ |
| 129 | const struct device *parent = dev->bus->dev; |
| 130 | |
| 131 | if (parent) |
| 132 | acpigen_emit_namestring(acpi_device_path_join(parent, "PGPR._OFF")); |
| 133 | } |
| 134 | |
Eric Lai | af92d07 | 2022-03-14 15:08:27 +0800 | [diff] [blame] | 135 | static void mainboard_generate_s0ix_hook(void) |
| 136 | { |
| 137 | acpigen_write_if_lequal_op_int(ARG0_OP, 1); |
| 138 | { |
| 139 | if (CONFIG(HAVE_SLP_S0_GATE)) |
| 140 | acpigen_soc_clear_tx_gpio(GPIO_SLP_S0_GATE); |
| 141 | variant_generate_s0ix_hook(S0IX_ENTRY); |
| 142 | } |
| 143 | acpigen_write_else(); |
| 144 | { |
| 145 | if (CONFIG(HAVE_SLP_S0_GATE)) |
| 146 | acpigen_soc_set_tx_gpio(GPIO_SLP_S0_GATE); |
| 147 | variant_generate_s0ix_hook(S0IX_EXIT); |
| 148 | } |
| 149 | acpigen_write_if_end(); |
| 150 | } |
| 151 | |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 152 | static void mainboard_fill_ssdt(const struct device *dev) |
| 153 | { |
| 154 | const struct device *wwan = DEV_PTR(rp6_wwan); |
Tim Wawrzynczak | 52ccd29 | 2022-06-24 15:31:36 -0600 | [diff] [blame] | 155 | const struct device *dgpu = DEV_PTR(dgpu); |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 156 | |
Tim Wawrzynczak | 52ccd29 | 2022-06-24 15:31:36 -0600 | [diff] [blame] | 157 | acpigen_write_scope("\\_SB"); |
| 158 | acpigen_write_method_serialized("MPTS", 1); |
| 159 | if (wwan) |
| 160 | mainboard_generate_wwan_shutdown(wwan); |
| 161 | if (dgpu) |
| 162 | mainboard_generate_dgpu_shutdown(dgpu); |
| 163 | |
| 164 | acpigen_write_method_end(); /* Method */ |
| 165 | acpigen_write_scope_end(); /* Scope */ |
| 166 | |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 167 | /* for variant to fill additional SSDT */ |
| 168 | variant_fill_ssdt(dev); |
Eric Lai | af92d07 | 2022-03-14 15:08:27 +0800 | [diff] [blame] | 169 | |
| 170 | acpigen_write_scope("\\_SB"); |
| 171 | acpigen_write_method_serialized("MS0X", 1); |
| 172 | mainboard_generate_s0ix_hook(); |
| 173 | acpigen_write_method_end(); /* Method */ |
| 174 | acpigen_write_scope_end(); /* Scope */ |
| 175 | |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void __weak variant_fill_ssdt(const struct device *dev) |
| 179 | { |
| 180 | /* Add board-specific SSDT entries */ |
| 181 | } |
| 182 | |
Reka Norman | 581cd67 | 2022-04-12 09:51:32 +1000 | [diff] [blame] | 183 | void __weak variant_generate_s0ix_hook(enum s0ix_entry entry) |
Eric Lai | af92d07 | 2022-03-14 15:08:27 +0800 | [diff] [blame] | 184 | { |
| 185 | /* Add board-specific MS0X entries */ |
| 186 | /* |
| 187 | if (s0ix_entry == S0IX_ENTRY) { |
| 188 | implement variant operations here |
| 189 | } |
| 190 | if (s0ix_entry == S0IX_EXIT) { |
| 191 | implement variant operations here |
| 192 | } |
| 193 | */ |
| 194 | } |
| 195 | |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 196 | static void mainboard_enable(struct device *dev) |
| 197 | { |
Eric Lai | 78b6a1b | 2020-11-27 14:11:59 +0800 | [diff] [blame] | 198 | dev->ops->init = mainboard_dev_init; |
Wisley Chen | b8461aa | 2021-08-25 18:13:59 +0600 | [diff] [blame] | 199 | dev->ops->get_smbios_strings = mainboard_smbios_strings; |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 200 | dev->ops->acpi_fill_ssdt = mainboard_fill_ssdt; |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 201 | } |
| 202 | |
Tim Wawrzynczak | a46056f | 2022-02-17 11:40:54 -0700 | [diff] [blame] | 203 | |
| 204 | void __weak variant_finalize(void) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | static void mainboard_final(void *chip_info) |
| 209 | { |
| 210 | variant_finalize(); |
| 211 | } |
| 212 | |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 213 | struct chip_operations mainboard_ops = { |
| 214 | .init = mainboard_init, |
| 215 | .enable_dev = mainboard_enable, |
Tim Wawrzynczak | a46056f | 2022-02-17 11:40:54 -0700 | [diff] [blame] | 216 | .final = mainboard_final, |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 217 | }; |