Skip to content

Commit ffbe78f

Browse files
Andrei Kuchynskigregkh
authored andcommitted
usb: typec: ucsi: Enforce mode selection for cros_ec_ucsi
The mode selection sequence is initiated by the driver after all partner alternate modes have been successfully registered. When a partner is disconnected, the driver also stops the mode selection process and releases resources via `typec_mode_selection_delete`. Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://patch.msgid.link/20260119131824.2529334-8-akuchynski@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ab2588c commit ffbe78f

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

drivers/usb/typec/ucsi/cros_ec_ucsi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/platform_device.h>
1717
#include <linux/slab.h>
1818
#include <linux/wait.h>
19+
#include <linux/usb/typec_altmode.h>
1920

2021
#include "ucsi.h"
2122

@@ -33,6 +34,11 @@
3334
/* Number of times to attempt recovery from a write timeout before giving up. */
3435
#define WRITE_TMO_CTR_MAX 5
3536

37+
/* Delay between mode entry/exit attempts, ms */
38+
static const unsigned int mode_selection_delay = 1000;
39+
/* Timeout for a mode entry attempt, ms */
40+
static const unsigned int mode_selection_timeout = 4000;
41+
3642
struct cros_ucsi_data {
3743
struct device *dev;
3844
struct ucsi *ucsi;
@@ -134,13 +140,29 @@ static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd, u32 *cci,
134140
return ret;
135141
}
136142

143+
static void cros_ucsi_add_partner_altmodes(struct ucsi_connector *con)
144+
{
145+
if (!con->typec_cap.no_mode_control)
146+
typec_mode_selection_start(con->partner,
147+
mode_selection_delay,
148+
mode_selection_timeout);
149+
}
150+
151+
static void cros_ucsi_remove_partner_altmodes(struct ucsi_connector *con)
152+
{
153+
if (!con->typec_cap.no_mode_control)
154+
typec_mode_selection_delete(con->partner);
155+
}
156+
137157
static const struct ucsi_operations cros_ucsi_ops = {
138158
.read_version = cros_ucsi_read_version,
139159
.read_cci = cros_ucsi_read_cci,
140160
.poll_cci = cros_ucsi_read_cci,
141161
.read_message_in = cros_ucsi_read_message_in,
142162
.async_control = cros_ucsi_async_control,
143163
.sync_control = cros_ucsi_sync_control,
164+
.add_partner_altmodes = cros_ucsi_add_partner_altmodes,
165+
.remove_partner_altmodes = cros_ucsi_remove_partner_altmodes,
144166
};
145167

146168
static void cros_ucsi_work(struct work_struct *work)

0 commit comments

Comments
 (0)