From 2be1e1c949138b40aac6be1e6f761c69e98dcf66 Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Thu, 3 Sep 2020 14:59:40 +0100
Subject: [PATCH] overlays: Update i2c0 overlay to disable the
 i2c0mux.

The i2c0 overlay was assigning pinctrl settings to node i2c0,
which is now the port@0 output of the mux. That leaves a high
chance of it colliding with the port@1 output and not doing
what was intended.

Set the i2c0 overlay to disable i2c0mux, set the pin-ctrl on
the root i2c controller, and redirect the alias, so overall it
behaves exactly as before.
Combining with dtparam=i2c_vc=on is going to cause conflicts,
so this is noted in the README.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 arch/arm/boot/dts/overlays/README           |  7 +++++++
 arch/arm/boot/dts/overlays/i2c0-overlay.dts | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -1354,6 +1354,13 @@ Name:   i2c0
 Info:   Change i2c0 pin usage. Not all pin combinations are usable on all
         platforms - platforms other then Compute Modules can only use this
         to disable transaction combining.
+        Do NOT use in conjunction with dtparam=i2c_vc=on. From the 5.4 kernel
+        onwards the base DT includes the use of i2c_mux_pinctrl to expose two
+        muxings of BSC0 - GPIOs 0&1, and whichever combination is used for the
+        camera and display connectors. This overlay disables that mux and
+        configures /dev/i2c0 to point at whichever set of pins is requested.
+        dtparam=i2c_vc=on will try and enable the mux, so combining the two
+        will cause conflicts.
 Load:   dtoverlay=i2c0,<param>=<val>
 Params: pins_0_1                Use pins 0 and 1 (default)
         pins_28_29              Use pins 28 and 29
--- a/arch/arm/boot/dts/overlays/i2c0-overlay.dts
+++ b/arch/arm/boot/dts/overlays/i2c0-overlay.dts
@@ -5,7 +5,7 @@
 	compatible = "brcm,bcm2835";
 
 	fragment@0 {
-		target = <&i2c0>;
+		target = <&i2c0if>;
 		__overlay__ {
 			status = "okay";
 			pinctrl-0 = <&i2c0_pins>;
@@ -51,6 +51,19 @@
 		};
 	};
 
+	fragment@6 {
+		target = <&i2c0mux>;
+		__overlay__ {
+			status = "disabled";
+		};
+	};
+
+	fragment@7 {
+		target-path = "/aliases";
+		__overlay__ {
+			i2c0 = "/soc/i2c@7e205000";
+		};
+	};
 	__overrides__ {
 		pins_0_1   = <0>,"+1-2-3-4";
 		pins_28_29 = <0>,"-1+2-3-4";
