public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: bigunclemax@gmail.com
Cc: bigunclemax@gmail.com,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Marek Vasut <marex@denx.de>, Tom Rini <trini@konsulko.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	Wang Jie <dave.wang@rock-chips.com>,
	u-boot@lists.denx.de
Subject: [PATCH v1 3/3] usb: tcpm: fix toggling in host (SRC) mode
Date: Fri,  1 Nov 2024 13:34:52 +0300	[thread overview]
Message-ID: <20241101103501.21432-4-bigunclemax@gmail.com> (raw)
In-Reply-To: <20241101103501.21432-1-bigunclemax@gmail.com>

From: Maksim Kiselev <bigunclemax@gmail.com>

PU\PD resistors on CC lines must be configured before running the TCPM
state machine.

Also, when the Type-C port acts as a host (SRC), the VBUS sould be enabled
only after the toggling has been completed. And we have to wait for
the corresponding IRQ to finish the toggling process. But this doesn't
happen because we exit from tcpm_poll_event() if VBUS != OK.

So, Let's check for VBUS state only when the port acts as a host (SRC)
to solve this problem.

Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
---
 drivers/usb/tcpm/tcpm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/tcpm/tcpm.c b/drivers/usb/tcpm/tcpm.c
index 0aee57cb2f4..c9f8dbdc795 100644
--- a/drivers/usb/tcpm/tcpm.c
+++ b/drivers/usb/tcpm/tcpm.c
@@ -2122,6 +2122,12 @@ static void tcpm_init(struct udevice *dev)
 	else
 		port->vbus_vsafe0v = true;
 
+	if (port->self_powered)
+		tcpm_set_cc(dev, TYPEC_CC_OPEN);
+	else
+		tcpm_set_cc(dev, tcpm_default_state(port) == SNK_UNATTACHED ?
+				TYPEC_CC_RD : tcpm_rp_cc(port));
+
 	tcpm_set_state(dev, tcpm_default_state(port), 0);
 
 	if (drvops->get_cc(dev, &cc1, &cc2) == 0)
@@ -2234,7 +2240,7 @@ static void tcpm_poll_event(struct udevice *dev)
 	const struct dm_tcpm_ops *drvops = dev_get_driver_ops(dev);
 	struct tcpm_port *port = dev_get_uclass_plat(dev);
 
-	if (!drvops->get_vbus(dev))
+	if (!drvops->get_vbus(dev) && (tcpm_default_state(port) == SNK_UNATTACHED))
 		return;
 
 	while (port->poll_event_cnt < TCPM_POLL_EVENT_TIME_OUT) {
-- 
2.45.2


  parent reply	other threads:[~2024-11-01 10:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-01 10:34 [PATCH v1 0/3] USB TCPM host (SRC) mode improvements bigunclemax
2024-11-01 10:34 ` [PATCH v1 1/3] usb: tcpm: fusb302: add missing newline character to debug output bigunclemax
2024-11-01 18:10   ` Sebastian Reichel
2024-11-01 10:34 ` [PATCH v1 2/3] usb: tcpm: fusb302: add support for set_vbus() callback bigunclemax
2024-11-01 18:17   ` Sebastian Reichel
2024-11-02 23:21     ` Jonas Karlman
2024-11-06 16:10       ` Maxim Kiselev
2024-11-01 10:34 ` bigunclemax [this message]
2024-11-01 18:31   ` [PATCH v1 3/3] usb: tcpm: fix toggling in host (SRC) mode Sebastian Reichel
2024-11-06 16:10     ` Maxim Kiselev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241101103501.21432-4-bigunclemax@gmail.com \
    --to=bigunclemax@gmail.com \
    --cc=dave.wang@rock-chips.com \
    --cc=jonas@kwiboo.se \
    --cc=marex@denx.de \
    --cc=sebastian.reichel@collabora.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox