Skip to contentSkip to conversation

phy: mtk-mipi-csi: add driver for CSI phy

PATCH Superseded Julien Stephan 4 participants 9 messages May 24, 2023 – Jun 8, 2023

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Julien Stephan

author maintainer
#0 lore raw

v3 cover phy: mtk-mipi-csi: add driver for CSI phy

Adding a new driver for the MIPI CSI CD-PHY module v 0.5 embedded in some Mediatek soc, such as the MT8365

This driver was adapted from https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/

v1 can be found here: https://lore.kernel.org/all/[email protected]/

v2 can be found here: https://lore.kernel.org/all/[email protected]/

Changelog
Changes in v3:
Binding file:
- rename compatible string
mediatek,phy-mipi-csi-0-5 -> mediatek,mt8365-csi-rx
- rename binding file to be as compatible string
- change property mediatek,is_cdphy -> mediatek,phy-type using an enum value instead of boolean for scalability
- remove status property from example nodes
- rename example node name 'mipi_rx_csi0: mipi_rx_csi0@11c10000' -> 'csi0_rx: phy@11c10000'
- put reg address in lower case

include/dt-bindings/phy/phy.h:
- add PHY_TYPE_CDPHY definition

Driver:
- rename compatible string
- rename property mediatek,is_cdphy -> mediatek,phy-type
- rename CSIx* macro to CSIX* (x -> X)
- fix style issue on the driver data structure
- update MODULE_DESCRIPTION as suggested by Angelo and update the kconfig module description to match it
- add dphy /cdphy eq tuning function to factor the code and increase readability
- fix typo __PHY_MTK__MIPI_CSI__C_0_5_RX_REG_H_ --> __PHY_MTK_MIPI_CSI_V_0_5_RX_REG_H_
- reword commit message to update my contributions
- added missing copyright
- added module name in Kconfig

Changes in v2:
- fix all comments on bindings
- move the binding chunk from driver to binding commit
- fix dt_binding_check error (reported by DT_CHECKER_FLAGS)
- use a more generic compatible string
- add a new dt properties to simplify the driver "mediatek,is_cdphy"
- rename the driver and the corresponding file to include version
- drop of_match_ptr()
- use devm_platform_ioremap_resource
- use phy-mtk-io.h api instead of regmap
- rework the driver to use dt nodes to declare PHY instead of an array in the driver
- remove useless define for unused registers
- remove support for CSI0A/B because it cannot be tested, and it simplifies the driver for a first review
- edit commit message and bindings to be more descriptive about the hardware

Florian Sylvestre (1):
dt-bindings: phy: add mediatek MIPI CD-PHY module v0.5

Julien Stephan (1):
dt-bindings: phy: add PHY_TYPE_CDPHY definition

Phi-bang Nguyen (1):
phy: mtk-mipi-csi: add driver for CSI phy

 .../bindings/phy/mediatek,mt8365-csi-rx.yaml  |  68 +++++
 MAINTAINERS                                   |   7 +
 drivers/phy/mediatek/Kconfig                  |   8 +
 drivers/phy/mediatek/Makefile                 |   2 +
 .../mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h    |  58 ++++
 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c   | 272 ++++++++++++++++++
 include/dt-bindings/phy/phy.h                 |   3 +-
 7 files changed, 417 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml
 create mode 100644 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h
 create mode 100644 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c

--
2.40.1

author maintainer
#1 lore raw

PATCH v3 1/3 dt-bindings: phy: add PHY_TYPE_CDPHY definition

Add definition for CDPHY phy type that can be configured in either D-PHY mode or C-PHY mode

---
 include/dt-bindings/phy/phy.h | 1 +
 1 file changed, 1 insertion(+)
include/dt-bindings/phy/phy.h +1 -0
index 6b901b342348..a19d85dbbf16 100644
@@ -23,5 +23,6 @@
 #define PHY_TYPE_DPHY		10
 #define PHY_TYPE_CPHY		11
 #define PHY_TYPE_USXGMII	12
+#define PHY_TYPE_CDPHY		13
 
 #endif /* _DT_BINDINGS_PHY */
Signature · 1 line
2.40.1
author maintainer
#4 lore raw

PATCH v3 2/3 dt-bindings: phy: add mediatek MIPI CD-PHY module v0.5

In reply to Julien Stephan

From: Florian Sylvestre <[email protected]>

This adds the bindings, for the MIPI CD-PHY module v0.5 embedded in some Mediatek soc, such as the mt8365

---
 .../bindings/phy/mediatek,mt8365-csi-rx.yaml  | 67 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml
Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +67 -0
new file mode 100644
index 000000000000..a1bd96a98051
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/mediatek,mt8365-csi-rx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek Sensor Interface MIPI CSI CD-PHY
+
+maintainers:
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The SENINF CD-PHY is a set of CD-PHY connected to the SENINF CSI-2
+  receivers. The number of PHYs depends on the SoC model.
+  Depending on the SoC model, each PHYs can be either CD-PHY or D-PHY only
+  capable.
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt8365-csi-rx
+
+  reg:
+    maxItems: 1
+
+  '#phy-cells':
+    const: 0
+
+  mediatek,phy-type:
+    description:
+      Specify the phy type. Supported phy are D-PHY only or CD-PHY capable phys.
+      See include/dt-bindings/phy/phy.h for constants.
+    enum: [10, 13]
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+required:
+  - compatible
+  - reg
+  - mediatek,phy-type
+  - '#phy-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+    soc {
+      #address-cells = <2>;
+      #size-cells = <2>;
+
+      csi0_rx: phy@11c10000 {
+        compatible = "mediatek,mt8365-csi-rx";
+        reg = <0 0x11c10000 0 0x2000>;
+        mediatek,phy-type = <PHY_TYPE_CDPHY>;
+        #phy-cells = <0>;
+      };
+
+      csi1_rx: phy@11c12000 {
+        compatible = "mediatek,mt8365-csi-rx";
+        reg = <0 0x11c12000 0 0x2000>;
+        mediatek,phy-type = <PHY_TYPE_DPHY>;
+        #phy-cells = <0>;
+      };
+    };
+...
MAINTAINERS +6 -0
index b81e9fcc66cb..5da594fbb761 100644
@@ -13184,6 +13184,12 @@ F:	Documentation/devicetree/bindings/media/mediatek-vpu.txt
 F:	drivers/media/platform/mediatek/vcodec/
 F:	drivers/media/platform/mediatek/vpu/
 
+MEDIATEK MIPI-CSI CDPHY DRIVER
+M:	Julien Stephan <[email protected]>
+M:	Andy Hsieh <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml
+
 MEDIATEK MMC/SD/SDIO DRIVER
 M:	Chaotian Jing <[email protected]>
 S:	Maintained
Signature · 1 line
2.40.1
author maintainer
#8 lore raw

PATCH v3 3/3 phy: mtk-mipi-csi: add driver for CSI phy

In reply to Julien Stephan

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

This is a new driver that supports the MIPI CSI CD-PHY version 0.5

The number of PHYs depend on the SoC.
Each PHY can support D-PHY only or CD-PHY configuration. The driver supports only D-PHY mode, so CD-PHY compatible PHY are configured in D-PHY mode.

[Julien Stephan: refactor code]

[Julien Stephan: simplify driver model: one instance per phy vs one instance for all phys]

---
 MAINTAINERS                                   |   1 +
 drivers/phy/mediatek/Kconfig                  |  12 +
 drivers/phy/mediatek/Makefile                 |   2 +
 .../mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h    |  62 ++++
 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c   | 278 ++++++++++++++++++
 5 files changed, 355 insertions(+)
 create mode 100644 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h
 create mode 100644 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c
MAINTAINERS +1 -0
index 5da594fbb761..e505023ffda1 100644
@@ -13189,6 +13189,7 @@ M:	Julien Stephan <[email protected]>
 M:	Andy Hsieh <[email protected]>
 S:	Supported
 F:	Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml
+F:	drivers/phy/mediatek/phy-mtk-mipi-csi-0-5*
 
 MEDIATEK MMC/SD/SDIO DRIVER
 M:	Chaotian Jing <[email protected]>
drivers/phy/mediatek/Kconfig +12 -0
index 3125ecb5d119..7088382ebc9e 100644
@@ -74,3 +74,15 @@ config PHY_MTK_DP
 	select GENERIC_PHY
 	help
 	  Support DisplayPort PHY for MediaTek SoCs.
+
+config PHY_MTK_MIPI_CSI_0_5
+	tristate "MediaTek MIPI CSI CD-PHY v0.5 Driver"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on OF
+	select GENERIC_PHY
+	help
+	  Enable this to support the MIPI CSI CD-PHY receiver version 0.5.
+	  The driver supports multiple CSI cdphy ports simultaneously.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called phy-mtk-mipi-csi-0-5.
drivers/phy/mediatek/Makefile +2 -0
index c9a50395533e..63f2fa3ec7e5 100644
@@ -19,3 +19,5 @@ phy-mtk-mipi-dsi-drv-y			:= phy-mtk-mipi-dsi.o
 phy-mtk-mipi-dsi-drv-y			+= phy-mtk-mipi-dsi-mt8173.o
 phy-mtk-mipi-dsi-drv-y			+= phy-mtk-mipi-dsi-mt8183.o
 obj-$(CONFIG_PHY_MTK_MIPI_DSI)		+= phy-mtk-mipi-dsi-drv.o
+
+obj-$(CONFIG_PHY_MTK_MIPI_CSI_0_5)	+= phy-mtk-mipi-csi-0-5.o
drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h new file +62 -0

62 lines not on this page · raw message

drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c new file +278 -0

278 lines not on this page · raw message

Signature · 1 line
2.40.1
#5 lore raw

Re: [PATCH v3 2/3] dt-bindings: phy: add mediatek MIPI CD-PHY module v0.5

In reply to Julien Stephan

Il 24/05/23 10:30, Julien Stephan ha scritto:

Quoted 40 lines

From: Florian Sylvestre <[email protected]>

This adds the bindings, for the MIPI CD-PHY module v0.5 embedded in some Mediatek soc, such as the mt8365

---
  .../bindings/phy/mediatek,mt8365-csi-rx.yaml  | 67 +++++++++++++++++++
  MAINTAINERS                                   |  6 ++
  2 files changed, 73 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml

Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +21 -0
new file mode 100644
index 000000000000..a1bd96a98051
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/mediatek,mt8365-csi-rx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek Sensor Interface MIPI CSI CD-PHY
+
+maintainers:
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The SENINF CD-PHY is a set of CD-PHY connected to the SENINF CSI-2
+  receivers. The number of PHYs depends on the SoC model.
+  Depending on the SoC model, each PHYs can be either CD-PHY or D-PHY only
+  capable.
+
+properties:
+  compatible:

Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +10 -0
+    enum:
+      - mediatek,mt8365-csi-rx
+
+  reg:
+    maxItems: 1
+
+  '#phy-cells':
+    const: 0
+
+  mediatek,phy-type:

Instead of declaring a phy-type here like this, can't we instead declare that in the phy cells, like we're doing with MTK TPHY and like other non-MediaTek PHYs are already doing?

device {
	...
	phys = <&csi0_rx PHY_TYPE_CDPHY>;
	...
}

Regards,
Angelo

maintainer Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] dt-bindings: phy: add PHY_TYPE_CDPHY definition

In reply to Julien Stephan

Il 24/05/23 10:30, Julien Stephan ha scritto:

Quoted 4 lines

Add definition for CDPHY phy type that can be configured in either D-PHY mode or C-PHY mode

Quoted 15 lines
---
  include/dt-bindings/phy/phy.h | 1 +
  1 file changed, 1 insertion(+)
include/dt-bindings/phy/phy.h +1 -0
index 6b901b342348..a19d85dbbf16 100644
@@ -23,5 +23,6 @@
  #define PHY_TYPE_DPHY		10
  #define PHY_TYPE_CPHY		11
  #define PHY_TYPE_USXGMII	12
+#define PHY_TYPE_CDPHY		13
 
  #endif /* _DT_BINDINGS_PHY */
author maintainer
#6 lore raw

Re: [PATCH v3 2/3] dt-bindings: phy: add mediatek MIPI CD-PHY module v0.5

In reply to AngeloGioacchino Del Regno
Quoted 56 lines · AngeloGioacchino Del Regno

Il 24/05/23 10:30, Julien Stephan ha scritto:

Quoted 40 lines

From: Florian Sylvestre <[email protected]>

This adds the bindings, for the MIPI CD-PHY module v0.5 embedded in some Mediatek soc, such as the mt8365

---
  .../bindings/phy/mediatek,mt8365-csi-rx.yaml  | 67 +++++++++++++++++++
  MAINTAINERS                                   |  6 ++
  2 files changed, 73 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml

Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +21 -0
new file mode 100644
index 000000000000..a1bd96a98051
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/mediatek,mt8365-csi-rx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek Sensor Interface MIPI CSI CD-PHY
+
+maintainers:
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The SENINF CD-PHY is a set of CD-PHY connected to the SENINF CSI-2
+  receivers. The number of PHYs depends on the SoC model.
+  Depending on the SoC model, each PHYs can be either CD-PHY or D-PHY only
+  capable.
+
+properties:
+  compatible:

Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +10 -0
+    enum:
+      - mediatek,mt8365-csi-rx
+
+  reg:
+    maxItems: 1
+
+  '#phy-cells':
+    const: 0
+
+  mediatek,phy-type:

Instead of declaring a phy-type here like this, can't we instead declare that in the phy cells, like we're doing with MTK TPHY and like other non-MediaTek PHYs are already doing?

Quoted 10 lines
device {
	...
	phys = <&csi0_rx PHY_TYPE_CDPHY>;
	...
}

Regards,
Angelo

Hi Angelo,

This is a hardware property that is not dynamic, so IMHO it doesn't make sense to use phy argument for that. Some driver already use a 'phy-type' property (such as phy-cadence-torrent.yaml).

I was thinking of using phy argument on future upgrade when driver will support D-PHY and C-PHY modes so the phy user will be able to choose the mode.

Does it makes sense?

Best
Julien

#3 lore raw

Re: [PATCH v3 1/3] dt-bindings: phy: add PHY_TYPE_CDPHY definition

In reply to Julien Stephan
Quoted 13 lines · Julien Stephan

Add definition for CDPHY phy type that can be configured in either D-PHY mode or C-PHY mode

---
 include/dt-bindings/phy/phy.h | 1 +
 1 file changed, 1 insertion(+)
include/dt-bindings/phy/phy.h +0 -0
index 6b901b342348..a19d85dbbf16 100644

include/dt-bindings/phy/phy.h line 26

Quoted 4 lines
include/dt-bindings/phy/phy.h +1 -0
@@ -23,5 +23,6 @@
 #define PHY_TYPE_DPHY		10
 #define PHY_TYPE_CPHY		11
 #define PHY_TYPE_USXGMII	12
+#define PHY_TYPE_CDPHY		13

I don't think there is CD phy. It is D-PHY or C-PHY. This is not for all possible combinations but just types of phy.

Best regards,
Krzysztof

maintainer
#7 lore raw

Re: [PATCH v3 2/3] dt-bindings: phy: add mediatek MIPI CD-PHY module v0.5

In reply to Julien Stephan
Quoted 68 lines · Julien Stephan
Quoted 56 lines · AngeloGioacchino Del Regno

Il 24/05/23 10:30, Julien Stephan ha scritto:

Quoted 40 lines

From: Florian Sylvestre <[email protected]>

This adds the bindings, for the MIPI CD-PHY module v0.5 embedded in some Mediatek soc, such as the mt8365

---
  .../bindings/phy/mediatek,mt8365-csi-rx.yaml  | 67 +++++++++++++++++++
  MAINTAINERS                                   |  6 ++
  2 files changed, 73 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml

Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +21 -0
new file mode 100644
index 000000000000..a1bd96a98051
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2023 MediaTek, BayLibre
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/mediatek,mt8365-csi-rx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek Sensor Interface MIPI CSI CD-PHY
+
+maintainers:
+  - Julien Stephan <[email protected]>
+  - Andy Hsieh <[email protected]>
+
+description:
+  The SENINF CD-PHY is a set of CD-PHY connected to the SENINF CSI-2
+  receivers. The number of PHYs depends on the SoC model.
+  Depending on the SoC model, each PHYs can be either CD-PHY or D-PHY only
+  capable.
+
+properties:
+  compatible:

Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/phy/mediatek,mt8365-csi-rx.yaml new file +10 -0
+    enum:
+      - mediatek,mt8365-csi-rx
+
+  reg:
+    maxItems: 1
+
+  '#phy-cells':
+    const: 0
+
+  mediatek,phy-type:

Instead of declaring a phy-type here like this, can't we instead declare that in the phy cells, like we're doing with MTK TPHY and like other non-MediaTek PHYs are already doing?

Quoted 10 lines
device {
	...
	phys = <&csi0_rx PHY_TYPE_CDPHY>;
	...
}

Regards,
Angelo

Quoted 4 lines

Hi Angelo,

This is a hardware property that is not dynamic, so IMHO it doesn't make sense to use phy argument for that.

Why? Interrupt numbers are fixed hardware properties which go in arg cells.

Quoted 6 lines

Some driver already use a 'phy-type'
property (such as phy-cadence-torrent.yaml).

I was thinking of using phy argument on future upgrade when driver will support D-PHY and C-PHY modes so the phy user will be able to choose the mode.

Once you design the binding, you don't get to change it.

Rob