Commit 928296ea authored by Matthias Brugger's avatar Matthias Brugger Committed by Matthias Brugger

soc: mediatek: pm_domains: Make bus protection generic

Bus protection is not exclusively done by calling the infracfg misc driver.
Make the calls for setting and clearing the bus protection generic so
that we can use other blocks for it as well.
Signed-off-by: default avatarMatthias Brugger <mbrugger@suse.com>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20201030113622.201188-6-enric.balletbo@collabora.comSigned-off-by: default avatarMatthias Brugger <matthias.bgg@gmail.com>
parent 916d6d71
...@@ -48,7 +48,6 @@ config MTK_SCPSYS_PM_DOMAINS ...@@ -48,7 +48,6 @@ config MTK_SCPSYS_PM_DOMAINS
bool "MediaTek SCPSYS generic power domain" bool "MediaTek SCPSYS generic power domain"
default ARCH_MEDIATEK default ARCH_MEDIATEK
depends on PM depends on PM
depends on MTK_INFRACFG
select PM_GENERIC_DOMAINS select PM_GENERIC_DOMAINS
select REGMAP select REGMAP
help help
......
...@@ -12,11 +12,6 @@ ...@@ -12,11 +12,6 @@
#define MTK_POLL_DELAY_US 10 #define MTK_POLL_DELAY_US 10
#define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ)) #define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
#define INFRA_TOPAXI_PROTECTEN 0x0220
#define INFRA_TOPAXI_PROTECTSTA1 0x0228
#define INFRA_TOPAXI_PROTECTEN_SET 0x0260
#define INFRA_TOPAXI_PROTECTEN_CLR 0x0264
/** /**
* mtk_infracfg_set_bus_protection - enable bus protection * mtk_infracfg_set_bus_protection - enable bus protection
* @infracfg: The infracfg regmap * @infracfg: The infracfg regmap
......
...@@ -86,18 +86,24 @@ static int scpsys_sram_disable(struct scpsys_domain *pd) ...@@ -86,18 +86,24 @@ static int scpsys_sram_disable(struct scpsys_domain *pd)
MTK_POLL_TIMEOUT); MTK_POLL_TIMEOUT);
} }
static int scpsys_bus_protect_enable(struct scpsys_domain *pd) static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap)
{ {
const struct scpsys_bus_prot_data *bpd = pd->data->bp_infracfg;
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++) {
if (!bpd[i].bus_prot_mask) u32 val, mask = bpd[i].bus_prot_mask;
if (!mask)
break; break;
ret = mtk_infracfg_set_bus_protection(pd->infracfg, if (bpd[i].bus_prot_reg_update)
bpd[i].bus_prot_mask, regmap_set_bits(regmap, bpd[i].bus_prot_set, mask);
bpd[i].bus_prot_reg_update); else
regmap_write(regmap, INFRA_TOPAXI_PROTECTEN_SET, mask);
ret = regmap_read_poll_timeout(regmap, INFRA_TOPAXI_PROTECTSTA1,
val, (val & mask) == mask,
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -105,18 +111,34 @@ static int scpsys_bus_protect_enable(struct scpsys_domain *pd) ...@@ -105,18 +111,34 @@ static int scpsys_bus_protect_enable(struct scpsys_domain *pd)
return 0; return 0;
} }
static int scpsys_bus_protect_disable(struct scpsys_domain *pd) static int scpsys_bus_protect_enable(struct scpsys_domain *pd)
{
int ret;
ret = _scpsys_bus_protect_enable(pd->data->bp_infracfg, pd->infracfg);
return ret;
}
static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
struct regmap *regmap)
{ {
const struct scpsys_bus_prot_data *bpd = pd->data->bp_infracfg;
int i, ret; int i, ret;
for (i = SPM_MAX_BUS_PROT_DATA; i > 0; i--) { for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
if (!bpd[i].bus_prot_mask) u32 val, mask = bpd[i].bus_prot_mask;
if (!mask)
continue; continue;
ret = mtk_infracfg_clear_bus_protection(pd->infracfg, if (bpd[i].bus_prot_reg_update)
bpd[i].bus_prot_mask, regmap_clear_bits(regmap, bpd[i].bus_prot_clr, mask);
bpd[i].bus_prot_reg_update); else
regmap_write(regmap, INFRA_TOPAXI_PROTECTEN_CLR, mask);
ret = regmap_read_poll_timeout(regmap, INFRA_TOPAXI_PROTECTSTA1,
val, !(val & mask),
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -124,6 +146,15 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd) ...@@ -124,6 +146,15 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd)
return 0; return 0;
} }
static int scpsys_bus_protect_disable(struct scpsys_domain *pd)
{
int ret;
ret = _scpsys_bus_protect_disable(pd->data->bp_infracfg, pd->infracfg);
return ret;
}
static int scpsys_power_on(struct generic_pm_domain *genpd) static int scpsys_power_on(struct generic_pm_domain *genpd)
{ {
struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd);
......
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
#define MT7622_TOP_AXI_PROT_EN_WB (BIT(2) | BIT(6) | \ #define MT7622_TOP_AXI_PROT_EN_WB (BIT(2) | BIT(6) | \
BIT(7) | BIT(8)) BIT(7) | BIT(8))
#define INFRA_TOPAXI_PROTECTEN 0x0220
#define INFRA_TOPAXI_PROTECTSTA1 0x0228
#define INFRA_TOPAXI_PROTECTEN_SET 0x0260
#define INFRA_TOPAXI_PROTECTEN_CLR 0x0264
#define REG_INFRA_MISC 0xf00 #define REG_INFRA_MISC 0xf00
#define F_DDR_4GB_SUPPORT_EN BIT(13) #define F_DDR_4GB_SUPPORT_EN BIT(13)
......
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