Skip to contentSkip to conversation

media: i2c: Add onsemi AR0234 camera sensor driver

PATCH In review Alexander Shiyan 4 participants 14 messages Aug 20 – Sep 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover media: i2c: Add onsemi AR0234 camera sensor driver

This series adds a driver for the onsemi AR0234 CMOS image sensor. The AR0234 is a 1/2.6-inch global-shutter sensor with a 1940x1220 pixel array, capable of 1920x1200 resolution at up to 120 fps. It supports MIPI CSI-2 output with 1 to 4 data lanes, raw Bayer (8/10-bit) and monochrome formats, as well as DPCM 10->8 compression.

The driver has been tested with 2 and 4 lanes on an ARM64 Rockchip RK3588 platform with a 27 MHz external clock. Both 8-bit and 10-bit raw Bayer modes are functional.

Notes:
- 1-lane mode is currently disabled; attempts to use it produced no valid image.

[root@diasom-evb ~]# v4l2-compliance -u 2
v4l2-compliance 1.28.1, 64 bits, 64-bit time_t

Compliance test for device /dev/v4l-subdev2:

Driver Info:
ar0234 9-0018: ================= START STATUS ================= ar0234 9-0018: ================== END STATUS ==================

        Driver version   : 7.1.0
        Capabilities     : 0x00000000
        Client Capabilities: 0x0000000000000002

interval-uses-which
Required ioctls:
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev2 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)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 20 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-subdev2: 45, Succeeded: 45, Failed: 0, Warnings: 0

V1 -> V2:
- Fixed bugs reported by sashiko-bot:
- [Low] The compatible property schema contains fatal YAML syntax errors due to missing list hyphens (-), resulting in invalid JSON schema constructs that will fail dt_binding_check.
- [Low] The data-lanes schema constraint mathematically allows 3 lanes, which contradicts the explicit 2-or-4 lane hardware requirement described in the binding.
- [Critical] Incorrect clamping order in crop selection bounds calculation causes unsigned integer underflow, bypassing bounds checks.
- [High] Incorrect validation of pm_runtime_get_if_active() allows execution to proceed on negative error codes, leading to a usage counter underflow.
- [High] Static hblank lower bounds permit dynamic line length reduction below the absolute hardware minimum.
- [High] Potential division by zero during delay calculation if the clock rate is zero.
- [Medium] Unlocked V4L2 control helpers are called during initialization without acquiring the control handler lock, triggering a lockdep splat.
- [Medium] Mixing goto-based error handling with scope-based __free() cleanup in the same function violates API guidelines.
- [Medium] Changing the crop height fails to update exposure control limits reliably.
- [Medium] The active format state is modified before verifying PLL configuration, leaving state inconsistent on error.
- [Medium] Unlocked access to shared format state in ar0234_get_frame_desc.
- [Low] Using DIV_ROUND_UP with a 64-bit numerator causes a link error on 32-bit architectures.

V2 -> V3:
- Fixed bugs reported by sashiko-bot:
- [Low] Standard properties 'orientation' and 'rotation' bypass standard type validation.
- [High] Incorrect initialization order of the V4L2 active state and control handler breaks lock sharing, causing lockdep splats, data races, and masking a self-deadlock in ar0234_set_pad_format().
- [High] Brittle and restrictive parsing of the 'link-frequencies' device tree property.
- [High] Invalid rectangle clamping logic in ar0234_set_selection() allows crop width and height to underflow their minimum limits.
- [High] Incorrect power-down sequence disables regulators before stopping the external clock.
- [Medium] Unchecked return value from v4l2_subdev_state_get_format() in ar0234_get_frame_desc() may cause a NULL pointer dereference.
- [Medium] Unconditional overwrite of the VBLANK control value upon format or crop changes.
- [Medium] Missing media_entity_cleanup() in the subdevice cleanup routine causes media graph objects to leak upon removal.

Alexander Shiyan (2):
dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding
media: i2c: Add onsemi AR0234 image sensor driver

 .../bindings/media/i2c/onnn,ar0234.yaml       |  121 ++
 drivers/media/i2c/Kconfig                     |   12 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/ar0234.c                    | 1294 +++++++++++++++++
 4 files changed, 1428 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
 create mode 100644 drivers/media/i2c/ar0234.c
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/2 dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---
 .../bindings/media/i2c/onnn,ar0234.yaml       | 121 ++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +121 -0
new file mode 100644
index 000000000000..ee321acf22b5
@@ -0,0 +1,121 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/onnn,ar0234.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ON Semiconductor AR0234 1/2.6-inch CMOS Digital Image Sensor
+
+maintainers:
+  - Alexander Shiyan <[email protected]>
+
+description:
+  The AR0234 is a 1/2.6-inch CMOS digital image sensor with a pixel
+  array of 1940x1220 pixels, capable of 1920x1200 resolution at up
+  to 120 fps. It supports MIPI CSI-2 output with 2 or 4 data lanes,
+  color raw Bayer (8/10-bit) or monochrome output.
+
+allOf:
+- $ref: /schemas/media/video-interface-devices.yaml#
+
+properties:
+  compatible:
+    enum:
+      - onnn,ar0234cssc
+      - onnn,ar0234cssm
+      - onnn,ar0234cs
+    description:
+      The AR0234 sensor exists in two different models, a colour variant
+      (AR0234CSSC) and a monochrome variant (AR0234CSSM). The device exposes
+      the model through registers, allowing for auto-detection with a common
+      "onnn,ar0234cs" compatible string.
+
+  reg:
+    description: I2C device address
+    maxItems: 1
+
+  clocks:
+    description: Reference clock (external clock) input
+    maxItems: 1
+
+  reset-gpios:
+    description: Reset pin, usually active low (if needed)
+    maxItems: 1
+
+  vaa-supply:
+    description: Analog (2.8V) supply regulator
+
+  vdd-supply:
+    description: Digital Core (1.2V) supply regulator
+
+  vddio-supply:
+    description: I/O (1.8V-2.8V) supply regulator
+
+  port:
+    $ref: /schemas/graph.yaml#/$defs/port-base
+    description: CSI-2 transmitter port
+    additionalProperties: false
+
+    properties:
+      endpoint:
+        $ref: /schemas/media/video-interfaces.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          data-lanes:
+            oneOf:
+              - items:
+                  - const: 1
+                  - const: 2
+              - items:
+                  - const: 1
+                  - const: 2
+                  - const: 3
+                  - const: 4
+
+          link-frequencies: true
+
+        required:
+          - data-lanes
+          - link-frequencies
+
+    required:
+      - endpoint
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        camera@18 {
+            compatible = "onnn,ar0234cs";
+            reg = <0x18>;
+            pinctrl-names = "default";
+            pinctrl-0 = <&pinctrl_cam>;
+            clocks = <&clk27m>;
+            vaa-supply = <&reg_cam_vaa>;
+            vdd-supply = <&reg_cam_vdd>;
+            vddio-supply = <&reg_cam_vddio>;
+            reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
+
+            port {
+                ar0234_out: endpoint {
+                    data-lanes = <1 2 3 4>;
+                    link-frequencies = /bits/ 64 <360000000 450000000>;
+                    remote-endpoint = <&ar0234_in>;
+                };
+            };
+        };
+    };
+...
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The dt-binding schema uses `additionalProperties: false` at the top level alongside an `$ref` to…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The dt-binding schema uses additionalProperties: false at the top level alongside an $ref to video-interface-devices.yaml, which incorrectly rejects standard video interface properties.
- [Low] The hardware power supplies (vaa-supply, vdd-supply, vddio-supply) are omitted from the required list.
--

--- Patch [1]: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding --- commit 9f105de6fb0990c272e7a588c7c4aea9fe0b6566
Author: Alexander Shiyan <[email protected]>

dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

This commit adds the devicetree binding schema for the onsemi AR0234 CMOS image sensor. It defines properties for clocks, supplies, reset GPIOs, and the CSI-2 transmitter port.

Quoted 6 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +0 -0
new file mode 100644
index 0000000000000..ee321acf22b59
@@ -0,0 +1,121 @@

[ ... ]

Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +4 -0
+allOf:
+- $ref: /schemas/media/video-interface-devices.yaml#
+
+properties:

[ ... ]

Quoted 8 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +8 -0
+  vaa-supply:
+    description: Analog (2.8V) supply regulator
+
+  vdd-supply:
+    description: Digital Core (1.2V) supply regulator
+
+  vddio-supply:
+    description: I/O (1.8V-2.8V) supply regulator

[ ... ]

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 89

Quoted 5 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +5 -0
+required:
+  - compatible
+  - reg
+  - clocks
+  - port

[Severity: Low]
Should the hardware power supplies (vaa-supply, vdd-supply, vddio-supply) be included in this required list to ensure the physical power routing is fully described in the device tree?

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml

Quoted 2 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +2 -0
+
+additionalProperties: false

[Severity: Medium]
Since this schema uses an allOf $ref to video-interface-devices.yaml, will using additionalProperties: false incorrectly reject standard properties inherited from that schema? Should this be changed to
unevaluatedProperties: false?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

In reply to Alexander Shiyan
Quoted 8 lines · Alexander Shiyan

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---
 .../bindings/media/i2c/onnn,ar0234.yaml       | 121 ++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml

Unanswered Sashiko comments.

Quoted 27 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +21 -0
new file mode 100644
index 000000000000..ee321acf22b5
@@ -0,0 +1,121 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/onnn,ar0234.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ON Semiconductor AR0234 1/2.6-inch CMOS Digital Image Sensor
+
+maintainers:
+  - Alexander Shiyan <[email protected]>
+
+description:
+  The AR0234 is a 1/2.6-inch CMOS digital image sensor with a pixel
+  array of 1940x1220 pixels, capable of 1920x1200 resolution at up
+  to 120 fps. It supports MIPI CSI-2 output with 2 or 4 data lanes,
+  color raw Bayer (8/10-bit) or monochrome output.
+
+allOf:
+- $ref: /schemas/media/video-interface-devices.yaml#
+
+properties:

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +10 -0
+  compatible:
+    enum:
+      - onnn,ar0234cssc
+      - onnn,ar0234cssm
+      - onnn,ar0234cs
+    description:
+      The AR0234 sensor exists in two different models, a colour variant
+      (AR0234CSSC) and a monochrome variant (AR0234CSSM). The device exposes
+      the model through registers, allowing for auto-detection with a common
+      "onnn,ar0234cs" compatible string.

So all devices are compatible? Then why compatibility is not expressed? What are the actual programming differences between sc, sm and "none" variants?

...

Quoted 16 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +16 -0
+  vddio-supply:
+    description: I/O (1.8V-2.8V) supply regulator
+
+  port:
+    $ref: /schemas/graph.yaml#/$defs/port-base
+    description: CSI-2 transmitter port
+    additionalProperties: false
+
+    properties:
+      endpoint:
+        $ref: /schemas/media/video-interfaces.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          data-lanes:
+            oneOf:

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 76

Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +10 -0
+              - items:
+                  - const: 1
+                  - const: 2
+              - items:
+                  - const: 1
+                  - const: 2
+                  - const: 3
+                  - const: 4
+
+          link-frequencies: true

Drop

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Hello.

Quoted 9 lines · Alexander Shiyan
Quoted 6 lines

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---
 .../bindings/media/i2c/onnn,ar0234.yaml       | 121 ++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml

Unanswered Sashiko comments.

I do not understand this remark.
The corrections based on sashiko-bot's feedback are included in the cover letter.
Is something wrong?

Quoted 1 line
Quoted 1 line
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +0 -0

...

Quoted 12 lines

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 31

Quoted 11 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +11 -0
+properties:
+  compatible:
+    enum:
+      - onnn,ar0234cssc
+      - onnn,ar0234cssm
+      - onnn,ar0234cs
+    description:
+      The AR0234 sensor exists in two different models, a colour variant
+      (AR0234CSSC) and a monochrome variant (AR0234CSSM). The device exposes
+      the model through registers, allowing for auto-detection with a common
+      "onnn,ar0234cs" compatible string.
Quoted 3 lines

So all devices are compatible? Then why compatibility is not expressed? What are the actual programming differences between sc, sm and "none" variants?

Perhaps I need to revert to the compatibility strings that were used in version 2
(https://patchwork.kernel.org/project/linux-media/patch/[email protected]/).

From a programming standpoint, it makes almost no difference which sensor is used
- the only differences are in the output format and the format count. Either way, the driver always uses the sensor model determined via register reads.
If the specified type does not match the detected one, only a warning will be printed.

Thanks!

#5 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Quoted 10 lines · Alexander Shiyan

Hello.

Quoted 8 lines · Alexander Shiyan
Quoted 6 lines

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---
 .../bindings/media/i2c/onnn,ar0234.yaml       | 121 ++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
Quoted 6 lines
Quoted 1 line

Unanswered Sashiko comments.

I do not understand this remark.
The corrections based on sashiko-bot's feedback are included in the cover letter.
Is something wrong?

You received here Sashiko report which looks reasonable and you did not answer it. At least I could not find such answer.

Quoted 23 lines
Quoted 2 lines
Quoted 2 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +0 -0

...

Quoted 12 lines

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 31

Quoted 11 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +11 -0
+properties:
+  compatible:
+    enum:
+      - onnn,ar0234cssc
+      - onnn,ar0234cssm
+      - onnn,ar0234cs
+    description:
+      The AR0234 sensor exists in two different models, a colour variant
+      (AR0234CSSC) and a monochrome variant (AR0234CSSM). The device exposes
+      the model through registers, allowing for auto-detection with a common
+      "onnn,ar0234cs" compatible string.
Quoted 3 lines

So all devices are compatible? Then why compatibility is not expressed? What are the actual programming differences between sc, sm and "none" variants?

Perhaps I need to revert to the compatibility strings that were used in version 2
(https://patchwork.kernel.org/project/linux-media/patch/[email protected]/).

Quoted 7 lines

From a programming standpoint, it makes almost no difference which sensor is used
- the only differences are in the output format and the format count. Either way, the driver always uses the sensor model determined via register reads.
If the specified type does not match the detected one, only a warning will be printed.

Devices should be made compatible with the fallback or even the color and mono variants could be dropped. That depends on the difference between color/mono.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Hello.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Alexander Shiyan
Quoted 2 lines

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

...

Quoted 30 lines
Quoted 22 lines
Quoted 1 line
Quoted 1 line
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +0 -0

...

Quoted 12 lines

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 31

Quoted 11 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +11 -0
+properties:
+  compatible:
+    enum:
+      - onnn,ar0234cssc
+      - onnn,ar0234cssm
+      - onnn,ar0234cs
+    description:
+      The AR0234 sensor exists in two different models, a colour variant
+      (AR0234CSSC) and a monochrome variant (AR0234CSSM). The device exposes
+      the model through registers, allowing for auto-detection with a common
+      "onnn,ar0234cs" compatible string.
Quoted 3 lines

So all devices are compatible? Then why compatibility is not expressed? What are the actual programming differences between sc, sm and "none" variants?

Perhaps I need to revert to the compatibility strings that were used in version 2
(https://patchwork.kernel.org/project/linux-media/patch/[email protected]/).

Quoted 7 lines

From a programming standpoint, it makes almost no difference which sensor is used
- the only differences are in the output format and the format count. Either way, the driver always uses the sensor model determined via register reads.
If the specified type does not match the detected one, only a warning will be printed.

Quoted 3 lines

Devices should be made compatible with the fallback or even the color and mono variants could be dropped. That depends on the difference between color/mono.

Removing the separation would result in a regression.
The addition of the color and mono variants was proposed by Dave Stevenson following
the first RFC version of the patch.
Subsequently, Laurent Pinchart suggested an implementation approach, which was indeed adopted, though it has evolved somewhat into its current form.

Thanks!

#7 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Quoted 36 lines · Alexander Shiyan

Hello.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Alexander Shiyan
Quoted 2 lines

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

...

Quoted 30 lines
Quoted 29 lines
Quoted 1 line
Quoted 1 line
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +0 -0

...

Quoted 12 lines

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 31

Quoted 11 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml +11 -0
+properties:
+  compatible:
+    enum:
+      - onnn,ar0234cssc
+      - onnn,ar0234cssm
+      - onnn,ar0234cs
+    description:
+      The AR0234 sensor exists in two different models, a colour variant
+      (AR0234CSSC) and a monochrome variant (AR0234CSSM). The device exposes
+      the model through registers, allowing for auto-detection with a common
+      "onnn,ar0234cs" compatible string.
Quoted 3 lines

So all devices are compatible? Then why compatibility is not expressed? What are the actual programming differences between sc, sm and "none" variants?

Perhaps I need to revert to the compatibility strings that were used in version 2
(https://patchwork.kernel.org/project/linux-media/patch/[email protected]/).

From a programming standpoint, it makes almost no difference which sensor is used
- the only differences are in the output format and the format count. Either way, the driver always uses the sensor model determined via register reads.
If the specified type does not match the detected one, only a warning will be printed.

Quoted 5 lines
Quoted 3 lines

Devices should be made compatible with the fallback or even the color and mono variants could be dropped. That depends on the difference between color/mono.

Removing the separation would result in a regression.

What regression? You just proposed these compatibles, they are not accepted, so how and what possible could ever regress?

Best regards,
Krzysztof

#8 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Hi,

Three things that may help: the concrete colour/mono difference, a close precedent in-tree, and a piece of earlier review that has not come up.

Quoted 2 lines

What are the actual programming differences between sc, sm and "none" variants?

There are two hardware models; the third string is not one of them. From patch 2/2: the models have distinct chip ids, 0x0a56 and 0x1a56, read from CHIP_VERSION (0x3000), and an unrecognised id fails probe. The only register write conditioned on the model is DIGITAL_TEST bit 7, MONO_CHROME_OPERATION. The model also selects the advertised bus codes, Y8/Y10 versus SGRBG8/SGRBG10, and the mode table exposes the 10-to-8-bit DPCM code for colour only - though that last one is arguably a media-bus-format gap, as there is no mono DPCM code, rather than a sensor difference.

The suffix-less "onnn,ar0234cs" entry carries no match data, so the model read from the chip is kept. The cssc/cssm entries do carry match data, and on a mismatch the driver warns and uses the DT-selected one.

Quoted 1 line

So all devices are compatible? Then why compatibility is not expressed?

sony,imx678.yaml went through this exact question in May. It was posted as a flat enum of three strings, with a description noting the variants could be detected at runtime:

compatible:
enum:
- sony,imx678
- sony,imx678-aamr
- sony,imx678-aaqr

Conor's objection was that a DT naming both the specific and the generic string would then fail validation:

https://lore.kernel.org/all/20260520-crusher-species-cf707a9a8b46@spud/

and v4 changed it to the form now in tree, with the changelog entry "Follow Conor's suggestion of mandating both the specific and generic device name in the compatible property":

compatible:
items:
- enum:
- sony,imx678-aamr
- sony,imx678-aaqr
- const: sony,imx678

Note that is the mandatory form rather than the oneOf v2 used - there the generic string alone is not valid.

The other colour/mono bindings in that directory use a flat enum:
sony,imx296, st,vd55g1 and st,vd56g3 all describe the split in the binding text, and aptina,mt9p031 does not. sony,imx290 uses a oneOf, but of five model strings plus a deprecated standalone generic.

The v2 fallback form did go through dt-bindings review. Rob quoted it down to the enum line:

compatible:
oneOf:
- const: onnn,ar0234cs
- items:
- enum: ["onnn,ar0234cssc", "onnn,ar0234cssm"]

replied inline with

- enum:
- onnn,ar0234cssc
- onnn,ar0234cssm

Please explain somewhere what the differences between the 3 cases are.

and the quotation then resumes with "- const: onnn,ar0234cs":

https://lore.kernel.org/all/[email protected]/

So that replaced the flow-style enum with a block one and left the oneOf/items structure standing. Reverting to the v2 shape would not be going against that review.

That leaves the question the thread has not settled: whether a bare generic compatible is meant to be valid. Laurent listed the use cases the model-specific strings serve, on the RFC -

https://lore.kernel.org/linux-media/[email protected]/

avoiding a sensor power-up at boot when the module is known at build time, and a runtime sanity check. Of those only the sanity check is delivered today, since probe powers the sensor up and reads the id before it looks at the match data, so a model-specific compatible does not currently save anything at boot. He proposed both forms in that message, and concluded "I don't think we've decided on a recommended practice."

If one DT is meant to serve interchangeable colour and mono modules, the v2 oneOf expresses that. If conforming DTs are expected to name the model, the mandatory imx678 form fits, and the driver can still tolerate generic-only DTs. Either way it seems worth saying which one in the binding.

Thanks,
Aleksandr Chubuchnyi

#9 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

In reply to Alexander Shiyan
Quoted 4 lines · Alexander Shiyan

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---

Plus, there was already v3 here:
<[email protected]>

so how are we supposed to compare this?
Did you address v3 feedback in this v3+1 version?

Drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Hello.

Quoted 8 lines · Alexander Shiyan
Quoted 3 lines

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---

Plus, there was already v3 here:
<[email protected]> so how are we supposed to compare this?
Did you address v3 feedback in this v3+1 version?

Version v3, which was introduced about six months ago, was labeled with the 'RFC' prefix.

Quoted 3 lines

Drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

You're right - this will need to be fixed.

Thanks!

#11 lore raw

Re: [PATCH v3 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Quoted 6 lines · Alexander Shiyan

Hello.

Quoted 4 lines · Alexander Shiyan
Quoted 3 lines

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---

Quoted 7 lines
Quoted 4 lines

Plus, there was already v3 here:
<[email protected]> so how are we supposed to compare this?
Did you address v3 feedback in this v3+1 version?

Version v3, which was introduced about six months ago, was labeled with the 'RFC' prefix.

Label does not matter, it was still v3 and this is v3. Again - try comparing them yourself:

b4 diff '<[email protected]>'

Which version is used for comparing?

Best regards,
Krzysztof

#12 lore raw

PATCH v3 2/2 media: i2c: Add onsemi AR0234 image sensor driver

In reply to Alexander Shiyan

Add driver for the onsemi AR0234 CMOS image sensor.

---
 drivers/media/i2c/Kconfig  |   12 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/ar0234.c | 1294 ++++++++++++++++++++++++++++++++++++
 3 files changed, 1307 insertions(+)
 create mode 100644 drivers/media/i2c/ar0234.c
drivers/media/i2c/Kconfig +12 -0
index 5c52007f9cbe..febab9857cd5 100644
@@ -51,6 +51,18 @@ config VIDEO_ALVIUM_CSI2
 	  To compile this driver as a module, choose M here: the
 	  module will be called alvium-csi2.
 
+config VIDEO_AR0234
+	tristate "onsemi AR0234 sensor support"
+	depends on ACPI || OF || COMPILE_TEST
+	select V4L2_CCI_I2C
+	select VIDEO_CCS_PLL
+	help
+	  This is a Video4Linux2 sensor driver for the onsemi
+	  AR0234 camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ar0234.
+
 config VIDEO_AR0521
 	tristate "ON Semiconductor AR0521 sensor support"
 	help
drivers/media/i2c/Makefile +1 -0
index d04bd5724552..8310db5c63b5 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_VIDEO_AK7375) += ak7375.o
 obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
 obj-$(CONFIG_VIDEO_ALVIUM_CSI2) += alvium-csi2.o
 obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
+obj-$(CONFIG_VIDEO_AR0234) += ar0234.o
 obj-$(CONFIG_VIDEO_AR0521) += ar0521.o
 obj-$(CONFIG_VIDEO_BT819) += bt819.o
 obj-$(CONFIG_VIDEO_BT856) += bt856.o
drivers/media/i2c/ar0234.c new file +1294 -0

1,294 lines not on this page · raw message

Signature · 1 line
2.52.0
#13 lore raw

Re: [PATCH v3 2/2] media: i2c: Add onsemi AR0234 image sensor driver

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Incorrect initialization order of `v4l2_subdev.state_lock` causes a lock mismatch between the…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Incorrect initialization order of v4l2_subdev.state_lock causes a lock mismatch between the subdev state and control handler, resulting in lockdep splats and data races.
- [High] Default PLL state is overwritten during probe and does not match the default active format, leading to streaming failures.
- [High] ar0234_enable_streams() calls the internal setup function __v4l2_ctrl_handler_setup() without holding the control handler lock.
- [Medium] Crop rectangle width, height, and negative coordinates are not properly clamped, allowing invalid 0-size crops to be programmed into hardware.
- [Medium] ar0234_set_framing_limits incorrectly modifies HBLANK control range by passing the dynamic minimum as the default instead of the minimum limit.
- [Medium] ar0234_get_frame_desc returns without unlocking the active state lock on the error path.
--

--- Patch [2]: [PATCH v3 2/2] media: i2c: Add onsemi AR0234 image sensor driver --- commit 8532ef0e666030b52590e6a5adfa76a0332b4935
Author: Alexander Shiyan <[email protected]>
Subject: media: i2c: Add onsemi AR0234 image sensor driver

This commit introduces a new V4L2 I2C driver for the onsemi AR0234 CMOS image sensor. It implements standard subdevice callbacks including pad operations, streaming control, and PM runtime support. The sensor supports multiple MIPI CSI-2 data lane modes and resolutions.

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +0 -0
new file mode 100644

[ ... ]

drivers/media/i2c/ar0234.c line 538

Quoted 9 lines
drivers/media/i2c/ar0234.c new file +9 -0
+static void ar0234_set_framing_limits(struct ar0234 *ar0234, u32 width)
+{
+	int hblank =
+		max(AR0234_LINE_LENGTH_PCK_MIN * 4 - width, AR0234_HBLANK_MIN);
+
+	ar0234_update_exposure_limits(ar0234);
+
+	__v4l2_ctrl_modify_range(ar0234->hblank, AR0234_HBLANK_MIN,
+				 AR0234_HBLANK_MAX, 4, hblank);

[Severity: Medium]
Is the dynamic minimum applied to the correct parameter here?

By passing AR0234_HBLANK_MIN as the minimum and the calculated dynamic hblank as the default value to __v4l2_ctrl_modify_range(), this could allow userspace to set HBLANK below the hardware's minimum line length constraint.

[ ... ]

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+static int ar0234_set_selection(struct v4l2_subdev *sd,
+				struct v4l2_subdev_state *state,
+				struct v4l2_subdev_selection *sel)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 657

Quoted 13 lines
drivers/media/i2c/ar0234.c new file +13 -0
+	max_top = AR0234_PIXEL_ARRAY_TOP + AR0234_PIXEL_ARRAY_HEIGHT -
+		  max(rect.height, AR0234_MIN_CROP_HEIGHT);
+
+	rect.left = clamp_t(u32, rect.left, AR0234_PIXEL_ARRAY_LEFT, max_left);
+	rect.top = clamp_t(u32, rect.top, AR0234_PIXEL_ARRAY_TOP, max_top);
+
+	/*
+	 * Now recalculate width/height as the remaining space. This value
+	 * is guaranteed to be >= AR0234_MIN_CROP_WIDTH/HEIGHT because we
+	 * clamped left/top using the max() of the current size and the min.
+	 */
+	rect.width = min(rect.width, AR0234_PIXEL_ARRAY_LEFT +
+			 AR0234_PIXEL_ARRAY_WIDTH - rect.left);

[Severity: Medium]
Does this code properly bound negative left coordinates?

Since rect.left is clamped using a u32 cast via clamp_t(), a negative sel->r.left bypasses the minimum bound and is clamped to max_left instead.

Subsequently, rect.width is bounded by min() but never bounded to a minimum, allowing a zero-width crop to be calculated and eventually written to the hardware registers.

[ ... ]

Quoted 11 lines
drivers/media/i2c/ar0234.c new file +11 -0
+static int ar0234_init_state(struct v4l2_subdev *sd,
+			     struct v4l2_subdev_state *state)
+{
+	struct v4l2_subdev_selection sel = {
+		.target = V4L2_SEL_TGT_CROP,
+		.which = V4L2_SUBDEV_FORMAT_TRY,
+		.r.left = AR0234_PIXEL_ARRAY_LEFT,
+		.r.top = AR0234_PIXEL_ARRAY_TOP,
+		.r.width = AR0234_PIXEL_ARRAY_WIDTH,
+		.r.height = AR0234_PIXEL_ARRAY_HEIGHT,
+	};

drivers/media/i2c/ar0234.c line 700

Quoted 10 lines
drivers/media/i2c/ar0234.c new file +10 -0
+	struct v4l2_subdev_format format = {
+		.which = V4L2_SUBDEV_FORMAT_TRY,
+		.format = {
+			.width = AR0234_PIXEL_ARRAY_WIDTH,
+			.height = AR0234_PIXEL_ARRAY_HEIGHT,
+		},
+	};
+
+	ar0234_set_selection(sd, state, &sel);
+	ar0234_set_pad_format(sd, state, &format);

[Severity: High]
Does hardcoding V4L2_SUBDEV_FORMAT_TRY prevent the default active state from receiving the correct PLL values?

During probe in ar0234_parse_hw_config(), ar0234_calculate_pll() is called for all evaluated modes, leaving ar0234->pll globally overwritten with the final mode's calculations (10-bpp).

Because ar0234_init_state() specifies V4L2_SUBDEV_FORMAT_TRY, it bypasses the PLL recalculation that would normally update the active state. If userspace starts streaming without explicitly setting a format, the 8-bpp mode might be used alongside the leftover 10-bpp PLL configuration, causing a failure.

[ ... ]

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+static int ar0234_enable_streams(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *state, u32 pad,
+				 u64 streams_mask)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 771

Quoted 9 lines
drivers/media/i2c/ar0234.c new file +9 -0
+	cci_write(ar0234->regmap, AR0234_REG_X_ADDR_START, x_addr_start, &ret);
+	cci_write(ar0234->regmap, AR0234_REG_Y_ADDR_START, y_addr_start, &ret);
+	cci_write(ar0234->regmap, AR0234_REG_X_ADDR_END, x_addr_end, &ret);
+	cci_write(ar0234->regmap, AR0234_REG_Y_ADDR_END, y_addr_end, &ret);
+
+	if (ret)
+		goto start_err;
+
+	ret = __v4l2_ctrl_handler_setup(ar0234->sd.ctrl_handler);

[Severity: High]
Should the control handler lock be held during this setup call?

The __v4l2_ctrl_handler_setup() function is an internal helper that expects the caller to hold ctrls.lock. Since the V4L2 core does not hold the control handler lock when invoking the enable_streams pad operation, calling this directly can cause lockdep splats and data races.

[ ... ]

drivers/media/i2c/ar0234.c line 825

Quoted 13 lines
drivers/media/i2c/ar0234.c new file +13 -0
+static int ar0234_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+				 struct v4l2_mbus_frame_desc *fd)
+{
+	struct ar0234 *ar0234 = to_ar0234(sd);
+	const struct v4l2_mbus_framefmt *fmt;
+	struct v4l2_subdev_state *state;
+	const struct ar0234_mode *mode;
+	u32 code;
+
+	state = v4l2_subdev_lock_and_get_active_state(&ar0234->sd);
+	fmt = v4l2_subdev_state_get_format(state, pad);
+	if (!fmt)
+		return -EINVAL;

[Severity: Medium]
Can this error path cause a subdevice state deadlock?

The active state lock is acquired via v4l2_subdev_lock_and_get_active_state(), but if fmt happens to be NULL, the function returns -EINVAL directly without calling v4l2_subdev_unlock_state().

[ ... ]

Quoted 2 lines
drivers/media/i2c/ar0234.c new file +2 -0
+static int ar0234_probe(struct i2c_client *client)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 1218

Quoted 9 lines
drivers/media/i2c/ar0234.c new file +9 -0
+	ret = v4l2_subdev_init_finalize(&ar0234->sd);
+	if (ret)
+		goto err_media;
+
+	ret = ar0234_ctrls_init(ar0234);
+	if (ret)
+		goto err_media;
+
+	ar0234->sd.state_lock = ar0234->ctrls.lock;

[Severity: High]
Is the active state lock initialized properly here?

Because v4l2_subdev_init_finalize() is called before sd->state_lock is assigned to ar0234->ctrls.lock, the active state ends up allocating and using its own internal fallback mutex.

Later operations like V4L2 control updates will execute with ctrls.lock held but will access the active state which expects its own separate lock to be held, causing a lock mismatch and lockdep assertion failures.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2