USB: EHCI: Add I2C support for SMSC hsic hub

Currently default configuration will be active
during SMSC hub enumeration. For changing the default
configuration, requires I2C support for configuring
the configurable parameters of SMSC hub like VID,PID.

Change-Id: Ie0449b166ddaae990b9a69c3a75f8059250faf0e
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
diff --git a/drivers/usb/host/ehci-msm-hsic.c b/drivers/usb/host/ehci-msm-hsic.c
index dbbfad4..1457ab2 100644
--- a/drivers/usb/host/ehci-msm-hsic.c
+++ b/drivers/usb/host/ehci-msm-hsic.c
@@ -53,7 +53,6 @@
 	struct regulator	*hsic_vddcx;
 	bool			async_int;
 	atomic_t                in_lpm;
-	struct msm_xo_voter	*xo_handle;
 	struct wake_lock	wlock;
 	int			peripheral_status_irq;
 	int			wakeup_irq;
@@ -156,79 +155,6 @@
 	return 0;
 }
 
-#define HSIC_HUB_VDD_VOL_MIN	1650000 /* uV */
-#define HSIC_HUB_VDD_VOL_MAX	1950000 /* uV */
-#define HSIC_HUB_VDD_LOAD	36000	/* uA */
-static int msm_hsic_config_hub(struct msm_hsic_hcd *mehci, int init)
-{
-	int ret = 0;
-	struct msm_hsic_host_platform_data *pdata;
-	static struct regulator *hsic_hub_reg;
-
-	pdata = mehci->dev->platform_data;
-	if (!pdata || !pdata->hub_reset)
-		return ret;
-
-	if (!init)
-		goto disable_reg;
-
-	hsic_hub_reg = devm_regulator_get(mehci->dev, "EXT_HUB_VDDIO");
-	if (IS_ERR(hsic_hub_reg)) {
-		dev_err(mehci->dev, "unable to get ext hub vddcx\n");
-		return PTR_ERR(hsic_hub_reg);
-	}
-
-	ret = gpio_request(pdata->hub_reset, "HSIC_HUB_RESET_GPIO");
-	if (ret < 0) {
-		dev_err(mehci->dev, "gpio request failed for GPIO%d\n",
-							pdata->hub_reset);
-		return ret;
-	}
-
-	ret = regulator_set_voltage(hsic_hub_reg,
-			HSIC_HUB_VDD_VOL_MIN,
-			HSIC_HUB_VDD_VOL_MAX);
-	if (ret) {
-		dev_err(mehci->dev, "unable to set the voltage"
-				"for hsic hub reg\n");
-		goto reg_set_voltage_fail;
-	}
-
-	ret = regulator_set_optimum_mode(hsic_hub_reg,
-				HSIC_HUB_VDD_LOAD);
-	if (ret < 0) {
-		pr_err("%s: Unable to set optimum mode of the regulator:"
-					"VDDCX\n", __func__);
-		goto reg_optimum_mode_fail;
-	}
-
-	ret = regulator_enable(hsic_hub_reg);
-	if (ret) {
-		dev_err(mehci->dev, "unable to enable ext hub vddcx\n");
-		goto reg_enable_fail;
-	}
-
-	gpio_direction_output(pdata->hub_reset, 0);
-	/* Hub reset should be asserted for minimum 2usec before deasserting */
-	udelay(5);
-	gpio_direction_output(pdata->hub_reset, 1);
-
-	return 0;
-
-disable_reg:
-	regulator_disable(hsic_hub_reg);
-reg_enable_fail:
-	regulator_set_optimum_mode(hsic_hub_reg, 0);
-reg_optimum_mode_fail:
-	regulator_set_voltage(hsic_hub_reg, 0,
-				HSIC_HUB_VDD_VOL_MIN);
-reg_set_voltage_fail:
-	gpio_free(pdata->hub_reset);
-
-	return ret;
-
-}
-
 static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en)
 {
 	int rc = 0;
@@ -407,7 +333,6 @@
 	struct usb_hcd *hcd = hsic_to_hcd(mehci);
 	int cnt = 0, ret;
 	u32 val;
-	struct msm_hsic_host_platform_data *pdata;
 
 	if (atomic_read(&mehci->in_lpm)) {
 		dev_dbg(mehci->dev, "%s called in lpm\n", __func__);
@@ -455,13 +380,6 @@
 	clk_disable_unprepare(mehci->phy_clk);
 	clk_disable_unprepare(mehci->cal_clk);
 	clk_disable_unprepare(mehci->ahb_clk);
-	pdata = mehci->dev->platform_data;
-	if (pdata && pdata->hub_reset) {
-		ret = msm_xo_mode_vote(mehci->xo_handle, MSM_XO_MODE_OFF);
-		if (ret)
-			pr_err("%s failed to devote for"
-				"TCXO D1 buffer%d\n", __func__, ret);
-	}
 
 	ret = regulator_set_voltage(mehci->hsic_vddcx,
 				USB_PHY_VDD_DIG_VOL_SUSP_MIN,
@@ -491,7 +409,6 @@
 	struct usb_hcd *hcd = hsic_to_hcd(mehci);
 	int cnt = 0, ret;
 	unsigned temp;
-	struct msm_hsic_host_platform_data *pdata;
 
 	if (!atomic_read(&mehci->in_lpm)) {
 		dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__);
@@ -514,13 +431,6 @@
 	if (ret < 0)
 		dev_err(mehci->dev, "unable to set vddcx voltage: min:1v max:1.3v\n");
 
-	pdata = mehci->dev->platform_data;
-	if (pdata && pdata->hub_reset) {
-		ret = msm_xo_mode_vote(mehci->xo_handle, MSM_XO_MODE_ON);
-		if (ret)
-			pr_err("%s failed to vote for"
-				"TCXO D1 buffer%d\n", __func__, ret);
-	}
 	clk_prepare_enable(mehci->core_clk);
 	clk_prepare_enable(mehci->phy_clk);
 	clk_prepare_enable(mehci->cal_clk);
@@ -868,6 +778,14 @@
 
 	dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n");
 
+	/* After parent device's probe is executed, it will be put in suspend
+	 * mode. When child device's probe is called, driver core is not
+	 * resuming parent device due to which parent will be in suspend even
+	 * though child is active. Hence resume the parent device explicitly.
+	 */
+	if (pdev->dev.parent)
+		pm_runtime_get_sync(pdev->dev.parent);
+
 	hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev,
 				dev_name(&pdev->dev));
 	if (!hcd) {
@@ -921,34 +839,10 @@
 		goto deinit_clocks;
 	}
 
-	pdata = mehci->dev->platform_data;
-	if (pdata && pdata->hub_reset) {
-		mehci->xo_handle = msm_xo_get(MSM_XO_TCXO_D1, "hsic");
-		if (IS_ERR(mehci->xo_handle)) {
-			pr_err(" %s not able to get the handle"
-				"to vote for TCXO D1 buffer\n", __func__);
-			ret = PTR_ERR(mehci->xo_handle);
-			goto deinit_vddcx;
-		}
-
-		ret = msm_xo_mode_vote(mehci->xo_handle, MSM_XO_MODE_ON);
-		if (ret) {
-			pr_err("%s failed to vote for TCXO"
-				"D1 buffer%d\n", __func__, ret);
-			goto free_xo_handle;
-		}
-	}
-
-	ret = msm_hsic_config_hub(mehci, 1);
-	if (ret) {
-		dev_err(&pdev->dev, "unable to initialize hsic hub");
-		goto free_xo_handle;
-	}
-
 	ret = msm_hsic_reset(mehci);
 	if (ret) {
 		dev_err(&pdev->dev, "unable to initialize PHY\n");
-		goto deinit_hub;
+		goto deinit_vddcx;
 	}
 
 	ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
@@ -994,6 +888,7 @@
 		dev_dbg(&pdev->dev, "mode debugfs file is"
 			"not available\n");
 
+	pdata = mehci->dev->platform_data;
 	if (pdata && pdata->bus_scale_table) {
 		mehci->bus_perf_client =
 		    msm_bus_scale_register_client(pdata->bus_scale_table);
@@ -1017,16 +912,17 @@
 	 */
 	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
+	/* Decrement the parent device's counter after probe.
+	 * As child is active, parent will not be put into
+	 * suspend mode.
+	 */
+	if (pdev->dev.parent)
+		pm_runtime_put_sync(pdev->dev.parent);
 
 	return 0;
 
 unconfig_gpio:
 	msm_hsic_config_gpios(mehci, 0);
-deinit_hub:
-	msm_hsic_config_hub(mehci, 0);
-free_xo_handle:
-	if (pdata && pdata->hub_reset)
-		msm_xo_put(mehci->xo_handle);
 deinit_vddcx:
 	msm_hsic_init_vddcx(mehci, 0);
 deinit_clocks:
@@ -1043,7 +939,6 @@
 {
 	struct usb_hcd *hcd = platform_get_drvdata(pdev);
 	struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
-	struct msm_hsic_host_platform_data *pdata;
 
 	if (mehci->peripheral_status_irq)
 		free_irq(mehci->peripheral_status_irq, mehci);
@@ -1063,10 +958,6 @@
 
 	usb_remove_hcd(hcd);
 	msm_hsic_config_gpios(mehci, 0);
-	msm_hsic_config_hub(mehci, 0);
-	pdata = mehci->dev->platform_data;
-	if (pdata && pdata->hub_reset)
-		msm_xo_put(mehci->xo_handle);
 	msm_hsic_init_vddcx(mehci, 0);
 
 	msm_hsic_init_clocks(mehci, 0);