Hi Sebastian,

Thanks for new patch version!

On 03.09.24 20:16, Sebastian Reichel wrote:
Hi,

On ROCK 5B power is usually supplied via it's USB-C port. This port has the
data lines connected to RK3588, VBUS connected to the input regulator and
CC pins connected to FUSB302. FUSB302 is a USB-C controller, which can be
accessed via I2C from RK3588. The USB-C controller is needed to figure out
the USB-C cable orientation, but also to do USB PD communication. Thus it
would be great to enable support for it in the operating system.

But the USB-PD specification requires, that a device reacts to USB-PD messages
send by the power-supply within around 5 seconds. If that does not happen the
power-supply assumes, that the device does not support USB-PD. If a device
later starts sending USB-PD messages it is considered an error, which is solved
by doing a hard reset. A USB-PD hard reset means, that all supply voltages are
removed for a short period of time. For boards, which are solely powered
through their USB-C port, like the Radxa Rock 5B, this results in an machine
reset. This is currently worked around by not describing the FUSB302 in the
kernel DT, so nothing will ever speak USB-PD on the Rock 5B. This means

1. the USB-C port cannot be used at all
2. the board will be running via fallback supply, which provides limited
    power capabilities

In order to avoid the hard reset, this adds FUSB302 support to U-Boot, so
that we react to the power-supply's queries in time. The code, which is
originally from the Linux kernel, consists of two parts:

1. the tcpm state machine, which implements the Type C port manager state
    machine as described in the USB PD specification
2. the fusb302 driver, which knows about specific registers

Especially the first part has been heavily modified compared to the
kernel, which makes use of multiple delayed works and threads. For this
I used a priorly ported version from Rockchip, removed their hacks and
any states not necessary in U-Boot (e.g. audio accessory support).

This version has been tested on Radxa Rock 5B using the open source TF-A
(patches recently got merged into master branch) using the following power
supplies:

  * non PD capable (reports 5V 0A)
With a dumb power supply (actually 12V w/o USB-PD) I see a error message
(not really sure if that makes sense, but no strong opinion from my side)
and 5V/1.5A reported with 'tcpm info', see below.
Can we expect 1.5A as fallback supply w/o USB-PD negotiation? 5V OK, but
I'm not sure if USB2/USB3 type A to type C cables are allowed according
to the USB spec, with lower possible currents.

I'm not sure what the 'right' thing is to report in this situation
(also cable orientation makes no sense).
Just want to mention that I see something different here.
  * RavPower 90W
  * UGREEN 100W
  * Anker 45W
  * RavPower PB

Changes since PATCHv4:
  * Rebase to latest master (v2024.10-rc4)
  * Fix regression introduced in PATCHv3: The exit code for fusb302_set_vconn()
    when vconn stays the same should be 0 instead of undefined
  * Fix regression introduced in PATCHv3: tcpm_set_polarity() needs to update
    port->polarity when there is no driver specific set_polarity function
I can confirm that these fixes indeed fix my reported regression from v2.
Booting to Linux works perfectly fine when powering from simple USB-PD
supplies (12V, 20V), as well as with power from my notebook computer.

So for the v5 series:
Tested-by: Soeren Moch <sm...@web.de>

I also tested powering from a UGREEN USB-C dock (see boot log below).
This also worked well. Only the data role was not switched correctly
to host as required for the dock. At least we got this 'not supported'
message probably related to that. Maybe that can be fixed later in
follow-up patches.

Thanks again for this great and very helpful rock-5b USB-PD support,
Soeren


Boot Logs:

============ dumb power supply w/o USB-PD ================

U-Boot 2024.07-00006-g8b9f4ed46f (Sep 03 2024 - 22:11:56 +0200)

Model: Radxa ROCK 5 Model B
DRAM:  8 GiB
fusb302 usb-typec@22: TCPM: PD transmit data failed: -110
Core:  355 devices, 33 uclasses, devicetree: separate
MMC:   mmc@fe2c0000: 1, mmc@fe2d0000: 2, mmc@fe2e0000: 0
Loading Environment from nowhere... OK
In:    serial@feb50000
Out:   serial@feb50000
Err:   serial@feb50000
Model: Radxa ROCK 5 Model B
Net:   No ethernet found.
Hit any key to stop autoboot:  0
=> tcpm list
| Name                            | Parent name         | Parent uclass
@ seq
| usb-typec@22                    | i2c@feac0000        | i2c @ 4 |
status: 0
=> tcpm dev usb-typec@22
dev: 0 @ usb-typec@22
=> tcpm info
Orientation: normal
PD Revision: rev3
Power Role:  sink
Data Role:   device
Voltage:      5.000 V
Current:      1.500 A
=>

============ dock + 20V USB-PD supply ====================

U-Boot 2024.07-00006-g8b9f4ed46f (Sep 03 2024 - 22:11:56 +0200)

Model: Radxa ROCK 5 Model B
DRAM:  8 GiB
fusb302 usb-typec@22: TCPM: Currently not supported type 0xb
Core:  355 devices, 33 uclasses, devicetree: separate
MMC:   mmc@fe2c0000: 1, mmc@fe2d0000: 2, mmc@fe2e0000: 0
Loading Environment from nowhere... OK
In:    serial@feb50000
Out:   serial@feb50000
Err:   serial@feb50000
Model: Radxa ROCK 5 Model B
Net:   No ethernet found.
Hit any key to stop autoboot:  0
=> tcpm list
| Name                            | Parent name         | Parent uclass
@ seq
| usb-typec@22                    | i2c@feac0000        | i2c @ 4 |
status: 0
=> tcpm dev usb-typec@22
dev: 0 @ usb-typec@22
=> tcpm info
Orientation: reverse
PD Revision: rev3
Power Role:  sink
Data Role:   device
Voltage:     20.000 V
Current:      2.750 A
=>

============================================================

Reply via email to