Skip to content

Commit 95f8f1c

Browse files
committed
thunderbolt: Move port CL state functions into correct place in switch.c
They should be close to other functions dealing with USB4 ports. No functional impact. Signed-off-by: Mika Westerberg <[email protected]>
1 parent 7f333ac commit 95f8f1c

File tree

1 file changed

+106
-106
lines changed

1 file changed

+106
-106
lines changed

drivers/thunderbolt/switch.c

Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,112 @@ int tb_port_update_credits(struct tb_port *port)
12291229
return tb_port_do_update_credits(port->dual_link_port);
12301230
}
12311231

1232+
static int __tb_port_pm_secondary_set(struct tb_port *port, bool secondary)
1233+
{
1234+
u32 phy;
1235+
int ret;
1236+
1237+
ret = tb_port_read(port, &phy, TB_CFG_PORT,
1238+
port->cap_phy + LANE_ADP_CS_1, 1);
1239+
if (ret)
1240+
return ret;
1241+
1242+
if (secondary)
1243+
phy |= LANE_ADP_CS_1_PMS;
1244+
else
1245+
phy &= ~LANE_ADP_CS_1_PMS;
1246+
1247+
return tb_port_write(port, &phy, TB_CFG_PORT,
1248+
port->cap_phy + LANE_ADP_CS_1, 1);
1249+
}
1250+
1251+
static int tb_port_pm_secondary_enable(struct tb_port *port)
1252+
{
1253+
return __tb_port_pm_secondary_set(port, true);
1254+
}
1255+
1256+
static int tb_port_pm_secondary_disable(struct tb_port *port)
1257+
{
1258+
return __tb_port_pm_secondary_set(port, false);
1259+
}
1260+
1261+
/* Called for USB4 or Titan Ridge routers only */
1262+
static bool tb_port_clx_supported(struct tb_port *port, enum tb_clx clx)
1263+
{
1264+
u32 mask, val;
1265+
bool ret;
1266+
1267+
/* Don't enable CLx in case of two single-lane links */
1268+
if (!port->bonded && port->dual_link_port)
1269+
return false;
1270+
1271+
/* Don't enable CLx in case of inter-domain link */
1272+
if (port->xdomain)
1273+
return false;
1274+
1275+
if (tb_switch_is_usb4(port->sw)) {
1276+
if (!usb4_port_clx_supported(port))
1277+
return false;
1278+
} else if (!tb_lc_is_clx_supported(port)) {
1279+
return false;
1280+
}
1281+
1282+
switch (clx) {
1283+
case TB_CL1:
1284+
/* CL0s and CL1 are enabled and supported together */
1285+
mask = LANE_ADP_CS_0_CL0S_SUPPORT | LANE_ADP_CS_0_CL1_SUPPORT;
1286+
break;
1287+
1288+
/* For now we support only CL0s and CL1. Not CL2 */
1289+
case TB_CL2:
1290+
default:
1291+
return false;
1292+
}
1293+
1294+
ret = tb_port_read(port, &val, TB_CFG_PORT,
1295+
port->cap_phy + LANE_ADP_CS_0, 1);
1296+
if (ret)
1297+
return false;
1298+
1299+
return !!(val & mask);
1300+
}
1301+
1302+
static int __tb_port_clx_set(struct tb_port *port, enum tb_clx clx, bool enable)
1303+
{
1304+
u32 phy, mask;
1305+
int ret;
1306+
1307+
/* CL0s and CL1 are enabled and supported together */
1308+
if (clx == TB_CL1)
1309+
mask = LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE;
1310+
else
1311+
/* For now we support only CL0s and CL1. Not CL2 */
1312+
return -EOPNOTSUPP;
1313+
1314+
ret = tb_port_read(port, &phy, TB_CFG_PORT,
1315+
port->cap_phy + LANE_ADP_CS_1, 1);
1316+
if (ret)
1317+
return ret;
1318+
1319+
if (enable)
1320+
phy |= mask;
1321+
else
1322+
phy &= ~mask;
1323+
1324+
return tb_port_write(port, &phy, TB_CFG_PORT,
1325+
port->cap_phy + LANE_ADP_CS_1, 1);
1326+
}
1327+
1328+
static int tb_port_clx_disable(struct tb_port *port, enum tb_clx clx)
1329+
{
1330+
return __tb_port_clx_set(port, clx, false);
1331+
}
1332+
1333+
static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx)
1334+
{
1335+
return __tb_port_clx_set(port, clx, true);
1336+
}
1337+
12321338
static int tb_port_start_lane_initialization(struct tb_port *port)
12331339
{
12341340
int ret;
@@ -3361,35 +3467,6 @@ struct tb_port *tb_switch_find_port(struct tb_switch *sw,
33613467
return NULL;
33623468
}
33633469

3364-
static int __tb_port_pm_secondary_set(struct tb_port *port, bool secondary)
3365-
{
3366-
u32 phy;
3367-
int ret;
3368-
3369-
ret = tb_port_read(port, &phy, TB_CFG_PORT,
3370-
port->cap_phy + LANE_ADP_CS_1, 1);
3371-
if (ret)
3372-
return ret;
3373-
3374-
if (secondary)
3375-
phy |= LANE_ADP_CS_1_PMS;
3376-
else
3377-
phy &= ~LANE_ADP_CS_1_PMS;
3378-
3379-
return tb_port_write(port, &phy, TB_CFG_PORT,
3380-
port->cap_phy + LANE_ADP_CS_1, 1);
3381-
}
3382-
3383-
static int tb_port_pm_secondary_enable(struct tb_port *port)
3384-
{
3385-
return __tb_port_pm_secondary_set(port, true);
3386-
}
3387-
3388-
static int tb_port_pm_secondary_disable(struct tb_port *port)
3389-
{
3390-
return __tb_port_pm_secondary_set(port, false);
3391-
}
3392-
33933470
static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)
33943471
{
33953472
struct tb_switch *parent = tb_switch_parent(sw);
@@ -3408,83 +3485,6 @@ static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)
34083485
return tb_port_pm_secondary_disable(down);
34093486
}
34103487

3411-
/* Called for USB4 or Titan Ridge routers only */
3412-
static bool tb_port_clx_supported(struct tb_port *port, enum tb_clx clx)
3413-
{
3414-
u32 mask, val;
3415-
bool ret;
3416-
3417-
/* Don't enable CLx in case of two single-lane links */
3418-
if (!port->bonded && port->dual_link_port)
3419-
return false;
3420-
3421-
/* Don't enable CLx in case of inter-domain link */
3422-
if (port->xdomain)
3423-
return false;
3424-
3425-
if (tb_switch_is_usb4(port->sw)) {
3426-
if (!usb4_port_clx_supported(port))
3427-
return false;
3428-
} else if (!tb_lc_is_clx_supported(port)) {
3429-
return false;
3430-
}
3431-
3432-
switch (clx) {
3433-
case TB_CL1:
3434-
/* CL0s and CL1 are enabled and supported together */
3435-
mask = LANE_ADP_CS_0_CL0S_SUPPORT | LANE_ADP_CS_0_CL1_SUPPORT;
3436-
break;
3437-
3438-
/* For now we support only CL0s and CL1. Not CL2 */
3439-
case TB_CL2:
3440-
default:
3441-
return false;
3442-
}
3443-
3444-
ret = tb_port_read(port, &val, TB_CFG_PORT,
3445-
port->cap_phy + LANE_ADP_CS_0, 1);
3446-
if (ret)
3447-
return false;
3448-
3449-
return !!(val & mask);
3450-
}
3451-
3452-
static int __tb_port_clx_set(struct tb_port *port, enum tb_clx clx, bool enable)
3453-
{
3454-
u32 phy, mask;
3455-
int ret;
3456-
3457-
/* CL0s and CL1 are enabled and supported together */
3458-
if (clx == TB_CL1)
3459-
mask = LANE_ADP_CS_1_CL0S_ENABLE | LANE_ADP_CS_1_CL1_ENABLE;
3460-
else
3461-
/* For now we support only CL0s and CL1. Not CL2 */
3462-
return -EOPNOTSUPP;
3463-
3464-
ret = tb_port_read(port, &phy, TB_CFG_PORT,
3465-
port->cap_phy + LANE_ADP_CS_1, 1);
3466-
if (ret)
3467-
return ret;
3468-
3469-
if (enable)
3470-
phy |= mask;
3471-
else
3472-
phy &= ~mask;
3473-
3474-
return tb_port_write(port, &phy, TB_CFG_PORT,
3475-
port->cap_phy + LANE_ADP_CS_1, 1);
3476-
}
3477-
3478-
static int tb_port_clx_disable(struct tb_port *port, enum tb_clx clx)
3479-
{
3480-
return __tb_port_clx_set(port, clx, false);
3481-
}
3482-
3483-
static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx)
3484-
{
3485-
return __tb_port_clx_set(port, clx, true);
3486-
}
3487-
34883488
static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)
34893489
{
34903490
struct tb_switch *parent = tb_switch_parent(sw);

0 commit comments

Comments
 (0)