usb4.c (284652a4a49917e121277a6cacbefed9f65b94ca) usb4.c (b2911a593a705e54adde6d06d4657c1ff2f16583)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * USB4 specific functionality
4 *
5 * Copyright (C) 2019, Intel Corporation
6 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
7 * Rajmohan Mani <rajmohan.mani@intel.com>
8 */

--- 182 unchanged lines hidden (view full) ---

191
192 if (val & ROUTER_CS_26_ONS)
193 return -EOPNOTSUPP;
194
195 *status = (val & ROUTER_CS_26_STATUS_MASK) >> ROUTER_CS_26_STATUS_SHIFT;
196 return 0;
197}
198
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * USB4 specific functionality
4 *
5 * Copyright (C) 2019, Intel Corporation
6 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
7 * Rajmohan Mani <rajmohan.mani@intel.com>
8 */

--- 182 unchanged lines hidden (view full) ---

191
192 if (val & ROUTER_CS_26_ONS)
193 return -EOPNOTSUPP;
194
195 *status = (val & ROUTER_CS_26_STATUS_MASK) >> ROUTER_CS_26_STATUS_SHIFT;
196 return 0;
197}
198
199static void usb4_switch_check_wakes(struct tb_switch *sw)
200{
201 struct tb_port *port;
202 bool wakeup = false;
203 u32 val;
204
205 if (!device_may_wakeup(&sw->dev))
206 return;
207
208 if (tb_route(sw)) {
209 if (tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1))
210 return;
211
212 tb_sw_dbg(sw, "PCIe wake: %s, USB3 wake: %s\n",
213 (val & ROUTER_CS_6_WOPS) ? "yes" : "no",
214 (val & ROUTER_CS_6_WOUS) ? "yes" : "no");
215
216 wakeup = val & (ROUTER_CS_6_WOPS | ROUTER_CS_6_WOUS);
217 }
218
219 /* Check for any connected downstream ports for USB4 wake */
220 tb_switch_for_each_port(sw, port) {
221 if (!tb_port_has_remote(port))
222 continue;
223
224 if (tb_port_read(port, &val, TB_CFG_PORT,
225 port->cap_usb4 + PORT_CS_18, 1))
226 break;
227
228 tb_port_dbg(port, "USB4 wake: %s\n",
229 (val & PORT_CS_18_WOU4S) ? "yes" : "no");
230
231 if (val & PORT_CS_18_WOU4S)
232 wakeup = true;
233 }
234
235 if (wakeup)
236 pm_wakeup_event(&sw->dev, 0);
237}
238
199static bool link_is_usb4(struct tb_port *port)
200{
201 u32 val;
202
203 if (!port->cap_usb4)
204 return false;
205
206 if (tb_port_read(port, &val, TB_CFG_PORT,

--- 17 unchanged lines hidden (view full) ---

224int usb4_switch_setup(struct tb_switch *sw)
225{
226 struct tb_port *downstream_port;
227 struct tb_switch *parent;
228 bool tbt3, xhci;
229 u32 val = 0;
230 int ret;
231
239static bool link_is_usb4(struct tb_port *port)
240{
241 u32 val;
242
243 if (!port->cap_usb4)
244 return false;
245
246 if (tb_port_read(port, &val, TB_CFG_PORT,

--- 17 unchanged lines hidden (view full) ---

264int usb4_switch_setup(struct tb_switch *sw)
265{
266 struct tb_port *downstream_port;
267 struct tb_switch *parent;
268 bool tbt3, xhci;
269 u32 val = 0;
270 int ret;
271
272 usb4_switch_check_wakes(sw);
273
232 if (!tb_route(sw))
233 return 0;
234
235 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1);
236 if (ret)
237 return ret;
238
239 parent = tb_switch_parent(sw);

--- 115 unchanged lines hidden (view full) ---

355 ret = tb_port_read(up, &val, TB_CFG_PORT, up->cap_usb4 + PORT_CS_18, 1);
356 if (ret)
357 return false;
358
359 return !!(val & PORT_CS_18_BE);
360}
361
362/**
274 if (!tb_route(sw))
275 return 0;
276
277 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1);
278 if (ret)
279 return ret;
280
281 parent = tb_switch_parent(sw);

--- 115 unchanged lines hidden (view full) ---

397 ret = tb_port_read(up, &val, TB_CFG_PORT, up->cap_usb4 + PORT_CS_18, 1);
398 if (ret)
399 return false;
400
401 return !!(val & PORT_CS_18_BE);
402}
403
404/**
405 * usb4_switch_set_wake() - Enabled/disable wake
406 * @sw: USB4 router
407 * @flags: Wakeup flags (%0 to disable)
408 *
409 * Enables/disables router to wake up from sleep.
410 */
411int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
412{
413 struct tb_port *port;
414 u64 route = tb_route(sw);
415 u32 val;
416 int ret;
417
418 /*
419 * Enable wakes coming from all USB4 downstream ports (from
420 * child routers). For device routers do this also for the
421 * upstream USB4 port.
422 */
423 tb_switch_for_each_port(sw, port) {
424 if (!route && tb_is_upstream_port(port))
425 continue;
426
427 ret = tb_port_read(port, &val, TB_CFG_PORT,
428 port->cap_usb4 + PORT_CS_19, 1);
429 if (ret)
430 return ret;
431
432 val &= ~(PORT_CS_19_WOC | PORT_CS_19_WOD | PORT_CS_19_WOU4);
433
434 if (flags & TB_WAKE_ON_CONNECT)
435 val |= PORT_CS_19_WOC;
436 if (flags & TB_WAKE_ON_DISCONNECT)
437 val |= PORT_CS_19_WOD;
438 if (flags & TB_WAKE_ON_USB4)
439 val |= PORT_CS_19_WOU4;
440
441 ret = tb_port_write(port, &val, TB_CFG_PORT,
442 port->cap_usb4 + PORT_CS_19, 1);
443 if (ret)
444 return ret;
445 }
446
447 /*
448 * Enable wakes from PCIe and USB 3.x on this router. Only
449 * needed for device routers.
450 */
451 if (route) {
452 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1);
453 if (ret)
454 return ret;
455
456 val &= ~(ROUTER_CS_5_WOP | ROUTER_CS_5_WOU);
457 if (flags & TB_WAKE_ON_USB3)
458 val |= ROUTER_CS_5_WOU;
459 if (flags & TB_WAKE_ON_PCIE)
460 val |= ROUTER_CS_5_WOP;
461
462 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1);
463 if (ret)
464 return ret;
465 }
466
467 return 0;
468}
469
470/**
363 * usb4_switch_set_sleep() - Prepare the router to enter sleep
364 * @sw: USB4 router
365 *
471 * usb4_switch_set_sleep() - Prepare the router to enter sleep
472 * @sw: USB4 router
473 *
366 * Enables wakes and sets sleep bit for the router. Returns when the
367 * router sleep ready bit has been asserted.
474 * Sets sleep bit for the router. Returns when the router sleep ready
475 * bit has been asserted.
368 */
369int usb4_switch_set_sleep(struct tb_switch *sw)
370{
371 int ret;
372 u32 val;
373
374 /* Set sleep bit and wait for sleep ready to be asserted */
375 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1);

--- 1249 unchanged lines hidden ---
476 */
477int usb4_switch_set_sleep(struct tb_switch *sw)
478{
479 int ret;
480 u32 val;
481
482 /* Set sleep bit and wait for sleep ready to be asserted */
483 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1);

--- 1249 unchanged lines hidden ---