Skip to content

Add front camera support for Surface Laptop 1/2 (OV9734) - #186

Open
GuyliandeJong wants to merge 4 commits into
linux-surface:v7.3-surface-develfrom
GuyliandeJong:surface-laptop-2-front-camera
Open

GuyliandeJong wants to merge 4 commits into
linux-surface:v7.3-surface-develfrom
GuyliandeJong:surface-laptop-2-front-camera

Conversation

@GuyliandeJong

Copy link
Copy Markdown

This adds front camera support for the Surface Laptop 2 (and, by the same ACPI layout, most likely the Surface Laptop 1). The feature matrix currently lists cameras as unsupported on both.

Hardware

From the DSDT of a Surface Laptop 2 (Surface_Laptop_2_1769_Consumer):

  • Front camera: \_SB_.PCI0.I2C2.CAMF, HID OVTI9734 (OV9734), I2C address 0x36, with _DEP on SKC1
  • SSDB: CSI-2 link 1, 1 lane, 19.2 MHz MCLK, degree 0, privacy LED present
  • SKC1 is a discrete INT3472 with three GPIOs: 0x78 clock enable, 0x4D reset, 0x16 privacy LED. There is no power-enable GPIO.
  • The IR camera (INT347E, OV7251) on link 2 behind SKC2 already worked before this change.

Changes

  1. ov9734: add reset GPIO, regulator and clock handling. The driver never enabled its clock or released reset, so the sensor did not answer on I2C. It now requests the optional reset GPIO and the avdd/dovdd/dvdd supplies, powers the sensor on before identifying it, and uses the power functions as runtime PM callbacks.
  2. ipu-bridge: add OVTI9734 with the 180 MHz link frequency required by the driver. Without this, probing fails with failed to check HW configuration: -6.

Testing (Surface Laptop 2, 7.2.14-arch1-1-surface with these two modules rebuilt)

ipu3-cio2 0000:00:14.3: Found supported sensor INT347E:00
ipu3-cio2 0000:00:14.3: Found supported sensor OVTI9734:00
ipu3-cio2 0000:00:14.3: Connected 2 cameras
  • ov9734 2-0036 is linked to ipu3-csi2 1, and raw capture from the CIO2 gives correct 1296x734 SGRBG10 frames.
  • Runtime PM suspend and resume work across repeated captures.
  • With libcamera's IPU3 pipeline, it streams at about 30 fps via cam and via PipeWire. Tested at 320x240, 640x480, 1024x576 and 1280x704.

Userspace note

libcamera 0.7.2 also needs changes before the camera is usable by apps. I plan to send these to libcamera upstream separately:

  • an ov9734 CameraSensorHelper (linear gain {1, 0, 0, 16}, black level 64 at 10 bits)
  • initialise testPatternMode_ in CameraSensorLegacy/CameraSensorRaw. It is uninitialised, so start() fails at random for sensors without a test pattern map.
  • avoid an unsigned underflow in the IPU3 calculateBDSHeight(). For sensors shorter than 1080 lines it inverts the std::clamp bounds and aborts. Also cap the advertised viewfinder size to what validate() actually allows.

🤖 Generated with Claude Code

@Dvaderfun

Copy link
Copy Markdown

First-generation Surface Laptop confirmation: the OV9734 front color camera works on a real SL1, using the three patches in linux-surface/linux-surface#2401. This is independent evidence for the hardware assumption in this PR. The two series are not identical, so this is not a Tested-by for bdd5d113.

  • Machine: DMI SKU Surface_Laptop, firmware 138.3732.768; Fedora 45 with 7.3.4-2.surface and Secure Boot enabled. OVTI9734 / MSHW0073, I²C2 0x36, one lane on CSI-2 port 1, 19.2 MHz external clock. Its discrete INT3472 exposes a clock gate, reset and privacy LED.
  • The single 180 MHz link frequency plus clock/reset sequencing allowed real color capture. With a patched libcamera IPU3 pipeline and PipeWire, GNOME Camera previewed 1280×720 and independent captures returned 60 timestamped frames at 30.3–30.4 fps. Closing capture let the sensor suspend. This is the RGB sensor, not the separate OV7251.

Two differences from the tested series matter when updating this PR to v7.3-surface-devel:

  1. ov9734_check_hwcfg() still returns -ENXIO if the IPU bridge hasn't created the endpoint yet. When sensor probing wins that race it may never retry. Sam's second patch in #2401 returns -EPROBE_DEFER; it applies on top of this PR.
  2. DEFINE_RUNTIME_DEV_PM_OPS also installs system-sleep callbacks. Both it and CIO2 can then change power around active-stream suspend. In #2401, the author reports a failed register write (-121) on SL2 after s2idle with this macro; using only RUNTIME_PM_OPS fixed that test. Please keep the runtime callbacks, avoid registering forced system-sleep callbacks, and test both an idle camera and an active stream across suspend on the final branch. No SL1 system-sleep result is claimed here.

The SL1 results used no new regulator requests; the optional GPIO/clock sequence is sufficient for this wiring. The regulator paths and timing differences in this PR still merit their own coverage. The working color variant also compiles on current v7.3-surface-devel (96cd24ea) with W=1. The two follow-ups can be reviewed independently on this PR. The driver changes belong in the kernel source repository; the generated patches/*/0013-cameras.patch need not be edited by hand.

Two suggested follow-ups on this exact PR head · 7.3 alternative with original attribution · fresh libcamera build and the separate single-stream 720p RFC.

GuyliandeJong and others added 4 commits November 30, 2026 12:32
The ov9734 driver assumes the sensor is already powered by ACPI domain
PM and never drives a reset line or enables its clock. On the Surface
Laptop 1 and 2, the sensor (OVTI9734) is powered through a discrete
INT3472 device (SKC1) which exposes a clock-enable GPIO, a reset GPIO
and a privacy LED. Without toggling these, the sensor never answers on
I2C.

Request the optional "reset" GPIO and the avdd/dovdd/dvdd supplies, and
add power on/off functions that enable the regulators and the clock and
release the reset line. Power the sensor on before identifying it and
hook the functions up as runtime PM callbacks.

Tested on a Surface Laptop 2: the sensor is identified and streams via
the IPU3 CIO2 and ImgU with libcamera.

Signed-off-by: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Patchset: cameras
The front camera of the Surface Laptop 1 and 2 is an OmniVision OV9734
(ACPI HID OVTI9734), connected to CSI-2 port 1 of the IPU3 with one
data lane. Without an entry in the supported sensor list, the bridge
does not build the fwnode graph for it and the ov9734 driver fails to
probe with "failed to check HW configuration: -6".

Add the sensor with the 180 MHz link frequency required by the ov9734
driver.

Tested on a Surface Laptop 2 together with the ov9734 power handling
change: the bridge reports two connected cameras and the front camera
streams with libcamera.

Signed-off-by: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Patchset: cameras
On the Surface Laptop 2 the fwnode graph of the sensor is created by
ipu-bridge, which can probe after the ov9734 driver. The driver then
finds no endpoint, fails with -ENXIO and is never probed again, leaving
the camera missing until the module is reloaded. This happened on about
one boot in two.

Return -EPROBE_DEFER when the endpoint is missing, as other sensor
drivers used with ipu-bridge do, and report the error with
dev_err_probe() so that deferral doesn't log an error.

Signed-off-by: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DEFINE_RUNTIME_DEV_PM_OPS() also installs pm_runtime_force_suspend() and
pm_runtime_force_resume() as system sleep callbacks. ipu3-cio2 already
stops and restarts the sensor across system sleep through .s_stream(), and
the two are not ordered against each other, so the sensor can be powered
off while the bridge still uses it, or written to before it is powered on
again. With a stream running across s2idle this ends in a failed register
write (-121) on resume.

Register the runtime PM callbacks only, as ov5693, ov7251 and ov8865 do.

Reported-by: Sam <sammydirksz@gmail.com>
Link: linux-surface/linux-surface#2401
Signed-off-by: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GuyliandeJong
GuyliandeJong force-pushed the surface-laptop-2-front-camera branch from bdd5d11 to ef23da9 Compare November 30, 2026 11:36
@GuyliandeJong
GuyliandeJong changed the base branch from v7.2-surface-devel to v7.3-surface-devel November 30, 2026 11:36
@GuyliandeJong

Copy link
Copy Markdown
Author

Thanks for testing this on a real SL1. That confirms the SL1 has the same wiring as the SL2.

  1. Probe race: agreed. I hit the same race here, on about one boot in two. Commit 8b5e01ccb344 ("media: i2c: ov9734: Defer probe until the fwnode graph is ready") returns -EPROBE_DEFER and uses dev_err_probe(). Since then the camera has been present on every boot without reloading the module.

  2. System sleep: agreed. Commit ef23da957736 ("media: i2c: ov9734: Use runtime PM callbacks only") replaces DEFINE_RUNTIME_DEV_PM_OPS with RUNTIME_PM_OPS, like ov5693, ov7251 and ov8865. s2idle on the SL2 with this change:

    • without the change: I could reproduce what was reported in Surface Laptop 2 front camera (OV9734) working on 7.3.4-surface with three small patches linux-surface#2401. With a stream running across a 10 s s2idle, resume fails with write reg 0x3030 return err = -121 and failed to set plls, followed by ipu3-cio2: pci_pm_resume returns -121. The stream stops, and stopping it afterwards gives a sd->s_stream_enabled == !!enable warning in call_s_stream(). The module also stays in use until a reboot. An idle camera was not affected.
    • with the change: with the camera idle, a new capture after resume gives 30/30 frames. With a stream running, the stream continues after resume (460 frames, seq 0 to 459 without loss), with no sensor or CIO2 errors, and a new capture afterwards also works.

    Tested on the SL2 with 7.3.6-arch1-1-surface. The only remaining message is ipu3-imgu: wait buffer drain timeout, which also appears without the change.

The PR is now rebased onto v7.3-surface-devel (96cd24ea) and includes both commits. The driver code is the same as the version tested above.

For context: Tin Posavec's upstream series "media: ov9734, ipu-bridge: Enable the camera on the Intel NUC M15" covers the same changes for mainline. Its ipu-bridge entry is already in media next. On the SL2, v2 2/3 fails to probe (failed to find sensor: -121), because the sensor needs at least 1 ms after reset is released and v2 waits 427 µs. I reported this on linux-media and offered to test v3. Once that series is merged, the driver part of this PR can be replaced by a backport.

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.

2 participants