From bcf363f5cd91ed0818005c10e75af14fd3160a14 Mon Sep 17 00:00:00 2001
From: Peter Robinson <pbrobinson@gmail.com>
Date: Tue, 18 Jul 2017 19:43:31 +0100
Subject: [PATCH] Add QCom patch to fix USB on Dragonboard

---
 kernel.spec                                   |  4 +
 ...rce-host-mode-for-USB-on-apq8016-sbc.patch | 93 +++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 qcom-Force-host-mode-for-USB-on-apq8016-sbc.patch

diff --git a/kernel.spec b/kernel.spec
index d8c0d8a45..b1ecb1dc6 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -616,6 +616,9 @@ Patch311: arm-tegra-fix-gpu-iommu.patch
 # https://www.spinics.net/lists/linux-arm-msm/msg28203.html
 Patch312: qcom-display-iommu.patch
 
+# https://patchwork.kernel.org/patch/9839803/
+Patch313: qcom-Force-host-mode-for-USB-on-apq8016-sbc.patch
+
 # 400 - IBM (ppc/s390x) patches
 
 # 500 - Temp fixes/CVEs etc
@@ -2190,6 +2193,7 @@ fi
 * Tue Jul 18 2017 Peter Robinson <pbrobinson@fedoraproject.org>
 - Add fix for Tegra GPU display with IOMMU
 - Add QCom IOMMU for Dragonboard display
+- Add QCom patch to fix USB on Dragonboard
 
 * Tue Jul 18 2017 Laura Abbott <labbott@fedoraproject.org> - 4.13.0-0.rc1.git1.1
 - Linux v4.13-rc1-24-gcb8c65ccff7f
diff --git a/qcom-Force-host-mode-for-USB-on-apq8016-sbc.patch b/qcom-Force-host-mode-for-USB-on-apq8016-sbc.patch
new file mode 100644
index 000000000..4932539a3
--- /dev/null
+++ b/qcom-Force-host-mode-for-USB-on-apq8016-sbc.patch
@@ -0,0 +1,93 @@
+From patchwork Fri Jul 14 02:20:42 2017
+Content-Type: text/plain; charset="utf-8"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [v2] arm64: dts: qcom: Force host mode for USB on apq8016-sbc
+From: Stephen Boyd <sboyd@codeaurora.org>
+X-Patchwork-Id: 9839803
+Message-Id: <20170714022042.13886-1-sboyd@codeaurora.org>
+To: Andy Gross <andy.gross@linaro.org>
+Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
+ linux-arm-kernel@lists.infradead.org, Rob Clark <robdclark@gmail.com>
+Date: Thu, 13 Jul 2017 19:20:42 -0700
+
+Commit ed75d6a96905 ("arm64: dts: qcom: Collapse usb support into
+one node") breaks host mode support on apq8016-sbc boards. This
+is because the mux driver (tc7usb40mu) hasn't been merged.
+Without that driver, we can't toggle the GPIO going to the mux to
+route out the D+/D- lines to the USB hub that's on the board.
+
+One solution would be to totally revert this change, but that
+opens us up to other problems when two USB drivers are operating
+the same hardware block at the same time. Let's modify the DT so
+that the USB controller is always in host mode and connected to
+the hub so that things like USB keyboards and mouses work. This
+is the mode that most people prefer anyway with these devices. We
+also delete the usb-switch node because the binding was never
+accepted upstream.
+
+In the future, we can add muxing support and then update the DT
+to support both modes at runtime. Patches to support this are
+already on the mailing list.
+
+Fixes: ed75d6a96905 ("arm64: dts: qcom: Collapse usb support into one node")
+Reported-by: Rob Clark <robdclark@gmail.com>
+Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
+---
+
+I noticed that I accidently removed the vbus notifier part of the phy.
+Without it, we'll change settings that shouldn't changed. The thing
+that we don't have is the ID pin on this board, not the vbus. That's
+the only difference from v1.
+
+ arch/arm64/boot/dts/qcom/apq8016-sbc-pmic-pins.dtsi |  1 +
+ arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi           | 13 ++++---------
+ 2 files changed, 5 insertions(+), 9 deletions(-)
+
+diff --git a/arch/arm64/boot/dts/qcom/apq8016-sbc-pmic-pins.dtsi b/arch/arm64/boot/dts/qcom/apq8016-sbc-pmic-pins.dtsi
+index d94640812194..790b7775b901 100644
+--- a/arch/arm64/boot/dts/qcom/apq8016-sbc-pmic-pins.dtsi
++++ b/arch/arm64/boot/dts/qcom/apq8016-sbc-pmic-pins.dtsi
+@@ -17,6 +17,7 @@
+ 			function = PMIC_GPIO_FUNC_NORMAL;
+ 			power-source = <PM8916_GPIO_VPH>;
+ 			input-disable;
++			output-high;
+ 		};
+ 	};
+ 
+diff --git a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
+index bd310ac1967a..bb9e29e6b164 100644
+--- a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
++++ b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
+@@ -213,11 +213,14 @@
+ 		};
+ 
+ 		usb@78d9000 {
+-			extcon = <&usb_id>, <&usb_id>;
++			extcon = <&usb_id>;
+ 			status = "okay";
+ 			adp-disable;
+ 			hnp-disable;
+ 			srp-disable;
++			dr_mode = "host";
++			pinctrl-names = "default";
++			pinctrl-0 = <&usb_sw_sel_pm>;
+ 			ulpi {
+ 				phy {
+ 					v1p8-supply = <&pm8916_l7>;
+@@ -342,14 +345,6 @@
+ 		pinctrl-0 = <&usb_id_default>;
+ 	};
+ 
+-	usb-switch {
+-		compatible = "toshiba,tc7usb40mu";
+-		switch-gpios = <&pm8916_gpios 4 GPIO_ACTIVE_HIGH>;
+-		extcon = <&usb_id>;
+-		pinctrl-names = "default";
+-		pinctrl-0 = <&usb_sw_sel_pm>;
+-	};
+-
+ 	hdmi-out {
+ 		compatible = "hdmi-connector";
+ 		type = "a";