From eb6ebc025ed5de4985ef756efe38917fca827981 Mon Sep 17 00:00:00 2001 From: Tim Wawrzynczak Date: Mon, 22 Mar 2021 16:39:57 -0600 Subject: soc/intel/tigerlake: Move TCSS code to intel/common/block The Type-C subsystem ("TCSS") IP block is similar between TGL and ADL. For pre-boot purposes, the limited amount of functionality required appears to be common between the two, therefore move the functionality to intel/common/block and rename from `early_tcss to `tcss` along the way. Signed-off-by: Tim Wawrzynczak Change-Id: I1c6bb9c7098691f0c828f9d5ab4bd522515ae966 Reviewed-on: https://review.coreboot.org/c/coreboot/+/51753 Reviewed-by: Furquan Shaikh Tested-by: build bot (Jenkins) --- src/mainboard/google/volteer/Kconfig | 2 +- src/mainboard/google/volteer/mainboard.c | 2 +- .../intel/common/block/include/intelblocks/tcss.h | 158 ++++++++++ src/soc/intel/common/block/tcss/Kconfig | 10 + src/soc/intel/common/block/tcss/Makefile.inc | 1 + src/soc/intel/common/block/tcss/tcss.c | 325 ++++++++++++++++++++ src/soc/intel/tigerlake/Kconfig | 11 - src/soc/intel/tigerlake/Makefile.inc | 1 - src/soc/intel/tigerlake/early_tcss.c | 326 --------------------- src/soc/intel/tigerlake/fsp_params.c | 7 +- src/soc/intel/tigerlake/include/soc/early_tcss.h | 158 ---------- 11 files changed, 500 insertions(+), 501 deletions(-) create mode 100644 src/soc/intel/common/block/include/intelblocks/tcss.h create mode 100644 src/soc/intel/common/block/tcss/Kconfig create mode 100644 src/soc/intel/common/block/tcss/Makefile.inc create mode 100644 src/soc/intel/common/block/tcss/tcss.c delete mode 100644 src/soc/intel/tigerlake/early_tcss.c delete mode 100644 src/soc/intel/tigerlake/include/soc/early_tcss.h diff --git a/src/mainboard/google/volteer/Kconfig b/src/mainboard/google/volteer/Kconfig index f6f1e4151c..de301f12d2 100644 --- a/src/mainboard/google/volteer/Kconfig +++ b/src/mainboard/google/volteer/Kconfig @@ -16,7 +16,6 @@ config BOARD_GOOGLE_BASEBOARD_VOLTEER select DRIVERS_SOUNDWIRE_ALC5682 select DRIVERS_SOUNDWIRE_MAX98373 select DRIVERS_USB_ACPI - select EARLY_TCSS select EC_GOOGLE_CHROMEEC select EC_GOOGLE_CHROMEEC_BOARDID select EC_GOOGLE_CHROMEEC_SKUID @@ -31,6 +30,7 @@ config BOARD_GOOGLE_BASEBOARD_VOLTEER select MAINBOARD_HAS_SPI_TPM_CR50 if !BOARD_GOOGLE_VOLTEER2_TI50 select MAINBOARD_HAS_I2C_TPM_CR50 if BOARD_GOOGLE_VOLTEER2_TI50 select MAINBOARD_HAS_TPM2 + select SOC_INTEL_COMMON_BLOCK_TCSS select SOC_INTEL_CSE_LITE_SKU select SOC_INTEL_TIGERLAKE select HAVE_SPD_IN_CBFS diff --git a/src/mainboard/google/volteer/mainboard.c b/src/mainboard/google/volteer/mainboard.c index 70fa22b515..5e52b01a6a 100644 --- a/src/mainboard/google/volteer/mainboard.c +++ b/src/mainboard/google/volteer/mainboard.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/intel/common/block/include/intelblocks/tcss.h b/src/soc/intel/common/block/include/intelblocks/tcss.h new file mode 100644 index 0000000000..68e279ca2a --- /dev/null +++ b/src/soc/intel/common/block/include/intelblocks/tcss.h @@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _TCSS_H_ +#define _TCSS_H_ + +/* PMC IPC related offsets and commands */ +#define PMC_IPC_USBC_CMD_ID 0xA7 +#define PMC_IPC_USBC_SUBCMD_ID 0x0 +#define PMC_IPC_CMD 0x0 +#define PMC_IPC_TCSS_CONN_REQ_RES 0x0 +#define PMC_IPC_TCSS_DISC_REQ_RES 0x1 +#define PMC_IPC_TCSS_SAFE_MODE_REQ_RES 0x2 +#define PMC_IPC_TCSS_ALTMODE_REQ_RES 0x3 +#define PMC_IPC_TCSS_HPD_REQ_RES 0x4 +#define PMC_IPC_CONN_REQ_SIZE 2 +#define PMC_IPC_DISC_REQ_SIZE 2 +#define PMC_IPC_ALT_REQ_SIZE 8 +#define PMC_IPC_SAFE_REQ_SIZE 1 +#define PMC_IPC_HPD_REQ_SIZE 2 +#define PMC_IPC_DP_MODE 1 + +#define TCSS_CD_USAGE_SHIFT 0 +#define TCSS_CD_USAGE_MASK 0x0f +#define TCSS_CD_USB3_SHIFT 4 +#define TCSS_CD_USB3_MASK 0x0f +#define TCSS_CD_USB2_SHIFT 8 +#define TCSS_CD_USB2_MASK 0x0f +#define TCSS_CD_UFP_SHIFT 12 +#define TCSS_CD_UFP_MASK 0x01 +#define TCSS_CD_HSL_SHIFT 13 +#define TCSS_CD_HSL_MASK 0x01 +#define TCSS_CD_SBU_SHIFT 14 +#define TCSS_CD_SBU_MASK 0x01 +#define TCSS_CD_ACC_SHIFT 15 +#define TCSS_CD_ACC_MASK 0x01 +#define TCSS_CD_FAILED_SHIFT 16 +#define TCSS_CD_FAILED_MASK 0x01 +#define TCSS_CD_FATAL_SHIFT 17 +#define TCSS_CD_FATAL_MASK 0x01 + +#define TCSS_ALT_USAGE_SHIFT 0 +#define TCSS_ALT_USAGE_MASK 0x0f +#define TCSS_ALT_USB3_SHIFT 4 +#define TCSS_ALT_USB3_MASK 0x0f +#define TCSS_ALT_MODE_SHIFT 12 +#define TCSS_ALT_MODE_MASK 0x0f +#define TCSS_ALT_POLARITY_SHIFT 1 +#define TCSS_ALT_POLARITY_MASK 0x01 +#define TCSS_ALT_CABLE_SHIFT 2 +#define TCSS_ALT_CABLE_MASK 0x01 +#define TCSS_ALT_UFP_SHIFT 3 +#define TCSS_ALT_UFP_MASK 0x01 +#define TCSS_ALT_DP_MODE_SHIFT 8 +#define TCSS_ALT_DP_MODE_MASK 0x0f +#define TCSS_ALT_FAILED_SHIFT 8 +#define TCSS_ALT_FAILED_MASK 0x01 +#define TCSS_ALT_FATAL_SHIFT 9 +#define TCSS_ALT_FATAL_MASK 0x01 + +#define TCSS_HPD_USAGE_SHIFT 0 +#define TCSS_HPD_USAGE_MASK 0x0f +#define TCSS_HPD_USB3_SHIFT 4 +#define TCSS_HPD_USB3_MASK 0x0f +#define TCSS_HPD_LVL_SHIFT 12 +#define TCSS_HPD_LVL_MASK 0x01 +#define TCSS_HPD_IRQ_SHIFT 13 +#define TCSS_HPD_IRQ_MASK 0x01 + +#define MAX_TYPE_C_PORTS 4 + +#define TCSS_CD_FIELD(name, val) \ + (((val) & TCSS_CD_##name##_MASK) << TCSS_CD_##name##_SHIFT) + +#define GET_TCSS_CD_FIELD(name, val) \ + (((val) >> TCSS_CD_##name##_SHIFT) & TCSS_CD_##name##_MASK) + + +#define TCSS_ALT_FIELD(name, val) \ + (((val) & TCSS_ALT_##name##_MASK) << TCSS_ALT_##name##_SHIFT) + +#define TCSS_HPD_FIELD(name, val) \ + (((val) & TCSS_HPD_##name##_MASK) << TCSS_HPD_##name##_SHIFT) + +#define GET_TCSS_ALT_FIELD(name, val) \ + (((val) >> TCSS_ALT_##name##_SHIFT) & TCSS_ALT_##name##_MASK) + +#define TCSS_CONN_STATUS_HAS_FAILED(s) GET_TCSS_CD_FIELD(FAILED, s) +#define TCSS_STATUS_HAS_FAILED(s) GET_TCSS_ALT_FIELD(FAILED, s) +/* !fatal means retry */ +#define TCSS_CONN_STATUS_IS_FATAL(s) GET_TCSS_CD_FIELD(FATAL, s) +#define TCSS_STATUS_IS_FATAL(s) GET_TCSS_ALT_FIELD(FATAL, s) + +#define USB_2_PORT_MASK 0x0f +#define USB_3_PORT_MASK 0xf0 + +/* TCSS connection modes for PMC */ +enum pmc_ipc_conn_mode { + PMC_IPC_TCSS_DISCONNECT_MODE, + PMC_IPC_TCSS_USB_MODE, + PMC_IPC_TCSS_ALTERNATE_MODE, + PMC_IPC_TCSS_SAFE_MODE, + PMC_IPC_TCSS_HPD_MODE, + PMC_IPC_TCSS_TOTAL_MODES, +}; + +enum pmc_ipc_command_type { + CONNECT_REQ, + SAFE_REQ, + DP_REQ, + HPD_REQ, +}; + +/* DP Mode pin definitions */ +#define MODE_DP_PIN_A BIT(0) +#define MODE_DP_PIN_B BIT(1) +#define MODE_DP_PIN_C BIT(2) +#define MODE_DP_PIN_D BIT(3) +#define MODE_DP_PIN_E BIT(4) +#define MODE_DP_PIN_F BIT(5) + +/* struct to hold all tcss_mux related variables */ +struct tcss_mux_info { + bool dp; /* DP connected */ + bool usb; /* USB connected */ + bool cable; /* Activ/Passive Cable */ + bool polarity; /* polarity of connected device */ + bool hpd_lvl; /* HPD Level assert */ + bool hpd_irq; /* HPD IRQ assert */ + bool ufp; + bool acc; + uint8_t dp_mode; /* DP Operation Mode */ +}; + +struct tcss_port_map { + uint8_t usb2_port; /* USB2 Port Number */ + uint8_t usb3_port; /* USB3 Port Number */ +}; + +void tcss_configure(void); + +/* + * Mainboard method to setup any mux config needed for TCSS display operations. + * This function will need to obtain any mux data needed to forward to IOM/PMC + * Since the mux data may be stored differently by different mainboards this + * function must be defined by mainboard with its specific mux data stored in a + * tcss_mux_info struct as defined above. + * Returns completed tcss_mux_info structure for the specified port + */ +const struct tcss_mux_info *mainboard_tcss_get_mux_info(int port); + +/* + * Mainboard method to get only the port information to initialize the muxes to + * disconnect mode during boot. + * returns tscc_port_map of all ports on system + */ +const struct tcss_port_map *mainboard_tcss_get_port_info(size_t *num_ports); + +#endif /* _TCSS_H_ */ diff --git a/src/soc/intel/common/block/tcss/Kconfig b/src/soc/intel/common/block/tcss/Kconfig new file mode 100644 index 0000000000..f35390178e --- /dev/null +++ b/src/soc/intel/common/block/tcss/Kconfig @@ -0,0 +1,10 @@ +config SOC_INTEL_COMMON_BLOCK_TCSS + def_bool n + help + Sets up USB2/3 port mapping in TCSS MUX and sets MUX to disconnect state + +config TCSS_DISPLAY + bool "Enable early TCSS display" + depends on SOC_INTEL_COMMON_BLOCK_TCSS && RUN_FSP_GOP + help + Enable displays to be detected over Type-C ports during boot. diff --git a/src/soc/intel/common/block/tcss/Makefile.inc b/src/soc/intel/common/block/tcss/Makefile.inc new file mode 100644 index 0000000000..a3910808f8 --- /dev/null +++ b/src/soc/intel/common/block/tcss/Makefile.inc @@ -0,0 +1 @@ +ramstage-$(CONFIG_SOC_INTEL_COMMON_BLOCK_TCSS) += tcss.c diff --git a/src/soc/intel/common/block/tcss/tcss.c b/src/soc/intel/common/block/tcss/tcss.c new file mode 100644 index 0000000000..97805f55e6 --- /dev/null +++ b/src/soc/intel/common/block/tcss/tcss.c @@ -0,0 +1,325 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static uint32_t tcss_make_conn_cmd(int u, int u3, int u2, int ufp, int hsl, + int sbu, int acc) +{ + return TCSS_CD_FIELD(USAGE, u) | + TCSS_CD_FIELD(USB3, u3) | + TCSS_CD_FIELD(USB2, u2) | + TCSS_CD_FIELD(UFP, ufp) | + TCSS_CD_FIELD(HSL, hsl) | + TCSS_CD_FIELD(SBU, sbu) | + TCSS_CD_FIELD(ACC, acc); +} + +static uint32_t tcss_make_alt_mode_cmd_buf_0(int u, int u3, int m) +{ + return TCSS_ALT_FIELD(USAGE, u) | + TCSS_ALT_FIELD(USB3, u3) | + TCSS_ALT_FIELD(MODE, m); + +} + +static uint32_t tcss_make_alt_mode_cmd_buf_1(int p, int c, int ufp, int dp) +{ + return TCSS_ALT_FIELD(POLARITY, p) | + TCSS_ALT_FIELD(CABLE, c) | + TCSS_ALT_FIELD(UFP, ufp) | + TCSS_ALT_FIELD(DP_MODE, dp); +} + +static uint32_t tcss_make_safe_mode_cmd(int u, int u3) +{ + return TCSS_CD_FIELD(USAGE, u) | + TCSS_CD_FIELD(USB3, u3); +} + + +static uint32_t tcss_make_hpd_mode_cmd(int u, int u3, int hpd_lvl, int hpd_irq) +{ + return TCSS_HPD_FIELD(USAGE, u) | + TCSS_HPD_FIELD(USB3, u3) | + TCSS_HPD_FIELD(LVL, hpd_lvl) | + TCSS_HPD_FIELD(IRQ, hpd_irq); + +} + +static int send_pmc_req(int cmd_type, const struct pmc_ipc_buffer *req, + struct pmc_ipc_buffer *res, uint32_t size) +{ + uint32_t cmd_reg; + uint32_t res_reg; + int tries = 2; + int r; + + cmd_reg = pmc_make_ipc_cmd(PMC_IPC_USBC_CMD_ID, PMC_IPC_USBC_SUBCMD_ID, + size); + + printk(BIOS_DEBUG, "Raw Buffer output 0 %08" PRIx32 "\n", req->buf[0]); + printk(BIOS_DEBUG, "Raw Buffer output 1 %08" PRIx32 "\n", req->buf[1]); + + do { + r = pmc_send_ipc_cmd(cmd_reg, req, res); + if (r < 0) { + printk(BIOS_ERR, "pmc_send_ipc_cmd failed\n"); + return -1; + } + + res_reg = res->buf[0]; + if (cmd_type == CONNECT_REQ) { + if (!TCSS_CONN_STATUS_HAS_FAILED(res_reg)) { + printk(BIOS_DEBUG, "pmc_send_ipc_cmd succeeded\n"); + return 0; + } + + if (TCSS_CONN_STATUS_IS_FATAL(res_reg)) { + printk(BIOS_ERR, "pmc_send_ipc_cmd status: fatal\n"); + return -1; + } + } else { + if (!TCSS_STATUS_HAS_FAILED(res_reg)) { + printk(BIOS_DEBUG, "pmc_send_ipc_cmd succeeded\n"); + return 0; + } + + if (TCSS_STATUS_IS_FATAL(res_reg)) { + printk(BIOS_ERR, "pmc_send_ipc_cmd status: fatal\n"); + return -1; + } + } + } while (--tries >= 0); + + printk(BIOS_ERR, "pmc_send_ipc_cmd failed after retries\n"); + return -1; +} + +static int send_pmc_disconnect_request(int port, const struct tcss_port_map *port_map) +{ + uint32_t cmd; + struct pmc_ipc_buffer req = { 0 }; + struct pmc_ipc_buffer rsp; + + cmd = tcss_make_conn_cmd(PMC_IPC_TCSS_DISC_REQ_RES, port_map->usb3_port, + port_map->usb2_port, 0, 0, 0, 0); + + req.buf[0] = cmd; + + printk(BIOS_DEBUG, "port C%d DISC req: usage %d usb3 %d usb2 %d\n", + port, + GET_TCSS_CD_FIELD(USAGE, cmd), + GET_TCSS_CD_FIELD(USB3, cmd), + GET_TCSS_CD_FIELD(USB2, cmd)); + + return send_pmc_req(CONNECT_REQ, &req, &rsp, PMC_IPC_DISC_REQ_SIZE); +} + +static int send_pmc_connect_request(int port, const struct tcss_mux_info *mux_data, + const struct tcss_port_map *port_map) +{ + uint32_t cmd; + struct pmc_ipc_buffer req = { 0 }; + struct pmc_ipc_buffer rsp; + + cmd = tcss_make_conn_cmd( + PMC_IPC_TCSS_CONN_REQ_RES, + port_map->usb3_port, + port_map->usb2_port, + mux_data->ufp, + mux_data->polarity, + mux_data->polarity, + mux_data->acc); + + req.buf[0] = cmd; + + printk(BIOS_DEBUG, "port C%d CONN req: usage %d usb3 %d usb2 %d " + "ufp %d ori_hsl %d ori_sbu %d dbg_acc %d\n", + port, + GET_TCSS_CD_FIELD(USAGE, cmd), + GET_TCSS_CD_FIELD(USB3, cmd), + GET_TCSS_CD_FIELD(USB2, cmd), + GET_TCSS_CD_FIELD(UFP, cmd), + GET_TCSS_CD_FIELD(HSL, cmd), + GET_TCSS_CD_FIELD(SBU, cmd), + GET_TCSS_CD_FIELD(ACC, cmd)); + + return send_pmc_req(CONNECT_REQ, &req, &rsp, PMC_IPC_CONN_REQ_SIZE); +} + +static int send_pmc_safe_mode_request(int port, const struct tcss_mux_info *mux_data, + const struct tcss_port_map *port_map) +{ + uint32_t cmd; + struct pmc_ipc_buffer req = { 0 }; + struct pmc_ipc_buffer rsp; + + cmd = tcss_make_safe_mode_cmd(PMC_IPC_TCSS_SAFE_MODE_REQ_RES, port_map->usb3_port); + + req.buf[0] = cmd; + + printk(BIOS_DEBUG, "port C%d SAFE req: usage %d usb3 %d\n", + port, + GET_TCSS_CD_FIELD(USAGE, cmd), + GET_TCSS_CD_FIELD(USB3, cmd)); + + return send_pmc_req(SAFE_REQ, &req, &rsp, PMC_IPC_SAFE_REQ_SIZE); +} + +static int send_pmc_dp_hpd_request(int port, const struct tcss_mux_info *mux_data, + const struct tcss_port_map *port_map) +{ + struct pmc_ipc_buffer req = { 0 }; + struct pmc_ipc_buffer rsp; + uint32_t cmd; + + cmd = tcss_make_hpd_mode_cmd( + PMC_IPC_TCSS_HPD_REQ_RES, + port_map->usb3_port, + mux_data->hpd_lvl, + mux_data->hpd_irq); + + req.buf[0] = cmd; + + return send_pmc_req(HPD_REQ, &req, &rsp, PMC_IPC_HPD_REQ_SIZE); + +} + +static int send_pmc_dp_mode_request(int port, const struct tcss_mux_info *mux_data, + const struct tcss_port_map *port_map) +{ + uint32_t cmd; + uint8_t dp_mode; + int ret; + + struct pmc_ipc_buffer req = { 0 }; + struct pmc_ipc_buffer rsp; + + cmd = tcss_make_alt_mode_cmd_buf_0( + PMC_IPC_TCSS_ALTMODE_REQ_RES, + port_map->usb3_port, + PMC_IPC_DP_MODE); + + req.buf[0] = cmd; + + printk(BIOS_DEBUG, "port C%d ALT_1 req: usage %d usb3 %d dp_mode %d\n", + port, + GET_TCSS_ALT_FIELD(USAGE, cmd), + GET_TCSS_ALT_FIELD(USB3, cmd), + GET_TCSS_ALT_FIELD(MODE, cmd)); + + switch (mux_data->dp_mode) { + case MODE_DP_PIN_A: + dp_mode = 1; + break; + case MODE_DP_PIN_B: + dp_mode = 2; + break; + case MODE_DP_PIN_C: + dp_mode = 3; + break; + case MODE_DP_PIN_D: + dp_mode = 4; + break; + case MODE_DP_PIN_E: + dp_mode = 5; + break; + case MODE_DP_PIN_F: + dp_mode = 6; + break; + default: + dp_mode = 0; + break; + } + + cmd = tcss_make_alt_mode_cmd_buf_1( + mux_data->polarity, + mux_data->cable, + 0, /* ufp is not supported in DP ALT Mode request */ + dp_mode); + + printk(BIOS_DEBUG, "port C%d ALT_2 req: polarity %d cable %d ufp %d " + "dp_mode %d\n", + port, + GET_TCSS_ALT_FIELD(POLARITY, cmd), + GET_TCSS_ALT_FIELD(CABLE, cmd), + GET_TCSS_ALT_FIELD(UFP, cmd), + GET_TCSS_ALT_FIELD(DP_MODE, cmd)); + + req.buf[1] = cmd; + + ret = send_pmc_req(DP_REQ, &req, &rsp, PMC_IPC_ALT_REQ_SIZE); + if (ret) + return ret; + + send_pmc_dp_hpd_request(port, mux_data, port_map); + return 0; +} + +static void tcss_init_mux(int port, const struct tcss_port_map *port_map) +{ + int ret; + + ret = send_pmc_disconnect_request(port, port_map); + if (ret) + printk(BIOS_ERR, "Failed to setup port:%d to initial state\n", port); +} + +static void tcss_configure_dp_mode(const struct tcss_port_map *port_map, size_t num_ports) +{ + int ret; + size_t i; + const struct tcss_mux_info *mux_info; + const struct tcss_port_map *port_info; + + if (!display_init_required()) + return; + + for (i = 0; i < num_ports; i++) { + mux_info = mainboard_tcss_get_mux_info(i); + port_info = &port_map[i]; + + if (!mux_info->dp) + continue; + + ret = send_pmc_connect_request(i, mux_info, port_info); + if (ret) { + printk(BIOS_ERR, "Port %zd connect request failed\n", i); + continue; + } + ret = send_pmc_safe_mode_request(i, mux_info, port_info); + if (ret) { + printk(BIOS_ERR, "Port %zd safe mode request failed\n", i); + continue; + } + + ret = send_pmc_dp_mode_request(i, mux_info, port_info); + if (ret) + printk(BIOS_ERR, "Port C%zd mux set failed with error %d\n", i, ret); + } +} + +void tcss_configure(void) +{ + const struct tcss_port_map *port_map; + size_t num_ports; + size_t i; + + port_map = mainboard_tcss_get_port_info(&num_ports); + if (port_map == NULL) + return; + + for (i = 0; i < num_ports; i++) + tcss_init_mux(i, &port_map[i]); + + if (CONFIG(TCSS_DISPLAY)) + tcss_configure_dp_mode(port_map, num_ports); +} diff --git a/src/soc/intel/tigerlake/Kconfig b/src/soc/intel/tigerlake/Kconfig index afebc0f3c4..d77ad52723 100644 --- a/src/soc/intel/tigerlake/Kconfig +++ b/src/soc/intel/tigerlake/Kconfig @@ -239,17 +239,6 @@ config PRERAM_CBMEM_CONSOLE_SIZE hex default 0x2000 -config EARLY_TCSS - bool "Enable early TCSS device Init" - help - Sets up USB2/3 port mapping in TCSS MUX and sets MUX to disconnect state - -config EARLY_TCSS_DISPLAY - bool "Enable early TCSS display" if EARLY_TCSS - depends on EARLY_TCSS && RUN_FSP_GOP - help - Enable displays to be detected over Type-C ports during boot. - config DATA_BUS_WIDTH int default 128 diff --git a/src/soc/intel/tigerlake/Makefile.inc b/src/soc/intel/tigerlake/Makefile.inc index 25aa3f9286..572b96ee56 100644 --- a/src/soc/intel/tigerlake/Makefile.inc +++ b/src/soc/intel/tigerlake/Makefile.inc @@ -30,7 +30,6 @@ romstage-y += reset.c ramstage-y += acpi.c ramstage-y += chip.c ramstage-y += cpu.c -ramstage-$(CONFIG_EARLY_TCSS) += early_tcss.c ramstage-y += elog.c ramstage-y += espi.c ramstage-y += finalize.c diff --git a/src/soc/intel/tigerlake/early_tcss.c b/src/soc/intel/tigerlake/early_tcss.c deleted file mode 100644 index e32c29fc1b..0000000000 --- a/src/soc/intel/tigerlake/early_tcss.c +++ /dev/null @@ -1,326 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -static uint32_t tcss_make_conn_cmd(int u, int u3, int u2, int ufp, int hsl, - int sbu, int acc) -{ - return TCSS_CD_FIELD(USAGE, u) | - TCSS_CD_FIELD(USB3, u3) | - TCSS_CD_FIELD(USB2, u2) | - TCSS_CD_FIELD(UFP, ufp) | - TCSS_CD_FIELD(HSL, hsl) | - TCSS_CD_FIELD(SBU, sbu) | - TCSS_CD_FIELD(ACC, acc); -} - -static uint32_t tcss_make_alt_mode_cmd_buf_0(int u, int u3, int m) -{ - return TCSS_ALT_FIELD(USAGE, u) | - TCSS_ALT_FIELD(USB3, u3) | - TCSS_ALT_FIELD(MODE, m); - -} - -static uint32_t tcss_make_alt_mode_cmd_buf_1(int p, int c, int ufp, int dp) -{ - return TCSS_ALT_FIELD(POLARITY, p) | - TCSS_ALT_FIELD(CABLE, c) | - TCSS_ALT_FIELD(UFP, ufp) | - TCSS_ALT_FIELD(DP_MODE, dp); -} - -static uint32_t tcss_make_safe_mode_cmd(int u, int u3) -{ - return TCSS_CD_FIELD(USAGE, u) | - TCSS_CD_FIELD(USB3, u3); -} - - -static uint32_t tcss_make_hpd_mode_cmd(int u, int u3, int hpd_lvl, int hpd_irq) -{ - return TCSS_HPD_FIELD(USAGE, u) | - TCSS_HPD_FIELD(USB3, u3) | - TCSS_HPD_FIELD(LVL, hpd_lvl) | - TCSS_HPD_FIELD(IRQ, hpd_irq); - -} - -static int send_pmc_req(int cmd_type, const struct pmc_ipc_buffer *req, - struct pmc_ipc_buffer *res, uint32_t size) -{ - uint32_t cmd_reg; - uint32_t res_reg; - int tries = 2; - int r; - - cmd_reg = pmc_make_ipc_cmd(PMC_IPC_USBC_CMD_ID, PMC_IPC_USBC_SUBCMD_ID, - size); - - printk(BIOS_DEBUG, "Raw Buffer output 0 %08" PRIx32 "\n", req->buf[0]); - printk(BIOS_DEBUG, "Raw Buffer output 1 %08" PRIx32 "\n", req->buf[1]); - - do { - r = pmc_send_ipc_cmd(cmd_reg, req, res); - if (r < 0) { - printk(BIOS_ERR, "pmc_send_ipc_cmd failed\n"); - return -1; - } - - res_reg = res->buf[0]; - if (cmd_type == CONNECT_REQ) { - if (!TCSS_CONN_STATUS_HAS_FAILED(res_reg)) { - printk(BIOS_DEBUG, "pmc_send_ipc_cmd succeeded\n"); - return 0; - } - - if (TCSS_CONN_STATUS_IS_FATAL(res_reg)) { - printk(BIOS_ERR, "pmc_send_ipc_cmd status: fatal\n"); - return -1; - } - } else { - if (!TCSS_STATUS_HAS_FAILED(res_reg)) { - printk(BIOS_DEBUG, "pmc_send_ipc_cmd succeeded\n"); - return 0; - } - - if (TCSS_STATUS_IS_FATAL(res_reg)) { - printk(BIOS_ERR, "pmc_send_ipc_cmd status: fatal\n"); - return -1; - } - } - } while (--tries >= 0); - - printk(BIOS_ERR, "pmc_send_ipc_cmd failed after retries\n"); - return -1; -} - -static int send_pmc_disconnect_request(int port, const struct tcss_port_map *port_map) -{ - uint32_t cmd; - struct pmc_ipc_buffer req = { 0 }; - struct pmc_ipc_buffer rsp; - - cmd = tcss_make_conn_cmd(PMC_IPC_TCSS_DISC_REQ_RES, port_map->usb3_port, - port_map->usb2_port, 0, 0, 0, 0); - - req.buf[0] = cmd; - - printk(BIOS_DEBUG, "port C%d DISC req: usage %d usb3 %d usb2 %d\n", - port, - GET_TCSS_CD_FIELD(USAGE, cmd), - GET_TCSS_CD_FIELD(USB3, cmd), - GET_TCSS_CD_FIELD(USB2, cmd)); - - return send_pmc_req(CONNECT_REQ, &req, &rsp, PMC_IPC_DISC_REQ_SIZE); -} - -static int send_pmc_connect_request(int port, const struct tcss_mux_info *mux_data, - const struct tcss_port_map *port_map) -{ - uint32_t cmd; - struct pmc_ipc_buffer req = { 0 }; - struct pmc_ipc_buffer rsp; - - cmd = tcss_make_conn_cmd( - PMC_IPC_TCSS_CONN_REQ_RES, - port_map->usb3_port, - port_map->usb2_port, - mux_data->ufp, - mux_data->polarity, - mux_data->polarity, - mux_data->acc); - - req.buf[0] = cmd; - - printk(BIOS_DEBUG, "port C%d CONN req: usage %d usb3 %d usb2 %d " - "ufp %d ori_hsl %d ori_sbu %d dbg_acc %d\n", - port, - GET_TCSS_CD_FIELD(USAGE, cmd), - GET_TCSS_CD_FIELD(USB3, cmd), - GET_TCSS_CD_FIELD(USB2, cmd), - GET_TCSS_CD_FIELD(UFP, cmd), - GET_TCSS_CD_FIELD(HSL, cmd), - GET_TCSS_CD_FIELD(SBU, cmd), - GET_TCSS_CD_FIELD(ACC, cmd)); - - return send_pmc_req(CONNECT_REQ, &req, &rsp, PMC_IPC_CONN_REQ_SIZE); -} - -static int send_pmc_safe_mode_request(int port, const struct tcss_mux_info *mux_data, - const struct tcss_port_map *port_map) -{ - uint32_t cmd; - struct pmc_ipc_buffer req = { 0 }; - struct pmc_ipc_buffer rsp; - - cmd = tcss_make_safe_mode_cmd(PMC_IPC_TCSS_SAFE_MODE_REQ_RES, port_map->usb3_port); - - req.buf[0] = cmd; - - printk(BIOS_DEBUG, "port C%d SAFE req: usage %d usb3 %d\n", - port, - GET_TCSS_CD_FIELD(USAGE, cmd), - GET_TCSS_CD_FIELD(USB3, cmd)); - - return send_pmc_req(SAFE_REQ, &req, &rsp, PMC_IPC_SAFE_REQ_SIZE); -} - -static int send_pmc_dp_hpd_request(int port, const struct tcss_mux_info *mux_data, - const struct tcss_port_map *port_map) -{ - struct pmc_ipc_buffer req = { 0 }; - struct pmc_ipc_buffer rsp; - uint32_t cmd; - - cmd = tcss_make_hpd_mode_cmd( - PMC_IPC_TCSS_HPD_REQ_RES, - port_map->usb3_port, - mux_data->hpd_lvl, - mux_data->hpd_irq); - - req.buf[0] = cmd; - - return send_pmc_req(HPD_REQ, &req, &rsp, PMC_IPC_HPD_REQ_SIZE); - -} - -static int send_pmc_dp_mode_request(int port, const struct tcss_mux_info *mux_data, - const struct tcss_port_map *port_map) -{ - uint32_t cmd; - uint8_t dp_mode; - int ret; - - struct pmc_ipc_buffer req = { 0 }; - struct pmc_ipc_buffer rsp; - - cmd = tcss_make_alt_mode_cmd_buf_0( - PMC_IPC_TCSS_ALTMODE_REQ_RES, - port_map->usb3_port, - PMC_IPC_DP_MODE); - - req.buf[0] = cmd; - - printk(BIOS_DEBUG, "port C%d ALT_1 req: usage %d usb3 %d dp_mode %d\n", - port, - GET_TCSS_ALT_FIELD(USAGE, cmd), - GET_TCSS_ALT_FIELD(USB3, cmd), - GET_TCSS_ALT_FIELD(MODE, cmd)); - - switch (mux_data->dp_mode) { - case MODE_DP_PIN_A: - dp_mode = 1; - break; - case MODE_DP_PIN_B: - dp_mode = 2; - break; - case MODE_DP_PIN_C: - dp_mode = 3; - break; - case MODE_DP_PIN_D: - dp_mode = 4; - break; - case MODE_DP_PIN_E: - dp_mode = 5; - break; - case MODE_DP_PIN_F: - dp_mode = 6; - break; - default: - dp_mode = 0; - break; - } - - cmd = tcss_make_alt_mode_cmd_buf_1( - mux_data->polarity, - mux_data->cable, - 0, /* ufp is not supported in DP ALT Mode request */ - dp_mode); - - printk(BIOS_DEBUG, "port C%d ALT_2 req: polarity %d cable %d ufp %d " - "dp_mode %d\n", - port, - GET_TCSS_ALT_FIELD(POLARITY, cmd), - GET_TCSS_ALT_FIELD(CABLE, cmd), - GET_TCSS_ALT_FIELD(UFP, cmd), - GET_TCSS_ALT_FIELD(DP_MODE, cmd)); - - req.buf[1] = cmd; - - ret = send_pmc_req(DP_REQ, &req, &rsp, PMC_IPC_ALT_REQ_SIZE); - if (ret) - return ret; - - send_pmc_dp_hpd_request(port, mux_data, port_map); - return 0; -} - -static void tcss_init_mux(int port, const struct tcss_port_map *port_map) -{ - int ret; - - ret = send_pmc_disconnect_request(port, port_map); - if (ret) - printk(BIOS_ERR, "Failed to setup port:%d to initial state\n", port); -} - -static void tcss_configure_dp_mode(const struct tcss_port_map *port_map, size_t num_ports) -{ - int ret; - size_t i; - const struct tcss_mux_info *mux_info; - const struct tcss_port_map *port_info; - - if (!display_init_required()) - return; - - for (i = 0; i < num_ports; i++) { - mux_info = mainboard_tcss_get_mux_info(i); - port_info = &port_map[i]; - - if (!mux_info->dp) - continue; - - ret = send_pmc_connect_request(i, mux_info, port_info); - if (ret) { - printk(BIOS_ERR, "Port %zd connect request failed\n", i); - continue; - } - ret = send_pmc_safe_mode_request(i, mux_info, port_info); - if (ret) { - printk(BIOS_ERR, "Port %zd safe mode request failed\n", i); - continue; - } - - ret = send_pmc_dp_mode_request(i, mux_info, port_info); - if (ret) - printk(BIOS_ERR, "Port C%zd mux set failed with error %d\n", i, ret); - } -} - -void tcss_early_configure(void) -{ - const struct tcss_port_map *port_map; - size_t num_ports; - size_t i; - - port_map = mainboard_tcss_get_port_info(&num_ports); - if (port_map == NULL) - return; - - for (i = 0; i < num_ports; i++) - tcss_init_mux(i, &port_map[i]); - - if (CONFIG(EARLY_TCSS_DISPLAY)) - tcss_configure_dp_mode(port_map, num_ports); -} diff --git a/src/soc/intel/tigerlake/fsp_params.c b/src/soc/intel/tigerlake/fsp_params.c index 6d08e1f68c..6bd4a7cbe1 100644 --- a/src/soc/intel/tigerlake/fsp_params.c +++ b/src/soc/intel/tigerlake/fsp_params.c @@ -14,10 +14,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -463,8 +463,9 @@ void platform_fsp_multi_phase_init_cb(uint32_t phase_index) /* TCSS specific initialization here */ printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n", __FILE__, __func__); - if (CONFIG(EARLY_TCSS)) - tcss_early_configure(); + + if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCSS)) + tcss_configure(); break; default: break; diff --git a/src/soc/intel/tigerlake/include/soc/early_tcss.h b/src/soc/intel/tigerlake/include/soc/early_tcss.h deleted file mode 100644 index 8e45607d83..0000000000 --- a/src/soc/intel/tigerlake/include/soc/early_tcss.h +++ /dev/null @@ -1,158 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ - -#ifndef _EARLY_TCSS_H_ -#define _EARLY_TCSS_H_ - -/* PMC IPC related offsets and commands */ -#define PMC_IPC_USBC_CMD_ID 0xA7 -#define PMC_IPC_USBC_SUBCMD_ID 0x0 -#define PMC_IPC_CMD 0x0 -#define PMC_IPC_TCSS_CONN_REQ_RES 0x0 -#define PMC_IPC_TCSS_DISC_REQ_RES 0x1 -#define PMC_IPC_TCSS_SAFE_MODE_REQ_RES 0x2 -#define PMC_IPC_TCSS_ALTMODE_REQ_RES 0x3 -#define PMC_IPC_TCSS_HPD_REQ_RES 0x4 -#define PMC_IPC_CONN_REQ_SIZE 2 -#define PMC_IPC_DISC_REQ_SIZE 2 -#define PMC_IPC_ALT_REQ_SIZE 8 -#define PMC_IPC_SAFE_REQ_SIZE 1 -#define PMC_IPC_HPD_REQ_SIZE 2 -#define PMC_IPC_DP_MODE 1 - -#define TCSS_CD_USAGE_SHIFT 0 -#define TCSS_CD_USAGE_MASK 0x0f -#define TCSS_CD_USB3_SHIFT 4 -#define TCSS_CD_USB3_MASK 0x0f -#define TCSS_CD_USB2_SHIFT 8 -#define TCSS_CD_USB2_MASK 0x0f -#define TCSS_CD_UFP_SHIFT 12 -#define TCSS_CD_UFP_MASK 0x01 -#define TCSS_CD_HSL_SHIFT 13 -#define TCSS_CD_HSL_MASK 0x01 -#define TCSS_CD_SBU_SHIFT 14 -#define TCSS_CD_SBU_MASK 0x01 -#define TCSS_CD_ACC_SHIFT 15 -#define TCSS_CD_ACC_MASK 0x01 -#define TCSS_CD_FAILED_SHIFT 16 -#define TCSS_CD_FAILED_MASK 0x01 -#define TCSS_CD_FATAL_SHIFT 17 -#define TCSS_CD_FATAL_MASK 0x01 - -#define TCSS_ALT_USAGE_SHIFT 0 -#define TCSS_ALT_USAGE_MASK 0x0f -#define TCSS_ALT_USB3_SHIFT 4 -#define TCSS_ALT_USB3_MASK 0x0f -#define TCSS_ALT_MODE_SHIFT 12 -#define TCSS_ALT_MODE_MASK 0x0f -#define TCSS_ALT_POLARITY_SHIFT 1 -#define TCSS_ALT_POLARITY_MASK 0x01 -#define TCSS_ALT_CABLE_SHIFT 2 -#define TCSS_ALT_CABLE_MASK 0x01 -#define TCSS_ALT_UFP_SHIFT 3 -#define TCSS_ALT_UFP_MASK 0x01 -#define TCSS_ALT_DP_MODE_SHIFT 8 -#define TCSS_ALT_DP_MODE_MASK 0x0f -#define TCSS_ALT_FAILED_SHIFT 8 -#define TCSS_ALT_FAILED_MASK 0x01 -#define TCSS_ALT_FATAL_SHIFT 9 -#define TCSS_ALT_FATAL_MASK 0x01 - -#define TCSS_HPD_USAGE_SHIFT 0 -#define TCSS_HPD_USAGE_MASK 0x0f -#define TCSS_HPD_USB3_SHIFT 4 -#define TCSS_HPD_USB3_MASK 0x0f -#define TCSS_HPD_LVL_SHIFT 12 -#define TCSS_HPD_LVL_MASK 0x01 -#define TCSS_HPD_IRQ_SHIFT 13 -#define TCSS_HPD_IRQ_MASK 0x01 - -#define MAX_TYPE_C_PORTS 4 - -#define TCSS_CD_FIELD(name, val) \ - (((val) & TCSS_CD_##name##_MASK) << TCSS_CD_##name##_SHIFT) - -#define GET_TCSS_CD_FIELD(name, val) \ - (((val) >> TCSS_CD_##name##_SHIFT) & TCSS_CD_##name##_MASK) - - -#define TCSS_ALT_FIELD(name, val) \ - (((val) & TCSS_ALT_##name##_MASK) << TCSS_ALT_##name##_SHIFT) - -#define TCSS_HPD_FIELD(name, val) \ - (((val) & TCSS_HPD_##name##_MASK) << TCSS_HPD_##name##_SHIFT) - -#define GET_TCSS_ALT_FIELD(name, val) \ - (((val) >> TCSS_ALT_##name##_SHIFT) & TCSS_ALT_##name##_MASK) - -#define TCSS_CONN_STATUS_HAS_FAILED(s) GET_TCSS_CD_FIELD(FAILED, s) -#define TCSS_STATUS_HAS_FAILED(s) GET_TCSS_ALT_FIELD(FAILED, s) -/* !fatal means retry */ -#define TCSS_CONN_STATUS_IS_FATAL(s) GET_TCSS_CD_FIELD(FATAL, s) -#define TCSS_STATUS_IS_FATAL(s) GET_TCSS_ALT_FIELD(FATAL, s) - -#define USB_2_PORT_MASK 0x0f -#define USB_3_PORT_MASK 0xf0 - -/* TCSS connection modes for PMC */ -enum pmc_ipc_conn_mode { - PMC_IPC_TCSS_DISCONNECT_MODE, - PMC_IPC_TCSS_USB_MODE, - PMC_IPC_TCSS_ALTERNATE_MODE, - PMC_IPC_TCSS_SAFE_MODE, - PMC_IPC_TCSS_HPD_MODE, - PMC_IPC_TCSS_TOTAL_MODES, -}; - -enum pmc_ipc_command_type { - CONNECT_REQ, - SAFE_REQ, - DP_REQ, - HPD_REQ, -}; - -/* DP Mode pin definitions */ -#define MODE_DP_PIN_A BIT(0) -#define MODE_DP_PIN_B BIT(1) -#define MODE_DP_PIN_C BIT(2) -#define MODE_DP_PIN_D BIT(3) -#define MODE_DP_PIN_E BIT(4) -#define MODE_DP_PIN_F BIT(5) - -/* struct to hold all tcss_mux related variables */ -struct tcss_mux_info { - bool dp; /* DP connected */ - bool usb; /* USB connected */ - bool cable; /* Activ/Passive Cable */ - bool polarity; /* polarity of connected device */ - bool hpd_lvl; /* HPD Level assert */ - bool hpd_irq; /* HPD IRQ assert */ - bool ufp; - bool acc; - uint8_t dp_mode; /* DP Operation Mode */ -}; - -struct tcss_port_map { - uint8_t usb2_port; /* USB2 Port Number */ - uint8_t usb3_port; /* USB3 Port Number */ -}; - -void tcss_early_configure(void); - -/* - * Mainboard method to setup any mux config needed for early TCSS display operations. - * This function will need to obtain any mux data needed to forward to IOM/PMC - * Since the mux data may be stored differently by different mainboards this function - * must be defined by mainboard with its specific mux data stored in a tcss_mux_info - * struct as defined above. - * Returns completed tcss_mux_info structure for the specified port - */ -const struct tcss_mux_info *mainboard_tcss_get_mux_info(int port); - -/* - * Mainboard method to get only the port information to initialize the muxes to - * disconnect mode during boot. - * returns tscc_port_map of all ports on system - */ -const struct tcss_port_map *mainboard_tcss_get_port_info(size_t *num_ports); - -#endif /* _EARLY_TCSS_H_ */ -- cgit v1.2.3