blob: 269620d0d1905a90da0000b91ff41fb4edea0c41 [file] [log] [blame]
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <console/console.h>
4#include <device/device.h>
5#include <drivers/intel/usb4/retimer/retimer.h>
6#include <intelblocks/tcss.h>
7
8int retimer_get_index_for_typec(uint8_t typec_port)
9{
10 int ec_port = 0;
11
12 const struct device *tcss_port_arr[] = {
Eric Lai884a70b2023-06-16 09:26:18 +080013 DEV_PTR(tcss_usb3_port0),
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070014 DEV_PTR(tcss_usb3_port1),
15 DEV_PTR(tcss_usb3_port2),
16 DEV_PTR(tcss_usb3_port3),
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070017 };
18
19 for (uint8_t i = 0; i < MAX_TYPE_C_PORTS; i++) {
20 if (i == typec_port) {
Ivy Jian64c77dc2022-09-12 15:23:22 +080021 printk(BIOS_INFO, "USB Type-C %d mapped to EC port %d\n", typec_port,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070022 ec_port);
23 return ec_port;
24 }
25
26 if (is_dev_enabled(tcss_port_arr[i]))
27 ec_port++;
28 }
29
30 // Code should not come here if typec_port input is correct
31 return -1;
32}