From 7a1905f969cfa2e303f5e74efee56dbd0523e5bb Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Tue, 23 Jun 2020 15:41:42 +0100
Subject: [PATCH] dt/dtoverlays: Fix up base DT and overlays for
 updated Unicam driver

The upstreamed Unicam driver uses a dt property to denote how many
lanes are supported by the receiver peripheral, independent of
the number of lanes that the sensor wants to use. It also doesn't
check the remote endpoint config for the number of lanes as that
isn't the accepted way of doing things.

Update the base DT for the brcm,num-data-lanes property, and the
overlays to define the desired number of lanes at both ends of
the link.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 arch/arm/boot/dts/bcm2711-rpi-cm4.dts           |  3 ++-
 arch/arm/boot/dts/bcm283x-rpi-csi0-2lane.dtsi   |  6 +-----
 arch/arm/boot/dts/bcm283x-rpi-csi1-2lane.dtsi   |  6 +-----
 arch/arm/boot/dts/bcm283x-rpi-csi1-4lane.dtsi   |  6 +-----
 arch/arm/boot/dts/overlays/adv7282m-overlay.dts |  1 +
 arch/arm/boot/dts/overlays/imx477-overlay.dts   |  1 +
 arch/arm/boot/dts/overlays/irs1125-overlay.dts  |  2 ++
 arch/arm/boot/dts/overlays/ov5647-overlay.dts   |  1 +
 arch/arm/boot/dts/overlays/tc358743-overlay.dts | 16 +++++++++++++++-
 9 files changed, 25 insertions(+), 17 deletions(-)

--- a/arch/arm/boot/dts/bcm2711-rpi-cm4.dts
+++ b/arch/arm/boot/dts/bcm2711-rpi-cm4.dts
@@ -203,7 +203,8 @@
 };
 
 #include "bcm2711-rpi.dtsi"
-#include "bcm283x-rpi-csi1-2lane.dtsi"
+#include "bcm283x-rpi-csi0-2lane.dtsi"
+#include "bcm283x-rpi-csi1-4lane.dtsi"
 #include "bcm283x-rpi-i2c0mux_0_44.dtsi"
 
 /delete-node/ &emmc2;
--- a/arch/arm/boot/dts/bcm283x-rpi-csi0-2lane.dtsi
+++ b/arch/arm/boot/dts/bcm283x-rpi-csi0-2lane.dtsi
@@ -1,8 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0-only
 &csi0 {
-	port {
-		endpoint {
-			data-lanes = <1 2>;
-		};
-	};
+	brcm,num-data-lanes = <2>;
 };
--- a/arch/arm/boot/dts/bcm283x-rpi-csi1-2lane.dtsi
+++ b/arch/arm/boot/dts/bcm283x-rpi-csi1-2lane.dtsi
@@ -1,8 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0-only
 &csi1 {
-	port {
-		endpoint {
-			data-lanes = <1 2>;
-		};
-	};
+	brcm,num-data-lanes = <2>;
 };
--- a/arch/arm/boot/dts/bcm283x-rpi-csi1-4lane.dtsi
+++ b/arch/arm/boot/dts/bcm283x-rpi-csi1-4lane.dtsi
@@ -1,8 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0-only
 &csi1 {
-	port {
-		endpoint {
-			data-lanes = <1 2 3 4>;
-		};
-	};
+	brcm,num-data-lanes = <4>;
 };
--- a/arch/arm/boot/dts/overlays/adv7282m-overlay.dts
+++ b/arch/arm/boot/dts/overlays/adv7282m-overlay.dts
@@ -40,6 +40,7 @@
 			port {
 				csi1_ep: endpoint {
 					remote-endpoint = <&adv728x_0>;
+					data-lanes = <1>;
 				};
 			};
 		};
--- a/arch/arm/boot/dts/overlays/imx477-overlay.dts
+++ b/arch/arm/boot/dts/overlays/imx477-overlay.dts
@@ -49,6 +49,7 @@
 			port {
 				csi1_ep: endpoint {
 					remote-endpoint = <&imx477_0>;
+					data-lanes = <1 2>;
 				};
 			};
 		};
--- a/arch/arm/boot/dts/overlays/irs1125-overlay.dts
+++ b/arch/arm/boot/dts/overlays/irs1125-overlay.dts
@@ -43,6 +43,8 @@
 			port {
 				csi1_ep: endpoint {
 					remote-endpoint = <&irs1125_0>;
+					data-lanes = <1 2>;
+					clock-noncontinuous;
 				};
 			};
 		};
--- a/arch/arm/boot/dts/overlays/ov5647-overlay.dts
+++ b/arch/arm/boot/dts/overlays/ov5647-overlay.dts
@@ -43,6 +43,7 @@
 			port {
 				csi1_ep: endpoint {
 					remote-endpoint = <&ov5647_0>;
+					data-lanes = <1 2>;
 				};
 			};
 		};
--- a/arch/arm/boot/dts/overlays/tc358743-overlay.dts
+++ b/arch/arm/boot/dts/overlays/tc358743-overlay.dts
@@ -86,8 +86,22 @@
 		};
 	};
 
+	fragment@7 {
+		target = <&csi1_ep>;
+		__overlay__ {
+			data-lanes = <1 2>;
+		};
+	};
+
+	fragment@8 {
+		target = <&csi1_ep>;
+		__dormant__ {
+			data-lanes = <1 2 3 4>;
+		};
+	};
+
 	__overrides__ {
-		4lane = <0>, "-2+3";
+		4lane = <0>, "-2+3-7+8";
 		link-frequency = <&tc358743>,"link-frequencies#0";
 	};
 };
