From e89e1eec1c22e92fd30483ce815e226e6da9744d Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Mon, 7 Sep 2026 17:30:21 +0300 Subject: [PATCH 01/21] media: ipu-bridge: Add ipu_bridge_get_ipu6() Add ipu_bridge_get_ipu6() for obtaining the IPU 6 (or soon later) PCI device. This isn't technically a job of the IPU bridge, but the functionality is required in conjunction with the firmware definitions that necessitate the use of the IPU bridge on many systems. Signed-off-by: Sakari Ailus Reviewed-by: Antti Laakso Reviewed-by: Daniel Scally (cherry picked from commit eda381fd8c0c6f77cc0b3b8d777129eb884a08e0) [ backport: taken as a prerequisite of 8e3def7bf410, which uses the IPU6 PCI IDs from that this commit includes ] Patchset: cameras --- drivers/media/pci/intel/ipu-bridge.c | 13 +++++++++++++ include/media/ipu-bridge.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 271b987660c5c..69fbfbcf0f017 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -15,6 +15,7 @@ #include #include +#include #include #define ADEV_DEV(adev) ACPI_PTR(&((adev)->dev)) @@ -967,6 +968,18 @@ static int ipu_bridge_check_fwnode_graph(struct fwnode_handle *fwnode) return ipu_bridge_check_fwnode_graph(fwnode->secondary); } +struct pci_dev *ipu_bridge_get_ipu6(void) +{ + struct pci_dev *ipu = NULL; + + for (unsigned int i = 0; !ipu && ipu6_pci_tbl[i].vendor; i++) + ipu = pci_get_device(ipu6_pci_tbl[i].vendor, + ipu6_pci_tbl[i].device, NULL); + + return ipu; +} +EXPORT_SYMBOL_NS_GPL(ipu_bridge_get_ipu6, "INTEL_IPU_BRIDGE"); + static DEFINE_MUTEX(ipu_bridge_mutex); int ipu_bridge_init(struct device *dev, diff --git a/include/media/ipu-bridge.h b/include/media/ipu-bridge.h index 16fac765456e8..b46b6693f856b 100644 --- a/include/media/ipu-bridge.h +++ b/include/media/ipu-bridge.h @@ -169,11 +169,13 @@ struct ipu_bridge { }; #if IS_ENABLED(CONFIG_IPU_BRIDGE) +struct pci_dev *ipu_bridge_get_ipu6(void); int ipu_bridge_init(struct device *dev, ipu_parse_sensor_fwnode_t parse_sensor_fwnode); int ipu_bridge_parse_ssdb(struct acpi_device *adev, struct ipu_sensor *sensor); int ipu_bridge_instantiate_vcm(struct device *sensor); #else +static inline struct pci_dev *ipu_bridge_get_ipu6(void) { return NULL; } /* Use a define to avoid the @parse_sensor_fwnode argument getting evaluated */ #define ipu_bridge_init(dev, parse_sensor_fwnode) (0) static inline int ipu_bridge_instantiate_vcm(struct device *s) { return 0; } From 914dff47e60abc722f9a92a8d04c452c6180d5f7 Mon Sep 17 00:00:00 2001 From: Fernando Rimoli Date: Wed, 2 Sep 2026 16:23:18 +0200 Subject: [PATCH 02/21] media: i2c: ov5693: Gate the MIPI clock lane for non-continuous clock The ov5693 never programs MIPI_CTRL00 (0x4800), leaving it at its 0x00 power-on default, which lets the MIPI clock run freely. The IPU3 CSI-2 receiver tolerates this, but the IPU6 receiver (e.g. on Microsoft Surface Pro 7+, Pro 8, Pro 9 and Surface Go 4) fails to lock onto the link, so the sensor streams but capture times out with "stream stop time out". On most affected machines no frames arrive at all; on some the failure is intermittent. Gate the clock lane while idle at stream on when the endpoint requests a non-continuous clock. Only the gate bit is touched, so platforms that do not request it are unaffected. No counterpart is needed at stream off, as the link is down by then and the register returns to its default when the sensor is powered off. The property is supplied by the ipu-bridge in a subsequent patch. Link: https://github.com/linux-surface/linux-surface/pull/2171 Co-developed-by: Arsalan Naeem Signed-off-by: Arsalan Naeem Signed-off-by: Fernando Rimoli Tested-by: Jakob Berg Jespersen # Surface Pro 7+, IPU6 Tiger Lake Tested-by: Fil Dunsky # Surface Pro 8, IPU6 Tiger Lake (8086:9a19) Tested-by: Lucas Lis # Surface Pro 7+, IPU6 Tiger Lake (0x9a19) Tested-by: Kengo Oki # Surface Go 4, IPU6 Alder Lake-N 8086:462e Signed-off-by: Sakari Ailus (cherry picked from commit 0e12587945f66d5b8c72be145b95fc5f109b3a32) Patchset: cameras --- drivers/media/i2c/ov5693.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index d90f135bc55f4..37f24f4d6e91d 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -35,6 +35,11 @@ #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) + #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 +149,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 +619,19 @@ static int ov5693_enable_streaming(struct ov5693_device *ov5693, bool enable) { int ret = 0; + /* + * Gate the MIPI clock lane while idle if the CSI-2 link is configured + * for a non-continuous clock. Only that bit is touched, and only in + * that case, so the register keeps whatever the platform left in it + * and the clock stays free-running as before everywhere else. It + * needs no counterpart at stream off: the link is down by then, and + * the register returns to its default when the sensor is powered off. + */ + 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 +1280,9 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693) goto out_free_bus_cfg; } + ov5693->clock_ncont = bus_cfg.bus.mipi_csi2.flags & + V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; + out_free_bus_cfg: v4l2_fwnode_endpoint_free(&bus_cfg); From d44e42bc48ad86603171d877a47f02ae19f50e27 Mon Sep 17 00:00:00 2001 From: Fernando Rimoli Date: Wed, 2 Sep 2026 16:23:19 +0200 Subject: [PATCH 03/21] media: ipu-bridge: Assign endpoint property indices dynamically Index the ep_properties array dynamically instead of plain numerical values as is done in mipi-disco-img.c. Signed-off-by: Fernando Rimoli Tested-by: Jakob Berg Jespersen # Surface Pro 7+, IPU6 Tiger Lake Tested-by: Fil Dunsky # Surface Pro 8, IPU6 Tiger Lake (8086:9a19) Tested-by: Lucas Lis # Surface Pro 7+, IPU6 Tiger Lake (0x9a19) Tested-by: Kengo Oki # Surface Go 4, IPU6 Alder Lake-N 8086:462e Signed-off-by: Sakari Ailus (cherry picked from commit 3436405beac895b589e2ad4a7be3b57e17605057) Patchset: cameras --- drivers/media/pci/intel/ipu-bridge.c | 27 ++++++++++++++------------- include/media/ipu-bridge.h | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 69fbfbcf0f017..8eb52dd99ee1d 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -499,6 +499,7 @@ static void ipu_bridge_create_fwnode_properties( { struct ipu_property_names *names = &sensor->prop_names; struct software_node *nodes = sensor->swnodes; + unsigned int i = 0; sensor->prop_names = prop_names; @@ -556,21 +557,21 @@ static void ipu_bridge_create_fwnode_properties( PROPERTY_ENTRY_REF_ARRAY("lens-focus", sensor->vcm_ref); } - sensor->ep_properties[0] = PROPERTY_ENTRY_U32( - sensor->prop_names.bus_type, - V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); - sensor->ep_properties[1] = PROPERTY_ENTRY_U32_ARRAY_LEN( - sensor->prop_names.data_lanes, - bridge->data_lanes, sensor->lanes); - sensor->ep_properties[2] = PROPERTY_ENTRY_REF_ARRAY( - sensor->prop_names.remote_endpoint, - sensor->local_ref); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_BUS_TYPE)] = + PROPERTY_ENTRY_U32(names->bus_type, + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_DATA_LANES)] = + PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes, + bridge->data_lanes, sensor->lanes); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_REMOTE_EP)] = + PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint, + sensor->local_ref); if (cfg->nr_link_freqs > 0) - sensor->ep_properties[3] = PROPERTY_ENTRY_U64_ARRAY_LEN( - sensor->prop_names.link_frequencies, - cfg->link_freqs, - cfg->nr_link_freqs); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_LINK_FREQUENCIES)] = + PROPERTY_ENTRY_U64_ARRAY_LEN(names->link_frequencies, + cfg->link_freqs, + cfg->nr_link_freqs); sensor->ipu_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN( sensor->prop_names.data_lanes, diff --git a/include/media/ipu-bridge.h b/include/media/ipu-bridge.h index b46b6693f856b..e8aeb23dc5a21 100644 --- a/include/media/ipu-bridge.h +++ b/include/media/ipu-bridge.h @@ -64,6 +64,23 @@ enum ipu_sensor_swnodes { SWNODE_COUNT }; +enum ipu_bridge_ep_props { + IPU_BRIDGE_EP_BUS_TYPE, + IPU_BRIDGE_EP_DATA_LANES, + IPU_BRIDGE_EP_REMOTE_EP, + IPU_BRIDGE_EP_LINK_FREQUENCIES, + IPU_BRIDGE_EP_NUM_OF, + IPU_BRIDGE_EP_NUM_ENTRIES +}; + +/* + * Get the index of the next property in a property array, with a given maximum + * value. + */ +#define IPU_BRIDGE_NEXT_PROPERTY(index, max) \ + (WARN_ON((index) > IPU_BRIDGE_##max) ? \ + IPU_BRIDGE_##max : (index)++) + /* Data representation as it is in ACPI SSDB buffer */ struct ipu_sensor_ssdb { u8 version; @@ -141,7 +158,7 @@ struct ipu_sensor { const char *vcm_type; struct ipu_property_names prop_names; - struct property_entry ep_properties[5]; + struct property_entry ep_properties[IPU_BRIDGE_EP_NUM_ENTRIES]; struct property_entry dev_properties[5]; struct property_entry ipu_properties[3]; struct property_entry ivsc_properties[1]; From 8040935a575a93132eec958abc8777a41dccbd04 Mon Sep 17 00:00:00 2001 From: Fernando Rimoli Date: Wed, 2 Sep 2026 16:23:20 +0200 Subject: [PATCH 04/21] media: ipu-bridge: Match sensor configs per IPU and add config flags Some sensors need different treatment depending on which IPU they are connected to, so the ACPI HID alone is not enough. Match on an optional list of IPU PCI product IDs. Entries for one HID must be adjacent, IPU-specific ones first, so the generic entry is skipped once a specific one has matched. Signed-off-by: Fernando Rimoli Tested-by: Jakob Berg Jespersen # Surface Pro 7+, IPU6 Tiger Lake Tested-by: Fil Dunsky # Surface Pro 8, IPU6 Tiger Lake (8086:9a19) Tested-by: Lucas Lis # Surface Pro 7+, IPU6 Tiger Lake (0x9a19) Tested-by: Kengo Oki # Surface Go 4, IPU6 Alder Lake-N 8086:462e Signed-off-by: Sakari Ailus (cherry picked from commit b883954d842f57f6f349bbbdf3d4347db3a416dc) Patchset: cameras --- drivers/media/pci/intel/ipu-bridge.c | 35 ++++++++++++++++++++++++++++ include/media/ipu-bridge.h | 26 +++++++++++++++++---- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 8eb52dd99ee1d..a31d3f34f6360 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -901,8 +902,28 @@ static int ipu_bridge_connect_sensor(const struct ipu_sensor_config *cfg, return ret; } +/* + * Whether a sensor config applies to the IPU this bridge sits on. A config + * listing PCI product IDs only applies to those IPUs. + */ +static bool ipu_bridge_config_matches(const struct ipu_sensor_config *cfg, + struct ipu_bridge *bridge) +{ + const u16 *id; + + if (!cfg->pci_ids) + return true; + + for (id = cfg->pci_ids; *id; id++) + if (*id == bridge->pci_id) + return true; + + return false; +} + static int ipu_bridge_connect_sensors(struct ipu_bridge *bridge) { + const char *done_hid = NULL; unsigned int i; int ret; @@ -910,9 +931,22 @@ static int ipu_bridge_connect_sensors(struct ipu_bridge *bridge) const struct ipu_sensor_config *cfg = &ipu_supported_sensors[i]; + /* + * Entries for one HID are adjacent, IPU-specific ones first, + * so the generic entry is skipped once a specific one has + * matched and the sensor is not connected twice. + */ + if (done_hid && !strcmp(cfg->hid, done_hid)) + continue; + + if (!ipu_bridge_config_matches(cfg, bridge)) + continue; + ret = ipu_bridge_connect_sensor(cfg, bridge); if (ret) goto err_unregister_sensors; + + done_hid = cfg->hid; } return 0; @@ -1008,6 +1042,7 @@ int ipu_bridge_init(struct device *dev, sizeof(bridge->ipu_node_name)); bridge->ipu_hid_node.name = bridge->ipu_node_name; bridge->dev = dev; + bridge->pci_id = dev_is_pci(dev) ? to_pci_dev(dev)->device : 0; bridge->parse_sensor_fwnode = parse_sensor_fwnode; ret = software_node_register(&bridge->ipu_hid_node); diff --git a/include/media/ipu-bridge.h b/include/media/ipu-bridge.h index e8aeb23dc5a21..c562db794ca8b 100644 --- a/include/media/ipu-bridge.h +++ b/include/media/ipu-bridge.h @@ -17,13 +17,24 @@ #define IPU_SENSOR_ROTATION_NORMAL 0 #define IPU_SENSOR_ROTATION_INVERTED 1 -#define IPU_SENSOR_CONFIG(_HID, _NR, ...) \ - (const struct ipu_sensor_config) { \ - .hid = _HID, \ - .nr_link_freqs = _NR, \ - .link_freqs = { __VA_ARGS__ } \ +/* + * Sensor config specific to one or more IPUs, identified by their PCI product + * IDs, with flags describing what the sensor needs there. Entries for one HID + * must be adjacent in ipu_supported_sensors[], with the IPU-specific ones + * before the generic one. + */ +#define IPU_SENSOR_CONFIG_MATCH_FL(_HID, _IDS, _FLAGS, _NR, ...) \ + (const struct ipu_sensor_config) { \ + .hid = _HID, \ + .pci_ids = _IDS, \ + .flags = _FLAGS, \ + .nr_link_freqs = _NR, \ + .link_freqs = { __VA_ARGS__ } \ } +#define IPU_SENSOR_CONFIG(_HID, _NR, ...) \ + IPU_SENSOR_CONFIG_MATCH_FL(_HID, NULL, 0, _NR, __VA_ARGS__) + #define NODE_SENSOR(_HID, _PROPS) \ (const struct software_node) { \ .name = _HID, \ @@ -132,6 +143,9 @@ struct ipu_node_names { struct ipu_sensor_config { const char *hid; + /* Zero-terminated list of IPU PCI product IDs, NULL for any IPU */ + const u16 *pci_ids; + const u32 flags; const u8 nr_link_freqs; const u64 link_freqs[MAX_NUM_LINK_FREQS]; }; @@ -177,6 +191,8 @@ typedef int (*ipu_parse_sensor_fwnode_t)(struct acpi_device *adev, struct ipu_bridge { struct device *dev; + /* PCI product ID of the IPU, 0 if it is not a PCI device */ + u16 pci_id; ipu_parse_sensor_fwnode_t parse_sensor_fwnode; char ipu_node_name[ACPI_ID_LEN]; struct software_node ipu_hid_node; From 508f319d6827dced5f5ae1f3735b3de560f137f4 Mon Sep 17 00:00:00 2001 From: Fernando Rimoli Date: Wed, 2 Sep 2026 16:23:21 +0200 Subject: [PATCH 05/21] media: ipu-bridge: Request non-continuous clock for ov5693 on IPU6 The ov5693 (INT33BE / OVTI5693) needs its MIPI clock lane gated while idle for the IPU6 CSI-2 receiver to lock onto the link, which the sensor driver does when the endpoint requests a non-continuous clock. The same sensor works with a free-running clock on the IPU3, so request it only for the IPU6 variants where it has been confirmed on hardware: Tiger Lake, Alder Lake-P and Alder Lake-N. Signed-off-by: Fernando Rimoli Tested-by: Jakob Berg Jespersen # Surface Pro 7+, IPU6 Tiger Lake Tested-by: Fil Dunsky # Surface Pro 8, IPU6 Tiger Lake (8086:9a19) Tested-by: Lucas Lis # Surface Pro 7+, IPU6 Tiger Lake (0x9a19) Tested-by: Kengo Oki # Surface Go 4, IPU6 Alder Lake-N 8086:462e Signed-off-by: Sakari Ailus (cherry picked from commit 8e3def7bf4102c5b32b597b2f6ea1419174fc480) [ backport: linux-surface's "Add camera support for Surface Pro 9" lists OVTI5693 after INT33F0 rather than in sorted order, so the new OVTI5693 entry goes just before that one instead of at the sorted position; no other change ] Assisted-by: LLM Patchset: cameras --- drivers/media/pci/intel/ipu-bridge.c | 18 ++++++++++++++++++ include/media/ipu-bridge.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index a31d3f34f6360..271afcc22ac67 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -50,6 +50,14 @@ * * Please keep the list sorted by ACPI HID. */ +/* IPU6 variants whose CSI-2 receiver needs the ov5693 clock lane gated */ +static const u16 ipu6_ov5693_ncont_clk[] = { + PCI_DEVICE_ID_INTEL_IPU6, /* Tiger Lake */ + PCI_DEVICE_ID_INTEL_IPU6EP_ADLP, /* Alder Lake-P */ + PCI_DEVICE_ID_INTEL_IPU6EP_ADLN, /* Alder Lake-N */ + 0 +}; + static const struct ipu_sensor_config ipu_supported_sensors[] = { /* Himax HM1092 */ IPU_SENSOR_CONFIG("HIMX1092", 2, 180000000, 180480000), @@ -62,10 +70,16 @@ static const struct ipu_sensor_config ipu_supported_sensors[] = { /* GalaxyCore GC0310 */ IPU_SENSOR_CONFIG("INT0310", 1, 55692000), /* Omnivision OV5693 */ + IPU_SENSOR_CONFIG_MATCH_FL("INT33BE", ipu6_ov5693_ncont_clk, + IPU_BR_FL_CSI2_CLK_NONCONTINUOUS, + 1, 419200000), IPU_SENSOR_CONFIG("INT33BE", 1, 419200000), /* Onsemi MT9M114 */ IPU_SENSOR_CONFIG("INT33F0", 1, 384000000), /* Omnivision OV5693 - Surface Pro 9 */ + IPU_SENSOR_CONFIG_MATCH_FL("OVTI5693", ipu6_ov5693_ncont_clk, + IPU_BR_FL_CSI2_CLK_NONCONTINUOUS, + 1, 419200000), IPU_SENSOR_CONFIG("OVTI5693", 1, 419200000), /* Omnivision OV13858 - Surface Pro 9 */ IPU_SENSOR_CONFIG("OVTID858", 4, 540000000), @@ -574,6 +588,10 @@ static void ipu_bridge_create_fwnode_properties( cfg->link_freqs, cfg->nr_link_freqs); + if (cfg->flags & IPU_BR_FL_CSI2_CLK_NONCONTINUOUS) + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_CLOCK_NONCONTINUOUS)] = + PROPERTY_ENTRY_BOOL("clock-noncontinuous"); + sensor->ipu_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN( sensor->prop_names.data_lanes, bridge->data_lanes, sensor->lanes); diff --git a/include/media/ipu-bridge.h b/include/media/ipu-bridge.h index c562db794ca8b..760f0767ce58f 100644 --- a/include/media/ipu-bridge.h +++ b/include/media/ipu-bridge.h @@ -17,6 +17,10 @@ #define IPU_SENSOR_ROTATION_NORMAL 0 #define IPU_SENSOR_ROTATION_INVERTED 1 +/* Flags for struct ipu_sensor_config */ +/* The sensor's CSI-2 transmitter needs a non-continuous clock */ +#define IPU_BR_FL_CSI2_CLK_NONCONTINUOUS BIT(0) + /* * Sensor config specific to one or more IPUs, identified by their PCI product * IDs, with flags describing what the sensor needs there. Entries for one HID @@ -80,6 +84,7 @@ enum ipu_bridge_ep_props { IPU_BRIDGE_EP_DATA_LANES, IPU_BRIDGE_EP_REMOTE_EP, IPU_BRIDGE_EP_LINK_FREQUENCIES, + IPU_BRIDGE_EP_CLOCK_NONCONTINUOUS, IPU_BRIDGE_EP_NUM_OF, IPU_BRIDGE_EP_NUM_ENTRIES }; From a0327cc27b49e923f1d44ca47bb409f725ee7b81 Mon Sep 17 00:00:00 2001 From: Fernando Rimoli Date: Sun, 13 Sep 2026 20:38:40 +0100 Subject: [PATCH 06/21] media: ipu-bridge: Keep the clock-noncontinuous property name out of rodata The software nodes ipu-bridge registers on a successful init are never unregistered. There is no module_exit and no remove hook, and every software_node_unregister_node_group() call sits on an error unwind label inside ipu_bridge_init(), so on success the nodes stay registered and readable after the module is unloaded, which a later rebind relies on. Nothing reachable from a registered node may therefore point into the module image. PROPERTY_ENTRY_BOOL() stores a pointer to its name, so the "clock-noncontinuous" string literal leaves the surviving node carrying a dangling property name once ipu-bridge is gone. Add the name to struct ipu_property_names, which is copied by value into each struct ipu_sensor, and use that copy, as every other endpoint property name already does. Fixes: 8e3def7bf410 ("media: ipu-bridge: Request non-continuous clock for ov5693 on IPU6") Reported-by: D. Manresa Closes: https://lore.kernel.org/linux-media/20260905211307.542810-1-dmanresa@gmail.com/ Signed-off-by: Fernando Rimoli Signed-off-by: Sakari Ailus (cherry picked from commit a20c843c9bc40ab8703a2b17fcbc69532baca692) Patchset: cameras --- drivers/media/pci/intel/ipu-bridge.c | 3 ++- include/media/ipu-bridge.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 271afcc22ac67..b55578be327f6 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -244,6 +244,7 @@ static const struct ipu_property_names prop_names = { .data_lanes = "data-lanes", .remote_endpoint = "remote-endpoint", .link_frequencies = "link-frequencies", + .clock_noncontinuous = "clock-noncontinuous", }; static const char * const ipu_vcm_types[] = { @@ -590,7 +591,7 @@ static void ipu_bridge_create_fwnode_properties( if (cfg->flags & IPU_BR_FL_CSI2_CLK_NONCONTINUOUS) sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_CLOCK_NONCONTINUOUS)] = - PROPERTY_ENTRY_BOOL("clock-noncontinuous"); + PROPERTY_ENTRY_BOOL(names->clock_noncontinuous); sensor->ipu_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN( sensor->prop_names.data_lanes, diff --git a/include/media/ipu-bridge.h b/include/media/ipu-bridge.h index 760f0767ce58f..3ef94c2b76789 100644 --- a/include/media/ipu-bridge.h +++ b/include/media/ipu-bridge.h @@ -135,6 +135,7 @@ struct ipu_property_names { char data_lanes[11]; char remote_endpoint[16]; char link_frequencies[17]; + char clock_noncontinuous[20]; }; struct ipu_node_names { From 0db0257e0fa8cad621b165f95e4977b2d5172945 Mon Sep 17 00:00:00 2001 From: Sergey Lebedev Date: Wed, 30 Sep 2026 07:33:12 +0000 Subject: [PATCH 07/21] media: i2c: ov13858: add horizontal and vertical flip controls The Microsoft Surface Pro 11 for Business (Intel) mounts this sensor upside down, as commit b238116ccd4b ("media: ipu-bridge: Add upside-down quirk for Surface Pro 11") records, and the driver has no flip controls to compensate. Add V4L2_CID_HFLIP and V4L2_CID_VFLIP on bits 3 and 4 of register 0x3820. The mirror bit is active low, as in Intel's out-of-tree ov13858 driver. The Bayer order does not change with either flip, so the controls do not set V4L2_CTRL_FLAG_MODIFY_LAYOUT. They are clustered, and grabbed while streaming. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Sergey Lebedev Tested-by: German Pablo Lindo Signed-off-by: Sakari Ailus (cherry picked from commit deb515fcc369f16ffe099a8b3b940785180dfc48) Patchset: cameras --- drivers/media/i2c/ov13858.c | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c index 015493a164309..8e2065b089609 100644 --- a/drivers/media/i2c/ov13858.c +++ b/drivers/media/i2c/ov13858.c @@ -77,6 +77,12 @@ #define OV13858_DGTL_GAIN_DEFAULT 1024 /* Default gain = 1 X */ #define OV13858_DGTL_GAIN_STEP 1 /* Each step = 1/1024 */ +/* Readout direction */ +#define OV13858_REG_FORMAT1 0x3820 +#define OV13858_FORMAT1_VFLIP BIT(4) +/* Horizontal flip, active low: every mode table sets this bit */ +#define OV13858_FORMAT1_HFLIP_N BIT(3) + /* Test Pattern Control */ #define OV13858_REG_TEST_PATTERN 0x4503 #define OV13858_TEST_PATTERN_ENABLE BIT(7) @@ -1051,6 +1057,8 @@ struct ov13858 { struct v4l2_ctrl *vblank; struct v4l2_ctrl *hblank; struct v4l2_ctrl *exposure; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; /* Current mode */ const struct ov13858_mode *cur_mode; @@ -1331,6 +1339,31 @@ static int ov13858_enable_test_pattern(struct ov13858 *ov13858, u32 pattern) OV13858_REG_VALUE_08BIT, val); } +static int ov13858_update_flips(struct ov13858 *ov13858) +{ + u32 val; + int ret; + + ret = ov13858_read_reg(ov13858, OV13858_REG_FORMAT1, + OV13858_REG_VALUE_08BIT, &val); + if (ret) + return ret; + + if (ov13858->vflip->val) + val |= OV13858_FORMAT1_VFLIP; + else + val &= ~OV13858_FORMAT1_VFLIP; + + /* The mirror bit is active low, as it is on ov13b10. */ + if (ov13858->hflip->val) + val &= ~OV13858_FORMAT1_HFLIP_N; + else + val |= OV13858_FORMAT1_HFLIP_N; + + return ov13858_write_reg(ov13858, OV13858_REG_FORMAT1, + OV13858_REG_VALUE_08BIT, val); +} + static int ov13858_set_ctrl(struct v4l2_ctrl *ctrl) { struct ov13858 *ov13858 = container_of(ctrl->handler, @@ -1377,6 +1410,10 @@ static int ov13858_set_ctrl(struct v4l2_ctrl *ctrl) ov13858->cur_mode->height + ctrl->val); break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + ret = ov13858_update_flips(ov13858); + break; case V4L2_CID_TEST_PATTERN: ret = ov13858_enable_test_pattern(ov13858, ctrl->val); break; @@ -1603,6 +1640,13 @@ static int ov13858_set_stream(struct v4l2_subdev *sd, int enable) pm_runtime_put(ov13858->dev); } + /* + * Do not let the flips change while streaming. ov13858->mutex is the + * control handler's own lock and is held here, hence the __ form. + */ + __v4l2_ctrl_grab(ov13858->hflip, enable); + __v4l2_ctrl_grab(ov13858->vflip, enable); + mutex_unlock(&ov13858->mutex); return ret; @@ -1745,6 +1789,12 @@ static int ov13858_init_controls(struct ov13858 *ov13858) OV13858_DGTL_GAIN_MIN, OV13858_DGTL_GAIN_MAX, OV13858_DGTL_GAIN_STEP, OV13858_DGTL_GAIN_DEFAULT); + ov13858->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); + ov13858->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_cluster(2, &ov13858->hflip); + v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_TEST_PATTERN, ARRAY_SIZE(ov13858_test_pattern_menu) - 1, From d61d55d4116f7d8df664f9976f603249363ac140 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 15 Oct 2026 22:04:29 +0200 Subject: [PATCH 08/21] media: i2c: ov5693: Program the mode registers on stream start Same issue as ov8865: the mode registers are only written on runtime PM resume, so a format change on a sensor that stays powered never reaches the chip. Program the mode before the controls on every stream start. Tested-by: Chris Simpson # Surface Pro 9 (IPU6) Tested-by: Firas Sharary <29305778+T-Caster@users.noreply.github.com> # Surface Pro 7+ (IPU6) Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov5693.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index 37f24f4d6e91d..a39a33df4704d 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -997,6 +997,19 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable) return ret; mutex_lock(&ov5693->lock); + + /* + * Same as ov8865: the mode registers are only written on + * runtime PM resume, so a format change on a sensor that stays + * powered never reaches the chip. Program the mode first, then + * the controls, so the mode registers don't clobber them. + */ + ret = ov5693_mode_configure(ov5693); + if (ret) { + mutex_unlock(&ov5693->lock); + goto err_power_down; + } + ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler); if (ret) { mutex_unlock(&ov5693->lock); From 8d7660a8cf76faadd94e12524c5091e40a8e604e Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 15 Oct 2026 22:05:01 +0200 Subject: [PATCH 09/21] media: Surface Pro 5: fix front and rear camera orientation The SSDB of the Surface Pro 5 (SKU 1796, and 1807 for the LTE model) reports a 180 degree rotation for both the front OV5693 and the rear OV8865. Measured on the device, both sensors need a vertical flip only, without mirroring, which is not a rotation: applying the reported 180 degrees leaves both images mirrored. - ipu-bridge: add a DMI list of sensors that are not rotated despite what the SSDB says, and report 0 degrees for them. - ov8865: on these machines invert the VFLIP control, so the default value gives an upright image and userspace (libcamera resets the flip controls) keeps working. The front sensor gets the same treatment in a separate patch. Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov8865.c | 25 ++++++++++++++++ drivers/media/pci/intel/ipu-bridge.c | 44 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index 289a34a3eeb17..104ba4770efb0 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -2189,11 +2190,35 @@ static int ov8865_blue_balance_configure(struct ov8865_sensor *sensor, /* Flip */ +/* + * On the Surface Pro 5 the rear OV8865 is mounted vertically mirrored: the + * upright image needs the sensor's vertical flip enabled. Invert the VFLIP + * control so that the default (0) gives an upright image. + */ +static const struct dmi_system_id ov8865_vflip_inverted_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + static int ov8865_flip_vert_configure(struct ov8865_sensor *sensor, bool enable) { u8 bits = OV8865_FORMAT1_FLIP_VERT_ISP_EN | OV8865_FORMAT1_FLIP_VERT_SENSOR_EN; + if (dmi_check_system(ov8865_vflip_inverted_dmi_ids)) + enable = !enable; + return ov8865_update_bits(sensor, OV8865_FORMAT1_REG, bits, enable ? bits : 0); } diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index b55578be327f6..77097a844acd4 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -236,6 +236,45 @@ static const struct dmi_system_id upside_down_sensor_dmi_ids[] = { {} /* Terminating entry */ }; +/* + * DMI matches for devices whose SSDB reports a 180° rotation for sensors that + * are not actually rotated. On the Surface Pro 5 the firmware reports 180° for + * both the front (OV5693) and the rear (OV8865) camera. Measured on the + * device, both need a vertical flip only and no mirroring, which is not a + * rotation: report 0 degrees and let the sensor drivers apply the flip. + */ +static const struct dmi_system_id not_rotated_sensor_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + .driver_data = "INT347A", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + .driver_data = "INT347A", + }, + {} /* Terminating entry */ +}; + static const struct ipu_property_names prop_names = { .clock_frequency = "clock-frequency", .rotation = "rotation", @@ -429,6 +468,11 @@ static u32 ipu_bridge_parse_rotation(struct acpi_device *adev, if (acpi_dev_hid_match(adev, dmi_id->driver_data)) return 180; + for (dmi_id = dmi_first_match(not_rotated_sensor_dmi_ids); dmi_id; + dmi_id = dmi_first_match(dmi_id + 1)) + if (acpi_dev_hid_match(adev, dmi_id->driver_data)) + return 0; + switch (ssdb->degree) { case IPU_SENSOR_ROTATION_NORMAL: return 0; From 915bef915abfdca28ab967d1666f3beab3e41d8e Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 15 Oct 2026 22:17:03 +0200 Subject: [PATCH 10/21] media: i2c: ov7251: Drive the Surface IR illuminator via STROBE On the Surface Pro 5 the IR flood LED is driven by the OV7251 STROBE pad, not by a GPIO or the TPS68470 LED outputs, and ACPI does not describe it. The mode tables leave the pad disabled (0x3005 = 0x00, 0x3016..0x301c = 0xf0), so the LED never lights and the IR camera, which sits behind an IR-pass filter, only sees black. Enable the STROBE output on stream start on the Surface Pro 5 (SKU 1796 and 1807), with an alternate-frame pattern (0x3b81 = 0xaa) so userspace gets lit and unlit frames. The module parameter surface_ir_strobe overrides the DMI match (-1 auto, 0 off, 1 on). Verified on a Surface Pro 5 (1796): with the strobe enabled the mean level of consecutive 640x480 frames alternates between 16 and 42, with it disabled it stays at 16. Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov7251.c | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index a1a91b41eb4d6..14133dccde22e 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -234,6 +235,64 @@ static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = { [OV7251_24_MHZ] = &ov7251_pll_cfgs_24_mhz, }; +/* + * Surface IR flood illuminator. + * + * On the Surface Pro 5 the IR LED is driven by the sensor's STROBE pad, not by + * a GPIO or the TPS68470 LED outputs, and ACPI does not describe it. The mode + * tables leave the pad disabled (0x3005 = 0x00, 0x3016-0x301c = 0xf0), so the + * LED never lights and the IR camera (behind an IR-pass filter) sees black. + * + * 0x3b81 is the strobe pattern: 0xaa lights the LED on alternate frames, so + * userspace gets lit and unlit frames for ambient light subtraction. + * + * surface_ir_strobe: -1 = auto (on for the DMI matches below), 0 = off, 1 = on. + */ +static int surface_ir_strobe = -1; +module_param(surface_ir_strobe, int, 0644); +MODULE_PARM_DESC(surface_ir_strobe, + "Drive the Surface IR illuminator via STROBE (-1 auto, 0 off, 1 on)"); + +static const struct dmi_system_id ov7251_surface_ir_strobe_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + +static const struct reg_value ov7251_surface_ir_strobe_regs[] = { + { 0x3005, 0x08 }, + { 0x3016, 0x10 }, + { 0x3017, 0x00 }, + { 0x3018, 0x00 }, + { 0x301a, 0x00 }, + { 0x301b, 0x00 }, + { 0x301c, 0x00 }, + { 0x3664, 0xf0 }, + { 0x3b81, 0xaa }, + { 0x3b8b, 0x00 }, + { 0x3b8e, 0x03 }, + { 0x3b8f, 0x08 }, + { 0x3b96, 0xc0 }, +}; + +static bool ov7251_use_surface_ir_strobe(void) +{ + if (surface_ir_strobe >= 0) + return surface_ir_strobe; + + return dmi_check_system(ov7251_surface_ir_strobe_dmi_ids); +} + static const struct reg_value ov7251_global_init_setting[] = { { 0x0103, 0x01 }, { 0x303b, 0x02 }, @@ -1362,6 +1421,15 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable) ov7251->current_mode->height); goto err_power_down; } + if (ov7251_use_surface_ir_strobe()) { + ret = ov7251_set_register_array(ov7251, + ov7251_surface_ir_strobe_regs, + ARRAY_SIZE(ov7251_surface_ir_strobe_regs)); + if (ret < 0) { + dev_err(ov7251->dev, "could not set IR strobe\n"); + goto err_power_down; + } + } ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls); if (ret < 0) { dev_err(ov7251->dev, "could not sync v4l2 controls\n"); From bed99d9a26f952b95af0ca45825602a747569698 Mon Sep 17 00:00:00 2001 From: "D. Manresa" Date: Thu, 27 Aug 2026 23:03:33 +0200 Subject: [PATCH 11/21] media: i2c: ov5693: make the 2x2-binned mode stream on IPU6 The driver's 1296x972 binned mode has never streamed on IPU6 machines (Surface Pro 7+/8/9, Go 4): the receiver reports "Transfer FIFO overflow" or "Frame sync error" and no frame ever completes. Because of that, every IPU6 setup has had to read the sensor at full 2592x1944 and downscale, throwing away two stops of light and pinning the AGC at its maximum analogue gain (127 vs ~15) - the familiar "working but unusably noisy" IPU6 front camera. Fix the mode by porting what the vendor (Windows) driver ov5693.sys programs differently, extracted from its mode tables: - Per-mode MIPI PLL (0x30b3: 0x70 binned / 0x83 full) and six per-mode analogue readout registers. Mainline writes only the full-resolution values, once, globally; the binned readout then overflows the receiver's FIFO. - Readout geometry with spare pixels: cropping exactly the output size starves the sensor's internal ISP and every frame fails CSI-2 framing ("Frame sync error"). The vendor reads the whole pixel array, bins it to 1312x978, and places the 1296x972 output via the ISP window offsets. The parity of the Y offset selects the vertical Bayer phase (even = the advertised BGGR, odd = GRBG); it is exposed as a module parameter (binned_y_offset, default 2) because libcamera's software ISP wants the advertised phase while pipelines built around the Windows tuning (Intel's IPU6 HAL/PSYS) expect the vendor's odd offset. - Mode-dependent vertical-flip bits: with binning, setting both FORMAT1 flip bits corrupts the CSI-2 framing and the ISP bit alone does not flip; only the sensor-side bit both streams and flips. Re-apply the vflip control when the mode is configured, since the correct bits depend on the selected mode. - Cap the frame rate at 30 fps: the auto-picked 60 fps VTS for the binned mode exceeds what the slower binned MIPI PLL can carry (the vendor runs this mode at VTS 1984 / 30 fps). Also document the black-level pedestal next to the BLC init values: the sensor keeps ~16 LSB (10-bit) at every analogue gain, while OEM .aiqb calibrations state 64.9 because Windows' ISYS delivers RAW10 aligned to 12 bits. Verified on a Surface Pro 7+ (IPU6, Tiger Lake): 1296x972 at 30 fps, analogue gain in normal indoor light drops from 127 (maximum) to ~15, both through libcamera's software ISP and through Intel's IPU6 HAL on top of the hardware ISP. Reference setup and measurements: https://github.com/dmanresa-saes/surface-ipu6-cameras Signed-off-by: D. Manresa [rylos: dropped the MIPI_CTRL00 = 0x2d write, the IPU6 clock lane gate from mainline ("ov5693: Gate the MIPI clock lane for non-continuous clock") covers it] Tested-by: Chris Simpson # Surface Pro 9 (IPU6) Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov5693.c | 152 ++++++++++++++++++++++++++++++++++--- 1 file changed, 140 insertions(+), 12 deletions(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index a39a33df4704d..3244f3806d804 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -87,6 +87,17 @@ #define OV5693_OFFSET_START_X_REG CCI_REG16(0x3810) #define OV5693_OFFSET_START_Y_REG CCI_REG16(0x3812) +/* + * ISP window Y offset used in the binned mode. Parity selects the Bayer + * phase of the output: 2 (even) keeps the advertised BGGR phase and is what + * libcamera's software ISP expects; 3 (odd, the Windows value) yields the + * GRBG phase that the IPU6 PSYS program groups from the Windows tuning + * expect. Switch with: modprobe ov5693 binned_y_offset=3 + */ +static int binned_y_offset = 2; +module_param(binned_y_offset, int, 0644); +MODULE_PARM_DESC(binned_y_offset, "binned-mode ISP window Y offset (2=softISP/BGGR, 3=PSYS/GRBG)"); + #define OV5693_SUB_INC_X_REG CCI_REG8(0x3814) #define OV5693_SUB_INC_Y_REG CCI_REG8(0x3815) @@ -293,6 +304,15 @@ static const struct cci_reg_sequence ov5693_global_regs[] = { {CCI_REG8(0x3a04), 0x06}, {CCI_REG8(0x3a05), 0x14}, {CCI_REG8(0x3e07), 0x20}, + /* + * BLC: same values the Windows driver writes. The sensor keeps its + * black pedestal at ~16 LSB (10-bit) at every analogue gain (measured + * with dark captures; adding the remaining Windows BLC registers + * 0x4002/0x4005/0x400c/0x400d/0x404e/0x404f does not change that). + * Note the OEM .aiqb black-level calibration says 64.9 because it is + * expressed at the 12-bit alignment Windows' ISYS DMA delivers + * (16.2 <<2); see REPRODUCIR.md section 10. + */ {CCI_REG8(0x4000), 0x08}, {CCI_REG8(0x4001), 0x04}, {CCI_REG8(0x4004), 0x08}, @@ -361,15 +381,36 @@ static const u8 ov5693_test_pattern_bits[] = { /* V4L2 Controls Functions */ +/* + * Which FORMAT1 bits express a vertical flip depends on the readout mode. + * + * At full resolution both the sensor-side and the ISP-side bit are used, as + * the datasheet describes. With 2x2 binning, setting both corrupts the CSI-2 + * framing: an IPU6 receiver reports "Frame sync error" on every frame and no + * data arrives at all. The ISP bit alone streams cleanly but does not + * actually flip the picture, so the sensor-side bit alone is the one that + * both streams and flips. It also inverts the vertical Bayer phase, which + * the even ISP window offset in ov5693_mode_configure() keeps in place -- + * measured on a Surface Pro 7+ against the full-resolution orientation. + */ +static u8 ov5693_flip_vert_bits(struct ov5693_device *ov5693) +{ + if (ov5693->mode.binning_y) + return OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; + + return OV5693_FORMAT1_FLIP_VERT_ISP_EN | + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; +} + static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable) { - u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN | + u8 mask = OV5693_FORMAT1_FLIP_VERT_ISP_EN | OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; int ret; - ret = cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, bits, - enable ? bits : 0, NULL); + ret = cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, mask, + enable ? ov5693_flip_vert_bits(ov5693) : 0, NULL); if (ret) return ret; @@ -557,17 +598,73 @@ static const struct v4l2_ctrl_ops ov5693_ctrl_ops = { /* System Control Functions */ +/* + * Registers the vendor (Windows) driver programs differently for the full + * resolution and the 2x2 binned readout, taken from the mode tables in + * ov5693.sys. + * + * The mainline driver writes only the full-resolution values, once, from + * ov5693_global_regs, and never revisits them. Selecting the binned mode + * therefore leaves the sensor with a MIPI PLL multiplier (0x30b3) and + * analogue readout timing meant for twice the line length. On an IPU6 the + * receiver then reports "Transfer FIFO overflow" and every frame arrives + * empty, which is why the binned mode has been unusable -- and why the + * sensor has had to be read at full resolution and downscaled, costing two + * stops of light and forcing the AGC to its maximum analogue gain. + */ +static const struct cci_reg_sequence ov5693_mode_full_regs[] = { + {CCI_REG8(0x30b3), 0x83}, /* MIPI PLL multiplier */ + {CCI_REG8(0x3620), 0x54}, + {CCI_REG8(0x3621), 0xc7}, + {CCI_REG8(0x3622), 0x0f}, + {CCI_REG8(0x3708), 0xe2}, + {CCI_REG8(0x3709), 0xc3}, + {CCI_REG8(0x371f), 0x0c}, +}; + +static const struct cci_reg_sequence ov5693_mode_binned_regs[] = { + {CCI_REG8(0x30b3), 0x70}, /* MIPI PLL multiplier */ + {CCI_REG8(0x3600), 0xbc}, /* analogue, vendor sets it binned-only */ + {CCI_REG8(0x3620), 0x44}, + {CCI_REG8(0x3621), 0xb5}, + {CCI_REG8(0x3622), 0x0c}, + {CCI_REG8(0x3708), 0xe6}, + {CCI_REG8(0x3709), 0xc7}, + {CCI_REG8(0x371f), 0x1f}, +}; + static int ov5693_mode_configure(struct ov5693_device *ov5693) { const struct ov5693_mode *mode = &ov5693->mode; + bool binned = mode->binning_x || mode->binning_y; int ret = 0; + /* + * Readout geometry. At full resolution this is the crop rectangle + * selected over the media API, with the sensor-ISP window offsets at + * zero. + * + * The binned mode instead copies the vendor driver: read the whole + * pixel array (0..2623 x 0..1955), bin it to 1312x978, and let the + * ISP window offsets place the 1296x972 output inside that. The + * vertical offset is 2 rather than the vendor's 3: an odd offset + * shifts the Bayer phase by one row (everything decodes magenta and + * green); the vendor ISP knows the resulting phase, a V4L2 receiver + * assumes it unchanged. The + * obvious alternative -- keeping the 2592x1944 crop so the binned + * readout exactly equals the output size with zero offset -- leaves + * the sensor ISP without spare pixels around the window, and the + * frames it emits then fail CSI-2 framing ("Frame sync error" on the + * IPU6, no frame ever completes). + */ + /* Crop Start X */ - cci_write(ov5693->regmap, OV5693_CROP_START_X_REG, mode->crop.left, - &ret); + cci_write(ov5693->regmap, OV5693_CROP_START_X_REG, + binned ? 0 : mode->crop.left, &ret); /* Offset X */ - cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, 0, &ret); + cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, + binned ? 8 : 0, &ret); /* Output Size X */ cci_write(ov5693->regmap, OV5693_OUTPUT_SIZE_X_REG, mode->format.width, @@ -575,18 +672,20 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) /* Crop End X */ cci_write(ov5693->regmap, OV5693_CROP_END_X_REG, - mode->crop.left + mode->crop.width, &ret); + binned ? OV5693_NATIVE_WIDTH - 1 : + mode->crop.left + mode->crop.width, &ret); /* Horizontal Total Size */ cci_write(ov5693->regmap, OV5693_TIMING_HTS_REG, OV5693_FIXED_PPL, &ret); /* Crop Start Y */ - cci_write(ov5693->regmap, OV5693_CROP_START_Y_REG, mode->crop.top, - &ret); + cci_write(ov5693->regmap, OV5693_CROP_START_Y_REG, + binned ? 0 : mode->crop.top, &ret); - /* Offset Y */ - cci_write(ov5693->regmap, OV5693_OFFSET_START_Y_REG, 0, &ret); + /* Offset Y: parity picks the Bayer phase, see binned_y_offset. */ + cci_write(ov5693->regmap, OV5693_OFFSET_START_Y_REG, + binned ? binned_y_offset : 0, &ret); /* Output Size Y */ cci_write(ov5693->regmap, OV5693_OUTPUT_SIZE_Y_REG, mode->format.height, @@ -594,7 +693,8 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) /* Crop End Y */ cci_write(ov5693->regmap, OV5693_CROP_END_Y_REG, - mode->crop.top + mode->crop.height, &ret); + binned ? OV5693_NATIVE_HEIGHT - 1 : + mode->crop.top + mode->crop.height, &ret); /* Subsample X increase */ cci_write(ov5693->regmap, OV5693_SUB_INC_X_REG, @@ -612,6 +712,24 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) OV5693_FORMAT2_HBIN_EN, mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0, &ret); + /* + * The set of FORMAT1 bits that means "vertical flip" changes with the + * readout mode, so re-apply the control now that binning is known. + */ + if (ov5693->ctrls.vflip && ov5693->ctrls.vflip->val) + cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, + OV5693_FORMAT1_FLIP_VERT_ISP_EN | + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN, + ov5693_flip_vert_bits(ov5693), &ret); + + /* PLL and analogue readout timing follow the readout mode. */ + if (mode->binning_x || mode->binning_y) + cci_multi_reg_write(ov5693->regmap, ov5693_mode_binned_regs, + ARRAY_SIZE(ov5693_mode_binned_regs), &ret); + else + cci_multi_reg_write(ov5693->regmap, ov5693_mode_full_regs, + ARRAY_SIZE(ov5693_mode_full_regs), &ret); + return ret; } @@ -783,6 +901,16 @@ static unsigned int __ov5693_calc_vts(u32 height) tgt_fps = rounddown(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / height, 30); + /* + * Cap at 30fps. Left alone this picks 60fps for the 2x2 binned mode, + * which halves VTS to 1038 -- and the binned readout runs off a slower + * MIPI PLL (0x30b3), so the link cannot carry twice the frame rate: + * the IPU6 reports "Frame sync error" and no frame ever completes. The + * vendor driver runs the same mode at VTS 1984. Staying at 30fps also + * keeps the exposure ceiling, which is VTS bound, where it was. + */ + tgt_fps = min(tgt_fps, 30U); + return ALIGN_DOWN(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / tgt_fps, 2); } From 1c5b33fb9a42aa295c5a7a2d363b18e1e09785b8 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 15 Oct 2026 22:53:04 +0200 Subject: [PATCH 12/21] media: i2c: ov5693: Surface Pro 5: upright front image by default The front OV5693 of the Surface Pro 5 is mounted vertically mirrored: the upright, unmirrored image needs the sensor vertical flip and no horizontal flip. The firmware reports a 180 degree rotation, which makes userspace enable both flips and leaves the image mirrored. ipu-bridge now reports 0 degrees for this sensor; invert the VFLIP control on the Surface Pro 5 (SKU 1796/1807) so that its default value gives the upright image. In the full 2592x1944 readout each flip also moves the Bayer phase by one column: with exactly one of them enabled the receiver gets GBRG instead of BGGR, which gives a magenta image through libcamera; with both enabled the two shifts cancel out. The crop start only moves in steps of two columns, so shift the output window by one column and widen the crop accordingly when hflip XOR vflip, and reprogram the window when either flip changes. The binned readout keeps its phase with either flip. Verified on a Surface Pro 5 (1796): raw full-resolution frames are BGGR for all four hflip/vflip combinations; upright and unmirrored in the full and in the binned 1296x972 mode, natural colours through libcamera. Tested-by: Chris Simpson # Surface Pro 9 (IPU6) Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov5693.c | 92 +++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index 3244f3806d804..cd5ba90d661c6 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -402,9 +403,82 @@ static u8 ov5693_flip_vert_bits(struct ov5693_device *ov5693) OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; } +/* + * On the Surface Pro 5 the front OV5693 is mounted vertically mirrored: the + * upright, unmirrored image needs the sensor's vertical flip and no horizontal + * flip (the firmware reports a 180 degree rotation instead, which would leave + * the image mirrored). Invert the VFLIP control so that its default (0) gives + * the upright image; ipu-bridge reports 0 degrees for this sensor. + */ +static const struct dmi_system_id ov5693_vflip_inverted_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + +static bool ov5693_vflip_enabled(bool ctrl_val) +{ + return ctrl_val ^ !!dmi_check_system(ov5693_vflip_inverted_dmi_ids); +} + +/* + * In the full readout each flip (ISP + sensor bits) moves the Bayer phase by + * one column, so with exactly one of them enabled the receiver gets GBRG + * instead of BGGR; with both enabled the two shifts cancel out. The crop + * start is only honoured in steps of two, so compensate by shifting the + * output window by one column instead, and widen the crop so the window still + * fits. The binned readout keeps its phase with either flip. + */ +static bool ov5693_bayer_shift(struct ov5693_device *ov5693) +{ + const struct ov5693_mode *mode = &ov5693->mode; + bool hflip, vflip; + + if (mode->binning_x || mode->binning_y) + return false; + + hflip = ov5693->ctrls.hflip && ov5693->ctrls.hflip->val; + vflip = ov5693->ctrls.vflip && + ov5693_vflip_enabled(ov5693->ctrls.vflip->val); + + return hflip ^ vflip; +} + +static int ov5693_window_x_configure(struct ov5693_device *ov5693) +{ + const struct ov5693_mode *mode = &ov5693->mode; + bool binned = mode->binning_x || mode->binning_y; + bool shift = ov5693_bayer_shift(ov5693); + int ret = 0; + + /* Offset X */ + cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, + binned ? 8 : shift, &ret); + + /* Crop End X */ + cci_write(ov5693->regmap, OV5693_CROP_END_X_REG, + binned ? OV5693_NATIVE_WIDTH - 1 : + mode->crop.left + mode->crop.width + + (shift ? 2 : 0), &ret); + + return ret; +} + static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable) { + enable = ov5693_vflip_enabled(enable); + u8 mask = OV5693_FORMAT1_FLIP_VERT_ISP_EN | OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; int ret; @@ -414,7 +488,7 @@ static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, if (ret) return ret; - return 0; + return ov5693_window_x_configure(ov5693); } static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, @@ -429,7 +503,7 @@ static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, if (ret) return ret; - return 0; + return ov5693_window_x_configure(ov5693); } static int ov5693_get_exposure(struct ov5693_device *ov5693, s32 *value) @@ -662,18 +736,13 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) cci_write(ov5693->regmap, OV5693_CROP_START_X_REG, binned ? 0 : mode->crop.left, &ret); - /* Offset X */ - cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, - binned ? 8 : 0, &ret); - /* Output Size X */ cci_write(ov5693->regmap, OV5693_OUTPUT_SIZE_X_REG, mode->format.width, &ret); - /* Crop End X */ - cci_write(ov5693->regmap, OV5693_CROP_END_X_REG, - binned ? OV5693_NATIVE_WIDTH - 1 : - mode->crop.left + mode->crop.width, &ret); + /* Offset X and Crop End X follow the flips, see ov5693_bayer_shift(). */ + if (!ret) + ret = ov5693_window_x_configure(ov5693); /* Horizontal Total Size */ cci_write(ov5693->regmap, OV5693_TIMING_HTS_REG, OV5693_FIXED_PPL, @@ -716,7 +785,8 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) * The set of FORMAT1 bits that means "vertical flip" changes with the * readout mode, so re-apply the control now that binning is known. */ - if (ov5693->ctrls.vflip && ov5693->ctrls.vflip->val) + if (ov5693->ctrls.vflip && + ov5693_vflip_enabled(ov5693->ctrls.vflip->val)) cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, OV5693_FORMAT1_FLIP_VERT_ISP_EN | OV5693_FORMAT1_FLIP_VERT_SENSOR_EN, From 1f16689cb58bfa4a9a55a07a9be76fb2329c0b93 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 15 Oct 2026 23:38:59 +0200 Subject: [PATCH 13/21] media: i2c: ov8865: Reset VBLANK on mode change, 30 fps default on Surface Pro 5 set_fmt() updates the VBLANK range and default for the new mode but keeps the current value when it is still in range. A value left over from the previous mode then keeps that mode's timing: after the full-size mode (VBLANK 22) the 800x600 mode runs faster than its nominal 90 fps, with the exposure capped accordingly. Set VBLANK to the mode default on every active format change, and derive the exposure range from it. On the Surface Pro 5 the rear camera is used through libcamera's IPU3 pipeline, which does not change the frame length. With the 800x600 mode, which libcamera picks for 640x480 and smaller requests, the exposure is limited to ~11 ms and indoor images are black even at maximum analogue gain. On this machine (SKU 1796/1807) default that mode to 30 fps by tripling its frame length; higher frame rates remain available through VBLANK. Verified on a Surface Pro 5 (1796): 800x600 at 30.6 fps with the full exposure range usable. Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov8865.c | 52 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index 104ba4770efb0..eff9919b542b3 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2726,6 +2726,43 @@ static int ov8865_get_fmt(struct v4l2_subdev *subdev, return 0; } +/* + * The Surface Pro 5 exposes the rear camera through libcamera's IPU3 + * pipeline, which does not change the frame length. In the 800x600 mode + * (90 fps) the exposure is then capped at ~11 ms and indoor images are + * black even at maximum gain, so default to 30 fps there. Higher frame + * rates stay available through VBLANK. + */ +static const struct dmi_system_id ov8865_30fps_default_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + +/* The 800x600 mode is the only one faster than 30 fps: 90 fps at its VTS. */ +#define OV8865_SVGA_FPS_DIVIDER 3 + +static u32 ov8865_vblank_default(const struct ov8865_mode *mode) +{ + u32 vts = mode->vts; + + if (mode->output_size_x == 800 && mode->output_size_y == 600 && + dmi_check_system(ov8865_30fps_default_dmi_ids)) + vts *= OV8865_SVGA_FPS_DIVIDER; + + return vts - mode->output_size_y; +} + static int ov8865_set_fmt(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) @@ -2736,6 +2773,7 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev, u32 mbus_code = 0; unsigned int hblank; unsigned int index; + u32 vblank_def; int exposure_max; int ret = 0; @@ -2776,15 +2814,25 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev, sensor->state.mbus_code != mbus_code) ret = ov8865_state_configure(sensor, mode, mbus_code); + vblank_def = ov8865_vblank_default(mode); __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV8865_TIMING_MIN_VTS, OV8865_TIMING_MAX_VTS - mode->output_size_y, - 1, mode->vts - mode->output_size_y); + 1, vblank_def); + + /* + * Start every mode from its default frame length: a VBLANK value left + * over from the previous mode would keep that mode's timing (e.g. the + * full-size mode's 22 lines make the 800x600 mode run at ~93 fps). + */ + if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) + __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, vblank_def); hblank = mode->hts - mode->output_size_x; __v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1, hblank); - exposure_max = mode->vts - OV8865_INTEGRATION_TIME_MARGIN; + exposure_max = mode->output_size_y + vblank_def - + OV8865_INTEGRATION_TIME_MARGIN; __v4l2_ctrl_modify_range(sensor->ctrls.exposure, sensor->ctrls.exposure->minimum, exposure_max, sensor->ctrls.exposure->step, From e3976f20b734208184c8fba493206cf50f6aabbe Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Fri, 16 Oct 2026 10:05:05 +0200 Subject: [PATCH 14/21] media: i2c: ov8865: Fix the VTS high byte mask Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov8865.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index eff9919b542b3..a3289d2305c36 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -181,10 +181,10 @@ #define OV8865_HTS_L_REG 0x380d #define OV8865_HTS_L(v) ((v) & GENMASK(7, 0)) #define OV8865_VTS_H_REG 0x380e -#define OV8865_VTS_H(v) (((v) & GENMASK(11, 8)) >> 8) +#define OV8865_VTS_H(v) (((v) & GENMASK(14, 8)) >> 8) #define OV8865_VTS_L_REG 0x380f #define OV8865_VTS_L(v) ((v) & GENMASK(7, 0)) -#define OV8865_TIMING_MAX_VTS 0xffff +#define OV8865_TIMING_MAX_VTS 0x7fff #define OV8865_TIMING_MIN_VTS 0x04 #define OV8865_OFFSET_X_H_REG 0x3810 #define OV8865_OFFSET_X_H(v) (((v) & GENMASK(15, 8)) >> 8) From 233239b2246dfe4dbcf10230c33674ca05be1bcd Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Fri, 16 Oct 2026 10:05:24 +0200 Subject: [PATCH 15/21] media: i2c: ov8865: Allow fine analogue gain steps Tested-by: Firas Sharary <29305778+T-Caster@users.noreply.github.com> # Surface Pro 7+ (IPU6) Tested-by: irishchug <75328733+irishchug@users.noreply.github.com> # Surface Book 2 Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov8865.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index a3289d2305c36..14fcba8bbc027 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2553,7 +2553,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor) /* Gain */ - v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 128, + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 1, 128); /* White Balance */ From f1c8495159d8a1a778a7bcae937e8b3ac7bc8e75 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Fri, 16 Oct 2026 10:05:24 +0200 Subject: [PATCH 16/21] media: i2c: ov5693: 30 fps binned readout values With the readout and MIPI PLL values of the 60 fps binned mode, the IPU3 CIO2 of the Surface Pro 5 loses several frames per stream ("frame sync error", payloads of 778 or 831 lines instead of 972). The 30 fps binned values (MIPI PLL multiplier 0x7d, analogue 0x3620-0x3622, 0x3708, 0x3709, 0x371f) stream cleanly: 90 of 90 frames, no errors, through libcamera at 640x480. Use them by default; the module parameter binned_regs selects the old set (0) or the 30 fps values with the full-mode PLL (2). Also set 0x4307 to 0x30 and add a blc_target parameter for the black level target (0x4009) for further tuning. Tested-by: Chris Simpson # Surface Pro 9 (IPU6) Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov5693.c | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index cd5ba90d661c6..062d7a64b05e7 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -322,7 +322,7 @@ static const struct cci_reg_sequence ov5693_global_regs[] = { {CCI_REG8(0x4009), 0x10}, {CCI_REG8(0x4058), 0x00}, {CCI_REG8(0x4101), 0xb2}, - {CCI_REG8(0x4307), 0x31}, + {CCI_REG8(0x4307), 0x30}, {CCI_REG8(0x4511), 0x05}, {CCI_REG8(0x4512), 0x01}, {CCI_REG8(0x481f), 0x30}, @@ -707,6 +707,33 @@ static const struct cci_reg_sequence ov5693_mode_binned_regs[] = { {CCI_REG8(0x371f), 0x1f}, }; +/* + * Binned readout set. With the 60 fps values (0) the IPU3 CIO2 of the + * Surface Pro 5 loses several frames per stream ("frame sync error", + * short payloads); the 30 fps values (1, default) stream cleanly. + * binned_regs = 0: readout and MIPI PLL of the 60 fps binned mode + * binned_regs = 1: 30 fps binned values, MIPI PLL multiplier 0x7d + * binned_regs = 2: 30 fps binned values with the full-mode PLL (0x83) + * blc_target: black level target (0x4009); 0 leaves the default. + */ +static int binned_regs = 1; +module_param(binned_regs, int, 0644); +MODULE_PARM_DESC(binned_regs, "binned readout set (0=60fps, 1=30fps, 2=30fps+full PLL)"); + +static int blc_target; +module_param(blc_target, int, 0644); +MODULE_PARM_DESC(blc_target, "black level target 0x4009 (0=default)"); + +static const struct cci_reg_sequence ov5693_mode_binned30_regs[] = { + {CCI_REG8(0x30b3), 0x7d}, /* MIPI PLL multiplier */ + {CCI_REG8(0x3620), 0x54}, + {CCI_REG8(0x3621), 0xc7}, + {CCI_REG8(0x3622), 0x0f}, + {CCI_REG8(0x3708), 0xe6}, + {CCI_REG8(0x3709), 0xc7}, + {CCI_REG8(0x371f), 0x0c}, +}; + static int ov5693_mode_configure(struct ov5693_device *ov5693) { const struct ov5693_mode *mode = &ov5693->mode; @@ -793,13 +820,22 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) ov5693_flip_vert_bits(ov5693), &ret); /* PLL and analogue readout timing follow the readout mode. */ - if (mode->binning_x || mode->binning_y) + if ((mode->binning_x || mode->binning_y) && binned_regs) { + cci_multi_reg_write(ov5693->regmap, ov5693_mode_binned30_regs, + ARRAY_SIZE(ov5693_mode_binned30_regs), &ret); + if (binned_regs == 2) + cci_write(ov5693->regmap, CCI_REG8(0x30b3), 0x83, &ret); + } else if (mode->binning_x || mode->binning_y) cci_multi_reg_write(ov5693->regmap, ov5693_mode_binned_regs, ARRAY_SIZE(ov5693_mode_binned_regs), &ret); else cci_multi_reg_write(ov5693->regmap, ov5693_mode_full_regs, ARRAY_SIZE(ov5693_mode_full_regs), &ret); + if (blc_target) + cci_write(ov5693->regmap, CCI_REG8(0x4009), blc_target & 0xff, + &ret); + return ret; } From ece47eacfa158e7efd49a2f611492478fdace718 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Fri, 16 Oct 2026 10:05:46 +0200 Subject: [PATCH 17/21] media: i2c: ov7251: Surface IR strobe pulse follows the exposure Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov7251.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 14133dccde22e..a15df177b0338 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -285,6 +285,18 @@ static const struct reg_value ov7251_surface_ir_strobe_regs[] = { { 0x3b96, 0xc0 }, }; +/* + * Strobe pattern (0x3b81): 0xaa lights alternate frames, 0xff every frame. + * The strobe pulse follows the exposure time (0x3b8c-0x3b8f, in lines), + * clamped to the range the Surface uses. + */ +static int surface_ir_pattern = 0xaa; +module_param(surface_ir_pattern, int, 0644); +MODULE_PARM_DESC(surface_ir_pattern, "IR strobe pattern 0x3b81 (0xaa alternate frames, 0xff every frame)"); + +#define OV7251_STROBE_MIN_LINES 52 +#define OV7251_STROBE_MAX_LINES 776 + static bool ov7251_use_surface_ir_strobe(void) { if (surface_ir_strobe >= 0) @@ -924,13 +936,28 @@ static int ov7251_set_exposure(struct ov7251 *ov7251, s32 exposure) { u16 reg; u8 val[3]; + s32 strobe; + int ret; reg = OV7251_AEC_EXPO_0; val[0] = (exposure & 0xf000) >> 12; /* goes to OV7251_AEC_EXPO_0 */ val[1] = (exposure & 0x0ff0) >> 4; /* goes to OV7251_AEC_EXPO_1 */ val[2] = (exposure & 0x000f) << 4; /* goes to OV7251_AEC_EXPO_2 */ - return ov7251_write_seq_regs(ov7251, reg, val, 3); + ret = ov7251_write_seq_regs(ov7251, reg, val, 3); + if (ret < 0 || !ov7251_use_surface_ir_strobe()) + return ret; + + strobe = clamp_t(s32, exposure, OV7251_STROBE_MIN_LINES, + OV7251_STROBE_MAX_LINES); + val[0] = 0; + val[1] = 0; + val[2] = strobe >> 8; + ret = ov7251_write_seq_regs(ov7251, 0x3b8c, val, 3); + if (ret < 0) + return ret; + + return ov7251_write_reg(ov7251, 0x3b8f, strobe & 0xff); } static int ov7251_set_gain(struct ov7251 *ov7251, s32 gain) @@ -1425,6 +1452,9 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable) ret = ov7251_set_register_array(ov7251, ov7251_surface_ir_strobe_regs, ARRAY_SIZE(ov7251_surface_ir_strobe_regs)); + if (!ret) + ret = ov7251_write_reg(ov7251, 0x3b81, + surface_ir_pattern & 0xff); if (ret < 0) { dev_err(ov7251->dev, "could not set IR strobe\n"); goto err_power_down; From f8850d8db484530fbace36020c5400c30eb5a1f5 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 5 Nov 2026 08:52:19 +0100 Subject: [PATCH 18/21] media: Surface Pro 4: same camera orientation quirks as the Pro 5 The Surface Pro 4 (IPU3, DMI SKU "Surface_Pro_4") has the same cameras as the Pro 5 and the same mounting: the SSDB reports a 180 degree rotation for the front OV5693 and the rear OV8865, but both sensors only need a vertical flip. Applying the reported rotation leaves both images mirrored. Add the Pro 4 to the ipu-bridge list of sensors that are not rotated and to the VFLIP inversion lists of ov5693 and ov8865, as for the Pro 5. Checked on a Surface Pro 4 with a letter held in front of each camera: the raw frames of both sensors show a vertical flip only, and after the reported 180 degree rotation the letter is mirrored. Reported-by: technosf Link: https://github.com/linux-surface/kernel/pull/181#issuecomment-6651694374 Tested-by: technosf # Surface Pro 4 Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov5693.c | 16 +++++++++++----- drivers/media/i2c/ov8865.c | 10 ++++++++-- drivers/media/pci/intel/ipu-bridge.c | 20 +++++++++++++++++--- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index 062d7a64b05e7..ea87b4edbda89 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -404,13 +404,19 @@ static u8 ov5693_flip_vert_bits(struct ov5693_device *ov5693) } /* - * On the Surface Pro 5 the front OV5693 is mounted vertically mirrored: the - * upright, unmirrored image needs the sensor's vertical flip and no horizontal - * flip (the firmware reports a 180 degree rotation instead, which would leave - * the image mirrored). Invert the VFLIP control so that its default (0) gives - * the upright image; ipu-bridge reports 0 degrees for this sensor. + * On the Surface Pro 4 and 5 the front OV5693 is mounted vertically mirrored: + * the upright, unmirrored image needs the sensor's vertical flip and no + * horizontal flip (the firmware reports a 180 degree rotation instead, which + * would leave the image mirrored). Invert the VFLIP control so that its default + * (0) gives the upright image; ipu-bridge reports 0 degrees for this sensor. */ static const struct dmi_system_id ov5693_vflip_inverted_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index 14fcba8bbc027..c0a3e803243a3 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2191,11 +2191,17 @@ static int ov8865_blue_balance_configure(struct ov8865_sensor *sensor, /* Flip */ /* - * On the Surface Pro 5 the rear OV8865 is mounted vertically mirrored: the - * upright image needs the sensor's vertical flip enabled. Invert the VFLIP + * On the Surface Pro 4 and 5 the rear OV8865 is mounted vertically mirrored: + * the upright image needs the sensor's vertical flip enabled. Invert the VFLIP * control so that the default (0) gives an upright image. */ static const struct dmi_system_id ov8865_vflip_inverted_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 77097a844acd4..a56761848656c 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -238,12 +238,26 @@ static const struct dmi_system_id upside_down_sensor_dmi_ids[] = { /* * DMI matches for devices whose SSDB reports a 180° rotation for sensors that - * are not actually rotated. On the Surface Pro 5 the firmware reports 180° for - * both the front (OV5693) and the rear (OV8865) camera. Measured on the - * device, both need a vertical flip only and no mirroring, which is not a + * are not actually rotated. On the Surface Pro 4 and 5 the firmware reports + * 180° for both the front (OV5693) and the rear (OV8865) camera. Measured on + * the devices, both need a vertical flip only and no mirroring, which is not a * rotation: report 0 degrees and let the sensor drivers apply the flip. */ static const struct dmi_system_id not_rotated_sensor_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + .driver_data = "INT347A", + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), From 469453c0dfef85cf5fc4ad1c9be081702f4634b4 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Mon, 23 Nov 2026 08:58:15 +0100 Subject: [PATCH 19/21] media: i2c: ov7251: Surface Pro 6: enable the IR illuminator strobe The Surface Pro 6 (DMI SKU "Surface_Pro_6_1796_Consumer") drives its IR flood LED from the OV7251 STROBE pad like the Pro 5, and the mode tables leave the pad disabled there too, so IR frames stay at black level. Add it to the DMI list that enables the strobe by default. Checked on a Surface Pro 6 with the stock linux-surface 7.3.4 kernel, by writing the strobe registers over I2C while the sensor streamed: the mean frame level rose from about 16 to about 163 with the LED on every frame, and to about 90 with the alternate-frame pattern (0xaa) used by this driver. Other Pro 6 SKUs can be added once reported. Reported-by: Moritz <24388294+Blightbuster@users.noreply.github.com> Link: https://github.com/linux-surface/kernel/pull/181#issuecomment-7087893475 Tested-by: Moritz <24388294+Blightbuster@users.noreply.github.com> # Surface Pro 6 Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov7251.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index a15df177b0338..ba0b9a04b0b40 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -238,10 +238,11 @@ static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = { /* * Surface IR flood illuminator. * - * On the Surface Pro 5 the IR LED is driven by the sensor's STROBE pad, not by - * a GPIO or the TPS68470 LED outputs, and ACPI does not describe it. The mode - * tables leave the pad disabled (0x3005 = 0x00, 0x3016-0x301c = 0xf0), so the - * LED never lights and the IR camera (behind an IR-pass filter) sees black. + * On the Surface Pro 5 and 6 the IR LED is driven by the sensor's STROBE pad, + * not by a GPIO or the TPS68470 LED outputs, and ACPI does not describe it. + * The mode tables leave the pad disabled (0x3005 = 0x00, 0x3016-0x301c = + * 0xf0), so the LED never lights and the IR camera (behind an IR-pass filter) + * sees black. * * 0x3b81 is the strobe pattern: 0xaa lights the LED on alternate frames, so * userspace gets lit and unlit frames for ambient light subtraction. @@ -266,6 +267,13 @@ static const struct dmi_system_id ov7251_surface_ir_strobe_dmi_ids[] = { DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), }, }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, + "Surface_Pro_6_1796_Consumer"), + }, + }, {} }; From 1ba4255aa90b8da64a65e60ddbba5eab7c2840d8 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 3 Dec 2026 18:38:50 +0100 Subject: [PATCH 20/21] media: Surface Book 2: same camera orientation quirks as the Pro 5 The Surface Book 2 (DMI SKU "Surface_Book_1793") has the same front OV5693 and rear OV8865 as the Pro 5, with the same ACPI IDs (INT33BE, INT347A) and the same mounting: the SSDB reports a 180 degree rotation for both, but both only need a vertical flip, so libcamera's hflip + vflip leaves both images mirrored. Add the Book 2 to the ipu-bridge list of sensors that are not rotated and to the VFLIP inversion lists of ov5693 and ov8865, as for the Pro 4 and Pro 5. Reported-by: irishchug <75328733+irishchug@users.noreply.github.com> Link: https://github.com/linux-surface/kernel/pull/181#issuecomment-7234674803 Tested-by: irishchug <75328733+irishchug@users.noreply.github.com> # Surface Book 2 Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov5693.c | 17 ++++++++++++----- drivers/media/i2c/ov8865.c | 13 ++++++++++--- drivers/media/pci/intel/ipu-bridge.c | 23 +++++++++++++++++++---- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index ea87b4edbda89..6b8282562d9e3 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -404,11 +404,12 @@ static u8 ov5693_flip_vert_bits(struct ov5693_device *ov5693) } /* - * On the Surface Pro 4 and 5 the front OV5693 is mounted vertically mirrored: - * the upright, unmirrored image needs the sensor's vertical flip and no - * horizontal flip (the firmware reports a 180 degree rotation instead, which - * would leave the image mirrored). Invert the VFLIP control so that its default - * (0) gives the upright image; ipu-bridge reports 0 degrees for this sensor. + * On the Surface Pro 4 and 5 and the Surface Book 2 the front OV5693 is mounted + * vertically mirrored: the upright, unmirrored image needs the sensor's + * vertical flip and no horizontal flip (the firmware reports a 180 degree + * rotation instead, which would leave the image mirrored). Invert the VFLIP + * control so that its default (0) gives the upright image; ipu-bridge reports + * 0 degrees for this sensor. */ static const struct dmi_system_id ov5693_vflip_inverted_dmi_ids[] = { { @@ -417,6 +418,12 @@ static const struct dmi_system_id ov5693_vflip_inverted_dmi_ids[] = { DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), }, }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index c0a3e803243a3..247b66ac359f0 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2191,9 +2191,10 @@ static int ov8865_blue_balance_configure(struct ov8865_sensor *sensor, /* Flip */ /* - * On the Surface Pro 4 and 5 the rear OV8865 is mounted vertically mirrored: - * the upright image needs the sensor's vertical flip enabled. Invert the VFLIP - * control so that the default (0) gives an upright image. + * On the Surface Pro 4 and 5 and the Surface Book 2 the rear OV8865 is mounted + * vertically mirrored: the upright image needs the sensor's vertical flip + * enabled. Invert the VFLIP control so that the default (0) gives an upright + * image. */ static const struct dmi_system_id ov8865_vflip_inverted_dmi_ids[] = { { @@ -2202,6 +2203,12 @@ static const struct dmi_system_id ov8865_vflip_inverted_dmi_ids[] = { DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), }, }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index a56761848656c..c9b9dcbc355a6 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -238,10 +238,11 @@ static const struct dmi_system_id upside_down_sensor_dmi_ids[] = { /* * DMI matches for devices whose SSDB reports a 180° rotation for sensors that - * are not actually rotated. On the Surface Pro 4 and 5 the firmware reports - * 180° for both the front (OV5693) and the rear (OV8865) camera. Measured on - * the devices, both need a vertical flip only and no mirroring, which is not a - * rotation: report 0 degrees and let the sensor drivers apply the flip. + * are not actually rotated. On the Surface Pro 4 and 5 and the Surface Book 2 + * the firmware reports 180° for both the front (OV5693) and the rear (OV8865) + * camera. Measured on the devices, both need a vertical flip only and no + * mirroring, which is not a rotation: report 0 degrees and let the sensor + * drivers apply the flip. */ static const struct dmi_system_id not_rotated_sensor_dmi_ids[] = { { @@ -251,6 +252,13 @@ static const struct dmi_system_id not_rotated_sensor_dmi_ids[] = { }, .driver_data = "INT33BE", }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + .driver_data = "INT33BE", + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), @@ -258,6 +266,13 @@ static const struct dmi_system_id not_rotated_sensor_dmi_ids[] = { }, .driver_data = "INT347A", }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + .driver_data = "INT347A", + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), From f89440a2bde52f5af6391dd1b1dc1a3aaa146df9 Mon Sep 17 00:00:00 2001 From: Marco Ziliani Date: Thu, 3 Dec 2026 18:39:00 +0100 Subject: [PATCH 21/21] media: i2c: ov7251: Surface Book 2: enable the IR illuminator strobe The Surface Book 2 (DMI SKU "Surface_Book_1793") drives its IR flood LED from the OV7251 STROBE pad like the Pro 5 and 6, and the mode tables leave the pad disabled there too, so IR frames stay at black level. Add it to the DMI list that enables the strobe by default. Checked on a Surface Book 2: with the strobe registers written over I2C the frame mean rose from 16 to 73 with the LED on every frame, and with this entry the LED fires on stream start with the default alternate pattern (frames alternate 16 / 72). Face login with howdy works. Reported-by: irishchug <75328733+irishchug@users.noreply.github.com> Link: https://github.com/linux-surface/kernel/pull/181#issuecomment-7233093153 Tested-by: irishchug <75328733+irishchug@users.noreply.github.com> # Surface Book 2 Signed-off-by: Marco Ziliani Patchset: cameras --- drivers/media/i2c/ov7251.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index ba0b9a04b0b40..b59a4f668b088 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -238,11 +238,11 @@ static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = { /* * Surface IR flood illuminator. * - * On the Surface Pro 5 and 6 the IR LED is driven by the sensor's STROBE pad, - * not by a GPIO or the TPS68470 LED outputs, and ACPI does not describe it. - * The mode tables leave the pad disabled (0x3005 = 0x00, 0x3016-0x301c = - * 0xf0), so the LED never lights and the IR camera (behind an IR-pass filter) - * sees black. + * On the Surface Pro 5 and 6 and the Surface Book 2 the IR LED is driven by + * the sensor's STROBE pad, not by a GPIO or the TPS68470 LED outputs, and ACPI + * does not describe it. The mode tables leave the pad disabled (0x3005 = 0x00, + * 0x3016-0x301c = 0xf0), so the LED never lights and the IR camera (behind an + * IR-pass filter) sees black. * * 0x3b81 is the strobe pattern: 0xaa lights the LED on alternate frames, so * userspace gets lit and unlit frames for ambient light subtraction. @@ -274,6 +274,12 @@ static const struct dmi_system_id ov7251_surface_ir_strobe_dmi_ids[] = { "Surface_Pro_6_1796_Consumer"), }, }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + }, {} };