mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/6] soc: imx: gpcv2: switch to regmap
Date: Wed, 31 Aug 2022 14:52:43 +0200	[thread overview]
Message-ID: <20220831125248.2105893-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20220831125248.2105893-1-s.hauer@pengutronix.de>

From: Ahmad Fatoum <a.fatoum@pengutronix.de>

The Kernel driver uses regmap, so switch to regmap as well to get the
code closer to the kernel code.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/soc/imx/gpcv2.c | 55 ++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
index a0e78ce55e..4e2a687634 100644
--- a/drivers/soc/imx/gpcv2.c
+++ b/drivers/soc/imx/gpcv2.c
@@ -10,12 +10,14 @@
 
 #include <of_device.h>
 #include <common.h>
+#include <regmap.h>
 #include <clock.h>
 #include <abort.h>
 #include <malloc.h>
 #include <io.h>
 #include <init.h>
 #include <linux/iopoll.h>
+#include <linux/sizes.h>
 
 #include <pm_domain.h>
 #include <regulator.h>
@@ -102,7 +104,7 @@
 
 struct imx_pgc_domain {
 	struct generic_pm_domain genpd;
-	void __iomem *base;
+	struct regmap *regmap;
 	struct regulator *regulator;
 
 	unsigned int pgc;
@@ -131,12 +133,11 @@ static int imx_gpc_pu_pgc_sw_pxx_req(struct generic_pm_domain *genpd,
 		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;
-	unsigned int mapping, ctrl = 0, pxx;
 
-	mapping = readl(domain->base + GPC_PGC_CPU_MAPPING);
-	mapping |= domain->bits.map;
-	writel(mapping, domain->base + GPC_PGC_CPU_MAPPING);
+	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
+			   domain->bits.map, domain->bits.map);
 
 	if (has_regulator && on) {
 		ret = regulator_enable(domain->regulator);
@@ -147,21 +148,21 @@ static int imx_gpc_pu_pgc_sw_pxx_req(struct generic_pm_domain *genpd,
 	}
 
 	if (enable_power_control) {
-		ctrl = readl(domain->base + GPC_PGC_CTRL(domain->pgc));
-		ctrl |= GPC_PGC_CTRL_PCR;
-		writel(ctrl, domain->base + GPC_PGC_CTRL(domain->pgc));
+		regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
+				   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
 	}
 
-	pxx = readl(domain->base + offset);
-	pxx |= domain->bits.pxx;
-	writel(pxx, domain->base + offset);
+	regmap_update_bits(domain->regmap, offset,
+			   domain->bits.pxx, domain->bits.pxx);
 
 	/*
 	 * As per "5.5.9.4 Example Code 4" in IMX7DRM.pdf wait
 	 * for PUP_REQ/PDN_REQ bit to be cleared
 	 */
-	ret = readl_poll_timeout(domain->base + offset, pxx,
-				 !(pxx & domain->bits.pxx), MSECOND);
+	ret = regmap_read_poll_timeout(domain->regmap,
+				       offset, reg_val,
+				       !(reg_val & domain->bits.pxx),
+				       MSECOND);
 	if (ret < 0) {
 		dev_err(domain->dev, "falied to command PGC\n");
 		/*
@@ -175,8 +176,8 @@ static int imx_gpc_pu_pgc_sw_pxx_req(struct generic_pm_domain *genpd,
 	}
 
 	if (enable_power_control) {
-		ctrl &= ~GPC_PGC_CTRL_PCR;
-		writel(ctrl, domain->base + GPC_PGC_CTRL(domain->pgc));
+		regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc),
+				   GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR);
 	}
 
 	if (has_regulator && !on) {
@@ -190,8 +191,8 @@ static int imx_gpc_pu_pgc_sw_pxx_req(struct generic_pm_domain *genpd,
 		ret = ret ?: err;
 	}
 unmap:
-	mapping &= ~domain->bits.map;
-	writel(mapping, domain->base + GPC_PGC_CPU_MAPPING);
+	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
+			   domain->bits.map, 0);
 
 	return ret;
 }
@@ -425,10 +426,18 @@ coredevice_platform_driver(imx_pgc_domain_driver);
 
 static int imx_gpcv2_probe(struct device_d *dev)
 {
-	static const struct imx_pgc_domain_data *domain_data;
+	const struct imx_pgc_domain_data *domain_data =
+			of_device_get_match_data(dev);
+
+	struct regmap_config regmap_config = {
+		.reg_bits	= 32,
+		.val_bits	= 32,
+		.reg_stride	= 4,
+		.max_register   = SZ_4K,
+	};
 	struct device_node *pgc_np, *np;
 	struct resource *res;
-	void __iomem *base;
+	struct regmap *regmap;
 	int ret, pass = 0;
 
 	pgc_np = of_get_child_by_name(dev->device_node, "pgc");
@@ -441,9 +450,9 @@ static int imx_gpcv2_probe(struct device_d *dev)
 	if (IS_ERR(res))
 		return PTR_ERR(res);
 
-	base = IOMEM(res->start);
-
-	domain_data = of_device_get_match_data(dev);
+	regmap = regmap_init_mmio(dev, IOMEM(res->start), &regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "failed to init regmap\n");
 
 	/*
 	 * Run two passes for the registration of the PGC domain platform
@@ -477,7 +486,7 @@ again:
 
 		domain = xmemdup(&domain_data->domains[domain_index],
 				 sizeof(domain_data->domains[domain_index]));
-		domain->base = base;
+		domain->regmap = regmap;
 		domain->genpd.power_on = imx_gpc_pu_pgc_sw_pup_req;
 		domain->genpd.power_off = imx_gpc_pu_pgc_sw_pdn_req;
 
-- 
2.30.2




  reply	other threads:[~2022-08-31 12:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 12:52 [PATCH 0/6] Add power domain support for i.MX8MM, i.MX8MN and i.MX8MP Sascha Hauer
2022-08-31 12:52 ` Sascha Hauer [this message]
2022-08-31 12:52 ` [PATCH 2/6] soc: imx: gpcv2: split power_up/power_off Sascha Hauer
2022-08-31 12:52 ` [PATCH 3/6] soc: imx: gpcv2: align with upstream Linux driver Sascha Hauer
2022-08-31 12:52 ` [PATCH 4/6] soc: imx: gpcv2: extend for i.MX8M Mini/Nano/Plus support Sascha Hauer
2022-08-31 12:52 ` [PATCH 5/6] Revert "ARM: i.MX8MM: assume USBOTG power domains to be powered" Sascha Hauer
2022-08-31 18:27   ` Ahmad Fatoum
2022-08-31 12:52 ` [PATCH 6/6] Revert "ARM: i.MX8MN: " Sascha Hauer
2022-08-31 18:28   ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220831125248.2105893-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox