* [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
@ 2026-09-22 19:39 Cédric Bellegarde
2026-09-23 6:34 ` Sakari Ailus
2026-11-30 14:42 ` Hans de Goede
0 siblings, 2 replies; 9+ messages in thread
From: Cédric Bellegarde @ 2026-09-22 19:39 UTC (permalink / raw)
To: Sakari Ailus, Mauro Carvalho Chehab, kieran.bingham
Cc: linux-media, linux-kernel, phone-devel, Cédric Bellegarde
When a sensor's fwnode references an ancillary lens or flash device
(e.g. via the "lens-focus" or "flash-leds" properties),
v4l2_async_create_ancillary_links() already creates a media controller
link between the two entities, but their runtime PM states remain
independent.
This is a problem for devices such as VCM lens actuators, which are
typically spring-loaded: holding a position away from the spring's
rest point requires continuous power, and the position is not retained
once power is cut. If such an actuator is allowed to runtime-suspend
independently of the sensor, the lens can drift back to its rest
position during an otherwise active capture session.
Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
that its runtime PM state be linked to the associated sensor.
Signed-off-by: Cédric Bellegarde <cedric.bellegarde@adishatz.org>
---
Link runtime PM of ancillary devices such as lens actuators to their associated sensor,
while allowing actuators to autosuspend when idle.
Example usage:
https://gitlab.com/gnumdk/linux/-/commit/82b2d71415a1d95b2170e19ce025afc8bbdcf145
---
drivers/media/v4l2-core/v4l2-async.c | 18 ++++++++++++++----
include/media/v4l2-subdev.h | 7 +++++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 460bf3dbbb88..22df627153b8 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -318,6 +318,7 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
{
#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
struct media_link *link;
+ struct device_link *devlink;
if (sd->entity.function != MEDIA_ENT_F_LENS &&
sd->entity.function != MEDIA_ENT_F_FLASH)
@@ -331,11 +332,20 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
}
link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
-
- return IS_ERR(link) ? PTR_ERR(link) : 0;
-#else
- return 0;
+ if (IS_ERR(link))
+ return PTR_ERR(link);
+
+ if (sd->flags & V4L2_SUBDEV_FL_PM_LINK) {
+ devlink = device_link_add(n->sd->dev, sd->dev,
+ DL_FLAG_PM_RUNTIME |
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (!devlink)
+ dev_warn(notifier_dev(n),
+ "failed to link power management of %s to %s\n",
+ dev_name(sd->dev), dev_name(n->sd->dev));
+ }
#endif
+ return 0;
}
static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index d256b7ec8f84..9f64b10afd10 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -972,6 +972,13 @@ struct v4l2_subdev_internal_ops {
* - Multiple streams per pad are supported
*/
#define V4L2_SUBDEV_FL_STREAMS (1U << 4)
+/*
+ * Set this flag to keep the subdevice active while its associated sensor is active.
+ *
+ * This is intended for ancillary devices, such as lens actuators, whose
+ * hardware state or physical position cannot be retained while powered off.
+ */
+#define V4L2_SUBDEV_FL_PM_LINK (1U << 5)
struct regulator_bulk_data;
---
base-commit: df2908090cda368b01ff43709f51890076c56157
change-id: 20260911-sensors_pm-787eac01aa18
Best regards,
--
Cédric Bellegarde <cedric.bellegarde@adishatz.org>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-09-22 19:39 [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's Cédric Bellegarde
@ 2026-09-23 6:34 ` Sakari Ailus
2026-09-23 6:58 ` Kieran Bingham
2026-11-30 14:42 ` Hans de Goede
1 sibling, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2026-09-23 6:34 UTC (permalink / raw)
To: Cédric Bellegarde
Cc: Mauro Carvalho Chehab, kieran.bingham, linux-media, linux-kernel,
phone-devel, Laurent Pinchart, Hans Verkuil
Hi Cédric,
On Tue, Sep 22, 2026 at 09:39:12PM +0200, Cédric Bellegarde wrote:
> When a sensor's fwnode references an ancillary lens or flash device
> (e.g. via the "lens-focus" or "flash-leds" properties),
> v4l2_async_create_ancillary_links() already creates a media controller
> link between the two entities, but their runtime PM states remain
> independent.
>
> This is a problem for devices such as VCM lens actuators, which are
> typically spring-loaded: holding a position away from the spring's
> rest point requires continuous power, and the position is not retained
> once power is cut. If such an actuator is allowed to runtime-suspend
> independently of the sensor, the lens can drift back to its rest
> position during an otherwise active capture session.
>
> Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
> that its runtime PM state be linked to the associated sensor.
Interesting idea.
The IPU bridge has created such a device link between the VCM and the
sensor as on some ACPI systems the VCM is in fact relying on the power
resources of the sensor. But to do this everywhere?
VCMs traditionally have been powered through opening their sub-device node
and that hasn't been exactly neat API-wise. It has been practical still,
AFAIK, as in order to control the VCM, you have to have a sub-device node
open.
This change also does mean that if the sensor is powered, even for
always-on use cases that generally consume very little power, the VCM is
powered on as well. VCMs still typically consume very little power if the
current is configured to zero. Maybe this won't be an issue? Backtracking
from such a change wouldn't be simple, and might not be possible at all.
There wouldn't be a need for a sub-device flag and this would be done for
all VCMs based on the ancillary link.
I wonder what others think.
Cc Laurent and Hans as well.
--
Kind regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-09-23 6:34 ` Sakari Ailus
@ 2026-09-23 6:58 ` Kieran Bingham
2026-09-25 11:15 ` Sakari Ailus
0 siblings, 1 reply; 9+ messages in thread
From: Kieran Bingham @ 2026-09-23 6:58 UTC (permalink / raw)
To: Cédric Bellegarde, Sakari Ailus
Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, phone-devel,
Laurent Pinchart, Hans Verkuil, Dave Stevenson
Quoting Sakari Ailus (2026-09-23 07:34:54)
> Hi C�dric,
>
> On Tue, Sep 22, 2026 at 09:39:12PM +0200, C�dric Bellegarde wrote:
> > When a sensor's fwnode references an ancillary lens or flash device
> > (e.g. via the "lens-focus" or "flash-leds" properties),
> > v4l2_async_create_ancillary_links() already creates a media controller
> > link between the two entities, but their runtime PM states remain
> > independent.
> >
> > This is a problem for devices such as VCM lens actuators, which are
> > typically spring-loaded: holding a position away from the spring's
> > rest point requires continuous power, and the position is not retained
> > once power is cut. If such an actuator is allowed to runtime-suspend
> > independently of the sensor, the lens can drift back to its rest
> > position during an otherwise active capture session.
> >
> > Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
> > that its runtime PM state be linked to the associated sensor.
>
> Interesting idea.
>
> The IPU bridge has created such a device link between the VCM and the
> sensor as on some ACPI systems the VCM is in fact relying on the power
> resources of the sensor. But to do this everywhere?
Same on any Raspberry Pi camera module. The VCM is powered by the same
enable lines as the Sensor there I think which has made things
interesting in handling VCMs for those devices.
> VCMs traditionally have been powered through opening their sub-device node
> and that hasn't been exactly neat API-wise. It has been practical still,
> AFAIK, as in order to control the VCM, you have to have a sub-device node
> open.
This is an issue though, as libcamera opens the device nodes and holds
the file descriptor when it has a camera. This means that even if the
camera isn't streaming, the VCM is powered on and causes power
consumption on mobile devices which people then attribute to pipewire.
> This change also does mean that if the sensor is powered, even for
> always-on use cases that generally consume very little power, the VCM is
> powered on as well. VCMs still typically consume very little power if the
Do you foresee use cases where a linked VCM shouldn't be powered while
a camera is streaming? That effectively means the lens position seen by
the camera is 'arbitrary' / undefined ?
> current is configured to zero. Maybe this won't be an issue? Backtracking
> from such a change wouldn't be simple, and might not be possible at all.
>
> There wouldn't be a need for a sub-device flag and this would be done for
> all VCMs based on the ancillary link.
>
> I wonder what others think.
>
> Cc Laurent and Hans as well.
Cc Dave too as he's looked at similar things in the past.
--
Kieran
>
> --
> Kind regards,
>
> Sakari Ailus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-09-23 6:58 ` Kieran Bingham
@ 2026-09-25 11:15 ` Sakari Ailus
2026-11-26 6:23 ` Cédric Bellegarde
0 siblings, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2026-09-25 11:15 UTC (permalink / raw)
To: Kieran Bingham
Cc: Cédric Bellegarde, Mauro Carvalho Chehab, linux-media,
linux-kernel, phone-devel, Laurent Pinchart, Hans Verkuil,
Dave Stevenson
Hi Kieran,
On Wed, Sep 23, 2026 at 07:58:21AM +0100, Kieran Bingham wrote:
> Quoting Sakari Ailus (2026-09-23 07:34:54)
> > Hi C�dric,
> >
> > On Tue, Sep 22, 2026 at 09:39:12PM +0200, C�dric Bellegarde wrote:
> > > When a sensor's fwnode references an ancillary lens or flash device
> > > (e.g. via the "lens-focus" or "flash-leds" properties),
> > > v4l2_async_create_ancillary_links() already creates a media controller
> > > link between the two entities, but their runtime PM states remain
> > > independent.
> > >
> > > This is a problem for devices such as VCM lens actuators, which are
> > > typically spring-loaded: holding a position away from the spring's
> > > rest point requires continuous power, and the position is not retained
> > > once power is cut. If such an actuator is allowed to runtime-suspend
> > > independently of the sensor, the lens can drift back to its rest
> > > position during an otherwise active capture session.
> > >
> > > Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
> > > that its runtime PM state be linked to the associated sensor.
> >
> > Interesting idea.
> >
> > The IPU bridge has created such a device link between the VCM and the
> > sensor as on some ACPI systems the VCM is in fact relying on the power
> > resources of the sensor. But to do this everywhere?
>
> Same on any Raspberry Pi camera module. The VCM is powered by the same
> enable lines as the Sensor there I think which has made things
> interesting in handling VCMs for those devices.
Yes, this has been an issue in DT for a long time. :-( I'm not sure if this
approach could extend into a solution for that though.
>
>
> > VCMs traditionally have been powered through opening their sub-device node
> > and that hasn't been exactly neat API-wise. It has been practical still,
> > AFAIK, as in order to control the VCM, you have to have a sub-device node
> > open.
>
> This is an issue though, as libcamera opens the device nodes and holds
> the file descriptor when it has a camera. This means that even if the
> camera isn't streaming, the VCM is powered on and causes power
> consumption on mobile devices which people then attribute to pipewire.
A practical fix for that could be to set the current to 0 when streaming is
off.
>
>
> > This change also does mean that if the sensor is powered, even for
> > always-on use cases that generally consume very little power, the VCM is
> > powered on as well. VCMs still typically consume very little power if the
>
> Do you foresee use cases where a linked VCM shouldn't be powered while
> a camera is streaming? That effectively means the lens position seen by
> the camera is 'arbitrary' / undefined ?
It's neither, in that case the lens will be just in the resting position
which is typically close to infinite.
>
> > current is configured to zero. Maybe this won't be an issue? Backtracking
> > from such a change wouldn't be simple, and might not be possible at all.
> >
> > There wouldn't be a need for a sub-device flag and this would be done for
> > all VCMs based on the ancillary link.
> >
> > I wonder what others think.
> >
> > Cc Laurent and Hans as well.
>
> Cc Dave too as he's looked at similar things in the past.
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-09-25 11:15 ` Sakari Ailus
@ 2026-11-26 6:23 ` Cédric Bellegarde
2026-11-27 17:33 ` Sakari Ailus
0 siblings, 1 reply; 9+ messages in thread
From: Cédric Bellegarde @ 2026-11-26 6:23 UTC (permalink / raw)
To: Sakari Ailus, Kieran Bingham
Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, phone-devel,
Laurent Pinchart, Hans Verkuil, Dave Stevenson
Hello,
Le 25/09/2026 à 13:15, Sakari Ailus a écrit :
> Hi Kieran,
>
> On Wed, Sep 23, 2026 at 07:58:21AM +0100, Kieran Bingham wrote:
>> Quoting Sakari Ailus (2026-09-23 07:34:54)
>>> Hi C�dric,
>>>
>>> On Tue, Sep 22, 2026 at 09:39:12PM +0200, C�dric Bellegarde wrote:
>>>> When a sensor's fwnode references an ancillary lens or flash device
>>>> (e.g. via the "lens-focus" or "flash-leds" properties),
>>>> v4l2_async_create_ancillary_links() already creates a media controller
>>>> link between the two entities, but their runtime PM states remain
>>>> independent.
>>>>
>>>> This is a problem for devices such as VCM lens actuators, which are
>>>> typically spring-loaded: holding a position away from the spring's
>>>> rest point requires continuous power, and the position is not retained
>>>> once power is cut. If such an actuator is allowed to runtime-suspend
>>>> independently of the sensor, the lens can drift back to its rest
>>>> position during an otherwise active capture session.
>>>>
>>>> Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
>>>> that its runtime PM state be linked to the associated sensor.
>>>
>>> Interesting idea.
>>>
>>> The IPU bridge has created such a device link between the VCM and the
>>> sensor as on some ACPI systems the VCM is in fact relying on the power
>>> resources of the sensor. But to do this everywhere?
>>
>> Same on any Raspberry Pi camera module. The VCM is powered by the same
>> enable lines as the Sensor there I think which has made things
>> interesting in handling VCMs for those devices.
>
> Yes, this has been an issue in DT for a long time. :-( I'm not sure if this
> approach could extend into a solution for that though.
>
>>
>>
>>> VCMs traditionally have been powered through opening their sub-device node
>>> and that hasn't been exactly neat API-wise. It has been practical still,
>>> AFAIK, as in order to control the VCM, you have to have a sub-device node
>>> open.
>>
>> This is an issue though, as libcamera opens the device nodes and holds
>> the file descriptor when it has a camera. This means that even if the
>> camera isn't streaming, the VCM is powered on and causes power
>> consumption on mobile devices which people then attribute to pipewire.
>
> A practical fix for that could be to set the current to 0 when streaming is
> off.
For the zero-current route: lens subdevs have no s_stream, so how would
the VCM driver learn that streaming stopped? The device link gets this
from sensor runtime PM without a new API.
>>
>>
>>> This change also does mean that if the sensor is powered, even for
>>> always-on use cases that generally consume very little power, the VCM is
>>> powered on as well. VCMs still typically consume very little power if the
>>
>> Do you foresee use cases where a linked VCM shouldn't be powered while
>> a camera is streaming? That effectively means the lens position seen by
>> the camera is 'arbitrary' / undefined ?
>
> It's neither, in that case the lens will be just in the resting position
> which is typically close to infinite.
>>
>>> current is configured to zero. Maybe this won't be an issue? Backtracking
>>> from such a change wouldn't be simple, and might not be possible at all.
>>>
>>> There wouldn't be a need for a sub-device flag and this would be done for
>>> all VCMs based on the ancillary link.
>>>
>>> I wonder what others think.
>>>
>>> Cc Laurent and Hans as well.
>>
>> Cc Dave too as he's looked at similar things in the past.
>
regards,
--
Cédric Bellegarde
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-11-26 6:23 ` Cédric Bellegarde
@ 2026-11-27 17:33 ` Sakari Ailus
2026-11-30 16:38 ` Dave Stevenson
0 siblings, 1 reply; 9+ messages in thread
From: Sakari Ailus @ 2026-11-27 17:33 UTC (permalink / raw)
To: Cédric Bellegarde
Cc: Kieran Bingham, Mauro Carvalho Chehab, linux-media, linux-kernel,
phone-devel, Laurent Pinchart, Hans Verkuil, Dave Stevenson
Hi Cédric,
On Thu, Nov 26, 2026 at 07:23:32AM +0100, Cédric Bellegarde wrote:
> Hello,
>
> Le 25/09/2026 à 13:15, Sakari Ailus a écrit :
> > Hi Kieran,
> >
> > On Wed, Sep 23, 2026 at 07:58:21AM +0100, Kieran Bingham wrote:
> > > Quoting Sakari Ailus (2026-09-23 07:34:54)
> > > > Hi C�dric,
> > > >
> > > > On Tue, Sep 22, 2026 at 09:39:12PM +0200, C�dric Bellegarde wrote:
> > > > > When a sensor's fwnode references an ancillary lens or flash device
> > > > > (e.g. via the "lens-focus" or "flash-leds" properties),
> > > > > v4l2_async_create_ancillary_links() already creates a media controller
> > > > > link between the two entities, but their runtime PM states remain
> > > > > independent.
> > > > >
> > > > > This is a problem for devices such as VCM lens actuators, which are
> > > > > typically spring-loaded: holding a position away from the spring's
> > > > > rest point requires continuous power, and the position is not retained
> > > > > once power is cut. If such an actuator is allowed to runtime-suspend
> > > > > independently of the sensor, the lens can drift back to its rest
> > > > > position during an otherwise active capture session.
> > > > >
> > > > > Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
> > > > > that its runtime PM state be linked to the associated sensor.
> > > >
> > > > Interesting idea.
> > > >
> > > > The IPU bridge has created such a device link between the VCM and the
> > > > sensor as on some ACPI systems the VCM is in fact relying on the power
> > > > resources of the sensor. But to do this everywhere?
> > >
> > > Same on any Raspberry Pi camera module. The VCM is powered by the same
> > > enable lines as the Sensor there I think which has made things
> > > interesting in handling VCMs for those devices.
> >
> > Yes, this has been an issue in DT for a long time. :-( I'm not sure if this
> > approach could extend into a solution for that though.
> >
> > >
> > >
> > > > VCMs traditionally have been powered through opening their sub-device node
> > > > and that hasn't been exactly neat API-wise. It has been practical still,
> > > > AFAIK, as in order to control the VCM, you have to have a sub-device node
> > > > open.
> > >
> > > This is an issue though, as libcamera opens the device nodes and holds
> > > the file descriptor when it has a camera. This means that even if the
> > > camera isn't streaming, the VCM is powered on and causes power
> > > consumption on mobile devices which people then attribute to pipewire.
> >
> > A practical fix for that could be to set the current to 0 when streaming is
> > off.
>
> For the zero-current route: lens subdevs have no s_stream, so how would the
> VCM driver learn that streaming stopped? The device link gets this from
libcamera would have to do that. I don't see why it couldn't.
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-11-27 17:33 ` Sakari Ailus
@ 2026-11-30 16:38 ` Dave Stevenson
2026-11-30 17:07 ` johannes.goede
0 siblings, 1 reply; 9+ messages in thread
From: Dave Stevenson @ 2026-11-30 16:38 UTC (permalink / raw)
To: Sakari Ailus
Cc: Cédric Bellegarde, Kieran Bingham, Mauro Carvalho Chehab,
linux-media, linux-kernel, phone-devel, Laurent Pinchart,
Hans Verkuil
Hi Sakari and others.
On Fri, 27 Nov 2026 at 17:33, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
>
> Hi Cédric,
>
> On Thu, Nov 26, 2026 at 07:23:32AM +0100, Cédric Bellegarde wrote:
> > Hello,
> >
> > Le 25/09/2026 à 13:15, Sakari Ailus a écrit :
> > > Hi Kieran,
> > >
> > > On Wed, Sep 23, 2026 at 07:58:21AM +0100, Kieran Bingham wrote:
> > > > Quoting Sakari Ailus (2026-09-23 07:34:54)
> > > > > Hi C�dric,
> > > > >
> > > > > On Tue, Sep 22, 2026 at 09:39:12PM +0200, C�dric Bellegarde wrote:
> > > > > > When a sensor's fwnode references an ancillary lens or flash device
> > > > > > (e.g. via the "lens-focus" or "flash-leds" properties),
> > > > > > v4l2_async_create_ancillary_links() already creates a media controller
> > > > > > link between the two entities, but their runtime PM states remain
> > > > > > independent.
> > > > > >
> > > > > > This is a problem for devices such as VCM lens actuators, which are
> > > > > > typically spring-loaded: holding a position away from the spring's
> > > > > > rest point requires continuous power, and the position is not retained
> > > > > > once power is cut. If such an actuator is allowed to runtime-suspend
> > > > > > independently of the sensor, the lens can drift back to its rest
> > > > > > position during an otherwise active capture session.
> > > > > >
> > > > > > Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
> > > > > > that its runtime PM state be linked to the associated sensor.
> > > > >
> > > > > Interesting idea.
> > > > >
> > > > > The IPU bridge has created such a device link between the VCM and the
> > > > > sensor as on some ACPI systems the VCM is in fact relying on the power
> > > > > resources of the sensor. But to do this everywhere?
> > > >
> > > > Same on any Raspberry Pi camera module. The VCM is powered by the same
> > > > enable lines as the Sensor there I think which has made things
> > > > interesting in handling VCMs for those devices.
> > >
> > > Yes, this has been an issue in DT for a long time. :-( I'm not sure if this
> > > approach could extend into a solution for that though.
It was a related issue that I've cheated on downstream. I added a
regulator notifier hook so that if the shared regulator is powered up
then the lens position is restored to the programmed position, so you
can capture in-focus images without worrying about the lens driver
subdev.
If only the lens driver subdev is opened then that will power up the
sensor as well, but normally it'll sit in standby mode until told to
do otherwise over I2C.
I know it's not acceptable to mainline as I'm relying on there being a
common regulator, but it was a pragmatic solution for those not using
libcamera on the Pi.
I'd not noticed that libcamera keeps the lens node open, so I guess we
will still get hit by that issue and it'll keep the regulators powered
up but the sensor in standby.
> > > >
> > > >
> > > > > VCMs traditionally have been powered through opening their sub-device node
> > > > > and that hasn't been exactly neat API-wise. It has been practical still,
> > > > > AFAIK, as in order to control the VCM, you have to have a sub-device node
> > > > > open.
> > > >
> > > > This is an issue though, as libcamera opens the device nodes and holds
> > > > the file descriptor when it has a camera. This means that even if the
> > > > camera isn't streaming, the VCM is powered on and causes power
> > > > consumption on mobile devices which people then attribute to pipewire.
> > >
> > > A practical fix for that could be to set the current to 0 when streaming is
> > > off.
> >
> > For the zero-current route: lens subdevs have no s_stream, so how would the
> > VCM driver learn that streaming stopped? The device link gets this from
>
> libcamera would have to do that. I don't see why it couldn't.
I'm going to play devil's advocate here. This is still "Video 4 Linux
2", not "Video for Libcamera 2" (I'm waiting for the proposal of a
name change).
Mandating that the use of a VCM requires using libcamera would be quite a step.
Then again it's libcamera that is keeping the lens driver open and
causing problems in the first place, so fixing it there is likely
valid.
It's worth noting that devices like DW9817 are bidirectional driver
ICs for +/-100mA drive. So the zero current V4L2_CID_FOCUS_ABSOLUTE
value would be 512 (of 0-1023) and not 0.
Is it better to add a new control to the VCM subdev that gives
userspace a device agnostic zero current power down? The driver can
then take whatever steps to adopt a minimal current state is
appropriate for the particular driver IC (probably with ramping to
avoid "ticks" as lenses hit endstops).
Dave
> --
> Regards,
>
> Sakari Ailus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-11-30 16:38 ` Dave Stevenson
@ 2026-11-30 17:07 ` johannes.goede
0 siblings, 0 replies; 9+ messages in thread
From: johannes.goede @ 2026-11-30 17:07 UTC (permalink / raw)
To: Dave Stevenson, Sakari Ailus
Cc: Cédric Bellegarde, Kieran Bingham, Mauro Carvalho Chehab,
linux-media, linux-kernel, phone-devel, Laurent Pinchart,
Hans Verkuil
Hi Dave,
On 30-Nov-26 17:38, Dave Stevenson wrote:
> Hi Sakari and others.
>
> On Fri, 27 Nov 2026 at 17:33, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
>>
>> Hi Cédric,
>>
>> On Thu, Nov 26, 2026 at 07:23:32AM +0100, Cédric Bellegarde wrote:
>>> Hello,
>>>
>>> Le 25/09/2026 à 13:15, Sakari Ailus a écrit :
>>>> Hi Kieran,
>>>>
>>>> On Wed, Sep 23, 2026 at 07:58:21AM +0100, Kieran Bingham wrote:
>>>>> Quoting Sakari Ailus (2026-09-23 07:34:54)
>>>>>> Hi C�dric,
>>>>>>
>>>>>> On Tue, Sep 22, 2026 at 09:39:12PM +0200, C�dric Bellegarde wrote:
>>>>>>> When a sensor's fwnode references an ancillary lens or flash device
>>>>>>> (e.g. via the "lens-focus" or "flash-leds" properties),
>>>>>>> v4l2_async_create_ancillary_links() already creates a media controller
>>>>>>> link between the two entities, but their runtime PM states remain
>>>>>>> independent.
>>>>>>>
>>>>>>> This is a problem for devices such as VCM lens actuators, which are
>>>>>>> typically spring-loaded: holding a position away from the spring's
>>>>>>> rest point requires continuous power, and the position is not retained
>>>>>>> once power is cut. If such an actuator is allowed to runtime-suspend
>>>>>>> independently of the sensor, the lens can drift back to its rest
>>>>>>> position during an otherwise active capture session.
>>>>>>>
>>>>>>> Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
>>>>>>> that its runtime PM state be linked to the associated sensor.
>>>>>>
>>>>>> Interesting idea.
>>>>>>
>>>>>> The IPU bridge has created such a device link between the VCM and the
>>>>>> sensor as on some ACPI systems the VCM is in fact relying on the power
>>>>>> resources of the sensor. But to do this everywhere?
>>>>>
>>>>> Same on any Raspberry Pi camera module. The VCM is powered by the same
>>>>> enable lines as the Sensor there I think which has made things
>>>>> interesting in handling VCMs for those devices.
>>>>
>>>> Yes, this has been an issue in DT for a long time. :-( I'm not sure if this
>>>> approach could extend into a solution for that though.
>
> It was a related issue that I've cheated on downstream. I added a
> regulator notifier hook so that if the shared regulator is powered up
> then the lens position is restored to the programmed position, so you
> can capture in-focus images without worrying about the lens driver
> subdev.
> If only the lens driver subdev is opened then that will power up the
> sensor as well, but normally it'll sit in standby mode until told to
> do otherwise over I2C.
>
> I know it's not acceptable to mainline as I'm relying on there being a
> common regulator, but it was a pragmatic solution for those not using
> libcamera on the Pi.
>
> I'd not noticed that libcamera keeps the lens node open, so I guess we
> will still get hit by that issue and it'll keep the regulators powered
> up but the sensor in standby.
>
>>>>>
>>>>>
>>>>>> VCMs traditionally have been powered through opening their sub-device node
>>>>>> and that hasn't been exactly neat API-wise. It has been practical still,
>>>>>> AFAIK, as in order to control the VCM, you have to have a sub-device node
>>>>>> open.
>>>>>
>>>>> This is an issue though, as libcamera opens the device nodes and holds
>>>>> the file descriptor when it has a camera. This means that even if the
>>>>> camera isn't streaming, the VCM is powered on and causes power
>>>>> consumption on mobile devices which people then attribute to pipewire.
>>>>
>>>> A practical fix for that could be to set the current to 0 when streaming is
>>>> off.
>>>
>>> For the zero-current route: lens subdevs have no s_stream, so how would the
>>> VCM driver learn that streaming stopped? The device link gets this from
>>
>> libcamera would have to do that. I don't see why it couldn't.
>
> I'm going to play devil's advocate here. This is still "Video 4 Linux
> 2", not "Video for Libcamera 2" (I'm waiting for the proposal of a
> name change).
> Mandating that the use of a VCM requires using libcamera would be quite a step.
> Then again it's libcamera that is keeping the lens driver open and
> causing problems in the first place, so fixing it there is likely
> valid.
>
> It's worth noting that devices like DW9817 are bidirectional driver
> ICs for +/-100mA drive. So the zero current V4L2_CID_FOCUS_ABSOLUTE
> value would be 512 (of 0-1023) and not 0.
> Is it better to add a new control to the VCM subdev that gives
> userspace a device agnostic zero current power down? The driver can
> then take whatever steps to adopt a minimal current state is
> appropriate for the particular driver IC (probably with ramping to
> avoid "ticks" as lenses hit endstops).
Interesting timing on your reply, I just did a top-level reply
today in this thread with what hopefully can be a solution which works
for everyone:
https://lore.kernel.org/linux-media/462ca475-5b95-4804-83b9-15e7040a9997@oss.qualcomm.com/
TL;DR: I believe that the sensor + VCM should be treated as a single
entity from a power-management pov, with all power-management controlled
by the sensor driver.
The idea being that proper sensor drivers already turn the sensor on
when streaming and off when they are done streaming and with a runtime-pm
link we can simply make the runtime-pm framework turn on the VCM when
ever the sensor runtime-resumes.
See my reply for some more details.
Regards,
Hans
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's
2026-09-22 19:39 [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's Cédric Bellegarde
2026-09-23 6:34 ` Sakari Ailus
@ 2026-11-30 14:42 ` Hans de Goede
1 sibling, 0 replies; 9+ messages in thread
From: Hans de Goede @ 2026-11-30 14:42 UTC (permalink / raw)
To: Cédric Bellegarde, Sakari Ailus, Mauro Carvalho Chehab,
kieran.bingham
Cc: linux-media, linux-kernel, phone-devel, libcamera devel
Hi,
On 22-Sep-26 21:39, Cédric Bellegarde wrote:
> When a sensor's fwnode references an ancillary lens or flash device
> (e.g. via the "lens-focus" or "flash-leds" properties),
> v4l2_async_create_ancillary_links() already creates a media controller
> link between the two entities, but their runtime PM states remain
> independent.
>
> This is a problem for devices such as VCM lens actuators, which are
> typically spring-loaded: holding a position away from the spring's
> rest point requires continuous power, and the position is not retained
> once power is cut. If such an actuator is allowed to runtime-suspend
> independently of the sensor, the lens can drift back to its rest
> position during an otherwise active capture session.
In my experience at the moment we actually mostly have the reverse problem,
on x86_64 devices a runtime-pm link is created from the VCM device
to the sensor device, because they are both powered on through the ACPI
power-on sequences from the sensor.
And VCM drivers power-on the VCM as soon as the /dev/v4l-subdev# device
for the VCM is opened, which now also powers the sensor on leading to
undesirable power-consumption especially since libcamera typically opens
all v4l-subdev# devices as soon as a libcamera context is created which
e.g. pipewire does.
I do like this patch though since I think it can solve all of the above
problems in one go.
What we are seeing on x86 at least is that camera-modules are designed
with regulators, but also e.g. power-down / reset pins shared between
sensor and VCM, assuming that the sensor + vcm are always powered on/off
together.
And sensors are already powered-on only when streaming (vs the VCM
drivers powering them on as soon as the /dev/v4l-subdev# device is open).
So what I think we should do is:
1. Add this patch to always automatically power-up the VCM when a sensor
powers up (so when streaming for proper sensor drivers)
2. Drop the runtime_pm_get() and put() calls from the open()/close()
v4l2_subdev_internal_ops for VCM devices so that they no longer are
always on as soon as userspace has the /dev/v4l-subdev# VCM node open.
This also requires no longer probing / powering up during probe() as
this will fail when patch 3 is added into the mix.
3. Drop the runtime-pm link added by drivers/media/pci/intel/ipu-bridge.c,
removing:
device_link_add(&vcm_client->dev, data->sensor, DL_FLAG_PM_RUNTIME);
which is in essence the same link from this patch in the other direction.
Note:
3a) This needs to be last to avoid regressions.
3b) Maybe we should not drop this, avoiding the need for changes to
probe() in VCM drivers. Although IMHO just delaying the VCM detect
code till first power-on would be better.
Assuming we can all agree as the way forward to solve the power-management
issues surrounding VCM devices then a series implementing this would be very
welcome!
Regards,
Hans
> Add V4L2_SUBDEV_FL_PM_LINK to allow an ancillary subdevice to request
> that its runtime PM state be linked to the associated sensor.
>
> Signed-off-by: Cédric Bellegarde <cedric.bellegarde@adishatz.org>
> ---
> Link runtime PM of ancillary devices such as lens actuators to their associated sensor,
> while allowing actuators to autosuspend when idle.
>
> Example usage:
> https://gitlab.com/gnumdk/linux/-/commit/82b2d71415a1d95b2170e19ce025afc8bbdcf145
> ---
> drivers/media/v4l2-core/v4l2-async.c | 18 ++++++++++++++----
> include/media/v4l2-subdev.h | 7 +++++++
> 2 files changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> index 460bf3dbbb88..22df627153b8 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -318,6 +318,7 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> {
> #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> struct media_link *link;
> + struct device_link *devlink;
>
> if (sd->entity.function != MEDIA_ENT_F_LENS &&
> sd->entity.function != MEDIA_ENT_F_FLASH)
> @@ -331,11 +332,20 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> }
>
> link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
> -
> - return IS_ERR(link) ? PTR_ERR(link) : 0;
> -#else
> - return 0;
> + if (IS_ERR(link))
> + return PTR_ERR(link);
> +
> + if (sd->flags & V4L2_SUBDEV_FL_PM_LINK) {
> + devlink = device_link_add(n->sd->dev, sd->dev,
> + DL_FLAG_PM_RUNTIME |
> + DL_FLAG_AUTOREMOVE_CONSUMER);
> + if (!devlink)
> + dev_warn(notifier_dev(n),
> + "failed to link power management of %s to %s\n",
> + dev_name(sd->dev), dev_name(n->sd->dev));
> + }
> #endif
> + return 0;
> }
>
> static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index d256b7ec8f84..9f64b10afd10 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -972,6 +972,13 @@ struct v4l2_subdev_internal_ops {
> * - Multiple streams per pad are supported
> */
> #define V4L2_SUBDEV_FL_STREAMS (1U << 4)
> +/*
> + * Set this flag to keep the subdevice active while its associated sensor is active.
> + *
> + * This is intended for ancillary devices, such as lens actuators, whose
> + * hardware state or physical position cannot be retained while powered off.
> + */
> +#define V4L2_SUBDEV_FL_PM_LINK (1U << 5)
>
> struct regulator_bulk_data;
>
>
> ---
> base-commit: df2908090cda368b01ff43709f51890076c56157
> change-id: 20260911-sensors_pm-787eac01aa18
>
> Best regards,
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-30 17:07 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-22 19:39 [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's Cédric Bellegarde
2026-09-23 6:34 ` Sakari Ailus
2026-09-23 6:58 ` Kieran Bingham
2026-09-25 11:15 ` Sakari Ailus
2026-11-26 6:23 ` Cédric Bellegarde
2026-11-27 17:33 ` Sakari Ailus
2026-11-30 16:38 ` Dave Stevenson
2026-11-30 17:07 ` johannes.goede
2026-11-30 14:42 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®