Skip to content

load_goke: opt-in sensor_dvp / sensor_mclk gate for DVP-wired boards - #2276

Open
bneigher wants to merge 1 commit into
OpenIPC:masterfrom
bneigher:w7-dvp-sensor-gate
Open

load_goke: opt-in sensor_dvp / sensor_mclk gate for DVP-wired boards#2276
bneigher wants to merge 1 commit into
OpenIPC:masterfrom
bneigher:w7-dvp-sensor-gate

Conversation

@bneigher

Copy link
Copy Markdown

Adds an opt-in env-var gate so DVP-wired boards can select the DVP pad
routing, without changing behaviour for anything that does not ask for it.

open_sys_config picks MIPI or DVP pad routing from its chip= and
g_cmos_yuv_flag= arguments. On a board that routes the sensor's parallel data,
sync, PCLK and i2c to the SoC's DVP pads, the MIPI arguments mux the i2c
controller to pads the sensor is not connected to — every address NACKs, no chip
ID is ever read, and no video is possible.

Per @widgetii's review note on #2074, this is keyed off an env
var rather than $CHIP_TYPE:

chip=gk7205v200 g_cmos_yuv_flag=1 is right for your W7 wiring but wrong for
MIPI-wired gk7202v300 boards, and there are some in the wild — a blanket change
would break them.

So a profile opts in with fw_setenv sensor_dvp 1. Unset — every existing board —
takes exactly the path it takes today.

sensor_mclk is gated the same way. open_sys_config reads MCLK only from its
module parameters and defaults to 27 MHz at this chip=, so a sensor init table
tuned for 24 MHz (the GC2053 ForCar tables are) runs against the wrong clock.
Worth noting for anyone who hits this: the .ini MCLK key is not consulted on
this path, so sweeping it produces identical results at every value — which is
indistinguishable from having ruled the cause out. That cost me a while.

Companion to the gk7202v300_lite_w7_8m device profile in OpenIPC/builder,
which is where the board-specific bring-up lives.

Verified on three GK-W7 boards (GK7202V300, 8 MB NOR, GC2053 in DVP mode with
SID strapped high): with sensor_dvp=1 and sensor_mclk=24 the i2c bus comes
up, the sensor answers at 7-bit 0x3f with chip ID 0x2053, and the pipeline
delivers 1920x1080 H.264 over RTSP at 25 fps with FrmErrCnt 0. With the vars
unset the script is byte-for-byte equivalent in behaviour to before.

sh -n clean.

Refs: #2074

open_sys_config picks MIPI or DVP pad routing from its chip= and
g_cmos_yuv_flag= arguments. On a board that wires the sensor to the DVP pads,
the MIPI arguments mux the i2c controller to pads the sensor is not connected
to, so every address NACKs and no sensor is ever detected.

Gated on an env var rather than $CHIP_TYPE deliberately: both wirings exist on
gk7202v300, so keying this off the SoC name would fix DVP boards by breaking
every MIPI one. Profiles opt in with 'fw_setenv sensor_dvp 1'; unset means the
current behaviour is unchanged.

sensor_mclk is gated the same way. open_sys_config reads MCLK only from its
module parameters and defaults to 27 MHz at this chip=, so a sensor init table
tuned for 24 MHz runs against the wrong clock -- and the ini's MCLK key is never
consulted on this path, which makes sweeping it look like a ruled-out cause.

Refs: OpenIPC#2074
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

load_goke: opt-in sensor_dvp/sensor_mclk gates for DVP-wired boards

🐞 Bug fix ✨ Enhancement ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Add opt-in sensor_dvp=1 gate to force DVP pad routing without changing defaults.
• Add opt-in sensor_mclk=24 gate to override MCLK when .ini MCLK is ignored.
• Document why env-var gating is used instead of $CHIP_TYPE to avoid regressions.
Diagram

graph TD
  Profile["Device profile"] --> Env[("U-Boot env vars") ] --> Script["load_goke"] --> SysCfg["open_sys_config"] --> I2C["Sensor I2C bus"] --> Sensor["DVP sensor"]
  Script --> Mclk{"sensor_mclk=24?"} --> Devmem["devmem MCLK reg"]
  subgraph Legend
    direction LR
    _cfg["Config/Script"] ~~~ _env[("Env storage")] ~~~ _dec{"Decision"}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Auto-detect DVP vs MIPI via probe fallback
  • ➕ No per-board env configuration required
  • ➕ Can self-heal on misconfigured profiles
  • ➖ Risky/slow boot path (extra probe attempts/timeouts)
  • ➖ Detection may be ambiguous across sensors/boards
  • ➖ Harder to reason about regressions vs explicit opt-in
2. Key routing off `$CHIP_TYPE` or SoC table
  • ➕ Simple implementation; no tooling dependency on U-Boot env
  • ➖ Incorrect when multiple wirings exist for the same SoC (explicitly noted for gk7202v300)
  • ➖ High regression risk for existing MIPI-wired boards
3. Fix in `open_sys_config` to read `.ini` MCLK / add explicit DVP flag
  • ➕ Moves policy into the driver/module where the behavior originates
  • ➕ Avoids devmem register pokes from userland
  • ➖ Requires kernel/module changes and broader validation across boards
  • ➖ Longer turnaround; potentially larger blast radius

Recommendation: Keep the current env-var opt-in gates in load_goke: it’s the lowest-regression approach given mixed DVP/MIPI wiring on the same SoC family. If this pattern expands, consider a follow-up to make open_sys_config accept an explicit DVP/MCLK override (or consult .ini MCLK) to eliminate the devmem workaround.

Files changed (1) +23 / -0

Bug fix (1) +23 / -0
load_gokeAdd opt-in DVP routing and 24 MHz MCLK override via U-Boot env +23/-0

Add opt-in DVP routing and 24 MHz MCLK override via U-Boot env

• Introduces an opt-in 'sensor_dvp=1' gate that forces 'CHIP_TYPE=gk7205v200' and 'YUV_TYPE0=1' so 'open_sys_config' selects DVP pad routing on DVP-wired boards, while preserving default behavior when unset. Adds an opt-in 'sensor_mclk=24' gate to write the MCLK register via 'devmem' because this path does not consult the '.ini' MCLK key and defaults to 27 MHz.

general/package/goke-osdrv-gk7205v200/files/script/load_goke

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Silent MCLK write failure 🐞 Bug ☼ Reliability
Description
insert_ko adds a devmem write when sensor_mclk=24 but does not check whether devmem exists or
whether the write succeeded, so the script can continue with the wrong MCLK while giving no
diagnostic. This can make sensor bring-up fail with little/no signal in logs.
Code

general/package/goke-osdrv-gk7205v200/files/script/load_goke[R188-190]

+	case "$(fw_printenv -n sensor_mclk 2>/dev/null)" in
+		24) devmem 0x120100F0 32 0x0000000D ;;
+	esac
Evidence
The new MCLK path performs a raw devmem write with no || report_error handling, while the script
otherwise uses report_error for module load failures, indicating this omission is an introduced
reliability gap.

general/package/goke-osdrv-gk7205v200/files/script/load_goke[82-106]
general/package/goke-osdrv-gk7205v200/files/script/load_goke[179-190]

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

### Issue description
A new `devmem`-based MCLK override is executed without checking for tool presence or write success. If the write fails, the script continues silently, leaving the system misconfigured.

### Issue Context
This is a shared boot-time module loader script; failures should be explicit to avoid hard-to-debug field breakage.

### Fix Focus Areas
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[184-190]

### Suggested fix
- Check `command -v devmem` before use.
- Check `devmem` exit status; on failure, emit a `logger` message (daemon.err) and either `report_error` or explicitly continue with a warning (but do not fail silently).

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


2. CHIP_TYPE role conflation 🐞 Bug ⚙ Maintainability
Description
The sensor_dvp opt-in block overwrites the detected CHIP_TYPE globally, conflating the actual SoC
identity with the value intended to steer open_sys_config routing. This makes later CHIP_TYPE-based
logic (present now or added later) harder to reason about and increases the risk of unintended
behavior changes when extending the script.
Code

general/package/goke-osdrv-gk7205v200/files/script/load_goke[R35-38]

+if [ "$(fw_printenv -n sensor_dvp 2>/dev/null)" = "1" ]; then
+	CHIP_TYPE=gk7205v200
+	YUV_TYPE0=1
+fi
Evidence
CHIP_TYPE is initially derived from ipcinfo --chip-name, then globally overwritten by the new
sensor_dvp gate, and subsequently reused as the chip= argument to open_sys_config (and as a
general chip discriminator elsewhere in the script).

general/package/goke-osdrv-gk7205v200/files/script/load_goke[4-10]
general/package/goke-osdrv-gk7205v200/files/script/load_goke[24-38]
general/package/goke-osdrv-gk7205v200/files/script/load_goke[109-115]
general/package/goke-osdrv-gk7205v200/files/script/load_goke[179-184]

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

### Issue description
`sensor_dvp=1` currently mutates `CHIP_TYPE` (the detected SoC name) for the remainder of the script. This mixes two concepts:
- detected SoC (used for chip-specific branching)
- desired `open_sys_config chip=` selector (used for pad routing selection)

### Issue Context
This script is shared across multiple Goke SoCs/boards; minimizing global state mutation reduces future regressions.

### Fix Focus Areas
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[4-10]
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[24-38]
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[109-115]
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[179-184]

### Suggested fix
- Introduce e.g. `SYS_CONFIG_CHIP="$CHIP_TYPE"` after detection.
- In the `sensor_dvp` block, set `SYS_CONFIG_CHIP=gk7205v200` (and keep `CHIP_TYPE` unchanged).
- Pass `chip=$SYS_CONFIG_CHIP` to `modprobe open_sys_config` in both `insert_detect` and `insert_ko`.

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


Grey Divider

Context

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +188 to +190
case "$(fw_printenv -n sensor_mclk 2>/dev/null)" in
24) devmem 0x120100F0 32 0x0000000D ;;
esac

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Silent mclk write failure 🐞 Bug ☼ Reliability

insert_ko adds a devmem write when sensor_mclk=24 but does not check whether devmem exists or
whether the write succeeded, so the script can continue with the wrong MCLK while giving no
diagnostic. This can make sensor bring-up fail with little/no signal in logs.
Agent Prompt
### Issue description
A new `devmem`-based MCLK override is executed without checking for tool presence or write success. If the write fails, the script continues silently, leaving the system misconfigured.

### Issue Context
This is a shared boot-time module loader script; failures should be explicit to avoid hard-to-debug field breakage.

### Fix Focus Areas
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[184-190]

### Suggested fix
- Check `command -v devmem` before use.
- Check `devmem` exit status; on failure, emit a `logger` message (daemon.err) and either `report_error` or explicitly continue with a warning (but do not fail silently).

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

Comment on lines +35 to +38
if [ "$(fw_printenv -n sensor_dvp 2>/dev/null)" = "1" ]; then
CHIP_TYPE=gk7205v200
YUV_TYPE0=1
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

2. Chip_type role conflation 🐞 Bug ⚙ Maintainability

The sensor_dvp opt-in block overwrites the detected CHIP_TYPE globally, conflating the actual SoC
identity with the value intended to steer open_sys_config routing. This makes later CHIP_TYPE-based
logic (present now or added later) harder to reason about and increases the risk of unintended
behavior changes when extending the script.
Agent Prompt
### Issue description
`sensor_dvp=1` currently mutates `CHIP_TYPE` (the detected SoC name) for the remainder of the script. This mixes two concepts:
- detected SoC (used for chip-specific branching)
- desired `open_sys_config chip=` selector (used for pad routing selection)

### Issue Context
This script is shared across multiple Goke SoCs/boards; minimizing global state mutation reduces future regressions.

### Fix Focus Areas
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[4-10]
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[24-38]
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[109-115]
- general/package/goke-osdrv-gk7205v200/files/script/load_goke[179-184]

### Suggested fix
- Introduce e.g. `SYS_CONFIG_CHIP="$CHIP_TYPE"` after detection.
- In the `sensor_dvp` block, set `SYS_CONFIG_CHIP=gk7205v200` (and keep `CHIP_TYPE` unchanged).
- Pass `chip=$SYS_CONFIG_CHIP` to `modprobe open_sys_config` in both `insert_detect` and `insert_ko`.

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

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