Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
| 4 | #include <acpi/acpi_device.h> |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 5 | #include <acpi/acpi_pld.h> |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 9 | #include <drivers/usb/acpi/chip.h> |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 10 | #include <gpio.h> |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 11 | #include <string.h> |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 12 | #include "chip.h" |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 13 | #include "retimer.h" |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 14 | |
| 15 | /* Unique ID for the retimer _DSM. */ |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 16 | #define INTEL_USB4_RETIMER_DSM_UUID "E0053122-795B-4122-8A5E-57BE1D26ACB3" |
| 17 | |
| 18 | static const char *usb4_retimer_scope; |
| 19 | static const char *usb4_retimer_path_arg(const char *arg) |
| 20 | { |
| 21 | /* \\_SB.PCI0.TDMx.ARG */ |
| 22 | static char name[DEVICE_PATH_MAX]; |
| 23 | snprintf(name, sizeof(name), "%s%c%s", usb4_retimer_scope, '.', arg); |
| 24 | return name; |
| 25 | } |
| 26 | |
| 27 | /* Each polling cycle takes up to 25 ms with a total of 12 of these iterations */ |
| 28 | #define USB4_RETIMER_ITERATION_NUM 12 |
| 29 | #define USB4_RETIMER_POLL_CYCLE_MS 25 |
| 30 | static void usb4_retimer_execute_ec_cmd(uint8_t port, uint8_t cmd, uint8_t expected_value) |
| 31 | { |
| 32 | const char *RFWU = ec_retimer_fw_update_path(); |
| 33 | const uint8_t data = cmd << USB_RETIMER_FW_UPDATE_OP_SHIFT | port; |
| 34 | |
| 35 | /* Invoke EC Retimer firmware update command execution */ |
| 36 | ec_retimer_fw_update(data); |
| 37 | /* If RFWU has return value 0xfe, return error -1 */ |
| 38 | acpigen_write_if_lequal_namestr_int(RFWU, USB_RETIMER_FW_UPDATE_ERROR); |
| 39 | acpigen_write_return_integer(-1); |
| 40 | acpigen_pop_len(); /* If */ |
| 41 | |
| 42 | acpigen_write_store_int_to_op(USB4_RETIMER_ITERATION_NUM, LOCAL2_OP); |
| 43 | acpigen_emit_byte(WHILE_OP); |
| 44 | acpigen_write_len_f(); |
| 45 | acpigen_emit_byte(LGREATER_OP); |
| 46 | acpigen_emit_byte(LOCAL2_OP); |
| 47 | acpigen_emit_byte(ZERO_OP); |
| 48 | acpigen_write_if_lequal_namestr_int(RFWU, expected_value); |
| 49 | acpigen_emit_byte(BREAK_OP); |
| 50 | acpigen_pop_len(); /* If */ |
| 51 | |
| 52 | if (cmd == USB_RETIMER_FW_UPDATE_SET_TBT) { |
| 53 | /* |
| 54 | * EC return either USB_PD_MUX_USB4_ENABLED or USB_PD_MUX_TBT_COMPAT_ENABLED |
| 55 | * to RFWU after the USB_RETIMER_FW_UPDATE_SET_TBT command execution. It is |
| 56 | * needed to add additional check for USB_PD_MUX_TBT_COMPAT_ENABLED. |
| 57 | */ |
| 58 | acpigen_write_if_lequal_namestr_int(RFWU, USB_PD_MUX_TBT_COMPAT_ENABLED); |
| 59 | acpigen_emit_byte(BREAK_OP); |
| 60 | acpigen_pop_len(); /* If */ |
| 61 | } |
| 62 | |
| 63 | acpigen_write_sleep(USB4_RETIMER_POLL_CYCLE_MS); |
| 64 | acpigen_emit_byte(DECREMENT_OP); |
| 65 | acpigen_emit_byte(LOCAL2_OP); |
| 66 | acpigen_pop_len(); /* While */ |
| 67 | |
| 68 | /* |
| 69 | * Check whether there is timeout error |
| 70 | * Return: -1 if timeout error occurring |
| 71 | */ |
| 72 | acpigen_write_if_lequal_op_int(LOCAL2_OP, 0); |
| 73 | acpigen_write_return_integer(-1); |
| 74 | acpigen_pop_len(); /* If */ |
| 75 | } |
| 76 | |
| 77 | static void enable_retimer_online_state(uint8_t port, struct acpi_gpio *power_gpio) |
| 78 | { |
| 79 | uint8_t expected_value; |
| 80 | |
| 81 | /* |
| 82 | * Enable_retimer_online_state under NDA |
| 83 | * 1. Force power on |
| 84 | * 2. Check if there is a device connected |
| 85 | * 3. Suspend PD |
| 86 | * 4. Set Mux to USB mode |
| 87 | * 5. Set Mux to Safe mode |
| 88 | * 6. Set Mux to TBT mode |
| 89 | */ |
| 90 | |
| 91 | /* Force power on for the retimer on the port */ |
| 92 | acpigen_enable_tx_gpio(power_gpio); |
| 93 | |
| 94 | /* |
| 95 | * Get MUX mode state |
| 96 | * Return -1 if there is a device connected on the port. |
| 97 | * Otherwise proceed Retimer firmware upgrade operation. |
| 98 | */ |
| 99 | expected_value = USB_PD_MUX_NONE; |
| 100 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_GET_MUX, expected_value); |
| 101 | |
| 102 | /* |
| 103 | * Suspend PD |
| 104 | * Command: USB_RETIMER_FW_UPDATE_SUSPEND_PD |
| 105 | * Expect return value: 0 |
| 106 | */ |
| 107 | expected_value = 0; |
| 108 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SUSPEND_PD, expected_value); |
| 109 | |
| 110 | /* |
| 111 | * Set MUX USB Mode |
| 112 | * Command: USB_RETIMER_FW_UPDATE_SUSPEND_PD |
| 113 | * Expect return value: USB_PD_MUX_USB_ENABLED |
| 114 | */ |
| 115 | expected_value = USB_PD_MUX_USB_ENABLED; |
| 116 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SET_USB, expected_value); |
| 117 | |
| 118 | /* |
| 119 | * Set MUX Safe Mode |
| 120 | * Command: USB_RETIMER_FW_UPDATE_SET_SAFE |
| 121 | * Expect return value: USB_PD_MUX_SAFE_MODE |
| 122 | */ |
| 123 | expected_value = USB_PD_MUX_SAFE_MODE; |
| 124 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SET_SAFE, expected_value); |
| 125 | |
| 126 | /* |
| 127 | * Set MUX TBT Mode |
| 128 | * Command: USB_RETIMER_FW_UPDATE_SET_TBT |
| 129 | * Expect return value: USB_PD_MUX_USB4_ENABLED or USB_PD_MUX_TBT_COMPAT_ENABLED |
| 130 | */ |
| 131 | expected_value = USB_PD_MUX_USB4_ENABLED; |
| 132 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SET_TBT, expected_value); |
| 133 | } |
| 134 | |
| 135 | static void disable_retimer_online_state(uint8_t port, struct acpi_gpio *power_gpio) |
| 136 | { |
| 137 | uint8_t expected_value; |
| 138 | |
| 139 | /* |
| 140 | * Disable_retimer_online_state |
| 141 | * 1. Set Mux to disconnect mode |
| 142 | * 2. Resume PD |
| 143 | * 3. Force power off |
| 144 | */ |
| 145 | |
| 146 | /* |
| 147 | * Set MUX Disconnect Mode |
| 148 | * Command: USB_RETIMER_FW_UPDATE_DISCONNECT |
| 149 | * Expect return value: 0 |
| 150 | */ |
| 151 | expected_value = 0; |
| 152 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_DISCONNECT, expected_value); |
| 153 | |
| 154 | /* |
| 155 | * Resume PD |
| 156 | * Command: USB_RETIMER_FW_UPDATE_RESUME_PD |
| 157 | * Expect return value: 1 |
| 158 | */ |
| 159 | expected_value = 1; |
| 160 | usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_RESUME_PD, expected_value); |
| 161 | |
| 162 | /* Force power off */ |
| 163 | acpigen_disable_tx_gpio(power_gpio); |
| 164 | } |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 165 | |
| 166 | /* |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 167 | * Arg0: UUID e0053122-795b-4122-8a5e-57be1d26acb3 |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 168 | * Arg1: Revision ID (set to 1) |
| 169 | * Arg2: Function Index |
| 170 | * 0: Query command implemented |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 171 | * 1: Get power state |
| 172 | * 2: Set power state |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 173 | * Arg3: A package containing parameters for the function specified |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 174 | * by the UUID, revision ID, function index and port index. |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 175 | */ |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 176 | static void usb4_retimer_cb_standard_query(uint8_t port, void *arg) |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 177 | { |
| 178 | /* |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 179 | * ToInteger (Arg1, Local1) |
| 180 | * If (Local1 == 1) { |
| 181 | * Return(Buffer() {0x7}) |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 182 | * } |
| 183 | * Return (Buffer() {0x01}) |
| 184 | */ |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 185 | acpigen_write_to_integer(ARG1_OP, LOCAL1_OP); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 186 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 187 | /* Revision 1 supports 2 Functions beyond the standard query */ |
| 188 | acpigen_write_if_lequal_op_int(LOCAL1_OP, 1); |
| 189 | acpigen_write_return_singleton_buffer(0x7); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 190 | acpigen_pop_len(); /* If */ |
| 191 | |
| 192 | /* Other revisions support no additional functions */ |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 193 | acpigen_write_return_singleton_buffer(0x1); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 194 | } |
| 195 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 196 | static void usb4_retimer_cb_get_power_state(uint8_t port, void *arg) |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 197 | { |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 198 | const char *PWR; |
| 199 | char pwr[DEVICE_PATH_MAX]; |
| 200 | |
| 201 | snprintf(pwr, sizeof(pwr), "HR.DFP%1d.PWR", port); |
| 202 | PWR = usb4_retimer_path_arg(pwr); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 203 | |
| 204 | /* |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 205 | * If (PWR > 0) { |
| 206 | * Return (1) |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 207 | * } |
| 208 | */ |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 209 | acpigen_write_if(); |
| 210 | acpigen_emit_byte(LGREATER_OP); |
| 211 | acpigen_emit_namestring(PWR); |
| 212 | acpigen_emit_byte(0); |
| 213 | acpigen_write_return_integer(1); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 214 | |
| 215 | /* |
| 216 | * Else { |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 217 | * Return (0) |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 218 | * } |
| 219 | */ |
| 220 | acpigen_write_else(); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 221 | acpigen_write_return_integer(0); |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 222 | acpigen_pop_len(); |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 223 | } |
| 224 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 225 | static void usb4_retimer_cb_set_power_state(uint8_t port, void *arg) |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 226 | { |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 227 | struct acpi_gpio *power_gpio = arg; |
| 228 | const char *PWR; |
| 229 | char pwr[DEVICE_PATH_MAX]; |
| 230 | |
| 231 | snprintf(pwr, sizeof(pwr), "HR.DFP%1d.PWR", port); |
| 232 | PWR = usb4_retimer_path_arg(pwr); |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 233 | |
| 234 | /* |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 235 | * Get information to set retimer power state from Arg3[0] |
| 236 | * Local1 = DeRefOf (Arg3[0]) |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 237 | */ |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 238 | acpigen_get_package_op_element(ARG3_OP, 0, LOCAL1_OP); |
| 239 | |
| 240 | /* |
| 241 | * If ((Local1 == 0) && (PWR > 0)) { |
| 242 | * PWR-- |
| 243 | * If (PWR == 0) { |
| 244 | * // Disable retimer online state |
| 245 | * } |
| 246 | * } |
| 247 | */ |
| 248 | acpigen_write_if(); |
| 249 | acpigen_emit_byte(LAND_OP); |
| 250 | acpigen_emit_byte(LEQUAL_OP); |
| 251 | acpigen_emit_byte(LOCAL1_OP); |
| 252 | acpigen_emit_byte(0); |
| 253 | acpigen_emit_byte(LGREATER_OP); |
| 254 | acpigen_emit_namestring(PWR); |
| 255 | acpigen_emit_byte(0); |
| 256 | /* PWR-- */ |
| 257 | acpigen_emit_byte(DECREMENT_OP); |
| 258 | acpigen_emit_namestring(PWR); |
| 259 | acpigen_write_if_lequal_namestr_int(PWR, 0); /* If (PWR == 0) */ |
| 260 | disable_retimer_online_state(port, power_gpio); |
| 261 | acpigen_pop_len(); /* If (PWR == 0) */ |
| 262 | |
| 263 | /* |
| 264 | * Else If ((Local1 == 1) && (PWR == 0)) { |
| 265 | * // Enable retimer online state |
| 266 | * PWR++ |
| 267 | * } |
| 268 | */ |
| 269 | acpigen_write_else(); |
| 270 | acpigen_write_if(); |
| 271 | acpigen_emit_byte(LAND_OP); |
| 272 | acpigen_emit_byte(LEQUAL_OP); |
| 273 | acpigen_emit_byte(LOCAL1_OP); |
| 274 | acpigen_emit_byte(1); |
| 275 | acpigen_emit_byte(LEQUAL_OP); |
| 276 | acpigen_emit_namestring(PWR); |
| 277 | acpigen_emit_byte(0); |
| 278 | enable_retimer_online_state(port, power_gpio); |
| 279 | /* PWR++ */ |
| 280 | acpigen_emit_byte(INCREMENT_OP); |
| 281 | acpigen_emit_namestring(PWR); |
| 282 | |
| 283 | /* |
| 284 | * Else { |
| 285 | * Return (0) |
| 286 | * } |
| 287 | */ |
| 288 | acpigen_write_else(); |
| 289 | acpigen_write_return_integer(0); |
| 290 | acpigen_pop_len(); /* Else */ |
| 291 | acpigen_pop_len(); /* If */ |
| 292 | |
| 293 | /* |
| 294 | * If (PWR == 1) { |
| 295 | * Return (1) |
| 296 | * } |
| 297 | */ |
| 298 | acpigen_write_if_lequal_namestr_int(PWR, 1); |
| 299 | acpigen_write_return_integer(1); |
| 300 | |
| 301 | /* |
| 302 | * Else { |
| 303 | * Return (0) |
| 304 | * } |
| 305 | */ |
| 306 | acpigen_write_else(); |
| 307 | acpigen_write_return_integer(0); |
| 308 | acpigen_pop_len(); |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 309 | } |
| 310 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 311 | static void (*usb4_retimer_callbacks[3])(uint8_t port, void *) = { |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 312 | usb4_retimer_cb_standard_query, /* Function 0 */ |
| 313 | usb4_retimer_cb_get_power_state, /* Function 1 */ |
| 314 | usb4_retimer_cb_set_power_state, /* Function 2 */ |
| 315 | }; |
| 316 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 317 | static void usb4_retimer_write_dsm(uint8_t port, const char *uuid, |
| 318 | void (**callbacks)(uint8_t port, void *), size_t count, void *arg) |
| 319 | { |
| 320 | struct usb4_retimer_dsm_uuid id = DSM_UUID(uuid, callbacks, count, arg); |
| 321 | size_t i; |
| 322 | |
| 323 | acpigen_write_to_integer(ARG2_OP, LOCAL0_OP); |
| 324 | |
| 325 | for (i = 0; i < id.count; i++) { |
| 326 | /* If (LEqual (Local0, i)) */ |
| 327 | acpigen_write_if_lequal_op_int(LOCAL0_OP, i); |
| 328 | |
| 329 | /* Callback to write if handler. */ |
| 330 | if (id.callbacks[i]) |
| 331 | id.callbacks[i](port, id.arg); |
| 332 | |
| 333 | acpigen_pop_len(); /* If */ |
| 334 | } |
| 335 | } |
| 336 | |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 337 | static void usb4_retimer_fill_ssdt(const struct device *dev) |
| 338 | { |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 339 | struct drivers_intel_usb4_retimer_config *config = dev->chip_info; |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 340 | const struct device *usb_device; |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 341 | static char dfp[DEVICE_PATH_MAX]; |
| 342 | struct acpi_pld pld; |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 343 | uint8_t dfp_port, usb_port; |
MAULIK V VAGHELA | a70288d | 2021-11-25 14:41:19 +0530 | [diff] [blame] | 344 | int ec_port = 0; |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 345 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 346 | usb4_retimer_scope = acpi_device_scope(dev); |
| 347 | if (!usb4_retimer_scope || !config) |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 348 | return; |
| 349 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 350 | /* Scope */ |
| 351 | acpigen_write_scope(usb4_retimer_scope); |
| 352 | |
| 353 | /* Host router */ |
| 354 | acpigen_write_device("HR"); |
| 355 | acpigen_write_ADR(0); |
| 356 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
| 357 | |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 358 | for (dfp_port = 0; dfp_port < DFP_NUM_MAX; dfp_port++) { |
| 359 | |
| 360 | if (!config->dfp[dfp_port].power_gpio.pin_count) { |
| 361 | printk(BIOS_ERR, "%s: No DFP%1d power GPIO for %s\n", |
| 362 | __func__, dfp_port, dev_path(dev)); |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 363 | continue; |
| 364 | } |
| 365 | |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 366 | usb_device = config->dfp[dfp_port].typec_port; |
| 367 | usb_port = usb_device->path.usb.port_id; |
| 368 | |
MAULIK V VAGHELA | a70288d | 2021-11-25 14:41:19 +0530 | [diff] [blame] | 369 | ec_port = retimer_get_index_for_typec(usb_port); |
| 370 | if (ec_port == -1) { |
| 371 | printk(BIOS_ERR, "%s: No relative EC port found for TC port %d\n", |
| 372 | __func__, usb_port); |
Elyes Haouas | 5b0103f | 2022-02-16 16:43:42 +0100 | [diff] [blame^] | 373 | continue; |
MAULIK V VAGHELA | a70288d | 2021-11-25 14:41:19 +0530 | [diff] [blame] | 374 | } |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 375 | /* DFPx */ |
MAULIK V VAGHELA | a70288d | 2021-11-25 14:41:19 +0530 | [diff] [blame] | 376 | snprintf(dfp, sizeof(dfp), "DFP%1d", ec_port); |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 377 | acpigen_write_device(dfp); |
| 378 | /* _ADR part is for the lane adapter */ |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 379 | acpigen_write_ADR(dfp_port*2 + 1); |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 380 | |
| 381 | /* Fill _PLD with the same USB 3.x object on the Type-C connector */ |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 382 | if (CONFIG(DRIVERS_USB_ACPI)) { |
| 383 | if (usb_acpi_get_pld(usb_device, &pld)) |
| 384 | acpigen_write_pld(&pld); |
| 385 | else |
| 386 | printk(BIOS_ERR, "Error retrieving PLD for USB Type-C %d\n", |
| 387 | usb_port); |
| 388 | } |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 389 | |
| 390 | /* Power online reference counter(_PWR) */ |
| 391 | acpigen_write_name("PWR"); |
| 392 | acpigen_write_zero(); |
| 393 | |
| 394 | /* Method (_DSM, 4, Serialized) */ |
| 395 | acpigen_write_method_serialized("_DSM", 0x4); |
| 396 | /* ToBuffer (Arg0, Local0) */ |
| 397 | acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP); |
| 398 | acpigen_write_if(); /* If (UUID != INTEL_USB4_RETIMER_DSM_UUID) */ |
| 399 | acpigen_emit_byte(LNOT_OP); |
| 400 | acpigen_emit_byte(LEQUAL_OP); |
| 401 | acpigen_emit_byte(LOCAL0_OP); |
| 402 | acpigen_write_uuid(INTEL_USB4_RETIMER_DSM_UUID); |
| 403 | /* Return (Buffer (One) { 0x0 }) */ |
| 404 | acpigen_write_return_singleton_buffer(0x0); |
| 405 | acpigen_pop_len(); |
MAULIK V VAGHELA | a70288d | 2021-11-25 14:41:19 +0530 | [diff] [blame] | 406 | usb4_retimer_write_dsm(ec_port, INTEL_USB4_RETIMER_DSM_UUID, |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 407 | usb4_retimer_callbacks, ARRAY_SIZE(usb4_retimer_callbacks), |
Maulik V Vaghela | 0f7e086 | 2021-06-29 17:16:49 +0530 | [diff] [blame] | 408 | (void *)&config->dfp[dfp_port].power_gpio); |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 409 | /* Default case: Return (Buffer (One) { 0x0 }) */ |
| 410 | acpigen_write_return_singleton_buffer(0x0); |
| 411 | |
| 412 | acpigen_pop_len(); /* Method _DSM */ |
| 413 | acpigen_pop_len(); /* DFP */ |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 414 | } |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 415 | acpigen_pop_len(); /* Host Router */ |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 416 | acpigen_pop_len(); /* Scope */ |
| 417 | |
Eric Lai | ef8a139 | 2022-01-22 14:06:54 +0800 | [diff] [blame] | 418 | printk(BIOS_INFO, "%s.HR: %s at %s\n", usb4_retimer_scope, dev->chip_ops->name, |
Duncan Laurie | 2cc126b | 2020-08-28 19:46:35 +0000 | [diff] [blame] | 419 | dev_path(dev)); |
| 420 | } |
| 421 | |
| 422 | static struct device_operations usb4_retimer_dev_ops = { |
| 423 | .read_resources = noop_read_resources, |
| 424 | .set_resources = noop_set_resources, |
| 425 | .acpi_fill_ssdt = usb4_retimer_fill_ssdt, |
| 426 | }; |
| 427 | |
| 428 | static void usb4_retimer_enable(struct device *dev) |
| 429 | { |
| 430 | dev->ops = &usb4_retimer_dev_ops; |
| 431 | } |
| 432 | |
| 433 | struct chip_operations drivers_intel_usb4_retimer_ops = { |
| 434 | CHIP_NAME("Intel USB4 Retimer") |
| 435 | .enable_dev = usb4_retimer_enable |
| 436 | }; |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 437 | |
| 438 | __weak const char *ec_retimer_fw_update_path(void) |
| 439 | { |
| 440 | return NULL; |
| 441 | } |
| 442 | |
John Zhao | 0b3f15c | 2021-04-27 10:47:25 -0700 | [diff] [blame] | 443 | __weak void ec_retimer_fw_update(uint8_t data) |
Brandon Breitenstein | 297d27b | 2020-12-14 13:52:24 -0800 | [diff] [blame] | 444 | { |
| 445 | } |
MAULIK V VAGHELA | a70288d | 2021-11-25 14:41:19 +0530 | [diff] [blame] | 446 | |
| 447 | /* |
| 448 | * This function will convert CPU physical port mapping to abstract |
| 449 | * EC port mapping. |
| 450 | * For example, board might have enabled TCSS port 1 and 3 as per physical |
| 451 | * port mapping. Since only 2 TCSS ports are enabled EC will index it as port 0 |
| 452 | * and port 1. So there will be an issue when coreboot sends command to EC for |
| 453 | * port 3 (with coreboot index of 2). EC will produce an error due to wrong index. |
| 454 | * |
| 455 | * Note: Each SoC code using retimer driver needs to implement this function |
| 456 | * since SoC will have physical port details. |
| 457 | */ |
| 458 | __weak int retimer_get_index_for_typec(uint8_t typec_port) |
| 459 | { |
| 460 | /* By default assume that retimer port index = Type C port */ |
| 461 | return (int)typec_port; |
| 462 | } |