From patchwork Wed Nov 15 18:18:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 744007 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="frqu3lkc" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F58E1A3; Wed, 15 Nov 2023 10:18:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700072334; x=1731608334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/V+4a6YBThcc56i41tofczUJdxwhFYsIxlS5sBR3VII=; b=frqu3lkcWZ2MFDbp/hKQ0TANfH5WsBbqJgk+qZWxRde1RJ/jhSr/JZoa 4g5cjUztuo28zuZ24XjJ3eoMebCcFVAsOVuOb/wt+xJkXOxmAatrpFq4R HfoH3S3PAqbXsOs1z18vfwGh/GkjimiTURU/Xcbisqfi8Cu9NTZ5oau9a JV2MLy7dTugqIBFkXHW7mRg6ndfi9Oi3MS/1AbbnTzBAE/mBvXvxK3/HA veseXbrnGQCvZs7QPV+uWTN33arBf8jQtPCdbzoqo55PqDltStjHg9cQL SSD84XJgGBxAgtAk0hDflHr0LCyzZC1G96uo+fsS/V62d1sP02f+tBD8r g==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="381321123" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="381321123" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="831014655" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="831014655" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:44 -0800 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 68ACD11FBD1; Wed, 15 Nov 2023 20:18:41 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, jacopo.mondi@ideasonboard.com, laurent.pinchart@ideasonboard.com Subject: [PATCH 1/6] pm: runtime: Simplify pm_runtime_get_if_active() usage Date: Wed, 15 Nov 2023 20:18:35 +0200 Message-Id: <20231115181840.1509046-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> References: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The majority of the callers currently using pm_runtime_get_if_active() call it with ign_usage_count argument set to true. There's only one driver using this feature (and natually implementation of pm_runtime_get_if_in_use()). To make this function more practical to use, remove the ign_usage_count argument from the function. The main implementation is renamed as __pm_runtime_get_conditional(). This function is expected to gain a large number of users in the future --- camera sensor drivers using runtime autosuspend have a need to get the device's usage_count conditionally if it is enabled. Most of these currently use pm_runtime_get_if_in_use(), which is a bug. Signed-off-by: Sakari Ailus --- Documentation/power/runtime_pm.rst | 5 ++-- drivers/base/power/runtime.c | 9 ++++--- drivers/gpu/drm/i915/intel_runtime_pm.c | 2 +- drivers/media/i2c/ccs/ccs-core.c | 2 +- drivers/net/ipa/ipa_smp2p.c | 2 +- drivers/pci/pci.c | 2 +- include/linux/pm_runtime.h | 31 +++++++++++++++++++++---- sound/hda/hdac_device.c | 2 +- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst index 65b86e487afe..da99379071a4 100644 --- a/Documentation/power/runtime_pm.rst +++ b/Documentation/power/runtime_pm.rst @@ -396,10 +396,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: nonzero, increment the counter and return 1; otherwise return 0 without changing the counter - `int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count);` + `int pm_runtime_get_if_active(struct device *dev);` - return -EINVAL if 'power.disable_depth' is nonzero; otherwise, if the - runtime PM status is RPM_ACTIVE, and either ign_usage_count is true - or the device's usage_count is non-zero, increment the counter and + runtime PM status is RPM_ACTIVE, increment the counter and return 1; otherwise return 0 without changing the counter `void pm_runtime_put_noidle(struct device *dev);` diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 4545669cb973..8b56468eca9d 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1175,7 +1175,7 @@ int __pm_runtime_resume(struct device *dev, int rpmflags) EXPORT_SYMBOL_GPL(__pm_runtime_resume); /** - * pm_runtime_get_if_active - Conditionally bump up device usage counter. + * __pm_runtime_get_conditional - Conditionally bump up device usage counter. * @dev: Device to handle. * @ign_usage_count: Whether or not to look at the current usage counter value. * @@ -1195,8 +1195,11 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume); * * The caller is responsible for decrementing the runtime PM usage counter of * @dev after this function has returned a positive value for it. + * + * This function is not intended to be called by drivers, use + * pm_runtime_get_if_active() or pm_runtime_get_if_in_use() instead. */ -int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count) +int __pm_runtime_get_conditional(struct device *dev, bool ign_usage_count) { unsigned long flags; int retval; @@ -1217,7 +1220,7 @@ int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count) return retval; } -EXPORT_SYMBOL_GPL(pm_runtime_get_if_active); +EXPORT_SYMBOL_GPL(__pm_runtime_get_conditional); /** * __pm_runtime_set_status - Set runtime PM status of a device. diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c index 6d8e5e5c0cba..b163efe80975 100644 --- a/drivers/gpu/drm/i915/intel_runtime_pm.c +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c @@ -434,7 +434,7 @@ static intel_wakeref_t __intel_runtime_pm_get_if_active(struct intel_runtime_pm * function, since the power state is undefined. This applies * atm to the late/early system suspend/resume handlers. */ - if (pm_runtime_get_if_active(rpm->kdev, ignore_usecount) <= 0) + if (__pm_runtime_get_conditional(rpm->kdev, ignore_usecount) <= 0) return 0; } diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c index 12e6f0a26fc8..45701a18c845 100644 --- a/drivers/media/i2c/ccs/ccs-core.c +++ b/drivers/media/i2c/ccs/ccs-core.c @@ -664,7 +664,7 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl) break; } - pm_status = pm_runtime_get_if_active(&client->dev, true); + pm_status = pm_runtime_get_if_active(&client->dev); if (!pm_status) return 0; diff --git a/drivers/net/ipa/ipa_smp2p.c b/drivers/net/ipa/ipa_smp2p.c index 5620dc271fac..cbf3d4761ce3 100644 --- a/drivers/net/ipa/ipa_smp2p.c +++ b/drivers/net/ipa/ipa_smp2p.c @@ -92,7 +92,7 @@ static void ipa_smp2p_notify(struct ipa_smp2p *smp2p) return; dev = &smp2p->ipa->pdev->dev; - smp2p->power_on = pm_runtime_get_if_active(dev, true) > 0; + smp2p->power_on = pm_runtime_get_if_active(dev) > 0; /* Signal whether the IPA power is enabled */ mask = BIT(smp2p->enabled_bit); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 59c01d68c6d5..d8d4abbc936f 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2439,7 +2439,7 @@ static void pci_pme_list_scan(struct work_struct *work) * If the device is in a low power state it * should not be polled either. */ - pm_status = pm_runtime_get_if_active(dev, true); + pm_status = pm_runtime_get_if_active(dev); if (!pm_status) continue; diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 7c9b35448563..810330bb802b 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -72,7 +72,8 @@ extern int pm_runtime_force_resume(struct device *dev); extern int __pm_runtime_idle(struct device *dev, int rpmflags); extern int __pm_runtime_suspend(struct device *dev, int rpmflags); extern int __pm_runtime_resume(struct device *dev, int rpmflags); -extern int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count); +extern int __pm_runtime_get_conditional(struct device *dev, + bool ign_usage_count); extern int pm_schedule_suspend(struct device *dev, unsigned int delay); extern int __pm_runtime_set_status(struct device *dev, unsigned int status); extern int pm_runtime_barrier(struct device *dev); @@ -94,16 +95,33 @@ extern void pm_runtime_release_supplier(struct device_link *link); extern int devm_pm_runtime_enable(struct device *dev); +/** + * pm_runtime_get_if_active - Bump up runtime PM usage counter if the device is + * in active state + * @dev: Target device. + * + * Increment the runtime PM usage counter of @dev if its runtime PM status is + * %RPM_ACTIVE, in which case it returns 1. If the device is in a different + * state, 0 is returned. -EINVAL is returned if runtime PM is disabled for the + * device. + */ +static inline int pm_runtime_get_if_active(struct device *dev) +{ + return __pm_runtime_get_conditional(dev, true); +} + /** * pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter. * @dev: Target device. * * Increment the runtime PM usage counter of @dev if its runtime PM status is - * %RPM_ACTIVE and its runtime PM usage counter is greater than 0. + * %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case + * it returns 1. If the device is in a different state or its usage_count is 0, + * 0 is returned. -EINVAL is returned if runtime PM is disabled for the device. */ static inline int pm_runtime_get_if_in_use(struct device *dev) { - return pm_runtime_get_if_active(dev, false); + return __pm_runtime_get_conditional(dev, false); } /** @@ -275,8 +293,11 @@ static inline int pm_runtime_get_if_in_use(struct device *dev) { return -EINVAL; } -static inline int pm_runtime_get_if_active(struct device *dev, - bool ign_usage_count) +static inline int pm_runtime_get_if_active(struct device *dev) +{ + return -EINVAL; +} +static inline int __pm_runtime_get_conditional(struct device *dev) { return -EINVAL; } diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index bbf7bcdb449a..0a9223c18d77 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -611,7 +611,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_power_up_pm); int snd_hdac_keep_power_up(struct hdac_device *codec) { if (!atomic_inc_not_zero(&codec->in_pm)) { - int ret = pm_runtime_get_if_active(&codec->dev, true); + int ret = pm_runtime_get_if_active(&codec->dev); if (!ret) return -1; if (ret < 0) From patchwork Wed Nov 15 18:18:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 744010 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cVoilLmq" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F01B18B; Wed, 15 Nov 2023 10:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700072332; x=1731608332; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xqZXn0Yxfn3Sk9v5JbBgGwiaA3KD1uEzo/vK6o/D7T4=; b=cVoilLmq9JtRoNN65FWqBi03qlDXixKbmsFd4kNT4BjXEGLscPtWCZ2a E6HwFGiJUA6XraBHp6n5HgoeYkToJqXAwNJSBeR2bQNTM4N1mJwbHWLup AVZJK2K7sOM2t/2WKLu2BRWsgjLOK9BAy+Sm8zvX1hsr37jZd5n3v2vjg iHi7FozsekIQBbFz6kCzzOdW5RDlNFucGfDyVv+LFK4tnQM+4TpWwgdNR 5iQx/Ht/CNSxwAB9JZljTGkv4CFpqtSh/e6XmOLj00y6WNoZfeQYG2p3C W7TxekjwZx8lW9Yxj1Lx1TBcLbWC4XfkLfSpd4XX0FB01ulzhg+oOuadh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="381321128" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="381321128" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="831014657" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="831014657" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:45 -0800 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 5DA5411FC11; Wed, 15 Nov 2023 20:18:42 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, jacopo.mondi@ideasonboard.com, laurent.pinchart@ideasonboard.com Subject: [PATCH 2/6] pm: runtime: Add pm_runtime_put_mark_busy_autosusp() helper Date: Wed, 15 Nov 2023 20:18:36 +0200 Message-Id: <20231115181840.1509046-3-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> References: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add pm_runtime_put_mark_busy_autosusp() helper function for users that wish to set the last_busy timestamp to current time and put the usage_count of the device and set the autosuspend timer. Essentially calling pm_runtime_suspend_mark_busy_autosusp() equal to calling first pm_runtime_mark_last_busy() and then pm_runtime_put_autosuspend(). Signed-off-by: Sakari Ailus --- include/linux/pm_runtime.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 810330bb802b..59871ab1532a 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -494,6 +494,23 @@ static inline int pm_runtime_put_autosuspend(struct device *dev) RPM_GET_PUT | RPM_ASYNC | RPM_AUTO); } +/** + * pm_runtime_put_mark_busy_autosusp - Update the last access time of a device + * and drop device usage counter and queue + * autosuspend if 0. + * @dev: Target device. + * + * Update the last access time of @dev using pm_runtime_mark_last_busy(), then + * decrement the runtime PM usage counter of @dev and if it turns out to be + * equal to 0, queue up a work item for @dev like in pm_request_autosuspend(). + */ +static inline int pm_runtime_put_mark_busy_autosusp(struct device *dev) +{ + pm_runtime_mark_last_busy(dev); + + return pm_runtime_autosuspend(dev); +} + /** * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0. * @dev: Target device. From patchwork Wed Nov 15 18:18:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 744462 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LGh9doLm" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CF621A4; Wed, 15 Nov 2023 10:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700072335; x=1731608335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RaEMyiauU/9JpJO6Nmz7wbzZ0ghxj71bUy55K9W8zM8=; b=LGh9doLmDrGQoqpU1Tjy3amxBVYGW7rNucEJwkB7wJcwlCL4cCLVYtD2 ceEMydN3i7ZWKoy0ek06FkYd9wfG9SyNAliNv372ZuPg5C9rj9FykI99K cNyAQKMmkgG40us8QQK93NWay9vjeITQz9CM/8IFcohk8rq67g4mIx+q3 EzxffiBDyjDZS1rfNJPiMFNiU21Y9lonrLtfrZxQHlfMkugAo7ArFikm/ KkDsFlszNrcpogtNaQBoIfxdVGdUERXuNRX801+M2e0K6cpuiUHcsak5O olJAd+TpwDcf816JSxeNpDmboI9Mms6HJgzpZO9QocviMXP/CMICdvMAB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="381321134" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="381321134" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="831014660" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="831014660" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:45 -0800 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 2B22A12022F; Wed, 15 Nov 2023 20:18:43 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, jacopo.mondi@ideasonboard.com, laurent.pinchart@ideasonboard.com Subject: [PATCH 3/6] media: Documentation: Improve camera sensor runtime PM documentation Date: Wed, 15 Nov 2023 20:18:37 +0200 Message-Id: <20231115181840.1509046-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> References: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Endorse the use of pm_runtime_get_sync() in order to resume the device and pm_runtime_get_if_active() to increment its usage_count if the device is in RPM_ACTIVE state. Signed-off-by: Sakari Ailus --- .../driver-api/media/camera-sensor.rst | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Documentation/driver-api/media/camera-sensor.rst b/Documentation/driver-api/media/camera-sensor.rst index 6456145f96ed..a15c09f8347e 100644 --- a/Documentation/driver-api/media/camera-sensor.rst +++ b/Documentation/driver-api/media/camera-sensor.rst @@ -67,11 +67,23 @@ system resources required to power the sensor up and down. For drivers that don't use any of those resources (such as drivers that support ACPI systems only), the runtime PM handlers may be left unimplemented. -In general, the device shall be powered on at least when its registers are -being accessed and when it is streaming. Drivers should use -``pm_runtime_resume_and_get()`` when starting streaming and -``pm_runtime_put()`` or ``pm_runtime_put_autosuspend()`` when stopping -streaming. They may power the device up at probe time (for example to read +In general, the device shall be powered on at least when its registers are being +accessed and when it is streaming. Drivers not using autosuspend should use +:c:func:`pm_runtime_resume_and_get()` to ensure the device is powered on. The +function increments Runtime PM usage_count which the driver is responsible for +decrementing using e.g. :c:func:`pm_runtime_put()` in order to power off the +device. Drivers using autosuspend in order to avoid needless powering the sensor +off and on again, should use :c:func:`pm_runtime_get_sync()` and +:c:func:`pm_runtime_put_mark_busy_autosusp()` respectively. Note that runtime PM +usage_count of the device must be put even if :c:func:`pm_runtime_get_sync()` +fails. :c:func:`pm_runtime_get_sync()` returns 1 if the device was already +powered on. + +Drivers that support Devicetree shall also power on the device explicitly in +driver's probe() function and power the device off in driver's remove() function +without relying on Runtime PM. + +Drivers may power the device up at probe time (for example to read identification registers), but should not keep it powered unconditionally after probe. @@ -103,11 +115,13 @@ of the device. This is because the power state of the device is only changed after the power state transition has taken place. The ``s_ctrl`` callback can be used to obtain device's power state after the power state transition: -.. c:function:: int pm_runtime_get_if_in_use(struct device *dev); +.. c:function:: int pm_runtime_get_if_active(struct device *dev); The function returns a non-zero value if it succeeded getting the power count or runtime PM was disabled, in either of which cases the driver may proceed to -access the device. +access the device. Note that the device's usage_count is not incremented if the +function returns an error, in which case the usage_count also must not be put +using pm_runtime_put() or its variants. Rotation, orientation and flipping ---------------------------------- From patchwork Wed Nov 15 18:18:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 744009 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NXfXKfkN" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF961A8; Wed, 15 Nov 2023 10:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700072335; x=1731608335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A9/YvkwCnHZnNCqK8j9jReosCqqZSDqKlSJZVgPOZyA=; b=NXfXKfkNO/YtySFtz44GhxGNhNfXno/ZGT/2i6GEw/5K+Br/XsE0yPlp wKS476bZRGQV+UmXmz5zynQfhnfGcsWz/wRoSFfxsTQIiOBsMtYebEtLv Ioa3POwJijSgLAN+9++DgSIoTCcVGJQVU2LYSBrtHcLC80AXEaufBiaAd 5Q7rQOOZiKdnuBebBKo3gO1vez3s/eQ4p/ixAAJVYgDwyhVfdMfmTfTMn wPw0IG0ENms4nnSTdMwh3QDJQfBEilIsW37PGk21nUzHPFY0qIyxj21Oh 0dW24qgcGWlgHIUOoTRx/6fKRGmlQ5QJNR7U+6oQqepeFZgXV6AH2ReMr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="381321142" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="381321142" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="831014661" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="831014661" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:46 -0800 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 285D01202AB; Wed, 15 Nov 2023 20:18:44 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, jacopo.mondi@ideasonboard.com, laurent.pinchart@ideasonboard.com Subject: [PATCH 4/6] media: ov8858: Use pm_runtime_get_if_active(), put usage_count correctly Date: Wed, 15 Nov 2023 20:18:38 +0200 Message-Id: <20231115181840.1509046-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> References: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use pm_runtime_get_if_active() to get the device's runtime PM usage_count and set controls, then use runtime PM autosuspend once the controls have been set (instead of likely transitioning to suspended state immediately). Signed-off-by: Sakari Ailus --- drivers/media/i2c/ov8858.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c index 3af6125a2eee..a99b91700a8d 100644 --- a/drivers/media/i2c/ov8858.c +++ b/drivers/media/i2c/ov8858.c @@ -1538,7 +1538,7 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl) struct v4l2_subdev_state *state; u16 digi_gain; s64 max_exp; - int ret; + int ret, pm_status; /* * The control handler and the subdev state use the same mutex and the @@ -1561,7 +1561,8 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl) break; } - if (!pm_runtime_get_if_in_use(&client->dev)) + pm_status = pm_runtime_get_if_active(&client->dev); + if (!pm_status) return 0; switch (ctrl->id) { @@ -1601,7 +1602,8 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl) break; } - pm_runtime_put(&client->dev); + if (pm_status > 0) + pm_runtime_mark_busy_autosusp(&client->dev); return ret; } From patchwork Wed Nov 15 18:18:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 744008 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N4eGbtHr" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F43A18B; Wed, 15 Nov 2023 10:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700072336; x=1731608336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BHZ3rQCBwZttLGzPJ5NDl4vbRktavRob3om7tj6BWeQ=; b=N4eGbtHr8hDfMhAOoIc+ggUi/gfPxjgEsS0ZeOBIAucceYFmi+PaGX5f qYsvT3cIMMJZRITz4MUtwRTNrXtxltoIaEfir2pVRhfNqoYfL8xoX3y/l Ue2cyCeqSqb80rlS81m5X0BeFYPjXqwRHSVOKKIS2UOoNNBkC6X6Fhply hRt7a+B9G6RzbFUWhQtOweUBxvYSGq7iHhxg/ZOAGyvWJeOTVQoXrlUuI OTSGAKe0f2Bvhv2fveq/52qyeqH15RQYmldFleSDSXUSNUoRc/rdo/YEk B8ikFnHj6m2Id++Yvq3XTHg5ciuj4PI7N3kWvUpoRUEaDxD1MYFNjNVoW g==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="381321150" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="381321150" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="831014664" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="831014664" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:48 -0800 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 079D0120AB3; Wed, 15 Nov 2023 20:18:44 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, jacopo.mondi@ideasonboard.com, laurent.pinchart@ideasonboard.com Subject: [PATCH 5/6] media: imx319: Use pm_runtime_get_if_active(), put usage_count correctly Date: Wed, 15 Nov 2023 20:18:39 +0200 Message-Id: <20231115181840.1509046-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> References: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use pm_runtime_get_if_active() to get the device's runtime PM usage_count and set controls, then use runtime PM autosuspend once the controls have been set (instead of likely transitioning to suspended state immediately). Signed-off-by: Sakari Ailus --- drivers/media/i2c/imx319.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c index 5378f607f340..b1031bba71b7 100644 --- a/drivers/media/i2c/imx319.c +++ b/drivers/media/i2c/imx319.c @@ -1880,8 +1880,8 @@ static int imx319_set_ctrl(struct v4l2_ctrl *ctrl) struct imx319 *imx319 = container_of(ctrl->handler, struct imx319, ctrl_handler); struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); + int ret, pm_status; s64 max; - int ret; /* Propagate change of current control to all related controls */ switch (ctrl->id) { @@ -1898,7 +1898,8 @@ static int imx319_set_ctrl(struct v4l2_ctrl *ctrl) * Applying V4L2 control value only happens * when power is up for streaming */ - if (!pm_runtime_get_if_in_use(&client->dev)) + pm_status = pm_runtime_get_if_active(&client->dev); + if (!pm_status) return 0; switch (ctrl->id) { @@ -1937,7 +1938,8 @@ static int imx319_set_ctrl(struct v4l2_ctrl *ctrl) break; } - pm_runtime_put(&client->dev); + if (pm_status > 0) + pm_runtime_put(&client->dev); return ret; } From patchwork Wed Nov 15 18:18:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 744461 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fcA6jjzm" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EFA11B8; Wed, 15 Nov 2023 10:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700072336; x=1731608336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3aLB1aRUdymuA6UhjFx/E2icz3ilO2LbesGWwW2V+rs=; b=fcA6jjzm0o+nzUO3j+jZ4Wlvv2hIg8U8ePRDzWZHF8ebuEgi/ElNuQKV 0oVzpQRHQ1FvVlfDLzj/By5sQ99MpuIjFHThCrXFECk7n1XOl4HWfUtPz OpRvOS93rTauDBwMMj/FhmGy962LiCK4g0v2Tu8u0izhG52QuH1Q3FjHB Ug9H5CQygMVr3lL7DLgl8uOYbR3UzwuESYyvXVXMLQ4bEApF3/I6TC7g8 xUaYsu/OzABLFVi14YKxpVMhLZgzdCfCOXek4Dt8v4nxOqzT/5pqYqaxI 2BLmHGRrGUBLbGYSRO8k0ocwtx2GSS7+jGAlZegbaIRNtxz+4/TqJyA8Z A==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="381321156" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="381321156" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="831014666" X-IronPort-AV: E=Sophos;i="6.03,305,1694761200"; d="scan'208";a="831014666" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 10:18:48 -0800 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 2790311F830; Wed, 15 Nov 2023 20:18:46 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, jacopo.mondi@ideasonboard.com, laurent.pinchart@ideasonboard.com Subject: [PATCH 6/6] media: imx219: Use pm_runtime_get_if_active(), put usage_count correctly Date: Wed, 15 Nov 2023 20:18:40 +0200 Message-Id: <20231115181840.1509046-7-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> References: <20231115181840.1509046-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use pm_runtime_get_if_active() to get the device's runtime PM usage_count and set controls, then use runtime PM autosuspend once the controls have been set (instead of likely transitioning to suspended state immediately). Signed-off-by: Sakari Ailus --- drivers/media/i2c/imx219.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 8436880dcf7a..b38ee8b3e073 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -371,7 +371,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); const struct v4l2_mbus_framefmt *format; struct v4l2_subdev_state *state; - int ret = 0; + int ret = 0, pm_status; state = v4l2_subdev_get_locked_active_state(&imx219->sd); format = v4l2_subdev_get_pad_format(&imx219->sd, state, 0); @@ -393,7 +393,8 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) * Applying V4L2 control value only happens * when power is up for streaming */ - if (pm_runtime_get_if_in_use(&client->dev) == 0) + pm_status = pm_runtime_get_if_active(&client->dev); + if (!pm_status) return 0; switch (ctrl->id) { @@ -446,7 +447,8 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) break; } - pm_runtime_put(&client->dev); + if (pm_status > 0) + pm_runtime_put(&client->dev); return ret; }