Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

AngeloGioacchino Del Regno and committed by
Ulf Hansson
8e98bade 88914db0

+39 -2
+38 -2
drivers/pmdomain/mediatek/mtk-pm-domains.c
··· 15 15 #include <linux/regmap.h> 16 16 #include <linux/regulator/consumer.h> 17 17 #include <linux/soc/mediatek/infracfg.h> 18 + #include <linux/soc/mediatek/mtk_sip_svc.h> 18 19 19 20 #include "mt6735-pm-domains.h" 20 21 #include "mt6795-pm-domains.h" ··· 51 50 #define PWR_RTFF_CLK_DIS BIT(26) 52 51 #define PWR_RTFF_SAVE_FLAG BIT(27) 53 52 #define PWR_RTFF_UFS_CLK_DIS BIT(28) 53 + 54 + #define MTK_SIP_KERNEL_HWCCF_CONTROL MTK_SIP_SMC_CMD(0x540) 54 55 55 56 struct scpsys_domain { 56 57 struct generic_pm_domain genpd; ··· 117 114 118 115 /* Enable is done when the bit is set in DONE and EN, cleared in SET_STA */ 119 116 return (val[0] & mask) && (val[1] & mask) && !(val[2] & mask); 117 + } 118 + 119 + static int scpsys_sec_infra_power_on(bool on) 120 + { 121 + struct arm_smccc_res res; 122 + unsigned long cmd = on ? 1 : 0; 123 + 124 + arm_smccc_smc(MTK_SIP_KERNEL_HWCCF_CONTROL, cmd, 0, 0, 0, 0, 0, 0, &res); 125 + return res.a0; 120 126 } 121 127 122 128 static int scpsys_sram_enable(struct scpsys_domain *pd) ··· 303 291 u32 val; 304 292 int ret; 305 293 294 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) { 295 + ret = scpsys_sec_infra_power_on(true); 296 + if (ret) 297 + return ret; 298 + } 299 + 306 300 ret = scpsys_regulator_enable(pd->supply); 307 301 if (ret) 308 - return ret; 302 + goto err_infra; 309 303 310 304 ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks); 311 305 if (ret) ··· 362 344 /* It's done! Disable the HWV low power subsystem clocks */ 363 345 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); 364 346 347 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) 348 + scpsys_sec_infra_power_on(false); 349 + 365 350 return 0; 366 351 367 352 err_disable_subsys_clks: ··· 373 352 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); 374 353 err_reg: 375 354 scpsys_regulator_disable(pd->supply); 355 + err_infra: 356 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) 357 + scpsys_sec_infra_power_on(false); 376 358 return ret; 377 359 }; 378 360 ··· 387 363 u32 val; 388 364 int ret; 389 365 366 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) { 367 + ret = scpsys_sec_infra_power_on(true); 368 + if (ret) 369 + return ret; 370 + } 371 + 390 372 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, pd->subsys_clks); 391 373 if (ret) 392 - return ret; 374 + goto err_infra; 393 375 394 376 /* Make sure the HW Voter is idle and able to accept commands */ 395 377 ret = regmap_read_poll_timeout_atomic(scpsys->base, hwv->done, val, ··· 437 407 438 408 scpsys_regulator_disable(pd->supply); 439 409 410 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) 411 + scpsys_sec_infra_power_on(false); 412 + 440 413 return 0; 441 414 442 415 err_disable_subsys_clks: 443 416 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); 417 + err_infra: 418 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_INFRA_PWR_CTL)) 419 + scpsys_sec_infra_power_on(false); 444 420 return ret; 445 421 }; 446 422
+1
drivers/pmdomain/mediatek/mtk-pm-domains.h
··· 16 16 #define MTK_SCPD_SRAM_PDN_INVERTED BIT(9) 17 17 #define MTK_SCPD_MODEM_PWRSEQ BIT(10) 18 18 #define MTK_SCPD_SKIP_RESET_B BIT(11) 19 + #define MTK_SCPD_INFRA_PWR_CTL BIT(12) 19 20 #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data ? \ 20 21 (_scpd)->data->caps & (_x) : \ 21 22 (_scpd)->hwv_data->caps & (_x))