Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Subrata Banik | 6e7e8bf | 2022-12-02 02:21:11 +0530 | [diff] [blame] | 4 | #include <acpi/acpigen.h> |
Subrata Banik | cb32919 | 2022-12-02 00:29:30 +0530 | [diff] [blame] | 5 | #include <baseboard/gpio.h> |
Eric Lai | 5c02779 | 2022-05-23 16:21:36 +0800 | [diff] [blame] | 6 | #include <baseboard/variants.h> |
Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 7 | #include <device/device.h> |
Subrata Banik | 6e7e8bf | 2022-12-02 02:21:11 +0530 | [diff] [blame] | 8 | #include <drivers/wwan/fm/chip.h> |
Eric Lai | 7c304f8 | 2022-05-24 10:01:49 +0800 | [diff] [blame] | 9 | #include <ec/ec.h> |
Subrata Banik | db59e48 | 2022-12-02 01:24:02 +0530 | [diff] [blame] | 10 | #include <fw_config.h> |
Anil Kumar | 0e1f08d | 2023-05-09 15:14:29 -0700 | [diff] [blame^] | 11 | #include <soc/ramstage.h> |
Kapil Porwal | 8c1075a | 2023-02-21 18:36:31 +0530 | [diff] [blame] | 12 | #include <stdlib.h> |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 13 | #include <vendorcode/google/chromeos/chromeos.h> |
Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 14 | |
Subrata Banik | 6e7e8bf | 2022-12-02 02:21:11 +0530 | [diff] [blame] | 15 | WEAK_DEV_PTR(rp6_wwan); |
| 16 | |
Kapil Porwal | 8c1075a | 2023-02-21 18:36:31 +0530 | [diff] [blame] | 17 | void __weak fw_config_gpio_padbased_override(struct pad_config *padbased_table) |
| 18 | { |
| 19 | /* default implementation does nothing */ |
| 20 | } |
| 21 | |
Anil Kumar | 0e1f08d | 2023-05-09 15:14:29 -0700 | [diff] [blame^] | 22 | void mainboard_update_soc_chip_config(struct soc_intel_meteorlake_config *config) |
| 23 | { |
| 24 | variant_update_soc_chip_config(config); |
| 25 | } |
| 26 | |
| 27 | __weak void variant_update_soc_chip_config(struct soc_intel_meteorlake_config *config) |
| 28 | { |
| 29 | /* default implementation does nothing */ |
| 30 | } |
| 31 | |
Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 32 | static void mainboard_init(void *chip_info) |
| 33 | { |
Kapil Porwal | 8c1075a | 2023-02-21 18:36:31 +0530 | [diff] [blame] | 34 | struct pad_config *padbased_table; |
| 35 | const struct pad_config *base_pads; |
| 36 | size_t base_num; |
| 37 | |
| 38 | padbased_table = new_padbased_table(); |
| 39 | base_pads = variant_gpio_table(&base_num); |
| 40 | gpio_padbased_override(padbased_table, base_pads, base_num); |
| 41 | fw_config_gpio_padbased_override(padbased_table); |
| 42 | gpio_configure_pads_with_padbased(padbased_table); |
| 43 | free(padbased_table); |
Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 44 | } |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 45 | |
Subrata Banik | cb32919 | 2022-12-02 00:29:30 +0530 | [diff] [blame] | 46 | void __weak variant_generate_s0ix_hook(enum s0ix_entry entry) |
| 47 | { |
| 48 | /* Add board-specific MS0X entries */ |
| 49 | /* |
| 50 | if (s0ix_entry == S0IX_ENTRY) { |
| 51 | implement variant operations here |
| 52 | } |
| 53 | if (s0ix_entry == S0IX_EXIT) { |
| 54 | implement variant operations here |
| 55 | } |
| 56 | */ |
| 57 | } |
| 58 | |
| 59 | static void mainboard_generate_s0ix_hook(void) |
| 60 | { |
| 61 | acpigen_write_if_lequal_op_int(ARG0_OP, 1); |
| 62 | { |
| 63 | if (CONFIG(HAVE_SLP_S0_GATE)) |
| 64 | acpigen_soc_clear_tx_gpio(GPIO_SLP_S0_GATE); |
| 65 | variant_generate_s0ix_hook(S0IX_ENTRY); |
| 66 | } |
| 67 | acpigen_write_else(); |
| 68 | { |
| 69 | if (CONFIG(HAVE_SLP_S0_GATE)) |
| 70 | acpigen_soc_set_tx_gpio(GPIO_SLP_S0_GATE); |
| 71 | variant_generate_s0ix_hook(S0IX_EXIT); |
| 72 | } |
| 73 | acpigen_write_if_end(); |
| 74 | } |
| 75 | |
Subrata Banik | 6e7e8bf | 2022-12-02 02:21:11 +0530 | [diff] [blame] | 76 | static void mainboard_generate_wwan_shutdown(const struct device *dev) |
| 77 | { |
| 78 | const struct drivers_wwan_fm_config *config = config_of(dev); |
| 79 | const struct device *parent = dev->bus->dev; |
| 80 | |
| 81 | if (!config) |
| 82 | return; |
| 83 | if (config->rtd3dev) { |
| 84 | acpigen_write_store(); |
| 85 | acpigen_emit_namestring(acpi_device_path_join(parent, "RTD3._STA")); |
| 86 | acpigen_emit_byte(LOCAL0_OP); |
| 87 | acpigen_write_if_lequal_op_int(LOCAL0_OP, ONE_OP); |
| 88 | { |
| 89 | acpigen_emit_namestring(acpi_device_path_join(dev, "DPTS")); |
| 90 | acpigen_emit_byte(ARG0_OP); |
| 91 | } |
| 92 | acpigen_write_if_end(); |
| 93 | } |
| 94 | } |
| 95 | |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 96 | static void mainboard_fill_ssdt(const struct device *dev) |
| 97 | { |
Subrata Banik | 6e7e8bf | 2022-12-02 02:21:11 +0530 | [diff] [blame] | 98 | const struct device *wwan = DEV_PTR(rp6_wwan); |
| 99 | |
| 100 | if (wwan) { |
| 101 | acpigen_write_scope("\\_SB"); |
| 102 | acpigen_write_method_serialized("MPTS", 1); |
| 103 | mainboard_generate_wwan_shutdown(wwan); |
| 104 | acpigen_write_method_end(); /* Method */ |
| 105 | acpigen_write_scope_end(); /* Scope */ |
| 106 | } |
Subrata Banik | cb32919 | 2022-12-02 00:29:30 +0530 | [diff] [blame] | 107 | |
| 108 | acpigen_write_scope("\\_SB"); |
| 109 | acpigen_write_method_serialized("MS0X", 1); |
| 110 | mainboard_generate_s0ix_hook(); |
| 111 | acpigen_write_method_end(); /* Method */ |
| 112 | acpigen_write_scope_end(); /* Scope */ |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 113 | } |
| 114 | |
Subrata Banik | db59e48 | 2022-12-02 01:24:02 +0530 | [diff] [blame] | 115 | static void add_fw_config_oem_string(const struct fw_config *config, void *arg) |
| 116 | { |
| 117 | struct smbios_type11 *t; |
| 118 | char buffer[64]; |
| 119 | |
| 120 | t = (struct smbios_type11 *)arg; |
| 121 | |
| 122 | snprintf(buffer, sizeof(buffer), "%s-%s", config->field_name, config->option_name); |
| 123 | t->count = smbios_add_string(t->eos, buffer); |
| 124 | } |
| 125 | |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 126 | static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t) |
| 127 | { |
Subrata Banik | db59e48 | 2022-12-02 01:24:02 +0530 | [diff] [blame] | 128 | fw_config_for_each_found(add_fw_config_oem_string, t); |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 129 | } |
| 130 | |
Eric Lai | 7c304f8 | 2022-05-24 10:01:49 +0800 | [diff] [blame] | 131 | static void mainboard_dev_init(struct device *dev) |
| 132 | { |
| 133 | mainboard_ec_init(); |
| 134 | } |
Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 135 | |
| 136 | static void mainboard_enable(struct device *dev) |
| 137 | { |
Eric Lai | 7c304f8 | 2022-05-24 10:01:49 +0800 | [diff] [blame] | 138 | dev->ops->init = mainboard_dev_init; |
Eric Lai | 366fba2 | 2022-05-24 09:25:57 +0800 | [diff] [blame] | 139 | dev->ops->get_smbios_strings = mainboard_smbios_strings; |
| 140 | dev->ops->acpi_fill_ssdt = mainboard_fill_ssdt; |
Eric Lai | f6c52f4 | 2022-05-23 15:47:20 +0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | struct chip_operations mainboard_ops = { |
| 144 | .init = mainboard_init, |
| 145 | .enable_dev = mainboard_enable, |
| 146 | }; |