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 <deepti.deshatty@intel.com>
Change-Id: I7894363df4862f7cfe733d93e6160677fb8a9e31
Reviewed-on: https://review.coreboot.org/c/coreboot/+/54733
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: EricR Lai <ericr_lai@compal.corp-partner.google.com>
diff --git a/src/drivers/intel/pmc_mux/conn/chip.h b/src/drivers/intel/pmc_mux/conn/chip.h
index 8497350..461916e 100644
--- a/src/drivers/intel/pmc_mux/conn/chip.h
+++ b/src/drivers/intel/pmc_mux/conn/chip.h
@@ -23,4 +23,12 @@
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 9fd8543..b6bf371 100644
--- a/src/drivers/intel/pmc_mux/conn/conn.c
+++ b/src/drivers/intel/pmc_mux/conn/conn.c
@@ -85,3 +85,18 @@
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 5e52b01..7426445 100644
--- a/src/mainboard/google/volteer/mainboard.c
+++ b/src/mainboard/google/volteer/mainboard.c
@@ -142,63 +142,6 @@
}
}
-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 29093d1..9595a78 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 @@
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 da19954..28564e3 100644
--- a/src/soc/intel/common/block/tcss/tcss.c
+++ b/src/soc/intel/common/block/tcss/tcss.c
@@ -12,6 +12,7 @@
#include <soc/pcr_ids.h>
#include <soc/tcss.h>
#include <stdlib.h>
+#include <drivers/intel/pmc_mux/conn/chip.h>
#define BIAS_CTRL_VW_INDEX_SHIFT 16
#define BIAS_CTRL_BIT_POS_SHIFT 8
@@ -338,13 +339,44 @@
}
}
+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;