jzhao80 | 6c4edff | 2022-01-10 07:54:57 -0800 | [diff] [blame] | 1 | /* 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> |
Elyes Haouas | cbbbb6c | 2022-10-22 22:15:27 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
jzhao80 | 6c4edff | 2022-01-10 07:54:57 -0800 | [diff] [blame] | 8 | |
| 9 | int retimer_get_index_for_typec(uint8_t typec_port) |
| 10 | { |
| 11 | int ec_port = 0; |
| 12 | |
| 13 | const struct device *tcss_port_arr[] = { |
| 14 | DEV_PTR(tcss_usb3_port1), |
| 15 | DEV_PTR(tcss_usb3_port2), |
| 16 | DEV_PTR(tcss_usb3_port3), |
| 17 | DEV_PTR(tcss_usb3_port4), |
| 18 | }; |
| 19 | |
| 20 | for (uint8_t i = 0; i < MAX_TYPE_C_PORTS; i++) { |
| 21 | if (i == typec_port) { |
| 22 | printk(BIOS_ERR, "USB Type-C %d mapped to EC port %d\n", typec_port, |
| 23 | ec_port); |
| 24 | return ec_port; |
| 25 | } |
| 26 | |
| 27 | if (is_dev_enabled(tcss_port_arr[i])) |
| 28 | ec_port++; |
| 29 | } |
| 30 | |
| 31 | // Code should not come here if typec_port input is correct |
| 32 | return -1; |
| 33 | } |