From: Sakari Ailus <sakari.ailus@linux.intel.com>
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 v2 4/7] media: Documentation: Improve camera sensor runtime PM documentation
Date: Fri, 17 Nov 2023 13:14:30 +0200 [thread overview]
Message-ID: <20231117111433.1561669-5-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20231117111433.1561669-1-sakari.ailus@linux.intel.com>
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 <sakari.ailus@linux.intel.com>
---
.../driver-api/media/camera-sensor.rst | 76 +++++++++++++------
.../firmware-guide/acpi/non-d0-probe.rst | 2 +
2 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/Documentation/driver-api/media/camera-sensor.rst b/Documentation/driver-api/media/camera-sensor.rst
index 6456145f96ed..c1bb0de40189 100644
--- a/Documentation/driver-api/media/camera-sensor.rst
+++ b/Documentation/driver-api/media/camera-sensor.rst
@@ -58,35 +58,55 @@ pipeline. They must obey the rules listed herein to ensure coherent power
management over the pipeline.
Camera sensor drivers are responsible for controlling the power state of the
-device they otherwise control as well. They shall use runtime PM to manage
-power states. Runtime PM shall be enabled at probe time and disabled at remove
-time. Drivers should enable runtime PM autosuspend.
+device they otherwise control as well. They shall use runtime PM to manage power
+states. Runtime PM shall be enabled at probe time using
+:c:func:`pm_runtime_enable()` and disabled using :c:func:`pm_runtime_disable()`
+at remove time. Before enabling Runtime PM, the device's Runtime PM status is
+set to ``RPM_ACTIVE`` using :c:func:`pm_runtime_set_active()` and after
+disabling set to ``RPM_SUSPENDED`` using :c:func:`pm_runtime_set_suspended()`.
+Drivers should enable runtime PM autosuspend.
The runtime PM handlers shall handle clocks, regulators, GPIOs, and other
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 using autosuspend should use
+:c:func:`pm_runtime_get_sync()` 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_mark_busy_autosusp()`, which
+starts autosuspend timer to power off the device later on when its
+``usage_count`` is 0, or :c:func:`pm_runtime_put()` which proceeds to power off
+the device without a delay when its ``usage_count`` is 0.
+
+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, which may be used as a signal for the
+driver that initialisation related registers need to be written to the
+sensor.
+
+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.
+probe. On ACPI systems I²C devices are normally powered on for probe but
+:ref:`this can be avoided if needed <firmware_acpi_non_d0_probe>`.
At system suspend time, the whole camera pipeline must stop streaming, and
restart when the system is resumed. This requires coordination between the
camera sensor and the rest of the camera pipeline. Bridge drivers are
responsible for this coordination, and instruct camera sensors to stop and
-restart streaming by calling the appropriate subdev operations
-(``.s_stream()``, ``.enable_streams()`` or ``.disable_streams()``). Camera
-sensor drivers shall therefore **not** keep track of the streaming state to
-stop streaming in the PM suspend handler and restart it in the resume handler.
-Drivers should in general not implement the system PM handlers.
+restart streaming by calling the appropriate subdev operations (``.s_stream()``,
+``.enable_streams()`` or ``.disable_streams()``). Camera sensor drivers shall
+therefore **not** keep track of the streaming state to stop streaming in the PM
+suspend handler and restart it in the resume handler. Drivers should in general
+not implement the system PM handlers.
Camera sensor drivers shall **not** implement the subdev ``.s_power()``
-operation, as it is deprecated. While this operation is implemented in some
+operation as it is deprecated. While this operation is implemented in some
existing drivers as they predate the deprecation, new drivers shall use runtime
PM instead. If you feel you need to begin calling ``.s_power()`` from an ISP or
a bridge driver, instead add runtime PM support to the sensor driver you are
@@ -94,20 +114,26 @@ using and drop its ``.s_power()`` handler.
Please also see :ref:`examples <media-camera-sensor-examples>`.
+.. _media_writing_camera_sensor_drives_control_framework:
+
Control framework
~~~~~~~~~~~~~~~~~
``v4l2_ctrl_handler_setup()`` function may not be used in the device's runtime
-PM ``runtime_resume`` callback, as it has no way to figure out the power state
-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);
-
-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.
+PM ``runtime_resume`` callback as it has no way to figure out the power state of
+the device. This is because the Runtime PM status of the device is only changed
+after the Runtime PM status transition has taken place. The ``s_ctrl`` callback
+can be used to obtain device's Runtime PM status once the transition has taken
+place:
+
+.. c:function:: int pm_runtime_get_if_active(struct device *dev);
+
+The function returns a non-zero value if the device is powered on (in which case
+it increments the device's ``usage_count``) or runtime PM was disabled, in
+either of which cases the driver may proceed to 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
+:c:func:`pm_runtime_put()` or its variants.
Rotation, orientation and flipping
----------------------------------
diff --git a/Documentation/firmware-guide/acpi/non-d0-probe.rst b/Documentation/firmware-guide/acpi/non-d0-probe.rst
index 815bcc8db69f..f0669059101f 100644
--- a/Documentation/firmware-guide/acpi/non-d0-probe.rst
+++ b/Documentation/firmware-guide/acpi/non-d0-probe.rst
@@ -1,5 +1,7 @@
.. SPDX-License-Identifier: GPL-2.0
+.. _firmware_acpi_non_d0_probe:
+
========================================
Probing devices in other D states than 0
========================================
--
2.39.2
next prev parent reply other threads:[~2023-11-17 11:14 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-17 11:14 [PATCH v2 0/7] Small Runtime PM API changes Sakari Ailus
2023-11-17 11:14 ` [PATCH v2 1/7] pm: runtime: Simplify pm_runtime_get_if_active() usage Sakari Ailus
2023-11-18 17:46 ` Laurent Pinchart
2023-11-17 11:14 ` [PATCH v2 2/7] pm: runtime: Add pm_runtime_put_mark_busy_autosusp() helper Sakari Ailus
2023-11-18 17:49 ` Laurent Pinchart
2023-11-18 21:20 ` Rafael J. Wysocki
2023-11-18 21:30 ` Laurent Pinchart
2023-11-20 9:27 ` Sakari Ailus
2023-11-20 9:47 ` Laurent Pinchart
2023-11-21 8:41 ` Sakari Ailus
2023-11-21 8:50 ` Laurent Pinchart
2023-11-21 10:00 ` Sakari Ailus
2023-11-17 11:14 ` [PATCH v2 3/7] ACPI: Documentation: Document acpi_dev_state_d0() Sakari Ailus
2023-11-18 18:50 ` Laurent Pinchart
2023-11-20 9:31 ` Sakari Ailus
2023-11-20 12:52 ` Rafael J. Wysocki
2023-11-20 20:03 ` Sakari Ailus
2023-11-20 20:22 ` Rafael J. Wysocki
2023-11-20 20:53 ` Sakari Ailus
2023-11-17 11:14 ` Sakari Ailus [this message]
2023-11-18 18:49 ` [PATCH v2 4/7] media: Documentation: Improve camera sensor runtime PM documentation Laurent Pinchart
2023-11-17 11:14 ` [PATCH v2 5/7] media: ov8858: Use pm_runtime_get_if_active(), put usage_count correctly Sakari Ailus
2023-11-17 15:30 ` Jacopo Mondi
2023-11-18 11:12 ` Sakari Ailus
2023-11-18 17:33 ` Laurent Pinchart
2023-11-20 8:31 ` Sakari Ailus
2023-11-17 11:14 ` [PATCH v2 6/7] media: imx319: Put usage_count correctly in s_ctrl callback Sakari Ailus
2023-11-18 18:52 ` Laurent Pinchart
2023-11-20 9:32 ` Sakari Ailus
2023-11-20 9:45 ` Laurent Pinchart
2023-11-21 8:18 ` Sakari Ailus
2023-11-21 8:25 ` Laurent Pinchart
2023-11-21 8:44 ` Sakari Ailus
2023-11-17 11:14 ` [PATCH v2 7/7] media: imx219: " Sakari Ailus
2023-11-17 14:20 ` Dave Stevenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231117111433.1561669-5-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox