Skip to content

Commit 9ec71a8

Browse files
author
Desnes Nunes
committed
usb: typec: tcpm: allow switching to mode accessory to mux properly
JIRA: https://issues.redhat.com/browse/RHEL-116016 commit 8a50da8 Author: Michael Grzeschik <m.grzeschik@pengutronix.de> Date: Fri, 4 Apr 2025 00:43:06 +0200 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 <m.grzeschik@pengutronix.de> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20250404-ml-topic-tcpm-v1-3-b99f44badce8@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Desnes Nunes <desnesn@redhat.com>
1 parent dd8ab32 commit 9ec71a8

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ static int tcpm_set_attached_state(struct tcpm_port *port, bool attached)
11531153
port->data_role);
11541154
}
11551155

1156-
static int tcpm_set_roles(struct tcpm_port *port, bool attached,
1156+
static int tcpm_set_roles(struct tcpm_port *port, bool attached, int state,
11571157
enum typec_role role, enum typec_data_role data)
11581158
{
11591159
enum typec_orientation orientation;
@@ -1190,7 +1190,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,
11901190
}
11911191
}
11921192

1193-
ret = tcpm_mux_set(port, TYPEC_STATE_USB, usb_role, orientation);
1193+
ret = tcpm_mux_set(port, state, usb_role, orientation);
11941194
if (ret < 0)
11951195
return ret;
11961196

@@ -4355,7 +4355,8 @@ static int tcpm_src_attach(struct tcpm_port *port)
43554355

43564356
tcpm_enable_auto_vbus_discharge(port, true);
43574357

4358-
ret = tcpm_set_roles(port, true, TYPEC_SOURCE, tcpm_data_role_for_source(port));
4358+
ret = tcpm_set_roles(port, true, TYPEC_STATE_USB,
4359+
TYPEC_SOURCE, tcpm_data_role_for_source(port));
43594360
if (ret < 0)
43604361
return ret;
43614362

@@ -4530,7 +4531,8 @@ static int tcpm_snk_attach(struct tcpm_port *port)
45304531

45314532
tcpm_enable_auto_vbus_discharge(port, true);
45324533

4533-
ret = tcpm_set_roles(port, true, TYPEC_SINK, tcpm_data_role_for_sink(port));
4534+
ret = tcpm_set_roles(port, true, TYPEC_STATE_USB,
4535+
TYPEC_SINK, tcpm_data_role_for_sink(port));
45344536
if (ret < 0)
45354537
return ret;
45364538

@@ -4555,6 +4557,7 @@ static int tcpm_acc_attach(struct tcpm_port *port)
45554557
int ret;
45564558
enum typec_role role;
45574559
enum typec_data_role data;
4560+
int state = TYPEC_STATE_USB;
45584561

45594562
if (port->attached)
45604563
return 0;
@@ -4563,7 +4566,13 @@ static int tcpm_acc_attach(struct tcpm_port *port)
45634566
data = tcpm_port_is_sink(port) ? tcpm_data_role_for_sink(port)
45644567
: tcpm_data_role_for_source(port);
45654568

4566-
ret = tcpm_set_roles(port, true, role, data);
4569+
if (tcpm_port_is_audio(port))
4570+
state = TYPEC_MODE_AUDIO;
4571+
4572+
if (tcpm_port_is_debug(port))
4573+
state = TYPEC_MODE_DEBUG;
4574+
4575+
ret = tcpm_set_roles(port, true, state, role, data);
45674576
if (ret < 0)
45684577
return ret;
45694578

@@ -5349,7 +5358,7 @@ static void run_state_machine(struct tcpm_port *port)
53495358
*/
53505359
tcpm_set_vconn(port, false);
53515360
tcpm_set_vbus(port, false);
5352-
tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE,
5361+
tcpm_set_roles(port, port->self_powered, TYPEC_STATE_USB, TYPEC_SOURCE,
53535362
tcpm_data_role_for_source(port));
53545363
/*
53555364
* If tcpc fails to notify vbus off, TCPM will wait for PD_T_SAFE_0V +
@@ -5381,7 +5390,7 @@ static void run_state_machine(struct tcpm_port *port)
53815390
tcpm_set_vconn(port, false);
53825391
if (port->pd_capable)
53835392
tcpm_set_charge(port, false);
5384-
tcpm_set_roles(port, port->self_powered, TYPEC_SINK,
5393+
tcpm_set_roles(port, port->self_powered, TYPEC_STATE_USB, TYPEC_SINK,
53855394
tcpm_data_role_for_sink(port));
53865395
/*
53875396
* VBUS may or may not toggle, depending on the adapter.
@@ -5505,10 +5514,10 @@ static void run_state_machine(struct tcpm_port *port)
55055514
case DR_SWAP_CHANGE_DR:
55065515
tcpm_unregister_altmodes(port);
55075516
if (port->data_role == TYPEC_HOST)
5508-
tcpm_set_roles(port, true, port->pwr_role,
5517+
tcpm_set_roles(port, true, TYPEC_STATE_USB, port->pwr_role,
55095518
TYPEC_DEVICE);
55105519
else
5511-
tcpm_set_roles(port, true, port->pwr_role,
5520+
tcpm_set_roles(port, true, TYPEC_STATE_USB, port->pwr_role,
55125521
TYPEC_HOST);
55135522
tcpm_ams_finish(port);
55145523
tcpm_set_state(port, ready_state(port), 0);

0 commit comments

Comments
 (0)