]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pmdomain: mediatek: Move ctl sequences out of power_on/off functions
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Tue, 5 Aug 2025 07:47:42 +0000 (09:47 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 19 Aug 2025 12:12:40 +0000 (14:12 +0200)
In preparation to support power domains of new SoCs and the modem
power domains for both new and already supported chips, move the
generic control power sequences out of the scpsys_power_on() and
scpsys_power_off() and put them in new scpsys_ctl_pwrseq_on(),
scpsys_ctl_pewseq_off() functions.

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-7-angelogioacchino.delregno@collabora.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/pmdomain/mediatek/mtk-pm-domains.c

index 6118a389244a8817875d136641d268dc85bc5416..d84f0e7cde12f2d9be1b6297f722fc9a8e8cbaaa 100644 (file)
@@ -244,11 +244,45 @@ static int scpsys_regulator_disable(struct regulator *supply)
        return supply ? regulator_disable(supply) : 0;
 }
 
+static int scpsys_ctl_pwrseq_on(struct scpsys_domain *pd)
+{
+       struct scpsys *scpsys = pd->scpsys;
+       bool tmp;
+       int ret;
+
+       /* subsys power on */
+       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT);
+       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT);
+
+       /* wait until PWR_ACK = 1 */
+       ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, tmp, MTK_POLL_DELAY_US,
+                                MTK_POLL_TIMEOUT);
+       if (ret < 0)
+               return ret;
+
+       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT);
+       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT);
+       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
+
+       return 0;
+}
+
+static void scpsys_ctl_pwrseq_off(struct scpsys_domain *pd)
+{
+       struct scpsys *scpsys = pd->scpsys;
+
+       /* subsys power off */
+       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT);
+       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT);
+       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
+       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT);
+       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT);
+}
+
 static int scpsys_power_on(struct generic_pm_domain *genpd)
 {
        struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd);
        struct scpsys *scpsys = pd->scpsys;
-       bool tmp;
        int ret;
 
        ret = scpsys_regulator_enable(pd->supply);
@@ -263,20 +297,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
                regmap_clear_bits(scpsys->base, pd->data->ext_buck_iso_offs,
                                  pd->data->ext_buck_iso_mask);
 
-       /* subsys power on */
-       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT);
-       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT);
-
-       /* wait until PWR_ACK = 1 */
-       ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, tmp, MTK_POLL_DELAY_US,
-                                MTK_POLL_TIMEOUT);
-       if (ret < 0)
+       ret = scpsys_ctl_pwrseq_on(pd);
+       if (ret)
                goto err_pwr_ack;
 
-       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT);
-       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT);
-       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
-
        /*
         * In few Mediatek platforms(e.g. MT6779), the bus protect policy is
         * stricter, which leads to bus protect release must be prior to bus
@@ -342,12 +366,7 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 
        clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks);
 
-       /* subsys power off */
-       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT);
-       regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT);
-       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
-       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT);
-       regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT);
+       scpsys_ctl_pwrseq_off(pd);
 
        /* wait until PWR_ACK = 0 */
        ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, !tmp, MTK_POLL_DELAY_US,