Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: typec: tcpci_rt1711h: restart DRP toggling on Ra/Open in TOGGLING
@ 2026-11-26  0:33 Ilia Snezhkov via B4 Relay
  2026-11-26  0:49 ` sashiko-bot
  0 siblings, 1 reply; 4+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:33 UTC (permalink / raw)
  To: heikki.krogerus, gregkh, linux
  Cc: badhri, shufan_lee, linux-usb, linux-kernel

From: Ilia Snezhkov <iasnezhkov@gmail.com>

When a DRP port using RT1711H/RT1715 or its ETEK ET7303/ET7304
compatible silicon is connected via an e-marked USB-C cable (for example
to a USB-C PD charger whose own port is temporarily open), the hardware
can stop DRP toggling during its Rp phase upon detecting a single Ra
pull-down, reporting CC_STATUS with LOOKING4CONNECTION=0,
CONNECTRESULT=0 (Rp), and (CC1=Ra, CC2=Open).

In tcpm_cc_change(), case TOGGLING only transitions out of TOGGLING for
source (Rd), sink (Rp), audio accessory (Ra+Ra), and debug accessory
states. (Ra, Open), (Open, Ra), and (Open, Open) fall through with no
state change and no call to tcpm_start_toggling(). Because the TCPC has
already exited hardware toggling, the port remains permanently wedged
presenting Rp: PD chargers never see Rd and never source VBUS, and
subsequent USB host connections fail to enumerate until another
TCPC_CMD_LOOK4CONNECTION command is issued. (fusb302 handles the same
condition by restarting toggling on unexpected CC states.)

In rt1711h_irq(), when TCPC_ALERT_CC_STATUS fires with
TCPC_CC_STATUS_TOGGLING clear while tcpm_port_is_toggling() is true and
TCPC_ROLE_CTRL_DRP is set, decode (cc1, cc2) identically to
tcpci_get_cc(). If the state is (Open, Open), (Ra, Open), or (Open, Ra),
clear TCPC_ALERT_CC_STATUS, preserve RP_VAL while resetting CC1/CC2 to
Rd with the RT1711H DRP=0 settle delay matching
rt1711h_start_drp_toggling(), re-enable DRP, and issue
TCPC_CMD_LOOK4CONNECTION. Return IRQ_HANDLED so any co-occurring alert
bits remain pending on the level-low IRQ line and re-enter cleanly.

Observed and verified on hardware (MT6789 phone with ETEK ET7303
VID 0x6DCF PID 0x1711 DID 0x2173 and Anker/Apple USB-C PD chargers with
e-marked C-to-C cables) as well as a 1542-case host state-machine test
covering all 64 CC states, RP_VAL preservation, co-occurring alerts, and
I2C error fallbacks.

Drafted with an AI coding assistant.

Fixes: ce08eaeb6388 ("staging: typec: rt1711h typec chip driver")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 drivers/usb/typec/tcpm/tcpci_rt1711h.c | 47 ++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
index 0581659..e03eca7 100644
--- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
+++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
@@ -253,6 +253,51 @@ static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
 	return 0;
 }
 
+static bool rt1711h_cc_needs_retoggle(enum typec_cc_status cc1,
+				      enum typec_cc_status cc2)
+{
+	return (cc1 == TYPEC_CC_OPEN && cc2 == TYPEC_CC_OPEN) ||
+	       (cc1 == TYPEC_CC_RA && cc2 == TYPEC_CC_OPEN) ||
+	       (cc1 == TYPEC_CC_OPEN && cc2 == TYPEC_CC_RA);
+}
+
+static bool rt1711h_restart_toggling(struct rt1711h_chip *chip, u8 status)
+{
+	struct tcpm_port *port = tcpci_get_tcpm_port(chip->tcpci);
+	enum typec_cc_status cc1, cc2;
+	unsigned int base;
+	u8 role = 0;
+	int ret;
+
+	if (!tcpm_port_is_toggling(port))
+		return false;
+	ret = rt1711h_read8(chip, TCPC_ROLE_CTRL, &role);
+	if (ret < 0 || !(role & TCPC_ROLE_CTRL_DRP))
+		return false;
+	cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, status),
+				status & TCPC_CC_STATUS_TERM ||
+				tcpc_presenting_rd(role, CC1));
+	cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, status),
+				status & TCPC_CC_STATUS_TERM ||
+				tcpc_presenting_rd(role, CC2));
+	if (!rt1711h_cc_needs_retoggle(cc1, cc2))
+		return false;
+	base = (role & TCPC_ROLE_CTRL_RP_VAL) |
+	       FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) |
+	       FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD);
+	ret = rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS);
+	if (ret < 0)
+		return false;
+	ret = rt1711h_write8(chip, TCPC_ROLE_CTRL, base);
+	if (ret < 0)
+		return false;
+	usleep_range(500, 1000);
+	ret = rt1711h_write8(chip, TCPC_ROLE_CTRL, base | TCPC_ROLE_CTRL_DRP);
+	if (ret < 0)
+		return false;
+	return rt1711h_write8(chip, TCPC_COMMAND, TCPC_CMD_LOOK4CONNECTION) == 0;
+}
+
 static irqreturn_t rt1711h_irq(int irq, void *dev_id)
 {
 	int ret;
@@ -274,6 +319,8 @@ static irqreturn_t rt1711h_irq(int irq, void *dev_id)
 		/* Clear cc change event triggered by starting toggling */
 		if (status & TCPC_CC_STATUS_TOGGLING)
 			rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS);
+		else if (rt1711h_restart_toggling(chip, status))
+			return IRQ_HANDLED;
 		else
 			rt1711h_init_cc_params(chip, status);
 	}
-- 
2.54.0 (Apple Git-157)




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: typec: tcpci_rt1711h: restart DRP toggling on Ra/Open in TOGGLING
  2026-11-26  0:33 [PATCH] usb: typec: tcpci_rt1711h: restart DRP toggling on Ra/Open in TOGGLING Ilia Snezhkov via B4 Relay
@ 2026-11-26  0:49 ` sashiko-bot
  2026-11-26  6:37   ` Ilia Snezhkov
  0 siblings, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-11-26  0:49 UTC (permalink / raw)
  To: Ilia Snezhkov; +Cc: linux-usb

> From: Ilia Snezhkov <iasnezhkov@gmail.com>
> 
> When a DRP port using RT1711H/RT1715 or its ETEK ET7303/ET7304
> compatible silicon is connected via an e-marked USB-C cable (for example
> to a USB-C PD charger whose own port is temporarily open), the hardware
> can stop DRP toggling during its Rp phase upon detecting a single Ra
> pull-down, reporting CC_STATUS with LOOKING4CONNECTION=0,
> CONNECTRESULT=0 (Rp), and (CC1=Ra, CC2=Open).
> 
> In tcpm_cc_change(), case TOGGLING only transitions out of TOGGLING for
> source (Rd), sink (Rp), audio accessory (Ra+Ra), and debug accessory
> states. (Ra, Open), (Open, Ra), and (Open, Open) fall through with no
> state change and no call to tcpm_start_toggling(). Because the TCPC has
> already exited hardware toggling, the port remains permanently wedged
> presenting Rp: PD chargers never see Rd and never source VBUS, and
> [ ... ]
> 
> Drafted with an AI coding assistant.
> 
> Fixes: ce08eaeb6388 ("staging: typec: rt1711h typec chip driver")
> Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126003308.48940-1-iasnezhkov@gmail.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: typec: tcpci_rt1711h: restart DRP toggling on Ra/Open in TOGGLING
  2026-11-26  0:49 ` sashiko-bot
@ 2026-11-26  6:37   ` Ilia Snezhkov
  2026-11-30 13:13     ` Heikki Krogerus
  0 siblings, 1 reply; 4+ messages in thread
From: Ilia Snezhkov @ 2026-11-26  6:37 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: linux-usb

Please disregard this v1 patch.

On further self-review I noticed two defects with restarting DRP toggling directly from rt1711h_irq():
1. The unlocked TCPC_ROLE_CTRL read-modify-write across usleep_range(500, 1000) races with TCPM state transitions under port->lock, and an I2C failure after clearing TCPC_ROLE_CTRL_DRP can leave toggling disabled with TCPC_ALERT_CC_STATUS already cleared.
2. tcpc_presenting_rd() is dead after verifying TCPC_ROLE_CTRL_DRP is set (and the case TOGGLING check is in _tcpm_cc_change(), not tcpm_cc_change()).

I will re-evaluate handling this under TCPM serialization before sendin a v2. Apologies for the noise.

Best regards,
Ilia

> On Nov 26, 2026, at 8:49, sashiko-bot@kernel.org wrote:
> 
>> From: Ilia Snezhkov <iasnezhkov@gmail.com>
>> 
>> When a DRP port using RT1711H/RT1715 or its ETEK ET7303/ET7304
>> compatible silicon is connected via an e-marked USB-C cable (for example
>> to a USB-C PD charger whose own port is temporarily open), the hardware
>> can stop DRP toggling during its Rp phase upon detecting a single Ra
>> pull-down, reporting CC_STATUS with LOOKING4CONNECTION=0,
>> CONNECTRESULT=0 (Rp), and (CC1=Ra, CC2=Open).
>> 
>> In tcpm_cc_change(), case TOGGLING only transitions out of TOGGLING for
>> source (Rd), sink (Rp), audio accessory (Ra+Ra), and debug accessory
>> states. (Ra, Open), (Open, Ra), and (Open, Open) fall through with no
>> state change and no call to tcpm_start_toggling(). Because the TCPC has
>> already exited hardware toggling, the port remains permanently wedged
>> presenting Rp: PD chargers never see Rd and never source VBUS, and
>> [ ... ]
>> 
>> Drafted with an AI coding assistant.
>> 
>> Fixes: ce08eaeb6388 ("staging: typec: rt1711h typec chip driver")
>> Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
> 
> Sashiko has reviewed this patch and found no issues.
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261126003308.48940-1-iasnezhkov@gmail.com?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: typec: tcpci_rt1711h: restart DRP toggling on Ra/Open in TOGGLING
  2026-11-26  6:37   ` Ilia Snezhkov
@ 2026-11-30 13:13     ` Heikki Krogerus
  0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2026-11-30 13:13 UTC (permalink / raw)
  To: Ilia Snezhkov; +Cc: linux-usb

On Thu, Nov 26, 2026 at 02:37:32PM +0800, Ilia Snezhkov wrote:
> Please disregard this v1 patch.
> 
> On further self-review I noticed two defects with restarting DRP toggling directly from rt1711h_irq():
> 1. The unlocked TCPC_ROLE_CTRL read-modify-write across usleep_range(500, 1000) races with TCPM state transitions under port->lock, and an I2C failure after clearing TCPC_ROLE_CTRL_DRP can leave toggling disabled with TCPC_ALERT_CC_STATUS already cleared.
> 2. tcpc_presenting_rd() is dead after verifying TCPC_ROLE_CTRL_DRP is set (and the case TOGGLING check is in _tcpm_cc_change(), not tcpm_cc_change()).
> 
> I will re-evaluate handling this under TCPM serialization before sendin a v2. Apologies for the noise.

Note, Sashiko drops everybody from CC. It's possible that some
maintainers haven't seen your comment.

When you prepare v2, please CC also stable if this really is a fix.

Oh, and no top-posting on the list.

Cheers,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 13:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  0:33 [PATCH] usb: typec: tcpci_rt1711h: restart DRP toggling on Ra/Open in TOGGLING Ilia Snezhkov via B4 Relay
2026-11-26  0:49 ` sashiko-bot
2026-11-26  6:37   ` Ilia Snezhkov
2026-11-30 13:13     ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox