Skip to contentSkip to conversation

Add Mediatek ISP3.0

PATCH Superseded Julien Stephan 5 participants 22 messages Jun 30, 2023 – Aug 4, 2023

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add Mediatek ISP3.0

This series add the support of the Mediatek ISP3.0 found on some Mediatek SoCs such as the mt8365. The driver is divided into 2 parts:

* SENINF: the sensor interface
* CAMSV: this driver provides a path to bypass the SoC ISP so that image data coming from the SENINF can go directly into memory without any image processing. This allows the use of an external ISP or camera sensor directly.

The SENINF driver is based on previous work done by Louis Kuo available
as an RFC here: https://lore.kernel.org/all/[email protected]/

This series depends on the following series: [1] for the phy, [2] for power management support

Changes in v2:
- renamed clock cam_seninf to camsys
- renamed clock top_mux_seninf to top_mux
- moved phy properties from port nodes to top level
- remove patternProperties
- specify power management dependency in the cover letter description to fix missing include in dt-binding example
- change '$ref' properties on some endpoint nodes from
'$ref: video-interfaces.yaml#' to '$ref: /schemas/graph.yaml#/$defs/endpoint-base'
where applicable

Best
Julien Stephan

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

Louis Kuo (2):
dt-bindings: media: add mediatek ISP3.0 sensor interface
media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor
interface

Phi-bang Nguyen (2):
dt-bindings: media: add mediatek ISP3.0 camsv
media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

 .../bindings/media/mediatek,mt8365-camsv.yaml |  113 ++
 .../media/mediatek,mt8365-seninf.yaml         |  295 ++++
 MAINTAINERS                                   |   10 +
 drivers/media/platform/mediatek/Kconfig       |    1 +
 drivers/media/platform/mediatek/Makefile      |    1 +
 drivers/media/platform/mediatek/isp/Kconfig   |    2 +
 drivers/media/platform/mediatek/isp/Makefile  |    3 +
 .../platform/mediatek/isp/isp_30/Kconfig      |   35 +
 .../platform/mediatek/isp/isp_30/Makefile     |    4 +
 .../mediatek/isp/isp_30/camsv/Makefile        |    7 +
 .../mediatek/isp/isp_30/camsv/mtk_camsv.c     |  334 ++++
 .../mediatek/isp/isp_30/camsv/mtk_camsv.h     |  200 +++
 .../isp/isp_30/camsv/mtk_camsv30_hw.c         |  474 +++++
 .../isp/isp_30/camsv/mtk_camsv30_regs.h       |   59 +
 .../isp/isp_30/camsv/mtk_camsv_video.c        |  781 +++++++++
 .../mediatek/isp/isp_30/seninf/Makefile       |    5 +
 .../mediatek/isp/isp_30/seninf/mtk_seninf.c   | 1561 +++++++++++++++++
 .../isp/isp_30/seninf/mtk_seninf_reg.h        |   99 ++
 18 files changed, 3984 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
 create mode 100644 drivers/media/platform/mediatek/isp/Kconfig
 create mode 100644 drivers/media/platform/mediatek/isp/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Kconfig
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_regs.h
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv_video.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h

--
2.41.0

#1 lore raw

PATCH v2 1/4 dt-bindings: media: add mediatek ISP3.0 sensor interface

From: Louis Kuo <[email protected]>

This adds the bindings, for the mediatek ISP3.0 SENINF module embedded in some Mediatek SoC, such as the mt8365

---
 .../media/mediatek,mt8365-seninf.yaml         | 295 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 302 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml new file +295 -0
new file mode 100644
index 000000000000..1697e94853f5
@@ -0,0 +1,295 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/mediatek,mt8365-seninf.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek Sensor Interface 3.0
+
+maintainers:
+  - Laurent Pinchart <[email protected]>
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The ISP3.0 SENINF is the CSI-2 and parallel camera sensor interface found in
+  multiple MediaTek SoCs. It can support up to three physical CSI-2
+  input ports, configured in DPHY (2 or 4 data lanes) or CPHY depending on the SoC.
+  On the output side, SENINF can be connected either to CAMSV instance or
+  to the internal ISP. CAMSV is used to transfer the sensor data (Raw, YUV)
+  to DRAM directly, without internal ISP processing.
+
+properties:
+  compatible:
+    const: mediatek,mt8365-seninf
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  power-domains:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Seninf camsys clock
+      - description: Seninf top mux clock
+
+  clock-names:
+    items:
+      - const: camsys
+      - const: top_mux
+
+  phys:
+    minItems: 1
+    maxItems: 4
+    description:
+      phandle to the PHYs connected to CSI0/A, CSI1, CSI2 and CSI0B
+
+  phy-names:
+    minItems: 1
+    items:
+      - const: csi0
+      - const: csi1
+      - const: csi2
+      - const: csi0b
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI0 or CSI0A port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+
+      port@1:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI1 port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+
+      port@2:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI2 port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+
+      port@3:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI0B port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 2
+
+      port@4:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: connection point for cam0
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+      port@5:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: connection point for cam1
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+      port@6:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: connection point for camsv0
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+      port@7:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: connection point for camsv1
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+      port@8:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: connection point for camsv2
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+      port@9:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: connection point for camsv3
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+    required:
+      - port@0
+      - port@1
+      - port@2
+      - port@3
+      - port@4
+      - port@5
+      - port@6
+      - port@7
+      - port@8
+      - port@9
+
+required:
+  - compatible
+  - interrupts
+  - clocks
+  - clock-names
+  - power-domains
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/mediatek,mt8365-clk.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/phy/phy.h>
+    #include <dt-bindings/power/mediatek,mt8365-power.h>
+
+    soc {
+          #address-cells = <2>;
+          #size-cells = <2>;
+
+          seninf: seninf@15040000 {
+                compatible = "mediatek,mt8365-seninf";
+                reg = <0 0x15040000 0 0x6000>;
+                interrupts = <GIC_SPI 210 IRQ_TYPE_LEVEL_LOW>;
+                clocks = <&camsys CLK_CAM_SENIF>,
+                         <&topckgen CLK_TOP_SENIF_SEL>;
+                clock-names = "camsys", "top_mux";
+
+                power-domains = <&spm MT8365_POWER_DOMAIN_CAM>;
+
+                phys = <&mipi_csi0 PHY_TYPE_DPHY>;
+                phy-names = "csi0";
+
+                ports {
+                      #address-cells = <1>;
+                      #size-cells = <0>;
+
+                      port@0 {
+                            reg = <0>;
+                            seninf_in1: endpoint {
+                              clock-lanes = <2>;
+                              data-lanes = <1 3 0 4>;
+                              remote-endpoint = <&isp1_out>;
+                            };
+                      };
+
+                      port@1 {
+                          reg = <1>;
+                      };
+
+                      port@2 {
+                            reg = <2>;
+                      };
+
+                      port@3 {
+                            reg = <3>;
+                      };
+
+                      port@4 {
+                            reg = <4>;
+                            seninf_camsv1_endpoint: endpoint {
+                                remote-endpoint = <&camsv1_endpoint>;
+                            };
+                      };
+
+                      port@5 {
+                            reg = <5>;
+                      };
+
+                      port@6 {
+                            reg = <6>;
+                      };
+
+                      port@7 {
+                            reg = <7>;
+                      };
+
+                      port@8 {
+                            reg = <8>;
+                      };
+
+                      port@9 {
+                            reg = <9>;
+                      };
+
+                };
+          };
+    };
+
+...
MAINTAINERS +7 -0
index e0976ae2a523..af273a477139 100644
@@ -13350,6 +13350,13 @@ M:	Sean Wang <[email protected]>
 S:	Maintained
 F:	drivers/char/hw_random/mtk-rng.c
 
+MEDIATEK ISP3.0 DRIVER
+M:	Laurent Pinchart <[email protected]>
+M:	Julien Stephan <[email protected]>
+M:	Andy Hsieh <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
+
 MEDIATEK SMI DRIVER
 M:	Yong Wu <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
Signature · 1 line
2.41.0
maintainer
#2 lore raw

Re: [PATCH v2 1/4] dt-bindings: media: add mediatek ISP3.0 sensor interface

Quoted 9 lines · Julien Stephan

From: Louis Kuo <[email protected]>

This adds the bindings, for the mediatek ISP3.0 SENINF module embedded in some Mediatek SoC, such as the mt8365

Quoted 6 lines
---
 .../media/mediatek,mt8365-seninf.yaml         | 295 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 302 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.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/mediatek,mt8365-seninf.example.dts:28:18: fatal error: dt-bindings/power/mediatek,mt8365-power.h: No such file or directory
28 | #include <dt-bindings/power/mediatek,mt8365-power.h>

      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:419: Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.example.dtb] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1512: dt_binding_check] Error 2

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.

maintainer
#3 lore raw

Re: [PATCH v2 1/4] dt-bindings: media: add mediatek ISP3.0 sensor interface

In reply to Julien Stephan
Quoted 144 lines · Julien Stephan

From: Louis Kuo <[email protected]>

This adds the bindings, for the mediatek ISP3.0 SENINF module embedded in some Mediatek SoC, such as the mt8365

---
 .../media/mediatek,mt8365-seninf.yaml         | 295 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 302 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml new file +123 -0
new file mode 100644
index 000000000000..1697e94853f5
@@ -0,0 +1,295 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/mediatek,mt8365-seninf.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek Sensor Interface 3.0
+
+maintainers:
+  - Laurent Pinchart <[email protected]>
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The ISP3.0 SENINF is the CSI-2 and parallel camera sensor interface found in
+  multiple MediaTek SoCs. It can support up to three physical CSI-2
+  input ports, configured in DPHY (2 or 4 data lanes) or CPHY depending on the SoC.
+  On the output side, SENINF can be connected either to CAMSV instance or
+  to the internal ISP. CAMSV is used to transfer the sensor data (Raw, YUV)
+  to DRAM directly, without internal ISP processing.
+
+properties:
+  compatible:
+    const: mediatek,mt8365-seninf
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  power-domains:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Seninf camsys clock
+      - description: Seninf top mux clock
+
+  clock-names:
+    items:
+      - const: camsys
+      - const: top_mux
+
+  phys:
+    minItems: 1
+    maxItems: 4
+    description:
+      phandle to the PHYs connected to CSI0/A, CSI1, CSI2 and CSI0B
+
+  phy-names:
+    minItems: 1
+    items:
+      - const: csi0
+      - const: csi1
+      - const: csi2
+      - const: csi0b
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI0 or CSI0A port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+
+      port@1:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI1 port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+
+      port@2:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI2 port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+
+      port@3:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: CSI0B port
+
+        properties:
+          endpoint:
+            $ref: video-interfaces.yaml#
+            unevaluatedProperties: false

Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml line 133

Quoted 10 lines
Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml new file +10 -0
+
+            properties:
+              clock-lanes:
+                maxItems: 1
+              data-lanes:
+                minItems: 1
+                maxItems: 2
+
+      port@4:
+        $ref: /schemas/graph.yaml#/$defs/port-base

/schemas/graph.yaml#/properties/port

Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml line 134

Quoted 1 line
Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml new file +1 -0
+        unevaluatedProperties: false

Drop

Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml line 137

Quoted 3 lines
Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml new file +3 -0
+        description: connection point for cam0
+
+        properties:

Drop all this. Don't need to define endpoint as /schemas/graph.yaml#/properties/port already does.

Same on other ports.

Quoted 3 lines
Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml new file +3 -0
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
#4 lore raw

PATCH v2 2/4 media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

In reply to Julien Stephan

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

---
 MAINTAINERS                                   |    1 +
 drivers/media/platform/mediatek/Kconfig       |    1 +
 drivers/media/platform/mediatek/Makefile      |    1 +
 drivers/media/platform/mediatek/isp/Kconfig   |    2 +
 drivers/media/platform/mediatek/isp/Makefile  |    3 +
 .../platform/mediatek/isp/isp_30/Kconfig      |   16 +
 .../platform/mediatek/isp/isp_30/Makefile     |    3 +
 .../mediatek/isp/isp_30/seninf/Makefile       |    5 +
 .../mediatek/isp/isp_30/seninf/mtk_seninf.c   | 1561 +++++++++++++++++
 .../isp/isp_30/seninf/mtk_seninf_reg.h        |   99 ++
 10 files changed, 1692 insertions(+)
 create mode 100644 drivers/media/platform/mediatek/isp/Kconfig
 create mode 100644 drivers/media/platform/mediatek/isp/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Kconfig
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h
MAINTAINERS +1 -0
index af273a477139..9fda342ad331 100644
@@ -13356,6 +13356,7 @@ M:	Julien Stephan <[email protected]>
 M:	Andy Hsieh <[email protected]>
 S:	Supported
 F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
+F:	drivers/media/platform/mediatek/isp/isp_30/seninf/*
 
 MEDIATEK SMI DRIVER
 M:	Yong Wu <[email protected]>
drivers/media/platform/mediatek/Kconfig +1 -0
index 84104e2cd024..4e0a5a43f35e 100644
@@ -7,3 +7,4 @@ source "drivers/media/platform/mediatek/mdp/Kconfig"
 source "drivers/media/platform/mediatek/vcodec/Kconfig"
 source "drivers/media/platform/mediatek/vpu/Kconfig"
 source "drivers/media/platform/mediatek/mdp3/Kconfig"
+source "drivers/media/platform/mediatek/isp/Kconfig"
drivers/media/platform/mediatek/Makefile +1 -0
index 38e6ba917fe5..695f05f525a6 100644
@@ -4,3 +4,4 @@ obj-y += mdp/
 obj-y += vcodec/
 obj-y += vpu/
 obj-y += mdp3/
+obj-y += isp/
drivers/media/platform/mediatek/isp/Kconfig new file +2 -0
new file mode 100644
index 000000000000..708b9a6660d2
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+source "drivers/media/platform/mediatek/isp/isp_30/Kconfig"
drivers/media/platform/mediatek/isp/Makefile new file +3 -0
new file mode 100644
index 000000000000..a81ab33d0dd3
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += isp_30/
drivers/media/platform/mediatek/isp/isp_30/Kconfig new file +16 -0
new file mode 100644
index 000000000000..831f9bee5fdd
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config MTK_SENINF
+	tristate "MediaTek ISP3.0 SENINF driver"
+	depends on VIDEO_V4L2_SUBDEV_API
+	depends on MEDIA_CAMERA_SUPPORT
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on OF
+	select V4L2_FWNODE
+	default n
+	help
+	  This driver provides a MIPI CSI-2 receiver interface to connect
+	  an external camera module with MediaTek ISP3.0. It is able to handle
+	  multiple cameras at the same time.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mtk-seninf.
drivers/media/platform/mediatek/isp/isp_30/Makefile new file +3 -0
new file mode 100644
index 000000000000..2e7d731d42b7
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_MTK_SENINF) += seninf/
drivers/media/platform/mediatek/isp/isp_30/seninf/Makefile new file +5 -0
new file mode 100644
index 000000000000..853dad32f2b3
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+mtk-seninf-objs += mtk_seninf.o
+
+obj-$(CONFIG_MTK_SENINF) += mtk-seninf.o
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +1561 -0

1,561 lines not on this page · raw message

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
2.41.0
#5 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

Hi, Julien:

Julien Stephan <[email protected]> 於 2023年6月30日 週五 下午6:05寫道:

Quoted 14 lines

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

Quoted 11 lines
---
 MAINTAINERS                                   |    1 +
 drivers/media/platform/mediatek/Kconfig       |    1 +
 drivers/media/platform/mediatek/Makefile      |    1 +
 drivers/media/platform/mediatek/isp/Kconfig   |    2 +
 drivers/media/platform/mediatek/isp/Makefile  |    3 +
 .../platform/mediatek/isp/isp_30/Kconfig      |   16 +
 .../platform/mediatek/isp/isp_30/Makefile     |    3 +
 .../mediatek/isp/isp_30/seninf/Makefile       |    5 +
 .../mediatek/isp/isp_30/seninf/mtk_seninf.c   | 1561 +++++++++++++++++
 .../isp/isp_30/seninf/mtk_seninf_reg.h        |   99 ++

I think it's not necessary to create a folder isp_30 inside isp and you could just place all file in isp folder because there are only few files. After adding more and more files then we consider to create folder to separate them.

Regards,
Chun-Kuang.

Quoted 10 lines
 10 files changed, 1692 insertions(+)
 create mode 100644 drivers/media/platform/mediatek/isp/Kconfig
 create mode 100644 drivers/media/platform/mediatek/isp/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Kconfig
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h
#6 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

In reply to Julien Stephan

Hi, Julien:

Julien Stephan <[email protected]> 於 2023年6月30日 週五 下午6:05寫道:

Quoted 15 lines

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

[snip]

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1540

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+static const struct mtk_seninf_conf seninf_8365_conf = {
+       .model = "mtk-camsys-3.0",
+       .nb_inputs = 4,
+       .nb_muxes = 6,
+       .nb_outputs = 4,
+};
+
+static const struct of_device_id mtk_seninf_of_match[] = {
+       {
+               .compatible = "mediatek,mt8365-seninf",
+               .data = &seninf_8365_conf,

Now only support one SoC, so it's necessary to select the SoC data and you could directly place the data in the code. After support other SoC, so we could know what should be placed in struct mtg_seninf_conf (Now we have no any information).

Regards,
Chun-Kuang.

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+       },
+       {
+       },
+};
+MODULE_DEVICE_TABLE(of, mtk_seninf_of_match);
#7 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

Hi, Julien:

Chun-Kuang Hu <[email protected]> 於 2023年7月2日 週日 上午7:35寫道:

Quoted 22 lines

Hi, Julien:

Julien Stephan <[email protected]> 於 2023年6月30日 週五 下午6:05寫道:

Quoted 15 lines

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

[snip]

Quoted 15 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1540

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+static const struct mtk_seninf_conf seninf_8365_conf = {
+       .model = "mtk-camsys-3.0",
+       .nb_inputs = 4,
+       .nb_muxes = 6,
+       .nb_outputs = 4,
+};
+
+static const struct of_device_id mtk_seninf_of_match[] = {
+       {
+               .compatible = "mediatek,mt8365-seninf",
+               .data = &seninf_8365_conf,

Now only support one SoC, so it's necessary to select the SoC data and you could directly place the data in the code. After support other

Typo.

Now only support one SoC, so it's not necessary to select the SoC data and you could directly place the data in the code.

Regards,
Chun-Kuang.

Quoted 11 lines

SoC, so we could know what should be placed in struct mtg_seninf_conf (Now we have no any information).

Regards,
Chun-Kuang.

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+       },
+       {
+       },
+};
+MODULE_DEVICE_TABLE(of, mtk_seninf_of_match);
#8 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

Quoted 36 lines · Chun-Kuang Hu

Chun-Kuang Hu <[email protected]> 於 2023年7月2日 週日 上午7:35寫道:

Quoted 19 lines

Julien Stephan <[email protected]> 於 2023年6月30日 週五 下午6:05寫道:

Quoted 15 lines

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

[snip]

Quoted 15 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1540

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+static const struct mtk_seninf_conf seninf_8365_conf = {
+       .model = "mtk-camsys-3.0",
+       .nb_inputs = 4,
+       .nb_muxes = 6,
+       .nb_outputs = 4,
+};
+
+static const struct of_device_id mtk_seninf_of_match[] = {
+       {
+               .compatible = "mediatek,mt8365-seninf",
+               .data = &seninf_8365_conf,

Now only support one SoC, so it's necessary to select the SoC data and you could directly place the data in the code. After support other

Quoted 4 lines

Typo.

Now only support one SoC, so it's not necessary to select the SoC data and you could directly place the data in the code.

I think Julien has visibility on other SoCs that could use the same driver, and has designed the mtk_seninf_conf structure accordingly. I'll let Julien confirm (or tell I'm wrong).

Quoted 8 lines
Quoted 8 lines

SoC, so we could know what should be placed in struct mtg_seninf_conf (Now we have no any information).

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+       },
+       {
+       },
+};
+MODULE_DEVICE_TABLE(of, mtk_seninf_of_match);
Signature · 3 lines
Regards,

Laurent Pinchart
#9 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

Il 03/07/23 14:18, Laurent Pinchart ha scritto:

Quoted 37 lines · Chun-Kuang Hu
Quoted 36 lines

Chun-Kuang Hu <[email protected]> 於 2023年7月2日 週日 上午7:35寫道:

Quoted 34 lines

Julien Stephan <[email protected]> 於 2023年6月30日 週五 下午6:05寫道:

Quoted 15 lines

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

[snip]

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1540

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+static const struct mtk_seninf_conf seninf_8365_conf = {
+       .model = "mtk-camsys-3.0",
+       .nb_inputs = 4,
+       .nb_muxes = 6,
+       .nb_outputs = 4,
+};
+
+static const struct of_device_id mtk_seninf_of_match[] = {
+       {
+               .compatible = "mediatek,mt8365-seninf",
+               .data = &seninf_8365_conf,

Now only support one SoC, so it's necessary to select the SoC data and you could directly place the data in the code. After support other

Quoted 9 lines
Quoted 4 lines

Typo.

Now only support one SoC, so it's not necessary to select the SoC data and you could directly place the data in the code.

I think Julien has visibility on other SoCs that could use the same driver, and has designed the mtk_seninf_conf structure accordingly. I'll let Julien confirm (or tell I'm wrong).

You're not wrong.

Cheers,
Angelo

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

SoC, so we could know what should be placed in struct mtg_seninf_conf (Now we have no any information).

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+       },
+       {
+       },
+};
+MODULE_DEVICE_TABLE(of, mtk_seninf_of_match);
#10 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

In reply to Julien Stephan

Il 30/06/23 12:01, Julien Stephan ha scritto:

Quoted 86 lines

From: Louis Kuo <[email protected]>

This will add the mediatek ISP3.0 seninf (sensor interface) driver found on several Mediatek SoCs such as the mt8365.

Then seninf module has 4 physical CSI-2 inputs. Depending on the soc they may not be all connected.

---
  MAINTAINERS                                   |    1 +
  drivers/media/platform/mediatek/Kconfig       |    1 +
  drivers/media/platform/mediatek/Makefile      |    1 +
  drivers/media/platform/mediatek/isp/Kconfig   |    2 +
  drivers/media/platform/mediatek/isp/Makefile  |    3 +
  .../platform/mediatek/isp/isp_30/Kconfig      |   16 +
  .../platform/mediatek/isp/isp_30/Makefile     |    3 +
  .../mediatek/isp/isp_30/seninf/Makefile       |    5 +
  .../mediatek/isp/isp_30/seninf/mtk_seninf.c   | 1561 +++++++++++++++++
  .../isp/isp_30/seninf/mtk_seninf_reg.h        |   99 ++
  10 files changed, 1692 insertions(+)

create mode 100644 drivers/media/platform/mediatek/isp/Kconfig
create mode 100644 drivers/media/platform/mediatek/isp/Makefile
create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Kconfig create mode 100644 drivers/media/platform/mediatek/isp/isp_30/Makefile create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/Makefile create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c create mode 100644 drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h

MAINTAINERS +1 -0
index af273a477139..9fda342ad331 100644
@@ -13356,6 +13356,7 @@ M:	Julien Stephan <[email protected]>
  M:	Andy Hsieh <[email protected]>
  S:	Supported
  F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
+F:	drivers/media/platform/mediatek/isp/isp_30/seninf/*
 
  MEDIATEK SMI DRIVER
  M:	Yong Wu <[email protected]>
drivers/media/platform/mediatek/Kconfig +1 -0
index 84104e2cd024..4e0a5a43f35e 100644
@@ -7,3 +7,4 @@ source "drivers/media/platform/mediatek/mdp/Kconfig"
  source "drivers/media/platform/mediatek/vcodec/Kconfig"
  source "drivers/media/platform/mediatek/vpu/Kconfig"
  source "drivers/media/platform/mediatek/mdp3/Kconfig"
+source "drivers/media/platform/mediatek/isp/Kconfig"
drivers/media/platform/mediatek/Makefile +1 -0
index 38e6ba917fe5..695f05f525a6 100644
@@ -4,3 +4,4 @@ obj-y += mdp/
  obj-y += vcodec/
  obj-y += vpu/
  obj-y += mdp3/
+obj-y += isp/
drivers/media/platform/mediatek/isp/Kconfig new file +2 -0
new file mode 100644
index 000000000000..708b9a6660d2
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+source "drivers/media/platform/mediatek/isp/isp_30/Kconfig"
drivers/media/platform/mediatek/isp/Makefile new file +3 -0
new file mode 100644
index 000000000000..a81ab33d0dd3
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += isp_30/
drivers/media/platform/mediatek/isp/isp_30/Kconfig new file +0 -0
new file mode 100644
index 000000000000..831f9bee5fdd

drivers/media/platform/mediatek/isp/isp_30/Kconfig line 2

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/Kconfig new file +2 -0
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config MTK_SENINF

MTK_SENINF_V30 or MTK_ISP30_SENINF instead?

Quoted 14 lines
drivers/media/platform/mediatek/isp/isp_30/Kconfig new file +14 -0
+	tristate "MediaTek ISP3.0 SENINF driver"
+	depends on VIDEO_V4L2_SUBDEV_API
+	depends on MEDIA_CAMERA_SUPPORT
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on OF
+	select V4L2_FWNODE
+	default n
+	help
+	  This driver provides a MIPI CSI-2 receiver interface to connect
+	  an external camera module with MediaTek ISP3.0. It is able to handle
+	  multiple cameras at the same time.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mtk-seninf.

..snip..

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +0 -0
new file mode 100644
index 000000000000..93a13a87d967

s/isp_30/isp30/g and s/mtk_seninf.c/mtk-seninf.c/g

...but then, I'm not sure that having a isp30 folder inside of isp would be actually beneficial for the driver structure. You're the judge.

Quoted 19 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +18 -0
@@ -0,0 +1,1561 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of_graph.h>
+#include <linux/of_platform.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/videodev2.h>
+#include <media/media-device.h>
+#include <media/media-entity.h>
+#include <media/v4l2-async.h>

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 28

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+#include <media/v4l2-common.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-mc.h>
+#include <media/v4l2-subdev.h>
+
+#include "mtk_seninf_reg.h"

If seninf for ISP3 is entirely different from ISP2 and ISP1 seninf, I'd rename that header to "mtk_isp3_seninf_reg.h" instead.

Quoted 15 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +15 -0
+
+#define SENINF_TIMESTAMP_STEP		0x67
+#define SENINF_SETTLE_DELAY		0x15
+#define SENINF_HS_TRAIL_PARAMETER	0x8
+
+#define SENINF_MAX_NUM_INPUTS		4
+#define SENINF_MAX_NUM_OUTPUTS		6
+#define SENINF_MAX_NUM_MUXES		6
+#define SENINF_MAX_NUM_PADS		(SENINF_MAX_NUM_INPUTS + \
+					 SENINF_MAX_NUM_OUTPUTS)
+
+#define SENINF_DEFAULT_BUS_FMT		MEDIA_BUS_FMT_SGRBG10_1X10
+#define SENINF_DEFAULT_WIDTH		1920
+#define SENINF_DEFAULT_HEIGHT		1080
+

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 53

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+#define SENINF_PAD_10BIT		0
+
+#define SENINF_TEST_MODEL		0
+#define SENINF_NORMAL_MODEL		1
+#define SENINF_ALL_ERR_IRQ_EN		0x7f
+#define SENINF_IRQ_CLR_SEL		0x80000000
+
+#define SENINF_MIPI_SENSOR		0x8
+
+enum PIXEL_MODE {

Lowercase please.

Quoted 8 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +8 -0
+	ONE_PIXEL_MODE  = 0x0,
+	TWO_PIXEL_MODE  = 0x1,
+	FOUR_PIXEL_MODE = 0x2,
+};
+
+/* Port number in the device tree. */
+enum mtk_seninf_port {
+	CSI_PORT_0 = 0,	/* 4D1C or 2D1C */

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 71

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	CSI_PORT_1,	/* 4D1C */
+	CSI_PORT_2,	/* 4D1C */
+	CSI_PORT_0B,	/* 2D1C */
+};
+
+enum mtk_seninf_id {
+	SENINF_1 = 0,
+	SENINF_2 = 1,
+	SENINF_3 = 2,
+	SENINF_5 = 4,

Why is there no SENINF_4?
That deserves a comment in the code.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 78

Quoted 7 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +7 -0
+};
+
+static const u32 port_to_seninf_id[] = {
+	[CSI_PORT_0] = SENINF_1,
+	[CSI_PORT_1] = SENINF_3,
+	[CSI_PORT_2] = SENINF_5,
+	[CSI_PORT_0B] = SENINF_2,

Is the port-to-seninf path really static? Is there any way we can for example configure CSI_PORT_0 to use SENINF_3 instead?

Quoted 29 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +29 -0
+};
+
+enum mtk_seninf_phy_mode {
+	SENINF_PHY_MODE_NONE,
+	SENINF_PHY_MODE_4D1C,
+	SENINF_PHY_MODE_2D1C,
+};
+
+enum mtk_seninf_format_flag {
+	MTK_SENINF_FORMAT_BAYER = BIT(0),
+	MTK_SENINF_FORMAT_DPCM = BIT(1),
+	MTK_SENINF_FORMAT_JPEG = BIT(2),
+	MTK_SENINF_FORMAT_INPUT_ONLY = BIT(3),
+};
+
+/**
+ * struct mtk_seninf_conf - Model-specific SENINF parameters
+ * @model: Model description
+ * @nb_inputs: Number of SENINF inputs
+ * @nb_muxes: Number of SENINF MUX (FIFO) instances
+ * @nb_outputs: Number of outputs (to CAM and CAMSV instances)
+ */
+struct mtk_seninf_conf {
+	const char *model;
+	u8 nb_inputs;
+	u8 nb_muxes;
+	u8 nb_outputs;
+};
+

...snip...

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 222

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+
+static const struct mtk_seninf_format_info mtk_seninf_formats[] = {
+	{
+		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
+		.flags = MTK_SENINF_FORMAT_BAYER,

Each entry fits in one line.

	{ .code = MEDIA_BUS_FMT_SBGGR8_1X8, .flags = MTK_SENINF_FORMAT_BAYER },
Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+	}, {
+		.code = MEDIA_BUS_FMT_SGBRG8_1X8,
+		.flags = MTK_SENINF_FORMAT_BAYER,

..snip..

Quoted 9 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +9 -0
+
+static const struct mtk_seninf_format_info *mtk_seninf_format_info(u32 code)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mtk_seninf_formats); ++i) {
+		if (mtk_seninf_formats[i].code == code)
+			return &mtk_seninf_formats[i];
+	}

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 328

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+
+	return NULL;
+}
+
+/* -----------------------------------------------------------------------------
+ * I/O Accessors
+ */
+static u32 mtk_seninf_read(struct mtk_seninf *priv, u32 reg)
+{
+	return readl(priv->base + reg);

I don't think that we need this kind of accessor. It's one line, performing either just a readl or just a writel, so you can simply use readl/writel directly.

Quoted 17 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +17 -0
+}
+
+static void mtk_seninf_write(struct mtk_seninf *priv, u32 reg, u32 value)
+{
+	writel(value, priv->base + reg);
+}
+
+static void __mtk_seninf_update(struct mtk_seninf *priv, u32 reg,
+				u32 mask, u32 value)
+{
+	u32 val = mtk_seninf_read(priv, reg);
+
+	mtk_seninf_write(priv, reg, (val & ~mask) | (value & mask));
+}
+
+#define mtk_seninf_update(priv, reg, field, val)			\
+	__mtk_seninf_update(priv, reg, reg##_##field,		\

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 355

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+			    FIELD_PREP(reg##_##field, val))
+
+static u32 mtk_seninf_input_read(struct mtk_seninf_input *input, u32 reg)
+{
+	return readl(input->base + reg);
+}
+
+static void mtk_seninf_input_write(struct mtk_seninf_input *input, u32 reg,
+				   u32 value)
+{

same here.

Quoted 8 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +8 -0
+	writel(value, input->base + reg);
+}
+
+static void __mtk_seninf_input_update(struct mtk_seninf_input *input, u32 reg,
+				      u32 mask, u32 value)
+{
+	u32 val = mtk_seninf_input_read(input, reg);
+

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 373

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	mtk_seninf_input_write(input, reg, (val & ~mask) | (value & mask));
+}
+
+#define mtk_seninf_input_update(input, reg, field, val)			\
+	__mtk_seninf_input_update(input, reg, reg##_##field,	\
+				  FIELD_PREP(reg##_##field, val))
+
+static u32 mtk_seninf_mux_read(struct mtk_seninf_mux *mux, u32 reg)
+{
+	return readl(mux->base + reg);

...and here

Quoted 20 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +20 -0
+}
+
+static void mtk_seninf_mux_write(struct mtk_seninf_mux *mux, u32 reg,
+				 u32 value)
+{
+	writel(value, mux->base + reg);
+}
+
+static void __mtk_seninf_mux_update(struct mtk_seninf_mux *mux, u32 reg,
+				    u32 mask, u32 value)
+{
+	u32 val = mtk_seninf_mux_read(mux, reg);
+
+	mtk_seninf_mux_write(mux, reg, (val & ~mask) | (value & mask));
+}
+
+#define mtk_seninf_mux_update(mux, reg, field, val)			\
+	__mtk_seninf_mux_update(mux, reg, reg##_##field,	\
+				FIELD_PREP(reg##_##field, val))
+

..snip..

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 455

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+static void mtk_seninf_input_setup_csi2_rx(struct mtk_seninf_input *input)
+{
+	unsigned int lanes[4] = { };

I don't like that 4 magic number.

#define MTK_CSI_MAX_LANES 4
or
#define MTK_CSIHW_MAX_LANES 4

Quoted 14 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +14 -0
+	unsigned int i;
+
+	/*
+	 * Configure data lane muxing. In 2D1C mode, lanes 0 to 2 correspond to
+	 * CSIx[AB]_L{0,1,2}, and in 4D1C lanes 0 to 5 correspond to
+	 * CSIxA_L{0,1,2}, CSIxB_L{0,1,2}.
+	 *
+	 * The clock lane must be skipped when calculating the index of the
+	 * physical data lane. For instance, in 4D1C mode, the sensor clock
+	 * lane is typically connected to lane 2 (CSIxA_L2), and the sensor
+	 * data lanes 0-3 to lanes 1 (CSIxA_L1), 3 (CSIxB_L0), 0 (CSIxA_L0) and
+	 * 4 (CSIxB_L1). The when skipping the clock lane, the data lane
+	 * indices become 1, 2, 0 and 3.
+	 */

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 479

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	for (i = 0; i < input->bus.num_data_lanes; ++i) {
+		lanes[i] = input->bus.data_lanes[i];
+		if (lanes[i] > input->bus.clock_lane)
+			lanes[i]--;
+	}
+
+	mtk_seninf_input_update(input, MIPI_RX_CON24_CSI0,
+				CSI0_BIST_LN0_MUX, lanes[0]);
+	mtk_seninf_input_update(input, MIPI_RX_CON24_CSI0,
+				CSI0_BIST_LN1_MUX, lanes[1]);

89 columns is fine, so all of those do fit in one line.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 492

Quoted 13 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +13 -0
+	mtk_seninf_input_update(input, MIPI_RX_CON24_CSI0,
+				CSI0_BIST_LN2_MUX, lanes[2]);
+	mtk_seninf_input_update(input, MIPI_RX_CON24_CSI0,
+				CSI0_BIST_LN3_MUX, lanes[3]);
+}
+
+static void mtk_seninf_input_setup_csi2(struct mtk_seninf_input *input,
+					struct v4l2_subdev_state *state)
+{
+	const struct mtk_seninf_format_info *fmtinfo;
+	const struct v4l2_mbus_framefmt *format;
+	unsigned int dpcm;
+	unsigned int data_lane_num = input->bus.num_data_lanes;

unsigned int num_data_lanes would be more consistent.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 493

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +1 -0
+	unsigned int data_header_order = 1;

Is this a constant?! If so, why is it not a definition? Also, what does 1 mean?

Quoted 11 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +11 -0
+	unsigned int val = 0;
+
+	format = v4l2_subdev_state_get_stream_format(state, input->pad, 0);
+	fmtinfo = mtk_seninf_format_info(format->code);
+
+	/* Configure timestamp */
+	mtk_seninf_input_write(input, SENINF_TG1_TM_STP, SENINF_TIMESTAMP_STEP);
+
+	/* HQ */
+	mtk_seninf_input_write(input, SENINF_TG1_PH_CNT, 0x0);
+	mtk_seninf_input_write(input, SENINF_TG1_SEN_CK, 0x10001);

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 514

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+
+	/* First Enable Sensor interface and select pad (0x1a04_0200) */
+	mtk_seninf_input_update(input, SENINF_CTRL, SENINF_EN, 1);
+	mtk_seninf_input_update(input, SENINF_CTRL, PAD2CAM_DATA_SEL, SENINF_PAD_10BIT);
+	mtk_seninf_input_update(input, SENINF_CTRL, SENINF_SRC_SEL, 0);
+	mtk_seninf_input_update(input, SENINF_CTRL_EXT, SENINF_CSI2_IP_EN, 1);
+	mtk_seninf_input_update(input, SENINF_CTRL_EXT, SENINF_NCSI2_IP_EN, 0);
+
+	/* DPCM Enable */
+	dpcm = fmtinfo->flags & MTK_SENINF_FORMAT_DPCM ? 0x2a : 0;

What does 0x2a mean?

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 515

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +1 -0
+	val = 1 << ((dpcm == 0x2a) ? 15 : ((dpcm & 0xF) + 7));

This is BIT(something);

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 527

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+	mtk_seninf_input_write(input, SENINF_CSI2_DPCM, val);
+
+	/* Settle delay */
+	mtk_seninf_input_update(input, SENINF_CSI2_LNRD_TIMING,
+				DATA_SETTLE_PARAMETER, SENINF_SETTLE_DELAY);
+
+	/* HQ */
+	mtk_seninf_input_write(input, SENINF_CSI2_LNRC_FSM, 0x10);
+
+	/* CSI2 control */
+	val = mtk_seninf_input_read(input, SENINF_CSI2_CTL)
+	    | (data_header_order << 16) | 0x10 | ((1 << data_lane_num) - 1);

What is 0x10?
Also, (BIT(data_lane_num) - 1).

Quoted 25 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +25 -0
+	mtk_seninf_input_write(input, SENINF_CSI2_CTL, val);
+
+	mtk_seninf_input_update(input, SENINF_CSI2_RESYNC_MERGE_CTL,
+				BYPASS_LANE_RESYNC, 0);
+	mtk_seninf_input_update(input, SENINF_CSI2_RESYNC_MERGE_CTL, CDPHY_SEL, 0);
+	mtk_seninf_input_update(input, SENINF_CSI2_RESYNC_MERGE_CTL,
+				CPHY_LANE_RESYNC_CNT, 3);
+	mtk_seninf_input_update(input, SENINF_CSI2_MODE, CSR_CSI2_MODE, 0);
+	mtk_seninf_input_update(input, SENINF_CSI2_MODE, CSR_CSI2_HEADER_LEN, 0);
+	mtk_seninf_input_update(input, SENINF_CSI2_DPHY_SYNC, SYNC_SEQ_MASK_0, 0xff00);
+	mtk_seninf_input_update(input, SENINF_CSI2_DPHY_SYNC, SYNC_SEQ_PAT_0, 0x001d);
+
+	mtk_seninf_input_update(input, SENINF_CSI2_CTL, CLOCK_HS_OPTION, 0);
+	mtk_seninf_input_update(input, SENINF_CSI2_CTL, HSRX_DET_EN, 0);
+	mtk_seninf_input_update(input, SENINF_CSI2_CTL, HS_TRAIL_EN, 1);
+	mtk_seninf_input_update(input, SENINF_CSI2_HS_TRAIL, HS_TRAIL_PARAMETER,
+				SENINF_HS_TRAIL_PARAMETER);
+
+	/* Set debug port to output packet number */
+	mtk_seninf_input_update(input, SENINF_CSI2_DGB_SEL, DEBUG_EN, 1);
+	mtk_seninf_input_update(input, SENINF_CSI2_DGB_SEL, DEBUG_SEL, 0x1a);
+
+	/* HQ */
+	mtk_seninf_input_write(input, SENINF_CSI2_SPARE0, 0xfffffffe);
+

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 562

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	/* Enable CSI2 IRQ mask */
+	/* Turn on all interrupt */
+	mtk_seninf_input_write(input, SENINF_CSI2_INT_EN, 0xffffffff);
+	/* Write clear CSI2 IRQ */
+	mtk_seninf_input_write(input, SENINF_CSI2_INT_STATUS, 0xffffffff);
+	/* Enable CSI2 Extend IRQ mask */
+	/* Turn on all interrupt */
+	mtk_seninf_input_update(input, SENINF_CTRL, CSI2_SW_RST, 1);
+	udelay(1);
+	mtk_seninf_input_update(input, SENINF_CTRL, CSI2_SW_RST, 0);

Is there any way to check if the CSI port did reset, or is it *guaranteed* to get out of reset in a microsecond after deasserting SW_RST?

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+}
+
+static void mtk_seninf_mux_setup(struct mtk_seninf_mux *mux,
+				 struct mtk_seninf_input *input,
+				 struct v4l2_subdev_state *state)
+{
+	const struct mtk_seninf_format_info *fmtinfo;
+	const struct v4l2_mbus_framefmt *format;
+	unsigned int pix_sel_ext;
+	unsigned int pix_sel;
+	unsigned int hs_pol = 0;
+	unsigned int vs_pol = 0;

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 584

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	unsigned int pixel_mode = TWO_PIXEL_MODE;
+	unsigned int val;
+
+	format = v4l2_subdev_state_get_stream_format(state, input->pad, 0);
+	fmtinfo = mtk_seninf_format_info(format->code);
+
+	/* Enable mux */
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_MUX_EN, 1);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_SRC_SEL,
+			      SENINF_MIPI_SENSOR);

Fits in one line.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 586

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL_EXT,
+			      SENINF_SRC_SEL_EXT, SENINF_NORMAL_MODEL);

This one too, it's 98 cols, still acceptable.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+
+	switch (pixel_mode) {

You're forcing TWO_PIXEL_MODE but then you have a switch here: I get the point, as in I get that you expect this to be extended to have that read from somewhere, but only then will this switch make sense.

So, you could either remove this switch or actually introduce some logic that will make pixel_mode variable; I'd be happy if you go for the second option.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 589

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +1 -0
+	case 1: /* 2 Pixel */

Besides, case 1 is from enum pixel_mode, so please use the definitions instead of magic numbers.

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+		pix_sel_ext = 0;
+		pix_sel = 1;
+		break;
+	case 2: /* 4 Pixel */
+		pix_sel_ext = 1;

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 604

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+		pix_sel = 0;
+		break;
+	default: /* 1 Pixel */
+		pix_sel_ext = 0;
+		pix_sel = 0;
+		break;
+	}
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL_EXT,
+			      SENINF_PIX_SEL_EXT, pix_sel_ext);

one line.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 607

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_PIX_SEL, pix_sel);
+
+	if (!(fmtinfo->flags & MTK_SENINF_FORMAT_JPEG)) {

Logically, inverting this branch to

	if (fmtinfo->flags & MTK_SENINF_FORMAT_JPEG) {
		...
	} else {
		...
	}

would be better imo.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 610

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+		mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_FULL_WR_EN, 2);
+		mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_FLUSH_EN, 0x1b);
+		mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_PUSH_EN, 0x1f);

Also, can you please add definitions for those FIFO_xxxx_EN values?

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 620

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	} else {
+		mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_FULL_WR_EN, 0);
+		mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_FLUSH_EN, 0x18);
+		mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_PUSH_EN, 0x1e);
+	}
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_HSYNC_POL, hs_pol);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_VSYNC_POL, vs_pol);
+
+	val = mtk_seninf_mux_read(mux, SENINF_MUX_CTRL);

rst_mask = SENINF_MUX_CTRL_SENINF_IRQ_SW_RST | SENINF_MUX_CTRL_SENINF_MUX_SW_RST;

writel(mux->base + SENINF_MUX_CTRL, val | rst_mask); writel(mux->base + SENINFMUX_CTRL, val & ~rst_mask);

that's better, right? :-)

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 629

Quoted 9 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +9 -0
+	mtk_seninf_mux_write(mux, SENINF_MUX_CTRL, val |
+			     SENINF_MUX_CTRL_SENINF_IRQ_SW_RST |
+			     SENINF_MUX_CTRL_SENINF_MUX_SW_RST);
+	mtk_seninf_mux_write(mux, SENINF_MUX_CTRL, val &
+			     ~(SENINF_MUX_CTRL_SENINF_IRQ_SW_RST |
+			       SENINF_MUX_CTRL_SENINF_MUX_SW_RST));
+
+	/* HQ */
+	mtk_seninf_mux_write(mux, SENINF_MUX_SPARE, 0xc2000);

Again, what does 0xc2000 mean?!

Quoted 49 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +49 -0
+}
+
+static void mtk_seninf_top_mux_setup(struct mtk_seninf *priv,
+				     enum mtk_seninf_id seninf_id,
+				     struct mtk_seninf_mux *mux)
+{
+	unsigned int val;
+
+	/*
+	 * Use the top mux (from SENINF input to MUX) to configure routing, and
+	 * hardcode a 1:1 mapping from the MUX instances to the SENINF outputs.
+	 */
+	val = mtk_seninf_read(priv, SENINF_TOP_MUX_CTRL)
+		& ~(0xf << (mux->mux_id * 4));
+	val |= (seninf_id & 0xf) << (mux->mux_id * 4);
+	mtk_seninf_write(priv, SENINF_TOP_MUX_CTRL, val);
+
+	mtk_seninf_write(priv, SENINF_TOP_CAM_MUX_CTRL, 0x76541010);
+}
+
+static void seninf_enable_test_pattern(struct mtk_seninf *priv,
+				       struct v4l2_subdev_state *state)
+{
+	struct mtk_seninf_input *input = &priv->inputs[CSI_PORT_0];
+	struct mtk_seninf_mux *mux = &priv->muxes[0];
+	const struct mtk_seninf_format_info *fmtinfo;
+	const struct v4l2_mbus_framefmt *format;
+	unsigned int val;
+	unsigned int pixel_mode = TWO_PIXEL_MODE;
+	unsigned int pix_sel_ext;
+	unsigned int pix_sel;
+	unsigned int hs_pol = 0;
+	unsigned int vs_pol = 0;
+	unsigned int seninf = 0;
+	unsigned int mux_id = mux->mux_id;
+
+	format = v4l2_subdev_state_get_stream_format(state, priv->conf->nb_inputs, 0);
+	fmtinfo = mtk_seninf_format_info(format->code);
+
+	mtk_seninf_update(priv, SENINF_TOP_CTRL, MUX_LP_MODE, 0);
+
+	mtk_seninf_update(priv, SENINF_TOP_CTRL, SENINF_PCLK_EN, 1);
+	mtk_seninf_update(priv, SENINF_TOP_CTRL, SENINF2_PCLK_EN, 1);
+
+	mtk_seninf_input_update(input, SENINF_CTRL, SENINF_EN, 1);
+	mtk_seninf_input_update(input, SENINF_CTRL, SENINF_SRC_SEL, 1);
+	mtk_seninf_input_update(input, SENINF_CTRL_EXT,
+				SENINF_TESTMDL_IP_EN, 1);
+

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 688

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	mtk_seninf_input_update(input, SENINF_TG1_TM_CTL, TM_EN, 1);
+	mtk_seninf_input_update(input, SENINF_TG1_TM_CTL, TM_PAT, 0xc);
+	mtk_seninf_input_update(input, SENINF_TG1_TM_CTL, TM_VSYNC, 4);
+	mtk_seninf_input_update(input, SENINF_TG1_TM_CTL, TM_DUMMYPXL, 0x28);
+
+	if (fmtinfo->flags & MTK_SENINF_FORMAT_BAYER)
+		mtk_seninf_input_update(input, SENINF_TG1_TM_CTL, TM_FMT, 0x0);
+	else
+		mtk_seninf_input_update(input, SENINF_TG1_TM_CTL, TM_FMT, 0x1);
+

#define SENINF_TG1_TM_HEIGHT GENMASK(31, 16)
#define SENINF_TG1_TM_WIDTH GENMASK(15, 0)

size = FIELD_PREP(SENINF_TG1_TM_HEIGHT, (format->height + 8));

switch ... {
	case something:
		size |= FIELD_PREP(SENINF_TG1_TM_WIDTH, format->width * 2);
		break;
	case default:
		size |= FIELD_PREP(SENINF_TG1_TM_WIDTH, format->width);
		break;
}

writel(the_base + the_reg, size);

:-) :-) :-) :-)

Quoted 7 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +7 -0
+	switch (format->code) {
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_VYUY8_1X16:
+	case MEDIA_BUS_FMT_YUYV8_1X16:
+	case MEDIA_BUS_FMT_YVYU8_1X16:
+		mtk_seninf_input_write(input, SENINF_TG1_TM_SIZE,
+				       (format->height + 8) << 16 |

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 705

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+				       format->width * 2);
+		break;
+	default:
+		mtk_seninf_input_write(input, SENINF_TG1_TM_SIZE,
+				       (format->height + 8) << 16 |
+				       format->width);
+		break;
+	}
+
+	mtk_seninf_input_write(input, SENINF_TG1_TM_CLK, 0x8);

Magic numbers again...

Quoted 44 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +44 -0
+	mtk_seninf_input_write(input, SENINF_TG1_TM_STP, 0x1);
+
+	/* Set top mux */
+	val = (mtk_seninf_read(priv, SENINF_TOP_MUX_CTRL) & (~(0xf << (mux_id * 4)))) |
+		((seninf & 0xf) << (mux_id * 4));
+	mtk_seninf_write(priv, SENINF_TOP_MUX_CTRL, val);
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_MUX_EN, 1);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL_EXT,
+			      SENINF_SRC_SEL_EXT, SENINF_TEST_MODEL);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_SRC_SEL, 1);
+
+	switch (pixel_mode) {
+	case 1:
+		pix_sel_ext = 0;
+		pix_sel = 1;
+		break;
+	case 2:
+		pix_sel_ext = 1;
+		pix_sel = 0;
+		break;
+	default:
+		pix_sel_ext = 0;
+		pix_sel = 0;
+		break;
+	}
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL_EXT,
+			      SENINF_PIX_SEL_EXT, pix_sel_ext);
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_PIX_SEL, pix_sel);
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_PUSH_EN, 0x1f);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_FLUSH_EN, 0x1b);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, FIFO_FULL_WR_EN, 2);
+
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_HSYNC_POL, hs_pol);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_VSYNC_POL, vs_pol);
+	mtk_seninf_mux_update(mux, SENINF_MUX_CTRL, SENINF_HSYNC_MASK, 1);
+
+	mtk_seninf_mux_write(mux, SENINF_MUX_INTEN,
+			     SENINF_IRQ_CLR_SEL | SENINF_ALL_ERR_IRQ_EN);
+
+	mtk_seninf_mux_write(mux, SENINF_MUX_CTRL,

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 759

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+			     mtk_seninf_mux_read(mux, SENINF_MUX_CTRL) |
+			     SENINF_MUX_CTRL_SENINF_IRQ_SW_RST |
+			     SENINF_MUX_CTRL_SENINF_MUX_SW_RST);
+	udelay(1);
+	mtk_seninf_mux_write(mux, SENINF_MUX_CTRL,
+			     mtk_seninf_mux_read(mux, SENINF_MUX_CTRL) &
+			     ~(SENINF_MUX_CTRL_SENINF_IRQ_SW_RST |
+			       SENINF_MUX_CTRL_SENINF_MUX_SW_RST));
+
+	//check this

Please, check this :-) :-)

Quoted 37 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +37 -0
+	mtk_seninf_write(priv, SENINF_TOP_CAM_MUX_CTRL, 0x76540010);
+
+	dev_dbg(priv->dev, "%s: OK\n", __func__);
+}
+
+static void mtk_seninf_start(struct mtk_seninf *priv,
+			     struct v4l2_subdev_state *state,
+			     struct mtk_seninf_input *input,
+			     struct mtk_seninf_mux *mux)
+{
+	phy_power_on(input->phy);
+
+	mtk_seninf_input_setup_csi2_rx(input);
+	mtk_seninf_input_setup_csi2(input, state);
+
+	mtk_seninf_mux_setup(mux, input, state);
+	mtk_seninf_top_mux_setup(priv, input->seninf_id, mux);
+}
+
+static void mtk_seninf_stop(struct mtk_seninf *priv,
+			    struct mtk_seninf_input *input)
+{
+	unsigned int val;
+
+	/* Disable CSI2(2.5G) first */
+	val = mtk_seninf_input_read(input, SENINF_CSI2_CTL);
+	val &= ~(SENINF_CSI2_CTL_CLOCK_LANE_EN |
+		 SENINF_CSI2_CTL_DATA_LANE3_EN |
+		 SENINF_CSI2_CTL_DATA_LANE2_EN |
+		 SENINF_CSI2_CTL_DATA_LANE1_EN |
+		 SENINF_CSI2_CTL_DATA_LANE0_EN);
+	mtk_seninf_input_write(input, SENINF_CSI2_CTL, val);
+
+	if (!priv->is_testmode)
+		phy_power_off(input->phy);
+}
+

..snip..

Quoted 25 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +25 -0
+/* -----------------------------------------------------------------------------
+ * V4L2 Subdev Operations
+ */
+static int seninf_s_stream(struct v4l2_subdev *sd, unsigned int source_pad,
+			   int on)
+{
+	struct mtk_seninf *priv = sd_to_mtk_seninf(sd);
+	struct v4l2_subdev_state *state;
+	struct mtk_seninf_input *input;
+	struct mtk_seninf_mux *mux;
+	struct v4l2_subdev *source;
+	u32 sink_pad;
+	int ret;
+
+	/* Stream control can only operate on source pads. */
+	if (source_pad < priv->conf->nb_inputs ||
+	    source_pad >= priv->conf->nb_inputs + priv->conf->nb_outputs)
+		return -EINVAL;
+
+	/*
+	 * Locate the SENINF input and MUX for the source pad.
+	 *
+	 * Hardcode a 1:1 mapping of MUX instances to SENINF
+	 * outputs to match the TOP_CAM_MUX configuration in
+	 * mtk_seninf_top_mux_setup().

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 888

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	 */
+	state = v4l2_subdev_lock_and_get_active_state(&priv->subdev);
+	if (!state)
+		return -EPIPE;
+
+	ret = v4l2_subdev_routing_find_opposite_end(&state->routing, source_pad, 0, &sink_pad,
+						    NULL);
+	if (ret) {
+		dev_dbg(priv->dev, "No sink pad routed to source pad %u\n",
+			source_pad);

one line please...

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+		goto unlock;
+	}
+

..snip..

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+
+static int seninf_set_fmt(struct v4l2_subdev *sd,
+			  struct v4l2_subdev_state *state,
+			  struct v4l2_subdev_format *fmt)
+{

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1050

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	struct mtk_seninf *priv = sd_to_mtk_seninf(sd);
+	const struct mtk_seninf_format_info *fmtinfo;
+	struct v4l2_mbus_framefmt *format;
+
+	/*
+	 * TODO (?): We should disallow setting formats on the source pad
+	 * completely, as the SENINF can't perform any processing. This would
+	 * however break usage of the test pattern generator, as there would be
+	 * no way to configure formats at all when no active input is selected.
+	 */

It's either a TODO or not... but whatever, I imagine that the difficulty here is that priv->is_testmode may become true after .set_fmt(), right?

Quoted 6 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +6 -0
+
+	/*
+	 * Default to the first format if the requested media bus code isn't
+	 * supported.
+	 */
+	fmtinfo = mtk_seninf_format_info(fmt->format.code);

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1066

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	if (!fmtinfo) {
+		fmtinfo = &mtk_seninf_formats[0];
+		fmt->format.code = fmtinfo->code;
+	}
+
+	/* Interlaced formats are not supported yet. */
+	fmt->format.field = V4L2_FIELD_NONE;
+
+	/* Store the format. */
+

Drop extra blank line please.

Quoted 20 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +20 -0
+	format = v4l2_subdev_state_get_stream_format(state, fmt->pad, fmt->stream);
+	if (!format)
+		return -EINVAL;
+
+	*format = fmt->format;
+
+	if (mtk_seninf_pad_is_source(priv, fmt->pad))
+		return 0;
+
+	/* Propagate the format to the corresponding source pad. */
+	format = v4l2_subdev_state_get_opposite_stream_format(state, fmt->pad,
+							      fmt->stream);
+	if (!format)
+		return -EINVAL;
+
+	*format = fmt->format;
+
+	return 0;
+}
+

..snip..

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1140

Quoted 7 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +7 -0
+
+static int mtk_seninf_fwnode_parse(struct device *dev,
+				   unsigned int id)
+
+{
+	static const char * const phy_names[] = { "csi0", "csi1", "csi2", "csi0b"};
+

Please remove the extra blank line.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1143

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+	struct mtk_seninf *priv = dev_get_drvdata(dev);
+	struct mtk_seninf_async_subdev *s_asd;
+	unsigned int port;

Move this before ret: makes it a little more readable.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1150

Quoted 7 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +7 -0
+	struct mtk_seninf_input *input;
+	struct fwnode_handle *ep, *fwnode;
+	struct v4l2_fwnode_endpoint vep = {
+		.bus_type = V4L2_MBUS_CSI2_DPHY,
+	};
+	struct v4l2_async_subdev *asd;
+	int ret;

static const char * const phy_names[] = { "csi0", "csi1", "csi2", "csi0b" }; struct mtk_seninf *priv = dev_get_drvdata(dev);
struct mtk_seninf_async_subdev *s_asd;
struct fwnode_handle *ep, *fwnode;
struct mtk_seninf_input *input;
struct v4l2_async_subdev *asd;

struct v4l2_fwnode_endpoint vep = {
	.bus_type = V4L2_MBUS_CSI2_DPHY,
};

unsigned int port;
int ret;

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1154

Quoted 4 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +4 -0
+
+	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), id, 0, 0);
+	if (!ep)
+		return 0;

Are you sure that this should really be return 0?

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+	fwnode = fwnode_graph_get_remote_endpoint(ep);
+	ret = v4l2_fwnode_endpoint_parse(ep, &vep);
+	if (ret) {
+		dev_err(dev, "Failed to parse %pOF\n", to_of_node(fwnode));
+		ret = -EINVAL;
+		goto out;
+	}
+
+	asd = v4l2_async_nf_add_fwnode(&priv->notifier,
+				       fwnode, struct v4l2_async_subdev);
+	if (IS_ERR(asd)) {

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1176

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+		ret = PTR_ERR(asd);
+		goto out;
+	}
+	s_asd = container_of(asd, struct mtk_seninf_async_subdev, asd);
+
+	port = vep.base.port;
+	s_asd->port = port;
+
+	if (mtk_seninf_pad_is_source(priv, port))
+		return 0;

hmmm... no fwnode_handle_put()!?

Quoted 17 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +17 -0
+
+	if (vep.bus_type != V4L2_MBUS_CSI2_DPHY) {
+		dev_err(dev, "Only CSI2 bus type is currently supported\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	input = &priv->inputs[port];
+
+	input->pad = port;
+	input->seninf_id = port_to_seninf_id[port];
+	input->base = priv->base + 0x1000 * input->seninf_id;
+	input->seninf = priv;
+
+	input->bus = vep.bus.mipi_csi2;
+
+	input->phy = devm_phy_get(dev, phy_names[port]);

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1203

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	if (IS_ERR(input->phy)) {
+		dev_err(dev, "failed to get phy:%ld\n", PTR_ERR(input->phy));
+		ret = PTR_ERR(input->phy);
+		goto out;
+	}
+	input->phy_mode = SENINF_PHY_MODE_4D1C;
+
+	s_asd->input = input;
+
+	ret = 0;

Honestly, I don't like that ret = 0, but I admit that this is the cleanest option that we can have here, so it's fine.

Quoted 8 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +8 -0
+out:
+	fwnode_handle_put(ep);
+	fwnode_handle_put(fwnode);
+	return ret;
+}
+
+static int mtk_seninf_notifier_bound(struct v4l2_async_notifier *notifier,
+				     struct v4l2_subdev *sd,

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1221

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+				     struct v4l2_async_subdev *asd)
+{
+	struct mtk_seninf *priv = container_of(notifier, struct mtk_seninf, notifier);
+	struct mtk_seninf_async_subdev *s_asd =
+		container_of(asd, struct mtk_seninf_async_subdev, asd);
+	struct device_link *link;
+	int ret;
+
+	dev_dbg(priv->dev, "%s bound to SENINF port %u\n", sd->entity.name,
+		s_asd->port);

one line.

Quoted 24 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +24 -0
+
+	if (mtk_seninf_pad_is_sink(priv, s_asd->port)) {
+		struct mtk_seninf_input *input = s_asd->input;
+
+		input->source_sd = sd;
+
+		link = device_link_add(priv->dev, sd->dev,
+				       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+		if (!link) {
+			dev_err(priv->dev,
+				"Failed to create device link from source %s\n", sd->name);
+			return -EINVAL;
+		}
+
+		ret = v4l2_create_fwnode_links_to_pad(sd, &priv->pads[input->pad],
+						      MEDIA_LNK_FL_IMMUTABLE |
+						      MEDIA_LNK_FL_ENABLED);
+	} else {
+		link = device_link_add(sd->dev, priv->dev,
+				       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+		if (!link) {
+			dev_err(priv->dev,
+				"Failed to create device link to output %s\n", sd->name);
+			return -EINVAL;

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1255

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+		}
+
+		ret = v4l2_create_fwnode_links_to_pad(&priv->subdev,
+						      &sd->entity.pads[0],
+						      MEDIA_LNK_FL_IMMUTABLE |
+						      MEDIA_LNK_FL_ENABLED);
+	}
+	if (ret)
+		dev_err(priv->dev, "Failed to create links between SENINF port %u and %s (%d)\n",
+			s_asd->port, sd->entity.name, ret);
if (ret) {
	dev_err(...)
	return ret;
}

return 0;

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1267

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+	return ret;
+}
+
+static int mtk_seninf_notifier_complete(struct v4l2_async_notifier *notifier)
+{
+	struct mtk_seninf *priv = container_of(notifier, struct mtk_seninf, notifier);
+	int ret;
+
+	ret = v4l2_device_register_subdev_nodes(&priv->v4l2_dev);
+	if (ret)
+		dev_err(priv->dev, "Failed to register subdev nodes: %d\n", ret);
if (ret) {
	dev_err....
	return ret;
}

return 0;

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1279

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+
+	return ret;
+}
+
+static const struct v4l2_async_notifier_operations mtk_seninf_async_ops = {
+	.bound = mtk_seninf_notifier_bound,
+	.complete = mtk_seninf_notifier_complete,
+};
+
+/* -----------------------------------------------------------------------------
+ * Probe & Remove
+ */

I don't think that we need such comments, btw.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1287

Quoted 8 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +8 -0
+
+static int mtk_seninf_media_init(struct mtk_seninf *priv)
+{
+	struct media_pad *pads = priv->pads;
+	const struct mtk_seninf_conf *conf = priv->conf;
+	struct device *dev = priv->dev;
+	struct media_device *media_dev = &priv->media_dev;
+	u8 num_pads = conf->nb_outputs + conf->nb_inputs;

Some reordering would be good for readability here.

Quoted 22 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +22 -0
+	unsigned int i;
+	int ret;
+
+	media_dev->dev = dev;
+	strscpy(media_dev->model, conf->model, sizeof(media_dev->model));
+	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
+		 "platform:%s", dev_name(dev));
+	media_dev->hw_revision = 0;
+	media_device_init(media_dev);
+
+	ret = media_entity_pads_init(&priv->subdev.entity, num_pads, pads);
+	if (ret)
+		goto err_clean_media;
+
+	for (i = 0; i < conf->nb_inputs; i++)
+		pads[i].flags = MEDIA_PAD_FL_SINK;
+	for (i = conf->nb_inputs; i < num_pads; i++)
+		pads[i].flags = MEDIA_PAD_FL_SOURCE;
+
+	return 0;
+err_clean_media:
+	media_device_cleanup(media_dev);

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1319

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+
+	return ret;
+}
+
+static int mtk_seninf_v4l2_async_register(struct mtk_seninf *priv)
+{
+	struct device *dev = priv->dev;
+	const struct mtk_seninf_conf *conf = priv->conf;
+	int ret;
+	unsigned int i;

const struct mtk_seninf_conf *conf = priv->conf;
struct device *dev = priv->dev;
unsigned int i;
int ret;

Quoted 6 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +6 -0
+
+	v4l2_async_nf_init(&priv->notifier);
+
+	for (i = 0; i < conf->nb_inputs + conf->nb_outputs; ++i) {
+		ret = mtk_seninf_fwnode_parse(dev, i);
+

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1335

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+		if (ret) {
+			dev_err(dev, "Failed to parse endpoint at port %d, err: %d\n", i, ret);
+			goto err_clean_notififer;
+		}
+	}
+
+	priv->notifier.ops = &mtk_seninf_async_ops;
+	ret = v4l2_async_nf_register(&priv->v4l2_dev, &priv->notifier);
+	if (ret)
+		dev_err(dev, "Failed to register async notifier: %d\n", ret);

So you don't care about this failure?! :-)

Quoted 15 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +15 -0
+	return 0;
+
+err_clean_notififer:
+	v4l2_async_nf_cleanup(&priv->notifier);
+
+	return ret;
+}
+
+static int mtk_seninf_v4l2_register(struct mtk_seninf *priv)
+{
+	struct v4l2_subdev *sd = &priv->subdev;
+	struct device *dev = priv->dev;
+	int ret;
+
+	/* Initialize media device & pads. */

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1360

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	ret = mtk_seninf_media_init(priv);
+	if (ret)
+		return ret;
+
+	/* Initialize & register v4l2 device. */
+	priv->v4l2_dev.mdev = &priv->media_dev;
+
+	ret = v4l2_device_register(dev, &priv->v4l2_dev);
+	if (ret) {
+		dev_err(dev, "Failed to register V4L2 device: %d\n", ret);

You can still use dev_err_probe, even if you're not returning: this would make sure that the log format is consistent for at least all probe functions :-)

Quoted 57 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +57 -0
+		goto err_clean_media;
+	}
+
+	/* Initialize & register subdev. */
+	v4l2_subdev_init(sd, &seninf_subdev_ops);
+	sd->dev = dev;
+	sd->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+	sd->entity.ops = &seninf_media_ops;
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS
+		  |  V4L2_SUBDEV_FL_STREAMS;
+	strscpy(sd->name, dev_name(dev), V4L2_SUBDEV_NAME_SIZE);
+	ret = seninf_initialize_controls(priv);
+	if (ret) {
+		dev_err(dev, "Failed to initialize controls: %d\n", ret);
+		goto err_unreg_v4l2;
+	}
+	v4l2_set_subdevdata(sd, priv);
+
+	ret = v4l2_subdev_init_finalize(sd);
+	if (ret)
+		goto err_free_handler;
+
+	ret = v4l2_device_register_subdev(&priv->v4l2_dev, sd);
+	if (ret) {
+		dev_err(dev, "Failed to register subdev: %d\n", ret);
+		goto err_cleanup_subdev;
+	}
+
+	/* Set up async device */
+	ret = mtk_seninf_v4l2_async_register(priv);
+	if (ret) {
+		dev_err(dev, "Failed to register v4l2 async notifier: %d\n", ret);
+		goto err_unreg_subdev;
+	}
+
+	/* Register media device */
+	ret = media_device_register(&priv->media_dev);
+	if (ret) {
+		dev_err(dev, "failed to register media device: %d\n", ret);
+		goto err_unreg_notifier;
+	}
+
+	return 0;
+
+err_unreg_notifier:
+	v4l2_async_nf_unregister(&priv->notifier);
+err_unreg_subdev:
+	v4l2_device_unregister_subdev(sd);
+err_cleanup_subdev:
+	v4l2_subdev_cleanup(sd);
+err_free_handler:
+	v4l2_ctrl_handler_free(&priv->ctrl_handler);
+err_unreg_v4l2:
+	v4l2_device_unregister(&priv->v4l2_dev);
+err_clean_media:
+	media_entity_cleanup(&sd->entity);
+	media_device_cleanup(&priv->media_dev);

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1427

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+
+	return ret;
+}
+
+static int seninf_probe(struct platform_device *pdev)
+{
+	/* List of clocks required by seninf. */
+	static const char * const clk_names[] = {
+		"camsys", "top_mux"
+	};

Fits in one line; drop extra blank line.

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1430

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+
+	struct mtk_seninf *priv;
+	struct device *dev = &pdev->dev;

reordering: dev before priv

Quoted 31 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +31 -0
+	unsigned int i;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(struct mtk_seninf), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->conf = of_device_get_match_data(dev);
+
+	dev_set_drvdata(dev, priv);
+	priv->dev = dev;
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	priv->num_clks = ARRAY_SIZE(clk_names);
+	priv->clks = devm_kcalloc(dev, priv->num_clks,
+				  sizeof(*priv->clks), GFP_KERNEL);
+	if (!priv->clks)
+		return -ENOMEM;
+
+	for (i = 0; i < priv->num_clks; ++i)
+		priv->clks[i].id = clk_names[i];
+
+	ret = devm_clk_bulk_get(dev, priv->num_clks, priv->clks);
+	if (ret) {
+		dev_err(dev, "failed to get seninf clock:%d\n", ret);
+		return ret;
+	}
+

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1471

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	for (i = 0; i < priv->conf->nb_muxes; ++i) {
+		struct mtk_seninf_mux *mux = &priv->muxes[i];
+
+		mux->pad = priv->conf->nb_inputs + i;
+		mux->mux_id = i;
+		mux->base = priv->base + 0x1000 * i;
+		mux->seninf = priv;
+	}
+
+	ret = mtk_seninf_v4l2_register(priv);

if (ret)

	return ret;

pm_runtime_enable(dev); (P.S.: Why not devm_pm_runtime_enable()?)

return 0;
}

Quoted 27 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +27 -0
+	if (!ret)
+		pm_runtime_enable(dev);
+
+	return ret;
+}
+
+static int seninf_pm_suspend(struct device *dev)
+{
+	struct mtk_seninf *priv = dev_get_drvdata(dev);
+
+	dev_dbg(dev, "seninf runtime suspend\n");
+	clk_bulk_disable_unprepare(priv->num_clks, priv->clks);
+
+	return 0;
+}
+
+static int seninf_pm_resume(struct device *dev)
+{
+	struct mtk_seninf *priv = dev_get_drvdata(dev);
+	int ret;
+
+	dev_dbg(dev, "seninf runtime resume\n");
+	ret = clk_bulk_prepare_enable(priv->num_clks, priv->clks);
+	if (ret) {
+		dev_err(dev, "failed to enable clock:%d\n", ret);
+		return ret;
+	}

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1508

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+
+	mtk_seninf_csi2_setup_phy(priv);
+
+	return 0;
+}
+
+static const struct dev_pm_ops runtime_pm_ops = {
+	SET_RUNTIME_PM_OPS(seninf_pm_suspend, seninf_pm_resume, NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+				pm_runtime_force_resume)

Fits in one line.

Quoted 22 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +22 -0
+};
+
+static int seninf_remove(struct platform_device *pdev)
+{
+	struct mtk_seninf *priv = dev_get_drvdata(&pdev->dev);
+
+	media_device_unregister(&priv->media_dev);
+	media_device_cleanup(&priv->media_dev);
+	v4l2_async_nf_unregister(&priv->notifier);
+	v4l2_async_nf_cleanup(&priv->notifier);
+	v4l2_device_unregister_subdev(&priv->subdev);
+	v4l2_subdev_cleanup(&priv->subdev);
+	v4l2_ctrl_handler_free(&priv->ctrl_handler);
+	media_entity_cleanup(&priv->subdev.entity);
+	v4l2_device_unregister(&priv->v4l2_dev);
+
+	pm_runtime_disable(priv->dev);
+
+	return 0;
+}
+
+static const struct mtk_seninf_conf seninf_8365_conf = {

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1540

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +10 -0
+	.model = "mtk-camsys-3.0",
+	.nb_inputs = 4,
+	.nb_muxes = 6,
+	.nb_outputs = 4,
+};
+
+static const struct of_device_id mtk_seninf_of_match[] = {
+	{
+		.compatible = "mediatek,mt8365-seninf",
+		.data = &seninf_8365_conf,

This fits in one line:

{ .compatible = "mediatek,mt8365-seninf", .data = &seninf_8365_conf }

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+	},
+	{

Please always end of_device_id lists with

	{ /* sentinel */ }

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 1549

Quoted 7 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +7 -0
+	},
+};
+MODULE_DEVICE_TABLE(of, mtk_seninf_of_match);
+
+static struct platform_driver seninf_pdrv = {
+	.driver	= {
+		.name	= "mtk-seninf",

Either tabs or one space please.

Quoted 30 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +12 -0
+		.pm  = &runtime_pm_ops,
+		.of_match_table = mtk_seninf_of_match,
+	},
+	.probe	= seninf_probe,
+	.remove	= seninf_remove,
+};
+
+module_platform_driver(seninf_pdrv);
+
+MODULE_DESCRIPTION("MTK sensor interface driver");
+MODULE_AUTHOR("Louis Kuo <[email protected]>");
+MODULE_LICENSE("GPL");
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h new file +12 -0
new file mode 100644
index 000000000000..b6af8567fa20
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ */
+
+#ifndef __SENINF_REG_H__
+#define __SENINF_REG_H__
+
+#include <linux/bits.h>
+
+#define SENINF_TOP_CTRL							0x0000
+#define SENINF_TOP_CTRL_MUX_LP_MODE					BIT(31)

..snip..

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h line 98

Quoted 6 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf_reg.h new file +6 -0
+#define SENINF_MUX_CTRL_SENINF_MUX_EN					BIT(31)
+#define SENINF_MUX_INTEN						0x0d04
+#define SENINF_MUX_SPARE						0x0d2c
+#define SENINF_MUX_CTRL_EXT						0x0d3c
+#define SENINF_MUX_CTRL_EXT_SENINF_SRC_SEL_EXT				GENMASK(1, 0)
+#define SENINF_MUX_CTRL_EXT_SENINF_PIX_SEL_EXT				BIT(4)

#endif /* __SENINF_REG_H__ */

Quoted 1 line

+#endif

Regards,
Angelo

#11 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

Quoted 1 line · AngeloGioacchino Del Regno

Il 30/06/23 12:01, Julien Stephan ha scritto:

..snip..

Quoted 10 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 222

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+
+static const struct mtk_seninf_format_info mtk_seninf_formats[] = {
+	{
+		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
+		.flags = MTK_SENINF_FORMAT_BAYER,

Each entry fits in one line.

	{ .code = MEDIA_BUS_FMT_SBGGR8_1X8, .flags = MTK_SENINF_FORMAT_BAYER },

Hi Angelo,

Actually not all entries fit in one line. The last 4 ones don't:

{ .code = MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, .flags = MTK_SENINF_FORMAT_DPCM | MTK_SENINF_FORMAT_INPUT_ONLY },
which is 115 chars..

so what is the best? put all in one line except the last 4 one? or keep them all as is?

Quoted 1 line
Quoted 1 line
(quoted diff) +1 -0
+	}, {

..snip..

Quoted 6 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 562

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+	udelay(1);
+	mtk_seninf_input_update(input, SENINF_CTRL, CSI2_SW_RST, 0);

Is there any way to check if the CSI port did reset, or is it *guaranteed* to get out of reset in a microsecond after deasserting SW_RST?

I will double check this

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+}
+

..snip..

Quoted 10 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 620

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+
+	val = mtk_seninf_mux_read(mux, SENINF_MUX_CTRL);

rst_mask = SENINF_MUX_CTRL_SENINF_IRQ_SW_RST | SENINF_MUX_CTRL_SENINF_MUX_SW_RST;

writel(mux->base + SENINF_MUX_CTRL, val | rst_mask); writel(mux->base + SENINFMUX_CTRL, val & ~rst_mask);

that's better, right? :-)

right :)

Cheers
Julien

Quoted 3 lines
Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+	mtk_seninf_mux_write(mux, SENINF_MUX_CTRL, val |
+			     SENINF_MUX_CTRL_SENINF_IRQ_SW_RST |
+			     SENINF_MUX_CTRL_SENINF_MUX_SW_RST);
#12 lore raw

Re: [PATCH v2 2/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface

Quoted 16 lines · Julien Stephan
Quoted 1 line · AngeloGioacchino Del Regno

Il 30/06/23 12:01, Julien Stephan ha scritto:

..snip..

Quoted 10 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 222

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +5 -0
+
+static const struct mtk_seninf_format_info mtk_seninf_formats[] = {
+	{
+		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
+		.flags = MTK_SENINF_FORMAT_BAYER,

Each entry fits in one line.

	{ .code = MEDIA_BUS_FMT_SBGGR8_1X8, .flags = MTK_SENINF_FORMAT_BAYER },

Hi Angelo,

Quoted 7 lines

Actually not all entries fit in one line. The last 4 ones don't:

{ .code = MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, .flags = MTK_SENINF_FORMAT_DPCM | MTK_SENINF_FORMAT_INPUT_ONLY },
which is 115 chars..

so what is the best? put all in one line except the last 4 one? or keep them all as is?

I'd keep them all as is.

Quoted 8 lines
Quoted 1 line
Quoted 1 line
(quoted diff) +1 -0
+	}, {

..snip..

Quoted 5 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 562

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+	udelay(1);
+	mtk_seninf_input_update(input, SENINF_CTRL, CSI2_SW_RST, 0);

Is there any way to check if the CSI port did reset, or is it *guaranteed* to get out of reset in a microsecond after deasserting SW_RST?

Quoted 14 lines

I will double check this

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+}
+

..snip..

Quoted 9 lines

drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c line 620

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +2 -0
+
+	val = mtk_seninf_mux_read(mux, SENINF_MUX_CTRL);

rst_mask = SENINF_MUX_CTRL_SENINF_IRQ_SW_RST | SENINF_MUX_CTRL_SENINF_MUX_SW_RST;

writel(mux->base + SENINF_MUX_CTRL, val | rst_mask); writel(mux->base + SENINFMUX_CTRL, val & ~rst_mask);

that's better, right? :-)

With mtk_seninf_mux_write() instead of writel(), yes :-)

Quoted 5 lines

right :)

Quoted 3 lines
Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/seninf/mtk_seninf.c new file +3 -0
+	mtk_seninf_mux_write(mux, SENINF_MUX_CTRL, val |
+			     SENINF_MUX_CTRL_SENINF_IRQ_SW_RST |
+			     SENINF_MUX_CTRL_SENINF_MUX_SW_RST);
Signature · 3 lines
Regards,

Laurent Pinchart
#13 lore raw

PATCH v2 3/4 dt-bindings: media: add mediatek ISP3.0 camsv

In reply to Julien Stephan

From: Phi-bang Nguyen <[email protected]>

This adds the bindings, for the ISP3.0 camsv module embedded in some Mediatek SoC, such as the mt8365

---
 .../bindings/media/mediatek,mt8365-camsv.yaml | 113 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml new file +113 -0
new file mode 100644
index 000000000000..d81fa5d6db74
@@ -0,0 +1,113 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/mediatek,mt8365-camsv.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek CAMSV 3.0
+
+maintainers:
+  - Laurent Pinchart <[email protected]>
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The CAMSV is a set of DMA engines connected to the SENINF CSI-2
+  receivers. The number of CAMSVs depend on the SoC model.
+
+properties:
+  compatible:
+    const: mediatek,mt8365-camsv
+
+  reg:
+    maxItems: 3
+
+  interrupts:
+    maxItems: 1
+
+  power-domains:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: cam clock
+      - description: camtg clock
+      - description: camsv clock
+
+  clock-names:
+    items:
+      - const: camsys_cam_cgpdn
+      - const: camsys_camtg_cgpdn
+      - const: camsys_camsv
+
+  iommus:
+    maxItems: 1
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        unevaluatedProperties: false
+        description: connection point for camsv0
+
+        properties:
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+    required:
+      - port@0
+
+required:
+  - compatible
+  - interrupts
+  - clocks
+  - clock-names
+  - power-domains
+  - iommus
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/mediatek,mt8365-clk.h>
+    #include <dt-bindings/memory/mediatek,mt8365-larb-port.h>
+    #include <dt-bindings/power/mediatek,mt8365-power.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        camsv1: camsv@15050000 {
+            compatible = "mediatek,mt8365-camsv";
+            reg = <0 0x15050000 0 0x0040>,
+            <0 0x15050208 0 0x0020>,
+            <0 0x15050400 0 0x0100>;
+            interrupts = <GIC_SPI 186 IRQ_TYPE_LEVEL_LOW>;
+            clocks = <&camsys CLK_CAM>,
+            <&camsys CLK_CAMTG>,
+            <&camsys CLK_CAMSV0>;
+            clock-names = "camsys_cam_cgpdn", "camsys_camtg_cgpdn",
+            "camsys_camsv";
+            iommus = <&iommu M4U_PORT_CAM_IMGO>;
+            power-domains = <&spm MT8365_POWER_DOMAIN_CAM>;
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                port@0 {
+                    reg = <0>;
+                    camsv1_endpoint: endpoint {
+                        remote-endpoint = <&seninf_camsv1_endpoint>;
+                    };
+                };
+            };
+        };
+    };
+...
MAINTAINERS +1 -0
index 9fda342ad331..60b2bceca584 100644
@@ -13355,6 +13355,7 @@ M:	Laurent Pinchart <[email protected]>
 M:	Julien Stephan <[email protected]>
 M:	Andy Hsieh <[email protected]>
 S:	Supported
+F:	Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
 F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
 F:	drivers/media/platform/mediatek/isp/isp_30/seninf/*
 
Signature · 1 line
2.41.0
maintainer
#14 lore raw

Re: [PATCH v2 3/4] dt-bindings: media: add mediatek ISP3.0 camsv

Quoted 5 lines · Julien Stephan

From: Phi-bang Nguyen <[email protected]>

This adds the bindings, for the ISP3.0 camsv module embedded in some Mediatek SoC, such as the mt8365

Quoted 8 lines
---
 .../bindings/media/mediatek,mt8365-camsv.yaml | 113 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.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/mediatek,mt8365-camsv.example.dts:28:18: fatal error: dt-bindings/power/mediatek,mt8365-power.h: No such file or directory
28 | #include <dt-bindings/power/mediatek,mt8365-power.h>

      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:419: Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.example.dtb] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1512: dt_binding_check] Error 2

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.

maintainer
#15 lore raw

Re: [PATCH v2 3/4] dt-bindings: media: add mediatek ISP3.0 camsv

In reply to Julien Stephan
Quoted 62 lines · Julien Stephan

From: Phi-bang Nguyen <[email protected]>

This adds the bindings, for the ISP3.0 camsv module embedded in some Mediatek SoC, such as the mt8365

---
 .../bindings/media/mediatek,mt8365-camsv.yaml | 113 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml new file +43 -0
new file mode 100644
index 000000000000..d81fa5d6db74
@@ -0,0 +1,113 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/mediatek,mt8365-camsv.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek CAMSV 3.0
+
+maintainers:
+  - Laurent Pinchart <[email protected]>
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The CAMSV is a set of DMA engines connected to the SENINF CSI-2
+  receivers. The number of CAMSVs depend on the SoC model.
+
+properties:
+  compatible:
+    const: mediatek,mt8365-camsv
+
+  reg:
+    maxItems: 3
+
+  interrupts:
+    maxItems: 1
+
+  power-domains:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: cam clock
+      - description: camtg clock
+      - description: camsv clock
+
+  clock-names:
+    items:
+      - const: camsys_cam_cgpdn
+      - const: camsys_camtg_cgpdn
+      - const: camsys_camsv
+

Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml line 53

Quoted 10 lines
Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml new file +10 -0
+  iommus:
+    maxItems: 1
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        unevaluatedProperties: false

Drop

Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml line 56

Quoted 3 lines
Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml new file +3 -0
+        description: connection point for camsv0
+
+        properties:

Drop

Quoted 72 lines
Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml new file +57 -0
+          endpoint:
+            $ref: /schemas/graph.yaml#/$defs/endpoint-base
+            unevaluatedProperties: false
+
+    required:
+      - port@0
+
+required:
+  - compatible
+  - interrupts
+  - clocks
+  - clock-names
+  - power-domains
+  - iommus
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/mediatek,mt8365-clk.h>
+    #include <dt-bindings/memory/mediatek,mt8365-larb-port.h>
+    #include <dt-bindings/power/mediatek,mt8365-power.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        camsv1: camsv@15050000 {
+            compatible = "mediatek,mt8365-camsv";
+            reg = <0 0x15050000 0 0x0040>,
+            <0 0x15050208 0 0x0020>,
+            <0 0x15050400 0 0x0100>;
+            interrupts = <GIC_SPI 186 IRQ_TYPE_LEVEL_LOW>;
+            clocks = <&camsys CLK_CAM>,
+            <&camsys CLK_CAMTG>,
+            <&camsys CLK_CAMSV0>;
+            clock-names = "camsys_cam_cgpdn", "camsys_camtg_cgpdn",
+            "camsys_camsv";
+            iommus = <&iommu M4U_PORT_CAM_IMGO>;
+            power-domains = <&spm MT8365_POWER_DOMAIN_CAM>;
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                port@0 {
+                    reg = <0>;
+                    camsv1_endpoint: endpoint {
+                        remote-endpoint = <&seninf_camsv1_endpoint>;
+                    };
+                };
+            };
+        };
+    };
+...
MAINTAINERS +1 -0
index 9fda342ad331..60b2bceca584 100644
@@ -13355,6 +13355,7 @@ M:	Laurent Pinchart <[email protected]>
 M:	Julien Stephan <[email protected]>
 M:	Andy Hsieh <[email protected]>
 S:	Supported
+F:	Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
 F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
 F:	drivers/media/platform/mediatek/isp/isp_30/seninf/*
 
Signature · 1 line
2.41.0
#16 lore raw

PATCH v2 4/4 media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

In reply to Julien Stephan

From: Phi-bang Nguyen <[email protected]>

This driver provides a path to bypass the SoC ISP so that image data coming from the SENINF can go directly into memory without any image processing. This allows the use of an external ISP.

---
 MAINTAINERS                                   |   1 +
 .../platform/mediatek/isp/isp_30/Kconfig      |  19 +
 .../platform/mediatek/isp/isp_30/Makefile     |   1 +
 .../mediatek/isp/isp_30/camsv/Makefile        |   7 +
 .../mediatek/isp/isp_30/camsv/mtk_camsv.c     | 334 ++++++++
 .../mediatek/isp/isp_30/camsv/mtk_camsv.h     | 200 +++++
 .../isp/isp_30/camsv/mtk_camsv30_hw.c         | 474 +++++++++++
 .../isp/isp_30/camsv/mtk_camsv30_regs.h       |  59 ++
 .../isp/isp_30/camsv/mtk_camsv_video.c        | 781 ++++++++++++++++++
 9 files changed, 1876 insertions(+)
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/Makefile
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_regs.h
 create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv_video.c
MAINTAINERS +1 -0
index 60b2bceca584..cebb8fb62b45 100644
@@ -13357,6 +13357,7 @@ M:	Andy Hsieh <[email protected]>
 S:	Supported
 F:	Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
 F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
+F:	drivers/media/platform/mediatek/isp/isp_30/camsv/*
 F:	drivers/media/platform/mediatek/isp/isp_30/seninf/*
 
 MEDIATEK SMI DRIVER
drivers/media/platform/mediatek/isp/isp_30/Kconfig +19 -0
index 831f9bee5fdd..04d4a2af80bc 100644
@@ -14,3 +14,22 @@ config MTK_SENINF
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called mtk-seninf.
+
+config MTK_CAMSV30
+	tristate "MediaTek ISP3.0 CAMSV driver"
+	depends on VIDEO_V4L2_SUBDEV_API
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on OF
+	depends on PM
+	select VIDEOBUF2_VMALLOC
+	select VIDEOBUF2_DMA_CONTIG
+	select MTK_SENINF
+	select PHY_MTK_MIPI_CSI_0_5
+	default n
+	help
+	  This driver provides a path to bypass the SoC ISP so that
+	  image data come from the SENINF can go directly into memory
+	  without any image processing.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mtk-camsv30.
drivers/media/platform/mediatek/isp/isp_30/Makefile +1 -0
index 2e7d731d42b7..c0034ef31702 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_MTK_SENINF) += seninf/
+obj-$(CONFIG_MTK_CAMSV30) += camsv/
drivers/media/platform/mediatek/isp/isp_30/camsv/Makefile new file +7 -0
new file mode 100644
index 000000000000..fffbc6e7cb78
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+mtk-camsv30-objs += mtk_camsv.o
+mtk-camsv30-objs += mtk_camsv30_hw.o
+mtk-camsv30-objs += mtk_camsv_video.o
+
+obj-$(CONFIG_MTK_CAMSV30) += mtk-camsv30.o
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +334 -0

334 lines not on this page · raw message

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +200 -0

200 lines not on this page · raw message

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +474 -0

474 lines not on this page · raw message

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_regs.h new file +59 -0

59 lines not on this page · raw message

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv_video.c new file +781 -0

781 lines not on this page · raw message

Signature · 1 line
2.41.0
#17 lore raw

Re: [PATCH v2 4/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

Hi, Julien:

Julien Stephan <[email protected]> 於 2023年6月30日 週五 下午6:06寫道:

Quoted 12 lines

From: Phi-bang Nguyen <[email protected]>

This driver provides a path to bypass the SoC ISP so that image data coming from the SENINF can go directly into memory without any image processing. This allows the use of an external ISP.

---

[snip]

Quoted 27 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +27 -0
+
+static irqreturn_t isp_irq_camsv30(int irq, void *data)
+{
+       struct mtk_cam_dev *cam_dev = (struct mtk_cam_dev *)data;
+       struct mtk_cam_dev_buffer *buf;
+       unsigned long flags = 0;
+       unsigned int irq_status;
+
+       spin_lock_irqsave(&cam_dev->irqlock, flags);
+
+       irq_status = mtk_camsv30_read(cam_dev, CAMSV_INT_STATUS);
+
+       if (irq_status & INT_ST_MASK_CAMSV_ERR) {
+               dev_err(cam_dev->dev, "irq error 0x%x\n",
+                       (unsigned int)(irq_status & INT_ST_MASK_CAMSV_ERR));
+       }
+
+       /* De-queue frame */
+       if (irq_status & CAMSV_IRQ_PASS1_DON) {
+               cam_dev->sequence++;
+
+               if (!cam_dev->is_dummy_used) {
+                       buf = list_first_entry_or_null(&cam_dev->buf_list,
+                                                      struct mtk_cam_dev_buffer,
+                                                      list);
+                       if (buf) {
+                               buf->v4l2_buf.sequence = cam_dev->sequence;

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 242

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+                               buf->v4l2_buf.vb2_buf.timestamp = ktime_get_ns();
+                               vb2_buffer_done(&buf->v4l2_buf.vb2_buf,
+                                               VB2_BUF_STATE_DONE);
+                               list_del(&buf->list);
+                       }
+               }
+
+               if (list_empty(&cam_dev->buf_list)) {
+                       (*cam_dev->hw_functions->mtk_cam_update_buffers_add)
+                                               (cam_dev, &cam_dev->dummy);

It's not necessary to use function pointer. Call
mtk_camsv30_update_buffers_add() directly.

Regards,
Chun-Kuang.

Quoted 16 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +16 -0
+                       cam_dev->is_dummy_used = true;
+               } else {
+                       buf = list_first_entry_or_null(&cam_dev->buf_list,
+                                                      struct mtk_cam_dev_buffer,
+                                                      list);
+                       (*cam_dev->hw_functions->mtk_cam_update_buffers_add)
+                                               (cam_dev, buf);
+                       cam_dev->is_dummy_used = false;
+               }
+       }
+
+       spin_unlock_irqrestore(&cam_dev->irqlock, flags);
+
+       return IRQ_HANDLED;
+}
+
#18 lore raw

Re: [PATCH v2 4/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

In reply to Julien Stephan

Il 30/06/23 12:01, Julien Stephan ha scritto:

Quoted 156 lines

From: Phi-bang Nguyen <[email protected]>

This driver provides a path to bypass the SoC ISP so that image data coming from the SENINF can go directly into memory without any image processing. This allows the use of an external ISP.

---
  MAINTAINERS                                   |   1 +
  .../platform/mediatek/isp/isp_30/Kconfig      |  19 +
  .../platform/mediatek/isp/isp_30/Makefile     |   1 +
  .../mediatek/isp/isp_30/camsv/Makefile        |   7 +
  .../mediatek/isp/isp_30/camsv/mtk_camsv.c     | 334 ++++++++
  .../mediatek/isp/isp_30/camsv/mtk_camsv.h     | 200 +++++
  .../isp/isp_30/camsv/mtk_camsv30_hw.c         | 474 +++++++++++
  .../isp/isp_30/camsv/mtk_camsv30_regs.h       |  59 ++
  .../isp/isp_30/camsv/mtk_camsv_video.c        | 781 ++++++++++++++++++
  9 files changed, 1876 insertions(+)

create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/Makefile create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_regs.h create mode 100644 drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv_video.c

MAINTAINERS +1 -0
index 60b2bceca584..cebb8fb62b45 100644
@@ -13357,6 +13357,7 @@ M:	Andy Hsieh <[email protected]>
  S:	Supported
  F:	Documentation/devicetree/bindings/media/mediatek,mt8365-camsv.yaml
  F:	Documentation/devicetree/bindings/media/mediatek,mt8365-seninf.yaml
+F:	drivers/media/platform/mediatek/isp/isp_30/camsv/*
  F:	drivers/media/platform/mediatek/isp/isp_30/seninf/*
 
  MEDIATEK SMI DRIVER
drivers/media/platform/mediatek/isp/isp_30/Kconfig +19 -0
index 831f9bee5fdd..04d4a2af80bc 100644
@@ -14,3 +14,22 @@ config MTK_SENINF
 
  	  To compile this driver as a module, choose M here: the
  	  module will be called mtk-seninf.
+
+config MTK_CAMSV30
+	tristate "MediaTek ISP3.0 CAMSV driver"
+	depends on VIDEO_V4L2_SUBDEV_API
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on OF
+	depends on PM
+	select VIDEOBUF2_VMALLOC
+	select VIDEOBUF2_DMA_CONTIG
+	select MTK_SENINF
+	select PHY_MTK_MIPI_CSI_0_5
+	default n
+	help
+	  This driver provides a path to bypass the SoC ISP so that
+	  image data come from the SENINF can go directly into memory
+	  without any image processing.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mtk-camsv30.
drivers/media/platform/mediatek/isp/isp_30/Makefile +1 -0
index 2e7d731d42b7..c0034ef31702 100644
@@ -1,3 +1,4 @@
  # SPDX-License-Identifier: GPL-2.0
 
  obj-$(CONFIG_MTK_SENINF) += seninf/
+obj-$(CONFIG_MTK_CAMSV30) += camsv/
drivers/media/platform/mediatek/isp/isp_30/camsv/Makefile new file +7 -0
new file mode 100644
index 000000000000..fffbc6e7cb78
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+mtk-camsv30-objs += mtk_camsv.o
+mtk-camsv30-objs += mtk_camsv30_hw.o
+mtk-camsv30-objs += mtk_camsv_video.o
+
+obj-$(CONFIG_MTK_CAMSV30) += mtk-camsv30.o
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +61 -0
new file mode 100644
index 000000000000..03d234f54e1c
@@ -0,0 +1,334 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020 BayLibre
+ * Copyright (c) 2022 MediaTek Inc.
+ */
+
+#include <media/v4l2-async.h>
+#include <media/v4l2-device.h>
+
+#include "mtk_camsv.h"
+
+static inline struct mtk_cam_dev *to_mtk_cam_dev(struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct mtk_cam_dev, subdev);
+}
+
+static const u32 mtk_cam_mbus_formats[] = {
+	MEDIA_BUS_FMT_SBGGR8_1X8,
+	MEDIA_BUS_FMT_SGBRG8_1X8,
+	MEDIA_BUS_FMT_SGRBG8_1X8,
+	MEDIA_BUS_FMT_SRGGB8_1X8,
+	MEDIA_BUS_FMT_SBGGR10_1X10,
+	MEDIA_BUS_FMT_SGBRG10_1X10,
+	MEDIA_BUS_FMT_SGRBG10_1X10,
+	MEDIA_BUS_FMT_SRGGB10_1X10,
+	MEDIA_BUS_FMT_SBGGR12_1X12,
+	MEDIA_BUS_FMT_SGBRG12_1X12,
+	MEDIA_BUS_FMT_SGRBG12_1X12,
+	MEDIA_BUS_FMT_SRGGB12_1X12,
+	MEDIA_BUS_FMT_UYVY8_1X16,
+	MEDIA_BUS_FMT_VYUY8_1X16,
+	MEDIA_BUS_FMT_YUYV8_1X16,
+	MEDIA_BUS_FMT_YVYU8_1X16,
+};
+
+/* -----------------------------------------------------------------------------
+ * V4L2 Subdev Operations
+ */
+
+static int mtk_cam_cio_stream_on(struct mtk_cam_dev *cam)
+{
+	struct device *dev = cam->dev;
+	struct v4l2_subdev *seninf;
+	int ret;
+
+	if (!cam->seninf) {
+		cam->seninf = media_pad_remote_pad_first(&cam->subdev_pads[MTK_CAM_CIO_PAD_SENINF]);
+		if (!cam->seninf) {
+			dev_err(dev, "%s: No SENINF connected\n", __func__);
+			return -ENOLINK;
+		}
+	}
+
+	seninf = media_entity_to_v4l2_subdev(cam->seninf->entity);
+
+	/* Seninf must stream on first */
+	ret = v4l2_subdev_call(seninf, pad, enable_streams, NULL, cam->seninf->index, 0);
+	if (ret) {
+		dev_err(dev, "failed to stream on %s:%d\n",
+			seninf->entity.name, ret);
+		return ret;

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 71

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +10 -0
+	}
+
+	cam->streaming = true;
+
+	return 0;
+}
+
+static int mtk_cam_cio_stream_off(struct mtk_cam_dev *cam)
+{
+	struct device *dev = cam->dev;

You're using dev only once, might as well drop it and just reference to cam->dev directly for that dev_err() call...

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 75

Quoted 4 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +4 -0
+	struct v4l2_subdev *seninf;
+	int ret;
+
+	if (cam->seninf) {
if (cam->seninf) {
	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(...);
Quoted 16 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +16 -0
+		seninf = media_entity_to_v4l2_subdev(cam->seninf->entity);
+
+		ret = v4l2_subdev_call(seninf, pad, disable_streams, NULL,
+				       cam->seninf->index, 0);
+		if (ret) {
+			dev_err(dev, "failed to stream off %s:%d\n",
+				seninf->entity.name, ret);
+			return ret;
+		}
+	}
+
+	cam->streaming = false;
+
+	return 0;
+}
+

..snip..

Quoted 19 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +19 -0
+static int mtk_cam_v4l2_register(struct mtk_cam_dev *cam)
+{
+	struct device *dev = cam->dev;
+	int ret;
+
+	/* Initialize subdev pads */
+	ret = media_entity_pads_init(&cam->subdev.entity,
+				     ARRAY_SIZE(cam->subdev_pads),
+				     cam->subdev_pads);
+	if (ret) {
+		dev_err(dev, "failed to initialize media pads:%d\n", ret);
+		return ret;
+	}
+
+	cam->subdev_pads[MTK_CAM_CIO_PAD_SENINF].flags = MEDIA_PAD_FL_SINK;
+	cam->subdev_pads[MTK_CAM_CIO_PAD_VIDEO].flags = MEDIA_PAD_FL_SOURCE;
+
+	/* Initialize subdev */
+	v4l2_subdev_init(&cam->subdev, &mtk_cam_subdev_ops);

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 290

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +10 -0
+
+	cam->subdev.dev = dev;
+	cam->subdev.entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
+	cam->subdev.entity.ops = &mtk_cam_media_entity_ops;
+	cam->subdev.internal_ops = &mtk_cam_internal_ops;
+	cam->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
+	strscpy(cam->subdev.name, dev_name(dev), V4L2_SUBDEV_NAME_SIZE);
+	v4l2_set_subdevdata(&cam->subdev, cam);
+
+	mtk_cam_init_cfg(&cam->subdev, NULL);

mtk_cam_init_cfg() returns an integer, and this is probably because you expect it to get logic to fail: in that case, check the result of that call here, otherwise, make that function void.

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 295

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +5 -0
+
+	ret = v4l2_async_register_subdev(&cam->subdev);
+	if (ret) {
+		dev_err(dev, "failed to initialize subdev:%d\n", ret);
+		goto fail_clean_media_entiy;

You don't need a goto here, as this the only fail path that requires cleaning up the entity: just do the same here and return ret *here*.

Quoted 22 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +22 -0
+	}
+
+	return 0;
+
+fail_clean_media_entiy:
+	media_entity_cleanup(&cam->subdev.entity);
+
+	return ret;
+}
+
+static void mtk_cam_v4l2_unregister(struct mtk_cam_dev *cam)
+{
+	mtk_cam_video_unregister(&cam->vdev);
+
+	media_entity_cleanup(&cam->subdev.entity);
+	v4l2_async_unregister_subdev(&cam->subdev);
+}
+
+int mtk_cam_dev_init(struct mtk_cam_dev *cam_dev)
+{
+	int ret;
+

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 327

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +10 -0
+	mutex_init(&cam_dev->op_lock);
+
+	/* v4l2 sub-device registration */
+	ret = mtk_cam_v4l2_register(cam_dev);
+	if (ret) {
+		mutex_destroy(&cam_dev->op_lock);
+		return ret;
+	}
+
+	return ret;

return 0;

Quoted 42 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +7 -0
+}
+
+void mtk_cam_dev_cleanup(struct mtk_cam_dev *cam)
+{
+	mtk_cam_v4l2_unregister(cam);
+	mutex_destroy(&cam->op_lock);
+}
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +29 -0
new file mode 100644
index 000000000000..91e30fe006a8
@@ -0,0 +1,200 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2020 BayLibre
+ * Copyright (c) 2022 MediaTek Inc.
+ */
+
+#ifndef __MTK_CAMSV_H__
+#define __MTK_CAMSV_H__
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/of_graph.h>
+#include <linux/pm_runtime.h>
+#include <linux/videodev2.h>
+#include <media/media-entity.h>
+#include <media/v4l2-subdev.h>
+#include <media/videobuf2-core.h>
+#include <media/videobuf2-dma-contig.h>
+#include <media/videobuf2-v4l2.h>
+#include <soc/mediatek/smi.h>
+
+#define IMG_MAX_WIDTH			5376
+#define IMG_MAX_HEIGHT			4032
+#define IMG_DEF_WIDTH			1920
+#define IMG_DEF_HEIGHT			1080
+#define IMG_MIN_WIDTH			80
+#define IMG_MIN_HEIGHT			60

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 39

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +10 -0
+
+#define MTK_CAM_CIO_PAD_SENINF		0
+#define MTK_CAM_CIO_PAD_VIDEO		1
+#define MTK_CAM_CIO_NUM_PADS		2
+
+struct mtk_cam_format_info {
+	u32 code;
+	u32 fourcc;
+	bool packed;
+	unsigned int bpp;

Can we get any format that uses a billion bits per pixel? :-P

u8 bpp;

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +5 -0
+};
+
+struct mtk_cam_dev_buffer {
+	struct vb2_v4l2_buffer v4l2_buf;
+	struct list_head list;

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 54

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +10 -0
+	dma_addr_t daddr;
+	dma_addr_t fhaddr;
+};
+
+struct mtk_cam_sparams {
+	unsigned int w_factor;
+	unsigned int module_en_pak;
+	unsigned int fmt_sel;
+	unsigned int pak;
+	unsigned int imgo_stride;

If this relates to registers somehow, that must be a fixed type; otherwise, if not, I believe you can reduce the size of some of those vars in here.

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 57

Quoted 3 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +3 -0
+};
+
+/*

For kerneldoc, you start with /**

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 59

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +2 -0
+ * struct mtk_cam_vdev_desc - MTK camera device descriptor
+ *

Remove extra blank line.

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 71

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +12 -0
+ * @name: name of the node
+ * @cap: supported V4L2 capabilities
+ * @buf_type: supported V4L2 buffer type
+ * @link_flags: default media link flags
+ * @def_width: the default format width
+ * @def_height: the default format height
+ * @num_fmts: the number of supported node formats
+ * @max_buf_count: maximum VB2 buffer count
+ * @ioctl_ops:  mapped to v4l2_ioctl_ops
+ * @fmts: supported format
+ * @frmsizes: supported V4L2 frame size number
+ *

same

Quoted 6 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +6 -0
+ */
+struct mtk_cam_vdev_desc {
+	const char *name;
+	u32 cap;
+	u32 buf_type;
+	u32 link_flags;

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 87

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +10 -0
+	u32 def_width;
+	u32 def_height;
+	u8 num_fmts;
+	u8 max_buf_count;
+	const struct v4l2_ioctl_ops *ioctl_ops;
+	const u32 *fmts;
+	const struct v4l2_frmsizeenum *frmsizes;
+};
+
+/*

/**

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 89

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +2 -0
+ * struct mtk_cam_video_device - MediaTek video device structure
+ *

and again... please fix all instances of that.

Quoted 81 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +81 -0
+ * @desc: The node description of video device
+ * @vdev_pad: The media pad graph object of video device
+ * @vdev: The video device instance
+ * @vbq: A videobuf queue of video device
+ * @vdev_lock: Serializes vb2 queue and video device operations
+ * @format: The V4L2 format of video device
+ * @fmtinfo: Information about the current format
+ */
+struct mtk_cam_video_device {
+	const struct mtk_cam_vdev_desc *desc;
+
+	struct media_pad vdev_pad;
+	struct video_device vdev;
+	struct vb2_queue vbq;
+
+	/* Serializes vb2 queue and video device operations */
+	struct mutex vdev_lock;
+
+	struct v4l2_pix_format_mplane format;
+	const struct mtk_cam_format_info *fmtinfo;
+};
+
+/*
+ * struct mtk_cam_dev - MediaTek camera device structure.
+ *
+ * @dev: Pointer to device.
+ * @regs: Base address of CAMSV.
+ * @regs_img0: Base address of CAMSV IMG0.
+ * @regs_tg: Base address of CAMSV TG.
+ * @num_clks: Number of clocks.
+ * @clks: The clocks.
+ * @irq: Irq fired when buffer is ready.
+ * @conf: soc specific driver data.
+ * @pipeline: Media pipeline information.
+ * @subdev: The V4L2 sub-device instance.
+ * @subdev_pads: Media pads of this sub-device.
+ * @formats: Media bus format for all pads.
+ * @vdev: The video device node.
+ * @seninf: Pointer to the seninf pad.
+ * @streaming: Indicate the overall streaming status is on or off.
+ * @stream_count: Number of streaming video nodes.
+ * @sequence: Buffer sequence number.
+ * @op_lock: Serializes driver's VB2 callback operations.
+ * @irqlock: Protects the buffer list.
+ * @buf_list: List head for the buffer list.
+ * @hw_functions: Hardware specific functions.
+ * @dummy: Dummy buffer used when user buffer is not available.
+ * @dummy_size : Size of the dummy buffer.
+ * @is_dummy_used: True if dummy buffer is currently used.
+ */
+struct mtk_cam_dev {
+	struct device *dev;
+	void __iomem *regs;
+	void __iomem *regs_img0;
+	void __iomem *regs_tg;
+
+	unsigned int num_clks;
+	struct clk_bulk_data *clks;
+	unsigned int irq;
+	const struct mtk_cam_conf *conf;
+
+	struct media_pipeline pipeline;
+	struct v4l2_subdev subdev;
+	struct media_pad subdev_pads[MTK_CAM_CIO_NUM_PADS];
+	struct v4l2_mbus_framefmt formats[MTK_CAM_CIO_NUM_PADS];
+	struct mtk_cam_video_device vdev;
+	struct media_pad *seninf;
+	unsigned int streaming;
+	unsigned int stream_count;
+	unsigned int sequence;
+
+	struct mutex op_lock;
+	spinlock_t irqlock;
+
+	struct list_head buf_list;
+
+	struct mtk_cam_hw_functions *hw_functions;
+
+	struct mtk_cam_dev_buffer dummy;
+	unsigned int dummy_size;
+	bool is_dummy_used;

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 180

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +10 -0
+};
+
+struct mtk_cam_conf {
+	unsigned int tg_sen_mode;
+	unsigned int module_en;
+	unsigned int pak;
+	unsigned int dma_special_fun;
+	unsigned int imgo_con;
+	unsigned int imgo_con2;
+	unsigned int imgo_con3;

u32?

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 181

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +1 -0
+	bool enableFH;

bool frm_hdr_en;

Quoted 99 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +19 -0
+};
+
+struct mtk_cam_hw_functions {
+	void (*mtk_cam_setup)(struct mtk_cam_dev *cam_dev, u32 width,
+			      u32 height, u32 bpl, u32 mbus_fmt);
+	void (*mtk_cam_update_buffers_add)(struct mtk_cam_dev *cam_dev,
+					   struct mtk_cam_dev_buffer *buf);
+	void (*mtk_cam_cmos_vf_hw_enable)(struct mtk_cam_dev *cam_dev,
+					  bool pak_en);
+	void (*mtk_cam_cmos_vf_hw_disable)(struct mtk_cam_dev *cam_dev,
+					   bool pak_en);
+};
+
+int mtk_cam_dev_init(struct mtk_cam_dev *cam_dev);
+void mtk_cam_dev_cleanup(struct mtk_cam_dev *cam_dev);
+int mtk_cam_video_register(struct mtk_cam_dev *cam_dev);
+void mtk_cam_video_unregister(struct mtk_cam_video_device *vdev);
+
+#endif /* __MTK_CAMSV_H__ */
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +74 -0
new file mode 100644
index 000000000000..39fc3ef7b4e7
@@ -0,0 +1,474 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020 BayLibre
+ * Copyright (c) 2022 MediaTek Inc.
+ */
+
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/iommu.h>
+#include <linux/ktime.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+
+#include "mtk_camsv.h"
+#include "mtk_camsv30_regs.h"
+
+#define MTK_CAMSV30_AUTOSUSPEND_DELAY_MS 100
+
+static const struct mtk_cam_conf camsv30_conf = {
+	.tg_sen_mode = 0x00010002U, /* TIME_STP_EN = 1. DBL_DATA_BUS = 1 */
+	.module_en = 0x40000001U, /* enable double buffer and TG */
+	.dma_special_fun = 0x61000000U, /* enable RDMA insterlace */
+	.imgo_con = 0x80000080U, /* DMA FIFO depth and burst */
+	.imgo_con2 = 0x00020002U, /* DMA priority */
+	.imgo_con3 = 0x00020002U, /* DMA pre-priority */
+	.enableFH = false, /* Frame Header disabled */
+};
+
+static void fmt_to_sparams(u32 mbus_fmt, struct mtk_cam_sparams *sparams)
+{
+	switch (mbus_fmt) {
+	/* SBGGR values coming from isp5.0 configuration.
+	 * not tested on isp2.0
+	 */
+	case MEDIA_BUS_FMT_SBGGR12_1X12:
+	case MEDIA_BUS_FMT_SGBRG12_1X12:
+	case MEDIA_BUS_FMT_SGRBG12_1X12:
+	case MEDIA_BUS_FMT_SRGGB12_1X12:
+		sparams->w_factor = 1;
+		sparams->module_en_pak = 0x4;
+		sparams->fmt_sel = 0x2;
+		sparams->pak = 0x5;
+		sparams->imgo_stride = 0x000B0000;
+		break;
+	case MEDIA_BUS_FMT_SBGGR10_1X10:
+	case MEDIA_BUS_FMT_SGBRG10_1X10:
+	case MEDIA_BUS_FMT_SGRBG10_1X10:
+	case MEDIA_BUS_FMT_SRGGB10_1X10:
+		sparams->w_factor = 1;
+		sparams->module_en_pak = 0x4;
+		sparams->fmt_sel = 0x1;
+		sparams->pak = 0x6;
+		sparams->imgo_stride = 0x000B0000;
+		break;
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+	case MEDIA_BUS_FMT_SGBRG8_1X8:
+	case MEDIA_BUS_FMT_SGRBG8_1X8:
+	case MEDIA_BUS_FMT_SRGGB8_1X8:
+		sparams->w_factor = 1;
+		sparams->module_en_pak = 0x4;
+		sparams->fmt_sel = 0x0;
+		sparams->pak = 0x7;
+		sparams->imgo_stride = 0x000B0000;
+		break;
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_VYUY8_1X16:
+	case MEDIA_BUS_FMT_YUYV8_1X16:
+	case MEDIA_BUS_FMT_YVYU8_1X16:
+		sparams->w_factor = 2;
+		sparams->module_en_pak = 0x8;
+		sparams->fmt_sel = 0x1000003;
+		sparams->pak = 0x0;

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 84

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+		sparams->imgo_stride = 0x00090000;
+		break;
+	default:
+		break;
+	}
+}
+
+static u32 mtk_camsv30_read(struct mtk_cam_dev *priv, u32 reg)
+{
+	return readl(priv->regs + reg);

Drop those one-liners please, it's just not worth the noise imo.

Quoted 22 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +22 -0
+}
+
+static void mtk_camsv30_write(struct mtk_cam_dev *priv, u32 reg, u32 value)
+{
+	writel(value, priv->regs + reg);
+}
+
+static void mtk_camsv30_img0_write(struct mtk_cam_dev *priv, u32 reg, u32 value)
+{
+	writel(value, priv->regs_img0 + reg);
+}
+
+static u32 mtk_camsv30_tg_read(struct mtk_cam_dev *priv, u32 reg)
+{
+	return readl(priv->regs_tg + reg);
+}
+
+static void mtk_camsv30_tg_write(struct mtk_cam_dev *priv, u32 reg, u32 value)
+{
+	writel(value, priv->regs_tg + reg);
+}
+

..snip..

Quoted 27 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +27 -0
+
+static void mtk_camsv30_setup(struct mtk_cam_dev *cam_dev, u32 w, u32 h,
+			      u32 bpl, u32 mbus_fmt)
+{
+	const struct mtk_cam_conf *conf = cam_dev->conf;
+	int poll_num = 1000;
+	u32 int_en = INT_ST_MASK_CAMSV;
+	struct mtk_cam_sparams sparams;
+
+	fmt_to_sparams(mbus_fmt, &sparams);
+
+	spin_lock(&cam_dev->irqlock);
+
+	if (pm_runtime_get_sync(cam_dev->dev) < 0) {
+		dev_err(cam_dev->dev, "failed to get pm_runtime\n");
+		spin_unlock(&cam_dev->irqlock);
+		return;
+	}
+
+	mtk_camsv30_tg_write(cam_dev, CAMSV_TG_SEN_MODE, conf->tg_sen_mode);
+
+	mtk_camsv30_tg_write(cam_dev,
+			     CAMSV_TG_SEN_GRAB_PXL, (w * sparams.w_factor) << 16U);
+
+	mtk_camsv30_tg_write(cam_dev, CAMSV_TG_SEN_GRAB_LIN, h << 16U);
+
+	/* YUV_U2S_DIS: disable YUV sensor unsigned to signed */

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 175

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+	mtk_camsv30_tg_write(cam_dev, CAMSV_TG_PATH_CFG, 0x1000U);
+
+	/* Reset cam */
+	mtk_camsv30_write(cam_dev, CAMSV_SW_CTL, CAMSV_SW_RST);
+	mtk_camsv30_write(cam_dev, CAMSV_SW_CTL, 0x0U);
+	mtk_camsv30_write(cam_dev, CAMSV_SW_CTL, CAMSV_IMGO_RST_TRIG);
+
+	while (mtk_camsv30_read(cam_dev, CAMSV_SW_CTL) !=
+		       (CAMSV_IMGO_RST_TRIG | CAMSV_IMGO_RST_ST) &&
+	       poll_num++ < 1000)

Decide: this is either

 # poll_num = 1000; poll_num-- > 0;  or
 # poll_num = 0; poll_num++ < 1000.

Besides, however we put it, it's anyway wrong, as you can use common (atomic or not) helpers for polling registers, which is what you should do here :-)

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +12 -0
+		;
+
+	mtk_camsv30_write(cam_dev, CAMSV_SW_CTL, 0x0U);
+
+	mtk_camsv30_write(cam_dev, CAMSV_INT_EN, int_en);
+
+	mtk_camsv30_write(cam_dev, CAMSV_MODULE_EN,
+			  conf->module_en | sparams.module_en_pak);
+	mtk_camsv30_write(cam_dev, CAMSV_FMT_SEL, sparams.fmt_sel);
+	mtk_camsv30_write(cam_dev, CAMSV_PAK, sparams.pak);
+
+	mtk_camsv30_img0_write(cam_dev, CAMSV_IMGO_SV_XSIZE, bpl - 1U);

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 197

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+	mtk_camsv30_img0_write(cam_dev, CAMSV_IMGO_SV_YSIZE, h - 1U);
+
+	mtk_camsv30_img0_write(cam_dev, CAMSV_IMGO_SV_STRIDE, sparams.imgo_stride | bpl);
+
+	mtk_camsv30_img0_write(cam_dev, CAMSV_IMGO_SV_CON, conf->imgo_con);
+	mtk_camsv30_img0_write(cam_dev, CAMSV_IMGO_SV_CON2, conf->imgo_con2);
+
+	/* CMOS_EN first */
+	mtk_camsv30_tg_write(cam_dev, CAMSV_TG_SEN_MODE,
+			     mtk_camsv30_tg_read(cam_dev, CAMSV_TG_SEN_MODE) | 0x1U);

#define CAMSV_TG_SEN_MODE_CMOS_EN BIT(0) (did I get that right?)

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 201

Quoted 4 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +4 -0
+
+	/* finally, CAMSV_MODULE_EN : IMGO_EN */
+	mtk_camsv30_write(cam_dev, CAMSV_MODULE_EN,
+			  mtk_camsv30_read(cam_dev, CAMSV_MODULE_EN) | 0x00000010U);

#define CAMSV_MODULE_IMGO_EN BIT(4)

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +5 -0
+
+	pm_runtime_put_autosuspend(cam_dev->dev);
+	spin_unlock(&cam_dev->irqlock);
+}
+

..snip..

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 352

Quoted 7 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +7 -0
+
+static int mtk_camsv30_probe(struct platform_device *pdev)
+{
+	static const char * const clk_names[] = {
+		"camsys_cam_cgpdn",
+		"camsys_camtg_cgpdn",
+		"camsys_camsv"

"CG" stands for "Clock Gating" while "PDN" stands for "Power DowN", and it also looks obvious for those clocks to be in the camsys clock controller anyway... and even if not, we definitely don't care (from this driver's perspective) about which clock controller they're located at.
In any case, we have those names in the clock controller drivers (so, names are accessible from the clock framework anyway), and each clock controller driver has the subsystem name (so, the camsys clk controller advertises being camsys already), which means that we can shorten the clk_names to...

static const char * const clk_names[] = { "cam", "camtg", "camsv" };

...also eventually leading to a more readable devicetree, as the clock-names will be just one line.

Quoted 14 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +14 -0
+	};
+
+	struct mtk_cam_dev *cam_dev;
+	struct device *dev = &pdev->dev;
+	int ret;
+	int i;
+
+	if (!iommu_present(&platform_bus_type))
+		return -EPROBE_DEFER;
+
+	cam_dev = devm_kzalloc(dev, sizeof(*cam_dev), GFP_KERNEL);
+	if (!cam_dev)
+		return -ENOMEM;
+

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 376

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+	cam_dev->conf = of_device_get_match_data(dev);
+	if (!cam_dev->conf)
+		return -ENODEV;
+
+	cam_dev->dev = dev;
+	dev_set_drvdata(dev, cam_dev);
+
+	cam_dev->regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(cam_dev->regs)) {
+		dev_err(dev, "failed to map register base\n");

return dev_err_probe( .... )

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 384

Quoted 8 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +8 -0
+		return PTR_ERR(cam_dev->regs);
+	}
+
+	cam_dev->regs_img0 = devm_platform_ioremap_resource(pdev, 1);
+
+	if (IS_ERR(cam_dev->regs_img0)) {
+		dev_err(dev, "failed to map img0 register base\n");
+		return PTR_ERR(cam_dev->regs_img0);

dev_err_probe()

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 390

Quoted 6 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +6 -0
+	}
+
+	cam_dev->regs_tg = devm_platform_ioremap_resource(pdev, 2);
+	if (IS_ERR(cam_dev->regs_tg)) {
+		dev_err(dev, "failed to map TG register base\n");
+		return PTR_ERR(cam_dev->regs_tg);

again

Quoted 5 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +5 -0
+	}
+
+	cam_dev->num_clks = ARRAY_SIZE(clk_names);
+	cam_dev->clks = devm_kcalloc(dev, cam_dev->num_clks,
+				     sizeof(*cam_dev->clks), GFP_KERNEL);

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 405

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+	if (!cam_dev->clks)
+		return -ENOMEM;
+
+	for (i = 0; i < cam_dev->num_clks; ++i)
+		cam_dev->clks[i].id = clk_names[i];
+
+	ret = devm_clk_bulk_get(dev, cam_dev->num_clks, cam_dev->clks);
+	if (ret) {
+		dev_err(dev, "failed to get clocks: %i\n", ret);
+		return ret;

and again

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 414

Quoted 9 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +9 -0
+	}
+
+	cam_dev->irq = platform_get_irq(pdev, 0);
+	ret = devm_request_irq(dev, cam_dev->irq,
+			       isp_irq_camsv30, 0,
+			       dev_name(dev), cam_dev);
+	if (ret != 0) {
+		dev_err(dev, "failed to request irq=%d\n", cam_dev->irq);
+		return -ENODEV;

and again.

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 426

Quoted 12 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +12 -0
+	}
+
+	cam_dev->hw_functions = &mtk_camsv30_hw_functions;
+
+	spin_lock_init(&cam_dev->irqlock);
+
+	/* initialise runtime power management */
+	pm_runtime_set_autosuspend_delay(dev, MTK_CAMSV30_AUTOSUSPEND_DELAY_MS);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_suspended(dev);
+	pm_runtime_enable(dev);
+	//pm_runtime_get_sync(dev);

Oops! development leftovers around! :-)

Quoted 18 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +18 -0
+
+	/* Initialize the v4l2 common part */
+	return mtk_cam_dev_init(cam_dev);
+}
+
+static int mtk_camsv30_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct mtk_cam_dev *cam_dev = dev_get_drvdata(dev);
+
+	mtk_cam_dev_cleanup(cam_dev);
+	pm_runtime_put_autosuspend(dev);
+	pm_runtime_disable(dev);
+
+	return 0;
+}
+
+static const struct dev_pm_ops mtk_camsv30_pm_ops = {

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 454

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+				pm_runtime_force_resume)
+	SET_RUNTIME_PM_OPS(mtk_camsv30_runtime_suspend,
+			   mtk_camsv30_runtime_resume, NULL)
+};
+
+static const struct of_device_id mtk_camsv30_of_ids[] = {
+	{
+		.compatible = "mediatek,mt8365-camsv",
+		.data = &camsv30_conf,

Fits in one line: { .compatible =..... data... },

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 456

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +2 -0
+	},
+	{}

and { /* sentinel */ }

Quoted 8 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +8 -0
+};
+MODULE_DEVICE_TABLE(of, mtk_camsv30_of_ids);
+
+static struct platform_driver mtk_camsv30_driver = {
+	.probe = mtk_camsv30_probe,
+	.remove = mtk_camsv30_remove,
+	.driver = {
+		.name = "mtk-camsv-isp30",

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c line 474

Quoted 10 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv30_hw.c new file +10 -0
+		.of_match_table = mtk_camsv30_of_ids,
+		.pm = &mtk_camsv30_pm_ops,
+	}
+};
+
+module_platform_driver(mtk_camsv30_driver);
+
+MODULE_DESCRIPTION("MediaTek CAMSV ISP3.0 driver");
+MODULE_AUTHOR("Florian Sylvestre <[email protected]>");
+MODULE_LICENSE("GPL");

...there might be something else, but it's a long review already; let's see what comes as v3.

Regards,
Angelo

#19 lore raw

Re: [PATCH v2 4/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

On Mon, Jul 03, 2023 at 02:21:17PM +0200, AngeloGioacchino Del Regno wrote:
..snip..

Quoted 7 lines

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 290

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +2 -0
+
+	mtk_cam_init_cfg(&cam->subdev, NULL);

mtk_cam_init_cfg() returns an integer, and this is probably because you expect it to get logic to fail: in that case, check the result of that call here, otherwise, make that function void.

Hi Angelo,

mtk_cam_init_cfg returns an int because it should match v4l2_subdev_pad_ops->init_cfg prototype..

mtk_cam_init does not fail, always return 0, so I though it would be ok to discard the return value here. What do you think?

Quoted 1 line
Quoted 1 line

+

..snip..

Quoted 6 lines

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 39

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +1 -0
+	unsigned int bpp;

Can we get any format that uses a billion bits per pixel? :-P

u8 bpp;

I am preparing the driver for futur upgrades.. in a billion years ;)

Cheers
Julien

#20 lore raw

Re: [PATCH v2 4/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

Quoted 10 lines · Julien Stephan

On Mon, Jul 03, 2023 at 02:21:17PM +0200, AngeloGioacchino Del Regno wrote:
..snip..

Quoted 7 lines

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 290

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +2 -0
+
+	mtk_cam_init_cfg(&cam->subdev, NULL);

mtk_cam_init_cfg() returns an integer, and this is probably because you expect it to get logic to fail: in that case, check the result of that call here, otherwise, make that function void.

Quoted 6 lines

Hi Angelo,

mtk_cam_init_cfg returns an int because it should match v4l2_subdev_pad_ops->init_cfg prototype..

mtk_cam_init does not fail, always return 0, so I though it would be ok to discard the return value here. What do you think?

Fine with me.

Quoted 11 lines
Quoted 1 line
Quoted 1 line

+

..snip..

Quoted 5 lines

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 39

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +1 -0
+	unsigned int bpp;

Can we get any format that uses a billion bits per pixel? :-P

u8 bpp;

I am preparing the driver for futur upgrades.. in a billion years ;)

Signature · 3 lines
Regards,

Laurent Pinchart
#21 lore raw

Re: [PATCH v2 4/4] media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv

In reply to Julien Stephan

Il 03/08/23 11:53, Julien Stephan ha scritto:

Quoted 10 lines · AngeloGioacchino Del Regno

..snip..

Quoted 7 lines

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c line 290

Quoted 2 lines
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.c new file +2 -0
+
+	mtk_cam_init_cfg(&cam->subdev, NULL);

mtk_cam_init_cfg() returns an integer, and this is probably because you expect it to get logic to fail: in that case, check the result of that call here, otherwise, make that function void.

Quoted 7 lines

Hi Angelo,

mtk_cam_init_cfg returns an int because it should match v4l2_subdev_pad_ops->init_cfg prototype..

mtk_cam_init does not fail, always return 0, so I though it would be ok to discard the return value here. What do you think?

Right, I was thinking to make a void __mtk_cam_init_cfg(), but as an afterthought it's just better to leave it as it is, let's go with your solution.

Cheers,
Angelo

Quoted 15 lines
Quoted 1 line
Quoted 1 line

+

..snip..

Quoted 6 lines

drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h line 39

Quoted 1 line
drivers/media/platform/mediatek/isp/isp_30/camsv/mtk_camsv.h new file +1 -0
+	unsigned int bpp;

Can we get any format that uses a billion bits per pixel? :-P

u8 bpp;

I am preparing the driver for futur upgrades.. in a billion years ;)

Cheers
Julien