Skip to content

Commit 8e98bad

Browse files
AngeloGioacchino Del RegnoUlf Hansson
authored andcommitted
pmdomain: mediatek: Add support for secure HWCCF infra power on
Some SoCs, like the MediaTek Dimensity 9400 (MT6991), have granular power controls and will disable power to the infracfg to save power when the platform is in deeper sleep states (or when no IP in the the infracfg macro-block is in use). These chips also cannot control the infracfg power states directly via AP register writes as those are protected by the secure world. Add a new MTK_SCPD_INFRA_PWR_CTL cap and, if present, make a call to the secure world to poweron the infracfg block, as the HWV IP resides in there, when executing HWV domains power sequences. Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 88914db commit 8e98bad

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

drivers/pmdomain/mediatek/mtk-pm-domains.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/regmap.h>
1616
#include <linux/regulator/consumer.h>
1717
#include <linux/soc/mediatek/infracfg.h>
18+
#include <linux/soc/mediatek/mtk_sip_svc.h>
1819

1920
#include "mt6735-pm-domains.h"
2021
#include "mt6795-pm-domains.h"
@@ -51,6 +52,8 @@
5152
#define PWR_RTFF_SAVE_FLAG BIT(27)
5253
#define PWR_RTFF_UFS_CLK_DIS BIT(28)
5354

55+
#define MTK_SIP_KERNEL_HWCCF_CONTROL MTK_SIP_SMC_CMD(0x540)
56+
5457
struct scpsys_domain {
5558
struct generic_pm_domain genpd;
5659
const struct scpsys_domain_data *data;
@@ -116,6 +119,15 @@ static bool scpsys_hwv_domain_is_enable_done(struct scpsys_domain *pd)
116119
return (val[0] & mask) && (val[1] & mask) && !(val[2] & mask);
117120
}
118121

122+
static int scpsys_sec_infra_power_on(bool on)
123+
{
124+
struct arm_smccc_res res;
125+
unsigned long cmd = on ? 1 : 0;
126+
127+
arm_smccc_smc(MTK_SIP_KERNEL_HWCCF_CONTROL, cmd, 0, 0, 0, 0, 0, 0, &res);
128+
return res.a0;
129+
}
130+
119131
static int scpsys_sram_enable(struct scpsys_domain *pd)
120132
{
121133
u32 expected_ack, pdn_ack = pd->data->sram_pdn_ack_bits;
@@ -291,9 +303,15 @@ static int scpsys_hwv_power_on(struct generic_pm_domain *genpd)
291303
u32 val;
292304
int ret;
293305

306+
if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) {
307+
ret = scpsys_sec_infra_power_on(true);
308+
if (ret)
309+
return ret;
310+
}
311+
294312
ret = scpsys_regulator_enable(pd->supply);
295313
if (ret)
296-
return ret;
314+
goto err_infra;
297315

298316
ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks);
299317
if (ret)
@@ -344,6 +362,9 @@ static int scpsys_hwv_power_on(struct generic_pm_domain *genpd)
344362
/* It's done! Disable the HWV low power subsystem clocks */
345363
clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks);
346364

365+
if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL))
366+
scpsys_sec_infra_power_on(false);
367+
347368
return 0;
348369

349370
err_disable_subsys_clks:
@@ -352,6 +373,9 @@ static int scpsys_hwv_power_on(struct generic_pm_domain *genpd)
352373
clk_bulk_disable_unprepare(pd->num_clks, pd->clks);
353374
err_reg:
354375
scpsys_regulator_disable(pd->supply);
376+
err_infra:
377+
if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL))
378+
scpsys_sec_infra_power_on(false);
355379
return ret;
356380
};
357381

@@ -363,9 +387,15 @@ static int scpsys_hwv_power_off(struct generic_pm_domain *genpd)
363387
u32 val;
364388
int ret;
365389

390+
if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) {
391+
ret = scpsys_sec_infra_power_on(true);
392+
if (ret)
393+
return ret;
394+
}
395+
366396
ret = clk_bulk_prepare_enable(pd->num_subsys_clks, pd->subsys_clks);
367397
if (ret)
368-
return ret;
398+
goto err_infra;
369399

370400
/* Make sure the HW Voter is idle and able to accept commands */
371401
ret = regmap_read_poll_timeout_atomic(scpsys->base, hwv->done, val,
@@ -407,10 +437,16 @@ static int scpsys_hwv_power_off(struct generic_pm_domain *genpd)
407437

408438
scpsys_regulator_disable(pd->supply);
409439

440+
if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL))
441+
scpsys_sec_infra_power_on(false);
442+
410443
return 0;
411444

412445
err_disable_subsys_clks:
413446
clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks);
447+
err_infra:
448+
if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL))
449+
scpsys_sec_infra_power_on(false);
414450
return ret;
415451
};
416452

drivers/pmdomain/mediatek/mtk-pm-domains.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define MTK_SCPD_SRAM_PDN_INVERTED BIT(9)
1717
#define MTK_SCPD_MODEM_PWRSEQ BIT(10)
1818
#define MTK_SCPD_SKIP_RESET_B BIT(11)
19+
#define MTK_SCPD_INFRA_PWR_CTL BIT(12)
1920
#define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data ? \
2021
(_scpd)->data->caps & (_x) : \
2122
(_scpd)->hwv_data->caps & (_x))

0 commit comments

Comments
 (0)