[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230918093751.1188668-5-msp@baylibre.com>
Date: Mon, 18 Sep 2023 11:37:48 +0200
From: Markus Schneider-Pargmann <msp@...libre.com>
To: Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>
Cc: Ulf Hansson <ulf.hansson@...aro.org>,
Alexandre Mergnat <amergnat@...libre.com>,
Chun-Jie Chen <chun-jie.chen@...iatek.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>,
Tinghan Shen <tinghan.shen@...iatek.com>,
Fabien Parent <parent.f@...il.com>, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org,
Markus Schneider-Pargmann <msp@...libre.com>
Subject: [PATCH v8 4/8] soc: mediatek: pm-domains: Create bus protection operation functions
Separate the register access used for bus protection enable/disable into
their own functions. These will be used later for WAY_EN support.
Signed-off-by: Markus Schneider-Pargmann <msp@...libre.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
Reviewed-by: Alexandre Mergnat <amergnat@...libre.com>
Tested-by: Alexandre Mergnat <amergnat@...libre.com>
---
drivers/pmdomain/mediatek/mtk-pm-domains.c | 68 +++++++++++++---------
1 file changed, 39 insertions(+), 29 deletions(-)
diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c b/drivers/pmdomain/mediatek/mtk-pm-domains.c
index dbb268e96310..5b694fde7b56 100644
--- a/drivers/pmdomain/mediatek/mtk-pm-domains.c
+++ b/drivers/pmdomain/mediatek/mtk-pm-domains.c
@@ -118,26 +118,50 @@ static int scpsys_sram_disable(struct scpsys_domain *pd)
MTK_POLL_TIMEOUT);
}
+static int scpsys_bus_protect_clear(const struct scpsys_bus_prot_data *bpd,
+ struct regmap *regmap)
+{
+ u32 sta_mask = bpd->bus_prot_sta_mask;
+ u32 val;
+
+ if (bpd->flags & BUS_PROT_REG_UPDATE)
+ regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
+ else
+ regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
+
+ if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK)
+ return 0;
+
+ return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
+ val, !(val & sta_mask),
+ MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+}
+
+static int scpsys_bus_protect_set(const struct scpsys_bus_prot_data *bpd,
+ struct regmap *regmap)
+{
+ u32 sta_mask = bpd->bus_prot_sta_mask;
+ u32 val;
+
+ if (bpd->flags & BUS_PROT_REG_UPDATE)
+ regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
+ else
+ regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
+
+ return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
+ val, (val & sta_mask) == sta_mask,
+ MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+}
+
static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap)
{
int i, ret;
for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) {
- u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
- u32 sta_mask = bpd[i].bus_prot_sta_mask;
- u32 val;
-
- if (!set_clr_mask)
+ if (!bpd[i].bus_prot_set_clr_mask)
break;
- if (bpd[i].flags & BUS_PROT_REG_UPDATE)
- regmap_set_bits(regmap, bpd[i].bus_prot_set, set_clr_mask);
- else
- regmap_write(regmap, bpd[i].bus_prot_set, set_clr_mask);
-
- ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
- val, (val & sta_mask) == sta_mask,
- MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+ ret = scpsys_bus_protect_set(&bpd[i], regmap);
if (ret)
return ret;
}
@@ -162,24 +186,10 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
int i, ret;
for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
- u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
- u32 sta_mask = bpd[i].bus_prot_sta_mask;
- u32 val;
-
- if (!set_clr_mask)
- continue;
-
- if (bpd[i].flags & BUS_PROT_REG_UPDATE)
- regmap_clear_bits(regmap, bpd[i].bus_prot_clr, set_clr_mask);
- else
- regmap_write(regmap, bpd[i].bus_prot_clr, set_clr_mask);
-
- if (bpd[i].flags & BUS_PROT_IGNORE_CLR_ACK)
+ if (!bpd[i].bus_prot_set_clr_mask)
continue;
- ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
- val, !(val & sta_mask),
- MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+ ret = scpsys_bus_protect_clear(&bpd[i], regmap);
if (ret)
return ret;
}
--
2.40.1
Powered by blists - more mailing lists