Skip to content

sensors: detect Sony IMX662 (Starvis 2) - #274

Merged
dimerr merged 1 commit into
masterfrom
sensors-imx662
Nov 9, 2026
Merged

dimerr merged 1 commit into
masterfrom
sensors-imx662

Conversation

@dimerr

@dimerr dimerr commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

detect_sony_sensor() has no IMX662 entry, so a camera carrying one reports "No sensor detected". On a Hi3516CV610 the probe path already reaches the sensor correctly (sony_addrs = {0x34} → 0x34>>1 = 0x1a on /dev/i2c-0, 16-bit register reads) — the decision tree was simply missing the leaf, so auto-detection (and the firmware's SENSOR auto-set) fell through to unknown.

Fix

Add an IMX662 branch keyed on 0x3B00:

  • 0x41 at power-on reset — the state boot-time auto-detection reads
  • 0x39 after the standard init ("Set to 39h", IMX662 Standard Register Setting v2.0)

Both are distinct from IMX415's 0x2E/0x28 ruled out just above. 0x341C == 0x01 (IMX334 reads 0x47 there) confirms and holds in either state; the branch sits after the IMX415 check so nothing else is perturbed.

Verification

Tested on a live IMX662 on a Hi3516CV610 over both states:

sensor state 0x3B00 ipctool -s
power-on reset (boot) 0x41 imx662_i2c
configured (streaming) 0x39 imx662_i2c

Register values cross-checked against the IMX662 Standard Register Setting v2.0 datasheet. Unit test (sensors_test.c) added for both 0x3B00 values; sensors_test passes. Cross-builds clean with the 32-bit ARM musl toolchain.

detect_sony_sensor() had no IMX662 entry, so a camera carrying one came
back "no sensor detected" -- e.g. a Hi3516CV610, where the probe path
already reaches the sensor (0x34>>1 = 0x1a on /dev/i2c-0) and only the
decision tree was missing a leaf.

Key on 0x3B00: 0x41 at power-on reset -- the state at boot-time
auto-detection -- and 0x39 after the standard init ("Set to 39h", IMX662
Standard Register Setting v2.0); both distinct from IMX415's 0x2E/0x28
ruled out just above. 0x341C=0x01 (IMX334 reads 0x47 there) confirms and
holds in either state. Verified on a live IMX662 on a Hi3516CV610 in both
reset and configured states; the unit test covers both 0x3B00 values.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Detect Sony IMX662 at reset and after initialization

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Identify IMX662 in both reset and configured states instead of reporting no sensor detected.
• Confirm its register signature without changing earlier Sony sensor matches.
• Add mock-bus tests for both detection states.
Diagram

graph TD
  A["Sony probe"] --> B["Existing checks"] --> C{"IMX662 signature?"} -->|yes| D["IMX662 ID"]
  C -->|no| E["Other Sony checks"]
Loading
High-Level Assessment

Adding a guarded branch to the existing Sony decision tree is appropriate: the probe already reaches the sensor, and the two register values distinguish its observed states. A separate probe or identification table would add complexity without addressing a routing problem.

Files changed (2) +34 / -0

Bug fix (1) +11 / -0
sensors.cRecognize the IMX662 register signature +11/-0

Recognize the IMX662 register signature

• Adds an IMX662 branch after the IMX415 check. It accepts reset and initialized values at 0x3B00, confirms 0x341C, and returns the IMX662 model.

src/sensors.c

Tests (1) +23 / -0
sensors_test.cCover IMX662 detection in both sensor states +23/-0

Cover IMX662 detection in both sensor states

• Adds mock-register cases that verify IMX662 identification with 0x3B00 at its reset and configured values.

src/sensors_test.c

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@dimerr
dimerr merged commit 4b0c092 into master Nov 9, 2026
5 checks passed
@dimerr
dimerr deleted the sensors-imx662 branch November 9, 2026 13:58
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