Re: [PATCH] platform/chrome: cros_ec_typec: Add support for setting USB mode via sysfs

From: Andrei Kuchynski
Date: Thu Feb 20 2025 - 08:40:27 EST


On Tue, Feb 18, 2025 at 2:26 PM Tzung-Bi Shih <tzungbi@xxxxxxxxxx> wrote:
>
> On Mon, Feb 10, 2025 at 01:04:19PM +0000, Andrei Kuchynski wrote:
> > +static int cros_typec_enter_usb_mode(struct typec_port *tc_port, enum usb_mode mode)
> > +{
> > + struct cros_typec_port *port = typec_get_drvdata(tc_port);
> > + struct ec_params_typec_control req = {
> > + .port = port->port_num,
> > + .command = (mode == USB_MODE_USB4) ?
> > + TYPEC_CONTROL_COMMAND_ENTER_MODE : TYPEC_CONTROL_COMMAND_EXIT_MODES,
> > + .mode_to_enter = CROS_EC_ALTMODE_USB4
>
> The symbol `CROS_EC_ALTMODE_USB4` doesn't exist. On a related note, wouldn't
> it always enter CROS_EC_ALTMODE_USB4 if the value is hard-coded here?
>

CROS_EC_ALTMODE_USB4 is defined in drivers/platform/chrome/cros_ec_typec.h.
TYPEC_CONTROL_COMMAND_ENTER_MODE command will be sent only if
mode == USB_MODE_USB4 because EC currently only supports entering USB4 mode.
Otherwise, TYPEC_CONTROL_COMMAND_EXIT_MODES is sent, and the mode_to_enter
field is irrelevant for this command.

> > @@ -84,6 +102,13 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
> > cap->prefer_role = ret;
> > }
> >
> > + if (fwnode_property_present(fwnode, "usb2-port"))
> > + cap->usb_capability |= USB_CAPABILITY_USB2;
> > + if (fwnode_property_present(fwnode, "usb3-port"))
> > + cap->usb_capability |= USB_CAPABILITY_USB3;
> > + if (fwnode_property_present(fwnode, "usb4-port"))
> > + cap->usb_capability |= USB_CAPABILITY_USB4;
>
> Are these defined somewhere? E.g. the bindings?

Unfortunately, property names are set in the ACPI firmware in the same way.