Skip to content

Commit 9fc8337

Browse files
Andrei KuchynskiTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_typec: Add support for setting USB mode via sysfs
This patch implements USB mode setting via a sysfs interface in cros_ec_typec driver. User-space applications can now change the current USB mode by writing to "usb_mode" sysfs entry, replacing the previous ioctl-based method. The embedded controller (EC) currently supports only entering USB4 mode and exiting all modes (including altmodes). Both of these operations trigger Data Reset Message, even if no USB Mode is active. Additionally, the patch exposes the USB modes supported by the port via "usb_capability" sysfs attribute. Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org> Link: https://lore.kernel.org/r/20250210130419.4110130-1-akuchynski@chromium.org Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
1 parent 435a3d7 commit 9fc8337

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ static void cros_typec_role_switch_quirk(struct fwnode_handle *fwnode)
4242
#endif
4343
}
4444

45+
static int cros_typec_enter_usb_mode(struct typec_port *tc_port, enum usb_mode mode)
46+
{
47+
struct cros_typec_port *port = typec_get_drvdata(tc_port);
48+
struct ec_params_typec_control req = {
49+
.port = port->port_num,
50+
.command = (mode == USB_MODE_USB4) ?
51+
TYPEC_CONTROL_COMMAND_ENTER_MODE : TYPEC_CONTROL_COMMAND_EXIT_MODES,
52+
.mode_to_enter = CROS_EC_ALTMODE_USB4
53+
};
54+
55+
return cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL,
56+
&req, sizeof(req), NULL, 0);
57+
}
58+
59+
static const struct typec_operations cros_typec_usb_mode_ops = {
60+
.enter_usb_mode = cros_typec_enter_usb_mode
61+
};
62+
4563
static int cros_typec_parse_port_props(struct typec_capability *cap,
4664
struct fwnode_handle *fwnode,
4765
struct device *dev)
@@ -84,6 +102,13 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
84102
cap->prefer_role = ret;
85103
}
86104

105+
if (fwnode_property_present(fwnode, "usb2-port"))
106+
cap->usb_capability |= USB_CAPABILITY_USB2;
107+
if (fwnode_property_present(fwnode, "usb3-port"))
108+
cap->usb_capability |= USB_CAPABILITY_USB3;
109+
if (fwnode_property_present(fwnode, "usb4-port"))
110+
cap->usb_capability |= USB_CAPABILITY_USB4;
111+
87112
cros_typec_role_switch_quirk(fwnode);
88113

89114
cap->fwnode = fwnode;
@@ -379,6 +404,9 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
379404
if (ret < 0)
380405
goto unregister_ports;
381406

407+
cap->driver_data = cros_port;
408+
cap->ops = &cros_typec_usb_mode_ops;
409+
382410
cros_port->port = typec_register_port(dev, cap);
383411
if (IS_ERR(cros_port->port)) {
384412
ret = PTR_ERR(cros_port->port);

drivers/platform/chrome/cros_ec_typec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
enum {
1919
CROS_EC_ALTMODE_DP = 0,
2020
CROS_EC_ALTMODE_TBT,
21+
CROS_EC_ALTMODE_USB4,
2122
CROS_EC_ALTMODE_MAX,
2223
};
2324

0 commit comments

Comments
 (0)