From nobody Mon Jun 8 04:24:36 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D41854CB5B for ; Sun, 7 Jun 2026 10:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780827619; cv=none; b=rYRC391In9eHdxIB7+YQlDrv4uHtJN7xW+ewPs3UejpFKHP+qRxYTJ8g23XfGaFSk1GuImzcBcolQfJgsi5Fmo8iX7L89GIyrIF/Y+e9gYRFHP/iBq0kotzErhp8sJg+ucKrT5DErTBiKvC0YJprVOlbX1cSsU49dR1nlzI9y+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780827619; c=relaxed/simple; bh=6UPUyR/iIrwRUAlQA+0uiaKnFim+086J02JKKx43t5U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bIWOV+Z3UP3//S3AXaLsNurgT6eXJpPSmDl0YkwJQI0McE/KW3tpv8O7u0Jvf4JEf11Yx2+fT6Fd/bLHLyczfFSLsFwR1XyySOYlgnHgGq4wl4RJ8fEMGu87Sv3A4YY+SsWx9Z/RsOdXgZmlD27ntnhCcDexSTHThAhPyWDn2l8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oOeFBdZA; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oOeFBdZA" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-36b900f350fso3147721a91.0 for ; Sun, 07 Jun 2026 03:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780827616; x=1781432416; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4cYHoEnn8Lw9yUZnPqIqEGwANKak1fsk1XF/TKoC4MM=; b=oOeFBdZAXLKOyZGyxrBNOjPajauWwcwfs2N8oIJaGbEfOOq/FL81pIysXpDX4kbJH+ yjQ83rIpVE0jlnkpQY9sTC2Q0BILFWVCIusoOqKY+PsxYoMc+7LZ14ImORcv3eXfPbE1 uJsjCd+a3blEOjzTUdF/JK50UkvYk3UH8RGQZKC4haUDSoKyFnG//geFYnGVK8LCvp6s zow6PS5+EAncNbdBKzWZhx6fd09JkaWGIU62G0nwH/1sqvLqJsHhmQRJrLDqnfiVX5FM fa3PfnRkhvh4yay1qr2AOB3VsLF0koD+L0ACMRyCDX2p0/oK5u/ue/N+617cgJERtoBl 6ZNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780827616; x=1781432416; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4cYHoEnn8Lw9yUZnPqIqEGwANKak1fsk1XF/TKoC4MM=; b=Iod7RYzMZUdub9/OcyPEOqx4K1bpNpUwTvnMicmI1y3R59aQGK9M36DYl76PaWML+5 mEVwbHbhyRODIfJp7j3tkY5h3BqwTAcDXVz6zw1oJKRMDnQj+V2iDpM5muOo5Nfjgswx b16jHvHxRQbE0NEXaeokg21/LVY20Tnt3gOuuSt75Nrb+iEtimC/Vv9GmbNFUOtDBfXH jYyZvD8wZ7u/1qk5xB+bM7n2QXcoO4MeR3EC1nJcBY0Hxmu4GnRzHPGtZqHFVkXOYwxR JyKHNUIYmceJgX0zjgGf+L3y01kUfs2yKv4eKvR1K4IvUQ9E/sl20wXP7POS8zC12GYo SuNA== X-Forwarded-Encrypted: i=1; AFNElJ+EqJYasqibNIqAONWjr/wHyAbqPuTYa1b5sQB5wFI2KAe4IxdYq5HhKvuCYTArAXppY2dy/hM69TEcrHQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxrJrbyd2rYheDHHga1MOvUk5RO9c/uFL7SDDntf27hRLMSlsaW ZQG23M0wJZ9ln5BKFP4yyTQSdMDuhxz3ZsYO4cfX7VsW0X4YdQNrxG/vQGda+g== X-Gm-Gg: Acq92OHPHsO3fAkVM2X7XahmxPFAlrTLXqzyrsODM7y+11FKDC55VGDu9UbmyGbqnyo ZXj1P7WLWO5kxGh+B9FbSdfHoAL9zEHIVmzKjFdeiQ45xF4snSAvOg6H/9ZS92JEKYc6RqGVw0l NK+BF7/zGUAT3zU1iy6MiGAyXbtaPu3kDwix9ILD5qDEW2CmBHgFlgUXhfdp4A2RANQjc3lzWQ2 DL3jrA5TvnjuI9soIla2IKwNUbdXUlWb9hqkRV2kg7FSbRMCqThnwcw9wjLnvhBg3v+/WfllmxK ne2ezZRGYUDy6cWpIb18Dr1o8jhJkYIy+w2rMRvz93glmiMw2I+QTKfYD+d0VhXzXx8ZX3c2Dgy CHAiUgvW1KalqCn/alpSAmCeJ0QyQ1VOWV3YObBRkX8VZGtPNBguoEmRNlmT9LwtgY2b5yIazcg 1kZutsxM4wQkpxaD2mpwdsIaIkDw64L4s= X-Received: by 2002:a17:902:f603:b0:2c0:b932:8680 with SMTP id d9443c01a7336-2c1e7e3f22cmr132901695ad.10.1780827615986; Sun, 07 Jun 2026 03:20:15 -0700 (PDT) Received: from nuvole ([2001:19f0:8001:53c:5400:4ff:fe86:d241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c16609df63sm143424675ad.40.2026.06.07.03.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2026 03:20:15 -0700 (PDT) From: Pengyu Luo To: Pengyu Luo , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: ucsi: huawei_gaokun: support mode switching Date: Sun, 7 Jun 2026 18:18:44 +0800 Message-ID: <20260607101844.820064-1-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The USB PHY (QMP Combo PHY) is always initialized in USB3+DP mode. In the past, there was no MUX, and it was unnecessary to set it, since MSM only supported 2-lane DP. But now, MST and 4-lane DP support has been added to MSM, and a MUX has been added to the PHY. To support 4-lane DP and mode switching for gaokun, get the MUX and set it. Signed-off-by: Pengyu Luo --- drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 55 +++++++++++++++------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/type= c/ucsi/ucsi_huawei_gaokun.c index c5965656baba..95b7b77b726d 100644 --- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c @@ -18,6 +18,7 @@ #include #include #include +#include #include =20 #include "ucsi.h" @@ -82,6 +83,8 @@ struct gaokun_ucsi_port { struct gaokun_ucsi *ucsi; struct auxiliary_device *bridge; =20 + struct typec_mux *typec_mux; + int idx; enum gaokun_ucsi_ccx ccx; enum gaokun_ucsi_mux mux; @@ -226,19 +229,18 @@ static void gaokun_ucsi_port_update(struct gaokun_ucs= i_port *port, port->hpd_state =3D FIELD_GET(GAOKUN_HPD_STATE_MASK, ddi); port->hpd_irq =3D FIELD_GET(GAOKUN_HPD_IRQ_MASK, ddi); =20 - /* Mode and SVID are unused; keeping them to make things clearer */ switch (port->mode) { case USBC_DPAM_PAN_C: case USBC_DPAM_PAN_C_REVERSE: - port->mode =3D DP_PIN_ASSIGN_C; /* correct it for usb later */ + port->mode =3D TYPEC_DP_STATE_C; /* correct it for usb later */ break; case USBC_DPAM_PAN_D: case USBC_DPAM_PAN_D_REVERSE: - port->mode =3D DP_PIN_ASSIGN_D; + port->mode =3D TYPEC_DP_STATE_D; break; case USBC_DPAM_PAN_E: case USBC_DPAM_PAN_E_REVERSE: - port->mode =3D DP_PIN_ASSIGN_E; + port->mode =3D TYPEC_DP_STATE_E; break; case USBC_DPAM_PAN_NONE: port->mode =3D TYPEC_STATE_SAFE; @@ -287,18 +289,32 @@ static int gaokun_ucsi_refresh(struct gaokun_ucsi *ue= c) return idx; } =20 -static void gaokun_ucsi_handle_altmode(struct gaokun_ucsi_port *port) +static void gaokun_ucsi_handle_usb_mode(struct gaokun_ucsi_port *port) { struct gaokun_ucsi *uec =3D port->ucsi; - int idx =3D port->idx; - - if (idx >=3D uec->ucsi->cap.num_connectors) { + struct typec_mux_state state =3D {}; + struct typec_altmode dp_alt =3D {}; + int idx =3D port->idx, ret; + + /* + * For every typec port on this platform, the only mode-switch is + * controlled by its qmp combo phy which consumes svid and mode only. + */ + dp_alt.svid =3D port->svid; + state.mode =3D port->mode; + state.alt =3D &dp_alt; + + if (idx >=3D uec->num_ports) { dev_warn(uec->dev, "altmode port out of range: %d\n", idx); return; } =20 + ret =3D typec_mux_set(port->typec_mux, &state); + if (ret) + dev_err(uec->dev, "failed to set mux %d\n", ret); + /* UCSI callback .connector_status() have set orientation */ - if (port->bridge) + if (port->bridge && port->svid =3D=3D USB_TYPEC_DP_SID) drm_aux_hpd_bridge_notify(&port->bridge->dev, port->hpd_state ? connector_status_connected : @@ -307,7 +323,7 @@ static void gaokun_ucsi_handle_altmode(struct gaokun_uc= si_port *port) gaokun_ec_ucsi_pan_ack(uec->ec, port->idx); } =20 -static void gaokun_ucsi_altmode_notify_ind(struct gaokun_ucsi *uec) +static void gaokun_ucsi_usb_notify_ind(struct gaokun_ucsi *uec) { int idx; =20 @@ -320,7 +336,7 @@ static void gaokun_ucsi_altmode_notify_ind(struct gaoku= n_ucsi *uec) if (idx =3D=3D GAOKUN_UCSI_NO_PORT_UPDATE) gaokun_ec_ucsi_pan_ack(uec->ec, idx); /* ack directly if no update */ else - gaokun_ucsi_handle_altmode(&uec->ports[idx]); + gaokun_ucsi_handle_usb_mode(&uec->ports[idx]); } =20 /* @@ -352,7 +368,7 @@ static void gaokun_ucsi_handle_no_usb_event(struct gaok= un_ucsi *uec, int idx) port =3D &uec->ports[idx]; if (!wait_for_completion_timeout(&port->usb_ack, 2 * HZ)) { dev_warn(uec->dev, "No USB EVENT, triggered by UCSI EVENT"); - gaokun_ucsi_altmode_notify_ind(uec); + gaokun_ucsi_usb_notify_ind(uec); } } =20 @@ -366,7 +382,7 @@ static int gaokun_ucsi_notify(struct notifier_block *nb, switch (action) { case EC_EVENT_USB: gaokun_ucsi_complete_usb_ack(uec); - gaokun_ucsi_altmode_notify_ind(uec); + gaokun_ucsi_usb_notify_ind(uec); return NOTIFY_OK; =20 case EC_EVENT_UCSI: @@ -429,8 +445,15 @@ static int gaokun_ucsi_ports_init(struct gaokun_ucsi *= uec) fwnode_handle_put(fwnode); return PTR_ERR(ucsi_port->bridge); } - } =20 + ucsi_port->typec_mux =3D fwnode_typec_mux_get(fwnode); + if (IS_ERR(ucsi_port->typec_mux)) { + fwnode_handle_put(fwnode); + return dev_err_probe(dev, PTR_ERR(ucsi_port->typec_mux), + "failed to acquire mode-switch for port: %d\n", + port); + } + } for (i =3D 0; i < num_ports; i++) { if (!uec->ports[i].bridge) continue; @@ -502,10 +525,14 @@ static int gaokun_ucsi_probe(struct auxiliary_device = *adev, static void gaokun_ucsi_remove(struct auxiliary_device *adev) { struct gaokun_ucsi *uec =3D auxiliary_get_drvdata(adev); + int i; =20 disable_delayed_work_sync(&uec->work); gaokun_ec_unregister_notify(uec->ec, &uec->nb); ucsi_unregister(uec->ucsi); + for (i =3D 0; i < uec->num_ports; ++i) + typec_mux_put(uec->ports[i].typec_mux); + ucsi_destroy(uec->ucsi); } =20 --=20 2.54.0