From c146daf8a3241026c8c8906add2b5ae37cc76427 Mon Sep 17 00:00:00 2001 From: Deepti Deshatty Date: Thu, 20 May 2021 21:01:52 +0530 Subject: [PATCH] intel/common/block: Move mainboard api to tcss common block As per the comments in CB:54090 mainboard api mainboard_tcss_get_port_info() is simplified and moved to tcss common block code. Signed-off-by: Deepti Deshatty Change-Id: I7894363df4862f7cfe733d93e6160677fb8a9e31 Reviewed-on: https://review.coreboot.org/c/coreboot/+/54733 Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak Reviewed-by: EricR Lai --- src/drivers/intel/pmc_mux/conn/chip.h | 8 +++ src/drivers/intel/pmc_mux/conn/conn.c | 15 +++++ src/mainboard/google/volteer/mainboard.c | 57 ------------------- .../common/block/include/intelblocks/tcss.h | 4 +- src/soc/intel/common/block/tcss/tcss.c | 34 ++++++++++- 5 files changed, 58 insertions(+), 60 deletions(-) diff --git a/src/drivers/intel/pmc_mux/conn/chip.h b/src/drivers/intel/pmc_mux/conn/chip.h index 8497350337..461916ed98 100644 --- a/src/drivers/intel/pmc_mux/conn/chip.h +++ b/src/drivers/intel/pmc_mux/conn/chip.h @@ -23,4 +23,12 @@ struct drivers_intel_pmc_mux_conn_config { enum typec_orientation hsl_orientation; }; +/* + * Method verifies input "conn" device. + * Returns 'true' if device passed is Intel PMC MUX Conn device else returns 'false'. + * Method also outputs the usb2 and usb3 port numbers associated with the 'conn' device + */ +bool intel_pmc_mux_conn_get_ports(const struct device *conn, unsigned int *usb2_port, + unsigned int *usb3_port); + #endif /* __DRIVERS_INTEL_PMC_MUX_CONN_H__ */ diff --git a/src/drivers/intel/pmc_mux/conn/conn.c b/src/drivers/intel/pmc_mux/conn/conn.c index 9fd85431f3..b6bf371471 100644 --- a/src/drivers/intel/pmc_mux/conn/conn.c +++ b/src/drivers/intel/pmc_mux/conn/conn.c @@ -85,3 +85,18 @@ struct chip_operations drivers_intel_pmc_mux_conn_ops = { CHIP_NAME("Intel PMC MUX CONN Driver") .enable_dev = conn_enable, }; + +bool intel_pmc_mux_conn_get_ports(const struct device *conn, unsigned int *usb2_port, + unsigned int *usb3_port) +{ + const struct drivers_intel_pmc_mux_conn_config *mux_config; + + if (!conn->chip_info || conn->chip_ops != &drivers_intel_pmc_mux_conn_ops) + return false; + + mux_config = conn->chip_info; + *usb2_port = mux_config->usb2_port_number; + *usb3_port = mux_config->usb3_port_number; + + return true; +}; diff --git a/src/mainboard/google/volteer/mainboard.c b/src/mainboard/google/volteer/mainboard.c index 5e52b01a6a..74264451b6 100644 --- a/src/mainboard/google/volteer/mainboard.c +++ b/src/mainboard/google/volteer/mainboard.c @@ -142,63 +142,6 @@ void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg) } } -static bool is_correct_port(const struct device *dev, int port) -{ - return dev->path.type == DEVICE_PATH_GENERIC && dev->path.generic.id == port - && dev->chip_ops == &drivers_intel_pmc_mux_conn_ops; -} - -static const struct drivers_intel_pmc_mux_conn_config *get_connector_config( - const struct device *mux, - int port) -{ - const struct drivers_intel_pmc_mux_conn_config *config = NULL; - DEVTREE_CONST struct device *conn = NULL; - - while ((conn = dev_bus_each_child(mux->link_list, conn)) != NULL) { - if (is_correct_port(conn, port)) - break; - } - - if (conn) - config = (const struct drivers_intel_pmc_mux_conn_config *) conn->chip_info; - - return config; -} - -const struct tcss_port_map *mainboard_tcss_get_port_info(size_t *num_ports) -{ - static struct tcss_port_map port_map[MAX_TYPE_C_PORTS]; - size_t port; - const struct device *pmc; - const struct device *mux; - const struct drivers_intel_pmc_mux_conn_config *mux_config; - size_t active_ports = 0; - - pmc = pcidev_path_on_root(PCH_DEVFN_PMC); - if (!pmc || !pmc->link_list) { - printk(BIOS_ERR, "%s: unable to find PMC device or its mux\n", __func__); - return NULL; - } - - mux = pmc->link_list->children; - if (!mux) - return NULL; - - for (port = 0; port < MAX_TYPE_C_PORTS; port++) { - mux_config = get_connector_config(mux, port); - if (mux_config == NULL) - continue; - - port_map[active_ports].usb2_port = mux_config->usb2_port_number; - port_map[active_ports].usb3_port = mux_config->usb3_port_number; - active_ports++; - } - - *num_ports = active_ports; - return port_map; -} - static void mainboard_chip_init(void *chip_info) { const struct pad_config *base_pads; diff --git a/src/soc/intel/common/block/include/intelblocks/tcss.h b/src/soc/intel/common/block/include/intelblocks/tcss.h index 29093d1664..9595a78e00 100644 --- a/src/soc/intel/common/block/include/intelblocks/tcss.h +++ b/src/soc/intel/common/block/include/intelblocks/tcss.h @@ -161,10 +161,10 @@ void tcss_configure(const struct typec_aux_bias_pads pads[MAX_TYPE_C_PORTS]); 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 + * 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); +const struct tcss_port_map *tcss_get_port_info(size_t *num_ports); #endif /* _TCSS_H_ */ diff --git a/src/soc/intel/common/block/tcss/tcss.c b/src/soc/intel/common/block/tcss/tcss.c index da19954b10..28564e34cc 100644 --- a/src/soc/intel/common/block/tcss/tcss.c +++ b/src/soc/intel/common/block/tcss/tcss.c @@ -12,6 +12,7 @@ #include #include #include +#include #define BIAS_CTRL_VW_INDEX_SHIFT 16 #define BIAS_CTRL_BIT_POS_SHIFT 8 @@ -338,13 +339,44 @@ static void tcss_configure_aux_bias_pads( } } +const struct tcss_port_map *tcss_get_port_info(size_t *num_ports) +{ + static struct tcss_port_map port_map[MAX_TYPE_C_PORTS]; + size_t active_ports = 0; + size_t port; + + for (port = 0; port < MAX_TYPE_C_PORTS; port++) { + const struct device_path conn_path[] = { + {.type = DEVICE_PATH_PCI, .pci.devfn = PCH_DEVFN_PMC}, + {.type = DEVICE_PATH_GENERIC, .generic.id = 0, .generic.subid = 0}, + {.type = DEVICE_PATH_GENERIC, .generic.id = port}, + }; + const struct device *conn = find_dev_nested_path(pci_root_bus(), conn_path, + ARRAY_SIZE(conn_path)); + unsigned int usb2_port, usb3_port; + + if (!conn) + continue; + + if (CONFIG(DRIVERS_INTEL_PMC) && + intel_pmc_mux_conn_get_ports(conn, &usb2_port, &usb3_port)) { + port_map[active_ports].usb2_port = usb2_port; + port_map[active_ports].usb3_port = usb3_port; + ++active_ports; + } + } + + *num_ports = active_ports; + return port_map; +} + void tcss_configure(const struct typec_aux_bias_pads aux_bias_pads[MAX_TYPE_C_PORTS]) { const struct tcss_port_map *port_map; size_t num_ports; size_t i; - port_map = mainboard_tcss_get_port_info(&num_ports); + port_map = tcss_get_port_info(&num_ports); if (port_map == NULL) return;