From b838601c4221aaaa6e9cf57e355854f2df6e0814 Mon Sep 17 00:00:00 2001 From: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com> Date: Tue, 3 Nov 2026 08:44:38 +0100 Subject: [PATCH 1/4] media: i2c: ov9734: Add reset GPIO, regulator and clock handling 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 Patchset: cameras --- drivers/media/i2c/ov9734.c | 93 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/ov9734.c b/drivers/media/i2c/ov9734.c index 0eaf33807fc92..984d10e0cae80 100644 --- a/drivers/media/i2c/ov9734.c +++ b/drivers/media/i2c/ov9734.c @@ -4,9 +4,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -27,6 +29,14 @@ #define OV9734_MODE_STANDBY 0x00 #define OV9734_MODE_STREAMING 0x01 +static const char * const ov9734_supply_names[] = { + "avdd", /* Analog power */ + "dovdd", /* Digital I/O power */ + "dvdd", /* Digital core power */ +}; + +#define OV9734_NUM_SUPPLIES ARRAY_SIZE(ov9734_supply_names) + /* vertical-timings from sensor */ #define OV9734_REG_VTS 0x380e #define OV9734_VTS_30FPS 0x0322 @@ -325,6 +335,8 @@ static const struct ov9734_mode supported_modes[] = { struct ov9734 { struct device *dev; struct clk *clk; + struct gpio_desc *reset; + struct regulator_bulk_data supplies[OV9734_NUM_SUPPLIES]; struct v4l2_subdev sd; struct media_pad pad; @@ -805,6 +817,45 @@ static const struct v4l2_subdev_internal_ops ov9734_internal_ops = { .open = ov9734_open, }; +static int ov9734_power_off(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct ov9734 *ov9734 = to_ov9734(sd); + + gpiod_set_value_cansleep(ov9734->reset, 1); + clk_disable_unprepare(ov9734->clk); + regulator_bulk_disable(OV9734_NUM_SUPPLIES, ov9734->supplies); + + return 0; +} + +static int ov9734_power_on(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct ov9734 *ov9734 = to_ov9734(sd); + int ret; + + ret = regulator_bulk_enable(OV9734_NUM_SUPPLIES, ov9734->supplies); + if (ret) { + dev_err(dev, "failed to enable regulators: %d", ret); + return ret; + } + + ret = clk_prepare_enable(ov9734->clk); + if (ret) { + dev_err(dev, "failed to enable clock: %d", ret); + regulator_bulk_disable(OV9734_NUM_SUPPLIES, ov9734->supplies); + return ret; + } + + usleep_range(1000, 2000); + gpiod_set_value_cansleep(ov9734->reset, 0); + /* 8192 xvclk cycles before the first SCCB transaction, with margin */ + usleep_range(5000, 6000); + + return 0; +} + static int ov9734_identify_module(struct ov9734 *ov9734) { int ret; @@ -881,6 +932,8 @@ static void ov9734_remove(struct i2c_client *client) media_entity_cleanup(&sd->entity); v4l2_ctrl_handler_free(sd->ctrl_handler); pm_runtime_disable(ov9734->dev); + if (!pm_runtime_status_suspended(ov9734->dev)) + ov9734_power_off(ov9734->dev); pm_runtime_set_suspended(ov9734->dev); mutex_destroy(&ov9734->mutex); } @@ -915,11 +968,31 @@ static int ov9734_probe(struct i2c_client *client) "external clock %lu is not supported", freq); + ov9734->reset = devm_gpiod_get_optional(ov9734->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(ov9734->reset)) + return dev_err_probe(ov9734->dev, PTR_ERR(ov9734->reset), + "failed to get reset gpio\n"); + + for (unsigned int i = 0; i < OV9734_NUM_SUPPLIES; i++) + ov9734->supplies[i].supply = ov9734_supply_names[i]; + + ret = devm_regulator_bulk_get(ov9734->dev, OV9734_NUM_SUPPLIES, + ov9734->supplies); + if (ret) + return dev_err_probe(ov9734->dev, ret, + "failed to get regulators\n"); + v4l2_i2c_subdev_init(&ov9734->sd, client, &ov9734_subdev_ops); + + ret = ov9734_power_on(ov9734->dev); + if (ret) + return ret; + ret = ov9734_identify_module(ov9734); if (ret) { dev_err(ov9734->dev, "failed to find sensor: %d", ret); - return ret; + goto probe_error_power_off; } mutex_init(&ov9734->mutex); @@ -941,10 +1014,7 @@ static int ov9734_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } - /* - * Device is already turned on by i2c-core with ACPI domain PM. - * Enable runtime PM and turn off the device. - */ + /* Device is powered on above. Enable runtime PM and turn it off. */ pm_runtime_set_active(ov9734->dev); pm_runtime_enable(ov9734->dev); pm_runtime_idle(ov9734->dev); @@ -960,16 +1030,28 @@ static int ov9734_probe(struct i2c_client *client) probe_error_media_entity_cleanup_pm: pm_runtime_disable(ov9734->dev); + if (!pm_runtime_status_suspended(ov9734->dev)) + ov9734_power_off(ov9734->dev); pm_runtime_set_suspended(ov9734->dev); media_entity_cleanup(&ov9734->sd.entity); + v4l2_ctrl_handler_free(ov9734->sd.ctrl_handler); + mutex_destroy(&ov9734->mutex); + + return ret; probe_error_v4l2_ctrl_handler_free: v4l2_ctrl_handler_free(ov9734->sd.ctrl_handler); mutex_destroy(&ov9734->mutex); +probe_error_power_off: + ov9734_power_off(ov9734->dev); + return ret; } +static DEFINE_RUNTIME_DEV_PM_OPS(ov9734_pm_ops, ov9734_power_off, + ov9734_power_on, NULL); + static const struct acpi_device_id ov9734_acpi_ids[] = { { "OVTI9734", }, {} @@ -981,6 +1063,7 @@ static struct i2c_driver ov9734_i2c_driver = { .driver = { .name = "ov9734", .acpi_match_table = ov9734_acpi_ids, + .pm = pm_ptr(&ov9734_pm_ops), }, .probe = ov9734_probe, .remove = ov9734_remove, From fb562f728358cd138af6a581e0b16b7457b00373 Mon Sep 17 00:00:00 2001 From: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com> Date: Tue, 3 Nov 2026 08:44:38 +0100 Subject: [PATCH 2/4] media: ipu-bridge: Add OV9734 for the Surface Laptop 1/2 front camera 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 Patchset: cameras --- drivers/media/pci/intel/ipu-bridge.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 271b987660c5c..10a1a6e52acbd 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -101,6 +101,8 @@ static const struct ipu_sensor_config ipu_supported_sensors[] = { IPU_SENSOR_CONFIG("OVTI5675", 1, 450000000), /* Omnivision OV8856 */ IPU_SENSOR_CONFIG("OVTI8856", 3, 180000000, 360000000, 720000000), + /* Omnivision OV9734 - Surface Laptop 1/2 front camera */ + IPU_SENSOR_CONFIG("OVTI9734", 1, 180000000), /* Sony IMX471 */ IPU_SENSOR_CONFIG("SONY471A", 1, 200000000), /* Sony IMX471 (found on Lenovo X1 Carbon G14) */ From 8b5e01ccb344f179454390d7e548b041768a0ed2 Mon Sep 17 00:00:00 2001 From: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:34:12 +0100 Subject: [PATCH 3/4] media: i2c: ov9734: Defer probe until the fwnode graph is ready 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 --- drivers/media/i2c/ov9734.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov9734.c b/drivers/media/i2c/ov9734.c index 984d10e0cae80..1ae0d4e0095b4 100644 --- a/drivers/media/i2c/ov9734.c +++ b/drivers/media/i2c/ov9734.c @@ -887,9 +887,13 @@ static int ov9734_check_hwcfg(struct device *dev) if (!fwnode) return -ENXIO; + /* + * The fwnode graph may be created by a bridge driver such as + * ipu-bridge, which can probe after the sensor. Wait for it. + */ ep = fwnode_graph_get_next_endpoint(fwnode, NULL); if (!ep) - return -ENXIO; + return -EPROBE_DEFER; ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); fwnode_handle_put(ep); @@ -945,11 +949,9 @@ static int ov9734_probe(struct i2c_client *client) int ret; ret = ov9734_check_hwcfg(&client->dev); - if (ret) { - dev_err(&client->dev, "failed to check HW configuration: %d", - ret); - return ret; - } + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to check HW configuration\n"); ov9734 = devm_kzalloc(&client->dev, sizeof(*ov9734), GFP_KERNEL); if (!ov9734) From ef23da9577364811186a609800cffd5b42cb2f69 Mon Sep 17 00:00:00 2001 From: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com> Date: Mon, 30 Nov 2026 12:08:32 +0100 Subject: [PATCH 4/4] media: i2c: ov9734: Use runtime PM callbacks only 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 Link: https://github.com/linux-surface/linux-surface/issues/2401 Signed-off-by: GuyliandeJong <109021171+GuyliandeJong@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/media/i2c/ov9734.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov9734.c b/drivers/media/i2c/ov9734.c index 1ae0d4e0095b4..8876c8db4a6fd 100644 --- a/drivers/media/i2c/ov9734.c +++ b/drivers/media/i2c/ov9734.c @@ -1051,8 +1051,14 @@ static int ov9734_probe(struct i2c_client *client) return ret; } -static DEFINE_RUNTIME_DEV_PM_OPS(ov9734_pm_ops, ov9734_power_off, - ov9734_power_on, NULL); +/* + * Runtime PM callbacks only: ipu3-cio2 stops and restarts the sensor across + * system sleep through .s_stream(), so system sleep callbacks here would race + * with it. + */ +static const struct dev_pm_ops ov9734_pm_ops = { + RUNTIME_PM_OPS(ov9734_power_off, ov9734_power_on, NULL) +}; static const struct acpi_device_id ov9734_acpi_ids[] = { { "OVTI9734", },