Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: Move usb4_switch_wait_for_bit() to switch.c

Currently usb4_switch_wait_for_bit() used only in usb4.c Moving to
switch.c to call it from other files. Also change the prefix to "tb_"
to follow to the naming convention.

Signed-off-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

authored by

Gil Fine and committed by
Mika Westerberg
1639664f 8a90e4fa

+41 -27
+34
drivers/thunderbolt/switch.c
··· 1457 1457 return res.err; 1458 1458 } 1459 1459 1460 + /** 1461 + * tb_switch_wait_for_bit() - Wait for specified value of bits in offset 1462 + * @sw: Router to read the offset value from 1463 + * @offset: Offset in the router config space to read from 1464 + * @bit: Bit mask in the offset to wait for 1465 + * @value: Value of the bits to wait for 1466 + * @timeout_msec: Timeout in ms how long to wait 1467 + * 1468 + * Wait till the specified bits in specified offset reach specified value. 1469 + * Returns %0 in case of success, %-ETIMEDOUT if the @value was not reached 1470 + * within the given timeout or a negative errno in case of failure. 1471 + */ 1472 + int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, 1473 + u32 value, int timeout_msec) 1474 + { 1475 + ktime_t timeout = ktime_add_ms(ktime_get(), timeout_msec); 1476 + 1477 + do { 1478 + u32 val; 1479 + int ret; 1480 + 1481 + ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); 1482 + if (ret) 1483 + return ret; 1484 + 1485 + if ((val & bit) == value) 1486 + return 0; 1487 + 1488 + usleep_range(50, 100); 1489 + } while (ktime_before(ktime_get(), timeout)); 1490 + 1491 + return -ETIMEDOUT; 1492 + } 1493 + 1460 1494 /* 1461 1495 * tb_plug_events_active() - enable/disable plug events on a switch 1462 1496 *
+2
drivers/thunderbolt/tb.h
··· 760 760 void tb_switch_suspend(struct tb_switch *sw, bool runtime); 761 761 int tb_switch_resume(struct tb_switch *sw); 762 762 int tb_switch_reset(struct tb_switch *sw); 763 + int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, 764 + u32 value, int timeout_msec); 763 765 void tb_sw_set_unplugged(struct tb_switch *sw); 764 766 struct tb_port *tb_switch_find_port(struct tb_switch *sw, 765 767 enum tb_port_type type);
+5 -27
drivers/thunderbolt/usb4.c
··· 50 50 #define USB4_BA_VALUE_MASK GENMASK(31, 16) 51 51 #define USB4_BA_VALUE_SHIFT 16 52 52 53 - static int usb4_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, 54 - u32 value, int timeout_msec) 55 - { 56 - ktime_t timeout = ktime_add_ms(ktime_get(), timeout_msec); 57 - 58 - do { 59 - u32 val; 60 - int ret; 61 - 62 - ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); 63 - if (ret) 64 - return ret; 65 - 66 - if ((val & bit) == value) 67 - return 0; 68 - 69 - usleep_range(50, 100); 70 - } while (ktime_before(ktime_get(), timeout)); 71 - 72 - return -ETIMEDOUT; 73 - } 74 - 75 53 static int usb4_native_switch_op(struct tb_switch *sw, u16 opcode, 76 54 u32 *metadata, u8 *status, 77 55 const void *tx_data, size_t tx_dwords, ··· 75 97 if (ret) 76 98 return ret; 77 99 78 - ret = usb4_switch_wait_for_bit(sw, ROUTER_CS_26, ROUTER_CS_26_OV, 0, 500); 100 + ret = tb_switch_wait_for_bit(sw, ROUTER_CS_26, ROUTER_CS_26_OV, 0, 500); 79 101 if (ret) 80 102 return ret; 81 103 ··· 281 303 if (ret) 282 304 return ret; 283 305 284 - return usb4_switch_wait_for_bit(sw, ROUTER_CS_6, ROUTER_CS_6_CR, 285 - ROUTER_CS_6_CR, 50); 306 + return tb_switch_wait_for_bit(sw, ROUTER_CS_6, ROUTER_CS_6_CR, 307 + ROUTER_CS_6_CR, 50); 286 308 } 287 309 288 310 /** ··· 458 480 if (ret) 459 481 return ret; 460 482 461 - return usb4_switch_wait_for_bit(sw, ROUTER_CS_6, ROUTER_CS_6_SLPR, 462 - ROUTER_CS_6_SLPR, 500); 483 + return tb_switch_wait_for_bit(sw, ROUTER_CS_6, ROUTER_CS_6_SLPR, 484 + ROUTER_CS_6_SLPR, 500); 463 485 } 464 486 465 487 /**