From 07dad18a058170c0bfd38fd1f0eb21407efcbafb Mon Sep 17 00:00:00 2001
From: David Plowman <david.plowman@raspberrypi.com>
Date: Tue, 29 Jun 2021 14:41:15 +0100
Subject: [PATCH] overlays: Add overlay for imx378 sensor

This is based off a common overlay which is now also used by the
imx477 sensor.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
---
 arch/arm/boot/dts/overlays/Makefile           |   1 +
 arch/arm/boot/dts/overlays/README             |   9 ++
 arch/arm/boot/dts/overlays/imx378-overlay.dts |  10 ++
 arch/arm/boot/dts/overlays/imx477-overlay.dts | 109 +-----------------
 .../boot/dts/overlays/imx477_378-overlay.dtsi | 108 +++++++++++++++++
 5 files changed, 131 insertions(+), 106 deletions(-)
 create mode 100644 arch/arm/boot/dts/overlays/imx378-overlay.dts
 create mode 100644 arch/arm/boot/dts/overlays/imx477_378-overlay.dtsi

--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -94,6 +94,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
 	ilitek251x.dtbo \
 	imx219.dtbo \
 	imx290.dtbo \
+	imx378.dtbo \
 	imx477.dtbo \
 	iqaudio-codec.dtbo \
 	iqaudio-dac.dtbo \
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -1674,6 +1674,15 @@ Params: 4lane                   Enable 4
         mono                    Denote that the module is a mono sensor.
 
 
+Name:   imx378
+Info:   Sony IMX378 camera module.
+        Uses Unicam 1, which is the standard camera connector on most Pi
+        variants.
+Load:   dtoverlay=imx378,<param>=<val>
+Params: rotation                Mounting rotation of the camera sensor (0 or
+                                180, default 180)
+
+
 Name:   imx477
 Info:   Sony IMX477 camera module.
         Uses Unicam 1, which is the standard camera connector on most Pi
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/imx378-overlay.dts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Definitions for IMX378 camera module on VC I2C bus
+/dts-v1/;
+/plugin/;
+
+#include "imx477_378-overlay.dtsi"
+
+&imx477 {
+	compatible = "sony,imx378";
+};
--- a/arch/arm/boot/dts/overlays/imx477-overlay.dts
+++ b/arch/arm/boot/dts/overlays/imx477-overlay.dts
@@ -3,111 +3,8 @@
 /dts-v1/;
 /plugin/;
 
-#include <dt-bindings/gpio/gpio.h>
+#include "imx477_378-overlay.dtsi"
 
-/{
-	compatible = "brcm,bcm2835";
-
-	fragment@0 {
-		target = <&i2c_csi_dsi>;
-		__overlay__ {
-			#address-cells = <1>;
-			#size-cells = <0>;
-			status = "okay";
-
-			imx477: imx477@1a {
-				compatible = "sony,imx477";
-				reg = <0x1a>;
-				status = "okay";
-
-				clocks = <&imx477_clk>;
-				clock-names = "xclk";
-
-				VANA-supply = <&cam1_reg>;	/* 2.8v */
-				VDIG-supply = <&imx477_vdig>;	/* 1.05v */
-				VDDL-supply = <&imx477_vddl>;	/* 1.8v */
-
-				rotation = <180>;
-
-				port {
-					imx477_0: endpoint {
-						remote-endpoint = <&csi1_ep>;
-						clock-lanes = <0>;
-						data-lanes = <1 2>;
-						clock-noncontinuous;
-						link-frequencies =
-							/bits/ 64 <450000000>;
-					};
-				};
-			};
-		};
-	};
-
-	fragment@1 {
-		target = <&csi1>;
-		__overlay__ {
-			status = "okay";
-
-			port {
-				csi1_ep: endpoint {
-					remote-endpoint = <&imx477_0>;
-					clock-lanes = <0>;
-					data-lanes = <1 2>;
-					clock-noncontinuous;
-				};
-			};
-		};
-	};
-
-	fragment@2 {
-		target = <&i2c0if>;
-		__overlay__ {
-			status = "okay";
-		};
-	};
-
-	fragment@3 {
-		target-path="/";
-		__overlay__ {
-			imx477_vdig: fixedregulator@0 {
-				compatible = "regulator-fixed";
-				regulator-name = "imx477_vdig";
-				regulator-min-microvolt = <1050000>;
-				regulator-max-microvolt = <1050000>;
-			};
-			imx477_vddl: fixedregulator@1 {
-				compatible = "regulator-fixed";
-				regulator-name = "imx477_vddl";
-				regulator-min-microvolt = <1800000>;
-				regulator-max-microvolt = <1800000>;
-			};
-			imx477_clk: camera-clk {
-				compatible = "fixed-clock";
-				#clock-cells = <0>;
-				clock-frequency = <24000000>;
-			};
-		};
-	};
-
-	fragment@4 {
-		target = <&i2c0mux>;
-		__overlay__ {
-			status = "okay";
-		};
-	};
-
-	fragment@5 {
-		target = <&cam1_reg>;
-		__overlay__ {
-			status = "okay";
-			regulator-name = "imx477_vana";
-			startup-delay-us = <300000>;
-			regulator-min-microvolt = <2800000>;
-			regulator-max-microvolt = <2800000>;
-		};
-	};
-
-	__overrides__ {
-		rotation = <&imx477>,"rotation:0";
-	};
+&imx477 {
+	compatible = "sony,imx477";
 };
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/imx477_378-overlay.dtsi
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Definitions for IMX477 camera module on VC I2C bus
+
+/{
+	compatible = "brcm,bcm2835";
+
+	fragment@0 {
+		target = <&i2c_csi_dsi>;
+		__overlay__ {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "okay";
+
+			imx477: imx477@1a {
+				reg = <0x1a>;
+				status = "okay";
+
+				clocks = <&imx477_clk>;
+				clock-names = "xclk";
+
+				VANA-supply = <&cam1_reg>;	/* 2.8v */
+				VDIG-supply = <&imx477_vdig>;	/* 1.05v */
+				VDDL-supply = <&imx477_vddl>;	/* 1.8v */
+
+				rotation = <180>;
+
+				port {
+					imx477_0: endpoint {
+						remote-endpoint = <&csi1_ep>;
+						clock-lanes = <0>;
+						data-lanes = <1 2>;
+						clock-noncontinuous;
+						link-frequencies =
+							/bits/ 64 <450000000>;
+					};
+				};
+			};
+		};
+	};
+
+	fragment@1 {
+		target = <&csi1>;
+		__overlay__ {
+			status = "okay";
+
+			port {
+				csi1_ep: endpoint {
+					remote-endpoint = <&imx477_0>;
+					clock-lanes = <0>;
+					data-lanes = <1 2>;
+					clock-noncontinuous;
+				};
+			};
+		};
+	};
+
+	fragment@2 {
+		target = <&i2c0if>;
+		__overlay__ {
+			status = "okay";
+		};
+	};
+
+	fragment@3 {
+		target-path="/";
+		__overlay__ {
+			imx477_vdig: fixedregulator@0 {
+				compatible = "regulator-fixed";
+				regulator-name = "imx477_vdig";
+				regulator-min-microvolt = <1050000>;
+				regulator-max-microvolt = <1050000>;
+			};
+			imx477_vddl: fixedregulator@1 {
+				compatible = "regulator-fixed";
+				regulator-name = "imx477_vddl";
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+			};
+			imx477_clk: camera-clk {
+				compatible = "fixed-clock";
+				#clock-cells = <0>;
+				clock-frequency = <24000000>;
+			};
+		};
+	};
+
+	fragment@4 {
+		target = <&i2c0mux>;
+		__overlay__ {
+			status = "okay";
+		};
+	};
+
+	fragment@5 {
+		target = <&cam1_reg>;
+		__overlay__ {
+			status = "okay";
+			regulator-name = "imx477_vana";
+			startup-delay-us = <300000>;
+			regulator-min-microvolt = <2800000>;
+			regulator-max-microvolt = <2800000>;
+		};
+	};
+
+	__overrides__ {
+		rotation = <&imx477>,"rotation:0";
+	};
+};