Skip to content

hisi: report every sensor on Hi3519DV500 dual-sensor boards; fix V5 DDR rate, DV500 CPU clock - #294

Merged
widgetii merged 2 commits into
masterfrom
dv500-multisensor
Nov 24, 2026
Merged

widgetii merged 2 commits into
masterfrom
dv500-multisensor

Conversation

@widgetii

@widgetii widgetii commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

A Hi3519DV500 kit with an OS04A10 on SENSOR0 and an OS08A20 on SENSOR1 reported one sensor. Three things stood in the way, and the clock report was wrong in two places.

Sensors

  • Every sensor, on boards that have more than one. A new HAL global, hal_sensor_buses, lets a HAL list the i2c buses its board family carries sensors on. When it is set, detect_sensors() probes those buses after the first hit and lists every sensor, one entry per bus. DV500 sets {4, 5, 3, 6}, the vendor SDK's SENSOR0..3. Every other platform leaves it NULL and reports exactly as before. Probes write (two-byte register addresses, page registers), so they must not reach unrelated buses. The fallback sweep is unchanged (0..5). getsensorid() and libipchw are unchanged.
  • DV500 SENSOR1 is on I2C5, whose pads (iocfg_reg109/110, 0x0EFF0024/28) the stock sys_config.ko leaves as GPIO1_0/1_1 unless built with I2C_EX_EN. Every transfer on /dev/i2c-5 timed out. The OT arm switches them to function 2 only while both are GPIO inputs, and only from a probe's arm, never at HAL setup, so ipctool -c and clocks leave them alone. It never touches them in SPI1 mode or as a driven GPIO, and puts back what it found if the pad still holds our word. Our word keeps the found drive/pull bits, unlike the vendor's 0x1752, so the undo survives the SPI arm, which has no cleanup.
  • Sensor clock select. PERI_CRG8464/8472 reset to cksel 0 = 74.25 MHz on CV610 and DV500 alike, above the 27 MHz an OS08A10/A20 and the 36 MHz an OS04A10 accept. A clock we ungate from that state now gets 24 MHz. A running clock, or one whose select somebody chose, is left alone.
  • OS08A10 vs OS08A20. They share 0x300A..C = 53 08 41 and 0x302A = 0xB0 in every data sheet revision; only Nyxel NIR sensitivity differs. sensor_id stays OS08A10, which is what consumers pick a driver by, and the report adds id_shared_with: OS08A20.

Clocks

  • V5 DDR rate was the DRAM clock. With DFI 1:2 the DRAM runs at twice the DPLL and transfers on both edges, so the rate is DPLL * (1 << dficlk_ratio) * 2. The DV500 data sheet's clock tree runs the DPLL at 667 MHz for "up to 2666 Mbps DDR4". The kit (boot table ..._DDR4_2666M-4GB) reads 664 MHz and now reports 2656 MT/s instead of 1328.
  • DV500 CPU. PERI_CRG2064 a55_cksel [10:8] picks one of seven sources, only one of them the APLL. The kit reads 6, the fixed 1000 MHz source, with the APLL at 750 MHz beside it. A new clocks.cpu entry decodes it. CV610's A7 uses a different register and is left out.

Tests

  • hal_hisi_test: +10 cases covering:
    • cksel: default, kept, running
    • I2C5 pads: idle input, SPI1, GPIO output, already I2C5, re-muxed by someone else, non-DV500, and the whole sweep including the SPI arm
  • Mutation-checked: breaking the 24 MHz value or the pad undo makes them fail.
  • All host tests and tools/test_pipeline.sh pass. arm64 and arm32 build clean; mips32 was not built locally.

On hardware

Hi3519DV500 kit, MPP V2.0.1.1, OS04A10 on SENSOR0 and OS08A20 on SENSOR1:

State Result
I2C5 pads already muxed (0x1752) both sensors; pads untouched
stock pads (0x1300) both sensors; pads back to 0x1300 afterwards
both sensor CRGs at reset (0x3) both sensors, probed at 24 MHz
sensors:
- vendor: OmniVision
  model: OS04A10
  control: {bus: 4, type: i2c, addr: 0x6c}
- vendor: OmniVision
  model: OS08A10
  id_shared_with: OS08A20
  control: {bus: 5, type: i2c, addr: 0x6c}

Cost: a full report takes 14.6 s on this board instead of 13.0 s, from the two extra listed buses. Most of the time, before and after, is unmuxed adapters timing out in the fallback sweep. Skipping adapters whose pads aren't I2C, using the pad table, would be a follow-up. ipcinfo is unchanged in size on arm32.

Review round 1 (Qodo, 7 findings) is addressed in 3939e17.

…DR rate, DV500 CPU clock

A Hi3519DV500 kit with an OS04A10 on SENSOR0 and an OS08A20 on SENSOR1
reported one sensor. Three things stood in the way, and the clock report
was wrong in two places.

- The report stopped at the first sensor. detect_sensors() now probes the
  remaining i2c buses and lists every sensor it finds, one entry per bus.
  Both sweeps now run to bus 7: the vendor SDK puts sensors 0..3 on I2C4,
  I2C5, I2C3 and I2C6. Buses the first probe already found empty are not
  probed again. getsensorid() and libipchw are unchanged.

- On DV500 the SENSOR1 bus is I2C5, whose pads (iocfg_reg109/110 at
  0x0EFF0024/28) the stock sys_config.ko leaves as GPIO1_0/1_1 unless
  built with I2C_EX_EN, so every transfer timed out. The OT arm switches
  them to function 2 (I2C5) only while both are GPIO inputs -- never in
  SPI1 mode, never a GPIO the board drives -- and puts back what it found
  if the pad still holds our word. Our word keeps the found drive and pull
  bits, unlike the vendor's 0x1752, so the undo can survive the SPI arm,
  which has no cleanup of its own.

- PERI_CRG8464/8472 reset to cksel 0, which is 74.25 MHz on CV610 and
  DV500 alike, above the 27 MHz an OS08A10/A20 or the 36 MHz an OS04A10
  accepts. A clock we ungate from that state now gets 24 MHz. A running
  clock, or one whose select somebody chose, is left alone.

- OS08A10 and OS08A20 share 0x300A..C = 53 08 41 and 0x302A = 0xB0 in
  every data sheet revision; only Nyxel NIR sensitivity differs. sensor_id
  stays OS08A10, which is what consumers select a driver by, and the
  report adds `id_shared_with: OS08A20`.

- clocks: the V5 DDR rate was the DRAM clock. With DFI 1:2 the DRAM runs
  at twice the DPLL and moves data on both edges, so the rate is
  DPLL * (1 << dficlk_ratio) * 2. The DV500 data sheet's clock tree runs
  the DPLL at 667 MHz for "up to 2666 Mbps DDR4"; the kit (boot table
  ..._DDR4_2666M-4GB) reads 664 MHz and now reports 2656 MT/s, not 1328.

- clocks: on DV500 the A55 does not have to run from the APLL.
  PERI_CRG2064 a55_cksel [10:8] picks one of seven sources; the kit reads
  6, the fixed 1000 MHz source, with the APLL at 750 MHz beside it. A new
  `cpu` entry decodes it. CV610's A7 uses a different register and is
  left out.

hal_hisi_test gains ten cases for the clock select and the I2C5 pads.
Breaking the 24 MHz value or the pad undo makes them fail.

Verified on the kit (MPP V2.0.1.1): both sensors found with the pads
already muxed (0x1752, left untouched), with stock pads (0x1300, restored
afterwards), and with both sensor CRGs at their reset value 0x3.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Report all DV500 sensors and correct V5 clock rates

🐞 Bug fix ✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Report sensors on every detected I²C bus, including DV500 SENSOR1, without changing the existing
 sensor ID API.
• Safely enable DV500 I²C5 pads and select 24 MHz when ungating reset-state sensor clocks.
• Correct V5 DDR data rates and report the DV500 CPU clock’s selected source.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: clock_reporting, sensor_discovery.
  • The changed paths all feed the single end-to-end clock-reporting output consumed by the standard YAML report or the clocks command.
  • The CPU selection, PLL read helper, and DDR conversion are reporting stages of that bounded capability, not independent user behaviors.
  • The changed HAL bus list, clock/pad preparation, per-bus I2C probe, cleanup, and JSON construction form one end-to-end sensor-discovery behavior.
  • The HAL changes are producer/preparation hops for the inventory report, not separate capabilities; all claimed paths terminate in the sensor inventory output.
Sources

src/hal/hisi/clocks_v5.c[211-214]

static void v5_extra(cJSON *root, bool brief) {
    /* First, and on its own registers: a DDR read failing below must not
     * take the CPU clock with it. */
    v5_dv500_cpu(root, brief);
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: sensor discovery constructed one entry from the first successful probe, and the HAL used a simpler single-probe readiness path.
  • After: discovery iterates a board-specific ordered bus list while managing the process-global adapter, repeated probe arms, temporary sensor context, and cleanup; DV500 also conditionally changes two pad muxes and sensor clock-selection fields.
  • New correctness conditions: the first bus must not be probed twice, skipped buses must be justified by the prior fallback sweep, the global adapter must be restored, both pads must be eligible before partial muxing, and each temporary clock/pad change must be restored only when ownership and the observed register value still match.
  • These are newly interacting state and ownership invariants, not merely reuse of existing I2C or cleanup helpers.
Sources

src/hal/hisi/hal_hisi.c[494-496]

    uint32_t want = (cur | cken) & ~srst;
    if (sel_mask && !(cur & cken) && !(cur & sel_mask))
        want = (want & ~sel_mask) | sel_safe;
Potential damage 🟡 Medium 🩹 Incorrect results

  • When activated, the supported consequence of a bad decode is an incorrect or incomplete frequency/data-rate report.
  • Reverting or correcting the decoder restores future reports; no persistent state or external device state is changed by these additions.
  • Re-run after software correction or after the relevant register-read condition is restored.
  • A revert repairs code but does not retroactively correct reports already collected; no state repair or external compensation is required.
Assessed commit 3939e17
Diagram

graph TD
  report["Hardware report"] --> discovery["Sensor discovery"] --> hal["HiSilicon HAL"] --> buses["I2C buses"] --> sensors["Board sensors"]
  discovery --> entries["Sensor entries"]
  report --> clocks["V5 clock decode"] --> registers[("Clock registers")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Configure I²C5 pads in the vendor SDK
  • ➕ Avoids temporarily changing pad muxing during detection.
  • ➖ Requires a modified SDK module or board configuration; stock DV500 installations would still miss SENSOR1.
2. Use a board-specific bus and pad map
  • ➕ Could avoid timeouts on unmuxed adapters and shorten reports.
  • ➖ Adds board-specific configuration and risks missing sensors on custom wiring.

Recommendation: Keep the reversible HAL setup and bounded bus sweep: they work with stock boards while preserving existing pad ownership and sensor-driver IDs. A board-specific bus map is worth considering separately if the measured report-time increase becomes significant.

Files changed (5) +374 / -34

Enhancement (1) +100 / -19
sensors.cReport sensors across I²C buses +100/-19

Report sensors across I²C buses

• Extends probing through bus 7 and adds one report entry per detected I²C sensor, avoiding buses already found empty in the first sweep. Preserves the first sensor’s process-global adapter and driver-facing ID, reports shared OS08A10/OS08A20 identity, and attaches pipeline information only to the first entry.

src/sensors.c

Bug fix (3) +161 / -14
clocks_v5.cCorrect V5 DDR throughput and decode DV500 CPU frequency +65/-7

Correct V5 DDR throughput and decode DV500 CPU frequency

• Includes both DRAM clock multiplication and double-edge transfers in the reported DDR data rate. Adds a DV500-only CPU entry derived from the selected fixed clock or APLL, leaving CV610 CPU reporting unchanged.

src/hal/hisi/clocks_v5.c

hal_hisi.cSafely prepare sensor clocks and DV500 I²C5 pads +90/-7

Safely prepare sensor clocks and DV500 I²C5 pads

• Selects 24 MHz when ungating an OT sensor clock still at its default selection, without changing running or explicitly selected clocks. On DV500, temporarily muxes eligible GPIO-input pads to I²C5 and restores them only while they retain the written value.

src/hal/hisi/hal_hisi.c

ispreg.hDefine OT sensor clock-select values +6/-0

Define OT sensor clock-select values

• Adds the clock-select mask and 24 MHz setting used when enabling reset-state CV610 and DV500 sensor clocks.

src/hal/hisi/ispreg.h

Tests (1) +113 / -1
hal_hisi_test.cCover sensor clock selection and I²C5 pad ownership +113/-1

Cover sensor clock selection and I²C5 pad ownership

• Expands fake-register capacity and adds cases for default, selected, and running clocks. Exercises DV500 pad setup, conflicting SPI or GPIO ownership, external re-muxing, non-DV500 behavior, and cleanup across a full sweep.

src/hal/hisi/hal_hisi_test.c

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

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Secondary HiSilicon sensors go undetected ✓ Resolved
Description
detect_sensors() calls i2c_bus_openable(bus) before assigning bus to i2c_adapter_nr, which
is the value the HiSilicon opener actually uses. If an earlier adapter is absent, its failed check
causes later valid adapters to be skipped, including a sensor on I2C5 after an I2C4 hit.

2. Chip queries leave GPIO pads remuxed ✓ Resolved
Description
setup_hal_hisi() immediately invokes the new DV500 pad arm, but pad restoration occurs only
through hisi_hal_cleanup(). A chip-name or clock query triggers setup without a sensor probe or
cleanup, so stock GPIO-input pads remain switched to I2C5 after the command exits.

3. Same sensor listed up to eight times ✓ Resolved
Description
The per-bus loop in detect_sensors() assumes open_i2c_sensor_fd() opens the requested adapter,
but several HAL openers ignore or rewrite i2c_adapter_nr: HiSilicon V1, XM V1, Allwinner, Tegra,
Rockchip, and Novatek can open a fixed or fallback device instead. When a sensor is present on one
of those transports, iterations for buses 0–7 can probe the same physical bus and append that sensor
under incorrect bus numbers, whereas the previous fallback sweep stopped at its first hit.


Remediation recommended

4. A failed probe can leave pads switched ✓ Resolved
Description
The new sweep arms the sensor state before get_sensor_id_i2c(), whose failed-open path returns
without calling hal_cleanup(). If the preliminary availability open succeeds but the probe’s
separate open fails, and no later probe completes cleanup, the DV500 pads remain in I2C5 mode.

5. DDR read failures hide the CPU clock ✓ Resolved
Description
v5_extra() calls v5_dv500_cpu() only after its DDR and PHY reads have all succeeded. If one of
those reads fails while the CPU-select register remains readable, the clock report omits the
independent CPU frequency entry.

6. Every report now probes devices on all buses ✓ Resolved
Description
Before this change other buses were probed only when the nominated bus had no sensor.
detect_sensors() now sweeps buses 0..7 after every successful i2c detection, on every platform.
The probes send two-byte register addresses, which a one-byte-address device takes as a register
write (the source says so at the SuperPix/GalaxyCore ordering), and some probes write page
registers. So any codec, MCU, PMIC or EEPROM that sits at a sensor address on another bus is now
written to on every ipctool run, and boards with unmuxed adapters spend extra seconds in timeouts.
The PR measured +2 s on the DV500 kit.


Informational

7. DDR rate comment now sits above the CPU helper ✓ Resolved
Description
The new v5_dv500_cpu() and its comment were inserted between the DDR data-rate comment block and
v5_extra(), which that block documents. A reader now sees the DDR derivation directly above an
unrelated CPU-clock function. The APLL decode was also copied inline rather than reusing the
existing PLL field table.

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

…nly for a probe

Review fixes (Qodo on #294):

- The extra sweep ran on every platform after every hit, and a probe is
  not a read: the two-byte register address is a write to a one-byte
  part, and some families write page registers. It is now opt-in through
  a new HAL global, hal_sensor_buses, and covers only the buses listed
  there. DV500 lists the vendor SDK's SENSOR0..3 buses, {4, 5, 3, 6}.
  Everywhere else the report stops at the first sensor, as before, and
  the fallback sweep is back to buses 0..5. This also rules out a sensor
  being listed under several bus numbers by an opener that ignores
  i2c_adapter_nr (V1, XM, Allwinner, Tegra, Rockchip, Novatek): only a
  HAL whose opener honours it may set the list.
- i2c_bus_openable() was called before i2c_adapter_nr was set, and every
  opener reads the global, so it tested the previous adapter.
- setup_hal_hisi() arms the clocks, and with them the DV500 pads, but a
  chip-name or clocks query never reaches the cleanup that puts the pads
  back. The pads are now armed only by hal_enable_sensor_clock, which is
  to say by a probe; setup still arms the clocks alone, as before.
- A probe whose own open fails returns without a cleanup; the sweep now
  runs one after any failed probe. A cleanup after one that already ran
  is a no-op, because each undo is spent.
- clocks: the DV500 CPU decoder runs first, on its own registers, so a
  failed DDR PHY read no longer hides it. It reads the APLL through the
  PLL table, via a new pll_read_freq_mhz() that decode_pll() now shares,
  instead of a second copy of the field layout. It moved above the DDR
  comment, which again sits directly over v5_extra().

hal_hisi_test checks that setup alone leaves the pads alone; that check
fails if setup arms them. It also checks that hal_sensor_buses is set on
DV500 and on nothing else.

On the DV500 kit: `ipctool -c` and `ipctool clocks` leave stock pads at
0x1300; the report finds both sensors with stock pads (restored after),
muxed pads, and sensor CRGs at reset; 14.6 s instead of 15.0 s.
ipcinfo is unchanged in size on arm32.
@widgetii
widgetii merged commit f4d91c5 into master Nov 24, 2026
5 checks passed
@widgetii
widgetii deleted the dv500-multisensor branch November 24, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant