Skip to contentSkip to conversation

Sub-device configuration models

RFC Superseded Sakari Ailus 3 participants 25 messages Nov 29, 2024 – Dec 5, 2024 Media (V4L/DVB)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Sub-device configuration models

Hello everyone,

I've been recently working (with others) on sub-device streams support as well as on internal pads. The two can be used to make sub-device configuration more versatile.

At the same time, the added interfaces are much more useful if we require specific semantics of those interfaces, so that the user space knows exactly what e.g. a given selection target signifies. However, as the same selection rectangle could be used for a different purpose on a non-raw sensor device, we need a way to tell how should the user space determine how to use a given interface.

I'm proposing to solve this problem by introducing sub-device configuration models, and by the common raw sensor model, also present in this patchset, in particular.

This has been (and will, for some time, continue to be) the reason why I have reviewed few sensor driver related patches lately. As we're introducing a new interface, it's beneficial to be able to use that interface right from the start, rather than trying to later on offer compatibility support, which is almost always a fair amount of work with less than desirable results in the driver.

With this solved, I believe we can enable the use of the streams UAPI.

Comments are welcome.

RFC v2 (labelled as PATCH) is <[email protected]> on LMML.

RFC v1 is <[email protected]> on LMML.

We may end up postponing merging three last patches (those adding controls) until current control values are moved to sub-device (and video device) state. Discussion is needed on the topic.

The compiled documentation can be found here <URL:https://www.retiisi.eu/~sailus/v4l2/tmp/common-raw/output/userspace-api/media/v4l/dev-subdev.html#media-subdev-config-model-common-raw-sensor>.

since v2:

- Remove the CROP_BOUNDS rectangle on the image data sink pad. It's redundant.

- Remove scaling from the sink compose rectangle, leaving binning and sub-sampling.

- Introduce scaling as well as post-scaler digital crop on source pad (image stream). This is a new patch, preceding control changes.

- Use monospace font for selection targets.

- Improvements in referring to previous configuration steps in text description.

since v1:

- Rework the documentation according to the comments (spelling fixes, alignment mostly).

- Include separate patches for binning and sub-sampling controls.

- Allow binning, scaling and scaling to be configured using the compose rectangle. This will change to just scaling in the three last patches.

Sakari Ailus (9):
media: Documentation: Rework embedded data documentation
media: Documentation: Add a hyphen to list-based
media: Documentation: Reword split of sensor driver to two classes
media: Documentation: Add subdev configuration models, raw sensor
model
media: Documentation: Add scaling and post-scaler crop for common raw
media: uapi: Add V4L2_CID_CONFIG_MODEL control
media: uapi: Add V4L2_CID_BINNING control for binning configuration
media: uapi: Add controls for sub-sampling configuration
media: Documentation: Add binning and sub-sampling controls

 .../media/drivers/camera-sensor.rst           |  53 ++-
 .../media/v4l/common-raw-sensor.dia           | 441 ++++++++++++++++++
 .../media/v4l/common-raw-sensor.svg           | 134 ++++++
 .../userspace-api/media/v4l/dev-subdev.rst    |   2 +
 .../media/v4l/ext-ctrls-camera.rst            |  40 ++
 .../media/v4l/ext-ctrls-image-process.rst     |   4 +
 .../media/v4l/subdev-config-model.rst         | 228 +++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   9 +
 include/uapi/linux/v4l2-controls.h            |   6 +
 9 files changed, 903 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.dia
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.svg
 create mode 100644 Documentation/userspace-api/media/v4l/subdev-config-model.rst

base-commit: f188c7293d34f9ac50c1005da2613d519d97db83

Signature · 1 line
2.39.5
#1 lore raw

RFC v3 1/9 media: Documentation: Rework embedded data documentation

Rework embedded data documentation by removing the reference to the pixel data stream. The specific documentation of the embedded data interface will be elsewhere, in the near future either CCS or common raw camera sensor model documentation.

---
 .../userspace-api/media/drivers/camera-sensor.rst   | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +6 -7
index dc415b8f6c8e..8e1083417ae1 100644
@@ -111,13 +111,12 @@ the sensor configuration for the captured frame back to the host. While CSI-2 is
 the most common data interface used by such sensors, embedded data can be
 available on other interfaces as well.
 
-Such sensors expose two internal sink pads (pads that have both the
-``MEDIA_PAD_FL_SINK <MEDIA-PAD-FL-SINK>`` and ``MEDIA_PAD_FL_INTERNAL
-<MEDIA-PAD-FL-INTERNAL>`` flags set) to model the source of the image and
-embedded data streams. Both of these pads produces a single stream, and the
-sub-device routes those streams to the external (source) pad. If the sub-device
-driver supports disabling embedded data, this can be done by disabling the
-embedded data route via the ``VIDIOC_SUBDEV_S_ROUTING`` IOCTL.
+Embedded data support is indicated by the precence of an internal sink pad (pad
+that has both the ``MEDIA_PAD_FL_SINK <MEDIA-PAD-FL-SINK>`` and
+``MEDIA_PAD_FL_INTERNAL <MEDIA-PAD-FL-INTERNAL>`` flags set) with a metadata
+format to model the embedded data stream. If the sub-device driver supports
+disabling embedded data, this can be done by disabling the embedded data route
+via the ``VIDIOC_SUBDEV_S_ROUTING`` IOCTL.
 
 In general, changing the embedded data format from the driver-configured values
 is not supported. The height of the metadata is device-specific and the width
Signature · 1 line
2.39.5
#2 lore raw

RFC v3 2/9 media: Documentation: Add a hyphen to list-based

In reply to Sakari Ailus

Add a hyphen to list-based for uniform spelling in camera-sensor.rst.

---
 Documentation/userspace-api/media/drivers/camera-sensor.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +3 -3
index 8e1083417ae1..9a1e8aa9fc77 100644
@@ -26,10 +26,10 @@ of cropping and scaling operations from the device's pixel array's size.
 
 An example of such a driver is the CCS driver.
 
-Register list based drivers
+Register list-based drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Register list based drivers generally, instead of able to configure the device
+Register list-based drivers generally, instead of able to configure the device
 they control based on user requests, are limited to a number of preset
 configurations that combine a number of different parameters that on hardware
 level are independent. How a driver picks such configuration is based on the
@@ -67,7 +67,7 @@ is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in
 the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same
 sub-device. The unit of that control is pixels per second.
 
-Register list based drivers need to implement read-only sub-device nodes for the
+Register list-based drivers need to implement read-only sub-device nodes for the
 purpose. Devices that are not register list based need these to configure the
 device's internal processing pipeline.
 
Signature · 1 line
2.39.5
Reviewed-by on v3 2/9
#3 lore raw

Re: [RFC v3 2/9] media: Documentation: Add a hyphen to list-based

Hi Sakari

Quoted 3 lines · Sakari Ailus

Add a hyphen to list-based for uniform spelling in camera-sensor.rst.

Quoted 34 lines
---
 Documentation/userspace-api/media/drivers/camera-sensor.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +3 -4
index 8e1083417ae1..9a1e8aa9fc77 100644
@@ -26,10 +26,10 @@ of cropping and scaling operations from the device's pixel array's size.
 
 An example of such a driver is the CCS driver.
 
-Register list based drivers
+Register list-based drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Register list based drivers generally, instead of able to configure the device
+Register list-based drivers generally, instead of able to configure the device
 they control based on user requests, are limited to a number of preset
 configurations that combine a number of different parameters that on hardware
 level are independent. How a driver picks such configuration is based on the
@@ -67,7 +67,7 @@ is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in
 the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same
 sub-device. The unit of that control is pixels per second.
 
-Register list based drivers need to implement read-only sub-device nodes for the
+Register list-based drivers need to implement read-only sub-device nodes for the
 purpose. Devices that are not register list based need these to configure the
 device's internal processing pipeline.
 
--

2.39.5

#4 lore raw

RFC v3 3/9 media: Documentation: Reword split of sensor driver to two classes

In reply to Sakari Ailus

The sensor drivers do not configure the output size of the sensors but the entire internal pipeline. Reflect this in the documentation.

---
 .../userspace-api/media/drivers/camera-sensor.rst      | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +6 -4
index 9a1e8aa9fc77..bc55c861fb69 100644
@@ -10,11 +10,13 @@ used to control the camera sensor drivers.
 
 You may also find :ref:`media_writing_camera_sensor_drivers` useful.
 
-Frame size
-----------
+Sensor internal pipeline configuration
+--------------------------------------
 
-There are two distinct ways to configure the frame size produced by camera
-sensors.
+Camera sensors have an internal processing pipeline including cropping and
+binning functionality. The sensor drivers belong to two distinct classes, freely
+configurable and register list-based drivers, depending on how the driver
+configures this functionality.
 
 Freely configurable camera sensor drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.39.5
Reviewed-by on v3 3/9
#5 lore raw

Re: [RFC v3 3/9] media: Documentation: Reword split of sensor driver to two classes

Hi Sakari

Quoted 5 lines · Sakari Ailus

The sensor drivers do not configure the output size of the sensors but the entire internal pipeline. Reflect this in the documentation.

Thanks
j

Quoted 30 lines
---
 .../userspace-api/media/drivers/camera-sensor.rst      | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +6 -5
index 9a1e8aa9fc77..bc55c861fb69 100644
@@ -10,11 +10,13 @@ used to control the camera sensor drivers.
 
 You may also find :ref:`media_writing_camera_sensor_drivers` useful.
 
-Frame size
-----------
+Sensor internal pipeline configuration
+--------------------------------------
 
-There are two distinct ways to configure the frame size produced by camera
-sensors.
+Camera sensors have an internal processing pipeline including cropping and
+binning functionality. The sensor drivers belong to two distinct classes, freely
+configurable and register list-based drivers, depending on how the driver
+configures this functionality.
 
 Freely configurable camera sensor drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--

2.39.5

#6 lore raw

RFC v3 4/9 media: Documentation: Add subdev configuration models, raw sensor model

In reply to Sakari Ailus

Sub-device configuration models define what V4L2 API elements are available on a compliant sub-device and how do they behave.

The patch also adds a model for common raw sensors.

---
 .../media/drivers/camera-sensor.rst           |   4 +
 .../media/v4l/common-raw-sensor.dia           | 441 ++++++++++++++++++
 .../media/v4l/common-raw-sensor.svg           | 134 ++++++
 .../userspace-api/media/v4l/dev-subdev.rst    |   2 +
 .../media/v4l/subdev-config-model.rst         | 208 +++++++++
 5 files changed, 789 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.dia
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.svg
 create mode 100644 Documentation/userspace-api/media/v4l/subdev-config-model.rst
Documentation/userspace-api/media/drivers/camera-sensor.rst +4 -0
index bc55c861fb69..5bc4c79d230c 100644
@@ -18,6 +18,8 @@ binning functionality. The sensor drivers belong to two distinct classes, freely
 configurable and register list-based drivers, depending on how the driver
 configures this functionality.
 
+Also see :ref:`media_subdev_config_model_common_raw_sensor`.
+
 Freely configurable camera sensor drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -105,6 +107,8 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
+.. _media_using_camera_sensor_drivers_embedded_data:
+
 Embedded data
 -------------
 
Documentation/userspace-api/media/v4l/common-raw-sensor.dia new file +441 -0

441 lines not on this page · raw message

Documentation/userspace-api/media/v4l/common-raw-sensor.svg new file +134 -0

134 lines not on this page · raw message

Documentation/userspace-api/media/v4l/dev-subdev.rst +2 -0
index dcfcbd52490d..4d145bd3bd09 100644
@@ -838,3 +838,5 @@ stream while it may be possible to enable and disable the embedded data stream.
 
 The embedded data format does not need to be configured on the sensor's pads as
 the format is dictated by the pixel data format in this case.
+
+.. include:: subdev-config-model.rst
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +208 -0

208 lines not on this page · raw message

Signature · 1 line
2.39.5
#7 lore raw

Re: [RFC v3 4/9] media: Documentation: Add subdev configuration models, raw sensor model

Hi Sakari

Quoted 40 lines · Sakari Ailus

Sub-device configuration models define what V4L2 API elements are available on a compliant sub-device and how do they behave.

The patch also adds a model for common raw sensors.

---
 .../media/drivers/camera-sensor.rst           |   4 +
 .../media/v4l/common-raw-sensor.dia           | 441 ++++++++++++++++++
 .../media/v4l/common-raw-sensor.svg           | 134 ++++++
 .../userspace-api/media/v4l/dev-subdev.rst    |   2 +
 .../media/v4l/subdev-config-model.rst         | 208 +++++++++
 5 files changed, 789 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.dia
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.svg
 create mode 100644 Documentation/userspace-api/media/v4l/subdev-config-model.rst
Documentation/userspace-api/media/drivers/camera-sensor.rst +4 -0
index bc55c861fb69..5bc4c79d230c 100644
@@ -18,6 +18,8 @@ binning functionality. The sensor drivers belong to two distinct classes, freely
 configurable and register list-based drivers, depending on how the driver
 configures this functionality.
 
+Also see :ref:`media_subdev_config_model_common_raw_sensor`.
+
 Freely configurable camera sensor drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -105,6 +107,8 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
+.. _media_using_camera_sensor_drivers_embedded_data:
+
 Embedded data
 -------------
 
Documentation/userspace-api/media/v4l/common-raw-sensor.dia +0 -0

snip

Quoted 16 lines
Documentation/userspace-api/media/v4l/dev-subdev.rst +2 -0
index dcfcbd52490d..4d145bd3bd09 100644
@@ -838,3 +838,5 @@ stream while it may be possible to enable and disable the embedded data stream.
 
 The embedded data format does not need to be configured on the sensor's pads as
 the format is dictated by the pixel data format in this case.
+
+.. include:: subdev-config-model.rst
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +0 -0
new file mode 100644
index 000000000000..4ddf98e3143c

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 10

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
@@ -0,0 +1,208 @@
+.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
+
+.. _media_subdev_config_model:
+
+Sub-device configuration models
+===============================
+
+A sub-device configuration model specifies in detail what the user space can
+expect from a sub-device in terms of V4L2 sub-device interface support,
+including IOCTL (including selection targets and controls) semantics.

including IOCTLs, selection targets and controls semantics.

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 23

Quoted 13 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +13 -0
+
+A sub-device may implement more than one configuration model at the same
+time. The implemented configuration models can be obtained from the sub-device's
+``V4L2_CID_CONFIG_MODEL`` control.
+
+.. _media_subdev_config_model_common_raw_sensor:
+
+Common raw camera sensor model
+------------------------------
+
+The common raw camera sensor model defines a set of enumeration and
+configuration interfaces (formats, selections etc.) that cover the vast majority
+of funcitionality of raw camera sensors. Not all of the interfaces are

s/funcitionality/functionalities

Quoted 43 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +43 -0
+necessarily offered by all drivers.
+
+A sub-device complies with the common raw sensor model if the
+``V4L2_CONFIG_MODEL_COMMON_RAW`` bit is set in the ``V4L2_CID_CONFIG_MODEL``
+control of the sub-device.
+
+The common raw camera sensor model is aligned with
+:ref:`media_using_camera_sensor_drivers`. Please refer to that regarding aspects
+not specified here.
+
+Each camera sensor implementing the common raw sensor model exposes a single
+V4L2 sub-device. The sub-device contains a single source pad (0) and two or more
+internal pads: an image data internal pad (1) and optionally an embedded data
+pad (2). Additionally, further internal pads may be supported for other
+features, in which case they are documented separately for the given device.
+
+This is shown in :ref:`media_subdev_config_model_common_raw_sensor_subdev`.
+
+.. _media_subdev_config_model_common_raw_sensor_subdev:
+
+.. kernel-figure:: common-raw-sensor.svg
+    :alt:    common-raw-sensor.svg
+    :align:  center
+
+    **Common raw sensor sub-device**
+
+Routes
+^^^^^^
+
+A sub-device conforming to common raw camera sensor model implements the
+following routes.
+
+.. flat-table:: Routes
+    :header-rows: 1
+
+    * - Sink pad/stream
+      - Source pad/stream
+      - Static (X/M(aybe)/-)
+      - Mandatory (X/-)
+      - Synopsis
+    * - 1/0
+      - 0/0
+      - X

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 76

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+      - X
+      - Image data
+    * - 2/0
+      - 0/1
+      - M
+      - \-
+      - Embedded data
+
+Some devices do not support the embedded data stream, others do support it and
+in some of the latter, it can be turned on and off before streaming is started.

What about:

Support for the embedded data stream is optional. Device that support the embedded data stream might allow to enable/disable the route before the streaming is started.

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 82

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+
+Sensor pixel array size, cropping and binning
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The sensor's pixel array is divided into one or more areas. The areas around the
+edge of the pixel array, usually one or more sides, may contain optical black

optically ?

Quoted 12 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +12 -0
+pixels, dummy pixels and other non-image pixels. The entire pixel array size is
+conveyed by the format on (pad, stream) pair 1/0.
+
+A rectangle within the pixel array contains the visible pixels. Capturing the
+non-visible pixels outside the visible pixel area may be supported by the
+sensor. The visible pixel area corresponds to the ``V4L2_SEL_TGT_CROP_DEFAULT``
+selection target on (pad, stream) pair 1/0.
+
+Sensors can perform multiple operations that affect the output image size. First
+of these is the analogue crop. Analogue crop limits the area of the pixel array
+which the sensor will read, affecting sensor timing as well. The granularity of
+the analogue crop configuration varies greatly across sensors: some sensors

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 104

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+support only a few different analogue crop configurations whereas others may
+support anything divisible by a given number of pixels. The analogue crop
+configuration corresponds the ``V4L2_SEL_TGT_CROP`` selection target on (pad,
+stream) pair 1/0. The default analogue crop rectangle corresponds to the visible
+pixel area.
+
+In the next step, binning is performed on the image data read from camera
+sensor's pixel array, as determined by the analogue crop configuration. Enabling
+binning will effectively result in an image smaller than the original by given
+binning factors horizontally and vertically. Typical values are 1/2 and 1/3 but

I thought 1/4 was more common than 1/3... Nevermind..

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 116

Quoted 12 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +12 -0
+others may well be supported by the hardware as well.
+
+Sub-sampling follows binning. Sub-sampling, like binning, reduces the size of
+the image by including only a subset of samples read from the sensor's pixel
+matrix, typically every n'th pixel horizontally and vertically, taking the
+sensor's colour pattern into account. Sub-sampling is generally configurable
+separately horizontally and vertically.
+
+Binning and sub-sampling are configured using the ``V4L2_SEL_TGT_COMPOSE``
+rectangle, relative to the analogue crop rectangle, on (pad, stream) pair
+1/0. It depends on the driver which of these operations are being used to
+achieve the resulting size.

I would say "It depends on the driver implementation to decide how binning and skipping are combined to obtain the desired scaling ratio."

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 120

Quoted 4 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
+
+The digital crop operation takes place after binning and sub-sampling. It is
+configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
+0/0. The resulting image size is further output by the sensor.

This is not true anymore if we consider digital scaling and post-scaler crop.

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 125

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+
+The sensor's output mbus code is configured by setting the format on the (pad,
+stream) pair 0/0. When setting the format, always use the same width and height
+as for the digital crop setting.
+

Same comment here as well.

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 126

Quoted 1 line
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +1 -0
+Drivers may only support some of even none of these configurations, in which

s/configurations/configuration options/

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 127

Quoted 1 line
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +1 -0
+case they do not expose the corresponding selection rectangles. If any selection

How are selection rectangles "exposed" ?
I would say "support" instead of expose.

However I'm a bit concerned what "support" (or "expose") means. We should probably define it. I do think that driver should allow reading all the above selection rectangles and return the correct values (if a configuration step is not supported, sizes are simply passed forward from the previous selection target to the next target/format). I'm less sure about setting them, if they should error out or simply adjust it as get_selection() would have done.

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 132

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+targets are omitted, the further selection rectangle or format is instead
+related to the previous implemented selection rectangle. For instance, if the
+sensor supports binning but not analogue crop, then the binning configuration
+(``V4L2_SEL_TGT_COMPOSE`` selection target) is done in relation to the visible
+pixel area (``V4L2_SEL_TGT_CROP_DEFAULT`` selection target).

Let alone the fact I would have used, say, digital crop as an example of an optional feature, I think allowing to read all the possible targets would save userspace keeping track of what target the rectangle they want to configure refers to.

Quoted 47 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +47 -0
+
+Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
+
+.. flat-table:: Selection targets on pads
+    :header-rows: 1
+
+    * - Pad/Stream
+      - Selection target/format
+      - Mandatory (X/-)
+      - Modifiable (X/-)
+      - Synopsis
+    * - 1/0
+      - Format
+      - X
+      - \-
+      - Image data format. The width and the height fields indicates the full
+        size of the pixel array, including non-visible pixels. The media bus
+        code of this format reflects the native pixel depth of the sensor.
+    * - 1/0
+      - ``V4L2_SEL_TGT_CROP_DEFAULT``
+      - X
+      - \
+      - The visible pixel area. This rectangle is relative to the format on the
+        same (pad, stream).
+    * - 1/0
+      - ``V4L2_SEL_TGT_CROP``
+      - \-
+      - X
+      - Analogue crop. Analogue crop typically has a coarse granularity. This
+        rectangle is relative to the format on the same (pad, stream).
+    * - 1/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Binning and sub-sampling. This rectangle is relative to the
+        ``V4L2_SEL_TGT_CROP`` rectangle on the same (pad, stream). The
+        combination of binning and sub-sampling is configured using this
+        selection target.
+    * - 2/0
+      - Format
+      - X
+      - \-
+      - Embedded data format.
+    * - 0/0
+      - ``V4L2_SEL_TGT_CROP``
+      - \-
+      - X

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 189

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+      - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
+        rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - Format
+      - X
+      - X
+      - Image data source format. Always assign the width and height fields of
+        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+        rectangle on (pad, stream) pair 0/0. The media bus code reflects the
+        pixel data output of the sensor.

This makes me think it is intentional not to document digital scaling/post-scaler crop in this version ?

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+    * - 0/1
+      - Format
+      - X
+      - \-
+      - Embedded data source format.

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 204

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+
+Embedded data
+^^^^^^^^^^^^^
+
+The embedded data stream is produced by the sensor when the corresponding route
+is enabled. The embedded data route may also be immutable or not exist at all,
+in case the sensor (or the driver) does not support it.
+
+Generally the sensor embedded data width is determined by the width of the image
+data whereas the number of lines are constant for the embedded data. The user

Maybe drop "The" from "The user space" ?

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 208

Quoted 4 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
+space may obtain the size of the embedded data once the image data size on the
+source pad has been configured.
+
+Also see :ref:`media_using_camera_sensor_drivers_embedded_data`.

Thanks for the hard work here, I like how this new document clearly outlines the expected interfaces exposed by drivers.

Thanks
j

Quoted 4 lines

--
2.39.5

#8 lore raw

Re: [RFC v3 4/9] media: Documentation: Add subdev configuration models, raw sensor model

Hi Jacopo,

Thank you for the review.

Quoted 66 lines · Jacopo Mondi

Hi Sakari

Quoted 40 lines · Sakari Ailus

Sub-device configuration models define what V4L2 API elements are available on a compliant sub-device and how do they behave.

The patch also adds a model for common raw sensors.

---
 .../media/drivers/camera-sensor.rst           |   4 +
 .../media/v4l/common-raw-sensor.dia           | 441 ++++++++++++++++++
 .../media/v4l/common-raw-sensor.svg           | 134 ++++++
 .../userspace-api/media/v4l/dev-subdev.rst    |   2 +
 .../media/v4l/subdev-config-model.rst         | 208 +++++++++
 5 files changed, 789 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.dia
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.svg
 create mode 100644 Documentation/userspace-api/media/v4l/subdev-config-model.rst
Documentation/userspace-api/media/drivers/camera-sensor.rst +4 -0
index bc55c861fb69..5bc4c79d230c 100644
@@ -18,6 +18,8 @@ binning functionality. The sensor drivers belong to two distinct classes, freely
 configurable and register list-based drivers, depending on how the driver
 configures this functionality.
 
+Also see :ref:`media_subdev_config_model_common_raw_sensor`.
+
 Freely configurable camera sensor drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -105,6 +107,8 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
+.. _media_using_camera_sensor_drivers_embedded_data:
+
 Embedded data
 -------------
 
Documentation/userspace-api/media/v4l/common-raw-sensor.dia +0 -0

snip

Quoted 20 lines
Documentation/userspace-api/media/v4l/dev-subdev.rst +2 -0
index dcfcbd52490d..4d145bd3bd09 100644
@@ -838,3 +838,5 @@ stream while it may be possible to enable and disable the embedded data stream.
 
 The embedded data format does not need to be configured on the sensor's pads as
 the format is dictated by the pixel data format in this case.
+
+.. include:: subdev-config-model.rst
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
new file mode 100644
index 000000000000..4ddf98e3143c
@@ -0,0 +1,208 @@
+.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
+
+.. _media_subdev_config_model:
+
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 10

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+Sub-device configuration models
+===============================
+
+A sub-device configuration model specifies in detail what the user space can
+expect from a sub-device in terms of V4L2 sub-device interface support,
+including IOCTL (including selection targets and controls) semantics.

including IOCTLs, selection targets and controls semantics.

I think we could as well as drop these, i.e. just mention semantics.

Quoted 16 lines
Quoted 4 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +3 -0
+
+A sub-device may implement more than one configuration model at the same
+time. The implemented configuration models can be obtained from the sub-device's

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 23

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+``V4L2_CID_CONFIG_MODEL`` control.
+
+.. _media_subdev_config_model_common_raw_sensor:
+
+Common raw camera sensor model
+------------------------------
+
+The common raw camera sensor model defines a set of enumeration and
+configuration interfaces (formats, selections etc.) that cover the vast majority
+of funcitionality of raw camera sensors. Not all of the interfaces are

s/funcitionality/functionalities

I'd say singular is right in this case. Maybe Kieran or Dave have an opinion as well? :-)

Quoted 57 lines
Quoted 44 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +43 -0
+necessarily offered by all drivers.
+
+A sub-device complies with the common raw sensor model if the
+``V4L2_CONFIG_MODEL_COMMON_RAW`` bit is set in the ``V4L2_CID_CONFIG_MODEL``
+control of the sub-device.
+
+The common raw camera sensor model is aligned with
+:ref:`media_using_camera_sensor_drivers`. Please refer to that regarding aspects
+not specified here.
+
+Each camera sensor implementing the common raw sensor model exposes a single
+V4L2 sub-device. The sub-device contains a single source pad (0) and two or more
+internal pads: an image data internal pad (1) and optionally an embedded data
+pad (2). Additionally, further internal pads may be supported for other
+features, in which case they are documented separately for the given device.
+
+This is shown in :ref:`media_subdev_config_model_common_raw_sensor_subdev`.
+
+.. _media_subdev_config_model_common_raw_sensor_subdev:
+
+.. kernel-figure:: common-raw-sensor.svg
+    :alt:    common-raw-sensor.svg
+    :align:  center
+
+    **Common raw sensor sub-device**
+
+Routes
+^^^^^^
+
+A sub-device conforming to common raw camera sensor model implements the
+following routes.
+
+.. flat-table:: Routes
+    :header-rows: 1
+
+    * - Sink pad/stream
+      - Source pad/stream
+      - Static (X/M(aybe)/-)
+      - Mandatory (X/-)
+      - Synopsis
+    * - 1/0
+      - 0/0
+      - X

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 76

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+      - X
+      - Image data
+    * - 2/0
+      - 0/1
+      - M
+      - \-
+      - Embedded data
+
+Some devices do not support the embedded data stream, others do support it and
+in some of the latter, it can be turned on and off before streaming is started.

What about:

Quoted 3 lines

Support for the embedded data stream is optional. Device that support the embedded data stream might allow to enable/disable the route before the streaming is started.

How about:

Support for the embedded data stream is optional. Drivers supporting the embedded data stream may allow disabling and enabling the route when the streaming is disabled.

Quoted 9 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 82

Quoted 7 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+
+Sensor pixel array size, cropping and binning
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The sensor's pixel array is divided into one or more areas. The areas around the
+edge of the pixel array, usually one or more sides, may contain optical black

optically ?

E.g. CCS spec refers to these as "optical black" pixels.

Quoted 26 lines
Quoted 13 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +12 -0
+pixels, dummy pixels and other non-image pixels. The entire pixel array size is
+conveyed by the format on (pad, stream) pair 1/0.
+
+A rectangle within the pixel array contains the visible pixels. Capturing the
+non-visible pixels outside the visible pixel area may be supported by the
+sensor. The visible pixel area corresponds to the ``V4L2_SEL_TGT_CROP_DEFAULT``
+selection target on (pad, stream) pair 1/0.
+
+Sensors can perform multiple operations that affect the output image size. First
+of these is the analogue crop. Analogue crop limits the area of the pixel array
+which the sensor will read, affecting sensor timing as well. The granularity of
+the analogue crop configuration varies greatly across sensors: some sensors

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 104

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+support only a few different analogue crop configurations whereas others may
+support anything divisible by a given number of pixels. The analogue crop
+configuration corresponds the ``V4L2_SEL_TGT_CROP`` selection target on (pad,
+stream) pair 1/0. The default analogue crop rectangle corresponds to the visible
+pixel area.
+
+In the next step, binning is performed on the image data read from camera
+sensor's pixel array, as determined by the analogue crop configuration. Enabling
+binning will effectively result in an image smaller than the original by given
+binning factors horizontally and vertically. Typical values are 1/2 and 1/3 but

I thought 1/4 was more common than 1/3... Nevermind..

Quoted 16 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 116

Quoted 12 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +12 -0
+others may well be supported by the hardware as well.
+
+Sub-sampling follows binning. Sub-sampling, like binning, reduces the size of
+the image by including only a subset of samples read from the sensor's pixel
+matrix, typically every n'th pixel horizontally and vertically, taking the
+sensor's colour pattern into account. Sub-sampling is generally configurable
+separately horizontally and vertically.
+
+Binning and sub-sampling are configured using the ``V4L2_SEL_TGT_COMPOSE``
+rectangle, relative to the analogue crop rectangle, on (pad, stream) pair
+1/0. It depends on the driver which of these operations are being used to
+achieve the resulting size.

I would say "It depends on the driver implementation to decide how binning and skipping are combined to obtain the desired scaling ratio."

I wouldn't refer to this as scaling as we'll have specific scaling configuration elsewhere. How about:

The driver implementation determines how to configure binning and sub-sampling to achieve the desired size.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 120

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
+
+The digital crop operation takes place after binning and sub-sampling. It is
+configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
+0/0. The resulting image size is further output by the sensor.

This is not true anymore if we consider digital scaling and post-scaler crop.

Yes. I'll address this in the next patch.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 125

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+
+The sensor's output mbus code is configured by setting the format on the (pad,
+stream) pair 0/0. When setting the format, always use the same width and height
+as for the digital crop setting.
+

Same comment here as well.

Ditto.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 126

Quoted 2 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +1 -0
+Drivers may only support some of even none of these configurations, in which

s/configurations/configuration options/

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 127

Quoted 1 line
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +1 -0
+case they do not expose the corresponding selection rectangles. If any selection

How are selection rectangles "exposed" ?

Well, they are not imposed at least. :-)

Quoted 9 lines

I would say "support" instead of expose.

However I'm a bit concerned what "support" (or "expose") means. We should probably define it. I do think that driver should allow reading all the above selection rectangles and return the correct values (if a configuration step is not supported, sizes are simply passed forward from the previous selection target to the next target/format). I'm less sure about setting them, if they should error out or simply adjust it as get_selection() would have done.

Either could be used IMO. If something is not supported and the user tries to access it, the result is an error (-EINVAL in this case).

Quoted 12 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 132

Quoted 7 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+targets are omitted, the further selection rectangle or format is instead
+related to the previous implemented selection rectangle. For instance, if the
+sensor supports binning but not analogue crop, then the binning configuration
+(``V4L2_SEL_TGT_COMPOSE`` selection target) is done in relation to the visible
+pixel area (``V4L2_SEL_TGT_CROP_DEFAULT`` selection target).

Let alone the fact I would have used, say, digital crop as an example of an optional feature, I think allowing to read all the possible targets would save userspace keeping track of what target the rectangle they want to configure refers to.

This is how the selection API works. If we want to deviate from that, it's another thing, but currently if a driver doesn't support configuring a selection, it won't support that target either.

If we required all selection rectangles to be supported even if they wouldn't be configurable, then it'd be up to user to try to change them to see if they can be modified. I'm not sure if that would be an improvement as a whole.

I wonder what Laurent thinks.

Quoted 53 lines
Quoted 53 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +52 -0
+
+Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
+
+.. flat-table:: Selection targets on pads
+    :header-rows: 1
+
+    * - Pad/Stream
+      - Selection target/format
+      - Mandatory (X/-)
+      - Modifiable (X/-)
+      - Synopsis
+    * - 1/0
+      - Format
+      - X
+      - \-
+      - Image data format. The width and the height fields indicates the full
+        size of the pixel array, including non-visible pixels. The media bus
+        code of this format reflects the native pixel depth of the sensor.
+    * - 1/0
+      - ``V4L2_SEL_TGT_CROP_DEFAULT``
+      - X
+      - \
+      - The visible pixel area. This rectangle is relative to the format on the
+        same (pad, stream).
+    * - 1/0
+      - ``V4L2_SEL_TGT_CROP``
+      - \-
+      - X
+      - Analogue crop. Analogue crop typically has a coarse granularity. This
+        rectangle is relative to the format on the same (pad, stream).
+    * - 1/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Binning and sub-sampling. This rectangle is relative to the
+        ``V4L2_SEL_TGT_CROP`` rectangle on the same (pad, stream). The
+        combination of binning and sub-sampling is configured using this
+        selection target.
+    * - 2/0
+      - Format
+      - X
+      - \-
+      - Embedded data format.
+    * - 0/0
+      - ``V4L2_SEL_TGT_CROP``
+      - \-
+      - X
+      - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
+        rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - Format
+      - X
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 189

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+      - X
+      - Image data source format. Always assign the width and height fields of
+        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+        rectangle on (pad, stream) pair 0/0. The media bus code reflects the
+        pixel data output of the sensor.

This makes me think it is intentional not to document digital scaling/post-scaler crop in this version ?

Not in this patch, no. :-)

I'm fine merging this to the 5th patch if there's an agreement they should be merged together (probably?).

Quoted 10 lines
Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +9 -0
+    * - 0/1
+      - Format
+      - X
+      - \-
+      - Embedded data source format.
+
+Embedded data
+^^^^^^^^^^^^^
+
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 204

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+The embedded data stream is produced by the sensor when the corresponding route
+is enabled. The embedded data route may also be immutable or not exist at all,
+in case the sensor (or the driver) does not support it.
+
+Generally the sensor embedded data width is determined by the width of the image
+data whereas the number of lines are constant for the embedded data. The user

Maybe drop "The" from "The user space" ?

I'd keep it as-is.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 208

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
+space may obtain the size of the embedded data once the image data size on the
+source pad has been configured.
+
+Also see :ref:`media_using_camera_sensor_drivers_embedded_data`.

Thanks for the hard work here, I like how this new document clearly outlines the expected interfaces exposed by drivers.

Thank you. Hopefully we could all agree on this soonish and get libcamera support implemented so we could merge it all. :-)

Signature · 3 lines
Kind regards,

Sakari Ailus
#9 lore raw

Re: [RFC v3 4/9] media: Documentation: Add subdev configuration models, raw sensor model

Hi Sakari

Quoted 80 lines · Sakari Ailus

Hi Jacopo,

Thank you for the review.

Quoted 66 lines · Jacopo Mondi

Hi Sakari

Quoted 40 lines · Sakari Ailus

Sub-device configuration models define what V4L2 API elements are available on a compliant sub-device and how do they behave.

The patch also adds a model for common raw sensors.

---
 .../media/drivers/camera-sensor.rst           |   4 +
 .../media/v4l/common-raw-sensor.dia           | 441 ++++++++++++++++++
 .../media/v4l/common-raw-sensor.svg           | 134 ++++++
 .../userspace-api/media/v4l/dev-subdev.rst    |   2 +
 .../media/v4l/subdev-config-model.rst         | 208 +++++++++
 5 files changed, 789 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.dia
 create mode 100644 Documentation/userspace-api/media/v4l/common-raw-sensor.svg
 create mode 100644 Documentation/userspace-api/media/v4l/subdev-config-model.rst
Documentation/userspace-api/media/drivers/camera-sensor.rst +4 -0
index bc55c861fb69..5bc4c79d230c 100644
@@ -18,6 +18,8 @@ binning functionality. The sensor drivers belong to two distinct classes, freely
 configurable and register list-based drivers, depending on how the driver
 configures this functionality.
 
+Also see :ref:`media_subdev_config_model_common_raw_sensor`.
+
 Freely configurable camera sensor drivers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -105,6 +107,8 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
+.. _media_using_camera_sensor_drivers_embedded_data:
+
 Embedded data
 -------------
 
Documentation/userspace-api/media/v4l/common-raw-sensor.dia +0 -0

snip

Quoted 20 lines
Documentation/userspace-api/media/v4l/dev-subdev.rst +2 -0
index dcfcbd52490d..4d145bd3bd09 100644
@@ -838,3 +838,5 @@ stream while it may be possible to enable and disable the embedded data stream.
 
 The embedded data format does not need to be configured on the sensor's pads as
 the format is dictated by the pixel data format in this case.
+
+.. include:: subdev-config-model.rst
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
new file mode 100644
index 000000000000..4ddf98e3143c
@@ -0,0 +1,208 @@
+.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
+
+.. _media_subdev_config_model:
+
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 10

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+Sub-device configuration models
+===============================
+
+A sub-device configuration model specifies in detail what the user space can
+expect from a sub-device in terms of V4L2 sub-device interface support,
+including IOCTL (including selection targets and controls) semantics.

including IOCTLs, selection targets and controls semantics.

Quoted 2 lines

I think we could as well as drop these, i.e. just mention semantics.

ack

Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +3 -0
+
+A sub-device may implement more than one configuration model at the same
+time. The implemented configuration models can be obtained from the sub-device's

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 23

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+``V4L2_CID_CONFIG_MODEL`` control.
+
+.. _media_subdev_config_model_common_raw_sensor:
+
+Common raw camera sensor model
+------------------------------
+
+The common raw camera sensor model defines a set of enumeration and
+configuration interfaces (formats, selections etc.) that cover the vast majority
+of funcitionality of raw camera sensors. Not all of the interfaces are

s/funcitionality/functionalities

Quoted 2 lines

I'd say singular is right in this case. Maybe Kieran or Dave have an opinion as well? :-)

Then
s/funcitionality/functionality

:)

Quoted 62 lines
Quoted 58 lines
Quoted 45 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +43 -0
+necessarily offered by all drivers.
+
+A sub-device complies with the common raw sensor model if the
+``V4L2_CONFIG_MODEL_COMMON_RAW`` bit is set in the ``V4L2_CID_CONFIG_MODEL``
+control of the sub-device.
+
+The common raw camera sensor model is aligned with
+:ref:`media_using_camera_sensor_drivers`. Please refer to that regarding aspects
+not specified here.
+
+Each camera sensor implementing the common raw sensor model exposes a single
+V4L2 sub-device. The sub-device contains a single source pad (0) and two or more
+internal pads: an image data internal pad (1) and optionally an embedded data
+pad (2). Additionally, further internal pads may be supported for other
+features, in which case they are documented separately for the given device.
+
+This is shown in :ref:`media_subdev_config_model_common_raw_sensor_subdev`.
+
+.. _media_subdev_config_model_common_raw_sensor_subdev:
+
+.. kernel-figure:: common-raw-sensor.svg
+    :alt:    common-raw-sensor.svg
+    :align:  center
+
+    **Common raw sensor sub-device**
+
+Routes
+^^^^^^
+
+A sub-device conforming to common raw camera sensor model implements the
+following routes.
+
+.. flat-table:: Routes
+    :header-rows: 1
+
+    * - Sink pad/stream
+      - Source pad/stream
+      - Static (X/M(aybe)/-)
+      - Mandatory (X/-)
+      - Synopsis
+    * - 1/0
+      - 0/0
+      - X

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 76

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+      - X
+      - Image data
+    * - 2/0
+      - 0/1
+      - M
+      - \-
+      - Embedded data
+
+Some devices do not support the embedded data stream, others do support it and
+in some of the latter, it can be turned on and off before streaming is started.

What about:

Quoted 3 lines

Support for the embedded data stream is optional. Device that support the embedded data stream might allow to enable/disable the route before the streaming is started.

Quoted 6 lines

How about:

Support for the embedded data stream is optional. Drivers supporting the embedded data stream may allow disabling and enabling the route when the streaming is disabled.

Yeah, better

Quoted 11 lines
Quoted 10 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 82

Quoted 8 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+
+Sensor pixel array size, cropping and binning
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The sensor's pixel array is divided into one or more areas. The areas around the
+edge of the pixel array, usually one or more sides, may contain optical black

optically ?

Quoted 2 lines

E.g. CCS spec refers to these as "optical black" pixels.

ack then

Quoted 43 lines
Quoted 26 lines
Quoted 13 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +12 -0
+pixels, dummy pixels and other non-image pixels. The entire pixel array size is
+conveyed by the format on (pad, stream) pair 1/0.
+
+A rectangle within the pixel array contains the visible pixels. Capturing the
+non-visible pixels outside the visible pixel area may be supported by the
+sensor. The visible pixel area corresponds to the ``V4L2_SEL_TGT_CROP_DEFAULT``
+selection target on (pad, stream) pair 1/0.
+
+Sensors can perform multiple operations that affect the output image size. First
+of these is the analogue crop. Analogue crop limits the area of the pixel array
+which the sensor will read, affecting sensor timing as well. The granularity of
+the analogue crop configuration varies greatly across sensors: some sensors

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 104

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +10 -0
+support only a few different analogue crop configurations whereas others may
+support anything divisible by a given number of pixels. The analogue crop
+configuration corresponds the ``V4L2_SEL_TGT_CROP`` selection target on (pad,
+stream) pair 1/0. The default analogue crop rectangle corresponds to the visible
+pixel area.
+
+In the next step, binning is performed on the image data read from camera
+sensor's pixel array, as determined by the analogue crop configuration. Enabling
+binning will effectively result in an image smaller than the original by given
+binning factors horizontally and vertically. Typical values are 1/2 and 1/3 but

I thought 1/4 was more common than 1/3... Nevermind..

Quoted 16 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 116

Quoted 12 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +12 -0
+others may well be supported by the hardware as well.
+
+Sub-sampling follows binning. Sub-sampling, like binning, reduces the size of
+the image by including only a subset of samples read from the sensor's pixel
+matrix, typically every n'th pixel horizontally and vertically, taking the
+sensor's colour pattern into account. Sub-sampling is generally configurable
+separately horizontally and vertically.
+
+Binning and sub-sampling are configured using the ``V4L2_SEL_TGT_COMPOSE``
+rectangle, relative to the analogue crop rectangle, on (pad, stream) pair
+1/0. It depends on the driver which of these operations are being used to
+achieve the resulting size.

I would say "It depends on the driver implementation to decide how binning and skipping are combined to obtain the desired scaling ratio."

Quoted 6 lines

I wouldn't refer to this as scaling as we'll have specific scaling configuration elsewhere. How about:

The driver implementation determines how to configure binning and sub-sampling to achieve the desired size.

Fine with me indeed

Quoted 59 lines
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 120

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
+
+The digital crop operation takes place after binning and sub-sampling. It is
+configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
+0/0. The resulting image size is further output by the sensor.

This is not true anymore if we consider digital scaling and post-scaler crop.

Yes. I'll address this in the next patch.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 125

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+
+The sensor's output mbus code is configured by setting the format on the (pad,
+stream) pair 0/0. When setting the format, always use the same width and height
+as for the digital crop setting.
+

Same comment here as well.

Ditto.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 126

Quoted 2 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +1 -0
+Drivers may only support some of even none of these configurations, in which

s/configurations/configuration options/

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 127

Quoted 1 line
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +1 -0
+case they do not expose the corresponding selection rectangles. If any selection

How are selection rectangles "exposed" ?

Well, they are not imposed at least. :-)

Quoted 9 lines

I would say "support" instead of expose.

However I'm a bit concerned what "support" (or "expose") means. We should probably define it. I do think that driver should allow reading all the above selection rectangles and return the correct values (if a configuration step is not supported, sizes are simply passed forward from the previous selection target to the next target/format). I'm less sure about setting them, if they should error out or simply adjust it as get_selection() would have done.

Either could be used IMO. If something is not supported and the user tries to access it, the result is an error (-EINVAL in this case).

Quoted 12 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 132

Quoted 7 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+targets are omitted, the further selection rectangle or format is instead
+related to the previous implemented selection rectangle. For instance, if the
+sensor supports binning but not analogue crop, then the binning configuration
+(``V4L2_SEL_TGT_COMPOSE`` selection target) is done in relation to the visible
+pixel area (``V4L2_SEL_TGT_CROP_DEFAULT`` selection target).

Let alone the fact I would have used, say, digital crop as an example of an optional feature, I think allowing to read all the possible targets would save userspace keeping track of what target the rectangle they want to configure refers to.

Quoted 9 lines

This is how the selection API works. If we want to deviate from that, it's another thing, but currently if a driver doesn't support configuring a selection, it won't support that target either.

If we required all selection rectangles to be supported even if they wouldn't be configurable, then it'd be up to user to try to change them to see if they can be modified. I'm not sure if that would be an improvement as a whole.

Yeah, probably a set-then-verify-if-changed is more cumbersome than detecting an -EINVAL on set_selection.

I'm fine with this as long as all the mentioned targets are readable.

Quoted 64 lines

I wonder what Laurent thinks.

Quoted 53 lines
Quoted 53 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +52 -0
+
+Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
+
+.. flat-table:: Selection targets on pads
+    :header-rows: 1
+
+    * - Pad/Stream
+      - Selection target/format
+      - Mandatory (X/-)
+      - Modifiable (X/-)
+      - Synopsis
+    * - 1/0
+      - Format
+      - X
+      - \-
+      - Image data format. The width and the height fields indicates the full
+        size of the pixel array, including non-visible pixels. The media bus
+        code of this format reflects the native pixel depth of the sensor.
+    * - 1/0
+      - ``V4L2_SEL_TGT_CROP_DEFAULT``
+      - X
+      - \
+      - The visible pixel area. This rectangle is relative to the format on the
+        same (pad, stream).
+    * - 1/0
+      - ``V4L2_SEL_TGT_CROP``
+      - \-
+      - X
+      - Analogue crop. Analogue crop typically has a coarse granularity. This
+        rectangle is relative to the format on the same (pad, stream).
+    * - 1/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Binning and sub-sampling. This rectangle is relative to the
+        ``V4L2_SEL_TGT_CROP`` rectangle on the same (pad, stream). The
+        combination of binning and sub-sampling is configured using this
+        selection target.
+    * - 2/0
+      - Format
+      - X
+      - \-
+      - Embedded data format.
+    * - 0/0
+      - ``V4L2_SEL_TGT_CROP``
+      - \-
+      - X
+      - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
+        rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - Format
+      - X
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 189

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+      - X
+      - Image data source format. Always assign the width and height fields of
+        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+        rectangle on (pad, stream) pair 0/0. The media bus code reflects the
+        pixel data output of the sensor.

This makes me think it is intentional not to document digital scaling/post-scaler crop in this version ?

Quoted 5 lines

Not in this patch, no. :-)

I'm fine merging this to the 5th patch if there's an agreement they should be merged together (probably?).

I would probably merge the two, yes

Quoted 30 lines
Quoted 10 lines
Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +9 -0
+    * - 0/1
+      - Format
+      - X
+      - \-
+      - Embedded data source format.
+
+Embedded data
+^^^^^^^^^^^^^
+
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 204

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+The embedded data stream is produced by the sensor when the corresponding route
+is enabled. The embedded data route may also be immutable or not exist at all,
+in case the sensor (or the driver) does not support it.
+
+Generally the sensor embedded data width is determined by the width of the image
+data whereas the number of lines are constant for the embedded data. The user

Maybe drop "The" from "The user space" ?

I'd keep it as-is.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 208

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +4 -0
+space may obtain the size of the embedded data once the image data size on the
+source pad has been configured.
+
+Also see :ref:`media_using_camera_sensor_drivers_embedded_data`.

Thanks for the hard work here, I like how this new document clearly outlines the expected interfaces exposed by drivers.

Quoted 3 lines

Thank you. Hopefully we could all agree on this soonish and get libcamera support implemented so we could merge it all. :-)

Yep, very close now!

Thanks
j

Quoted 4 lines

--
Kind regards,

Sakari Ailus

#10 lore raw

Re: [RFC v3 4/9] media: Documentation: Add subdev configuration models, raw sensor model

Hi Jacopo,

Quoted 9 lines · Jacopo Mondi
Quoted 9 lines
Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 23

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +6 -0
+Common raw camera sensor model
+------------------------------
+
+The common raw camera sensor model defines a set of enumeration and
+configuration interfaces (formats, selections etc.) that cover the vast majority
+of funcitionality of raw camera sensors. Not all of the interfaces are

s/funcitionality/functionalities

Quoted 8 lines
Quoted 2 lines

I'd say singular is right in this case. Maybe Kieran or Dave have an opinion as well? :-)

Then
s/funcitionality/functionality

:)

Ah, indeed. ;-)

...

Quoted 21 lines
Quoted 11 lines
Quoted 10 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst line 132

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +5 -0
+targets are omitted, the further selection rectangle or format is instead
+related to the previous implemented selection rectangle. For instance, if the
+sensor supports binning but not analogue crop, then the binning configuration
+(``V4L2_SEL_TGT_COMPOSE`` selection target) is done in relation to the visible
+pixel area (``V4L2_SEL_TGT_CROP_DEFAULT`` selection target).

Let alone the fact I would have used, say, digital crop as an example of an optional feature, I think allowing to read all the possible targets would save userspace keeping track of what target the rectangle they want to configure refers to.

Quoted 9 lines

This is how the selection API works. If we want to deviate from that, it's another thing, but currently if a driver doesn't support configuring a selection, it won't support that target either.

If we required all selection rectangles to be supported even if they wouldn't be configurable, then it'd be up to user to try to change them to see if they can be modified. I'm not sure if that would be an improvement as a whole.

Quoted 4 lines

Yeah, probably a set-then-verify-if-changed is more cumbersome than detecting an -EINVAL on set_selection.

I'm fine with this as long as all the mentioned targets are readable.

Currently it's how this is documented in V4L2 sub-device UAPI
documentation: if you have nothing to configure, then there's no selection target either.

Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

This makes me think it is intentional not to document digital scaling/post-scaler crop in this version ?

Not in this patch, no. :-)

I'm fine merging this to the 5th patch if there's an agreement they should be merged together (probably?).

I would probably merge the two, yes

Ack. Let's wait for the discussion to conclude.

Signature · 3 lines
Kind regards,

Sakari Ailus
#11 lore raw

RFC v3 5/9 media: Documentation: Add scaling and post-scaler crop for common raw

In reply to Sakari Ailus

Document scaling and post-scaler digital crop operations for the common raw sensor model.

---
 .../media/v4l/subdev-config-model.rst         | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +15 -4
index 4ddf98e3143c..1ae20800f34b 100644
@@ -119,9 +119,13 @@ The digital crop operation takes place after binning and sub-sampling. It is
 configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
 0/0. The resulting image size is further output by the sensor.
 
+The digital scaling operation is performed after the digital crop. It is
+configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair
+0/0, relative to the digital crop.
+
 The sensor's output mbus code is configured by setting the format on the (pad,
-stream) pair 0/0. When setting the format, always use the same width and height
-as for the digital crop setting.
+stream) pair 0/0. The width and height fields are used to configure post-scaler
+digital crop, affecting the right side and the bottom of the frame.
 
 Drivers may only support some of even none of these configurations, in which
 case they do not expose the corresponding selection rectangles. If any selection
@@ -179,12 +183,19 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
       - X
       - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Scaling. This rectangle is relative to the ``V4L2_SEL_TGT_CROP``
+        rectangle on (pad, stream) pair 0/0.
     * - 0/0
       - Format
       - X
       - X
-      - Image data source format. Always assign the width and height fields of
-        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+      - Image data source format and post-scaler crop. The width and height
+        fields of the format, used to configure post-scaler crop on the right
+        and bottom edges of the image, are related to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 0/0. The media bus code reflects the
         pixel data output of the sensor.
     * - 0/1
Signature · 1 line
2.39.5
#12 lore raw

Re: [RFC v3 5/9] media: Documentation: Add scaling and post-scaler crop for common raw

Hi Sakari
thanks for the update

Quoted 12 lines · Sakari Ailus

Document scaling and post-scaler digital crop operations for the common raw sensor model.

---
 .../media/v4l/subdev-config-model.rst         | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +0 -0
index 4ddf98e3143c..1ae20800f34b 100644

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 120

Quoted 2 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +0 -0
@@ -119,9 +119,13 @@ The digital crop operation takes place after binning and sub-sampling. It is
 configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
 0/0. The resulting image size is further output by the sensor.

I think this last line "The resulting image size is further output by the sensor." doesn't apply anymore now that we have [digital crop + digital scaling + post-scaling crop].

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 125

Quoted 5 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +4 -0
+The digital scaling operation is performed after the digital crop. It is
+configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair
+0/0, relative to the digital crop.
+

"to the digital crop rectangle." maybe ?

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 129

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +2 -2
 The sensor's output mbus code is configured by setting the format on the (pad,
-stream) pair 0/0. When setting the format, always use the same width and height
-as for the digital crop setting.
+stream) pair 0/0. The width and height fields are used to configure post-scaler
+digital crop, affecting the right side and the bottom of the frame.
 

I would introduce the (optional) presence of an additional post-scaler digital crop step explicitly, also I get this is kind of rare feature, isn't it ?

-------------------------------------------------------------------------------
The digital scaling operation is performed after the digital crop. It is configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair 0/0, relative to the digital crop rectangle.

The sensor's output mbus code is configured by setting the format on the (pad, stream) pair 0/0. An optional post-scaler crop step might be performed by specifying a width and height smaller than the digital scaling rectangle. If post-scaler cropping is not supported the format's sizes will always match the compose rectangle sizes applied on the same 0/0 (pad, stream) pair.
-------------------------------------------------------------------------------

I didn't get when we spoke about it where the "affecting the right side and bottom of the frame" comes from when talking about post-scaler cropping.

Documentation/userspace-api/media/v4l/subdev-config-model.rst Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. · line 190

Quoted 11 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +5 -0
 Drivers may only support some of even none of these configurations, in which
 case they do not expose the corresponding selection rectangles. If any selection
@@ -179,12 +183,19 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
       - X
       - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Scaling. This rectangle is relative to the ``V4L2_SEL_TGT_CROP``

"Digital scaling" ? or is not necessary ?

Quoted 17 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +4 -3
+        rectangle on (pad, stream) pair 0/0.
     * - 0/0
       - Format
       - X
       - X
-      - Image data source format. Always assign the width and height fields of
-        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+      - Image data source format and post-scaler crop. The width and height
+        fields of the format, used to configure post-scaler crop on the right
+        and bottom edges of the image, are related to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 0/0. The media bus code reflects the
         pixel data output of the sensor.
     * - 0/1
--

2.39.5

#13 lore raw

Re: [RFC v3 5/9] media: Documentation: Add scaling and post-scaler crop for common raw

Hi Jacopo,

Thank you for the review.

Quoted 11 lines · Jacopo Mondi

Hi Sakari
thanks for the update

Quoted 7 lines · Sakari Ailus

Document scaling and post-scaler digital crop operations for the common raw sensor model.

---
 .../media/v4l/subdev-config-model.rst         | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Quoted 11 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 120

Quoted 7 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +0 -0
index 4ddf98e3143c..1ae20800f34b 100644
@@ -119,9 +119,13 @@ The digital crop operation takes place after binning and sub-sampling. It is
 configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
 0/0. The resulting image size is further output by the sensor.

I think this last line "The resulting image size is further output by the sensor." doesn't apply anymore now that we have [digital crop + digital scaling + post-scaling crop].

Indeed. I'll address this in v4.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 125

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +4 -0
+The digital scaling operation is performed after the digital crop. It is
+configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair
+0/0, relative to the digital crop.
+

"to the digital crop rectangle." maybe ?

Yes.

Quoted 18 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 129

Quoted 8 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +2 -2
 The sensor's output mbus code is configured by setting the format on the (pad,
-stream) pair 0/0. When setting the format, always use the same width and height
-as for the digital crop setting.
+stream) pair 0/0. The width and height fields are used to configure post-scaler
+digital crop, affecting the right side and the bottom of the frame.
 

I would introduce the (optional) presence of an additional post-scaler digital crop step explicitly, also I get this is kind of rare feature, isn't it ?

-------------------------------------------------------------------------------
The digital scaling operation is performed after the digital crop. It is configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair 0/0, relative to the digital crop rectangle.

Quoted 6 lines

The sensor's output mbus code is configured by setting the format on the (pad, stream) pair 0/0. An optional post-scaler crop step might be performed by specifying a width and height smaller than the digital scaling rectangle. If post-scaler cropping is not supported the format's sizes will always match the compose rectangle sizes applied on the same 0/0 (pad, stream) pair.

Right, even if the post-scaler crop is optional, the format is always there but unmodifiable (directly). I'd refer to driver support instead of somewhat nebulous "might be performed".

How about:

The sensor's output mbus code is configured by setting the format on the (pad, stream) pair 0/0. The width and height fields are used to configure post-scaler digital crop if supported by the driver, affecting the right and bottom edges of the frame. If post-scaler digital crop is not supported, the width and height fields of the format will match the compose rectangle sizes applied on the same 0/0 (pad, stream) pair.

Quoted 7 lines

-------------------------------------------------------------------------------

I didn't get when we spoke about it where the "affecting the right side and bottom of the frame" comes from when talking about post-scaler cropping.

Quoted 13 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. · line 190

Quoted 11 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +5 -0
 Drivers may only support some of even none of these configurations, in which
 case they do not expose the corresponding selection rectangles. If any selection
@@ -179,12 +183,19 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
       - X
       - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Scaling. This rectangle is relative to the ``V4L2_SEL_TGT_CROP``

"Digital scaling" ? or is not necessary ?

We don't mention it in the context of sub-sampling either. Digital and analogue variants are separately documented where they exist, I think this should be fine. What do you think?

Quoted 14 lines
Quoted 14 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +4 -2
+        rectangle on (pad, stream) pair 0/0.
     * - 0/0
       - Format
       - X
       - X
-      - Image data source format. Always assign the width and height fields of
-        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+      - Image data source format and post-scaler crop. The width and height
+        fields of the format, used to configure post-scaler crop on the right
+        and bottom edges of the image, are related to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 0/0. The media bus code reflects the
         pixel data output of the sensor.
     * - 0/1
Signature · 3 lines
Kind regards,

Sakari Ailus
#14 lore raw

Re: [RFC v3 5/9] media: Documentation: Add scaling and post-scaler crop for common raw

Hi Sakari

Quoted 70 lines · Sakari Ailus

Hi Jacopo,

Thank you for the review.

Quoted 11 lines · Jacopo Mondi

Hi Sakari
thanks for the update

Quoted 7 lines · Sakari Ailus

Document scaling and post-scaler digital crop operations for the common raw sensor model.

---
 .../media/v4l/subdev-config-model.rst         | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Quoted 11 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 120

Quoted 7 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +0 -0
index 4ddf98e3143c..1ae20800f34b 100644
@@ -119,9 +119,13 @@ The digital crop operation takes place after binning and sub-sampling. It is
 configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
 0/0. The resulting image size is further output by the sensor.

I think this last line "The resulting image size is further output by the sensor." doesn't apply anymore now that we have [digital crop + digital scaling + post-scaling crop].

Indeed. I'll address this in v4.

Quoted 8 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 125

Quoted 6 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +4 -0
+The digital scaling operation is performed after the digital crop. It is
+configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair
+0/0, relative to the digital crop.
+

"to the digital crop rectangle." maybe ?

Yes.

Quoted 18 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst The digital crop operation takes place after binning and sub-sampling. It is · line 129

Quoted 8 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +2 -2
 The sensor's output mbus code is configured by setting the format on the (pad,
-stream) pair 0/0. When setting the format, always use the same width and height
-as for the digital crop setting.
+stream) pair 0/0. The width and height fields are used to configure post-scaler
+digital crop, affecting the right side and the bottom of the frame.
 

I would introduce the (optional) presence of an additional post-scaler digital crop step explicitly, also I get this is kind of rare feature, isn't it ?

-------------------------------------------------------------------------------
The digital scaling operation is performed after the digital crop. It is configured by setting the ``V4L2_SEL_TGT_COMPOSE`` rectangle on (pad, stream) pair 0/0, relative to the digital crop rectangle.

Quoted 6 lines

The sensor's output mbus code is configured by setting the format on the (pad, stream) pair 0/0. An optional post-scaler crop step might be performed by specifying a width and height smaller than the digital scaling rectangle. If post-scaler cropping is not supported the format's sizes will always match the compose rectangle sizes applied on the same 0/0 (pad, stream) pair.

Right, even if the post-scaler crop is optional, the format is always there but unmodifiable (directly). I'd refer to driver support instead of somewhat nebulous "might be performed".

Quoted 9 lines

How about:

The sensor's output mbus code is configured by setting the format on the (pad, stream) pair 0/0. The width and height fields are used to configure post-scaler digital crop if supported by the driver, affecting the right and bottom edges of the frame. If post-scaler digital crop is not supported, the width and height fields of the format will match the compose rectangle sizes applied on the same 0/0 (pad, stream) pair.

Fine indeed!

Quoted 21 lines
Quoted 7 lines

-------------------------------------------------------------------------------

I didn't get when we spoke about it where the "affecting the right side and bottom of the frame" comes from when talking about post-scaler cropping.

Quoted 13 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. · line 190

Quoted 11 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +5 -0
 Drivers may only support some of even none of these configurations, in which
 case they do not expose the corresponding selection rectangles. If any selection
@@ -179,12 +183,19 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
       - X
       - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Scaling. This rectangle is relative to the ``V4L2_SEL_TGT_CROP``

"Digital scaling" ? or is not necessary ?

Quoted 4 lines

We don't mention it in the context of sub-sampling either. Digital and analogue variants are separately documented where they exist, I think this should be fine. What do you think?

I'm fine, after all there's no "analogue scaling" this can be confused with, right ?

Quoted 20 lines
Quoted 14 lines
Quoted 4 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +1 -0
+        rectangle on (pad, stream) pair 0/0.
     * - 0/0
       - Format

Documentation/userspace-api/media/v4l/subdev-config-model.rst Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. · line 201

Quoted 10 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +3 -2
       - X
       - X
-      - Image data source format. Always assign the width and height fields of
-        the format to the same values than for the ``V4L2_SEL_TGT_CROP``
+      - Image data source format and post-scaler crop. The width and height
+        fields of the format, used to configure post-scaler crop on the right
+        and bottom edges of the image, are related to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 0/0. The media bus code reflects the
         pixel data output of the sensor.
     * - 0/1

--
Kind regards,

Sakari Ailus

#15 lore raw

Re: [RFC v3 5/9] media: Documentation: Add scaling and post-scaler crop for common raw

Hi Jacopo,

Quoted 12 lines · Jacopo Mondi
Quoted 12 lines
Quoted 11 lines

Documentation/userspace-api/media/v4l/subdev-config-model.rst Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. · line 190

Quoted 9 lines
Documentation/userspace-api/media/v4l/subdev-config-model.rst +5 -0
@@ -179,12 +183,19 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
       - X
       - Digital crop. This rectangle is relative to the ``V4L2_SEL_TGT_COMPOSE``
         rectangle on (pad, stream) pair 1/0.
+    * - 0/0
+      - ``V4L2_SEL_TGT_COMPOSE``
+      - \-
+      - X
+      - Scaling. This rectangle is relative to the ``V4L2_SEL_TGT_CROP``

"Digital scaling" ? or is not necessary ?

Quoted 7 lines
Quoted 4 lines

We don't mention it in the context of sub-sampling either. Digital and analogue variants are separately documented where they exist, I think this should be fine. What do you think?

I'm fine, after all there's no "analogue scaling" this can be confused with, right ?

Correct.

Signature · 1 line
Sakari Ailus
#16 lore raw

RFC v3 6/9 media: uapi: Add V4L2_CID_CONFIG_MODEL control

In reply to Sakari Ailus

Add the V4L2_CID_CONFIG_MODEL control for the configuration model.

---
 .../userspace-api/media/v4l/ext-ctrls-image-process.rst      | 4 ++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c                    | 5 +++++
 include/uapi/linux/v4l2-controls.h                           | 3 +++
 3 files changed, 12 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst +4 -0
index 27803dca8d3e..928e8e3eed7f 100644
@@ -55,3 +55,7 @@ Image Process Control IDs
     control value divided by e.g. 0x100, meaning that to get no
     digital gain the control value needs to be 0x100. The no-gain
     configuration is also typically the default.
+
+``V4L2_CID_CONFIG_MODEL (bitmask)``
+    Which configuration models the sub-device supports. Please see
+    :ref:`media_subdev_config_model`.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +5 -0
index 1ea52011247a..24c9c25e20d1 100644
@@ -1164,6 +1164,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_TEST_PATTERN:		return "Test Pattern";
 	case V4L2_CID_DEINTERLACING_MODE:	return "Deinterlacing Mode";
 	case V4L2_CID_DIGITAL_GAIN:		return "Digital Gain";
+	case V4L2_CID_CONFIG_MODEL:		return "Sub-device configuration model";
 
 	/* DV controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1481,6 +1482,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DV_RX_POWER_PRESENT:
 		*type = V4L2_CTRL_TYPE_BITMASK;
 		break;
+	case V4L2_CID_CONFIG_MODEL:
+		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
+		*type = V4L2_CTRL_TYPE_BITMASK;
+		break;
 	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
 	case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
 		*type = V4L2_CTRL_TYPE_INTEGER;
include/uapi/linux/v4l2-controls.h +3 -0
index 974fd254e573..0152240229ab 100644
@@ -1225,6 +1225,9 @@ enum v4l2_jpeg_chroma_subsampling {
 #define V4L2_CID_TEST_PATTERN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
 #define V4L2_CID_DEINTERLACING_MODE		(V4L2_CID_IMAGE_PROC_CLASS_BASE + 4)
 #define V4L2_CID_DIGITAL_GAIN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 5)
+#define V4L2_CID_CONFIG_MODEL			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 6)
+
+#define V4L2_CID_CONFIG_MODEL_COMMON_RAW	(1ULL << 0)
 
 /*  DV-class control IDs defined by V4L2 */
 #define V4L2_CID_DV_CLASS_BASE			(V4L2_CTRL_CLASS_DV | 0x900)
Signature · 1 line
2.39.5
Reviewed-by on v3 6/9
#17 lore raw

Re: [RFC v3 6/9] media: uapi: Add V4L2_CID_CONFIG_MODEL control

Hi Sakari

Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst

Quoted 14 lines · Sakari Ailus

Add the V4L2_CID_CONFIG_MODEL control for the configuration model.

---
 .../userspace-api/media/v4l/ext-ctrls-image-process.rst      | 4 ++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c                    | 5 +++++
 include/uapi/linux/v4l2-controls.h                           | 3 +++
 3 files changed, 12 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst +0 -0
index 27803dca8d3e..928e8e3eed7f 100644

I was initially not sure this belongs to "Image process" controls, but having had a look at the existing ones I'm not sure there are better places.

I would have considered "Camera Controls" but I'm not sure it's -that- better

Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst Image Process Control IDs · line 61

Quoted 8 lines
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst +4 -0
@@ -55,3 +55,7 @@ Image Process Control IDs
     control value divided by e.g. 0x100, meaning that to get no
     digital gain the control value needs to be 0x100. The no-gain
     configuration is also typically the default.
+
+``V4L2_CID_CONFIG_MODEL (bitmask)``
+    Which configuration models the sub-device supports. Please see
+    :ref:`media_subdev_config_model`.

Other RO controls in the file (such as PIXEL_RATE) specify "this control is read-only"

Quoted 28 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +5 -0
index 1ea52011247a..24c9c25e20d1 100644
@@ -1164,6 +1164,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_TEST_PATTERN:		return "Test Pattern";
 	case V4L2_CID_DEINTERLACING_MODE:	return "Deinterlacing Mode";
 	case V4L2_CID_DIGITAL_GAIN:		return "Digital Gain";
+	case V4L2_CID_CONFIG_MODEL:		return "Sub-device configuration model";
 
 	/* DV controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1481,6 +1482,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DV_RX_POWER_PRESENT:
 		*type = V4L2_CTRL_TYPE_BITMASK;
 		break;
+	case V4L2_CID_CONFIG_MODEL:
+		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
+		*type = V4L2_CTRL_TYPE_BITMASK;
+		break;
 	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
 	case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
 		*type = V4L2_CTRL_TYPE_INTEGER;
include/uapi/linux/v4l2-controls.h +0 -0
index 974fd254e573..0152240229ab 100644

include/uapi/linux/v4l2-controls.h enum v4l2_jpeg_chroma_subsampling { · line 1230

Quoted 6 lines
include/uapi/linux/v4l2-controls.h +3 -0
@@ -1225,6 +1225,9 @@ enum v4l2_jpeg_chroma_subsampling {
 #define V4L2_CID_TEST_PATTERN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
 #define V4L2_CID_DEINTERLACING_MODE		(V4L2_CID_IMAGE_PROC_CLASS_BASE + 4)
 #define V4L2_CID_DIGITAL_GAIN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 5)
+#define V4L2_CID_CONFIG_MODEL			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 6)
+
+#define V4L2_CID_CONFIG_MODEL_COMMON_RAW	(1ULL << 0)

I wonder if "COMMON_" couldn't be removed.

Anyway, all nits or mostly questions, whatever is fine really

Thanks
j

Quoted 7 lines
include/uapi/linux/v4l2-controls.h +0 -1
 /*  DV-class control IDs defined by V4L2 */
 #define V4L2_CID_DV_CLASS_BASE			(V4L2_CTRL_CLASS_DV | 0x900)
--

2.39.5

#18 lore raw

Re: [RFC v3 6/9] media: uapi: Add V4L2_CID_CONFIG_MODEL control

Hi Jacopo,

Quoted 13 lines · Jacopo Mondi

Hi Sakari

Quoted 10 lines · Sakari Ailus

Add the V4L2_CID_CONFIG_MODEL control for the configuration model.

---
 .../userspace-api/media/v4l/ext-ctrls-image-process.rst      | 4 ++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c                    | 5 +++++
 include/uapi/linux/v4l2-controls.h                           | 3 +++
 3 files changed, 12 insertions(+)
Quoted 8 lines

Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst +0 -0
index 27803dca8d3e..928e8e3eed7f 100644

I was initially not sure this belongs to "Image process" controls, but having had a look at the existing ones I'm not sure there are better places.

Good question. Let's keep it here for the time being. I'm not sure any other extended control class is a better target. Maybe old user controls? I wonder what Hans would think.

Quoted 4 lines

I would have considered "Camera Controls" but I'm not sure it's -that- better

Quoted 11 lines

Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst Image Process Control IDs · line 61

Quoted 8 lines
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst +4 -0
@@ -55,3 +55,7 @@ Image Process Control IDs
     control value divided by e.g. 0x100, meaning that to get no
     digital gain the control value needs to be 0x100. The no-gain
     configuration is also typically the default.
+
+``V4L2_CID_CONFIG_MODEL (bitmask)``
+    Which configuration models the sub-device supports. Please see
+    :ref:`media_subdev_config_model`.

Other RO controls in the file (such as PIXEL_RATE) specify "this control is read-only"

I'll add that.

Quoted 29 lines
Quoted 29 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +5 -0
index 1ea52011247a..24c9c25e20d1 100644
@@ -1164,6 +1164,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_TEST_PATTERN:		return "Test Pattern";
 	case V4L2_CID_DEINTERLACING_MODE:	return "Deinterlacing Mode";
 	case V4L2_CID_DIGITAL_GAIN:		return "Digital Gain";
+	case V4L2_CID_CONFIG_MODEL:		return "Sub-device configuration model";
 
 	/* DV controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1481,6 +1482,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DV_RX_POWER_PRESENT:
 		*type = V4L2_CTRL_TYPE_BITMASK;
 		break;
+	case V4L2_CID_CONFIG_MODEL:
+		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
+		*type = V4L2_CTRL_TYPE_BITMASK;
+		break;
 	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
 	case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
 		*type = V4L2_CTRL_TYPE_INTEGER;
include/uapi/linux/v4l2-controls.h +0 -0
index 974fd254e573..0152240229ab 100644
@@ -1225,6 +1225,9 @@ enum v4l2_jpeg_chroma_subsampling {
Quoted 8 lines

include/uapi/linux/v4l2-controls.h enum v4l2_jpeg_chroma_subsampling { · line 1230

Quoted 6 lines
include/uapi/linux/v4l2-controls.h +3 -0
 #define V4L2_CID_TEST_PATTERN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
 #define V4L2_CID_DEINTERLACING_MODE		(V4L2_CID_IMAGE_PROC_CLASS_BASE + 4)
 #define V4L2_CID_DIGITAL_GAIN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 5)
+#define V4L2_CID_CONFIG_MODEL			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 6)
+
+#define V4L2_CID_CONFIG_MODEL_COMMON_RAW	(1ULL << 0)

I wonder if "COMMON_" couldn't be removed.

We might have different models for raw sensors. These are just for the current ones but new ones will have new functionality and we may need to make changes that won't be compliant. Maybe in that case we'd have v2 or something though.

Quoted 3 lines

Anyway, all nits or mostly questions, whatever is fine really

Thank you!

Signature · 3 lines
Kind regards,

Sakari Ailus
#19 lore raw

RFC v3 7/9 media: uapi: Add V4L2_CID_BINNING control for binning configuration

In reply to Sakari Ailus

Add V4L2_CID_BINNING control for configuting binning and enumerating a camera sensor's binning capabilities. The control combines horizontal and vertical binning into a single control as the two are generally related.

New drivers should use this control to configure binning.

---
 .../media/drivers/camera-sensor.rst           | 10 +++++++
 .../media/v4l/ext-ctrls-camera.rst            | 29 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  1 +
 4 files changed, 42 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +10 -0
index 5bc4c79d230c..c6167c91f46c 100644
@@ -107,6 +107,16 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
+Binning
+-------
+
+Binning has traditionally been configured using :ref:`the compose selection
+rectangle <v4l2-selection-targets-table>`. The :ref:`V4L2_CID_BINNING
+<v4l2-cid-camera-sensor-binning>` is also available for binning configuration and
+users should use it when it's available. Drivers supporting the control shall
+also support the compose rectangle, albeit the rectangle may be read-only when
+the control is present.
+
 .. _media_using_camera_sensor_drivers_embedded_data:
 
 Embedded data
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +29 -0
index cdc515c60468..3fbab0e78719 100644
@@ -672,3 +672,32 @@ enum v4l2_scene_mode -
 
     As modes differ for each sensor, menu items are not standardized by this
     control and are left to the programmer.
+
+.. _v4l2-cid-camera-sensor-binning:
+
+``V4L2_CID_BINNING (integer menu)``
+
+    Horizontal and vertical binning factors. Binning combines several
+    horizontal, vertical or both pixel values into a single pixel. It is a way
+    to scale an image. Binning typically produces fairly good quality output.
+
+    Determines both horizontal and vertical binning factors for a camera
+    sensor. The values are encoded in the following way:
+
+.. flat-table::
+    :header-rows:  1
+    :stub-columns: 0
+
+    * - Bits
+      - Synopsis
+    * - 48--63
+      - Horizontal binning numerator.
+    * - 32--47
+      - Horizontal binning denominator.
+    * - 16--31
+      - Vertical binning numerator.
+    * - 0--15
+      - Vertical binning denominator.
+
+For instance, a value of ``0x0001000300020003`` indicates binning by 3
+(horizontally) * 3/2 (vertically).
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 24c9c25e20d1..3a84051ec11c 100644
@@ -1087,6 +1087,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_CAMERA_ORIENTATION:	return "Camera Orientation";
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
 	case V4L2_CID_HDR_SENSOR_MODE:		return "HDR Sensor Mode";
+	case V4L2_CID_BINNING:			return "Binning Factors";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1424,6 +1425,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_HDR_SENSOR_MODE:
 		*type = V4L2_CTRL_TYPE_MENU;
 		break;
+	case V4L2_CID_BINNING:
 	case V4L2_CID_LINK_FREQ:
 		*type = V4L2_CTRL_TYPE_INTEGER_MENU;
 		break;
include/uapi/linux/v4l2-controls.h +1 -0
index 0152240229ab..8d5815a058d7 100644
@@ -1088,6 +1088,7 @@ enum v4l2_auto_focus_range {
 #define V4L2_CID_CAMERA_SENSOR_ROTATION		(V4L2_CID_CAMERA_CLASS_BASE+35)
 
 #define V4L2_CID_HDR_SENSOR_MODE		(V4L2_CID_CAMERA_CLASS_BASE+36)
+#define V4L2_CID_BINNING_FACTORS		(V4L2_CID_CAMERA_CLASS_BASE+37)
 
 /* FM Modulator class control IDs */
 
Signature · 1 line
2.39.5
#20 lore raw

Re: [RFC v3 7/9] media: uapi: Add V4L2_CID_BINNING control for binning configuration

Hi Sakari

Quoted 5 lines · Sakari Ailus

Add V4L2_CID_BINNING control for configuting binning and enumerating a camera sensor's binning capabilities. The control combines horizontal and vertical binning into a single control as the two are generally related.

New drivers should use this control to configure binning.

I thought the idea was to post-pone this (and the following 2 patches) to when controls will be able to be tested without changing the device configuration, to properly support TRY_FORMAT, and before that time work with selection rectangles and let the drivers select the "correct" binning/scaling factors deduced from the TGT_CROP-to-TGT_COMPOSE ratio on (pad, stream) 1/0

Quoted 103 lines
---
 .../media/drivers/camera-sensor.rst           | 10 +++++++
 .../media/v4l/ext-ctrls-camera.rst            | 29 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  1 +
 4 files changed, 42 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +10 -0
index 5bc4c79d230c..c6167c91f46c 100644
@@ -107,6 +107,16 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
+Binning
+-------
+
+Binning has traditionally been configured using :ref:`the compose selection
+rectangle <v4l2-selection-targets-table>`. The :ref:`V4L2_CID_BINNING
+<v4l2-cid-camera-sensor-binning>` is also available for binning configuration and
+users should use it when it's available. Drivers supporting the control shall
+also support the compose rectangle, albeit the rectangle may be read-only when
+the control is present.
+
 .. _media_using_camera_sensor_drivers_embedded_data:
 
 Embedded data
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +29 -0
index cdc515c60468..3fbab0e78719 100644
@@ -672,3 +672,32 @@ enum v4l2_scene_mode -
 
     As modes differ for each sensor, menu items are not standardized by this
     control and are left to the programmer.
+
+.. _v4l2-cid-camera-sensor-binning:
+
+``V4L2_CID_BINNING (integer menu)``
+
+    Horizontal and vertical binning factors. Binning combines several
+    horizontal, vertical or both pixel values into a single pixel. It is a way
+    to scale an image. Binning typically produces fairly good quality output.
+
+    Determines both horizontal and vertical binning factors for a camera
+    sensor. The values are encoded in the following way:
+
+.. flat-table::
+    :header-rows:  1
+    :stub-columns: 0
+
+    * - Bits
+      - Synopsis
+    * - 48--63
+      - Horizontal binning numerator.
+    * - 32--47
+      - Horizontal binning denominator.
+    * - 16--31
+      - Vertical binning numerator.
+    * - 0--15
+      - Vertical binning denominator.
+
+For instance, a value of ``0x0001000300020003`` indicates binning by 3
+(horizontally) * 3/2 (vertically).
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 24c9c25e20d1..3a84051ec11c 100644
@@ -1087,6 +1087,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_CAMERA_ORIENTATION:	return "Camera Orientation";
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
 	case V4L2_CID_HDR_SENSOR_MODE:		return "HDR Sensor Mode";
+	case V4L2_CID_BINNING:			return "Binning Factors";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1424,6 +1425,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_HDR_SENSOR_MODE:
 		*type = V4L2_CTRL_TYPE_MENU;
 		break;
+	case V4L2_CID_BINNING:
 	case V4L2_CID_LINK_FREQ:
 		*type = V4L2_CTRL_TYPE_INTEGER_MENU;
 		break;
include/uapi/linux/v4l2-controls.h +1 -1
index 0152240229ab..8d5815a058d7 100644
@@ -1088,6 +1088,7 @@ enum v4l2_auto_focus_range {
 #define V4L2_CID_CAMERA_SENSOR_ROTATION		(V4L2_CID_CAMERA_CLASS_BASE+35)
 
 #define V4L2_CID_HDR_SENSOR_MODE		(V4L2_CID_CAMERA_CLASS_BASE+36)
+#define V4L2_CID_BINNING_FACTORS		(V4L2_CID_CAMERA_CLASS_BASE+37)
 
 /* FM Modulator class control IDs */
 
--

2.39.5

#21 lore raw

Re: [RFC v3 7/9] media: uapi: Add V4L2_CID_BINNING control for binning configuration

Hi Jacopo,

Quoted 7 lines · Jacopo Mondi

Hi Sakari

Quoted 4 lines · Sakari Ailus

Add V4L2_CID_BINNING control for configuting binning and enumerating a camera sensor's binning capabilities. The control combines horizontal and vertical binning into a single control as the two are generally related.

Quoted 8 lines
Quoted 1 line

New drivers should use this control to configure binning.

I thought the idea was to post-pone this (and the following 2 patches) to when controls will be able to be tested without changing the device configuration, to properly support TRY_FORMAT, and before that time work with selection rectangles and let the drivers select the "correct" binning/scaling factors deduced from the TGT_CROP-to-TGT_COMPOSE ratio on (pad, stream) 1/0

As I wrote on the cover letter, some of the patches in the set will likely be postponed. Most likely this will mean the binning and sub-sampling control patches. I still wanted to include them so we'd give some view on how this would look like once we have control values in sub-device state.

Signature · 3 lines
Kind regards,

Sakari Ailus
#22 lore raw

RFC v3 8/9 media: uapi: Add controls for sub-sampling configuration

In reply to Sakari Ailus

Sub-sampling is a way to decrease the data rates after the pixel array by systematically discarding some samples, either vertically or horizontally or both. Add two controls for the purpose and document them. The sub-sampling configuration is taken into account in the compose rectangle.

---
 .../userspace-api/media/drivers/camera-sensor.rst  | 14 ++++++++++++--
 .../userspace-api/media/v4l/ext-ctrls-camera.rst   | 11 +++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c          |  2 ++
 include/uapi/linux/v4l2-controls.h                 |  2 ++
 4 files changed, 27 insertions(+), 2 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +12 -2
index c6167c91f46c..e65e82c5940a 100644
@@ -107,8 +107,8 @@ values programmed by the register sequences. The default values of these
 controls shall be 0 (disabled). Especially these controls shall not be inverted,
 independently of the sensor's mounting rotation.
 
-Binning
--------
+Binning and sub-sampling
+------------------------
 
 Binning has traditionally been configured using :ref:`the compose selection
 rectangle <v4l2-selection-targets-table>`. The :ref:`V4L2_CID_BINNING
@@ -117,6 +117,16 @@ users should use it when it's available. Drivers supporting the control shall
 also support the compose rectangle, albeit the rectangle may be read-only when
 the control is present.
 
+Sub-sampling is often supported as part of a camera sensor's binning
+functionality and performed after the binning operation. Sub-sampling typically
+produces quality-wise worse results than binning. Sub-sampling factors are
+independent horizontally and vertically and they are controlled using two
+controls, :ref:`V4L2_CID_SUBSAMPLING_HORIZONTAL and
+V4L2_CID_SUBSAMPLING_VERTICAL <v4l2-cid-camera-sensor-subsampling>`. In
+sub-sampling, the image size before sub-sampling is horizontally and vertically
+divided by the respective sub-sampling factors. Drivers supporting the control shall
+also reflect the sub-sampling configuration in the compose rectangle.
+
 .. _media_using_camera_sensor_drivers_embedded_data:
 
 Embedded data
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +11 -0
index 3fbab0e78719..38fa97397793 100644
@@ -701,3 +701,14 @@ enum v4l2_scene_mode -
 
 For instance, a value of ``0x0001000300020003`` indicates binning by 3
 (horizontally) * 3/2 (vertically).
+
+.. _v4l2-cid-camera-sensor-subsampling:
+
+``V4L2_CID_SUBSAMPLING_HORIZONTAL`` and ``V4L2_CID_SUBSAMPLING_VERTICAL``
+(integer)
+
+    Horizontal and vertical subsampling factors.
+
+    Sub-sampling is used to downscale an image, horizontally and vertically, by
+    discarding a part of the image data. Typically sub-sampling produces lower
+    quality images than binning.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 3a84051ec11c..62d19b09fd6d 100644
@@ -1088,6 +1088,8 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
 	case V4L2_CID_HDR_SENSOR_MODE:		return "HDR Sensor Mode";
 	case V4L2_CID_BINNING:			return "Binning Factors";
+	case V4L2_CID_SUBSAMPLING_HORIZONTAL:	return "Sub-Sampling Factor, Horizontal";
+	case V4L2_CID_SUBSAMPLING_VERTICAL:	return "Sub-Sampling Factor, Vertical";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
include/uapi/linux/v4l2-controls.h +2 -0
index 8d5815a058d7..e85747e2181b 100644
@@ -1089,6 +1089,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_HDR_SENSOR_MODE		(V4L2_CID_CAMERA_CLASS_BASE+36)
 #define V4L2_CID_BINNING_FACTORS		(V4L2_CID_CAMERA_CLASS_BASE+37)
+#define V4L2_CID_SUBSAMPLING_HORIZONTAL		(V4L2_CID_CAMERA_CLASS_BASE+38)
+#define V4L2_CID_SUBSAMPLING_VERTICAL		(V4L2_CID_CAMERA_CLASS_BASE+39)
 
 /* FM Modulator class control IDs */
 
Signature · 1 line
2.39.5
#23 lore raw

RFC v3 9/9 media: Documentation: Add binning and sub-sampling controls

In reply to Sakari Ailus

Document the binning and scaling controls (V4L2_CID_BINNING and V4L2_CID_SUBSAMPLING_{HORIZONTAL,VERTICAL}) in the common raw sensor model.

---
 .../media/v4l/subdev-config-model.rst           | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +13 -4
index 1ae20800f34b..06a94ff4d2b4 100644
@@ -113,7 +113,10 @@ separately horizontally and vertically.
 Binning and sub-sampling are configured using the ``V4L2_SEL_TGT_COMPOSE``
 rectangle, relative to the analogue crop rectangle, on (pad, stream) pair
 1/0. It depends on the driver which of these operations are being used to
-achieve the resulting size.
+achieve the resulting size. Binning and sub-sampling are also directly
+configured using :ref:`V4L2_CID_BINNING <v4l2-cid-camera-sensor-binning>` and
+:ref:`V4L2_CID_SUBSAMPLING_HORIZONTAL and V4L2_CID_SUBSAMPLING_VERTICAL
+<v4l2-cid-camera-sensor-subsampling>` controls on drivers that support them.
 
 The digital crop operation takes place after binning and sub-sampling. It is
 configured by setting the ``V4L2_SEL_TGT_CROP`` rectangle on (pad, stream) pair
@@ -169,9 +172,15 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`.
       - \-
       - X
       - Binning and sub-sampling. This rectangle is relative to the
-        ``V4L2_SEL_TGT_CROP`` rectangle on the same (pad, stream). The
-        combination of binning and sub-sampling is configured using this
-        selection target.
+        ``V4L2_SEL_TGT_CROP`` rectangle on the same (pad, stream). Binning is
+        configured using the :ref:`V4L2_CID_BINNING
+        <v4l2-cid-camera-sensor-binning>` control and sub-sampling is configured
+        using the :ref:`V4L2_CID_SUBSAMPLING_HORIZONTAL and
+        V4L2_CID_SUBSAMPLING_VERTICAL <v4l2-cid-camera-sensor-subsampling>`
+        controls on drivers that support these controls. To configure binning
+        and sub-sampling on drivers that do not support these controls, the
+        selection rectangle may be changed directly to configure the combined
+        effect on the image size.
     * - 2/0
       - Format
       - X
Signature · 1 line
2.39.5