blob: ae7519e10e25d0a391f2fa31027effaece624465 [file] [log] [blame]
Elyes HAOUASf50b6622020-07-19 14:00:43 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Nick Vaccarof9781912020-01-28 18:43:28 -08002
3#include <console/console.h>
Nick Vaccarof9781912020-01-28 18:43:28 -08004#include <baseboard/variants.h>
5#include <device/device.h>
Tim Wawrzynczak6b8599f2022-02-14 16:04:21 -07006#include <drivers/tpm/cr50.h>
Nick Vaccarof9781912020-01-28 18:43:28 -08007#include <ec/ec.h>
Tim Wawrzynczak1d849412020-08-25 16:50:29 -06008#include <fw_config.h>
Duncan Laurie98a9f1f2020-11-05 10:06:17 -08009#include <gpio.h>
10#include <intelblocks/gpio.h>
Jes Klinke7f844ab2020-08-28 13:44:21 -070011#include <security/tpm/tss.h>
Tim Wawrzynczakeb6ebc02021-03-22 16:39:57 -060012#include <intelblocks/tcss.h>
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060013#include <soc/pci_devs.h>
Jes Klinke7f844ab2020-08-28 13:44:21 -070014#include <soc/ramstage.h>
Elyes Haouasbdd03c22024-05-27 11:20:07 +020015#include <stdio.h>
Nick Vaccarof9781912020-01-28 18:43:28 -080016#include <variant/gpio.h>
John Zhao623da4b2020-09-08 09:44:44 -070017#include <vb2_api.h>
Nick Vaccarof9781912020-01-28 18:43:28 -080018
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060019#include "drivers/intel/pmc_mux/conn/chip.h"
20
Furquan Shaikh522174b2021-09-16 16:54:04 -070021WEAK_DEV_PTR(conn1);
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060022
23static void typec_orientation_fixup(void)
24{
Furquan Shaikh522174b2021-09-16 16:54:04 -070025 const struct device *conn = DEV_PTR(conn1);
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060026
Furquan Shaikh522174b2021-09-16 16:54:04 -070027 if (!is_dev_enabled(conn))
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060028 return;
29
Jes Klinke6e929ac2020-12-01 15:21:38 -080030 if (fw_config_probe(FW_CONFIG(DB_USB, USB4_GEN2))
31 || fw_config_probe(FW_CONFIG(DB_USB, USB3_ACTIVE))
32 || fw_config_probe(FW_CONFIG(DB_USB, USB4_GEN3))
33 || fw_config_probe(FW_CONFIG(DB_USB, USB3_NO_A))) {
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060034 struct drivers_intel_pmc_mux_conn_config *config = conn->chip_info;
35
36 if (config) {
Jes Klinke6e929ac2020-12-01 15:21:38 -080037 printk(BIOS_INFO,
38 "Configure Right Type-C port orientation for retimer\n");
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060039 config->sbu_orientation = TYPEC_ORIENTATION_NORMAL;
40 }
41 }
42}
43
Nick Vaccarof9781912020-01-28 18:43:28 -080044static void mainboard_init(struct device *dev)
45{
46 mainboard_ec_init();
Tim Wawrzynczakeafe7982020-09-30 13:59:21 -060047 typec_orientation_fixup();
Jes Klinke6e929ac2020-12-01 15:21:38 -080048 variant_devtree_update();
49}
50
51void __weak variant_devtree_update(void)
52{
Nick Vaccarof9781912020-01-28 18:43:28 -080053}
54
Nick Vaccaro3865a332021-02-16 18:58:43 -080055void __weak variant_ramstage_init(void)
56{
57 /* Default weak implementation */
58}
59
Tim Wawrzynczak1d849412020-08-25 16:50:29 -060060static void add_fw_config_oem_string(const struct fw_config *config, void *arg)
61{
62 struct smbios_type11 *t;
63 char buffer[64];
64
65 t = (struct smbios_type11 *)arg;
66
67 snprintf(buffer, sizeof(buffer), "%s-%s", config->field_name, config->option_name);
68 t->count = smbios_add_string(t->eos, buffer);
69}
70
71static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t)
72{
73 fw_config_for_each_found(add_fw_config_oem_string, t);
74}
75
Nick Vaccarof9781912020-01-28 18:43:28 -080076static void mainboard_enable(struct device *dev)
77{
78 dev->ops->init = mainboard_init;
Tim Wawrzynczak1d849412020-08-25 16:50:29 -060079 dev->ops->get_smbios_strings = mainboard_smbios_strings;
Nick Vaccaro3865a332021-02-16 18:58:43 -080080
81 variant_ramstage_init();
Nick Vaccarof9781912020-01-28 18:43:28 -080082}
83
Jes Klinke7f844ab2020-08-28 13:44:21 -070084void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg)
85{
Jon Murphyd7b8dc92023-09-05 11:36:43 -060086 tpm_result_t rc;
Jes B. Klinkec6b041a12022-04-19 14:00:33 -070087 if (!CONFIG(TPM_GOOGLE_CR50) || !CONFIG(SPI_TPM)) {
Jes Klinkee94f8652020-10-30 13:46:39 -070088 /*
89 * Negotiation of long interrupt pulses is only supported via SPI. I2C is only
90 * used on reworked prototypes on which the TPM is replaced with Dauntless under
91 * development, it will use long pulses by default, or use the interrupt line in
92 * a different way altogether.
93 */
94 return;
95 }
96
Jon Murphy24604812023-09-05 10:37:05 -060097 rc = tlcl_lib_init();
Jon Murphyd7b8dc92023-09-05 11:36:43 -060098 if (rc != TPM_SUCCESS) {
Jon Murphy53fc6672023-09-26 21:05:37 -060099 printk(BIOS_ERR, "tlcl_lib_init() failed: %#x\n", rc);
John Zhao623da4b2020-09-08 09:44:44 -0700100 return;
101 }
102
Jes Klinkee94f8652020-10-30 13:46:39 -0700103 if (cr50_is_long_interrupt_pulse_enabled()) {
Jes Klinke7f844ab2020-08-28 13:44:21 -0700104 printk(BIOS_INFO, "Enabling S0i3.4\n");
105 } else {
106 /*
107 * Disable S0i3.4, preventing the GPIO block from switching to
108 * slow clock.
109 */
110 printk(BIOS_INFO, "Not enabling S0i3.4\n");
111 cfg->LpmStateDisableMask |= LPM_S0i3_4;
112 cfg->gpio_override_pm = 1;
113 memset(cfg->gpio_pm, 0, sizeof(cfg->gpio_pm));
114 }
115}
116
Nick Vaccarof9781912020-01-28 18:43:28 -0800117static void mainboard_chip_init(void *chip_info)
118{
119 const struct pad_config *base_pads;
120 const struct pad_config *override_pads;
121 size_t base_num, override_num;
122
Matt DeVillier6b8728f2022-09-23 13:34:22 -0500123 base_pads = baseboard_gpio_table(&base_num);
Nick Vaccarof9781912020-01-28 18:43:28 -0800124 override_pads = variant_override_gpio_table(&override_num);
125
Jes Klinke5c7311a2020-10-30 13:23:14 -0700126 gpio_configure_pads_with_override(base_pads, base_num, override_pads, override_num);
Duncan Laurie98a9f1f2020-11-05 10:06:17 -0800127
128 /*
129 * Check SATAXPCIE1 (GPP_A12) RX status to determine if SSD is NVMe or SATA and set
130 * the IOSSTATE RX field to drive 0 or 1 back to the internal controller to ensure
131 * the attached device is not mis-detected on resume from S0ix.
132 */
133 if (gpio_get(GPP_A12)) {
134 const struct pad_config gpio_pedet_nvme[] = {
135 PAD_CFG_NF_IOSSTATE(GPP_A12, NONE, DEEP, NF1, HIZCRx1),
136 };
137 gpio_configure_pads(gpio_pedet_nvme, ARRAY_SIZE(gpio_pedet_nvme));
138 printk(BIOS_INFO, "SATAXPCIE1 indicates PCIe NVMe is present\n");
139 } else {
140 const struct pad_config gpio_pedet_sata[] = {
141 PAD_CFG_NF_IOSSTATE(GPP_A12, NONE, DEEP, NF1, HIZCRx0),
142 };
143 gpio_configure_pads(gpio_pedet_sata, ARRAY_SIZE(gpio_pedet_sata));
144 printk(BIOS_INFO, "SATAXPCIE1 indicates SATA SSD is present\n");
145 }
Nick Vaccarof9781912020-01-28 18:43:28 -0800146}
147
Nick Vaccarof9781912020-01-28 18:43:28 -0800148struct chip_operations mainboard_ops = {
149 .init = mainboard_chip_init,
150 .enable_dev = mainboard_enable,
151};