Skip to content

hi3520dv200: bring the NVP6134 analog decoder up - #3036

Open
openipc-ai wants to merge 2 commits into
masterfrom
hi3520dv200-nvp6134
Open

openipc-ai wants to merge 2 commits into
masterfrom
hi3520dv200-nvp6134

Conversation

@openipc-ai

Copy link
Copy Markdown
Collaborator

On a Xiongmai Hi3520DV200 DVR (Nextchip NVP6134 at I2C 0x60, four BNC inputs) OpenIPC never saw an analog camera. Three things in load_hisilicon were wrong for this board:

  1. Wrong driver parameters: the NVP6114's vdec_mode=1 outmode=3 were passed to nvp6134_ex.ko, whose only parameter is nvp6134_mode. So the 6134 driver never loaded, and the NVP6114 driver found no chip.
  2. Decoder held in reset: the board keeps the decoder in reset on GPIO1_2 (pin 72, muxctrl_reg48) until software drives it high. The vendor's driver does that when it loads. Until then nothing answers on the I2C bus.
  3. Wrong clock: the decoder is clocked from the SoC's VI_ADC_CLK, set by PERI_CRG11 bits 19:18 (00 = 54 MHz, 01 = 27 MHz, per the Hi3520D data sheet). The 8D1 setting gives 54 MHz, and at that rate the chip detects no camera. It needs 27 MHz.

load_decoder now:

  • loads the NVP6134 driver with no parameters;
  • if no chip answers, releases GPIO1_2 and tries again; if still nothing answers, puts the pin back as it was;
  • with an NVP6134, sets 27 MHz and loads the driver again at that clock;
  • without one, loads the NVP6114 driver as before.

remove_ko now unloads the 6134 driver under its real module name, open_nvp6134_ex. test_load_hisilicon.sh Part 7 covers three cases: the chip answers at once, only after the reset, or never.

On an NVR without a decoder, GPIO1_2 (whose other function is the TEMPER_DQ line) is driven high for one second, then restored.

The vigil side (VI setup, the decoder's channel and port modes, tiles, encoder) is OpenIPC/vigil#29.

Tested on hardware

Board: the Xiongmai DVR above, freshly booted from flash (nightly 2026-11-29: NVP6114 driver loaded, no chip found, clock at 54 MHz). The NVP6114 and gpioi2c drivers were unloaded, then this branch's load_decoder was run, taken from the script:

mux=0x00000000 dir=0x000000C4 crg=0x5524FF02
Device (0x60) ID OK... 90
Chip Count = 1, [0x60][0x62][0x64][0x66]
open_nvp6134_ex       168183  0

After the channels were set to AHD 720p (as vigil does), the camera on input 1 was detected: register 0xA8 changed from 0x0F to 0x0E. Its picture came through VI at 1280×720 (Y 1–254). In the vigil#29 run, the same bring-up (done by hand) gave all four inputs at 1280×720 H.264 25 fps, with the camera shown on the monitor.

bash .github/scripts/test_load_hisilicon.sh and ci-matrix.py --self-test pass.

Not tested:

  • a full image with this script booted from flash: the function was run by hand on the running board;
  • an NVP6114 board;
  • an NVR (the restore path is covered only by the test).

On a Xiongmai Hi3520DV200 DVR (NVP6134 at I2C 0x60) no analog camera was
ever seen, for three reasons found on the board:

- load_hisilicon passed the NVP6114's parameters (vdec_mode, outmode) to
  nvp6134_ex.ko, whose only parameter is nvp6134_mode, so it never loaded
  and the NVP6114 driver found nothing.
- The board holds the decoder in reset on GPIO1_2 (pin 72) until software
  drives it high, as its vendor driver does at load: until then nothing
  answers on the I2C bus at all.
- The decoder is clocked from the SoC's VI_ADC_CLK, PERI_CRG11 bits 19:18:
  the 8D1 setting gives 54 MHz, at which the chip detects no camera; it
  needs 27 MHz.

load_decoder now loads the NVP6134's driver without parameters; when no
chip answers it releases GPIO1_2 and tries again, and puts the pin back
when nothing answers then either. With an NVP6134 it sets 27 MHz and
loads the driver again at that clock; without one, the NVP6114's driver
as before. remove_ko unloads the 6134 driver under its module name,
open_nvp6134_ex. Covered by test_load_hisilicon.sh Part 7.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

hi3520dv200: bring the NVP6134 analog decoder up

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Loads the NVP6134 driver with no parameters, so it actually loads on the DVR.
• Releases the GPIO1_2 reset and sets VI_ADC_CLK to 27 MHz when the NVP6134 answers.
• Falls back to the unchanged NVP6114 path; Part 7 of the test script covers all three cases.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed probe, GPIO reset handling, VI_ADC_CLK programming, driver reload, and NVP6114 fallback all determine one bounded end-to-end outcome: analog camera signals becoming available to the hi3520dv200 video-input pipeline.
  • They are implementation hops of that same decoder integration, not independent capabilities.
Sources

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[192-214]

load_decoder() {
	insmod gpioi2c.ko
	if ! nvp6134_found; then
		mux=$(devmem 0x200f00c0 32)
		dir=$(devmem 0x20160400 32)
		lvl=$(devmem 0x20160010 32)
		devmem 0x200f00c0 32 0
		devmem 0x20160400 32 $((dir | 0x04))
		devmem 0x20160010 32 0xff
		sleep 1
		if ! nvp6134_found; then
			devmem 0x20160010 32 "$lvl"
			devmem 0x20160400 32 "$dir"
			devmem 0x200f00c0 32 "$mux"
			insmod nvp6114_ex.ko vdec_mode=1 outmode=3
			return
		fi
	fi
	crg=$(devmem 0x2003002c 32)
	devmem 0x2003002c 32 $(((crg & ~0xc0000) | 0x40000))
	rmmod open_nvp6134_ex 2>/dev/null || rmmod nvp6134_ex 2>/dev/null
	insmod nvp6134_ex.ko
}

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[245-245]

	load_decoder
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: the script loaded NVP6134 with NVP6114 parameters and fell back only when insmod failed.
  • After: it performs two probes, conditionally changes GPIO1_2, preserves and restores mux/direction/level on fallback, changes VI_ADC_CLK, unloads, and reloads the driver.
  • New correctness conditions: the probe result must correspond to the current driver load, GPIO restoration must preserve all three saved register values, the clock must be changed only for a real NVP6134, and each unload/reload state must agree with the selected decoder.
  • The changed branches interact through hardware state and driver lifecycle rather than merely reusing an existing helper.
Sources

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[192-214]

load_decoder() {
	insmod gpioi2c.ko
	if ! nvp6134_found; then
		mux=$(devmem 0x200f00c0 32)
		dir=$(devmem 0x20160400 32)
		lvl=$(devmem 0x20160010 32)
		devmem 0x200f00c0 32 0
		devmem 0x20160400 32 $((dir | 0x04))
		devmem 0x20160010 32 0xff
		sleep 1
		if ! nvp6134_found; then
			devmem 0x20160010 32 "$lvl"
			devmem 0x20160400 32 "$dir"
			devmem 0x200f00c0 32 "$mux"
			insmod nvp6114_ex.ko vdec_mode=1 outmode=3
			return
		fi
	fi
	crg=$(devmem 0x2003002c 32)
	devmem 0x2003002c 32 $(((crg & ~0xc0000) | 0x40000))
	rmmod open_nvp6134_ex 2>/dev/null || rmmod nvp6134_ex 2>/dev/null
	insmod nvp6134_ex.ko
}
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the probe is falsely positive, the NVP6114 fallback is skipped and the NVP6134 path may leave analog capture unavailable or produce no usable camera frames.
  • Reverting the code prevents future occurrences, but the active module and VI clock state require a script rerun or reboot to restore the prior setup.
  • The affected capability can generally be restored by rerunning the corrected loader or rebooting, provided the NVP6114 driver and hardware are present.
  • Reverting code alone does not repair already changed runtime clock, GPIO, or module state.
Sources

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[192-214]

load_decoder() {
	insmod gpioi2c.ko
	if ! nvp6134_found; then
		mux=$(devmem 0x200f00c0 32)
		dir=$(devmem 0x20160400 32)
		lvl=$(devmem 0x20160010 32)
		devmem 0x200f00c0 32 0
		devmem 0x20160400 32 $((dir | 0x04))
		devmem 0x20160010 32 0xff
		sleep 1
		if ! nvp6134_found; then
			devmem 0x20160010 32 "$lvl"
			devmem 0x20160400 32 "$dir"
			devmem 0x200f00c0 32 "$mux"
			insmod nvp6114_ex.ko vdec_mode=1 outmode=3
			return
		fi
	fi
	crg=$(devmem 0x2003002c 32)
	devmem 0x2003002c 32 $(((crg & ~0xc0000) | 0x40000))
	rmmod open_nvp6134_ex 2>/dev/null || rmmod nvp6134_ex 2>/dev/null
	insmod nvp6134_ex.ko
}
Assessed commit 43f8dbf
Diagram

graph TD
  A["load_decoder"] --> B["insmod gpioi2c.ko"] --> C{"NVP6134 answers?"}
  C -->|yes| D["Set VI_ADC_CLK 27 MHz"] --> E["Reload nvp6134_ex at 27 MHz"]
  C -->|no| F["Release GPIO1_2 reset"] --> G{"Answers now?"}
  G -->|yes| D
  G -->|no| H["Restore GPIO1_2"] --> I["Load nvp6114_ex"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Set 27 MHz before the first probe
  • ➕ Removes one driver reload
  • ➕ Simpler control flow with a single probe
  • ➖ Changes the clock on NVP6114 boards and NVRs, which are untested
  • ➖ Still needs the reset release, so the flow is not much shorter
2. Keep the NVP6134 driver loaded and set the clock at runtime
  • ➕ Avoids rmmod and insmod at the clock change
  • ➖ Depends on whether the vendor driver re-reads the clock, which is not verified
  • ➖ The diff does not show the driver supports this

Recommendation: The PR's approach is sound. The clock is set only once a chip has answered, so NVP6114 boards and NVRs keep the old clock. The cost is one extra driver reload, which is acceptable at boot. Setting the clock first would be simpler, but it would change behaviour on hardware that was not tested.

Files changed (2) +96 / -6

Bug fix (1) +43 / -6
load_hisiliconAdd NVP6134 probe, GPIO1_2 reset release and 27 MHz clock to load_decoder +43/-6

Add NVP6134 probe, GPIO1_2 reset release and 27 MHz clock to load_decoder

• Adds nvp6134_found() to load the NVP6134 driver and check dmesg for ID OK. load_decoder() releases the GPIO1_2 reset and probes again if nothing answers, then restores the pin and loads the NVP6114 driver. If an NVP6134 answers, it sets PERI_CRG11 bits 19:18 to 01 (27 MHz) and reloads the driver. remove_ko() now unloads open_nvp6134_ex.

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon

Tests (1) +53 / -0
test_load_hisilicon.shAdd Part 7 tests for the hi3520dv200 decoder bring-up +53/-0

Add Part 7 tests for the hi3520dv200 decoder bring-up

• Extracts nvp6134_found and load_decoder from the script and runs them with stubbed insmod, rmmod, dmesg, devmem and sleep. It covers three cases: the chip answers at once, only after the reset, and never. Each case checks the module sequence, GPIO1_2 state and clock register.

.github/scripts/test_load_hisilicon.sh

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (3) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. NVRs get a shared pin driven high 📘 Rule violation ☼ Reliability
Description
load_decoder hard-codes the Xiongmai reset sequence in the shared Hi3520DV200 script, changing the
GPIO1_2 pinmux, direction and data registers whenever no decoder answers. On an NVR without a
decoder, GPIO1_2 is shared with TEMPER_DQ, so the script drives it high for one second at every
boot even on boards outside the bench test.
Code

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[R194-197]

+		mux=$(devmem 0x200f00c0 32)
+		dir=$(devmem 0x20160400 32)
+		devmem 0x200f00c0 32 0
+		devmem 0x20160400 32 $((dir | 0x04))
Evidence
The GPIO1_2 register writes are in load_decoder at
general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[191-211], a script
installed for the SoC family rather than selected per board. They run on the no-decoder path, while
the PR identifies GPIO1_2 as TEMPER_DQ on NVRs; together, those facts show why the board-specific
reset sequence reaches NVRs without a decoder.

Rule 7: No device-specific values in generic configuration
general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[194-197]
general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[191-199]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The shared Hi3520DV200 `load_decoder` script changes GPIO1_2 pinmux (`0x200f00c0`), direction (`0x20160400`) and data (`0x20160010`) whenever no decoder answers. On NVRs without a decoder, that pin is shared with `TEMPER_DQ`, so the script drives it high by default.
## Fix Focus Areas
- general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[191-211]
## Recommended Fix
Remove the unconditional GPIO1_2 writes from `load_decoder`. Put the reset release in a per-device seam, such as a board-owned hook in `/usr/share/openipc/customizer.sh` or a `gpio.conf` entry under the device's `devices/<board>/` configuration, and call it only when configured; alternatively, handle it in the NVP6134 driver's probe path. If register writes must remain in the shared script, check that the board owns the pin and carries an NVP6134 before writing, and restore pinmux and direction on every exit path, including the no-chip path. Keep NVP6134 detection, the 27 MHz clock step and the NVP6114 fallback in the shared script, and ensure the NVR path does not toggle GPIO1_2 by default.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Other boards get the DVR's decoder setup 📘 Rule violation ≡ Correctness
Description
load_decoder releases GPIO1_2 and sets VI_ADC_CLK to 27 MHz whenever an NVP6134 answers, values
the PR ties to the Xiongmai DVR, in the script every hi3520dv200 board shares. Any other board
carrying an NVP6134 with different wiring takes the new reset and clock without opting in.
Code

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[R207-210]

+	crg=$(devmem 0x2003002c 32)
+	devmem 0x2003002c 32 $(((crg & ~0xc0000) | 0x40000))
+	rmmod open_nvp6134_ex 2>/dev/null || rmmod nvp6134_ex 2>/dev/null
+	insmod nvp6134_ex.ko
Evidence
The clock and reset values are described as specific to the Xiongmai DVR, yet they are written
unconditionally in the shared family script.

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[207-210]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
The PR adds Xiongmai DVR-specific values (GPIO1_2 reset release, VI_ADC_CLK 27 MHz via `0x2003002c`, and the NVP6134 reload) to the shared hi3520dv200 `load_hisilicon` script, so every board using this family's script inherits them.
Fix Focus Areas
- general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[191-211]
Recommended Fix
Keep the shared script's behaviour unchanged for existing families. Put the 27 MHz clock and the GPIO1_2 reset in per-device configuration in OpenIPC/builder, or gate them on a device-specific condition. Confirm that the NVP6114 path and the existing defaults are unchanged for other boards.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Decoder fixes stuck in firmware script 📘 Rule violation ⚙ Maintainability
Description
The GPIO reset and the clock setting are behaviours the NVP6134 driver or the SoC SDK should own,
yet load_decoder implements them as startup-script devmem writes. A fix to the driver's handling
would not reach this path, and the workaround would outlive the driver fix.
Code

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[R191-194]

+load_decoder() {
+	insmod gpioi2c.ko
+	if ! nvp6134_found; then
+		mux=$(devmem 0x200f00c0 32)
Evidence
The script compensates for missing reset and clock handling in the decoder or SoC driver with
startup-time register writes.

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[191-194]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
The `load_decoder` function in the shared hi3520dv200 `load_hisilicon` script releases the NVP6134 reset on GPIO1_2 and sets VI_ADC_CLK through `devmem`. The PR's own description says the vendor driver performs the reset release, so this is driver-owned behaviour implemented as a startup workaround.
Fix Focus Areas
- general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[191-211]
Recommended Fix
Move the reset release and the 27 MHz clock setting into the NVP6134 driver or the owning SDK, so the firmware script just loads the driver with no parameters. Keep the script change limited to whatever cannot move, and document that as a temporary bridge.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. A failed probe leaves an output pin high ✓ Resolved Bug Correctness

Resolving commit: 43f8dbf

Resolution reason
The commit reads the GPIO1_2 data register (0x20160010) before driving it, saves it as "lvl" (bit 2
of the value), and on the failed-probe path restores the saved value via devmem 0x20160010 before
restoring direction and mux. The test was extended with a case starting from an output-low pin
(dir=0xc4, lvl=0) that verifies the level is restored low after fallback. This matches the suggested
fix's approach, with a slightly different mechanism (the data-register value is restored before
dir/mux, as the fix prompt requests).
Description
load_decoder saves GPIO1_2's mux and direction but not its output value before writing 0xff to
its data register. If neither probe finds an NVP6134 and the pin was already configured as an output
driven low, restoring only its direction and mux leaves it driven high while the NVP6114 fallback
loads.

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

When no NVP6134 answers even after the Xiongmai reset, GPIO1_2 got its
direction and function back but not its level: a pin that was an output
driven low was left high. The level is saved with the rest and restored
first. Part 7 checks a pin that was an output driven low.
@openipc-ai

Copy link
Copy Markdown
Collaborator Author

Answers to Qodo's review:

  1. A failed probe leaves an output pin high — fixed in the latest commit. GPIO1_2's level is now saved along with its function and direction, and restored first. Part 7 has a new case, a pin that was an output driven low; with the previous script it fails, because the pin is left high.

  2. NVRs get a shared pin driven high — declined. The reset is tried only when no NVP6134 answered on the first load, and the pin is put back right after: function, direction and now level. On a board where pin 72 is TEMPER_DQ, that's a 1-wire line whose idle level is high (pulled up), so one second high is its resting state, not a signal. I'd rather an NVR pay that once at boot than have every Xiongmai DVR need a setting before its cameras work. (Part 7, "no NVP6134", covers the restore.)

  3. Other boards get the DVR's decoder setup — declined. Two parts:

    • Clock: 27 MHz is what the NVP6134 itself needs from VI_ADC_CLK, not a property of this board. A board whose NVP6134 has its own crystal doesn't use that output, so the setting does nothing there.
    • Reset: only touched when the chip didn't answer without it. An NVP6134 board wired otherwise answers on the first load and keeps its GPIO1_2 untouched (Part 7, "NVP6134 answers").
  4. Belongs in the driver — declined. Pin mux and clock set-up for the media blocks is what load_hisilicon already does for every OpenIPC HiSilicon board (apply_pinmux, apply_crgctrl, apply_sysctl), and it is where a reader of this board's bring-up looks. The NVP6134 driver is shared with boards that route reset and clock differently; putting one vendor's GPIO into it would be the board-specific coupling this review warns about in Dev #2.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant