From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796315184; b=TOelsleSml5mTPeK8p4L8Gok8MYybSR6GMiyZPCM4JlcljtVJk3ErkhKbl/jrtAKrmYn NIqA4aSiiCp8WkLkASNTeCF4M/dUh1/2HJzs2WXToRVSOBtwNJR/OiiWksAReEqB5lHqZ DbXdtM5lqFVi2IjnQk9Cqzoc/ywfCOKciX38fo+3hJAX/NoVKRhQqAmfus84qo0H6/4Up gCcJLW45/Tc+V0zsYLQPE0M77PV/TkNCPfL85n7Fuw1JYbVAzAPXgciPMc/9bOOlrh9pT caB5AWSUFolWG8+0BQEYJQ/ahTxIKyNZjQB4+J30h3YrrO5WVoqr5zpTqTFUku8Vwdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796315184; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:From:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=nqCsgu0ttPRXiyrxwazsxC7njyOPw2j/ea+wyUSmnQY=; b=R93layGrOGYyPxH0dpcT9kH73VSIWHmuEzSL7HURIrveVG4cjBXfsEcY7mGyzkmIoT9+ zRD3qXDj5GSTvScysdnYYyAOuya2fY+k3nrZxWT/X8UZg/MTLkVufe9mW9QoasVPD8Qql ysSAtZxapcyl6pscSb2Dg3GtbjAYzXYL05dBOWQt6lveu6QwCPF52NToOYlGeQ0A+wAn4 zR+KktLZus0hf9yDZbaPrxsNuuROX1r77g+Kc7E4Qe5dHgSezHkQuz8Okkt3ih5isiJ2W a5bmiPI/+ciCAYh2fatakVWEwYgwyA/j9OVP2esWPcMzGmmPXXZTHDtd49w8HRpPMbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OvFi9Esy; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=LOztxdUs; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE14D606A332 for ; Thu, 3 Dec 2026 16:26:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE14D606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OvFi9Esy; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=LOztxdUs Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B3FmL4G531608 for ; Thu, 3 Dec 2026 16:26:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= nqCsgu0ttPRXiyrxwazsxC7njyOPw2j/ea+wyUSmnQY=; b=OvFi9Esyqy8J5t8Y Dy6SDiZJTYfZ5pofKTd19xlVxjc/S1T3JWlvEaZb2T6zTLfj/FqShUTlMwueG1E2 W4HCN1GuAACU3EjCj6QzwFt9bQz5UWvidX/JLbQ2rxVmZa0r4fmDr7aW3Z3BwGSx qzqGSOwAnrzJozxQhcSB+DrDmlHYGsSN55D1PCvWLZjoLczGSrXmFgBqseoAJsgO ludW1eT370cmB9c7aTywtLeTwV1nW7+SW9dz5bUJXLgrzBI0RbgH+35GWntU9TSB M+cQK06fh4PtxVm4/N1Nr2TP+ZTVUdKlrszByl+5pYeJFLiadEkm+wKFpncfnjH1 xWx85Q== Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4jb395jj03-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 03 Dec 2026 16:26:23 +0000 (GMT) Received: by mail-ua1-f71.google.com with SMTP id a1e0cc1a2514c-97e8be2221eso2322426241.2 for ; Thu, 03 Dec 2026 08:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796315182; x=1796919982; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=nqCsgu0ttPRXiyrxwazsxC7njyOPw2j/ea+wyUSmnQY=; b=LOztxdUsFnB6EJuoIzZwsz4DBu+CR40x2ujLB5XvtfZ5GuaOBndFb9azQqKK72CZil WfAGnKZ0gtL9D7F1KV1xKFxnpLZdR5f0Bagm1onN9L3J153Oj8tOHPEF4sJ8bG9v43hB YmVx8nbFbSHtLhM5q1O614Q9oTm1uiBuLXYw1Wb8KLicBi5NTKKy3RURm2n+RHfPryPi /rX3lAZOT8fx31N1dKWlSSf/zxkG2dtpRRmGi3lmJEp7VtROACJhGQyEL2v0WYGHnWrv ScvwegOP6zJ0OjjsKmQuLzI23nB/0MF2vYKobV+Z3zYfqLa+m3+z3au4QpARnMl6tTN3 9f/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796315182; x=1796919982; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nqCsgu0ttPRXiyrxwazsxC7njyOPw2j/ea+wyUSmnQY=; b=N82aTk6oDM4pMNTzFAOQkmNmd9UbvmMpRyRDTwNYn99Biz8T/ZtPGjuDpz04f92LeX TV6OMbZ9/S3iBSMEPolftN2eE6HdyTBPF1W+RanM+oPcGIo/6SvLEkLGsxwIwQw6hLhF vV+yJ2m1HSpTp4Xk/G6UNKwtNXw1Uowt/uIcKyauHLlJ05NFP0YsFhZyl1MOlMtOLdEV eyfG7QciNn6ikO+I9gQfN08D0H64OZ0u2XDaor6zv4UQqPe1c0JIOzuOFjus/JoTGfnO lA2atqIQBEcGANuBFR/SKzkqktwnwT9h5zblsoklB05RuXSJ4jZlfFlY5dGZ9FvP3saI OezQ== X-Forwarded-Encrypted: i=1; AL+hErEM3Verx9IAouvraUymTbfJovRBjwV88LZdsCO/2hwW3ABd7Q7rFxCsU1q4Ca+C32hNEEcD8gJyMMroEkI=@vger.kernel.org X-Gm-Message-State: APuU4Z/lkWGISioDCwlCunYNwnqo+HkX65otz7qJL2omgcWcpZL+cm4A tYhmHDmDTB0YHgschWaGG8Ik6SkWZR/xJafY+sk7JdES+G7w83CqgyAzegwzMnQ5fD5YvbDLxwC zFd2fciOFMasx2apTNIvTVegQhIg5qEGisunc/l1TuYy+ylRe4rYUqQxpkJ5dXafYjds= X-Gm-Gg: AZFdTZcYw5RCP+ScukPZvFtlyc2jxE6X4OwHL+1mH1dwMJftXVMx29aFnvKjSXXpTog oHIAG1pDuiY5YnpwS/yLIQoV7Rbe/YazeBqho/L4E5XFJcW0R0GdP/zFnI9XGd4KYp6/N4opQBy E/D7HbHhJjj8EKCC8Uj7fHgWc2nf/ECRsoYaP5rtxKHfR4BKfmG1a7CLKHwVrnOX1eJ3ONikdzF +/Z5aa5Mg4F1yIh5oAZsSkbERhiZtztcMU2M84ytU6EdMC1Xs/wyXTFSMkClEXTlfa+sPiS+FfP tjk/h7UHz3CeBIQ/5FVg8016rT9Lp/FTfXDbeSnFa7pICIpjOWH+Q1WfPXo9oJ3ntge1C3lkJP0 pANFF8PmnYuBCbHJ1t1cgJdEpvWOEHO77H5jCtveIYnzGdmBklyUtI0zckJkN1cdDHpUVBtjOht y/FuKPqH24GH4ePouaOqgB3oCJu/b1j+YH67MAZR/3YtLewH9BRYPWc0+xtzYzvAvimrPzktn8i Z18KquPyF43mBdK1dtF61KAYCKnugU6zxcr3Sy0TUs= X-Received: by 2002:a05:6102:290c:b0:779:5049:87b2 with SMTP id ada2fe7eead31-7d71e348050mr28930472137.0.1796315181212; Thu, 03 Dec 2026 08:26:21 -0800 (PST) X-Received: by 2002:a05:6102:290c:b0:779:5049:87b2 with SMTP id ada2fe7eead31-7d71e348050mr28930417137.0.1796315180505; Thu, 03 Dec 2026 08:26:20 -0800 (PST) Received: from ?IPV6:2001:1c00:c07:4900:cedc:3657:d7f1:7571? (2001-1c00-0c07-4900-cedc-3657-d7f1-7571.cable.dynamic.v6.ziggo.nl. [2001:1c00:c07:4900:cedc:3657:d7f1:7571]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b2b92b1sm1589666b.6.2026.12.03.08.26.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 08:26:19 -0800 (PST) Message-ID: <22ff0499-1427-4d2e-8326-4d30262773d4@oss.qualcomm.com> Date: Thu, 3 Dec 2026 17:26:18 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] media: v4l2-async: link ancillary device runtime PM to the sensor's From: Hans de Goede To: =?UTF-8?Q?C=C3=A9dric_Bellegarde?= , Sakari Ailus , Mauro Carvalho Chehab , kieran.bingham@ideasonboard.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, libcamera devel References: <20260922-sensors_pm-v1-1-05adf2098b5e@adishatz.org> <462ca475-5b95-4804-83b9-15e7040a9997@oss.qualcomm.com> Content-Language: en-US, nl In-Reply-To: <462ca475-5b95-4804-83b9-15e7040a9997@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=DK8acCNb c=1 sm=1 tr=0 ts=6b11982f cx=c_pps a=KB4UBwrhAZV1kjiGHFQexw==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=VwQbUJbxAAAA:8 a=20KFwNOVAAAA:8 a=p0WdMEafAAAA:8 a=LCWlJkpBAAAA:8 a=6YWaI9_3j2N-BHR1yH8A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=o1xkdb1NAhiiM49bd1HK:22 a=z1lahxahPt366DkPXCx7:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAzMDA2NSBTYWx0ZWRfX1tWqj89uz2/z WRv43JGKCogCZoEfRhssRlW8KtA4ukJyYHWZBtRl+xqPF/cuB39YCd2bHUyrwEPRKpgL9yDO5o8 avIkhg+qCHuZDsAfFxceKYxA0wD55noarV2zKChUdnOEiHhKPHbrAsNslTBsM73/ujXHWbMD3+k 9U/68u+uuUqN+9CkjkfbCKr0k5a4NV5C/La372H5jI3jj7jvQZ+N0hYKVnZxgXkaesX9dB2Afyn yf/vdiAkuClT8y1XpcdA0tweQ/wTjxLL70KhQw8Kkw+1SBH4sd6q9qfd8Z0JDxEsy3u/nP7w2sm uS6kC+uVi2tTIQT1Ev5t9RGatIbnUznB6Xux+VtnF1OwDDqe/0Xo+FFmZtmb2CS908A+XeIcZta muB1nznvGph/x6ONGfvFCgHU/9T7elPuSDFoJqzroyAmvF/iAOREZRLTYykountZo4Sw6tpbkCQ qbIlx6cWiQdVAxkGLgQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAzMDA2NSBTYWx0ZWRfX4vMPnDgzqF+O oIEw6LsHMpnF/YhMf+uAYvgfEUgSJySaiEa7755weTAUd6A0YgrPfz1phT3We16X9mVvLYzLl9/ AlLEYvHrU6lDGjCyl9SL62JBem+M/NA= X-Proofpoint-ORIG-GUID: 9PkayEpEl41k0p3OgHYqJY0jOuPwraVI X-Proofpoint-GUID: 9PkayEpEl41k0p3OgHYqJY0jOuPwraVI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-03_04,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 suspectscore=0 adultscore=0 phishscore=0 clxscore=1015 spamscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612030065 Hi, On 30-Nov-26 15:42, Hans de Goede wrote: > 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! Ok, so thinking more about this I'm afraid that this is not going to work. The problem is that on x86 the sensor must be powered-up *first* since some of the rails, etc. are only described on the sensor side. So the existing runtime-pm link from VCM to sensor on x86 is correct. But we do want to get rid of the auto power-on on /dev/v4l-subdev open and instead only power-on together with the sensor, but *after* the sensor's runtime-resume method has run. So what I think we should do is resurrect this patch-set from me: https://lore.kernel.org/linux-media/202409a01211834.145186-1-hdegoede@redhat.com/ One of the objections against that one was (ab)using the s_stream() API: ".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." The other objection was about the design of it. But based on the libcamera softISP from last week where there seemed to be consensus that powering the sensor and VCM on together is what we want since the hw is often designed with that in mind and powering on only 1 of the 2 often leads to problems like the unpowered device blocking the i2c bus. So my plan is to write + submit a new version of the linked patch, but then use pm_runtime_resume_and_get() on the VCM's v4l2_subdev.dev instead of s_stream(). As suggested by Sakari in his review of the linked patch. Combined with a suitable autosuspend delay on VCM drivers opting in to this behavior so that the VCM does not turn off + on again on a quick stream stop + start to change the sensor mode. Regards, Hans p.s. We could go further then this and make the v4l2-core also do the pm_runtime_resume_and_get() for the sensor itself on stream-on this way we can runtime-resume both before doing any I2C transfers, which is really what we want because of the 2 being so tightly coupled. And also moving the runtime-pm management into the core instead of having every sensor driver do this itself on stream on seems to make sense to me. > > > > > >> 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 >> --- >> 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, >