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