* [PATCH 0/3] usb: typec: tcpm: sink (ufp) accessory mode support
@ 2025-04-03 22:43 Michael Grzeschik
2025-04-03 22:43 ` [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Michael Grzeschik
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Michael Grzeschik @ 2025-04-03 22:43 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, kernel, Michael Grzeschik
This series is adding support to reach the DEBUG_ACC_ATTACHED state
when configured as sink. It also extends the tcpm_acc_attach function
to handle sink and src cases and sets the proper modal state when
calling tcpm_set_role.
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
Michael Grzeschik (3):
usb: typec: tcpm: allow to use sink in accessory mode
usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug
usb: typec: tcpm: allow switching to mode accessory to mux properly
drivers/usb/typec/tcpm/tcpm.c | 68 +++++++++++++++++++++++++++++++++----------
1 file changed, 53 insertions(+), 15 deletions(-)
---
base-commit: a1b5bd45d4ee58af4f56e49497b8c3db96d8f8a3
change-id: 20250404-ml-topic-tcpm-aabcc5f2d55e
Best regards,
--
Michael Grzeschik <m.grzeschik@pengutronix.de>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode 2025-04-03 22:43 [PATCH 0/3] usb: typec: tcpm: sink (ufp) accessory mode support Michael Grzeschik @ 2025-04-03 22:43 ` Michael Grzeschik 2025-04-07 13:46 ` Heikki Krogerus 2025-04-03 22:43 ` [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug Michael Grzeschik 2025-04-03 22:43 ` [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly Michael Grzeschik 2 siblings, 1 reply; 7+ messages in thread From: Michael Grzeschik @ 2025-04-03 22:43 UTC (permalink / raw) To: Heikki Krogerus, Greg Kroah-Hartman Cc: linux-usb, linux-kernel, kernel, Michael Grzeschik Since the function tcpm_acc_attach is not setting the data and role for for the sink case we extend it to check for it first. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> --- drivers/usb/typec/tcpm/tcpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index a99db4e025cd0..839697c14265e 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4551,12 +4551,17 @@ static void tcpm_snk_detach(struct tcpm_port *port) static int tcpm_acc_attach(struct tcpm_port *port) { int ret; + enum typec_role role; + enum typec_data_role data; if (port->attached) return 0; - ret = tcpm_set_roles(port, true, TYPEC_SOURCE, - tcpm_data_role_for_source(port)); + role = tcpm_port_is_sink(port) ? TYPEC_SINK : TYPEC_SOURCE; + 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 (ret < 0) return ret; -- 2.39.5 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode 2025-04-03 22:43 ` [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Michael Grzeschik @ 2025-04-07 13:46 ` Heikki Krogerus 0 siblings, 0 replies; 7+ messages in thread From: Heikki Krogerus @ 2025-04-07 13:46 UTC (permalink / raw) To: Michael Grzeschik Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, kernel, Badhri Jagan Sridharan +Badhri On Fri, Apr 04, 2025 at 12:43:04AM +0200, Michael Grzeschik wrote: > Since the function tcpm_acc_attach is not setting the data and role for > for the sink case we extend it to check for it first. > > Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > drivers/usb/typec/tcpm/tcpm.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index a99db4e025cd0..839697c14265e 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -4551,12 +4551,17 @@ static void tcpm_snk_detach(struct tcpm_port *port) > static int tcpm_acc_attach(struct tcpm_port *port) > { > int ret; > + enum typec_role role; > + enum typec_data_role data; > > if (port->attached) > return 0; > > - ret = tcpm_set_roles(port, true, TYPEC_SOURCE, > - tcpm_data_role_for_source(port)); > + role = tcpm_port_is_sink(port) ? TYPEC_SINK : TYPEC_SOURCE; > + 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 (ret < 0) > return ret; > -- heikki ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug 2025-04-03 22:43 [PATCH 0/3] usb: typec: tcpm: sink (ufp) accessory mode support Michael Grzeschik 2025-04-03 22:43 ` [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Michael Grzeschik @ 2025-04-03 22:43 ` Michael Grzeschik 2025-04-07 13:48 ` Heikki Krogerus 2025-04-03 22:43 ` [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly Michael Grzeschik 2 siblings, 1 reply; 7+ messages in thread From: Michael Grzeschik @ 2025-04-03 22:43 UTC (permalink / raw) To: Heikki Krogerus, Greg Kroah-Hartman Cc: linux-usb, linux-kernel, kernel, Michael Grzeschik This patch extends the is_debug macro to cover the sink case (ufp). It also handles the transition to access the DEBUG_ACC_ATTACHED state in the sink case. It also handles the debounce case in which the cc pins are not immediately valid after the plug event. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> --- drivers/usb/typec/tcpm/tcpm.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 839697c14265e..01714a42f848a 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -67,6 +67,7 @@ \ S(ACC_UNATTACHED), \ S(DEBUG_ACC_ATTACHED), \ + S(DEBUG_ACC_DEBOUNCE), \ S(AUDIO_ACC_ATTACHED), \ S(AUDIO_ACC_DEBOUNCE), \ \ @@ -621,7 +622,8 @@ static const char * const pd_rev[] = { !tcpm_cc_is_source((port)->cc1))) #define tcpm_port_is_debug(port) \ - (tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) + ((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \ + (tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2))) #define tcpm_port_is_audio(port) \ (tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2)) @@ -4969,7 +4971,13 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC); break; case SNK_ATTACH_WAIT: - if ((port->cc1 == TYPEC_CC_OPEN && + if (tcpm_port_is_debug(port)) + tcpm_set_state(port, DEBUG_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); + else if (tcpm_port_is_audio(port)) + tcpm_set_state(port, AUDIO_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); + else if ((port->cc1 == TYPEC_CC_OPEN && port->cc2 != TYPEC_CC_OPEN) || (port->cc1 != TYPEC_CC_OPEN && port->cc2 == TYPEC_CC_OPEN)) @@ -4983,6 +4991,12 @@ static void run_state_machine(struct tcpm_port *port) if (tcpm_port_is_disconnected(port)) tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE); + else if (tcpm_port_is_debug(port)) + tcpm_set_state(port, DEBUG_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); + else if (tcpm_port_is_audio(port)) + tcpm_set_state(port, AUDIO_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); else if (port->vbus_present) tcpm_set_state(port, tcpm_try_src(port) ? SRC_TRY @@ -5281,7 +5295,10 @@ static void run_state_machine(struct tcpm_port *port) /* Accessory states */ case ACC_UNATTACHED: tcpm_acc_detach(port); - tcpm_set_state(port, SRC_UNATTACHED, 0); + if (port->port_type == TYPEC_PORT_SRC) + tcpm_set_state(port, SRC_UNATTACHED, 0); + else + tcpm_set_state(port, SNK_UNATTACHED, 0); break; case DEBUG_ACC_ATTACHED: case AUDIO_ACC_ATTACHED: @@ -5289,6 +5306,7 @@ static void run_state_machine(struct tcpm_port *port) if (ret < 0) tcpm_set_state(port, ACC_UNATTACHED, 0); break; + case DEBUG_ACC_DEBOUNCE: case AUDIO_ACC_DEBOUNCE: tcpm_set_state(port, ACC_UNATTACHED, port->timings.cc_debounce_time); break; @@ -5880,7 +5898,8 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, } break; case SNK_UNATTACHED: - if (tcpm_port_is_sink(port)) + if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) || + tcpm_port_is_sink(port)) tcpm_set_state(port, SNK_ATTACH_WAIT, 0); break; case SNK_ATTACH_WAIT: @@ -5943,7 +5962,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, case DEBUG_ACC_ATTACHED: if (cc1 == TYPEC_CC_OPEN || cc2 == TYPEC_CC_OPEN) - tcpm_set_state(port, ACC_UNATTACHED, 0); + tcpm_set_state(port, DEBUG_ACC_DEBOUNCE, 0); + break; + + case DEBUG_ACC_DEBOUNCE: + if (tcpm_port_is_debug(port)) + tcpm_set_state(port, DEBUG_ACC_ATTACHED, 0); break; case SNK_TRY: -- 2.39.5 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug 2025-04-03 22:43 ` [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug Michael Grzeschik @ 2025-04-07 13:48 ` Heikki Krogerus 0 siblings, 0 replies; 7+ messages in thread From: Heikki Krogerus @ 2025-04-07 13:48 UTC (permalink / raw) To: Michael Grzeschik Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, kernel, Badhri Jagan Sridharan +Badhri On Fri, Apr 04, 2025 at 12:43:05AM +0200, Michael Grzeschik wrote: > This patch extends the is_debug macro to cover the sink case (ufp). It > also handles the transition to access the DEBUG_ACC_ATTACHED state in > the sink case. It also handles the debounce case in which the cc > pins are not immediately valid after the plug event. > > Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > drivers/usb/typec/tcpm/tcpm.c | 34 +++++++++++++++++++++++++++++----- > 1 file changed, 29 insertions(+), 5 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index 839697c14265e..01714a42f848a 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -67,6 +67,7 @@ > \ > S(ACC_UNATTACHED), \ > S(DEBUG_ACC_ATTACHED), \ > + S(DEBUG_ACC_DEBOUNCE), \ > S(AUDIO_ACC_ATTACHED), \ > S(AUDIO_ACC_DEBOUNCE), \ > \ > @@ -621,7 +622,8 @@ static const char * const pd_rev[] = { > !tcpm_cc_is_source((port)->cc1))) > > #define tcpm_port_is_debug(port) \ > - (tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) > + ((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \ > + (tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2))) > > #define tcpm_port_is_audio(port) \ > (tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2)) > @@ -4969,7 +4971,13 @@ static void run_state_machine(struct tcpm_port *port) > tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC); > break; > case SNK_ATTACH_WAIT: > - if ((port->cc1 == TYPEC_CC_OPEN && > + if (tcpm_port_is_debug(port)) > + tcpm_set_state(port, DEBUG_ACC_ATTACHED, > + PD_T_CC_DEBOUNCE); > + else if (tcpm_port_is_audio(port)) > + tcpm_set_state(port, AUDIO_ACC_ATTACHED, > + PD_T_CC_DEBOUNCE); > + else if ((port->cc1 == TYPEC_CC_OPEN && > port->cc2 != TYPEC_CC_OPEN) || > (port->cc1 != TYPEC_CC_OPEN && > port->cc2 == TYPEC_CC_OPEN)) > @@ -4983,6 +4991,12 @@ static void run_state_machine(struct tcpm_port *port) > if (tcpm_port_is_disconnected(port)) > tcpm_set_state(port, SNK_UNATTACHED, > PD_T_PD_DEBOUNCE); > + else if (tcpm_port_is_debug(port)) > + tcpm_set_state(port, DEBUG_ACC_ATTACHED, > + PD_T_CC_DEBOUNCE); > + else if (tcpm_port_is_audio(port)) > + tcpm_set_state(port, AUDIO_ACC_ATTACHED, > + PD_T_CC_DEBOUNCE); > else if (port->vbus_present) > tcpm_set_state(port, > tcpm_try_src(port) ? SRC_TRY > @@ -5281,7 +5295,10 @@ static void run_state_machine(struct tcpm_port *port) > /* Accessory states */ > case ACC_UNATTACHED: > tcpm_acc_detach(port); > - tcpm_set_state(port, SRC_UNATTACHED, 0); > + if (port->port_type == TYPEC_PORT_SRC) > + tcpm_set_state(port, SRC_UNATTACHED, 0); > + else > + tcpm_set_state(port, SNK_UNATTACHED, 0); > break; > case DEBUG_ACC_ATTACHED: > case AUDIO_ACC_ATTACHED: > @@ -5289,6 +5306,7 @@ static void run_state_machine(struct tcpm_port *port) > if (ret < 0) > tcpm_set_state(port, ACC_UNATTACHED, 0); > break; > + case DEBUG_ACC_DEBOUNCE: > case AUDIO_ACC_DEBOUNCE: > tcpm_set_state(port, ACC_UNATTACHED, port->timings.cc_debounce_time); > break; > @@ -5880,7 +5898,8 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, > } > break; > case SNK_UNATTACHED: > - if (tcpm_port_is_sink(port)) > + if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) || > + tcpm_port_is_sink(port)) > tcpm_set_state(port, SNK_ATTACH_WAIT, 0); > break; > case SNK_ATTACH_WAIT: > @@ -5943,7 +5962,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, > > case DEBUG_ACC_ATTACHED: > if (cc1 == TYPEC_CC_OPEN || cc2 == TYPEC_CC_OPEN) > - tcpm_set_state(port, ACC_UNATTACHED, 0); > + tcpm_set_state(port, DEBUG_ACC_DEBOUNCE, 0); > + break; > + > + case DEBUG_ACC_DEBOUNCE: > + if (tcpm_port_is_debug(port)) > + tcpm_set_state(port, DEBUG_ACC_ATTACHED, 0); > break; > > case SNK_TRY: > > -- > 2.39.5 -- heikki ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly 2025-04-03 22:43 [PATCH 0/3] usb: typec: tcpm: sink (ufp) accessory mode support Michael Grzeschik 2025-04-03 22:43 ` [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Michael Grzeschik 2025-04-03 22:43 ` [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug Michael Grzeschik @ 2025-04-03 22:43 ` Michael Grzeschik 2025-04-07 13:50 ` Heikki Krogerus 2 siblings, 1 reply; 7+ messages in thread From: Michael Grzeschik @ 2025-04-03 22:43 UTC (permalink / raw) To: Heikki Krogerus, Greg Kroah-Hartman Cc: linux-usb, linux-kernel, kernel, Michael Grzeschik 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> --- 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 01714a42f848a..784fa23102f90 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1153,7 +1153,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; @@ -1190,7 +1190,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; @@ -4355,7 +4355,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; @@ -4530,7 +4531,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; @@ -4555,6 +4557,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; @@ -4563,7 +4566,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; @@ -5349,7 +5358,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 + @@ -5381,7 +5390,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. @@ -5505,10 +5514,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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly 2025-04-03 22:43 ` [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly Michael Grzeschik @ 2025-04-07 13:50 ` Heikki Krogerus 0 siblings, 0 replies; 7+ messages in thread From: Heikki Krogerus @ 2025-04-07 13:50 UTC (permalink / raw) To: Michael Grzeschik Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, kernel, Badhri Jagan Sridharan +Badhri On Fri, Apr 04, 2025 at 12:43:06AM +0200, Michael Grzeschik wrote: > 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> > --- > 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 01714a42f848a..784fa23102f90 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -1153,7 +1153,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; > @@ -1190,7 +1190,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; > > @@ -4355,7 +4355,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; > > @@ -4530,7 +4531,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; > > @@ -4555,6 +4557,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; > @@ -4563,7 +4566,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; > > @@ -5349,7 +5358,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 + > @@ -5381,7 +5390,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. > @@ -5505,10 +5514,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 -- heikki ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-04-07 13:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-04-03 22:43 [PATCH 0/3] usb: typec: tcpm: sink (ufp) accessory mode support Michael Grzeschik 2025-04-03 22:43 ` [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Michael Grzeschik 2025-04-07 13:46 ` Heikki Krogerus 2025-04-03 22:43 ` [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug Michael Grzeschik 2025-04-07 13:48 ` Heikki Krogerus 2025-04-03 22:43 ` [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly Michael Grzeschik 2025-04-07 13:50 ` Heikki Krogerus
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox