blob: 9e627de3485ddbe2b06145cee840672f546f1912 [file] [log] [blame]
Duncan Laurie2cc126b2020-08-28 19:46:35 +00001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <acpi/acpigen.h>
4#include <acpi/acpi_device.h>
John Zhao0b3f15c2021-04-27 10:47:25 -07005#include <acpi/acpi_pld.h>
Duncan Laurie2cc126b2020-08-28 19:46:35 +00006#include <console/console.h>
7#include <device/device.h>
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +05308#include <drivers/usb/acpi/chip.h>
Duncan Laurie2cc126b2020-08-28 19:46:35 +00009#include <gpio.h>
John Zhao0b3f15c2021-04-27 10:47:25 -070010#include <string.h>
Duncan Laurie2cc126b2020-08-28 19:46:35 +000011#include "chip.h"
Brandon Breitenstein297d27b2020-12-14 13:52:24 -080012#include "retimer.h"
Duncan Laurie2cc126b2020-08-28 19:46:35 +000013
14/* Unique ID for the retimer _DSM. */
John Zhao0b3f15c2021-04-27 10:47:25 -070015#define INTEL_USB4_RETIMER_DSM_UUID "E0053122-795B-4122-8A5E-57BE1D26ACB3"
16
17static const char *usb4_retimer_scope;
18static const char *usb4_retimer_path_arg(const char *arg)
19{
20 /* \\_SB.PCI0.TDMx.ARG */
21 static char name[DEVICE_PATH_MAX];
22 snprintf(name, sizeof(name), "%s%c%s", usb4_retimer_scope, '.', arg);
23 return name;
24}
25
26/* Each polling cycle takes up to 25 ms with a total of 12 of these iterations */
27#define USB4_RETIMER_ITERATION_NUM 12
28#define USB4_RETIMER_POLL_CYCLE_MS 25
John1dfed8f2022-04-21 17:58:16 -070029static void usb4_retimer_execute_ec_cmd(uint8_t port, uint8_t cmd, uint8_t expected_value,
30 struct acpi_gpio *power_gpio)
John Zhao0b3f15c2021-04-27 10:47:25 -070031{
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);
John1dfed8f2022-04-21 17:58:16 -070039 acpigen_disable_tx_gpio(power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -070040 acpigen_write_return_integer(-1);
41 acpigen_pop_len(); /* If */
42
43 acpigen_write_store_int_to_op(USB4_RETIMER_ITERATION_NUM, LOCAL2_OP);
44 acpigen_emit_byte(WHILE_OP);
45 acpigen_write_len_f();
46 acpigen_emit_byte(LGREATER_OP);
47 acpigen_emit_byte(LOCAL2_OP);
48 acpigen_emit_byte(ZERO_OP);
49 acpigen_write_if_lequal_namestr_int(RFWU, expected_value);
50 acpigen_emit_byte(BREAK_OP);
51 acpigen_pop_len(); /* If */
52
John1dfed8f2022-04-21 17:58:16 -070053 if (cmd == USB_RETIMER_FW_UPDATE_GET_MUX) {
54 acpigen_write_if_lequal_namestr_int(RFWU, USB_RETIMER_FW_UPDATE_INVALID_MUX);
55 acpigen_write_sleep(USB4_RETIMER_POLL_CYCLE_MS);
56 acpigen_emit_byte(DECREMENT_OP);
57 acpigen_emit_byte(LOCAL2_OP);
58 acpigen_emit_byte(CONTINUE_OP);
59 acpigen_pop_len(); /* If */
60
61 acpigen_emit_byte(AND_OP);
62 acpigen_emit_namestring(RFWU);
63 acpigen_write_integer(USB_RETIMER_FW_UPDATE_MUX_MASK);
64 acpigen_emit_byte(LOCAL3_OP);
65 acpigen_write_if();
66 acpigen_emit_byte(LNOT_OP);
67 acpigen_emit_byte(LEQUAL_OP);
68 acpigen_emit_byte(LOCAL3_OP);
69 acpigen_emit_byte(0);
70 acpigen_disable_tx_gpio(power_gpio);
71 acpigen_write_return_integer(-1);
72 acpigen_pop_len(); /* If */
73 } else if (cmd == USB_RETIMER_FW_UPDATE_SET_TBT) {
John Zhao0b3f15c2021-04-27 10:47:25 -070074 /*
75 * EC return either USB_PD_MUX_USB4_ENABLED or USB_PD_MUX_TBT_COMPAT_ENABLED
76 * to RFWU after the USB_RETIMER_FW_UPDATE_SET_TBT command execution. It is
77 * needed to add additional check for USB_PD_MUX_TBT_COMPAT_ENABLED.
78 */
79 acpigen_write_if_lequal_namestr_int(RFWU, USB_PD_MUX_TBT_COMPAT_ENABLED);
80 acpigen_emit_byte(BREAK_OP);
81 acpigen_pop_len(); /* If */
82 }
83
84 acpigen_write_sleep(USB4_RETIMER_POLL_CYCLE_MS);
85 acpigen_emit_byte(DECREMENT_OP);
86 acpigen_emit_byte(LOCAL2_OP);
87 acpigen_pop_len(); /* While */
88
89 /*
90 * Check whether there is timeout error
91 * Return: -1 if timeout error occurring
92 */
93 acpigen_write_if_lequal_op_int(LOCAL2_OP, 0);
John1dfed8f2022-04-21 17:58:16 -070094 acpigen_disable_tx_gpio(power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -070095 acpigen_write_return_integer(-1);
96 acpigen_pop_len(); /* If */
97}
98
99static void enable_retimer_online_state(uint8_t port, struct acpi_gpio *power_gpio)
100{
101 uint8_t expected_value;
102
103 /*
104 * Enable_retimer_online_state under NDA
105 * 1. Force power on
106 * 2. Check if there is a device connected
107 * 3. Suspend PD
108 * 4. Set Mux to USB mode
109 * 5. Set Mux to Safe mode
110 * 6. Set Mux to TBT mode
111 */
112
113 /* Force power on for the retimer on the port */
114 acpigen_enable_tx_gpio(power_gpio);
115
116 /*
117 * Get MUX mode state
118 * Return -1 if there is a device connected on the port.
119 * Otherwise proceed Retimer firmware upgrade operation.
120 */
121 expected_value = USB_PD_MUX_NONE;
John1dfed8f2022-04-21 17:58:16 -0700122 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_GET_MUX, expected_value,
123 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700124
125 /*
126 * Suspend PD
127 * Command: USB_RETIMER_FW_UPDATE_SUSPEND_PD
128 * Expect return value: 0
129 */
130 expected_value = 0;
John1dfed8f2022-04-21 17:58:16 -0700131 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SUSPEND_PD, expected_value,
132 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700133
134 /*
135 * Set MUX USB Mode
136 * Command: USB_RETIMER_FW_UPDATE_SUSPEND_PD
137 * Expect return value: USB_PD_MUX_USB_ENABLED
138 */
139 expected_value = USB_PD_MUX_USB_ENABLED;
John1dfed8f2022-04-21 17:58:16 -0700140 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SET_USB, expected_value,
141 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700142
143 /*
144 * Set MUX Safe Mode
145 * Command: USB_RETIMER_FW_UPDATE_SET_SAFE
146 * Expect return value: USB_PD_MUX_SAFE_MODE
147 */
148 expected_value = USB_PD_MUX_SAFE_MODE;
John1dfed8f2022-04-21 17:58:16 -0700149 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SET_SAFE, expected_value,
150 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700151
152 /*
153 * Set MUX TBT Mode
154 * Command: USB_RETIMER_FW_UPDATE_SET_TBT
155 * Expect return value: USB_PD_MUX_USB4_ENABLED or USB_PD_MUX_TBT_COMPAT_ENABLED
156 */
157 expected_value = USB_PD_MUX_USB4_ENABLED;
John1dfed8f2022-04-21 17:58:16 -0700158 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_SET_TBT, expected_value,
159 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700160}
161
162static void disable_retimer_online_state(uint8_t port, struct acpi_gpio *power_gpio)
163{
164 uint8_t expected_value;
165
166 /*
167 * Disable_retimer_online_state
168 * 1. Set Mux to disconnect mode
169 * 2. Resume PD
170 * 3. Force power off
171 */
172
173 /*
174 * Set MUX Disconnect Mode
175 * Command: USB_RETIMER_FW_UPDATE_DISCONNECT
176 * Expect return value: 0
177 */
178 expected_value = 0;
John1dfed8f2022-04-21 17:58:16 -0700179 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_DISCONNECT, expected_value,
180 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700181
182 /*
183 * Resume PD
184 * Command: USB_RETIMER_FW_UPDATE_RESUME_PD
185 * Expect return value: 1
186 */
187 expected_value = 1;
John1dfed8f2022-04-21 17:58:16 -0700188 usb4_retimer_execute_ec_cmd(port, USB_RETIMER_FW_UPDATE_RESUME_PD, expected_value,
189 power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700190
191 /* Force power off */
192 acpigen_disable_tx_gpio(power_gpio);
193}
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000194
195/*
John Zhao0b3f15c2021-04-27 10:47:25 -0700196 * Arg0: UUID e0053122-795b-4122-8a5e-57be1d26acb3
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000197 * Arg1: Revision ID (set to 1)
198 * Arg2: Function Index
199 * 0: Query command implemented
John Zhao0b3f15c2021-04-27 10:47:25 -0700200 * 1: Get power state
201 * 2: Set power state
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000202 * Arg3: A package containing parameters for the function specified
John Zhao0b3f15c2021-04-27 10:47:25 -0700203 * by the UUID, revision ID, function index and port index.
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000204 */
John Zhao0b3f15c2021-04-27 10:47:25 -0700205static void usb4_retimer_cb_standard_query(uint8_t port, void *arg)
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000206{
207 /*
John Zhao0b3f15c2021-04-27 10:47:25 -0700208 * ToInteger (Arg1, Local1)
209 * If (Local1 == 1) {
210 * Return(Buffer() {0x7})
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000211 * }
212 * Return (Buffer() {0x01})
213 */
John Zhao0b3f15c2021-04-27 10:47:25 -0700214 acpigen_write_to_integer(ARG1_OP, LOCAL1_OP);
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000215
John Zhao0b3f15c2021-04-27 10:47:25 -0700216 /* Revision 1 supports 2 Functions beyond the standard query */
217 acpigen_write_if_lequal_op_int(LOCAL1_OP, 1);
218 acpigen_write_return_singleton_buffer(0x7);
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000219 acpigen_pop_len(); /* If */
220
221 /* Other revisions support no additional functions */
John Zhao0b3f15c2021-04-27 10:47:25 -0700222 acpigen_write_return_singleton_buffer(0x1);
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000223}
224
John Zhao0b3f15c2021-04-27 10:47:25 -0700225static void usb4_retimer_cb_get_power_state(uint8_t port, void *arg)
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000226{
John Zhao0b3f15c2021-04-27 10:47:25 -0700227 const char *PWR;
228 char pwr[DEVICE_PATH_MAX];
229
230 snprintf(pwr, sizeof(pwr), "HR.DFP%1d.PWR", port);
231 PWR = usb4_retimer_path_arg(pwr);
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000232
233 /*
John Zhao0b3f15c2021-04-27 10:47:25 -0700234 * If (PWR > 0) {
235 * Return (1)
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000236 * }
237 */
John Zhao0b3f15c2021-04-27 10:47:25 -0700238 acpigen_write_if();
239 acpigen_emit_byte(LGREATER_OP);
240 acpigen_emit_namestring(PWR);
241 acpigen_emit_byte(0);
242 acpigen_write_return_integer(1);
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000243
244 /*
245 * Else {
John Zhao0b3f15c2021-04-27 10:47:25 -0700246 * Return (0)
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000247 * }
248 */
249 acpigen_write_else();
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000250 acpigen_write_return_integer(0);
John Zhao0b3f15c2021-04-27 10:47:25 -0700251 acpigen_pop_len();
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000252}
253
John Zhao0b3f15c2021-04-27 10:47:25 -0700254static void usb4_retimer_cb_set_power_state(uint8_t port, void *arg)
Brandon Breitenstein297d27b2020-12-14 13:52:24 -0800255{
John Zhao0b3f15c2021-04-27 10:47:25 -0700256 struct acpi_gpio *power_gpio = arg;
257 const char *PWR;
258 char pwr[DEVICE_PATH_MAX];
259
260 snprintf(pwr, sizeof(pwr), "HR.DFP%1d.PWR", port);
261 PWR = usb4_retimer_path_arg(pwr);
Brandon Breitenstein297d27b2020-12-14 13:52:24 -0800262
263 /*
John Zhao0b3f15c2021-04-27 10:47:25 -0700264 * Get information to set retimer power state from Arg3[0]
265 * Local1 = DeRefOf (Arg3[0])
Brandon Breitenstein297d27b2020-12-14 13:52:24 -0800266 */
John Zhao0b3f15c2021-04-27 10:47:25 -0700267 acpigen_get_package_op_element(ARG3_OP, 0, LOCAL1_OP);
268
269 /*
270 * If ((Local1 == 0) && (PWR > 0)) {
271 * PWR--
272 * If (PWR == 0) {
273 * // Disable retimer online state
274 * }
275 * }
276 */
277 acpigen_write_if();
278 acpigen_emit_byte(LAND_OP);
279 acpigen_emit_byte(LEQUAL_OP);
280 acpigen_emit_byte(LOCAL1_OP);
281 acpigen_emit_byte(0);
282 acpigen_emit_byte(LGREATER_OP);
283 acpigen_emit_namestring(PWR);
284 acpigen_emit_byte(0);
285 /* PWR-- */
286 acpigen_emit_byte(DECREMENT_OP);
287 acpigen_emit_namestring(PWR);
288 acpigen_write_if_lequal_namestr_int(PWR, 0); /* If (PWR == 0) */
289 disable_retimer_online_state(port, power_gpio);
290 acpigen_pop_len(); /* If (PWR == 0) */
291
292 /*
293 * Else If ((Local1 == 1) && (PWR == 0)) {
294 * // Enable retimer online state
295 * PWR++
296 * }
297 */
298 acpigen_write_else();
299 acpigen_write_if();
300 acpigen_emit_byte(LAND_OP);
301 acpigen_emit_byte(LEQUAL_OP);
302 acpigen_emit_byte(LOCAL1_OP);
303 acpigen_emit_byte(1);
304 acpigen_emit_byte(LEQUAL_OP);
305 acpigen_emit_namestring(PWR);
306 acpigen_emit_byte(0);
307 enable_retimer_online_state(port, power_gpio);
308 /* PWR++ */
309 acpigen_emit_byte(INCREMENT_OP);
310 acpigen_emit_namestring(PWR);
311
312 /*
313 * Else {
314 * Return (0)
315 * }
316 */
317 acpigen_write_else();
318 acpigen_write_return_integer(0);
319 acpigen_pop_len(); /* Else */
320 acpigen_pop_len(); /* If */
321
322 /*
323 * If (PWR == 1) {
324 * Return (1)
325 * }
326 */
327 acpigen_write_if_lequal_namestr_int(PWR, 1);
328 acpigen_write_return_integer(1);
329
330 /*
331 * Else {
332 * Return (0)
333 * }
334 */
335 acpigen_write_else();
336 acpigen_write_return_integer(0);
337 acpigen_pop_len();
Brandon Breitenstein297d27b2020-12-14 13:52:24 -0800338}
339
John Zhao0b3f15c2021-04-27 10:47:25 -0700340static void (*usb4_retimer_callbacks[3])(uint8_t port, void *) = {
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000341 usb4_retimer_cb_standard_query, /* Function 0 */
342 usb4_retimer_cb_get_power_state, /* Function 1 */
343 usb4_retimer_cb_set_power_state, /* Function 2 */
344};
345
John Zhao0b3f15c2021-04-27 10:47:25 -0700346static void usb4_retimer_write_dsm(uint8_t port, const char *uuid,
347 void (**callbacks)(uint8_t port, void *), size_t count, void *arg)
348{
349 struct usb4_retimer_dsm_uuid id = DSM_UUID(uuid, callbacks, count, arg);
350 size_t i;
351
352 acpigen_write_to_integer(ARG2_OP, LOCAL0_OP);
353
354 for (i = 0; i < id.count; i++) {
355 /* If (LEqual (Local0, i)) */
356 acpigen_write_if_lequal_op_int(LOCAL0_OP, i);
357
358 /* Callback to write if handler. */
359 if (id.callbacks[i])
360 id.callbacks[i](port, id.arg);
361
362 acpigen_pop_len(); /* If */
363 }
364}
365
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000366static void usb4_retimer_fill_ssdt(const struct device *dev)
367{
John Zhao0b3f15c2021-04-27 10:47:25 -0700368 struct drivers_intel_usb4_retimer_config *config = dev->chip_info;
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530369 const struct device *usb_device;
John Zhao0b3f15c2021-04-27 10:47:25 -0700370 static char dfp[DEVICE_PATH_MAX];
371 struct acpi_pld pld;
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530372 uint8_t dfp_port, usb_port;
MAULIK V VAGHELAa70288d2021-11-25 14:41:19 +0530373 int ec_port = 0;
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000374
John Zhao0b3f15c2021-04-27 10:47:25 -0700375 usb4_retimer_scope = acpi_device_scope(dev);
376 if (!usb4_retimer_scope || !config)
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000377 return;
378
John Zhao0b3f15c2021-04-27 10:47:25 -0700379 /* Scope */
380 acpigen_write_scope(usb4_retimer_scope);
381
382 /* Host router */
383 acpigen_write_device("HR");
384 acpigen_write_ADR(0);
385 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
386
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530387 for (dfp_port = 0; dfp_port < DFP_NUM_MAX; dfp_port++) {
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530388 if (!config->dfp[dfp_port].power_gpio.pin_count) {
Wisley Chendc27d802022-03-15 16:31:47 +0600389 printk(BIOS_WARNING, "%s: No DFP%1d power GPIO for %s\n",
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530390 __func__, dfp_port, dev_path(dev));
John Zhao0b3f15c2021-04-27 10:47:25 -0700391 continue;
392 }
393
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530394 usb_device = config->dfp[dfp_port].typec_port;
395 usb_port = usb_device->path.usb.port_id;
396
MAULIK V VAGHELAa70288d2021-11-25 14:41:19 +0530397 ec_port = retimer_get_index_for_typec(usb_port);
398 if (ec_port == -1) {
399 printk(BIOS_ERR, "%s: No relative EC port found for TC port %d\n",
400 __func__, usb_port);
Elyes Haouas5b0103f2022-02-16 16:43:42 +0100401 continue;
MAULIK V VAGHELAa70288d2021-11-25 14:41:19 +0530402 }
John Zhao0b3f15c2021-04-27 10:47:25 -0700403 /* DFPx */
MAULIK V VAGHELAa70288d2021-11-25 14:41:19 +0530404 snprintf(dfp, sizeof(dfp), "DFP%1d", ec_port);
John Zhao0b3f15c2021-04-27 10:47:25 -0700405 acpigen_write_device(dfp);
406 /* _ADR part is for the lane adapter */
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530407 acpigen_write_ADR(dfp_port*2 + 1);
John Zhao0b3f15c2021-04-27 10:47:25 -0700408
409 /* Fill _PLD with the same USB 3.x object on the Type-C connector */
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530410 if (CONFIG(DRIVERS_USB_ACPI)) {
411 if (usb_acpi_get_pld(usb_device, &pld))
412 acpigen_write_pld(&pld);
413 else
414 printk(BIOS_ERR, "Error retrieving PLD for USB Type-C %d\n",
415 usb_port);
416 }
John Zhao0b3f15c2021-04-27 10:47:25 -0700417
418 /* Power online reference counter(_PWR) */
419 acpigen_write_name("PWR");
420 acpigen_write_zero();
421
422 /* Method (_DSM, 4, Serialized) */
423 acpigen_write_method_serialized("_DSM", 0x4);
424 /* ToBuffer (Arg0, Local0) */
425 acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP);
426 acpigen_write_if(); /* If (UUID != INTEL_USB4_RETIMER_DSM_UUID) */
427 acpigen_emit_byte(LNOT_OP);
428 acpigen_emit_byte(LEQUAL_OP);
429 acpigen_emit_byte(LOCAL0_OP);
430 acpigen_write_uuid(INTEL_USB4_RETIMER_DSM_UUID);
431 /* Return (Buffer (One) { 0x0 }) */
432 acpigen_write_return_singleton_buffer(0x0);
433 acpigen_pop_len();
MAULIK V VAGHELAa70288d2021-11-25 14:41:19 +0530434 usb4_retimer_write_dsm(ec_port, INTEL_USB4_RETIMER_DSM_UUID,
John Zhao0b3f15c2021-04-27 10:47:25 -0700435 usb4_retimer_callbacks, ARRAY_SIZE(usb4_retimer_callbacks),
Maulik V Vaghela0f7e0862021-06-29 17:16:49 +0530436 (void *)&config->dfp[dfp_port].power_gpio);
John Zhao0b3f15c2021-04-27 10:47:25 -0700437 /* Default case: Return (Buffer (One) { 0x0 }) */
438 acpigen_write_return_singleton_buffer(0x0);
439
440 acpigen_pop_len(); /* Method _DSM */
441 acpigen_pop_len(); /* DFP */
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000442 }
John Zhao0b3f15c2021-04-27 10:47:25 -0700443 acpigen_pop_len(); /* Host Router */
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000444 acpigen_pop_len(); /* Scope */
445
Eric Laief8a1392022-01-22 14:06:54 +0800446 printk(BIOS_INFO, "%s.HR: %s at %s\n", usb4_retimer_scope, dev->chip_ops->name,
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000447 dev_path(dev));
448}
449
450static struct device_operations usb4_retimer_dev_ops = {
451 .read_resources = noop_read_resources,
452 .set_resources = noop_set_resources,
453 .acpi_fill_ssdt = usb4_retimer_fill_ssdt,
454};
455
456static void usb4_retimer_enable(struct device *dev)
457{
458 dev->ops = &usb4_retimer_dev_ops;
459}
460
461struct chip_operations drivers_intel_usb4_retimer_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900462 .name = "Intel USB4 Retimer",
Duncan Laurie2cc126b2020-08-28 19:46:35 +0000463 .enable_dev = usb4_retimer_enable
464};
Brandon Breitenstein297d27b2020-12-14 13:52:24 -0800465
466__weak const char *ec_retimer_fw_update_path(void)
467{
468 return NULL;
469}
470
John Zhao0b3f15c2021-04-27 10:47:25 -0700471__weak void ec_retimer_fw_update(uint8_t data)
Brandon Breitenstein297d27b2020-12-14 13:52:24 -0800472{
473}
MAULIK V VAGHELAa70288d2021-11-25 14:41:19 +0530474
475/*
476 * This function will convert CPU physical port mapping to abstract
477 * EC port mapping.
478 * For example, board might have enabled TCSS port 1 and 3 as per physical
479 * port mapping. Since only 2 TCSS ports are enabled EC will index it as port 0
480 * and port 1. So there will be an issue when coreboot sends command to EC for
481 * port 3 (with coreboot index of 2). EC will produce an error due to wrong index.
482 *
483 * Note: Each SoC code using retimer driver needs to implement this function
484 * since SoC will have physical port details.
485 */
486__weak int retimer_get_index_for_typec(uint8_t typec_port)
487{
488 /* By default assume that retimer port index = Type C port */
489 return (int)typec_port;
490}