Skip to content

rockchip64-6.18: rebase rk3399 dwc3 phy-reset-quirk patch for 6.18.32#9847

Merged
SuperKali merged 1 commit into
armbian:mainfrom
OpenSource-YYT:fix-rockchip64-6.18-rk3399-dwc3-patch-rebase
May 17, 2026
Merged

rockchip64-6.18: rebase rk3399 dwc3 phy-reset-quirk patch for 6.18.32#9847
SuperKali merged 1 commit into
armbian:mainfrom
OpenSource-YYT:fix-rockchip64-6.18-rk3399-dwc3-patch-rebase

Conversation

@SuperKali
Copy link
Copy Markdown
Member

@SuperKali SuperKali commented May 17, 2026

Description

The rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch in patch/kernel/archive/rockchip64-6.18/ was last rewritten against 6.18.18 (commit 2dc5b23). Mainline 6.18 stable progressed past that point and refactored dwc3_readl() / dwc3_writel() to take the struct dwc3 * directly instead of dwc->regs. The patch context still references the old form, so hunks 1 (drivers/usb/dwc3/core.c line 153) and 3 (line 213) fail to match when building against 6.18.32.

This commit updates only the patch context (no change to the + / - payload) so the same logic applies cleanly on 6.18.32 while remaining compatible with the prior baseline.

The copies of the same patch in rockchip64-7.0 (rebased by Paolo Sabatino on 2026-03-08, commit 37142830b) and rockchip64-7.1 (copy from 7.0 on 2026-04-28, 9d967eccf) already use the new dwc3_writel(dwc, ...) form and do not need a similar update.

How Has This Been Tested?

Before, on a build pulling 6.18.32 sources (./compile.sh BOARD=youyeetoo-r1-v3 BRANCH=current):

patching file "drivers/usb/dwc3/core.c"
Hunk #1 FAILED at 153.
Hunk #3 FAILED at 213.
2 out of 10 hunks FAILED -- saving rejects to file "/tmp/tmpnd4dvnbx"

After rebase, the patch applies cleanly on kernel 6.18.32, all 16 hunks across the 3 files (core.c, core.h, drd.c), no offset, no rejects.

  • dry-run against 6.18.32

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced USB3 PHY power management for RK3399 TypeC devices during USB mode transitions
    • Improved USB controller behavior during role changes and power state transitions

Review Change Stack

Kernel 6.18 stable progressed past 6.18.18 (last patch rewrite baseline,
commit 2dc5b23) and refactored dwc3_readl()/dwc3_writel() to take the
struct dwc3 pointer directly instead of dwc->regs. The patch context
still referenced dwc->regs, causing hunks #1 (at core.c:153) and armbian#3
(at core.c:213) to fail on builds against 6.18.32.

Update the patch context to drop "->regs" (no change to the +/- payload)
so it applies cleanly on 6.18.32 while remaining compatible with the
prior baseline.

Verified with patch -p1 --dry-run against the 6.18.32 HEAD blob from the
linux-rockchip 6.18 branch: exit 0, all 16 hunks across the 3 files
apply (offset -2 on core.h, harmless).

Signed-off-by: SuperKali <hello@superkali.me>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

This patch enhances the DWC3 USB controller driver to support RK3399 TypeC PHYs that require USB3 PHY power-cycling during role transitions. It adds a device-tree-configurable quirk, introduces a disconnected pseudo-role state, and integrates selective PHY power management into the mode-setting, suspend/resume, and DRD event handling paths.

Changes

DWC3 USB3 PHY Reset Quirk

Layer / File(s) Summary
Data structure, macro, and property parsing
patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch
Adds DWC3_GCTL_PRTCAP_DEVICE_DISCONNECTED macro and usb3_phy_reset_quirk bit field to struct dwc3, and parses the device property snps,usb3-phy-reset-quirk during initialization.
Core mode-setting with PHY reset logic
patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch
Masks PRTCAPDIR bits in dwc3_set_prtcap(), treats disconnected as a first-class role in __dwc3_set_mode(), and power-cycles USB3 PHYs (off before CoreSoftReset, on after) when the quirk is enabled.
Suspend/resume and runtime role handling
patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch
Extends suspend/resume logic to recognize the disconnected state, and updates resume to restore the stored current_dr_role instead of forcing device mode.
DRD role update and extcon event handling
patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch
Refactors dwc3_drd_update() to compute role from EXTCON_USB_HOST, conditionally checks EXTCON_USB for disconnected state when quirk is enabled, and changes notifier registration to use extcon_register_notifier_all().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

Ready to merge, size/medium

Suggested reviewers

  • paolosabatino
  • brentr
  • krachlatte
  • joekhoobyar
  • prahal
  • rpardini
  • pyavitz

Poem

🐰 A quirk most wise for TypeC gates,
Where PHYs reset at mode-change states,
The RK's dance now smooth and bright,
Power cycles make disconnects right,
USB3 hops through each new sight! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: rebasing a patch for kernel 6.18.32 to fix compatibility with updated dwc3 refactoring, which is the core issue addressed in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size/small PR with less then 50 lines 05 Milestone: Second quarter release Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... labels May 17, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch (1)

187-218: 💤 Low value

Pre-existing logic concern in non-quirk path (not introduced by this PR).

The dwc3_drd_update() logic has a potential issue: when usb3_phy_reset_quirk is disabled (the else branch at lines 213-215), the mode is unconditionally set to DEVICE, which would overwrite a previously set HOST mode from the EXTCON_USB_HOST check. This means without the quirk, host mode can never be selected.

The quirk-enabled path works correctly because the EXTCON_USB conditional preserves the HOST mode when EXTCON_USB is not asserted.

Since this PR explicitly states it changes only context lines for 6.18 compatibility and not patch logic, this is noted for awareness only.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch`
around lines 187 - 218, In dwc3_drd_update() the else branch for when
usb3_phy_reset_quirk is false currently unconditionally sets mode =
DWC3_GCTL_PRTCAP_DEVICE and thus overwrites a previously-detected HOST mode;
change that branch to only set DEVICE when extcon shows no HOST (i.e., respect
the result of extcon_get_state(dwc->edev, EXTCON_USB_HOST) / the local variable
ret so HOST is preserved), then call dwc3_set_mode(dwc, mode); update logic
around usb3_phy_reset_quirk, extcon_get_state, EXTCON_USB_HOST/EXTCON_USB and
the mode variable in dwc3_drd_update() so the HOST path is not clobbered by the
non-quirk path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch`:
- Around line 187-218: In dwc3_drd_update() the else branch for when
usb3_phy_reset_quirk is false currently unconditionally sets mode =
DWC3_GCTL_PRTCAP_DEVICE and thus overwrites a previously-detected HOST mode;
change that branch to only set DEVICE when extcon shows no HOST (i.e., respect
the result of extcon_get_state(dwc->edev, EXTCON_USB_HOST) / the local variable
ret so HOST is preserved), then call dwc3_set_mode(dwc, mode); update logic
around usb3_phy_reset_quirk, extcon_get_state, EXTCON_USB_HOST/EXTCON_USB and
the mode variable in dwc3_drd_update() so the HOST path is not clobbered by the
non-quirk path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 86d09085-ec11-4e1f-8978-39bcb583ea9a

📥 Commits

Reviewing files that changed from the base of the PR and between e747fa4 and 82e65df.

📒 Files selected for processing (1)
  • patch/kernel/archive/rockchip64-6.18/rk3399-usbc-phy-rockchip-naneng-Add-fallback-for-old-DTs.patch

Copy link
Copy Markdown
Contributor

@Shadowrom2020 Shadowrom2020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, fixes compilation of other rockchip64 boards

@github-actions github-actions Bot added the Ready to merge Reviewed, tested and ready for merge label May 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions Bot removed the Needs review Seeking for review label May 17, 2026
@SuperKali SuperKali merged commit adbc46c into armbian:main May 17, 2026
15 checks passed
@SuperKali SuperKali deleted the fix-rockchip64-6.18-rk3399-dwc3-patch-rebase branch May 17, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second 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/small PR with less then 50 lines

Development

Successfully merging this pull request may close these issues.

3 participants