From c63b13bddf317347ba0b69807c1591526d50ba47 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.org>
Date: Tue, 7 May 2019 14:29:38 +0100
Subject: [PATCH] BCM270X_DT: Add non-removable clone of mmc node

non-removable is a boolean property, and as such can't be unset by an
overlay if it is set in a base DTB. Until now the workaround for this
problem has been for overlays to clone non-removable nodes without
the offending property, but this involves a lot of unnecessary
replication. Instead, add a clone of the mmc node with non-removable
already set to the base DTB, selecting the required version using
the status properties.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
---
 arch/arm/boot/dts/bcm2708-rpi-0-w.dts       |  4 +--
 arch/arm/boot/dts/bcm2708-rpi.dtsi          |  3 +-
 arch/arm/boot/dts/bcm270x.dtsi              | 13 ++++++++
 arch/arm/boot/dts/bcm2710-rpi-3-b-plus.dts  |  5 ++--
 arch/arm/boot/dts/bcm2710-rpi-3-b.dts       |  5 ++--
 arch/arm/boot/dts/overlays/mmc-overlay.dts  |  7 +++++
 arch/arm/boot/dts/overlays/sdio-overlay.dts | 33 +++++++--------------
 7 files changed, 38 insertions(+), 32 deletions(-)

--- a/arch/arm/boot/dts/bcm2708-rpi-0-w.dts
+++ b/arch/arm/boot/dts/bcm2708-rpi-0-w.dts
@@ -14,6 +14,7 @@
 	aliases {
 		serial0 = &uart1;
 		serial1 = &uart0;
+		mmc1 = &mmcnr;
 	};
 };
 
@@ -73,10 +74,9 @@
 	};
 };
 
-&mmc {
+&mmcnr {
 	pinctrl-names = "default";
 	pinctrl-0 = <&sdio_pins>;
-	non-removable;
 	bus-width = <4>;
 	status = "okay";
 };
--- a/arch/arm/boot/dts/bcm2708-rpi.dtsi
+++ b/arch/arm/boot/dts/bcm2708-rpi.dtsi
@@ -118,7 +118,8 @@
 		sd_force_pio = <&sdhost>,"brcm,force-pio?";
 		sd_pio_limit = <&sdhost>,"brcm,pio-limit:0";
 		sd_debug     = <&sdhost>,"brcm,debug";
-		sdio_overclock = <&mmc>,"brcm,overclock-50:0";
+		sdio_overclock = <&mmc>,"brcm,overclock-50:0",
+				 <&mmcnr>,"brcm,overclock-50:0";
 		axiperf      = <&axiperf>,"status";
 	};
 };
--- a/arch/arm/boot/dts/bcm270x.dtsi
+++ b/arch/arm/boot/dts/bcm270x.dtsi
@@ -79,6 +79,19 @@
 			status = "disabled";
 		};
 
+		/* A clone of mmc but with non-removable set */
+		mmcnr: mmcnr@7e300000 {
+			compatible = "brcm,bcm2835-mmc", "brcm,bcm2835-sdhci";
+			reg = <0x7e300000 0x100>;
+			interrupts = <2 30>;
+			clocks = <&clocks BCM2835_CLOCK_EMMC>;
+			dmas = <&dma 11>;
+			dma-names = "rx-tx";
+			brcm,overclock-50 = <0>;
+			non-removable;
+			status = "disabled";
+		};
+
 		hvs: hvs@7e400000 {
 			/* Add alias */
 			status = "disabled";
--- a/arch/arm/boot/dts/bcm2710-rpi-3-b-plus.dts
+++ b/arch/arm/boot/dts/bcm2710-rpi-3-b-plus.dts
@@ -15,6 +15,7 @@
 	aliases {
 		serial0 = &uart1;
 		serial1 = &uart0;
+		mmc1 = &mmcnr;
 	};
 };
 
@@ -74,13 +75,11 @@
 	};
 };
 
-&mmc {
+&mmcnr {
 	pinctrl-names = "default";
 	pinctrl-0 = <&sdio_pins>;
-	non-removable;
 	bus-width = <4>;
 	status = "okay";
-	brcm,overclock-50 = <0>;
 };
 
 &firmware {
--- a/arch/arm/boot/dts/bcm2710-rpi-3-b.dts
+++ b/arch/arm/boot/dts/bcm2710-rpi-3-b.dts
@@ -15,6 +15,7 @@
 	aliases {
 		serial0 = &uart1;
 		serial1 = &uart0;
+		mmc1 = &mmcnr;
 	};
 };
 
@@ -74,13 +75,11 @@
 	};
 };
 
-&mmc {
+&mmcnr {
 	pinctrl-names = "default";
 	pinctrl-0 = <&sdio_pins>;
-	non-removable;
 	bus-width = <4>;
 	status = "okay";
-	brcm,overclock-50 = <0>;
 };
 
 &soc {
--- a/arch/arm/boot/dts/overlays/mmc-overlay.dts
+++ b/arch/arm/boot/dts/overlays/mmc-overlay.dts
@@ -33,6 +33,13 @@
 		};
 	};
 
+	fragment@3 {
+		target = <&mmcnr>;
+		__overlay__ {
+			status = "disabled";
+		};
+	};
+
 	__overrides__ {
 		overclock_50     = <&frag0>,"brcm,overclock-50:0";
 	};
--- a/arch/arm/boot/dts/overlays/sdio-overlay.dts
+++ b/arch/arm/boot/dts/overlays/sdio-overlay.dts
@@ -1,39 +1,26 @@
 /dts-v1/;
 /plugin/;
 
-/* Enable SDIO from MMC interface via GPIOs 22-27. Includes sdhost overlay. */
+/* Enable SDIO from MMC interface via various GPIO groups */
 
 /{
 	compatible = "brcm,bcm2835";
 
 	fragment@0 {
-		target = <&mmc>;
+		target = <&mmcnr>;
 		__overlay__ {
 			status = "disabled";
 		};
 	};
 
 	fragment@1 {
-		target = <&soc>;
-		__overlay__ {
-			#address-cells = <1>;
-			#size-cells = <1>;
-
-			sdio_ovl: sdio@7e300000 {
-				compatible = "brcm,bcm2835-mmc",
-					     "brcm,bcm2835-sdhci";
-				reg = <0x7e300000 0x100>;
-				interrupts = <2 30>;
-				clocks = <&clocks 28/*BCM2835_CLOCK_EMMC*/>;
-				dmas = <&dma 11>;
-				dma-names = "rx-tx";
-				brcm,overclock-50 = <0>;
-				status = "okay";
-				pinctrl-names = "default";
-				pinctrl-0 = <&sdio_ovl_pins>;
-				non-removable;
-				bus-width = <4>;
-			};
+		target = <&mmc>;
+		sdio_ovl: __overlay__ {
+			pinctrl-0 = <&sdio_ovl_pins>;
+			pinctrl-names = "default";
+			non-removable;
+			bus-width = <4>;
+			status = "okay";
 		};
 	};
 
@@ -75,7 +62,7 @@
 	fragment@6 {
 		target-path = "/aliases";
 		__overlay__ {
-			mmc1 = "/soc/sdio@7e300000";
+			mmc1 = "/soc/mmc@7e300000";
 		};
 	};