Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
John Zhao | 3c46371 | 2022-01-10 15:49:37 -0800 | [diff] [blame] | 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Brandon Breitenstein | 2914455 | 2020-11-17 11:29:45 -0800 | [diff] [blame] | 5 | #include <bootmode.h> |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/pci.h> |
John Zhao | 3c46371 | 2022-01-10 15:49:37 -0800 | [diff] [blame] | 8 | #include <intelblocks/p2sb.h> |
| 9 | #include <intelblocks/pcr.h> |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 10 | #include <intelblocks/pmc_ipc.h> |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 11 | #include <intelblocks/systemagent.h> |
Tim Wawrzynczak | eb6ebc0 | 2021-03-22 16:39:57 -0600 | [diff] [blame] | 12 | #include <intelblocks/tcss.h> |
| 13 | #include <inttypes.h> |
Sridhar Siricilla | f9ee35e | 2022-12-08 16:15:16 +0530 | [diff] [blame] | 14 | #include <lib.h> |
Brandon Breitenstein | 2914455 | 2020-11-17 11:29:45 -0800 | [diff] [blame] | 15 | #include <security/vboot/vboot_common.h> |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 16 | #include <soc/pci_devs.h> |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 17 | #include <soc/pcr_ids.h> |
| 18 | #include <soc/tcss.h> |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 19 | #include <drivers/intel/pmc_mux/conn/chip.h> |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 20 | |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 21 | #define BIAS_CTRL_VW_INDEX_SHIFT 16 |
| 22 | #define BIAS_CTRL_BIT_POS_SHIFT 8 |
Kapil Porwal | 400f1aa | 2023-07-10 11:40:16 +0000 | [diff] [blame] | 23 | #define WAIT_FOR_DISPLAYPORT_TIMEOUT_MS 1000 |
| 24 | #define WAIT_FOR_DP_MODE_ENTRY_TIMEOUT_MS 500 |
| 25 | #define WAIT_FOR_HPD_TIMEOUT_MS 3000 |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 26 | |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 27 | static uint32_t tcss_make_conn_cmd(int u, int u3, int u2, int ufp, int hsl, |
| 28 | int sbu, int acc) |
| 29 | { |
| 30 | return TCSS_CD_FIELD(USAGE, u) | |
| 31 | TCSS_CD_FIELD(USB3, u3) | |
| 32 | TCSS_CD_FIELD(USB2, u2) | |
| 33 | TCSS_CD_FIELD(UFP, ufp) | |
| 34 | TCSS_CD_FIELD(HSL, hsl) | |
| 35 | TCSS_CD_FIELD(SBU, sbu) | |
| 36 | TCSS_CD_FIELD(ACC, acc); |
| 37 | } |
| 38 | |
| 39 | static uint32_t tcss_make_alt_mode_cmd_buf_0(int u, int u3, int m) |
| 40 | { |
| 41 | return TCSS_ALT_FIELD(USAGE, u) | |
| 42 | TCSS_ALT_FIELD(USB3, u3) | |
| 43 | TCSS_ALT_FIELD(MODE, m); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static uint32_t tcss_make_alt_mode_cmd_buf_1(int p, int c, int ufp, int dp) |
| 47 | { |
| 48 | return TCSS_ALT_FIELD(POLARITY, p) | |
| 49 | TCSS_ALT_FIELD(CABLE, c) | |
| 50 | TCSS_ALT_FIELD(UFP, ufp) | |
| 51 | TCSS_ALT_FIELD(DP_MODE, dp); |
| 52 | } |
| 53 | |
| 54 | static uint32_t tcss_make_safe_mode_cmd(int u, int u3) |
| 55 | { |
| 56 | return TCSS_CD_FIELD(USAGE, u) | |
| 57 | TCSS_CD_FIELD(USB3, u3); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | static uint32_t tcss_make_hpd_mode_cmd(int u, int u3, int hpd_lvl, int hpd_irq) |
| 62 | { |
| 63 | return TCSS_HPD_FIELD(USAGE, u) | |
| 64 | TCSS_HPD_FIELD(USB3, u3) | |
| 65 | TCSS_HPD_FIELD(LVL, hpd_lvl) | |
| 66 | TCSS_HPD_FIELD(IRQ, hpd_irq); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static int send_pmc_req(int cmd_type, const struct pmc_ipc_buffer *req, |
| 70 | struct pmc_ipc_buffer *res, uint32_t size) |
| 71 | { |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 72 | uint32_t cmd_reg; |
| 73 | uint32_t res_reg; |
| 74 | int tries = 2; |
| 75 | int r; |
| 76 | |
| 77 | cmd_reg = pmc_make_ipc_cmd(PMC_IPC_USBC_CMD_ID, PMC_IPC_USBC_SUBCMD_ID, |
| 78 | size); |
| 79 | |
| 80 | printk(BIOS_DEBUG, "Raw Buffer output 0 %08" PRIx32 "\n", req->buf[0]); |
| 81 | printk(BIOS_DEBUG, "Raw Buffer output 1 %08" PRIx32 "\n", req->buf[1]); |
| 82 | |
| 83 | do { |
| 84 | r = pmc_send_ipc_cmd(cmd_reg, req, res); |
| 85 | if (r < 0) { |
| 86 | printk(BIOS_ERR, "pmc_send_ipc_cmd failed\n"); |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | res_reg = res->buf[0]; |
| 91 | if (cmd_type == CONNECT_REQ) { |
| 92 | if (!TCSS_CONN_STATUS_HAS_FAILED(res_reg)) { |
| 93 | printk(BIOS_DEBUG, "pmc_send_ipc_cmd succeeded\n"); |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | if (TCSS_CONN_STATUS_IS_FATAL(res_reg)) { |
| 98 | printk(BIOS_ERR, "pmc_send_ipc_cmd status: fatal\n"); |
| 99 | return -1; |
| 100 | } |
| 101 | } else { |
| 102 | if (!TCSS_STATUS_HAS_FAILED(res_reg)) { |
| 103 | printk(BIOS_DEBUG, "pmc_send_ipc_cmd succeeded\n"); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | if (TCSS_STATUS_IS_FATAL(res_reg)) { |
| 108 | printk(BIOS_ERR, "pmc_send_ipc_cmd status: fatal\n"); |
| 109 | return -1; |
| 110 | } |
| 111 | } |
| 112 | } while (--tries >= 0); |
| 113 | |
| 114 | printk(BIOS_ERR, "pmc_send_ipc_cmd failed after retries\n"); |
| 115 | return -1; |
| 116 | } |
| 117 | |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 118 | static int send_pmc_disconnect_request(int port, const struct tcss_port_map *port_map) |
| 119 | { |
| 120 | uint32_t cmd; |
| 121 | struct pmc_ipc_buffer req = { 0 }; |
| 122 | struct pmc_ipc_buffer rsp; |
| 123 | |
| 124 | cmd = tcss_make_conn_cmd(PMC_IPC_TCSS_DISC_REQ_RES, port_map->usb3_port, |
| 125 | port_map->usb2_port, 0, 0, 0, 0); |
| 126 | |
| 127 | req.buf[0] = cmd; |
| 128 | |
| 129 | printk(BIOS_DEBUG, "port C%d DISC req: usage %d usb3 %d usb2 %d\n", |
| 130 | port, |
| 131 | GET_TCSS_CD_FIELD(USAGE, cmd), |
| 132 | GET_TCSS_CD_FIELD(USB3, cmd), |
| 133 | GET_TCSS_CD_FIELD(USB2, cmd)); |
| 134 | |
| 135 | return send_pmc_req(CONNECT_REQ, &req, &rsp, PMC_IPC_DISC_REQ_SIZE); |
| 136 | } |
| 137 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 138 | static int send_pmc_connect_request(int port, const struct usbc_mux_info *mux_data, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 139 | const struct tcss_port_map *port_map) |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 140 | { |
| 141 | uint32_t cmd; |
| 142 | struct pmc_ipc_buffer req = { 0 }; |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 143 | struct pmc_ipc_buffer rsp; |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 144 | |
| 145 | cmd = tcss_make_conn_cmd( |
| 146 | PMC_IPC_TCSS_CONN_REQ_RES, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 147 | port_map->usb3_port, |
| 148 | port_map->usb2_port, |
| 149 | mux_data->ufp, |
| 150 | mux_data->polarity, |
| 151 | mux_data->polarity, |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 152 | mux_data->dbg_acc); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 153 | |
| 154 | req.buf[0] = cmd; |
| 155 | |
| 156 | printk(BIOS_DEBUG, "port C%d CONN req: usage %d usb3 %d usb2 %d " |
| 157 | "ufp %d ori_hsl %d ori_sbu %d dbg_acc %d\n", |
| 158 | port, |
| 159 | GET_TCSS_CD_FIELD(USAGE, cmd), |
| 160 | GET_TCSS_CD_FIELD(USB3, cmd), |
| 161 | GET_TCSS_CD_FIELD(USB2, cmd), |
| 162 | GET_TCSS_CD_FIELD(UFP, cmd), |
| 163 | GET_TCSS_CD_FIELD(HSL, cmd), |
| 164 | GET_TCSS_CD_FIELD(SBU, cmd), |
| 165 | GET_TCSS_CD_FIELD(ACC, cmd)); |
| 166 | |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 167 | return send_pmc_req(CONNECT_REQ, &req, &rsp, PMC_IPC_CONN_REQ_SIZE); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 170 | static int send_pmc_safe_mode_request(int port, const struct usbc_mux_info *mux_data, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 171 | const struct tcss_port_map *port_map) |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 172 | { |
| 173 | uint32_t cmd; |
| 174 | struct pmc_ipc_buffer req = { 0 }; |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 175 | struct pmc_ipc_buffer rsp; |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 176 | |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 177 | cmd = tcss_make_safe_mode_cmd(PMC_IPC_TCSS_SAFE_MODE_REQ_RES, port_map->usb3_port); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 178 | |
| 179 | req.buf[0] = cmd; |
| 180 | |
| 181 | printk(BIOS_DEBUG, "port C%d SAFE req: usage %d usb3 %d\n", |
| 182 | port, |
| 183 | GET_TCSS_CD_FIELD(USAGE, cmd), |
| 184 | GET_TCSS_CD_FIELD(USB3, cmd)); |
| 185 | |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 186 | return send_pmc_req(SAFE_REQ, &req, &rsp, PMC_IPC_SAFE_REQ_SIZE); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 189 | static int send_pmc_dp_hpd_request(int port, const struct usbc_mux_info *mux_data, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 190 | const struct tcss_port_map *port_map) |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 191 | { |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 192 | struct pmc_ipc_buffer req = { 0 }; |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 193 | struct pmc_ipc_buffer rsp; |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 194 | uint32_t cmd; |
| 195 | |
| 196 | cmd = tcss_make_hpd_mode_cmd( |
| 197 | PMC_IPC_TCSS_HPD_REQ_RES, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 198 | port_map->usb3_port, |
| 199 | mux_data->hpd_lvl, |
| 200 | mux_data->hpd_irq); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 201 | |
| 202 | req.buf[0] = cmd; |
| 203 | |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 204 | return send_pmc_req(HPD_REQ, &req, &rsp, PMC_IPC_HPD_REQ_SIZE); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Sridhar Siricilla | f9ee35e | 2022-12-08 16:15:16 +0530 | [diff] [blame] | 207 | static uint8_t get_dp_mode(uint8_t dp_pin_mode) |
| 208 | { |
| 209 | switch (dp_pin_mode) { |
| 210 | case MODE_DP_PIN_A: |
| 211 | case MODE_DP_PIN_B: |
| 212 | case MODE_DP_PIN_C: |
| 213 | case MODE_DP_PIN_D: |
| 214 | case MODE_DP_PIN_E: |
| 215 | case MODE_DP_PIN_F: |
| 216 | return log2(dp_pin_mode) + 1; |
| 217 | default: |
| 218 | return 0; |
| 219 | } |
| 220 | } |
| 221 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 222 | static int send_pmc_dp_mode_request(int port, const struct usbc_mux_info *mux_data, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 223 | const struct tcss_port_map *port_map) |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 224 | { |
| 225 | uint32_t cmd; |
| 226 | uint8_t dp_mode; |
| 227 | int ret; |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 228 | |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 229 | struct pmc_ipc_buffer req = { 0 }; |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 230 | struct pmc_ipc_buffer rsp; |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 231 | |
| 232 | cmd = tcss_make_alt_mode_cmd_buf_0( |
| 233 | PMC_IPC_TCSS_ALTMODE_REQ_RES, |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 234 | port_map->usb3_port, |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 235 | PMC_IPC_DP_MODE); |
| 236 | |
| 237 | req.buf[0] = cmd; |
| 238 | |
| 239 | printk(BIOS_DEBUG, "port C%d ALT_1 req: usage %d usb3 %d dp_mode %d\n", |
| 240 | port, |
| 241 | GET_TCSS_ALT_FIELD(USAGE, cmd), |
| 242 | GET_TCSS_ALT_FIELD(USB3, cmd), |
| 243 | GET_TCSS_ALT_FIELD(MODE, cmd)); |
| 244 | |
Sridhar Siricilla | f9ee35e | 2022-12-08 16:15:16 +0530 | [diff] [blame] | 245 | dp_mode = get_dp_mode(mux_data->dp_pin_mode); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 246 | cmd = tcss_make_alt_mode_cmd_buf_1( |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 247 | mux_data->polarity, |
| 248 | mux_data->cable, |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 249 | 0, /* ufp is not supported in DP ALT Mode request */ |
| 250 | dp_mode); |
| 251 | |
| 252 | printk(BIOS_DEBUG, "port C%d ALT_2 req: polarity %d cable %d ufp %d " |
| 253 | "dp_mode %d\n", |
| 254 | port, |
| 255 | GET_TCSS_ALT_FIELD(POLARITY, cmd), |
| 256 | GET_TCSS_ALT_FIELD(CABLE, cmd), |
| 257 | GET_TCSS_ALT_FIELD(UFP, cmd), |
| 258 | GET_TCSS_ALT_FIELD(DP_MODE, cmd)); |
| 259 | |
| 260 | req.buf[1] = cmd; |
| 261 | |
Furquan Shaikh | 338d668 | 2021-03-03 09:45:50 -0800 | [diff] [blame] | 262 | ret = send_pmc_req(DP_REQ, &req, &rsp, PMC_IPC_ALT_REQ_SIZE); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 263 | if (ret) |
| 264 | return ret; |
| 265 | |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 266 | send_pmc_dp_hpd_request(port, mux_data, port_map); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | |
Sean Rhodes | 04afc53 | 2024-01-10 15:46:15 +0000 | [diff] [blame] | 270 | static void disconnect_tcss_devices(int port, const struct tcss_port_map *port_map) |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 271 | { |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 272 | int ret; |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 273 | |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 274 | ret = send_pmc_disconnect_request(port, port_map); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 275 | if (ret) |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 276 | printk(BIOS_ERR, "Failed to setup port:%d to initial state\n", port); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 279 | static void tcss_configure_dp_mode(const struct tcss_port_map *port_map, size_t num_ports) |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 280 | { |
Kapil Porwal | 400f1aa | 2023-07-10 11:40:16 +0000 | [diff] [blame] | 281 | int ret, port_bitmask; |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 282 | size_t i; |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 283 | const struct usbc_ops *ops; |
| 284 | struct usbc_mux_info mux_info; |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 285 | const struct tcss_port_map *port_info; |
Brandon Breitenstein | 2914455 | 2020-11-17 11:29:45 -0800 | [diff] [blame] | 286 | |
| 287 | if (!display_init_required()) |
| 288 | return; |
| 289 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 290 | ops = usbc_get_ops(); |
| 291 | if (ops == NULL) |
| 292 | return; |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 293 | |
Kapil Porwal | 400f1aa | 2023-07-10 11:40:16 +0000 | [diff] [blame] | 294 | port_bitmask = ops->dp_ops.wait_for_connection(WAIT_FOR_DISPLAYPORT_TIMEOUT_MS); |
| 295 | if (!port_bitmask) /* No DP device is connected */ |
| 296 | return; |
| 297 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 298 | for (i = 0; i < num_ports; i++) { |
Kapil Porwal | 400f1aa | 2023-07-10 11:40:16 +0000 | [diff] [blame] | 299 | if (!(port_bitmask & BIT(i))) |
| 300 | continue; |
| 301 | |
| 302 | ret = ops->dp_ops.enter_dp_mode(i); |
| 303 | if (ret < 0) |
| 304 | continue; |
| 305 | |
| 306 | ret = ops->dp_ops.wait_for_dp_mode_entry(i, WAIT_FOR_DP_MODE_ENTRY_TIMEOUT_MS); |
| 307 | if (ret < 0) |
| 308 | continue; |
| 309 | |
| 310 | ret = ops->dp_ops.wait_for_hpd(i, WAIT_FOR_HPD_TIMEOUT_MS); |
| 311 | if (ret < 0) |
| 312 | continue; |
| 313 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 314 | ret = ops->mux_ops.get_mux_info(i, &mux_info); |
Kapil Porwal | 400f1aa | 2023-07-10 11:40:16 +0000 | [diff] [blame] | 315 | if (ret < 0) |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 316 | continue; |
| 317 | |
| 318 | port_info = &port_map[i]; |
| 319 | |
| 320 | ret = send_pmc_connect_request(i, &mux_info, port_info); |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 321 | if (ret) { |
Matt DeVillier | b33778e | 2023-08-04 09:35:32 -0500 | [diff] [blame] | 322 | printk(BIOS_ERR, "Port %zu connect request failed\n", i); |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 323 | continue; |
| 324 | } |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 325 | ret = send_pmc_safe_mode_request(i, &mux_info, port_info); |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 326 | if (ret) { |
Matt DeVillier | b33778e | 2023-08-04 09:35:32 -0500 | [diff] [blame] | 327 | printk(BIOS_ERR, "Port %zu safe mode request failed\n", i); |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 328 | continue; |
| 329 | } |
| 330 | |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 331 | ret = send_pmc_dp_mode_request(i, &mux_info, port_info); |
| 332 | if (ret) { |
Matt DeVillier | b33778e | 2023-08-04 09:35:32 -0500 | [diff] [blame] | 333 | printk(BIOS_ERR, "Port C%zu mux set failed with error %d\n", i, ret); |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 334 | } else { |
Matt DeVillier | b33778e | 2023-08-04 09:35:32 -0500 | [diff] [blame] | 335 | printk(BIOS_INFO, "Port C%zu is configured to DP mode!\n", i); |
Derek Huang | 7f22bc4 | 2021-08-25 17:47:25 +0800 | [diff] [blame] | 336 | return; |
| 337 | } |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
CoolStar | 9c7433e | 2023-02-07 14:44:54 -0800 | [diff] [blame] | 341 | static void tcss_configure_usb_mode(const struct tcss_port_map *port_map, size_t num_ports) |
| 342 | { |
| 343 | int ret; |
| 344 | size_t i; |
| 345 | const struct usbc_ops *ops; |
| 346 | struct usbc_mux_info mux_info; |
| 347 | const struct tcss_port_map *port_info; |
| 348 | |
| 349 | ops = usbc_get_ops(); |
| 350 | if (ops == NULL) |
| 351 | return; |
| 352 | |
| 353 | for (i = 0; i < num_ports; i++) { |
| 354 | ret = ops->mux_ops.get_mux_info(i, &mux_info); |
| 355 | if ((ret < 0) || !mux_info.usb || (mux_info.dp && mux_info.hpd_lvl)) |
| 356 | continue; |
| 357 | |
| 358 | port_info = &port_map[i]; |
| 359 | ret = send_pmc_connect_request(i, &mux_info, port_info); |
| 360 | if (ret) { |
| 361 | printk(BIOS_ERR, "Port %zu connect request failed\n", i); |
| 362 | continue; |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 367 | static uint32_t calc_bias_ctrl_reg_value(gpio_t pad) |
| 368 | { |
| 369 | unsigned int vw_index, vw_bit; |
| 370 | const unsigned int cpu_pid = gpio_get_pad_cpu_portid(pad); |
| 371 | if (!gpio_get_vw_info(pad, &vw_index, &vw_bit) || !cpu_pid) |
| 372 | return 0; |
| 373 | |
| 374 | return vw_index << BIAS_CTRL_VW_INDEX_SHIFT | |
| 375 | vw_bit << BIAS_CTRL_BIT_POS_SHIFT | |
| 376 | cpu_pid; |
| 377 | } |
| 378 | |
John | 848b425 | 2022-03-09 17:51:56 -0800 | [diff] [blame] | 379 | void tcss_configure_aux_bias_pads_regbar( |
John Zhao | 3c46371 | 2022-01-10 15:49:37 -0800 | [diff] [blame] | 380 | const struct typec_aux_bias_pads *pads) |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 381 | { |
| 382 | for (size_t i = 0; i < MAX_TYPE_C_PORTS; i++) { |
| 383 | if (pads[i].pad_auxn_dc && pads[i].pad_auxp_dc) { |
| 384 | REGBAR32(PID_IOM, IOM_AUX_BIAS_CTRL_PULLUP_OFFSET(i)) = |
| 385 | calc_bias_ctrl_reg_value(pads[i].pad_auxp_dc); |
| 386 | REGBAR32(PID_IOM, IOM_AUX_BIAS_CTRL_PULLDOWN_OFFSET(i)) = |
| 387 | calc_bias_ctrl_reg_value(pads[i].pad_auxn_dc); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
John | 2bcc5f3 | 2022-03-27 09:06:25 -0700 | [diff] [blame] | 392 | void ioe_tcss_configure_aux_bias_pads_sbi( |
| 393 | const struct typec_aux_bias_pads *pads) |
| 394 | { |
| 395 | for (size_t i = 0; i < MAX_TYPE_C_PORTS; i++) { |
| 396 | if (pads[i].pad_auxn_dc && pads[i].pad_auxp_dc) { |
| 397 | ioe_p2sb_sbi_write(PID_IOM, IOM_AUX_BIAS_CTRL_PULLUP_OFFSET(i), |
| 398 | calc_bias_ctrl_reg_value(pads[i].pad_auxp_dc)); |
| 399 | ioe_p2sb_sbi_write(PID_IOM, IOM_AUX_BIAS_CTRL_PULLDOWN_OFFSET(i), |
| 400 | calc_bias_ctrl_reg_value(pads[i].pad_auxn_dc)); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 405 | const struct tcss_port_map *tcss_get_port_info(size_t *num_ports) |
| 406 | { |
| 407 | static struct tcss_port_map port_map[MAX_TYPE_C_PORTS]; |
| 408 | size_t active_ports = 0; |
| 409 | size_t port; |
| 410 | |
| 411 | for (port = 0; port < MAX_TYPE_C_PORTS; port++) { |
| 412 | const struct device_path conn_path[] = { |
| 413 | {.type = DEVICE_PATH_PCI, .pci.devfn = PCH_DEVFN_PMC}, |
| 414 | {.type = DEVICE_PATH_GENERIC, .generic.id = 0, .generic.subid = 0}, |
| 415 | {.type = DEVICE_PATH_GENERIC, .generic.id = port}, |
| 416 | }; |
| 417 | const struct device *conn = find_dev_nested_path(pci_root_bus(), conn_path, |
| 418 | ARRAY_SIZE(conn_path)); |
| 419 | unsigned int usb2_port, usb3_port; |
| 420 | |
Reka Norman | e78669e | 2022-03-30 19:49:31 +1100 | [diff] [blame] | 421 | if (!is_dev_enabled(conn)) |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 422 | continue; |
| 423 | |
| 424 | if (CONFIG(DRIVERS_INTEL_PMC) && |
| 425 | intel_pmc_mux_conn_get_ports(conn, &usb2_port, &usb3_port)) { |
| 426 | port_map[active_ports].usb2_port = usb2_port; |
| 427 | port_map[active_ports].usb3_port = usb3_port; |
| 428 | ++active_ports; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | *num_ports = active_ports; |
| 433 | return port_map; |
| 434 | } |
| 435 | |
Tim Wawrzynczak | 59a621a | 2021-03-22 10:43:42 -0600 | [diff] [blame] | 436 | void tcss_configure(const struct typec_aux_bias_pads aux_bias_pads[MAX_TYPE_C_PORTS]) |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 437 | { |
| 438 | const struct tcss_port_map *port_map; |
| 439 | size_t num_ports; |
| 440 | size_t i; |
| 441 | |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 442 | port_map = tcss_get_port_info(&num_ports); |
Sean Rhodes | 7201602 | 2024-01-10 20:38:05 +0000 | [diff] [blame] | 443 | if ((port_map == NULL) || platform_is_resuming()) |
Brandon Breitenstein | d8774f6 | 2021-03-03 14:09:22 -0800 | [diff] [blame] | 444 | return; |
Brandon Breitenstein | 2914455 | 2020-11-17 11:29:45 -0800 | [diff] [blame] | 445 | |
Sean Rhodes | 7201602 | 2024-01-10 20:38:05 +0000 | [diff] [blame] | 446 | if (CONFIG(TCSS_HAS_USBC_OPS)) |
Sridhar Siricilla | db8a97a | 2022-04-29 15:13:38 +0530 | [diff] [blame] | 447 | for (i = 0; i < num_ports; i++) |
Sean Rhodes | 04afc53 | 2024-01-10 15:46:15 +0000 | [diff] [blame] | 448 | disconnect_tcss_devices(i, &port_map[i]); |
Subrata Banik | 97a45e6 | 2022-12-01 16:58:13 +0530 | [diff] [blame] | 449 | |
Sean Rhodes | 7201602 | 2024-01-10 20:38:05 +0000 | [diff] [blame] | 450 | /* This should be performed before alternate modes are entered */ |
| 451 | if (tcss_ops.configure_aux_bias_pads) |
| 452 | tcss_ops.configure_aux_bias_pads(aux_bias_pads); |
Subrata Banik | 97a45e6 | 2022-12-01 16:58:13 +0530 | [diff] [blame] | 453 | |
Sean Rhodes | 7201602 | 2024-01-10 20:38:05 +0000 | [diff] [blame] | 454 | if (CONFIG(ENABLE_TCSS_DISPLAY_DETECTION)) |
| 455 | tcss_configure_dp_mode(port_map, num_ports); |
CoolStar | 9c7433e | 2023-02-07 14:44:54 -0800 | [diff] [blame] | 456 | |
Sean Rhodes | 7201602 | 2024-01-10 20:38:05 +0000 | [diff] [blame] | 457 | if (CONFIG(ENABLE_TCSS_USB_DETECTION)) |
| 458 | tcss_configure_usb_mode(port_map, num_ports); |
Brandon Breitenstein | 99b38a9 | 2019-12-19 23:12:58 -0800 | [diff] [blame] | 459 | } |
John Zhao | 3c46371 | 2022-01-10 15:49:37 -0800 | [diff] [blame] | 460 | |
John | 848b425 | 2022-03-09 17:51:56 -0800 | [diff] [blame] | 461 | bool tcss_valid_tbt_auth(void) |
John Zhao | 3c46371 | 2022-01-10 15:49:37 -0800 | [diff] [blame] | 462 | { |
John | 848b425 | 2022-03-09 17:51:56 -0800 | [diff] [blame] | 463 | return REGBAR32(PID_IOM, IOM_CSME_IMR_TBT_STATUS) & TBT_VALID_AUTHENTICATION; |
John Zhao | 3c46371 | 2022-01-10 15:49:37 -0800 | [diff] [blame] | 464 | } |