Skip to contentSkip to conversation

media: v4l: Call s_stream() on VCM when it is called on the associated sensor

PATCH In review Hans de Goede 4 participants 10 messages Sep 1, 2024 – Oct 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover media: v4l: Call s_stream() on VCM when it is called on the associated sensor

Hi All,

The first patch in this series addresses a long standing issue with VCM device power-management where merely opening the /dev node causes the VCM to power on. This issue was recently brought up on the libcamera- devel list and this is my attempt at fixing this.

The second patch is a new VCM driver which I have had in my personal tree for quite a while now, but finishing it was blocked on the power-management issue. This new driver shows how VCM runtime-pm can work after patch 1.

Regards,

Hans

Hans de Goede (2):
media: v4l: Call s_stream() on VCM when it is called on the associated
sensor
media: i2c: Add driver for AD5823 VCM

 drivers/media/i2c/Kconfig             |   5 +
 drivers/media/i2c/Makefile            |   1 +
 drivers/media/i2c/ad5823.c            | 311 ++++++++++++++++++++++++++
 drivers/media/v4l2-core/v4l2-async.c  |  20 ++
 drivers/media/v4l2-core/v4l2-subdev.c |  28 ++-
 include/media/v4l2-subdev.h           |   2 +
 6 files changed, 361 insertions(+), 6 deletions(-)
 create mode 100644 drivers/media/i2c/ad5823.c
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/2 media: v4l: Call s_stream() on VCM when it is called on the associated sensor

Currently VCM drivers power-up the VCM as soon as the VCM's /dev node is opened and through the runtime-pm device-link to the sensor this also powers up the sensor.

Powering up the VCM and sensor when the /dev node is opened is undesirable, without a VCM sensors delay powering up until s_stream(1) is called. This allows querying / negotiating capabilities without powering things up.

Sometimes a long running daemon like pipewire may keep the /dev node open all the time. The kernel should still be able to powerdown the VCM + sensor in this scenario.

VCM drivers should be able to do the same as sensor drivers and only power-up the VCM when s_stream(1) is called on the VCM subdev, but this requires that s_stream() is actually called on the VCM when the sensor starts / stops streaming.

The s_stream() call on sensor subdevs is done by CSI-receiver/ISP drivers. To avoid needing to change all these call sites to also call s_stream() on the VCM (if there is one) handle the VCM in the v4l2-core similar to how the core takes care of turning on/off the privacy LED.

---
 drivers/media/v4l2-core/v4l2-async.c  | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-subdev.c | 28 +++++++++++++++++++++------
 include/media/v4l2-subdev.h           |  2 ++
 3 files changed, 44 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +20 -0
index ee884a8221fb..9b854f1d1051 100644
@@ -330,6 +330,11 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
 		return 0;
 	}
 
+	if (sd->entity.function == MEDIA_ENT_F_LENS) {
+		dev_dbg(n->sd->dev, "Using %s VCM\n", dev_name(sd->dev));
+		n->sd->vcm = sd;
+	}
+
 	link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
 
 	return IS_ERR(link) ? PTR_ERR(link) : 0;
@@ -871,6 +876,21 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 	if (!sd->async_list.next)
 		return;
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	if (sd->entity.function == MEDIA_ENT_F_LENS && sd->v4l2_dev && sd->v4l2_dev->mdev) {
+		struct media_entity *entity;
+
+		media_device_for_each_entity(entity, sd->v4l2_dev->mdev) {
+			struct v4l2_subdev *it = media_entity_to_v4l2_subdev(entity);
+
+			if (it->vcm == sd) {
+				dev_dbg(it->dev, "Clearing VCM\n");
+				it->vcm = NULL;
+			}
+		}
+	}
+#endif
+
 	v4l2_subdev_put_privacy_led(sd);
 
 	mutex_lock(&list_lock);
drivers/media/v4l2-core/v4l2-subdev.c +22 -6
index 7c5812d55315..24a68d90f686 100644
@@ -148,17 +148,33 @@ static int subdev_close(struct file *file)
 }
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
-static void v4l2_subdev_enable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_enable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led,
 				   sd->privacy_led->max_brightness);
 #endif
+
+	if (sd->vcm && !sd->vcm_enabled &&
+	    v4l2_subdev_has_op(sd->vcm, video, s_stream)) {
+		int ret;
+
+		ret = v4l2_subdev_call(sd->vcm, video, s_stream, 1);
+		if (ret)
+			dev_err(sd->vcm->dev, "Error powering on VCM: %d\n", ret);
+		else
+			sd->vcm_enabled = true;
+	}
 }
 
-static void v4l2_subdev_disable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_disable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
+	if (sd->vcm && sd->vcm_enabled) {
+		v4l2_subdev_call(sd->vcm, video, s_stream, 0);
+		sd->vcm_enabled = false;
+	}
+
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led, 0);
@@ -466,9 +482,9 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		sd->s_stream_enabled = enable;
 
 		if (enable)
-			v4l2_subdev_enable_privacy_led(sd);
+			v4l2_subdev_enable_privacy_led_and_vcm(sd);
 		else
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 	}
 
 	return ret;
@@ -2289,7 +2305,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 	 * for all cases.
 	 */
 	if (!use_s_stream && !already_streaming)
-		v4l2_subdev_enable_privacy_led(sd);
+		v4l2_subdev_enable_privacy_led_and_vcm(sd);
 
 done:
 	if (!use_s_stream)
@@ -2382,7 +2398,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 done:
 	if (!use_s_stream) {
 		if (!v4l2_subdev_is_streaming(sd))
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 
 		v4l2_subdev_unlock_state(state);
 	}
include/media/v4l2-subdev.h +2 -0
index bd235d325ff9..6568a0cc070b 100644
@@ -1094,6 +1094,7 @@ struct v4l2_subdev {
 	 */
 
 	struct led_classdev *privacy_led;
+	struct v4l2_subdev *vcm;
 
 	/*
 	 * TODO: active_state should most likely be changed from a pointer to an
@@ -1104,6 +1105,7 @@ struct v4l2_subdev {
 	struct v4l2_subdev_state *active_state;
 	u64 enabled_pads;
 	bool s_stream_enabled;
+	bool vcm_enabled;
 };
 
 
Signature · 1 line
2.46.0
#2 lore raw

Hi Hans,

Thank you for the patch.

Quoted 8 lines · Hans de Goede

Currently VCM drivers power-up the VCM as soon as the VCM's /dev node is opened and through the runtime-pm device-link to the sensor this also powers up the sensor.

Powering up the VCM and sensor when the /dev node is opened is undesirable, without a VCM sensors delay powering up until s_stream(1) is called. This allows querying / negotiating capabilities without powering things up.

Quoted 8 lines

Sometimes a long running daemon like pipewire may keep the /dev node open all the time. The kernel should still be able to powerdown the VCM + sensor in this scenario.

VCM drivers should be able to do the same as sensor drivers and only power-up the VCM when s_stream(1) is called on the VCM subdev, but this requires that s_stream() is actually called on the VCM when the sensor starts / stops streaming.

.s_stream() doesn't conceptually make sense for VCMs. Furthermore, .s_stream() is being replaced with .enable_streams() and .disable_streams(), which will make even less sense. We need a different API.

Quoted 4 lines

The s_stream() call on sensor subdevs is done by CSI-receiver/ISP drivers. To avoid needing to change all these call sites to also call s_stream() on the VCM (if there is one) handle the VCM in the v4l2-core similar to how the core takes care of turning on/off the privacy LED.

This needs to come with a design rationale, documented in Documentation/. The design needs to explain the use cases. Lens motion may take time, which I expect will influence how we will need to handle power management.

I'm not very comfortable handling this in v4l2-subdev.c, it seems that we'll hardcode use cases. Without a clear and detailed designed rationale, this patch feels we'll paint ourselves in a corner. We have enough badly designed (or not designed at all) APIs for cameras, it's time to do better.

Quoted 135 lines
---
 drivers/media/v4l2-core/v4l2-async.c  | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-subdev.c | 28 +++++++++++++++++++++------
 include/media/v4l2-subdev.h           |  2 ++
 3 files changed, 44 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +20 -0
index ee884a8221fb..9b854f1d1051 100644
@@ -330,6 +330,11 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
 		return 0;
 	}
 
+	if (sd->entity.function == MEDIA_ENT_F_LENS) {
+		dev_dbg(n->sd->dev, "Using %s VCM\n", dev_name(sd->dev));
+		n->sd->vcm = sd;
+	}
+
 	link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
 
 	return IS_ERR(link) ? PTR_ERR(link) : 0;
@@ -871,6 +876,21 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 	if (!sd->async_list.next)
 		return;
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	if (sd->entity.function == MEDIA_ENT_F_LENS && sd->v4l2_dev && sd->v4l2_dev->mdev) {
+		struct media_entity *entity;
+
+		media_device_for_each_entity(entity, sd->v4l2_dev->mdev) {
+			struct v4l2_subdev *it = media_entity_to_v4l2_subdev(entity);
+
+			if (it->vcm == sd) {
+				dev_dbg(it->dev, "Clearing VCM\n");
+				it->vcm = NULL;
+			}
+		}
+	}
+#endif
+
 	v4l2_subdev_put_privacy_led(sd);
 
 	mutex_lock(&list_lock);
drivers/media/v4l2-core/v4l2-subdev.c +22 -6
index 7c5812d55315..24a68d90f686 100644
@@ -148,17 +148,33 @@ static int subdev_close(struct file *file)
 }
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
-static void v4l2_subdev_enable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_enable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led,
 				   sd->privacy_led->max_brightness);
 #endif
+
+	if (sd->vcm && !sd->vcm_enabled &&
+	    v4l2_subdev_has_op(sd->vcm, video, s_stream)) {
+		int ret;
+
+		ret = v4l2_subdev_call(sd->vcm, video, s_stream, 1);
+		if (ret)
+			dev_err(sd->vcm->dev, "Error powering on VCM: %d\n", ret);
+		else
+			sd->vcm_enabled = true;
+	}
 }
 
-static void v4l2_subdev_disable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_disable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
+	if (sd->vcm && sd->vcm_enabled) {
+		v4l2_subdev_call(sd->vcm, video, s_stream, 0);
+		sd->vcm_enabled = false;
+	}
+
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led, 0);
@@ -466,9 +482,9 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		sd->s_stream_enabled = enable;
 
 		if (enable)
-			v4l2_subdev_enable_privacy_led(sd);
+			v4l2_subdev_enable_privacy_led_and_vcm(sd);
 		else
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 	}
 
 	return ret;
@@ -2289,7 +2305,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 	 * for all cases.
 	 */
 	if (!use_s_stream && !already_streaming)
-		v4l2_subdev_enable_privacy_led(sd);
+		v4l2_subdev_enable_privacy_led_and_vcm(sd);
 
 done:
 	if (!use_s_stream)
@@ -2382,7 +2398,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 done:
 	if (!use_s_stream) {
 		if (!v4l2_subdev_is_streaming(sd))
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 
 		v4l2_subdev_unlock_state(state);
 	}
include/media/v4l2-subdev.h +2 -0
index bd235d325ff9..6568a0cc070b 100644
@@ -1094,6 +1094,7 @@ struct v4l2_subdev {
 	 */
 
 	struct led_classdev *privacy_led;
+	struct v4l2_subdev *vcm;
 
 	/*
 	 * TODO: active_state should most likely be changed from a pointer to an
@@ -1104,6 +1105,7 @@ struct v4l2_subdev {
 	struct v4l2_subdev_state *active_state;
 	u64 enabled_pads;
 	bool s_stream_enabled;
+	bool vcm_enabled;
 };
 
 
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

Hi Laurent,

Quoted 22 lines · Laurent Pinchart

Hi Hans,

Thank you for the patch.

Quoted 8 lines · Hans de Goede

Currently VCM drivers power-up the VCM as soon as the VCM's /dev node is opened and through the runtime-pm device-link to the sensor this also powers up the sensor.

Powering up the VCM and sensor when the /dev node is opened is undesirable, without a VCM sensors delay powering up until s_stream(1) is called. This allows querying / negotiating capabilities without powering things up.

Quoted 8 lines

Sometimes a long running daemon like pipewire may keep the /dev node open all the time. The kernel should still be able to powerdown the VCM + sensor in this scenario.

VCM drivers should be able to do the same as sensor drivers and only power-up the VCM when s_stream(1) is called on the VCM subdev, but this requires that s_stream() is actually called on the VCM when the sensor starts / stops streaming.

Quoted 4 lines

.s_stream() doesn't conceptually make sense for VCMs. Furthermore, .s_stream() is being replaced with .enable_streams() and .disable_streams(), which will make even less sense. We need a different API.

We can discuss how to call the subdev ops for this once we know what the overal design for this is going to be. So lets postpone the discussion about naming the subdev ops for this till later.

Quoted 10 lines
Quoted 4 lines

The s_stream() call on sensor subdevs is done by CSI-receiver/ISP drivers. To avoid needing to change all these call sites to also call s_stream() on the VCM (if there is one) handle the VCM in the v4l2-core similar to how the core takes care of turning on/off the privacy LED.

This needs to come with a design rationale, documented in Documentation/. The design needs to explain the use cases. Lens motion may take time, which I expect will influence how we will need to handle power management.

Quoted 5 lines

I'm not very comfortable handling this in v4l2-subdev.c, it seems that we'll hardcode use cases. Without a clear and detailed designed rationale, this patch feels we'll paint ourselves in a corner. We have enough badly designed (or not designed at all) APIs for cameras, it's time to do better.

Design wise I roughly see 3 options:

a. Stick with the current design of powering on on open of /dev/v4l-subdev

b. Add explicit calls userspace can make to power-on the device

c. My current proposal to automatically power-on when the sensor associated with the VCM.

Since this patch series implements 3, I'm going to discuss that option here now. But if that hits a dead end we can look at 2. too.

Talking about use-cases, lets simplify things by looking at use-cases solely from a VCM power on/off point of view. Looking at it that way I really only see 2 orthogonal groupings for all use-cases (so 4 possible combinations of groupings, but I think we can discuss each of the 2 axis separately):

Grouping i: amount of sensor stream start/stops in a single "use"

1. The sensor starts streaming once and then the stream stops for a significant period of time; vs

2. The stream is sometimes stopped to change settings and then restarted within a single use-case.

For 1. automatically powering on the VCM on stream start is fine. For 2. we do not want the VCM to turn off and then back on again while changing settings. We can use auto-suspend with a long enough auto-suspend delay (we could default to 1s) for this. There might be some special cases where we need to change the auto-suspend delay. We could add some V4L2 API (ctrl?) for this, or use the existing sysfs API through e.g. a udev rule.

To me using autosuspend-delays here seems workable and having the v4l2-subdev code manage the power has the advantage that it does not break any userspace APIs. IOW things will just work while saving power for existing users and things will also just work for new use-cases without requiring userspace to have to do extra work for this.

Grouping ii: Does the VCM need to be turned on before the stream starts:

3. A small delay at startup for the power-on (on the first start stream, not when switching modes) is fine / having the first few frames being out of focus while the lens moves is fine, they typically will be anyways until the autofocus algorithm has locked; vs

4. A small delay at startup for the power-on is undesirable / the focus value is known beforehand and the lens must be in position before capturing the first frame.

4. will clearly not work well when the v4l2-subdev code manage the power. But this seems like a rather corner case scenario; and one which we could still make work by simply disabling runtime-pm for the VCM through sysfs in this case.

In conclusion to me it seems that having the v4l2-subdev code manage the power seems like it would work well. The only really problematic scenario which I can come up with is 4. and that seems a bit of a corner case. If this ever becomes a problem we could can make it work by either disabling runtime-pm through sysfs or by offering some API to prime the VCM which turns it on before the first stream-start (and it will still get automatically turned off after stream-stop + timeout).

We could even mix option b) and c) from the "Design wise I roughly see 3 options" options above and offer explicit power-management for apps which want that; while still automatically increasing the power-on count on sensor streaming, with any power-on count > 1 turning the VCM on.

This way apps/use-cases which want to make sure the VCM is on early or stays on during mode switching can use the explicit APIs while simpler use-cases (and existing use-cases since we cannot break userspace API) can rely on the automatic powering on done by the v4l2-subdev core.

The only downside which I can see of using a power-on counter and combining explicit + automatic control is that it will be impossible to turn the VCM off while streaming.

Regards,

Hans

Quoted 137 lines
Quoted 136 lines
---
 drivers/media/v4l2-core/v4l2-async.c  | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-subdev.c | 28 +++++++++++++++++++++------
 include/media/v4l2-subdev.h           |  2 ++
 3 files changed, 44 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +20 -0
index ee884a8221fb..9b854f1d1051 100644
@@ -330,6 +330,11 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
 		return 0;
 	}
 
+	if (sd->entity.function == MEDIA_ENT_F_LENS) {
+		dev_dbg(n->sd->dev, "Using %s VCM\n", dev_name(sd->dev));
+		n->sd->vcm = sd;
+	}
+
 	link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
 
 	return IS_ERR(link) ? PTR_ERR(link) : 0;
@@ -871,6 +876,21 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 	if (!sd->async_list.next)
 		return;
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	if (sd->entity.function == MEDIA_ENT_F_LENS && sd->v4l2_dev && sd->v4l2_dev->mdev) {
+		struct media_entity *entity;
+
+		media_device_for_each_entity(entity, sd->v4l2_dev->mdev) {
+			struct v4l2_subdev *it = media_entity_to_v4l2_subdev(entity);
+
+			if (it->vcm == sd) {
+				dev_dbg(it->dev, "Clearing VCM\n");
+				it->vcm = NULL;
+			}
+		}
+	}
+#endif
+
 	v4l2_subdev_put_privacy_led(sd);
 
 	mutex_lock(&list_lock);
drivers/media/v4l2-core/v4l2-subdev.c +22 -6
index 7c5812d55315..24a68d90f686 100644
@@ -148,17 +148,33 @@ static int subdev_close(struct file *file)
 }
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
-static void v4l2_subdev_enable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_enable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led,
 				   sd->privacy_led->max_brightness);
 #endif
+
+	if (sd->vcm && !sd->vcm_enabled &&
+	    v4l2_subdev_has_op(sd->vcm, video, s_stream)) {
+		int ret;
+
+		ret = v4l2_subdev_call(sd->vcm, video, s_stream, 1);
+		if (ret)
+			dev_err(sd->vcm->dev, "Error powering on VCM: %d\n", ret);
+		else
+			sd->vcm_enabled = true;
+	}
 }
 
-static void v4l2_subdev_disable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_disable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
+	if (sd->vcm && sd->vcm_enabled) {
+		v4l2_subdev_call(sd->vcm, video, s_stream, 0);
+		sd->vcm_enabled = false;
+	}
+
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led, 0);
@@ -466,9 +482,9 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		sd->s_stream_enabled = enable;
 
 		if (enable)
-			v4l2_subdev_enable_privacy_led(sd);
+			v4l2_subdev_enable_privacy_led_and_vcm(sd);
 		else
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 	}
 
 	return ret;
@@ -2289,7 +2305,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 	 * for all cases.
 	 */
 	if (!use_s_stream && !already_streaming)
-		v4l2_subdev_enable_privacy_led(sd);
+		v4l2_subdev_enable_privacy_led_and_vcm(sd);
 
 done:
 	if (!use_s_stream)
@@ -2382,7 +2398,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 done:
 	if (!use_s_stream) {
 		if (!v4l2_subdev_is_streaming(sd))
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 
 		v4l2_subdev_unlock_state(state);
 	}
include/media/v4l2-subdev.h +2 -0
index bd235d325ff9..6568a0cc070b 100644
@@ -1094,6 +1094,7 @@ struct v4l2_subdev {
 	 */
 
 	struct led_classdev *privacy_led;
+	struct v4l2_subdev *vcm;
 
 	/*
 	 * TODO: active_state should most likely be changed from a pointer to an
@@ -1104,6 +1105,7 @@ struct v4l2_subdev {
 	struct v4l2_subdev_state *active_state;
 	u64 enabled_pads;
 	bool s_stream_enabled;
+	bool vcm_enabled;
 };
 
 
#4 lore raw

p.s.

Quoted 84 lines · Hans de Goede

Hi Laurent,

Quoted 22 lines · Laurent Pinchart

Hi Hans,

Thank you for the patch.

Quoted 8 lines · Hans de Goede

Currently VCM drivers power-up the VCM as soon as the VCM's /dev node is opened and through the runtime-pm device-link to the sensor this also powers up the sensor.

Powering up the VCM and sensor when the /dev node is opened is undesirable, without a VCM sensors delay powering up until s_stream(1) is called. This allows querying / negotiating capabilities without powering things up.

Quoted 8 lines

Sometimes a long running daemon like pipewire may keep the /dev node open all the time. The kernel should still be able to powerdown the VCM + sensor in this scenario.

VCM drivers should be able to do the same as sensor drivers and only power-up the VCM when s_stream(1) is called on the VCM subdev, but this requires that s_stream() is actually called on the VCM when the sensor starts / stops streaming.

Quoted 4 lines

.s_stream() doesn't conceptually make sense for VCMs. Furthermore, .s_stream() is being replaced with .enable_streams() and .disable_streams(), which will make even less sense. We need a different API.

We can discuss how to call the subdev ops for this once we know what the overal design for this is going to be. So lets postpone the discussion about naming the subdev ops for this till later.

Quoted 10 lines
Quoted 4 lines

The s_stream() call on sensor subdevs is done by CSI-receiver/ISP drivers. To avoid needing to change all these call sites to also call s_stream() on the VCM (if there is one) handle the VCM in the v4l2-core similar to how the core takes care of turning on/off the privacy LED.

This needs to come with a design rationale, documented in Documentation/. The design needs to explain the use cases. Lens motion may take time, which I expect will influence how we will need to handle power management.

Quoted 5 lines

I'm not very comfortable handling this in v4l2-subdev.c, it seems that we'll hardcode use cases. Without a clear and detailed designed rationale, this patch feels we'll paint ourselves in a corner. We have enough badly designed (or not designed at all) APIs for cameras, it's time to do better.

Design wise I roughly see 3 options:

a. Stick with the current design of powering on on open of /dev/v4l-subdev

b. Add explicit calls userspace can make to power-on the device

c. My current proposal to automatically power-on when the sensor associated with the VCM.

Since this patch series implements 3, I'm going to discuss that option here now. But if that hits a dead end we can look at 2. too.

Talking about use-cases, lets simplify things by looking at use-cases solely from a VCM power on/off point of view. Looking at it that way I really only see 2 orthogonal groupings for all use-cases (so 4 possible combinations of groupings, but I think we can discuss each of the 2 axis separately):

Grouping i: amount of sensor stream start/stops in a single "use"

1. The sensor starts streaming once and then the stream stops for a significant period of time; vs

2. The stream is sometimes stopped to change settings and then restarted within a single use-case.

For 1. automatically powering on the VCM on stream start is fine. For 2. we do not want the VCM to turn off and then back on again while changing settings. We can use auto-suspend with a long enough auto-suspend delay (we could default to 1s) for this. There might be some special cases where we need to change the auto-suspend delay. We could add some V4L2 API (ctrl?) for this, or use the existing sysfs API through e.g. a udev rule.

Quoted 6 lines

To me using autosuspend-delays here seems workable and having the v4l2-subdev code manage the power has the advantage that it does not break any userspace APIs. IOW things will just work while saving power for existing users and things will also just work for new use-cases without requiring userspace to have to do extra work for this.

Note that apparently even with the existing power-on on open() there are issues where the VCM powers-down when change modes and people are already submitting patch to work around this, e.g. :

https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/

Quoted 189 lines

Grouping ii: Does the VCM need to be turned on before the stream starts:

3. A small delay at startup for the power-on (on the first start stream, not when switching modes) is fine / having the first few frames being out of focus while the lens moves is fine, they typically will be anyways until the autofocus algorithm has locked; vs

4. A small delay at startup for the power-on is undesirable / the focus value is known beforehand and the lens must be in position before capturing the first frame.

4. will clearly not work well when the v4l2-subdev code manage the power. But this seems like a rather corner case scenario; and one which we could still make work by simply disabling runtime-pm for the VCM through sysfs in this case.

In conclusion to me it seems that having the v4l2-subdev code manage the power seems like it would work well. The only really problematic scenario which I can come up with is 4. and that seems a bit of a corner case. If this ever becomes a problem we could can make it work by either disabling runtime-pm through sysfs or by offering some API to prime the VCM which turns it on before the first stream-start (and it will still get automatically turned off after stream-stop + timeout).

We could even mix option b) and c) from the "Design wise I roughly see 3 options" options above and offer explicit power-management for apps which want that; while still automatically increasing the power-on count on sensor streaming, with any power-on count > 1 turning the VCM on.

This way apps/use-cases which want to make sure the VCM is on early or stays on during mode switching can use the explicit APIs while simpler use-cases (and existing use-cases since we cannot break userspace API) can rely on the automatic powering on done by the v4l2-subdev core.

The only downside which I can see of using a power-on counter and combining explicit + automatic control is that it will be impossible to turn the VCM off while streaming.

Regards,

Hans

Quoted 137 lines
Quoted 136 lines
---
 drivers/media/v4l2-core/v4l2-async.c  | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-subdev.c | 28 +++++++++++++++++++++------
 include/media/v4l2-subdev.h           |  2 ++
 3 files changed, 44 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +20 -0
index ee884a8221fb..9b854f1d1051 100644
@@ -330,6 +330,11 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
 		return 0;
 	}
 
+	if (sd->entity.function == MEDIA_ENT_F_LENS) {
+		dev_dbg(n->sd->dev, "Using %s VCM\n", dev_name(sd->dev));
+		n->sd->vcm = sd;
+	}
+
 	link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
 
 	return IS_ERR(link) ? PTR_ERR(link) : 0;
@@ -871,6 +876,21 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 	if (!sd->async_list.next)
 		return;
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	if (sd->entity.function == MEDIA_ENT_F_LENS && sd->v4l2_dev && sd->v4l2_dev->mdev) {
+		struct media_entity *entity;
+
+		media_device_for_each_entity(entity, sd->v4l2_dev->mdev) {
+			struct v4l2_subdev *it = media_entity_to_v4l2_subdev(entity);
+
+			if (it->vcm == sd) {
+				dev_dbg(it->dev, "Clearing VCM\n");
+				it->vcm = NULL;
+			}
+		}
+	}
+#endif
+
 	v4l2_subdev_put_privacy_led(sd);
 
 	mutex_lock(&list_lock);
drivers/media/v4l2-core/v4l2-subdev.c +22 -6
index 7c5812d55315..24a68d90f686 100644
@@ -148,17 +148,33 @@ static int subdev_close(struct file *file)
 }
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
-static void v4l2_subdev_enable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_enable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led,
 				   sd->privacy_led->max_brightness);
 #endif
+
+	if (sd->vcm && !sd->vcm_enabled &&
+	    v4l2_subdev_has_op(sd->vcm, video, s_stream)) {
+		int ret;
+
+		ret = v4l2_subdev_call(sd->vcm, video, s_stream, 1);
+		if (ret)
+			dev_err(sd->vcm->dev, "Error powering on VCM: %d\n", ret);
+		else
+			sd->vcm_enabled = true;
+	}
 }
 
-static void v4l2_subdev_disable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_disable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
+	if (sd->vcm && sd->vcm_enabled) {
+		v4l2_subdev_call(sd->vcm, video, s_stream, 0);
+		sd->vcm_enabled = false;
+	}
+
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led, 0);
@@ -466,9 +482,9 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		sd->s_stream_enabled = enable;
 
 		if (enable)
-			v4l2_subdev_enable_privacy_led(sd);
+			v4l2_subdev_enable_privacy_led_and_vcm(sd);
 		else
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 	}
 
 	return ret;
@@ -2289,7 +2305,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 	 * for all cases.
 	 */
 	if (!use_s_stream && !already_streaming)
-		v4l2_subdev_enable_privacy_led(sd);
+		v4l2_subdev_enable_privacy_led_and_vcm(sd);
 
 done:
 	if (!use_s_stream)
@@ -2382,7 +2398,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 done:
 	if (!use_s_stream) {
 		if (!v4l2_subdev_is_streaming(sd))
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 
 		v4l2_subdev_unlock_state(state);
 	}
include/media/v4l2-subdev.h +2 -0
index bd235d325ff9..6568a0cc070b 100644
@@ -1094,6 +1094,7 @@ struct v4l2_subdev {
 	 */
 
 	struct led_classdev *privacy_led;
+	struct v4l2_subdev *vcm;
 
 	/*
 	 * TODO: active_state should most likely be changed from a pointer to an
@@ -1104,6 +1105,7 @@ struct v4l2_subdev {
 	struct v4l2_subdev_state *active_state;
 	u64 enabled_pads;
 	bool s_stream_enabled;
+	bool vcm_enabled;
 };
 
 
maintainer
#5 lore raw
In reply to Hans de Goede

Hi Hans, Laurent,

Quoted 34 lines · Hans de Goede

Currently VCM drivers power-up the VCM as soon as the VCM's /dev node is opened and through the runtime-pm device-link to the sensor this also powers up the sensor.

Powering up the VCM and sensor when the /dev node is opened is undesirable, without a VCM sensors delay powering up until s_stream(1) is called. This allows querying / negotiating capabilities without powering things up.

Sometimes a long running daemon like pipewire may keep the /dev node open all the time. The kernel should still be able to powerdown the VCM + sensor in this scenario.

VCM drivers should be able to do the same as sensor drivers and only power-up the VCM when s_stream(1) is called on the VCM subdev, but this requires that s_stream() is actually called on the VCM when the sensor starts / stops streaming.

The s_stream() call on sensor subdevs is done by CSI-receiver/ISP drivers. To avoid needing to change all these call sites to also call s_stream() on the VCM (if there is one) handle the VCM in the v4l2-core similar to how the core takes care of turning on/off the privacy LED.

---
 drivers/media/v4l2-core/v4l2-async.c  | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-subdev.c | 28 +++++++++++++++++++++------
 include/media/v4l2-subdev.h           |  2 ++
 3 files changed, 44 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +0 -0
index ee884a8221fb..9b854f1d1051 100644

drivers/media/v4l2-core/v4l2-async.c static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n, · line 333

Quoted 4 lines
drivers/media/v4l2-core/v4l2-async.c +1 -0
@@ -330,6 +330,11 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
 		return 0;
 	}
 
+	if (sd->entity.function == MEDIA_ENT_F_LENS) {

There can be, at least in principle, multiple lenses to control per a sensor. I don't think we have limitations elsewhere in the framework; still API-wise we're limited to focus.

Quoted 41 lines
drivers/media/v4l2-core/v4l2-async.c +19 -0
+		dev_dbg(n->sd->dev, "Using %s VCM\n", dev_name(sd->dev));
+		n->sd->vcm = sd;
+	}
+
 	link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
 
 	return IS_ERR(link) ? PTR_ERR(link) : 0;
@@ -871,6 +876,21 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 	if (!sd->async_list.next)
 		return;
 
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	if (sd->entity.function == MEDIA_ENT_F_LENS && sd->v4l2_dev && sd->v4l2_dev->mdev) {
+		struct media_entity *entity;
+
+		media_device_for_each_entity(entity, sd->v4l2_dev->mdev) {
+			struct v4l2_subdev *it = media_entity_to_v4l2_subdev(entity);
+
+			if (it->vcm == sd) {
+				dev_dbg(it->dev, "Clearing VCM\n");
+				it->vcm = NULL;
+			}
+		}
+	}
+#endif
+
 	v4l2_subdev_put_privacy_led(sd);
 
 	mutex_lock(&list_lock);
drivers/media/v4l2-core/v4l2-subdev.c +1 -1
index 7c5812d55315..24a68d90f686 100644
@@ -148,17 +148,33 @@ static int subdev_close(struct file *file)
 }
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
-static void v4l2_subdev_enable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_enable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)

drivers/media/v4l2-core/v4l2-subdev.c static int subdev_close(struct file *file) · line 163

Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +6 -0
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led,
 				   sd->privacy_led->max_brightness);
 #endif
+
+	if (sd->vcm && !sd->vcm_enabled &&
+	    v4l2_subdev_has_op(sd->vcm, video, s_stream)) {
+		int ret;
+
+		ret = v4l2_subdev_call(sd->vcm, video, s_stream, 1);

Would it be wrong to just use Runtime PM for this?

I'm not sure I like the approach taken in the patch but then again the other suggested solutions don't seem obviously better either.

In the long run, I think we should have a way to tell drivers the userspace would like the (largely I²C) devices to remain in initialised state rather than be powered down. That'll require per-file handle controls in practice so that will have to wait for some time. But it would probably work well with this.

Quoted 68 lines
drivers/media/v4l2-core/v4l2-subdev.c +15 -5
+		if (ret)
+			dev_err(sd->vcm->dev, "Error powering on VCM: %d\n", ret);
+		else
+			sd->vcm_enabled = true;
+	}
 }
 
-static void v4l2_subdev_disable_privacy_led(struct v4l2_subdev *sd)
+static void v4l2_subdev_disable_privacy_led_and_vcm(struct v4l2_subdev *sd)
 {
+	if (sd->vcm && sd->vcm_enabled) {
+		v4l2_subdev_call(sd->vcm, video, s_stream, 0);
+		sd->vcm_enabled = false;
+	}
+
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
 	if (!IS_ERR_OR_NULL(sd->privacy_led))
 		led_set_brightness(sd->privacy_led, 0);
@@ -466,9 +482,9 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		sd->s_stream_enabled = enable;
 
 		if (enable)
-			v4l2_subdev_enable_privacy_led(sd);
+			v4l2_subdev_enable_privacy_led_and_vcm(sd);
 		else
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 	}
 
 	return ret;
@@ -2289,7 +2305,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 	 * for all cases.
 	 */
 	if (!use_s_stream && !already_streaming)
-		v4l2_subdev_enable_privacy_led(sd);
+		v4l2_subdev_enable_privacy_led_and_vcm(sd);
 
 done:
 	if (!use_s_stream)
@@ -2382,7 +2398,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 done:
 	if (!use_s_stream) {
 		if (!v4l2_subdev_is_streaming(sd))
-			v4l2_subdev_disable_privacy_led(sd);
+			v4l2_subdev_disable_privacy_led_and_vcm(sd);
 
 		v4l2_subdev_unlock_state(state);
 	}
include/media/v4l2-subdev.h +2 -0
index bd235d325ff9..6568a0cc070b 100644
@@ -1094,6 +1094,7 @@ struct v4l2_subdev {
 	 */
 
 	struct led_classdev *privacy_led;
+	struct v4l2_subdev *vcm;
 
 	/*
 	 * TODO: active_state should most likely be changed from a pointer to an
@@ -1104,6 +1105,7 @@ struct v4l2_subdev {
 	struct v4l2_subdev_state *active_state;
 	u64 enabled_pads;
 	bool s_stream_enabled;
+	bool vcm_enabled;
 };
 
 
Signature · 3 lines
Regards,

Sakari Ailus
#6 lore raw

PATCH 2/2 media: i2c: Add driver for AD5823 VCM

In reply to Hans de Goede

Add a driver for the AD5823 VCM. The driver creates a v4l2 subdevice and registers a control to set the desired focus.

---
 drivers/media/i2c/Kconfig  |   5 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ad5823.c | 311 +++++++++++++++++++++++++++++++++++++
 3 files changed, 317 insertions(+)
 create mode 100644 drivers/media/i2c/ad5823.c
drivers/media/i2c/Kconfig +5 -0
index 70254f0cca67..4c0b198b7c31 100644
@@ -742,6 +742,11 @@ config VIDEO_AD5820
 	  This is a driver for the AD5820 camera lens voice coil.
 	  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AD5823
+	tristate "AD5823 lens voice coil support"
+	help
+	  This is a driver for the AD5823 camera lens voice coil / VCM.
+
 config VIDEO_AK7375
 	tristate "AK7375 lens voice coil support"
 	depends on I2C && VIDEO_DEV
drivers/media/i2c/Makefile +1 -0
index babc1bc2393e..34d3e7a2abbb 100644
@@ -4,6 +4,7 @@ msp3400-objs	:=	msp3400-driver.o msp3400-kthreads.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
 obj-$(CONFIG_VIDEO_AD5820) += ad5820.o
+obj-$(CONFIG_VIDEO_AD5823) += ad5823.o
 obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
drivers/media/i2c/ad5823.c new file +311 -0

311 lines not on this page · raw message

Signature · 1 line
2.46.0
#7 lore raw

Re: [PATCH 2/2] media: i2c: Add driver for AD5823 VCM

kernel test robot noticed the following build errors:

Hi Hans,

kernel test robot noticed the following build errors:

[auto build test ERROR on media-tree/master]
[also build test ERROR on linuxtv-media-stage/master sailus-media-tree/master linus/master v6.11-rc6 next-20240903] [cannot apply to sailus-media-tree/streams]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Hans-de-Goede/media-v4l-Call-s_stream-on-VCM-when-it-is-called-on-the-associated-sensor/20240902-052000
base:   git://linuxtv.org/media_tree.git master
patch link:    https://lore.kernel.org/r/20240901211834.145186-3-hdegoede%40redhat.com
patch subject: [PATCH 2/2] media: i2c: Add driver for AD5823 VCM
config: x86_64-randconfig-121-20240904 (https://download.01.org/0day-ci/archive/20240904/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240904/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

drivers/media/i2c/ad5823.c: In function 'ad5823_probe':

>> drivers/media/i2c/ad5823.c:203:26: error: implicit declaration of function 'devm_cci_regmap_init_i2c' [-Werror=implicit-function-declaration]
     203 |         ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);
         |                          ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/media/i2c/ad5823.c:203:24: warning: assignment to 'struct regmap *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     203 |         ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);
         |                        ^

cc1: some warnings being treated as errors

vim +/devm_cci_regmap_init_i2c +203 drivers/media/i2c/ad5823.c

193
194 static int ad5823_probe(struct i2c_client *client)
195 {
196 struct ad5823_device *ad5823;
197 int ret;
198
199 ad5823 = devm_kzalloc(&client->dev, sizeof(*ad5823), GFP_KERNEL);
200 if (!ad5823)
201 return -ENOMEM;
202

 > 203		ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);

204 if (IS_ERR(ad5823->regmap))
205 return PTR_ERR(ad5823->regmap);
206
207 ad5823->arc_mode = AD5823_ARC_RES1;
208 ad5823->resonance_period = AD5823_RESONANCE_PERIOD;
209
210 /* Optional indication of ARC mode select */
211 device_property_read_u32(&client->dev, "adi,arc-mode",
212 &ad5823->arc_mode);
213
214 /* Optional indication of VCM resonance period */
215 device_property_read_u32(&client->dev, "adi,resonance-period",
216 &ad5823->resonance_period);
217
218 ad5823->regulator = devm_regulator_get(&client->dev, "vdd");
219 if (IS_ERR(ad5823->regulator))
220 return dev_err_probe(&client->dev, PTR_ERR(ad5823->regulator),
221 "getting regulator\n");
222
223 v4l2_i2c_subdev_init(&ad5823->sd, client, &ad5823_ops);
224 ad5823->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
225
226 ret = ad5823_init_controls(ad5823);
227 if (ret)
228 return ret;
229
230 ret = media_entity_pads_init(&ad5823->sd.entity, 0, NULL);
231 if (ret < 0)
232 goto err_free_ctrl_handler;
233
234 ad5823->sd.entity.function = MEDIA_ENT_F_LENS;
235
236 /*
237 * We need the driver to work in the event that pm runtime is disable in
238 * the kernel, so power up and verify the chip now. In the event that
239 * runtime pm is disabled this will leave the chip on, so that the lens
240 * will work.
241 */
242
243 ret = ad5823_power_up(ad5823, true);
244 if (ret)
245 goto err_cleanup_media;
246
247 pm_runtime_set_active(&client->dev);
248 pm_runtime_get_noresume(&client->dev);
249 pm_runtime_enable(&client->dev);
250
251 ret = v4l2_async_register_subdev(&ad5823->sd);
252 if (ret < 0)
253 goto err_pm_runtime;
254
255 pm_runtime_set_autosuspend_delay(&client->dev, 1000);
256 pm_runtime_use_autosuspend(&client->dev);
257 pm_runtime_put_autosuspend(&client->dev);
258
259 return ret;
260
261 err_pm_runtime:
262 pm_runtime_disable(&client->dev);
263 pm_runtime_put_noidle(&client->dev);
264 ad5823_power_down(ad5823);
265 err_cleanup_media:
266 media_entity_cleanup(&ad5823->sd.entity);
267 err_free_ctrl_handler:
268 v4l2_ctrl_handler_free(&ad5823->ctrls.handler);
269
270 return ret;
271 }
272

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

Re: [PATCH 2/2] media: i2c: Add driver for AD5823 VCM

Hi,

Quoted 26 lines · kernel test robot

Hi Hans,

kernel test robot noticed the following build errors:

[auto build test ERROR on media-tree/master]
[also build test ERROR on linuxtv-media-stage/master sailus-media-tree/master linus/master v6.11-rc6 next-20240903] [cannot apply to sailus-media-tree/streams]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Hans-de-Goede/media-v4l-Call-s_stream-on-VCM-when-it-is-called-on-the-associated-sensor/20240902-052000
base:   git://linuxtv.org/media_tree.git master
patch link:    https://lore.kernel.org/r/20240901211834.145186-3-hdegoede%40redhat.com
patch subject: [PATCH 2/2] media: i2c: Add driver for AD5823 VCM
config: x86_64-randconfig-121-20240904 (https://download.01.org/0day-ci/archive/20240904/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240904/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

Quoted 8 lines
   drivers/media/i2c/ad5823.c: In function 'ad5823_probe':
Quoted 1 line
Quoted 1 line

drivers/media/i2c/ad5823.c:203:26: error: implicit declaration of function 'devm_cci_regmap_init_i2c' [-Werror=implicit-function-declaration]

     203 |         ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);
         |                          ^~~~~~~~~~~~~~~~~~~~~~~~
Quoted 1 line
Quoted 1 line

drivers/media/i2c/ad5823.c:203:24: warning: assignment to 'struct regmap *' from 'int' makes pointer from integer without a cast [-Wint-conversion]

     203 |         ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);
         |                        ^

cc1: some warnings being treated as errors

This is caused by a missing "select V4L2_CCI_I2C" I have fixed this in my local tree and this fix will be included in v2 when I get around to posting v2 (which also depends on the discussion surrounding patch 1/2).

Regards,

Hans

#9 lore raw

Re: [PATCH 2/2] media: i2c: Add driver for AD5823 VCM

In reply to Hans de Goede
kernel test robot noticed the following build errors:

Hi Hans,

kernel test robot noticed the following build errors:

[auto build test ERROR on media-tree/master]
[also build test ERROR on linuxtv-media-stage/master sailus-media-tree/master linus/master v6.11-rc6 next-20240903] [cannot apply to sailus-media-tree/streams]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Hans-de-Goede/media-v4l-Call-s_stream-on-VCM-when-it-is-called-on-the-associated-sensor/20240902-052000
base:   git://linuxtv.org/media_tree.git master
patch link:    https://lore.kernel.org/r/20240901211834.145186-3-hdegoede%40redhat.com
patch subject: [PATCH 2/2] media: i2c: Add driver for AD5823 VCM
config: x86_64-randconfig-076-20240904 (https://download.01.org/0day-ci/archive/20240904/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240904/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/media/i2c/ad5823.c:203:19: error: call to undeclared function 'devm_cci_regmap_init_i2c'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     203 |         ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);
         |                          ^
>> drivers/media/i2c/ad5823.c:203:17: error: incompatible integer to pointer conversion assigning to 'struct regmap *' from 'int' [-Wint-conversion]
     203 |         ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);
         |                        ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2 errors generated.

vim +/devm_cci_regmap_init_i2c +203 drivers/media/i2c/ad5823.c

193
194 static int ad5823_probe(struct i2c_client *client)
195 {
196 struct ad5823_device *ad5823;
197 int ret;
198
199 ad5823 = devm_kzalloc(&client->dev, sizeof(*ad5823), GFP_KERNEL);
200 if (!ad5823)
201 return -ENOMEM;
202

 > 203		ad5823->regmap = devm_cci_regmap_init_i2c(client, 8);

204 if (IS_ERR(ad5823->regmap))
205 return PTR_ERR(ad5823->regmap);
206
207 ad5823->arc_mode = AD5823_ARC_RES1;
208 ad5823->resonance_period = AD5823_RESONANCE_PERIOD;
209
210 /* Optional indication of ARC mode select */
211 device_property_read_u32(&client->dev, "adi,arc-mode",
212 &ad5823->arc_mode);
213
214 /* Optional indication of VCM resonance period */
215 device_property_read_u32(&client->dev, "adi,resonance-period",
216 &ad5823->resonance_period);
217
218 ad5823->regulator = devm_regulator_get(&client->dev, "vdd");
219 if (IS_ERR(ad5823->regulator))
220 return dev_err_probe(&client->dev, PTR_ERR(ad5823->regulator),
221 "getting regulator\n");
222
223 v4l2_i2c_subdev_init(&ad5823->sd, client, &ad5823_ops);
224 ad5823->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
225
226 ret = ad5823_init_controls(ad5823);
227 if (ret)
228 return ret;
229
230 ret = media_entity_pads_init(&ad5823->sd.entity, 0, NULL);
231 if (ret < 0)
232 goto err_free_ctrl_handler;
233
234 ad5823->sd.entity.function = MEDIA_ENT_F_LENS;
235
236 /*
237 * We need the driver to work in the event that pm runtime is disable in
238 * the kernel, so power up and verify the chip now. In the event that
239 * runtime pm is disabled this will leave the chip on, so that the lens
240 * will work.
241 */
242
243 ret = ad5823_power_up(ad5823, true);
244 if (ret)
245 goto err_cleanup_media;
246
247 pm_runtime_set_active(&client->dev);
248 pm_runtime_get_noresume(&client->dev);
249 pm_runtime_enable(&client->dev);
250
251 ret = v4l2_async_register_subdev(&ad5823->sd);
252 if (ret < 0)
253 goto err_pm_runtime;
254
255 pm_runtime_set_autosuspend_delay(&client->dev, 1000);
256 pm_runtime_use_autosuspend(&client->dev);
257 pm_runtime_put_autosuspend(&client->dev);
258
259 return ret;
260
261 err_pm_runtime:
262 pm_runtime_disable(&client->dev);
263 pm_runtime_put_noidle(&client->dev);
264 ad5823_power_down(ad5823);
265 err_cleanup_media:
266 media_entity_cleanup(&ad5823->sd.entity);
267 err_free_ctrl_handler:
268 v4l2_ctrl_handler_free(&ad5823->ctrls.handler);
269
270 return ret;
271 }
272

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki