Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AED98256D for ; Thu, 24 Jul 2025 00:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753317385; cv=none; b=Vg6pocUc6TZi6FxmyignPWYeJ1YJv/xtlDVWIm9wT3DWHvp/mpAyiJSZ7LaqsIgkpoPQLYqJcieg+ydeF0wGhkmDZsqwMvu2MGud/iOiOV8smo5eAhjanvPNPWm4htVnCPDaSGrqeDmKuUj+VGQ+cKmh92TNAx+356TRBE1sz6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753317385; c=relaxed/simple; bh=PSyKf9Cc4nwBUFzixdHaxvYymDgGnVE2FQMQdiJc+vE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PVODwL3ZomO33+PnBlQc2IIRPXv0hmMIUCPPI/XDnyEU+pe+LNi8n+xLZHTG5mwi1M1uL3OaC0l5eZhNOlyJ4Jdq0/1evJ9cbRWJ8P0ScXVKcg9WaXigpJ5CvEpWqavhC8M58nQ3PjmjeTTBBbwYiA2CM/e0MJiE43Kc4u9O09w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jELgxRy3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jELgxRy3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F8EBC4CEEF; Thu, 24 Jul 2025 00:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753317385; bh=PSyKf9Cc4nwBUFzixdHaxvYymDgGnVE2FQMQdiJc+vE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jELgxRy32xuux4Xr3SQX5uGzZlAD9c6uAdoG/czbk53s3QS4S1FvWLErhPUGylTjY oM1ZBX+84L28dUarQofb9SxJV72tKU+rxYTeUDERH7HqIUiuK6THK3e8n4eEj0rxBr iNWtC3VnmS+fz2a7a5ddocJXdyPtHCau9iBUjSGzf55ngbygXseuz4lJZ7iMkwipat UKdxhcOEqHcEzBUT3cRvI5Sw00ITg6uAF1/HiPEn7UOesF7sQ9VYsKUPSQwz2GfqAv GFLD0IlBw9X19BfU0fS2AWUR8Y/4VvJv6/Q1nQtllk27ev1XhG61wVX59BlbnhcT7q b8qP3r5sER3vA== From: Sasha Levin To: stable@vger.kernel.org Cc: Michael Grzeschik , Heikki Krogerus , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.1.y 2/3] usb: typec: tcpm: allow switching to mode accessory to mux properly Date: Wed, 23 Jul 2025 20:36:18 -0400 Message-Id: <20250724003619.1211156-2-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250724003619.1211156-1-sashal@kernel.org> References: <2025070814-evict-shelf-8b8d@gregkh> <20250724003619.1211156-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Michael Grzeschik [ Upstream commit 8a50da849151e7e12b43c1d8fe7ad302223aef6b ] The funciton tcpm_acc_attach is not setting the proper state when calling tcpm_set_role. The function tcpm_set_role is currently only handling TYPEC_STATE_USB. For the tcpm_acc_attach to switch into other modal states tcpm_set_role needs to be extended by an extra state parameter. This patch is handling the proper state change when calling tcpm_acc_attach. Signed-off-by: Michael Grzeschik Reviewed-by: Heikki Krogerus Link: https://lore.kernel.org/r/20250404-ml-topic-tcpm-v1-3-b99f44badce8@pengutronix.de Signed-off-by: Greg Kroah-Hartman Stable-dep-of: bec15191d523 ("usb: typec: tcpm: apply vbus before data bringup in tcpm_src_attach") Signed-off-by: Sasha Levin --- drivers/usb/typec/tcpm/tcpm.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 2515fa12c626e..09b43d5260fa4 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1032,7 +1032,7 @@ static int tcpm_set_attached_state(struct tcpm_port *port, bool attached) port->data_role); } -static int tcpm_set_roles(struct tcpm_port *port, bool attached, +static int tcpm_set_roles(struct tcpm_port *port, bool attached, int state, enum typec_role role, enum typec_data_role data) { enum typec_orientation orientation; @@ -1069,7 +1069,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached, } } - ret = tcpm_mux_set(port, TYPEC_STATE_USB, usb_role, orientation); + ret = tcpm_mux_set(port, state, usb_role, orientation); if (ret < 0) return ret; @@ -3686,7 +3686,8 @@ static int tcpm_src_attach(struct tcpm_port *port) tcpm_enable_auto_vbus_discharge(port, true); - ret = tcpm_set_roles(port, true, TYPEC_SOURCE, tcpm_data_role_for_source(port)); + ret = tcpm_set_roles(port, true, TYPEC_STATE_USB, + TYPEC_SOURCE, tcpm_data_role_for_source(port)); if (ret < 0) return ret; @@ -3844,7 +3845,8 @@ static int tcpm_snk_attach(struct tcpm_port *port) tcpm_enable_auto_vbus_discharge(port, true); - ret = tcpm_set_roles(port, true, TYPEC_SINK, tcpm_data_role_for_sink(port)); + ret = tcpm_set_roles(port, true, TYPEC_STATE_USB, + TYPEC_SINK, tcpm_data_role_for_sink(port)); if (ret < 0) return ret; @@ -3868,6 +3870,7 @@ static int tcpm_acc_attach(struct tcpm_port *port) int ret; enum typec_role role; enum typec_data_role data; + int state = TYPEC_STATE_USB; if (port->attached) return 0; @@ -3876,7 +3879,13 @@ static int tcpm_acc_attach(struct tcpm_port *port) data = tcpm_port_is_sink(port) ? tcpm_data_role_for_sink(port) : tcpm_data_role_for_source(port); - ret = tcpm_set_roles(port, true, role, data); + if (tcpm_port_is_audio(port)) + state = TYPEC_MODE_AUDIO; + + if (tcpm_port_is_debug(port)) + state = TYPEC_MODE_DEBUG; + + ret = tcpm_set_roles(port, true, state, role, data); if (ret < 0) return ret; @@ -4556,7 +4565,7 @@ static void run_state_machine(struct tcpm_port *port) */ tcpm_set_vconn(port, false); tcpm_set_vbus(port, false); - tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE, + tcpm_set_roles(port, port->self_powered, TYPEC_STATE_USB, TYPEC_SOURCE, tcpm_data_role_for_source(port)); /* * If tcpc fails to notify vbus off, TCPM will wait for PD_T_SAFE_0V + @@ -4588,7 +4597,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_vconn(port, false); if (port->pd_capable) tcpm_set_charge(port, false); - tcpm_set_roles(port, port->self_powered, TYPEC_SINK, + tcpm_set_roles(port, port->self_powered, TYPEC_STATE_USB, TYPEC_SINK, tcpm_data_role_for_sink(port)); /* * VBUS may or may not toggle, depending on the adapter. @@ -4693,10 +4702,10 @@ static void run_state_machine(struct tcpm_port *port) case DR_SWAP_CHANGE_DR: tcpm_unregister_altmodes(port); if (port->data_role == TYPEC_HOST) - tcpm_set_roles(port, true, port->pwr_role, + tcpm_set_roles(port, true, TYPEC_STATE_USB, port->pwr_role, TYPEC_DEVICE); else - tcpm_set_roles(port, true, port->pwr_role, + tcpm_set_roles(port, true, TYPEC_STATE_USB, port->pwr_role, TYPEC_HOST); tcpm_ams_finish(port); tcpm_set_state(port, ready_state(port), 0); -- 2.39.5