]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pmdomain: mediatek: Handle SoCs with inverted SRAM power-down bits
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Tue, 5 Aug 2025 07:47:41 +0000 (09:47 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 19 Aug 2025 12:12:40 +0000 (14:12 +0200)
Some SoCs, and even some subsystems in the same SoC, may have the
logic for SRAM power-down inverted, as in, setting the bit means
"power down" and unsetting means "power up": this is because some
hardware subsystems use this as a power-lock indication and some
use this as a power down one (for example, usually, the modem ss
has it inverted!).

In preparation for adding support for power domains with inverted
SRAM_PDN bits, add a new MTK_SCPD_SRAM_PDN_INVERTED flag and check
for it in scpsys_sram_enable() and scpsys_sram_disable().

Reviewed-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20250805074746.29457-6-angelogioacchino.delregno@collabora.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/pmdomain/mediatek/mtk-pm-domains.c
drivers/pmdomain/mediatek/mtk-pm-domains.h

index 48dc5f18843820f91bb6f25d6973129f920e28f1..6118a389244a8817875d136641d268dc85bc5416 100644 (file)
@@ -79,16 +79,23 @@ static bool scpsys_domain_is_on(struct scpsys_domain *pd)
 
 static int scpsys_sram_enable(struct scpsys_domain *pd)
 {
-       u32 pdn_ack = pd->data->sram_pdn_ack_bits;
+       u32 expected_ack, pdn_ack = pd->data->sram_pdn_ack_bits;
        struct scpsys *scpsys = pd->scpsys;
        unsigned int tmp;
        int ret;
 
-       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits);
+       if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_PDN_INVERTED)) {
+               regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits);
+               expected_ack = pdn_ack;
+       } else {
+               regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits);
+               expected_ack = 0;
+       }
 
        /* Either wait until SRAM_PDN_ACK all 1 or 0 */
        ret = regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp,
-                                      (tmp & pdn_ack) == 0, MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+                                      (tmp & pdn_ack) == expected_ack,
+                                      MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
        if (ret < 0)
                return ret;
 
@@ -103,7 +110,7 @@ static int scpsys_sram_enable(struct scpsys_domain *pd)
 
 static int scpsys_sram_disable(struct scpsys_domain *pd)
 {
-       u32 pdn_ack = pd->data->sram_pdn_ack_bits;
+       u32 expected_ack, pdn_ack = pd->data->sram_pdn_ack_bits;
        struct scpsys *scpsys = pd->scpsys;
        unsigned int tmp;
 
@@ -113,12 +120,18 @@ static int scpsys_sram_disable(struct scpsys_domain *pd)
                regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT);
        }
 
-       regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits);
+       if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_PDN_INVERTED)) {
+               regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits);
+               expected_ack = 0;
+       } else {
+               regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits);
+               expected_ack = pdn_ack;
+       }
 
        /* Either wait until SRAM_PDN_ACK all 1 or 0 */
        return regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp,
-                                       (tmp & pdn_ack) == pdn_ack, MTK_POLL_DELAY_US,
-                                       MTK_POLL_TIMEOUT);
+                                       (tmp & pdn_ack) == expected_ack,
+                                       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
 }
 
 static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd,
index 4f2d331a866ab0d7b47a0ad5c5bfc9b4a8797c15..fbbfb23a87396882a3ba0692ab10668a5ad13342 100644 (file)
@@ -13,6 +13,7 @@
 #define MTK_SCPD_EXT_BUCK_ISO          BIT(6)
 #define MTK_SCPD_HAS_INFRA_NAO         BIT(7)
 #define MTK_SCPD_STRICT_BUS_PROTECTION BIT(8)
+#define MTK_SCPD_SRAM_PDN_INVERTED     BIT(9)
 #define MTK_SCPD_CAPS(_scpd, _x)       ((_scpd)->data->caps & (_x))
 
 #define SPM_VDE_PWR_CON                        0x0210