Generic line based metadata support, internal pads
Subsystems (10)
Sakari Ailus
maintainerv13 cover Generic line based metadata support, internal pads
Hi folks,
Here are a few patches to add support generic, line based metadata as well as internal pads, sub-device configuration models (including the common raw sensor model) and a streaming control helper for MC-enabled drivers. The amount of code and documentation is in this version is no longer small but it still requires some explaining.
Metadata mbus codes and formats have existed for some time in V4L2. They however have been only used by drivers that produce the data itself and effectively this metadata has always been statistics of some sort (at least when it comes to ISPs). What is different here is that we intend to add support for metadata originating from camera sensors.
Camera sensors produce different kinds of metadata, embedded data (usually register address--value pairs used to capture the frame, in a more or less sensor specific format), histograms (in a very sensor specific format), dark pixels etc. The number of these formats is probably going to be about as large as image data formats if not larger, as the image data formats are much better standardised but a smaller subset of them will be supported by V4L2, at least initially but possibly much more in the long run.
Having this many device specific formats would be a major problem for all the other drivers along that pipeline (not to mention the users of those drivers), including bridge (e.g. CSI-2 to parallel) but especially CSI-2 receiver drivers that have DMA: the poor driver developer would not only need to know camera sensor specific formats but to choose the specific packing of that format suitable for the DMA used by the hardware. It is unlikely many of these would ever get tested while being present on the driver API. Also adding new sensors with new embedded data formats would involve updating all bridge and CSI-2 receiver drivers. I don't expect this to be a workable approach.
Instead what I'm proposing is to use controls to convey the colour pattern and metadata layout. Generic mbus codes convey the width of the data transferred on serial buses (for now, corresponding parallel formats may be added when needed) but the control is only relevant on the UAPI, not between drivers. This approach unsnarls the layout of the data and its colour components, defining what data there is (specific mbus code) and how that is transported and packed (generic mbus codes and V4L2 formats) separately.
The user space would be required to "know" the path of that data from the sensor's internal pad to the V4L2 video node. I do not see this as these devices require at least some knowledge of the pipeline, i.e. hardware at hand. Separating what the data means and how it is packed may even be
beneficial: it allows separating code that interprets the data (sensor internal mbus code) from the code that accesses it (packing).
These formats are in practice line based, meaning that there may be padding at the end of the line, depending on the bus as well as the DMA. If non-line based formats are needed, it is always possible to set the "height" field to 1.
Internal sink pads behave mostly like regular sink pads, but they describe a flow of data that originates from a sub-device instead of arriving to a sub-device. The SUBDEV_S_ROUTING IOCTLs are used to enable and disable routes from internal sink pads to sub-device's source pads. The subdev format IOCTLs are usable, too, so one can find which subdev format is available on given internal sink pad.
I've tested the patches using the IPU6 / ov2740 pair of drivers as well as Unicam / imx219.
Questions and comments are most welcome.
Preliminary media-ctl and yavta patches can be found here:
<URL:https://git.retiisi.eu/?p=~sailus/yavta.git;a=shortlog;h=refs/heads/metadata> <URL:https://git.retiisi.eu/?p=~sailus/v4l-utils.git;a=shortlog;h=refs/heads/metadata>
The patches are on my metadata branch <URL:https://git.linuxtv.org/sailus/media_tree.git/log/>.
The documentation build output can be found here:
<URL:https://www.retiisi.eu/~sailus/v4l2/tmp/metadata/>.
since v12:
- Merged ipu6 patches.
- Merged client_info changes.
- Improve internal sink pad documentation.
- Add subdev-config-model rst file to index directly.
- Improve HBLANK and VBLANK control documentation.
- Use hexadecimal numbers for CFA pattern numbers and add a MONO pattern.
- Fix binning integer menu value example.
- Add unpacked raw pixelformats for 10, 12 and 14 bpp.
- Document the compose rectangle isn't modifiable in Common Raw Sensor Model.
- Fix selection rectangle values for imx219.
- Do not maintain streaming state locally in imx219.
- Dropped a local handler for LLP and FLL controls in imx219; use generic v4l2_sensor_fll_llp_set() instead (moved from v4l2-mc.c to v4l2-common.c).
- Grab binning control during streaming in imx219.
- Use factual (i.e. non-register) values for FLL, LLP and PIXEL_RATE.
- Call client_caps caps instead in struct v4l2_subdev_client_info.
- Drop the VALIDATE_LATE MC link flag.
- Drop v4l2_subdev_call_ci_state_try() and v4l2_subdev_call_ci_state_active(); instead move the code in drivers (one for each) and so avoid interesting-looking macros in v4l2-subdev.h.
- Include Frank's patch for media bus format info.
- Check client caps when accessing internal pads.
- Move out the patches to obtain frame descriptors. They can wait.
- Use __u* types in macros working with binning factors in v4l2-controls.h.
since v11:
- Add a note (patch "media: Documentation: Add a note on Bayer raw mbus codes") to document the use of new generic raw formats
- Link to the LINK_FREQ control from the tx-rx driver documentation.
- Refer to V4L2 fwnode endpoint parsing functions in tx-rx driver documentation.
- Rename V4L2_CID_COLOR_PATTERN as V4L2_CID_CFA_PATTERN. This matches better with the established use of the terms (CFA in particular).
- Improve and fix references in new camera sensor driver documentation.
- Improve and fix language regarding embedded data in camera sensor driver documentation.
- Improve language in routing documentation in dev-subdev.rst.
- Document the IMMUTABLE route flag in routing documentation.
- Add a note in routing documentation that a sub-device may have either user-created or static routes.
- Also use IMMUTABLE and STATIC flags in internal pads example.
- Elaborate image and metadata stream dependencies in imx219 documentation.
- Don't mention selections in sub-device configuration documentation for internal pads.
- The source format of the camera sensor is configured using the source pad; document this in the Common raw sensor model.
- Move binning factors from camera controls class to image source class where they belong.
- Improve description of colour filter array patterns.
- Add that CFA_PATTERN_FLIP is a read-only control.
- Add references to metadata layouts into the metadata layout control.
- Refer to V4L2_METADATA_LAYOUT_OV2740 in ov2740 documentation (not V4L2_METADATA_LAYOUT_CCS).
- Note that ov2740 embedded data dpc correction threshold uses bits 9--2.
- Postpone adding 16 and higher bpp generic raw formats until we have a user (split into separate patches later in the set).
- Generic 16- and 24-bit format isn't really CSI-2 packed (but appears to be big endian) so rename the two accordingly.
- Small but numerous fixes in generic raw image data format documentation.
- Improve documentation of different parts of the pixel array and relation of that to the UAPI under common raw sensor model documentation.
- Reword documentation of the compose rectangle in common raw sensor model documentation.
- Add crop bounds rectangle to the common raw sensor model to convey the bounds of the pixel array. This allows using negative numbers as well.
- Document that the sensor's output format is configured on the source pad.
- Add references to relevant controls in generic raw format documentation.
- Introduce V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR sub-device capability bit. This bit is set by the userspace to signal support for the common raw sensor model and allows supporting common raw sensor model also in existing drivers.
- Introduce the static route flag to indicate a route is always present.
- Add new struct v4l2_subdev_client_info as argument to certain pad operations in order to support passing information on client capabilities to sub-device drivers.
- Added common raw format support to the CCS driver.
- Drop leftover mutex_unlock() in ccs_set_format().
- Fully rely on sub-device state locking in the CCS driver.
- Make METADATA_LAYOUT control read-only.
- Add new controls FRAME_LENGTH_LINES and LINE_LENGTH_PIXELS.
- Don't handle the CFA pattern control in set_ctrl() -- ops is NULL.
- Support the common raw sensor model in imx219:
- Add support for BINNING_FACTORS, FRAME_LENGTH_LINES and LINE_LENGTH_PIXELS controls.
- Support both Common Raw Sensor Model and old behaviour, depending on V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR bit. The internal state is the same in both cases but the view to the state and UAPI behaviour differs based on that bit.
- Keep track of enabled streams; any started stream starts streaming on the sensor.
- Enumerate only generic raw mbus code on the internal image source pad.
- Support set_selection for setting analogue crop area.
- Remove redundant comments in imx219_probe().
- Ipu6 driver changes:
- Lots of cleanups.
- Only start streaming on the upstream sub-device when all queues in the pipeline have been set streaming.
- Use VALIDATE_LATE link flag for links to video nodes.
- Move streaming control to the CSI-2 driver. Streaming now starts on the upstream sub-device once all participating video nodes have been set streaming.
- Support generic raw formats in the unicam driver.
- Document that common raw sensor model requires implementing FRAME_LENGTH_LINES and LINE_LENGTH_PIXELS controls.
since v10:
- Merge a few patches that aren't strictly related to metadata, mostly documentation cleanups and improvements.
- Add V4L2_SUBDEV_ROUTE_FL_STATIC, to indicate a route is mutable but hardware specific so it remains even if disabled. An example of this are embedded data routes on camera sensors. IMMUTABLE implies STATIC.
- Postpone adding formats higher than 14 bpp and remove reference to "little endian" for the CSI-2 packed formats. It's not entirely clear how the data on higher bit depth formats are laid out in memory. The documentation suggests these are in big endian format but that would be impractical for CPU processing.
- Add references to controls in flipping documentation in subdev-formats.rst.
- Add -ENXIO return code for device specific invalid routing configuration and clarify routing error conditions for -EINVAL.
- Add braces for the case in imx219_enum_mbus_code() to make Clang happy.
- Rebase off of mc-streamon set (to my cleanup branch). The problem of when to stream on and off still needs to be addressed but I'm looking into a different, better integrated approach right now.
- Rename generic metadata formats at bit depths 16 and 24 as it seems these have more generic packing than CSI-2.
since v9:
- Introduce controls for sub-device configuration models (separately discussed in <[email protected]>), with the following changes:
- Fix spelling and improve wording in documentation based on comments.
- Use US English spelling for V4L2 control names.
- Allow for more than one internal pad for pixel data.
- Introduce (or change a bit) generic mbus codes for raw pixel data and metadata.
- Introduce generic and CSI-2 specifc V4L2 pixelformats for image data and metadata. Also 16- and 24-bit formats are generic, not specific to CSI-2.
- Introduce new controls to convey metadata layout on bus and by extension, in memory, instead of relying on separate metadata mbus codes, aligning with pixel data.
- Use generic metadata codes in the example.
- Include imx219 embedded data support patches from Laurent, with modifications.
- Patches to IPU6 ISYS driver needed to support metadata capture. Luma formats added, too.
- Improved debug prints in v4l2_subdev_{en,dis}able_streams().
- Added a patch to make media_entity_to_video_device() NULL-safe.
- Drop _media-glossary-data-unit reference, use :term: to reference it.
- Include a patch to set IPU6 ISYS minimum height to 1.
- Patch 'media: uapi: Document which mbus format fields are valid for metadata' already merged.
- Patch 'media: uapi: v4l: Add generic 8-bit metadata format definitions' already merged.
- Patch 'media: v4l: Support line-based metadata capture' already merged.
- Patch 'media: Documentation: Document S_ROUTING behaviour' already merged.
- Patch 'media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing' already merged.
since v8:
- Move the patch adding internal pad flag past the routing API reworks, as well as a few other patches, in order to separate the patches to those that could still be merged for v6.10 (routing changes) and those that couldn't (sensor API related). The patch on the edge is "media: uapi:
v4l: subdev: Enable streams API".
- Include Laurent's two patches to address crop API issues wrt. streams.
- Add two patches to prepare for CCS driver rework (media: ccs: Move ccs_pm_get_init function up and media: ccs: Rename out label of ccs_start_streaming).
- Address issues in the ov2740 driver patches (as well as the driver itself), 4 more patches towards the end of the set.
- Improved generic metadata format names, align with other existing formats.
- Improved ov2740 embedded data documentation.
- Reworked streams and camera sensor documentation based on Laurent's comments mainly. In particular, the contradictory concept of internal source pads no longer should exist in the patches.
- Fixed pad numbering in the CCS example.
- Fixed S_ROUTING behaviour when len_routes is too small and when S_ROUTING isn't implemented by the driver.
- Reorder sections in meta-formats.rst alphabetically.
- Add a note per struct fields that certain struct v4l2_subdev_format are zero for metadata mbus codes.
- CCS driver patch cleanups.
- CCS driver metadata width fix for space-efficient embedded data at 16 bpp and over.
- Postpone CCS frame descriptor quirk for now.
- Use MIPI_CSI2_DT_USER_DEFINED(0) instead of a numerical value for compressed data datatype.
since v7:
- Add embedded data support for the ov2740 driver.
- Add three patches on top, to add an IMMUTABLE flag to source streams when they cannot be disabled.
- Improved documentation of len_routes and num_routes arguments of [GS]_ROUTING.
- Remove one inclusion of twice-included media/v4l2-fwnode.h in drivers/media/i2c/ccs/ccs-core.c .
- Add missing forward declaration of ccs_internal_ops in drivers/media/i2c/ccs/ccs-core.c .
since v6:
- Improve embedded data UAPI documentation on camera sensors.
- Improve wording of stream glossary entry.
- Improve internal pad flag documentation.
- Fix definition of "data unit" and remove an extra "only" in INTERNAL pad flag description (1st patch).
- Use IMX219 driver in examples consistently.
- Remove the CSI-2 to parallel bridge from the example to simplify the example.
- Minor rewording of some parts of the routing examples.
- Rebase on unified sub-device state information access functions:
<URL:https://lore.kernel.org/linux-media/[email protected]/T/#t>
- In CCS driver, do not maintain current active configuration in driver's device context struct (apart from mbus codes). Rely on sub-device state locking and clean up the code. (Multiple patches towards the end of the set.)
- Arrange the CCS patches early in the set towards the end of the set.
- Move the patch enabling streams API to the end of the set.
- Rework IOCTL argument copying condition for [GS]_ROUTING).
- Handle copying back routes in S_ROUTING, do not rely on G_ROUTING IOCTL implementation.
- Rebase on metadata preparation patchset v6:
<URL:https://lore.kernel.org/linux-media/[email protected]/T/#t>.
since v5:
- Rebase on new set of preparation patches.
- Switch CCS driver from s_stream to enable_streams/disable_streams. Keep streaming state information --- the sensor remains in streaming state if any of the streams is enabled.
- Fix setting mbus code on embedded data in get_frame_desc() op in the CCS driver.
since v4:
- Add a patch to acquire two sub-device states that may use the same lock.
- Add a patch for CCS driver to remove ccs_get_crop_compose() helper.
- Add a patch for CCS driver moving acquiring and releasing the mutex to the s_stream callback.
- Add a patch for CCS driver to rely on sub-device state locking using a single driver-provided lock.
- Fixed calculating minimum number of routes in copying the routes (thanks, Laurent).
- Moved a label in S_ROUTING handling to make Clang happy (hopefully).
- Fixed setting emb_data_ctrl register for CCS embedded data support.
- Rebase on Laurent's cleanup patches.
- Wrap a few long lines.
- Write in embedded data documentation sensor drivers generally don't allow configuring it.
since v3:
- Separate preparation patches from this set.
- Add a definition for "Data unit", a pixel that is not image data and use it instead in format documentation.
- Fix more numbered lists in dev-subdev.rst.
- Remove a redundant definition for V4L2_META_FMT_GENERIC_CSI2_2_24 --- V4L2_META_FMT_GENERIC_CSI2_12 can be used instead.
- Use "X" instead of "p" to denote padding in format documentation.
- Use IMX219 in examples instead of CCS.
- Document that the generic V4L2 CSI-2 metadata formats use padding defined in CSI-2 spec and packing defined in CCS spec.
- Add patches to align [GS]_ROUTING behaviour with V4L2. This means mainly returning configured routes as part of S_ROUTING as well. "len_routes" field is added to denote the length of the array and having more routes than fits in the array is no longer an error. Also added more reserved fields.
- Added trivial support for S_ROUTING (via G_ROUTING implementation) for use in drivers with static-only routes.
- Added helper functions to obtain mbus format as well as crop and compose rectangles that are streams-independent.
- Added a patch to define generic CSI-2 long packet types.
- Removed MEDIA_BUS_FMT_IS_META() macro. It didn't seem useful in the end.
- Use a single CCS embedded data format. The bit depth can be selected using the meta stream on the source pad.
- Fix mbus code numbers (there were holes due to removed redundant formats).
- Fix generic mbus code documentation (byte was being used instead of bit).
- Fix spelling of "length".
- Added a patch to remove v4l2_subdev_enable_streams_api that disables streams API. This should be merged once libcamera support for streams works nicely.
- Don't use strings in printing frame descriptor flags.
- Warn on string truncation in printing frame descriptor.
since v2:
- Add a better example, with formats.
- Add CCS static data media bus codes.
- Added an example demonstrating the use of internal pads. --- Is the level of detail enough for the purpose?
- Improved documentation.
- Added a macro to tell whether a format is a metadata format. (Documentation could be added.)
- A small ReST syntax fix in the same section.
- Drop leftovers of a patch checking for the INTERNAL_SOURCE flag.
since v1:
- Make the new pad flag just "INTERNAL", requiring either SINK or SOURCE pad flag to accompany it. Removed the union in struct v4l2_subdev_route.
- Add the term "stream" to MC glossary.
- Improved and fixed documentation (according to comments).
- Note these formats are little endian.
- Remove 1X8 from the names of the mbus codes. These formats have generally 8 bits per pixel.
- Fix mbus code numbering (had holes in RFC).
- Add new metadata fields to debug prints.
- Fix a minor documentation build issue.
Frank Li (1):
media: v4l2-common: Add helper function
media_bus_fmt_to_csi2_(bpp|dt)()
Laurent Pinchart (4):
media: imx219: Add image stream
media: imx219: Report internal routes to userspace
media: imx219: Report streams using frame descriptors
media: imx219: Add embedded data support
Sakari Ailus (68):
media: uapi: Bump the STREAMS bit a little
Revert "media: mc: Keep INTERNAL pad flags just for the kernel, for
now"
media: uapi: Add generic CSI-2 raw pixelformats
media: uapi: Add new media bus codes for generic raw formats
media: uapi: Add V4L2_CID_CONFIG_MODEL control
media: uapi: Add V4L2_CID_CFA_PATTERN for describing color patterns
media: uapi: Add monochromatic CFA pattern
media: Documentation: Reference CFA pattern control in pixelformat
docs
media: Documentation: Reference CFA_PATTERN control in raw mbus docs
media: v4l: uapi: Add a control for color pattern flipping effect
media: Documentation: Reference flipping controls in raw format docs
media: Documentation: Document raw mbus codes and CFA for cameras
media: uapi: Add V4L2_CID_METADATA_LAYOUT control
media: Documentation: Refer to metadata layout in metadata
documentation
media: Documentation: v4l: Document internal sink pads
media: Documentation: Document embedded data guidelines for camera
sensors
media: uapi: Correct generic CSI-2 metadata format 4cc Revert "media: uapi: v4l: Don't expose generic metadata formats to
userspace"
media: v4l: Add V4L2_SUBDEV_ROUTE_FL_IMMUTABLE sub-device routing flag
media: v4l: Add V4L2_SUBDEV_ROUTE_FL_STATIC sub-device routing flag
media: Documentation: There are either immutable or mutable routes
media: Documentation: Document IMMUTABLE and STATIC route flags
media: Documentation: Add subdev configuration models, raw sensor
model
media: v4l2-subdev: Prevent accessing internal pads without STREAMS
cap
media: subdev: Make get_fmt on INTERNAL pads without STREAMS an error
media: Documentation: Add scaling and post-scaler crop for common raw
media: uapi: Add MIPI CCS configuration model
media: uapi: Add V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR
media: uapi: Add V4L2_CID_BINNING_FACTORS control for binning
configuration
media: uapi: Add controls for sub-sampling configuration
media: uapi: Add new controls for camera sensor FLL and LLP
media: v4l2-common: Add v4l2_sensor_fll_llp_set()
media: Documentation: Add binning and sub-sampling controls
media: v4l2-subdev: Set STATIC route flag if IMMUTABLE route flag is
set
media: uapi: v4l: subdev: Enable streams API
media: uapi: Add binning factor helper macros
media: Documentation: Document frame controls for common raw sensor
model
media: v4l2-ctrl: Improve v4l2_ctrl_g_ctrl{,int64} documentation
media: Documentation: Add sub-device internal pads example
media: Documentation: Document streaming behaviour for common raw
cameras
media: Documentation: Add a note on Bayer raw mbus codes
media: uapi: Add generic raw pixelformats for 10, 12 and 14 bits
media: uapi: Add more media bus codes for generic raw formats
media: uapi: ccs: Add metadata layout for MIPI CCS embedded data
media: Documentation: Document non-CCS use of CCS embedded data layout
media: ccs: Add support for generic raw mbus codes
media: ccs: Add support for embedded data stream
media: Documentation: ccs: Document routing
media: ccs: Add IMMUTABLE and STATIC route flags
media: uapi: Add metadata layout for ov2740 embedded data
media: ov2740: Add support for embedded data
media: ov2740: Add support for generic raw formats
media: ov2740: Add metadata layout control
media: ov2740: Add support for G_SELECTION IOCTL
media: ov2740: Add support for FLL and LLP controls
media: ov2740: Signal common raw sensor model support
media: ov2740: Add IMMUTABLE and STATIC route flags
media: imx219: Add internal image pad for Common Raw Sensor Model
media: imx219: Add support for generic raw formats
media: imx219: Add V4L2_CID_BINNING_FACTORS
media: imx219: Allow configuring cropping and binning through CRSM
media: imx219: Support LINE_LENGTH_PIXELS and FRAME_LENGTH_LINES
controls
media: bcm2835-unicam: Support generic raw formats
media: ipu6: Add support for raw CFA-agnostic formats
media: ipu6: Add support for generic unpacked pixel and metadata
formats
Documentation: media: Reword blanking control documentation
media: uapi: Add generic raw pixelformat for 16 bpp
media: uapi: Add generic CSI-2 raw pixelformats for 16, 20, 24 and 28
bpp
.../driver-api/media/camera-sensor.rst | 11 + .../media/drivers/camera-sensor.rst | 79 ++ .../userspace-api/media/drivers/ccs.rst | 43 +- .../media/v4l/common-raw-sensor.dia | 442 ++++++++++ .../media/v4l/common-raw-sensor.svg | 134 ++++ .../userspace-api/media/v4l/dev-subdev.rst | 174 +++- .../userspace-api/media/v4l/devices.rst | 1 + .../media/v4l/ext-ctrls-image-process.rst | 6 + .../media/v4l/ext-ctrls-image-source.rst | 158 +++- .../userspace-api/media/v4l/meta-formats.rst | 1 + .../media/v4l/metadata-layouts.rst | 114 +++ .../media/v4l/metafmt-generic.rst | 48 +- .../media/v4l/pixfmt-raw-generic.rst | 500 ++++++++++++ .../userspace-api/media/v4l/pixfmt.rst | 1 + .../media/v4l/subdev-config-model.rst | 299 +++++++ .../media/v4l/subdev-formats.rst | 48 ++ .../media/v4l/vidioc-subdev-g-client-cap.rst | 6 + .../media/v4l/vidioc-subdev-g-routing.rst | 9 + drivers/media/i2c/ccs/ccs-core.c | 398 ++++++++- drivers/media/i2c/ccs/ccs.h | 17 +- drivers/media/i2c/imx219.c | 755 +++++++++++++++--- drivers/media/i2c/ov2740.c | 371 +++++++-- drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 3 + .../media/pci/intel/ipu6/ipu6-isys-subdev.c | 3 + .../media/pci/intel/ipu6/ipu6-isys-video.c | 18 +- .../media/platform/broadcom/bcm2835-unicam.c | 27 + drivers/media/v4l2-core/v4l2-common.c | 253 ++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 21 + drivers/media/v4l2-core/v4l2-ioctl.c | 19 +- drivers/media/v4l2-core/v4l2-subdev.c | 85 +- include/media/mipi-csi2.h | 24 + include/media/v4l2-common.h | 31 + include/media/v4l2-ctrls.h | 4 + include/media/v4l2-mc.h | 1 + include/uapi/linux/media-bus-format.h | 10 + include/uapi/linux/media.h | 6 - include/uapi/linux/v4l2-controls.h | 34 + include/uapi/linux/v4l2-subdev.h | 20 +- include/uapi/linux/videodev2.h | 27 +- 39 files changed, 3868 insertions(+), 333 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/metadata-layouts.rst create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst create mode 100644 Documentation/userspace-api/media/v4l/subdev-config-model.rst
base-commit: decc53804e94320af09c3df13d1eee66caa9c25f
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 1/73 media: uapi: Bump the STREAMS bit a little
Bump the V4L2_SUBDEV_CAP_STREAMS by one bit up, in order to avoid confusing libcamera with streams that has moved forward from the original libcamera implementation. The bit can presumably be taken into use but only after the other free bits.
--- include/uapi/linux/v4l2-subdev.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/linux/v4l2-subdev.h +4 -1
@@ -196,8 +196,11 @@ struct v4l2_subdev_capability {/* The v4l2 sub-device video device node is registered in read-only mode. */ #define V4L2_SUBDEV_CAP_RO_SUBDEV 0x00000001 +/* Reserved, old STREAMS bit libcamera used before API stabilisation. */ +/* #define V4L2_SUBDEV_CAP_STREAMS_PRELIMINARY 0x00000002 */ +/* The v4l2 sub-device supports routing and multiplexed streams. */ -#define V4L2_SUBDEV_CAP_STREAMS 0x00000002 +#define V4L2_SUBDEV_CAP_STREAMS 0x00000004/* * Is the route active? An active route will start when streaming is enabled
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 2/73 Revert "media: mc: Keep INTERNAL pad flags just for the kernel, for now"
In reply to Sakari AilusThis reverts commit 77a10651b2f23b6a56d27570fa9a870f8e977125.
The INTERNAL pads can now be made visible to the userspace so revert the patch that made them kernel-only.
--- include/uapi/linux/media.h | 6 ------ 1 file changed, 6 deletions(-)
include/uapi/linux/media.h +0 -6
@@ -208,13 +208,7 @@ struct media_entity_desc {#define MEDIA_PAD_FL_SINK (1U << 0)#define MEDIA_PAD_FL_SOURCE (1U << 1)#define MEDIA_PAD_FL_MUST_CONNECT (1U << 2) -#if defined(__KERNEL__) -/* -* Forgo INTERNAL pads until proper documentation and v4l2-compliance testing -* are merged. -*/ #define MEDIA_PAD_FL_INTERNAL (1U << 3) -#endif /* __KERNEL__ */ struct media_pad_desc {__u32 entity;/* entity ID */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 3/73 media: uapi: Add generic CSI-2 raw pixelformats
In reply to Sakari AilusAdd generic raw pixelformats for bit depths 8, 10, 12 and 14. These formats are CSI-2 packed, apart from the 8-bit format.
--- .../media/v4l/pixfmt-raw-generic.rst | 175 ++++++++++++++++++ .../userspace-api/media/v4l/pixfmt.rst | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 4 + include/uapi/linux/videodev2.h | 6 + 4 files changed, 186 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst
Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst new file +175 -0
@@ -0,0 +1,175 @@ +.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later + +************************************************************************************************************************************ +V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE') +************************************************************************************************************************************ + + +Generic line-based raw image data formats + + +Description +=========== + +These generic raw image data formats define the memory layout of the data without +defining the order of the colour components or even the colour components +themselves. + +.. _v4l2-pix-fmt-raw-8: + +V4L2_PIX_FMT_RAW_8 +------------------ + +The V4L2_PIX_FMT_RAW_8 format is a plain 8-bit raw pixel data format. This +format is used on CSI-2 for 8 bits per :term:`Data Unit`. + +**Byte Order Of V4L2_PIX_FMT_RAW_8.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 + + * - start + 0: + - P\ :sub:`00` + - P\ :sub:`10` + - P\ :sub:`20` + - P\ :sub:`30` + * - start + 4: + - P\ :sub:`01` + - P\ :sub:`11` + - P\ :sub:`21` + - P\ :sub:`31` + +.. _v4l2-pix-fmt-raw-csi2-10: + +V4L2_PIX_FMT_RAW_CSI2_10 +------------------------ + +V4L2_PIX_FMT_RAW_CSI2_10 contains 10-bit packed image data, with four bytes +containing the top 8 bits of the pixels followed by lowest 2 bits of the pixels +packed into one byte. This format is typically used by CSI-2 receivers with +a source that transmits MEDIA_BUS_FMT_RAW_10 and the CSI-2 receiver writes the +received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_10.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 9--2` + - P\ :sub:`10 bits 9--2` + - P\ :sub:`20 bits 9--2` + - P\ :sub:`30 bits 9--2` + - P\ :sub:`00 bits 1--0` (bits 1--0), + P\ :sub:`10 bits 1--0` (bits 3--2), + P\ :sub:`20 bits 1--0` (bits 5--4), + P\ :sub:`30 bits 1--0` (bits 7--6) + * - start + 5: + - P\ :sub:`01 bits 9--2` + - P\ :sub:`11 bits 9--2` + - P\ :sub:`21 bits 9--2` + - P\ :sub:`31 bits 9--2` + - P\ :sub:`01 bits 1--0` (bits 1--0), + P\ :sub:`11 bits 1--0` (bits 3--2), + P\ :sub:`21 bits 1--0` (bits 5--4), + P\ :sub:`31 bits 1--0` (bits 7--6) + +.. _v4l2-pix-fmt-raw-csi2-12: + +V4L2_PIX_FMT_RAW_CSI2_12 +------------------------ + +V4L2_PIX_FMT_RAW_CSI2_12 contains 12-bit packed image data, with two bytes +containing the top 8 bits of the pixels followed by lowest 4 bits of the pixels +packed into 1 byte. This format is typically used by CSI-2 receivers with +a source that transmits MEDIA_BUS_FMT_RAW_12 and the CSI-2 receiver writes the +received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_12.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{2cm}|p{1.2cm}|p{1.2cm}|p{2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 11--4` + - P\ :sub:`10 bits 11--4` + - P\ :sub:`00 bits 3--0` (bits 3--0), + P\ :sub:`10 bits 3--0` (bits 7--4) + - P\ :sub:`20 bits 11--4` + - P\ :sub:`30 bits 11--4` + - P\ :sub:`20 bits 3--0` (bits 3--0), + P\ :sub:`30 bits 3--0` (bits 7--4) + * - start + 6: + - P\ :sub:`01 bits 11--4` + - P\ :sub:`11 bits 11--4` + - P\ :sub:`01 bits 3--0` (bits 3--0), + P\ :sub:`11 bits 3--0` (bits 7--4) + - P\ :sub:`21 bits 11--4` + - P\ :sub:`31 bits 11--4` + - P\ :sub:`21 bits 3--0` (bits 3--0), + P\ :sub:`31 bits 3--0` (bits 7--4) + +.. _v4l2-pix-fmt-raw-csi2-14: + +V4L2_PIX_FMT_RAW_CSI2_14 +------------------------ + +V4L2_PIX_FMT_RAW_CSI2_14 contains 14-bit packed image data, with four bytes +containing the top 8 bits of the pixels followed by lowest 6 bits of the pixels +packed into three bytes. This format is typically used by CSI-2 receivers with a +source that transmits MEDIA_BUS_FMT_RAW_14 and the CSI-2 receiver writes the +received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_14.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{2cm}|p{2cm}|p{2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 13--6` + - P\ :sub:`10 bits 13--6` + - P\ :sub:`20 bits 13--6` + - P\ :sub:`30 bits 13--6` + - P\ :sub:`10 bits 1--0` (bits 7--6), + P\ :sub:`00 bits 5--0` (bits 5--0) + - P\ :sub:`20 bits 3--0` (bits 7--4), + P\ :sub:`10 bits 5--2` (bits 3--0) + - P\ :sub:`30 bits 5--0` (bits 7--2), + P\ :sub:`20 bits 5--4` (bits 1--0) + * - start + 7: + - P\ :sub:`01 bits 13--6` + - P\ :sub:`11 bits 13--6` + - P\ :sub:`21 bits 13--6` + - P\ :sub:`31 bits 13--6` + - P\ :sub:`11 bits 1--0` (bits 7--6), + P\ :sub:`01 bits 5--0` (bits 5--0) + - P\ :sub:`21 bits 3--0` (bits 7--4), + P\ :sub:`11 bits 5--2` (bits 3--0) + - P\ :sub:`31 bits 5--0` (bits 7--2), + P\ :sub:`21 bits 5--4` (bits 1--0)
Documentation/userspace-api/media/v4l/pixfmt.rst +1 -0
@@ -26,6 +26,7 @@ see also :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>`.) pixfmt-indexed pixfmt-rgb pixfmt-bayer + pixfmt-raw-generic yuv-formats hsv-formats depth-formats
drivers/media/v4l2-core/v4l2-ioctl.c +4 -0
@@ -1434,6 +1434,10 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG16 : descr ="16-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG16 : descr ="16-bit Bayer GRGR/BGBG" ;break ;case V4L2_PIX_FMT_SRGGB16 : descr ="16-bit Bayer RGRG/GBGB" ;break ; +case V4L2_PIX_FMT_RAW_8 : descr ="8-bit Raw" ;break ; +case V4L2_PIX_FMT_RAW_CSI2_10 : descr ="10-bit Raw, CSI-2 Packed" ;break ; +case V4L2_PIX_FMT_RAW_CSI2_12 : descr ="12-bit Raw, CSI-2 Packed" ;break ; +case V4L2_PIX_FMT_RAW_CSI2_14 : descr ="14-bit Raw, CSI-2 Packed" ;break ;case V4L2_PIX_FMT_RAW_CRU20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;
include/uapi/linux/videodev2.h +6 -0
@@ -745,6 +745,12 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_SGRBG16 v4l2_fourcc('G', 'R', '1', '6')/* 16 GRGR.. BGBG.. */ #define V4L2_PIX_FMT_SRGGB16 v4l2_fourcc('R', 'G', '1', '6')/* 16 RGRG.. GBGB.. */ +/* Generic CSI-2 packed raw pixel formats */ +#define V4L2_PIX_FMT_RAW_8 v4l2_fourcc('R', 'A', 'W', '8') +#define V4L2_PIX_FMT_RAW_CSI2_10 v4l2_fourcc('R', 'A', 'C', 'A') +#define V4L2_PIX_FMT_RAW_CSI2_12 v4l2_fourcc('R', 'A', 'C', 'C') +#define V4L2_PIX_FMT_RAW_CSI2_14 v4l2_fourcc('R', 'A', 'C', 'E') +/* HSV formats */ #define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')#define V4L2_PIX_FMT_HSV32 v4l2_fourcc('H', 'S', 'V', '4')
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 4/73 media: uapi: Add new media bus codes for generic raw formats
In reply to Sakari AilusAdd new media bus codes for generic raw formats that are not specific to the colour filter array but that simply specify the bit depth. The layout (packing) of the data is interface specific.
The rest of the properties of the format are specified with controls in the image source.
The mbus codes added by this patch have bit depth of 8, 10, 12 and 14.
--- .../media/v4l/subdev-formats.rst | 27 +++++++++++++++++++ include/uapi/linux/media-bus-format.h | 6 +++++ 2 files changed, 33 insertions(+)
Documentation/userspace-api/media/v4l/subdev-formats.rst +27 -0
@@ -3855,6 +3855,33 @@ organization is given as an example for the first pixel only. \endgroup +Generic raw formats on serial interfaces +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Those formats transfer raw pixel data typically from raw camera sensors using +Bayer and other Colour Filter Arrays (CFAs) on serial interfaces. The packing of +the data on the bus is determined by the hardware, however the bit depth is +still specific to the format. + +.. tabularcolumns:: |p{2.0cm}|p{4.0cm}|p{11.3cm}| + +.. cssclass:: longtable + +.. flat-table:: Generic raw formats on serial buses + :header-rows: 1 + :stub-columns: 0 + :widths: 1 1 + + * - Format name + - Bit depth + * - MEDIA_BUS_FMT_RAW_8 + - 8 + * - MEDIA_BUS_FMT_RAW_10 + - 10 + * - MEDIA_BUS_FMT_RAW_12 + - 12 + * - MEDIA_BUS_FMT_RAW_14 + - 14 Packed YUV Formats ^^^^^^^^^^^^^^^^^^
include/uapi/linux/media-bus-format.h +6 -0
@@ -190,4 +190,10 @@#define MEDIA_BUS_FMT_META_20 0x8006#define MEDIA_BUS_FMT_META_24 0x8007 +/* Generic (CFA independent) pixel data formats. Next is 0x9005. */ +#define MEDIA_BUS_FMT_RAW_8 0x9001 +#define MEDIA_BUS_FMT_RAW_10 0x9002 +#define MEDIA_BUS_FMT_RAW_12 0x9003 +#define MEDIA_BUS_FMT_RAW_14 0x9004 +#endif /* __LINUX_MEDIA_BUS_FORMAT_H */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 5/73 media: uapi: Add V4L2_CID_CONFIG_MODEL control
In reply to Sakari AilusAdd 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
@@ -59,3 +59,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`. This is a read-only control.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +5 -0
@@ -1167,6 +1167,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! */
@@ -1488,6 +1489,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
@@ -1269,6 +1269,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_CONFIG_MODEL_COMMON_RAW_SENSOR (1U << 0)/* DV-class control IDs defined by V4L2 */ #define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 6/73 media: uapi: Add V4L2_CID_CFA_PATTERN for describing color patterns
In reply to Sakari AilusAdd V4L2_CID_CFA_PATTERN to tell the camera sensor's native Color Filter Array (CFA) pattern.
--- .../media/v4l/ext-ctrls-image-source.rst | 43 +++++++++++++++++++ .../media/v4l/subdev-formats.rst | 2 + drivers/media/v4l2-core/v4l2-ctrls-defs.c | 1 + include/uapi/linux/v4l2-controls.h | 6 +++ 4 files changed, 52 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +43 -0
@@ -93,3 +93,46 @@ Image Source Control IDs representing a gain of exactly 1.0. For example, if this default value is reported as being (say) 128, then a value of 192 would represent a gain of exactly 1.5. + +``V4L2_CID_CFA_PATTERN (integer)`` + This control determines the color components and native pixel order in the + sensor's CFA (Color Filter Array) when used in conjunction with + :ref:`generic raw mbus codes MEDIA_BUS_FMT_RAW_x (where 'x' is the bit + depth) <v4l2-mbus-pixelcode-generic-raw>` pixelcodes. The native pixel + order is constant for a given device, it is not affected by cropping or + flipping. + + This control may only be used on V4L2 sub-devices. + + This is a read-only control. + + Available patterns: + +.. flat-table:: V4L2 Color Filter Array Patterns + :header-rows: 1 + :stub-columns: 0 + :widths: 1 2 1 + + * - Macro name + - Synopsis + - Value + * - V4L2_CFA_PATTERN_GRBG + - Bayer pattern (2x2 macroblocks). Each macroblock has a green filter in + the top-left and bottom-right pixels, a red filter in the top-right + pixel, and a blue filter in the bottom-left pixel. + - 0x00000000 + * - V4L2_CFA_PATTERN_RGGB + - Bayer pattern (2x2 macroblocks). Each macroblock has a green filter in + the top-right and bottom-left pixels, a red filter in the top-left + pixel, and a blue filter in the bottom-right pixel. + - 0x00000001 + * - V4L2_CFA_PATTERN_BGGR + - Bayer pattern (2x2 macroblocks). Each macroblock has a green filter in + the top-right and bottom-left pixels, a blue filter in the top-left + pixel, and a red filter in the bottom-right pixel. + - 0x00000002 + * - V4L2_CFA_PATTERN_GBRG + - Bayer pattern (2x2 macroblocks). Each macroblock has a green filter in + the top-left and bottom-right pixels, a blue filter in the top-right + pixel, and a red filter in the bottom-left pixel. + - 0x00000003
Documentation/userspace-api/media/v4l/subdev-formats.rst +2 -0
@@ -3855,6 +3855,8 @@ organization is given as an example for the first pixel only. \endgroup +.. _v4l2-mbus-pixelcode-generic-raw: + Generic raw formats on serial interfaces ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
@@ -1158,6 +1158,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_TEST_PATTERN_BLUE :return "Blue Pixel Value" ;case V4L2_CID_TEST_PATTERN_GREENB :return "Green (Blue) Pixel Value" ;case V4L2_CID_NOTIFY_GAINS :return "Notify Gains" ; +case V4L2_CID_CFA_PATTERN :return "Color Filter Array Pattern" ;/* Image processing controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
include/uapi/linux/v4l2-controls.h +6 -0
@@ -1258,6 +1258,12 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_UNIT_CELL_SIZE (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 8)#define V4L2_CID_NOTIFY_GAINS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 9) +#define V4L2_CID_CFA_PATTERN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 10) +#define V4L2_CFA_PATTERN_GRBG 0x00000000 +#define V4L2_CFA_PATTERN_RGGB 0x00000001 +#define V4L2_CFA_PATTERN_BGGR 0x00000002 +#define V4L2_CFA_PATTERN_GBRG 0x00000003 +/* Image processing controls */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 7/73 media: uapi: Add monochromatic CFA pattern
In reply to Sakari AilusAdd monochromatic CFA pattern to the V4L2_CID_CFA_PATTERN control.
--- .../userspace-api/media/v4l/ext-ctrls-image-source.rst | 3 +++ include/uapi/linux/v4l2-controls.h | 1 + 2 files changed, 4 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +3 -0
@@ -136,3 +136,6 @@ Image Source Control IDs the top-left and bottom-right pixels, a blue filter in the top-right pixel, and a red filter in the bottom-left pixel. - 0x00000003 + * - V4L2_CFA_PATTERN_MONO + - Monochromatic sensor, no CFA pattern. + - 0x00010000
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1263,6 +1263,7 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CFA_PATTERN_RGGB 0x00000001#define V4L2_CFA_PATTERN_BGGR 0x00000002#define V4L2_CFA_PATTERN_GBRG 0x00000003 +#define V4L2_CFA_PATTERN_MONO 0x00010000/* Image processing controls */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 8/73 media: Documentation: Reference CFA pattern control in pixelformat docs
In reply to Sakari AilusRefer to the CFA pattern control in the generic raw pixelformat documentation.
--- .../userspace-api/media/v4l/ext-ctrls-image-source.rst | 2 ++ Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +2 -0
@@ -94,6 +94,8 @@ Image Source Control IDs is reported as being (say) 128, then a value of 192 would represent a gain of exactly 1.5. +.. _image-source-control-cfa-pattern: + ``V4L2_CID_CFA_PATTERN (integer)`` This control determines the color components and native pixel order in the sensor's CFA (Color Filter Array) when used in conjunction with
Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst +3 -1
@@ -13,7 +13,9 @@ Description These generic raw image data formats define the memory layout of the data without defining the order of the colour components or even the colour components -themselves. +themselves. These formats may only be used with a Media Controller pipeline where +the more specific format is reported by the :ref:`V4L2_CID_CFA_PATTERN +<image-source-control-cfa-pattern>` control on the source sub-device. .. _v4l2-pix-fmt-raw-8:
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 9/73 media: Documentation: Reference CFA_PATTERN control in raw mbus docs
In reply to Sakari AilusAdd a reference to the V4L2_CID_CFA_PATTERN control in the generic raw media bus code documentation.
--- Documentation/userspace-api/media/v4l/subdev-formats.rst | 3 +++ 1 file changed, 3 insertions(+)
Documentation/userspace-api/media/v4l/subdev-formats.rst +3 -0
@@ -3865,6 +3865,9 @@ Bayer and other Colour Filter Arrays (CFAs) on serial interfaces. The packing of the data on the bus is determined by the hardware, however the bit depth is still specific to the format. +The native Colour Filter Array (CFA) pattern is determined by the +:ref:`V4L2_CID_CFA_PATTERN <image-source-control-cfa-pattern>` control. + .. tabularcolumns:: |p{2.0cm}|p{4.0cm}|p{11.3cm}| .. cssclass:: longtable
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 10/73 media: v4l: uapi: Add a control for color pattern flipping effect
In reply to Sakari AilusAdd a bitmask control (V4L2_CID_CFA_PATTERN_FLIP) to tell whether flipping results in a change in the sensor's Color Filter Array (CFA) pattern, separately horizontally and vertically. The information is essential for raw formats when using generic raw mbus codes.
--- .../media/v4l/ext-ctrls-image-source.rst | 12 ++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++ include/uapi/linux/v4l2-controls.h | 6 ++++++ 3 files changed, 20 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +12 -0
@@ -141,3 +141,15 @@ Image Source Control IDs * - V4L2_CFA_PATTERN_MONO - Monochromatic sensor, no CFA pattern. - 0x00010000 + +``V4L2_CID_CFA_PATTERN_FLIP (bitmask)`` + This control determines whether the horizontal or vertical flipping controls + (V4L2_CID_HFLIP and V4L2_CID_VFLIP) have an effect on the pixel order of the + output color pattern. Macros ``V4L2_CFA_PATTERN_FLIP_HORIZONTAL`` and + ``V4L2_CFA_PATTERN_FLIP_VERTICAL`` define bitmasks for both bits. If either + horizontal or vertical bit is set, the readout pattern order is that of the + reversed readout. ``V4L2_CFA_PATTERN_FLIP_BOTH`` for setting both + ``V4L2_CFA_PATTERN_FLIP_HORIZONTAL`` and ``V4L2_CFA_PATTERN_FLIP_VERTICAL`` + is provided as well. + + This is a read-only control.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
@@ -1159,6 +1159,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_TEST_PATTERN_GREENB :return "Green (Blue) Pixel Value" ;case V4L2_CID_NOTIFY_GAINS :return "Notify Gains" ;case V4L2_CID_CFA_PATTERN :return "Color Filter Array Pattern" ; +case V4L2_CID_CFA_PATTERN_FLIP :return "CFA Pattern Flip" ;/* Image processing controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1491,6 +1492,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, *type =V4L2_CTRL_TYPE_BITMASK ;break ;case V4L2_CID_CONFIG_MODEL : +case V4L2_CID_CFA_PATTERN_FLIP : *flags |=V4L2_CTRL_FLAG_READ_ONLY ; *type =V4L2_CTRL_TYPE_BITMASK ;break ;
include/uapi/linux/v4l2-controls.h +6 -0
@@ -1265,6 +1265,12 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CFA_PATTERN_GBRG 0x00000003#define V4L2_CFA_PATTERN_MONO 0x00010000 +#define V4L2_CID_CFA_PATTERN_FLIP (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 11) +#define V4L2_CFA_PATTERN_FLIP_HORIZONTAL (1U << 0) +#define V4L2_CFA_PATTERN_FLIP_VERTICAL (1U << 1) +#define V4L2_CFA_PATTERN_FLIP_BOTH \ + (V4L2_CFA_PATTERN_FLIP_HORIZONTAL | V4L2_CFA_PATTERN_FLIP_VERTICAL) +/* Image processing controls */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 11/73 media: Documentation: Reference flipping controls in raw format docs
In reply to Sakari AilusAdd a reference to the flipping related controls (V4L2_CID_HFLIP, V4L2_CID_VFLIP and V4L2_CID_COLOR_PATTERN_FLIP) to the generic raw format documentation.
--- .../userspace-api/media/v4l/ext-ctrls-image-source.rst | 2 ++ Documentation/userspace-api/media/v4l/subdev-formats.rst | 3 +++ 2 files changed, 5 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +2 -0
@@ -142,6 +142,8 @@ Image Source Control IDs - Monochromatic sensor, no CFA pattern. - 0x00010000 +.. _image-source-control-cfa-pattern-flip: + ``V4L2_CID_CFA_PATTERN_FLIP (bitmask)`` This control determines whether the horizontal or vertical flipping controls (V4L2_CID_HFLIP and V4L2_CID_VFLIP) have an effect on the pixel order of the
Documentation/userspace-api/media/v4l/subdev-formats.rst +3 -0
@@ -3867,6 +3867,9 @@ still specific to the format. The native Colour Filter Array (CFA) pattern is determined by the :ref:`V4L2_CID_CFA_PATTERN <image-source-control-cfa-pattern>` control. +Whether or not flipping controls (``V4L2_CID_HFLIP`` and ``V4L2_CID_VFLIP``) +affect the pattern is conveyed via the :ref:`V4L2_CID_CFA_PATTERN_FLIP +<image-source-control-cfa-pattern-flip>` control. .. tabularcolumns:: |p{2.0cm}|p{4.0cm}|p{11.3cm}|
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 12/73 media: Documentation: Document raw mbus codes and CFA for cameras
In reply to Sakari AilusDocument the use of raw mbus codes for camera sensors and how the V4L2_CID_CFA_PATTERN and V4L2_CID_CFA_PATTERN_FLIP controls are used to convey the color filter array pattern on UAPI.
--- .../userspace-api/media/drivers/camera-sensor.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +13 -0
@@ -39,6 +39,19 @@ format set on a source pad at the end of the device's internal pipeline. Most sensor drivers are implemented this way. +V4L2_CID_CFA_PATTERN, raw mbus formats, flipping and cropping +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For raw image data originating from camera sensors, specific :ref:`raw mbus +codes MEDIA_BUS_FMT_RAW_x (where 'x' is the bit depth) +<v4l2-mbus-pixelcode-generic-raw>` are used as Color Filter Array (CFA) agnostic +raw formats. The :ref:`V4L2_CID_CFA_PATTERN <image-source-control-cfa-pattern>` +control in the same sub-device defines the native CFA pattern of the +device. Flipping may further affect the readout pattern as indicated by the +:ref:`V4L2_CID_CFA_PATTERN_FLIP <image-source-control-cfa-pattern-flip>` +control. Further on, cropping also has an effect on the pattern if cropped +amount is not divisible by the size of the pattern, horizontally and vertically. + Frame interval configuration ----------------------------
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 13/73 media: uapi: Add V4L2_CID_METADATA_LAYOUT control
In reply to Sakari AilusThe metadata layout control defines the layout of the metadata on the bus. It is used on sub-devices that use generic metadata mbus codes on at least one of the pads.
--- .../userspace-api/media/v4l/ext-ctrls-image-source.rst | 6 ++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 7 +++++++ include/uapi/linux/v4l2-controls.h | 1 + 3 files changed, 14 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +6 -0
@@ -155,3 +155,9 @@ Image Source Control IDs is provided as well. This is a read-only control. + +``V4L2_CID_METADATA_LAYOUT (integer)`` + The metadata layout control defines the metadata layout on the device's data + interface for metadata streams. The control is used in conjunction with + :ref:`generic metadata formats <media-bus-format-generic-meta>` formats to + specify the layout of the data.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +7 -0
@@ -1160,6 +1160,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_NOTIFY_GAINS :return "Notify Gains" ;case V4L2_CID_CFA_PATTERN :return "Color Filter Array Pattern" ;case V4L2_CID_CFA_PATTERN_FLIP :return "CFA Pattern Flip" ; +case V4L2_CID_METADATA_LAYOUT :return "Metadata Layout" ;/* Image processing controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1324,6 +1325,12 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, *min =0 ; *max = *step =1 ;break ; +case V4L2_CID_METADATA_LAYOUT : + *type =V4L2_CTRL_TYPE_INTEGER ; + *flags |=V4L2_CTRL_FLAG_READ_ONLY ; + *min =0 ; + *step =1 ; +break ;case V4L2_CID_ROTATE : *type =V4L2_CTRL_TYPE_INTEGER ; *flags |=V4L2_CTRL_FLAG_MODIFY_LAYOUT ;
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1271,6 +1271,7 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CFA_PATTERN_FLIP_BOTH \ (V4L2_CFA_PATTERN_FLIP_HORIZONTAL | V4L2_CFA_PATTERN_FLIP_VERTICAL) +#define V4L2_CID_METADATA_LAYOUT (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12)/* Image processing controls */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 14/73 media: Documentation: Refer to metadata layout in metadata documentation
In reply to Sakari AilusUsing generic metadata mbus codes requires the use of V4L2_CID_METADATA_LAYOUT control to define the metadata layout. Document this in generic metadata format documentation.
--- Documentation/userspace-api/media/v4l/metafmt-generic.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Documentation/userspace-api/media/v4l/metafmt-generic.rst +6 -2
@@ -8,12 +8,16 @@ V4L2_META_FMT_GENERIC_8 ('MET8'), V4L2_META_FMT_GENERIC_CSI2_10 ('MC1A'), V4L2_M Generic line-based metadata formats - Description =========== These generic line-based metadata formats define the memory layout of the data -without defining the format or meaning of the metadata itself. +without defining the format or meaning of the metadata itself. These formats may +only be used with a Media Controller pipeline where the exact metadata layout is +reported using the :ref:`V4L2_CID_METADATA_LAYOUT control +<image_source_control_metadata_layout>` by the sub-device generating the +metadata. See also :ref:`source routes <subdev-routing>`. + .. _v4l2-meta-fmt-generic-8:
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 15/73 media: Documentation: v4l: Document internal sink pads
In reply to Sakari AilusDocument internal sink pads, pads that have both SINK and INTERNAL flags set. Use the IMX219 camera sensor as an example.
--- .../userspace-api/media/v4l/dev-subdev.rst | 22 +++++++++++++++++++ .../media/v4l/ext-ctrls-image-source.rst | 2 ++ 2 files changed, 24 insertions(+)
Documentation/userspace-api/media/v4l/dev-subdev.rst +22 -0
@@ -554,6 +554,23 @@ A stream at a specific point in the media pipeline is identified by the sub-device and a (pad, stream) pair. For sub-devices that do not support multiplexed streams the 'stream' field is always 0. +Internal sink pads and routing +------------------------------ + +Internal sink pads are used to denote sources of routes that originate from +within a sub-device itself. No external sink pads exist for such routes. +Internal sink pads have the :ref:`MEDIA_PAD_FL_INTERNAL <MEDIA-PAD-FL-INTERNAL>` +pad flag set. + +Internal pads have all the properties of an external pad, including formats and +selections. The format in this case is the source format of the stream. An +internal pad always has a single stream only (0). + +Routes from an internal sink pad to an external source pad are created by the +driver and can be activated and deactivated using the +:ref:`V4L2_SUBDEV_ROUTE_FL_ACTIVE <v4l2-subdev-routing-flags>` flag, depending +on the device capabilities. + Interaction between routes, streams, formats and selections -----------------------------------------------------------
@@ -691,3 +708,8 @@ To configure this pipeline, the userspace must take the following steps: the configurations along the stream towards the receiver, using :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls to configure each stream endpoint in each sub-device. + + In case generic raw and metadata formats are used, :ref:`V4L2_CID_CFA_PATTERN + <image-source-control-cfa-pattern>` and :ref:`V4L2_CID_METADATA_LAYOUT + <image_source_control_metadata_layout>` controls are present on the source + sub-device to obtain the pixel array CFA pattern and metadata layout.
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +2 -0
@@ -156,6 +156,8 @@ Image Source Control IDs This is a read-only control. +.. _image_source_control_metadata_layout: + ``V4L2_CID_METADATA_LAYOUT (integer)`` The metadata layout control defines the metadata layout on the device's data interface for metadata streams. The control is used in conjunction with
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 16/73 media: Documentation: Document embedded data guidelines for camera sensors
In reply to Sakari AilusDocument how embedded data support should be implemented for camera sensors, and when and how CCS embedded data layout should be referenced.
--- .../media/drivers/camera-sensor.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +19 -0
@@ -117,3 +117,22 @@ register programming sequences shall initialize the :ref:`V4L2_CID_HFLIP 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. + +Embedded data +------------- + +Many sensors, mostly raw sensors, support embedded data which is used to convey +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. + +Embedded data support is indicated by the presence of an internal sink pad (pad +that has both the :ref:`MEDIA_PAD_FL_SINK <MEDIA-PAD-FL-SINK>` and +:ref:`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 layout from the driver-configured values +is not supported. The width of the metadata is device-specific and equal to or +less than the width of the image data, as configured on the pixel data stream.
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 17/73 media: uapi: Correct generic CSI-2 metadata format 4cc
In reply to Sakari AilusRework the pixelformat 4cc for CSI-2 generic metadata, the 16- and 24-bit variants are not specific to CSI-2. This can be done as no driver uses this yet and the interface is disabled.
--- .../media/v4l/metafmt-generic.rst | 40 +++++++++---------- .../media/pci/intel/ipu6/ipu6-isys-video.c | 2 +- drivers/media/v4l2-core/v4l2-ioctl.c | 8 ++-- include/uapi/linux/videodev2.h | 12 +++--- 4 files changed, 30 insertions(+), 32 deletions(-)
Documentation/userspace-api/media/v4l/metafmt-generic.rst +19 -21
@@ -2,7 +2,7 @@ .. c:namespace:: V4L ******************************************************************************************************************************************************************************************************************************************************************************** -V4L2_META_FMT_GENERIC_8 ('MET8'), V4L2_META_FMT_GENERIC_CSI2_10 ('MC1A'), V4L2_META_FMT_GENERIC_CSI2_12 ('MC1C'), V4L2_META_FMT_GENERIC_CSI2_14 ('MC1E'), V4L2_META_FMT_GENERIC_CSI2_16 ('MC1G'), V4L2_META_FMT_GENERIC_CSI2_20 ('MC1K'), V4L2_META_FMT_GENERIC_CSI2_24 ('MC1O') +V4L2_META_FMT_GENERIC_8 ('MET8'), V4L2_META_FMT_GENERIC_CSI2_10 ('MECA'), V4L2_META_FMT_GENERIC_CSI2_12 ('MECC'), V4L2_META_FMT_GENERIC_CSI2_14 ('MECE'), V4L2_META_FMT_GENERIC_16 ('METG'), V4L2_META_FMT_GENERIC_CSI2_20 ('MECK'), V4L2_META_FMT_GENERIC_24 ('METO') ********************************************************************************************************************************************************************************************************************************************************************************
@@ -29,7 +29,7 @@ is used on CSI-2 for 8 bits per :term:`Data Unit`. Additionally it is used for 16 bits per Data Unit when two bytes of metadata are packed into one 16-bit Data Unit. Otherwise the 16 bits per pixel dataformat is -:ref:`V4L2_META_FMT_GENERIC_CSI2_16 <v4l2-meta-fmt-generic-csi2-16>`. +:ref:`V4L2_META_FMT_GENERIC_16 <v4l2-meta-fmt-generic-16>`. **Byte Order Of V4L2_META_FMT_GENERIC_8.** Each cell is one byte. "M" denotes a byte of metadata.
@@ -112,8 +112,8 @@ the data is defined in the MIPI CCS specification. This format is also used in conjunction with 24 bits per :term:`Data Unit` formats that pack two bytes of metadata into one Data Unit. Otherwise the -24 bits per pixel dataformat is :ref:`V4L2_META_FMT_GENERIC_CSI2_24 -<v4l2-meta-fmt-generic-csi2-24>`. +24 bits per pixel dataformat is :ref:`V4L2_META_FMT_GENERIC_24 +<v4l2-meta-fmt-generic-24>`. This format is little endian.
@@ -185,16 +185,15 @@ Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding. - x - x -.. _v4l2-meta-fmt-generic-csi2-16: +.. _v4l2-meta-fmt-generic-16: -V4L2_META_FMT_GENERIC_CSI2_16 ------------------------------ +V4L2_META_FMT_GENERIC_16 +------------------------ -V4L2_META_FMT_GENERIC_CSI2_16 contains 8-bit generic metadata packed in 16-bit -Data Units, with one padding byte after every byte of metadata. This format is -typically used by CSI-2 receivers with a source that transmits -MEDIA_BUS_FMT_META_16 and the CSI-2 receiver writes the received data to memory -as-is. +V4L2_META_FMT_GENERIC_16 contains 8-bit generic metadata packed in 16-bit Data +Units, with one padding byte after every byte of metadata. This format is also +used by CSI-2 receivers with a source that transmits MEDIA_BUS_FMT_META_16 and +the CSI-2 receiver writes the received data to memory as-is. The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.
@@ -205,7 +204,7 @@ Some devices support more efficient packing of metadata in conjunction with This format is little endian. -**Byte Order Of V4L2_META_FMT_GENERIC_CSI2_16.** +**Byte Order Of V4L2_META_FMT_GENERIC_16.** Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding. .. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{1.2cm}|p{.8cm}|
@@ -287,16 +286,15 @@ Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding. - x - x -.. _v4l2-meta-fmt-generic-csi2-24: +.. _v4l2-meta-fmt-generic-24: -V4L2_META_FMT_GENERIC_CSI2_24 ------------------------------ +V4L2_META_FMT_GENERIC_24 +------------------------ -V4L2_META_FMT_GENERIC_CSI2_24 contains 8-bit generic metadata packed in 24-bit -Data Units, with two padding bytes after every byte of metadata. This format is -typically used by CSI-2 receivers with a source that transmits -MEDIA_BUS_FMT_META_24 and the CSI-2 receiver writes the received data to memory -as-is. +V4L2_META_FMT_GENERIC_24 contains 8-bit generic metadata packed in 24-bit Data +Units, with two padding bytes after every byte of metadata. This format is also +used by CSI-2 receivers with a source that transmits MEDIA_BUS_FMT_META_24 and +the CSI-2 receiver writes the received data to memory as-is. The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.
drivers/media/pci/intel/ipu6/ipu6-isys-video.c +1 -1
@@ -105,7 +105,7 @@ const struct ipu6_isys_pixelformat ipu6_isys_pfmts[] = { IPU6_FW_ISYS_FRAME_FORMAT_RAW10, true }, { V4L2_META_FMT_GENERIC_CSI2_12, 12, 12, MEDIA_BUS_FMT_META_12, IPU6_FW_ISYS_FRAME_FORMAT_RAW12, true }, - { V4L2_META_FMT_GENERIC_CSI2_16, 16, 16, MEDIA_BUS_FMT_META_16, + { V4L2_META_FMT_GENERIC_16, 16, 16, MEDIA_BUS_FMT_META_16, IPU6_FW_ISYS_FRAME_FORMAT_RAW16, true }, };
drivers/media/v4l2-core/v4l2-ioctl.c +4 -4
@@ -1491,9 +1491,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_META_FMT_GENERIC_CSI2_10 : descr ="8-bit Generic Meta, 10b CSI-2" ;break ;case V4L2_META_FMT_GENERIC_CSI2_12 : descr ="8-bit Generic Meta, 12b CSI-2" ;break ;case V4L2_META_FMT_GENERIC_CSI2_14 : descr ="8-bit Generic Meta, 14b CSI-2" ;break ; -case V4L2_META_FMT_GENERIC_CSI2_16 : descr ="8-bit Generic Meta, 16b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_16 : descr ="8-bit Generic Meta, 16b" ;break ;case V4L2_META_FMT_GENERIC_CSI2_20 : descr ="8-bit Generic Meta, 20b CSI-2" ;break ; -case V4L2_META_FMT_GENERIC_CSI2_24 : descr ="8-bit Generic Meta, 24b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_24 : descr ="8-bit Generic Meta, 24b" ;break ;default :/* Compressed formats */
@@ -1581,9 +1581,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_META_FMT_GENERIC_CSI2_10 :case V4L2_META_FMT_GENERIC_CSI2_12 :case V4L2_META_FMT_GENERIC_CSI2_14 : -case V4L2_META_FMT_GENERIC_CSI2_16 : +case V4L2_META_FMT_GENERIC_16 :case V4L2_META_FMT_GENERIC_CSI2_20 : -case V4L2_META_FMT_GENERIC_CSI2_24 : +case V4L2_META_FMT_GENERIC_24 : fmt->flags |=V4L2_FMT_FLAG_META_LINE_BASED ;break ;default :
include/uapi/linux/videodev2.h +6 -6
@@ -905,12 +905,12 @@ struct v4l2_pix_format {* adding new ones! */ #define V4L2_META_FMT_GENERIC_8 v4l2_fourcc('M', 'E', 'T', '8')/* Generic 8-bit metadata */ -#define V4L2_META_FMT_GENERIC_CSI2_10 v4l2_fourcc('M', 'C', '1', 'A')/* 10-bit CSI-2 packed 8-bit metadata */ -#define V4L2_META_FMT_GENERIC_CSI2_12 v4l2_fourcc('M', 'C', '1', 'C')/* 12-bit CSI-2 packed 8-bit metadata */ -#define V4L2_META_FMT_GENERIC_CSI2_14 v4l2_fourcc('M', 'C', '1', 'E')/* 14-bit CSI-2 packed 8-bit metadata */ -#define V4L2_META_FMT_GENERIC_CSI2_16 v4l2_fourcc('M', 'C', '1', 'G')/* 16-bit CSI-2 packed 8-bit metadata */ -#define V4L2_META_FMT_GENERIC_CSI2_20 v4l2_fourcc('M', 'C', '1', 'K')/* 20-bit CSI-2 packed 8-bit metadata */ -#define V4L2_META_FMT_GENERIC_CSI2_24 v4l2_fourcc('M', 'C', '1', 'O')/* 24-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_10 v4l2_fourcc('M', 'E', 'C', 'A')/* 10-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_12 v4l2_fourcc('M', 'E', 'C', 'C')/* 12-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_14 v4l2_fourcc('M', 'E', 'C', 'E')/* 14-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_16 v4l2_fourcc('M', 'E', 'T', 'G')/* Generic 16-bit 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_20 v4l2_fourcc('M', 'E', 'C', 'K')/* 20-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_24 v4l2_fourcc('M', 'E', 'T', 'O')/* Generic 24-bit 8-bit metadata */ #endif /* priv field value to indicates that subsequent fields are valid. */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 18/73 Revert "media: uapi: v4l: Don't expose generic metadata formats to userspace"
In reply to Sakari AilusThis reverts commit d69c8429ea80af02e89e5b3eecb78e417ad049c8.
Now that the API has stabilised, make the generic metadata formats visible for the userspace again.
--- include/uapi/linux/videodev2.h | 2 -- 1 file changed, 2 deletions(-)
include/uapi/linux/videodev2.h +0 -2
@@ -899,7 +899,6 @@ struct v4l2_pix_format {#define V4L2_META_FMT_RPPX1_PARAMS v4l2_fourcc('D', 'R', '1', 'P')/* Dreamchip RPP-X1 Parameters */ #define V4L2_META_FMT_RPPX1_STATS v4l2_fourcc('D', 'R', '1', 'S')/* Dreamchip RPP-X1 Statistics */ -#ifdef __KERNEL__/* * Line-based metadata formats. Remember to update v4l_fill_fmtdesc() when * adding new ones!
@@ -911,7 +910,6 @@ struct v4l2_pix_format {#define V4L2_META_FMT_GENERIC_16 v4l2_fourcc('M', 'E', 'T', 'G')/* Generic 16-bit 8-bit metadata */ #define V4L2_META_FMT_GENERIC_CSI2_20 v4l2_fourcc('M', 'E', 'C', 'K')/* 20-bit CSI-2 packed 8-bit metadata */ #define V4L2_META_FMT_GENERIC_24 v4l2_fourcc('M', 'E', 'T', 'O')/* Generic 24-bit 8-bit metadata */ -#endif /* priv field value to indicates that subsequent fields are valid. */ #define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 19/73 media: v4l: Add V4L2_SUBDEV_ROUTE_FL_IMMUTABLE sub-device routing flag
In reply to Sakari AilusAdd a flag to denote immutable routes, V4L2_SUBDEV_ROUTE_FL_IMMUTABLE. Such routes cannot be changed and they're always active.
--- Documentation/userspace-api/media/v4l/dev-subdev.rst | 4 +++- .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst | 5 +++++ include/uapi/linux/v4l2-subdev.h | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/v4l/dev-subdev.rst +3 -1
@@ -569,7 +569,9 @@ internal pad always has a single stream only (0). Routes from an internal sink pad to an external source pad are created by the driver and can be activated and deactivated using the :ref:`V4L2_SUBDEV_ROUTE_FL_ACTIVE <v4l2-subdev-routing-flags>` flag, depending -on the device capabilities. +on the device capabilities. The :ref:`V4L2_SUBDEV_ROUTE_FL_IMMUTABLE +<v4l2-subdev-routing-flags>` flag indicates that the +``V4L2_SUBDEV_ROUTE_FLAG_ACTIVE`` of the route may not be unset. Interaction between routes, streams, formats and selections -----------------------------------------------------------
Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +5 -0
@@ -146,6 +146,11 @@ wants to retrieve the missing routes, it can issue a new * - V4L2_SUBDEV_ROUTE_FL_ACTIVE - 0x0001 - The route is enabled. Set by applications. + * - V4L2_SUBDEV_ROUTE_FL_IMMUTABLE + - 0x0002 + - The route is immutable. Set by the driver. Indicates that the + ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag of an immutable route may not be + unset. Return Value ============
include/uapi/linux/v4l2-subdev.h +5 -0
@@ -207,6 +207,11 @@ struct v4l2_subdev_capability {* on a video node. */ #define V4L2_SUBDEV_ROUTE_FL_ACTIVE (1U << 0) +/* +* Is the route immutable? The ACTIVE flag of an immutable route may not be +* unset. +*/ +#define V4L2_SUBDEV_ROUTE_FL_IMMUTABLE (1U << 1)/** * struct v4l2_subdev_route - A route inside a subdev
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 20/73 media: v4l: Add V4L2_SUBDEV_ROUTE_FL_STATIC sub-device routing flag
In reply to Sakari AilusAdd a flag to denote static routes, V4L2_SUBDEV_ROUTE_FL_STATIC. Such routes cannot be removed as they are related to hardware features.
--- .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst | 6 +++++- include/uapi/linux/v4l2-subdev.h | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +5 -1
@@ -150,7 +150,11 @@ wants to retrieve the missing routes, it can issue a new - 0x0002 - The route is immutable. Set by the driver. Indicates that the ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag of an immutable route may not be - unset. + unset. Implies ``V4L2_SUBDEV_ROUTE_FL_STATIC``. + * - ``V4L2_SUBDEV_ROUTE_FL_STATIC`` + - 0x0004 + - The route is static. Set by the driver. Indicates that the route is + always present and cannot be removed. Return Value ============
include/uapi/linux/v4l2-subdev.h +4 -0
@@ -212,6 +212,10 @@ struct v4l2_subdev_capability {* unset. */ #define V4L2_SUBDEV_ROUTE_FL_IMMUTABLE (1U << 1) +/* +* Is the route static? Routes with the STATIC flag are not removable. +*/ +#define V4L2_SUBDEV_ROUTE_FL_STATIC (1U << 2)/** * struct v4l2_subdev_route - A route inside a subdev
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 21/73 media: Documentation: There are either immutable or mutable routes
In reply to Sakari AilusDocument that each sub-device may have either immutable or mutable routes, not both of them.
--- Documentation/userspace-api/media/v4l/dev-subdev.rst | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/userspace-api/media/v4l/dev-subdev.rst +6 -0
@@ -614,6 +614,12 @@ and user-created routes are fully replaced when ``VIDIOC_SUBDEV_S_ROUTING`` is called on the sub-device. Such newly created routes have the device's default configuration for format and selection rectangles. +A sub-device may only have either static routes (routes that have +``V4L2_SUBDEV_ROUTE_FL_STATIC`` flag set) or routes that are all user-created or +user-removable (routes that do not have ``V4L2_SUBDEV_ROUTE_FL_STATIC`` +flag). Mixing static and non-static routes is not allowed in the same +sub-device. This is subject to change in the future. + Configuring streams -------------------
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 22/73 media: Documentation: Document IMMUTABLE and STATIC route flags
In reply to Sakari AilusInclude the V4L2_SUBDEV_ROUTE_FL_IMMUTABLE and V4L2_SUBDEV_ROUTE_FL_STATIC flags in V4L2 sub-device documentation that discusses routing.
--- .../userspace-api/media/v4l/dev-subdev.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
Documentation/userspace-api/media/v4l/dev-subdev.rst +9 -5
@@ -600,11 +600,15 @@ depending on the hardware. In all cases, however, only routes that have the ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag set are active. Devices generating the streams may allow enabling and disabling some of the -routes or have a fixed routing configuration. If the routes can be disabled, not -declaring the routes (or declaring them without ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` -flag set) in ``VIDIOC_SUBDEV_S_ROUTING`` will disable the routes. -``VIDIOC_SUBDEV_S_ROUTING`` will still return such routes back to the user in -the routes array, with the ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag unset. +routes or have a fixed routing configuration. Routes that are bound to hardware +resources and are always present are marked with ``V4L2_SUBDEV_ROUTE_FL_STATIC`` +flag. Static routes that cannot be disabled are marked with +``V4L2_SUBDEV_ROUTE_FL_IMMUTABLE`` route flag. Static routes can be disabled by +not declaring the routes (or declaring them without +``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag set) in +``VIDIOC_SUBDEV_S_ROUTING``. ``VIDIOC_SUBDEV_S_ROUTING`` will still return such +routes back to the user in the routes array, with the +``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag unset. Devices transporting the streams almost always have more configurability with respect to routing. Typically any route between the sub-device's sink and source
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 23/73 media: Documentation: Add subdev configuration models, raw sensor model
In reply to Sakari AilusSub-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 | 442 ++++++++++++++++++ .../media/v4l/common-raw-sensor.svg | 134 ++++++ .../userspace-api/media/v4l/dev-subdev.rst | 9 +- .../userspace-api/media/v4l/devices.rst | 1 + .../media/v4l/subdev-config-model.rst | 250 ++++++++++ 6 files changed, 836 insertions(+), 4 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
Documentation/userspace-api/media/drivers/camera-sensor.rst +4 -0
@@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -118,6 +120,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 +442 -0
442 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 +5 -4
@@ -721,7 +721,8 @@ To configure this pipeline, the userspace must take the following steps: :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls to configure each stream endpoint in each sub-device. - In case generic raw and metadata formats are used, :ref:`V4L2_CID_CFA_PATTERN - <image-source-control-cfa-pattern>` and :ref:`V4L2_CID_METADATA_LAYOUT - <image_source_control_metadata_layout>` controls are present on the source - sub-device to obtain the pixel array CFA pattern and metadata layout. + In case generic raw and metadata formats are used, + :ref:`V4L2_CID_CFA_PATTERN <image-source-control-cfa-pattern>` and + :ref:`V4L2_CID_METADATA_LAYOUT <image_source_control_metadata_layout>` + controls are present on the source sub-device to obtain the pixel array CFA + pattern and metadata layout.
Documentation/userspace-api/media/v4l/devices.rst +1 -0
@@ -24,4 +24,5 @@ Interfaces dev-touch dev-event dev-subdev + subdev-config-model dev-meta
Documentation/userspace-api/media/v4l/subdev-config-model.rst new file +250 -0
250 lines not on this page · raw message
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 24/73 media: v4l2-subdev: Prevent accessing internal pads without STREAMS cap
In reply to Sakari AilusThe internal pads are expected to be accessed by users that are aware of streams. Require the V4L2_SUBDEV_CLIENT_CAP_STREAMS client capability to be set before allowing accessing internal pads from the user space.
--- drivers/media/v4l2-core/v4l2-subdev.c | 39 ++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +36 -3
@@ -233,6 +233,18 @@ static int check_state(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,return 0 ; } +static inline int check_caps (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +const struct v4l2_subdev_client_info *ci, +u32 pad) +{ +if (ci && sd->entity.pads[pad].flags &MEDIA_PAD_FL_INTERNAL ) +return ci->caps &V4L2_SUBDEV_CLIENT_CAP_STREAMS ? +0 : -EINVAL ; + +return 0 ; +} +static inline int check_format (struct v4l2_subdev *sd,struct v4l2_subdev_state *state,struct v4l2_subdev_format *format)
@@ -244,6 +256,15 @@ static inline int check_format(struct v4l2_subdev *sd,check_state (sd, state, format->which, format->pad, format->stream); } +static inline int check_format_caps (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *format) +{ +return check_format (sd, state, format) ?: +check_caps (sd, state, ci, format->pad); +} + #define do_subdev_call(sd, check, o, f, args...) \ (!(sd)->ops->o->f ? -ENOIOCTLCMD : (check) ? : \ (sd)->ops->o->f(sd, ##args))
@@ -266,7 +287,7 @@ static int call_set_fmt(struct v4l2_subdev *sd,if (!sd->ops->pad->set_fmt && !sd->ops->pad->get_fmt)return -ENOIOCTLCMD ; - ret =check_format (sd, state, format); + ret =check_format_caps (sd, ci, state, format);if (ret)return ret;
@@ -331,12 +352,24 @@ static inline int check_selection(struct v4l2_subdev *sd,check_state (sd, state, sel->which, sel->pad, sel->stream); } +static inline int check_selection_caps (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_selection *sel) +{ +if (!sel) +return -EINVAL ; + +return check_selection (sd, state, sel) ? : +check_caps (sd, state, ci, sel->pad); +} +static int call_get_selection (struct v4l2_subdev *sd,const struct v4l2_subdev_client_info *ci,struct v4l2_subdev_state *state,struct v4l2_subdev_selection *sel) { -return do_subdev_call (sd,check_selection (sd, state, sel), +return do_subdev_call (sd,check_selection_caps (sd, ci, state, sel), pad, get_selection, ci, state, sel); }
@@ -345,7 +378,7 @@ static int call_set_selection(struct v4l2_subdev *sd,struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - return do_subdev_call(sd, check_selection(sd, state, sel), + return do_subdev_call(sd, check_selection_caps(sd, ci, state, sel),pad ,set_selection ,ci ,state ,sel ); }
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 25/73 media: subdev: Make get_fmt on INTERNAL pads without STREAMS an error
In reply to Sakari AilusInternal pads should only be accessible to file handles with V4L2_SUBDEV_CLIENT_CAP_STREAMS flag set. Return an error otherwise.
--- drivers/media/v4l2-core/v4l2-subdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-subdev.c +6 -1
@@ -887,8 +887,13 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,case VIDIOC_SUBDEV_G_FMT : {struct v4l2_subdev_format *format = arg; -if (!client_supports_streams) +if (!client_supports_streams) { +if (format->pad < sd->entity.num_pads && + sd->entity.pads[format->pad].flags &MEDIA_PAD_FL_INTERNAL ) +return -EINVAL ; + format->stream =0 ; + }memset (format->reserved,0 ,sizeof (format->reserved));memset (format->format.reserved,0 ,sizeof (format->format.reserved));
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 26/73 media: Documentation: Add scaling and post-scaler crop for common raw
In reply to Sakari AilusDocument scaling and post-scaler digital crop operations for the common raw sensor model.
--- .../media/v4l/subdev-config-model.rst | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +20 -6
@@ -146,12 +146,19 @@ binning and sub-sampling to achieve the desired size. 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 on the sensor's -data interface. +0/0. + +The 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 resulting image size is further output by the +sensor on the sensor's data interface. 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 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. Drivers may only support some or even none of these configurations, in which case they do not expose the corresponding selection rectangles. If any selection
@@ -220,12 +227,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. Setting the media bus code on this pad configures the output format.
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 27/73 media: uapi: Add MIPI CCS configuration model
In reply to Sakari AilusAdd a configuration model for MIPI CCS sensors and refer to the CCS driver documentation from it. If more drivers start implementing the CCS model the documentation should be split into two but that appears to be unlikely at the moment.
--- .../userspace-api/media/v4l/subdev-config-model.rst | 6 ++++++ include/uapi/linux/v4l2-controls.h | 1 + 2 files changed, 7 insertions(+)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +6 -0
@@ -262,3 +262,9 @@ 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`. + +MIPI Camera Command Set (CCS) model +----------------------------------- + +The MIPI Camera Command Set configuration model is implemented by the :ref:`CCS +driver <media-ccs-uapi>`.
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1286,6 +1286,7 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_CONFIG_MODEL (V4L2_CID_IMAGE_PROC_CLASS_BASE + 6)#define V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR (1U << 0) +#define V4L2_CONFIG_MODEL_MIPI_CCS (1U << 1)/* DV-class control IDs defined by V4L2 */ #define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 28/73 media: uapi: Add V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR
In reply to Sakari AilusAdd V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR client capability bit to signal the userspace's support for the common raw sensor model and document it. A specific capability bit is required for the purpose of adding support for the common raw sensor model to existing drivers that already have a well-established UAPI that cannot be modified without breaking the userspace.
--- .../userspace-api/media/v4l/ext-ctrls-image-process.rst | 2 ++ .../userspace-api/media/v4l/subdev-config-model.rst | 5 ++++- .../userspace-api/media/v4l/vidioc-subdev-g-client-cap.rst | 6 ++++++ drivers/media/v4l2-core/v4l2-subdev.c | 3 ++- include/uapi/linux/v4l2-subdev.h | 6 ++++++ 5 files changed, 20 insertions(+), 2 deletions(-)
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst +2 -0
@@ -60,6 +60,8 @@ Image Process Control IDs digital gain the control value needs to be 0x100. The no-gain configuration is also typically the default. +.. _v4l2-cid-config-model: + ``V4L2_CID_CONFIG_MODEL (bitmask)`` Which configuration models the sub-device supports. Please see :ref:`media_subdev_config_model`. This is a read-only control.
Documentation/userspace-api/media/v4l/subdev-config-model.rst +4 -1
@@ -41,7 +41,10 @@ necessarily offered by all drivers. A sub-device complies with the common raw sensor model if the ``V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR`` bit is set in the -``V4L2_CID_CONFIG_MODEL`` control of the sub-device. +``V4L2_CID_CONFIG_MODEL`` control of the sub-device. A client supporting the +common raw sensor model shall set the +``V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR`` :ref:`sub-device client capability +<VIDIOC_SUBDEV_G_CLIENT_CAP>` bit. The common raw camera sensor model is aligned with :ref:`media_using_camera_sensor_drivers`. Please refer to that regarding aspects
Documentation/userspace-api/media/v4l/vidioc-subdev-g-client-cap.rst +6 -0
@@ -91,6 +91,12 @@ is unknown to the kernel. ``which`` field. If this is not set (which is the default), the ``which`` field is forced to ``V4L2_SUBDEV_FORMAT_ACTIVE`` by the kernel. + * - ``V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR`` + - The client is aware of the :ref:`common raw sensor model + <media_subdev_config_model_common_raw_sensor>` and expects it where it + is supported, as indicated by the :ref:`V4L2_CID_CONFIG_MODEL + <v4l2-cid-config-model>` control bit + ``V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR``. Return Value ============
drivers/media/v4l2-core/v4l2-subdev.c +2 -1
@@ -1230,7 +1230,8 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,/* Filter out unsupported capabilities */ client_cap->capabilities &= (V4L2_SUBDEV_CLIENT_CAP_STREAMS | -V4L2_SUBDEV_CLIENT_CAP_INTERVAL_USES_WHICH ); +V4L2_SUBDEV_CLIENT_CAP_INTERVAL_USES_WHICH | +V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR ); subdev_fh->ci.caps = client_cap->capabilities;
include/uapi/linux/v4l2-subdev.h +6 -0
@@ -270,6 +270,12 @@ struct v4l2_subdev_routing {*/ #define V4L2_SUBDEV_CLIENT_CAP_INTERVAL_USES_WHICH (1ULL << 1) +/* +* The client is aware of the common raw sensor model and expects that on camera +* sensor UAPI where supported. +*/ +#define V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR (1ULL << 2) +/** * struct v4l2_subdev_client_capability - Capabilities of the client accessing * the subdev
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 29/73 media: uapi: Add V4L2_CID_BINNING_FACTORS control for binning configuration
In reply to Sakari AilusAdd V4L2_CID_BINNING_FACTORS control for configuring 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 | 12 ++++++++ .../media/v4l/ext-ctrls-image-source.rst | 30 +++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++ include/uapi/linux/v4l2-controls.h | 2 ++ 4 files changed, 46 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +12 -0
@@ -120,6 +120,18 @@ 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_FACTORS +<image_source_control_binning_factors>` control 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. + +Binning isn't affected by flipping. + .. _media_using_camera_sensor_drivers_embedded_data: Embedded data
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +30 -0
@@ -163,3 +163,33 @@ Image Source Control IDs interface for metadata streams. The control is used in conjunction with :ref:`generic metadata formats <media-bus-format-generic-meta>` formats to specify the layout of the data. + +.. _image_source_control_binning_factors: + +``V4L2_CID_BINNING_FACTORS (integer menu)`` + + This control determines 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 ``0x0003000100030002`` indicates binning by 3 +(horizontally) * 3/2 (vertically).
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
@@ -1161,6 +1161,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_CFA_PATTERN :return "Color Filter Array Pattern" ;case V4L2_CID_CFA_PATTERN_FLIP :return "CFA Pattern Flip" ;case V4L2_CID_METADATA_LAYOUT :return "Metadata Layout" ; +case V4L2_CID_BINNING_FACTORS :return "Binning Factors" ;/* Image processing controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1440,6 +1441,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_FACTORS :case V4L2_CID_LINK_FREQ : *type =V4L2_CTRL_TYPE_INTEGER_MENU ;break ;
include/uapi/linux/v4l2-controls.h +2 -0
@@ -1273,6 +1273,8 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_METADATA_LAYOUT (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12) +#define V4L2_CID_BINNING_FACTORS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 13) +/* Image processing controls */ #define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 30/73 media: uapi: Add controls for sub-sampling configuration
In reply to Sakari AilusSub-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.
--- .../media/drivers/camera-sensor.rst | 16 +++++++++++++--- .../media/v4l/ext-ctrls-image-source.rst | 11 +++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++ include/uapi/linux/v4l2-controls.h | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/drivers/camera-sensor.rst +13 -3
@@ -120,8 +120,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_FACTORS
@@ -130,7 +130,17 @@ 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. -Binning isn't affected by flipping. +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 <image_source_control_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. + +Binning and sub-sampling aren't affected by flipping. .. _media_using_camera_sensor_drivers_embedded_data:
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +11 -0
@@ -193,3 +193,14 @@ Image Source Control IDs For instance, a value of ``0x0003000100030002`` indicates binning by 3 (horizontally) * 3/2 (vertically). + +.. _image_source_control_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
@@ -1162,6 +1162,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_CFA_PATTERN_FLIP :return "CFA Pattern Flip" ;case V4L2_CID_METADATA_LAYOUT :return "Metadata Layout" ;case V4L2_CID_BINNING_FACTORS :return "Binning Factors" ; +case V4L2_CID_SUBSAMPLING_HORIZONTAL :return "Sub-Sampling Factor, Horizontal" ; +case V4L2_CID_SUBSAMPLING_VERTICAL :return "Sub-Sampling Factor, Vertical" ;/* Image processing controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
include/uapi/linux/v4l2-controls.h +2 -0
@@ -1274,6 +1274,8 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_METADATA_LAYOUT (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12)#define V4L2_CID_BINNING_FACTORS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 13) +#define V4L2_CID_SUBSAMPLING_HORIZONTAL (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 14) +#define V4L2_CID_SUBSAMPLING_VERTICAL (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 15)/* Image processing controls */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 31/73 media: uapi: Add new controls for camera sensor FLL and LLP
In reply to Sakari AilusAdd new controls for camera sensors, V4L2_CID_LINE_LENGTH_PIXELS and V4L2_CID_FRAME_LENGTH_LINES, to convey the combined size of the analogue crop rectangle and horizontal and vertical blanking.
The reason for adding the new controls is that they're much easier to use as the user doesn't have to be concerned of the analogue crop in the same context. Secondarily, the newly added common raw sensor model uses different values for the same.
--- .../userspace-api/media/v4l/ext-ctrls-image-source.rst | 10 ++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++ include/uapi/linux/v4l2-controls.h | 3 +++ 3 files changed, 15 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +10 -0
@@ -204,3 +204,13 @@ For instance, a value of ``0x0003000100030002`` indicates binning by 3 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. + +.. _image_source_control_frame_length: + +``V4L2_CID_FRAME_LENGTH_LINES (integer)`` + Frame length in lines. The value of the control is the number of lines + captured in the sensor's pixel array added to the vertical blanking. + +``V4L2_CID_LINE_LENGTH_PIXELS (integer)`` + Line length in pixels. The value of the control is the number of pixels per + line captured in the sensor's pixel array added to the horizontal blanking.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
@@ -1164,6 +1164,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_BINNING_FACTORS :return "Binning Factors" ;case V4L2_CID_SUBSAMPLING_HORIZONTAL :return "Sub-Sampling Factor, Horizontal" ;case V4L2_CID_SUBSAMPLING_VERTICAL :return "Sub-Sampling Factor, Vertical" ; +case V4L2_CID_FRAME_LENGTH_LINES :return "Frame Length in Lines" ; +case V4L2_CID_LINE_LENGTH_PIXELS :return "Line Length in Pixels" ;/* Image processing controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
include/uapi/linux/v4l2-controls.h +3 -0
@@ -1277,6 +1277,9 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_SUBSAMPLING_HORIZONTAL (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 14)#define V4L2_CID_SUBSAMPLING_VERTICAL (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 15) +#define V4L2_CID_FRAME_LENGTH_LINES (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 16) +#define V4L2_CID_LINE_LENGTH_PIXELS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 17) +/* Image processing controls */ #define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 32/73 media: v4l2-common: Add v4l2_sensor_fll_llp_set()
In reply to Sakari AilusAdd v4l2_sensor_fll_llp_set() to facilitate driver implementation of both blanking and line and frame lenght controls.
--- drivers/media/v4l2-core/v4l2-common.c | 66 +++++++++++++++++++++++++++ include/media/v4l2-common.h | 28 ++++++++++++ include/media/v4l2-mc.h | 1 + 3 files changed, 95 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +66 -0
@@ -862,3 +862,69 @@ struct clk *__devm_v4l2_sensor_clk_get(struct device *dev, const char *id,return clk_hw->clk; }EXPORT_SYMBOL_GPL (__devm_v4l2_sensor_clk_get); + +int v4l2_sensor_fll_llp_set (struct v4l2_ctrl *fll,struct v4l2_ctrl *vblank, +struct v4l2_ctrl *llp,struct v4l2_ctrl *hblank, +struct v4l2_ctrl *exposure, +const struct v4l2_mbus_framefmt *format, +struct v4l2_ctrl *src,bool *setting_ctrl, +int exposure_margin) +{ +struct v4l2_ctrl *dest; +s32 val; +int ret; + +/* Was setting the control user-initiated or were we called again? */ +if (*setting_ctrl) { + *setting_ctrl = false; +return 0 ; + } + +/* Are we being called for writing a value to a register? */ +if (src->val == src->cur.val) +return 0 ; + +switch (src->id) { +case V4L2_CID_FRAME_LENGTH_LINES : + dest = vblank; + val = src->val - format->height; +break ; +case V4L2_CID_VBLANK : + dest = fll; + val = src->val + format->height; +break ; +case V4L2_CID_LINE_LENGTH_PIXELS : + dest = hblank; + val = src->val - format->width; +break ; +case V4L2_CID_HBLANK : + dest = llp; + val = src->val + format->width; +break ; +default : +return -EINVAL ; + } + +if (val == dest->val) +return 0 ; + + *setting_ctrl = true; + + ret =__v4l2_ctrl_s_ctrl (dest, val); +if (ret) +return ret; + +/* +* Only modify exposure range when setting fll, directly or via vblank. +*/ +if (src->id !=V4L2_CID_FRAME_LENGTH_LINES && + dest->id !=V4L2_CID_FRAME_LENGTH_LINES ) +return 0 ; + +int exposure_max = fll->val - exposure_margin; + +return __v4l2_ctrl_modify_range (exposure, exposure->minimum, + exposure_max, exposure->step, + exposure_max); +} +EXPORT_SYMBOL_GPL (v4l2_sensor_fll_llp_set);
include/media/v4l2-common.h +28 -0
@@ -98,7 +98,9 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,/* ------------------------------------------------------------------------- */ struct clk ; +struct v4l2_ctrl ;struct v4l2_device ; +struct v4l2_mbus_framefmt ;struct v4l2_subdev ;struct v4l2_subdev_ops ;
@@ -825,4 +827,30 @@ static inline bool v4l2_is_quant_valid(__u8 quantization) quantization == V4L2_QUANTIZATION_LIM_RANGE; } +/** +* v4l2_sensor_fll_llp_set - Compatibility support for hblank and vblank +* controls +* +* @fll: Frame length in lines control +* @vblank: Vertical blanking control +* @llp: Line length in pixels control +* @hblank: Horizontal blanking control +* @exposure: Exposure control +* @format: Source pad format +* @src: The control being set -- one of the other four controls +* @setting_ctrl: Pointer to the sensor's setting_ctrl variable; false in +* initialisation +* @exposure_margin: The exposure margin of the sensor +* +* Compatiblity helper for handling frame time related controls for sensor +* drivers that support both the Common Raw Sensor Model and the legacy +* interface. +*/ +int v4l2_sensor_fll_llp_set (struct v4l2_ctrl *fll,struct v4l2_ctrl *vblank, +struct v4l2_ctrl *llp,struct v4l2_ctrl *hblank, +struct v4l2_ctrl *exposure, +const struct v4l2_mbus_framefmt *format, +struct v4l2_ctrl *src,bool *setting_ctrl, +int exposure_margin); +#endif /* V4L2_COMMON_H_ */
include/media/v4l2-mc.h +1 -0
@@ -18,6 +18,7 @@/* We don't need to include pci.h or usb.h here */ struct pci_dev ;struct usb_device ; +struct v4l2_ctrl ;#ifdef CONFIG_MEDIA_CONTROLLER /**
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 33/73 media: Documentation: Add binning and sub-sampling controls
In reply to Sakari AilusDocument the binning and sub-sampling controls (V4L2_CID_BINNING_FACTORS and V4L2_CID_SUBSAMPLING_{HORIZONTAL,VERTICAL}) in the common raw sensor model.
--- .../media/v4l/subdev-config-model.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +13 -5
@@ -144,8 +144,12 @@ separately horizontally and vertically. The combined effect of binning and sub-sampling is configured using the ``V4L2_SEL_TGT_COMPOSE`` rectangle, relative to the analogue crop rectangle, on -(pad, stream) pair 1/0. The driver implementation determines how to configure -binning and sub-sampling to achieve the desired size. +(pad, stream) pair 1/0. It depends on the driver which of these operations are +being used to achieve the resulting size. Binning and sub-sampling are also +directly configured using :ref:`V4L2_CID_BINNING_FACTORS +<image_source_control_binning_factors>` and +:ref:`V4L2_CID_SUBSAMPLING_HORIZONTAL and V4L2_CID_SUBSAMPLING_VERTICAL +<image_source_control_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
@@ -216,9 +220,13 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. - \- - \- - 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 expressed with this selection - target. + ``V4L2_SEL_TGT_CROP`` rectangle on the same (pad, stream). Binning is + configured using the :ref:`V4L2_CID_BINNING_FACTORS + <image_source_control_binning_factors>` control and sub-sampling is + configured using the :ref:`V4L2_CID_SUBSAMPLING_HORIZONTAL and + V4L2_CID_SUBSAMPLING_VERTICAL <image_source_control_subsampling>` + controls. The width and the height of this selection rectangle reflect + the combined effect of binning and subsampling. * - 2/0 - Format - X
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 34/73 media: v4l2-subdev: Set STATIC route flag if IMMUTABLE route flag is set
In reply to Sakari AilusAs the IMMUTABLE sub-device route flag implies the STATIC flag, do set the STATIC flag for all IMMUTABLE routes returned to the user space.
--- drivers/media/v4l2-core/v4l2-subdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-subdev.c +5 -1
@@ -725,7 +725,11 @@ static void v4l2_subdev_copy_routes(struct v4l2_subdev_routing *routing, (struct v4l2_subdev_route *)(uintptr_t )routing->routes;u32 copy_routes =min (routing->len_routes, state->routing.num_routes); -memcpy (routes, state->routing.routes,sizeof (*routes) * copy_routes); +for (u32 i =0 ; i < copy_routes; i++) { + routes[i] = state->routing.routes[i]; +if (routes[i].flags &V4L2_SUBDEV_ROUTE_FL_IMMUTABLE ) + routes[i].flags |=V4L2_SUBDEV_ROUTE_FL_STATIC ; + } routing->num_routes = state->routing.num_routes; }
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 35/73 media: uapi: v4l: subdev: Enable streams API
In reply to Sakari AilusRemove v4l2_subdev_enable_streams_api variable that was used to easily enable streams API for development, and conditions that use the variable.
This patch enables the streams API for V4L2 sub-device interface which allows transporting multiple streams on a single MC link.
--- drivers/media/v4l2-core/v4l2-subdev.c | 30 --------------------------- 1 file changed, 30 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +0 -30
@@ -50,15 +50,6 @@ struct v4l2_subdev_stream_config {struct v4l2_fract interval; }; -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API ) -/* -* The Streams API is an experimental feature. To use the Streams API, set -* 'v4l2_subdev_enable_streams_api' to 1 below. -*/ - -static bool v4l2_subdev_enable_streams_api; -#endif -/* * Maximum stream ID is 63 for now, as we use u64 bitmask to represent a set * of streams.
@@ -747,13 +738,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,V4L2_SUBDEV_CLIENT_CAP_STREAMS ;int rval; -/* -* If the streams API is not enabled, remove V4L2_SUBDEV_CAP_STREAMS. -* Remove this when the API is no longer experimental. -*/ -if (!v4l2_subdev_enable_streams_api) - streams_subdev = false; -switch (cmd) {case VIDIOC_SUBDEV_QUERYCAP : {struct v4l2_subdev_capability *cap = arg;
@@ -1112,9 +1096,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,case VIDIOC_SUBDEV_G_ROUTING : {struct v4l2_subdev_routing *routing = arg; -if (!v4l2_subdev_enable_streams_api) -return -ENOIOCTLCMD ; -if (!(sd->flags &V4L2_SUBDEV_FL_STREAMS ))return -ENOIOCTLCMD ;
@@ -1136,9 +1117,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,unsigned int num_active_routes =0 ;unsigned int i; -if (!v4l2_subdev_enable_streams_api) -return -ENOIOCTLCMD ; -if (!(sd->flags &V4L2_SUBDEV_FL_STREAMS ))return -ENOIOCTLCMD ;
@@ -1224,14 +1202,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,case VIDIOC_SUBDEV_S_CLIENT_CAP : {struct v4l2_subdev_client_capability *client_cap = arg; -/* -* Clear V4L2_SUBDEV_CLIENT_CAP_STREAMS if streams API is not -* enabled. Remove this when streams API is no longer -* experimental. -*/ -if (!v4l2_subdev_enable_streams_api) - client_cap->capabilities &= ~V4L2_SUBDEV_CLIENT_CAP_STREAMS ; -/* Filter out unsupported capabilities */ client_cap->capabilities &= (V4L2_SUBDEV_CLIENT_CAP_STREAMS | V4L2_SUBDEV_CLIENT_CAP_INTERVAL_USES_WHICH |
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 36/73 media: uapi: Add binning factor helper macros
In reply to Sakari AilusAdd helper macros for handling binning factor integer control menu items.
--- include/uapi/linux/v4l2-controls.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/uapi/linux/v4l2-controls.h +7 -0
@@ -1274,6 +1274,13 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_METADATA_LAYOUT (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12)#define V4L2_CID_BINNING_FACTORS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 13) +#define V4L2_BINNING_FACTORS_MAKE (hnum, hdem, vnum, vdem) \ + (((__u64)(0xffff & hnum) << 48) | ((__u64)(0xffff & hdem) << 32) | \ + ((__u64)(0xffff & vnum) << 16) | (__u64)(0xffff & vdem)) +#define V4L2_BINNING_FACTORS_HNUM (binning) (__u16)((binning >> 48) & 0xffff) +#define V4L2_BINNING_FACTORS_HDEM (binning) (__u16)((binning >> 32) & 0xffff) +#define V4L2_BINNING_FACTORS_VNUM (binning) (__u16)((binning >> 16) & 0xffff) +#define V4L2_BINNING_FACTORS_VDEM (binning) (__u16)(binning & 0xffff)#define V4L2_CID_SUBSAMPLING_HORIZONTAL (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 14)#define V4L2_CID_SUBSAMPLING_VERTICAL (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 15)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 37/73 media: Documentation: Document frame controls for common raw sensor model
In reply to Sakari AilusDocument that V4L2_CID_LINE_LENGTH_PIXELS V4L2_CID_FRAME_LENGTH_LINES are used to configure frame rate in common raw camera sensor model. Also mention the controls in camera sensor documentation.
--- .../userspace-api/media/drivers/camera-sensor.rst | 8 ++++++++ .../userspace-api/media/v4l/subdev-config-model.rst | 8 ++++++++ 2 files changed, 16 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +8 -0
@@ -61,6 +61,8 @@ There are two different methods for obtaining possibilities for different frame intervals as well as configuring the frame interval. Which one to implement depends on the type of the device. +.. _media_camera_sensor_frame_rate_raw: + Raw camera sensors ~~~~~~~~~~~~~~~~~~
@@ -78,6 +80,12 @@ The formula is bus independent and is applicable for raw timing parameters on large variety of devices beyond camera sensors. Devices that have no analogue crop, use the full source image size, i.e. pixel array size. +The combined *analogue crop width + horizontal blanking* and *analogue crop +height + vertical blanking* can be controlled directly using the +:ref:`V4L2_CID_LINE_LENGTH_PIXELS and V4L2_CID_FRAME_LENGTH_LINES +<image_source_control_frame_length>` controls, respectively, should the driver +support them. + Horizontal and vertical blanking are specified by ``V4L2_CID_HBLANK`` and ``V4L2_CID_VBLANK``, respectively. The unit of the ``V4L2_CID_HBLANK`` control is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in
Documentation/userspace-api/media/v4l/subdev-config-model.rst +8 -0
@@ -260,6 +260,14 @@ Also refer to :ref:`Selection targets <v4l2-selection-targets-table>`. - \- - Embedded data source format. +Frame rate +^^^^^^^^^^ + +Drivers supporting the Common raw camera sensor model support +:ref:`V4L2_CID_LINE_LENGTH_PIXELS and V4L2_CID_FRAME_LENGTH_LINES +<image_source_control_frame_length>` controls for :ref:`frame rate configuration +<media_camera_sensor_frame_rate_raw>`. + Embedded data ^^^^^^^^^^^^^
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 38/73 media: v4l2-ctrl: Improve v4l2_ctrl_g_ctrl{,int64} documentation
In reply to Sakari AilusImprove documentation of v4l2_ctrl_g_ctrl() and v4l2_ctrl_g_ctrl_int64() by documenting what the function returns on error (i.e. 0).
--- include/media/v4l2-ctrls.h | 4 ++++ 1 file changed, 4 insertions(+)
include/media/v4l2-ctrls.h +4 -0
@@ -1111,6 +1111,8 @@ const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);* used from within the &v4l2_ctrl_ops functions. * * This function is for integer type controls only. +* +* Returns: the value of the control or 0 on error. */ s32 v4l2_ctrl_g_ctrl (struct v4l2_ctrl *ctrl);
@@ -1162,6 +1164,8 @@ static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)* used from within the &v4l2_ctrl_ops functions. * * This function is for 64-bit integer type controls only. +* +* Returns: the value of the control or 0 on error. */ s64 v4l2_ctrl_g_ctrl_int64 (struct v4l2_ctrl *ctrl);
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 39/73 media: Documentation: Add sub-device internal pads example
In reply to Sakari AilusAdd an example using sub-device internal pads, with the Sony IMX219 camera sensor.
--- .../userspace-api/media/v4l/dev-subdev.rst | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+)
Documentation/userspace-api/media/v4l/dev-subdev.rst +129 -0
@@ -726,3 +726,132 @@ To configure this pipeline, the userspace must take the following steps: :ref:`V4L2_CID_METADATA_LAYOUT <image_source_control_metadata_layout>` controls are present on the source sub-device to obtain the pixel array CFA pattern and metadata layout. + +Internal pads setup example +--------------------------- + +A simple example of a multiplexed stream setup might be as follows: + +- An IMX219 camera sensor source sub-device, with one source pad (0), one + internal sink pad (1) as the source of the image data and an internal sink + pad (2) as the source of the embedded data. There are two routes, one from the + internal sink pad 1 to the source pad 0 (image data) and another from the + internal sink pad 2 to the source pad 0 (embedded data). Both streams are + always active, i.e. there is no need to separately enable the embedded data + stream. The sensor uses the CSI-2 interface. + +- A CSI-2 receiver in the SoC. The receiver has a single sink pad (pad 0), + connected to the sensor's source pad (0), and two source pads (pads 1 and 2), + to two DMA engines. The receiver demultiplexes the incoming streams to the + source pads. + +- Two DMA engines in the SoC, one for each stream. Each DMA engine is connected + to a different source pad of the receiver. + +The sensor and the receiver are modelled as V4L2 sub-devices, exposed to +userspace via /dev/v4l-subdevX device nodes. The DMA engines are modelled as +V4L2 video devices, exposed to userspace via /dev/videoX nodes. + +To configure this pipeline, the userspace must take the following steps: + +1) Set up media links between entities: enable the links from the sensor to the + receiver and from the receiver to the DMA engines. This step does not differ + from normal non-multiplexed media controller setup. + +2) Configure routing + +.. flat-table:: Camera sensor. There are no configurable routes. + :header-rows: 1 + + * - Sink Pad/Stream + - Source Pad/Stream + - Routing Flags + - Comments + * - 1/0 + - 0/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE | V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC + - Pixel data stream from the internal image sink pad + * - 2/0 + - 0/1 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE | V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC + - Metadata stream from the internal embedded data sink pad + +While both routes are immutable for the IMX219, other camera sensors may offer +more flexible configuration options. Routing configuration is dictated by the +hardware capabilities: camera sensors typically always produce an image data +stream, but some of them support enabling and disabling the embedded data +stream. + +.. flat-table:: Receiver routing table. Typically both routes need to be + explicitly created. + :header-rows: 1 + + * - Sink Pad/Stream + - Source Pad/Stream + - Routing Flags + - Comments + * - 0/0 + - 1/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Pixel data stream from camera sensor + * - 0/1 + - 2/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Metadata stream from camera sensor + +3) Configure formats + + This example assumes that the formats are propagated from sink pad to the + source pad as-is. The tables contain fields of both struct v4l2_subdev_format + and struct v4l2_mbus_framefmt. + +.. flat-table:: Formats set on the sub-devices. Bold values are set, others are + static or propagated. The order is aligned with configured + routes. + :header-rows: 1 + :fill-cells: + + * - Sub-device + - Pad/Stream + - Width + - Height + - Code + * - :rspan:`3` IMX219 + - 1/0 + - 3296 + - 2480 + - MEDIA_BUS_FMT_RAW_10 + * - 0/0 + - 3296 + - 2480 + - **MEDIA_BUS_FMT_RAW_10** + * - 2/0 + - 3296 + - 2 + - MEDIA_BUS_FMT_META_10 + * - 0/1 + - 3296 + - 2 + - MEDIA_BUS_FMT_META_10 + * - :rspan:`3` CSI-2 receiver + - 0/0 + - **3296** + - **2480** + - **MEDIA_BUS_FMT_RAW_10** + * - 1/0 + - 3296 + - 2480 + - MEDIA_BUS_FMT_RAW_10 + * - 0/1 + - **3296** + - **2** + - **MEDIA_BUS_FMT_META_10** + * - 2/0 + - 3296 + - 2 + - MEDIA_BUS_FMT_META_10 + +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.
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 40/73 media: Documentation: Document streaming behaviour for common raw cameras
In reply to Sakari AilusDocument that streaming control is based on stream number 0 and additional streams need to be started before that.
--- .../userspace-api/media/v4l/subdev-config-model.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/userspace-api/media/v4l/subdev-config-model.rst +10 -0
@@ -99,6 +99,16 @@ following routes. Support for the embedded data stream is optional. Drivers supporting the embedded data stream may allow disabling and enabling the route. +Starting and stopping streaming +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Starting and stopping streaming is controlled through the stream number 0; if +there's a desire to capture additional streams, such streams need to be started +before stream 0. All streams start and stop at the same moment. + +This is subject to change in the future through additional API elements while +the default behaviour will be maintained. + Sensor pixel array size, cropping and binning ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 41/73 media: Documentation: Add a note on Bayer raw mbus codes
In reply to Sakari AilusNow that we do have CFA-independent raw mbus codes, document that using them is required in sensor drivers and preferred in other drivers, too.
--- Documentation/driver-api/media/camera-sensor.rst | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/driver-api/media/camera-sensor.rst +11 -0
@@ -127,6 +127,17 @@ Use ``v4l2_fwnode_device_parse()`` to obtain rotation and orientation information from system firmware and ``v4l2_ctrl_new_fwnode_properties()`` to register the appropriate controls. +Media bus codes +--------------- + +Supporting the new :ref:`CFA-independent Media bus codes +<v4l2-mbus-pixelcode-generic-raw>` is required in new drivers on serial +interfaces and the old Bayer pattern specific Media bus codes are thus +deprecated. If the rest of the pipeline does not support the new generic raw +Media bus codes, the preference is to add support for the codes in the entire +pipeline instead of supporting old Bayer pattern specific mbus codes in a sensor +driver. + .. _media-camera-sensor-examples: Example drivers
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 42/73 media: uapi: Add generic raw pixelformats for 10, 12 and 14 bits
In reply to Sakari AilusAdd generic raw pixelformats for bit depths 10, 12 and 14 unpacked to 16 bits.
--- .../media/v4l/pixfmt-raw-generic.rst | 123 +++++++++++++++++- drivers/media/v4l2-core/v4l2-ioctl.c | 3 + include/uapi/linux/videodev2.h | 3 + 3 files changed, 126 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst +120 -3
@@ -1,8 +1,8 @@ .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -************************************************************************************************************************************ -V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE') -************************************************************************************************************************************ +****************************************************************************************************************************************************************************************************************************** +V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE'), V4L2_PIX_FMT_RAW_10 ('RAWA'), V4L2_PIX_FMT_RAW_12 ('RAWC'), V4L2_PIX_FMT_RAW_14 ('RAWE') +****************************************************************************************************************************************************************************************************************************** Generic line-based raw image data formats
@@ -175,3 +175,120 @@ Each cell is one byte. "P" denotes a pixel. P\ :sub:`11 bits 5--2` (bits 3--0) - P\ :sub:`31 bits 5--0` (bits 7--2), P\ :sub:`21 bits 5--4` (bits 1--0) + +.. _v4l2-pix-fmt-raw-10: + +V4L2_PIX_FMT_RAW_10 +------------------- + +V4L2_PIX_FMT_RAW_10 contains 10-bit image data, with each two consecutive +bytes forming a pixel value. This format is typically used by CSI-2 receivers +with a source that transmits MEDIA_BUS_FMT_RAW_10 and the CSI-2 receiver writes +the received data to memory unpacked. + +**Byte Order Of V4L2_PIX_FMT_RAW_10.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 7--0` + - P\ :sub:`00 bits 9--8` (bits 1--0) + - P\ :sub:`10 bits 7--0` + - P\ :sub:`10 bits 9--8` (bits 1--0) + - P\ :sub:`20 bits 7--0` + - P\ :sub:`20 bits 9--8` (bits 1--0) + - P\ :sub:`30 bits 7--0` + - P\ :sub:`30 bits 9--8` (bits 1--0) + * - start + 8: + - P\ :sub:`01 bits 7--0` + - P\ :sub:`01 bits 9--8` (bits 1--0) + - P\ :sub:`11 bits 7--0` + - P\ :sub:`11 bits 9--8` (bits 1--0) + - P\ :sub:`21 bits 7--0` + - P\ :sub:`21 bits 9--8` (bits 1--0) + - P\ :sub:`31 bits 7--0` + - P\ :sub:`31 bits 9--8` (bits 1--0) + +.. _v4l2-pix-fmt-raw-12: + +V4L2_PIX_FMT_RAW_12 +------------------- + +V4L2_PIX_FMT_RAW_12 contains 12-bit image data, with each two consecutive +bytes forming a pixel value. This format is typically used by CSI-2 receivers +with a source that transmits MEDIA_BUS_FMT_RAW_12 and the CSI-2 receiver writes +the received data to memory unpacked. + +**Byte Order Of V4L2_PIX_FMT_RAW_12.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 7--0` + - P\ :sub:`00 bits 11--8` (bits 3--0) + - P\ :sub:`10 bits 7--0` + - P\ :sub:`10 bits 11--8` (bits 3--0) + - P\ :sub:`20 bits 7--0` + - P\ :sub:`20 bits 11--8` (bits 3--0) + - P\ :sub:`30 bits 7--0` + - P\ :sub:`30 bits 11--8` (bits 3--0) + * - start + 8: + - P\ :sub:`01 bits 7--0` + - P\ :sub:`01 bits 11--8` (bits 3--0) + - P\ :sub:`11 bits 7--0` + - P\ :sub:`11 bits 11--8` (bits 3--0) + - P\ :sub:`21 bits 7--0` + - P\ :sub:`21 bits 11--8` (bits 3--0) + - P\ :sub:`31 bits 7--0` + - P\ :sub:`31 bits 11--8` (bits 3--0) + +.. _v4l2-pix-fmt-raw-14: + +V4L2_PIX_FMT_RAW_14 +------------------- + +V4L2_PIX_FMT_RAW_14 contains 14-bit image data, with each two consecutive +bytes forming a pixel value. This format is typically used by CSI-2 receivers +with a source that transmits MEDIA_BUS_FMT_RAW_14 and the CSI-2 receiver writes +the received data to memory unpacked. + +**Byte Order Of V4L2_PIX_FMT_RAW_14.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 7--0` + - P\ :sub:`00 bits 13--8` (bits 5--0) + - P\ :sub:`10 bits 7--0` + - P\ :sub:`10 bits 13--8` (bits 5--0) + - P\ :sub:`20 bits 7--0` + - P\ :sub:`20 bits 13--8` (bits 5--0) + - P\ :sub:`30 bits 7--0` + - P\ :sub:`30 bits 13--8` (bits 5--0) + * - start + 8: + - P\ :sub:`01 bits 7--0` + - P\ :sub:`01 bits 13--8` (bits 5--0) + - P\ :sub:`11 bits 7--0` + - P\ :sub:`11 bits 13--8` (bits 5--0) + - P\ :sub:`21 bits 7--0` + - P\ :sub:`21 bits 13--8` (bits 5--0) + - P\ :sub:`31 bits 7--0` + - P\ :sub:`31 bits 13--8` (bits 5--0)
drivers/media/v4l2-core/v4l2-ioctl.c +3 -0
@@ -1438,6 +1438,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_RAW_CSI2_10 : descr ="10-bit Raw, CSI-2 Packed" ;break ;case V4L2_PIX_FMT_RAW_CSI2_12 : descr ="12-bit Raw, CSI-2 Packed" ;break ;case V4L2_PIX_FMT_RAW_CSI2_14 : descr ="14-bit Raw, CSI-2 Packed" ;break ; +case V4L2_PIX_FMT_RAW_10 : descr ="10-bit Raw" ;break ; +case V4L2_PIX_FMT_RAW_12 : descr ="12-bit Raw" ;break ; +case V4L2_PIX_FMT_RAW_14 : descr ="14-bit Raw" ;break ;case V4L2_PIX_FMT_RAW_CRU20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;
include/uapi/linux/videodev2.h +3 -0
@@ -750,6 +750,9 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_RAW_CSI2_10 v4l2_fourcc('R', 'A', 'C', 'A')#define V4L2_PIX_FMT_RAW_CSI2_12 v4l2_fourcc('R', 'A', 'C', 'C')#define V4L2_PIX_FMT_RAW_CSI2_14 v4l2_fourcc('R', 'A', 'C', 'E') +#define V4L2_PIX_FMT_RAW_10 v4l2_fourcc('R', 'A', 'W', 'A') +#define V4L2_PIX_FMT_RAW_12 v4l2_fourcc('R', 'A', 'W', 'C') +#define V4L2_PIX_FMT_RAW_14 v4l2_fourcc('R', 'A', 'W', 'E')/* HSV formats */ #define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 43/73 media: uapi: Add more media bus codes for generic raw formats
In reply to Sakari AilusAdd new generic raw media bus codes for serial buses at bit depths or 16, 20, 24 and 28.
--- Documentation/userspace-api/media/v4l/subdev-formats.rst | 8 ++++++++ include/uapi/linux/media-bus-format.h | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/v4l/subdev-formats.rst +8 -0
@@ -3890,6 +3890,14 @@ affect the pattern is conveyed via the :ref:`V4L2_CID_CFA_PATTERN_FLIP - 12 * - MEDIA_BUS_FMT_RAW_14 - 14 + * - MEDIA_BUS_FMT_RAW_16 + - 16 + * - MEDIA_BUS_FMT_RAW_20 + - 20 + * - MEDIA_BUS_FMT_RAW_24 + - 24 + * - MEDIA_BUS_FMT_RAW_28 + - 28 Packed YUV Formats ^^^^^^^^^^^^^^^^^^
include/uapi/linux/media-bus-format.h +5 -1
@@ -190,10 +190,14 @@#define MEDIA_BUS_FMT_META_20 0x8006#define MEDIA_BUS_FMT_META_24 0x8007 -/* Generic (CFA independent) pixel data formats. Next is 0x9005. */ +/* Generic (CFA independent) pixel data formats. Next is 0x9009. */ #define MEDIA_BUS_FMT_RAW_8 0x9001#define MEDIA_BUS_FMT_RAW_10 0x9002#define MEDIA_BUS_FMT_RAW_12 0x9003#define MEDIA_BUS_FMT_RAW_14 0x9004 +#define MEDIA_BUS_FMT_RAW_16 0x9005 +#define MEDIA_BUS_FMT_RAW_20 0x9006 +#define MEDIA_BUS_FMT_RAW_24 0x9007 +#define MEDIA_BUS_FMT_RAW_28 0x9008#endif /* __LINUX_MEDIA_BUS_FORMAT_H */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 44/73 media: uapi: ccs: Add metadata layout for MIPI CCS embedded data
In reply to Sakari AilusAdd new metadata layout (V4L2_METADATA_LAYOUT_CCS) for MIPI CCS embedded data.
--- .../media/v4l/ext-ctrls-image-source.rst | 12 ++++++ .../userspace-api/media/v4l/meta-formats.rst | 1 + .../media/v4l/metadata-layouts.rst | 39 +++++++++++++++++++ .../media/v4l/metafmt-generic.rst | 2 + .../media/v4l/subdev-formats.rst | 5 +++ include/uapi/linux/v4l2-controls.h | 1 + 6 files changed, 60 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/metadata-layouts.rst
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +12 -0
@@ -164,6 +164,18 @@ Image Source Control IDs :ref:`generic metadata formats <media-bus-format-generic-meta>` formats to specify the layout of the data. +.. flat-table:: V4L2 metadata layouts + :header-rows: 1 + :stub-columns: 0 + :widths: 1 2 1 + + * - Macro name + - Synopsis + - Value + * - V4L2_METADATA_LAYOUT_CCS + - :ref:`CCS embedded data <media-metadata-layout-ccs>` + - 1 + .. _image_source_control_binning_factors: ``V4L2_CID_BINNING_FACTORS (integer menu)``
Documentation/userspace-api/media/v4l/meta-formats.rst +1 -0
@@ -17,6 +17,7 @@ These formats are used for the :ref:`metadata` interface only. metafmt-c3-isp metafmt-d4xx metafmt-generic + metadata-layouts metafmt-intel-ipu3 metafmt-pisp-be metafmt-pisp-fe
Documentation/userspace-api/media/v4l/metadata-layouts.rst new file +39 -0
@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later + +.. _media_metadata_layouts: + +Metadata Layouts +---------------- + +The :ref:`metadata layout control <image_source_control_metadata_layout>` +specifies the exact layout of the metadata stream while the a :ref:`generic +metadata mbus code <media-bus-format-generic-meta>` on the subdevice pads +only describe the size of the :term:`Data Unit`. + +.. _media-metadata-layout-ccs: + +MIPI CCS Embedded Data Layout (``V4L2_METADATA_LAYOUT_CCS``) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +`MIPI CCS <https://www.mipi.org/specifications/camera-command-set>`_ defines a +metadata layout for sensor embedded data, identified by +``V4L2_CID_METADATA_LAYOUT`` control value ``V4L2_METADATA_LAYOUT_CCS``, which +is used to store the register configuration used for capturing a given +frame. The layout itself is defined in the CCS specification. + +The CCS embedded data format (code ``0xa``) definition includes three levels: + +1. Padding within CSI-2 bus :term:`Data Unit` as documented in the MIPI CCS + specification. + +2. The tagged data format as documented in the MIPI CCS specification. + +3. Register addresses and register documentation as documented in the MIPI CCS + specification. + +The ``V4L2_METADATA_LAYOUT_CCS`` metadata layout value shall be used only by +devices that fulfill all three levels above. + +This metadata layout code is only used for "2-byte simplified tagged data +format" (code ``0xa``) but their use may be extended further in the future, to +cover other CCS embedded data format codes.
Documentation/userspace-api/media/v4l/metafmt-generic.rst +2 -0
@@ -8,6 +8,8 @@ V4L2_META_FMT_GENERIC_8 ('MET8'), V4L2_META_FMT_GENERIC_CSI2_10 ('MECA'), V4L2_M Generic line-based metadata formats +.. _v4l2-format-generic-meta: + Description ===========
Documentation/userspace-api/media/v4l/subdev-formats.rst +5 -0
@@ -8932,6 +8932,11 @@ content is more or less device specific but the data is transmitted and received by multiple devices that do not process the data in any way, simply writing it to system memory for processing in software at the end of the pipeline. +The exact layout of the data generated by the device is reported by the +:ref:`V4L2_CID_METADATA_LAYOUT <image_source_control_metadata_layout>` +control. For in-memory formats, :ref:`Generic line-based metadata formats +<v4l2-format-generic-meta>` are used. + "b" in an array cell signifies a byte of data, followed by the number of the bit and finally the bit number in subscript. "x" indicates a padding bit.
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1272,6 +1272,7 @@ enum v4l2_jpeg_chroma_subsampling { (V4L2_CFA_PATTERN_FLIP_HORIZONTAL | V4L2_CFA_PATTERN_FLIP_VERTICAL)#define V4L2_CID_METADATA_LAYOUT (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12) +#define V4L2_METADATA_LAYOUT_CCS 1U#define V4L2_CID_BINNING_FACTORS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 13)#define V4L2_BINNING_FACTORS_MAKE (hnum, hdem, vnum, vdem) \
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 45/73 media: Documentation: Document non-CCS use of CCS embedded data layout
In reply to Sakari AilusThe CCS embedded data layout has multiple aspects (packing, encoding and the rest, including register addresses and semantics). Explicitly allow non-compliant embedded data to use the two former to reduce redundant documentation.
--- .../userspace-api/media/drivers/camera-sensor.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/userspace-api/media/drivers/camera-sensor.rst +13 -0
@@ -170,3 +170,16 @@ via the ``VIDIOC_SUBDEV_S_ROUTING`` IOCTL. In general, changing the embedded data layout from the driver-configured values is not supported. The width of the metadata is device-specific and equal to or less than the width of the image data, as configured on the pixel data stream. + +CCS and non-CCS embedded data layout +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Embedded data which is fully compliant with CCS definitions uses :ref:`CCS +embedded data layout <media-metadata-layout-ccs>` (level 3) for :ref:`the +metadata layout control <image_source_control_metadata_layout>`. Device-specific +embedded data compliant with either MIPI CCS embedded data levels 1 or 2 only +shall not use CCS embedded data value ``V4L2_METADATA_LAYOUT_CCS`` for metadata +layout, but may refer to CCS embedded data documentation with the level of +conformance specified and omit documenting these aspects of the layout. The rest +of the device-specific embedded data layout is documented in the context of the +data layout itself.
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 46/73 media: ccs: Add support for generic raw mbus codes
In reply to Sakari AilusAdd support for generic media bus codes for 8, 10, 12 and 14 bits per pixel.
--- drivers/media/i2c/ccs/ccs-core.c | 54 ++++++++++++++++++++++---------- drivers/media/i2c/ccs/ccs.h | 2 ++ 2 files changed, 39 insertions(+), 17 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +37 -17
@@ -642,13 +642,18 @@ static const struct ccs_csi_data_format ccs_csi_data_formats[] = { { MEDIA_BUS_FMT_SRGGB8_1X8, 8, 8, CCS_PIXEL_ORDER_RGGB, }, { MEDIA_BUS_FMT_SBGGR8_1X8, 8, 8, CCS_PIXEL_ORDER_BGGR, }, { MEDIA_BUS_FMT_SGBRG8_1X8, 8, 8, CCS_PIXEL_ORDER_GBRG, }, + /* Generic formats are placed below. */ + { MEDIA_BUS_FMT_RAW_8, 8, 8, 0, true }, + { MEDIA_BUS_FMT_RAW_10, 10, 10, 0, true }, + { MEDIA_BUS_FMT_RAW_12, 12, 12, 0, true }, + { MEDIA_BUS_FMT_RAW_14, 14, 14, 0, true }, };static const char *pixel_order_str[] = {"GRBG" ,"RGGB" ,"BGGR" ,"GBRG" }; -#define to_csi_format_idx (fmt) (((unsigned long)(fmt) \ - - (unsigned long)ccs_csi_data_formats) \ - / sizeof(*ccs_csi_data_formats)) +#define to_csi_format_idx (fmt) \ + (((unsigned long)(fmt) - (unsigned long)ccs_csi_data_formats) \ + / sizeof(*ccs_csi_data_formats))static u32 ccs_pixel_order (struct ccs_sensor *sensor) {
@@ -669,27 +674,25 @@ static u32 ccs_pixel_order(struct ccs_sensor *sensor)static void ccs_update_mbus_formats (struct ccs_sensor *sensor) { -struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); +unsigned int mask = sensor->csi_format->is_generic ? ~0 : ~3 ;unsigned int csi_format_idx = -to_csi_format_idx (sensor->csi_format) & ~3 ; +to_csi_format_idx (sensor->csi_format) & mask;unsigned int internal_csi_format_idx = -to_csi_format_idx (sensor->internal_csi_format) & ~3 ; -unsigned int pixel_order =ccs_pixel_order (sensor); +to_csi_format_idx (sensor->internal_csi_format) & mask; +unsigned int pixel_order = sensor->csi_format->is_generic ? +0 :ccs_pixel_order (sensor);if (WARN_ON_ONCE (max (internal_csi_format_idx, csi_format_idx) + pixel_order >=ARRAY_SIZE (ccs_csi_data_formats)))return ; sensor->mbus_frame_fmts = - sensor->default_mbus_frame_fmts << pixel_order; + (sensor->default_mbus_frame_fmts << pixel_order) | + sensor->default_generic_mbus_frame_fmts; sensor->csi_format = &ccs_csi_data_formats[csi_format_idx + pixel_order]; sensor->internal_csi_format = - &ccs_csi_data_formats[internal_csi_format_idx - + pixel_order]; - -dev_dbg (&client->dev,"new pixel order %s\n" , - pixel_order_str[pixel_order]); + &ccs_csi_data_formats[internal_csi_format_idx + pixel_order]; }static const char *const ccs_test_patterns[] = {
@@ -896,7 +899,7 @@ static int ccs_init_controls(struct ccs_sensor *sensor)struct v4l2_fwnode_device_properties props;int rval; - rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,19 ); + rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,21 );if (rval)return rval;
@@ -1091,6 +1094,17 @@ static int ccs_init_controls(struct ccs_sensor *sensor)v4l2_ctrl_cluster (2 , &sensor->hflip); +v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler,NULL , +V4L2_CID_CFA_PATTERN , sensor->default_pixel_order, + sensor->default_pixel_order,1 , + sensor->default_pixel_order); + +v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler,NULL , +V4L2_CID_CFA_PATTERN_FLIP , +V4L2_CFA_PATTERN_FLIP_BOTH , +V4L2_CFA_PATTERN_FLIP_BOTH ,1 , +V4L2_CFA_PATTERN_FLIP_BOTH ); + rval =v4l2_ctrl_handler_init (&sensor->src->ctrl_handler,0 );if (rval)return rval;
@@ -1199,15 +1213,21 @@ static int ccs_get_mbus_formats(struct ccs_sensor *sensor)const struct ccs_csi_data_format *f = &ccs_csi_data_formats[j]; -if (f->pixel_order !=CCS_PIXEL_ORDER_GRBG ) -continue ; -if (f->width != fmt >>CCS_DATA_FORMAT_DESCRIPTOR_UNCOMPRESSED_SHIFT || f->compressed != (fmt &CCS_DATA_FORMAT_DESCRIPTOR_COMPRESSED_MASK ))continue ; +if (f->is_generic) { + sensor->default_generic_mbus_frame_fmts |= +BIT_U64 (j); +continue ; + } + +if (f->pixel_order !=CCS_PIXEL_ORDER_GRBG ) +continue ; +dev_dbg (&client->dev,"jolly good! %u\n" , j); sensor->default_mbus_frame_fmts |=BIT_U64 (j);
drivers/media/i2c/ccs/ccs.h +2 -0
@@ -170,6 +170,7 @@ struct ccs_csi_data_format {u8 width;u8 compressed;u8 pixel_order; +bool is_generic; };#define CCS_SUBDEVS 3
@@ -226,6 +227,7 @@ struct ccs_sensor {const struct ccs_csi_data_format *csi_format;const struct ccs_csi_data_format *internal_csi_format;u64 default_mbus_frame_fmts; +u64 default_generic_mbus_frame_fmts;int default_pixel_order;struct ccs_data_container sdata, mdata;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 47/73 media: ccs: Add support for embedded data stream
In reply to Sakari AilusAdd support for embedded data stream, in UAPI and frame descriptor.
This patch adds also a new embedded data pad (2) to the source sub-device.
--- drivers/media/i2c/ccs/ccs-core.c | 342 +++++++++++++++++++++++++++++-- drivers/media/i2c/ccs/ccs.h | 15 +- 2 files changed, 338 insertions(+), 19 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +327 -15
@@ -899,7 +899,7 @@ static int ccs_init_controls(struct ccs_sensor *sensor)struct v4l2_fwnode_device_properties props;int rval; - rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,21 ); + rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,22 );if (rval)return rval;
@@ -1105,6 +1105,12 @@ static int ccs_init_controls(struct ccs_sensor *sensor)V4L2_CFA_PATTERN_FLIP_BOTH ,1 , V4L2_CFA_PATTERN_FLIP_BOTH); +v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler,NULL , +V4L2_CID_METADATA_LAYOUT , +V4L2_METADATA_LAYOUT_CCS , +V4L2_METADATA_LAYOUT_CCS ,1 , +V4L2_METADATA_LAYOUT_CCS ); + rval =v4l2_ctrl_handler_init (&sensor->src->ctrl_handler,0 );if (rval)return rval;
@@ -1871,6 +1877,57 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)return rval; } +#define CCS_EMBEDDED_CODE_DEPTH (depth, half_depth) \ + depth, \ + CCS_EMB_DATA_CAPABILITY_TWO_BYTES_PER_RAW##depth, \ + CCS_EMB_DATA_CAPABILITY_NO_ONE_BYTE_PER_RAW##depth, \ + CCS_EMB_DATA_CTRL_RAW##half_depth##_PACKING_FOR_RAW##depth, \ + MEDIA_BUS_FMT_META_##half_depth, \ + MEDIA_BUS_FMT_META_##depth, \ + +static const struct ccs_embedded_code { +u8 depth; +u8 cap_two_bytes_per_sample; +u8 cap_no_legacy; +u8 ctrl; +u32 code_two_bytes; +u32 code_legacy; +} ccs_embedded_codes[] = { + {CCS_EMBEDDED_CODE_DEPTH (16 ,8 ) }, + {CCS_EMBEDDED_CODE_DEPTH (20 ,10 ) }, + {CCS_EMBEDDED_CODE_DEPTH (24 ,12 ) }, +}; + +static const struct ccs_embedded_code *ccs_embedded_code (unsigned int bpp) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (ccs_embedded_codes); i++) +if (ccs_embedded_codes[i].depth == bpp) +return ccs_embedded_codes + i; + +WARN_ON (1 ); + +return ccs_embedded_codes; +} + +static u32 +ccs_default_embedded_code (struct ccs_sensor *sensor, +const struct ccs_embedded_code *embedded_code) +{ +if (CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_two_bytes_per_sample)) +return embedded_code->code_two_bytes; + +if (!(CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_no_legacy))) +return embedded_code->code_legacy; + +WARN_ON (1 ); + +return embedded_code->code_legacy; +} +static int ccs_enable_streams (struct v4l2_subdev *subdev,struct v4l2_subdev_state *state,u32 pad,u64 streams_mask)
@@ -2003,6 +2060,22 @@ static int ccs_enable_streams(struct v4l2_subdev *subdev,if (rval <0 ) goto err_pm_put; +/* Configure embedded data */ +if (sensor->csi_format->compressed >=16 ) { +const struct ccs_embedded_code *embedded_code = +ccs_embedded_code (sensor->csi_format->compressed); +const struct v4l2_mbus_framefmt *meta_out_fmt = +v4l2_subdev_state_get_format (src_state,CCS_PAD_SRC , +CCS_STREAM_META ); + + rval =ccs_write (sensor,EMB_DATA_CTRL , + meta_out_fmt->code == + embedded_code->code_legacy ? +0 : embedded_code->ctrl); +if (rval <0 ) + goto err_pm_put; + } + if (CCS_LIM(sensor, FLASH_MODE_CAPABILITY) & (CCS_FLASH_MODE_CAPABILITY_SINGLE_STROBE | SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE) &&
@@ -2133,6 +2206,61 @@ static int ccs_enum_mbus_code(struct v4l2_subdev *subdev,dev_err (&client->dev,"subdev %s, pad %u, index %u\n" , subdev->name, code->pad, code->index); +if (subdev == &sensor->src->sd) { +if (code->pad ==CCS_PAD_META || + code->stream ==CCS_STREAM_META ) { +struct v4l2_mbus_framefmt *pix_fmt = +v4l2_subdev_state_get_format (sd_state, +CCS_PAD_SRC , +CCS_STREAM_PIXEL ); +const struct ccs_csi_data_format *csi_format = +ccs_validate_csi_data_format (sensor, + pix_fmt->code); +unsigned int i =0 ; +u32 codes[2 ]; + +switch (csi_format->compressed) { +case 8 : + codes[i++] =MEDIA_BUS_FMT_META_8 ; +break ; +case 10 : + codes[i++] =MEDIA_BUS_FMT_META_10 ; +break ; +case 12 : + codes[i++] =MEDIA_BUS_FMT_META_12 ; +break ; +case 14 : + codes[i++] =MEDIA_BUS_FMT_META_14 ; +break ; +case 16 : +case 20 : +case 24 : { +const struct ccs_embedded_code *embedded_code = +ccs_embedded_code (csi_format->compressed); + +if (CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_two_bytes_per_sample)) + codes[i++] = + embedded_code->code_two_bytes; + +if (!(CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_no_legacy))) + codes[i++] = embedded_code->code_legacy; +break ; + } +default : +WARN_ON (1 ); + } + +if (WARN_ON (i >ARRAY_SIZE (codes)) || code->index >= i) +return -EINVAL ; + + code->code = codes[code->index]; + +return 0 ; + } + } +if (subdev != &sensor->src->sd || code->pad !=CCS_PAD_SRC ) {if (code->index)return -EINVAL ;
@@ -2171,8 +2299,11 @@ static int ccs_get_format(struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - fmt->format = *v4l2_subdev_state_get_format(sd_state, fmt->pad); - fmt->format.code =ccs_get_mbus_code (subdev, fmt->pad); + fmt->format = *v4l2_subdev_state_get_format(sd_state, fmt->pad, + fmt->stream); + +if (fmt->pad !=CCS_PAD_META && fmt->stream !=CCS_STREAM_META ) + fmt->format.code =ccs_get_mbus_code (subdev, fmt->pad);return 0 ; }
@@ -2262,6 +2393,86 @@ static int ccs_set_format_source(struct v4l2_subdev *subdev,return ccs_pll_update (sensor); } +static inline unsigned int ccs_embedded_data_lines (struct ccs_sensor *sensor) +{ +return sensor->embedded_end - sensor->embedded_start; +} + +static int ccs_set_format_meta (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_mbus_framefmt *fmt) +{ +struct ccs_sensor *sensor =to_ccs_sensor (subdev); +const struct ccs_csi_data_format *csi_format; +struct v4l2_mbus_framefmt *pix_fmt; +struct v4l2_mbus_framefmt *meta_fmt; +struct v4l2_mbus_framefmt *meta_out_fmt; +u32 code; + + pix_fmt =v4l2_subdev_state_get_format (sd_state,CCS_PAD_SRC , +CCS_STREAM_PIXEL ); + meta_fmt =v4l2_subdev_state_get_format (sd_state,CCS_PAD_META ,0 ); + meta_out_fmt =v4l2_subdev_state_get_format (sd_state,CCS_PAD_SRC , +CCS_STREAM_META ); + + code = fmt ? fmt->code :0 ; + + meta_fmt->width = pix_fmt->width; + meta_fmt->height =ccs_embedded_data_lines (sensor); + + csi_format =ccs_validate_csi_data_format (sensor, pix_fmt->code); + +switch (csi_format->compressed) { +case 8 : + meta_fmt->code =MEDIA_BUS_FMT_META_8 ; +break ; +case 10 : + meta_fmt->code =MEDIA_BUS_FMT_META_10 ; +break ; +case 12 : + meta_fmt->code =MEDIA_BUS_FMT_META_12 ; +break ; +case 14 : + meta_fmt->code =MEDIA_BUS_FMT_META_14 ; +break ; +case 16 : +case 20 : +case 24 : { +const struct ccs_embedded_code *embedded_code; + + embedded_code =ccs_embedded_code (csi_format->compressed); + meta_fmt->code = +ccs_default_embedded_code (sensor, embedded_code); + +if (!(CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_no_legacy)) && + code == embedded_code->code_legacy) + meta_fmt->code = embedded_code->code_legacy; + +if (CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_two_bytes_per_sample) && + code == embedded_code->code_two_bytes) { + meta_fmt->code = embedded_code->code_two_bytes; + meta_fmt->width <<=1 ; + } + +break ; + } +default : +WARN_ON (1 ); +return 0 ; + } + + meta_out_fmt->width = meta_fmt->width; + meta_out_fmt->height = meta_fmt->height; + meta_out_fmt->code = meta_fmt->code; + +if (fmt) + *fmt = *meta_out_fmt; + +return 0 ; +} + static int ccs_set_format(struct v4l2_subdev *subdev, const struct v4l2_subdev_client_info *ci, struct v4l2_subdev_state *sd_state,
@@ -2271,10 +2482,21 @@ static int ccs_set_format(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *crop; +if (ssd == sensor->src && fmt->pad ==CCS_PAD_META ) +return ccs_get_format (subdev, sd_state, fmt); + +if (ssd == sensor->src && fmt->stream ==CCS_STREAM_META ) { +ccs_set_format_meta (subdev, sd_state, &fmt->format); + +return 0 ; + } +if (fmt->pad == ssd->source_pad) {int rval; rval =ccs_set_format_source (subdev, ci, sd_state, fmt); +if (ccs_embedded_data_lines (sensor) && ssd == sensor->src) +ccs_set_format_meta (subdev, sd_state,NULL );return rval; }
@@ -2526,6 +2748,12 @@ static int ccs_sel_supported(struct v4l2_subdev *subdev,struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev); +if (sel->stream !=CCS_STREAM_PIXEL ) +return -EINVAL ; + +if (sel->pad ==CCS_PAD_META ) +return -EINVAL ; +/* We only implement crop in three places. */ switch (sel->target) {case V4L2_SEL_TGT_CROP :
@@ -2575,7 +2803,8 @@ static int ccs_set_crop(struct v4l2_subdev *subdev,if (sel->pad == ssd->sink_pad) {struct v4l2_mbus_framefmt *mfmt = -v4l2_subdev_state_get_format (sd_state, sel->pad); +v4l2_subdev_state_get_format (sd_state, sel->pad, +CCS_STREAM_PIXEL ); src_size.width = mfmt->width; src_size.height = mfmt->height;
@@ -2637,7 +2866,9 @@ static int ccs_get_selection(struct v4l2_subdev *subdev, }else if (sel->pad == ssd->sink_pad) {struct v4l2_mbus_framefmt *sink_fmt =v4l2_subdev_state_get_format (sd_state, - ssd->sink_pad); + ssd->sink_pad, +CCS_STREAM_PIXEL ); + sel->r.top = sel->r.left =0 ; sel->r.width = sink_fmt->width; sel->r.height = sink_fmt->height;
@@ -2723,6 +2954,18 @@ static int ccs_get_frame_desc(struct v4l2_subdev *subdev, unsigned int pad, entry++; desc->num_entries++; +if (ccs_embedded_data_lines (sensor)) { +struct v4l2_mbus_framefmt *meta_out_fmt = +v4l2_subdev_state_get_format (sd_state,CCS_PAD_SRC , +CCS_STREAM_META ); + + entry->pixelcode = meta_out_fmt->code; + entry->stream =CCS_STREAM_META ; + entry->bus.csi2.dt =MIPI_CSI2_DT_EMBEDDED_8B ; + entry++; + desc->num_entries++; + } +v4l2_subdev_unlock_state (sd_state);return 0 ;
@@ -3063,7 +3306,8 @@ static int ccs_init_subdev(struct ccs_sensor *sensor, ssd->sensor = sensor; ssd->npads = num_pads; - ssd->source_pad = num_pads -1 ; + ssd->source_pad = + ssd == sensor->pixel_array ?CCS_PA_PAD_SRC :CCS_PAD_SRC ;v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name);
@@ -3077,6 +3321,10 @@ static int ccs_init_subdev(struct ccs_sensor *sensor, ssd->sd.owner =THIS_MODULE ; ssd->sd.dev = &client->dev;v4l2_set_subdevdata (&ssd->sd, client); + }else { + ssd->sd.flags |=V4L2_SUBDEV_FL_STREAMS ; + ssd->pads[CCS_PAD_META ].flags = +MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_INTERNAL ; } rval =media_entity_pads_init (&ssd->sd.entity, ssd->npads, ssd->pads);
@@ -3102,9 +3350,9 @@ static int ccs_init_state(struct v4l2_subdev *sd,unsigned int pad = ssd == sensor->pixel_array ?CCS_PA_PAD_SRC :CCS_PAD_SINK ;struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_state_get_format (sd_state, pad); +v4l2_subdev_state_get_format (sd_state, pad,CCS_STREAM_PIXEL );struct v4l2_rect *crop = -v4l2_subdev_state_get_crop (sd_state, pad); +v4l2_subdev_state_get_crop (sd_state, pad,CCS_STREAM_PIXEL );ccs_get_native_size (ssd, crop);
@@ -3116,7 +3364,8 @@ static int ccs_init_state(struct v4l2_subdev *sd,if (ssd == sensor->pixel_array)return 0 ; - fmt =v4l2_subdev_state_get_format (sd_state,CCS_PAD_SRC ); + fmt =v4l2_subdev_state_get_format (sd_state,CCS_PAD_SRC , +CCS_STREAM_PIXEL ); fmt->code = ssd == sensor->src ? sensor->csi_format->code : sensor->internal_csi_format->code; fmt->field =V4L2_FIELD_NONE ;
@@ -3126,6 +3375,47 @@ static int ccs_init_state(struct v4l2_subdev *sd,return 0 ; } +static int ccs_src_init_state (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state) +{ +struct v4l2_subdev_route routes[] = { + { + .sink_pad =CCS_PAD_SINK , + .source_pad =CCS_PAD_SRC , + .source_stream =CCS_STREAM_PIXEL , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE , + }, { + .sink_pad =CCS_PAD_META , + .source_pad =CCS_PAD_SRC , + .source_stream =CCS_STREAM_META , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE , + } + }; +struct v4l2_subdev_krouting routing = { + .routes = routes, + .num_routes =1 , + }; +struct ccs_subdev *ssd =to_ccs_subdev (sd); +struct ccs_sensor *sensor = ssd->sensor; +int rval; + +if (ccs_embedded_data_lines (sensor)) + routing.num_routes++; + + rval =v4l2_subdev_set_routing (sd, sd_state, &routing); +if (rval) +return rval; + + rval =ccs_init_state (sd, sd_state); +if (rval) +return rval; + +if (ccs_embedded_data_lines (sensor)) +ccs_set_format_meta (sd, sd_state,NULL ); + +return 0 ; +} +static const struct v4l2_subdev_video_ops ccs_video_ops = { .s_stream = v4l2_subdev_s_stream_helper, .pre_streamon = ccs_pre_streamon,
@@ -3138,6 +3428,14 @@ static const struct v4l2_subdev_pad_ops ccs_pad_ops = { .set_fmt = ccs_set_format, .get_selection = ccs_get_selection, .set_selection = ccs_set_selection, +}; + +static const struct v4l2_subdev_pad_ops ccs_src_pad_ops = { + .enum_mbus_code = ccs_enum_mbus_code, + .get_fmt = ccs_get_format, + .set_fmt = ccs_set_format, + .get_selection = ccs_get_selection, + .set_selection = ccs_set_selection, .enable_streams = ccs_enable_streams, .disable_streams = ccs_disable_streams, .get_frame_desc = ccs_get_frame_desc,
@@ -3154,6 +3452,12 @@ static const struct v4l2_subdev_ops ccs_ops = { .sensor = &ccs_sensor_ops, }; +static const struct v4l2_subdev_ops ccs_src_ops = { + .video = &ccs_video_ops, + .pad = &ccs_src_pad_ops, + .sensor = &ccs_sensor_ops, +}; +static const struct media_entity_operations ccs_entity_ops = { .link_validate = v4l2_subdev_link_validate, };
@@ -3162,8 +3466,8 @@ static const struct v4l2_subdev_internal_ops ccs_internal_ops = { .init_state = ccs_init_state, }; -static const struct v4l2_subdev_internal_ops ccs_internal_src_ops = { - .init_state = ccs_init_state, +static const struct v4l2_subdev_internal_ops ccs_src_internal_ops = { + .init_state = ccs_src_init_state, .registered = ccs_registered, .unregistered = ccs_unregistered, };
@@ -3305,8 +3609,8 @@ static int ccs_probe(struct i2c_client *client) sensor->src = &sensor->ssds[sensor->ssds_used]; -v4l2_i2c_subdev_init (&sensor->src->sd, client, &ccs_ops); - sensor->src->sd.internal_ops = &ccs_internal_src_ops; +v4l2_i2c_subdev_init (&sensor->src->sd, client, &ccs_src_ops); + sensor->src->sd.internal_ops = &ccs_src_internal_ops; sensor->regulators = devm_kcalloc(&client->dev, ARRAY_SIZE(ccs_regulators),
@@ -3573,12 +3877,20 @@ static int ccs_probe(struct i2c_client *client) goto out_cleanup; } - rval =ccs_init_subdev (sensor, sensor->scaler," scaler" ,2 , + rval =ccs_init_subdev (sensor, sensor->scaler," scaler" , + sensor->ssds_used !=CCS_SUBDEVS ? +CCS_PADS_NOMETA : +ccs_embedded_data_lines (sensor) ? +CCS_PADS :CCS_PADS_NOMETA ,MEDIA_ENT_F_PROC_VIDEO_SCALER ,"ccs scaler mutex" , &scaler_lock_key);if (rval) goto out_cleanup; - rval =ccs_init_subdev (sensor, sensor->binner," binner" ,2 , + rval =ccs_init_subdev (sensor, sensor->binner," binner" , + sensor->ssds_used ==CCS_SUBDEVS ? +CCS_PADS_NOMETA : +ccs_embedded_data_lines (sensor) ? +CCS_PADS :CCS_PADS_NOMETA ,MEDIA_ENT_F_PROC_VIDEO_SCALER ,"ccs binner mutex" , &binner_lock_key);if (rval)
drivers/media/i2c/ccs/ccs.h +11 -4
@@ -176,11 +176,18 @@ struct ccs_csi_data_format {#define CCS_SUBDEVS 3#define CCS_PA_PAD_SRC 0 -#define CCS_PAD_SINK 0 -#define CCS_PAD_SRC 1 -#define CCS_PADS 2 +enum { +CCS_PAD_SINK , +CCS_PAD_SRC , +CCS_PAD_META , +CCS_PADS_NOMETA =CCS_PAD_META , +CCS_PADS , +}; -#define CCS_STREAM_PIXEL 0 +enum { +CCS_STREAM_PIXEL , +CCS_STREAM_META , +};struct ccs_binning_subtype {u8 horizontal:4 ;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 48/73 media: Documentation: ccs: Document routing
In reply to Sakari AilusDocument which routes are available for the CCS driver (source) sub-device and what configuration are possible.
Also update copyright.
--- .../userspace-api/media/drivers/ccs.rst | 43 ++++++++++++++++++- .../media/v4l/metadata-layouts.rst | 2 + 2 files changed, 44 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/drivers/ccs.rst +42 -1
@@ -111,4 +111,45 @@ than in the centre. Shading correction needs to be enabled for luminance correction level to have an effect. -**Copyright** |copy| 2020 Intel Corporation +.. _media-ccs-routes: + +Routes +------ + +The CCS driver implements one or two :ref:`routes <subdev-routing>` in +its source sub-device (scaler sub-device if it exists for the device, otherwise +binner) depending on whether the sensor supports embedded data. (All CCS +compliant sensors do but the CCS driver supports preceding standards that did +not require embedded data support, too.) + +The first route of the CCS source sub-device is for pixel data (sink pad +0/stream 0 -> source pad 1/stream 0) and the second one is for embedded data +(internal sink pad 2/stream 0 -> source pad 1/stream 1). + +Embedded data +~~~~~~~~~~~~~ + +MIPI CCS supports generation of camera sensor embedded data. The metadata layout +used for this format on the internal sink pad is :ref:`V4L2_METADATA_LAYOUT_CCS +<media-metadata-layout-ccs>`. + +The bit depth of the CCS pixel data affects how the sensor will output the +embedded data, adding padding to align with CSI-2 bus :term:`Data Unit` for that +particular bit depth. This is indicated by the generic metadata format on the +source pad of the sensor's source sub-device. + +Devices supporting embedded data for bit depths greater than or equal to 16 may +support more dense packing or legacy single metadata byte per data unit, or both +of these. The supported embedded data formats can be enumerated and configured +on stream 1 of the source pad (1) of the CCS source sub-device. + +The use of the denser packing results in embedded data lines being longer than +the pixel data in data units since the data units are smaller. In bytes the +embedded data lines are still not longer than the image data lines. + +The embedded data format is determined by the sub-device image data format +configured on the source sub-device. The embedded data mbus code is only changed +when the bit depth of the image data changes in the source pad of the source +sub-device. + +**Copyright** |copy| 2020, 2024--2025 Intel Corporation
Documentation/userspace-api/media/v4l/metadata-layouts.rst +2 -0
@@ -37,3 +37,5 @@ devices that fulfill all three levels above. This metadata layout code is only used for "2-byte simplified tagged data format" (code ``0xa``) but their use may be extended further in the future, to cover other CCS embedded data format codes. + +Also see :ref:`CCS driver documentation <media-ccs-routes>`.
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 49/73 media: ccs: Add IMMUTABLE and STATIC route flags
In reply to Sakari AilusAdd immutable and static route flags to the routing table. The embedded data stream is always there.
--- drivers/media/i2c/ccs/ccs-core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +6 -2
@@ -3383,12 +3383,16 @@ static int ccs_src_init_state(struct v4l2_subdev *sd, .sink_pad = CCS_PAD_SINK, .source_pad = CCS_PAD_SRC, .source_stream = CCS_STREAM_PIXEL, - .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE | + V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC, }, { .sink_pad = CCS_PAD_META, .source_pad = CCS_PAD_SRC, .source_stream = CCS_STREAM_META, - .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE | + V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC, } }; struct v4l2_subdev_krouting routing = {
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 50/73 media: uapi: Add metadata layout for ov2740 embedded data
In reply to Sakari AilusAdd a metadata layout for ov2740 camera sensor embedded data and document it.
--- .../media/v4l/ext-ctrls-image-source.rst | 3 + .../media/v4l/metadata-layouts.rst | 73 +++++++++++++++++++ include/uapi/linux/v4l2-controls.h | 1 + 3 files changed, 77 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +3 -0
@@ -175,6 +175,9 @@ Image Source Control IDs * - V4L2_METADATA_LAYOUT_CCS - :ref:`CCS embedded data <media-metadata-layout-ccs>` - 1 + * - V4L2_METADATA_LAYOUT_OV2740 + - :ref:`OV2740 embedded data <media-metadata-layout-ov2740>` + - 2 .. _image_source_control_binning_factors:
Documentation/userspace-api/media/v4l/metadata-layouts.rst +73 -0
76 lines not on this page · raw message
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1273,6 +1273,7 @@ enum v4l2_jpeg_chroma_subsampling {#define V4L2_CID_METADATA_LAYOUT (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12)#define V4L2_METADATA_LAYOUT_CCS 1U +#define V4L2_METADATA_LAYOUT_OV2740 2U#define V4L2_CID_BINNING_FACTORS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 13)#define V4L2_BINNING_FACTORS_MAKE (hnum, hdem, vnum, vdem) \
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 51/73 media: ov2740: Add support for embedded data
In reply to Sakari AilusAdd support for embedded data. This introduces two internal pads for pixel and embedded data streams. As the driver supports a single mode only, there's no need for backward compatibility in mode selection.
The embedded data is configured to be placed before the image data whereas after the image data is the default.
This patch includes switching to {enable,disable}_streams as well.
--- drivers/media/i2c/ov2740.c | 258 ++++++++++++++++++++++++++++--------- 1 file changed, 197 insertions(+), 61 deletions(-)
drivers/media/i2c/ov2740.c +197 -61
@@ -12,6 +12,7 @@#include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/unaligned.h> +#include <media/mipi-csi2.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-fwnode.h>
@@ -23,6 +24,11 @@#define OV2740_DATA_LANES 2#define OV2740_RGB_DEPTH 10 +#define OV2740_CROP_TOP 4U +#define OV2740_CROP_LEFT 4U +#define OV2740_ACTIVE_WIDTH 1936U +#define OV2740_ACTIVE_HEIGHT 1096U +#define OV2740_REG_CHIP_ID 0x300a#define OV2740_CHIP_ID 0x2740
@@ -72,6 +78,15 @@#define OV2740_REG_ISP_CTRL00 0x5000/* ISP CTRL01 */ #define OV2740_REG_ISP_CTRL01 0x5001 + +/* Embedded data line location control */ +#define OV2740_REG_EMBEDDED_FLAG 0x5a08 +#define OV2740_EMBEDDED_FLAG_FOOTER BIT(2)/* otherwise it's in header */ +#define OV2740_EMBEDDED_FLAG_MYSTERY BIT(1) +#define OV2740_REG_EMBEDDED_DT 0x3036 +#define OV2740_REG_EMBEDDED_CTRL 0x4307 +#define OV2740_EMBEDDED_CTRL_MYSTERY 0x30 +#define OV2740_EMBEDDED_CTRL_ENABLE BIT(0)/* Customer Addresses: 0x7010 - 0x710F */ #define CUSTOMER_USE_OTP_SIZE 0x100/* OTP registers from sensor */
@@ -83,6 +98,21 @@ static const char * const ov2740_supply_name[] = { "DVDD", }; +enum { +OV2740_PAD_SOURCE , +OV2740_PAD_PIXEL , +OV2740_PAD_META , +OV2740_NUM_PADS , +}; + +enum { +OV2740_STREAM_PIXEL , +OV2740_STREAM_META , +}; + +#define OV2740_META_WIDTH 100U +#define OV2740_META_HEIGHT 1U +struct nvm_data {struct nvmem_device *nvmem;struct regmap *regmap;
@@ -156,6 +186,7 @@ static const struct ov2740_reg mode_1932x1092_regs_360mhz[] = { {0x3000, 0x00}, {0x3018, 0x32}, {0x3031, 0x0a}, + {OV2740_REG_EMBEDDED_DT, MIPI_CSI2_DT_EMBEDDED_8B}, {0x3080, 0x08}, {0x3083, 0xB4}, {0x3103, 0x00},
@@ -260,7 +291,8 @@ static const struct ov2740_reg mode_1932x1092_regs_360mhz[] = { {0x4017, 0x10}, {0x4044, 0x02}, {0x4304, 0x08}, - {0x4307, 0x30}, + {OV2740_REG_EMBEDDED_CTRL, + OV2740_EMBEDDED_CTRL_MYSTERY | OV2740_EMBEDDED_CTRL_ENABLE}, {0x4320, 0x80}, {0x4322, 0x00}, {0x4323, 0x00},
@@ -309,6 +341,7 @@ static const struct ov2740_reg mode_1932x1092_regs_180mhz[] = { {0x3000, 0x00}, {0x3018, 0x32}, /* 0x32 for 2 lanes, 0x12 for 1 lane */ {0x3031, 0x0a}, + {OV2740_REG_EMBEDDED_DT, MIPI_CSI2_DT_EMBEDDED_8B}, {0x3080, 0x08}, {0x3083, 0xB4}, {0x3103, 0x00},
@@ -413,7 +446,8 @@ static const struct ov2740_reg mode_1932x1092_regs_180mhz[] = { {0x4017, 0x10}, {0x4044, 0x02}, {0x4304, 0x08}, - {0x4307, 0x30}, + {OV2740_REG_EMBEDDED_CTRL, + OV2740_EMBEDDED_CTRL_MYSTERY | OV2740_EMBEDDED_CTRL_ENABLE}, {0x4320, 0x80}, {0x4322, 0x00}, {0x4323, 0x00},
@@ -522,7 +556,7 @@ struct ov2740 {struct device *dev;struct v4l2_subdev sd; -struct media_pad pad; +struct media_pad pads[OV2740_NUM_PADS ];struct v4l2_ctrl_handler ctrl_handler;/* V4L2 Controls */
@@ -837,15 +871,6 @@ static int ov2740_init_controls(struct ov2740 *ov2740)return 0 ; } -static void ov2740_update_pad_format (const struct ov2740_mode *mode, -struct v4l2_mbus_framefmt *fmt) -{ - fmt->width = mode->width; - fmt->height = mode->height; - fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; - fmt->field =V4L2_FIELD_NONE ; -} -static int ov2740_load_otp_data (struct nvm_data *nvm) {struct device *dev =regmap_get_device (nvm->regmap);
@@ -936,15 +961,25 @@ static int ov2740_load_otp_data(struct nvm_data *nvm)return ret; } -static int ov2740_start_streaming (struct ov2740 *ov2740) +static int ov2740_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) { +struct ov2740 *ov2740 =to_ov2740 (sd);const struct ov2740_reg_list *reg_list;int link_freq_index;int ret; +if (!(streams_mask &1ULL )) +return 0 ; + + ret =pm_runtime_resume_and_get (ov2740->dev); +if (ret <0 ) +return ret; + ret =ov2740_identify_module (ov2740);if (ret) -return ret; + goto out_pm_put;if (ov2740->nvm)ov2740_load_otp_data (ov2740->nvm);
@@ -953,7 +988,7 @@ static int ov2740_start_streaming(struct ov2740 *ov2740) ret =ov2740_write_reg (ov2740,0x0103 ,1 ,0x01 );if (ret) {dev_err (ov2740->dev,"failed to reset\n" ); -return ret; + goto out_pm_put; }usleep_range (10000 ,15000 );
@@ -963,83 +998,98 @@ static int ov2740_start_streaming(struct ov2740 *ov2740) ret =ov2740_write_reg_list (ov2740, reg_list);if (ret) {dev_err (ov2740->dev,"failed to set plls\n" ); -return ret; + goto out_pm_put; } reg_list = &ov2740->cur_mode->reg_list; ret =ov2740_write_reg_list (ov2740, reg_list);if (ret) {dev_err (ov2740->dev,"failed to set mode\n" ); -return ret; + goto out_pm_put; } ret =__v4l2_ctrl_handler_setup (ov2740->sd.ctrl_handler);if (ret) -return ret; + goto out_pm_put; + + ret =ov2740_write_reg (ov2740,OV2740_REG_EMBEDDED_FLAG ,1 , +OV2740_EMBEDDED_FLAG_MYSTERY ); +if (ret) + goto out_pm_put; ret =ov2740_write_reg (ov2740,OV2740_REG_MODE_SELECT ,1 ,OV2740_MODE_STREAMING ); -if (ret) +if (ret) {dev_err (ov2740->dev,"failed to start streaming\n" ); + goto out_pm_put; + } -return ret; -} +return 0 ; -static void ov2740_stop_streaming (struct ov2740 *ov2740) -{ -if (ov2740_write_reg (ov2740,OV2740_REG_MODE_SELECT ,1 , -OV2740_MODE_STANDBY )) -dev_err (ov2740->dev,"failed to stop streaming\n" ); +out_pm_put: +pm_runtime_put (ov2740->dev); + +return ret; } -static int ov2740_set_stream (struct v4l2_subdev *sd,int enable) +static int ov2740_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) {struct ov2740 *ov2740 =to_ov2740 (sd); -struct v4l2_subdev_state *sd_state; -int ret =0 ; - - sd_state =v4l2_subdev_lock_and_get_active_state (&ov2740->sd); +int ret; -if (enable) { - ret =pm_runtime_resume_and_get (ov2740->dev); -if (ret <0 ) - goto out_unlock; +if (!(streams_mask &1ULL )) +return 0 ; - ret =ov2740_start_streaming (ov2740); -if (ret) { - enable =0 ; -ov2740_stop_streaming (ov2740); -pm_runtime_put (ov2740->dev); - } - }else { -ov2740_stop_streaming (ov2740); -pm_runtime_put (ov2740->dev); - } + ret =ov2740_write_reg (ov2740,OV2740_REG_MODE_SELECT ,1 , +OV2740_MODE_STANDBY ); -out_unlock: -v4l2_subdev_unlock_state (sd_state); +pm_runtime_put (ov2740->dev);return ret; } -static int ov2740_set_format (struct v4l2_subdev *sd, -const struct v4l2_subdev_client_info *ci, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) +static int __ov2740_set_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_mbus_framefmt *format, +enum v4l2_subdev_format_whence which, +unsigned int pad,unsigned int stream) { +struct v4l2_mbus_framefmt *src_pix_fmt, *src_meta_fmt, *meta_fmt;struct ov2740 *ov2740 =to_ov2740 (sd);const struct ov2740_mode *mode;s32 vblank_def, h_blank; +/* +* Allow setting format on internal pixel pad as well as the source +* pad's pixel stream (for compatibility). +*/ +if ((pad ==OV2740_PAD_SOURCE && stream ==OV2740_STREAM_META ) || + pad ==OV2740_PAD_META ) { + *format = *v4l2_subdev_state_get_format (sd_state, pad, stream); +return 0 ; + } + + meta_fmt =v4l2_subdev_state_get_format (sd_state,OV2740_PAD_META ,0 ); + src_pix_fmt =v4l2_subdev_state_get_format (sd_state,OV2740_PAD_SOURCE , +OV2740_STREAM_PIXEL ); + src_meta_fmt =v4l2_subdev_state_get_format (sd_state,OV2740_PAD_SOURCE , +OV2740_STREAM_META ); + mode =v4l2_find_nearest_size (ov2740->supported_modes, ov2740->supported_modes_count, width, height, - fmt->format.width, fmt->format.height); + format->width, format->height); -ov2740_update_pad_format (mode, &fmt->format); - *v4l2_subdev_state_get_format (sd_state, fmt->pad) = fmt->format; + src_pix_fmt->code = format->code; + src_pix_fmt->width = mode->width; + src_pix_fmt->height = mode->height; -if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) + *format = *src_pix_fmt; + *src_meta_fmt = *meta_fmt; + +if (which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; ov2740->cur_mode = mode;
@@ -1059,6 +1109,15 @@ static int ov2740_set_format(struct v4l2_subdev *sd,return 0 ; } +static int ov2740_set_format (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +return __ov2740_set_format (sd, sd_state, &fmt->format, fmt->which, + fmt->pad, fmt->stream); +} +static int ov2740_enum_mbus_code (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)
@@ -1095,15 +1154,84 @@ static int ov2740_enum_frame_size(struct v4l2_subdev *sd,static int ov2740_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state) { +struct v4l2_subdev_route routes[] = { + { + .sink_pad =OV2740_PAD_PIXEL , + .source_pad =OV2740_PAD_SOURCE , + .source_stream =OV2740_STREAM_PIXEL , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE , + }, { + .sink_pad =OV2740_PAD_META , + .source_pad =OV2740_PAD_SOURCE , + .source_stream =OV2740_STREAM_META , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE , + }, + }; +struct v4l2_subdev_krouting routing = { + .routes = routes, + .num_routes =ARRAY_SIZE (routes), + };struct ov2740 *ov2740 =to_ov2740 (sd); +int ret; + + ret =v4l2_subdev_set_routing (sd, sd_state, &routing); +if (ret) +return ret; + +struct v4l2_subdev_state *active_state = +v4l2_subdev_get_locked_active_state (sd); +struct v4l2_mbus_framefmt *pix_fmt = +v4l2_subdev_state_get_format (sd_state,OV2740_PAD_PIXEL ,0 ); + + pix_fmt->code =MEDIA_BUS_FMT_RAW_10 ; + pix_fmt->width =OV2740_CROP_LEFT +OV2740_ACTIVE_WIDTH ; + pix_fmt->height =OV2740_CROP_TOP +OV2740_ACTIVE_HEIGHT ; + pix_fmt->field =V4L2_FIELD_NONE ; + +struct v4l2_mbus_framefmt *meta_fmt = +v4l2_subdev_state_get_format (sd_state,OV2740_PAD_META ,0 ); + + meta_fmt->code =MEDIA_BUS_FMT_META_10 ; + meta_fmt->width =OV2740_META_WIDTH ; + meta_fmt->height =OV2740_META_HEIGHT ; + +return __ov2740_set_format (sd, sd_state, pix_fmt, + active_state == sd_state ? +V4L2_SUBDEV_FORMAT_ACTIVE : +V4L2_SUBDEV_FORMAT_TRY ,OV2740_PAD_PIXEL ,0 ); +} + +static int ov2740_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_frame_desc *desc) +{ +struct v4l2_mbus_frame_desc_entry *entry = desc->entry; +struct v4l2_subdev_state *sd_state; +struct v4l2_mbus_framefmt *fmt; + + desc->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; + + sd_state =v4l2_subdev_lock_and_get_active_state (sd); + fmt =v4l2_subdev_state_get_format (sd_state,OV2740_PAD_SOURCE , +OV2740_STREAM_PIXEL ); + entry->pixelcode = fmt->code; +v4l2_subdev_unlock_state (sd_state); + + entry->stream =OV2740_STREAM_PIXEL ; + entry->bus.csi2.dt =MIPI_CSI2_DT_RAW10 ; + entry++; + desc->num_entries++; + + entry->pixelcode =MEDIA_BUS_FMT_META_10 ; + entry->stream =OV2740_STREAM_META ; + entry->bus.csi2.dt =MIPI_CSI2_DT_EMBEDDED_8B ; + entry++; + desc->num_entries++; -ov2740_update_pad_format (&ov2740->supported_modes[0 ], -v4l2_subdev_state_get_format (sd_state,0 ));return 0 ; }static const struct v4l2_subdev_video_ops ov2740_video_ops = { - .s_stream = ov2740_set_stream, + .s_stream = v4l2_subdev_s_stream_helper, };static const struct v4l2_subdev_pad_ops ov2740_pad_ops = {
@@ -1111,6 +1239,9 @@ static const struct v4l2_subdev_pad_ops ov2740_pad_ops = { .set_fmt = ov2740_set_format, .enum_mbus_code = ov2740_enum_mbus_code, .enum_frame_size = ov2740_enum_frame_size, + .enable_streams = ov2740_enable_streams, + .disable_streams = ov2740_disable_streams, + .get_frame_desc = ov2740_get_frame_desc, };static const struct v4l2_subdev_ops ov2740_subdev_ops = {
@@ -1408,11 +1539,16 @@ static int ov2740_probe(struct i2c_client *client) } ov2740->sd.state_lock = ov2740->ctrl_handler.lock; - ov2740->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov2740->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE |V4L2_SUBDEV_FL_STREAMS ; ov2740->sd.entity.ops = &ov2740_subdev_entity_ops; ov2740->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; - ov2740->pad.flags =MEDIA_PAD_FL_SOURCE ; - ret =media_entity_pads_init (&ov2740->sd.entity,1 , &ov2740->pad); + ov2740->pads[OV2740_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ; + ov2740->pads[OV2740_PAD_PIXEL ].flags = +MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_INTERNAL ; + ov2740->pads[OV2740_PAD_META ].flags = +MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_INTERNAL ; + ret =media_entity_pads_init (&ov2740->sd.entity, +ARRAY_SIZE (ov2740->pads), ov2740->pads);if (ret) {dev_err_probe (dev, ret,"failed to init entity pads\n" ); goto probe_error_v4l2_ctrl_handler_free;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 52/73 media: ov2740: Add support for generic raw formats
In reply to Sakari AilusAdd RAW_10 media bus code and V4L2_CID_CFA_PATTERN as well as V4L2_CID_CFA_PATTERN_FLIP control support.
--- drivers/media/i2c/ov2740.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2740.c +19 -4
@@ -804,7 +804,7 @@ static int ov2740_init_controls(struct ov2740 *ov2740)int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret =v4l2_ctrl_handler_init (ctrl_hdlr,10 ); + ret =v4l2_ctrl_handler_init (ctrl_hdlr,12 );if (ret)return ret;
@@ -852,6 +852,13 @@ static int ov2740_init_controls(struct ov2740 *ov2740)V4L2_CID_TEST_PATTERN ,ARRAY_SIZE (ov2740_test_pattern_menu) -1 , 0, 0, ov2740_test_pattern_menu); +v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_CFA_PATTERN , +V4L2_CFA_PATTERN_GRBG ,V4L2_CFA_PATTERN_GRBG , +1 ,V4L2_CFA_PATTERN_GRBG ); +v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_CFA_PATTERN_FLIP , +0 ,V4L2_CFA_PATTERN_FLIP_BOTH , +0 ,V4L2_CFA_PATTERN_FLIP_BOTH ); ret =v4l2_fwnode_device_parse (ov2740->dev, &props);if (ret) {
@@ -1082,6 +1089,9 @@ static int __ov2740_set_format(struct v4l2_subdev *sd, width, height, format->width, format->height); +if (format->code !=MEDIA_BUS_FMT_RAW_10 ) + format->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + src_pix_fmt->code = format->code; src_pix_fmt->width = mode->width; src_pix_fmt->height = mode->height;
@@ -1122,10 +1132,14 @@ static int ov2740_enum_mbus_code(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { -if (code->index >0 ) + const u32 codes[] = { +MEDIA_BUS_FMT_SGRBG10_1X10 , +MEDIA_BUS_FMT_RAW_10 , + }; +if (code->index >=ARRAY_SIZE (codes))return -EINVAL ; - code->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + code->code = codes[code->index];return 0 ; }
@@ -1140,7 +1154,8 @@ static int ov2740_enum_frame_size(struct v4l2_subdev *sd,if (fse->index >= ov2740->supported_modes_count)return -EINVAL ; -if (fse->code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) +if (fse->code !=MEDIA_BUS_FMT_SGRBG10_1X10 && + fse->code !=MEDIA_BUS_FMT_RAW_10 )return -EINVAL ; fse->min_width = supported_modes[fse->index].width;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 53/73 media: ov2740: Add metadata layout control
In reply to Sakari AilusAdd the V4L2_CID_METADATA_LAYOUT control to the sub-device's control handler, to convey the metadata layout for the sensor-generated embedded data.
--- drivers/media/i2c/ov2740.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov2740.c +4 -1
@@ -804,7 +804,7 @@ static int ov2740_init_controls(struct ov2740 *ov2740)int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret =v4l2_ctrl_handler_init (ctrl_hdlr,12 ); + ret =v4l2_ctrl_handler_init (ctrl_hdlr,13 );if (ret)return ret;
@@ -859,6 +859,9 @@ static int ov2740_init_controls(struct ov2740 *ov2740)V4L2_CID_CFA_PATTERN_FLIP ,0 ,V4L2_CFA_PATTERN_FLIP_BOTH , 0, V4L2_CFA_PATTERN_FLIP_BOTH); +v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_METADATA_LAYOUT , +0 ,V4L2_METADATA_LAYOUT_OV2740 , +1 ,V4L2_METADATA_LAYOUT_OV2740 ); ret =v4l2_fwnode_device_parse (ov2740->dev, &props);if (ret) {
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 54/73 media: ov2740: Add support for G_SELECTION IOCTL
In reply to Sakari AilusAdd support for the G_SELECTION IOCTL in the ov2740 driver.
--- drivers/media/i2c/ov2740.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/media/i2c/ov2740.c +27 -0
@@ -1131,6 +1131,32 @@ static int ov2740_set_format(struct v4l2_subdev *sd, fmt->pad, fmt->stream); } +static int ov2740_get_selection (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_selection *sel) +{ +if (!(ci && ci->caps &V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR )) +return -EINVAL ; + +if (sel->stream !=OV2740_STREAM_PIXEL || + sel->pad !=OV2740_PAD_PIXEL ) +return -EINVAL ; + +switch (sel->target) { +case V4L2_SEL_TGT_CROP_BOUNDS : +case V4L2_SEL_TGT_CROP_DEFAULT : +case V4L2_SEL_TGT_CROP : + sel->r.top =OV2740_CROP_TOP ; + sel->r.left =OV2740_CROP_LEFT ; + sel->r.width =OV2740_ACTIVE_WIDTH -OV2740_CROP_LEFT ; + sel->r.height =OV2740_ACTIVE_HEIGHT -OV2740_CROP_TOP ; +return 0 ; + } + +return -EINVAL ; +} +static int ov2740_enum_mbus_code (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)
@@ -1255,6 +1281,7 @@ static const struct v4l2_subdev_video_ops ov2740_video_ops = {static const struct v4l2_subdev_pad_ops ov2740_pad_ops = { .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov2740_set_format, + .get_selection = ov2740_get_selection, .enum_mbus_code = ov2740_enum_mbus_code, .enum_frame_size = ov2740_enum_frame_size, .enable_streams = ov2740_enable_streams,
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 55/73 media: ov2740: Add support for FLL and LLP controls
In reply to Sakari AilusAdd support for the V4L2_CID_FRAME_LENGTH_LINES and V4L2_CID_LINE_LENGTH_PIXELS controls.
--- drivers/media/i2c/ov2740.c | 55 ++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-)
drivers/media/i2c/ov2740.c +41 -14
@@ -16,6 +16,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-fwnode.h> +#include <media/v4l2-mc.h> #define OV2740_LINK_FREQ_360MHZ 360000000ULL#define OV2740_LINK_FREQ_180MHZ 180000000ULL
@@ -562,9 +563,12 @@ struct ov2740 {/* V4L2 Controls */ struct v4l2_ctrl *link_freq;struct v4l2_ctrl *pixel_rate; +struct v4l2_ctrl *fll;struct v4l2_ctrl *vblank; +struct v4l2_ctrl *llp;struct v4l2_ctrl *hblank;struct v4l2_ctrl *exposure; +bool setting_ctrl;/* GPIOs, clocks, regulators */ struct gpio_desc *reset_gpio;
@@ -738,18 +742,28 @@ static int ov2740_set_ctrl(struct v4l2_ctrl *ctrl) {struct ov2740 *ov2740 =container_of (ctrl->handler, struct ov2740, ctrl_handler); -s64 exposure_max; -int ret; +int ret =0 ;/* Propagate change of current control to all related controls */ -if (ctrl->id ==V4L2_CID_VBLANK ) { -/* Update max exposure while meeting expected vblanking */ - exposure_max = ov2740->cur_mode->height + ctrl->val - -OV2740_EXPOSURE_MAX_MARGIN ; -__v4l2_ctrl_modify_range (ov2740->exposure, - ov2740->exposure->minimum, - exposure_max, ov2740->exposure->step, - exposure_max); +switch (ctrl->id) { +case V4L2_CID_FRAME_LENGTH_LINES : +case V4L2_CID_VBLANK : +case V4L2_CID_LINE_LENGTH_PIXELS : +case V4L2_CID_HBLANK : { +struct v4l2_subdev_state *state = +v4l2_subdev_get_locked_active_state (&ov2740->sd); +const struct v4l2_mbus_framefmt *format = +v4l2_subdev_state_get_format (state,OV2740_PAD_SOURCE , +OV2740_STREAM_PIXEL ); + + ret =v4l2_sensor_fll_llp_set (ov2740->fll, ov2740->vblank, + ov2740->llp, ov2740->hblank, + ov2740->exposure, format, + ctrl, &ov2740->setting_ctrl, +OV2740_EXPOSURE_MAX_MARGIN ); +if (ret) +return ret; + } }/* V4L2 controls values will be applied only when power is already up */
@@ -773,8 +787,10 @@ static int ov2740_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_VBLANK : - ret =ov2740_write_reg (ov2740,OV2740_REG_VTS ,2 , - ov2740->cur_mode->height + ctrl->val); +break ; + +case V4L2_CID_FRAME_LENGTH_LINES : + ret =ov2740_write_reg (ov2740,OV2740_REG_VTS ,2 , ctrl->val);break ;case V4L2_CID_TEST_PATTERN :
@@ -804,7 +820,7 @@ static int ov2740_init_controls(struct ov2740 *ov2740)int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret =v4l2_ctrl_handler_init (ctrl_hdlr,13 ); + ret =v4l2_ctrl_handler_init (ctrl_hdlr,15 );if (ret)return ret;
@@ -825,10 +841,22 @@ static int ov2740_init_controls(struct ov2740 *ov2740) vblank_min = ov2740->cur_mode->vts_min - ov2740->cur_mode->height; vblank_max = ov2740->cur_mode->vts_max - ov2740->cur_mode->height; vblank_default = ov2740->cur_mode->vts_def - ov2740->cur_mode->height; + ov2740->fll =v4l2_ctrl_new_std (ctrl_hdlr, &ov2740_ctrl_ops, +V4L2_CID_FRAME_LENGTH_LINES , + ov2740->cur_mode->vts_min, + ov2740->cur_mode->vts_max,1 , + ov2740->cur_mode->vts_def); ov2740->vblank =v4l2_ctrl_new_std (ctrl_hdlr, &ov2740_ctrl_ops,V4L2_CID_VBLANK , vblank_min, vblank_max,1 , vblank_default); + ov2740->llp =v4l2_ctrl_new_std (ctrl_hdlr, &ov2740_ctrl_ops, +V4L2_CID_LINE_LENGTH_PIXELS , + ov2740->cur_mode->hts, + ov2740->cur_mode->hts,1 , + ov2740->cur_mode->hts); +if (ov2740->llp) + ov2740->llp->flags |=V4L2_CTRL_FLAG_READ_ONLY ; h_blank = ov2740->cur_mode->hts - ov2740->cur_mode->width; ov2740->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov2740_ctrl_ops, V4L2_CID_HBLANK, h_blank, h_blank, 1,
@@ -1215,7 +1243,6 @@ static int ov2740_init_state(struct v4l2_subdev *sd, .routes = routes, .num_routes = ARRAY_SIZE(routes), }; -struct ov2740 *ov2740 =to_ov2740 (sd);int ret; ret =v4l2_subdev_set_routing (sd, sd_state, &routing);
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 56/73 media: ov2740: Signal common raw sensor model support
In reply to Sakari AilusAdd support for the CONFIG_MODEL control and signal support for the common raw sensor model.
--- drivers/media/i2c/ov2740.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov2740.c +4 -1
@@ -820,7 +820,7 @@ static int ov2740_init_controls(struct ov2740 *ov2740)int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret =v4l2_ctrl_handler_init (ctrl_hdlr,15 ); + ret =v4l2_ctrl_handler_init (ctrl_hdlr,16 );if (ret)return ret;
@@ -890,6 +890,9 @@ static int ov2740_init_controls(struct ov2740 *ov2740)v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_METADATA_LAYOUT ,0 ,V4L2_METADATA_LAYOUT_OV2740 ,1 ,V4L2_METADATA_LAYOUT_OV2740 ); +v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_CONFIG_MODEL , +0 ,V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR , +0 ,V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR ); ret =v4l2_fwnode_device_parse (ov2740->dev, &props);if (ret) {
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 57/73 media: ov2740: Add IMMUTABLE and STATIC route flags
In reply to Sakari AilusAdd immutable and static route flags to the routing table. The driver does not support disabling the embedded data whereas the sensor itself does.
--- drivers/media/i2c/ov2740.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/i2c/ov2740.c +6 -2
@@ -1234,12 +1234,16 @@ static int ov2740_init_state(struct v4l2_subdev *sd, .sink_pad = OV2740_PAD_PIXEL, .source_pad = OV2740_PAD_SOURCE, .source_stream = OV2740_STREAM_PIXEL, - .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE | +V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC, }, { .sink_pad = OV2740_PAD_META, .source_pad = OV2740_PAD_SOURCE, .source_stream = OV2740_STREAM_META, - .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE | +V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC, }, }; struct v4l2_subdev_krouting routing = {
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 58/73 media: imx219: Add internal image pad for Common Raw Sensor Model
In reply to Sakari AilusAdd internal image pad in preparation of supporting the Common Raw Sensor Model. A compatibility interface provided for the existing users.
--- drivers/media/i2c/imx219.c | 232 +++++++++++++++++++++++++++---------- 1 file changed, 173 insertions(+), 59 deletions(-)
drivers/media/i2c/imx219.c +173 -59
@@ -145,13 +145,19 @@#define IMX219_DEFAULT_LINK_FREQ_4LANE_UNSUPPORTED 363000000#define IMX219_DEFAULT_LINK_FREQ_4LANE 364000000 +/* For compatibility with the old UAPI. */ +#define IMX219_COMPAT_ACTIVE_AREA_TOP 8U/* IMX219 native and active pixel array size. */ -#define IMX219_NATIVE_WIDTH 3296U -#define IMX219_NATIVE_HEIGHT 2480U +#define IMX219_INACTIVE_AREA_HEIGHT 42U#define IMX219_ACTIVE_AREA_LEFT 8U -#define IMX219_ACTIVE_AREA_TOP 8U +#define IMX219_ACTIVE_AREA_TOP (IMX219_INACTIVE_AREA_HEIGHT + 8U)#define IMX219_ACTIVE_AREA_WIDTH 3280U#define IMX219_ACTIVE_AREA_HEIGHT 2464U +#define IMX219_PIXEL_ARRAY_LEFT 0U +#define IMX219_PIXEL_ARRAY_TOP IMX219_INACTIVE_AREA_HEIGHT +#define IMX219_PIXEL_ARRAY_WIDTH 3296U +#define IMX219_PIXEL_ARRAY_HEIGHT 2480U +#define IMX219_NATIVE_FORMAT MEDIA_BUS_FMT_SRGGB10_1X10/* Mode : resolution and related config&values */ struct imx219_mode {
@@ -351,9 +357,15 @@ static const struct imx219_mode supported_modes[] = { }, }; +enum imx219_pad_ids { +IMX219_PAD_SOURCE =0 , +IMX219_PAD_IMAGE , +IMX219_NUM_PADS , +}; +struct imx219 {struct v4l2_subdev sd; -struct media_pad pad; +struct media_pad pads[IMX219_NUM_PADS ];struct regmap *regmap;struct clk *xclk;/* system clock to IMX219 */
@@ -421,8 +433,9 @@ static void imx219_get_binning(struct v4l2_subdev_state *state, u8 *bin_h, u8 *bin_v) {const struct v4l2_mbus_framefmt *format = -v4l2_subdev_state_get_format (state,0 ); -const struct v4l2_rect *crop =v4l2_subdev_state_get_crop (state,0 ); +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); +const struct v4l2_rect *crop = +v4l2_subdev_state_get_crop (state,IMX219_PAD_SOURCE );u32 hbin = crop->width / format->width;u32 vbin = crop->height / format->height;
@@ -460,7 +473,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)int ret =0 ; state =v4l2_subdev_get_locked_active_state (&imx219->sd); - format =v4l2_subdev_state_get_format (state,0 ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); rate_factor =imx219_get_rate_factor (state);if (ctrl->id ==V4L2_CID_VBLANK ) {
@@ -687,8 +700,8 @@ static int imx219_set_framefmt(struct imx219 *imx219,u32 bpp;int ret =0 ; - format =v4l2_subdev_state_get_format (state,0 ); - crop =v4l2_subdev_state_get_crop (state,0 ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); bpp =imx219_get_format_bpp (format); cci_write(imx219->regmap, IMX219_REG_X_ADD_STA_A,
@@ -815,10 +828,25 @@ static int imx219_enum_mbus_code(struct v4l2_subdev *sd, {struct imx219 *imx219 =to_imx219 (sd); -if (code->index >= (ARRAY_SIZE (imx219_mbus_formats) /4 )) -return -EINVAL ; +if (code->pad ==IMX219_PAD_IMAGE ) { +/* The internal image pad is hardwired to the native format. */ +if (code->index >0 ) +return -EINVAL ; + + code->code =IMX219_NATIVE_FORMAT ; + }else { +/* +* On the source pad, the sensor supports multiple raw formats +* with different bit depths. +*/ +u32 format; - code->code =imx219_get_format_code (imx219, imx219_mbus_formats[code->index *4 ]); +if (code->index >=ARRAY_SIZE (imx219_mbus_formats) /4 ) +return -EINVAL ; + + format = imx219_mbus_formats[code->index *4 ]; + code->code =imx219_get_format_code (imx219, format); + }return 0 ; }
@@ -828,27 +856,32 @@ static int imx219_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_frame_size_enum *fse) {struct imx219 *imx219 =to_imx219 (sd); -u32 code; - -if (fse->index >=ARRAY_SIZE (supported_modes)) -return -EINVAL ; - code =imx219_get_format_code (imx219, fse->code); -if (fse->code != code) -return -EINVAL ; +if (fse->pad ==IMX219_PAD_IMAGE ) { +if (fse->code !=MEDIA_BUS_FMT_RAW_10 || fse->index >0 ) +return -EINVAL ; - fse->min_width = supported_modes[fse->index].width; - fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; - fse->max_height = fse->min_height; + fse->min_width =IMX219_PIXEL_ARRAY_WIDTH ; + fse->max_width =IMX219_PIXEL_ARRAY_WIDTH ; + fse->min_height =IMX219_PIXEL_ARRAY_HEIGHT ; + fse->max_height =IMX219_PIXEL_ARRAY_HEIGHT ; + }else { +if (fse->code !=imx219_get_format_code (imx219, fse->code) || + fse->index >=ARRAY_SIZE (supported_modes)) +return -EINVAL ; + + fse->min_width = supported_modes[fse->index].width; + fse->max_width = fse->min_width; + fse->min_height = supported_modes[fse->index].height; + fse->max_height = fse->min_height; + }return 0 ; } -static int imx219_set_pad_format (struct v4l2_subdev *sd, -const struct v4l2_subdev_client_info *ci, -struct v4l2_subdev_state *state, -struct v4l2_subdev_format *fmt) +static int imx219_set_pad_format_compat (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *fmt) {struct imx219 *imx219 =to_imx219 (sd);const struct imx219_mode *mode;
@@ -857,7 +890,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,u8 bin_h, bin_v, bin_hv;int ret; - format =v4l2_subdev_state_get_format (state,0 ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE );/* * Adjust the requested format to match the closest mode. The Bayer
@@ -889,11 +922,12 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,/* Ensure bin_h and bin_v are same to avoid 1:2 or 2:1 stretching */ bin_hv =min (bin_h, bin_v); - crop =v4l2_subdev_state_get_crop (state,0 ); + crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_SOURCE ); crop->width = format->width * bin_hv; crop->height = format->height * bin_hv; - crop->left = (IMX219_NATIVE_WIDTH - crop->width) /2 ; - crop->top = (IMX219_NATIVE_HEIGHT - crop->height) /2 ; + crop->left = (IMX219_PIXEL_ARRAY_WIDTH - crop->width) /2 ; + crop->top = (IMX219_PIXEL_ARRAY_HEIGHT - crop->height) /2 + +IMX219_ACTIVE_AREA_TOP ;if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) {int rate_factor =imx219_get_rate_factor (state);
@@ -959,51 +993,130 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,return 0 ; } +static int imx219_set_pad_format (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *fmt) +{ +struct imx219 *imx219 =to_imx219 (sd); +struct v4l2_mbus_framefmt *format; + +if (!(ci && ci->caps &V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR )) +return imx219_set_pad_format_compat (sd, state, fmt); + +if (fmt->pad !=IMX219_PAD_SOURCE ) +return v4l2_subdev_get_fmt (sd, state, fmt); + + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + + format->code = fmt->format.code = +imx219_get_format_code (imx219, fmt->format.code); + +return 0 ; +} +static int imx219_get_selection (struct v4l2_subdev *sd,const struct v4l2_subdev_client_info *ci,struct v4l2_subdev_state *state,struct v4l2_subdev_selection *sel) { -switch (sel->target) { -case V4L2_SEL_TGT_CROP : - sel->r = *v4l2_subdev_state_get_crop (state,0 ); -return 0 ; +if (!(ci && + ci->caps &V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR )) { +if (sel->pad !=IMX219_PAD_SOURCE ) +return -EINVAL ; + +switch (sel->target) { +case V4L2_SEL_TGT_CROP : + sel->r = *v4l2_subdev_state_get_crop (state, +IMX219_PAD_IMAGE ); + sel->r.top += -IMX219_ACTIVE_AREA_TOP + +IMX219_COMPAT_ACTIVE_AREA_TOP ; +return 0 ; + +case V4L2_SEL_TGT_NATIVE_SIZE : + sel->r.top =0 ; + sel->r.left =0 ; + sel->r.width =IMX219_PIXEL_ARRAY_WIDTH ; + sel->r.height =IMX219_PIXEL_ARRAY_HEIGHT ; + +return 0 ; + +case V4L2_SEL_TGT_CROP_DEFAULT : +case V4L2_SEL_TGT_CROP_BOUNDS : + sel->r.top =IMX219_COMPAT_ACTIVE_AREA_TOP ; + sel->r.left =IMX219_ACTIVE_AREA_LEFT ; + sel->r.width =IMX219_ACTIVE_AREA_WIDTH ; + sel->r.height =IMX219_ACTIVE_AREA_HEIGHT ; + +return 0 ; + } -case V4L2_SEL_TGT_NATIVE_SIZE : - sel->r.top =0 ; - sel->r.left =0 ; - sel->r.width =IMX219_NATIVE_WIDTH ; - sel->r.height =IMX219_NATIVE_HEIGHT ; +return -EINVAL ; + } -return 0 ; +if (sel->pad !=IMX219_PAD_IMAGE ) +return -EINVAL ; -case V4L2_SEL_TGT_CROP_DEFAULT : +switch (sel->target) {case V4L2_SEL_TGT_CROP_BOUNDS : sel->r.top =IMX219_ACTIVE_AREA_TOP ; sel->r.left =IMX219_ACTIVE_AREA_LEFT ; sel->r.width =IMX219_ACTIVE_AREA_WIDTH ; sel->r.height =IMX219_ACTIVE_AREA_HEIGHT ; -return 0 ; +case V4L2_SEL_TGT_CROP_DEFAULT : + sel->r.top =IMX219_ACTIVE_AREA_TOP ; + sel->r.left =IMX219_ACTIVE_AREA_LEFT ; + sel->r.width =IMX219_ACTIVE_AREA_WIDTH ; + sel->r.height =IMX219_ACTIVE_AREA_HEIGHT ; +return 0 ; +case V4L2_SEL_TGT_CROP : + sel->r = *v4l2_subdev_state_get_crop (state, sel->pad); +return 0 ; +case V4L2_SEL_TGT_COMPOSE : + sel->r = *v4l2_subdev_state_get_compose (state, sel->pad); +return 0 ; +default : +return -EINVAL ; } - -return -EINVAL ; }static int imx219_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) { -struct v4l2_subdev_format fmt = { - .which =V4L2_SUBDEV_FORMAT_TRY , - .pad =0 , - .format = { - .code =MEDIA_BUS_FMT_SRGGB10_1X10 , - .width = supported_modes[0 ].width, - .height = supported_modes[0 ].height, - }, - }; +struct v4l2_mbus_framefmt *pixel_array_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_IMAGE ); +struct v4l2_rect *analogue_crop = +v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); +struct v4l2_rect *compose = +v4l2_subdev_state_get_compose (state,IMX219_PAD_IMAGE ); +struct v4l2_mbus_framefmt *source_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + +/* The image pad models the pixel array, and thus has a fixed format. */ + pixel_array_format->code =MEDIA_BUS_FMT_RAW_10 ; + pixel_array_format->width =IMX219_ACTIVE_AREA_WIDTH ; + pixel_array_format->height =IMX219_ACTIVE_AREA_HEIGHT ; + pixel_array_format->field =V4L2_FIELD_NONE ; + pixel_array_format->colorspace =V4L2_COLORSPACE_RAW ; + pixel_array_format->ycbcr_enc =V4L2_YCBCR_ENC_601 ; + pixel_array_format->quantization =V4L2_QUANTIZATION_FULL_RANGE ; + pixel_array_format->xfer_func =V4L2_XFER_FUNC_NONE ; + + analogue_crop->top =IMX219_ACTIVE_AREA_TOP ; + analogue_crop->left =IMX219_ACTIVE_AREA_LEFT ; + analogue_crop->width =IMX219_ACTIVE_AREA_WIDTH ; + analogue_crop->height =IMX219_ACTIVE_AREA_HEIGHT ; + + compose->width = analogue_crop->width; + compose->height = analogue_crop->height; + + *source_format = *pixel_array_format; + source_format->code =IMX219_NATIVE_FORMAT ; + source_format->width = compose->width; + source_format->height = compose->height; -return imx219_set_pad_format (sd,NULL , state, &fmt); +return 0 ; }static const struct v4l2_subdev_video_ops imx219_video_ops = {
@@ -1270,14 +1383,15 @@ static int imx219_probe(struct i2c_client *client)if (ret) goto error_power_off; -/* Initialize subdev */ imx219->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; imx219->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; -/* Initialize source pad */ - imx219->pad.flags =MEDIA_PAD_FL_SOURCE ; + imx219->pads[IMX219_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ; + imx219->pads[IMX219_PAD_IMAGE ].flags =MEDIA_PAD_FL_SINK + |MEDIA_PAD_FL_INTERNAL ; - ret =media_entity_pads_init (&imx219->sd.entity,1 , &imx219->pad); + ret =media_entity_pads_init (&imx219->sd.entity, +ARRAY_SIZE (imx219->pads), imx219->pads);if (ret) {dev_err_probe (dev, ret,"failed to init entity pads\n" ); goto error_handler_free;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 59/73 media: imx219: Add image stream
In reply to Sakari AilusFrom: Laurent Pinchart <[email protected]>
In preparation for embedded data stream support, introduce a new imx219_stream_ids enumeration for stream IDs, with a single value, IMX219_STREAM_IMAGE for the image data stream. Use it when accessing the formats, crop and compose rectangles on the source pad. This is meant to reduce the size of further commits, and doesn't introduce any functional change.
--- drivers/media/i2c/imx219.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/media/i2c/imx219.c +18 -8
@@ -363,6 +363,10 @@ enum imx219_pad_ids { IMX219_NUM_PADS, }; +enum imx219_stream_ids { +IMX219_STREAM_IMAGE , +}; +struct imx219 {struct v4l2_subdev sd;struct media_pad pads[IMX219_NUM_PADS ];
@@ -433,9 +437,10 @@ static void imx219_get_binning(struct v4l2_subdev_state *state, u8 *bin_h, u8 *bin_v) {const struct v4l2_mbus_framefmt *format = -v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE );const struct v4l2_rect *crop = -v4l2_subdev_state_get_crop (state,IMX219_PAD_SOURCE ); +v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE );u32 hbin = crop->width / format->width;u32 vbin = crop->height / format->height;
@@ -473,7 +478,8 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)int ret =0 ; state =v4l2_subdev_get_locked_active_state (&imx219->sd); - format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE ); rate_factor =imx219_get_rate_factor (state);if (ctrl->id ==V4L2_CID_VBLANK ) {
@@ -700,7 +706,8 @@ static int imx219_set_framefmt(struct imx219 *imx219,u32 bpp;int ret =0 ; - format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE ); crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); bpp =imx219_get_format_bpp (format);
@@ -890,7 +897,8 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,u8 bin_h, bin_v, bin_hv;int ret; - format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE );/* * Adjust the requested format to match the closest mode. The Bayer
@@ -922,7 +930,7 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,/* Ensure bin_h and bin_v are same to avoid 1:2 or 2:1 stretching */ bin_hv =min (bin_h, bin_v); - crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_SOURCE ); + crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); crop->width = format->width * bin_hv; crop->height = format->height * bin_hv; crop->left = (IMX219_PIXEL_ARRAY_WIDTH - crop->width) /2 ;
@@ -1007,7 +1015,8 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,if (fmt->pad !=IMX219_PAD_SOURCE )return v4l2_subdev_get_fmt (sd, state, fmt); - format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); + format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE ); format->code = fmt->format.code =imx219_get_format_code (imx219, fmt->format.code);
@@ -1091,7 +1100,8 @@ static int imx219_init_state(struct v4l2_subdev *sd,struct v4l2_rect *compose =v4l2_subdev_state_get_compose (state,IMX219_PAD_IMAGE );struct v4l2_mbus_framefmt *source_format = -v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ); +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE );/* The image pad models the pixel array, and thus has a fixed format. */ pixel_array_format->code =MEDIA_BUS_FMT_RAW_10 ;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 60/73 media: imx219: Report internal routes to userspace
In reply to Sakari AilusFrom: Laurent Pinchart <[email protected]>
Usage of internal pads creates a route internal to the subdev, and the V4L2 camera sensor API requires such routes to be reported to userspace. Create the route in the .init_state() operation.
Internal routing support requires stream support, so set the V4L2_SUBDEV_FL_STREAMS flag. As the route is immutable, there's no need to implement the .set_routing() operation.
--- drivers/media/i2c/imx219.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/media/i2c/imx219.c +24 -1
@@ -1093,6 +1093,28 @@ static int imx219_get_selection(struct v4l2_subdev *sd,static int imx219_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) { +struct v4l2_subdev_route routes[1 ] = { + { + .sink_pad =IMX219_PAD_IMAGE , + .sink_stream =0 , + .source_pad =IMX219_PAD_SOURCE , + .source_stream =IMX219_STREAM_IMAGE , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE | +V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | +V4L2_SUBDEV_ROUTE_FL_STATIC , + }, + }; +struct v4l2_subdev_krouting routing = { + .len_routes =ARRAY_SIZE (routes), + .num_routes =ARRAY_SIZE (routes), + .routes = routes, + }; +int ret; + + ret =v4l2_subdev_set_routing (sd, state, &routing); +if (ret) +return ret; +struct v4l2_mbus_framefmt *pixel_array_format =v4l2_subdev_state_get_format (state,IMX219_PAD_IMAGE ); struct v4l2_rect *analogue_crop =
@@ -1393,7 +1415,8 @@ static int imx219_probe(struct i2c_client *client)if (ret) goto error_power_off; - imx219->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + imx219->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE | +V4L2_SUBDEV_FL_STREAMS ; imx219->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; imx219->pads[IMX219_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 61/73 media: imx219: Report streams using frame descriptors
In reply to Sakari AilusFrom: Laurent Pinchart <[email protected]>
Implement the .get_frame_desc() subdev operation to report information about streams to the connected CSI-2 receiver. This is required to let the CSI-2 receiver driver know about virtual channels and data types for each stream.
--- drivers/media/i2c/imx219.c | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
drivers/media/i2c/imx219.c +48 -0
@@ -23,6 +23,7 @@#include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <media/mipi-csi2.h> #include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h>
@@ -697,6 +698,24 @@ static void imx219_free_controls(struct imx219 *imx219)* Subdev operations */ +static unsigned int imx219_format_bpp (u32 code) +{ +switch (code) { +case MEDIA_BUS_FMT_SRGGB8_1X8 : +case MEDIA_BUS_FMT_SGRBG8_1X8 : +case MEDIA_BUS_FMT_SGBRG8_1X8 : +case MEDIA_BUS_FMT_SBGGR8_1X8 : +return 8 ; + +case MEDIA_BUS_FMT_SRGGB10_1X10 : +case MEDIA_BUS_FMT_SGRBG10_1X10 : +case MEDIA_BUS_FMT_SGBRG10_1X10 : +case MEDIA_BUS_FMT_SBGGR10_1X10 : +default : +return 10 ; + } +} +static int imx219_set_framefmt (struct imx219 *imx219,struct v4l2_subdev_state *state) {
@@ -1090,6 +1109,34 @@ static int imx219_get_selection(struct v4l2_subdev *sd, } } +static int imx219_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_frame_desc *fd) +{ +const struct v4l2_mbus_framefmt *fmt; +struct v4l2_subdev_state *state; +u32 code; + +if (pad !=IMX219_PAD_SOURCE ) +return -EINVAL ; + + state =v4l2_subdev_lock_and_get_active_state (sd); + fmt =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE ); + code = fmt->code; +v4l2_subdev_unlock_state (state); + + fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; + fd->num_entries =1 ; + + fd->entry[0 ].pixelcode = code; + fd->entry[0 ].stream =IMX219_STREAM_IMAGE ; + fd->entry[0 ].bus.csi2.vc =0 ; + fd->entry[0 ].bus.csi2.dt =imx219_format_bpp (code) ==8 ? +MIPI_CSI2_DT_RAW8 :MIPI_CSI2_DT_RAW10 ; + +return 0 ; +} +static int imx219_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) {
@@ -1161,6 +1208,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = { .set_fmt = imx219_set_pad_format, .get_selection = imx219_get_selection, .enum_frame_size = imx219_enum_frame_size, + .get_frame_desc = imx219_get_frame_desc, .enable_streams = imx219_enable_streams, .disable_streams = imx219_disable_streams, };
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 62/73 media: imx219: Add embedded data support
In reply to Sakari AilusFrom: Laurent Pinchart <[email protected]>
The IMX219 generates embedded data unconditionally. Report it as an additional stream, with a new internal embedded data pad, and update subdev operations accordingly.
--- drivers/media/i2c/imx219.c | 176 +++++++++++++++++++++++++++++++------ 1 file changed, 150 insertions(+), 26 deletions(-)
drivers/media/i2c/imx219.c +150 -26
@@ -160,6 +160,9 @@#define IMX219_PIXEL_ARRAY_HEIGHT 2480U#define IMX219_NATIVE_FORMAT MEDIA_BUS_FMT_SRGGB10_1X10 +/* Embedded metadata stream height */ +#define IMX219_EMBEDDED_DATA_HEIGHT 2U +/* Mode : resolution and related config&values */ struct imx219_mode {/* Frame width */
@@ -361,11 +364,13 @@ static const struct imx219_mode supported_modes[] = {enum imx219_pad_ids {IMX219_PAD_SOURCE =0 ,IMX219_PAD_IMAGE , +IMX219_PAD_EDATA ,IMX219_NUM_PADS , };enum imx219_stream_ids {IMX219_STREAM_IMAGE , +IMX219_STREAM_EDATA , };struct imx219 {
@@ -434,6 +439,25 @@ static u32 imx219_get_format_bpp(const struct v4l2_mbus_framefmt *format) } } +static u32 +imx219_get_embedded_format_code (const struct v4l2_mbus_framefmt *format) +{ +switch (format->code) { +case MEDIA_BUS_FMT_SRGGB8_1X8 : +case MEDIA_BUS_FMT_SGRBG8_1X8 : +case MEDIA_BUS_FMT_SGBRG8_1X8 : +case MEDIA_BUS_FMT_SBGGR8_1X8 : +return MEDIA_BUS_FMT_META_8 ; + +case MEDIA_BUS_FMT_SRGGB10_1X10 : +case MEDIA_BUS_FMT_SGRBG10_1X10 : +case MEDIA_BUS_FMT_SGBRG10_1X10 : +case MEDIA_BUS_FMT_SBGGR10_1X10 : +default : +return MEDIA_BUS_FMT_META_10 ; + } +} +static void imx219_get_binning (struct v4l2_subdev_state *state,u8 *bin_h,u8 *bin_v) {
@@ -777,6 +801,9 @@ static int imx219_enable_streams(struct v4l2_subdev *sd,struct i2c_client *client =v4l2_get_subdevdata (&imx219->sd);int ret; +if (!(streams_mask &1ULL )) +return 0 ; + ret =pm_runtime_resume_and_get (&client->dev);if (ret <0 )return ret;
@@ -834,6 +861,9 @@ static int imx219_disable_streams(struct v4l2_subdev *sd,struct i2c_client *client =v4l2_get_subdevdata (&imx219->sd);int ret; +if (!(streams_mask &1ULL )) +return 0 ; +/* set stream off register */ ret =cci_write (imx219->regmap,IMX219_REG_MODE_SELECT ,IMX219_MODE_STANDBY ,NULL );
@@ -854,17 +884,32 @@ static int imx219_enum_mbus_code(struct v4l2_subdev *sd, {struct imx219 *imx219 =to_imx219 (sd); -if (code->pad ==IMX219_PAD_IMAGE ) { -/* The internal image pad is hardwired to the native format. */ +switch (code->pad) { +case IMX219_PAD_IMAGE :if (code->index >0 )return -EINVAL ; - code->code =IMX219_NATIVE_FORMAT ; - }else { -/* -* On the source pad, the sensor supports multiple raw formats -* with different bit depths. -*/ + code->code =MEDIA_BUS_FMT_RAW_10 ; +return 0 ; + +case IMX219_PAD_EDATA : +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_META_8 ; +return 0 ; + +case IMX219_PAD_SOURCE : +default : +break ; + } + +/* +* On the source pad, the sensor supports multiple image raw formats +* with different bit depths. The embedded data format bit depth +* follows the image stream. +*/ +if (code->stream ==IMX219_STREAM_IMAGE ) {u32 format;if (code->index >=ARRAY_SIZE (imx219_mbus_formats) /4 )
@@ -872,6 +917,15 @@ static int imx219_enum_mbus_code(struct v4l2_subdev *sd, format = imx219_mbus_formats[code->index *4 ]; code->code =imx219_get_format_code (imx219, format); + }else { +struct v4l2_mbus_framefmt *fmt; + +if (code->index >0 ) +return -EINVAL ; + + fmt =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_EDATA ); + code->code = fmt->code; }return 0 ;
@@ -883,15 +937,33 @@ static int imx219_enum_frame_size(struct v4l2_subdev *sd, {struct imx219 *imx219 =to_imx219 (sd); -if (fse->pad ==IMX219_PAD_IMAGE ) { +switch (fse->pad) { +case IMX219_PAD_IMAGE :if (fse->code !=MEDIA_BUS_FMT_RAW_10 || fse->index >0 )return -EINVAL ; - fse->min_width =IMX219_PIXEL_ARRAY_WIDTH ; - fse->max_width =IMX219_PIXEL_ARRAY_WIDTH ; - fse->min_height =IMX219_PIXEL_ARRAY_HEIGHT ; - fse->max_height =IMX219_PIXEL_ARRAY_HEIGHT ; - }else { + fse->min_width =IMX219_ACTIVE_AREA_WIDTH ; + fse->max_width =IMX219_ACTIVE_AREA_WIDTH ; + fse->min_height =IMX219_ACTIVE_AREA_HEIGHT ; + fse->max_height =IMX219_ACTIVE_AREA_HEIGHT ; +return 0 ; + +case IMX219_PAD_EDATA : +if (fse->code !=MEDIA_BUS_FMT_META_8 || fse->index >0 ) +return -EINVAL ; + + fse->min_width =IMX219_ACTIVE_AREA_WIDTH ; + fse->max_width =IMX219_ACTIVE_AREA_WIDTH ; + fse->min_height =IMX219_EMBEDDED_DATA_HEIGHT ; + fse->max_height =IMX219_EMBEDDED_DATA_HEIGHT ; +return 0 ; + +case IMX219_PAD_SOURCE : +default : +break ; + } + +if (fse->stream ==IMX219_STREAM_IMAGE ) {if (fse->code !=imx219_get_format_code (imx219, fse->code) || fse->index >=ARRAY_SIZE (supported_modes))return -EINVAL ;
@@ -900,6 +972,21 @@ static int imx219_enum_frame_size(struct v4l2_subdev *sd, fse->max_width = fse->min_width; fse->min_height = supported_modes[fse->index].height; fse->max_height = fse->min_height; + }else { +struct v4l2_mbus_framefmt *fmt; + + fmt =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_EDATA ); +if (fse->code != fmt->code) +return -EINVAL ; + +if (fse->index >0 ) +return -EINVAL ; + + fse->min_width = fmt->width; + fse->max_width = fmt->width; + fse->min_height =IMX219_EMBEDDED_DATA_HEIGHT ; + fse->max_height =IMX219_EMBEDDED_DATA_HEIGHT ; }return 0 ;
@@ -911,13 +998,16 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd, {struct imx219 *imx219 =to_imx219 (sd);const struct imx219_mode *mode; -struct v4l2_mbus_framefmt *format; +struct v4l2_mbus_framefmt *format, *embedded_format;struct v4l2_rect *crop;u8 bin_h, bin_v, bin_hv;int ret; format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ,IMX219_STREAM_IMAGE ); + embedded_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_EDATA );/* * Adjust the requested format to match the closest mode. The Bayer
@@ -939,6 +1029,8 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd, *format = fmt->format; + embedded_format->code =imx219_get_embedded_format_code (format); +/* * Use binning to maximize the crop rectangle size, and centre it in the * sensor.
@@ -1031,7 +1123,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,if (!(ci && ci->caps &V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR ))return imx219_set_pad_format_compat (sd, state, fmt); -if (fmt->pad !=IMX219_PAD_SOURCE ) +if (fmt->pad !=IMX219_PAD_SOURCE && fmt->stream !=IMX219_STREAM_IMAGE )return v4l2_subdev_get_fmt (sd, state, fmt); format = v4l2_subdev_state_get_format(state, IMX219_PAD_SOURCE,
@@ -1082,7 +1174,11 @@ static int imx219_get_selection(struct v4l2_subdev *sd,return -EINVAL ; } -if (sel->pad !=IMX219_PAD_IMAGE ) +/* +* The embedded data stream doesn't support selection rectangles, +* neither on the embedded data pad nor on the source pad. +*/ +if (sel->pad !=IMX219_PAD_IMAGE || sel->stream !=IMX219_STREAM_IMAGE )return -EINVAL ;switch (sel->target) {
@@ -1112,35 +1208,41 @@ static int imx219_get_selection(struct v4l2_subdev *sd,static int imx219_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) { -const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -u32 code; +u32 img_code; +u32 ed_code;if (pad !=IMX219_PAD_SOURCE )return -EINVAL ; state =v4l2_subdev_lock_and_get_active_state (sd); - fmt =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , -IMX219_STREAM_IMAGE ); - code = fmt->code; + img_code =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE )->code; + ed_code =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_EDATA )->code;v4l2_subdev_unlock_state (state); fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; - fd->num_entries =1 ; + fd->num_entries =2 ; - fd->entry[0 ].pixelcode = code; + fd->entry[0 ].pixelcode = img_code; fd->entry[0 ].stream =IMX219_STREAM_IMAGE ; fd->entry[0 ].bus.csi2.vc =0 ; - fd->entry[0 ].bus.csi2.dt =imx219_format_bpp (code) ==8 ? + fd->entry[0 ].bus.csi2.dt =imx219_format_bpp (img_code) ==8 ?MIPI_CSI2_DT_RAW8 :MIPI_CSI2_DT_RAW10 ; + fd->entry[1 ].pixelcode = ed_code; + fd->entry[1 ].stream =IMX219_STREAM_EDATA ; + fd->entry[1 ].bus.csi2.vc =0 ; + fd->entry[1 ].bus.csi2.dt =MIPI_CSI2_DT_EMBEDDED_8B ; +return 0 ; }static int imx219_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) { -struct v4l2_subdev_route routes[1 ] = { +struct v4l2_subdev_route routes[] = { { .sink_pad =IMX219_PAD_IMAGE , .sink_stream =0 ,
@@ -1149,6 +1251,14 @@ static int imx219_init_state(struct v4l2_subdev *sd, .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE | V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | V4L2_SUBDEV_ROUTE_FL_STATIC, + }, { + .sink_pad = IMX219_PAD_EDATA, + .sink_stream = 0, + .source_pad = IMX219_PAD_SOURCE, + .source_stream = IMX219_STREAM_EDATA, + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE | + V4L2_SUBDEV_ROUTE_FL_IMMUTABLE | + V4L2_SUBDEV_ROUTE_FL_STATIC, }, };struct v4l2_subdev_krouting routing = {
@@ -1171,6 +1281,11 @@ static int imx219_init_state(struct v4l2_subdev *sd,struct v4l2_mbus_framefmt *source_format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ,IMX219_STREAM_IMAGE ); +struct v4l2_mbus_framefmt *embedded_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_EDATA ); +struct v4l2_mbus_framefmt *embedded_source_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_EDATA );/* The image pad models the pixel array, and thus has a fixed format. */ pixel_array_format->code =MEDIA_BUS_FMT_RAW_10 ;
@@ -1195,6 +1310,13 @@ static int imx219_init_state(struct v4l2_subdev *sd, source_format->width = compose->width; source_format->height = compose->height; + embedded_format->code =imx219_get_embedded_format_code (source_format); + embedded_format->width = source_format->width; + embedded_format->height =IMX219_EMBEDDED_DATA_HEIGHT ; + embedded_format->field =V4L2_FIELD_NONE ; + + *embedded_source_format = *embedded_format; +return 0 ; }
@@ -1470,6 +1592,8 @@ static int imx219_probe(struct i2c_client *client) imx219->pads[IMX219_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ; imx219->pads[IMX219_PAD_IMAGE ].flags =MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_INTERNAL ; + imx219->pads[IMX219_PAD_EDATA ].flags =MEDIA_PAD_FL_SINK + |MEDIA_PAD_FL_INTERNAL ; ret =media_entity_pads_init (&imx219->sd.entity,ARRAY_SIZE (imx219->pads), imx219->pads);
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 63/73 media: imx219: Add support for generic raw formats
In reply to Sakari AilusAdd support for colour pattern agnostic raw formats, including controls to convey the colour pattern and the configuration model (common raw sensor).
--- drivers/media/i2c/imx219.c | 40 +++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-)
drivers/media/i2c/imx219.c +37 -3
@@ -306,6 +306,11 @@ static const u32 imx219_mbus_formats[] = { MEDIA_BUS_FMT_SBGGR8_1X8, }; +static const u32 imx219_mbus_formats_generic[] = { +MEDIA_BUS_FMT_RAW_10 , +MEDIA_BUS_FMT_RAW_8 , +}; +/* * Initialisation delay between XCLR low->high and the moment when the sensor * can start capture (i.e. can leave software stanby) must be not less than:
@@ -408,6 +413,10 @@ static u32 imx219_get_format_code(struct imx219 *imx219, u32 code) {unsigned int i; +for (i =0 ; i <ARRAY_SIZE (imx219_mbus_formats_generic); i++) +if (imx219_mbus_formats_generic[i] == code) +return code; +for (i =0 ; i <ARRAY_SIZE (imx219_mbus_formats); i++)if (imx219_mbus_formats[i] == code)break ;
@@ -428,12 +437,14 @@ static u32 imx219_get_format_bpp(const struct v4l2_mbus_framefmt *format)case MEDIA_BUS_FMT_SGRBG8_1X8 :case MEDIA_BUS_FMT_SGBRG8_1X8 :case MEDIA_BUS_FMT_SBGGR8_1X8 : +case MEDIA_BUS_FMT_RAW_8 :return 8 ;case MEDIA_BUS_FMT_SRGGB10_1X10 :case MEDIA_BUS_FMT_SGRBG10_1X10 :case MEDIA_BUS_FMT_SGBRG10_1X10 :case MEDIA_BUS_FMT_SBGGR10_1X10 : +case MEDIA_BUS_FMT_RAW_10 :default :return 10 ; }
@@ -447,12 +458,14 @@ imx219_get_embedded_format_code(const struct v4l2_mbus_framefmt *format)case MEDIA_BUS_FMT_SGRBG8_1X8 :case MEDIA_BUS_FMT_SGBRG8_1X8 :case MEDIA_BUS_FMT_SBGGR8_1X8 : +case MEDIA_BUS_FMT_RAW_8 :return MEDIA_BUS_FMT_META_8 ;case MEDIA_BUS_FMT_SRGGB10_1X10 :case MEDIA_BUS_FMT_SGRBG10_1X10 :case MEDIA_BUS_FMT_SGBRG10_1X10 :case MEDIA_BUS_FMT_SBGGR10_1X10 : +case MEDIA_BUS_FMT_RAW_10 :default :return MEDIA_BUS_FMT_META_10 ; }
@@ -688,6 +701,20 @@ static int imx219_init_controls(struct imx219 *imx219)/* The "Solid color" pattern is white by default */ } +v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_CFA_PATTERN , +V4L2_CFA_PATTERN_RGGB ,V4L2_CFA_PATTERN_RGGB , +1 ,V4L2_CFA_PATTERN_RGGB ); +v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_CFA_PATTERN_FLIP , +0 ,V4L2_CFA_PATTERN_FLIP_BOTH , +0 ,V4L2_CFA_PATTERN_FLIP_BOTH ); +v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_METADATA_LAYOUT , +0 ,V4L2_METADATA_LAYOUT_CCS , +1 ,V4L2_METADATA_LAYOUT_CCS ); +v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_CONFIG_MODEL , +0 ,V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR , +0 ,V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR ); +if (ctrl_hdlr->error) { ret = ctrl_hdlr->error;dev_err_probe (&client->dev, ret,"Control init failed\n" );
@@ -912,10 +939,17 @@ static int imx219_enum_mbus_code(struct v4l2_subdev *sd,if (code->stream ==IMX219_STREAM_IMAGE ) {u32 format; -if (code->index >=ARRAY_SIZE (imx219_mbus_formats) /4 ) -return -EINVAL ; +if (code->index >=ARRAY_SIZE (imx219_mbus_formats) /4 ) { +u32 idx = code->index - +ARRAY_SIZE (imx219_mbus_formats) /4 ; + +if (idx >=ARRAY_SIZE (imx219_mbus_formats_generic)) +return -EINVAL ; - format = imx219_mbus_formats[code->index *4 ]; + format = imx219_mbus_formats_generic[idx]; + }else { + format = imx219_mbus_formats[code->index *4 ]; + } code->code =imx219_get_format_code (imx219, format); }else {struct v4l2_mbus_framefmt *fmt;
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 64/73 media: imx219: Add V4L2_CID_BINNING_FACTORS
In reply to Sakari AilusAdd support for the V4L2_CID_BINNING_FACTORS control. It'll be read-only for now.
--- drivers/media/i2c/imx219.c | 92 ++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 39 deletions(-)
drivers/media/i2c/imx219.c +53 -39
@@ -398,6 +398,7 @@ struct imx219 {struct v4l2_ctrl *hflip;struct v4l2_ctrl *vblank;struct v4l2_ctrl *hblank; +struct v4l2_ctrl *binning;/* Two or Four lanes */ u8 lanes;
@@ -471,40 +472,33 @@ imx219_get_embedded_format_code(const struct v4l2_mbus_framefmt *format) } } -static void imx219_get_binning (struct v4l2_subdev_state *state,u8 *bin_h, -u8 *bin_v) -{ -const struct v4l2_mbus_framefmt *format = -v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , -IMX219_STREAM_IMAGE ); -const struct v4l2_rect *crop = -v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); -u32 hbin = crop->width / format->width; -u32 vbin = crop->height / format->height; - -if (hbin ==2 && vbin ==2 ) { - *bin_h =IMX219_BINNING_X2_ANALOG ; - *bin_v =IMX219_BINNING_X2_ANALOG ; - }else { - *bin_h =IMX219_BINNING_NONE ; - *bin_v =IMX219_BINNING_NONE ; - } +/* ----------------------------------------------------------------------------- +* Controls +*/ -} +enum imx219_binning_factor_indices { +IMX219_BINNING_11 , +IMX219_BINNING_22 , +}; -static inline u32 imx219_get_rate_factor (struct v4l2_subdev_state *state) -{ -u8 bin_h, bin_v; +static const struct { +u8 h, v; +} imx219_binnings[] = { + [IMX219_BINNING_11 ] = {IMX219_BINNING_NONE ,IMX219_BINNING_NONE , }, + [IMX219_BINNING_22 ] = {IMX219_BINNING_X2_ANALOG ,IMX219_BINNING_X2_ANALOG , }, +}; -imx219_get_binning (state, &bin_h, &bin_v); +static const s64 imx219_binning_factors[] = { + [IMX219_BINNING_11 ] =V4L2_BINNING_FACTORS_MAKE (1 ,1 ,1 ,1 ), + [IMX219_BINNING_22 ] =V4L2_BINNING_FACTORS_MAKE (2 ,1 ,2 ,1 ), +}; -return (bin_h & bin_v) ==IMX219_BINNING_X2_ANALOG ?2 :1 ; +static inline u32 imx219_get_rate_factor (struct imx219 *imx219) +{ +return imx219_binnings[imx219->binning->val].v == +IMX219_BINNING_X2_ANALOG ?2 :1 ; } -/* ----------------------------------------------------------------------------- -* Controls -*/ -static int imx219_set_ctrl (struct v4l2_ctrl *ctrl) { struct imx219 *imx219 =
@@ -518,9 +512,10 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) state =v4l2_subdev_get_locked_active_state (&imx219->sd); format =v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ,IMX219_STREAM_IMAGE ); - rate_factor =imx219_get_rate_factor (state); + rate_factor =imx219_get_rate_factor (imx219); -if (ctrl->id ==V4L2_CID_VBLANK ) { +switch (ctrl->id) { +case V4L2_CID_VBLANK : {int exposure_max, exposure_def;/* Update max exposure while meeting expected vblanking */
@@ -534,7 +529,10 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) rate_factor, exposure_def);if (ret)return ret; - +break ; + } +case V4L2_CID_BINNING_FACTORS : +return 0 ; }/*
@@ -612,6 +610,9 @@ static unsigned long imx219_get_pixel_rate(struct imx219 *imx219)return (imx219->lanes ==2 ) ?IMX219_PIXEL_RATE :IMX219_PIXEL_RATE_4LANE ; } +static_assert (ARRAY_SIZE (imx219_binnings) == +ARRAY_SIZE (imx219_binning_factors)); +/* Initialize control handlers */ static int imx219_init_controls (struct imx219 *imx219) {
@@ -714,6 +715,12 @@ static int imx219_init_controls(struct imx219 *imx219)v4l2_ctrl_new_std (ctrl_hdlr,NULL ,V4L2_CID_CONFIG_MODEL ,0 ,V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR ,0 ,V4L2_CONFIG_MODEL_COMMON_RAW_SENSOR ); + imx219->binning = +v4l2_ctrl_new_int_menu (ctrl_hdlr, &imx219_ctrl_ops, +V4L2_CID_BINNING_FACTORS , +ARRAY_SIZE (imx219_binning_factors) -1 , +IMX219_BINNING_11 , + imx219_binning_factors);if (ctrl_hdlr->error) { ret = ctrl_hdlr->error;
@@ -721,6 +728,8 @@ static int imx219_init_controls(struct imx219 *imx219) goto error; } + imx219->binning->flags =V4L2_CTRL_FLAG_READ_ONLY ; + ret =v4l2_fwnode_device_parse (&client->dev, &props);if (ret) goto error;
@@ -772,7 +781,6 @@ static int imx219_set_framefmt(struct imx219 *imx219, {const struct v4l2_mbus_framefmt *format;const struct v4l2_rect *crop; -u8 bin_h, bin_v;u32 bpp;int ret =0 ;
@@ -790,9 +798,10 @@ static int imx219_set_framefmt(struct imx219 *imx219,cci_write (imx219->regmap,IMX219_REG_Y_ADD_END_A , crop->top -IMX219_ACTIVE_AREA_TOP + crop->height -1 , &ret); -imx219_get_binning (state, &bin_h, &bin_v); -cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_H , bin_h, &ret); -cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_V , bin_v, &ret); +cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_H , + imx219_binnings[imx219->binning->val].h, &ret); +cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_V , + imx219_binnings[imx219->binning->val].v, &ret);cci_write (imx219->regmap,IMX219_REG_X_OUTPUT_SIZE , format->width, &ret);
@@ -1083,12 +1092,16 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,IMX219_ACTIVE_AREA_TOP ;if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -int rate_factor =imx219_get_rate_factor (state);int exposure_max;int exposure_def;int llp_min;int pixel_rate; + ret =__v4l2_ctrl_s_ctrl (imx219->binning, bin_hv ==1 ? +IMX219_BINNING_11 :IMX219_BINNING_22 ); +if (ret) +return ret; +/* Update limits and set FPS to default */ ret = __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, IMX219_FLL_MAX - mode->height,
@@ -1103,6 +1116,7 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,return ret;/* Update max exposure while meeting expected vblanking */ +int rate_factor =imx219_get_rate_factor (imx219); exposure_max = mode->fll_def -IMX219_EXPOSURE_OFFSET * rate_factor; exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
@@ -1120,9 +1134,9 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,* operates on two lines together. So we switch to a higher * minimum of 3560. */ -imx219_get_binning (state, &bin_h, &bin_v); - llp_min = (bin_h & bin_v) ==IMX219_BINNING_X2_ANALOG ? -IMX219_BINNED_LLP_MIN :IMX219_LLP_MIN ; + llp_min = imx219_binnings[imx219->binning->val].h == +IMX219_BINNING_X2_ANALOG ? +IMX219_BINNED_LLP_MIN :IMX219_LLP_MIN ; ret = __v4l2_ctrl_modify_range(imx219->hblank, llp_min - mode->width, IMX219_LLP_MAX - mode->width,
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 65/73 media: imx219: Allow configuring cropping and binning through CRSM
In reply to Sakari AilusEnable the configuration of cropping and binning through the Common Raw Sensor Model. Also change the minimum embedded data line length the same as that of the output pixel data line.
--- drivers/media/i2c/imx219.c | 103 +++++++++++++++++++++++++++++++++---- 1 file changed, 94 insertions(+), 9 deletions(-)
drivers/media/i2c/imx219.c +94 -9
@@ -160,6 +160,9 @@#define IMX219_PIXEL_ARRAY_HEIGHT 2480U#define IMX219_NATIVE_FORMAT MEDIA_BUS_FMT_SRGGB10_1X10 +#define IMX219_OUTPUT_X_SIZE_MIN 0x100 +#define IMX219_OUTPUT_Y_SIZE_MIN 0x100 +/* Embedded metadata stream height */ #define IMX219_EMBEDDED_DATA_HEIGHT 2U
@@ -499,6 +502,45 @@ static inline u32 imx219_get_rate_factor(struct imx219 *imx219)IMX219_BINNING_X2_ANALOG ?2 :1 ; } +static void imx219_apply_binning (struct v4l2_subdev_state *state, +struct v4l2_rect *crop,unsigned int index) +{ +struct v4l2_rect *compose = +v4l2_subdev_state_get_compose (state,IMX219_PAD_IMAGE ); +struct v4l2_mbus_framefmt *source_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_IMAGE ); +struct v4l2_mbus_framefmt *embedded_source_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE , +IMX219_STREAM_EDATA ); +s64 binning = imx219_binning_factors[index]; + + crop->width =clamp (crop->width,IMX219_OUTPUT_X_SIZE_MIN * +V4L2_BINNING_FACTORS_HNUM (binning), +IMX219_ACTIVE_AREA_WIDTH ) & ~1 ; + crop->height =clamp (crop->height,IMX219_OUTPUT_Y_SIZE_MIN * +V4L2_BINNING_FACTORS_VNUM (binning), +IMX219_ACTIVE_AREA_HEIGHT ) & ~1 ; + crop->left =clamp ((unsigned int )crop->left,IMX219_ACTIVE_AREA_LEFT , +IMX219_ACTIVE_AREA_LEFT +IMX219_ACTIVE_AREA_WIDTH - + crop->width); + crop->top =clamp ((unsigned int )crop->top,IMX219_ACTIVE_AREA_TOP , +IMX219_ACTIVE_AREA_TOP +IMX219_ACTIVE_AREA_HEIGHT - + crop->height); + + compose->width = crop->width /V4L2_BINNING_FACTORS_HNUM (binning); + compose->height = crop->height /V4L2_BINNING_FACTORS_VNUM (binning); + + source_format->width = compose->width; + source_format->height = compose->height; + +struct v4l2_mbus_framefmt *embedded_format = +v4l2_subdev_state_get_format (state,IMX219_PAD_EDATA ); + + embedded_format->width = + embedded_source_format->width = source_format->width; +} +static int imx219_set_ctrl (struct v4l2_ctrl *ctrl) { struct imx219 *imx219 =
@@ -531,9 +573,21 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)return ret;break ; } -case V4L2_CID_BINNING_FACTORS : +case V4L2_CID_BINNING_FACTORS : { +struct v4l2_rect *crop = +v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); + +cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_H , + imx219_binnings[ctrl->val].h, &ret); +cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_V , + imx219_binnings[ctrl->val].v, &ret); + +if (ctrl->val != ctrl->cur.val) +imx219_apply_binning (state, crop, ctrl->val); +return 0 ; } + }/* * Applying V4L2 control value only happens
@@ -728,8 +782,6 @@ static int imx219_init_controls(struct imx219 *imx219) goto error; } - imx219->binning->flags =V4L2_CTRL_FLAG_READ_ONLY ; - ret =v4l2_fwnode_device_parse (&client->dev, &props);if (ret) goto error;
@@ -798,11 +850,6 @@ static int imx219_set_framefmt(struct imx219 *imx219,cci_write (imx219->regmap,IMX219_REG_Y_ADD_END_A , crop->top -IMX219_ACTIVE_AREA_TOP + crop->height -1 , &ret); -cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_H , - imx219_binnings[imx219->binning->val].h, &ret); -cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_V , - imx219_binnings[imx219->binning->val].v, &ret); -cci_write (imx219->regmap,IMX219_REG_X_OUTPUT_SIZE , format->width, &ret); cci_write(imx219->regmap, IMX219_REG_Y_OUTPUT_SIZE,
@@ -881,6 +928,7 @@ static int imx219_enable_streams(struct v4l2_subdev *sd,/* vflip and hflip cannot change during streaming */ __v4l2_ctrl_grab (imx219->vflip, true);__v4l2_ctrl_grab (imx219->hflip, true); +__v4l2_ctrl_grab (imx219->binning, true);return 0 ;
@@ -908,6 +956,7 @@ static int imx219_disable_streams(struct v4l2_subdev *sd,__v4l2_ctrl_grab (imx219->vflip, false);__v4l2_ctrl_grab (imx219->hflip, false); +__v4l2_ctrl_grab (imx219->binning, false);pm_runtime_put_autosuspend (&client->dev);
@@ -995,7 +1044,7 @@ static int imx219_enum_frame_size(struct v4l2_subdev *sd,if (fse->code !=MEDIA_BUS_FMT_META_8 || fse->index >0 )return -EINVAL ; - fse->min_width =IMX219_ACTIVE_AREA_WIDTH ; + fse->min_width =IMX219_OUTPUT_X_SIZE_MIN ; fse->max_width =IMX219_ACTIVE_AREA_WIDTH ; fse->min_height =IMX219_EMBEDDED_DATA_HEIGHT ; fse->max_height =IMX219_EMBEDDED_DATA_HEIGHT ;
@@ -1253,6 +1302,41 @@ static int imx219_get_selection(struct v4l2_subdev *sd, } } +static int imx219_set_selection (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_selection *sel) +{ +if (!(ci && ci->caps &V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR )) +return -EINVAL ; + +/* +* The embedded data stream doesn't support selection rectangles, +* neither on the embedded data pad nor on the source pad. +*/ +if (sel->pad !=IMX219_PAD_IMAGE || sel->stream !=IMX219_STREAM_IMAGE ) +return -EINVAL ; + +switch (sel->target) { +case V4L2_SEL_TGT_CROP : { +struct imx219 *imx219 =to_imx219 (sd); +struct v4l2_rect *crop = +v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); + +imx219_apply_binning (state, &sel->r, imx219->binning->val); + + *crop = sel->r; + +return 0 ; + } +case V4L2_SEL_TGT_COMPOSE : + sel->r = *v4l2_subdev_state_get_compose (state, sel->pad); +return 0 ; +default : +return -EINVAL ; + } +} +static int imx219_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) {
@@ -1377,6 +1461,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = { .get_fmt = v4l2_subdev_get_fmt, .set_fmt = imx219_set_pad_format, .get_selection = imx219_get_selection, + .set_selection = imx219_set_selection, .enum_frame_size = imx219_enum_frame_size, .get_frame_desc = imx219_get_frame_desc, .enable_streams = imx219_enable_streams,
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 66/73 media: imx219: Support LINE_LENGTH_PIXELS and FRAME_LENGTH_LINES controls
In reply to Sakari AilusSupport V4L2_CID_LINE_LENGTH_PIXELS and V4L2_CID_FRAME_LENGTH_LINES controls. These two controls provide direct access to sensor's line and frame lengths, without requiring a reference crop rectangle.
--- drivers/media/i2c/imx219.c | 171 +++++++++++++++++++++++------------- include/media/v4l2-common.h | 3 + 2 files changed, 112 insertions(+), 62 deletions(-)
drivers/media/i2c/imx219.c +109 -62
@@ -399,12 +399,17 @@ struct imx219 {struct v4l2_ctrl *exposure;struct v4l2_ctrl *vflip;struct v4l2_ctrl *hflip; +struct v4l2_ctrl *fll;struct v4l2_ctrl *vblank; +struct v4l2_ctrl *llp;struct v4l2_ctrl *hblank;struct v4l2_ctrl *binning;/* Two or Four lanes */ u8 lanes; + +/* For handling frame timing dependencies. */ +bool setting_ctrl; };static inline struct imx219 *to_imx219 (struct v4l2_subdev *_sd)
@@ -486,9 +491,10 @@ enum imx219_binning_factor_indices {static const struct {u8 h, v; +u16 llp_min; } imx219_binnings[] = { - [IMX219_BINNING_11 ] = {IMX219_BINNING_NONE ,IMX219_BINNING_NONE , }, - [IMX219_BINNING_22 ] = {IMX219_BINNING_X2_ANALOG ,IMX219_BINNING_X2_ANALOG , }, + [IMX219_BINNING_11 ] = {IMX219_BINNING_NONE ,IMX219_BINNING_NONE ,IMX219_LLP_MIN , }, + [IMX219_BINNING_22 ] = {IMX219_BINNING_X2_ANALOG ,IMX219_BINNING_X2_ANALOG ,IMX219_BINNED_LLP_MIN , }, };static const s64 imx219_binning_factors[] = {
@@ -502,8 +508,10 @@ static inline u32 imx219_get_rate_factor(struct imx219 *imx219)IMX219_BINNING_X2_ANALOG ?2 :1 ; } -static void imx219_apply_binning (struct v4l2_subdev_state *state, -struct v4l2_rect *crop,unsigned int index) +static int imx219_apply_binning (struct imx219 *imx219, +struct v4l2_subdev_state *state, +struct v4l2_rect *crop,int rate_factor, +unsigned int index) {struct v4l2_rect *compose =v4l2_subdev_state_get_compose (state,IMX219_PAD_IMAGE );
@@ -514,6 +522,7 @@ static void imx219_apply_binning(struct v4l2_subdev_state *state,v4l2_subdev_state_get_format (state,IMX219_PAD_SOURCE ,IMX219_STREAM_EDATA );s64 binning = imx219_binning_factors[index]; +int ret; crop->width = clamp(crop->width, IMX219_OUTPUT_X_SIZE_MIN * V4L2_BINNING_FACTORS_HNUM(binning),
@@ -539,6 +548,33 @@ static void imx219_apply_binning(struct v4l2_subdev_state *state, embedded_format->width = embedded_source_format->width = source_format->width; + +int fll_min =IMX219_VBLANK_MIN + source_format->height; + ret =__v4l2_ctrl_modify_range (imx219->fll, fll_min,IMX219_FLL_MAX , + rate_factor, fll_min); +if (ret) +return ret; + +int vblank_min =IMX219_VBLANK_MIN ; + ret =__v4l2_ctrl_modify_range (imx219->vblank, + vblank_min, +IMX219_FLL_MAX - source_format->height, + rate_factor, vblank_min); +if (ret) +return ret; + +int llp_min = imx219_binnings[index].llp_min; + ret =__v4l2_ctrl_modify_range (imx219->llp, llp_min,IMX219_LLP_MAX , +IMX219_LLP_STEP , llp_min); +if (ret) +return ret; + +return __v4l2_ctrl_modify_range (imx219->hblank, + llp_min - (int )source_format->width, +IMX219_LLP_MAX - + (int )source_format->width, +IMX219_LLP_STEP , + llp_min - (int )source_format->width); }static int imx219_set_ctrl (struct v4l2_ctrl *ctrl)
@@ -557,35 +593,27 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) rate_factor =imx219_get_rate_factor (imx219);switch (ctrl->id) { -case V4L2_CID_VBLANK : { -int exposure_max, exposure_def; - -/* Update max exposure while meeting expected vblanking */ - exposure_max = format->height + ctrl->val - -IMX219_EXPOSURE_OFFSET * rate_factor; - exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? - exposure_max :IMX219_EXPOSURE_DEFAULT ; - ret =__v4l2_ctrl_modify_range (imx219->exposure, - imx219->exposure->minimum, - exposure_max, - rate_factor, exposure_def); +case V4L2_CID_FRAME_LENGTH_LINES : +case V4L2_CID_VBLANK : +case V4L2_CID_LINE_LENGTH_PIXELS : +case V4L2_CID_HBLANK : + ret =v4l2_sensor_fll_llp_set (imx219->fll, imx219->vblank, + imx219->llp, imx219->hblank, + imx219->exposure, format, ctrl, + &imx219->setting_ctrl, +IMX219_EXPOSURE_OFFSET * + rate_factor);if (ret)return ret;break ; - }case V4L2_CID_BINNING_FACTORS : {struct v4l2_rect *crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); -cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_H , - imx219_binnings[ctrl->val].h, &ret); -cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_V , - imx219_binnings[ctrl->val].v, &ret); - -if (ctrl->val != ctrl->cur.val) -imx219_apply_binning (state, crop, ctrl->val); - -return 0 ; + ret =imx219_apply_binning (imx219, state, crop, rate_factor, + ctrl->val); +if (ret) +return ret; } }
@@ -618,13 +646,22 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)cci_write (imx219->regmap,IMX219_REG_ORIENTATION , imx219->hflip->val | imx219->vflip->val <<1 , &ret);break ; -case V4L2_CID_VBLANK : +case V4L2_CID_FRAME_LENGTH_LINES :cci_write (imx219->regmap,IMX219_REG_FRM_LENGTH_A , - (format->height + ctrl->val) / rate_factor, &ret); + ctrl->val / rate_factor, &ret);break ; +case V4L2_CID_LINE_LENGTH_PIXELS : +cci_write (imx219->regmap,IMX219_REG_LINE_LENGTH_A , ctrl->val, + &ret); +break ; +case V4L2_CID_VBLANK :case V4L2_CID_HBLANK : -cci_write (imx219->regmap,IMX219_REG_LINE_LENGTH_A , - format->width + ctrl->val, &ret); +break ; +case V4L2_CID_BINNING_FACTORS : +cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_H , + imx219_binnings[ctrl->val].h, &ret); +cci_write (imx219->regmap,IMX219_REG_BINNING_MODE_V , + imx219_binnings[ctrl->val].v, &ret);break ;case V4L2_CID_TEST_PATTERN_RED : cci_write(imx219->regmap, IMX219_REG_TESTP_RED,
@@ -699,10 +736,19 @@ static int imx219_init_controls(struct imx219 *imx219) imx219->link_freq->flags |=V4L2_CTRL_FLAG_READ_ONLY ;/* Initial blanking and exposure. Limits are updated during set_fmt */ + imx219->fll =v4l2_ctrl_new_std (ctrl_hdlr, &imx219_ctrl_ops, +V4L2_CID_FRAME_LENGTH_LINES , +IMX219_ACTIVE_AREA_HEIGHT + +IMX219_VBLANK_MIN ,IMX219_FLL_MAX ,1 , + mode->fll_def); imx219->vblank =v4l2_ctrl_new_std (ctrl_hdlr, &imx219_ctrl_ops,V4L2_CID_VBLANK ,IMX219_VBLANK_MIN ,IMX219_FLL_MAX - mode->height,1 , mode->fll_def - mode->height); + imx219->llp =v4l2_ctrl_new_std (ctrl_hdlr, &imx219_ctrl_ops, +V4L2_CID_LINE_LENGTH_PIXELS , +IMX219_LLP_MIN ,IMX219_LLP_MAX ,1 , +IMX219_LLP_MIN ); imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_HBLANK, IMX219_LLP_MIN - mode->width,
@@ -782,6 +828,11 @@ static int imx219_init_controls(struct imx219 *imx219) goto error; } + imx219->fll->flags |=V4L2_CTRL_FLAG_UPDATE ; + imx219->vblank->flags |=V4L2_CTRL_FLAG_UPDATE ; + imx219->llp->flags |=V4L2_CTRL_FLAG_UPDATE ; + imx219->hblank->flags |=V4L2_CTRL_FLAG_UPDATE ; + ret =v4l2_fwnode_device_parse (&client->dev, &props);if (ret) goto error;
@@ -1141,39 +1192,39 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,IMX219_ACTIVE_AREA_TOP ;if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -int exposure_max; -int exposure_def; -int llp_min; +unsigned int binning = bin_hv ==1 ? +IMX219_BINNING_11 :IMX219_BINNING_22 ;int pixel_rate; - ret =__v4l2_ctrl_s_ctrl (imx219->binning, bin_hv ==1 ? -IMX219_BINNING_11 :IMX219_BINNING_22 ); + ret =__v4l2_ctrl_s_ctrl (imx219->binning, binning); +if (ret) +return ret; + +int rate_factor =imx219_get_rate_factor (imx219); + ret =imx219_apply_binning (imx219, state, crop, rate_factor, + binning);if (ret)return ret;/* Update limits and set FPS to default */ - ret =__v4l2_ctrl_modify_range (imx219->vblank,IMX219_VBLANK_MIN , -IMX219_FLL_MAX - mode->height, + ret =__v4l2_ctrl_modify_range (imx219->vblank, + imx219->vblank->minimum, + imx219->vblank->maximum, rate_factor, mode->fll_def - mode->height);if (ret)return ret; - ret =__v4l2_ctrl_s_ctrl (imx219->vblank, - mode->fll_def - mode->height); + ret =__v4l2_ctrl_modify_range (imx219->fll, + imx219->fll->minimum, + imx219->fll->maximum, + rate_factor, + mode->fll_def);if (ret)return ret; -/* Update max exposure while meeting expected vblanking */ -int rate_factor =imx219_get_rate_factor (imx219); - exposure_max = mode->fll_def - -IMX219_EXPOSURE_OFFSET * rate_factor; - exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? - exposure_max :IMX219_EXPOSURE_DEFAULT ; - ret =__v4l2_ctrl_modify_range (imx219->exposure, - imx219->exposure->minimum, - exposure_max, - rate_factor, exposure_def); + ret =__v4l2_ctrl_s_ctrl (imx219->vblank, + mode->fll_def - mode->height);if (ret)return ret;
@@ -1183,18 +1234,9 @@ static int imx219_set_pad_format_compat(struct v4l2_subdev *sd,* operates on two lines together. So we switch to a higher * minimum of 3560. */ - llp_min = imx219_binnings[imx219->binning->val].h == -IMX219_BINNING_X2_ANALOG ? -IMX219_BINNED_LLP_MIN :IMX219_LLP_MIN ; - ret =__v4l2_ctrl_modify_range (imx219->hblank, - llp_min - mode->width, -IMX219_LLP_MAX - mode->width, -IMX219_LLP_STEP , - llp_min - mode->width); -if (ret) -return ret; - - ret =__v4l2_ctrl_s_ctrl (imx219->hblank, llp_min - mode->width); + ret =__v4l2_ctrl_s_ctrl (imx219->hblank, + imx219_binnings[binning].llp_min - + mode->width);if (ret)return ret;
@@ -1322,8 +1364,13 @@ static int imx219_set_selection(struct v4l2_subdev *sd,struct imx219 *imx219 =to_imx219 (sd);struct v4l2_rect *crop =v4l2_subdev_state_get_crop (state,IMX219_PAD_IMAGE ); +int ret; -imx219_apply_binning (state, &sel->r, imx219->binning->val); + ret =imx219_apply_binning (imx219, state, &sel->r, +imx219_get_rate_factor (imx219), + imx219->binning->val); +if (ret) +return ret; *crop = sel->r;
include/media/v4l2-common.h +3 -0
@@ -17,6 +17,9 @@#include <linux/time.h> #include <media/v4l2-dev.h> +struct v4l2_ctrl ; +struct v4l2_mbus_framefmt ; +/* Common printk constructs for v4l-i2c drivers. These macros create a unique prefix consisting of the driver name, the adapter number and the i2c address. */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 67/73 media: v4l2-common: Add helper function media_bus_fmt_to_csi2_(bpp|dt)()
In reply to Sakari AilusFrom: Frank Li <[email protected]>
Add helper function media_bus_fmt_to_csi2_bpp() to get media bus fmt's bpp to reduce codes such as
static const struct imx7_csi_pixfmt pixel_formats[] = {
{
.fourcc = V4L2_PIX_FMT_UYVY,
.codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_UYVY8_2X8,
MEDIA_BUS_FMT_UYVY8_1X16
),
.yuv = true,
.bpp = 16,
},
.....bpp can be removed from pixel_formats with this helper function.
CSI2 data type is defined by MIPI Camera Serial Interface 2 Spec Ver4.1. See section 9.4.
Add helper function media_bus_fmt_to_csi2_dt() to convert media bus fmt to MIPI defined data type and avoid below duplicated static array in each CSI2 drivers.
{
.code = MEDIA_BUS_FMT_UYVY8_1X16,
.data_type = MIPI_CSI2_DT_YUV422_8B,
}Only add known map for dt type. Need update media_bus_fmt_info when new mapping used.
--- drivers/media/v4l2-core/v4l2-common.c | 187 ++++++++++++++++++++++++++ include/media/mipi-csi2.h | 24 ++++ 2 files changed, 211 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +187 -0
@@ -46,6 +46,7 @@#include <linux/uaccess.h> #include <asm/io.h> #include <asm/div64.h> +#include <media/mipi-csi2.h> #include <media/v4l2-common.h> #include <media/v4l2-device.h> #include <media/v4l2-ctrls.h>
@@ -928,3 +929,189 @@ int v4l2_sensor_fll_llp_set(struct v4l2_ctrl *fll, struct v4l2_ctrl *vblank, exposure_max); }EXPORT_SYMBOL_GPL (v4l2_sensor_fll_llp_set); + +/** +* struct media_bus_fmt_info - information about a media bus format +* @code: media bus format identifier (MEDIA_BUS_FMT_*) +* @dt: data type define in MIPI spec (MIPI_CSI2_DT *) +* @bpp: bit width per pixel, which is suffix from MEDIA_BUS_FMT_*, no pad. no +* compressed data. +*/ +struct media_bus_fmt_info { +u32 code; +u8 dt; +u8 bpp; +}; + +static const struct media_bus_fmt_info media_bus_fmt_info[] = { + { .code =MEDIA_BUS_FMT_RGB444_1X12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB565_1X16 , .dt =MIPI_CSI2_DT_RGB565 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_BGR565_2X8_BE , .dt =MIPI_CSI2_DT_RGB565 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_BGR565_2X8_LE , .dt =MIPI_CSI2_DT_RGB565 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB565_2X8_BE , .dt =MIPI_CSI2_DT_RGB565 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB565_2X8_LE , .dt =MIPI_CSI2_DT_RGB565 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_RGB666_1X18 , .bpp =18 }, + { .code =MEDIA_BUS_FMT_RGB666_2X9_BE , .bpp =18 }, + { .code =MEDIA_BUS_FMT_BGR666_1X18 , .bpp =18 }, + { .code =MEDIA_BUS_FMT_RBG888_1X24 , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB666_1X24_CPADHI , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_BGR666_1X24_CPADHI , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB565_1X24_CPADHI , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB666_1X7X3_SPWG , .bpp =21 }, + { .code =MEDIA_BUS_FMT_BGR888_1X24 , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_BGR888_3X8 , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_GBR888_1X24 , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB888_1X24 , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB888_2X12_BE , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB888_2X12_LE , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB888_3X8 , .dt =MIPI_CSI2_DT_RGB888 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB888_3X8_DELTA , .bpp =24 }, + { .code =MEDIA_BUS_FMT_RGB888_1X7X4_SPWG , .bpp =28 }, + { .code =MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA , .bpp =28 }, + { .code =MEDIA_BUS_FMT_RGB666_1X30_CPADLO , .bpp =30 }, + { .code =MEDIA_BUS_FMT_RGB888_1X30_CPADLO , .bpp =30 }, + { .code =MEDIA_BUS_FMT_ARGB8888_1X32 , .bpp =32 }, + { .code =MEDIA_BUS_FMT_RGB888_1X32_PADHI , .bpp =32 }, + { .code =MEDIA_BUS_FMT_RGB101010_1X30 , .bpp =30 }, + { .code =MEDIA_BUS_FMT_RGB101010_1X7X5_SPWG , .bpp =35 }, + { .code =MEDIA_BUS_FMT_RGB101010_1X7X5_JEIDA , .bpp =35 }, + { .code =MEDIA_BUS_FMT_RGB666_1X36_CPADLO , .bpp =36 }, + { .code =MEDIA_BUS_FMT_RGB888_1X36_CPADLO , .bpp =36 }, + { .code =MEDIA_BUS_FMT_RGB121212_1X36 , .bpp =36 }, + { .code =MEDIA_BUS_FMT_RGB161616_1X48 , .bpp =48 }, + + { .code =MEDIA_BUS_FMT_Y8_1X8 , .dt =MIPI_CSI2_DT_RAW8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_UV8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_UYVY8_1_5X8 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_VYUY8_1_5X8 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_YUYV8_1_5X8 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_YVYU8_1_5X8 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_UYVY8_2X8 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_VYUY8_2X8 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_YUYV8_2X8 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_YVYU8_2X8 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_Y10_1X10 , .dt =MIPI_CSI2_DT_RAW10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_Y10_2X8_PADHI_LE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_UYVY10_2X10 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_VYUY10_2X10 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_YUYV10_2X10 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_YVYU10_2X10 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_Y12_1X12 , .dt =MIPI_CSI2_DT_RAW12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_UYVY12_2X12 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_VYUY12_2X12 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_YUYV12_2X12 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_YVYU12_2X12 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_Y14_1X14 , .dt =MIPI_CSI2_DT_RAW14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_Y16_1X16 , .dt =MIPI_CSI2_DT_RAW16 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_UYVY8_1X16 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_VYUY8_1X16 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_YUYV8_1X16 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_YVYU8_1X16 , .dt =MIPI_CSI2_DT_YUV422_8B , .bpp =16 }, + { .code =MEDIA_BUS_FMT_YDYUYDYV8_1X16 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_UYVY10_1X20 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_VYUY10_1X20 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_YUYV10_1X20 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_YVYU10_1X20 , .dt =MIPI_CSI2_DT_YUV422_10B , .bpp =20 }, + { .code =MEDIA_BUS_FMT_VUY8_1X24 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_YUV8_1X24 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_UYYVYY8_0_5X24 , .dt =MIPI_CSI2_DT_YUV420_8B , .bpp =12 }, + { .code =MEDIA_BUS_FMT_UYVY12_1X24 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_VYUY12_1X24 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_YUYV12_1X24 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_YVYU12_1X24 , .bpp =24 }, + { .code =MEDIA_BUS_FMT_YUV10_1X30 , .bpp =30 }, + { .code =MEDIA_BUS_FMT_UYYVYY10_0_5X30 , .bpp =15 }, + { .code =MEDIA_BUS_FMT_AYUV8_1X32 , .bpp =32 }, + { .code =MEDIA_BUS_FMT_UYYVYY12_0_5X36 , .bpp =18 }, + { .code =MEDIA_BUS_FMT_YUV12_1X36 , .bpp =36 }, + { .code =MEDIA_BUS_FMT_YUV16_1X48 , .bpp =48 }, + { .code =MEDIA_BUS_FMT_UYYVYY16_0_5X48 , .bpp =24 }, + + { .code =MEDIA_BUS_FMT_SBGGR8_1X8 , .dt =MIPI_CSI2_DT_RAW8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SGBRG8_1X8 , .dt =MIPI_CSI2_DT_RAW8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SGRBG8_1X8 , .dt =MIPI_CSI2_DT_RAW8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SRGGB8_1X8 , .dt =MIPI_CSI2_DT_RAW8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_RAW_8 , .dt =MIPI_CSI2_DT_RAW8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SBGGR10_1X10 , .dt =MIPI_CSI2_DT_RAW10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_SGBRG10_1X10 , .dt =MIPI_CSI2_DT_RAW10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_SGRBG10_1X10 , .dt =MIPI_CSI2_DT_RAW10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_SRGGB10_1X10 , .dt =MIPI_CSI2_DT_RAW10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_RAW_10 , .dt =MIPI_CSI2_DT_RAW10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_SBGGR12_1X12 , .dt =MIPI_CSI2_DT_RAW12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_SGBRG12_1X12 , .dt =MIPI_CSI2_DT_RAW12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_SGRBG12_1X12 , .dt =MIPI_CSI2_DT_RAW12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_SRGGB12_1X12 , .dt =MIPI_CSI2_DT_RAW12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_RAW_12 , .dt =MIPI_CSI2_DT_RAW12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_SBGGR14_1X14 , .dt =MIPI_CSI2_DT_RAW14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_SGBRG14_1X14 , .dt =MIPI_CSI2_DT_RAW14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_SGRBG14_1X14 , .dt =MIPI_CSI2_DT_RAW14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_SRGGB14_1X14 , .dt =MIPI_CSI2_DT_RAW14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_RAW_14 , .dt =MIPI_CSI2_DT_RAW14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_SBGGR16_1X16 , .dt =MIPI_CSI2_DT_RAW16 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SGBRG16_1X16 , .dt =MIPI_CSI2_DT_RAW16 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SGRBG16_1X16 , .dt =MIPI_CSI2_DT_RAW16 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_SRGGB16_1X16 , .dt =MIPI_CSI2_DT_RAW16 , .bpp =16 }, + + { .code =MEDIA_BUS_FMT_JPEG_1X8 , .bpp =8 }, + + { .code =MEDIA_BUS_FMT_S5C_UYVY_JPEG_1X8 , .bpp =8 }, + + { .code =MEDIA_BUS_FMT_AHSV8888_1X32 , .bpp =32 }, + + { .code =MEDIA_BUS_FMT_META_8 , .bpp =8 }, + { .code =MEDIA_BUS_FMT_META_10 , .bpp =10 }, + { .code =MEDIA_BUS_FMT_META_12 , .bpp =12 }, + { .code =MEDIA_BUS_FMT_META_14 , .bpp =14 }, + { .code =MEDIA_BUS_FMT_META_16 , .bpp =16 }, + { .code =MEDIA_BUS_FMT_META_20 , .bpp =20 }, + { .code =MEDIA_BUS_FMT_META_24 , .bpp =24 }, +}; + +static const struct media_bus_fmt_info *media_bus_fmt_info_get (u32 bus_fmt) +{ +for (unsigned int i =0 ; i <ARRAY_SIZE (media_bus_fmt_info); i++) { +if (media_bus_fmt_info[i].code == bus_fmt) +return &media_bus_fmt_info[i]; + } + +return NULL ; +} + +int media_bus_fmt_to_csi2_dt (u32 bus_fmt) +{ +const struct media_bus_fmt_info *info =media_bus_fmt_info_get (bus_fmt); + +if (!info) +return -EINVAL ; + +/* Check bpp because 0 (MIPI_CSI2_DT_FS) is a valid data type code */ +return info->bpp ? info->dt : -EINVAL ; +} +EXPORT_SYMBOL_GPL (media_bus_fmt_to_csi2_dt); + +int media_bus_fmt_to_csi2_bpp (u32 bus_fmt) +{ +const struct media_bus_fmt_info *info =media_bus_fmt_info_get (bus_fmt); + +if (!info) +return -EINVAL ; + +return info->bpp ? info->bpp : -EINVAL ; +} +EXPORT_SYMBOL_GPL (media_bus_fmt_to_csi2_bpp);
include/media/mipi-csi2.h +24 -0
@@ -8,6 +8,8 @@#ifndef _MEDIA_MIPI_CSI2_H#define _MEDIA_MIPI_CSI2_H +#include <linux/types.h> +/* Short packet data types */ #define MIPI_CSI2_DT_FS 0x00#define MIPI_CSI2_DT_FE 0x01
@@ -44,4 +46,26 @@#define MIPI_CSI2_DT_RAW20 0x2f#define MIPI_CSI2_DT_USER_DEFINED (n) (0x30 + (n))/* 0..7 */ +/** +* media_bus_fmt_to_csi2_dt - Get MIPI CSI2 data type from media bus format +* +* @bus_fmt: media bus format identifier (MEDIA_BUS_FMT_*) +* +* Return: MIPI CSI2 data type MIPI_CSI2_DT_*, or -EINVAL if no mbus code is +* found.. +*/ +int media_bus_fmt_to_csi2_dt (u32 bus_fmt); + +/** +* media_bus_fmt_to_csi2_bpp - Get media bus format's bit depth +* +* @bus_fmt: media bus format identifier (MEDIA_BUS_FMT_*) +* +* Return: bit depth, -EINVAL if fail to get from bus_fmt. +* +* Notes: this bpp is suffix from MEDIA_BUS_FMT_*, no pad, not for compressed +* data. +*/ +int media_bus_fmt_to_csi2_bpp (u32 bus_fmt); +#endif /* _MEDIA_MIPI_CSI2_H */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 68/73 media: bcm2835-unicam: Support generic raw formats
In reply to Sakari AilusAdd support for 8-bit unpacked and 10-, 12- and 14-bit packed generic raw formats.
--- .../media/platform/broadcom/bcm2835-unicam.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/media/platform/broadcom/bcm2835-unicam.c +27 -0
@@ -452,6 +452,33 @@ static const struct unicam_format_info unicam_image_formats[] = { .csi_dt = MIPI_CSI2_DT_RAW14, .unpack = UNICAM_PUM_UNPACK14, }, { + /* Generic raw formats */ + .fourcc = V4L2_PIX_FMT_RAW_8, + .code = MEDIA_BUS_FMT_RAW_8, + .depth = 8, + .csi_dt = MIPI_CSI2_DT_RAW8, + }, { + .fourcc = V4L2_PIX_FMT_RAW_CSI2_10, + .unpacked_fourcc = V4L2_PIX_FMT_RAW_10, + .code = MEDIA_BUS_FMT_RAW_10, + .depth = 10, + .csi_dt = MIPI_CSI2_DT_RAW10, + .unpack = UNICAM_PUM_UNPACK10, + }, { + .fourcc = V4L2_PIX_FMT_RAW_CSI2_12, + .unpacked_fourcc = V4L2_PIX_FMT_RAW_12, + .code = MEDIA_BUS_FMT_RAW_12, + .depth = 12, + .csi_dt = MIPI_CSI2_DT_RAW12, + .unpack = UNICAM_PUM_UNPACK12, + }, { + .fourcc = V4L2_PIX_FMT_RAW_CSI2_14, + .unpacked_fourcc = V4L2_PIX_FMT_RAW_14, + .code = MEDIA_BUS_FMT_RAW_14, + .depth = 14, + .csi_dt = MIPI_CSI2_DT_RAW14, + .unpack = UNICAM_PUM_UNPACK14, + }, { /* 16 bit Bayer formats could be supported. */ /* Greyscale formats */
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 69/73 media: ipu6: Add support for raw CFA-agnostic formats
In reply to Sakari AilusAdd support for CFA-agnostic mbus codes and V4L2 pixelformats.
--- drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 3 +++ drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c | 3 +++ drivers/media/pci/intel/ipu6/ipu6-isys-video.c | 8 ++++++++ 3 files changed, 14 insertions(+)
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c +3 -0
@@ -51,6 +51,9 @@ static const u32 csi2_supported_codes[] = {MEDIA_BUS_FMT_Y10_1X10 ,MEDIA_BUS_FMT_Y12_1X12 ,MEDIA_BUS_FMT_Y16_1X16 , +MEDIA_BUS_FMT_RAW_8 , +MEDIA_BUS_FMT_RAW_10 , +MEDIA_BUS_FMT_RAW_12 ,MEDIA_BUS_FMT_META_8 ,MEDIA_BUS_FMT_META_10 , MEDIA_BUS_FMT_META_12,
drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c +3 -0
@@ -33,6 +33,7 @@ unsigned int ipu6_isys_mbus_code_to_bpp(u32 code)case MEDIA_BUS_FMT_SGRBG12_1X12 :case MEDIA_BUS_FMT_SRGGB12_1X12 :case MEDIA_BUS_FMT_Y12_1X12 : +case MEDIA_BUS_FMT_RAW_12 :case MEDIA_BUS_FMT_META_12 :return 12 ;case MEDIA_BUS_FMT_SBGGR10_1X10 :
@@ -40,6 +41,7 @@ unsigned int ipu6_isys_mbus_code_to_bpp(u32 code)case MEDIA_BUS_FMT_SGRBG10_1X10 :case MEDIA_BUS_FMT_SRGGB10_1X10 :case MEDIA_BUS_FMT_Y10_1X10 : +case MEDIA_BUS_FMT_RAW_10 :case MEDIA_BUS_FMT_META_10 :return 10 ;case MEDIA_BUS_FMT_SBGGR8_1X8 :
@@ -47,6 +49,7 @@ unsigned int ipu6_isys_mbus_code_to_bpp(u32 code)case MEDIA_BUS_FMT_SGRBG8_1X8 :case MEDIA_BUS_FMT_SRGGB8_1X8 :case MEDIA_BUS_FMT_Y8_1X8 : +case MEDIA_BUS_FMT_RAW_8 :case MEDIA_BUS_FMT_META_8 :return 8 ;default :
drivers/media/pci/intel/ipu6/ipu6-isys-video.c +8 -0
@@ -99,6 +99,14 @@ const struct ipu6_isys_pixelformat ipu6_isys_pfmts[] = { IPU6_FW_ISYS_FRAME_FORMAT_RGB565 }, {V4L2_PIX_FMT_BGR24 ,24 ,24 ,MEDIA_BUS_FMT_RGB888_1X24 , IPU6_FW_ISYS_FRAME_FORMAT_RGBA888 }, + + { V4L2_PIX_FMT_RAW_8, 8, 8, MEDIA_BUS_FMT_RAW_8, + IPU6_FW_ISYS_FRAME_FORMAT_RAW8 }, + { V4L2_PIX_FMT_RAW_CSI2_10, 10, 10, MEDIA_BUS_FMT_RAW_10, + IPU6_FW_ISYS_FRAME_FORMAT_RAW10 }, + { V4L2_PIX_FMT_RAW_CSI2_12, 12, 12, MEDIA_BUS_FMT_RAW_12, + IPU6_FW_ISYS_FRAME_FORMAT_RAW12 }, + { V4L2_META_FMT_GENERIC_8, 8, 8, MEDIA_BUS_FMT_META_8, IPU6_FW_ISYS_FRAME_FORMAT_RAW8, true }, { V4L2_META_FMT_GENERIC_CSI2_10, 10, 10, MEDIA_BUS_FMT_META_10,
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 70/73 media: ipu6: Add support for generic unpacked pixel and metadata formats
In reply to Sakari AilusAdd support for V4L2_PIX_FMT_RAW_10 and V4L2_PIX_FMT_RAW_12 pixelformats as well as V4L2_META_FMT_GENERIC_16 for 10- and 12-bit depths.
--- drivers/media/pci/intel/ipu6/ipu6-isys-video.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/pci/intel/ipu6/ipu6-isys-video.c +8 -0
@@ -106,6 +106,10 @@ const struct ipu6_isys_pixelformat ipu6_isys_pfmts[] = { IPU6_FW_ISYS_FRAME_FORMAT_RAW10 }, {V4L2_PIX_FMT_RAW_CSI2_12 ,12 ,12 ,MEDIA_BUS_FMT_RAW_12 , IPU6_FW_ISYS_FRAME_FORMAT_RAW12 }, + { V4L2_PIX_FMT_RAW_10, 16, 10, MEDIA_BUS_FMT_RAW_10, + IPU6_FW_ISYS_FRAME_FORMAT_RAW16 }, + { V4L2_PIX_FMT_RAW_12, 16, 12, MEDIA_BUS_FMT_RAW_12, + IPU6_FW_ISYS_FRAME_FORMAT_RAW16 }, { V4L2_META_FMT_GENERIC_8, 8, 8, MEDIA_BUS_FMT_META_8, IPU6_FW_ISYS_FRAME_FORMAT_RAW8, true },
@@ -113,6 +117,10 @@ const struct ipu6_isys_pixelformat ipu6_isys_pfmts[] = { IPU6_FW_ISYS_FRAME_FORMAT_RAW10, true }, { V4L2_META_FMT_GENERIC_CSI2_12, 12, 12, MEDIA_BUS_FMT_META_12, IPU6_FW_ISYS_FRAME_FORMAT_RAW12, true }, + { V4L2_META_FMT_GENERIC_16, 16, 10, MEDIA_BUS_FMT_META_10, + IPU6_FW_ISYS_FRAME_FORMAT_RAW16, true }, + { V4L2_META_FMT_GENERIC_16, 16, 12, MEDIA_BUS_FMT_META_12, + IPU6_FW_ISYS_FRAME_FORMAT_RAW16, true }, { V4L2_META_FMT_GENERIC_16, 16, 16, MEDIA_BUS_FMT_META_16, IPU6_FW_ISYS_FRAME_FORMAT_RAW16, true }, };
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 71/73 Documentation: media: Reword blanking control documentation
In reply to Sakari AilusOriginally the VBLANK and HBLANK controls were intended to signify camera sensor vertical and horizontal blanking values, respectively, and were used with the analogue crop rectangle and the pixel rate to calculate the frame interval. Due to various factors, namely the reference size of output format rather than analogue crop (non-CCS sensors) and the use of analogue binning, these values in fact have primarily served frame interval configuration whereas they may not have reflected blanking anymore. Take this into account in documentation.
--- .../media/v4l/ext-ctrls-image-source.rst | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-)
Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst +14 -8
@@ -22,16 +22,22 @@ Image Source Control IDs The IMAGE_SOURCE class descriptor. ``V4L2_CID_VBLANK (integer)`` - Vertical blanking. The idle period after every frame during which no - image data is produced. The unit of vertical blanking is a line. - Every line has length of the image width plus horizontal blanking at - the pixel rate defined by ``V4L2_CID_PIXEL_RATE`` control in the - same sub-device. + Difference between the reference analogue crop rectangle (CCS) height or + output format height and the frame length in lines. See :ref:`frame interval + configuration <media_camera_sensor_frame_rate_raw>`. + + The primary purpose of this control is low level frame interval + configuration. The value may also reflect vertical blanking but this is not + guaranteed. ``V4L2_CID_HBLANK (integer)`` - Horizontal blanking. The idle period after every line of image data - during which no image data is produced. The unit of horizontal - blanking is pixels. + Difference between the reference analogue crop rectangle (CCS) width or + output format width and the line length in pixels. See :ref:`frame interval + configuration <media_camera_sensor_frame_rate_raw>`. + + The primary purpose of this control is low level frame interval + configuration. The value may also reflect horizontal blanking but this is + not guaranteed. ``V4L2_CID_ANALOGUE_GAIN (integer)`` Analogue gain is gain affecting all colour components in the pixel
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 72/73 media: uapi: Add generic raw pixelformat for 16 bpp
In reply to Sakari AilusAdd generic raw pixelformats for bit depth 16.
--- .../media/v4l/pixfmt-raw-generic.rst | 49 +++++++++++++++++-- drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 3 files changed, 48 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst +46 -3
@@ -1,8 +1,8 @@ .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -****************************************************************************************************************************************************************************************************************************** -V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE'), V4L2_PIX_FMT_RAW_10 ('RAWA'), V4L2_PIX_FMT_RAW_12 ('RAWC'), V4L2_PIX_FMT_RAW_14 ('RAWE') -****************************************************************************************************************************************************************************************************************************** +************************************************************************************************************************************************************************************************************************************************************ +V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE'), V4L2_PIX_FMT_RAW_10 ('RAWA'), V4L2_PIX_FMT_RAW_12 ('RAWC'), V4L2_PIX_FMT_RAW_14 ('RAWE'), V4L2_PIX_FMT_RAW_16 ('RAWG') +************************************************************************************************************************************************************************************************************************************************************ Generic line-based raw image data formats
@@ -292,3 +292,46 @@ Each cell is one byte. "P" denotes a pixel. - P\ :sub:`21 bits 13--8` (bits 5--0) - P\ :sub:`31 bits 7--0` - P\ :sub:`31 bits 13--8` (bits 5--0) + +.. _v4l2-pix-fmt-raw-16: + +V4L2_PIX_FMT_RAW_16 +------------------- + +V4L2_PIX_FMT_RAW_16 contains 16-bit image data, with each two consecutive +bytes forming a pixel value. This format is typically used by CSI-2 receivers +with a source that transmits MEDIA_BUS_FMT_RAW_16 and the CSI-2 receiver writes +the received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_16.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 7--0` + - P\ :sub:`00 bits 15--8` + - P\ :sub:`10 bits 7--0` + - P\ :sub:`10 bits 15--8` + - P\ :sub:`20 bits 7--0` + - P\ :sub:`20 bits 15--8` + - P\ :sub:`30 bits 7--0` + - P\ :sub:`30 bits 15--8` + * - start + 8: + - P\ :sub:`01 bits 7--0` + - P\ :sub:`01 bits 15--8` + - P\ :sub:`11 bits 7--0` + - P\ :sub:`11 bits 15--8` + - P\ :sub:`21 bits 7--0` + - P\ :sub:`21 bits 15--8` + - P\ :sub:`31 bits 7--0` + - P\ :sub:`31 bits 15--8` + +.. _v4l2-pix-fmt-raw-csi2-20:
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
@@ -1441,6 +1441,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_RAW_10 : descr ="10-bit Raw" ;break ;case V4L2_PIX_FMT_RAW_12 : descr ="12-bit Raw" ;break ;case V4L2_PIX_FMT_RAW_14 : descr ="14-bit Raw" ;break ; +case V4L2_PIX_FMT_RAW_16 : descr ="16-bit Raw" ;break ;case V4L2_PIX_FMT_RAW_CRU20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;
include/uapi/linux/videodev2.h +1 -0
@@ -753,6 +753,7 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_RAW_10 v4l2_fourcc('R', 'A', 'W', 'A')#define V4L2_PIX_FMT_RAW_12 v4l2_fourcc('R', 'A', 'W', 'C')#define V4L2_PIX_FMT_RAW_14 v4l2_fourcc('R', 'A', 'W', 'E') +#define V4L2_PIX_FMT_RAW_16 v4l2_fourcc('R', 'A', 'W', 'G')/* HSV formats */ #define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v13 73/73 media: uapi: Add generic CSI-2 raw pixelformats for 16, 20, 24 and 28 bpp
In reply to Sakari AilusAdd generic raw pixelformats for bit depths 16, 20, 24 and 28. These formats are CSI-2 packed, apart from the 16-bit and 24-bit formats.
--- .../media/v4l/pixfmt-raw-generic.rst | 169 +++++++++++++++++- drivers/media/v4l2-core/v4l2-ioctl.c | 3 + include/uapi/linux/videodev2.h | 3 + 3 files changed, 172 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst +166 -3
@@ -1,8 +1,8 @@ .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -************************************************************************************************************************************************************************************************************************************************************ -V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE'), V4L2_PIX_FMT_RAW_10 ('RAWA'), V4L2_PIX_FMT_RAW_12 ('RAWC'), V4L2_PIX_FMT_RAW_14 ('RAWE'), V4L2_PIX_FMT_RAW_16 ('RAWG') -************************************************************************************************************************************************************************************************************************************************************ +**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** +V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE'), V4L2_PIX_FMT_RAW_10 ('RAWA'), V4L2_PIX_FMT_RAW_12 ('RAWC'), V4L2_PIX_FMT_RAW_14 ('RAWE'), V4L2_PIX_FMT_RAW_16 ('RAWG'), V4L2_PIX_FMT_RAW_CSI2_20 ('RACK'), V4L2_PIX_FMT_RAW_24 ('RAWO'), V4L2_PIX_FMT_RAW_CSI2_28 ('RACS') +**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** Generic line-based raw image data formats
@@ -335,3 +335,166 @@ Each cell is one byte. "P" denotes a pixel. - P\ :sub:`31 bits 15--8` .. _v4l2-pix-fmt-raw-csi2-20: + +V4L2_PIX_FMT_RAW_CSI2_20 +------------------------ + +V4L2_PIX_FMT_RAW_CSI2_20 contains 20-bit packed image data, with four bytes +containing the top 8 bits of two pixels followed by lowest 4 bits of the pixels +packed into one byte. This format is typically used by CSI-2 receivers with a +source that transmits MEDIA_BUS_FMT_RAW_20 and the CSI-2 receiver writes the +received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_20.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{2cm} + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 19--12` + - P\ :sub:`00 bits 11--4` + - P\ :sub:`10 bits 19--12` + - P\ :sub:`10 bits 11--4` + - P\ :sub:`10 bits 3--0` (bits 7--4), + P\ :sub:`00 bits 3--0` (bits 3--0) + - P\ :sub:`20 bits 19--12` + - P\ :sub:`20 bits 11--4` + - P\ :sub:`30 bits 19--12` + - P\ :sub:`30 bits 11--4` + - P\ :sub:`30 bits 3--0` (bits 7--4), + P\ :sub:`20 bits 3--0` (bits 3--0) + * - start + 10: + - P\ :sub:`01 bits 19--12` + - P\ :sub:`01 bits 11--4` + - P\ :sub:`11 bits 19--12` + - P\ :sub:`11 bits 11--4` + - P\ :sub:`11 bits 3--0` (bits 7--4), + P\ :sub:`01 bits 3--0` (bits 3--0) + - P\ :sub:`21 bits 19--12` + - P\ :sub:`21 bits 11--4` + - P\ :sub:`31 bits 19--12` + - P\ :sub:`31 bits 11--4` + - P\ :sub:`31 bits 3--0` (bits 7--4), + P\ :sub:`21 bits 3--0` (bits 3--0) + +.. _v4l2-pix-fmt-raw-24: + +V4L2_PIX_FMT_RAW_24 +------------------- + +V4L2_PIX_FMT_RAW_24 contains 24-bit packed image data, with each three bytes +containing the value of one pixel. This format is typically used by CSI-2 +receivers with a source that transmits MEDIA_BUS_FMT_RAW_24 and the CSI-2 +receiver writes the received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_24.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}| + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 23--16` + - P\ :sub:`00 bits 15--8` + - P\ :sub:`00 bits 7--0` + - P\ :sub:`10 bits 23--16` + - P\ :sub:`10 bits 15--8` + - P\ :sub:`10 bits 7--0` + - P\ :sub:`20 bits 23--16` + - P\ :sub:`20 bits 15--8` + - P\ :sub:`20 bits 7--0` + - P\ :sub:`30 bits 23--16` + - P\ :sub:`30 bits 15--8` + - P\ :sub:`30 bits 7--0` + * - start + 12: + - P\ :sub:`01 bits 23--16` + - P\ :sub:`01 bits 15--8` + - P\ :sub:`01 bits 7--0` + - P\ :sub:`11 bits 23--16` + - P\ :sub:`11 bits 15--8` + - P\ :sub:`11 bits 7--0` + - P\ :sub:`21 bits 23--16` + - P\ :sub:`21 bits 15--8` + - P\ :sub:`21 bits 7--0` + - P\ :sub:`31 bits 23--16` + - P\ :sub:`31 bits 15--8` + - P\ :sub:`31 bits 7--0` + +.. _v4l2-pix-fmt-raw-csi2-28: + +V4L2_PIX_FMT_RAW_CSI2_28 +------------------------ + +V4L2_PIX_FMT_RAW_CSI2_28 contains 28-bit packed image data, with four bytes +containing the top 8 bits of two pixels followed by lowest 4 bits of the pixels +packed into one byte. This format is typically used by CSI-2 receivers with a +source that transmits MEDIA_BUS_FMT_RAW_28 and the CSI-2 receiver writes the +received data to memory as-is. + +The packing of the data follows the MIPI CSI-2 specification. + +**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_28.** +Each cell is one byte. "P" denotes a pixel. + +.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm} + +.. flat-table:: Sample 4x2 Image Frame + :header-rows: 0 + :stub-columns: 0 + :widths: 12 8 8 8 8 8 8 8 8 8 8 8 8 8 8 + + * - start + 0: + - P\ :sub:`00 bits 27--20` + - P\ :sub:`00 bits 13--6` + - P\ :sub:`10 bits 27--20` + - P\ :sub:`10 bits 13--6` + - P\ :sub:`00 bits 19--14` (bits 7--2), + P\ :sub:`00 bits 1--0` (bits 1--0) + - P\ :sub:`00 bits 5--2` (bits 7--4), + P\ :sub:`10 bits 17--14` (bits 3--0) + - P\ :sub:`10 bits 19--18` (bits 7--6), + P\ :sub:`10 bits 5--0` (bits 5--0) + - P\ :sub:`20 bits 27--20` + - P\ :sub:`20 bits 13--6` + - P\ :sub:`30 bits 27--20` + - P\ :sub:`30 bits 13--6` + - P\ :sub:`20 bits 19--14` (bits 7--2), + P\ :sub:`20 bits 1--0` (bits 1--0) + - P\ :sub:`20 bits 5--2` (bits 7--4), + P\ :sub:`30 bits 17--14` (bits 3--0) + - P\ :sub:`30 bits 19--18` (bits 7--6), + P\ :sub:`30 bits 5--0` (bits 5--0) + * - start + 14: + - P\ :sub:`01 bits 27--20` + - P\ :sub:`01 bits 13--6` + - P\ :sub:`11 bits 27--20` + - P\ :sub:`11 bits 13--6` + - P\ :sub:`01 bits 19--14` (bits 7--2), + P\ :sub:`01 bits 1--0` (bits 1--0) + - P\ :sub:`01 bits 5--2` (bits 7--4), + P\ :sub:`11 bits 17--14` (bits 3--0) + - P\ :sub:`11 bits 19--18` (bits 7--6), + P\ :sub:`11 bits 5--0` (bits 5--0) + - P\ :sub:`21 bits 27--20` + - P\ :sub:`21 bits 13--6` + - P\ :sub:`31 bits 27--20` + - P\ :sub:`31 bits 13--6` + - P\ :sub:`21 bits 19--14` (bits 7--2), + P\ :sub:`21 bits 1--0` (bits 1--0) + - P\ :sub:`21 bits 5--2` (bits 7--4), + P\ :sub:`31 bits 17--14` (bits 3--0) + - P\ :sub:`31 bits 19--18` (bits 7--6), + P\ :sub:`31 bits 5--0` (bits 5--0)
drivers/media/v4l2-core/v4l2-ioctl.c +3 -0
@@ -1442,6 +1442,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_RAW_12 : descr ="12-bit Raw" ;break ;case V4L2_PIX_FMT_RAW_14 : descr ="14-bit Raw" ;break ;case V4L2_PIX_FMT_RAW_16 : descr ="16-bit Raw" ;break ; +case V4L2_PIX_FMT_RAW_CSI2_20 : descr ="20-bit Raw, CSI-2 Packed" ;break ; +case V4L2_PIX_FMT_RAW_24 : descr ="24-bit Raw" ;break ; +case V4L2_PIX_FMT_RAW_CSI2_28 : descr ="28-bit Raw, CSI-2 Packed" ;break ;case V4L2_PIX_FMT_RAW_CRU20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;
include/uapi/linux/videodev2.h +3 -0
@@ -754,6 +754,9 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_RAW_12 v4l2_fourcc('R', 'A', 'W', 'C')#define V4L2_PIX_FMT_RAW_14 v4l2_fourcc('R', 'A', 'W', 'E')#define V4L2_PIX_FMT_RAW_16 v4l2_fourcc('R', 'A', 'W', 'G') +#define V4L2_PIX_FMT_RAW_CSI2_20 v4l2_fourcc('R', 'A', 'C', 'K') +#define V4L2_PIX_FMT_RAW_24 v4l2_fourcc('R', 'A', 'W', 'O') +#define V4L2_PIX_FMT_RAW_CSI2_28 v4l2_fourcc('R', 'A', 'C', 'S')/* HSV formats */ #define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')
Signature · 1 line
2.47.3