Add Starfive Camera Subsystem driver
Subsystems (3)
v2 cover Add Starfive Camera Subsystem driver
Hi,
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 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 bindings for JH7110 Camera Subsystem
media: dt-bindings: cadence-csi2rx: Convert to DT schema
media: admin-guide: Add starfive_camss.rst for Starfive Camera
Subsystem
media: cadence: Add support for external dphy and JH7110 SoC
MAINTAINERS: Add Starfive Camera Subsystem driver
media: starfive: Add Starfive Camera Subsystem driver
.../admin-guide/media/starfive_camss.rst | 68 + .../media/starfive_camss_graph.dot | 28 + .../admin-guide/media/v4l-drivers.rst | 1 + .../devicetree/bindings/media/cdns,csi2rx.txt | 100 -- .../bindings/media/cdns,csi2rx.yaml | 163 ++ .../bindings/media/starfive,jh7110-camss.yaml | 144 ++ MAINTAINERS | 10 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/cadence/cdns-csi2rx.c | 273 +++- drivers/media/platform/starfive/Kconfig | 18 + drivers/media/platform/starfive/Makefile | 14 + drivers/media/platform/starfive/stf_camss.c | 728 +++++++++ drivers/media/platform/starfive/stf_camss.h | 104 ++ drivers/media/platform/starfive/stf_common.h | 149 ++ drivers/media/platform/starfive/stf_isp.c | 1079 ++++++++++++++ drivers/media/platform/starfive/stf_isp.h | 183 +++ .../media/platform/starfive/stf_isp_hw_ops.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.h | 89 ++ drivers/media/platform/starfive/stf_vin.c | 1314 +++++++++++++++++ drivers/media/platform/starfive/stf_vin.h | 194 +++ .../media/platform/starfive/stf_vin_hw_ops.c | 357 +++++ include/uapi/linux/stf_isp_ioctl.h | 127 ++ 24 files changed, 7607 insertions(+), 110 deletions(-) create mode 100644 Documentation/admin-guide/media/starfive_camss.rst create mode 100644 Documentation/admin-guide/media/starfive_camss_graph.dot delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.yaml 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 create mode 100644 include/uapi/linux/stf_isp_ioctl.h
Signature · 1 line
2.34.1
PATCH v2 1/6 media: dt-bindings: Add bindings for 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 | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +144 -0
@@ -0,0 +1,144 @@ +# 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@1: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: + Input port for receiving CSI data. + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + required: + - port@1 + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - power-domains + - interrupts + +additionalProperties: false + +examples: + - | + stfcamss: 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@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + vin_from_csi2rx: endpoint { + remote-endpoint = <&csi2rx_to_vin>; + }; + }; + }; + };
Signature · 1 line
2.34.1
Re: [PATCH v2 1/6] media: dt-bindings: Add bindings for JH7110 Camera Subsystem
Hi Jack,
Thank you for the patch.
Quoted 20 lines · Jack Zhu
Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.
Signed-off-by Jack Zhu <[email protected]>--- .../bindings/media/starfive,jh7110-camss.yaml | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yamlDocumentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +5
-0@@ -0,0 +1,144 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) + +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/starfive,jh7110-camss.yaml#
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 15
Quoted 10 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +10
-0+$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
s/.It/. It/
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 16
Quoted 1 line
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +1
-0+ consists of a VIN controller(Video In Controller, a top-level control until)
s/(/ (/
Quoted 41 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +41
-0+ 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:
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +10
-0+ - description: JH7110 ISP Power Domain Switch Controller. + + interrupts: + maxItems: 4 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@1:
Why port@1 if there is no port@0 ?
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 68
Quoted 1 line
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +1
-0+ $ref: /schemas/graph.yaml#/$defs/port-base
I think you can use
$ref: /schemas/graph.yaml#/properties/port
here as you don't define any additional property for the port node.
Quoted 12 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +12
-0+ unevaluatedProperties: false + description: + Input port for receiving CSI data. + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + required: + - port@1 +
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 90
Quoted 10 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +10
-0+required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - power-domains + - interrupts
The 'ports' node should be mandatory too.
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 96
Quoted 6 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +6
-0+ +additionalProperties: false + +examples: + - | + stfcamss: isp@19840000 {
You can drop the label as it's not used.
Quoted 48 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +48
-0+ 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@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + vin_from_csi2rx: endpoint { + remote-endpoint = <&csi2rx_to_vin>; + }; + }; + }; + };
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 1/6] media: dt-bindings: Add bindings for JH7110 Camera Subsystem
Quoted 3 lines · Laurent Pinchart
Hi Jack,
Thank you for the patch.
Thank you for your comments.
Quoted 26 lines · Jack Zhu
Quoted 24 lines
Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.
Signed-off-by Jack Zhu <[email protected]>--- .../bindings/media/starfive,jh7110-camss.yaml | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yamlDocumentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +9
-0@@ -0,0 +1,144 @@ +# 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 +
Quoted 8 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 15
Quoted 6 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +6
-0+maintainers: + - Jack Zhu <[email protected]> + - Changhuang Liang <[email protected]> + +description: + The Starfive CAMSS ISP is a Camera interface for Starfive JH7110 SoC.Its/.It/. It/
OK, will fix
Quoted 4 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 16
Quoted 2 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +1
-0+ consists of a VIN controller(Video In Controller, a top-level control until)s/(/ (/
OK, will fix
Quoted 46 lines
Quoted 46 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +45
-0+ 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
Quoted 8 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 67
Quoted 6 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +6
-0+ + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@1:Why port@1 if there is no port@0 ?
Will add port@0 node in the next version.
port@0 is reserved for DVP sensor which is not currently supported.
Quoted 8 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 68
Quoted 2 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +1
-0+ $ref: /schemas/graph.yaml#/$defs/port-baseI think you can use
$ref: /schemas/graph.yaml#/properties/port
here as you don't define any additional property for the port node.
OK, will alter it
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +16
-0+ unevaluatedProperties: false + description: + Input port for receiving CSI data. + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + required: + - port@1 + +required: + - compatible + - reg + - reg-names
Quoted 8 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 90
Quoted 6 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +6
-0+ - clocks + - clock-names + - resets + - reset-names + - power-domains + - interruptsThe 'ports' node should be mandatory too.
OK, will fix. Thanks.
Quoted 9 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 96
Quoted 7 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +6
-0+ +additionalProperties: false + +examples: + - | + stfcamss: isp@19840000 {You can drop the label as it's not used.
OK, will drop.
Quoted 50 lines
Quoted 49 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +48
-0+ 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@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + vin_from_csi2rx: endpoint { + remote-endpoint = <&csi2rx_to_vin>; + }; + }; + }; + };
Re: [PATCH v2 1/6] media: dt-bindings: Add bindings for JH7110 Camera Subsystem
In reply to Jack ZhuQuoted 71 lines · Jack Zhu
Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.
Signed-off-by Jack Zhu <[email protected]>--- .../bindings/media/starfive,jh7110-camss.yaml | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yamlDocumentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +56
-0@@ -0,0 +1,144 @@ +# 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:
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 66
Quoted 10 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +10
-0+ items: + - description: JH7110 ISP Power Domain Switch Controller. + + interrupts: + maxItems: 4 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties:
You should have here port@0. The binding does not represent what is supported by Linux. Binding represents hardware and you said you have port@0 for the sensor.
Quoted 57 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +57
-0+ port@1: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: + Input port for receiving CSI data. + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + required: + - port@1 + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - power-domains + - interrupts + +additionalProperties: false + +examples: + - | + stfcamss: 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",
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 133
Quoted 10 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +10
-0+ "axiwr", + "isp_top_n", + "isp_top_axi"; + power-domains = <&pwrc 5>; + interrupts = <92>, <87>, <88>, <90>; + + ports { + #address-cells = <1>; + #size-cells = <0>; +
Same here, DTS describes the hardware, so you need port@0.
Best regards,
Krzysztof
Re: [PATCH v2 1/6] media: dt-bindings: Add bindings for JH7110 Camera Subsystem
Quoted 78 lines · Krzysztof Kozlowski
Quoted 77 lines · Jack Zhu
Add the bindings documentation for Starfive JH7110 Camera Subsystem which is used for handing image sensor data.
Signed-off-by Jack Zhu <[email protected]>--- .../bindings/media/starfive,jh7110-camss.yaml | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/starfive,jh7110-camss.yamlDocumentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +62
-0@@ -0,0 +1,144 @@ +# 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 +
Quoted 9 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 66
Quoted 4 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +4
-0+ ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties:You should have here port@0. The binding does not represent what is supported by Linux. Binding represents hardware and you said you have port@0 for the sensor.
OK, will add port@0. Thanks.
Quoted 62 lines
Quoted 62 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +61
-0+ port@1: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: + Input port for receiving CSI data. + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + required: + - port@1 + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - power-domains + - interrupts + +additionalProperties: false + +examples: + - | + stfcamss: 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>;
Quoted 8 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml line 133
Quoted 6 lines
Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml new file +6
-0+ interrupts = <92>, <87>, <88>, <90>; + + ports { + #address-cells = <1>; + #size-cells = <0>; +Same here, DTS describes the hardware, so you need port@0.
OK, will add it.
Quoted 6 lines
Best regards,
Krzysztof
PATCH v2 2/6 media: dt-bindings: cadence-csi2rx: Convert to DT schema
In reply to Jack ZhuConvert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
--- .../devicetree/bindings/media/cdns,csi2rx.txt | 100 ----------- .../bindings/media/cdns,csi2rx.yaml | 163 ++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 164 insertions(+), 100 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.yaml
Documentation/devicetree/bindings/media/cdns,csi2rx.txt deleted +0 -100
@@ -1,100 +0,0 @@ -Cadence MIPI-CSI2 RX controller -=============================== - -The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI -lanes in input, and 4 different pixel streams in output. - -Required properties: - - compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible - - reg: base address and size of the memory mapped region - - clocks: phandles to the clocks driving the controller - - clock-names: must contain: - * sys_clk: main clock - * p_clk: register bank clock - * pixel_if[0-3]_clk: pixel stream output clock, one for each stream - implemented in hardware, between 0 and 3 - -Optional properties: - - phys: phandle to the external D-PHY, phy-names must be provided - - phy-names: must contain "dphy", if the implementation uses an - external D-PHY - -Required subnodes: - - ports: A ports node with one port child node per device input and output - port, in accordance with the video interface bindings defined in - Documentation/devicetree/bindings/media/video-interfaces.txt. The - port nodes are numbered as follows: - - Port Description - ----------------------------- - 0 CSI-2 input - 1 Stream 0 output - 2 Stream 1 output - 3 Stream 2 output - 4 Stream 3 output - - The stream output port nodes are optional if they are not - connected to anything at the hardware level or implemented - in the design.Since there is only one endpoint per port, - the endpoints are not numbered. - - -Example: - -csi2rx: csi-bridge@0d060000 { - compatible = "cdns,csi2rx"; - reg = <0x0d060000 0x1000>; - clocks = <&byteclock>, <&byteclock> - <&coreclock>, <&coreclock>, - <&coreclock>, <&coreclock>; - clock-names = "sys_clk", "p_clk", - "pixel_if0_clk", "pixel_if1_clk", - "pixel_if2_clk", "pixel_if3_clk"; - - ports { - #address-cells = <1>; - #size-cells = <0>; - - port@0 { - reg = <0>; - - csi2rx_in_sensor: endpoint { - remote-endpoint = <&sensor_out_csi2rx>; - clock-lanes = <0>; - data-lanes = <1 2>; - }; - }; - - port@1 { - reg = <1>; - - csi2rx_out_grabber0: endpoint { - remote-endpoint = <&grabber0_in_csi2rx>; - }; - }; - - port@2 { - reg = <2>; - - csi2rx_out_grabber1: endpoint { - remote-endpoint = <&grabber1_in_csi2rx>; - }; - }; - - port@3 { - reg = <3>; - - csi2rx_out_grabber2: endpoint { - remote-endpoint = <&grabber2_in_csi2rx>; - }; - }; - - port@4 { - reg = <4>; - - csi2rx_out_grabber3: endpoint { - remote-endpoint = <&grabber3_in_csi2rx>; - }; - }; - }; -};
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +163 -0
163 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -4632,6 +4632,7 @@ M: Maxime Ripard <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/media/cdns,*.txt +F: Documentation/devicetree/bindings/media/cdns,csi2rx.yaml F: drivers/media/platform/cadence/cdns-csi2* CADENCE NAND DRIVER
Signature · 1 line
2.34.1
Rob Herring
maintainerRe: [PATCH v2 2/6] media: dt-bindings: cadence-csi2rx: Convert to DT schema
Quoted 12 lines · Jack Zhu
Convert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
Signed-off-by Jack Zhu <[email protected]>--- .../devicetree/bindings/media/cdns,csi2rx.txt | 100 ----------- .../bindings/media/cdns,csi2rx.yaml | 163 ++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 164 insertions(+), 100 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.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:
Documentation/devicetree/bindings/media/cdns,csi2rx.example.dts:18.30-58.11: Warning (unit_address_format): /example-0/csi@0d060000: unit name should not have leading 0s
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
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 after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v2 2/6] media: dt-bindings: cadence-csi2rx: Convert to DT schema
Quoted 34 lines · Rob Herring
Quoted 12 lines · Jack Zhu
Convert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
Signed-off-by Jack Zhu <[email protected]>--- .../devicetree/bindings/media/cdns,csi2rx.txt | 100 ----------- .../bindings/media/cdns,csi2rx.yaml | 163 ++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 164 insertions(+), 100 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/media/cdns,csi2rx.example.dts:18.30-58.11: Warning (unit_address_format): /example-0/csi@0d060000: unit name should not have leading 0sdoc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
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:
Quoted 6 lines
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that
DT_SCHEMA_FILEScan be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
OK, will fix. Thanks.
Re: [PATCH v2 2/6] media: dt-bindings: cadence-csi2rx: Convert to DT schema
In reply to Jack ZhuHi Jack,
Thank you for the patch.
Quoted 2 lines · Jack Zhu
Convert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
This would have been easier to review if the patch had been split in two, with conversion to YAML first, and then addition of new properties. Generally speaking, one patch should contain a single logical change.
Quoted 130 lines
Signed-off-by Jack Zhu <[email protected]>--- .../devicetree/bindings/media/cdns,csi2rx.txt | 100 ----------- .../bindings/media/cdns,csi2rx.yaml | 163 ++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 164 insertions(+), 100 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.yamlDocumentation/devicetree/bindings/media/cdns,csi2rx.txt deleted +0
-100@@ -1,100 +0,0 @@ -Cadence MIPI-CSI2 RX controller -=============================== - -The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI -lanes in input, and 4 different pixel streams in output. - -Required properties: - - compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible - - reg: base address and size of the memory mapped region - - clocks: phandles to the clocks driving the controller - - clock-names: must contain: - * sys_clk: main clock - * p_clk: register bank clock - * pixel_if[0-3]_clk: pixel stream output clock, one for each stream - implemented in hardware, between 0 and 3 - -Optional properties: - - phys: phandle to the external D-PHY, phy-names must be provided - - phy-names: must contain "dphy", if the implementation uses an - external D-PHY - -Required subnodes: - - ports: A ports node with one port child node per device input and output - port, in accordance with the video interface bindings defined in - Documentation/devicetree/bindings/media/video-interfaces.txt. The - port nodes are numbered as follows: - - Port Description - ----------------------------- - 0 CSI-2 input - 1 Stream 0 output - 2 Stream 1 output - 3 Stream 2 output - 4 Stream 3 output - - The stream output port nodes are optional if they are not - connected to anything at the hardware level or implemented - in the design.Since there is only one endpoint per port, - the endpoints are not numbered. - - -Example: - -csi2rx: csi-bridge@0d060000 { - compatible = "cdns,csi2rx"; - reg = <0x0d060000 0x1000>; - clocks = <&byteclock>, <&byteclock> - <&coreclock>, <&coreclock>, - <&coreclock>, <&coreclock>; - clock-names = "sys_clk", "p_clk", - "pixel_if0_clk", "pixel_if1_clk", - "pixel_if2_clk", "pixel_if3_clk"; - - ports { - #address-cells = <1>; - #size-cells = <0>; - - port@0 { - reg = <0>; - - csi2rx_in_sensor: endpoint { - remote-endpoint = <&sensor_out_csi2rx>; - clock-lanes = <0>; - data-lanes = <1 2>; - }; - }; - - port@1 { - reg = <1>; - - csi2rx_out_grabber0: endpoint { - remote-endpoint = <&grabber0_in_csi2rx>; - }; - }; - - port@2 { - reg = <2>; - - csi2rx_out_grabber1: endpoint { - remote-endpoint = <&grabber1_in_csi2rx>; - }; - }; - - port@3 { - reg = <3>; - - csi2rx_out_grabber2: endpoint { - remote-endpoint = <&grabber2_in_csi2rx>; - }; - }; - - port@4 { - reg = <4>; - - csi2rx_out_grabber3: endpoint { - remote-endpoint = <&grabber3_in_csi2rx>; - }; - }; - }; -};Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +9
-0@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/cdns,csi2rx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cadence MIPI-CSI2 RX controller + +maintainers:
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 19
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ - Maxime Ripard <[email protected]> + +description: + The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI + lanes in input, and 4 different pixel streams in output. + +properties: + compatible: + enum: + - cdns,csi2rx
The existing bindings state
- compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible
This should thus be
compatible:
items:
- enum:
- vendor1,device1
- ...
- const: cdns,csi2rx
The trouble is that the existing bindings are not used in mainline and don't specify any SoC-specific compatible string, so I don't know what to indicate for vendor1,device1. One option would be to add the StarFive compatible string already:
compatible:
items:
- enum:
- starfive,jh7110-csi2rx
- const: cdns,csi2rx
The example below should be updated accordingly.
Quoted 11 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +11
-0+ + reg: + maxItems: 1 + + clocks: + items: + - description: CSI2Rx system clock + - description: Gated Register bank clock for APB interface + - description: pixel Clock for Stream interface 0 + - description: pixel Clock for Stream interface 1 + - description: pixel Clock for Stream interface 2
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ - description: pixel Clock for Stream interface 3 + + clock-names: + items: + - const: sys + - const: reg_bank + - const: pixel_if0 + - const: pixel_if1 + - const: pixel_if2 + - const: pixel_if3
This changes the clock names and breaks compatibility with the driver. The existing names must be preserved.
Quoted 8 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +8
-0+ + resets: + items: + - description: CSI2Rx system reset + - description: Gated Register bank reset for APB interface + - description: pixel reset for Stream interface 0 + - description: pixel reset for Stream interface 1 + - description: pixel reset for Stream interface 2
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 58
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ - description: pixel reset for Stream interface 3 + + reset-names: + items: + - const: sys + - const: reg_bank + - const: pixel_if0 + - const: pixel_if1 + - const: pixel_if2 + - const: pixel_if3
Let's move the addition of the resets and reset-names properties to a patch separate from the YAML conversion to make it easier to review them independently.
Quoted 18 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +18
-0+ + phys: + maxItems: 1 + description: MIPI D-PHY + + phy-names: + items: + - const: dphy + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: + Input port node, single endpoint describing the CSI-2 transmitter.
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 86
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + properties: + bus-type: + enum: + - 4
You can simplify this to
bus-type:
const: 4
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 95
Quoted 9 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +9
-0+ + clock-lanes: + maximum: 4 + + data-lanes: + minItems: 1 + maxItems: 4 + items: + maximum: 4
Does the IP core support clock and data lanes remapping ?
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 104
Quoted 9 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +9
-0+ + required: + - clock-lanes + - data-lanes + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + Output port node
This is also a change compared to the existing bindings, and it will break backward compatibility. You should have four output ports.
Quoted 7 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +7
-0+ + required: + - port@0 + - port@1 + +required: + - compatible
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 121
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ - reg + - clocks + - clock-names + - ports + +additionalProperties: false + +examples: + - | + csi2rx: csi@0d060000 {
The csi2rx label is never referenced, you can drop it.
Quoted 54 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +42
-0+ compatible = "cdns,csi2rx"; + reg = <0x0d060000 0x1000>; + clocks = <&byteclock 7>, <&byteclock 6>, + <&coreclock 8>, <&coreclock 9>, + <&coreclock 10>, <&coreclock 11>; + clock-names = "sys", "reg_bank", + "pixel_if0", "pixel_if1", + "pixel_if2", "pixel_if3"; + resets = <&bytereset 9>, <&bytereset 4>, + <&corereset 5>, <&corereset 6>, + <&corereset 7>, <&corereset 8>; + reset-names = "sys", "reg_bank", + "pixel_if0", "pixel_if1", + "pixel_if2", "pixel_if3"; + phys = <&csi_phy>; + phy-names = "dphy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + csi2rx_in_sensor: endpoint { + remote-endpoint = <&sensor_out_csi2rx>; + clock-lanes = <0>; + data-lanes = <1 2>; + }; + }; + + port@1 { + reg = <1>; + + csi2rx_out_grabber0: endpoint { + remote-endpoint = <&grabber0_in_csi2rx>; + }; + }; + }; + }; + +...MAINTAINERS +1
-0@@ -4632,6 +4632,7 @@ M: Maxime Ripard <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/media/cdns,*.txt +F: Documentation/devicetree/bindings/media/cdns,csi2rx.yaml F: drivers/media/platform/cadence/cdns-csi2* CADENCE NAND DRIVER
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 2/6] media: dt-bindings: cadence-csi2rx: Convert to DT schema
Quoted 4 lines · Laurent Pinchart
Hi Jack,
Thank you for the patch.
Quoted 8 lines
Quoted 2 lines · Jack Zhu
Convert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
This would have been easier to review if the patch had been split in two, with conversion to YAML first, and then addition of new properties. Generally speaking, one patch should contain a single logical change.
OK, will split the patch into two patches.
Quoted 159 lines
Quoted 130 lines
Signed-off-by Jack Zhu <[email protected]>--- .../devicetree/bindings/media/cdns,csi2rx.txt | 100 ----------- .../bindings/media/cdns,csi2rx.yaml | 163 ++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 164 insertions(+), 100 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.yamlDocumentation/devicetree/bindings/media/cdns,csi2rx.txt deleted +0
-100@@ -1,100 +0,0 @@ -Cadence MIPI-CSI2 RX controller -=============================== - -The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI -lanes in input, and 4 different pixel streams in output. - -Required properties: - - compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible - - reg: base address and size of the memory mapped region - - clocks: phandles to the clocks driving the controller - - clock-names: must contain: - * sys_clk: main clock - * p_clk: register bank clock - * pixel_if[0-3]_clk: pixel stream output clock, one for each stream - implemented in hardware, between 0 and 3 - -Optional properties: - - phys: phandle to the external D-PHY, phy-names must be provided - - phy-names: must contain "dphy", if the implementation uses an - external D-PHY - -Required subnodes: - - ports: A ports node with one port child node per device input and output - port, in accordance with the video interface bindings defined in - Documentation/devicetree/bindings/media/video-interfaces.txt. The - port nodes are numbered as follows: - - Port Description - ----------------------------- - 0 CSI-2 input - 1 Stream 0 output - 2 Stream 1 output - 3 Stream 2 output - 4 Stream 3 output - - The stream output port nodes are optional if they are not - connected to anything at the hardware level or implemented - in the design.Since there is only one endpoint per port, - the endpoints are not numbered. - - -Example: - -csi2rx: csi-bridge@0d060000 { - compatible = "cdns,csi2rx"; - reg = <0x0d060000 0x1000>; - clocks = <&byteclock>, <&byteclock> - <&coreclock>, <&coreclock>, - <&coreclock>, <&coreclock>; - clock-names = "sys_clk", "p_clk", - "pixel_if0_clk", "pixel_if1_clk", - "pixel_if2_clk", "pixel_if3_clk"; - - ports { - #address-cells = <1>; - #size-cells = <0>; - - port@0 { - reg = <0>; - - csi2rx_in_sensor: endpoint { - remote-endpoint = <&sensor_out_csi2rx>; - clock-lanes = <0>; - data-lanes = <1 2>; - }; - }; - - port@1 { - reg = <1>; - - csi2rx_out_grabber0: endpoint { - remote-endpoint = <&grabber0_in_csi2rx>; - }; - }; - - port@2 { - reg = <2>; - - csi2rx_out_grabber1: endpoint { - remote-endpoint = <&grabber1_in_csi2rx>; - }; - }; - - port@3 { - reg = <3>; - - csi2rx_out_grabber2: endpoint { - remote-endpoint = <&grabber2_in_csi2rx>; - }; - }; - - port@4 { - reg = <4>; - - csi2rx_out_grabber3: endpoint { - remote-endpoint = <&grabber3_in_csi2rx>; - }; - }; - }; -};Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +9
-0@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/cdns,csi2rx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cadence MIPI-CSI2 RX controller + +maintainers:Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 19
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ - Maxime Ripard <[email protected]> + +description: + The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI + lanes in input, and 4 different pixel streams in output. + +properties: + compatible: + enum: + - cdns,csi2rxThe existing bindings state
- compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible
This should thus be
compatible:
items:
- enum:
- vendor1,device1
- ...
- const: cdns,csi2rxThe trouble is that the existing bindings are not used in mainline and don't specify any SoC-specific compatible string, so I don't know what to indicate for vendor1,device1. One option would be to add the StarFive compatible string already:
Quoted 8 lines
compatible:
items:
- enum:
- starfive,jh7110-csi2rx
- const: cdns,csi2rxThe example below should be updated accordingly.
Will alter it according your opinion. Thanks.
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +16
-0+ + reg: + maxItems: 1 + + clocks: + items: + - description: CSI2Rx system clock + - description: Gated Register bank clock for APB interface + - description: pixel Clock for Stream interface 0 + - description: pixel Clock for Stream interface 1 + - description: pixel Clock for Stream interface 2 + - description: pixel Clock for Stream interface 3 + + clock-names: + items: + - const: sys
Quoted 9 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 40
Quoted 5 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +5
-0+ - const: reg_bank + - const: pixel_if0 + - const: pixel_if1 + - const: pixel_if2 + - const: pixel_if3This changes the clock names and breaks compatibility with the driver. The existing names must be preserved.
OK, will use the existing names.
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +14
-0+ + resets: + items: + - description: CSI2Rx system reset + - description: Gated Register bank reset for APB interface + - description: pixel reset for Stream interface 0 + - description: pixel reset for Stream interface 1 + - description: pixel reset for Stream interface 2 + - description: pixel reset for Stream interface 3 + + reset-names: + items: + - const: sys + - const: reg_bank
Quoted 8 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 40
Quoted 4 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +4
-0+ - const: pixel_if0 + - const: pixel_if1 + - const: pixel_if2 + - const: pixel_if3Let's move the addition of the resets and reset-names properties to a patch separate from the YAML conversion to make it easier to review them independently.
OK, will do. Thank.
Quoted 32 lines
Quoted 19 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +18
-0+ + phys: + maxItems: 1 + description: MIPI D-PHY + + phy-names: + items: + - const: dphy + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: + Input port node, single endpoint describing the CSI-2 transmitter.Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 86
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +10
-0+ + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + properties: + bus-type: + enum: + - 4You can simplify this to
Quoted 3 lines
bus-type:
const: 4
OK, will fix
Quoted 11 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 95
Quoted 9 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +9
-0+ + clock-lanes: + maximum: 4 + + data-lanes: + minItems: 1 + maxItems: 4 + items: + maximum: 4Does the IP core support clock and data lanes remapping ?
Only data lanes remapping is supported.
Will change it to the below:
clock-lanes:
const: 0
Quoted 13 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 104
Quoted 10 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +9
-0+ + required: + - clock-lanes + - data-lanes + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + Output port nodeThis is also a change compared to the existing bindings, and it will break backward compatibility. You should have four output ports.
OK, will fix.
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +11
-0+ + required: + - port@0 + - port@1 + +required: + - compatible + - reg + - clocks + - clock-names + - ports
Quoted 8 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml line 121
Quoted 6 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +6
-0+ +additionalProperties: false + +examples: + - | + csi2rx: csi@0d060000 {The csi2rx label is never referenced, you can drop it.
OK, will drop it.
Quoted 56 lines
Quoted 55 lines
Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file +42
-0+ compatible = "cdns,csi2rx"; + reg = <0x0d060000 0x1000>; + clocks = <&byteclock 7>, <&byteclock 6>, + <&coreclock 8>, <&coreclock 9>, + <&coreclock 10>, <&coreclock 11>; + clock-names = "sys", "reg_bank", + "pixel_if0", "pixel_if1", + "pixel_if2", "pixel_if3"; + resets = <&bytereset 9>, <&bytereset 4>, + <&corereset 5>, <&corereset 6>, + <&corereset 7>, <&corereset 8>; + reset-names = "sys", "reg_bank", + "pixel_if0", "pixel_if1", + "pixel_if2", "pixel_if3"; + phys = <&csi_phy>; + phy-names = "dphy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + csi2rx_in_sensor: endpoint { + remote-endpoint = <&sensor_out_csi2rx>; + clock-lanes = <0>; + data-lanes = <1 2>; + }; + }; + + port@1 { + reg = <1>; + + csi2rx_out_grabber0: endpoint { + remote-endpoint = <&grabber0_in_csi2rx>; + }; + }; + }; + }; + +...MAINTAINERS +1
-0@@ -4632,6 +4632,7 @@ M: Maxime Ripard <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/media/cdns,*.txt +F: Documentation/devicetree/bindings/media/cdns,csi2rx.yaml F: drivers/media/platform/cadence/cdns-csi2* CADENCE NAND DRIVER
Re: [PATCH v2 2/6] media: dt-bindings: cadence-csi2rx: Convert to DT schema
In reply to Jack ZhuQuoted 2 lines · Jack Zhu
Convert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
As pointed, first conversion, then new properties.
You also need to test each binding before sending. Best regards,
Krzysztof
Re: [PATCH v2 2/6] media: dt-bindings: cadence-csi2rx: Convert to DT schema
Quoted 7 lines · Krzysztof Kozlowski
Quoted 2 lines · Jack Zhu
Convert DT bindings document for Cadence MIPI-CSI2 RX controller to DT schema format and add new properties.
As pointed, first conversion, then new properties.
You also need to test each binding before sending.
Thank you for your suggestion. I will split the patch into two patches and test.
Quoted 3 lines
Best regards,
Krzysztof
PATCH v2 3/6 media: admin-guide: Add starfive_camss.rst for Starfive Camera Subsystem
In reply to Jack ZhuAdd the file 'starfive_camss.rst' that documents the Starfive Camera Subsystem driver which is used for handing image sensor data.
--- .../admin-guide/media/starfive_camss.rst | 68 +++++++++++++++++++ .../media/starfive_camss_graph.dot | 28 ++++++++ .../admin-guide/media/v4l-drivers.rst | 1 + 3 files changed, 97 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 +68 -0
@@ -0,0 +1,68 @@ +.. 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 5 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. +- stf_vin0_isp0_ss0_video2: capture device for images with adjustable + scale-down factor. +- stf_vin0_isp0_ss1_video3: capture device for images with adjustable + scale-down factor. +- stf_vin0_isp0_raw_video4: capture device for RAW images. + +The driver has 6 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 unscaled images for the stf_vin0_isp0_video1 + device. +- stf_vin0_isp0_ss0: used to resize and downsample frames for + the stf_vin0_isp0_ss0_video2 capture device. +- stf_vin0_isp0_ss1: used to resize and downsample frames for + the stf_vin0_isp0_ss1_video3 capture device. +- stf_vin0_isp0_raw: used to configure the camss ISP to get RAW + images for stf_vin0_isp0_raw_video4 capture device.
Documentation/admin-guide/media/starfive_camss_graph.dot new file +28 -0
@@ -0,0 +1,28 @@ +digraph board { + rankdir=TB + n00000001 [label="{{<port0> 0} | stf_isp0\n/dev/v4l-subdev0 | {<port1> 1 | <port2> 2 | <port3> 3 | <port4> 4}}", shape=Mrecord, style=filled, fillcolor=green] + n00000001:port1 -> n00000010:port0 + n00000001:port2 -> n00000019:port0 [style=dashed] + n00000001:port3 -> n00000022:port0 [style=dashed] + n00000001:port4 -> n0000002b:port0 [style=dashed] + n00000007 [label="{{<port0> 0} | stf_vin0_wr\n/dev/v4l-subdev1 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green] + n00000007:port1 -> n0000000a [style=bold] + n0000000a [label="stf_vin0_wr_video0\n/dev/video0", shape=box, style=filled, fillcolor=yellow] + n00000010 [label="{{<port0> 0} | stf_vin0_isp0\n/dev/v4l-subdev2 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green] + n00000010:port1 -> n00000013 [style=bold] + n00000013 [label="stf_vin0_isp0_video1\n/dev/video1", shape=box, style=filled, fillcolor=yellow] + n00000019 [label="{{<port0> 0} | stf_vin0_isp0_ss0\n/dev/v4l-subdev3 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green] + n00000019:port1 -> n0000001c [style=bold] + n0000001c [label="stf_vin0_isp0_ss0_video2\n/dev/video2", shape=box, style=filled, fillcolor=yellow] + n00000022 [label="{{<port0> 0} | stf_vin0_isp0_ss1\n/dev/v4l-subdev4 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green] + n00000022:port1 -> n00000025 [style=bold] + n00000025 [label="stf_vin0_isp0_ss1_video3\n/dev/video3", shape=box, style=filled, fillcolor=yellow] + n0000002b [label="{{<port0> 0} | stf_vin0_isp0_raw\n/dev/v4l-subdev5 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green] + n0000002b:port1 -> n0000002e [style=bold] + n0000002e [label="stf_vin0_isp0_raw_video4\n/dev/video4", shape=box, style=filled, fillcolor=yellow] + n0000003c [label="{{<port0> 0} | cdns_csi2rx.19800000.csi-bridge\n/dev/v4l-subdev6 | {<port1> 1 | <port2> 2 | <port3> 3 | <port4> 4}}", shape=Mrecord, style=filled, fillcolor=green] + n0000003c:port1 -> n00000007:port0 [style=dashed] + n0000003c:port1 -> n00000001:port0 + n00000054 [label="{{} | imx219 6-0010\n/dev/v4l-subdev7 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green] + n00000054:port0 -> n0000003c:port0 [style=bold] +}
Documentation/admin-guide/media/v4l-drivers.rst +1 -0
@@ -30,6 +30,7 @@ Video4Linux (V4L) driver-specific documentation si470x si4713 si476x + starfive vimc visl vivid
Signature · 1 line
2.34.1
PATCH v2 4/6 media: cadence: Add support for external dphy and JH7110 SoC
In reply to Jack ZhuAdd support for external MIPI D-PHY and Starfive JH7110 SoC which has the cadence csi2 receiver.
--- drivers/media/platform/cadence/cdns-csi2rx.c | 273 ++++++++++++++++++- 1 file changed, 263 insertions(+), 10 deletions(-)
drivers/media/platform/cadence/cdns-csi2rx.c +263 -10
@@ -10,9 +10,11 @@#include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/reset.h> #include <linux/slab.h> #include <media/v4l2-ctrls.h>
@@ -30,6 +32,12 @@#define CSI2RX_STATIC_CFG_DLANE_MAP (llane, plane) ((plane) << (16 + (llane) * 4))#define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8) +#define CSI2RX_DPHY_LANE_CTRL_REG 0x40 +#define CSI2RX_DPHY_CL_RST BIT(16) +#define CSI2RX_DPHY_DL_RST (i) BIT((i) + 12) +#define CSI2RX_DPHY_CL_EN BIT(4) +#define CSI2RX_DPHY_DL_EN (i) BIT(i) +#define CSI2RX_STREAM_BASE (n) (((n) + 1) * 0x100)#define CSI2RX_STREAM_CTRL_REG (n) (CSI2RX_STREAM_BASE(n) + 0x000)
@@ -37,6 +45,7 @@#define CSI2RX_STREAM_DATA_CFG_REG (n) (CSI2RX_STREAM_BASE(n) + 0x008)#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT BIT(31) +#define CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 BIT(7)#define CSI2RX_STREAM_DATA_CFG_VC_SELECT (n) BIT((n) + 16)#define CSI2RX_STREAM_CFG_REG (n) (CSI2RX_STREAM_BASE(n) + 0x00c)
@@ -54,8 +63,19 @@ enum csi2rx_pads { CSI2RX_PAD_MAX, }; +struct csi2rx_fmt { +u32 code; +u8 bpp; +u32 dt; +}; + +struct csi2rx_platform_info { +unsigned long sys_clk_rate; +}; +struct csi2rx_priv {struct device *dev; +unsigned int power_count;unsigned int count;/*
@@ -68,6 +88,9 @@ struct csi2rx_priv {struct clk *sys_clk;struct clk *p_clk;struct clk *pixel_clk[CSI2RX_STREAMS_MAX ]; +struct reset_control *sys_rst; +struct reset_control *p_rst; +struct reset_control *pixel_rst[CSI2RX_STREAMS_MAX ];struct phy *dphy;u8 lanes[CSI2RX_LANES_MAX ];
@@ -83,14 +106,100 @@ struct csi2rx_priv {/* Remote source */ struct v4l2_subdev *source_subdev;int source_pad; + +const struct csi2rx_platform_info *platform_info; +}; + +static const struct csi2rx_fmt formats[] = { + { + .code =MEDIA_BUS_FMT_SRGGB10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SGRBG10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SGBRG10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SBGGR10_1X10 , + .bpp =10 , + .dt =0x2b , + }, }; +static u8 csi2rx_get_bpp (u32 code) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (formats); i++) { +if (formats[i].code == code) +return formats[i].bpp; + } + +return 0 ; +} + +static u32 csi2rx_get_dt (u32 code) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (formats); i++) { +if (formats[i].code == code) +return formats[i].dt; + } + +return 0 ; +} + +static s64 csi2rx_get_pixel_rate (struct csi2rx_priv *csi2rx) +{ +struct v4l2_ctrl *ctrl; + + ctrl =v4l2_ctrl_find (csi2rx->source_subdev->ctrl_handler, +V4L2_CID_PIXEL_RATE ); +if (!ctrl) { +dev_err (csi2rx->dev,"no pixel rate control in subdev: %s\n" , + csi2rx->source_subdev->name); +return -EINVAL ; + } + +return v4l2_ctrl_g_ctrl_int64 (ctrl); +} +static inline struct csi2rx_priv *v4l2_subdev_to_csi2rx (struct v4l2_subdev *subdev) { return container_of(subdev, struct csi2rx_priv, subdev); } +static int csi2rx_s_power (struct v4l2_subdev *subdev,int on) +{ +struct csi2rx_priv *csi2rx =v4l2_subdev_to_csi2rx (subdev); + +mutex_lock (&csi2rx->lock); + +if (on) { +if (!csi2rx->power_count) +phy_init (csi2rx->dphy); + + csi2rx->power_count++; + }else { + csi2rx->power_count--; + +if (!csi2rx->power_count) +phy_exit (csi2rx->dphy); + } + +mutex_unlock (&csi2rx->lock); +return 0 ; +} +static void csi2rx_reset (struct csi2rx_priv *csi2rx) { writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,
@@ -101,17 +210,70 @@ static void csi2rx_reset(struct csi2rx_priv *csi2rx)writel (0 , csi2rx->base +CSI2RX_SOFT_RESET_REG ); } +static int csi2rx_configure_ext_dphy (struct csi2rx_priv *csi2rx) +{ +union phy_configure_opts opts = { }; +struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy; +struct v4l2_subdev_format sd_fmt; +s64 pixel_rate; +int ret; +u8 bpp; + + sd_fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + sd_fmt.pad =0 ; + + ret =v4l2_subdev_call (csi2rx->source_subdev, pad, get_fmt,NULL , + &sd_fmt); +if (ret) +return ret; + + bpp =csi2rx_get_bpp (sd_fmt.format.code); +if (!bpp) +return -EINVAL ; + + pixel_rate =csi2rx_get_pixel_rate (csi2rx); +if (pixel_rate <0 ) +return pixel_rate; + + ret =phy_mipi_dphy_get_default_config (pixel_rate, bpp, + csi2rx->num_lanes, cfg); +if (ret) +return ret; + +phy_pm_runtime_get_sync (csi2rx->dphy); + + ret =phy_power_on (csi2rx->dphy); +if (ret) + goto out; + + ret =phy_configure (csi2rx->dphy, &opts); +if (ret) { +/* Can't do anything if it fails. Ignore the return value. */ +phy_power_off (csi2rx->dphy); + goto out; + } + +out: +phy_pm_runtime_put_sync (csi2rx->dphy); + +return ret; +} +static int csi2rx_start (struct csi2rx_priv *csi2rx) { +struct v4l2_subdev_format sd_fmt;unsigned int i;unsigned long lanes_used =0 ;u32 reg; +u32 dt =0 ;int ret; ret =clk_prepare_enable (csi2rx->p_clk);if (ret)return ret; +reset_control_deassert (csi2rx->p_rst); +csi2rx_reset (csi2rx); reg = csi2rx->num_lanes <<8 ;
@@ -139,6 +301,29 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pclk; +/* Enable DPHY clk and data lanes. */ +if (csi2rx->dphy) { + reg =CSI2RX_DPHY_CL_EN |CSI2RX_DPHY_CL_RST ; +for (i =0 ; i < csi2rx->num_lanes; i++) { + reg |=CSI2RX_DPHY_DL_EN (csi2rx->lanes[i] -1 ); + reg |=CSI2RX_DPHY_DL_RST (csi2rx->lanes[i] -1 ); + } + +writel (reg, csi2rx->base +CSI2RX_DPHY_LANE_CTRL_REG ); + } + + sd_fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + sd_fmt.pad =0 ; + + ret =v4l2_subdev_call (csi2rx->source_subdev, pad, get_fmt,NULL , + &sd_fmt); +if (ret) +dev_warn (csi2rx->dev,"Couldn't get format\n" ); + + dt =csi2rx_get_dt (sd_fmt.format.code); +if (!dt) +dev_warn (csi2rx->dev,"Couldn't get dt\n" ); +/* * Create a static mapping between the CSI virtual channels * and the output stream.
@@ -154,6 +339,8 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pixclk; +reset_control_deassert (csi2rx->pixel_rst[i]); +writel (CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF , csi2rx->base +CSI2RX_STREAM_CFG_REG (i));
@@ -161,6 +348,11 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)CSI2RX_STREAM_DATA_CFG_VC_SELECT (i), csi2rx->base + CSI2RX_STREAM_DATA_CFG_REG(i)); +if (dt) +writel (readl (csi2rx->base +CSI2RX_STREAM_DATA_CFG_REG (i)) | +CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 | dt, + csi2rx->base +CSI2RX_STREAM_DATA_CFG_REG (i)); +writel (CSI2RX_STREAM_CTRL_START , csi2rx->base +CSI2RX_STREAM_CTRL_REG (i)); }
@@ -169,10 +361,27 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pixclk; +if (csi2rx->platform_info && csi2rx->platform_info->sys_clk_rate >0 ) +clk_set_rate (csi2rx->sys_clk, + csi2rx->platform_info->sys_clk_rate); + +reset_control_deassert (csi2rx->sys_rst); + +if (csi2rx->dphy) { + ret =csi2rx_configure_ext_dphy (csi2rx); +if (ret) { +dev_err (csi2rx->dev, +"Failed to configure external DPHY: %d\n" , ret); + goto err_disable_sysclk; + } + } +clk_disable_unprepare (csi2rx->p_clk);return 0 ; +err_disable_sysclk: +clk_disable_unprepare (csi2rx->sys_clk); err_disable_pixclk:for (; i >0 ; i--)clk_disable_unprepare (csi2rx->pixel_clk[i -1 ]);
@@ -188,18 +397,28 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx)unsigned int i;clk_prepare_enable (csi2rx->p_clk); +reset_control_assert (csi2rx->sys_rst);clk_disable_unprepare (csi2rx->sys_clk);for (i =0 ; i < csi2rx->max_streams; i++) {writel (0 , csi2rx->base +CSI2RX_STREAM_CTRL_REG (i)); +reset_control_assert (csi2rx->pixel_rst[i]);clk_disable_unprepare (csi2rx->pixel_clk[i]); } +reset_control_assert (csi2rx->p_rst);clk_disable_unprepare (csi2rx->p_clk);if (v4l2_subdev_call (csi2rx->source_subdev, video, s_stream, false))dev_warn (csi2rx->dev,"Couldn't disable our subdev\n" ); + +if (csi2rx->dphy) { +writel (0 , csi2rx->base +CSI2RX_DPHY_LANE_CTRL_REG ); + +if (phy_power_off (csi2rx->dphy)) +dev_warn (csi2rx->dev,"Couldn't power off DPHY\n" ); + } }static int csi2rx_s_stream (struct v4l2_subdev *subdev,int enable)
@@ -236,11 +455,16 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)return ret; } +static const struct v4l2_subdev_core_ops csi2rx_core_ops = { + .s_power = csi2rx_s_power, +}; +static const struct v4l2_subdev_video_ops csi2rx_video_ops = { .s_stream = csi2rx_s_stream, };static const struct v4l2_subdev_ops csi2rx_subdev_ops = { + .core = &csi2rx_core_ops, .video = &csi2rx_video_ops, };
@@ -250,6 +474,8 @@ static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, {struct v4l2_subdev *subdev = notifier->sd;struct csi2rx_priv *csi2rx =v4l2_subdev_to_csi2rx (subdev); +struct v4l2_device *v4l2_dev; +int ret; csi2rx->source_pad = media_entity_get_fwnode_pad(&s_subdev->entity, s_subdev->fwnode,
@@ -265,6 +491,15 @@ static int csi2rx_async_bound(struct v4l2_async_notifier *notifier,dev_dbg (csi2rx->dev,"Bound %s pad: %d\n" , s_subdev->name, csi2rx->source_pad); +/* ensure source subdev register subdev node */ + v4l2_dev = notifier->v4l2_dev ? notifier->v4l2_dev : + notifier->parent->v4l2_dev; +if (v4l2_dev) { + ret =v4l2_device_register_subdev_nodes (v4l2_dev); +if (ret <0 ) +return ret; + } + return media_create_pad_link(&csi2rx->source_subdev->entity, csi2rx->source_pad, &csi2rx->subdev.entity, 0,
@@ -299,21 +534,23 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,return PTR_ERR (csi2rx->p_clk); } + csi2rx->sys_rst = +devm_reset_control_get_optional_exclusive (&pdev->dev, +"sys_rst" ); +if (IS_ERR (csi2rx->sys_rst)) +return PTR_ERR (csi2rx->sys_rst); + + csi2rx->p_rst = +devm_reset_control_get_optional_exclusive (&pdev->dev,"p_rst" ); +if (IS_ERR (csi2rx->p_rst)) +return PTR_ERR (csi2rx->p_rst); + csi2rx->dphy =devm_phy_optional_get (&pdev->dev,"dphy" );if (IS_ERR (csi2rx->dphy)) {dev_err (&pdev->dev,"Couldn't get external D-PHY\n" );return PTR_ERR (csi2rx->dphy); } -/* -* FIXME: Once we'll have external D-PHY support, the check -* will need to be removed. -*/ -if (csi2rx->dphy) { -dev_err (&pdev->dev,"External D-PHY not supported yet\n" ); -return -EINVAL ; - } - ret =clk_prepare_enable (csi2rx->p_clk);if (ret) {dev_err (&pdev->dev,"Couldn't prepare and enable P clock\n" );
@@ -343,13 +580,14 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,* FIXME: Once we'll have internal D-PHY support, the check * will need to be removed. */ -if (csi2rx->has_internal_dphy) { +if (!csi2rx->dphy && csi2rx->has_internal_dphy) {dev_err (&pdev->dev,"Internal D-PHY not supported yet\n" );return -EINVAL ; }for (i =0 ; i < csi2rx->max_streams; i++) {char clk_name[16 ]; +char rst_name[16 ];snprintf (clk_name,sizeof (clk_name),"pixel_if%u_clk" , i); csi2rx->pixel_clk[i] =devm_clk_get (&pdev->dev, clk_name);
@@ -357,6 +595,13 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,dev_err (&pdev->dev,"Couldn't get clock %s\n" , clk_name);return PTR_ERR (csi2rx->pixel_clk[i]); } + +snprintf (rst_name,sizeof (rst_name),"pixel_if%u_rst" , i); + csi2rx->pixel_rst[i] = +devm_reset_control_get_optional_exclusive (&pdev->dev, + rst_name); +if (IS_ERR (csi2rx->pixel_rst[i])) +return PTR_ERR (csi2rx->pixel_rst[i]); }return 0 ;
@@ -425,6 +670,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx =kzalloc (sizeof (*csi2rx),GFP_KERNEL );if (!csi2rx)return -ENOMEM ; + csi2rx->platform_info =of_device_get_match_data (&pdev->dev);platform_set_drvdata (pdev, csi2rx); csi2rx->dev = &pdev->dev;mutex_init (&csi2rx->lock);
@@ -441,6 +687,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx->subdev.dev = &pdev->dev;v4l2_subdev_init (&csi2rx->subdev, &csi2rx_subdev_ops);v4l2_set_subdevdata (&csi2rx->subdev, &pdev->dev); + csi2rx->subdev.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;snprintf (csi2rx->subdev.name,V4L2_SUBDEV_NAME_SIZE ,"%s.%s" ,KBUILD_MODNAME ,dev_name (&pdev->dev));
@@ -462,6 +709,7 @@ static int csi2rx_probe(struct platform_device *pdev)dev_info (&pdev->dev,"Probed CSI2RX with %u/%u lanes, %u streams, %s D-PHY\n" , csi2rx->num_lanes, csi2rx->max_lanes, csi2rx->max_streams, + csi2rx->dphy ?"external" : csi2rx->has_internal_dphy ?"internal" :"no" );return 0 ;
@@ -483,8 +731,13 @@ static int csi2rx_remove(struct platform_device *pdev)return 0 ; } +static const struct csi2rx_platform_info stf_jh7110_info = { + .sys_clk_rate =297000000 , +}; +static const struct of_device_id csi2rx_of_table[] = { { .compatible ="cdns,csi2rx" }, + { .compatible ="starfive,jh7110-csi2rx" , .data = &stf_jh7110_info }, { }, };MODULE_DEVICE_TABLE (of, csi2rx_of_table);
Signature · 1 line
2.34.1
Re: [PATCH v2 4/6] media: cadence: Add support for external dphy and JH7110 SoC
Hi Jack,
Thank you for the patch.
Quoted 2 lines · Jack Zhu
Add support for external MIPI D-PHY and Starfive JH7110 SoC which has the cadence csi2 receiver.
This patch bundles multiple changes that should be split into their own patches. I'll comment on that below.
Quoted 139 lines
Signed-off-by Jack Zhu <[email protected]>--- drivers/media/platform/cadence/cdns-csi2rx.c | 273 ++++++++++++++++++- 1 file changed, 263 insertions(+), 10 deletions(-)drivers/media/platform/cadence/cdns-csi2rx.c +84
-0@@ -10,9 +10,11 @@#include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/reset.h> #include <linux/slab.h> #include <media/v4l2-ctrls.h> @@ -30,6 +32,12 @@#define CSI2RX_STATIC_CFG_DLANE_MAP (llane, plane) ((plane) << (16 + (llane) * 4))#define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8) +#define CSI2RX_DPHY_LANE_CTRL_REG 0x40 +#define CSI2RX_DPHY_CL_RST BIT(16) +#define CSI2RX_DPHY_DL_RST (i) BIT((i) + 12) +#define CSI2RX_DPHY_CL_EN BIT(4) +#define CSI2RX_DPHY_DL_EN (i) BIT(i) +#define CSI2RX_STREAM_BASE (n) (((n) + 1) * 0x100)#define CSI2RX_STREAM_CTRL_REG (n) (CSI2RX_STREAM_BASE(n) + 0x000)@@ -37,6 +45,7 @@#define CSI2RX_STREAM_DATA_CFG_REG (n) (CSI2RX_STREAM_BASE(n) + 0x008)#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT BIT(31) +#define CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 BIT(7)#define CSI2RX_STREAM_DATA_CFG_VC_SELECT (n) BIT((n) + 16)#define CSI2RX_STREAM_CFG_REG (n) (CSI2RX_STREAM_BASE(n) + 0x00c)@@ -54,8 +63,19 @@ enum csi2rx_pads { CSI2RX_PAD_MAX, }; +struct csi2rx_fmt { +u32 code; +u8 bpp; +u32 dt; +}; + +struct csi2rx_platform_info { +unsigned long sys_clk_rate; +}; +struct csi2rx_priv {struct device *dev; +unsigned int power_count;unsigned int count;/* @@ -68,6 +88,9 @@ struct csi2rx_priv {struct clk *sys_clk;struct clk *p_clk;struct clk *pixel_clk[CSI2RX_STREAMS_MAX ]; +struct reset_control *sys_rst; +struct reset_control *p_rst; +struct reset_control *pixel_rst[CSI2RX_STREAMS_MAX ];struct phy *dphy;u8 lanes[CSI2RX_LANES_MAX ];@@ -83,14 +106,100 @@ struct csi2rx_priv {/* Remote source */ struct v4l2_subdev *source_subdev;int source_pad; + +const struct csi2rx_platform_info *platform_info; +}; + +static const struct csi2rx_fmt formats[] = { + { + .code =MEDIA_BUS_FMT_SRGGB10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SGRBG10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SGBRG10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SBGGR10_1X10 , + .bpp =10 , + .dt =0x2b , + }, }; +static u8 csi2rx_get_bpp (u32 code) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (formats); i++) { +if (formats[i].code == code) +return formats[i].bpp; + } + +return 0 ; +} + +static u32 csi2rx_get_dt (u32 code) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (formats); i++) { +if (formats[i].code == code) +return formats[i].dt; + } + +return 0 ; +} + +static s64 csi2rx_get_pixel_rate (struct csi2rx_priv *csi2rx) +{ +struct v4l2_ctrl *ctrl; + + ctrl =v4l2_ctrl_find (csi2rx->source_subdev->ctrl_handler, +V4L2_CID_PIXEL_RATE ); +if (!ctrl) { +dev_err (csi2rx->dev,"no pixel rate control in subdev: %s\n" , + csi2rx->source_subdev->name); +return -EINVAL ; + } +
drivers/media/platform/cadence/cdns-csi2rx.c struct csi2rx_priv { · line 181
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2rx.c +4
-0+return v4l2_ctrl_g_ctrl_int64 (ctrl); +} +static inline struct csi2rx_priv *v4l2_subdev_to_csi2rx (struct v4l2_subdev *subdev) { return container_of(subdev, struct csi2rx_priv, subdev); } +static int csi2rx_s_power (struct v4l2_subdev *subdev,int on)
.s_power() is deprecated, please drop it. You should use runtime PM instead (with autosuspend). In .s_stream(), you should call pm_runtime_resume_and_get() when starting streaming, and pm_runtime_put_autosuspend() when stopping streaming.
Quoted 25 lines
drivers/media/platform/cadence/cdns-csi2rx.c +21
-0+{ +struct csi2rx_priv *csi2rx =v4l2_subdev_to_csi2rx (subdev); + +mutex_lock (&csi2rx->lock); + +if (on) { +if (!csi2rx->power_count) +phy_init (csi2rx->dphy); + + csi2rx->power_count++; + }else { + csi2rx->power_count--; + +if (!csi2rx->power_count) +phy_exit (csi2rx->dphy); + } + +mutex_unlock (&csi2rx->lock); +return 0 ; +} +static void csi2rx_reset (struct csi2rx_priv *csi2rx) { writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 213
Quoted 4 lines
drivers/media/platform/cadence/cdns-csi2rx.c +1
-0@@ -101,17 +210,70 @@ static void csi2rx_reset(struct csi2rx_priv *csi2rx)writel (0 , csi2rx->base +CSI2RX_SOFT_RESET_REG ); } +static int csi2rx_configure_ext_dphy (struct csi2rx_priv *csi2rx)
Support for external DPHYs should be split to a patch of its own.
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 226
Quoted 13 lines
drivers/media/platform/cadence/cdns-csi2rx.c +13
-0+{ +union phy_configure_opts opts = { }; +struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy; +struct v4l2_subdev_format sd_fmt; +s64 pixel_rate; +int ret; +u8 bpp; + + sd_fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + sd_fmt.pad =0 ; + + ret =v4l2_subdev_call (csi2rx->source_subdev, pad, get_fmt,NULL , + &sd_fmt);
Don't call .get_fmt() on the source. A subdev driver should only look at its own formats. As the format on the source pad of the source must match the format on the sink pad of this subdev when the pipeline is valid, you can use the format on the sink pad here.
Quoted 39 lines
drivers/media/platform/cadence/cdns-csi2rx.c +36
-0+if (ret) +return ret; + + bpp =csi2rx_get_bpp (sd_fmt.format.code); +if (!bpp) +return -EINVAL ; + + pixel_rate =csi2rx_get_pixel_rate (csi2rx); +if (pixel_rate <0 ) +return pixel_rate; + + ret =phy_mipi_dphy_get_default_config (pixel_rate, bpp, + csi2rx->num_lanes, cfg); +if (ret) +return ret; + +phy_pm_runtime_get_sync (csi2rx->dphy); + + ret =phy_power_on (csi2rx->dphy); +if (ret) + goto out; + + ret =phy_configure (csi2rx->dphy, &opts); +if (ret) { +/* Can't do anything if it fails. Ignore the return value. */ +phy_power_off (csi2rx->dphy); + goto out; + } + +out: +phy_pm_runtime_put_sync (csi2rx->dphy); + +return ret; +} +static int csi2rx_start (struct csi2rx_priv *csi2rx) { +struct v4l2_subdev_format sd_fmt;unsigned int i;
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 275
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2rx.c +2
-0unsigned long lanes_used =0 ;u32 reg; +u32 dt =0 ;int ret; ret =clk_prepare_enable (csi2rx->p_clk);if (ret)return ret; +reset_control_deassert (csi2rx->p_rst);
Support for reset controllers should also be split to a patch of its own.
Quoted 14 lines
drivers/media/platform/cadence/cdns-csi2rx.c +7
-0+csi2rx_reset (csi2rx); reg = csi2rx->num_lanes <<8 ;@@ -139,6 +301,29 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pclk; +/* Enable DPHY clk and data lanes. */ +if (csi2rx->dphy) { + reg =CSI2RX_DPHY_CL_EN |CSI2RX_DPHY_CL_RST ; +for (i =0 ; i < csi2rx->num_lanes; i++) { + reg |=CSI2RX_DPHY_DL_EN (csi2rx->lanes[i] -1 ); + reg |=CSI2RX_DPHY_DL_RST (csi2rx->lanes[i] -1 );
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_start(struct csi2rx_priv *csi2rx) · line 319
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2rx.c +10
-0+ } + +writel (reg, csi2rx->base +CSI2RX_DPHY_LANE_CTRL_REG ); + } + + sd_fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + sd_fmt.pad =0 ; + + ret =v4l2_subdev_call (csi2rx->source_subdev, pad, get_fmt,NULL , + &sd_fmt);
Same as above regarding the format.
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_start(struct csi2rx_priv *csi2rx) · line 324
Quoted 5 lines
drivers/media/platform/cadence/cdns-csi2rx.c +5
-0+if (ret) +dev_warn (csi2rx->dev,"Couldn't get format\n" ); + + dt =csi2rx_get_dt (sd_fmt.format.code); +if (!dt)
When you reach this point, the format should be guaranteed to be valid as .set_fmt() will have adjusted it. There should thus be no need to handle errors.
Quoted 15 lines
drivers/media/platform/cadence/cdns-csi2rx.c +4
-0+dev_warn (csi2rx->dev,"Couldn't get dt\n" ); +/* * Create a static mapping between the CSI virtual channels * and the output stream. @@ -154,6 +339,8 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pixclk; +reset_control_deassert (csi2rx->pixel_rst[i]); +writel (CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF , csi2rx->base +CSI2RX_STREAM_CFG_REG (i));
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_start(struct csi2rx_priv *csi2rx) · line 354
Quoted 7 lines
drivers/media/platform/cadence/cdns-csi2rx.c +4
-0@@ -161,6 +348,11 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)CSI2RX_STREAM_DATA_CFG_VC_SELECT (i), csi2rx->base + CSI2RX_STREAM_DATA_CFG_REG(i)); +if (dt) +writel (readl (csi2rx->base +CSI2RX_STREAM_DATA_CFG_REG (i)) | +CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 | dt, + csi2rx->base +CSI2RX_STREAM_DATA_CFG_REG (i));
Support for CSI-2 DT should be split to a patch of its own.
Quoted 88 lines
drivers/media/platform/cadence/cdns-csi2rx.c +35
-0+writel (CSI2RX_STREAM_CTRL_START , csi2rx->base +CSI2RX_STREAM_CTRL_REG (i)); }@@ -169,10 +361,27 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pixclk; +if (csi2rx->platform_info && csi2rx->platform_info->sys_clk_rate >0 ) +clk_set_rate (csi2rx->sys_clk, + csi2rx->platform_info->sys_clk_rate); + +reset_control_deassert (csi2rx->sys_rst); + +if (csi2rx->dphy) { + ret =csi2rx_configure_ext_dphy (csi2rx); +if (ret) { +dev_err (csi2rx->dev, +"Failed to configure external DPHY: %d\n" , ret); + goto err_disable_sysclk; + } + } +clk_disable_unprepare (csi2rx->p_clk);return 0 ; +err_disable_sysclk: +clk_disable_unprepare (csi2rx->sys_clk); err_disable_pixclk:for (; i >0 ; i--)clk_disable_unprepare (csi2rx->pixel_clk[i -1 ]);@@ -188,18 +397,28 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx)unsigned int i;clk_prepare_enable (csi2rx->p_clk); +reset_control_assert (csi2rx->sys_rst);clk_disable_unprepare (csi2rx->sys_clk);for (i =0 ; i < csi2rx->max_streams; i++) {writel (0 , csi2rx->base +CSI2RX_STREAM_CTRL_REG (i)); +reset_control_assert (csi2rx->pixel_rst[i]);clk_disable_unprepare (csi2rx->pixel_clk[i]); } +reset_control_assert (csi2rx->p_rst);clk_disable_unprepare (csi2rx->p_clk);if (v4l2_subdev_call (csi2rx->source_subdev, video, s_stream, false))dev_warn (csi2rx->dev,"Couldn't disable our subdev\n" ); + +if (csi2rx->dphy) { +writel (0 , csi2rx->base +CSI2RX_DPHY_LANE_CTRL_REG ); + +if (phy_power_off (csi2rx->dphy)) +dev_warn (csi2rx->dev,"Couldn't power off DPHY\n" ); + } }static int csi2rx_s_stream (struct v4l2_subdev *subdev,int enable)@@ -236,11 +455,16 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)return ret; } +static const struct v4l2_subdev_core_ops csi2rx_core_ops = { + .s_power = csi2rx_s_power, +}; +static const struct v4l2_subdev_video_ops csi2rx_video_ops = { .s_stream = csi2rx_s_stream, };static const struct v4l2_subdev_ops csi2rx_subdev_ops = { + .core = &csi2rx_core_ops, .video = &csi2rx_video_ops, };@@ -250,6 +474,8 @@ static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, {struct v4l2_subdev *subdev = notifier->sd;struct csi2rx_priv *csi2rx =v4l2_subdev_to_csi2rx (subdev); +struct v4l2_device *v4l2_dev; +int ret; csi2rx->source_pad = media_entity_get_fwnode_pad(&s_subdev->entity, s_subdev->fwnode,
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, · line 498
Quoted 8 lines
drivers/media/platform/cadence/cdns-csi2rx.c +5
-0@@ -265,6 +491,15 @@ static int csi2rx_async_bound(struct v4l2_async_notifier *notifier,dev_dbg (csi2rx->dev,"Bound %s pad: %d\n" , s_subdev->name, csi2rx->source_pad); +/* ensure source subdev register subdev node */ + v4l2_dev = notifier->v4l2_dev ? notifier->v4l2_dev : + notifier->parent->v4l2_dev; +if (v4l2_dev) { + ret =v4l2_device_register_subdev_nodes (v4l2_dev);
This belongs to the main driver (the camss in your case), not this driver.
Quoted 95 lines
drivers/media/platform/cadence/cdns-csi2rx.c +27
-10+if (ret <0 ) +return ret; + } + return media_create_pad_link(&csi2rx->source_subdev->entity, csi2rx->source_pad, &csi2rx->subdev.entity, 0,@@ -299,21 +534,23 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,return PTR_ERR (csi2rx->p_clk); } + csi2rx->sys_rst = +devm_reset_control_get_optional_exclusive (&pdev->dev, +"sys_rst" ); +if (IS_ERR (csi2rx->sys_rst)) +return PTR_ERR (csi2rx->sys_rst); + + csi2rx->p_rst = +devm_reset_control_get_optional_exclusive (&pdev->dev,"p_rst" ); +if (IS_ERR (csi2rx->p_rst)) +return PTR_ERR (csi2rx->p_rst); + csi2rx->dphy =devm_phy_optional_get (&pdev->dev,"dphy" );if (IS_ERR (csi2rx->dphy)) {dev_err (&pdev->dev,"Couldn't get external D-PHY\n" );return PTR_ERR (csi2rx->dphy); } -/* -* FIXME: Once we'll have external D-PHY support, the check -* will need to be removed. -*/ -if (csi2rx->dphy) { -dev_err (&pdev->dev,"External D-PHY not supported yet\n" ); -return -EINVAL ; - } - ret =clk_prepare_enable (csi2rx->p_clk);if (ret) {dev_err (&pdev->dev,"Couldn't prepare and enable P clock\n" );@@ -343,13 +580,14 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,* FIXME: Once we'll have internal D-PHY support, the check * will need to be removed. */ -if (csi2rx->has_internal_dphy) { +if (!csi2rx->dphy && csi2rx->has_internal_dphy) {dev_err (&pdev->dev,"Internal D-PHY not supported yet\n" );return -EINVAL ; }for (i =0 ; i < csi2rx->max_streams; i++) {char clk_name[16 ]; +char rst_name[16 ];snprintf (clk_name,sizeof (clk_name),"pixel_if%u_clk" , i); csi2rx->pixel_clk[i] =devm_clk_get (&pdev->dev, clk_name);@@ -357,6 +595,13 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,dev_err (&pdev->dev,"Couldn't get clock %s\n" , clk_name);return PTR_ERR (csi2rx->pixel_clk[i]); } + +snprintf (rst_name,sizeof (rst_name),"pixel_if%u_rst" , i); + csi2rx->pixel_rst[i] = +devm_reset_control_get_optional_exclusive (&pdev->dev, + rst_name); +if (IS_ERR (csi2rx->pixel_rst[i])) +return PTR_ERR (csi2rx->pixel_rst[i]); }return 0 ;@@ -425,6 +670,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx =kzalloc (sizeof (*csi2rx),GFP_KERNEL );if (!csi2rx)return -ENOMEM ; + csi2rx->platform_info =of_device_get_match_data (&pdev->dev);platform_set_drvdata (pdev, csi2rx); csi2rx->dev = &pdev->dev;mutex_init (&csi2rx->lock);@@ -441,6 +687,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx->subdev.dev = &pdev->dev;v4l2_subdev_init (&csi2rx->subdev, &csi2rx_subdev_ops);v4l2_set_subdevdata (&csi2rx->subdev, &pdev->dev); + csi2rx->subdev.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;snprintf (csi2rx->subdev.name,V4L2_SUBDEV_NAME_SIZE ,"%s.%s" ,KBUILD_MODNAME ,dev_name (&pdev->dev));@@ -462,6 +709,7 @@ static int csi2rx_probe(struct platform_device *pdev)dev_info (&pdev->dev,"Probed CSI2RX with %u/%u lanes, %u streams, %s D-PHY\n" , csi2rx->num_lanes, csi2rx->max_lanes, csi2rx->max_streams, + csi2rx->dphy ?"external" : csi2rx->has_internal_dphy ?"internal" :"no" );return 0 ;
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_remove(struct platform_device *pdev) · line 735
Quoted 5 lines
drivers/media/platform/cadence/cdns-csi2rx.c +2
-0@@ -483,8 +731,13 @@ static int csi2rx_remove(struct platform_device *pdev)return 0 ; } +static const struct csi2rx_platform_info stf_jh7110_info = { + .sys_clk_rate =297000000 ,
This sounds like something that would be better handled through the assigned-clock-rates property in DT.
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_remove(struct platform_device *pdev) · line 740
Quoted 5 lines
drivers/media/platform/cadence/cdns-csi2rx.c +3
-0+}; +static const struct of_device_id csi2rx_of_table[] = { { .compatible ="cdns,csi2rx" }, + { .compatible ="starfive,jh7110-csi2rx" , .data = &stf_jh7110_info },
I would move SoC-specific compatible strings before the generic one. Maxime, is there a need to keep the generic compatible string now that we have SoC-specific support ?
Quoted 3 lines
drivers/media/platform/cadence/cdns-csi2rx.c +0
-0{ }, };MODULE_DEVICE_TABLE (of, csi2rx_of_table);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 4/6] media: cadence: Add support for external dphy and JH7110 SoC
Quoted 10 lines · Laurent Pinchart
Hi Jack,
Thank you for the patch.
Quoted 2 lines · Jack Zhu
Add support for external MIPI D-PHY and Starfive JH7110 SoC which has the cadence csi2 receiver.
This patch bundles multiple changes that should be split into their own patches. I'll comment on that below.
Thank you for your suggestion and comments. I'll split the patch.
Quoted 149 lines
Quoted 149 lines
Signed-off-by Jack Zhu <[email protected]>--- drivers/media/platform/cadence/cdns-csi2rx.c | 273 ++++++++++++++++++- 1 file changed, 263 insertions(+), 10 deletions(-)drivers/media/platform/cadence/cdns-csi2rx.c +87
-0@@ -10,9 +10,11 @@#include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/reset.h> #include <linux/slab.h> #include <media/v4l2-ctrls.h> @@ -30,6 +32,12 @@#define CSI2RX_STATIC_CFG_DLANE_MAP (llane, plane) ((plane) << (16 + (llane) * 4))#define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8) +#define CSI2RX_DPHY_LANE_CTRL_REG 0x40 +#define CSI2RX_DPHY_CL_RST BIT(16) +#define CSI2RX_DPHY_DL_RST (i) BIT((i) + 12) +#define CSI2RX_DPHY_CL_EN BIT(4) +#define CSI2RX_DPHY_DL_EN (i) BIT(i) +#define CSI2RX_STREAM_BASE (n) (((n) + 1) * 0x100)#define CSI2RX_STREAM_CTRL_REG (n) (CSI2RX_STREAM_BASE(n) + 0x000)@@ -37,6 +45,7 @@#define CSI2RX_STREAM_DATA_CFG_REG (n) (CSI2RX_STREAM_BASE(n) + 0x008)#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT BIT(31) +#define CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 BIT(7)#define CSI2RX_STREAM_DATA_CFG_VC_SELECT (n) BIT((n) + 16)#define CSI2RX_STREAM_CFG_REG (n) (CSI2RX_STREAM_BASE(n) + 0x00c)@@ -54,8 +63,19 @@ enum csi2rx_pads { CSI2RX_PAD_MAX, }; +struct csi2rx_fmt { +u32 code; +u8 bpp; +u32 dt; +}; + +struct csi2rx_platform_info { +unsigned long sys_clk_rate; +}; +struct csi2rx_priv {struct device *dev; +unsigned int power_count;unsigned int count;/* @@ -68,6 +88,9 @@ struct csi2rx_priv {struct clk *sys_clk;struct clk *p_clk;struct clk *pixel_clk[CSI2RX_STREAMS_MAX ]; +struct reset_control *sys_rst; +struct reset_control *p_rst; +struct reset_control *pixel_rst[CSI2RX_STREAMS_MAX ];struct phy *dphy;u8 lanes[CSI2RX_LANES_MAX ];@@ -83,14 +106,100 @@ struct csi2rx_priv {/* Remote source */ struct v4l2_subdev *source_subdev;int source_pad; + +const struct csi2rx_platform_info *platform_info; +}; + +static const struct csi2rx_fmt formats[] = { + { + .code =MEDIA_BUS_FMT_SRGGB10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SGRBG10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SGBRG10_1X10 , + .bpp =10 , + .dt =0x2b , + }, + { + .code =MEDIA_BUS_FMT_SBGGR10_1X10 , + .bpp =10 , + .dt =0x2b , + }, }; +static u8 csi2rx_get_bpp (u32 code) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (formats); i++) { +if (formats[i].code == code) +return formats[i].bpp; + } + +return 0 ; +} + +static u32 csi2rx_get_dt (u32 code) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (formats); i++) { +if (formats[i].code == code) +return formats[i].dt; + } + +return 0 ; +} + +static s64 csi2rx_get_pixel_rate (struct csi2rx_priv *csi2rx) +{ +struct v4l2_ctrl *ctrl; + + ctrl =v4l2_ctrl_find (csi2rx->source_subdev->ctrl_handler, +V4L2_CID_PIXEL_RATE ); +if (!ctrl) { +dev_err (csi2rx->dev,"no pixel rate control in subdev: %s\n" , + csi2rx->source_subdev->name); +return -EINVAL ; + } + +return v4l2_ctrl_g_ctrl_int64 (ctrl); +} +static inline struct csi2rx_priv *v4l2_subdev_to_csi2rx (struct v4l2_subdev *subdev) { return container_of(subdev, struct csi2rx_priv, subdev); }
Quoted 7 lines
drivers/media/platform/cadence/cdns-csi2rx.c struct csi2rx_priv { · line 181
Quoted 1 line
drivers/media/platform/cadence/cdns-csi2rx.c +1
-0+static int csi2rx_s_power (struct v4l2_subdev *subdev,int on).s_power() is deprecated, please drop it. You should use runtime PM instead (with autosuspend). In .s_stream(), you should call
pm_runtime_resume_and_get()when starting streaming, andpm_runtime_put_autosuspend()when stopping streaming.
OK, will drop .s_power(). The csi2rx will do not call phy_init()/ phy_exit(). The work of phy_init()/phy_exit() is integrated into PHY driver.
Quoted 28 lines
Quoted 28 lines
drivers/media/platform/cadence/cdns-csi2rx.c +21
-0+{ +struct csi2rx_priv *csi2rx =v4l2_subdev_to_csi2rx (subdev); + +mutex_lock (&csi2rx->lock); + +if (on) { +if (!csi2rx->power_count) +phy_init (csi2rx->dphy); + + csi2rx->power_count++; + }else { + csi2rx->power_count--; + +if (!csi2rx->power_count) +phy_exit (csi2rx->dphy); + } + +mutex_unlock (&csi2rx->lock); +return 0 ; +} +static void csi2rx_reset (struct csi2rx_priv *csi2rx) { writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,@@ -101,17 +210,70 @@ static void csi2rx_reset(struct csi2rx_priv *csi2rx)writel (0 , csi2rx->base +CSI2RX_SOFT_RESET_REG ); }
Quoted 3 lines
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 213
Quoted 1 line
drivers/media/platform/cadence/cdns-csi2rx.c +1
-0+static int csi2rx_configure_ext_dphy (struct csi2rx_priv *csi2rx)Support for external DPHYs should be split to a patch of its own.
OK, will split the patch.
Quoted 11 lines
Quoted 11 lines
drivers/media/platform/cadence/cdns-csi2rx.c +10
-0+{ +union phy_configure_opts opts = { }; +struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy; +struct v4l2_subdev_format sd_fmt; +s64 pixel_rate; +int ret; +u8 bpp; + + sd_fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + sd_fmt.pad =0 ;
Quoted 8 lines
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 226
Quoted 3 lines
drivers/media/platform/cadence/cdns-csi2rx.c +3
-0+ + ret =v4l2_subdev_call (csi2rx->source_subdev, pad, get_fmt,NULL , + &sd_fmt);Don't call .get_fmt() on the source. A subdev driver should only look at its own formats. As the format on the source pad of the source must match the format on the sink pad of this subdev when the pipeline is valid, you can use the format on the sink pad here.
OK, will drop. This step of work is not necessary.
Quoted 45 lines
Quoted 45 lines
drivers/media/platform/cadence/cdns-csi2rx.c +37
-0+if (ret) +return ret; + + bpp =csi2rx_get_bpp (sd_fmt.format.code); +if (!bpp) +return -EINVAL ; + + pixel_rate =csi2rx_get_pixel_rate (csi2rx); +if (pixel_rate <0 ) +return pixel_rate; + + ret =phy_mipi_dphy_get_default_config (pixel_rate, bpp, + csi2rx->num_lanes, cfg); +if (ret) +return ret; + +phy_pm_runtime_get_sync (csi2rx->dphy); + + ret =phy_power_on (csi2rx->dphy); +if (ret) + goto out; + + ret =phy_configure (csi2rx->dphy, &opts); +if (ret) { +/* Can't do anything if it fails. Ignore the return value. */ +phy_power_off (csi2rx->dphy); + goto out; + } + +out: +phy_pm_runtime_put_sync (csi2rx->dphy); + +return ret; +} +static int csi2rx_start (struct csi2rx_priv *csi2rx) { +struct v4l2_subdev_format sd_fmt;unsigned int i;unsigned long lanes_used =0 ;u32 reg; +u32 dt =0 ;int ret;
Quoted 8 lines
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 275
Quoted 5 lines
drivers/media/platform/cadence/cdns-csi2rx.c +1
-0ret =clk_prepare_enable (csi2rx->p_clk);if (ret)return ret; +reset_control_deassert (csi2rx->p_rst);Support for reset controllers should also be split to a patch of its own.
OK, will split the patch according to logic change.
Quoted 19 lines
Quoted 19 lines
drivers/media/platform/cadence/cdns-csi2rx.c +11
-0+csi2rx_reset (csi2rx); reg = csi2rx->num_lanes <<8 ;@@ -139,6 +301,29 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pclk; +/* Enable DPHY clk and data lanes. */ +if (csi2rx->dphy) { + reg =CSI2RX_DPHY_CL_EN |CSI2RX_DPHY_CL_RST ; +for (i =0 ; i < csi2rx->num_lanes; i++) { + reg |=CSI2RX_DPHY_DL_EN (csi2rx->lanes[i] -1 ); + reg |=CSI2RX_DPHY_DL_RST (csi2rx->lanes[i] -1 ); + } + +writel (reg, csi2rx->base +CSI2RX_DPHY_LANE_CTRL_REG ); + }
Quoted 8 lines
drivers/media/platform/cadence/cdns-csi2rx.c static void csi2rx_reset(struct csi2rx_priv *csi2rx) · line 226
Quoted 6 lines
drivers/media/platform/cadence/cdns-csi2rx.c +6
-0+ + sd_fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + sd_fmt.pad =0 ; + + ret =v4l2_subdev_call (csi2rx->source_subdev, pad, get_fmt,NULL , + &sd_fmt);Same as above regarding the format.
OK, will fix.
Quoted 29 lines
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_start(struct csi2rx_priv *csi2rx) · line 324
Quoted 6 lines
drivers/media/platform/cadence/cdns-csi2rx.c +5
-0+if (ret) +dev_warn (csi2rx->dev,"Couldn't get format\n" ); + + dt =csi2rx_get_dt (sd_fmt.format.code); +if (!dt)When you reach this point, the format should be guaranteed to be valid as .set_fmt() will have adjusted it. There should thus be no need to handle errors.
Quoted 18 lines
drivers/media/platform/cadence/cdns-csi2rx.c +4
-0+dev_warn (csi2rx->dev,"Couldn't get dt\n" ); +/* * Create a static mapping between the CSI virtual channels * and the output stream. @@ -154,6 +339,8 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pixclk; +reset_control_deassert (csi2rx->pixel_rst[i]); +writel (CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF , csi2rx->base +CSI2RX_STREAM_CFG_REG (i));@@ -161,6 +348,11 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)CSI2RX_STREAM_DATA_CFG_VC_SELECT (i), csi2rx->base + CSI2RX_STREAM_DATA_CFG_REG(i));
Quoted 6 lines
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_start(struct csi2rx_priv *csi2rx) · line 354
Quoted 4 lines
drivers/media/platform/cadence/cdns-csi2rx.c +4
-0+if (dt) +writel (readl (csi2rx->base +CSI2RX_STREAM_DATA_CFG_REG (i)) | +CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 | dt, + csi2rx->base +CSI2RX_STREAM_DATA_CFG_REG (i));Support for CSI-2 DT should be split to a patch of its own.
CSI-2 DT is not necessary. I will drop the relevant code.
Quoted 92 lines
Quoted 92 lines
drivers/media/platform/cadence/cdns-csi2rx.c +35
-0+writel (CSI2RX_STREAM_CTRL_START , csi2rx->base +CSI2RX_STREAM_CTRL_REG (i)); }@@ -169,10 +361,27 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)if (ret) goto err_disable_pixclk; +if (csi2rx->platform_info && csi2rx->platform_info->sys_clk_rate >0 ) +clk_set_rate (csi2rx->sys_clk, + csi2rx->platform_info->sys_clk_rate); + +reset_control_deassert (csi2rx->sys_rst); + +if (csi2rx->dphy) { + ret =csi2rx_configure_ext_dphy (csi2rx); +if (ret) { +dev_err (csi2rx->dev, +"Failed to configure external DPHY: %d\n" , ret); + goto err_disable_sysclk; + } + } +clk_disable_unprepare (csi2rx->p_clk);return 0 ; +err_disable_sysclk: +clk_disable_unprepare (csi2rx->sys_clk); err_disable_pixclk:for (; i >0 ; i--)clk_disable_unprepare (csi2rx->pixel_clk[i -1 ]);@@ -188,18 +397,28 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx)unsigned int i;clk_prepare_enable (csi2rx->p_clk); +reset_control_assert (csi2rx->sys_rst);clk_disable_unprepare (csi2rx->sys_clk);for (i =0 ; i < csi2rx->max_streams; i++) {writel (0 , csi2rx->base +CSI2RX_STREAM_CTRL_REG (i)); +reset_control_assert (csi2rx->pixel_rst[i]);clk_disable_unprepare (csi2rx->pixel_clk[i]); } +reset_control_assert (csi2rx->p_rst);clk_disable_unprepare (csi2rx->p_clk);if (v4l2_subdev_call (csi2rx->source_subdev, video, s_stream, false))dev_warn (csi2rx->dev,"Couldn't disable our subdev\n" ); + +if (csi2rx->dphy) { +writel (0 , csi2rx->base +CSI2RX_DPHY_LANE_CTRL_REG ); + +if (phy_power_off (csi2rx->dphy)) +dev_warn (csi2rx->dev,"Couldn't power off DPHY\n" ); + } }static int csi2rx_s_stream (struct v4l2_subdev *subdev,int enable)@@ -236,11 +455,16 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)return ret; } +static const struct v4l2_subdev_core_ops csi2rx_core_ops = { + .s_power = csi2rx_s_power, +}; +static const struct v4l2_subdev_video_ops csi2rx_video_ops = { .s_stream = csi2rx_s_stream, };static const struct v4l2_subdev_ops csi2rx_subdev_ops = { + .core = &csi2rx_core_ops, .video = &csi2rx_video_ops, };@@ -250,6 +474,8 @@ static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, {struct v4l2_subdev *subdev = notifier->sd;struct csi2rx_priv *csi2rx =v4l2_subdev_to_csi2rx (subdev); +struct v4l2_device *v4l2_dev; +int ret; csi2rx->source_pad = media_entity_get_fwnode_pad(&s_subdev->entity, s_subdev->fwnode,@@ -265,6 +491,15 @@ static int csi2rx_async_bound(struct v4l2_async_notifier *notifier,dev_dbg (csi2rx->dev,"Bound %s pad: %d\n" , s_subdev->name, csi2rx->source_pad);
Quoted 8 lines
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, · line 498
Quoted 5 lines
drivers/media/platform/cadence/cdns-csi2rx.c +5
-0+/* ensure source subdev register subdev node */ + v4l2_dev = notifier->v4l2_dev ? notifier->v4l2_dev : + notifier->parent->v4l2_dev; +if (v4l2_dev) { + ret =v4l2_device_register_subdev_nodes (v4l2_dev);This belongs to the main driver (the camss in your case), not this driver.
OK, will fix.
Quoted 99 lines
Quoted 99 lines
drivers/media/platform/cadence/cdns-csi2rx.c +27
-10+if (ret <0 ) +return ret; + } + return media_create_pad_link(&csi2rx->source_subdev->entity, csi2rx->source_pad, &csi2rx->subdev.entity, 0,@@ -299,21 +534,23 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,return PTR_ERR (csi2rx->p_clk); } + csi2rx->sys_rst = +devm_reset_control_get_optional_exclusive (&pdev->dev, +"sys_rst" ); +if (IS_ERR (csi2rx->sys_rst)) +return PTR_ERR (csi2rx->sys_rst); + + csi2rx->p_rst = +devm_reset_control_get_optional_exclusive (&pdev->dev,"p_rst" ); +if (IS_ERR (csi2rx->p_rst)) +return PTR_ERR (csi2rx->p_rst); + csi2rx->dphy =devm_phy_optional_get (&pdev->dev,"dphy" );if (IS_ERR (csi2rx->dphy)) {dev_err (&pdev->dev,"Couldn't get external D-PHY\n" );return PTR_ERR (csi2rx->dphy); } -/* -* FIXME: Once we'll have external D-PHY support, the check -* will need to be removed. -*/ -if (csi2rx->dphy) { -dev_err (&pdev->dev,"External D-PHY not supported yet\n" ); -return -EINVAL ; - } - ret =clk_prepare_enable (csi2rx->p_clk);if (ret) {dev_err (&pdev->dev,"Couldn't prepare and enable P clock\n" );@@ -343,13 +580,14 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,* FIXME: Once we'll have internal D-PHY support, the check * will need to be removed. */ -if (csi2rx->has_internal_dphy) { +if (!csi2rx->dphy && csi2rx->has_internal_dphy) {dev_err (&pdev->dev,"Internal D-PHY not supported yet\n" );return -EINVAL ; }for (i =0 ; i < csi2rx->max_streams; i++) {char clk_name[16 ]; +char rst_name[16 ];snprintf (clk_name,sizeof (clk_name),"pixel_if%u_clk" , i); csi2rx->pixel_clk[i] =devm_clk_get (&pdev->dev, clk_name);@@ -357,6 +595,13 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,dev_err (&pdev->dev,"Couldn't get clock %s\n" , clk_name);return PTR_ERR (csi2rx->pixel_clk[i]); } + +snprintf (rst_name,sizeof (rst_name),"pixel_if%u_rst" , i); + csi2rx->pixel_rst[i] = +devm_reset_control_get_optional_exclusive (&pdev->dev, + rst_name); +if (IS_ERR (csi2rx->pixel_rst[i])) +return PTR_ERR (csi2rx->pixel_rst[i]); }return 0 ;@@ -425,6 +670,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx =kzalloc (sizeof (*csi2rx),GFP_KERNEL );if (!csi2rx)return -ENOMEM ; + csi2rx->platform_info =of_device_get_match_data (&pdev->dev);platform_set_drvdata (pdev, csi2rx); csi2rx->dev = &pdev->dev;mutex_init (&csi2rx->lock);@@ -441,6 +687,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx->subdev.dev = &pdev->dev;v4l2_subdev_init (&csi2rx->subdev, &csi2rx_subdev_ops);v4l2_set_subdevdata (&csi2rx->subdev, &pdev->dev); + csi2rx->subdev.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;snprintf (csi2rx->subdev.name,V4L2_SUBDEV_NAME_SIZE ,"%s.%s" ,KBUILD_MODNAME ,dev_name (&pdev->dev));@@ -462,6 +709,7 @@ static int csi2rx_probe(struct platform_device *pdev)dev_info (&pdev->dev,"Probed CSI2RX with %u/%u lanes, %u streams, %s D-PHY\n" , csi2rx->num_lanes, csi2rx->max_lanes, csi2rx->max_streams, + csi2rx->dphy ?"external" : csi2rx->has_internal_dphy ?"internal" :"no" );return 0 ;@@ -483,8 +731,13 @@ static int csi2rx_remove(struct platform_device *pdev)return 0 ; }
Quoted 5 lines
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_remove(struct platform_device *pdev) · line 735
Quoted 2 lines
drivers/media/platform/cadence/cdns-csi2rx.c +2
-0+static const struct csi2rx_platform_info stf_jh7110_info = { + .sys_clk_rate =297000000 ,This sounds like something that would be better handled through the assigned-clock-rates property in DT.
OK, will use assigned-clock-rates property in DT.
Quoted 8 lines
drivers/media/platform/cadence/cdns-csi2rx.c static int csi2rx_remove(struct platform_device *pdev) · line 740
Quoted 6 lines
drivers/media/platform/cadence/cdns-csi2rx.c +3
-0+}; +static const struct of_device_id csi2rx_of_table[] = { { .compatible ="cdns,csi2rx" }, + { .compatible ="starfive,jh7110-csi2rx" , .data = &stf_jh7110_info },I would move SoC-specific compatible strings before the generic one.
OK, will move it before the generic one.
Quoted 2 lines
Maxime, is there a need to keep the generic compatible string now that we have SoC-specific support ?
The existing bindings state
- compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible
It might be better to keep the generic compatible string.
Quoted 5 lines
Quoted 4 lines
drivers/media/platform/cadence/cdns-csi2rx.c +0
-0{ }, };MODULE_DEVICE_TABLE (of, csi2rx_of_table);
PATCH v2 5/6 MAINTAINERS: Add Starfive Camera Subsystem driver
In reply to Jack ZhuAdd an entry for Starfive Camera Subsystem driver.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -19907,6 +19907,15 @@ 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/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]> S: Maintained
Signature · 1 line
2.34.1
Re: [PATCH v2 5/6] MAINTAINERS: Add Starfive Camera Subsystem driver
Hi Jack,
Thank you for the patch.
Quoted 13 lines · Jack Zhu
Add an entry for Starfive Camera Subsystem driver.
Signed-off-by Jack Zhu <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -19907,6 +19907,15 @@ M: Ion Badulescu <[email protected]> S: Odd Fixes
MAINTAINERS M: Ion Badulescu <[email protected]> · line 19917
Quoted 10 lines
MAINTAINERS +8
-0F: 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/admin-guide/media/starfive_camss.rst +F: Documentation/devicetree/bindings/media/starfive,jh7110-camss.yaml +F: drivers/media/platform/starfive/
You could also add the MAINTAINERS entry in patch 1/6, with just the .yaml file to start with, and extend it in the patches that add more files. Up to you, I don't mind much.
Quoted 4 lines
MAINTAINERS +1
-0+ STARFIVE DEVICETREES M: Emil Renner Berthing <[email protected]> S: Maintained
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 5/6] MAINTAINERS: Add Starfive Camera Subsystem driver
Quoted 20 lines · Laurent Pinchart
Hi Jack,
Thank you for the patch.
Quoted 15 lines · Jack Zhu
Add an entry for Starfive Camera Subsystem driver.
Signed-off-by Jack Zhu <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -19907,6 +19907,15 @@ M: Ion Badulescu <[email protected]> S: Odd Fixes F: drivers/net/ethernet/adaptec/starfire*
Quoted 12 lines
MAINTAINERS M: Ion Badulescu <[email protected]> · line 19917
Quoted 8 lines
MAINTAINERS +8
-0+STARFIVE CAMERA SUBSYSTEM DRIVER +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 +F: drivers/media/platform/starfive/You could also add the
MAINTAINERSentry in patch 1/6, with just the .yaml file to start with, and extend it in the patches that add more files. Up to you, I don't mind much.
Thank you for your suggestion, I will do that.
Quoted 6 lines
Quoted 5 lines
MAINTAINERS +1
-0+ STARFIVE DEVICETREES M: Emil Renner Berthing <[email protected]> S: Maintained
PATCH v2 6/6 media: starfive: Add Starfive Camera Subsystem driver
In reply to Jack ZhuAdd the driver for Starfive Camera Subsystem found on Starfive JH7110 SoC. It is used for handing image sensor data.
--- drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/starfive/Kconfig | 18 + drivers/media/platform/starfive/Makefile | 14 + drivers/media/platform/starfive/stf_camss.c | 728 +++++++++ drivers/media/platform/starfive/stf_camss.h | 104 ++ drivers/media/platform/starfive/stf_common.h | 149 ++ drivers/media/platform/starfive/stf_isp.c | 1079 ++++++++++++++ drivers/media/platform/starfive/stf_isp.h | 183 +++ .../media/platform/starfive/stf_isp_hw_ops.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.h | 89 ++ drivers/media/platform/starfive/stf_vin.c | 1314 +++++++++++++++++ drivers/media/platform/starfive/stf_vin.h | 194 +++ .../media/platform/starfive/stf_vin_hw_ops.c | 357 +++++ include/uapi/linux/stf_isp_ioctl.h | 127 ++ 16 files changed, 6930 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 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 create mode 100644 include/uapi/linux/stf_isp_ioctl.h
drivers/media/platform/Kconfig +1 -0
@@ -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
@@ -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 +18 -0
@@ -0,0 +1,18 @@ +# 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 + 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 +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for StarFive camera subsystem driver. +# + +starfive-camss-objs += \ + stf_camss.o \ + stf_isp.o \ + stf_isp_hw_ops.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 new file +728 -0
728 lines not on this page · raw message
drivers/media/platform/starfive/stf_camss.h new file +104 -0
104 lines not on this page · raw message
drivers/media/platform/starfive/stf_common.h new file +149 -0
149 lines not on this page · raw message
drivers/media/platform/starfive/stf_isp.c new file +1079 -0
1,079 lines not on this page · raw message
drivers/media/platform/starfive/stf_isp.h new file +183 -0
183 lines not on this page · raw message
drivers/media/platform/starfive/stf_isp_hw_ops.c new file +1286 -0
711 lines not on this page · raw message
drivers/media/platform/starfive/stf_video.c new file +1286 -0
1,286 lines not on this page · raw message
drivers/media/platform/starfive/stf_video.h new file +89 -0
89 lines not on this page · raw message
drivers/media/platform/starfive/stf_vin.c new file +1314 -0
1,314 lines not on this page · raw message
drivers/media/platform/starfive/stf_vin.h new file +194 -0
194 lines not on this page · raw message
drivers/media/platform/starfive/stf_vin_hw_ops.c new file +357 -0
357 lines not on this page · raw message
include/uapi/linux/stf_isp_ioctl.h new file +127 -0
127 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
kernel test robot
build botRe: [PATCH v2 6/6] media: starfive: Add Starfive Camera Subsystem driver
I love your patch! Yet something to improve:
Hi Jack,
I love your patch! Yet something to improve:
[auto build test ERROR on media-tree/master]
[also build test ERROR on robh/for-next linus/master v6.3-rc1 next-20230310] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jack-Zhu/media-dt-bindings-Add-bindings-for-JH7110-Camera-Subsystem/20230310-200747 base: git://linuxtv.org/media_tree.git master patch link: https://lore.kernel.org/r/20230310120553.60586-7-jack.zhu%40starfivetech.com patch subject: [PATCH v2 6/6] media: starfive: Add Starfive Camera Subsystem driver config: i386-randconfig-a001 (https://download.01.org/0day-ci/archive/20230310/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/99a31fd3820a2d95b0d0f381491c473975e0b068
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jack-Zhu/media-dt-bindings-Add-bindings-for-JH7110-Camera-Subsystem/20230310-200747 git checkout 99a31fd3820a2d95b0d0f381491c473975e0b068
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 prepare
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> error: include/uapi/linux/stf_isp_ioctl.h: missing "WITH Linux-syscall-note" for SPDX-License-Identifier
make[2]: *** [scripts/Makefile.headersinst:63: usr/include/linux/stf_isp_ioctl.h] Error 1 make[2]: Target '__headers' not remade because of errors.
make[1]: *** [Makefile:1394: headers] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:242: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH v2 6/6] media: starfive: Add Starfive Camera Subsystem driver
In reply to Jack ZhuI love your patch! Yet something to improve:
Hi Jack,
I love your patch! Yet something to improve:
[auto build test ERROR on media-tree/master]
[also build test ERROR on robh/for-next linus/master v6.3-rc1 next-20230310] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jack-Zhu/media-dt-bindings-Add-bindings-for-JH7110-Camera-Subsystem/20230310-200747 base: git://linuxtv.org/media_tree.git master patch link: https://lore.kernel.org/r/20230310120553.60586-7-jack.zhu%40starfivetech.com patch subject: [PATCH v2 6/6] media: starfive: Add Starfive Camera Subsystem driver config: i386-randconfig-c021 (https://download.01.org/0day-ci/archive/20230310/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/99a31fd3820a2d95b0d0f381491c473975e0b068
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jack-Zhu/media-dt-bindings-Add-bindings-for-JH7110-Camera-Subsystem/20230310-200747 git checkout 99a31fd3820a2d95b0d0f381491c473975e0b068
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 prepare
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> error: include/uapi/linux/stf_isp_ioctl.h: missing "WITH Linux-syscall-note" for SPDX-License-Identifier
make[2]: *** [scripts/Makefile.headersinst:63: usr/include/linux/stf_isp_ioctl.h] Error 1 make[2]: Target '__headers' not remade because of errors.
make[1]: *** [Makefile:1394: headers] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:242: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 6/6] media: starfive: Add Starfive Camera Subsystem driver
Hi Jack,
Quoted 48 lines · Jack Zhu
Quoted 6 lines · Laurent Pinchart
Hi Jack,
Thank you for the patch.
I'll do a partial review here as the patch is huge and I'm lacking time at the moment.
Thank you for the review and your time.
Quoted 38 lines · Jack Zhu
Quoted 37 lines
Add the driver for Starfive Camera Subsystem found on Starfive JH7110 SoC. It is used for handing image sensor data.
Signed-off-by Jack Zhu <[email protected]>--- drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/starfive/Kconfig | 18 + drivers/media/platform/starfive/Makefile | 14 + drivers/media/platform/starfive/stf_camss.c | 728 +++++++++ drivers/media/platform/starfive/stf_camss.h | 104 ++ drivers/media/platform/starfive/stf_common.h | 149 ++ drivers/media/platform/starfive/stf_isp.c | 1079 ++++++++++++++ drivers/media/platform/starfive/stf_isp.h | 183 +++ .../media/platform/starfive/stf_isp_hw_ops.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.h | 89 ++ drivers/media/platform/starfive/stf_vin.c | 1314 +++++++++++++++++ drivers/media/platform/starfive/stf_vin.h | 194 +++ .../media/platform/starfive/stf_vin_hw_ops.c | 357 +++++ include/uapi/linux/stf_isp_ioctl.h | 127 ++ 16 files changed, 6930 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 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 create mode 100644 include/uapi/linux/stf_isp_ioctl.h
[snip]
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/platform/starfive/stf_camss.c new file +0
-0@@ -0,0 +1,728 @@
[snip]
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
+/*
+ *stfcamss_find_sensor- Find a linked media entity which represents a sensor
+ * @entity: Media entity to start searching from
+ *Quoted 8 lines
Quoted 3 lines
+ * Return a pointer to sensor media entity or NULL if not found
+ */
+structmedia_entity*stfcamss_find_sensor(structmedia_entity*entity)From a camss point of view, the source is the csi2rx. You shouldn't need to access the sensor directly, only the csi2rx. If you think you have a need to access the sensor, please explain why and we can discuss it.
Quoted 1 line
need to use format and bpp of sensor to configure isp HW.
You can obtain the same information from the ISP sink pad:
+----------+ +------------+ +-----------+ | | | | | | | Sensor [0| ----> |0] csi2rx [1| ----> |0] ISP | | | | | | | +----------+ +------------+ +-----------+
(I'm not entirely sure if the csi2rx and ISP pad numbers are correct, but that's the idea.)
The csi2rx can't modify the format (size and bpp), so the format on the sensor's pad 0, csi2rx pad 0, csi2rx pad 1 and ISP pad 0 must be identical.
In isp_sensor_fmt_to_index(), the ISP driver doesn't need to get the format from the sensor, it can use the format on ISP pad 0 instead.
In video_enum_framesizes(), the ISP driver shouldn't look at the format on the ISP input at all, it must enumerate all sizes that the video node supports, regardless of what is connected to its input.
video_enum_frameintervals() should be dropped, the ISP itself has no notion of frame interval. Userspace can query and configure the frame rate from the sensor subdev directly.
In video_pipeline_s_fmt(), the ISP driver shouldn't look at the format on the ISP input at all either. It must accept any format supported by the ISP. It's only when starting streaming that the pipeline is validated to make sure the formats configured on all subdevs match. I recommend reading https://git.ideasonboard.org/doc/mc-v4l2.git for an overview of how Media Controller-based drivers should behave. The documentation describes how the API is meant to be used from userspace, but the operating principles apply to driver development too.
video_subscribe_event() and video_unsubscribe_event() should also be dropped, events from the sensor can be accessed by userspace on the sensor subdev directly.
vin_set_stream() should call .s_stream() on the csi2rx, not the sensor. The csi2rx .s_stream() handler will forward the call to the sensor.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/media/platform/starfive/stf_camss.c new file +21
-0+{ +struct media_pad *pad; + +while (1 ) { +if (!entity->pads) +return NULL ; + + pad = &entity->pads[0 ]; +if (!(pad->flags &MEDIA_PAD_FL_SINK )) +return NULL ; + + pad =media_pad_remote_pad_first (pad); +if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) +return NULL ; + + entity = pad->entity; + +if (entity->function ==MEDIA_ENT_F_CAM_SENSOR ) +return entity; + } +}
[snip]
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/uapi/linux/stf_isp_ioctl.h new file +0
-0@@ -0,0 +1,127 @@
[snip]
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+enum
_STF_ISP_IOCTL{Device-specific ioctls are allowed, but they must all be clearly documented.
OK, I will add annotations for these ioctls.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
include/uapi/linux/stf_isp_ioctl.h line 31
Quoted 1 line
include/uapi/linux/stf_isp_ioctl.h new file +1
-0+ STF_ISP_IOCTL_LOAD_FW = BASE_VIDIOC_PRIVATE + 1,Why can't you use the Linux kernel firmware API ?
The ioctl is used for loading config file, it is different from the Linux kernel firmware API. I will rename it.
Could you explain what the config file is used for ?
Quoted 29 lines
Quoted 5 lines
include/uapi/linux/stf_isp_ioctl.h line 34
Quoted 3 lines
include/uapi/linux/stf_isp_ioctl.h new file +3
-0+STF_ISP_IOCTL_DMABUF_ALLOC , +STF_ISP_IOCTL_DMABUF_FREE , + STF_ISP_IOCTL_GET_HW_VER,Not used, drop them.
OK, will drop them.
Quoted 4 lines
include/uapi/linux/stf_isp_ioctl.h line 35
Quoted 2 lines
include/uapi/linux/stf_isp_ioctl.h new file +1
-0+ STF_ISP_IOCTL_REG,Setting registers from userspace isn't allowed. No exception.
OK, will fix.
Quoted 9 lines
include/uapi/linux/stf_isp_ioctl.h line 39
Quoted 5 lines
include/uapi/linux/stf_isp_ioctl.h new file +4
-0+STF_ISP_IOCTL_SHADOW_LOCK , +STF_ISP_IOCTL_SHADOW_UNLOCK , +STF_ISP_IOCTL_SHADOW_UNLOCK_N_TRIGGER , + STF_ISP_IOCTL_SET_USER_CONFIG_ISP,I'm not sure what these ioctls do exactly as documentation is missing, but I don't think they are the right API. Please describe the problem you're trying to solve, and we'll find a good API.
These were used for debugging, I will drop them. Thanks.
Quoted 2 lines
Quoted 2 lines
include/uapi/linux/stf_isp_ioctl.h new file +2
-0+ STF_ISP_IOCTL_MAX +};
[snip]
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 6/6] media: starfive: Add Starfive Camera Subsystem driver
Quoted 114 lines · Laurent Pinchart
Hi Jack,
Quoted 48 lines · Jack Zhu
Quoted 6 lines · Laurent Pinchart
Hi Jack,
Thank you for the patch.
I'll do a partial review here as the patch is huge and I'm lacking time at the moment.
Thank you for the review and your time.
Quoted 38 lines · Jack Zhu
Quoted 37 lines
Add the driver for Starfive Camera Subsystem found on Starfive JH7110 SoC. It is used for handing image sensor data.
Signed-off-by Jack Zhu <[email protected]>--- drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/starfive/Kconfig | 18 + drivers/media/platform/starfive/Makefile | 14 + drivers/media/platform/starfive/stf_camss.c | 728 +++++++++ drivers/media/platform/starfive/stf_camss.h | 104 ++ drivers/media/platform/starfive/stf_common.h | 149 ++ drivers/media/platform/starfive/stf_isp.c | 1079 ++++++++++++++ drivers/media/platform/starfive/stf_isp.h | 183 +++ .../media/platform/starfive/stf_isp_hw_ops.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.c | 1286 ++++++++++++++++ drivers/media/platform/starfive/stf_video.h | 89 ++ drivers/media/platform/starfive/stf_vin.c | 1314 +++++++++++++++++ drivers/media/platform/starfive/stf_vin.h | 194 +++ .../media/platform/starfive/stf_vin_hw_ops.c | 357 +++++ include/uapi/linux/stf_isp_ioctl.h | 127 ++ 16 files changed, 6930 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 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 create mode 100644 include/uapi/linux/stf_isp_ioctl.h[snip]
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/platform/starfive/stf_camss.c new file +0
-0@@ -0,0 +1,728 @@[snip]
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
+/*
+ *stfcamss_find_sensor- Find a linked media entity which represents a sensor
+ * @entity: Media entity to start searching from
+ *Quoted 8 lines
Quoted 3 lines
+ * Return a pointer to sensor media entity or NULL if not found
+ */
+structmedia_entity*stfcamss_find_sensor(structmedia_entity*entity)From a camss point of view, the source is the csi2rx. You shouldn't need to access the sensor directly, only the csi2rx. If you think you have a need to access the sensor, please explain why and we can discuss it.
Quoted 1 line
need to use format and bpp of sensor to configure isp HW.
You can obtain the same information from the ISP sink pad:
+----------+ +------------+ +-----------+ | | | | | | | Sensor [0| ----> |0] csi2rx [1| ----> |0] ISP | | | | | | | +----------+ +------------+ +-----------+(I'm not entirely sure if the csi2rx and ISP pad numbers are correct, but that's the idea.)
The csi2rx can't modify the format (size and bpp), so the format on the sensor's pad 0, csi2rx pad 0, csi2rx pad 1 and ISP pad 0 must be identical.
In
isp_sensor_fmt_to_index(), the ISP driver doesn't need to get the format from the sensor, it can use the format on ISP pad 0 instead.In
video_enum_framesizes(), the ISP driver shouldn't look at the format on the ISP input at all, it must enumerate all sizes that the video node supports, regardless of what is connected to its input.
video_enum_frameintervals()should be dropped, the ISP itself has no notion of frame interval. Userspace can query and configure the frame rate from the sensor subdev directly.In
video_pipeline_s_fmt(), the ISP driver shouldn't look at the format on the ISP input at all either. It must accept any format supported by the ISP. It's only when starting streaming that the pipeline is validated to make sure the formats configured on all subdevs match. I recommend reading https://git.ideasonboard.org/doc/mc-v4l2.git for an overview of how Media Controller-based drivers should behave. The documentation describes how the API is meant to be used from userspace, but the operating principles apply to driver development too.
Quoted 7 lines
video_subscribe_event()andvideo_unsubscribe_event()should also be dropped, events from the sensor can be accessed by userspace on the sensor subdev directly.
vin_set_stream()should call .s_stream() on the csi2rx, not the sensor. The csi2rx .s_stream() handler will forward the call to the sensor.
OK, will fix. Thank you for your comment.
Quoted 41 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/media/platform/starfive/stf_camss.c new file +21
-0+{ +struct media_pad *pad; + +while (1 ) { +if (!entity->pads) +return NULL ; + + pad = &entity->pads[0 ]; +if (!(pad->flags &MEDIA_PAD_FL_SINK )) +return NULL ; + + pad =media_pad_remote_pad_first (pad); +if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) +return NULL ; + + entity = pad->entity; + +if (entity->function ==MEDIA_ENT_F_CAM_SENSOR ) +return entity; + } +}[snip]
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/uapi/linux/stf_isp_ioctl.h new file +0
-0@@ -0,0 +1,127 @@[snip]
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+enum
_STF_ISP_IOCTL{Device-specific ioctls are allowed, but they must all be clearly documented.
OK, I will add annotations for these ioctls.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
include/uapi/linux/stf_isp_ioctl.h line 31
Quoted 1 line
include/uapi/linux/stf_isp_ioctl.h new file +1
-0+ STF_ISP_IOCTL_LOAD_FW = BASE_VIDIOC_PRIVATE + 1,Why can't you use the Linux kernel firmware API ?
The ioctl is used for loading config file, it is different from the Linux kernel firmware API. I will rename it.
Could you explain what the config file is used for ?
used for debugging. It's not necessary. I will drop it.
Quoted 33 lines
Quoted 30 lines
Quoted 6 lines
include/uapi/linux/stf_isp_ioctl.h line 34
Quoted 4 lines
include/uapi/linux/stf_isp_ioctl.h new file +3
-0+STF_ISP_IOCTL_DMABUF_ALLOC , +STF_ISP_IOCTL_DMABUF_FREE , + STF_ISP_IOCTL_GET_HW_VER,Not used, drop them.
OK, will drop them.
Quoted 4 lines
include/uapi/linux/stf_isp_ioctl.h line 35
Quoted 2 lines
include/uapi/linux/stf_isp_ioctl.h new file +1
-0+ STF_ISP_IOCTL_REG,Setting registers from userspace isn't allowed. No exception.
OK, will fix.
Quoted 9 lines
include/uapi/linux/stf_isp_ioctl.h line 39
Quoted 5 lines
include/uapi/linux/stf_isp_ioctl.h new file +4
-0+STF_ISP_IOCTL_SHADOW_LOCK , +STF_ISP_IOCTL_SHADOW_UNLOCK , +STF_ISP_IOCTL_SHADOW_UNLOCK_N_TRIGGER , + STF_ISP_IOCTL_SET_USER_CONFIG_ISP,I'm not sure what these ioctls do exactly as documentation is missing, but I don't think they are the right API. Please describe the problem you're trying to solve, and we'll find a good API.
These were used for debugging, I will drop them. Thanks.
Quoted 2 lines
Quoted 2 lines
include/uapi/linux/stf_isp_ioctl.h new file +2
-0+ STF_ISP_IOCTL_MAX +};[snip]