Skip to content

Commit ab2588c

Browse files
Andrei Kuchynskigregkh
authored andcommitted
usb: typec: ucsi: Support mode selection to activate altmodes
If the ucsi port driver supports modes selection, it should implement `add_partner_altmodes` and `remove_partner_altmodes` ucsi operations. With these operations the driver can manage the mode selection process. Once partner altmodes are registered, `add_partner_altmodes` is called to start the mode selection. When the partner is unregistered, `remove_partner_altmodes` is supposed to stop any ongoing processes and clean up the resources. `typec_altmode_state_update` informes mode selection about the current mode of the Type-C connector. Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://patch.msgid.link/20260119131824.2529334-7-akuchynski@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent be727d4 commit ab2588c

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ void ucsi_altmode_update_active(struct ucsi_connector *con)
314314
{
315315
const struct typec_altmode *altmode = NULL;
316316
u64 command;
317+
u16 svid = 0;
317318
int ret;
318319
u8 cur;
319320
int i;
@@ -335,6 +336,10 @@ void ucsi_altmode_update_active(struct ucsi_connector *con)
335336
for (i = 0; con->partner_altmode[i]; i++)
336337
typec_altmode_update_active(con->partner_altmode[i],
337338
con->partner_altmode[i] == altmode);
339+
340+
if (altmode)
341+
svid = altmode->svid;
342+
typec_altmode_state_update(con->partner, svid, 0);
338343
}
339344

340345
static int ucsi_altmode_next_mode(struct typec_altmode **alt, u16 svid)
@@ -609,6 +614,8 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)
609614
desc.vdo = alt[j].mid;
610615
desc.svid = alt[j].svid;
611616
desc.roles = TYPEC_PORT_DRD;
617+
desc.mode_selection = con->ucsi->ops->add_partner_altmodes &&
618+
!con->typec_cap.no_mode_control;
612619

613620
ret = ucsi_register_altmode(con, &desc, recipient);
614621
if (ret)
@@ -831,6 +838,8 @@ static int ucsi_check_altmodes(struct ucsi_connector *con)
831838
if (con->partner_altmode[0]) {
832839
num_partner_am = ucsi_get_num_altmode(con->partner_altmode);
833840
typec_partner_set_num_altmodes(con->partner, num_partner_am);
841+
if (con->ucsi->ops->add_partner_altmodes)
842+
con->ucsi->ops->add_partner_altmodes(con);
834843
ucsi_altmode_update_active(con);
835844
return 0;
836845
} else {
@@ -1119,6 +1128,8 @@ static void ucsi_unregister_partner(struct ucsi_connector *con)
11191128
return;
11201129

11211130
typec_set_mode(con->port, TYPEC_STATE_SAFE);
1131+
if (con->ucsi->ops->remove_partner_altmodes)
1132+
con->ucsi->ops->remove_partner_altmodes(con);
11221133

11231134
typec_partner_set_usb_power_delivery(con->partner, NULL);
11241135
ucsi_unregister_partner_pdos(con);
@@ -1659,6 +1670,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
16591670

16601671
cap->driver_data = con;
16611672
cap->ops = &ucsi_ops;
1673+
cap->no_mode_control = !(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE);
16621674

16631675
if (ucsi->version >= UCSI_VERSION_2_0)
16641676
con->typec_cap.orientation_aware = true;

drivers/usb/typec/ucsi/ucsi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct dentry;
7070
* @update_altmodes: Squashes duplicate DP altmodes
7171
* @update_connector: Update connector capabilities before registering
7272
* @connector_status: Updates connector status, called holding connector lock
73+
* @add_partner_altmodes: Start mode selection
74+
* @remove_partner_altmodes: Clean mode selection
7375
*
7476
* Read and write routines for UCSI interface. @sync_write must wait for the
7577
* Command Completion Event from the PPM before returning, and @async_write must
@@ -88,6 +90,8 @@ struct ucsi_operations {
8890
struct ucsi_altmode *updated);
8991
void (*update_connector)(struct ucsi_connector *con);
9092
void (*connector_status)(struct ucsi_connector *con);
93+
void (*add_partner_altmodes)(struct ucsi_connector *con);
94+
void (*remove_partner_altmodes)(struct ucsi_connector *con);
9195
};
9296

9397
struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops);

0 commit comments

Comments
 (0)