Commit 2ec81379 authored by Markus Schneider-Pargmann's avatar Markus Schneider-Pargmann Committed by Ulf Hansson

pmdomain: mediatek: 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: default avatarMarkus Schneider-Pargmann <msp@baylibre.com>
Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: default avatarAlexandre Mergnat <amergnat@baylibre.com>
Tested-by: default avatarAlexandre Mergnat <amergnat@baylibre.com>
Link: https://lore.kernel.org/r/20230918093751.1188668-5-msp@baylibre.comSigned-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent ae442ba8
...@@ -118,26 +118,50 @@ static int scpsys_sram_disable(struct scpsys_domain *pd) ...@@ -118,26 +118,50 @@ static int scpsys_sram_disable(struct scpsys_domain *pd)
MTK_POLL_TIMEOUT); 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) static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap)
{ {
int i, ret; int i, ret;
for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) { for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) {
u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask; if (!bpd[i].bus_prot_set_clr_mask)
u32 sta_mask = bpd[i].bus_prot_sta_mask;
u32 val;
if (!set_clr_mask)
break; break;
if (bpd[i].flags & BUS_PROT_REG_UPDATE) ret = scpsys_bus_protect_set(&bpd[i], regmap);
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);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -162,24 +186,10 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd, ...@@ -162,24 +186,10 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
int i, ret; int i, ret;
for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) { for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask; if (!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)
continue; continue;
ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta, ret = scpsys_bus_protect_clear(&bpd[i], regmap);
val, !(val & sta_mask),
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
if (ret) if (ret)
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment