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