clk: qcom: mdss: update resource management in PLL driver

Remove mutex and ref count variables that synchronize the
resource enable and disable calls since the regulator
and clock drivers take care of maintaining the ref
count for each resource. Also, remove resource enable
and disable calls from mux_set_rate/mux_get_rate/clk_enable
context of the DSI branch clocks to avoid warnings.

Change-Id: Ieb32141156afcce008b3555af476c20f888f064b
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
diff --git a/drivers/clk/qcom/mdss/mdss-dsi-pll-28hpm.c b/drivers/clk/qcom/mdss/mdss-dsi-pll-28hpm.c
index 18dca4f..03c1107 100644
--- a/drivers/clk/qcom/mdss/mdss-dsi-pll-28hpm.c
+++ b/drivers/clk/qcom/mdss/mdss-dsi-pll-28hpm.c
@@ -94,20 +94,12 @@
 
 int set_byte_mux_sel(struct mux_clk *clk, int sel)
 {
-	int rc;
 	struct mdss_pll_resources *dsi_pll_res = clk->priv;
 
-	rc = mdss_pll_resource_enable(dsi_pll_res, true);
-	if (rc) {
-		pr_err("Failed to enable mdss dsi pll resources\n");
-		return rc;
-	}
-
 	pr_debug("byte mux set to %s mode\n", sel ? "indirect" : "direct");
 	MDSS_PLL_REG_W(dsi_pll_res->pll_base,
 				DSI_PHY_PLL_UNIPHY_PLL_VREG_CFG, (sel << 1));
 
-	mdss_pll_resource_enable(dsi_pll_res, false);
 	return 0;
 }
 
@@ -147,6 +139,13 @@
 {
 	struct mux_clk *mux = to_mux_clk(c);
 	int i, rc, sel = 0;
+	struct mdss_pll_resources *dsi_pll_res = mux->priv;
+
+	rc = mdss_pll_resource_enable(dsi_pll_res, true);
+	if (rc) {
+		pr_err("Failed to enable mdss dsi pll resources\n");
+		return rc;
+	}
 
 	for (i = 0; i < mux->num_parents; i++)
 		if (mux->parents[i].src == c->parent) {
@@ -164,6 +163,7 @@
 	rc = mux->ops->set_mux_sel(mux, sel);
 
 error:
+	mdss_pll_resource_enable(dsi_pll_res, false);
 	return rc;
 }
 
diff --git a/drivers/clk/qcom/mdss/mdss-pll-util.c b/drivers/clk/qcom/mdss/mdss-pll-util.c
index 11515ad..03b5b61 100644
--- a/drivers/clk/qcom/mdss/mdss-pll-util.c
+++ b/drivers/clk/qcom/mdss/mdss-pll-util.c
@@ -75,11 +75,6 @@
 	struct dss_module_power *mp = &pll_res->mp;
 
 	if (enable) {
-		if (pll_res->resource_refcount) {
-			pll_res->resource_refcount++;
-			return 0;
-		}
-
 		rc = msm_dss_enable_vreg(mp->vreg_config, mp->num_vreg, enable);
 		if (rc) {
 			pr_err("Failed to enable vregs rc=%d\n", rc);
@@ -97,21 +92,10 @@
 			pr_err("clock enable failed rc:%d\n", rc);
 			goto clk_err;
 		}
-		pll_res->resource_refcount++;
 	} else {
-		if (pll_res->resource_refcount) {
-			pll_res->resource_refcount--;
-		} else {
-			pr_err("Trying to disable the resources without enabling them\n");
-			return -EINVAL;
-		}
+		msm_dss_enable_clk(mp->clk_config, mp->num_clk, enable);
 
-		if (!pll_res->resource_refcount) {
-			msm_dss_enable_clk(mp->clk_config, mp->num_clk, enable);
-
-			msm_dss_enable_vreg(mp->vreg_config, mp->num_vreg,
-									enable);
-		}
+		msm_dss_enable_vreg(mp->vreg_config, mp->num_vreg, enable);
 	}
 
 	return rc;
diff --git a/drivers/clk/qcom/mdss/mdss-pll.c b/drivers/clk/qcom/mdss/mdss-pll.c
index e92d1fa..0e51bbc 100644
--- a/drivers/clk/qcom/mdss/mdss-pll.c
+++ b/drivers/clk/qcom/mdss/mdss-pll.c
@@ -40,18 +40,16 @@
 	 * 1 refcount.
 	 */
 	if (pll_res->handoff_resources &&
-		(!enable || (enable && pll_res->resource_refcount == 1))) {
+		(!enable || (enable & pll_res->resource_enable))) {
 		pr_debug("Do not turn on/off pll resources during handoff case\n");
 		return rc;
 	}
 
-	mutex_lock(&pll_res->resource_lock);
 	rc = mdss_pll_util_resource_enable(pll_res, enable);
 	if (rc)
 		pr_err("Resource update failed rc=%d\n", rc);
 	else
 		pll_res->resource_enable = enable;
-	mutex_unlock(&pll_res->resource_lock);
 
 	return rc;
 }
@@ -191,9 +189,6 @@
 	}
 	platform_set_drvdata(pdev, pll_res);
 
-	mutex_init(&pll_res->resource_lock);
-	pll_res->resource_refcount = 0;
-
 	pll_base_reg = platform_get_resource_byname(pdev,
 						IORESOURCE_MEM, "pll_base");
 	if (!pll_base_reg) {
@@ -259,7 +254,6 @@
 res_parse_error:
 	iounmap(pll_res->pll_base);
 io_error:
-	mutex_destroy(&pll_res->resource_lock);
 	devm_kfree(&pdev->dev, pll_res);
 error:
 	return rc;
@@ -280,7 +274,6 @@
 		iounmap(pll_res->phy_base);
 	mdss_pll_resource_release(pdev, pll_res);
 	iounmap(pll_res->pll_base);
-	mutex_destroy(&pll_res->resource_lock);
 	devm_kfree(&pdev->dev, pll_res);
 	return 0;
 }
diff --git a/drivers/clk/qcom/mdss/mdss-pll.h b/drivers/clk/qcom/mdss/mdss-pll.h
index 5ae401a..27b7b4f 100644
--- a/drivers/clk/qcom/mdss/mdss-pll.h
+++ b/drivers/clk/qcom/mdss/mdss-pll.h
@@ -64,15 +64,6 @@
 	 * feature is disabled.
 	 */
 	bool		handoff_resources;
-
-	/*
-	 * Keep reference count of pll resource client to avoid releasing them
-	 * before all clients are finished with their tasks
-	 */
-	unsigned int	resource_refcount;
-
-	/* Lock status to provide updated resource status to all clients */
-	struct mutex	resource_lock;
 };
 
 int mdss_pll_resource_enable(struct mdss_pll_resources *pll_res, bool enable);