Skip to content

rockchip64-6.15: Fix DP alt mode on some rk3399 boards #8271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2025

Conversation

hyx0329
Copy link
Contributor

@hyx0329 hyx0329 commented Jun 4, 2025

Description

Fix Type-C DP altmode on some rk3399 boards. Currently only on rockchip64-6.15.

The old implementation is tricky, and only works in normal orientation. If the plug is flipped, there will be only USB2.0 connectivity.

With the proposed changes, the type-c ports on related rk3399 boards should work in both orientations. A few patches from Megous are picked(some of them already present in sunxi64 kernel patches). The tricky part is how to notify rk3399 cdn-dp driver about DP HPD(hot plug detection), and a workaround is written.

A caveat is that the c port has to be OTG mode, otherwise it will behave very similar to the old implementation if DP is enabled.

I'm not sure if orange pi 4 / 4 LTS support this, so there's no change to their dts yet.

Apart from the work above, the missing fan node is added to tinkerboard 2's dts.

list of changes

  • fix type-c dp altmode
    • Megous' glue driver and related improvements are imported
      • this involves enabling the driver in defconfig CONFIG_TYPEC_EXTCON=m
    • a workaround for notifying DP HPD to cdn-dp is written(not merged anywhere)
    • related device tree files/patches are updated accordingly(what about orangepi 4?)
  • add missing fan node in tinkerboard 2's dts along with some minor tweaks

How Has This Been Tested?

  • build tinkerboard-2 with edge kernel
  • test on tinkerboard 2s with a hub
    • hub alone works in both orientations
    • hub with display connected works in both orientations
    • when hub is connected, display hot plug/unplug works
    • USB 3.0 type-c drive works in both orientations
  • test with a DP-only dongle
  • test on pinebook pro
  • test on nanopc-t4
  • maybe test on orangepi 4 (need dts change)
  • maybe test on orangepi 4 LTS (need dts change)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Walkthrough

The linux-rockchip64-edge kernel configuration was modified to add the CONFIG_TYPEC_EXTCON=m option, enabling Type-C external connector (extcon) support as a loadable module. No other configuration changes were made.

Suggested labels

Ready to merge, 05

Suggested reviewers

  • paolosabatino
  • igorpecovnik

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff47cda and c8725a3.

⛔ Files ignored due to path filters (16)
  • patch/kernel/archive/rockchip64-6.16/board-nanopc-t4-add-typec-dp.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/board-pbp-add-dp-alt-mode.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/dt/rk3399-orangepi-4-lts.dts is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/dt/rk3399-orangepi-4.dts is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/dt/rk3399-tinker-2.dts is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-Revert-usb-typec-tcpm-unregister-existing-source-cap.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-notify-typec-dp-hpd-state-through-extcon.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-phy-phy-rockchip-inno-usb2-Decrease-delay-between-po.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-phy-rockchip-inno-usb2-More-robust-charger-detection.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-usb-dwc3-Extend-reset-quirk-support-to-include-role-.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-usb-dwc3-Track-the-power-state-of-usb3_generic_phy.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-usb-typec-altmodes-displayport-Respect-DP_CAP_RECEPT.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-usb-typec-tcpm-Fix-PD-devices-capabilities-registrat.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-usb-typec-tcpm-Unregister-altmodes-before-registerin.patch is excluded by !patch/**
  • patch/kernel/archive/rockchip64-6.16/rk3399-usbc-usb-typec-typec-extcon-Add-typec-extcon-bridge-drive.patch is excluded by !patch/**
📒 Files selected for processing (1)
  • config/kernel/linux-rockchip64-edge.config (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/kernel/linux-rockchip64-edge.config
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added size/large PR with 250 lines or more Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... 08 Milestone: Third quarter release labels Jun 4, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Jun 4, 2025
@EvilOlaf EvilOlaf removed the Ready to merge Reviewed, tested and ready for merge label Jun 4, 2025
@paolosabatino
Copy link
Contributor

Looks interesting; perhaps I can find some time during this weekend to give a check on Opi4 LTS. I'm only dubious about what the ~20 new patches for rk3399 do, but anyway...

@hyx0329 hyx0329 requested a review from pyavitz as a code owner June 18, 2025 05:25
@github-actions github-actions bot removed the Ready to merge Reviewed, tested and ready for merge label Jun 18, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Jun 18, 2025
@hyx0329
Copy link
Contributor Author

hyx0329 commented Jun 18, 2025

I think this will be a "partial" fix.

With a few more tests with different devices & configurations, 2 major flaws are found:

  • Powered USB hub may not be recognized.
  • Other dual-role USB devices(phone, tablet) may not be recognized.

I couldn't find the root cause of them. Loading a gadget driver only works around the first flaw.

If the behavior change and the workaround are acceptable, I think it's okay to merge.

I'll look into it if the workaround should be included by default for each affected boards.

Behavior change and comparison

Only on RK3399

Function Old implementation New implementation
USB 2.0 fully functional1 fully functional when downstream device has no power supply2, plus OTG
USB 3.0 only one orientation fully functional when downstream device has no power supply2, plus OTG3
DisplayPort only one orientation, only 2 lanes fully functional4
Power Delivery(Charging) working5 working5
  1. Host mode only.
  2. When connecting to a powered hub, loading a gadget driver, or manually toggling the mode through debugfs, can workaound the detection issue.
  3. It seems not working when the cable is a dumb C2C one without e-marker chip.
  4. Only tested with a hub supporting 2 lane DP, and it's always working, independent of the USB status.
  5. It looks working. The related boards are either not supporting power input, or only using a 5V input. The debugfs log shows the PD negotiation works.

The old behavior can still be preserved with some tweaks to the device tree, if it's desired.

Affected boards

As far as I know, only boards mentioned in this pr are affected. Other RK3399 boards are not affected because their type-c ports are either fully functional or not working at all, if they exist. Other non-RK3399 boards should be not affected.

To be affected, RK3399 boards will have to leave dr_mode unchanged(upstream default is "otg") and create+bind the node for the new extcon bridge in their dts.

@paolosabatino
Copy link
Contributor

Thanks @hyx0329 for the summary overview table, I have a couple of questions though.

This sentence confuses me a bit:

As far as I know, only boards mentioned in this pr are affected. Other RK3399 boards are not affected because their type-c ports are either fully functional or not working at all, if they exist. Other non-RK3399 boards should be not affected.

I thought the "old implementation" in the mainline kernel - regarding the RK3399 SoC in general - is limited and/or partially broken; First of all, the patches in this PR either fix and expand the functionalities for the RK3399 SoC, then the corrections to the device trees declare the hardware in the right way to make those functionalities available to the kernel.

About the sentence:

fully functional when downstream device has no power supply, plus OTG

do you mean that if the USB device has some kind of power supply of its own won't work anymore?

Thanks for any answer, this whole PR is definitely intersting but the risk of breakage and the patches it carries along (that will require maintenance by armbian maintainers, in the future) are my main concerns, so I would like to understand as much as I can.

@hyx0329
Copy link
Contributor Author

hyx0329 commented Jun 18, 2025

Hi @paolosabatino

This sentence confuses me a bit:

As far as I know, only boards mentioned in this pr are affected. Other RK3399 boards are not affected because their type-c ports are either fully functional or not working at all, if they exist. Other non-RK3399 boards should be not affected.

I thought the "old implementation" in the mainline kernel - regarding the RK3399 SoC in general - is limited and/or partially broken; First of all, the patches in this PR either fix and expand the functionalities for the RK3399 SoC, then the corrections to the device trees declare the hardware in the right way to make those functionalities available to the kernel.

The "old implementation" contains 2 parts: existing drivers in mainline kernel, and the patch board-pbp-add-dp-alt-mode.patch(before changed by this pr). Mainline kernel has most necessary drivers already, including:

  • cdn-dp, core for DP output
  • rk3399 type-c phy, some kind of mux
  • dwc3, usb controller
  • fusb302 chip, usb-c controller

But upstream misses the extcon bridge(shared state) connecting all those components. The patch board-pbp-add-dp-alt-mode.patch contains a tricky(broken) implementation possibly from 4.19 BSP kernel. Somehow it makes type-c DP and USB 3.0 work, at least in normal orientation.

The main reason that I created this PR is to make type-c work in both orientations, which should make it more comfortable to use.

The patches in this PR mainly bring these things:

  • (new) an extcon bridge driver
    • provides the necessary shared state
    • rk3399-usbc-usb-typec-typec-extcon-Add-typec-extcon-bridge-drive.patch
    • rk3399-usbc-usb-typec-typec-extcon-Allow-to-force-reset-on-each-.patch
  • (fix) add reset quirk for dwc3 driver to reset type-c phy(mux) on rk3399
    • rk3399 needs this to switch type-c orientation & allocate DP lanes on demand
    • rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch
    • rk3399-usbc-usb-dwc3-Extend-reset-quirk-support-to-include-role-.patch
  • (workaround) send DP HPD state through extcon in dp altmode driver
    • this is to notify cdn-dp driver about the actual connection state of DP, not type-c
    • I use the term workaround because it's definitely not a "proper" implementation.
    • rk3399-usbc-notify-typec-dp-hpd-state-through-extcon.patch

As you can see, there are still a few less relevant patches. Some are prerequisites, and others are minor improvements.

And yes the device trees are then updated to make those functionalities available. The functions have to be explictly specified per capable board.

Because dwc3 is a common driver, it can affect a wide range of boards if things go wrong.

About the sentence:

fully functional when downstream device has no power supply, plus OTG

do you mean that if the USB device has some kind of power supply of its own won't work anymore?

I think I made a mistake. Now I would say smarter devices which can negotiate data role or power role through USB-C may encounter issues.

What I observed:

  • The USB part of a powered hub is not detected, although DisplayPort works.
  • Some OTG gadgets(tablet) are not detected.

I thought the reason was power, but the fact seems to be their ability to negotiate data role and power role. I just tested a simple battery powered RP2040 gadget.

Thanks for any answer, this whole PR is definitely intersting but the risk of breakage and the patches it carries along (that will require maintenance by armbian maintainers, in the future) are my main concerns, so I would like to understand as much as I can.

Understood. That is being responsible :)

@paolosabatino
Copy link
Contributor

paolosabatino commented Jun 22, 2025

My tests on my Orange PI 4 LTS. Test hardware is:

  • Orange pi 4 LTS
  • Unnamed USB3 Type-C Hub with PD, HDMI and USB3 port
  • USB3 SD card reader
  • USB2 rtl8188eu wireless dongle

Patched kernel

Using a powered USB Hub to power the board:

  • with dr_mode="otg", Hub HDMI works, simple USB devices connected to Hub work in both orientations (!!)
  • with dr_mode="host", Hub HDMI does not work in any orientation, simple USB devices connected to Hub don't get detected in any orientation

Using the Hub without power:

  • with dr_mode="otg", HDMI and USB3 devices do not work
  • with dr_mode="host", HDMI and USB3 devices do not work

Direct connection of a USB device to type-c port:

  • with dr_mode="otg", no detection
  • with dr_mode="host", the device is detected only with one orientation

Kernel without patches

Using a powered USB Hub to power the board:

  • with dr_mode="otg", Hub HDMI does not work, simple USB devices connected to Hub do not work with any orientation
  • with dr_mode="host", Hub HDMI work with only one orientation, simple USB devices connected to Hub work when orientation is the same

Direct connection of a USB device to type-c port:

  • with dr_mode="otg", no detection
  • with dr_mode="host", the device is detected only with one orientation

@hyx0329 I don't know if these tests report the same behaviour you experienced, it looks a bit odd to me that the case "Patched kernel + Hub without power" the Type-C port is practically non-working and "Patched kernel + Power Hub" makes both HDMI and USB devices work too.

Also the patches change the way the type-c port work when there is a powered Hub connected to the port; if a non-OTG device is directly connected to the port, it behaves substantially the same as before.

I see a possible regression for people who use the Type-C port with a Hub to power the device and connects one or more USB devices to the Hub; in such case, if dr_mode="host" is set in the dtb, the Hub won't work anymore.

At the moment, the usb@fe800000 contoller has a mixed dr_mode bit in device tree:

paolo@armbian-build:~/armbian-build/cache/sources/linux-kernel-worktree/6.15__rockchip64__arm64/arch/arm64/boot/dts/rockchip$ grep -A4 '0xfe800000' *.deco | grep 'dr_mode'
rk3399-am40.dtb.deco-                   dr_mode = "host";
rk3399-eaidk-610.dtb.deco-                      dr_mode = "otg";
rk3399-evb.dtb.deco-                    dr_mode = "otg";
rk3399-ficus.dtb.deco-                  dr_mode = "host";
rk3399-fine3399.dtb.deco-                       dr_mode = "host";
rk3399-firefly.dtb.deco-                        dr_mode = "otg";
rk3399-gru-bob.dtb.deco-                        dr_mode = "host";
rk3399-gru-kevin.dtb.deco-                      dr_mode = "host";
rk3399-gru-scarlet-dumo.dtb.deco-                       dr_mode = "host";
rk3399-gru-scarlet-inx.dtb.deco-                        dr_mode = "host";
rk3399-gru-scarlet-kd.dtb.deco-                 dr_mode = "host";
rk3399-hugsun-x99.dtb.deco-                     dr_mode = "host";
rk3399-khadas-edge-captain.dtb.deco-                    dr_mode = "otg";
rk3399-khadas-edge-v.dtb.deco-                  dr_mode = "otg";
rk3399-khadas-edge.dtb.deco-                    dr_mode = "otg";
rk3399-kobol-helios64.dtb.deco-                 dr_mode = "otg";
rk3399-leez-p710.dtb.deco-                      dr_mode = "otg";
rk3399-nanopc-t4.dtb.deco-                      dr_mode = "otg";
rk3399-nanopi-m4.dtb.deco-                      dr_mode = "otg";
rk3399-nanopi-m4b.dtb.deco-                     dr_mode = "otg";
rk3399-nanopi-m4v2.dtb.deco-                    dr_mode = "otg";
rk3399-nanopi-neo4.dtb.deco-                    dr_mode = "otg";
rk3399-nanopi-r4s-enterprise.dtb.deco-                  dr_mode = "host";
rk3399-nanopi-r4s.dtb.deco-                     dr_mode = "host";
rk3399-nanopi-r4se.dtb.deco-                    dr_mode = "host";
rk3399-orangepi-4-lts.dtb.deco-                 dr_mode = "otg";
rk3399-orangepi-4.dtb.deco-                     dr_mode = "otg";
rk3399-orangepi.dtb.deco-                       dr_mode = "host";
rk3399-pinebook-pro.dtb.deco-                   dr_mode = "host";
rk3399-pinephone-pro.dtb.deco-                  dr_mode = "otg";
rk3399-puma-haikou.dtb.deco-                    dr_mode = "otg";
rk3399-roc-pc-mezzanine.dtb.deco-                       dr_mode = "otg";
rk3399-roc-pc-plus.dtb.deco-                    dr_mode = "host";
rk3399-roc-pc.dtb.deco-                 dr_mode = "otg";
rk3399-rock-4c-plus.dtb.deco-                   dr_mode = "host";
rk3399-rock-4se.dtb.deco-                       dr_mode = "host";
rk3399-rock-pi-4.dtb.deco-                      dr_mode = "host";
rk3399-rock-pi-4a-plus.dtb.deco-                        dr_mode = "host";
rk3399-rock-pi-4a.dtb.deco-                     dr_mode = "host";
rk3399-rock-pi-4b-plus.dtb.deco-                        dr_mode = "host";
rk3399-rock-pi-4b.dtb.deco-                     dr_mode = "host";
rk3399-rock-pi-4c.dtb.deco-                     dr_mode = "host";
rk3399-rock960.dtb.deco-                        dr_mode = "otg";
rk3399-rockpro64-v2.dtb.deco-                   dr_mode = "host";
rk3399-rockpro64.dtb.deco-                      dr_mode = "host";
rk3399-sapphire-excavator.dtb.deco-                     dr_mode = "host";
rk3399-sapphire.dtb.deco-                       dr_mode = "host";
rk3399-tinker-2.dtb.deco-                       dr_mode = "host";
rk3399-xiaobao-nas.dtb.deco-                    dr_mode = "host";
rk3399pro-rock-pi-n10.dtb.deco-                 dr_mode = "otg";

@hyx0329
Copy link
Contributor Author

hyx0329 commented Jun 23, 2025

Things become quite complicated. I'm not confident with the changes now.

Anyway, here's my report. Devices:

  • Tinkerboard 2S
  • Unnamed USB3 Type-C Hub with PD, HDMI and USB3 port
  • SanDisk USB 3.0 drive
  • Yubikey 5C
  • RP2040 board, it has pull resistors on CC pins, and have USB_DP/DN wired in both directions
  • A USB2.0 C2C cable

Kernel without patches

All results of kernel w/o patches are expected, except that I thought USB 2.0 should always work when dr_mode is set to "host". I haven't done a fresh test yet.

Kernel with patches

If something like cannot enter mode(-1) is printed in dmesg, the internal DP state is probably messed up, and the board need a cold boot to recover.

In the process, I met once that the port became unresponsive after multiple plugs and unplugs.

dr_mode = "otg"

Test Mine(Tinkerboard 2S, RK3399 OP1) Paolo's(Orange Pi 4 LTS, RK3399)
Using a powered USB Hub to power the board 🚧 HDMI works, USB need workaround1, both orientations. 2 ✅ USB and HDMI work, both orientations3
Using the Hub without power ✅ USB and HDMI work, both orientations ❌ USB and HDMI do not work.
Direct connection of a (simple) USB device to type-c port ✅ Works, U2 and U3, both orientations ❌ No detection.
  1. Workaround: load a gadget driver, or manually toggle the role(mode) through debugfs
  2. The board is actually powered by DC, not type-c.
  3. I do remember that a previous quick test done by @paolosabatino showing HDMI on the powered hub worked with Orange Pi 4, but the USB was not. So I'm sceptical about this result. I have no idea what happened.

dr_mode = "host"

It's not expected to work properly though.

Test Mine(TinkerBoard 2S, RK3399 OP1) Paolo's(Orange Pi 4 LTS, RK3399)
Using a powered USB Hub to power the board HDMI and U3 work only with normal orientation, U2 works with both1 HDMI and USB work with only one same orientation
Direct connection of a (simple) USB device to type-c port U3 only works with one orientation2, U2-only device works with both1 the device is detected only with one orientation
  1. Might be an illusion as USB2.0 type-c devices often have those wires mirrored.
  2. USB3 devices won't be detected by USB2 with any orientation.

During testing, I found that if the a simple device is connected after a first connection to a hub, it may not be detected at all, while the hub will still work. It seems not affecting those USB2-only devices like yubikeys, and devices connected through a USB 2.0 cable. It is possibly related to the internal state of the driver/phy hardware. Maybe I didn't fully understand the old behavior.

About mixed dr_mode

usb@fe800000(usbdrd3_0) and usb@fe900000(usbdrd3_1) use the same driver, and they provide USB 3.0 connectivity. As far as I know, most rk3399 boards configure the second one as a normal USB3 port, and some of them further introduce a regular external hub.

For those with type-c ports, usb@fe800000 is used.

From my understanding, a full-featured type-c port on a rk3399 board consists a USB 2.0 OTG peripheral and a set of USB 3.0 / DP multi-function peripherals:

Type-C port
    |_fusb302(Type-C controller, fusb302.c)
    |_USB 2.0 OTG peripheral
    |_tcphy (mux-like, phy-rockchip-typec.c)
        |_dwc3 (USB3.0, dwc3/core.c)
        |_cdn dp (DisplayPort, cdn-dp-core.c)

Because of the hardware design, if we need DP output through type-c port, we need to reconfigure the type-c phy(&tcphy0, a mux-like peripheral) on demand. This is how it works in BSP 4.4 kernel.

Because of the driver design and possibly other reasons I don't understand, the child USB3 phy of tcphy is consumed by dwc3 driver, therefore the reset of the phy should be performed by dwc3 driver to maintain consistent state.

Currently I'm not sure whether it's feasible to reconfigure the tcphy outside dwc3 driver.

If no extcon/usb-role-switch is defined for usb@fe800000 or usb@fe900000, they should not be affected. In this case, those ports should have dr_mode set to either "host" or "device", as they don't have the ability to check which mode to use.

@paolosabatino
Copy link
Contributor

paolosabatino commented Jun 24, 2025

I made another round of tests, this time I guess I was more rigorous and systematic than in the first round.

Hardware:

  • OrangePi4 LTS
  • Unnamed USB3 Type-C Hub (same as above)
  • Unnamed USB3 sdcard reader (same as above)
  • Old Kingston 1Gb USB2 stick

In the table Unpatched is kernel 6.16-rc3 and Patched is kernel 6.15.3 + USB patches.

Direct connection

Kernel dr_mode HDMI USB2 USB3
Unpatched otg N/A Not working Not working
Unpatched host N/A Works in one orientation Works in one orientation
Patched otg N/A Not working Not working
Patched host N/A Works in both orientations Works in one orientation

Connection via Unpowered Hub

Kernel dr_mode HDMI USB2 USB3
Unpatched otg Not working Not working Not working
Unpatched host Not working Works in one orientation Works in one orientation
Patched otg Not working Not working Not working
Patched host Not working Works in both orientations Works in one orientation

Connection via Powered Hub (powering the board via PD)

Kernel dr_mode HDMI USB2 USB3
Unpatched otg Works in one orientation Not working Not working
Unpatched host Works in one orientation Works in both orientations Works in one orientation
Patched otg Works in both orientations Works in one orientation Works in one orientation
Patched host Works in one orientation Works in both orientations Works in one orientation

This looks more reasonable to me than the previous test and, most important, there seems to be no regressions and in some cases some gains.

I guess my USB3 Type-C hub has some role in this (especially the unpowered case), but the direct connection also has its own issues. Direct connection also passes through an adapter which I don't know it is really suitable to handle OTG to Host mode (but I hope so, those things are usually made to attach USB sticks to phones...)

@paolosabatino
Copy link
Contributor

After a quick comparison on the device trees, it looks to me that the opi4lts device tree misses these lines: https://github.com/armbian/build/pull/8271/files#diff-b72b6fb9641cade670e223a16c0ecdd89dad4a06d460762c20e9a3bdad6248c4L451-L454

I'm pretty sure the very first tests I did, I included those changes in my device tree; in the latest test instead I used the device tree coming from this PR. Perhaps this can explain the differences?

I will fix the device tree and give a chance to another round of checks.

@paolosabatino paolosabatino removed the Ready to merge Reviewed, tested and ready for merge label Jun 25, 2025
@hyx0329
Copy link
Contributor Author

hyx0329 commented Jun 26, 2025

I'm pretty sure the very first tests I did, I included those changes in my device tree; in the latest test instead I used the device tree coming from this PR. Perhaps this can explain the differences?

Actually I did suspect those changes were the cause, but my tests didn't support it.

@paolosabatino
Copy link
Contributor

Actually I did suspect those changes were the cause, but my tests didn't support it.

Tried again with fixed DT, nothing changed. Now the thing becomes really puzzling 🤔

@paolosabatino
Copy link
Contributor

I could have a check with direct Type-C to HDMI cable and the display still does not get detected in orientation.

The only way I could get any display output with dr_mode="otg" and patches applied is via powered USB Type-C Hub. I double checked the device tree and things looks in the right place, but it still does not work.

I guess at this point the board is not really capable, could it be?

@hyx0329
Copy link
Contributor Author

hyx0329 commented Jun 28, 2025

I guess at this point the board is not really capable, could it be?

I'm not sure. The schematic shows the board should have all required bits. And since it's possible to have DP and USB3 work in some conditions, there should be a way to make it work.

When I have this line, the type-c port no longer works. Normally type-c port are not powered until negotiated(via CC pins pulls and PD messages). Maybe you want to check that.

@paolosabatino
Copy link
Contributor

When I have this line, the type-c port no longer works. Normally type-c port are not powered until negotiated(via CC pins pulls and PD messages). Maybe you want to check that.

This could indeed be important and I didn't notice that while I was reviewing the device tree. I will remove the property and check again soon, thanks!

@paolosabatino
Copy link
Contributor

paolosabatino commented Jun 28, 2025

@hyx0329 that's, the regulator-always-on property was the culprit! I quickly retested with dr_mode="otg":

  • direct connection for USB2 and USB3 devices work with both orientations (could not test DP/HDMI because I have not the cable with me right now)
  • Unpowered Type-C Hub with USB2, USB3 and HDMI attached all work with both orientations

Some other nice things are that the Type-C Hub hotplugging and Hub HDMI hot-plugging work very well!

I noticed the same issue as yours when I use PD via Type-C Hub: USB device does not get recognized, altough I have to admit that this problem also happens on my daily job laptop... also, looking at my previous tests were USB devices were working with PD over Type-C and regulator-always-on property set, I may guess that now, without regulator-always-on property, the vbus-typec regulator does not turn on when USB is attached to Type-C Hub. May be a Hub issue or some other software condition, but indeed this is a hint for further investigations.

This is the regulator summary with PD, HDMI and USB device plugged (but not detected) in the Type-C Hub:

root@orangepi4-lts:/sys/kernel/debug/regulator# cat regulator_summary 
 regulator                      use open bypass  opmode voltage current     min     max
---------------------------------------------------------------------------------------
 regulator-dummy                  4    3      0 unknown     0mV     0mA     0mV     0mV 
    ff940000.hdmi-avdd-1v8        1                                 0mA     0mV     0mV
    ff940000.hdmi-avdd-0v9        1                                 0mA     0mV     0mV
    vdd_log                       1    0      0 unknown  1400mV     0mA   800mV  1400mV 
 vcc_sys                          3    2      0 unknown     0mV     0mA     0mV     0mV 
    vcc3v3_sys                   18   17      0 unknown  3300mV     0mA  3300mV  3300mV 
       vdd_center                 1    0      0 unknown   900mV     0mA   750mV  1350mV 
       vdd_cpu_l                  2    1      0 unknown   825mV     0mA   750mV  1350mV 
          cpu0-cpu                1                                 0mA   825mV  1250mV
       vcc_ddr                    1    0      0 unknown  3300mV     0mA     0mV     0mV 
       vcc1v8                     2    1      0 unknown  1800mV     0mA  1800mV  1800mV 
          ff100000.saradc-vref    1                                 0mA     0mV     0mV
       vcc1v8_dvp                 1    1      0 unknown  1800mV     0mA  1800mV  1800mV 
          ff770000.syscon:io-domains-bt656   0                                 0mA     0mV     0mV
       vcc3v0_touch               1    0      0 unknown  3000mV     0mA  3000mV  3000mV 
       vcc1v8_pmu                 1    0      0 unknown  1800mV     0mA  1800mV  1800mV 
       vcc_sdio                   2    2      0 unknown  1800mV     0mA  1800mV  3000mV 
          fe320000.mmc-vqmmc      1                                 0mA  1800mV  1950mV
          ff770000.syscon:io-domains-sdmmc   0                                 0mA     0mV     0mV
       vcca3v0_codec              1    0      0 unknown  3000mV     0mA  3000mV  3000mV 
       vcc_1v5                    1    0      0 unknown  1500mV     0mA  1500mV  1500mV 
       vcca1v8_codec              1    1      0 unknown  1800mV     0mA  1800mV  1800mV 
          ff770000.syscon:io-domains-audio   0                                 0mA     0mV     0mV
       vcc_3v0                    1    2      0 unknown  3000mV     0mA  3000mV  3000mV 
          ff770000.syscon:io-domains-gpio1830   0                                 0mA     0mV     0mV
          ff320000.syscon:io-domains-pmu1830   0                                 0mA     0mV     0mV
       vcc3v3_s3                  2    1      0 unknown  3300mV     0mA     0mV     0mV 
          fe300000.ethernet-phy   1                                 0mA     0mV     0mV
       vcc3v3_s0                  1    0      0 unknown  3300mV     0mA     0mV     0mV 
       vdd_cpu_b                  2    1      0  normal   825mV     0mA   712mV  1500mV 
          cpu4-cpu                1                                 0mA   825mV  1250mV
       vdd_gpu                    2    1      0  normal   875mV     0mA   712mV  1500mV 
          ff9a0000.gpu-mali       1                                 0mA   875mV  1150mV
       vcc3v0_sd                  2    1      0 unknown  3000mV     0mA  3000mV  3000mV 
          fe320000.mmc-vmmc       1                                 0mA  3000mV  3100mV
    vcc5v0_sys                    3    3      0 unknown  5000mV     0mA  5000mV  5000mV 
       vbus-5v                    0    1      0 unknown  5000mV     0mA  5000mV  5000mV 
          4-0022-vbus             0                                 0mA     0mV     0mV
       usb3_vbus                  2    1      0 unknown  5000mV     0mA  5000mV  5000mV 
          phy-ff770000.syscon:usb2phy@e450.11-phy   2                                 0mA     0mV     0mV
       usb_vbus                   2    1      0 unknown  5000mV     0mA  5000mV  5000mV 
          phy-ff770000.syscon:usb2phy@e460.7-phy   2                                 0mA     0mV     0mV
 vcc3v3_pcie                      1    0      0 unknown     0mV     0mA     0mV     0mV 

By the way, everything looks great, the tests with dr_mode="host" do not report any regressions, so if you feel ok I may ask you to - please! 🙏 - rebase upon kernel 6.16 (rockchip64 has been advanced to 6.16-rc3, in the meantime) so we can merge and then the other minor fixes can be investigated later.

Anyway thanks for the great work! 👍 👍 👍

The old method carried along with board-pbp-add-dp-alt-mode.patch only
makes typec work in one(normal) orientation. This patch introduces a
proper extcon driver and makes the workaround cleaner, so orientation
switch is working.

Improvements:
- type-c DP on rk3399 works with both orientations
- type-c USB 3.0 on rk3399 works with both orientations, with minor
  issues, see below

Caveats:
- Powered USB-C hubs may be not recognized, and can be worked around by
  loading a gadget driver, or manually toggling the mode once for each
  connection.
- Some dual-role devices(phone, tablet) may be not recognized.

Affected boards:
- TinkerBoard 2/2S
- Pinebook Pro
- NanoPC T4
- Orange Pi 4
- Orange Pi 4 LTS

Tested on tinkerboard 2s. This patch contains other minor fixes for
tinker2's device tree, including adding a missing fan node, adding color
labels to leds.

The 2 patches adding dp support for nanopc t4 and pinebook pro are also
updated accordingly.

The device trees of Orange Pi 4 / 4 LTS are also updated to match the
new implementation.
@coderabbitai coderabbitai bot added 05 Milestone: Second quarter release Ready to merge Reviewed, tested and ready for merge labels Jun 29, 2025
@github-actions github-actions bot removed the Ready to merge Reviewed, tested and ready for merge label Jul 1, 2025
@igorpecovnik igorpecovnik added Ready to merge Reviewed, tested and ready for merge and removed Needs review Seeking for review labels Jul 2, 2025
@paolosabatino paolosabatino merged commit 6e39531 into armbian:main Jul 2, 2025
12 checks passed
@paolosabatino
Copy link
Contributor

Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05 Milestone: Second quarter release 08 Milestone: Third quarter release Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... Ready to merge Reviewed, tested and ready for merge size/large PR with 250 lines or more
Development

Successfully merging this pull request may close these issues.

4 participants