Skip to content

Commit b12d295

Browse files
committed
thunderbolt: Add helper to check if CL states are enabled on port
We will need this when enabling lane margining support. Signed-off-by: Mika Westerberg <[email protected]>
1 parent 3846d01 commit b12d295

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

drivers/thunderbolt/switch.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,34 @@ static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx)
13301330
return __tb_port_clx_set(port, clx, true);
13311331
}
13321332

1333+
/**
1334+
* tb_port_is_clx_enabled() - Is given CL state enabled
1335+
* @port: USB4 port to check
1336+
* @clx_mask: Mask of CL states to check
1337+
*
1338+
* Returns true if any of the given CL states is enabled for @port.
1339+
*/
1340+
bool tb_port_is_clx_enabled(struct tb_port *port, unsigned int clx_mask)
1341+
{
1342+
u32 val, mask = 0;
1343+
int ret;
1344+
1345+
if (!tb_port_clx_supported(port, clx_mask))
1346+
return false;
1347+
1348+
if (clx_mask & TB_CL1)
1349+
mask |= LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE;
1350+
if (clx_mask & TB_CL2)
1351+
mask |= LANE_ADP_CS_1_CL2_ENABLE;
1352+
1353+
ret = tb_port_read(port, &val, TB_CFG_PORT,
1354+
port->cap_phy + LANE_ADP_CS_1, 1);
1355+
if (ret)
1356+
return false;
1357+
1358+
return !!(val & mask);
1359+
}
1360+
13331361
static int tb_port_start_lane_initialization(struct tb_port *port)
13341362
{
13351363
int ret;

drivers/thunderbolt/tb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ void tb_port_lane_bonding_disable(struct tb_port *port);
10351035
int tb_port_wait_for_link_width(struct tb_port *port, int width,
10361036
int timeout_msec);
10371037
int tb_port_update_credits(struct tb_port *port);
1038+
bool tb_port_is_clx_enabled(struct tb_port *port, enum tb_clx clx);
10381039

10391040
int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
10401041
int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);

drivers/thunderbolt/tb_regs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ struct tb_regs_port_header {
334334
#define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3
335335
#define LANE_ADP_CS_1_CL0S_ENABLE BIT(10)
336336
#define LANE_ADP_CS_1_CL1_ENABLE BIT(11)
337+
#define LANE_ADP_CS_1_CL2_ENABLE BIT(12)
337338
#define LANE_ADP_CS_1_LD BIT(14)
338339
#define LANE_ADP_CS_1_LB BIT(15)
339340
#define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16)

0 commit comments

Comments
 (0)