Skip to contentSkip to conversation

Add StarFive Camera Subsystem driver

PATCH Superseded Jack Zhu 4 participants 14 messages May 12, 2023 – May 15, 2023

Subsystems (2)

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Jack Zhu

author
#0 lore raw

v5 cover Add StarFive Camera Subsystem driver

hi,

This series is the v5 of the series, the CSI driver is moved to another separate series.

Changes in v5:
- Rebased on v6.4-rc1.
- Added new patch.
- Modified ISP driver.

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

Previous cover letter from v4:

This patch series adds support for the StarFive Camera Subsystem found on StarFive JH7110 SoC.

The driver implements V4L2, Media controller and V4L2 subdev interfaces. Camera sensor using V4L2 subdev interface in the kernel is supported.

The driver is tested on VisionFive V2 board with IMX219 camera sensor. GStreamer 1.18.5 with v4l2src plugin is supported.

Changes since v3:
Patch 1:
- Modified port@0 and port@1 properties.
- Extended the port@0 example with appropriate properties.
- Added 'port@0' for 'required'
Patch 2:
- Modified spelling errors.
Patch 3:
- Merged patch 5 into the patch with an explanation for compatible in commit msg.
Patch 6:
- Asserted pixel_rst[i] reset in the loop after the err_disable_pixclk label.
- Modified Code Style for getting sys_rst and p_rst.
- Renamed clk_name to name and modified the relevant code. Patch 9:
- Added static for stfcamss_get_mem_res function.
- Added static for isp_close function.
- Fixed implicit conversion warning for stf_vin_map_isp_pad function.
- Dropped unused variables.

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

Changes since v2:
- Rebased on v6.3-rc1.
Patch 1:
- Modified spelling errors.
- Added port@0.
- Modified '$ref' of port.
- Added 'ports' to 'required'.
- Dropped 'stfcamss' label in example.
- Added port@0 in example.
- Added MAINTAINERS file.
Patch 2:
- Split this patch into three new patches.
- Modified compatible property.
- Replaced clock names with the existing names.
- Modified 'bus-type' and 'clock-lanes'
- Added port@2 - port@4
- Dropped 'csi2rx' label in example.
Patch 3:
- Updated rst and dot file as three pipelines were deleted. Patch 4:
- Split this patch into three new patches.
- Dropped .s_power() and .get_fmt().
- Dropped CSI-2 DT support.
- Dropped v4l2_device_register_subdev_nodes().
- Used assigned-clock-rates in DT to set clk value.
- Modified 'compatible' field.
Patch 5:
- Deleted three pipelines.
- Modified 'stfcamss_clocks'/'stfcamss_resets' struct.
- Dropped stfcamss_find_sensor() function.
- Removed redundant code from stfcamss_of_parse_endpoint_node().
- Modified spelling errors.
- Rewrote stfcamss_reg_media_subdev_node() function.
- Modified stfcamss_subdev_notifier_bound().
- Modified stfcamss_probe() function.
- Dropped stfcamss_suspend() and stfcamss_resume().
- Dropped dev_info() in stfcamss_remove() function.
- Added 'stf_' prefix for enum subdev_type.
- Moved all includes to the top in stf_camss.h file.
- Dropped unused fields in stfcamss struct.
- Replaced Custom logging macros with regular macros.
- Rewrote register read and write functions.
- Used lowercase for all hex constants.
- Used macro to name registers.
- Dropped unused ioctl and stf_isp_ioctl.h file.

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

Changes since v1:
- Deleted starfive,jh7110-mipi-csi2.yaml.
- Converted cdns,csi2rx.txt to cdns,csi2rx.yaml and added ‘resets’ properties.
- Added ‘cdns,csi2rx.yaml’ in ‘CADENCE MIPI-CSI2 BRIDGES’ entry.
- The following contents were modified in starfive,jh7110-camss.yaml:
dropped quotes from ’id’ and ‘schema’; dropped ‘|’ for ‘description’; corrected the wrong or redundant words: ‘a ISP’, ‘PD ISP’; dropped ‘minItems’ for ‘reg’, ‘clocks’, ‘resets’ and ‘interrupts’; dropped the '_clk' and 'rst_' prefix about the 'clock-names' and 'reset-names';
changed ‘endpoint@1’ to ‘endpoint’; updated examples;
- Updated Subject for some patches.
- Merged patch 6, 7, 8, 9, 10, 11 into one patch.

Jack Zhu (6):
media: dt-bindings: Add JH7110 Camera Subsystem
media: admin-guide: Add starfive_camss.rst for Starfive Camera
Subsystem
media: starfive: Add basic driver
media: starfive: Add video driver
media: starfive: Add ISP driver
media: starfive: Add VIN driver

 .../admin-guide/media/starfive_camss.rst      |   57 +
 .../media/starfive_camss_graph.dot            |   16 +
 .../admin-guide/media/v4l-drivers.rst         |    1 +
 .../bindings/media/starfive,jh7110-camss.yaml |  179 +++
 MAINTAINERS                                   |    9 +
 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    1 +
 drivers/media/platform/starfive/Kconfig       |   19 +
 drivers/media/platform/starfive/Makefile      |   14 +
 drivers/media/platform/starfive/stf_camss.c   |  476 +++++++
 drivers/media/platform/starfive/stf_camss.h   |  157 +++
 drivers/media/platform/starfive/stf_common.h  |   18 +
 drivers/media/platform/starfive/stf_isp.c     |  550 ++++++++
 drivers/media/platform/starfive/stf_isp.h     |  476 +++++++
 .../media/platform/starfive/stf_isp_hw_ops.c  |  452 +++++++
 drivers/media/platform/starfive/stf_video.c   |  864 +++++++++++++
 drivers/media/platform/starfive/stf_video.h   |   95 ++
 drivers/media/platform/starfive/stf_vin.c     | 1134 +++++++++++++++++
 drivers/media/platform/starfive/stf_vin.h     |  180 +++
 .../media/platform/starfive/stf_vin_hw_ops.c  |  241 ++++
 20 files changed, 4940 insertions(+)
 create mode 100644 Documentation/admin-guide/media/starfive_camss.rst
 create mode 100644 Documentation/admin-guide/media/starfive_camss_graph.dot
 create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
 create mode 100644 drivers/media/platform/starfive/Kconfig
 create mode 100644 drivers/media/platform/starfive/Makefile
 create mode 100644 drivers/media/platform/starfive/stf_camss.c
 create mode 100644 drivers/media/platform/starfive/stf_camss.h
 create mode 100644 drivers/media/platform/starfive/stf_common.h
 create mode 100644 drivers/media/platform/starfive/stf_isp.c
 create mode 100644 drivers/media/platform/starfive/stf_isp.h
 create mode 100644 drivers/media/platform/starfive/stf_isp_hw_ops.c
 create mode 100644 drivers/media/platform/starfive/stf_video.c
 create mode 100644 drivers/media/platform/starfive/stf_video.h
 create mode 100644 drivers/media/platform/starfive/stf_vin.c
 create mode 100644 drivers/media/platform/starfive/stf_vin.h
 create mode 100644 drivers/media/platform/starfive/stf_vin_hw_ops.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/6 media: dt-bindings: Add JH7110 Camera Subsystem

Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.

---
 .../bindings/media/starfive,jh7110-camss.yaml | 179 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 186 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +179 -0
new file mode 100644
index 000000000000..f3bef3eb2502
@@ -0,0 +1,179 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/starfive,jh7110-camss.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Starfive SoC CAMSS ISP
+
+maintainers:
+  - Jack Zhu <[email protected]>
+  - Changhuang Liang <[email protected]>
+
+description:
+  The Starfive CAMSS ISP is a Camera interface for Starfive JH7110 SoC. It
+  consists of a VIN controller (Video In Controller, a top-level control until)
+  and an ISP.
+
+properties:
+  compatible:
+    const: starfive,jh7110-camss
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: syscon
+      - const: isp
+
+  clocks:
+    maxItems: 7
+
+  clock-names:
+    items:
+      - const: apb_func
+      - const: wrapper_clk_c
+      - const: dvp_inv
+      - const: axiwr
+      - const: mipi_rx0_pxl
+      - const: ispcore_2x
+      - const: isp_axi
+
+  resets:
+    maxItems: 6
+
+  reset-names:
+    items:
+      - const: wrapper_p
+      - const: wrapper_c
+      - const: axird
+      - const: axiwr
+      - const: isp_top_n
+      - const: isp_top_axi
+
+  power-domains:
+    items:
+      - description: JH7110 ISP Power Domain Switch Controller.
+
+  interrupts:
+    maxItems: 4
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: Input port for receiving DVP data.
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              bus-type:
+                enum: [5, 6]
+
+              bus-width:
+                enum: [8, 10, 12]
+
+              data-shift:
+                enum: [0, 2]
+                default: 0
+
+              hsync-active:
+                enum: [0, 1]
+                default: 1
+
+              vsync-active:
+                enum: [0, 1]
+                default: 1
+
+            required:
+              - bus-type
+              - bus-width
+
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Input port for receiving CSI data.
+
+    required:
+      - port@0
+      - port@1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - power-domains
+  - interrupts
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    isp@19840000 {
+        compatible = "starfive,jh7110-camss";
+        reg = <0x19840000 0x10000>,
+              <0x19870000 0x30000>;
+        reg-names = "syscon", "isp";
+        clocks = <&ispcrg 0>,
+                 <&ispcrg 13>,
+                 <&ispcrg 2>,
+                 <&ispcrg 12>,
+                 <&ispcrg 1>,
+                 <&syscrg 51>,
+                 <&syscrg 52>;
+        clock-names = "apb_func",
+                      "wrapper_clk_c",
+                      "dvp_inv",
+                      "axiwr",
+                      "mipi_rx0_pxl",
+                      "ispcore_2x",
+                      "isp_axi";
+        resets = <&ispcrg 0>,
+                 <&ispcrg 1>,
+                 <&ispcrg 10>,
+                 <&ispcrg 11>,
+                 <&syscrg 41>,
+                 <&syscrg 42>;
+        reset-names = "wrapper_p",
+                      "wrapper_c",
+                      "axird",
+                      "axiwr",
+                      "isp_top_n",
+                      "isp_top_axi";
+        power-domains = <&pwrc 5>;
+        interrupts = <92>, <87>, <88>, <90>;
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            port@0 {
+                reg = <0>;
+                vin_from_sc2235: endpoint {
+                    remote-endpoint = <&sc2235_to_vin>;
+                    bus-width = <8>;
+                    data-shift = <2>;
+                    hsync-active = <1>;
+                    vsync-active = <0>;
+                    pclk-sample = <1>;
+                };
+            };
+
+            port@1 {
+                reg = <1>;
+                vin_from_csi2rx: endpoint {
+                    remote-endpoint = <&csi2rx_to_vin>;
+                };
+            };
+        };
+    };
MAINTAINERS +7 -0
index 869e1c7fc869..9ef5d0e5dff0 100644
@@ -20070,6 +20070,13 @@ M:	Ion Badulescu <[email protected]>
 S:	Odd Fixes
 F:	drivers/net/ethernet/adaptec/starfire*
 
+STARFIVE CAMERA SUBSYSTEM DRIVER
+M:	Jack Zhu <[email protected]>
+M:	Changhuang Liang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
+
 STARFIVE DEVICETREES
 M:	Emil Renner Berthing <[email protected]>
 S:	Maintained
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/6] media: dt-bindings: Add JH7110 Camera Subsystem

Quoted 11 lines · Jack Zhu

Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.

---
 .../bindings/media/starfive,jh7110-camss.yaml | 179 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 186 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/starfive,jh7110-camss.example.dtb: isp@19840000: ports:port@0:endpoint: 'bus-type' is a required property
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml

See https://patchwork.ozlabs.org/patch/1780481

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

author
#3 lore raw

Re: [PATCH v5 1/6] media: dt-bindings: Add JH7110 Camera Subsystem

Quoted 13 lines · Krzysztof Kozlowski
Quoted 11 lines · Jack Zhu

Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.

---
 .../bindings/media/starfive,jh7110-camss.yaml | 179 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 186 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
Quoted 9 lines

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/starfive,jh7110-camss.example.dtb: isp@19840000: ports:port@0:endpoint: 'bus-type' is a required property
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml

OK, I will fix it. Thank you!

Quoted 13 lines

See https://patchwork.ozlabs.org/patch/1780481

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

#4 lore raw

Re: [PATCH v5 1/6] media: dt-bindings: Add JH7110 Camera Subsystem

In reply to Jack Zhu

Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 16

Quoted 4 lines · Jack Zhu
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +4 -0
+description:
+  The Starfive CAMSS ISP is a Camera interface for Starfive JH7110 SoC. It
+  consists of a VIN controller (Video In Controller, a top-level control until)
+  and an ISP.

Just a minor comment here, "until" is a typo, right? I guess it should be "unit".

author
#5 lore raw

Re: [PATCH v5 1/6] media: dt-bindings: Add JH7110 Camera Subsystem

Quoted 9 lines · Conor Dooley

Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 16

Quoted 4 lines · Jack Zhu
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +4 -0
+description:
+  The Starfive CAMSS ISP is a Camera interface for Starfive JH7110 SoC. It
+  consists of a VIN controller (Video In Controller, a top-level control until)
+  and an ISP.

Just a minor comment here, "until" is a typo, right? I guess it should be "unit".

Yes, will modify it in next version. Thank you for your review.

author
#6 lore raw

PATCH v5 2/6 media: admin-guide: Add starfive_camss.rst for Starfive Camera Subsystem

In reply to Jack Zhu

Add starfive_camss.rst file that documents the Starfive Camera Subsystem driver which is used for handing image sensor data.

---
 .../admin-guide/media/starfive_camss.rst      | 57 +++++++++++++++++++
 .../media/starfive_camss_graph.dot            | 16 ++++++
 .../admin-guide/media/v4l-drivers.rst         |  1 +
 MAINTAINERS                                   |  1 +
 4 files changed, 75 insertions(+)
 create mode 100644 Documentation/admin-guide/media/starfive_camss.rst
 create mode 100644 Documentation/admin-guide/media/starfive_camss_graph.dot
Documentation/admin-guide/media/starfive_camss.rst new file +57 -0
new file mode 100644
index 000000000000..a6378849384f
@@ -0,0 +1,57 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. include:: <isonum.txt>
+
+================================
+Starfive Camera Subsystem driver
+================================
+
+Introduction
+------------
+
+This file documents the driver for the Starfive Camera Subsystem found on
+Starfive JH7110 SoC. The driver is located under drivers/media/platform/
+starfive.
+
+The driver implements V4L2, Media controller and v4l2_subdev interfaces.
+Camera sensor using V4L2 subdev interface in the kernel is supported.
+
+The driver has been successfully used on the Gstreamer 1.18.5 with
+v4l2src plugin.
+
+
+Starfive Camera Subsystem hardware
+----------------------------------
+
+The Starfive Camera Subsystem hardware consists of:
+
+- MIPI DPHY Receiver: receives mipi data from a MIPI camera sensor.
+- MIPI CSIRx Controller: is responsible for handling and decoding CSI2 protocol
+  based camera sensor data stream.
+- ISP: handles the image data streams from the MIPI CSIRx Controller.
+- VIN(Video In): a top-level module, is responsible for controlling power
+  and clocks to other modules, dumps the input data to memory or transfers the
+  input data to ISP.
+
+
+Topology
+--------
+
+The media controller pipeline graph is as follows:
+
+.. _starfive_camss_graph:
+
+.. kernel-figure:: starfive_camss_graph.dot
+    :alt:   starfive_camss_graph.dot
+    :align: center
+
+The driver has 2 video devices:
+
+- stf_vin0_wr_video0: capture device for images directly from the VIN module.
+- stf_vin0_isp0_video1: capture device for images without scaling.
+
+The driver has 3 subdevices:
+
+- stf_isp0: is responsible for all the isp operations.
+- stf_vin0_wr: used to dump RAW images to memory.
+- stf_vin0_isp0: used to capture images for the stf_vin0_isp0_video1 device.
Documentation/admin-guide/media/starfive_camss_graph.dot new file +16 -0
new file mode 100644
index 000000000000..850be912cdeb
@@ -0,0 +1,16 @@
+digraph board {
+	rankdir=TB
+	n00000001 [label="{{<port0> 0} | stf_isp0\n/dev/v4l-subdev0 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+	n00000001:port1 -> n0000000d:port0
+	n00000004 [label="{{<port0> 0} | stf_vin0_wr\n/dev/v4l-subdev1 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+	n00000004:port1 -> n00000007 [style=bold]
+	n00000007 [label="stf_vin0_wr_video0\n/dev/video0", shape=box, style=filled, fillcolor=yellow]
+	n0000000d [label="{{<port0> 0} | stf_vin0_isp0\n/dev/v4l-subdev2 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+	n0000000d:port1 -> n00000010 [style=bold]
+	n00000010 [label="stf_vin0_isp0_video1\n/dev/video1", shape=box, style=filled, fillcolor=yellow]
+	n00000018 [label="{{<port0> 0} | cdns_csi2rx.19800000.csi-bridge\n | {<port1> 1 | <port2> 2 | <port3> 3 | <port4> 4}}", shape=Mrecord, style=filled, fillcolor=green]
+	n00000018:port1 -> n00000004:port0 [style=dashed]
+	n00000018:port1 -> n00000001:port0
+	n00000028 [label="{{} | imx219 6-0010\n | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
+	n00000028:port0 -> n00000018:port0 [style=bold]
+}
Documentation/admin-guide/media/v4l-drivers.rst +1 -0
index 1c41f87c3917..2274fd29c1d7 100644
@@ -27,6 +27,7 @@ Video4Linux (V4L) driver-specific documentation
 	si470x
 	si4713
 	si476x
+	starfive_camss
 	vimc
 	visl
 	vivid
MAINTAINERS +1 -0
index 9ef5d0e5dff0..71291dc58671 100644
@@ -20075,6 +20075,7 @@ M:	Jack Zhu <[email protected]>
 M:	Changhuang Liang <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/admin-guide/media/starfive_camss.rst
 F:	Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
 
 STARFIVE DEVICETREES
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH v5 3/6 media: starfive: Add basic driver

In reply to Jack Zhu

Add basic platform driver for StarFive Camera Subsystem.

---
 MAINTAINERS                                  |   1 +
 drivers/media/platform/Kconfig               |   1 +
 drivers/media/platform/Makefile              |   1 +
 drivers/media/platform/starfive/Kconfig      |  19 +
 drivers/media/platform/starfive/Makefile     |   9 +
 drivers/media/platform/starfive/stf_camss.c  | 372 +++++++++++++++++++
 drivers/media/platform/starfive/stf_camss.h  | 153 ++++++++
 drivers/media/platform/starfive/stf_common.h |  18 +
 8 files changed, 574 insertions(+)
 create mode 100644 drivers/media/platform/starfive/Kconfig
 create mode 100644 drivers/media/platform/starfive/Makefile
 create mode 100644 drivers/media/platform/starfive/stf_camss.c
 create mode 100644 drivers/media/platform/starfive/stf_camss.h
 create mode 100644 drivers/media/platform/starfive/stf_common.h
MAINTAINERS +1 -0
index 71291dc58671..33a752569942 100644
@@ -20077,6 +20077,7 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/admin-guide/media/starfive_camss.rst
 F:	Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
+F:	drivers/media/platform/starfive/
 
 STARFIVE DEVICETREES
 M:	Emil Renner Berthing <[email protected]>
drivers/media/platform/Kconfig +1 -0
index ee579916f874..627eaa0ab3ee 100644
@@ -80,6 +80,7 @@ source "drivers/media/platform/renesas/Kconfig"
 source "drivers/media/platform/rockchip/Kconfig"
 source "drivers/media/platform/samsung/Kconfig"
 source "drivers/media/platform/st/Kconfig"
+source "drivers/media/platform/starfive/Kconfig"
 source "drivers/media/platform/sunxi/Kconfig"
 source "drivers/media/platform/ti/Kconfig"
 source "drivers/media/platform/verisilicon/Kconfig"
drivers/media/platform/Makefile +1 -0
index 5453bb868e67..5a038498a370 100644
@@ -23,6 +23,7 @@ obj-y += renesas/
 obj-y += rockchip/
 obj-y += samsung/
 obj-y += st/
+obj-y += starfive/
 obj-y += sunxi/
 obj-y += ti/
 obj-y += verisilicon/
drivers/media/platform/starfive/Kconfig new file +19 -0
new file mode 100644
index 000000000000..1a2293475bd2
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+comment "Starfive media platform drivers"
+
+config VIDEO_STARFIVE_CAMSS
+	tristate "Starfive Camera Subsystem driver"
+	depends on V4L_PLATFORM_DRIVERS
+	depends on VIDEO_DEV && OF
+	depends on DMA_CMA
+	select MEDIA_CONTROLLER
+	select VIDEO_V4L2_SUBDEV_API
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_FWNODE
+	help
+	   Enable this to support for the Starfive Camera subsystem
+	   found on Starfive JH7110 SoC.
+
+	   To compile this driver as a module, choose M here: the
+	   module will be called stf-camss.
drivers/media/platform/starfive/Makefile new file +9 -0
new file mode 100644
index 000000000000..796775fa52f4
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for StarFive camera subsystem driver.
+#
+
+starfive-camss-objs += \
+		stf_camss.o
+
+obj-$(CONFIG_VIDEO_STARFIVE_CAMSS) += starfive-camss.o \
drivers/media/platform/starfive/stf_camss.c new file +372 -0

372 lines not on this page · raw message

drivers/media/platform/starfive/stf_camss.h new file +153 -0

153 lines not on this page · raw message

drivers/media/platform/starfive/stf_common.h new file +18 -0
new file mode 100644
index 000000000000..e04fca2d9cd4
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * stf_common.h
+ *
+ * StarFive Camera Subsystem - Common definitions
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+
+#ifndef STF_COMMON_H
+#define STF_COMMON_H
+
+enum stf_subdev_type {
+	STF_SUBDEV_TYPE_VIN,
+	STF_SUBDEV_TYPE_ISP,
+};
+
+#endif /* STF_COMMON_H */
Signature · 1 line
2.34.1
Reviewed-by on v5 3/6
#8 lore raw

Re: [PATCH v5 3/6] media: starfive: Add basic driver

Quoted 3 lines · Jack Zhu

Add basic platform driver for StarFive Camera Subsystem.

A couple of nits below

Other than those

Quoted 322 lines
---
  MAINTAINERS                                  |   1 +
  drivers/media/platform/Kconfig               |   1 +
  drivers/media/platform/Makefile              |   1 +
  drivers/media/platform/starfive/Kconfig      |  19 +
  drivers/media/platform/starfive/Makefile     |   9 +
  drivers/media/platform/starfive/stf_camss.c  | 372 +++++++++++++++++++
  drivers/media/platform/starfive/stf_camss.h  | 153 ++++++++
  drivers/media/platform/starfive/stf_common.h |  18 +
  8 files changed, 574 insertions(+)

create mode 100644 drivers/media/platform/starfive/Kconfig create mode 100644 drivers/media/platform/starfive/Makefile create mode 100644 drivers/media/platform/starfive/stf_camss.c create mode 100644 drivers/media/platform/starfive/stf_camss.h create mode 100644 drivers/media/platform/starfive/stf_common.h

MAINTAINERS +1 -0
index 71291dc58671..33a752569942 100644
@@ -20077,6 +20077,7 @@ L:	[email protected]
  S:	Maintained
  F:	Documentation/admin-guide/media/starfive_camss.rst
  F:	Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
+F:	drivers/media/platform/starfive/
 
  STARFIVE DEVICETREES
  M:	Emil Renner Berthing <[email protected]>
drivers/media/platform/Kconfig +1 -0
index ee579916f874..627eaa0ab3ee 100644
@@ -80,6 +80,7 @@ source "drivers/media/platform/renesas/Kconfig"
  source "drivers/media/platform/rockchip/Kconfig"
  source "drivers/media/platform/samsung/Kconfig"
  source "drivers/media/platform/st/Kconfig"
+source "drivers/media/platform/starfive/Kconfig"
  source "drivers/media/platform/sunxi/Kconfig"
  source "drivers/media/platform/ti/Kconfig"
  source "drivers/media/platform/verisilicon/Kconfig"
drivers/media/platform/Makefile +1 -0
index 5453bb868e67..5a038498a370 100644
@@ -23,6 +23,7 @@ obj-y += renesas/
  obj-y += rockchip/
  obj-y += samsung/
  obj-y += st/
+obj-y += starfive/
  obj-y += sunxi/
  obj-y += ti/
  obj-y += verisilicon/
drivers/media/platform/starfive/Kconfig new file +19 -0
new file mode 100644
index 000000000000..1a2293475bd2
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+comment "Starfive media platform drivers"
+
+config VIDEO_STARFIVE_CAMSS
+	tristate "Starfive Camera Subsystem driver"
+	depends on V4L_PLATFORM_DRIVERS
+	depends on VIDEO_DEV && OF
+	depends on DMA_CMA
+	select MEDIA_CONTROLLER
+	select VIDEO_V4L2_SUBDEV_API
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_FWNODE
+	help
+	   Enable this to support for the Starfive Camera subsystem
+	   found on Starfive JH7110 SoC.
+
+	   To compile this driver as a module, choose M here: the
+	   module will be called stf-camss.
drivers/media/platform/starfive/Makefile new file +9 -0
new file mode 100644
index 000000000000..796775fa52f4
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for StarFive camera subsystem driver.
+#
+
+starfive-camss-objs += \
+		stf_camss.o
+
+obj-$(CONFIG_VIDEO_STARFIVE_CAMSS) += starfive-camss.o \
drivers/media/platform/starfive/stf_camss.c new file +224 -0
new file mode 100644
index 000000000000..ba3a2bc8a8ab
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * stf_camss.c
+ *
+ * Starfive Camera Subsystem driver
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/videodev2.h>
+#include <media/media-device.h>
+#include <media/v4l2-async.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-mc.h>
+
+#include "stf_camss.h"
+
+static const char * const stfcamss_clocks[] = {
+	"clk_apb_func",
+	"clk_wrapper_clk_c",
+	"clk_dvp_inv",
+	"clk_axiwr",
+	"clk_mipi_rx0_pxl",
+	"clk_ispcore_2x",
+	"clk_isp_axi",
+};
+
+static const char * const stfcamss_resets[] = {
+	"rst_wrapper_p",
+	"rst_wrapper_c",
+	"rst_axird",
+	"rst_axiwr",
+	"rst_isp_top_n",
+	"rst_isp_top_axi",
+};
+
+static int stfcamss_get_mem_res(struct platform_device *pdev,
+				struct stfcamss *stfcamss)
+{
+	stfcamss->syscon_base =
+		devm_platform_ioremap_resource_byname(pdev, "syscon");
+	if (IS_ERR(stfcamss->syscon_base))
+		return PTR_ERR(stfcamss->syscon_base);
+
+	stfcamss->isp_base =
+		devm_platform_ioremap_resource_byname(pdev, "isp");
+	if (IS_ERR(stfcamss->isp_base))
+		return PTR_ERR(stfcamss->isp_base);
+
+	return 0;
+}
+
+/*
+ * stfcamss_of_parse_endpoint_node - Parse port endpoint node
+ * @dev: Device
+ * @node: Device node to be parsed
+ * @csd: Parsed data from port endpoint node
+ *
+ * Return 0 on success or a negative error code on failure
+ */
+static int stfcamss_of_parse_endpoint_node(struct device *dev,
+					   struct device_node *node,
+					   struct stfcamss_async_subdev *csd)
+{
+	struct v4l2_fwnode_endpoint vep = { { 0 } };
+
+	v4l2_fwnode_endpoint_parse(of_fwnode_handle(node), &vep);
+	dev_dbg(dev, "vep.base.port = 0x%x, id = 0x%x\n",
+		vep.base.port, vep.base.id);
+
+	csd->port = vep.base.port;
+
+	return 0;
+}
+
+/*
+ * stfcamss_of_parse_ports - Parse ports node
+ * @stfcamss: STFCAMSS device
+ *
+ * Return number of "port" nodes found in "ports" node
+ */
+static int stfcamss_of_parse_ports(struct stfcamss *stfcamss)
+{
+	struct device *dev = stfcamss->dev;
+	struct device_node *node = NULL;
+	struct device_node *remote = NULL;
+	int ret, num_subdevs = 0;
+
+	for_each_endpoint_of_node(dev->of_node, node) {
+		struct stfcamss_async_subdev *csd;
+
+		if (!of_device_is_available(node))
+			continue;
+
+		remote = of_graph_get_remote_port_parent(node);
+		if (!remote) {
+			dev_err(dev, "Cannot get remote parent\n");
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+		csd = v4l2_async_nf_add_fwnode(&stfcamss->notifier,
+					       of_fwnode_handle(remote),
+					       struct stfcamss_async_subdev);
+		of_node_put(remote);
+		if (IS_ERR(csd)) {
+			ret = PTR_ERR(csd);
+			goto err_cleanup;
+		}
+
+		ret = stfcamss_of_parse_endpoint_node(dev, node, csd);
+		if (ret < 0)
+			goto err_cleanup;
+
+		num_subdevs++;
+	}
+
+	return num_subdevs;
+
+err_cleanup:
+	of_node_put(node);
+	return ret;
+}
+
+static int stfcamss_subdev_notifier_bound(struct v4l2_async_notifier *async,
+					  struct v4l2_subdev *subdev,
+					  struct v4l2_async_subdev *asd)
+{
+	struct stfcamss *stfcamss =
+		container_of(async, struct stfcamss, notifier);
+	struct host_data *host_data = &stfcamss->host_data;
+	struct media_entity *source;
+	int i, j;
+
+	source = &subdev->entity;
+
+	for (i = 0; i < source->num_pads; i++) {
+		if (source->pads[i].flags & MEDIA_PAD_FL_SOURCE)
+			break;
+	}
+
+	if (i == source->num_pads) {
+		dev_err(stfcamss->dev, "No source pad in external entity\n");
+		return -EINVAL;
+	}
+
+	for (j = 0; host_data->host_entity[j] && (j < HOST_ENTITY_MAX); j++) {
+		struct media_entity *input;
+		int ret;
+
+		input = host_data->host_entity[j];
+
+		ret = media_create_pad_link(
+			source,
+			i,
+			input,
+			STF_PAD_SINK,
+			source->function == MEDIA_ENT_F_CAM_SENSOR ?
+			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED :
+			0);
+		if (ret < 0) {
+			dev_err(stfcamss->dev,
+				"Failed to link %s->%s entities: %d\n",
+				source->name, input->name, ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int stfcamss_subdev_notifier_complete(struct v4l2_async_notifier *ntf)
+{
+	struct stfcamss *stfcamss =
+		container_of(ntf, struct stfcamss, notifier);
+
+	return v4l2_device_register_subdev_nodes(&stfcamss->v4l2_dev);
+}
+
+static const struct v4l2_async_notifier_operations
+stfcamss_subdev_notifier_ops = {
+	.bound = stfcamss_subdev_notifier_bound,
+	.complete = stfcamss_subdev_notifier_complete,
+};
+
+static const struct media_device_ops stfcamss_media_ops = {
+	.link_notify = v4l2_pipeline_link_notify,
+};
+
+static void stfcamss_mc_init(struct platform_device *pdev,
+			     struct stfcamss *stfcamss)
+{
+	stfcamss->media_dev.dev = stfcamss->dev;
+	strscpy(stfcamss->media_dev.model, "Starfive Camera Subsystem",
+		sizeof(stfcamss->media_dev.model));
+	snprintf(stfcamss->media_dev.bus_info,
+		 sizeof(stfcamss->media_dev.bus_info),
+		 "%s:%s", dev_bus_name(&pdev->dev), pdev->name);
+	stfcamss->media_dev.hw_revision = 0x01;
+	stfcamss->media_dev.ops = &stfcamss_media_ops;
+	media_device_init(&stfcamss->media_dev);
+
+	stfcamss->v4l2_dev.mdev = &stfcamss->media_dev;
+}
+
+/*
+ * stfcamss_probe - Probe STFCAMSS platform device
+ * @pdev: Pointer to STFCAMSS platform device
+ *
+ * Return 0 on success or a negative error code on failure
+ */
+static int stfcamss_probe(struct platform_device *pdev)
+{
+	struct stfcamss *stfcamss;
+	struct device *dev = &pdev->dev;
+	int ret = 0, i, num_subdevs;
+
+	stfcamss = devm_kzalloc(dev, sizeof(*stfcamss), GFP_KERNEL);
+	if (!stfcamss)
+		return -ENOMEM;

drivers/media/platform/starfive/stf_camss.c line 234

Quoted 10 lines
drivers/media/platform/starfive/stf_camss.c new file +10 -0
+
+	for (i = 0; i < ARRAY_SIZE(stfcamss->irq); ++i) {
+		stfcamss->irq[i] = platform_get_irq(pdev, i);
+		if (stfcamss->irq[i] < 0)
+			return dev_err_probe(&pdev->dev, stfcamss->irq[i],
+					     "Failed to get clock%d", i);
+	}
+
+	stfcamss->nclks = ARRAY_SIZE(stfcamss->sys_clk);
+	for (i = 0; i < ARRAY_SIZE(stfcamss->sys_clk); ++i)

Why use ARRAY_SIZE twice - you just derived stfcamss->nclks

drivers/media/platform/starfive/stf_camss.c line 243

Quoted 9 lines
drivers/media/platform/starfive/stf_camss.c new file +9 -0
+		stfcamss->sys_clk[i].id = stfcamss_clocks[i];
+	ret = devm_clk_bulk_get(dev, stfcamss->nclks, stfcamss->sys_clk);
+	if (ret) {
+		dev_err(dev, "Failed to get clk controls\n");
+		return ret;
+	}
+
+	stfcamss->nrsts = ARRAY_SIZE(stfcamss->sys_rst);
+	for (i = 0; i < ARRAY_SIZE(stfcamss->sys_rst); ++i)

i < stfcamss->nrsts

Quoted 312 lines
drivers/media/platform/starfive/stf_camss.c new file +129 -0
+		stfcamss->sys_rst[i].id = stfcamss_resets[i];
+	ret = devm_reset_control_bulk_get_shared(dev, stfcamss->nrsts,
+						 stfcamss->sys_rst);
+	if (ret) {
+		dev_err(dev, "Failed to get reset controls\n");
+		return ret;
+	}
+
+	ret = stfcamss_get_mem_res(pdev, stfcamss);
+	if (ret) {
+		dev_err(dev, "Could not map registers\n");
+		return ret;
+	}
+
+	stfcamss->dev = dev;
+	platform_set_drvdata(pdev, stfcamss);
+
+	v4l2_async_nf_init(&stfcamss->notifier);
+
+	num_subdevs = stfcamss_of_parse_ports(stfcamss);
+	if (num_subdevs < 0) {
+		dev_err(dev, "Failed to find subdevices\n");
+		return -ENODEV;
+	}
+
+	stfcamss_mc_init(pdev, stfcamss);
+
+	ret = v4l2_device_register(stfcamss->dev, &stfcamss->v4l2_dev);
+	if (ret < 0) {
+		dev_err(dev, "Failed to register V4L2 device: %d\n", ret);
+		goto err_cleanup_notifier;
+	}
+
+	ret = media_device_register(&stfcamss->media_dev);
+	if (ret) {
+		dev_err(dev, "Failed to register media device: %d\n", ret);
+		goto err_unregister_device;
+	}
+
+	stfcamss->notifier.ops = &stfcamss_subdev_notifier_ops;
+	ret = v4l2_async_nf_register(&stfcamss->v4l2_dev, &stfcamss->notifier);
+	if (ret) {
+		dev_err(dev, "Failed to register async subdev nodes: %d\n",
+			ret);
+		goto err_unregister_media_dev;
+	}
+
+	pm_runtime_enable(dev);
+
+	return 0;
+
+err_unregister_media_dev:
+	media_device_unregister(&stfcamss->media_dev);
+err_unregister_device:
+	v4l2_device_unregister(&stfcamss->v4l2_dev);
+err_cleanup_notifier:
+	v4l2_async_nf_cleanup(&stfcamss->notifier);
+	return ret;
+}
+
+/*
+ * stfcamss_remove - Remove STFCAMSS platform device
+ * @pdev: Pointer to STFCAMSS platform device
+ *
+ * Always returns 0.
+ */
+static int stfcamss_remove(struct platform_device *pdev)
+{
+	struct stfcamss *stfcamss = platform_get_drvdata(pdev);
+
+	v4l2_device_unregister(&stfcamss->v4l2_dev);
+	media_device_cleanup(&stfcamss->media_dev);
+	pm_runtime_disable(&pdev->dev);
+
+	return 0;
+}
+
+static const struct of_device_id stfcamss_of_match[] = {
+	{ .compatible = "starfive,jh7110-camss" },
+	{ /* sentinel */ },
+};
+
+MODULE_DEVICE_TABLE(of, stfcamss_of_match);
+
+static int __maybe_unused stfcamss_runtime_suspend(struct device *dev)
+{
+	struct stfcamss *stfcamss = dev_get_drvdata(dev);
+
+	reset_control_assert(stfcamss->sys_rst[STF_RST_ISP_TOP_AXI].rstc);
+	reset_control_assert(stfcamss->sys_rst[STF_RST_ISP_TOP_N].rstc);
+	clk_disable_unprepare(stfcamss->sys_clk[STF_CLK_ISP_AXI].clk);
+	clk_disable_unprepare(stfcamss->sys_clk[STF_CLK_ISPCORE_2X].clk);
+
+	return 0;
+}
+
+static int __maybe_unused stfcamss_runtime_resume(struct device *dev)
+{
+	struct stfcamss *stfcamss = dev_get_drvdata(dev);
+
+	clk_prepare_enable(stfcamss->sys_clk[STF_CLK_ISPCORE_2X].clk);
+	clk_prepare_enable(stfcamss->sys_clk[STF_CLK_ISP_AXI].clk);
+	reset_control_deassert(stfcamss->sys_rst[STF_RST_ISP_TOP_N].rstc);
+	reset_control_deassert(stfcamss->sys_rst[STF_RST_ISP_TOP_AXI].rstc);
+
+	return 0;
+}
+
+static const struct dev_pm_ops stfcamss_pm_ops = {
+	SET_RUNTIME_PM_OPS(stfcamss_runtime_suspend,
+			   stfcamss_runtime_resume,
+			   NULL)
+};
+
+static struct platform_driver stfcamss_driver = {
+	.probe = stfcamss_probe,
+	.remove = stfcamss_remove,
+	.driver = {
+		.name = DRV_NAME,
+		.pm = &stfcamss_pm_ops,
+		.of_match_table = of_match_ptr(stfcamss_of_match),
+	},
+};
+
+module_platform_driver(stfcamss_driver);
+
+MODULE_AUTHOR("StarFive Corporation");
+MODULE_DESCRIPTION("StarFive Camera Subsystem driver");
+MODULE_LICENSE("GPL");
drivers/media/platform/starfive/stf_camss.h new file +153 -0
new file mode 100644
index 000000000000..8f39cd65950c
@@ -0,0 +1,153 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * stf_camss.h
+ *
+ * Starfive Camera Subsystem driver
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+
+#ifndef STF_CAMSS_H
+#define STF_CAMSS_H
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/reset.h>
+#include <media/v4l2-device.h>
+
+#include "stf_common.h"
+
+#define DRV_NAME     "starfive-camss"
+#define STF_DVP_NAME "stf_dvp"
+#define STF_CSI_NAME "cdns_csi2rx"
+#define STF_ISP_NAME "stf_isp"
+#define STF_VIN_NAME "stf_vin"
+
+#define STF_PAD_SINK   0
+#define STF_PAD_SRC    1
+#define STF_PADS_NUM   2
+
+enum port_num {
+	PORT_NUMBER_DVP_SENSOR = 0,
+	PORT_NUMBER_CSI2RX
+};
+
+enum stf_clk {
+	STF_CLK_APB_FUNC = 0,
+	STF_CLK_WRAPPER_CLK_C,
+	STF_CLK_DVP_INV,
+	STF_CLK_AXIWR,
+	STF_CLK_MIPI_RX0_PXL,
+	STF_CLK_ISPCORE_2X,
+	STF_CLK_ISP_AXI,
+	STF_CLK_NUM
+};
+
+enum stf_rst {
+	STF_RST_WRAPPER_P = 0,
+	STF_RST_WRAPPER_C,
+	STF_RST_AXIRD,
+	STF_RST_AXIWR,
+	STF_RST_ISP_TOP_N,
+	STF_RST_ISP_TOP_AXI,
+	STF_RST_NUM
+};
+
+enum stf_irq {
+	STF_IRQ_VINWR = 0,
+	STF_IRQ_ISP,
+	STF_IRQ_ISPCSIL,
+	STF_IRQ_NUM
+};
+
+#define HOST_ENTITY_MAX		2
+
+struct host_data {
+	struct media_entity *host_entity[HOST_ENTITY_MAX];
+};
+
+struct stfcamss {
+	struct v4l2_device v4l2_dev;
+	struct media_device media_dev;
+	struct media_pipeline pipe;
+	struct device *dev;
+	struct v4l2_async_notifier notifier;
+	struct host_data host_data;
+	void __iomem *syscon_base;
+	void __iomem *isp_base;
+	int irq[STF_IRQ_NUM];
+	struct clk_bulk_data sys_clk[STF_CLK_NUM];
+	int nclks;
+	struct reset_control_bulk_data sys_rst[STF_RST_NUM];
+	int nrsts;
+};
+
+struct stfcamss_async_subdev {
+	struct v4l2_async_subdev asd;  /* must be first */
+	enum port_num port;
+};
+
+static inline u32 stf_isp_reg_read(struct stfcamss *stfcamss, u32 reg)
+{
+	return ioread32(stfcamss->isp_base + reg);
+}
+
+static inline void stf_isp_reg_write(struct stfcamss *stfcamss,
+				     u32 reg, u32 val)
+{
+	iowrite32(val, stfcamss->isp_base + reg);
+}
+
+static inline void stf_isp_reg_write_delay(struct stfcamss *stfcamss,
+					   u32 reg, u32 val, u32 delay)
+{
+	iowrite32(val, stfcamss->isp_base + reg);
+	usleep_range(1000 * delay, 1000 * delay + 100);
+}
+
+static inline void stf_isp_reg_set_bit(struct stfcamss *stfcamss,
+				       u32 reg, u32 mask, u32 val)
+{
+	u32 value;
+
+	value = ioread32(stfcamss->isp_base + reg) & ~mask;
+	val &= mask;
+	val |= value;
+	iowrite32(val, stfcamss->isp_base + reg);
+}
+
+static inline void stf_isp_reg_set(struct stfcamss *stfcamss, u32 reg, u32 mask)
+{
+	iowrite32(ioread32(stfcamss->isp_base + reg) | mask,
+		  stfcamss->isp_base + reg);
+}
+
+static inline u32 stf_syscon_reg_read(struct stfcamss *stfcamss, u32 reg)
+{
+	return ioread32(stfcamss->syscon_base + reg);
+}
+
+static inline void stf_syscon_reg_write(struct stfcamss *stfcamss,
+					u32 reg, u32 val)
+{
+	iowrite32(val, stfcamss->syscon_base + reg);
+}
+
+static inline void stf_syscon_reg_set_bit(struct stfcamss *stfcamss,
+					  u32 reg, u32 bit_mask)
+{
+	u32 value;
+
+	value = ioread32(stfcamss->syscon_base + reg);
+	iowrite32(value | bit_mask, stfcamss->syscon_base + reg);
+}
+
+static inline void stf_syscon_reg_clear_bit(struct stfcamss *stfcamss,
+					    u32 reg, u32 bit_mask)
+{
+	u32 value;
+
+	value = ioread32(stfcamss->syscon_base + reg);
+	iowrite32(value & ~bit_mask, stfcamss->syscon_base + reg);
+}
+#endif /* STF_CAMSS_H */
drivers/media/platform/starfive/stf_common.h new file +18 -0
new file mode 100644
index 000000000000..e04fca2d9cd4
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * stf_common.h
+ *
+ * StarFive Camera Subsystem - Common definitions
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+
+#ifndef STF_COMMON_H
+#define STF_COMMON_H
+
+enum stf_subdev_type {
+	STF_SUBDEV_TYPE_VIN,
+	STF_SUBDEV_TYPE_ISP,
+};
+
+#endif /* STF_COMMON_H */
author
#9 lore raw

Re: [PATCH v5 3/6] media: starfive: Add basic driver

Quoted 336 lines · Bryan O'Donoghue
Quoted 3 lines · Jack Zhu

Add basic platform driver for StarFive Camera Subsystem.

A couple of nits below

Other than those

Quoted 325 lines

---
  MAINTAINERS                                  |   1 + drivers/media/platform/Kconfig               |   1 + drivers/media/platform/Makefile              |   1 + drivers/media/platform/starfive/Kconfig      |  19 + drivers/media/platform/starfive/Makefile     |   9 + drivers/media/platform/starfive/stf_camss.c  | 372 +++++++++++++++++++ drivers/media/platform/starfive/stf_camss.h  | 153 ++++++++ drivers/media/platform/starfive/stf_common.h |  18 +

  8 files changed, 574 insertions(+)

  create mode 100644 drivers/media/platform/starfive/Kconfig create mode 100644 drivers/media/platform/starfive/Makefile create mode 100644 drivers/media/platform/starfive/stf_camss.c create mode 100644 drivers/media/platform/starfive/stf_camss.h create mode 100644 drivers/media/platform/starfive/stf_common.h

MAINTAINERS +0 -0
index 71291dc58671..33a752569942 100644
@@ -20077,6 +20077,7 @@ L:    [email protected]

  S:    Maintained
  F:    Documentation/admin-guide/media/starfive_camss.rst
  F:    Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml +F:    drivers/media/platform/starfive/
    STARFIVE DEVICETREES
  M:    Emil Renner Berthing <[email protected]>

drivers/media/platform/Kconfig +0 -0
index ee579916f874..627eaa0ab3ee 100644
@@ -80,6 +80,7 @@ source "drivers/media/platform/renesas/Kconfig"

  source "drivers/media/platform/rockchip/Kconfig" source "drivers/media/platform/samsung/Kconfig" source "drivers/media/platform/st/Kconfig" +source "drivers/media/platform/starfive/Kconfig" source "drivers/media/platform/sunxi/Kconfig" source "drivers/media/platform/ti/Kconfig" source "drivers/media/platform/verisilicon/Kconfig"

drivers/media/platform/Makefile +0 -0
index 5453bb868e67..5a038498a370 100644
@@ -23,6 +23,7 @@ obj-y += renesas/

  obj-y += rockchip/
  obj-y += samsung/
  obj-y += st/
+obj-y += starfive/
  obj-y += sunxi/
  obj-y += ti/
  obj-y += verisilicon/

drivers/media/platform/starfive/Kconfig new file +19 -0
new file mode 100644
index 000000000000..1a2293475bd2
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+comment "Starfive media platform drivers"
+
+config VIDEO_STARFIVE_CAMSS
+    tristate "Starfive Camera Subsystem driver"
+    depends on V4L_PLATFORM_DRIVERS
+    depends on VIDEO_DEV && OF
+    depends on DMA_CMA
+    select MEDIA_CONTROLLER
+    select VIDEO_V4L2_SUBDEV_API
+    select VIDEOBUF2_DMA_CONTIG
+    select V4L2_FWNODE
+    help
+       Enable this to support for the Starfive Camera subsystem
+       found on Starfive JH7110 SoC.
+
+       To compile this driver as a module, choose M here: the
+       module will be called stf-camss.
drivers/media/platform/starfive/Makefile new file +9 -0
new file mode 100644
index 000000000000..796775fa52f4
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for StarFive camera subsystem driver.
+#
+
+starfive-camss-objs += \
+        stf_camss.o
+
+obj-$(CONFIG_VIDEO_STARFIVE_CAMSS) += starfive-camss.o \
drivers/media/platform/starfive/stf_camss.c new file +228 -0
new file mode 100644
index 000000000000..ba3a2bc8a8ab
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * stf_camss.c
+ *
+ * Starfive Camera Subsystem driver
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/videodev2.h>
+#include <media/media-device.h>
+#include <media/v4l2-async.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-mc.h>
+
+#include "stf_camss.h"
+
+static const char * const stfcamss_clocks[] = {
+    "clk_apb_func",
+    "clk_wrapper_clk_c",
+    "clk_dvp_inv",
+    "clk_axiwr",
+    "clk_mipi_rx0_pxl",
+    "clk_ispcore_2x",
+    "clk_isp_axi",
+};
+
+static const char * const stfcamss_resets[] = {
+    "rst_wrapper_p",
+    "rst_wrapper_c",
+    "rst_axird",
+    "rst_axiwr",
+    "rst_isp_top_n",
+    "rst_isp_top_axi",
+};
+
+static int stfcamss_get_mem_res(struct platform_device *pdev,
+                struct stfcamss *stfcamss)
+{
+    stfcamss->syscon_base =
+        devm_platform_ioremap_resource_byname(pdev, "syscon");
+    if (IS_ERR(stfcamss->syscon_base))
+        return PTR_ERR(stfcamss->syscon_base);
+
+    stfcamss->isp_base =
+        devm_platform_ioremap_resource_byname(pdev, "isp");
+    if (IS_ERR(stfcamss->isp_base))
+        return PTR_ERR(stfcamss->isp_base);
+
+    return 0;
+}
+
+/*
+ * stfcamss_of_parse_endpoint_node - Parse port endpoint node
+ * @dev: Device
+ * @node: Device node to be parsed
+ * @csd: Parsed data from port endpoint node
+ *
+ * Return 0 on success or a negative error code on failure
+ */
+static int stfcamss_of_parse_endpoint_node(struct device *dev,
+                       struct device_node *node,
+                       struct stfcamss_async_subdev *csd)
+{
+    struct v4l2_fwnode_endpoint vep = { { 0 } };
+
+    v4l2_fwnode_endpoint_parse(of_fwnode_handle(node), &vep);
+    dev_dbg(dev, "vep.base.port = 0x%x, id = 0x%x\n",
+        vep.base.port, vep.base.id);
+
+    csd->port = vep.base.port;
+
+    return 0;
+}
+
+/*
+ * stfcamss_of_parse_ports - Parse ports node
+ * @stfcamss: STFCAMSS device
+ *
+ * Return number of "port" nodes found in "ports" node
+ */
+static int stfcamss_of_parse_ports(struct stfcamss *stfcamss)
+{
+    struct device *dev = stfcamss->dev;
+    struct device_node *node = NULL;
+    struct device_node *remote = NULL;
+    int ret, num_subdevs = 0;
+
+    for_each_endpoint_of_node(dev->of_node, node) {
+        struct stfcamss_async_subdev *csd;
+
+        if (!of_device_is_available(node))
+            continue;
+
+        remote = of_graph_get_remote_port_parent(node);
+        if (!remote) {
+            dev_err(dev, "Cannot get remote parent\n");
+            ret = -EINVAL;
+            goto err_cleanup;
+        }
+
+        csd = v4l2_async_nf_add_fwnode(&stfcamss->notifier,
+                           of_fwnode_handle(remote),
+                           struct stfcamss_async_subdev);
+        of_node_put(remote);
+        if (IS_ERR(csd)) {
+            ret = PTR_ERR(csd);
+            goto err_cleanup;
+        }
+
+        ret = stfcamss_of_parse_endpoint_node(dev, node, csd);
+        if (ret < 0)
+            goto err_cleanup;
+
+        num_subdevs++;
+    }
+
+    return num_subdevs;
+
+err_cleanup:
+    of_node_put(node);
+    return ret;
+}
+
+static int stfcamss_subdev_notifier_bound(struct v4l2_async_notifier *async,
+                      struct v4l2_subdev *subdev,
+                      struct v4l2_async_subdev *asd)
+{
+    struct stfcamss *stfcamss =
+        container_of(async, struct stfcamss, notifier);
+    struct host_data *host_data = &stfcamss->host_data;
+    struct media_entity *source;
+    int i, j;
+
+    source = &subdev->entity;
+
+    for (i = 0; i < source->num_pads; i++) {
+        if (source->pads[i].flags & MEDIA_PAD_FL_SOURCE)
+            break;
+    }
+
+    if (i == source->num_pads) {
+        dev_err(stfcamss->dev, "No source pad in external entity\n");
+        return -EINVAL;
+    }
+
+    for (j = 0; host_data->host_entity[j] && (j < HOST_ENTITY_MAX); j++) {
+        struct media_entity *input;
+        int ret;
+
+        input = host_data->host_entity[j];
+
+        ret = media_create_pad_link(
+            source,
+            i,
+            input,
+            STF_PAD_SINK,
+            source->function == MEDIA_ENT_F_CAM_SENSOR ?
+            MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED :
+            0);
+        if (ret < 0) {
+            dev_err(stfcamss->dev,
+                "Failed to link %s->%s entities: %d\n",
+                source->name, input->name, ret);
+            return ret;
+        }
+    }
+
+    return 0;
+}
+
+static int stfcamss_subdev_notifier_complete(struct v4l2_async_notifier *ntf)
+{
+    struct stfcamss *stfcamss =
+        container_of(ntf, struct stfcamss, notifier);
+
+    return v4l2_device_register_subdev_nodes(&stfcamss->v4l2_dev);
+}
+
+static const struct v4l2_async_notifier_operations
+stfcamss_subdev_notifier_ops = {
+    .bound = stfcamss_subdev_notifier_bound,
+    .complete = stfcamss_subdev_notifier_complete,
+};
+
+static const struct media_device_ops stfcamss_media_ops = {
+    .link_notify = v4l2_pipeline_link_notify,
+};
+
+static void stfcamss_mc_init(struct platform_device *pdev,
+                 struct stfcamss *stfcamss)
+{
+    stfcamss->media_dev.dev = stfcamss->dev;
+    strscpy(stfcamss->media_dev.model, "Starfive Camera Subsystem",
+        sizeof(stfcamss->media_dev.model));
+    snprintf(stfcamss->media_dev.bus_info,
+         sizeof(stfcamss->media_dev.bus_info),
+         "%s:%s", dev_bus_name(&pdev->dev), pdev->name);
+    stfcamss->media_dev.hw_revision = 0x01;
+    stfcamss->media_dev.ops = &stfcamss_media_ops;
+    media_device_init(&stfcamss->media_dev);
+
+    stfcamss->v4l2_dev.mdev = &stfcamss->media_dev;
+}
+
+/*
+ * stfcamss_probe - Probe STFCAMSS platform device
+ * @pdev: Pointer to STFCAMSS platform device
+ *
+ * Return 0 on success or a negative error code on failure
+ */
+static int stfcamss_probe(struct platform_device *pdev)
+{
+    struct stfcamss *stfcamss;
+    struct device *dev = &pdev->dev;
+    int ret = 0, i, num_subdevs;
+
+    stfcamss = devm_kzalloc(dev, sizeof(*stfcamss), GFP_KERNEL);
+    if (!stfcamss)
+        return -ENOMEM;
+
+    for (i = 0; i < ARRAY_SIZE(stfcamss->irq); ++i) {
+        stfcamss->irq[i] = platform_get_irq(pdev, i);
+        if (stfcamss->irq[i] < 0)
Quoted 8 lines

drivers/media/platform/starfive/stf_camss.c line 234

Quoted 6 lines
drivers/media/platform/starfive/stf_camss.c new file +6 -0
+            return dev_err_probe(&pdev->dev, stfcamss->irq[i],
+                         "Failed to get clock%d", i);
+    }
+
+    stfcamss->nclks = ARRAY_SIZE(stfcamss->sys_clk);
+    for (i = 0; i < ARRAY_SIZE(stfcamss->sys_clk); ++i)

Why use ARRAY_SIZE twice - you just derived stfcamss->nclks

OK, will use stfcamss->nclks. Thank you for your review.

Quoted 11 lines

drivers/media/platform/starfive/stf_camss.c line 243

Quoted 10 lines
drivers/media/platform/starfive/stf_camss.c new file +9 -0
+        stfcamss->sys_clk[i].id = stfcamss_clocks[i];
+    ret = devm_clk_bulk_get(dev, stfcamss->nclks, stfcamss->sys_clk);
+    if (ret) {
+        dev_err(dev, "Failed to get clk controls\n");
+        return ret;
+    }
+
+    stfcamss->nrsts = ARRAY_SIZE(stfcamss->sys_rst);
+    for (i = 0; i < ARRAY_SIZE(stfcamss->sys_rst); ++i)
Quoted 1 line

i < stfcamss->nrsts

OK, will fix it. Thanks!

Quoted 314 lines
Quoted 313 lines
drivers/media/platform/starfive/stf_camss.c new file +129 -0
+        stfcamss->sys_rst[i].id = stfcamss_resets[i];
+    ret = devm_reset_control_bulk_get_shared(dev, stfcamss->nrsts,
+                         stfcamss->sys_rst);
+    if (ret) {
+        dev_err(dev, "Failed to get reset controls\n");
+        return ret;
+    }
+
+    ret = stfcamss_get_mem_res(pdev, stfcamss);
+    if (ret) {
+        dev_err(dev, "Could not map registers\n");
+        return ret;
+    }
+
+    stfcamss->dev = dev;
+    platform_set_drvdata(pdev, stfcamss);
+
+    v4l2_async_nf_init(&stfcamss->notifier);
+
+    num_subdevs = stfcamss_of_parse_ports(stfcamss);
+    if (num_subdevs < 0) {
+        dev_err(dev, "Failed to find subdevices\n");
+        return -ENODEV;
+    }
+
+    stfcamss_mc_init(pdev, stfcamss);
+
+    ret = v4l2_device_register(stfcamss->dev, &stfcamss->v4l2_dev);
+    if (ret < 0) {
+        dev_err(dev, "Failed to register V4L2 device: %d\n", ret);
+        goto err_cleanup_notifier;
+    }
+
+    ret = media_device_register(&stfcamss->media_dev);
+    if (ret) {
+        dev_err(dev, "Failed to register media device: %d\n", ret);
+        goto err_unregister_device;
+    }
+
+    stfcamss->notifier.ops = &stfcamss_subdev_notifier_ops;
+    ret = v4l2_async_nf_register(&stfcamss->v4l2_dev, &stfcamss->notifier);
+    if (ret) {
+        dev_err(dev, "Failed to register async subdev nodes: %d\n",
+            ret);
+        goto err_unregister_media_dev;
+    }
+
+    pm_runtime_enable(dev);
+
+    return 0;
+
+err_unregister_media_dev:
+    media_device_unregister(&stfcamss->media_dev);
+err_unregister_device:
+    v4l2_device_unregister(&stfcamss->v4l2_dev);
+err_cleanup_notifier:
+    v4l2_async_nf_cleanup(&stfcamss->notifier);
+    return ret;
+}
+
+/*
+ * stfcamss_remove - Remove STFCAMSS platform device
+ * @pdev: Pointer to STFCAMSS platform device
+ *
+ * Always returns 0.
+ */
+static int stfcamss_remove(struct platform_device *pdev)
+{
+    struct stfcamss *stfcamss = platform_get_drvdata(pdev);
+
+    v4l2_device_unregister(&stfcamss->v4l2_dev);
+    media_device_cleanup(&stfcamss->media_dev);
+    pm_runtime_disable(&pdev->dev);
+
+    return 0;
+}
+
+static const struct of_device_id stfcamss_of_match[] = {
+    { .compatible = "starfive,jh7110-camss" },
+    { /* sentinel */ },
+};
+
+MODULE_DEVICE_TABLE(of, stfcamss_of_match);
+
+static int __maybe_unused stfcamss_runtime_suspend(struct device *dev)
+{
+    struct stfcamss *stfcamss = dev_get_drvdata(dev);
+
+    reset_control_assert(stfcamss->sys_rst[STF_RST_ISP_TOP_AXI].rstc);
+    reset_control_assert(stfcamss->sys_rst[STF_RST_ISP_TOP_N].rstc);
+    clk_disable_unprepare(stfcamss->sys_clk[STF_CLK_ISP_AXI].clk);
+    clk_disable_unprepare(stfcamss->sys_clk[STF_CLK_ISPCORE_2X].clk);
+
+    return 0;
+}
+
+static int __maybe_unused stfcamss_runtime_resume(struct device *dev)
+{
+    struct stfcamss *stfcamss = dev_get_drvdata(dev);
+
+    clk_prepare_enable(stfcamss->sys_clk[STF_CLK_ISPCORE_2X].clk);
+    clk_prepare_enable(stfcamss->sys_clk[STF_CLK_ISP_AXI].clk);
+    reset_control_deassert(stfcamss->sys_rst[STF_RST_ISP_TOP_N].rstc);
+    reset_control_deassert(stfcamss->sys_rst[STF_RST_ISP_TOP_AXI].rstc);
+
+    return 0;
+}
+
+static const struct dev_pm_ops stfcamss_pm_ops = {
+    SET_RUNTIME_PM_OPS(stfcamss_runtime_suspend,
+               stfcamss_runtime_resume,
+               NULL)
+};
+
+static struct platform_driver stfcamss_driver = {
+    .probe = stfcamss_probe,
+    .remove = stfcamss_remove,
+    .driver = {
+        .name = DRV_NAME,
+        .pm = &stfcamss_pm_ops,
+        .of_match_table = of_match_ptr(stfcamss_of_match),
+    },
+};
+
+module_platform_driver(stfcamss_driver);
+
+MODULE_AUTHOR("StarFive Corporation");
+MODULE_DESCRIPTION("StarFive Camera Subsystem driver");
+MODULE_LICENSE("GPL");
drivers/media/platform/starfive/stf_camss.h new file +153 -0
new file mode 100644
index 000000000000..8f39cd65950c
@@ -0,0 +1,153 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * stf_camss.h
+ *
+ * Starfive Camera Subsystem driver
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+
+#ifndef STF_CAMSS_H
+#define STF_CAMSS_H
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/reset.h>
+#include <media/v4l2-device.h>
+
+#include "stf_common.h"
+
+#define DRV_NAME     "starfive-camss"
+#define STF_DVP_NAME "stf_dvp"
+#define STF_CSI_NAME "cdns_csi2rx"
+#define STF_ISP_NAME "stf_isp"
+#define STF_VIN_NAME "stf_vin"
+
+#define STF_PAD_SINK   0
+#define STF_PAD_SRC    1
+#define STF_PADS_NUM   2
+
+enum port_num {
+    PORT_NUMBER_DVP_SENSOR = 0,
+    PORT_NUMBER_CSI2RX
+};
+
+enum stf_clk {
+    STF_CLK_APB_FUNC = 0,
+    STF_CLK_WRAPPER_CLK_C,
+    STF_CLK_DVP_INV,
+    STF_CLK_AXIWR,
+    STF_CLK_MIPI_RX0_PXL,
+    STF_CLK_ISPCORE_2X,
+    STF_CLK_ISP_AXI,
+    STF_CLK_NUM
+};
+
+enum stf_rst {
+    STF_RST_WRAPPER_P = 0,
+    STF_RST_WRAPPER_C,
+    STF_RST_AXIRD,
+    STF_RST_AXIWR,
+    STF_RST_ISP_TOP_N,
+    STF_RST_ISP_TOP_AXI,
+    STF_RST_NUM
+};
+
+enum stf_irq {
+    STF_IRQ_VINWR = 0,
+    STF_IRQ_ISP,
+    STF_IRQ_ISPCSIL,
+    STF_IRQ_NUM
+};
+
+#define HOST_ENTITY_MAX        2
+
+struct host_data {
+    struct media_entity *host_entity[HOST_ENTITY_MAX];
+};
+
+struct stfcamss {
+    struct v4l2_device v4l2_dev;
+    struct media_device media_dev;
+    struct media_pipeline pipe;
+    struct device *dev;
+    struct v4l2_async_notifier notifier;
+    struct host_data host_data;
+    void __iomem *syscon_base;
+    void __iomem *isp_base;
+    int irq[STF_IRQ_NUM];
+    struct clk_bulk_data sys_clk[STF_CLK_NUM];
+    int nclks;
+    struct reset_control_bulk_data sys_rst[STF_RST_NUM];
+    int nrsts;
+};
+
+struct stfcamss_async_subdev {
+    struct v4l2_async_subdev asd;  /* must be first */
+    enum port_num port;
+};
+
+static inline u32 stf_isp_reg_read(struct stfcamss *stfcamss, u32 reg)
+{
+    return ioread32(stfcamss->isp_base + reg);
+}
+
+static inline void stf_isp_reg_write(struct stfcamss *stfcamss,
+                     u32 reg, u32 val)
+{
+    iowrite32(val, stfcamss->isp_base + reg);
+}
+
+static inline void stf_isp_reg_write_delay(struct stfcamss *stfcamss,
+                       u32 reg, u32 val, u32 delay)
+{
+    iowrite32(val, stfcamss->isp_base + reg);
+    usleep_range(1000 * delay, 1000 * delay + 100);
+}
+
+static inline void stf_isp_reg_set_bit(struct stfcamss *stfcamss,
+                       u32 reg, u32 mask, u32 val)
+{
+    u32 value;
+
+    value = ioread32(stfcamss->isp_base + reg) & ~mask;
+    val &= mask;
+    val |= value;
+    iowrite32(val, stfcamss->isp_base + reg);
+}
+
+static inline void stf_isp_reg_set(struct stfcamss *stfcamss, u32 reg, u32 mask)
+{
+    iowrite32(ioread32(stfcamss->isp_base + reg) | mask,
+          stfcamss->isp_base + reg);
+}
+
+static inline u32 stf_syscon_reg_read(struct stfcamss *stfcamss, u32 reg)
+{
+    return ioread32(stfcamss->syscon_base + reg);
+}
+
+static inline void stf_syscon_reg_write(struct stfcamss *stfcamss,
+                    u32 reg, u32 val)
+{
+    iowrite32(val, stfcamss->syscon_base + reg);
+}
+
+static inline void stf_syscon_reg_set_bit(struct stfcamss *stfcamss,
+                      u32 reg, u32 bit_mask)
+{
+    u32 value;
+
+    value = ioread32(stfcamss->syscon_base + reg);
+    iowrite32(value | bit_mask, stfcamss->syscon_base + reg);
+}
+
+static inline void stf_syscon_reg_clear_bit(struct stfcamss *stfcamss,
+                        u32 reg, u32 bit_mask)
+{
+    u32 value;
+
+    value = ioread32(stfcamss->syscon_base + reg);
+    iowrite32(value & ~bit_mask, stfcamss->syscon_base + reg);
+}
+#endif /* STF_CAMSS_H */
drivers/media/platform/starfive/stf_common.h new file +18 -0
new file mode 100644
index 000000000000..e04fca2d9cd4
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * stf_common.h
+ *
+ * StarFive Camera Subsystem - Common definitions
+ *
+ * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
+ */
+
+#ifndef STF_COMMON_H
+#define STF_COMMON_H
+
+enum stf_subdev_type {
+    STF_SUBDEV_TYPE_VIN,
+    STF_SUBDEV_TYPE_ISP,
+};
+
+#endif /* STF_COMMON_H */
author
#10 lore raw

PATCH v5 4/6 media: starfive: Add video driver

In reply to Jack Zhu

Add video driver for StarFive Camera Subsystem.

---
 drivers/media/platform/starfive/Makefile    |   3 +-
 drivers/media/platform/starfive/stf_video.c | 864 ++++++++++++++++++++
 drivers/media/platform/starfive/stf_video.h |  95 +++
 3 files changed, 961 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/platform/starfive/stf_video.c
 create mode 100644 drivers/media/platform/starfive/stf_video.h
drivers/media/platform/starfive/Makefile +2 -1
index 796775fa52f4..d7a42b3a938c 100644
@@ -4,6 +4,7 @@
 #
 
 starfive-camss-objs += \
-		stf_camss.o
+		stf_camss.o \
+		stf_video.o
 
 obj-$(CONFIG_VIDEO_STARFIVE_CAMSS) += starfive-camss.o \
drivers/media/platform/starfive/stf_video.c new file +864 -0

864 lines not on this page · raw message

drivers/media/platform/starfive/stf_video.h new file +95 -0

95 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#11 lore raw

PATCH v5 5/6 media: starfive: Add ISP driver

In reply to Jack Zhu

Add ISP driver for StarFive Camera Subsystem.

---
 drivers/media/platform/starfive/Makefile      |   2 +
 drivers/media/platform/starfive/stf_camss.c   |  71 ++-
 drivers/media/platform/starfive/stf_camss.h   |   2 +
 drivers/media/platform/starfive/stf_isp.c     | 550 ++++++++++++++++++
 drivers/media/platform/starfive/stf_isp.h     | 476 +++++++++++++++
 .../media/platform/starfive/stf_isp_hw_ops.c  | 452 ++++++++++++++
 6 files changed, 1551 insertions(+), 2 deletions(-)
 create mode 100644 drivers/media/platform/starfive/stf_isp.c
 create mode 100644 drivers/media/platform/starfive/stf_isp.h
 create mode 100644 drivers/media/platform/starfive/stf_isp_hw_ops.c
drivers/media/platform/starfive/Makefile +2 -0
index d7a42b3a938c..60a3018f4994 100644
@@ -5,6 +5,8 @@
 
 starfive-camss-objs += \
 		stf_camss.o \
+		stf_isp.o \
+		stf_isp_hw_ops.o \
 		stf_video.o
 
 obj-$(CONFIG_VIDEO_STARFIVE_CAMSS) += starfive-camss.o \
drivers/media/platform/starfive/stf_camss.c +69 -2

125 lines not on this page · raw message

drivers/media/platform/starfive/stf_camss.h +2 -0
index 8f39cd65950c..c9d94be92ea8 100644
@@ -16,6 +16,7 @@
 #include <media/v4l2-device.h>
 
 #include "stf_common.h"
+#include "stf_isp.h"
 
 #define DRV_NAME     "starfive-camss"
 #define STF_DVP_NAME "stf_dvp"
@@ -71,6 +72,7 @@ struct stfcamss {
 	struct media_device media_dev;
 	struct media_pipeline pipe;
 	struct device *dev;
+	struct stf_isp_dev isp_dev;
 	struct v4l2_async_notifier notifier;
 	struct host_data host_data;
 	void __iomem *syscon_base;
drivers/media/platform/starfive/stf_isp.c new file +550 -0

550 lines not on this page · raw message

drivers/media/platform/starfive/stf_isp.h new file +476 -0

476 lines not on this page · raw message

drivers/media/platform/starfive/stf_isp_hw_ops.c new file +452 -0

452 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#12 lore raw

PATCH v5 6/6 media: starfive: Add VIN driver

In reply to Jack Zhu

Add Video In Controller driver for StarFive Camera Subsystem.

---
 drivers/media/platform/starfive/Makefile      |    4 +-
 drivers/media/platform/starfive/stf_camss.c   |   39 +-
 drivers/media/platform/starfive/stf_camss.h   |    2 +
 drivers/media/platform/starfive/stf_vin.c     | 1134 +++++++++++++++++
 drivers/media/platform/starfive/stf_vin.h     |  180 +++
 .../media/platform/starfive/stf_vin_hw_ops.c  |  241 ++++
 6 files changed, 1598 insertions(+), 2 deletions(-)
 create mode 100644 drivers/media/platform/starfive/stf_vin.c
 create mode 100644 drivers/media/platform/starfive/stf_vin.h
 create mode 100644 drivers/media/platform/starfive/stf_vin_hw_ops.c
drivers/media/platform/starfive/Makefile +3 -1
index 60a3018f4994..bf497dd24bbb 100644
@@ -7,6 +7,8 @@ starfive-camss-objs += \
 		stf_camss.o \
 		stf_isp.o \
 		stf_isp_hw_ops.o \
-		stf_video.o
+		stf_video.o \
+		stf_vin.o \
+		stf_vin_hw_ops.o
 
 obj-$(CONFIG_VIDEO_STARFIVE_CAMSS) += starfive-camss.o \
drivers/media/platform/starfive/stf_camss.c +38 -1
index 7ae9a827daa1..926315fce7fe 100644
@@ -142,27 +142,61 @@ static int stfcamss_init_subdevices(struct stfcamss *stfcamss)
 		return ret;
 	}
 
+	ret = stf_vin_subdev_init(stfcamss);
+	if (ret < 0) {
+		dev_err(stfcamss->dev, "Failed to init vin subdev: %d\n", ret);
+		return ret;
+	}
 	return ret;
 }
 
 static int stfcamss_register_subdevices(struct stfcamss *stfcamss)
 {
 	int ret;
+	struct stf_vin_dev *vin_dev = &stfcamss->vin_dev;
 	struct stf_isp_dev *isp_dev = &stfcamss->isp_dev;
 
 	ret = stf_isp_register(isp_dev, &stfcamss->v4l2_dev);
 	if (ret < 0) {
 		dev_err(stfcamss->dev,
 			"Failed to register stf isp%d entity: %d\n", 0, ret);
-		return ret;
+		goto err_reg_isp;
+	}
+
+	ret = stf_vin_register(vin_dev, &stfcamss->v4l2_dev);
+	if (ret < 0) {
+		dev_err(stfcamss->dev,
+			"Failed to register vin entity: %d\n", ret);
+		goto err_reg_vin;
 	}
 
+	ret = media_create_pad_link(&isp_dev->subdev.entity,
+				    STF_ISP_PAD_SRC,
+				    &vin_dev->line[VIN_LINE_ISP].subdev.entity,
+				    STF_VIN_PAD_SINK,
+				    0);
+	if (ret < 0) {
+		dev_err(stfcamss->dev,
+			"Failed to link %s->%s entities: %d\n",
+			isp_dev->subdev.entity.name,
+			vin_dev->line[VIN_LINE_ISP].subdev.entity.name, ret);
+		goto err_link;
+	}
+
+	return ret;
+
+err_link:
+	stf_vin_unregister(&stfcamss->vin_dev);
+err_reg_vin:
+	stf_isp_unregister(&stfcamss->isp_dev);
+err_reg_isp:
 	return ret;
 }
 
 static void stfcamss_unregister_subdevices(struct stfcamss *stfcamss)
 {
 	stf_isp_unregister(&stfcamss->isp_dev);
+	stf_vin_unregister(&stfcamss->vin_dev);
 }
 
 static int stfcamss_subdev_notifier_bound(struct v4l2_async_notifier *async,
@@ -175,11 +209,14 @@ static int stfcamss_subdev_notifier_bound(struct v4l2_async_notifier *async,
 		container_of(asd, struct stfcamss_async_subdev, asd);
 	enum port_num port = csd->port;
 	struct stf_isp_dev *isp_dev = &stfcamss->isp_dev;
+	struct stf_vin_dev *vin_dev = &stfcamss->vin_dev;
 	struct host_data *host_data = &stfcamss->host_data;
 	struct media_entity *source;
 	int i, j;
 
 	if (port == PORT_NUMBER_CSI2RX) {
+		host_data->host_entity[0] =
+			&vin_dev->line[VIN_LINE_WR].subdev.entity;
 		host_data->host_entity[1] = &isp_dev->subdev.entity;
 	} else if (port == PORT_NUMBER_DVP_SENSOR) {
 		dev_err(stfcamss->dev, "Not support DVP sensor\n");
drivers/media/platform/starfive/stf_camss.h +2 -0
index c9d94be92ea8..688bb3b7b6d0 100644
@@ -17,6 +17,7 @@
 
 #include "stf_common.h"
 #include "stf_isp.h"
+#include "stf_vin.h"
 
 #define DRV_NAME     "starfive-camss"
 #define STF_DVP_NAME "stf_dvp"
@@ -72,6 +73,7 @@ struct stfcamss {
 	struct media_device media_dev;
 	struct media_pipeline pipe;
 	struct device *dev;
+	struct stf_vin_dev vin_dev;
 	struct stf_isp_dev isp_dev;
 	struct v4l2_async_notifier notifier;
 	struct host_data host_data;
drivers/media/platform/starfive/stf_vin.c new file +1134 -0

1,134 lines not on this page · raw message

drivers/media/platform/starfive/stf_vin.h new file +180 -0

180 lines not on this page · raw message

drivers/media/platform/starfive/stf_vin_hw_ops.c new file +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.34.1
#13 lore raw
In reply to Jack Zhu
Quoted 4 lines · Jack Zhu

hi,

This series is the v5 of the series, the CSI driver is moved to another separate series.

You should run your series through checkpatch.pl --strict

0001-media-dt-bindings-Add-JH7110-Camera-Subsystem.patch has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 0 checks, 87 lines checked

0002-media-admin-guide-Add-starfive_camss.rst-for-Starfiv.patch has no obvious style problems and is ready for submission.
CHECK: Lines should not end with a '('
#263: FILE: drivers/media/platform/starfive/stf_camss.c:157:
+ ret = media_create_pad_link(

total: 0 errors, 0 warnings, 1 checks, 592 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.

0003-media-starfive-Add-basic-driver.patch has style problems, please review.

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #31:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 967 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.

0004-media-starfive-Add-video-driver.patch has style problems, please review.

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #188:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 1625 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.

0005-media-starfive-Add-ISP-driver.patch has style problems, please review.

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #138:
new file mode 100644

CHECK: Macro argument reuse 'ptr_line' - possible side-effects? #155: FILE: drivers/media/platform/starfive/stf_vin.c:13:
+#define vin_line_array(ptr_line) \
+ ((const struct vin_line (*)[]) &(ptr_line)[-((ptr_line)->id)])

CHECK: Alignment should match open parenthesis #597: FILE: drivers/media/platform/starfive/stf_vin.c:455:
+ vin_set_dummy_buffer(line,
+ stf_vin_map_isp_pad(line->id, STF_ISP_PAD_SINK));

CHECK: Lines should not end with a '('
#1222: FILE: drivers/media/platform/starfive/stf_vin.c:1080:
+ ret = media_create_pad_link(

CHECK: Lines should not end with a '('
#1513: FILE: drivers/media/platform/starfive/stf_vin_hw_ops.c:45:
+ vin_dev->isr_ops->isr_buffer_done(

CHECK: Lines should not end with a '('
#1543: FILE: drivers/media/platform/starfive/stf_vin_hw_ops.c:75:
+ vin_dev->isr_ops->isr_change_buffer(

total: 0 errors, 1 warnings, 5 checks, 1654 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.

0006-media-starfive-Add-VIN-driver.patch has style problems, please review.

---
bod