[PATCH 3/6] soc: imx: gpcv2: align with upstream Linux driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>

Bring the code closer to the upstream Linux driver to make it
better comparable to that code.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 drivers/soc/imx/gpcv2.c | 109 +++++++++++-----------------------------
 1 file changed, 29 insertions(+), 80 deletions(-)

diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
index 9150ed95da..3b1c715e5b 100644
--- a/drivers/soc/imx/gpcv2.c
+++ b/drivers/soc/imx/gpcv2.c
@@ -132,31 +132,21 @@ to_imx_pgc_domain(struct generic_pm_domain *genpd)
 static int imx_pgc_power_up(struct generic_pm_domain *genpd)
 {
 	struct imx_pgc_domain *domain = to_imx_pgc_domain(genpd);
-	bool on = true;
-	unsigned int offset = on ?
-		GPC_PU_PGC_SW_PUP_REQ : GPC_PU_PGC_SW_PDN_REQ;
-	const bool enable_power_control = !on;
-	const bool has_regulator = !IS_ERR(domain->regulator);
 	u32 reg_val;
-	int ret = 0;
+	int ret;
 
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, domain->bits.map);
 
-	if (has_regulator && on) {
+	if (!IS_ERR(domain->regulator)) {
 		ret = regulator_enable(domain->regulator);
 		if (ret) {
 			dev_err(domain->dev, "failed to enable regulator\n");
-			goto unmap;
+			goto out_unmap;
 		}
 	}
 
-	if (enable_power_control) {
-		regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
-				   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
-	}
-
-	regmap_update_bits(domain->regmap, offset,
+	regmap_update_bits(domain->regmap, GPC_PU_PGC_SW_PUP_REQ,
 			   domain->bits.pxx, domain->bits.pxx);
 
 	/*
@@ -164,71 +154,41 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)
 	 * for PUP_REQ/PDN_REQ bit to be cleared
 	 */
 	ret = regmap_read_poll_timeout(domain->regmap,
-				       offset, reg_val,
+				       GPC_PU_PGC_SW_PUP_REQ, reg_val,
 				       !(reg_val & domain->bits.pxx),
 				       MSECOND);
 	if (ret < 0) {
 		dev_err(domain->dev, "falied to command PGC\n");
-		/*
-		 * If we were in a process of enabling a
-		 * domain and failed we might as well disable
-		 * the regulator we just enabled. And if it
-		 * was the opposite situation and we failed to
-		 * power down -- keep the regulator on
-		 */
-		on = !on;
+		goto out_regulator_disable;
 	}
 
-	if (enable_power_control) {
-		regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
-				   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
-	}
+	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
+			   domain->bits.map, 0);
 
-	if (has_regulator && !on) {
-		int err;
+	return 0;
 
-		err = regulator_disable(domain->regulator);
-		if (err)
-			dev_err(domain->dev,
-				"failed to disable regulator: %d\n", ret);
-		/* Preserve earlier error code */
-		ret = ret ?: err;
-	}
-unmap:
+out_regulator_disable:
+	if (!IS_ERR(domain->regulator))
+		regulator_disable(domain->regulator);
+out_unmap:
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, 0);
-
 	return ret;
 }
 
 static int imx_pgc_power_down(struct generic_pm_domain *genpd)
 {
 	struct imx_pgc_domain *domain = to_imx_pgc_domain(genpd);
-	bool on = false;
-	unsigned int offset = on ?
-		GPC_PU_PGC_SW_PUP_REQ : GPC_PU_PGC_SW_PDN_REQ;
-	const bool enable_power_control = !on;
-	const bool has_regulator = !IS_ERR(domain->regulator);
 	u32 reg_val;
-	int ret = 0;
+	int ret;
 
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, domain->bits.map);
 
-	if (has_regulator && on) {
-		ret = regulator_enable(domain->regulator);
-		if (ret) {
-			dev_err(domain->dev, "failed to enable regulator\n");
-			goto unmap;
-		}
-	}
-
-	if (enable_power_control) {
-		regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
-				   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
-	}
+	regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
+			   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
 
-	regmap_update_bits(domain->regmap, offset,
+	regmap_update_bits(domain->regmap, GPC_PU_PGC_SW_PDN_REQ,
 			   domain->bits.pxx, domain->bits.pxx);
 
 	/*
@@ -236,37 +196,26 @@ static int imx_pgc_power_down(struct generic_pm_domain *genpd)
 	 * for PUP_REQ/PDN_REQ bit to be cleared
 	 */
 	ret = regmap_read_poll_timeout(domain->regmap,
-				       offset, reg_val,
+				       GPC_PU_PGC_SW_PDN_REQ, reg_val,
 				       !(reg_val & domain->bits.pxx),
 				       MSECOND);
 	if (ret < 0) {
 		dev_err(domain->dev, "falied to command PGC\n");
-		/*
-		 * If we were in a process of enabling a
-		 * domain and failed we might as well disable
-		 * the regulator we just enabled. And if it
-		 * was the opposite situation and we failed to
-		 * power down -- keep the regulator on
-		 */
-		on = !on;
+		goto out_regulator_disable;
 	}
 
-	if (enable_power_control) {
-		regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
-				   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
-	}
+	regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
+			   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
 
-	if (has_regulator && !on) {
-		int err;
+	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
+			   domain->bits.map, 0);
+
+	return 0;
+
+out_regulator_disable:
+	if (!IS_ERR(domain->regulator))
+		regulator_disable(domain->regulator);
 
-		err = regulator_disable(domain->regulator);
-		if (err)
-			dev_err(domain->dev,
-				"failed to disable regulator: %d\n", ret);
-		/* Preserve earlier error code */
-		ret = ret ?: err;
-	}
-unmap:
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, 0);
 
-- 
2.30.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux