From: Andrei Kuchynski <akuchynski@chromium.org>
To: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
Cc: Benson Leung <bleung@chromium.org>,
Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
Jameson Thies <jthies@google.com>,
Tzung-Bi Shih <tzungbi@kernel.org>,
Guenter Roeck <groeck@chromium.org>,
chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: Skip Type-C mux handling in EC-driven devices
Date: Tue, 3 Mar 2026 08:17:38 +0100 [thread overview]
Message-ID: <CAMMMRMf_Se9fbH50RSJvEfHCF6ds6TZfVzK4NJCs2UsViGAr1A@mail.gmail.com> (raw)
In-Reply-To: <20260205-smaug-type_c-v1-1-d6e556bf6640@tecnico.ulisboa.pt>
Hi Diogo,
On Thu, Feb 5, 2026 at 11:04 AM Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt> wrote:
>
> Currently the code assumes that the EC firmware will leave Type-C mux
> handling logic to the AP, exposing an interface to query and change the
> mux state via a request from the AP. However, in devices such as Smaug
> the EC automatically takes care of mux configuration and only USB role
> switching needs to be handled by the AP. In fact, in such devices this
> interface is not exposed by the EC making the whole process fail,
> including role switching.
>
> Fix this by first separating Type-C mux handling and USB role switching,
> explicitly querying the behaviour of the EC and execute each part
> conditionally according to what the EC reported.
>
> Signed-off-by: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
> ---
> drivers/platform/chrome/cros_ec_typec.c | 49 +++++++++++++++++++++++----------
> drivers/platform/chrome/cros_ec_typec.h | 2 +-
> 2 files changed, 35 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index b712bcff6fb2..bd7e6c365cab 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -751,11 +751,10 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
> }
>
> /* No change needs to be made, let's exit early. */
> - if (port->mux_flags == resp.flags && port->role == pd_ctrl->role)
> + if (port->mux_flags == resp.flags)
> return 0;
>
> port->mux_flags = resp.flags;
> - port->role = pd_ctrl->role;
>
> if (port->mux_flags == USB_PD_MUX_NONE) {
> ret = cros_typec_usb_disconnect_state(port);
> @@ -771,12 +770,6 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
> if (ret)
> return ret;
>
> - ret = usb_role_switch_set_role(typec->ports[port_num]->role_sw,
> - pd_ctrl->role & PD_CTRL_RESP_ROLE_DATA
> - ? USB_ROLE_HOST : USB_ROLE_DEVICE);
> - if (ret)
> - return ret;
> -
> if (port->mux_flags & USB_PD_MUX_USB4_ENABLED) {
> ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
> } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
> @@ -822,6 +815,25 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
> return ret;
> }
>
> +static int cros_typec_set_role(struct cros_typec_data *typec, int port_num,
> + struct ec_response_usb_pd_control_v1 *resp)
> +{
> + enum usb_role cur_role = usb_role_switch_get_role(typec->ports[port_num]->role_sw);
> + enum usb_role role = resp->role & PD_CTRL_RESP_ROLE_DATA ? USB_ROLE_HOST :
> + USB_ROLE_DEVICE;
> + bool connected = resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED;
> + int ret;
> +
> + if (!connected || cur_role == role)
> + return 0;
> +
> + ret = usb_role_switch_set_role(typec->ports[port_num]->role_sw, role);
> + if (ret)
> + dev_err(typec->dev, "Failed USB role switch, err = %d\n", ret);
While testing on Brya, I've got a role switch failure:
cros-ec-typec GOOG0014:00: Failed USB role switch, err = -22
cros-ec-typec GOOG0014:00: Update failed for port: 1
Steps to reproduce: deactivate any alt-mode.
Verified on the Brya platform.
This may be attributed to the altered sequence of mux and switch settings.
Thanks,
Andrei
next prev parent reply other threads:[~2026-03-03 7:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-05 10:04 Diogo Ivo
2026-03-02 9:09 ` Diogo Ivo
2026-03-03 2:49 ` Tzung-Bi Shih
2026-03-03 7:17 ` Andrei Kuchynski [this message]
2026-03-03 9:54 ` Diogo Ivo
2026-03-04 10:30 ` Andrei Kuchynski
2026-03-09 15:25 ` Diogo Ivo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMMMRMf_Se9fbH50RSJvEfHCF6ds6TZfVzK4NJCs2UsViGAr1A@mail.gmail.com \
--to=akuchynski@chromium.org \
--cc=abhishekpandit@chromium.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=diogo.ivo@tecnico.ulisboa.pt \
--cc=groeck@chromium.org \
--cc=jthies@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tzungbi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®