Re: [PATCH 2/2] soc: mediatek: pm-domains: support smi clamp protection

AngeloGioacchino Del Regno
2024-03-26T13:57:08Z

Il 26/03/24 03:00, Yu-chang Lee (李禹璋) ha scritto:
> On Mon, 2024-03-25 at 14:05 +0100, AngeloGioacchino Del Regno wrote:
>> Il 25/03/24 13:19, yu-chang.lee ha scritto:
>>> In order to avoid power glitch, this patch use smi clamp
>>> to disable/enable smi common port.
>>>
>>> Signed-off-by: yu-chang.lee <yu-chang.lee@mediatek.com>
>>> ---
>>> drivers/pmdomain/mediatek/mt8188-pm-domains.h | 41 ++++-
>>> drivers/pmdomain/mediatek/mtk-pm-domains.c | 147
>>> ++++++++++++++----
>>> drivers/pmdomain/mediatek/mtk-pm-domains.h | 1 +
>>> 3 files changed, 156 insertions(+), 33 deletions(-)
>>>
>>> diff --git a/drivers/pmdomain/mediatek/mt8188-pm-domains.h
>>> b/drivers/pmdomain/mediatek/mt8188-pm-domains.h
>>> index 7bbba4d56a77..39f057dca92c 100644
>>> --- a/drivers/pmdomain/mediatek/mt8188-pm-domains.h
>>> +++ b/drivers/pmdomain/mediatek/mt8188-pm-domains.h
>>> @@ -573,6 +573,18 @@ static const struct scpsys_domain_data
>>> scpsys_domain_data_mt8188[] = {
>>> .pwr_sta2nd_offs = 0x170,
>>> .sram_pdn_bits = BIT(8),
>>> .sram_pdn_ack_bits = BIT(12),
>>> + .bp_cfg = {
>>> + BUS_PROT_WR(SMI,
>>> + MT8188_SMI_COMMON_SMI_CLAMP_DIP_TO_
>>> VDO0,
>>> + MT8188_SMI_COMMON_CLAMP_EN_SET,
>>> + MT8188_SMI_COMMON_CLAMP_EN_CLR,
>>> + MT8188_SMI_COMMON_CLAMP_EN_STA),
>>> + BUS_PROT_WR(SMI,
>>> + MT8188_SMI_COMMON_SMI_CLAMP_DIP_TO_
>>> VPP1,
>>> + MT8188_SMI_COMMON_CLAMP_EN_SET,
>>> + MT8188_SMI_COMMON_CLAMP_EN_CLR,
>>> + MT8188_SMI_COMMON_CLAMP_EN_STA),
>>> + },
>>> .reset_smi = {
>>> SMI_RESET_WR(MT8188_SMI_LARB10_RESET,
>>> MT8188_SMI_LARB10_RESET_ADDR),
>>> @@ -585,7 +597,7 @@ static const struct scpsys_domain_data
>>> scpsys_domain_data_mt8188[] = {
>>> SMI_RESET_WR(MT8188_SMI_LARB15_RESET,
>>> MT8188_SMI_LARB15_RESET_ADDR),
>>> },
>>> - .caps = MTK_SCPD_KEEP_DEFAULT_OFF,
>>> + .caps = MTK_SCPD_KEEP_DEFAULT_OFF |
>>> MTK_SCPD_CLAMP_PROTECTION,
>>> },
>>> [MT8188_POWER_DOMAIN_IPE] = {
>>> .name = "ipe",
>>> @@ -595,11 +607,18 @@ static const struct scpsys_domain_data
>>> scpsys_domain_data_mt8188[] = {
>>> .pwr_sta2nd_offs = 0x170,
>>> .sram_pdn_bits = BIT(8),
>>> .sram_pdn_ack_bits = BIT(12),
>>> + .bp_cfg = {
>>> + BUS_PROT_WR(SMI,
>>> + MT8188_SMI_COMMON_SMI_CLAMP_IPE_TO_
>>> VPP1,
>>> + MT8188_SMI_COMMON_CLAMP_EN_SET,
>>> + MT8188_SMI_COMMON_CLAMP_EN_CLR,
>>> + MT8188_SMI_COMMON_CLAMP_EN_STA),
>>> + },
>>> .reset_smi = {
>>> SMI_RESET_WR(MT8188_SMI_LARB12_RESET,
>>> MT8188_SMI_LARB12_RESET_ADDR),
>>> },
>>> - .caps = MTK_SCPD_KEEP_DEFAULT_OFF,
>>> + .caps = MTK_SCPD_KEEP_DEFAULT_OFF |
>>> MTK_SCPD_CLAMP_PROTECTION,
>>> },
>>> [MT8188_POWER_DOMAIN_CAM_VCORE] = {
>>> .name = "cam_vcore",
>>> @@ -676,13 +695,20 @@ static const struct scpsys_domain_data
>>> scpsys_domain_data_mt8188[] = {
>>> .pwr_sta2nd_offs = 0x170,
>>> .sram_pdn_bits = BIT(8),
>>> .sram_pdn_ack_bits = BIT(12),
>>> + .bp_cfg = {
>>> + BUS_PROT_WR(SMI,
>>> + MT8188_SMI_COMMON_SMI_CLAMP_IPE_TO_
>>> VPP1,
>>> + MT8188_SMI_COMMON_CLAMP_EN_SET,
>>> + MT8188_SMI_COMMON_CLAMP_EN_CLR,
>>> + MT8188_SMI_COMMON_CLAMP_EN_STA),
>>> + },
>>> .reset_smi = {
>>> SMI_RESET_WR(MT8188_SMI_LARB16A_RESET,
>>> MT8188_SMI_LARB16A_RESET_ADDR),
>>> SMI_RESET_WR(MT8188_SMI_LARB17A_RESET,
>>> MT8188_SMI_LARB17A_RESET_ADDR),
>>> },
>>> - .caps = MTK_SCPD_KEEP_DEFAULT_OFF,
>>> + .caps = MTK_SCPD_KEEP_DEFAULT_OFF |
>>> MTK_SCPD_CLAMP_PROTECTION,
>>> },
>>> [MT8188_POWER_DOMAIN_CAM_SUBB] = {
>>> .name = "cam_subb",
>>> @@ -692,13 +718,20 @@ static const struct scpsys_domain_data
>>> scpsys_domain_data_mt8188[] = {
>>> .pwr_sta2nd_offs = 0x170,
>>> .sram_pdn_bits = BIT(8),
>>> .sram_pdn_ack_bits = BIT(12),
>>> + .bp_cfg = {
>>> + BUS_PROT_WR(SMI,
>>> + MT8188_SMI_COMMON_SMI_CLAMP_CAM_SUB
>>> B_TO_VDO0,
>>> + MT8188_SMI_COMMON_CLAMP_EN_SET,
>>> + MT8188_SMI_COMMON_CLAMP_EN_CLR,
>>> + MT8188_SMI_COMMON_CLAMP_EN_STA),
>>> + },
>>> .reset_smi = {
>>> SMI_RESET_WR(MT8188_SMI_LARB16B_RESET,
>>> MT8188_SMI_LARB16B_RESET_ADDR),
>>> SMI_RESET_WR(MT8188_SMI_LARB17B_RESET,
>>> MT8188_SMI_LARB17B_RESET_ADDR),
>>> },
>>> - .caps = MTK_SCPD_KEEP_DEFAULT_OFF,
>>> + .caps = MTK_SCPD_KEEP_DEFAULT_OFF |
>>> MTK_SCPD_CLAMP_PROTECTION,
>>> },
>>> };
>>>
>>> diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c
>>> b/drivers/pmdomain/mediatek/mtk-pm-domains.c
>>> index 9ab6fa105c8c..3c797e136c0e 100644
>>> --- a/drivers/pmdomain/mediatek/mtk-pm-domains.c
>>> +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.c
>>> @@ -47,9 +47,10 @@ struct scpsys_domain {
>>> struct clk_bulk_data *subsys_clks;
>>> struct regmap *infracfg_nao;
>>> struct regmap *infracfg;
>>> - struct regmap *smi;
>>> + struct regmap **smi;
>>> struct regmap **larb;
>>> int num_larb;
>>> + int num_smi;
>>> struct regulator *supply;
>>> };
>>>
>>> @@ -122,29 +123,19 @@ static int scpsys_sram_disable(struct
>>> scpsys_domain *pd)
>>> MTK_POLL_TIMEOUT);
>>> }
>>>
>>> -static struct regmap *scpsys_bus_protect_get_regmap(struct
>>> scpsys_domain *pd,
>>> - const struct
>>> scpsys_bus_prot_data *bpd)
>>> -{
>>> - if (bpd->flags & BUS_PROT_COMPONENT_SMI)
>>> - return pd->smi;
>>> - else
>>> - return pd->infracfg;
>>> -}
>>> -
>>> static struct regmap *scpsys_bus_protect_get_sta_regmap(struct
>>> scpsys_domain *pd,
>>> const struct
>>> scpsys_bus_prot_data *bpd)
>>> {
>>> if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO)
>>> return pd->infracfg_nao;
>>> else
>>> - return scpsys_bus_protect_get_regmap(pd, bpd);
>>> + return pd->infracfg;
>>> }
>>>
>>> static int scpsys_bus_protect_clear(struct scpsys_domain *pd,
>>> - const struct scpsys_bus_prot_data
>>> *bpd)
>>> + const struct scpsys_bus_prot_data
>>> *bpd,
>>> + struct regmap *sta_regmap,
>>> struct regmap *regmap)
>>> {
>>> - struct regmap *sta_regmap =
>>> scpsys_bus_protect_get_sta_regmap(pd, bpd);
>>> - struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd);
>>> u32 sta_mask = bpd->bus_prot_sta_mask;
>>> u32 expected_ack;
>>> u32 val;
>>> @@ -165,10 +156,9 @@ static int scpsys_bus_protect_clear(struct
>>> scpsys_domain *pd,
>>> }
>>>
>>> static int scpsys_bus_protect_set(struct scpsys_domain *pd,
>>> - const struct scpsys_bus_prot_data
>>> *bpd)
>>> + const struct scpsys_bus_prot_data
>>> *bpd,
>>> + struct regmap *sta_regmap, struct
>>> regmap *regmap)
>>> {
>>> - struct regmap *sta_regmap =
>>> scpsys_bus_protect_get_sta_regmap(pd, bpd);
>>> - struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd);
>>> u32 sta_mask = bpd->bus_prot_sta_mask;
>>> u32 val;
>>>
>>> @@ -182,19 +172,32 @@ static int scpsys_bus_protect_set(struct
>>> scpsys_domain *pd,
>>> MTK_POLL_DELAY_US,
>>> MTK_POLL_TIMEOUT);
>>> }
>>>
>>> -static int scpsys_bus_protect_enable(struct scpsys_domain *pd)
>>> +static int _scpsys_clamp_bus_protection_enable(struct
>>> scpsys_domain *pd, bool is_smi)
>>> {
>>> + int smi_count = 0;
>>> +
>>> for (int i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) {
>>> const struct scpsys_bus_prot_data *bpd = &pd->data-
>>>> bp_cfg[i];
>>> + struct regmap *sta_regmap, *regmap;
>>> + bool is_smi = bpd->flags & BUS_PROT_COMPONENT_SMI;
>>> int ret;
>>>
>>> if (!bpd->bus_prot_set_clr_mask)
>>> break;
>>>
>>> + if (is_smi) {
>>> + sta_regmap = pd->smi[smi_count];
>>> + regmap = pd->smi[smi_count];
>>> + smi_count++;
>>> + } else {
>>> + sta_regmap =
>>> scpsys_bus_protect_get_sta_regmap(pd, bpd);
>>> + regmap = pd->infracfg;
>>> + }
>>> +
>>> if (bpd->flags & BUS_PROT_INVERTED)
>>> - ret = scpsys_bus_protect_clear(pd, bpd);
>>> + ret = scpsys_bus_protect_clear(pd, bpd,
>>> sta_regmap, regmap);
>>> else
>>> - ret = scpsys_bus_protect_set(pd, bpd);
>>> + ret = scpsys_bus_protect_set(pd, bpd,
>>> sta_regmap, regmap);
>>> if (ret)
>>> return ret;
>>> }
>>> @@ -202,19 +205,32 @@ static int scpsys_bus_protect_enable(struct
>>> scpsys_domain *pd)
>>> return 0;
>>> }
>>>
>>> -static int scpsys_bus_protect_disable(struct scpsys_domain *pd)
>>> +static int _scpsys_clamp_bus_protection_disable(struct
>>> scpsys_domain *pd, bool is_smi)
>>> {
>>> + int smi_count = pd->num_smi - 1;
>>> +
>>> for (int i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
>>> const struct scpsys_bus_prot_data *bpd = &pd->data-
>>>> bp_cfg[i];
>>> + struct regmap *sta_regmap, *regmap;
>>> + bool is_smi = bpd->flags & BUS_PROT_COMPONENT_SMI;
>>> int ret;
>>>
>>> if (!bpd->bus_prot_set_clr_mask)
>>> continue;
>>>
>>> + if (is_smi) {
>>> + sta_regmap = pd->smi[smi_count];
>>> + regmap = pd->smi[smi_count];
>>> + smi_count--;
>>> + } else {
>>> + sta_regmap =
>>> scpsys_bus_protect_get_sta_regmap(pd, bpd);
>>> + regmap = pd->infracfg;
>>> + }
>>> +
>>> if (bpd->flags & BUS_PROT_INVERTED)
>>> - ret = scpsys_bus_protect_set(pd, bpd);
>>> + ret = scpsys_bus_protect_set(pd, bpd,
>>> sta_regmap, regmap);
>>> else
>>> - ret = scpsys_bus_protect_clear(pd, bpd);
>>> + ret = scpsys_bus_protect_clear(pd, bpd,
>>> sta_regmap, regmap);
>>> if (ret)
>>> return ret;
>>> }
>>> @@ -222,6 +238,50 @@ static int scpsys_bus_protect_disable(struct
>>> scpsys_domain *pd)
>>> return 0;
>>> }
>>>
>>> +static int scpsys_clamp_protection(struct scpsys_domain *pd)
>>> +{
>>> + int ret;
>>> +
>>
>> You can directly call _scpsys_clamp_bus_protection_enable(), no need
>> for a helper.
>>
>>> + ret = _scpsys_clamp_bus_protection_enable(pd, true);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int scpsys_clamp_protection_disable(struct scpsys_domain
>>> *pd)
>>> +{
>>> + int ret;
>>> +
>>> + ret = _scpsys_clamp_bus_protection_disable(pd, true);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int scpsys_bus_protect_enable(struct scpsys_domain *pd)
>>
>> Unused function, please remove.
>
> I think this is used in scpsys_power_off function. Do you mean I
> should directly call _scpsys_clamp_bus_protection_disable?
>

Yes, please.

Cheers,
Angelo