[PATCH v1 3/3] usb: tcpm: fix toggling in host (SRC) mode
Sebastian Reichel
sebastian.reichel at collabora.com
Fri Nov 1 19:31:45 CET 2024
Hi,
On Fri, Nov 01, 2024 at 01:34:52PM +0300, bigunclemax at gmail.com wrote:
> From: Maksim Kiselev <bigunclemax at 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 at gmail.com>
> ---
I will look into this patch next week and give it a try on the Rock
5B. As a first feedback the commit message seems to confuse data and
power roles. SRC (source) and SNK (sink) are for the power direction
while "host" and "device" are used for the data direction. With
USB-PD these are independent from each other. You seem to have the
old USB model in mind where e.g. a USB keyboard ("device") gets
power from the PC ("host"). But USB-PD allows setups like a USB-C
hub ("device") having its own power-supply and providing a laptop
("host") with power.
Greetings,
-- Sebastian
> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20241101/ce7cf243/attachment.sig>
More information about the U-Boot
mailing list