platform: msm_shared: Add support for hs only mode

Add support to program the usb controller to operate in high speed
only mode.

Change-Id: I2ce7af4fa2f14be75ab21fa2f91300d683f58ebf
diff --git a/platform/msm_shared/include/qmp_phy.h b/platform/msm_shared/include/qmp_phy.h
index ab669d7..4558abe 100644
--- a/platform/msm_shared/include/qmp_phy.h
+++ b/platform/msm_shared/include/qmp_phy.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -87,5 +87,6 @@
 
 void usb30_qmp_phy_reset(void);
 void usb30_qmp_phy_init(void);
+bool use_hsonly_mode();
 
 #endif
diff --git a/platform/msm_shared/qmp_usb30_phy.c b/platform/msm_shared/qmp_usb30_phy.c
index 821c0b2..a2c21cf 100644
--- a/platform/msm_shared/qmp_usb30_phy.c
+++ b/platform/msm_shared/qmp_usb30_phy.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -45,6 +45,8 @@
 #define QMP_PHY_MAX_TIMEOUT            1000
 #define PHYSTATUS                      BIT(6)
 
+static bool hsonly_mode;
+
 struct qmp_reg qmp_settings[] =
 {
 	{0xAC, 0x14}, /* QSERDES_COM_SYSCLK_EN_SEL */
@@ -301,8 +303,6 @@
 		writel(0x03, QMP_PHY_BASE + PCIE_USB3_PHY_START);
 	}
 
-	clock_bumpup_pipe3_clk();
-
 	if (rev_id >= 0x20000000)
 		phy_status = 0x77c;
 	else
@@ -314,8 +314,16 @@
 		timeout--;
 		if (!timeout)
 		{
-			dprintf(CRITICAL, "QMP phy initialization failed\n");
+			dprintf(CRITICAL, "QMP phy initialization failed, fallback to HighSpeed only mode\n");
+			hsonly_mode = true;
 			return;
 		}
 	}
+
+	clock_bumpup_pipe3_clk();
+}
+
+bool use_hsonly_mode()
+{
+	return hsonly_mode;
 }
diff --git a/platform/msm_shared/usb30_dwc_hw.c b/platform/msm_shared/usb30_dwc_hw.c
index 3327bca..7b69bbb 100644
--- a/platform/msm_shared/usb30_dwc_hw.c
+++ b/platform/msm_shared/usb30_dwc_hw.c
@@ -41,6 +41,7 @@
 #include <usb30_dwc_hw.h>
 #include <smem.h>
 #include <board.h>
+#include <qmp_phy.h>
 
 extern char* ss_link_state_lookup[20];
 extern char* hs_link_state_lookup[20];
@@ -512,17 +513,15 @@
 void dwc_phy_digital_reset(dwc_dev_t *dev)
 {
 	REG_WRITE_FIELDI(dev, GUSB2PHYCFG,  0, PHYSOFTRST, 1);
-#ifndef USE_HSONLY_MODE
-	REG_WRITE_FIELDI(dev, GUSB3PIPECTL, 0, PHYSOFTRST, 1);
-#endif
+	if (!use_hsonly_mode())
+		REG_WRITE_FIELDI(dev, GUSB3PIPECTL, 0, PHYSOFTRST, 1);
 
 	/* per HPG */
 	udelay(100);
 
 	REG_WRITE_FIELDI(dev, GUSB2PHYCFG,  0, PHYSOFTRST, 0);
-#ifndef USE_HSONLY_MODE
-	REG_WRITE_FIELDI(dev, GUSB3PIPECTL, 0, PHYSOFTRST, 0);
-#endif
+	if (!use_hsonly_mode())
+		REG_WRITE_FIELDI(dev, GUSB3PIPECTL, 0, PHYSOFTRST, 0);
 
 	/* per HPG */
 	udelay(100);
diff --git a/platform/msm_shared/usb30_udc.c b/platform/msm_shared/usb30_udc.c
index 0e47c81..0e5e1b0 100644
--- a/platform/msm_shared/usb30_udc.c
+++ b/platform/msm_shared/usb30_udc.c
@@ -46,6 +46,7 @@
 #include <smem.h>
 #include <board.h>
 #include <platform/timer.h>
+#include <qmp_phy.h>
 
 //#define DEBUG_USB
 
@@ -232,10 +233,6 @@
 	/* 2. Put controller in reset */
 	dwc_reset(dwc, 1);
 
-	/* HS only mode support */
-#ifdef USE_HSONLY_MODE
-	usb_wrapper_hsonly_mode(wrapper);
-#endif
 
 	/* Steps 3 - 7 must be done while dwc is in reset condition */
 
@@ -243,9 +240,8 @@
 	phy_reset(wrapper, dev_info);
 
 	/* 4. SS phy config */
-#ifndef USE_HSONLY_MODE
-	usb_wrapper_ss_phy_configure(wrapper);
-#endif
+	if (!use_hsonly_mode())
+		usb_wrapper_ss_phy_configure(wrapper);
 
 	/* 5. HS phy init */
 	usb_wrapper_hs_phy_init(wrapper);
@@ -266,6 +262,10 @@
 	if (dev_info->t_usb_if->phy_init)
 		dev_info->t_usb_if->phy_init();
 
+	/* HS only mode support */
+	if (use_hsonly_mode())
+		usb_wrapper_hsonly_mode(wrapper);
+
 	/* 10. */
 	usb_wrapper_workaround_10(wrapper);
 
diff --git a/platform/msm_shared/usb30_wrapper.c b/platform/msm_shared/usb30_wrapper.c
index 6cec193..b6ca7ea 100644
--- a/platform/msm_shared/usb30_wrapper.c
+++ b/platform/msm_shared/usb30_wrapper.c
@@ -49,6 +49,7 @@
 #include <platform/clock.h>
 #include <usb30_wrapper.h>
 #include <usb30_wrapper_hwio.h>
+#include <qmp_phy.h>
 
 
 /* Configure DBM mode: by-pass or DBM */
@@ -166,9 +167,8 @@
 	REG_WRITE_FIELD(dev, HS_PHY_CTRL, SW_SESSVLD_SEL, 0x1);
 
 	/* Indicate power present to SS phy */
-#ifndef USE_HSONLY_MODE
-	REG_WRITE_FIELD(dev, SS_PHY_CTRL, LANE0_PWR_PRESENT, 0x1);
-#endif
+	if (!use_hsonly_mode())
+		REG_WRITE_FIELD(dev, SS_PHY_CTRL, LANE0_PWR_PRESENT, 0x1);
 }
 
 /* API to read SS PHY registers */