* [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:53 ` Laurent Pinchart
2026-11-21 13:31 ` [PATCH v11 02/14] media: ov8858: Extract digital gain programming Maurizio Casciano
` (12 subsequent siblings)
13 siblings, 1 reply; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
Subdevice node registration skips nodes which already exist. On failure,
however, it walks the subdevice list from the beginning and unregisters
nodes regardless of whether the current call created them. On AtomISP
this can remove the camera sensor nodes when a lens rebind fails.
Keep a list of the video devices registered by this call and unregister
only those devices on failure. Record each device before creating its
media interface link so a failure in that step rolls back the new node
as well. Calls with no missing nodes need no bookkeeping allocation.
Codex drafted the change and tested allocation, registration and
media-link failure using the registration helper with mocked operations.
Fixes: db0f4691d974 ("[media] v4l: Allow calling v4l2_device_register_subdev_nodes() multiple times")
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
drivers/media/v4l2-core/v4l2-device.c | 26 ++++++++++++++++++++------
include/media/v4l2-device.h | 3 +++
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index b4036105c..8cfca95ce 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -191,10 +191,23 @@ static void v4l2_device_release_subdev_node(struct video_device *vdev)
int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
bool read_only)
{
+ unsigned int count = 0, registered = 0;
+ struct video_device **new_nodes;
struct video_device *vdev;
struct v4l2_subdev *sd;
int err;
+ list_for_each_entry(sd, &v4l2_dev->subdevs, list)
+ if ((sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE) && !sd->devnode)
+ count++;
+
+ if (!count)
+ return 0;
+
+ new_nodes = kcalloc(count, sizeof(*new_nodes), GFP_KERNEL);
+ if (!new_nodes)
+ return -ENOMEM;
+
/* Register a device node for every subdev marked with the
* V4L2_SUBDEV_FL_HAS_DEVNODE flag.
*/
@@ -228,6 +241,7 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
kfree(vdev);
goto clean_up;
}
+ new_nodes[registered++] = vdev;
#if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.info.dev.major = VIDEO_MAJOR;
sd->entity.info.dev.minor = vdev->minor;
@@ -247,15 +261,15 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
}
#endif
}
- return 0;
+ err = 0;
+ goto out;
clean_up:
- list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
- if (!sd->devnode)
- break;
- video_unregister_device(sd->devnode);
- }
+ while (registered)
+ video_unregister_device(new_nodes[--registered]);
+out:
+ kfree(new_nodes);
return err;
}
EXPORT_SYMBOL_GPL(__v4l2_device_register_subdev_nodes);
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index 25f69b1b8..6d8834d40 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -183,6 +183,9 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
* @read_only: subdevices read-only flag. True to register the subdevices
* device nodes in read-only mode, false to allow full access to the
* subdevice userspace API.
+ *
+ * Existing nodes are kept even if registration of a new node fails.
+ * The caller must serialize this operation with changes to the subdevice list.
*/
int __must_check
__v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback
2026-11-21 13:31 ` [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback Maurizio Casciano
@ 2026-11-21 13:53 ` Laurent Pinchart
0 siblings, 0 replies; 16+ messages in thread
From: Laurent Pinchart @ 2026-11-21 13:53 UTC (permalink / raw)
To: Maurizio Casciano
Cc: linux-media, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging
On Sat, Nov 21, 2026 at 02:31:31PM +0100, Maurizio Casciano wrote:
> Subdevice node registration skips nodes which already exist. On failure,
> however, it walks the subdevice list from the beginning and unregisters
> nodes regardless of whether the current call created them. On AtomISP
> this can remove the camera sensor nodes when a lens rebind fails.
>
> Keep a list of the video devices registered by this call and unregister
> only those devices on failure. Record each device before creating its
> media interface link so a failure in that step rolls back the new node
> as well. Calls with no missing nodes need no bookkeeping allocation.
>
> Codex drafted the change and tested allocation, registration and
> media-link failure using the registration helper with mocked operations.
And you didn't understand the change, because this is clearly not right.
NAK.
> Fixes: db0f4691d974 ("[media] v4l: Allow calling v4l2_device_register_subdev_nodes() multiple times")
> Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
> ---
> drivers/media/v4l2-core/v4l2-device.c | 26 ++++++++++++++++++++------
> include/media/v4l2-device.h | 3 +++
> 2 files changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> index b4036105c..8cfca95ce 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -191,10 +191,23 @@ static void v4l2_device_release_subdev_node(struct video_device *vdev)
> int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> bool read_only)
> {
> + unsigned int count = 0, registered = 0;
> + struct video_device **new_nodes;
> struct video_device *vdev;
> struct v4l2_subdev *sd;
> int err;
>
> + list_for_each_entry(sd, &v4l2_dev->subdevs, list)
> + if ((sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE) && !sd->devnode)
> + count++;
> +
> + if (!count)
> + return 0;
> +
> + new_nodes = kcalloc(count, sizeof(*new_nodes), GFP_KERNEL);
> + if (!new_nodes)
> + return -ENOMEM;
> +
> /* Register a device node for every subdev marked with the
> * V4L2_SUBDEV_FL_HAS_DEVNODE flag.
> */
> @@ -228,6 +241,7 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> kfree(vdev);
> goto clean_up;
> }
> + new_nodes[registered++] = vdev;
> #if defined(CONFIG_MEDIA_CONTROLLER)
> sd->entity.info.dev.major = VIDEO_MAJOR;
> sd->entity.info.dev.minor = vdev->minor;
> @@ -247,15 +261,15 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> }
> #endif
> }
> - return 0;
> + err = 0;
> + goto out;
>
> clean_up:
> - list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> - if (!sd->devnode)
> - break;
> - video_unregister_device(sd->devnode);
> - }
> + while (registered)
> + video_unregister_device(new_nodes[--registered]);
>
> +out:
> + kfree(new_nodes);
> return err;
> }
> EXPORT_SYMBOL_GPL(__v4l2_device_register_subdev_nodes);
> diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
> index 25f69b1b8..6d8834d40 100644
> --- a/include/media/v4l2-device.h
> +++ b/include/media/v4l2-device.h
> @@ -183,6 +183,9 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
> * @read_only: subdevices read-only flag. True to register the subdevices
> * device nodes in read-only mode, false to allow full access to the
> * subdevice userspace API.
> + *
> + * Existing nodes are kept even if registration of a new node fails.
> + * The caller must serialize this operation with changes to the subdevice list.
> */
> int __must_check
> __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> --
> 2.53.0
>
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v11 02/14] media: ov8858: Extract digital gain programming
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 03/14] media: ov8858: Support a 19.2 MHz input clock on four-lane R2A Maurizio Casciano
` (11 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
Move the existing packed digital-gain register programming into a
helper so clock-specific gain handling can be added separately.
This is a pure refactoring: preserve both the register packing and the
explanatory comment without changing the bytes written to the sensor.
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
drivers/media/i2c/ov8858.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c
index 97448fa75..295c34817 100644
--- a/drivers/media/i2c/ov8858.c
+++ b/drivers/media/i2c/ov8858.c
@@ -1525,6 +1525,23 @@ static int ov8858_enable_test_pattern(struct ov8858 *ov8858, u32 pattern)
return ov8858_write(ov8858, OV8858_REG_TEST_PATTERN, val, NULL);
}
+static int ov8858_set_long_digital_gain(struct ov8858 *ov8858, u32 gain)
+{
+ u16 long_gain;
+
+ /*
+ * Digital gain is assembled as:
+ * 0x350a[7:0] = dgain[13:6]
+ * 0x350b[5:0] = dgain[5:0]
+ * Reassemble the control value to write it in one go.
+ */
+ long_gain = (gain & OV8858_LONG_DIGIGAIN_L_MASK) |
+ ((gain & OV8858_LONG_DIGIGAIN_H_MASK) <<
+ OV8858_LONG_DIGIGAIN_H_SHIFT);
+
+ return ov8858_write(ov8858, OV8858_REG_LONG_DIGIGAIN, long_gain, NULL);
+}
+
static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
{
struct ov8858 *ov8858 = container_of(ctrl->handler,
@@ -1533,7 +1550,6 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
struct v4l2_mbus_framefmt *format;
struct v4l2_subdev_state *state;
- u16 digi_gain;
s64 max_exp;
int ret;
@@ -1572,17 +1588,7 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
ctrl->val, NULL);
break;
case V4L2_CID_DIGITAL_GAIN:
- /*
- * Digital gain is assembled as:
- * 0x350a[7:0] = dgain[13:6]
- * 0x350b[5:0] = dgain[5:0]
- * Reassemble the control value to write it in one go.
- */
- digi_gain = (ctrl->val & OV8858_LONG_DIGIGAIN_L_MASK)
- | ((ctrl->val & OV8858_LONG_DIGIGAIN_H_MASK) <<
- OV8858_LONG_DIGIGAIN_H_SHIFT);
- ret = ov8858_write(ov8858, OV8858_REG_LONG_DIGIGAIN,
- digi_gain, NULL);
+ ret = ov8858_set_long_digital_gain(ov8858, ctrl->val);
break;
case V4L2_CID_VBLANK:
ret = ov8858_write(ov8858, OV8858_REG_VTS,
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 03/14] media: ov8858: Support a 19.2 MHz input clock on four-lane R2A
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 02/14] media: ov8858: Extract digital gain programming Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 04/14] media: ov2740: Add OVTI2740 ACPI ID Maurizio Casciano
` (10 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The Yoga Book rear sensor uses a 19.2 MHz input clock with a 360 MHz
CSI-2 link frequency. Restrict the new clock table to four-lane R2A,
the configuration tested on the Yoga Book X91L. Retain the 24 MHz
tables for each existing variant and lane count. Base the power-on
delay on the selected input frequency.
Eighteen entries in the 19.2 MHz table match Intel's GPLv2 OV8858
initialization table from the Yoga Book vendor kernel. Retain its
2014 Intel copyright notice. The existing driver already uses
0x3f08 = 0x08. The four adjusted PLL entries at 0x0300, 0x0302,
0x030b and 0x030d are retained from the first public Yoga Book
patch. The source of those adjustments before that posting is
unverified.
Codex split the original patch, added the revision and lane-count
check and compared the register sources.
Link: https://github.com/jekhor/yogabook-linux-android-kernel/blob/574bae692716f1b14093497bfab8a007fe8e460b/drivers/external_drivers/camera/drivers/media/i2c/ov8858.h
Link: https://lkml.iu.edu/2608.3/05469.html
Link: https://linuxtv.org/mailman3/hyperkitty/list/media-ci@linuxtv.org/message/PWB2NAGYQ7EZVEDZNXK3R3UKZ7GGYAQY/
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
drivers/media/i2c/ov8858.c | 142 ++++++++++++++++++++++++++++---------
1 file changed, 107 insertions(+), 35 deletions(-)
diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c
index 295c34817..7b337dc93 100644
--- a/drivers/media/i2c/ov8858.c
+++ b/drivers/media/i2c/ov8858.c
@@ -3,10 +3,9 @@
* Copyright (C) 2023 Jacopo Mondi <jacopo.mondi@ideasonboard.com>
* Copyright (C) 2022 Nicholas Roth <nicholas@rothemail.net>
* Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
*/
-#include <linux/unaligned.h>
-
#include <linux/acpi.h>
#include <linux/clk.h>
#include <linux/delay.h>
@@ -19,6 +18,8 @@
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
+#include <linux/unaligned.h>
+#include <linux/units.h>
#include <media/media-entity.h>
#include <media/v4l2-async.h>
@@ -29,8 +30,9 @@
#include <media/v4l2-mediabus.h>
#include <media/v4l2-subdev.h>
-#define OV8858_LINK_FREQ 360000000U
-#define OV8858_XVCLK_FREQ 24000000
+#define OV8858_LINK_FREQ (360 * HZ_PER_MHZ)
+#define OV8858_XVCLK_FREQ_24MHZ (24000 * HZ_PER_KHZ)
+#define OV8858_XVCLK_FREQ_19_2MHZ (19200 * HZ_PER_KHZ)
#define OV8858_REG_SIZE_SHIFT 16
#define OV8858_REG_ADDR_MASK 0xffff
@@ -105,6 +107,7 @@ struct ov8858_mode {
struct ov8858 {
struct clk *xvclk;
+ unsigned long xvclk_rate;
struct gpio_desc *reset_gpio;
struct gpio_desc *pwdn_gpio;
struct regulator_bulk_data supplies[ARRAY_SIZE(ov8858_supply_names)];
@@ -118,10 +121,82 @@ struct ov8858 {
struct v4l2_ctrl *vblank;
const struct regval *global_regs;
+ const struct regval *xvclk_regs;
unsigned int num_lanes;
};
+/* Keep input-clock programming separate from the common sensor setup. */
+static const struct regval ov8858_24mhz_360mhz_r1a_2lane[] = {
+ {0x0302, 0x1e},
+ {0x0303, 0x00},
+ {0x0304, 0x03},
+ {0x030e, 0x00},
+ {0x030f, 0x09},
+ {0x0312, 0x01},
+ {0x031e, 0x0c},
+ {0x4837, 0x16},
+ {REG_NULL, 0x00}
+};
+
+static const struct regval ov8858_24mhz_360mhz_r2a_2lane[] = {
+ {0x0302, 0x1e},
+ {0x0303, 0x00},
+ {0x0304, 0x03},
+ {0x030e, 0x02},
+ {0x030f, 0x04},
+ {0x0312, 0x03},
+ {0x031e, 0x0c},
+ {0x4837, 0x16},
+ {REG_NULL, 0x00}
+};
+
+static const struct regval ov8858_24mhz_360mhz_r2a_4lane[] = {
+ {0x0302, 0x1e},
+ {0x0303, 0x00},
+ {0x0304, 0x03},
+ {0x030e, 0x00},
+ {0x030f, 0x04},
+ {0x0312, 0x01},
+ {0x031e, 0x0c},
+ {0x4837, 0x16},
+ {REG_NULL, 0x00}
+};
+
+/*
+ * Register settings for a 19.2 MHz input and 360 MHz CSI-2 link.
+ *
+ * Besides the corrected sensor/MIPI PLL divisors, keep the final common
+ * black-level settings here. The per-mode tables retain their resolution
+ * dependent black-column anchors and window sizes.
+ */
+static const struct regval ov8858_19_2mhz_360mhz[] = {
+ {0x0300, 0x00},
+ {0x0302, 0x27},
+ {0x0303, 0x00},
+ {0x0304, 0x03},
+ {0x030b, 0x00},
+ {0x030d, 0x27},
+ {0x030e, 0x00},
+ {0x030f, 0x04},
+ {0x0312, 0x01},
+ {0x031e, 0x0c},
+ {0x3f08, 0x08},
+ {0x400a, 0x01},
+ {0x400d, 0x10},
+ {0x4011, 0x20},
+ {0x403e, 0x08},
+ {0x4040, 0x07},
+ {0x4041, 0xc6},
+ {0x4202, 0x00},
+ {0x4500, 0x58},
+ {0x470b, 0x28},
+ {0x4837, 0x15},
+ {0x58f4, 0x32},
+ {0x58f8, 0x3d},
+ {REG_NULL, 0x00}
+};
+
static inline struct ov8858 *sd_to_ov8858(struct v4l2_subdev *sd)
{
return container_of(sd, struct ov8858, subdev);
@@ -132,13 +207,6 @@ static const struct regval ov8858_global_regs_r1a[] = {
{0x0100, 0x00},
{0x0100, 0x00},
{0x0100, 0x00},
- {0x0302, 0x1e},
- {0x0303, 0x00},
- {0x0304, 0x03},
- {0x030e, 0x00},
- {0x030f, 0x09},
- {0x0312, 0x01},
- {0x031e, 0x0c},
{0x3600, 0x00},
{0x3601, 0x00},
{0x3602, 0x00},
@@ -371,7 +439,6 @@ static const struct regval ov8858_global_regs_r1a[] = {
{0x4600, 0x00},
{0x4601, 0xcb},
{0x481f, 0x32},
- {0x4837, 0x16},
{0x4850, 0x10},
{0x4851, 0x32},
{0x4b00, 0x2a},
@@ -406,13 +473,6 @@ static const struct regval ov8858_global_regs_r2a_2lane[] = {
*/
{0x0103, 0x01}, /* software reset */
{0x0100, 0x00}, /* software standby */
- {0x0302, 0x1e}, /* pll1_multi */
- {0x0303, 0x00}, /* pll1_divm */
- {0x0304, 0x03}, /* pll1_div_mipi */
- {0x030e, 0x02}, /* pll2_rdiv */
- {0x030f, 0x04}, /* pll2_divsp */
- {0x0312, 0x03}, /* pll2_pre_div0, pll2_r_divdac */
- {0x031e, 0x0c}, /* pll1_no_lat */
{0x3600, 0x00},
{0x3601, 0x00},
{0x3602, 0x00},
@@ -649,7 +709,6 @@ static const struct regval ov8858_global_regs_r2a_2lane[] = {
{0x4600, 0x00},
{0x4601, 0xcb},
{0x481f, 0x32}, /* clk prepare min */
- {0x4837, 0x16}, /* global timing */
{0x4850, 0x10}, /* lane 1 = 1, lane 0 = 0 */
{0x4851, 0x32}, /* lane 3 = 3, lane 2 = 2 */
{0x4b00, 0x2a},
@@ -811,13 +870,6 @@ static const struct regval ov8858_global_regs_r2a_4lane[] = {
{0x0103, 0x01}, /* software reset for OVTATool only */
{0x0103, 0x01}, /* software reset */
{0x0100, 0x00}, /* software standby */
- {0x0302, 0x1e}, /* pll1_multi */
- {0x0303, 0x00}, /* pll1_divm */
- {0x0304, 0x03}, /* pll1_div_mipi */
- {0x030e, 0x00}, /* pll2_rdiv */
- {0x030f, 0x04}, /* pll2_divsp */
- {0x0312, 0x01}, /* pll2_pre_div0, pll2_r_divdac */
- {0x031e, 0x0c}, /* pll1_no_lat */
{0x3600, 0x00},
{0x3601, 0x00},
{0x3602, 0x00},
@@ -1054,7 +1106,6 @@ static const struct regval ov8858_global_regs_r2a_4lane[] = {
{0x4600, 0x00},
{0x4601, 0xcb},
{0x481f, 0x32}, /* clk prepare min */
- {0x4837, 0x16}, /* global timing */
{0x4850, 0x10}, /* lane 1 = 1, lane 0 = 0 */
{0x4851, 0x32}, /* lane 3 = 3, lane 2 = 2 */
{0x4b00, 0x2a},
@@ -1346,6 +1397,10 @@ static int ov8858_start_stream(struct ov8858 *ov8858,
if (ret)
return ret;
+ ret = ov8858_write_array(ov8858, ov8858->xvclk_regs);
+ if (ret)
+ return ret;
+
/* 200 usec max to let PLL stabilize. */
fsleep(200);
@@ -1624,9 +1679,6 @@ static int ov8858_power_on(struct ov8858 *ov8858)
unsigned long delay_us;
int ret;
- if (clk_get_rate(ov8858->xvclk) != OV8858_XVCLK_FREQ)
- dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
-
ret = clk_prepare_enable(ov8858->xvclk);
if (ret < 0) {
dev_err(dev, "Failed to enable xvclk\n");
@@ -1645,7 +1697,7 @@ static int ov8858_power_on(struct ov8858 *ov8858)
* transaction, but a double sleep between the release of gpios
* helps with sporadic failures observed at probe time.
*/
- delay_us = DIV_ROUND_UP(8192, OV8858_XVCLK_FREQ / 1000 / 1000);
+ delay_us = DIV_ROUND_UP(8192, ov8858->xvclk_rate / HZ_PER_MHZ);
gpiod_set_value_cansleep(ov8858->reset_gpio, 0);
fsleep(delay_us);
@@ -1806,15 +1858,20 @@ static int ov8858_check_sensor_id(struct ov8858 *ov8858)
if (id == OV8858_R2A) {
/* R2A supports 2 and 4 lanes modes. */
- ov8858->global_regs = ov8858->num_lanes == 4
- ? ov8858_global_regs_r2a_4lane
- : ov8858_global_regs_r2a_2lane;
+ if (ov8858->num_lanes == 4) {
+ ov8858->global_regs = ov8858_global_regs_r2a_4lane;
+ ov8858->xvclk_regs = ov8858_24mhz_360mhz_r2a_4lane;
+ } else {
+ ov8858->global_regs = ov8858_global_regs_r2a_2lane;
+ ov8858->xvclk_regs = ov8858_24mhz_360mhz_r2a_2lane;
+ }
} else if (ov8858->num_lanes == 2) {
/*
* R1A only supports 2 lanes mode and it's only partially
* supported.
*/
ov8858->global_regs = ov8858_global_regs_r1a;
+ ov8858->xvclk_regs = ov8858_24mhz_360mhz_r1a_2lane;
dev_warn(&client->dev, "R1A may not work well!\n");
} else {
dev_err(&client->dev,
@@ -1822,6 +1879,14 @@ static int ov8858_check_sensor_id(struct ov8858 *ov8858)
return -EINVAL;
}
+ if (ov8858->xvclk_rate == OV8858_XVCLK_FREQ_19_2MHZ) {
+ if (id != OV8858_R2A || ov8858->num_lanes != 4)
+ return dev_err_probe(&client->dev, -EINVAL,
+ "19.2 MHz requires four lanes and R2A\n");
+
+ ov8858->xvclk_regs = ov8858_19_2mhz_360mhz;
+ }
+
return 0;
}
@@ -1889,6 +1954,13 @@ static int ov8858_probe(struct i2c_client *client)
return dev_err_probe(dev, PTR_ERR(ov8858->xvclk),
"Failed to get xvclk\n");
+ ov8858->xvclk_rate = clk_get_rate(ov8858->xvclk);
+ if (ov8858->xvclk_rate != OV8858_XVCLK_FREQ_19_2MHZ &&
+ ov8858->xvclk_rate != OV8858_XVCLK_FREQ_24MHZ)
+ return dev_err_probe(dev, -EINVAL,
+ "Unsupported xvclk rate %lu Hz\n",
+ ov8858->xvclk_rate);
+
ov8858->reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_HIGH);
if (IS_ERR(ov8858->reset_gpio))
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 04/14] media: ov2740: Add OVTI2740 ACPI ID
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (2 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 03/14] media: ov8858: Support a 19.2 MHz input clock on four-lane R2A Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 05/14] media: intel: ipu-bridge: Add the Yoga Book OVTI2740 entry Maurizio Casciano
` (9 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
Firmware may enumerate OV2740 image sensors using the OVTI2740 ACPI ID.
Add it to the existing ACPI match table.
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
drivers/media/i2c/ov2740.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index b7c0f2890..7d786d09f 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -1463,6 +1463,7 @@ static DEFINE_RUNTIME_DEV_PM_OPS(ov2740_pm_ops, ov2740_suspend, ov2740_resume,
static const struct acpi_device_id ov2740_acpi_ids[] = {
{ .id = "INT3474" },
+ { .id = "OVTI2740" },
{ }
};
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 05/14] media: intel: ipu-bridge: Add the Yoga Book OVTI2740 entry
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (3 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 04/14] media: ov2740: Add OVTI2740 ACPI ID Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 06/14] media: atomisp: Add Yoga Book camera configuration Maurizio Casciano
` (8 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The Yoga Book YB1-X91 uses OVTI2740 for its OV2740 front sensor. Add
its default link frequency so the IPU bridge can construct the software
endpoint. The existing INT3477 entry covers the rear sensor.
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
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 2a38c4bd8..5f6baac2c 100644
--- a/drivers/media/pci/intel/ipu-bridge.c
+++ b/drivers/media/pci/intel/ipu-bridge.c
@@ -115,6 +115,8 @@ static const struct ipu_sensor_config ipu_supported_sensors[] = {
IPU_SENSOR_CONFIG("OVTIDB10", 1, 560000000),
/* Omnivision OV2680 */
IPU_SENSOR_CONFIG("OVTI2680", 1, 331200000),
+ /* Omnivision OV2740 */
+ IPU_SENSOR_CONFIG("OVTI2740", 1, 360000000),
/* Omnivision OV5675 */
IPU_SENSOR_CONFIG("OVTI5675", 1, 450000000),
/* Omnivision OV5693 */
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 06/14] media: atomisp: Add Yoga Book camera configuration
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (4 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 05/14] media: intel: ipu-bridge: Add the Yoga Book OVTI2740 entry Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 07/14] media: ov2740: support 288 MHz link frequency Maurizio Casciano
` (7 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The Yoga Book YB1-X91 firmware lacks usable AtomISP configuration for
both cameras. Rear INT3477 OV8858 uses four CSI-2 lanes and a WV517S
actuator, while the front OVTI2740 firmware reports the wrong lane
count.
Add the rear sensor configuration and a DMI-scoped two-lane override
for OVTI2740:00. Add the front sensor configuration separately once
its link frequency can be supplied at the same time.
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
.../media/atomisp/pci/atomisp_csi2_bridge.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
index cca91c6d7..56da454f0 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
@@ -74,6 +74,12 @@ static struct gmin_cfg_var lenovo_ideapad_miix_310_vars[] = {
{}
};
+static struct gmin_cfg_var lenovo_yogabook_x91_vars[] = {
+ /* The vendor driver and sensor modes use two CSI data lanes. */
+ { "OVTI2740:00", "CsiLanes", "2" },
+ {}
+};
+
static struct gmin_cfg_var xiaomi_mipad2_vars[] = {
/* _DSM contains the wrong CsiPort for the front facing OV5693 sensor */
{ "INT33BE:00", "CsiPort", "0" },
@@ -83,6 +89,14 @@ static struct gmin_cfg_var xiaomi_mipad2_vars[] = {
};
static const struct dmi_system_id gmin_cfg_dmi_overrides[] = {
+ {
+ /* Lenovo Yoga Book X91L */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91L"),
+ },
+ .driver_data = lenovo_yogabook_x91_vars,
+ },
{
/* Lenovo Ideapad Miix 310 */
.matches = {
@@ -359,7 +373,10 @@ static const struct acpi_device_id atomisp_sensor_configs[] = {
* the sensor fails to start streaming when instantiating
* an i2c-client for the VCM, so it is disabled for now.
*/
- ATOMISP_SENSOR_CONFIG("INT33BE", 2, false), /* OV5693 */
+ /* OV5693 */
+ ATOMISP_SENSOR_CONFIG("INT33BE", 2, false),
+ /* OV8858 */
+ ATOMISP_SENSOR_CONFIG("INT3477", 4, true),
{}
};
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 07/14] media: ov2740: support 288 MHz link frequency
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (5 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 06/14] media: atomisp: Add Yoga Book camera configuration Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 08/14] media: intel: ipu-bridge: select OV2740 frequency by IPU ID Maurizio Casciano
` (6 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The Lenovo Yoga Book YB1-X91 front camera uses two CSI-2 lanes at a
288 MHz link frequency. Add the matching PLL configuration and mode
timing.
Reuse the existing 1932x1092 crop and mode register list so the Bayer
order remains SGRBG across link frequencies. Cropping the CSI-2
receiver output to a smaller processed frame is a userspace pipeline
decision.
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
drivers/media/i2c/ov2740.c | 43 ++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index 7d786d09f..30eb58eed 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -12,12 +12,14 @@
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/unaligned.h>
+#include <linux/units.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fwnode.h>
-#define OV2740_LINK_FREQ_360MHZ 360000000ULL
-#define OV2740_LINK_FREQ_180MHZ 180000000ULL
+#define OV2740_LINK_FREQ_360MHZ (360 * HZ_PER_MHZ)
+#define OV2740_LINK_FREQ_288MHZ (288 * HZ_PER_MHZ)
+#define OV2740_LINK_FREQ_180MHZ (180 * HZ_PER_MHZ)
#define OV2740_SCLK 72000000LL
#define OV2740_MCLK 19200000
#define OV2740_DATA_LANES 2
@@ -91,6 +93,7 @@ struct nvm_data {
enum {
OV2740_LINK_FREQ_360MHZ_INDEX,
+ OV2740_LINK_FREQ_288MHZ_INDEX,
OV2740_LINK_FREQ_180MHZ_INDEX,
};
@@ -142,6 +145,14 @@ static const struct ov2740_reg mipi_data_rate_720mbps[] = {
{0x0312, 0x11},
};
+static const struct ov2740_reg mipi_data_rate_576mbps[] = {
+ {0x0302, 0x1e},
+ {0x0303, 0x00},
+ {0x030d, 0x1e},
+ {0x030e, 0x02},
+ {0x0312, 0x01},
+};
+
static const struct ov2740_reg mipi_data_rate_360mbps[] = {
{0x0302, 0x4b},
{0x0303, 0x01},
@@ -468,6 +479,7 @@ static const char * const ov2740_test_pattern_menu[] = {
static const s64 link_freq_menu_items[] = {
OV2740_LINK_FREQ_360MHZ,
+ OV2740_LINK_FREQ_288MHZ,
OV2740_LINK_FREQ_180MHZ,
};
@@ -478,6 +490,12 @@ static const struct ov2740_link_freq_config link_freq_configs[] = {
.regs = mipi_data_rate_720mbps,
}
},
+ [OV2740_LINK_FREQ_288MHZ_INDEX] = {
+ .reg_list = {
+ .num_of_regs = ARRAY_SIZE(mipi_data_rate_576mbps),
+ .regs = mipi_data_rate_576mbps,
+ }
+ },
[OV2740_LINK_FREQ_180MHZ_INDEX] = {
.reg_list = {
.num_of_regs = ARRAY_SIZE(mipi_data_rate_360mbps),
@@ -502,6 +520,22 @@ static const struct ov2740_mode supported_modes_360mhz[] = {
},
};
+static const struct ov2740_mode supported_modes_288mhz[] = {
+ {
+ .width = 1932,
+ .height = 1092,
+ .hts = 2160,
+ .vts_min = 1776,
+ .vts_def = 1776,
+ .vts_max = 32767,
+ .reg_list = {
+ .num_of_regs = ARRAY_SIZE(mode_1932x1092_regs_360mhz),
+ .regs = mode_1932x1092_regs_360mhz,
+ },
+ .link_freq_index = OV2740_LINK_FREQ_288MHZ_INDEX,
+ },
+};
+
static const struct ov2740_mode supported_modes_180mhz[] = {
{
.width = 1932,
@@ -1179,6 +1213,11 @@ static int ov2740_check_hwcfg(struct ov2740 *ov2740)
ov2740->supported_modes_count =
ARRAY_SIZE(supported_modes_360mhz);
break;
+ case OV2740_LINK_FREQ_288MHZ_INDEX:
+ ov2740->supported_modes = supported_modes_288mhz;
+ ov2740->supported_modes_count =
+ ARRAY_SIZE(supported_modes_288mhz);
+ break;
case OV2740_LINK_FREQ_180MHZ_INDEX:
ov2740->supported_modes = supported_modes_180mhz;
ov2740->supported_modes_count =
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 08/14] media: intel: ipu-bridge: select OV2740 frequency by IPU ID
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (6 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 07/14] media: ov2740: support 288 MHz link frequency Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 09/14] media: atomisp: Derive CSI-2 timing from the sensor link frequency Maurizio Casciano
` (5 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The OV2740 connected to the Cherry Trail AtomISP uses a 288 MHz link,
while the generic OVTI2740 configuration uses 360 MHz.
Use the bridge's existing PCI-device matching mechanism to add a
Cherry Trail-specific OVTI2740 entry before the generic fallback. This
keeps the platform distinction in the bridge and avoids adding a second
per-sensor link-frequency override path.
Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
drivers/media/pci/intel/ipu-bridge.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c
index 5f6baac2c..5dbd74e2b 100644
--- a/drivers/media/pci/intel/ipu-bridge.c
+++ b/drivers/media/pci/intel/ipu-bridge.c
@@ -58,6 +58,11 @@ static const u16 ipu6_ov5693_ncont_clk[] = {
0
};
+static const u16 atomisp_cht_pci_ids[] = {
+ PCI_DEVICE_ID_INTEL_ISP_BSW,
+ 0
+};
+
static const struct ipu_sensor_config ipu_supported_sensors[] = {
/* GalaxyCore GC5035 */
IPU_SENSOR_CONFIG("GCTI5035", 2, 175200000, 422400000),
@@ -116,6 +121,8 @@ static const struct ipu_sensor_config ipu_supported_sensors[] = {
/* Omnivision OV2680 */
IPU_SENSOR_CONFIG("OVTI2680", 1, 331200000),
/* Omnivision OV2740 */
+ IPU_SENSOR_CONFIG_MATCH_FL("OVTI2740", atomisp_cht_pci_ids, 0,
+ 1, 288000000),
IPU_SENSOR_CONFIG("OVTI2740", 1, 360000000),
/* Omnivision OV5675 */
IPU_SENSOR_CONFIG("OVTI5675", 1, 450000000),
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 09/14] media: atomisp: Derive CSI-2 timing from the sensor link frequency
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (7 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 08/14] media: intel: ipu-bridge: select OV2740 frequency by IPU ID Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 10/14] media: ov2740: release group hold after gain write errors Maurizio Casciano
` (4 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The ISP2401 CSI-2 receiver timing depends on the sensor link frequency.
Query it through v4l2_get_link_freq() instead of reading a 32-bit
control value directly.
Keep the frequency as s64 to avoid an arbitrary S32_MAX limit. Use
div64_s64() so 32-bit builds use the kernel division helper. Fall
back to the default timings when the frequency query or divisor is
invalid.
Sashiko identified the 32-bit division issue. Codex reproduced it
and drafted the division helper change.
Link: https://linuxtv.org/mailman3/hyperkitty/list/media-ci@linuxtv.org/message/X3S2EI4364O5ARJK5JLDHTTXCW6TPSLE/
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
.../staging/media/atomisp/pci/atomisp_csi2.c | 24 ++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2.c b/drivers/staging/media/atomisp/pci/atomisp_csi2.c
index 71df4ef62..f72fd0c3c 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2.c
@@ -5,6 +5,9 @@
* Copyright (c) 2010 Intel Corporation. All Rights Reserved.
*/
+#include <linux/math64.h>
+
+#include <media/v4l2-common.h>
#include <media/v4l2-event.h>
#include <media/v4l2-mediabus.h>
#include "atomisp_cmd.h"
@@ -210,7 +213,7 @@ int atomisp_mipi_csi2_register_entities(struct atomisp_mipi_csi2_device *csi2,
static const int LIMIT_SHIFT = 6; /* Limit numeric range into 31 bits */
static int
-atomisp_csi2_configure_calc(const short int coeffs[2], int mipi_freq, int def)
+atomisp_csi2_configure_calc(const short int coeffs[2], s64 mipi_freq, int def)
{
/* Delay counter accuracy, 1/0.0625 for ANN/CHT, 1/0.125 for BXT */
static const int accinv = 16; /* 1 / COUNT_ACC */
@@ -220,7 +223,7 @@ atomisp_csi2_configure_calc(const short int coeffs[2], int mipi_freq, int def)
return def;
r = accinv * coeffs[1] * (500000000 >> LIMIT_SHIFT);
- r /= mipi_freq >> LIMIT_SHIFT;
+ r = div64_s64(r, mipi_freq >> LIMIT_SHIFT);
r += accinv * coeffs[0];
return r;
@@ -289,18 +292,18 @@ static void atomisp_csi2_configure_isp2401(struct atomisp_sub_device *asd)
int dat_termen;
int dat_settle;
- struct v4l2_control ctrl;
struct atomisp_device *isp = asd->isp;
- int mipi_freq = 0;
enum atomisp_camera_port port;
+ struct v4l2_subdev *sensor;
+ s64 mipi_freq;
int n;
port = isp->inputs[asd->input_curr].port;
- ctrl.id = V4L2_CID_LINK_FREQ;
- if (v4l2_g_ctrl
- (isp->inputs[asd->input_curr].sensor->ctrl_handler, &ctrl) == 0)
- mipi_freq = ctrl.value;
+ sensor = isp->inputs[asd->input_curr].sensor;
+ mipi_freq = v4l2_get_link_freq(&sensor->entity.pads[0], 0, 0);
+ if (mipi_freq < 0)
+ mipi_freq = 0;
clk_termen = atomisp_csi2_configure_calc(coeff_clk_termen, mipi_freq,
TERMEN_DEFAULT);
@@ -311,6 +314,11 @@ static void atomisp_csi2_configure_isp2401(struct atomisp_sub_device *asd)
dat_settle = atomisp_csi2_configure_calc(coeff_dat_settle, mipi_freq,
SETTLE_DEFAULT);
+ dev_dbg(isp->dev,
+ "CSI port %u link frequency %lld Hz, clk timing %d/%d, data timing %d/%d\n",
+ port, mipi_freq, clk_termen, clk_settle,
+ dat_termen, dat_settle);
+
for (n = 0; n < csi2_port_lanes[port] + 1; n++) {
hrt_address base = csi2_port_base[port] + csi2_lane_base[n];
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 10/14] media: ov2740: release group hold after gain write errors
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (8 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 09/14] media: atomisp: Derive CSI-2 timing from the sensor link frequency Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 11/14] media: atomisp: Use struct v4l2_area for padding Maurizio Casciano
` (3 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
Digital-gain updates start a register group before writing the red, green
and blue gains. The current error paths return immediately when one of
those writes fails, leaving the group open and never issuing its end and
launch commands. Later control updates can then be accumulated in an
unfinished group instead of taking effect.
Once group hold has started, always attempt both commands needed to end
and launch the group. Preserve the first gain-write error; report an end
or launch error only when all gain writes succeeded.
Fixes: 84363509c725 ("media: ov2740: use group write for digital gain")
Cc: stable@vger.kernel.org
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
drivers/media/i2c/ov2740.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index 30eb58eed..b9a951e92 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -696,7 +696,7 @@ static int ov2740_identify_module(struct ov2740 *ov2740)
static int ov2740_update_digital_gain(struct ov2740 *ov2740, u32 d_gain)
{
- int ret;
+ int end_ret, launch_ret, ret;
ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
OV2740_GROUP_HOLD_START);
@@ -705,24 +705,21 @@ static int ov2740_update_digital_gain(struct ov2740 *ov2740, u32 d_gain)
ret = ov2740_write_reg(ov2740, OV2740_REG_MWB_R_GAIN, 2, d_gain);
if (ret)
- return ret;
+ goto release_group;
ret = ov2740_write_reg(ov2740, OV2740_REG_MWB_G_GAIN, 2, d_gain);
if (ret)
- return ret;
+ goto release_group;
ret = ov2740_write_reg(ov2740, OV2740_REG_MWB_B_GAIN, 2, d_gain);
- if (ret)
- return ret;
- ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
- OV2740_GROUP_HOLD_END);
- if (ret)
- return ret;
+release_group:
+ end_ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
+ OV2740_GROUP_HOLD_END);
+ launch_ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
+ OV2740_GROUP_HOLD_LAUNCH);
- ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
- OV2740_GROUP_HOLD_LAUNCH);
- return ret;
+ return ret ?: end_ret ?: launch_ret;
}
static int ov2740_test_pattern(struct ov2740 *ov2740, u32 pattern)
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 11/14] media: atomisp: Use struct v4l2_area for padding
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (9 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 10/14] media: ov2740: release group hold after gain write errors Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 12/14] media: atomisp: Allow raw Bayer capture Maurizio Casciano
` (2 subsequent siblings)
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The padding helper passes width and height as four separate scalar
arguments even though they form two logical dimensions.
Pass the requested size and returned padding as struct v4l2_area values.
This makes the dimensions explicit and simplifies all three callers.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
.../staging/media/atomisp/pci/atomisp_cmd.c | 69 +++++++++++--------
.../staging/media/atomisp/pci/atomisp_cmd.h | 6 +-
.../staging/media/atomisp/pci/atomisp_ioctl.c | 15 ++--
.../media/atomisp/pci/atomisp_subdev.c | 4 +-
.../media/atomisp/pci/atomisp_subdev.h | 3 +-
5 files changed, 54 insertions(+), 43 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index e66a7d1c7..c2978e587 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -3561,9 +3561,9 @@ static void atomisp_fill_pix_format(struct v4l2_pix_format *f,
f->xfer_func = V4L2_XFER_FUNC_709;
}
-/* Get sensor padding values for the non padded width x height resolution */
-void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
- u32 *padding_w, u32 *padding_h)
+/* Get sensor padding values for the non-padded size */
+void atomisp_get_padding(struct atomisp_device *isp, struct v4l2_area size,
+ struct v4l2_area *pad)
{
struct atomisp_input_subdev *input = &isp->inputs[isp->asd.input_curr];
struct v4l2_rect native_rect = input->native_rect;
@@ -3573,22 +3573,24 @@ void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
struct v4l2_mbus_framefmt *sink;
if (!input->crop_support) {
- *padding_w = pad_w;
- *padding_h = pad_h;
+ pad->width = pad_w;
+ pad->height = pad_h;
return;
}
- width = min(width, input->active_rect.width);
- height = min(height, input->active_rect.height);
+ size.width = min(size.width, input->active_rect.width);
+ size.height = min(size.height, input->active_rect.height);
- if (input->binning_support && width <= (input->active_rect.width / 2) &&
- height <= (input->active_rect.height / 2)) {
+ if (input->binning_support &&
+ size.width <= (input->active_rect.width / 2) &&
+ size.height <= (input->active_rect.height / 2)) {
native_rect.width /= 2;
native_rect.height /= 2;
}
- *padding_w = min_t(u32, (native_rect.width - width) & ~1, pad_w);
- *padding_h = min_t(u32, (native_rect.height - height) & ~1, pad_h);
+ pad->width = min_t(u32, (native_rect.width - size.width) & ~1, pad_w);
+ pad->height = min_t(u32, (native_rect.height - size.height) & ~1,
+ pad_h);
/* The below minimum padding requirements are for BYT / ISP2400 only */
if (IS_ISP2401)
@@ -3616,8 +3618,18 @@ void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
min_pad_h += 2;
apply_min_padding:
- *padding_w = max_t(u32, *padding_w, min_pad_w);
- *padding_h = max_t(u32, *padding_h, min_pad_h);
+ pad->width = max_t(u32, pad->width, min_pad_w);
+ pad->height = max_t(u32, pad->height, min_pad_h);
+}
+
+static void
+atomisp_get_pix_padding(struct atomisp_device *isp,
+ struct v4l2_pix_format *f,
+ struct v4l2_area *pad)
+{
+ struct v4l2_area size = { .width = f->width, .height = f->height };
+
+ atomisp_get_padding(isp, size, pad);
}
int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on)
@@ -3805,7 +3817,7 @@ int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
const struct atomisp_format_bridge *fmt, *snr_fmt;
struct atomisp_sub_device *asd = &isp->asd;
struct v4l2_mbus_framefmt ffmt = { };
- u32 padding_w, padding_h;
+ struct v4l2_area padding;
int ret;
fmt = atomisp_get_format_bridge(f->pixelformat);
@@ -3832,10 +3844,10 @@ int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
* resolution + padding. Add padding here and remove it again after
* the set_fmt call, like atomisp_set_fmt_to_snr() does.
*/
- atomisp_get_padding(isp, f->width, f->height, &padding_w, &padding_h);
+ atomisp_get_pix_padding(isp, f, &padding);
v4l2_fill_mbus_format(&ffmt, f, fmt->mbus_code);
- ffmt.width += padding_w;
- ffmt.height += padding_h;
+ ffmt.width += padding.width;
+ ffmt.height += padding.height;
dev_dbg(isp->dev, "try_mbus_fmt: try %ux%u\n", ffmt.width, ffmt.height);
@@ -3852,8 +3864,8 @@ int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
return -EINVAL;
}
- f->width = ffmt.width - padding_w;
- f->height = ffmt.height - padding_h;
+ f->width = ffmt.width - padding.width;
+ f->height = ffmt.height - padding.height;
/*
* If the format is jpeg or custom RAW, then the width and height will
@@ -4273,11 +4285,12 @@ static int atomisp_set_fmt_to_snr(struct video_device *vdev, const struct v4l2_p
return -EINVAL;
v4l2_fill_mbus_format(&ffmt, f, format->mbus_code);
- ffmt.height += asd->sink_pad_padding_h + dvs_env_h;
- ffmt.width += asd->sink_pad_padding_w + dvs_env_w;
+ ffmt.height += asd->sink_pad_padding.height + dvs_env_h;
+ ffmt.width += asd->sink_pad_padding.width + dvs_env_w;
dev_dbg(isp->dev, "s_mbus_fmt: ask %ux%u (padding %ux%u, dvs %ux%u)\n",
- ffmt.width, ffmt.height, asd->sink_pad_padding_w, asd->sink_pad_padding_h,
+ ffmt.width, ffmt.height, asd->sink_pad_padding.width,
+ asd->sink_pad_padding.height,
dvs_env_w, dvs_env_h);
__atomisp_init_stream_info(ATOMISP_INPUT_STREAM_GENERAL, stream_info);
@@ -4370,13 +4383,11 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f)
V4L2_SUBDEV_FORMAT_ACTIVE,
ATOMISP_SUBDEV_PAD_SOURCE, &isp_source_fmt);
- if (atomisp_subdev_format_conversion(asd)) {
- atomisp_get_padding(isp, f->fmt.pix.width, f->fmt.pix.height,
- &asd->sink_pad_padding_w, &asd->sink_pad_padding_h);
- } else {
- asd->sink_pad_padding_w = 0;
- asd->sink_pad_padding_h = 0;
- }
+ if (atomisp_subdev_format_conversion(asd))
+ atomisp_get_pix_padding(isp, &f->fmt.pix,
+ &asd->sink_pad_padding);
+ else
+ asd->sink_pad_padding = (struct v4l2_area) { };
atomisp_get_dis_envelop(asd, f->fmt.pix.width, f->fmt.pix.height,
&dvs_env_w, &dvs_env_h);
diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.h b/drivers/staging/media/atomisp/pci/atomisp_cmd.h
index d3d1f2574..8a84e774f 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.h
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.h
@@ -225,9 +225,9 @@ int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd,
int atomisp_compare_grid(struct atomisp_sub_device *asd,
struct atomisp_grid_info *atomgrid);
-/* Get sensor padding values for the non padded width x height resolution */
-void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
- u32 *padding_w, u32 *padding_h);
+/* Get sensor padding values for the non-padded size */
+void atomisp_get_padding(struct atomisp_device *isp, struct v4l2_area size,
+ struct v4l2_area *pad);
/* Set sensor power (no-op if already on/off) */
int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on);
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 50366bf10..87c29a940 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -457,7 +457,7 @@ static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
const struct v4l2_rect *native,
int *valid_sizes)
{
- static const struct v4l2_frmsize_discrete frame_sizes[] = {
+ static const struct v4l2_area frame_sizes[] = {
{ 1920, 1440 },
{ 1920, 1200 },
{ 1920, 1080 },
@@ -470,15 +470,15 @@ static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
{ 800, 600 },
{ 640, 480 },
};
- u32 padding_w, padding_h;
int i;
for (i = 0; i < ARRAY_SIZE(frame_sizes); i++) {
- atomisp_get_padding(isp, frame_sizes[i].width, frame_sizes[i].height,
- &padding_w, &padding_h);
+ struct v4l2_area padding;
- if ((frame_sizes[i].width + padding_w) > native->width ||
- (frame_sizes[i].height + padding_h) > native->height)
+ atomisp_get_padding(isp, frame_sizes[i], &padding);
+
+ if ((frame_sizes[i].width + padding.width) > native->width ||
+ (frame_sizes[i].height + padding.height) > native->height)
continue;
/*
@@ -491,7 +491,8 @@ static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
if (*valid_sizes == fsize->index) {
fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
- fsize->discrete = frame_sizes[i];
+ fsize->discrete.width = frame_sizes[i].width;
+ fsize->discrete.height = frame_sizes[i].height;
return 0;
}
diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.c b/drivers/staging/media/atomisp/pci/atomisp_subdev.c
index bdd2d9b18..495032966 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_subdev.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.c
@@ -327,8 +327,8 @@ int atomisp_subdev_set_selection(struct v4l2_subdev *sd,
if (atomisp_subdev_format_conversion(isp_sd)
&& crop[pad]->width && crop[pad]->height) {
- crop[pad]->width -= isp_sd->sink_pad_padding_w;
- crop[pad]->height -= isp_sd->sink_pad_padding_h;
+ crop[pad]->width -= isp_sd->sink_pad_padding.width;
+ crop[pad]->height -= isp_sd->sink_pad_padding.height;
}
if (isp_sd->params.video_dis_en &&
diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.h b/drivers/staging/media/atomisp/pci/atomisp_subdev.h
index b12bb65be..0045f380d 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_subdev.h
+++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.h
@@ -214,8 +214,7 @@ struct atomisp_sub_device {
struct media_pad pads[ATOMISP_SUBDEV_PADS_NUM];
struct atomisp_pad_format fmt[ATOMISP_SUBDEV_PADS_NUM];
/* Padding for currently set sink-pad fmt */
- u32 sink_pad_padding_w;
- u32 sink_pad_padding_h;
+ struct v4l2_area sink_pad_padding;
unsigned int output;
struct atomisp_video_pipe video_out;
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 12/14] media: atomisp: Allow raw Bayer capture
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (10 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 11/14] media: atomisp: Use struct v4l2_area for padding Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 13/14] media: i2c: Add WV517S lens actuator driver Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 14/14] media: atomisp: Preserve the capture graph when a lens rebinds Maurizio Casciano
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
AtomISP currently rejects raw formats and substitutes YUV420. Expose
the supported raw Bayer formats so userspace can select unprocessed
sensor frames with VIDIOC_S_FMT.
Enumerate the sensor's media-bus codes and pass the requested RAW code
to discrete frame-size enumeration. Crop-capable sensors report their
native RAW sizes without conversion padding. Match TRY_FMT to S_FMT
when sensor negotiation falls back to native processed output.
RAW formats expose the sensor transport frame for the ISP2401 copy
pipeline. Processed formats keep the existing padding rules.
Sashiko identified the negotiation and enumeration cases. Codex drafted
the follow-up and exercised it with simulated sensor replies.
Link: https://linuxtv.org/mailman3/hyperkitty/list/media-ci@linuxtv.org/message/TJOXYBYPVBPWJS47TNZF33YCWBAP2WZL/
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
.../staging/media/atomisp/pci/atomisp_cmd.c | 36 ++++--
.../staging/media/atomisp/pci/atomisp_ioctl.c | 106 +++++++++++++-----
2 files changed, 106 insertions(+), 36 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index c2978e587..bada0eec6 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -3818,11 +3818,11 @@ int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
struct atomisp_sub_device *asd = &isp->asd;
struct v4l2_mbus_framefmt ffmt = { };
struct v4l2_area padding;
+ bool retried = false;
int ret;
fmt = atomisp_get_format_bridge(f->pixelformat);
- /* Currently, raw formats are broken!!! */
- if (!fmt || fmt->sh_fmt == IA_CSS_FRAME_FORMAT_RAW) {
+ if (!fmt) {
f->pixelformat = V4L2_PIX_FMT_YUV420;
fmt = atomisp_get_format_bridge(f->pixelformat);
@@ -3840,23 +3840,24 @@ int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
}
/*
- * atomisp_set_fmt() will set the sensor resolution to the requested
- * resolution + padding. Add padding here and remove it again after
- * the set_fmt call, like atomisp_set_fmt_to_snr() does.
+ * Match S_FMT: only Bayer-to-processed conversion needs padding.
+ * Start with the requested format and retry without padding if the
+ * sensor supplies a native processed format.
*/
- atomisp_get_pix_padding(isp, f, &padding);
+ if (fmt->sh_fmt == IA_CSS_FRAME_FORMAT_RAW)
+ padding = (struct v4l2_area) { };
+ else
+ atomisp_get_pix_padding(isp, f, &padding);
+
+retry:
v4l2_fill_mbus_format(&ffmt, f, fmt->mbus_code);
ffmt.width += padding.width;
ffmt.height += padding.height;
- dev_dbg(isp->dev, "try_mbus_fmt: try %ux%u\n", ffmt.width, ffmt.height);
-
ret = atomisp_set_sensor_crop_and_fmt(isp, &ffmt, V4L2_SUBDEV_FORMAT_TRY);
if (ret)
return ret;
- dev_dbg(isp->dev, "try_mbus_fmt: got %ux%u\n", ffmt.width, ffmt.height);
-
snr_fmt = atomisp_get_format_bridge_from_mbus(ffmt.code);
if (!snr_fmt) {
dev_err(isp->dev, "unknown sensor format 0x%8.8x\n",
@@ -3864,6 +3865,21 @@ int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
return -EINVAL;
}
+ if (fmt->sh_fmt == IA_CSS_FRAME_FORMAT_RAW) {
+ fmt = snr_fmt;
+ f->pixelformat = fmt->pixelformat;
+ } else if (!atomisp_is_mbuscode_raw(ffmt.code) &&
+ (padding.width || padding.height)) {
+ padding = (struct v4l2_area) { };
+ retried = true;
+ goto retry;
+ } else if (retried && atomisp_is_mbuscode_raw(ffmt.code)) {
+ return -EINVAL;
+ }
+
+ if (ffmt.width < padding.width || ffmt.height < padding.height)
+ return -EINVAL;
+
f->width = ffmt.width - padding.width;
f->height = ffmt.height - padding.height;
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 87c29a940..948efa320 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -7,6 +7,7 @@
* Copyright (c) 2010 Silicon Hive www.siliconhive.com.
*/
+#include <linux/bitmap.h>
#include <linux/delay.h>
#include <linux/pci.h>
@@ -447,6 +448,36 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
return ret;
}
+static int atomisp_enum_raw_formats(struct v4l2_subdev *sensor,
+ unsigned long *raw_formats)
+{
+ struct v4l2_subdev_mbus_code_enum code = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
+ struct v4l2_subdev_state *state;
+ unsigned int i;
+ int ret;
+
+ state = v4l2_subdev_lock_and_get_active_state(sensor);
+ for (;; code.index++) {
+ ret = v4l2_subdev_call(sensor, pad, enum_mbus_code, state, &code);
+ if (ret)
+ break;
+
+ for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
+ const struct atomisp_format_bridge *fmt = &atomisp_output_fmts[i];
+
+ if (fmt->sh_fmt == IA_CSS_FRAME_FORMAT_RAW &&
+ fmt->mbus_code == code.code)
+ set_bit(i, raw_formats);
+ }
+ }
+ if (state)
+ v4l2_subdev_unlock_state(state);
+
+ return ret == -EINVAL || ret == -ENOIOCTLCMD ? 0 : ret;
+}
+
/*
* With crop any framesize <= sensor-size can be made, give
* userspace a list of sizes to choice from.
@@ -455,7 +486,7 @@ static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
struct v4l2_frmsizeenum *fsize,
const struct v4l2_rect *active,
const struct v4l2_rect *native,
- int *valid_sizes)
+ bool raw, int *valid_sizes)
{
static const struct v4l2_area frame_sizes[] = {
{ 1920, 1440 },
@@ -472,10 +503,22 @@ static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
};
int i;
+ if (raw && (*valid_sizes)++ == fsize->index) {
+ fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+ fsize->discrete.width = native->width;
+ fsize->discrete.height = native->height;
+ return 0;
+ }
+
for (i = 0; i < ARRAY_SIZE(frame_sizes); i++) {
- struct v4l2_area padding;
+ struct v4l2_area padding = { };
+
+ if (raw && frame_sizes[i].width == native->width &&
+ frame_sizes[i].height == native->height)
+ continue;
- atomisp_get_padding(isp, frame_sizes[i], &padding);
+ if (!raw)
+ atomisp_get_padding(isp, frame_sizes[i], &padding);
if ((frame_sizes[i].width + padding.width) > native->width ||
(frame_sizes[i].height + padding.height) > native->height)
@@ -503,14 +546,14 @@ static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
}
static int atomisp_enum_framesizes_crop(struct atomisp_device *isp,
- struct v4l2_frmsizeenum *fsize)
+ struct v4l2_frmsizeenum *fsize, bool raw)
{
struct atomisp_input_subdev *input = &isp->inputs[isp->asd.input_curr];
struct v4l2_rect active = input->active_rect;
struct v4l2_rect native = input->native_rect;
int ret, valid_sizes = 0;
- ret = atomisp_enum_framesizes_crop_inner(isp, fsize, &active, &native, &valid_sizes);
+ ret = atomisp_enum_framesizes_crop_inner(isp, fsize, &active, &native, raw, &valid_sizes);
if (ret == 0)
return 0;
@@ -522,7 +565,7 @@ static int atomisp_enum_framesizes_crop(struct atomisp_device *isp,
native.width /= 2;
native.height /= 2;
- return atomisp_enum_framesizes_crop_inner(isp, fsize, &active, &native, &valid_sizes);
+ return atomisp_enum_framesizes_crop_inner(isp, fsize, &active, &native, raw, &valid_sizes);
}
static int atomisp_enum_framesizes(struct file *file, void *priv,
@@ -537,14 +580,33 @@ static int atomisp_enum_framesizes(struct file *file, void *priv,
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
.code = input->code,
};
+ const struct atomisp_format_bridge *format;
struct v4l2_subdev_state *act_sd_state;
int ret;
if (!input->sensor)
return -EINVAL;
+ format = atomisp_get_format_bridge(fsize->pixel_format);
+ if (!format)
+ return -EINVAL;
+
+ if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW) {
+ fse.code = format->mbus_code;
+ if (input->crop_support) {
+ DECLARE_BITMAP(raw_formats, ARRAY_SIZE(atomisp_output_fmts)) = { };
+
+ ret = atomisp_enum_raw_formats(input->sensor, raw_formats);
+ if (ret)
+ return ret;
+ if (!test_bit(format - atomisp_output_fmts, raw_formats))
+ return -EINVAL;
+ }
+ }
+
if (input->crop_support)
- return atomisp_enum_framesizes_crop(isp, fsize);
+ return atomisp_enum_framesizes_crop(isp, fsize,
+ format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW);
act_sd_state = v4l2_subdev_lock_and_get_active_state(input->sensor);
ret = v4l2_subdev_call(input->sensor, pad, enum_frame_size,
@@ -555,8 +617,13 @@ static int atomisp_enum_framesizes(struct file *file, void *priv,
return ret;
fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
- fsize->discrete.width = fse.max_width - pad_w;
- fsize->discrete.height = fse.max_height - pad_h;
+ if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW) {
+ fsize->discrete.width = fse.max_width;
+ fsize->discrete.height = fse.max_height;
+ } else {
+ fsize->discrete.width = fse.max_width - pad_w;
+ fsize->discrete.height = fse.max_height - pad_h;
+ }
return 0;
}
@@ -602,35 +669,22 @@ static int atomisp_enum_fmt_cap(struct file *file, void *fh,
struct atomisp_device *isp = video_get_drvdata(vdev);
struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
struct atomisp_input_subdev *input = &isp->inputs[asd->input_curr];
- struct v4l2_subdev_mbus_code_enum code = {
- .which = V4L2_SUBDEV_FORMAT_ACTIVE,
- };
+ DECLARE_BITMAP(raw_formats, ARRAY_SIZE(atomisp_output_fmts)) = { };
const struct atomisp_format_bridge *format;
- struct v4l2_subdev_state *act_sd_state;
unsigned int i, fi = 0;
int ret;
if (!input->sensor)
return -EINVAL;
- act_sd_state = v4l2_subdev_lock_and_get_active_state(input->sensor);
- ret = v4l2_subdev_call(input->sensor, pad, enum_mbus_code,
- act_sd_state, &code);
- if (act_sd_state)
- v4l2_subdev_unlock_state(act_sd_state);
+ ret = atomisp_enum_raw_formats(input->sensor, raw_formats);
if (ret)
return ret;
for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
format = &atomisp_output_fmts[i];
-
- /*
- * Is the atomisp-supported format is valid for the
- * sensor (configuration)? If not, skip it.
- *
- * FIXME: fix the pipeline to allow sensor format too.
- */
- if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW)
+ if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW &&
+ !test_bit(i, raw_formats))
continue;
/* Found a match. Now let's pick f->index'th one. */
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 13/14] media: i2c: Add WV517S lens actuator driver
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (11 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 12/14] media: atomisp: Allow raw Bayer capture Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 14/14] media: atomisp: Preserve the capture graph when a lens rebinds Maurizio Casciano
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The Lenovo Yoga Book YB1-X91 rear camera has a WV517S voice-coil
actuator. Add a V4L2 lens subdevice with a standard 10-bit
FOCUS_ABSOLUTE control. Set the ringing-control mode internally.
Defer register I/O until open or a focus request so runtime PM can
use the IPU bridge sensor link to power the actuator. Use regmap
and restore the last successfully written focus position on resume.
With PM disabled, initialize the device on first use.
Hold a reference for each V4L2 registration until final subdevice
release. Remove access to the hardware and balance the open runtime
PM reference before unregistering the device. This depends on
David Heidelberg's V4L2 core fix, which clears the devnode pointer
before invoking the subdevice release callback.
Retain the Intel copyright notice for the register addresses and
drive-mode value from the vendor WV517 driver. Sashiko identified
the runtime PM and lifetime issues. Codex drafted the follow-up.
Link: https://github.com/jekhor/yogabook-linux-android-kernel/blob/574bae692716f1b14093497bfab8a007fe8e460b/drivers/external_drivers/camera/drivers/media/i2c/wv517.c
Link: https://lore.kernel.org/r/20260917-v4l2-release-fix-v1-1-acbac7f9b78e@ixit.cz/
Link: https://linuxtv.org/mailman3/hyperkitty/list/media-ci@linuxtv.org/message/2PUHZIDBEIGQKGXTJJOUXXJS2EOEMJGD/
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
MAINTAINERS | 1 +
drivers/media/i2c/Kconfig | 11 ++
drivers/media/i2c/Makefile | 1 +
drivers/media/i2c/wv517s.c | 320 +++++++++++++++++++++++++++++++++++++
4 files changed, 333 insertions(+)
create mode 100644 drivers/media/i2c/wv517s.c
diff --git a/MAINTAINERS b/MAINTAINERS
index f72ce07a4..2491353d8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -29324,6 +29324,7 @@ S: Maintained
F: drivers/media/i2c/ak*
F: drivers/media/i2c/dw*
F: drivers/media/i2c/lm*
+F: drivers/media/i2c/wv517s.c
V4L2 CAMERA SENSOR DRIVERS
M: Sakari Ailus <sakari.ailus@linux.intel.com>
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 162b8ea02..e97ef7749 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -1046,6 +1046,17 @@ config VIDEO_DW9807_VCM
capability. This is designed for linear control of
voice coil motors, controlled via I2C serial interface.
+config VIDEO_WV517S
+ tristate "WV517S lens voice coil support"
+ select REGMAP_I2C
+ help
+ This is a driver for the WV517S camera lens voice coil. The driver
+ supports 10-bit focus control and exposes the actuator through the
+ standard V4L2 lens sub-device interface.
+
+ To compile this driver as a module, choose M here: the module will be
+ called wv517s.
+
endif
menu "Flash devices"
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index a750942e9..9a40d0dbc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -181,4 +181,5 @@ obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
+obj-$(CONFIG_VIDEO_WV517S) += wv517s.o
obj-$(CONFIG_VIDEO_INTEL_CVS) += cvs/
diff --git a/drivers/media/i2c/wv517s.c b/drivers/media/i2c/wv517s.c
new file mode 100644
index 000000000..5f2da0a29
--- /dev/null
+++ b/drivers/media/i2c/wv517s.c
@@ -0,0 +1,320 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * WV517S voice-coil motor driver
+ *
+ * Copyright (c) 2014 Intel Corporation.
+ * Copyright (C) 2026 Maurizio Casciano <mauriziocasciano7@gmail.com>
+ */
+
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <linux/kref.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+
+#define WV517S_MAX_FOCUS_POSITION 1023
+#define WV517S_DEFAULT_FOCUS_POSITION 300
+
+#define WV517S_REG_FOCUS 0x41
+#define WV517S_REG_DRIVE_MODE 0x43
+#define WV517S_DRIVE_MODE_12_6_MS 0x0211
+
+enum wv517s_registration {
+ WV517S_UNBOUND,
+ WV517S_REGISTERED,
+ WV517S_RELEASE_PENDING,
+};
+
+struct wv517s_device {
+ struct v4l2_ctrl_handler ctrl_handler;
+ struct v4l2_subdev sd;
+ struct regmap *regmap;
+ struct kref ref;
+ /* Serialize hardware access and open/close against driver removal. */
+ struct mutex lock;
+ enum wv517s_registration registration;
+ unsigned int users;
+ u16 focus;
+ bool initialized;
+ bool removed;
+};
+
+static inline struct wv517s_device *to_wv517s(struct v4l2_subdev *sd)
+{
+ return container_of(sd, struct wv517s_device, sd);
+}
+
+static const struct regmap_config wv517s_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 16,
+ .max_register = WV517S_REG_DRIVE_MODE,
+ .val_format_endian = REGMAP_ENDIAN_BIG,
+};
+
+static int wv517s_resume(struct device *dev)
+{
+ struct v4l2_subdev *sd = dev_get_drvdata(dev);
+ struct wv517s_device *wv517s = to_wv517s(sd);
+ int ret;
+
+ ret = regmap_write(wv517s->regmap, WV517S_REG_DRIVE_MODE,
+ WV517S_DRIVE_MODE_12_6_MS);
+ if (ret)
+ return ret;
+
+ /*
+ * Every update of focus holds a runtime PM reference. Do not acquire
+ * the driver's mutex here: the caller may hold it while resuming.
+ */
+ return regmap_write(wv517s->regmap, WV517S_REG_FOCUS,
+ READ_ONCE(wv517s->focus));
+}
+
+static DEFINE_RUNTIME_DEV_PM_OPS(wv517s_pm_ops, NULL, wv517s_resume, NULL);
+
+static int wv517s_power_get(struct wv517s_device *wv517s)
+{
+ struct device *dev = wv517s->sd.dev;
+ int ret;
+
+ if (IS_ENABLED(CONFIG_PM))
+ return pm_runtime_resume_and_get(dev);
+
+ if (wv517s->initialized)
+ return 0;
+
+ ret = wv517s_resume(dev);
+ if (!ret)
+ wv517s->initialized = true;
+
+ return ret;
+}
+
+static int wv517s_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct wv517s_device *wv517s =
+ container_of(ctrl->handler, struct wv517s_device, ctrl_handler);
+ int ret;
+
+ if (ctrl->id != V4L2_CID_FOCUS_ABSOLUTE)
+ return -EINVAL;
+
+ guard(mutex)(&wv517s->lock);
+ if (wv517s->removed)
+ return -ENODEV;
+
+ ret = wv517s_power_get(wv517s);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(wv517s->regmap, WV517S_REG_FOCUS, ctrl->val);
+ if (!ret)
+ WRITE_ONCE(wv517s->focus, ctrl->val);
+
+ pm_runtime_put(wv517s->sd.dev);
+ return ret;
+}
+
+static const struct v4l2_ctrl_ops wv517s_ctrl_ops = {
+ .s_ctrl = wv517s_set_ctrl,
+};
+
+static void wv517s_free(struct kref *ref)
+{
+ struct wv517s_device *wv517s = container_of(ref, struct wv517s_device, ref);
+
+ v4l2_ctrl_handler_free(&wv517s->ctrl_handler);
+ media_entity_cleanup(&wv517s->sd.entity);
+ mutex_destroy(&wv517s->lock);
+ kfree(wv517s);
+}
+
+static int wv517s_registered(struct v4l2_subdev *sd)
+{
+ struct wv517s_device *wv517s = to_wv517s(sd);
+
+ guard(mutex)(&wv517s->lock);
+ if (wv517s->removed || wv517s->registration != WV517S_UNBOUND)
+ return -EBUSY;
+
+ kref_get(&wv517s->ref);
+ wv517s->registration = WV517S_REGISTERED;
+ return 0;
+}
+
+static void wv517s_unregistered(struct v4l2_subdev *sd)
+{
+ struct wv517s_device *wv517s = to_wv517s(sd);
+
+ guard(mutex)(&wv517s->lock);
+ wv517s->registration = WV517S_RELEASE_PENDING;
+}
+
+static void wv517s_release(struct v4l2_subdev *sd)
+{
+ struct wv517s_device *wv517s = to_wv517s(sd);
+
+ scoped_guard(mutex, &wv517s->lock) {
+ /* Node-registration rollback can run before unregistration. */
+ if (wv517s->registration != WV517S_RELEASE_PENDING)
+ return;
+
+ wv517s->registration = WV517S_UNBOUND;
+ }
+
+ kref_put(&wv517s->ref, wv517s_free);
+}
+
+static int wv517s_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+ struct wv517s_device *wv517s = to_wv517s(sd);
+ int ret;
+
+ guard(mutex)(&wv517s->lock);
+ if (wv517s->removed || wv517s->registration != WV517S_REGISTERED)
+ return -ENODEV;
+
+ if (!wv517s->users) {
+ ret = wv517s_power_get(wv517s);
+ if (ret)
+ return ret;
+ }
+
+ wv517s->users++;
+ return 0;
+}
+
+static int wv517s_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+ struct wv517s_device *wv517s = to_wv517s(sd);
+
+ guard(mutex)(&wv517s->lock);
+ if (!wv517s->removed && !--wv517s->users)
+ pm_runtime_put(sd->dev);
+
+ return 0;
+}
+
+static const struct v4l2_subdev_internal_ops wv517s_internal_ops = {
+ .registered = wv517s_registered,
+ .unregistered = wv517s_unregistered,
+ .open = wv517s_open,
+ .close = wv517s_close,
+ .release = wv517s_release,
+};
+
+static const struct v4l2_subdev_ops wv517s_subdev_ops = { };
+
+static void wv517s_stop(struct wv517s_device *wv517s)
+{
+ struct device *dev = wv517s->sd.dev;
+
+ scoped_guard(mutex, &wv517s->lock) {
+ wv517s->removed = true;
+ if (wv517s->users)
+ pm_runtime_put_noidle(dev);
+ }
+
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+}
+
+static int wv517s_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct wv517s_device *wv517s;
+ int ret;
+
+ wv517s = kzalloc_obj(*wv517s);
+ if (!wv517s)
+ return -ENOMEM;
+
+ wv517s->regmap = devm_regmap_init_i2c(client, &wv517s_regmap_config);
+ if (IS_ERR(wv517s->regmap)) {
+ ret = dev_err_probe(dev, PTR_ERR(wv517s->regmap),
+ "failed to initialize regmap\n");
+ kfree(wv517s);
+ return ret;
+ }
+
+ kref_init(&wv517s->ref);
+ mutex_init(&wv517s->lock);
+ wv517s->focus = WV517S_DEFAULT_FOCUS_POSITION;
+ v4l2_i2c_subdev_init(&wv517s->sd, client, &wv517s_subdev_ops);
+ wv517s->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+ wv517s->sd.internal_ops = &wv517s_internal_ops;
+ wv517s->sd.entity.function = MEDIA_ENT_F_LENS;
+
+ v4l2_ctrl_handler_init(&wv517s->ctrl_handler, 1);
+ v4l2_ctrl_new_std(&wv517s->ctrl_handler, &wv517s_ctrl_ops,
+ V4L2_CID_FOCUS_ABSOLUTE, 0,
+ WV517S_MAX_FOCUS_POSITION, 1,
+ WV517S_DEFAULT_FOCUS_POSITION);
+ if (wv517s->ctrl_handler.error) {
+ ret = wv517s->ctrl_handler.error;
+ goto err_free_ctrl_handler;
+ }
+ wv517s->sd.ctrl_handler = &wv517s->ctrl_handler;
+
+ ret = media_entity_pads_init(&wv517s->sd.entity, 0, NULL);
+ if (ret)
+ goto err_free_ctrl_handler;
+
+ /* Leave the actuator suspended until a consumer requests focus. */
+ pm_runtime_enable(dev);
+
+ ret = v4l2_async_register_subdev(&wv517s->sd);
+ if (ret) {
+ wv517s_stop(wv517s);
+ kref_put(&wv517s->ref, wv517s_free);
+ return ret;
+ }
+
+ return 0;
+
+err_free_ctrl_handler:
+ v4l2_ctrl_handler_free(&wv517s->ctrl_handler);
+ mutex_destroy(&wv517s->lock);
+ kfree(wv517s);
+ return ret;
+}
+
+static void wv517s_remove(struct i2c_client *client)
+{
+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
+ struct wv517s_device *wv517s = to_wv517s(sd);
+
+ wv517s_stop(wv517s);
+ v4l2_async_unregister_subdev(sd);
+ kref_put(&wv517s->ref, wv517s_free);
+}
+
+static const struct i2c_device_id wv517s_id_table[] = {
+ { .name = "wv517s" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, wv517s_id_table);
+
+static struct i2c_driver wv517s_i2c_driver = {
+ .driver = {
+ .name = "wv517s",
+ .pm = pm_ptr(&wv517s_pm_ops),
+ },
+ .probe = wv517s_probe,
+ .remove = wv517s_remove,
+ .id_table = wv517s_id_table,
+};
+module_i2c_driver(wv517s_i2c_driver);
+
+MODULE_AUTHOR("Maurizio Casciano <mauriziocasciano7@gmail.com>");
+MODULE_DESCRIPTION("WV517S VCM driver");
+MODULE_LICENSE("GPL");
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v11 14/14] media: atomisp: Preserve the capture graph when a lens rebinds
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
` (12 preceding siblings ...)
2026-11-21 13:31 ` [PATCH v11 13/14] media: i2c: Add WV517S lens actuator driver Maurizio Casciano
@ 2026-11-21 13:31 ` Maurizio Casciano
13 siblings, 0 replies; 16+ messages in thread
From: Maurizio Casciano @ 2026-11-21 13:31 UTC (permalink / raw)
To: linux-media
Cc: Maurizio Casciano, Sakari Ailus, Jacopo Mondi, Nicholas Roth,
Mauro Carvalho Chehab, Bingbu Cao, Dan Scally, Hans de Goede,
Andy Shevchenko, Greg Kroah-Hartman, Andy Shevchenko,
linux-kernel, linux-staging, Laurent Pinchart
The root notifier completes again when the lens subdevice is rebound.
Rebuilding the entire graph adds the original sensors a second time
and attempts to register the capture video device again.
If the capture node already exists and the sensors are unchanged,
register only missing subdevice nodes. Reject a changed sensor graph until
the driver is reinitialized. The preceding V4L2 rollback fix keeps
existing sensor nodes if new node registration fails. The X91L rebind
trial exposed the original issue. Codex drafted the notifier change.
Link: https://linuxtv.org/mailman3/hyperkitty/list/media-ci@linuxtv.org/message/2PUHZIDBEIGQKGXTJJOUXXJS2EOEMJGD/
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
.../media/atomisp/pci/atomisp_csi2_bridge.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
index 56da454f0..72048de9b 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
@@ -508,8 +508,23 @@ static void atomisp_notifier_unbind(struct v4l2_async_notifier *notifier,
static int atomisp_notifier_complete(struct v4l2_async_notifier *notifier)
{
struct atomisp_device *isp = notifier_to_atomisp(notifier);
+ unsigned int i;
- return atomisp_register_device_nodes(isp);
+ if (!video_is_registered(&isp->asd.video_out.vdev))
+ return atomisp_register_device_nodes(isp);
+
+ /*
+ * Completing the lens notifier again only needs a new lens node.
+ * The existing graph is valid as long as its sensors are unchanged.
+ */
+ for (i = 0; i < isp->input_cnt; i++) {
+ const struct atomisp_input_subdev *input = &isp->inputs[i];
+
+ if (input->csi_remote_source != isp->sensor_subdevs[input->port])
+ return -EBUSY;
+ }
+
+ return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
}
static const struct v4l2_async_notifier_operations atomisp_async_ops = {
--
2.53.0
^ permalink raw reply [flat|nested] 16+ messages in thread