1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <acpi/acpigen.h>
4 #include <baseboard/gpio.h>
5 #include <baseboard/variants.h>
6 #include <device/device.h>
7 #include <drivers/tpm/cr50.h>
8 #include <drivers/wwan/fm/chip.h>
10 #include <fw_config.h>
11 #include <security/tpm/tss.h>
13 #include <soc/ramstage.h>
17 WEAK_DEV_PTR(rp6_wwan
);
20 static void add_fw_config_oem_string(const struct fw_config
*config
, void *arg
)
22 struct smbios_type11
*t
;
25 t
= (struct smbios_type11
*)arg
;
27 snprintf(buffer
, sizeof(buffer
), "%s-%s", config
->field_name
, config
->option_name
);
28 t
->count
= smbios_add_string(t
->eos
, buffer
);
31 static void mainboard_smbios_strings(struct device
*dev
, struct smbios_type11
*t
)
33 fw_config_for_each_found(add_fw_config_oem_string
, t
);
36 void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config
*config
)
41 if (rc
!= TPM_SUCCESS
) {
42 printk(BIOS_ERR
, "tlcl_lib_init() failed: %#x\n", rc
);
46 if (cr50_is_long_interrupt_pulse_enabled()) {
47 printk(BIOS_INFO
, "Enabling GPIO PM b/c CR50 has long IRQ pulse support\n");
48 config
->gpio_override_pm
= 0;
50 printk(BIOS_INFO
, "Disabling GPIO PM b/c CR50 does not have long IRQ pulse "
52 config
->gpio_override_pm
= 1;
53 config
->gpio_pm
[COMM_0
] = 0;
54 config
->gpio_pm
[COMM_1
] = 0;
55 config
->gpio_pm
[COMM_2
] = 0;
56 config
->gpio_pm
[COMM_3
] = 0;
57 config
->gpio_pm
[COMM_4
] = 0;
58 config
->gpio_pm
[COMM_5
] = 0;
61 variant_update_soc_chip_config(config
);
64 void __weak
variant_update_soc_chip_config(struct soc_intel_alderlake_config
*config
)
66 /* default implementation does nothing */
69 void __weak
variant_init(void)
71 /* default implementation does nothing */
74 void __weak
fw_config_gpio_padbased_override(struct pad_config
*padbased_table
)
76 /* default implementation does nothing */
79 void __weak
variant_configure_pads(void)
81 const struct pad_config
*base_pads
;
82 const struct pad_config
*override_pads
;
83 size_t base_num
, override_num
;
85 base_pads
= variant_gpio_table(&base_num
);
86 override_pads
= variant_gpio_override_table(&override_num
);
87 gpio_configure_pads_with_override(base_pads
, base_num
, override_pads
, override_num
);
90 static void mainboard_init(void *chip_info
)
92 variant_configure_pads();
94 variant_devtree_update();
97 void __weak
variant_devtree_update(void)
99 /* Override dev tree settings per board */
102 static void mainboard_dev_init(struct device
*dev
)
107 static void mainboard_generate_wwan_shutdown(const struct device
*dev
)
109 const struct drivers_wwan_fm_config
*config
= config_of(dev
);
110 const struct device
*parent
= dev
->upstream
->dev
;
114 if (config
->rtd3dev
) {
115 acpigen_write_store();
116 acpigen_emit_namestring(acpi_device_path_join(parent
, "RTD3._STA"));
117 acpigen_emit_byte(LOCAL0_OP
);
118 acpigen_write_if_lequal_op_int(LOCAL0_OP
, ONE_OP
);
120 acpigen_emit_namestring(acpi_device_path_join(dev
, "DPTS"));
121 acpigen_emit_byte(ARG0_OP
);
123 acpigen_write_if_end();
127 static void mainboard_generate_dgpu_shutdown(const struct device
*dev
)
129 /* Call `_OFF` from the Power Resource associated with the dGPU's PEG port. */
130 const struct device
*parent
= dev
->upstream
->dev
;
133 acpigen_emit_namestring(acpi_device_path_join(parent
, "PGPR._OFF"));
136 static void mainboard_generate_mpts(void)
138 const struct device
*wwan
= DEV_PTR(rp6_wwan
);
139 const struct device
*dgpu
= DEV_PTR(dgpu
);
142 * If HAVE_WWAN_POWER_SEQUENCE is selected, MPTS will be added to the
143 * DSDT via wwan_power.asl. We can't add MPTS to the SSDT as well,
144 * since the duplicate definition will result in a kernel error.
146 * This special case can be removed in the future if the power-off
147 * sequences for all WWAN devices used on brya are moved to the SSDT.
149 if (CONFIG(HAVE_WWAN_POWER_SEQUENCE
)) {
151 printk(BIOS_ERR
, "Skip adding duplicate MPTS entry to SSDT\n");
155 acpigen_write_scope("\\_SB");
156 acpigen_write_method_serialized("MPTS", 1);
158 mainboard_generate_wwan_shutdown(wwan
);
160 mainboard_generate_dgpu_shutdown(dgpu
);
162 acpigen_write_method_end(); /* Method */
163 acpigen_write_scope_end(); /* Scope */
166 static void mainboard_generate_s0ix_hook(void)
168 acpigen_write_if_lequal_op_int(ARG0_OP
, 1);
170 if (CONFIG(HAVE_SLP_S0_GATE
))
171 acpigen_soc_clear_tx_gpio(GPIO_SLP_S0_GATE
);
172 variant_generate_s0ix_hook(S0IX_ENTRY
);
174 acpigen_write_else();
176 if (CONFIG(HAVE_SLP_S0_GATE
))
177 acpigen_soc_set_tx_gpio(GPIO_SLP_S0_GATE
);
178 variant_generate_s0ix_hook(S0IX_EXIT
);
180 acpigen_write_if_end();
183 static void mainboard_fill_ssdt(const struct device
*dev
)
185 mainboard_generate_mpts();
187 /* for variant to fill additional SSDT */
188 variant_fill_ssdt(dev
);
190 acpigen_write_scope("\\_SB");
191 acpigen_write_method_serialized("MS0X", 1);
192 mainboard_generate_s0ix_hook();
193 acpigen_write_method_end(); /* Method */
194 acpigen_write_scope_end(); /* Scope */
197 void __weak
variant_fill_ssdt(const struct device
*dev
)
199 /* Add board-specific SSDT entries */
202 void __weak
variant_generate_s0ix_hook(enum s0ix_entry entry
)
204 /* Add board-specific MS0X entries */
206 if (s0ix_entry == S0IX_ENTRY) {
207 implement variant operations here
209 if (s0ix_entry == S0IX_EXIT) {
210 implement variant operations here
215 static void mainboard_enable(struct device
*dev
)
217 dev
->ops
->init
= mainboard_dev_init
;
218 dev
->ops
->get_smbios_strings
= mainboard_smbios_strings
;
219 dev
->ops
->acpi_fill_ssdt
= mainboard_fill_ssdt
;
223 void __weak
variant_finalize(void)
227 static void mainboard_final(void *chip_info
)
232 struct chip_operations mainboard_ops
= {
233 .init
= mainboard_init
,
234 .enable_dev
= mainboard_enable
,
235 .final
= mainboard_final
,