Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Eric Lai | 5e053af | 2020-11-26 12:58:10 +0800 | [diff] [blame] | 3 | #include <baseboard/variants.h> |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 4 | #include <device/device.h> |
Eric Lai | 78b6a1b | 2020-11-27 14:11:59 +0800 | [diff] [blame] | 5 | #include <ec/ec.h> |
Sugnan Prabhu S | 061a93f | 2021-07-18 06:32:52 +0530 | [diff] [blame] | 6 | #include <soc/ramstage.h> |
Wisley Chen | b8461aa | 2021-08-25 18:13:59 +0600 | [diff] [blame] | 7 | #include <fw_config.h> |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 8 | #include <acpi/acpigen.h> |
| 9 | #include <drivers/wwan/fm/chip.h> |
| 10 | |
| 11 | WEAK_DEV_PTR(rp6_wwan); |
Wisley Chen | b8461aa | 2021-08-25 18:13:59 +0600 | [diff] [blame] | 12 | |
| 13 | static void add_fw_config_oem_string(const struct fw_config *config, void *arg) |
| 14 | { |
| 15 | struct smbios_type11 *t; |
| 16 | char buffer[64]; |
| 17 | |
| 18 | t = (struct smbios_type11 *)arg; |
| 19 | |
| 20 | snprintf(buffer, sizeof(buffer), "%s-%s", config->field_name, config->option_name); |
| 21 | t->count = smbios_add_string(t->eos, buffer); |
| 22 | } |
| 23 | |
| 24 | static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t) |
| 25 | { |
| 26 | fw_config_for_each_found(add_fw_config_oem_string, t); |
| 27 | } |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 28 | |
Sugnan Prabhu S | 061a93f | 2021-07-18 06:32:52 +0530 | [diff] [blame] | 29 | void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config) |
| 30 | { |
| 31 | variant_update_soc_chip_config(config); |
| 32 | } |
| 33 | |
| 34 | __weak void variant_update_soc_chip_config(struct soc_intel_alderlake_config *config) |
| 35 | { |
| 36 | /* default implementation does nothing */ |
| 37 | } |
| 38 | |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 39 | static void mainboard_init(void *chip_info) |
| 40 | { |
Tim Wawrzynczak | 5fed159 | 2021-06-08 14:44:56 -0600 | [diff] [blame] | 41 | const struct pad_config *base_pads; |
| 42 | const struct pad_config *override_pads; |
| 43 | size_t base_num, override_num; |
| 44 | |
| 45 | base_pads = variant_gpio_table(&base_num); |
| 46 | override_pads = variant_gpio_override_table(&override_num); |
| 47 | gpio_configure_pads_with_override(base_pads, base_num, override_pads, override_num); |
Sumeet Pawnikar | 582829d | 2021-07-23 15:50:17 +0530 | [diff] [blame] | 48 | |
| 49 | variant_devtree_update(); |
| 50 | } |
| 51 | |
| 52 | void __weak variant_devtree_update(void) |
| 53 | { |
| 54 | /* Override dev tree settings per board */ |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 55 | } |
| 56 | |
Eric Lai | 78b6a1b | 2020-11-27 14:11:59 +0800 | [diff] [blame] | 57 | static void mainboard_dev_init(struct device *dev) |
| 58 | { |
| 59 | mainboard_ec_init(); |
| 60 | } |
| 61 | |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 62 | static void mainboard_generate_shutdown(const struct device *dev) |
| 63 | { |
| 64 | const struct drivers_wwan_fm_config *config = config_of(dev); |
| 65 | const struct device *parent = dev->bus->dev; |
| 66 | |
| 67 | if (!config) |
| 68 | return; |
| 69 | if (config->rtd3dev) { |
| 70 | acpigen_write_store(); |
| 71 | acpigen_emit_namestring(acpi_device_path_join(parent, "RTD3._STA")); |
| 72 | acpigen_emit_byte(LOCAL0_OP); |
| 73 | acpigen_write_if_lequal_op_int(LOCAL0_OP, ONE_OP); |
| 74 | { |
| 75 | acpigen_emit_namestring(acpi_device_path_join(dev, "DPTS")); |
| 76 | acpigen_emit_byte(ARG0_OP); |
| 77 | } |
| 78 | acpigen_write_if_end(); |
| 79 | } else { |
| 80 | acpigen_emit_namestring(acpi_device_path_join(dev, "DPTS")); |
| 81 | acpigen_emit_byte(ARG0_OP); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static void mainboard_fill_ssdt(const struct device *dev) |
| 86 | { |
| 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_shutdown(wwan); |
| 93 | acpigen_write_method_end(); /* Method */ |
| 94 | acpigen_write_scope_end(); /* Scope */ |
| 95 | } |
| 96 | /* for variant to fill additional SSDT */ |
| 97 | variant_fill_ssdt(dev); |
| 98 | } |
| 99 | |
| 100 | void __weak variant_fill_ssdt(const struct device *dev) |
| 101 | { |
| 102 | /* Add board-specific SSDT entries */ |
| 103 | } |
| 104 | |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 105 | static void mainboard_enable(struct device *dev) |
| 106 | { |
Eric Lai | 78b6a1b | 2020-11-27 14:11:59 +0800 | [diff] [blame] | 107 | dev->ops->init = mainboard_dev_init; |
Wisley Chen | b8461aa | 2021-08-25 18:13:59 +0600 | [diff] [blame] | 108 | dev->ops->get_smbios_strings = mainboard_smbios_strings; |
Cliff Huang | 20ee22c | 2022-02-11 18:08:32 -0800 | [diff] [blame] | 109 | dev->ops->acpi_fill_ssdt = mainboard_fill_ssdt; |
Eric Lai | 5088682 | 2020-11-26 12:10:39 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | struct chip_operations mainboard_ops = { |
| 113 | .init = mainboard_init, |
| 114 | .enable_dev = mainboard_enable, |
| 115 | }; |