From 7353fd8d0fa204737b9f50dd477a626bc3270296 Mon Sep 17 00:00:00 2001 From: Lois Breant <185382558+loisBreant@users.noreply.github.com> Date: Fri, 23 Oct 2026 03:03:32 +0300 Subject: [PATCH] media: i2c: ov5693: Gate the MIPI clock lane for IPU6 Surface front cameras On the IPU6 Surface devices (Pro 8, Pro 9, Go 4) the front ov5693 starts streaming but the IPU6 CSI-2 receiver never gets a frame: the receiver needs the sensor to gate its clock lane when idle (non-continuous clock), which the driver never configures. Set MIPI_CTRL00 (0x4800) bit 5 (clock lane gate) before stream-on when the endpoint is non-continuous. As this kernel's ipu-bridge does not set "clock-noncontinuous" yet, also enable it for the OVTI5693 HID, which is only used on IPU6 Surface devices. Only that bit is touched; the clock_ncont module parameter can force it on or off. This follows the approach of the upstream series "media: Enable the OV5693 front camera on IPU6 Surface devices" (in media next), which gates bit 5 only. Linux-surface PR #2171 writes the whole register (0x2d) on 6.19 instead. Tested on a Surface Pro 9 (i7-1255U, IPU6 8086:465d), 7.2.11-surface-1, Ubuntu 24.04, libcamera 0.7.2 software ISP: 2592x1944 at 28.6 fps, no CSI-2 errors while streaming, 28.6 fps delivered in Chrome through v4l2loopback. Without the change no frame is received. Developed with the help of an AI assistant (Claude); tested on hardware. Link: https://patchew.org/linux/20260717132021.18034-1-fernandorimoli11@gmail.com/ Link: https://github.com/linux-surface/linux-surface/pull/2171 Link: https://github.com/loisBreant/surface-pro-9-camera Patchset: cameras Signed-off-by: Lois Breant <185382558+loisBreant@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/media/i2c/ov5693.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index 02236f3db19dc..5f25412b555b5 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -35,6 +35,15 @@ #define OV5693_STOP_STREAMING 0x00 #define OV5693_SW_RESET 0x01 +/* MIPI transmitter control */ +#define OV5693_MIPI_CTRL00_REG CCI_REG8(0x4800) +/* Gate the clock lane when there is no packet to transmit */ +#define OV5693_MIPI_CTRL00_CLOCK_LANE_GATE BIT(5) + +static int clock_ncont = -1; +module_param(clock_ncont, int, 0444); +MODULE_PARM_DESC(clock_ncont, "MIPI clock lane gating: -1 auto (default), 0 off, 1 on"); + #define OV5693_REG_CHIP_ID CCI_REG16(0x300a) /* Yes, this is right. The datasheet for the OV5693 gives its ID as 0x5690 */ #define OV5693_CHIP_ID 0x5690 @@ -144,6 +153,9 @@ struct ov5693_device { struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES]; struct clk *xvclk; + /* Gate the MIPI clock lane when idle (CSI-2 non-continuous clock) */ + bool clock_ncont; + struct ov5693_mode { struct v4l2_rect crop; struct v4l2_mbus_framefmt format; @@ -611,6 +623,12 @@ static int ov5693_enable_streaming(struct ov5693_device *ov5693, bool enable) { int ret = 0; + /* Backport of the linux-next fix for IPU6 Surface front cameras. */ + if (enable && ov5693->clock_ncont) + cci_update_bits(ov5693->regmap, OV5693_MIPI_CTRL00_REG, + OV5693_MIPI_CTRL00_CLOCK_LANE_GATE, + OV5693_MIPI_CTRL00_CLOCK_LANE_GATE, &ret); + cci_write(ov5693->regmap, OV5693_SW_STREAM_REG, enable ? OV5693_START_STREAMING : OV5693_STOP_STREAMING, &ret); @@ -1259,6 +1277,22 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693) goto out_free_bus_cfg; } + /* + * Upstream (linux-next) gets this from a "clock-noncontinuous" endpoint + * property set by ipu-bridge; this kernel's ipu-bridge does not set it, + * so also enable it for the OVTI5693 HID, only found on IPU6 Surface + * devices (Pro 8, Pro 9, Go 4). clock_ncont=0/1 overrides it. + */ + if (clock_ncont >= 0) + ov5693->clock_ncont = clock_ncont; + else + ov5693->clock_ncont = (bus_cfg.bus.mipi_csi2.flags & + V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK) || + (has_acpi_companion(ov5693->dev) && + acpi_dev_hid_match(ACPI_COMPANION(ov5693->dev), "OVTI5693")); + dev_info(ov5693->dev, "MIPI clock lane gating %s\n", + ov5693->clock_ncont ? "enabled" : "disabled"); + out_free_bus_cfg: v4l2_fwnode_endpoint_free(&bus_cfg);