Add board: Anbernic RG Vita Pro (RK3576 gaming handheld)#10128
Add board: Anbernic RG Vita Pro (RK3576 gaming handheld)#10128crackerjacques wants to merge 5 commits into
Conversation
Three SoC-generic RK3576 display fixes (affect all rk3576 boards, intended for upstream): - vop2 gamma LUT port select is write-masked on rk3576 (unlike rk3588); mainline's plain write is dropped, corrupting colors in any userspace that programs legacy gamma (e.g. Xorg at startup). - vop2 VP2 (the DP video port) has no primary plane, so enabling DP fails the whole VOP2 bind; promote Esmart0 to primary (reduced from ROCKNIX to match mainline's DUAL-pixel DP configuration). - usbdp phy: replay saved HPD state on DP PHY init so DP alt-mode displays connected at boot are detected (based on ROCKNIX). Signed-off-by: crackerjacques <jack@supremeoverlordjabs.co>
Kernel drivers needed by the RG Vita Pro (RK3576), ported from the ROCKNIX project (thanks to the ROCKNIX developers and Chris Morgan; HUSB311 based on a patch by Alexey Charkov, generic-dsi panel by Danil Zagoskin): - drm/panel: rocknix,generic-dsi panel driver (timings/init from DT) - input/joystick: spi-mcu-joypad (analog sticks + RGB LED rings) - mfd/pwm: rockchip mfpwm + PWMv4 (RK3576 backlight PWM) - Input/rmi4: hard-reset via reset GPIO instead of the chip-wide SW reset (the LCD is a TDDI module; the SW reset kills the display half) - power/supply: CW221x fuel gauge + SGM41542 charger - usb/typec: HUSB311 IDs for the register-compatible rt1711h TCPC driver Signed-off-by: crackerjacques <jack@supremeoverlordjabs.co>
Add the board config, device tree and kernel config options for the Anbernic RG Vita Pro, an RK3576 gaming handheld (5.5" 1080x1920 portrait TDDI touch LCD, SPI-MCU gamepad, es8388 + aw87391 audio, RTL8852BE, USB-C USB3/DP-altmode/PD, mini HDMI). - generic-rk3576 mainline U-Boot; the family boot_merger injects the rk3576 SD boost blob (nanopi-r76s pattern) - DDR blob pinned to v1.09 (family default v1.08 does not init this RAM) - SD first in the boot order - kernel config: JOYSTICK_SPI_MCU_JOYPAD, LEDS_CLASS_MULTICOLOR, DRM_PANEL_GENERIC_DSI, MFD_ROCKCHIP_MFPWM, PWM_ROCKCHIP_V4, BATTERY_CW221X, CHARGER_SGM41542 Device tree adapted from ROCKNIX. Signed-off-by: crackerjacques <jack@supremeoverlordjabs.co>
Board bsp package and default ALSA state: - vita-jack-switch: mute internal speakers while headphones are plugged - vita-pad2key + toggle: gamepad-to-keyboard remap for desktop navigation - vita-screen: X11-only rotation + touch mapping (Wayland uses the DRM panel-orientation property natively) - vita-offcharge: Android-style off-charge screen (the RK806 powers on when a charger is plugged, a hardware behavior; a plug-in boot shows a battery screen that powers off on unplug and continues to boot on power press) - SDDM configured for its Wayland greeter; udev rule reclassifying the ABS-only stick device from accelerometer to joystick - default asound.state with speakers and headphone jack enabled Signed-off-by: crackerjacques <jack@supremeoverlordjabs.co>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR adds complete board support for the Anbernic RG Vita Pro (RK3576): board configuration, kernel enablement, userspace power/audio/input/display helpers, an ALSA state blob, new kernel drivers, supporting kernel patches, and the board device tree. ChangesAnbernic RG Vita Pro board bring-up
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant systemd
participant vita-offcharge
participant RK806PMIC as RK806 PMIC
participant tty1 as /dev/tty1
systemd->>vita-offcharge: start before display-manager
vita-offcharge->>RK806PMIC: read ON_SOURCE via I2C
RK806PMIC-->>vita-offcharge: on_source value
alt power-button boot
vita-offcharge-->>systemd: exit 0 (continue normal boot)
else plug-in boot
vita-offcharge->>tty1: draw battery/charging screen
vita-offcharge->>vita-offcharge: monitor POWER key
vita-offcharge-->>systemd: exit 0 on long-press or poweroff on charger removal
end
sequenceDiagram
participant PWMv4 as pwm-rockchip-v4
participant MFPWM as rockchip-mfpwm
PWMv4->>MFPWM: mfpwm_acquire(pwmf)
MFPWM-->>PWMv4: ownership granted or busy
PWMv4->>MFPWM: write enable/period/duty/offset registers
PWMv4->>MFPWM: mfpwm_release(pwmf)
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (2)
config/kernel/linux-rockchip64-edge.config (1)
1151-1151: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffConsider board-scoping the Vita-Pro-only driver options.
These new symbols (
CONFIG_JOYSTICK_SPI_MCU_JOYPAD,CONFIG_BATTERY_CW221X,CONFIG_CHARGER_SGM41542,CONFIG_MFD_ROCKCHIP_MFPWM,CONFIG_DRM_PANEL_GENERIC_DSI,CONFIG_PWM_ROCKCHIP_V4) are specific to the RG Vita Pro but are being enabled in the sharedrockchip64-edgefamily config, so every rockchip64-edge board inherits them. The=yones in particular add unconditional bloat to all those kernels. Consider moving them into a board-scopedcustom_kernel_config__anbernic_rg_vita_pro()in the.cscunless the family intends to share these drivers across boards.Based on learnings: keep kernel config options that are truly board-specific at board scope; only promote to family scope if all boards in that family use the same driver.
Also applies to: 1434-1434, 1455-1455, 1679-1679, 2019-2019, 3081-3081
🤖 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 `@config/kernel/linux-rockchip64-edge.config` at line 1151, Move the Vita-Pro-only kernel symbols out of the shared rockchip64-edge family config and into the board-specific custom_kernel_config__anbernic_rg_vita_pro() in the .csc; CONFIG_JOYSTICK_SPI_MCU_JOYPAD, CONFIG_BATTERY_CW221X, CONFIG_CHARGER_SGM41542, CONFIG_MFD_ROCKCHIP_MFPWM, CONFIG_DRM_PANEL_GENERIC_DSI, and CONFIG_PWM_ROCKCHIP_V4 should not be enabled globally for every rockchip64-edge board. Keep only genuinely shared drivers in the family config and scope the rest to the RG Vita Pro board config.Source: Learnings
patch/kernel/archive/rockchip64-7.1/dt/rk3576-anbernic-rg-vita-pro.dts (1)
286-297: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
pwm2_8ch_7is enabled but has no consumer, and mixes spaces with tabs.Only
pwm1_6ch_3is referenced (bybacklight);pwm2_8ch_7is setstatus = "okay"with no phandle consumer in this DTS. Confirm it's actually needed (e.g. rumble/second backlight) — otherwise it needlessly claims thepwm2m2_ch7pins. The node body also uses 4-space indentation unlike the rest of the file.🤖 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-7.1/dt/rk3576-anbernic-rg-vita-pro.dts` around lines 286 - 297, The pwm2_8ch_7 node is enabled without any consumer in this DTS, so either remove or disable it unless it is intentionally needed for a feature like rumble or another backlight; check the pwm2_8ch_7 definition and only keep status = "okay" if a real phandle consumer exists. Also normalize the indentation in that node to match the rest of the file by using consistent tabs/spaces, especially around the clocks and clock-names properties.
🤖 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.
Inline comments:
In
`@config/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-offcharge`:
- Around line 8-10: The header comment in vita-offcharge still shows the old
PWRON_MASK example, so update the documented default to match the shipped
/etc/default/vita-offcharge value used by vita-offcharge. Make the comment
consistent with the actual power-button mask seen in the config and keep the
guidance aligned with the existing DISABLE setting so future edits don’t copy
the stale value.
- Around line 209-210: The `vita-offcharge` config parsing for `SCREEN_TIMEOUT`
and `BOOT_HOLD` can crash on malformed values because the `float(...)`
conversions are unchecked. Update the parsing logic around these settings to
safely handle invalid input in the script’s config-loading path, using the
existing `conf.get(...)` values but falling back to the defaults when conversion
fails. Keep the fix localized to the config read section so the charge-screen
flow continues even if `/etc/default/vita-offcharge` contains non-numeric
values.
In
`@config/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-pad2key-toggle`:
- Around line 7-11: The vita-pad2key-toggle script has a silent failure path if
systemctl stop/start vita-pad2key fails, leaving msg unset and the user with no
useful output. Update the toggle logic around the systemctl calls so each branch
handles failure explicitly, setting a fallback error message when the command
does not succeed and preserving the existing success messages otherwise. Make
sure the terminal echo/notification path always has a message to display, using
the script’s msg variable and the systemctl-based state switch.
In
`@patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-battery-01-cw221x.patch`:
- Around line 600-612: The battery-profile handling in the cw221x probe path
should return immediately when device_property_count_u8() reports that
"cellwise,battery-profile" is missing, because the current flow still reaches
devm_kzalloc() with a negative length and fails instead of using the
flash-contents fallback. Update the logic around the cw_bat->bat_profile
allocation so the missing-profile branch exits early after the dev_warn, while
keeping the SIZE_OF_PROFILE validation for the present-profile case.
In
`@patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-battery-02-sgm41542.patch`:
- Around line 1382-1384: alloc_ordered_workqueue() can return NULL here, which
leaves sgm->sgm_monitor_wq invalid for later queue_delayed_work() and
destroy_workqueue() usage. Update the initialization path around sgm_monitor_wq
in the sgm charger setup to check the return value immediately after
alloc_ordered_workqueue(), and if it fails, jump to error_out and return
-ENOMEM; keep INIT_DELAYED_WORK only on the success path.
- Around line 1369-1380: The OTG initialization failure paths currently return
directly after register_pm_notifier(), which skips cleanup and leaves the
notifier registered on probe failure. Update the error handling in the SGM4154x
probe/init flow around the sgm4154x_set_otg_voltage and sgm4154x_set_otg_current
calls to jump to error_out instead of returning immediately, so the existing
cleanup path can unregister the PM notifier.
In
`@patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-panel-generic-dsi.patch`:
- Around line 199-200: The allocations in load_mode and load_init_seq are used
immediately without checking for failure, so add NULL handling right after
devm_kzalloc for both mode and item before any dereference or get_option usage.
Update the load_mode and load_init_seq paths to fail gracefully if devm_kzalloc
returns NULL, using the existing symbols load_mode, load_init_seq, mode, and
item to keep the panel probe from faulting on allocation failure.
- Around line 573-578: The failure path after drm_mode_duplicate() in the mode
setup logic is using drm_mode_vrefresh(mode) even when mode is NULL, which can
crash while logging the error. Update the error handling in this branch to avoid
dereferencing mode on failure, and log using the available fallback data from
mode_tmp or a generic message in the same code path where drm_mode_duplicate()
is checked.
In `@patch/kernel/archive/rockchip64-7.1/dt/rk3576-anbernic-rg-vita-pro.dts`:
- Line 125: The simple-battery property factory-internal-resistance-micro-ohms
in rk3576-anbernic-rg-vita-pro.dts appears to be missing zeros and is
inconsistent with the other battery definitions in this tree. Verify the correct
internal resistance from the battery datasheet, then update the value in the
battery node so it matches the intended micro-ohms scale.
---
Nitpick comments:
In `@config/kernel/linux-rockchip64-edge.config`:
- Line 1151: Move the Vita-Pro-only kernel symbols out of the shared
rockchip64-edge family config and into the board-specific
custom_kernel_config__anbernic_rg_vita_pro() in the .csc;
CONFIG_JOYSTICK_SPI_MCU_JOYPAD, CONFIG_BATTERY_CW221X, CONFIG_CHARGER_SGM41542,
CONFIG_MFD_ROCKCHIP_MFPWM, CONFIG_DRM_PANEL_GENERIC_DSI, and
CONFIG_PWM_ROCKCHIP_V4 should not be enabled globally for every rockchip64-edge
board. Keep only genuinely shared drivers in the family config and scope the
rest to the RG Vita Pro board config.
In `@patch/kernel/archive/rockchip64-7.1/dt/rk3576-anbernic-rg-vita-pro.dts`:
- Around line 286-297: The pwm2_8ch_7 node is enabled without any consumer in
this DTS, so either remove or disable it unless it is intentionally needed for a
feature like rumble or another backlight; check the pwm2_8ch_7 definition and
only keep status = "okay" if a real phandle consumer exists. Also normalize the
indentation in that node to match the rest of the file by using consistent
tabs/spaces, especially around the clocks and clock-names properties.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: dc7ab04e-dd98-4d74-937b-88374dae7706
📒 Files selected for processing (33)
config/boards/anbernic-rg-vita-pro.cscconfig/kernel/linux-rockchip64-edge.configconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/default/vita-offchargeconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/polkit-1/rules.d/49-vita-pad2key.rulesconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/sddm.conf.d/10-vita-wayland.confconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/systemd/system/vita-jack-switch.serviceconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/systemd/system/vita-offcharge-reboot-marker.serviceconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/systemd/system/vita-offcharge.serviceconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/systemd/system/vita-pad2key.serviceconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/udev/rules.d/60-vita-joypad-not-accel.rulesconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/etc/xdg/autostart/vita-screen.desktopconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-jack-switchconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-offchargeconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-pad2keyconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-pad2key-toggleconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-screenconfig/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/share/applications/vita-pad2key-toggle.desktoppackages/blobs/asound.state/asound.state.anbernic-rg-vita-propatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-battery-01-cw221x.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-battery-02-sgm41542.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-dp-usbdp-hpd-replay.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-joypad-10-options.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-joypad-11-core.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-joypad-12-input.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-joypad-13-leds.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-panel-generic-dsi.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-pwm-01-mfpwm.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-pwm-02-pwmv4.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-touch-rmi4-reset-gpio.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-typec-husb311.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-vop2-rk3576-gamma-writemask.patchpatch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-vop2-rk3576-vp2-primary-plane.patchpatch/kernel/archive/rockchip64-7.1/dt/rk3576-anbernic-rg-vita-pro.dts
| # Config in /etc/default/vita-offcharge: | ||
| # PWRON_MASK=0x01 bit(s) set in ON_SOURCE when the power button caused boot | ||
| # DISABLE=1 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Stale example value in header comment.
Header documents PWRON_MASK=0x01, but the shipped /etc/default/vita-offcharge sets PWRON_MASK=0x80 (matching the measured-on-hardware comment there: 0x80 = power button). A future edit based on this stale docstring could reintroduce a broken mask.
📝 Proposed fix
-# PWRON_MASK=0x01 bit(s) set in ON_SOURCE when the power button caused boot
+# PWRON_MASK=0x80 bit(s) set in ON_SOURCE when the power button caused boot📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Config in /etc/default/vita-offcharge: | |
| # PWRON_MASK=0x01 bit(s) set in ON_SOURCE when the power button caused boot | |
| # DISABLE=1 | |
| # Config in /etc/default/vita-offcharge: | |
| # PWRON_MASK=0x80 bit(s) set in ON_SOURCE when the power button caused boot | |
| # DISABLE=1 |
🤖 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
`@config/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-offcharge`
around lines 8 - 10, The header comment in vita-offcharge still shows the old
PWRON_MASK example, so update the documented default to match the shipped
/etc/default/vita-offcharge value used by vita-offcharge. Make the comment
consistent with the actual power-button mask seen in the config and keep the
guidance aligned with the existing DISABLE setting so future edits don’t copy
the stale value.
| screen_timeout = float(conf.get('SCREEN_TIMEOUT', '10')) | ||
| boot_hold = float(conf.get('BOOT_HOLD', '2')) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Malformed config values crash the script.
float(conf.get('SCREEN_TIMEOUT', '10')) / float(conf.get('BOOT_HOLD', '2')) raise an uncaught ValueError if a user edits /etc/default/vita-offcharge with a non-numeric value, killing the charge-screen logic (silently, since the service isn't Required by boot targets).
🛡️ Proposed fix
- screen_timeout = float(conf.get('SCREEN_TIMEOUT', '10'))
- boot_hold = float(conf.get('BOOT_HOLD', '2'))
+ try:
+ screen_timeout = float(conf.get('SCREEN_TIMEOUT', '10'))
+ except ValueError:
+ screen_timeout = 10.0
+ try:
+ boot_hold = float(conf.get('BOOT_HOLD', '2'))
+ except ValueError:
+ boot_hold = 2.0📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| screen_timeout = float(conf.get('SCREEN_TIMEOUT', '10')) | |
| boot_hold = float(conf.get('BOOT_HOLD', '2')) | |
| try: | |
| screen_timeout = float(conf.get('SCREEN_TIMEOUT', '10')) | |
| except ValueError: | |
| screen_timeout = 10.0 | |
| try: | |
| boot_hold = float(conf.get('BOOT_HOLD', '2')) | |
| except ValueError: | |
| boot_hold = 2.0 |
🤖 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
`@config/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-offcharge`
around lines 209 - 210, The `vita-offcharge` config parsing for `SCREEN_TIMEOUT`
and `BOOT_HOLD` can crash on malformed values because the `float(...)`
conversions are unchecked. Update the parsing logic around these settings to
safely handle invalid input in the script’s config-loading path, using the
existing `conf.get(...)` values but falling back to the defaults when conversion
fails. Keep the fix localized to the config read section so the charge-screen
flow continues even if `/etc/default/vita-offcharge` contains non-numeric
values.
| if systemctl is-active --quiet vita-pad2key; then | ||
| systemctl stop vita-pad2key && msg="Pad-as-keyboard OFF — raw gamepad (for games)" | ||
| else | ||
| systemctl start vita-pad2key && msg="Pad-as-keyboard ON — D-pad drives the desktop" | ||
| fi |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Silent failure path when systemctl fails.
If systemctl stop/start vita-pad2key fails (e.g., permission denied without the polkit rule applied), msg stays unset and the terminal echo / notification silently shows nothing useful.
🛠️ Proposed fix
if systemctl is-active --quiet vita-pad2key; then
- systemctl stop vita-pad2key && msg="Pad-as-keyboard OFF — raw gamepad (for games)"
+ systemctl stop vita-pad2key && msg="Pad-as-keyboard OFF — raw gamepad (for games)" || msg="Failed to disable pad-as-keyboard"
else
- systemctl start vita-pad2key && msg="Pad-as-keyboard ON — D-pad drives the desktop"
+ systemctl start vita-pad2key && msg="Pad-as-keyboard ON — D-pad drives the desktop" || msg="Failed to enable pad-as-keyboard"
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if systemctl is-active --quiet vita-pad2key; then | |
| systemctl stop vita-pad2key && msg="Pad-as-keyboard OFF — raw gamepad (for games)" | |
| else | |
| systemctl start vita-pad2key && msg="Pad-as-keyboard ON — D-pad drives the desktop" | |
| fi | |
| if systemctl is-active --quiet vita-pad2key; then | |
| systemctl stop vita-pad2key && msg="Pad-as-keyboard OFF — raw gamepad (for games)" || msg="Failed to disable pad-as-keyboard" | |
| else | |
| systemctl start vita-pad2key && msg="Pad-as-keyboard ON — D-pad drives the desktop" || msg="Failed to enable pad-as-keyboard" | |
| fi |
🤖 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
`@config/optional/boards/anbernic-rg-vita-pro/_packages/bsp-cli/usr/bin/vita-pad2key-toggle`
around lines 7 - 11, The vita-pad2key-toggle script has a silent failure path if
systemctl stop/start vita-pad2key fails, leaving msg unset and the user with no
useful output. Update the toggle logic around the systemctl calls so each branch
handles failure explicitly, setting a fallback error message when the command
does not succeed and preserving the existing success messages otherwise. Make
sure the terminal echo/notification path always has a message to display, using
the script’s msg variable and the systemctl-based state switch.
| + length = device_property_count_u8(dev, "cellwise,battery-profile"); | ||
| + if (length < 0) { | ||
| + dev_warn(cw_bat->dev, | ||
| + "No battery-profile found, using current flash contents\n"); | ||
| + } else if (length != SIZE_OF_PROFILE) { | ||
| + dev_err(cw_bat->dev, "battery-profile must be %d bytes\n", | ||
| + SIZE_OF_PROFILE); | ||
| + return -EINVAL; | ||
| + } | ||
| + | ||
| + cw_bat->bat_profile = devm_kzalloc(dev, length, GFP_KERNEL); | ||
| + if (!cw_bat->bat_profile) | ||
| + return -ENOMEM; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Guard the missing-profile case before allocating
device_property_count_u8() returns a negative error when cellwise,battery-profile is absent. Passing that straight to devm_kzalloc() turns it into a huge size_t, so this path ends in -ENOMEM instead of using the flash-contents fallback the warning suggests. Return early before the allocation.
🤖 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-7.1/board-anbernic-rg-vita-battery-01-cw221x.patch`
around lines 600 - 612, The battery-profile handling in the cw221x probe path
should return immediately when device_property_count_u8() reports that
"cellwise,battery-profile" is missing, because the current flow still reaches
devm_kzalloc() with a negative length and fails instead of using the
flash-contents fallback. Update the logic around the cw_bat->bat_profile
allocation so the missing-profile branch exits early after the dev_warn, while
keeping the SIZE_OF_PROFILE validation for the present-profile case.
| + /* OTG setting 5V/1.2A */ | ||
| + ret = sgm4154x_set_otg_voltage(sgm, 5000000); | ||
| + if (ret) { | ||
| + dev_err(sgm->dev, "set OTG voltage error!\n"); | ||
| + return ret; | ||
| + } | ||
| + | ||
| + ret = sgm4154x_set_otg_current(sgm, 1200000); | ||
| + if (ret) { | ||
| + dev_err(sgm->dev, "set OTG current error!\n"); | ||
| + return ret; | ||
| + } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file='patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-battery-02-sgm41542.patch'
echo "== context around the cited lines =="
sed -n '1325,1405p' "$file" | cat -n
echo
echo "== locations of register_pm_notifier / error_out / OTG handling in this patch =="
rg -n "register_pm_notifier|error_out:|set_otg_voltage|set_otg_current|unregister_pm_notifier|pm_nb" "$file"
echo
echo "== broader context for error paths =="
sed -n '1280,1435p' "$file" | cat -nRepository: armbian/build
Length of output: 8359
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# If the patch references the underlying driver file name, inspect it too.
rg -n "sgm4154x_set_otg_voltage|sgm4154x_set_otg_current|register_pm_notifier|error_out:" -S .Repository: armbian/build
Length of output: 2305
Route the OTG init failures through error_out
register_pm_notifier(&sgm->pm_nb) runs before these calls, but both OTG error branches return directly and skip unregister_pm_notifier(). That leaves the notifier registered after probe failure. Use goto error_out here too.
🤖 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-7.1/board-anbernic-rg-vita-battery-02-sgm41542.patch`
around lines 1369 - 1380, The OTG initialization failure paths currently return
directly after register_pm_notifier(), which skips cleanup and leaves the
notifier registered on probe failure. Update the error handling in the SGM4154x
probe/init flow around the sgm4154x_set_otg_voltage and sgm4154x_set_otg_current
calls to jump to error_out instead of returning immediately, so the existing
cleanup path can unregister the PM notifier.
| + sgm->sgm_monitor_wq = alloc_ordered_workqueue("%s", | ||
| + WQ_MEM_RECLAIM | WQ_FREEZABLE, "sgm-monitor-wq"); | ||
| + INIT_DELAYED_WORK(&sgm->sgm_delay_work, sgm_charger_work); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the patch and inspect the surrounding context.
file='patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-battery-02-sgm41542.patch'
wc -l "$file"
sed -n '1360,1425p' "$file"
# Find the relevant symbols in the patch.
rg -n "alloc_ordered_workqueue|sgm_monitor_wq|queue_delayed_work|destroy_workqueue|error_out" "$file"
# If the patch references an upstream source file, list nearby paths to inspect next.
git ls-files | rg 'sgm4154x|rg-vita|battery|charger|sgm41542'Repository: armbian/build
Length of output: 12722
Handle alloc_ordered_workqueue() failure. A NULL return leaves sgm->sgm_monitor_wq unusable, so later queue_delayed_work() and destroy_workqueue() calls are unsafe. Return -ENOMEM via error_out here.
🤖 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-7.1/board-anbernic-rg-vita-battery-02-sgm41542.patch`
around lines 1382 - 1384, alloc_ordered_workqueue() can return NULL here, which
leaves sgm->sgm_monitor_wq invalid for later queue_delayed_work() and
destroy_workqueue() usage. Update the initialization path around sgm_monitor_wq
in the sgm charger setup to check the return value immediately after
alloc_ordered_workqueue(), and if it fails, jump to error_out and return
-ENOMEM; keep INIT_DELAYED_WORK only on the success path.
| + mode = devm_kzalloc(dev, sizeof(*mode), GFP_KERNEL); | ||
| + |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Unchecked devm_kzalloc in load_mode/load_init_seq.
Both allocate mode/item and immediately dereference them without a NULL check (item->dcs = -1;, mode->clock via get_option). An allocation failure here faults during panel probe.
Also applies to: 233-237
🤖 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-7.1/board-anbernic-rg-vita-panel-generic-dsi.patch`
around lines 199 - 200, The allocations in load_mode and load_init_seq are used
immediately without checking for failure, so add NULL handling right after
devm_kzalloc for both mode and item before any dereference or get_option usage.
Update the load_mode and load_init_seq paths to fail gracefully if devm_kzalloc
returns NULL, using the existing symbols load_mode, load_init_seq, mode, and
item to keep the panel probe from faulting on allocation failure.
| + mode = drm_mode_duplicate(connector->dev, &mode_tmp); | ||
| + if (!mode) { | ||
| + dev_err(ctx->dev, "Failed to add mode %u\n", | ||
| + drm_mode_vrefresh(mode)); | ||
| + return -ENOMEM; | ||
| + } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the patch and inspect the relevant section
git ls-files 'patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-panel-generic-dsi.patch'
wc -l patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-panel-generic-dsi.patch
sed -n '540,610p' patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-panel-generic-dsi.patch
# Search for the exact error path and the helper used in the log
rg -n "drm_mode_duplicate|drm_mode_vrefresh|Failed to add mode|Failed to duplicate mode" patch/kernel/archive/rockchip64-7.1/board-anbernic-rg-vita-panel-generic-dsi.patchRepository: armbian/build
Length of output: 3169
Avoid logging drm_mode_vrefresh(mode) after drm_mode_duplicate() fails
That branch passes a null mode into drm_mode_vrefresh(), so the OOM path can dereference NULL while reporting the error.
🤖 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-7.1/board-anbernic-rg-vita-panel-generic-dsi.patch`
around lines 573 - 578, The failure path after drm_mode_duplicate() in the mode
setup logic is using drm_mode_vrefresh(mode) even when mode is NULL, which can
crash while logging the error. Update the error handling in this branch to avoid
dereferencing mode on failure, and log using the available fallback data from
mode_tmp or a generic message in the same code path where drm_mode_duplicate()
is checked.
| charge-term-current-microamp = <300000>; | ||
| constant-charge-current-max-microamp = <3780000>; | ||
| constant-charge-voltage-max-microvolt = <4350000>; | ||
| factory-internal-resistance-micro-ohms = <80>; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the DTS and related battery binding/docs.
git ls-files 'patch/kernel/archive/rockchip64-7.1/dt/rk3576-anbernic-rg-vita-pro.dts' \
'Documentation/devicetree/bindings/power/supply/*.yaml' \
'Documentation/devicetree/bindings/power/supply/*.txt' \
'Documentation/devicetree/bindings/*battery*' \
| sed 's#^`#FILE` #'
echo
echo '--- DTS excerpt around the reported line ---'
cat -n patch/kernel/archive/rockchip64-7.1/dt/rk3576-anbernic-rg-vita-pro.dts | sed -n '110,135p'
echo
echo '--- Search for factory-internal-resistance-micro-ohms usage ---'
rg -n "factory-internal-resistance-micro-ohms|simple-battery|internal-resistance" \
patch/kernel/archive/rockchip64-7.1/dt \
Documentation/devicetree/bindings/power/supply \
2>/dev/null | sed -n '1,200p'Repository: armbian/build
Length of output: 1727
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
print("requesting repository evidence")
PYRepository: armbian/build
Length of output: 182
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Check the exact binding definition for the property.
rg -n "factory-internal-resistance-micro-ohms|internal-resistance-micro-ohms" \
Documentation/devicetree/bindings/power/supply -g '*.yaml' -g '*.txt' \
-A 6 -B 6Repository: armbian/build
Length of output: 238
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find the binding file for simple-battery and inspect the property definition.
fd -a 'simple-battery*.yaml' Documentation . 2>/dev/null || true
fd -a '*battery*.yaml' Documentation . 2>/dev/null | sed -n '1,80p'
echo
echo '--- simple-battery binding excerpts ---'
for f in $(fd -a 'simple-battery*.yaml' Documentation . 2>/dev/null); do
echo "FILE $f"
rg -n "factory-internal-resistance-micro-ohms|internal-resistance-micro-ohms|simple-battery|enum|minimum|maximum|unit" "$f" -A 4 -B 4
doneRepository: armbian/build
Length of output: 151
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Broaden the search to any devicetree binding mentioning the property.
rg -n "factory-internal-resistance-micro-ohms|internal-resistance-micro-ohms|simple-battery" \
Documentation patch/kernel/archive/rockchip64-7.1/dt \
-g '*.yaml' -g '*.yml' -g '*.txt' -g '*.dts' -g '*.dtsi' \
-A 5 -B 5 | sed -n '1,240p'Repository: armbian/build
Length of output: 1930
🌐 Web query:
simple-battery devicetree binding factory-internal-resistance-micro-ohms typical value micro-ohms
💡 Result:
The devicetree property factory-internal-resistance-micro-ohms is used in the simple-battery binding to represent the battery's internal resistance in micro-ohms (µΩ) [1][2]. There is no single "typical" value for this property, as the value is specific to the physical characteristics of the battery being described [2]. In practice, values are determined by the manufacturer's datasheet for the specific battery cell. Examples from existing device tree files in the Linux kernel and hardware documentation show a range of values depending on the device: - 117,000 µΩ (e.g., Quartz64 device configurations) [3][4][5] - 150,000 µΩ (e.g., PinePhone Pro) [6] - 250,000 µΩ (e.g., example provided in the official kernel documentation) [7][2][8] This property was introduced to allow the system to use a constant internal resistance value to estimate battery capacity, acknowledging that actual resistance varies over the battery's lifecycle due to aging, temperature, and other factors [2][9]. If the property is not specified in the device tree, the value is typically treated as unknown or handled by the specific power supply driver implementation [10].
Citations:
- 1: https://www.kernel.org/doc/Documentation/devicetree/bindings/power/supply/battery.yaml
- 2: https://lists.openwall.net/linux-kernel/2018/10/22/83
- 3: https://kernel.googlesource.com/pub/scm/linux/kernel/git/mmind/linux-rockchip/+/for-next/arch/arm64/boot/dts/rockchip/rk3566-anbernic-rg353vs.dts
- 4: https://pine64.org/documentation/Quartz64/How-Tos/Using_a_battery/
- 5: https://pine64.org/documentation/Quartz64/_full/
- 6: https://gitlab.com/pine64-org/linux/-/blob/caleb/ppp-5.19-rc5/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
- 7: https://mjmwired.net/kernel/Documentation/devicetree/bindings/power/supply/battery.yaml
- 8: https://gitlab.sdu.dk/sdurobotics/linux-kernels/kernel/-/blob/mainline/Documentation/devicetree/bindings/power/supply/battery.txt?ref_type=heads
- 9: https://lists.openwall.net/linux-kernel/2018/11/05/185
- 10: https://android.googlesource.com/kernel/common/+/50f6c7dbd973092d8e5f3c89f29eb4bea19fdebd%5E2..50f6c7dbd973092d8e5f3c89f29eb4bea19fdebd/
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Search the repo for battery bindings and any documentation copies.
git ls-files | rg '/(simple-battery|battery).*\.ya?ml$|/.*battery.*\.txt$|/.*battery.*\.rst$|/.*battery.*\.md$' || true
echo
echo '--- search for the property in all tracked files ---'
rg -n "factory-internal-resistance-micro-ohms|internal-resistance-micro-ohms" . -g '!**/.git/**' | sed -n '1,200p'Repository: armbian/build
Length of output: 2005
factory-internal-resistance-micro-ohms looks too small.
80 µΩ is far below the other simple-battery values in this tree (typically ~120000–150000 µΩ), so this looks like a missing-zeros typo. Please check the battery datasheet and update the value if needed.
🤖 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-7.1/dt/rk3576-anbernic-rg-vita-pro.dts` at
line 125, The simple-battery property factory-internal-resistance-micro-ohms in
rk3576-anbernic-rg-vita-pro.dts appears to be missing zeros and is inconsistent
with the other battery definitions in this tree. Verify the correct internal
resistance from the battery datasheet, then update the value in the battery node
so it matches the intended micro-ohms scale.
Source: Learnings
| CONFIG_KEYBOARD_IQS62X=m | ||
| CONFIG_KEYBOARD_CYPRESS_SF=m | ||
| CONFIG_INPUT_JOYSTICK=y | ||
| CONFIG_JOYSTICK_SPI_MCU_JOYPAD=y |
There was a problem hiding this comment.
Yes — changed CONFIG_JOYSTICK_SPI_MCU_JOYPAD to =m. Verified on hardware after a rebuild: it autoloads via its OF/SPI device table and registers the input device (lsmod shows spi_mcu_joypad, evtest sees "MCU Joypad", sticks work).
The battery and charger drivers are already =m as well. I deliberately kept the display/backlight path built-in (MFD_ROCKCHIP_MFPWM, PWM_ROCKCHIP_V4 =y): the case is glued shut so there is no serial console — the panel is the only local console — and I wanted the backlight/PWM up at the earliest point in boot. Happy to modularize those too if you prefer; I would just re-verify the panel still lights on a module build.
- csc: single-line hardware description (match other board configs) - csc: drop "Anbernic" from BOARD_NAME (already in BOARD_VENDOR) - kernel config: build the SPI-MCU joypad as a module instead of built-in (board-specific driver; autoloads via its OF/SPI device table) Signed-off-by: crackerjacques <jack@supremeoverlordjabs.co>
What is this
The Anbernic RG Vita Pro is a gaming handheld built around the Rockchip
RK3576 (4x Cortex-A72 + 4x Cortex-A53, Mali-G52 MC3):
in the same IC as the display driver)
TCPC, SGM41542 charger, CW2217 fuel gauge)
The case is glued shut, so there is no accessible UART; bring-up was done
over WiFi/ssh. Everything below is verified on real hardware, running both
console images and GNOME/KDE Wayland desktops.
What works
Boot specifics
generic-rk3576_defconfigmainline U-Boot; the family boot_merger injectsthe rk3576 SD boost blob (same pattern as nanopi-r76s).
board's RAM (the vendor image ships v1.09).
vendor OS in eMMC.
Kernel patches (rockchip64/edge)
Generic RK3576 fixes, affecting all boards of this SoC (I intend to send
these upstream):
board-anbernic-rg-vita-vop2-rk3576-gamma-writemask.patch— on RK3576 theVOP2
LUT_PORT_SELregister is write-masked (unlike RK3588); mainline'splain write is silently ignored, so the gamma LUT lands in VP0's table
while another VP enables its never-initialized LUT. Any userspace that
programs legacy gamma (Xorg does at startup) gets wildly corrupted colors.
board-anbernic-rg-vita-vop2-rk3576-vp2-primary-plane.patch— VP2 (the DPvideo port) has no primary plane, so enabling DP fails the whole VOP2 bind.
Promotes Esmart0 to primary (from ROCKNIX, reduced to match mainline's
DUAL-pixel DP configuration).
board-anbernic-rg-vita-dp-usbdp-hpd-replay.patch— replay HPD state on DPPHY init so DP alt-mode displays connected at boot are detected (based on
ROCKNIX).
Device enablement, ported from the ROCKNIX project (thanks to the ROCKNIX
developers and Chris Morgan for the excellent groundwork; HUSB311 based on a
patch by Alexey Charkov):
board-anbernic-rg-vita-panel-generic-dsi.patch—rocknix,generic-dsipanel driver (timings/init sequence from DT)
board-anbernic-rg-vita-joypad-1x-*.patch(4) — SPI-MCU gamepad driverboard-anbernic-rg-vita-pwm-01-mfpwm.patch,-02-pwmv4.patch— RK3576PWM (backlight)
board-anbernic-rg-vita-touch-rmi4-reset-gpio.patch— the LCD is a TDDImodule; rmi4's chip-wide soft reset at probe kills the display half. With
a dedicated reset GPIO in DT the driver hard-resets only the touch block.
board-anbernic-rg-vita-battery-01-cw221x.patch,-02-sgm41542.patch—fuel gauge and charger drivers
board-anbernic-rg-vita-typec-husb311.patch— HUSB311 IDs for the rt1711hTCPC driver (register-compatible, mainline no longer checks VID/PID)
Board DTS (
dt/rk3576-anbernic-rg-vita-pro.dts) comes from ROCKNIX, adaptedto the current kernel.
Kernel config additions:
JOYSTICK_SPI_MCU_JOYPAD,LEDS_CLASS_MULTICOLOR,DRM_PANEL_GENERIC_DSI,MFD_ROCKCHIP_MFPWM,PWM_ROCKCHIP_V4,BATTERY_CW221X,CHARGER_SGM41542.BSP helpers (config/optional, board bsp package)
vita-jack-switch— mutes the internal speakers while headphones areplugged (jack detection via the panel's input device)
vita-pad2key+ toggle — gamepad-to-keyboard remap for desktop navigation(D-pad = arrows, A = Enter, B = Esc, ...), toggleable per the RG DS pattern
vita-screen— X11-only default rotation + touch mapping (Wayland handlesthe portrait panel natively via the DRM panel-orientation property)
rotate); GDM works as-is, lightdm (X11-only) is not usable on this panel
joystick (stops desktops from auto-rotating the screen on stick movement)
vita-offcharge— Android-style off-charge mode: the RK806 powers thedevice on whenever a charger is plugged (hardware behavior), so a plug-in
boot (detected via the PMIC's ON_SOURCE register) shows a battery screen
instead of booting to the desktop; unplugging powers back off, pressing
the power button continues the normal boot
Known limitations
behavior), so the device cannot stay off while a powered USB-C device is
attached; the
vita-offchargehelper turns this into an Android-stylecharging screen that powers back off on unplug.
/dev/ttyGS0 open blocks dwc3's device->host role switch (worker deadlocks
in dwc3_gadget_exit), which would break USB host hotplug. I plan to report
this u_serial/dwc3 behavior upstream.
Ubuntu's wireplumber needs snapd present to expose audio devices (not
board-specific).
The board page image is submitted as armbian/armbian.github.io#351.
Summary by CodeRabbit