@@ -965,10 +965,20 @@ static void ucsi_unregister_plug(struct ucsi_connector *con)
965965
966966static int ucsi_register_cable (struct ucsi_connector * con )
967967{
968+ struct ucsi_cable_property cable_prop ;
968969 struct typec_cable * cable ;
969970 struct typec_cable_desc desc = {};
971+ u64 command ;
972+ int ret ;
973+
974+ command = UCSI_GET_CABLE_PROPERTY | UCSI_CONNECTOR_NUMBER (con -> num );
975+ ret = ucsi_send_command (con -> ucsi , command , & cable_prop , sizeof (cable_prop ));
976+ if (ret < 0 ) {
977+ dev_err (con -> ucsi -> dev , "GET_CABLE_PROPERTY failed (%d)\n" , ret );
978+ return ret ;
979+ }
970980
971- switch (UCSI_CABLE_PROP_FLAG_PLUG_TYPE (con -> cable_prop .flags )) {
981+ switch (UCSI_CABLE_PROP_FLAG_PLUG_TYPE (cable_prop .flags )) {
972982 case UCSI_CABLE_PROPERTY_PLUG_TYPE_A :
973983 desc .type = USB_PLUG_TYPE_A ;
974984 break ;
@@ -984,10 +994,10 @@ static int ucsi_register_cable(struct ucsi_connector *con)
984994 }
985995
986996 desc .identity = & con -> cable_identity ;
987- desc .active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE &
988- con -> cable_prop . flags );
989- desc . pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD (
990- con -> cable_prop .flags );
997+ desc .active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & cable_prop . flags );
998+
999+ if ( con -> ucsi -> version >= UCSI_VERSION_2_1 )
1000+ desc . pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD ( cable_prop .flags );
9911001
9921002 cable = typec_register_cable (con -> port , & desc );
9931003 if (IS_ERR (cable )) {
@@ -1012,6 +1022,27 @@ static void ucsi_unregister_cable(struct ucsi_connector *con)
10121022 con -> cable = NULL ;
10131023}
10141024
1025+ static int ucsi_check_connector_capability (struct ucsi_connector * con )
1026+ {
1027+ u64 command ;
1028+ int ret ;
1029+
1030+ if (!con -> partner || con -> ucsi -> version < UCSI_VERSION_2_1 )
1031+ return 0 ;
1032+
1033+ command = UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMBER (con -> num );
1034+ ret = ucsi_send_command (con -> ucsi , command , & con -> cap , sizeof (con -> cap ));
1035+ if (ret < 0 ) {
1036+ dev_err (con -> ucsi -> dev , "GET_CONNECTOR_CAPABILITY failed (%d)\n" , ret );
1037+ return ret ;
1038+ }
1039+
1040+ typec_partner_set_pd_revision (con -> partner ,
1041+ UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD (con -> cap .flags ));
1042+
1043+ return ret ;
1044+ }
1045+
10151046static void ucsi_pwr_opmode_change (struct ucsi_connector * con )
10161047{
10171048 switch (UCSI_CONSTAT_PWR_OPMODE (con -> status .flags )) {
@@ -1021,6 +1052,7 @@ static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
10211052 ucsi_partner_task (con , ucsi_get_src_pdos , 30 , 0 );
10221053 ucsi_partner_task (con , ucsi_check_altmodes , 30 , HZ );
10231054 ucsi_partner_task (con , ucsi_register_partner_pdos , 1 , HZ );
1055+ ucsi_partner_task (con , ucsi_check_connector_capability , 1 , HZ );
10241056 break ;
10251057 case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5 :
10261058 con -> rdo = 0 ;
@@ -1064,7 +1096,6 @@ static int ucsi_register_partner(struct ucsi_connector *con)
10641096
10651097 desc .identity = & con -> partner_identity ;
10661098 desc .usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD ;
1067- desc .pd_revision = UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD (con -> cap .flags );
10681099
10691100 partner = typec_register_partner (con -> port , & desc );
10701101 if (IS_ERR (partner )) {
@@ -1141,27 +1172,6 @@ static void ucsi_partner_change(struct ucsi_connector *con)
11411172 con -> num , u_role );
11421173}
11431174
1144- static int ucsi_check_connector_capability (struct ucsi_connector * con )
1145- {
1146- u64 command ;
1147- int ret ;
1148-
1149- if (!con -> partner || con -> ucsi -> version < UCSI_VERSION_2_0 )
1150- return 0 ;
1151-
1152- command = UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMBER (con -> num );
1153- ret = ucsi_send_command (con -> ucsi , command , & con -> cap , sizeof (con -> cap ));
1154- if (ret < 0 ) {
1155- dev_err (con -> ucsi -> dev , "GET_CONNECTOR_CAPABILITY failed (%d)\n" , ret );
1156- return ret ;
1157- }
1158-
1159- typec_partner_set_pd_revision (con -> partner ,
1160- UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD (con -> cap .flags ));
1161-
1162- return ret ;
1163- }
1164-
11651175static int ucsi_check_connection (struct ucsi_connector * con )
11661176{
11671177 u8 prev_flags = con -> status .flags ;
@@ -1193,21 +1203,11 @@ static int ucsi_check_connection(struct ucsi_connector *con)
11931203
11941204static int ucsi_check_cable (struct ucsi_connector * con )
11951205{
1196- u64 command ;
11971206 int ret , num_plug_am ;
11981207
11991208 if (con -> cable )
12001209 return 0 ;
12011210
1202- command = UCSI_GET_CABLE_PROPERTY | UCSI_CONNECTOR_NUMBER (con -> num );
1203- ret = ucsi_send_command (con -> ucsi , command , & con -> cable_prop ,
1204- sizeof (con -> cable_prop ));
1205- if (ret < 0 ) {
1206- dev_err (con -> ucsi -> dev , "GET_CABLE_PROPERTY failed (%d)\n" ,
1207- ret );
1208- return ret ;
1209- }
1210-
12111211 ret = ucsi_register_cable (con );
12121212 if (ret < 0 )
12131213 return ret ;
@@ -1283,15 +1283,16 @@ static void ucsi_handle_connector_change(struct work_struct *work)
12831283 if (con -> status .flags & UCSI_CONSTAT_CONNECTED ) {
12841284 ucsi_register_partner (con );
12851285 ucsi_partner_task (con , ucsi_check_connection , 1 , HZ );
1286- ucsi_partner_task (con , ucsi_check_connector_capability , 1 , HZ );
12871286 if (con -> ucsi -> cap .features & UCSI_CAP_GET_PD_MESSAGE )
12881287 ucsi_partner_task (con , ucsi_get_partner_identity , 1 , HZ );
12891288 if (con -> ucsi -> cap .features & UCSI_CAP_CABLE_DETAILS )
12901289 ucsi_partner_task (con , ucsi_check_cable , 1 , HZ );
12911290
12921291 if (UCSI_CONSTAT_PWR_OPMODE (con -> status .flags ) ==
1293- UCSI_CONSTAT_PWR_OPMODE_PD )
1292+ UCSI_CONSTAT_PWR_OPMODE_PD ) {
12941293 ucsi_partner_task (con , ucsi_register_partner_pdos , 1 , HZ );
1294+ ucsi_partner_task (con , ucsi_check_connector_capability , 1 , HZ );
1295+ }
12951296 } else {
12961297 ucsi_unregister_partner (con );
12971298 }
@@ -1706,6 +1707,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
17061707 ucsi_register_device_pdos (con );
17071708 ucsi_get_src_pdos (con );
17081709 ucsi_check_altmodes (con );
1710+ ucsi_check_connector_capability (con );
17091711 }
17101712
17111713 trace_ucsi_register_port (con -> num , & con -> status );
0 commit comments