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