media: nxp: Add CSI Pixel Formatter support
Subsystems (5)
v16 cover media: nxp: Add CSI Pixel Formatter support
CSI Pixel Formatter is a module found on i.MX95. It could unpack the pixels received by the formatter and reformat them to meet the pixel link format requirement.
This patch series adds a new V4L2 driver for CSI Pixel Formatter.
Background
----------
The Camera CSR binding was upstreamed during the pre-silicon phase when the hardware integration details were not fully finalized. At that time, the syscon binding focused on the CSR's primary role as a shared register provider for clock gating, QoS, and error handling across Camera domain IPs.
However, the Camera CSR hardware is actually a mixed-function register container with varying control levels over different IP blocks:
- ISP/CSI: Clock gating only
- ISI: QoS configuration
- CSI: Buffer overflow handling
- LPCAC: Error handling only
- ISP: Pixel link selection
- Formatter: Complete IP control (full register set)
Why Child Nodes Now
-------------------
The CSI formatter is unique among these IPs - it's an independent hardware block whose complete control registers reside within the CSR address space, not just a few configuration bits. This architectural detail was not reflected in the original binding because:
1. The pre-silicon binding focused on simple register-level controls
2. The syscon pattern for complete IP control was not initially considered
Discussion with original CSR author(Peng Fan) confirmed this reflects the intended hardware design that wasn't fully captured during pre-silicon upstreaming.
v4l2-compliance 1.28.1-5233, 64 bits, 64-bit time_t v4l2-compliance SHA: fc15e229d9d3 2024-07-23 19:22:15
Compliance test for device /dev/v4l-subdev9:
Driver Info:
Driver version : 7.1.0 Capabilities : 0x00000002 Streams Support Client Capabilities: 0x0000000000000003
streams interval-uses-which
Required ioctls:
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev9 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device routing ioctls:
test Try VIDIOC_SUBDEV_G_ROUTING/VIDIOC_SUBDEV_S_ROUTING: OK test Active VIDIOC_SUBDEV_G_ROUTING/VIDIOC_SUBDEV_S_ROUTING: OK
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
Total for device /dev/v4l-subdev9: 47, Succeeded: 47, Failed: 0, Warnings: 0
---
Changes in v16:
- [3/3] Use depends on PM_CLK instead of select PM_CLK to avoid Kconfig warnings when building with COMPILE_TEST without PM enabled (Sashiko)
- [3/3] Add err_pm_disable label and call pm_runtime_dont_use_autosuspend() on csi_formatter_async_register() failure to fix PM state leak (Sashiko)
- [3/3] Add pm_runtime_dont_use_autosuspend() and pm_runtime_suspend() in remove to ensure clocks are disabled when driver is unbound (Sashiko)
- Link to v15: https://lore.kernel.org/r/[email protected]
Changes in v15:
- [3/3] Add pm_runtime_dont_use_autosuspend() on devm_pm_runtime_enable() failure (Laurent)
- [3/3] Extract csi_formatter_get_frame_desc() helper for start/stop_stream (Laurent)
- [3/3] Use dev_WARN() instead of dev_warn() + WARN_ON(1) (Laurent)
- [3/3] Use pm_runtime_put_autosuspend() instead of pm_runtime_put() (Laurent)
- [3/3] Add Reviewed-by tag from Laurent
- Link to v14: https://lore.kernel.org/r/[email protected]
Changes in v14:
- [3/3] Use select MFD_SYSCON instead of depends on MFD_SYSCON (Laurent)
- [3/3] Remove unused v4l2-ctrls.h and v4l2-event.h includes (Laurent)
- [3/3] Rename csi_sd to remote_sd and group with remote_pad (Laurent)
- [3/3] Move reg_offset after clk to group generic resources (Laurent)
- [3/3] Remove mutex lock as enable/disable_streams hold state lock (Laurent)
- [3/3] Rename formatter_dt_to_index_map to csi_formatter_dt_to_index_map (Laurent)
- [3/3] Rename formats to csi_formatter_formats (Laurent)
- [3/3] Declare loop variables in for-loop and add braces (Laurent)
- [3/3] Simplify set_fmt, rename sdformat to format, drop NULL check (Laurent)
- [3/3] Set field to V4L2_FIELD_NONE as interlaced not yet supported (Laurent)
- [3/3] Add streaming check in set_fmt to match set_routing (Laurent)
- [3/3] Add WARN_ON for unsupported data type as it indicates driver bug (Laurent)
- [3/3] Return -EPIPE instead of -EINVAL for invalid VC (Laurent)
- [3/3] Refactor ENOIOCTLCMD handling and remove redundant pad check (Laurent)
- [3/3] Use strscpy instead of snprintf for sd->name (Laurent)
- [3/3] Remove redundant dev_dbg in notify_bound (Laurent)
- [3/3] Simplify remote_pad assignment and drop NULL check (Laurent)
- [3/3] Read reg property directly into formatter->reg_offset (Laurent)
- [3/3] Store formatter pointer in drvdata to avoid sd_to_formatter calls (Laurent)
- [3/3] Enable runtime PM autosuspend with 1s delay (Laurent)
- [3/3] Use PM clock framework instead of manual clock handling (Loic)
- [3/3] Add Reviewed-by tag from Loic Poulain
- [3/2] Add Reviewed-by tag from Laurent Pinchart
- [3/1] Add Reviewed-by tag from Laurent Pinchart
- Link to v13: https://lore.kernel.org/r/[email protected]
Changes in v13:
- [2/3] Add Reviewed-by tag from Frank and Krzysztof
- [3/3] Add Reviewed-by tag from Frank
- [3/3] Replace pr_warn_once() with dev_warn() in csi_formatter_get_index_by_dt() to provide device context and warn on every occurrence (Loic)
- [3/3] Add WARN_ON() check for csi_formatter_find_format() return value in start/stop_stream functions to catch unexpected NULL (Loic)
- [3/3] Use regmap_set_bits()/regmap_clear_bits() instead of read-modify-write pattern and remove unused csi_formatter_read/write helper functions (Loic)
- Link to v12: https://lore.kernel.org/r/[email protected]
Changes in v12:
- Fix stream ID handling: iterate routing table instead of assuming
stream ID equals loop index (0-7)
- Remove stream_to_vc[] array: derive VC from routing table and frame descriptor on each start/stop operation
- Remove V4L2_SUBDEV_FL_HAS_EVENTS flag since driver does not generate events
- Support stream IDs 0-63 by using BIT_ULL() for stream masks
- Add get_frame_desc call in stop_stream with proper error handling
- Add csi_formatter_read() helper function for register reads
- Use read-modify-write for CSI_VC_PIXEL_DATA_TYPE register to support multiplexed streams sharing the same virtual channel
- Use route->sink_pad instead of hardcoded CSI_FORMATTER_PAD_SINK
- Write back coerced format in set_fmt before propagating to source stream
- Drop Frank's Reviewed-by tag due to significant changes, requesting re-review
- Link to v11: https://lore.kernel.org/r/[email protected]
Changes in v11:
- Drop [PATCH v10 1/4] dt-bindings: clock: imx95-blk-ctl: Use single quotes consistently (Krzysztof)
- Move properties to top-level and use if:then:else (Krzysztof/Frank)
- Link to v10: https://lore.kernel.org/r/[email protected]
Changes in v10:
- Rebase to latest media/next
- [NEW PATCH] Use single quotes consistently (Krzysztof Kozlowski)
- Drop syscon parent node from example
- Drop Reviewed-by tags from Frank and Krzysztof due to binding changes, requesting re-review
- Add description for reg property
- Add space after formatter@20 before opening brace in example
- Enhance the port description with more detailed information
- Delete the blank line immediately following the endpoint in example
- Use single quotes for regex pattern to be consistent (Krzysztof Kozlowski)
- Add formatter subnode binding and camera-csr syscon example
- Update commit title and message
- Use u8 for vc in csi_formatter_get_vc() and drop vc < 0 check
- Add MFD_SYSCON dependency to Kconfig
- Fix stream/VC mapping potential mismatch in start/stop_stream functions
- Link to v9: https://lore.kernel.org/r/[email protected]
Changes in v9:
- [NEW PATCH] Fix formatter as syscon child node issue
- Link to v8: https://lore.kernel.org/r/[email protected]
Changes in v8:
- Rebase to latest media/next
- Use standard port reference instead of video-interfaces.yaml
- Add parent syscon node in example to show device integration
- Remove fmt field and look up format from subdev state instead
- Unify function and structure naming to use csi_formatter_ prefix
- Remove misleading alignment comment from set_fmt function
- Optimize get_frame_desc to call once per start_stream
- Replace V4L2_FRAME_DESC_ENTRY_MAX with CSI_FORMATTER_VC_NUM in loops
- Remove redundant debug message in enable_streams
- Use MEDIA_PAD_FL_MUST_CONNECT flag instead of manual link check
- Link to v7: https://lore.kernel.org/r/[email protected]
Changes in v7:
- Change compatible to imx95-csi-formatter as IP is i.MX95 specific per Marco's suggestion
- Update references from imx9 to imx95 for consistency with dt-bindings
- Enable PM runtime before async registration
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- Rebase to latest media/next
- Update v4l2-compliace test
- Remove unused header includes
- Unify macro naming: VCx/VCX -> VC and parameter x -> vc
- Remove unused format field from csi_formatter struct
- Use compact initialization for formats array
- Make find_csi_format() return NULL instead of default format
- Use unsigned int for array index in find_csi_format()
- Add err_ prefix to error handling labels
- Add v4l2_subdev_cleanup() and reorder cleanup sequence
- Update enable_streams debug output format
- Rename VC_MAX to VC_NUM and fix boundary check
- Update CSI formatter Kconfig description
- Use v4l2_subdev_get_frame_desc_passthrough() helper
- Fix error paths in async registration and probe
- Add mutex to protect enabled_streams
- Switch to devm_pm_runtime_enable()
- Remove redundant num_routes check in set_routing
- Optimize get_index_by_dt() and add warning for unsupported type
- csi_formatter_start/stop_stream: Process all streams in mask
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Remove CSI_FORMATTER_DRV_NAME macro since only use once.
- Remove sd->owner = THIS_MODULE;
- Simplify code by using DEFINE_RUNTIME_DEV_PM_OPS macro.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Rebase to latest media/next.
- Add comments to describe the index field in formatter_dt_to_index_map array.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Rename nxp,imx9-csi-formatter.yaml to fsl,imx9-csi-formatter.yaml.
- Drop clock-names property.
- Drop macro IMX95_PD_CAMERA definition and use a constant directly. [PATCH 1/2] media: dt-bindings: Add CSI Pixel Formatter DT bindings
- Remove the assignment driver.owner = THIS_MODULE.
- Assign struct fwnode_handle *ep __free(fwnode_handle) when definition.
- Update yaml file name for csi formatter in MAINTAINERS.
[PATCH 2/2] media: nxp: Add i.MX9 CSI pixel formatter v4l2 driver
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Delete "|" for description key.
- Add empty line between child node and property.
- Delete labels for endpoint of child nodes.
[PATCH 1/2] media: dt-bindings: Add CSI Pixel Formatter DT bindings
- Update commit message.
- Use the value defined by bellow macros directly since they are used only once.
#define CSI_FORMATTER_DEF_MBUS_CODE MEDIA_BUS_FMT_UYVY8_1X16
#define CSI_FORMATTER_DEF_PIX_WIDTH 1920U
#define CSI_FORMATTER_DEF_PIX_HEIGHT 1080U
#define CSI_FORMATTER_MAX_PIX_WIDTH 0xffff
#define CSI_FORMATTER_MAX_PIX_HEIGHT 0xffff
- Use macro pm_ptr() to fix build warning when CONFIG_PM is disabled.
- Finish route loop by break statement, instead of goto.
- Return dev_err_probe() when meet errors in probe() function instead of dev_err().
- Remove MODULE_ALIAS().
- Refine .enable(.dsable)_stream callback implementation, include bellow changes:
Add stream checking.
Fix potential pm runtime count unbalance issue.
Add stop stream error handling when enabling remote subdev stream.
- Use __free(fwnode_handle) to drop reference to a device node automatically. [PATCH 2/2] media: nxp: Add i.MX9 CSI pixel formatter v4l2 driver
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Guoniu Zhou (3):
media: dt-bindings: Add CSI Pixel Formatter DT bindings
dt-bindings: clock: imx95-blk-ctl: Define formatter child node schema
media: nxp: Add i.MX95 CSI pixel formatter v4l2 driver
.../bindings/clock/nxp,imx95-blk-ctl.yaml | 71 ++ .../bindings/media/fsl,imx95-csi-formatter.yaml | 88 +++ MAINTAINERS | 8 + drivers/media/platform/nxp/Kconfig | 16 + drivers/media/platform/nxp/Makefile | 1 + drivers/media/platform/nxp/imx95-csi-formatter.c | 758 +++++++++++++++++++++ 6 files changed, 942 insertions(+)
---
base-commit: 06cb687a5132fcffe624c0070576ab852ac6b568
change-id: 20251125-csi_formatter-e6d29316dce6
Best regards,
Signature · 1 line
Guoniu Zhou <[email protected]>
PATCH v16 1/3 media: dt-bindings: Add CSI Pixel Formatter DT bindings
From: Guoniu Zhou <[email protected]>
The i.MX95 CSI pixel formatting module uses packet info, pixel and non-pixel data from the CSI-2 host controller and reformat them to match Pixel Link(PL) definition.
---
Changes in v14:
- Add Rb tag from Laurent pinchart
Changes in v11:
- Add Rb tags from Frank Li and Krzysztof Kozlowski
Changes in v10:
- Drop syscon parent node from example
- Drop Reviewed-by tags from Frank and Krzysztof due to binding changes
- Add description for reg property
- Add space after formatter@20 before opening brace in example
- Enhance the port description with more detailed information
- Delete the blank line immediately following the endpoint in example
Changes in v9:
- Use direct node instead of syscon wrapper in example
Changes in v8:
- Use standard port reference instead of video-interfaces.yaml
- Add parent syscon node in example to show device integration
- Add required constraints for port@0 and port@1 in ports node
Changes in v7:
- Change compatible to imx95-csi-formatter as IP is i.MX95 specific per Marco's suggestion
--- .../bindings/media/fsl,imx95-csi-formatter.yaml | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+)
Documentation/devicetree/bindings/media/fsl,imx95-csi-formatter.yaml new file +88 -0
@@ -0,0 +1,88 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/fsl,imx95-csi-formatter.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: i.MX95 CSI Pixel Formatter + +maintainers: + - Guoniu Zhou <[email protected]> + +description: + The CSI pixel formatting module found on i.MX95 uses packet info, pixel + and non-pixel data from the CSI-2 host controller and reformat them to + match Pixel Link(PL) definition. + +properties: + compatible: + const: fsl,imx95-csi-formatter + + reg: + maxItems: 1 + description: Register offset and size within the parent syscon + + clocks: + maxItems: 1 + + power-domains: + maxItems: 1 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: + Input port, connects to MIPI CSI-2 receiver output (IDI interface) + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + Output port, connects to ISI input via Pixel Link (PL) + + required: + - port@0 + - port@1 + +required: + - compatible + - reg + - clocks + - power-domains + - ports + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/nxp,imx95-clock.h> + + formatter@20 { + compatible = "fsl,imx95-csi-formatter"; + reg = <0x20 0x100>; + clocks = <&cameramix_csr IMX95_CLK_CAMBLK_CSI2_FOR0>; + power-domains = <&scmi_devpd 3>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + endpoint { + remote-endpoint = <&mipi_csi_0_out>; + }; + }; + + port@1 { + reg = <1>; + + endpoint { + remote-endpoint = <&isi_in_2>; + }; + }; + }; + };
Signature · 1 line
2.34.1
PATCH v16 2/3 dt-bindings: clock: imx95-blk-ctl: Define formatter child node schema
In reply to [email protected]From: Guoniu Zhou <[email protected]>
The Camera CSR contains control registers for multiple CSI formatter IPs at different register offsets. Each formatter is an independent hardware block with its own clock input and media pipeline connection.
Define schema to allow formatter child nodes under nxp,imx95-camera-csr, with 'reg' property specifying the formatter's register offset within the CSR address space.
---
Changes in v14:
- Add Reviewed-by tag from Laurent Pinchart
Changes in v13:
- Add Reviewed-by tag from Frank and Krzysztof
Changes in v11:
- Move properties to top-level and use if:then:else (Krzysztof/Frank)
Changes in v10:
- Use single quotes for regex pattern to be consistent (Krzysztof Kozlowski)
- Add formatter subnode binding and camera-csr syscon example
- Update commit title and message
Changes in v9:
- New patch to address the issue of formatter acting as a child node of syscon
--- .../bindings/clock/nxp,imx95-blk-ctl.yaml | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+)
Documentation/devicetree/bindings/clock/nxp,imx95-blk-ctl.yaml +71 -0
@@ -39,6 +39,18 @@ properties: ID in its "clocks" phandle cell. See include/dt-bindings/clock/nxp,imx95-clock.h + '#address-cells': + const: 1 + + '#size-cells': + const: 1 + +patternProperties: + '^formatter@[0-9a-f]+$': + type: object + $ref: /schemas/media/fsl,imx95-csi-formatter.yaml# + unevaluatedProperties: false + required: - compatible - reg
@@ -46,6 +58,23 @@ required: - power-domains - clocks +allOf: + - if: + properties: + compatible: + contains: + const: nxp,imx95-camera-csr + then: + required: + - '#address-cells' + - '#size-cells' + else: + properties: + '#address-cells': false + '#size-cells': false + patternProperties: + '^formatter@[0-9a-f]+$': false + additionalProperties: false examples:
@@ -57,4 +86,46 @@ examples: clocks = <&scmi_clk 114>; power-domains = <&scmi_devpd 21>; }; + + - | + #include <dt-bindings/clock/nxp,imx95-clock.h> + + syscon@4ac10000 { + compatible = "nxp,imx95-camera-csr", "syscon"; + reg = <0x4ac10000 0x10000>; + #address-cells = <1>; + #size-cells = <1>; + #clock-cells = <1>; + clocks = <&scmi_clk 62>; + power-domains = <&scmi_devpd 3>; + + formatter@20 { + compatible = "fsl,imx95-csi-formatter"; + reg = <0x20 0x100>; + clocks = <&cameramix_csr IMX95_CLK_CAMBLK_CSI2_FOR0>; + power-domains = <&scmi_devpd 3>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + endpoint { + remote-endpoint = <&mipi_csi_0_out>; + }; + + }; + + port@1 { + reg = <1>; + + endpoint { + remote-endpoint = <&isi_in_2>; + }; + }; + }; + }; + }; ...
Signature · 1 line
2.34.1
Re: [PATCH v16 2/3] dt-bindings: clock: imx95-blk-ctl: Define formatter child node schema
Quoted 6 lines · On 26-07-28 14:14:15, [email protected] wrote:
From: Guoniu Zhou <[email protected]>
The Camera CSR contains control registers for multiple CSI formatter IPs at different register offsets. Each formatter is an independent hardware block with its own clock input and media pipeline connection.
Quoted 8 lines
Define schema to allow formatter child nodes under nxp,imx95-camera-csr, with 'reg' property specifying the formatter's register offset within the CSR address space.
Signed-off-by Guoniu Zhou <[email protected]>Reviewed-by Frank Li <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>
Mauro, please let me know if you want to take this through your tree.
PATCH v16 3/3 media: nxp: Add i.MX95 CSI pixel formatter v4l2 driver
In reply to [email protected]From: Guoniu Zhou <[email protected]>
The CSI pixel formatter is a module found on i.MX95 used to reformat packet info, pixel and non-pixel data from CSI-2 host controller to match Pixel Link(PL) definition.
Add data formatting support.
---
Changes in v16:
- Use depends on PM_CLK instead of select PM_CLK to avoid Kconfig warnings when building with COMPILE_TEST without PM enabled (Sashiko)
- Add err_pm_disable label and call pm_runtime_dont_use_autosuspend() on csi_formatter_async_register() failure to fix PM state leak (Sashiko)
- Add pm_runtime_dont_use_autosuspend() and pm_runtime_suspend() in remove to ensure clocks are disabled when driver is unbound (Sashiko)
Changes in v15:
- Add pm_runtime_dont_use_autosuspend() on devm_pm_runtime_enable() failure (Laurent)
- Extract csi_formatter_get_frame_desc() helper for start/stop_stream (Laurent)
- Use dev_WARN() instead of dev_warn() + WARN_ON(1) (Laurent)
- Use pm_runtime_put_autosuspend() instead of pm_runtime_put() (Laurent)
- Add Reviewed-by tag from Laurent
Changes in v14:
- Use select MFD_SYSCON instead of depends on MFD_SYSCON (Laurent)
- Remove unused v4l2-ctrls.h and v4l2-event.h includes (Laurent)
- Rename csi_sd to remote_sd and group with remote_pad (Laurent)
- Move reg_offset after clk to group generic resources (Laurent)
- Remove mutex lock as enable/disable_streams hold state lock (Laurent)
- Rename formatter_dt_to_index_map to csi_formatter_dt_to_index_map (Laurent)
- Rename formats to csi_formatter_formats (Laurent)
- Declare loop variables in for-loop and add braces (Laurent)
- Simplify set_fmt, rename sdformat to format, drop NULL check (Laurent)
- Set field to V4L2_FIELD_NONE as interlaced not yet supported (Laurent)
- Add streaming check in set_fmt to match set_routing (Laurent)
- Add WARN_ON for unsupported data type as it indicates driver bug (Laurent)
- Return -EPIPE instead of -EINVAL for invalid VC (Laurent)
- Refactor ENOIOCTLCMD handling and remove redundant pad check (Laurent)
- Use strscpy instead of snprintf for sd->name (Laurent)
- Remove redundant dev_dbg in notify_bound (Laurent)
- Simplify remote_pad assignment and drop NULL check (Laurent)
- Read reg property directly into formatter->reg_offset (Laurent)
- Store formatter pointer in drvdata to avoid sd_to_formatter calls (Laurent)
- Enable runtime PM autosuspend with 1s delay (Laurent)
- Use PM clock framework instead of manual clock handling (Loic)
- Add Reviewed-by tag from Loic Poulain
Changes in v13:
- Replace pr_warn_once() with dev_warn() in csi_formatter_get_index_by_dt() to provide device context and warn on every occurrence (Loic)
- Add WARN_ON() check for csi_formatter_find_format() return value in start/stop_stream functions to catch unexpected NULL (Loic)
- Use regmap_set_bits()/regmap_clear_bits() instead of read-modify-write pattern and remove unused csi_formatter_read/write helper functions (Loic)
- Add Reviewed-by tag from Frank Li
Changes in v12:
- Fix stream ID handling: iterate routing table instead of assuming stream ID equals loop index (0-7)
- Remove stream_to_vc[] array: derive VC from routing table and frame descriptor on each start/stop operation
- Remove V4L2_SUBDEV_FL_HAS_EVENTS flag since driver does not generate events
- Support stream IDs 0-63 by using BIT_ULL() for stream masks
- Add get_frame_desc call in stop_stream with proper error handling
- Add csi_formatter_read() helper function for register reads
- Use read-modify-write for CSI_VC_PIXEL_DATA_TYPE register to support multiplexed streams sharing the same virtual channel
- Use route->sink_pad instead of hardcoded CSI_FORMATTER_PAD_SINK
- Write back coerced format in set_fmt before propagating to source stream
- Drop Frank's Reviewed-by tag due to significant changes, requesting re-review
Changes in v10:
- Use u8 for vc in csi_formatter_get_vc() and drop vc < 0 check
- Add MFD_SYSCON dependency to Kconfig
- Fix stream/VC mapping potential mismatch in start_stop_stream functions
Changes in v8:
- Remove fmt field and look up format from subdev state instead
- Unify function and structure naming to use csi_formatter_ prefix
- Remove misleading alignment comment from set_fmt function
- Optimize get_frame_desc to call once per start_stream
- Replace V4L2_FRAME_DESC_ENTRY_MAX with CSI_FORMATTER_VC_NUM in loops
- Remove redundant debug message in enable_streams
- Use MEDIA_PAD_FL_MUST_CONNECT flag instead of manual link check
- Fix typo: Formater -> Formatter in Kconfig help text
- Improve grammar in data type index mapping comment
Changes in v7:
- Update references from imx9 to imx95 for consistency with dt-bindings
- Enable PM runtime before async registration
Changes in v6:
- Remove unused header includes
- Unify macro naming: VCx/VCX -> VC and parameter x -> vc
- Remove unused format field from csi_formatter struct
- Use compact initialization for formats array
- Make find_csi_format() return NULL instead of default format
- Use unsigned int for array index in find_csi_format()
- Add err_ prefix to error handling labels
- Add v4l2_subdev_cleanup() and reorder cleanup sequence
- Update enable_streams debug output format
- Rename VC_MAX to VC_NUM and fix boundary check
- Update CSI formatter Kconfig description
- Use v4l2_subdev_get_frame_desc_passthrough() helper
- Fix error paths in async registration and probe
- Add mutex to protect enabled_streams
- Switch to devm_pm_runtime_enable()
- Remove redundant num_routes check in set_routing
- Optimize get_index_by_dt() and add warning for unsupported type
- csi_formatter_start/stop_stream: Process all streams in mask
--- MAINTAINERS | 8 + drivers/media/platform/nxp/Kconfig | 16 + drivers/media/platform/nxp/Makefile | 1 + drivers/media/platform/nxp/imx95-csi-formatter.c | 758 +++++++++++++++++++++++ 4 files changed, 783 insertions(+)
MAINTAINERS +8 -0
@@ -19275,6 +19275,14 @@ S: Maintained F: Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml F: drivers/media/platform/nxp/imx-jpeg +NXP i.MX 95 CSI PIXEL FORMATTER V4L2 DRIVER +M: Guoniu Zhou <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/media/fsl,imx95-csi-formatter.yaml +F: drivers/media/platform/nxp/imx95-csi-formatter.c + NXP i.MX CLOCK DRIVERS M: Abel Vesa <[email protected]> R: Peng Fan <[email protected]>
drivers/media/platform/nxp/Kconfig +16 -0
@@ -28,6 +28,22 @@ config VIDEO_IMX8MQ_MIPI_CSI2 Video4Linux2 driver for the MIPI CSI-2 receiver found on the i.MX8MQ SoC. +config VIDEO_IMX95_CSI_FORMATTER + tristate "NXP i.MX95 CSI Pixel Formatter driver" + depends on ARCH_MXC || COMPILE_TEST + depends on PM_CLK + depends on VIDEO_DEV + select MEDIA_CONTROLLER + select MFD_SYSCON + select V4L2_FWNODE + select VIDEO_V4L2_SUBDEV_API + help + This driver provides support for the CSI Pixel Formatter found on + i.MX95 series SoCs. This module unpacks the pixels received from the + CSI-2 interface and reformats them to meet pixel link requirements. + + Say Y here to enable CSI Pixel Formatter module for i.MX95 SoC. + config VIDEO_IMX_MIPI_CSIS tristate "NXP MIPI CSI-2 CSIS receiver found on i.MX7 and i.MX8 models" depends on ARCH_MXC || COMPILE_TEST
drivers/media/platform/nxp/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-y += imx8-isi/ obj-$(CONFIG_VIDEO_IMX7_CSI) += imx7-media-csi.o obj-$(CONFIG_VIDEO_IMX8MQ_MIPI_CSI2) += imx8mq-mipi-csi2.o +obj-$(CONFIG_VIDEO_IMX95_CSI_FORMATTER) += imx95-csi-formatter.o obj-$(CONFIG_VIDEO_IMX_MIPI_CSIS) += imx-mipi-csis.o obj-$(CONFIG_VIDEO_IMX_PXP) += imx-pxp.o obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o
drivers/media/platform/nxp/imx95-csi-formatter.c new file +758 -0
758 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v16 3/3] media: nxp: Add i.MX95 CSI pixel formatter v4l2 driver
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] Missing NULL check for `media_pad_remote_pad_first()` result can cause kernel panic. - [High]…
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Missing NULL check for media_pad_remote_pad_first() result can cause kernel panic.
- [High] Unchecked dereference of v4l2_subdev_state_get_opposite_stream_format() in csi_formatter_subdev_set_fmt() for inactive routes.
- [High] Dangling remote_sd pointer leading to Use-After-Free if remote subdevice is unbound.
- [High] Contradictory routing restriction blocks multiplexing support.
- [Medium] Mixing __free() scope-based cleanup with goto-based error handling in the same function.
- [Medium] csi_formatter_stop_stream() silently bails out on get_frame_desc failure, leaving hardware streams enabled.
- [Medium] Missing pm_runtime_mark_last_busy() causes immediate autosuspend instead of respecting the configured delay. --
--- Patch [3]: [PATCH v16 3/3] media: nxp: Add i.MX95 CSI pixel formatter v4l2 driver --- commit b8f475efe55d7eb6b5ee1f2f2cd145ec93b5b430
Author: Guoniu Zhou <[email protected]>
Subject: media: nxp: Add i.MX95 CSI pixel formatter v4l2 driver
This commit adds a V4L2 driver for the CSI pixel formatter found on i.MX95 SoCs. It provides data formatting support to unpack pixels from the CSI-2 host controller to match Pixel Link definitions.
Quoted 6 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +0
-0@@ -0,0 +1,758 @@
[ ... ]
drivers/media/platform/nxp/imx95-csi-formatter.c line 182
Quoted 8 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +8
-0+static int __csi_formatter_subdev_set_routing (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +struct v4l2_subdev_krouting *routing) +{ +int ret; + + ret =v4l2_subdev_routing_validate (sd, routing, +V4L2_SUBDEV_ROUTING_ONLY_1_TO_1 );
[Severity: High]
Does this routing restriction block the multiplexing support implemented elsewhere in the driver?
The V4L2_SUBDEV_ROUTING_ONLY_1_TO_1 macro includes V4L2_SUBDEV_ROUTING_NO_MULTIPLEXING, which causes the V4L2 core to reject any configuration with multiple streams on the same sink pad. This appears to prevent the multiplexing functionality that the hardware virtual channel handling was designed to support.
Quoted 6 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +6
-0+if (ret) +return ret; + +return v4l2_subdev_set_routing_with_fmt (sd, state, routing, + &formatter_default_fmt); +}
[ ... ]
Quoted 4 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +4
-0+static int csi_formatter_subdev_set_fmt (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *format) +{
[ ... ]
drivers/media/platform/nxp/imx95-csi-formatter.c line 264
Quoted 4 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +4
-0+/* Propagate the format from sink stream to source stream */ + fmt =v4l2_subdev_state_get_opposite_stream_format (sd_state, format->pad, + format->stream); + *fmt = format->format;
[Severity: High]
Could this result in a null pointer regression if the stream route is inactive?
When an inactive routing entry is configured (without V4L2_SUBDEV_ROUTE_FL_ACTIVE) and a format is set on its sink pad, the validation passes because a stream configuration exists. However, v4l2_subdev_state_get_opposite_stream_format() skips inactive routes and returns a null pointer.
Would it be safer to verify fmt is not null before assigning to it?
Quoted 3 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +3
-0+ +return 0 ; +}
[ ... ]
Quoted 4 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +4
-0+static void csi_formatter_stop_stream (struct csi_formatter *formatter, +struct v4l2_subdev_state *state, +u64 stream_mask) +{
[ ... ]
drivers/media/platform/nxp/imx95-csi-formatter.c line 368
Quoted 3 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +3
-0+ ret =csi_formatter_get_frame_desc (formatter, &fd); +if (ret) +return ;
[Severity: Medium]
Could this early return leave hardware streams enabled if getting the frame descriptor fails?
This silently bails out without clearing the hardware registers, which might leak the active stream state in the hardware and affect subsequent operations.
Quoted 2 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +2
-0+ +for_each_active_route (&state->routing, route) {
[ ... ]
Quoted 4 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +4
-0+static int csi_formatter_subdev_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +u32 pad,u64 streams_mask) +{
[ ... ]
drivers/media/platform/nxp/imx95-csi-formatter.c line 490
Quoted 5 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +5
-0+err_stop_stream: +csi_formatter_stop_stream (formatter, state, streams_mask); +err_runtime_put: +if (!formatter->enabled_streams) +pm_runtime_put_autosuspend (formatter->dev);
[Severity: Medium]
Should pm_runtime_mark_last_busy() be called here before putting the device into autosuspend?
Without updating the last-busy timestamp, the PM core uses the elapsed time since the device was last marked busy. If this time exceeds the 1-second delay, the device may suspend immediately, bypassing the intended autosuspend delay.
Quoted 10 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +10
-0+return ret; +} + +static int csi_formatter_subdev_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +u32 pad,u64 streams_mask) +{ +struct csi_formatter *formatter =sd_to_formatter (sd); +u64 sink_streams; +int ret;
drivers/media/platform/nxp/imx95-csi-formatter.c line 510
Quoted 10 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +10
-0+ + sink_streams =v4l2_subdev_state_xlate_streams (state, +CSI_FORMATTER_PAD_SOURCE , +CSI_FORMATTER_PAD_SINK , + &streams_mask); +if (!sink_streams || !streams_mask) +return -EINVAL ; + + ret =v4l2_subdev_disable_streams (formatter->remote_sd, formatter->remote_pad, + sink_streams);
[Severity: Medium]
Is it intentional to disable the remote subdevice before stopping the local stream?
If the remote subdevice is disabled first, it might power down or refuse queries, which could cause csi_formatter_get_frame_desc() to fail when csi_formatter_stop_stream() is called shortly after.
drivers/media/platform/nxp/imx95-csi-formatter.c line 519
Quoted 9 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +9
-0+if (ret) +dev_err (formatter->dev,"Failed to disable streams: %d\n" , ret); + +csi_formatter_stop_stream (formatter, state, streams_mask); + + formatter->enabled_streams &= ~streams_mask; + +if (!formatter->enabled_streams) +pm_runtime_put_autosuspend (formatter->dev);
[Severity: Medium]
Similar to the error path in enable_streams, is a pm_runtime_mark_last_busy() call needed here to ensure the 1-second autosuspend delay is respected?
Quoted 3 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +3
-0+ +return ret; +}
[ ... ]
Quoted 8 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +8
-0+static int csi_formatter_notify_bound (struct v4l2_async_notifier *notifier, +struct v4l2_subdev *sd, +struct v4l2_async_connection *asc) +{ +const unsigned int link_flags =MEDIA_LNK_FL_IMMUTABLE + |MEDIA_LNK_FL_ENABLED ; +struct csi_formatter *formatter =notifier_to_csi_formatter (notifier); +struct v4l2_subdev *sdev = &formatter->sd;
drivers/media/platform/nxp/imx95-csi-formatter.c line 608
Quoted 10 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +10
-0+struct media_pad *sink = &sdev->entity.pads[CSI_FORMATTER_PAD_SINK ]; +int ret; + + formatter->remote_sd = sd; + + ret =v4l2_create_fwnode_links_to_pad (sd, sink, link_flags); +if (ret <0 ) +return ret; + + formatter->remote_pad =media_pad_remote_pad_first (sink)->index;
[Severity: High]
Could this cause a null pointer regression if the remote pad is not found?
If v4l2_create_fwnode_links_to_pad() returns 0 without creating any links (which can happen if the source subdevice has no matching endpoints in the device tree), media_pad_remote_pad_first() will return null. Dereferencing it immediately would cause a crash during initialization.
drivers/media/platform/nxp/imx95-csi-formatter.c line 615
Quoted 7 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +7
-0+ +return 0 ; +} + +static const struct v4l2_async_notifier_operations formatter_notify_ops = { + .bound = csi_formatter_notify_bound, +};
[Severity: High]
Is an unbind callback needed to clear the remote_sd pointer?
The driver caches the remote subdevice pointer in formatter->remote_sd when bound. If the remote subdevice is unregistered, the pointer becomes dangling. If csi_formatter_subdev_disable_streams() is subsequently called, it passes the freed pointer to v4l2_subdev_disable_streams(), resulting in a use-after-free.
Quoted 10 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +10
-0+ +static int csi_formatter_async_register (struct csi_formatter *formatter) +{ +struct device *dev = formatter->dev; +struct v4l2_async_connection *asc; +int ret; + + struct fwnode_handle *ep __free(fwnode_handle) = +fwnode_graph_get_endpoint_by_id (dev_fwnode (dev),0 ,0 , +FWNODE_GRAPH_ENDPOINT_NEXT );
drivers/media/platform/nxp/imx95-csi-formatter.c line 635
Quoted 10 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +10
-0+if (!ep) +return -ENOTCONN ; + +v4l2_async_subdev_nf_init (&formatter->notifier, &formatter->sd); + + asc =v4l2_async_nf_add_fwnode_remote (&formatter->notifier, ep, + struct v4l2_async_connection); +if (IS_ERR (asc)) { + ret =PTR_ERR (asc); + goto err_cleanup_notifier;
[Severity: Medium]
Is it safe to mix __free() scope-based cleanup with goto-based error handling in this function?
According to the cleanup subsystem guidelines (include/linux/cleanup.h), mixing __free() declarations with goto-based error handling in the same function is prohibited as it creates confusing ownership semantics.
Would it be better to convert the remaining cleanups to scope-based helpers or avoid using __free() here?
Quoted 20 lines
drivers/media/platform/nxp/imx95-csi-formatter.c new file +20
-0+ } + + formatter->notifier.ops = &formatter_notify_ops; + + ret =v4l2_async_nf_register (&formatter->notifier); +if (ret) + goto err_cleanup_notifier; + + ret =v4l2_async_register_subdev (&formatter->sd); +if (ret) + goto err_unregister_notifier; + +return 0 ; + +err_unregister_notifier: +v4l2_async_nf_unregister (&formatter->notifier); +err_cleanup_notifier: +v4l2_async_nf_cleanup (&formatter->notifier); +return ret; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AppliedFrom: Frank Li <[email protected]>
Quoted 6 lines · On Tue, 28 Jul 2026 14:14:13 +0800, [email protected] wrote:
CSI Pixel Formatter is a module found on i.MX95. It could unpack the pixels received by the formatter and reformat them to meet the pixel link format requirement.
This patch series adds a new V4L2 driver for CSI Pixel Formatter.
Quoted 8 lines
Background
----------
The Camera CSR binding was upstreamed during the pre-silicon phase when the hardware integration details were not fully finalized. At that time, the syscon binding focused on the CSR's primary role as a shared register provider for clock gating, QoS, and error handling across Camera domain IPs.[...]
Applied, thanks!
[1/3] media: dt-bindings: Add CSI Pixel Formatter DT bindings
commit: c0af539f5c2841f0756f8ae98808e1eafe4538af
[2/3] dt-bindings: clock: imx95-blk-ctl: Define formatter child node schema
commit: c6cc72164123f777933b0d3453fa3e3ad283e223
[3/3] media: nxp: Add i.MX95 CSI pixel formatter v4l2 driver
commit: cc29462f4d0723502feff17ff1758c690c5fce4dBest regards,
Signature · 1 line
Frank Li <[email protected]>