blob: 2f4bd22d54d1f351a72da539d915a1a86466210f [file] [log] [blame]
Angel Ponse67ab182020-04-04 18:51:11 +02001/* SPDX-License-Identifier: GPL-2.0-only */
CC Ma0c220842015-07-31 17:10:59 +08002
Weiyi Lu7fd93272021-02-09 15:59:02 +08003#include <delay.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
CC Ma0c220842015-07-31 17:10:59 +08005#include <soc/spm.h>
6
7enum {
8 SRAM_ISOINT_B = 1U << 6,
9 SRAM_CKISO = 1U << 5,
10 PWR_CLK_DIS = 1U << 4,
11 PWR_ON_2ND = 1U << 3,
12 PWR_ON = 1U << 2,
13 PWR_ISO = 1U << 1,
14 PWR_RST_B = 1U << 0
15};
16
Bo-Chen Chenf09872c2022-09-29 18:45:37 +080017__weak void mtcmos_set_scpd_ext_buck_iso(const struct power_domain_data *pd)
18{
19 /* do nothing */
20}
21
Mandy Liu55a1ba32022-10-11 13:40:07 +080022void mtcmos_power_on(const struct power_domain_data *pd)
CC Ma0c220842015-07-31 17:10:59 +080023{
Tristan Shieh0423a2b2018-06-12 15:04:43 +080024 write32(&mtk_spm->poweron_config_set,
CC Ma0c220842015-07-31 17:10:59 +080025 (SPM_PROJECT_CODE << 16) | (1U << 0));
26
Bo-Chen Chenf09872c2022-09-29 18:45:37 +080027 if (pd->caps & SCPD_EXT_BUCK_ISO)
28 mtcmos_set_scpd_ext_buck_iso(pd);
29
Julius Werner55009af2019-12-02 22:03:27 -080030 setbits32(pd->pwr_con, PWR_ON);
31 setbits32(pd->pwr_con, PWR_ON_2ND);
CC Ma0c220842015-07-31 17:10:59 +080032
Tristan Shieh0423a2b2018-06-12 15:04:43 +080033 while (!(read32(&mtk_spm->pwr_status) & pd->pwr_sta_mask) ||
34 !(read32(&mtk_spm->pwr_status_2nd) & pd->pwr_sta_mask))
CC Ma0c220842015-07-31 17:10:59 +080035 continue;
36
Julius Werner55009af2019-12-02 22:03:27 -080037 clrbits32(pd->pwr_con, PWR_CLK_DIS);
38 clrbits32(pd->pwr_con, PWR_ISO);
39 setbits32(pd->pwr_con, PWR_RST_B);
40 clrbits32(pd->pwr_con, pd->sram_pdn_mask);
CC Ma0c220842015-07-31 17:10:59 +080041
Tristan Shieh0423a2b2018-06-12 15:04:43 +080042 while (read32(pd->pwr_con) & pd->sram_ack_mask)
CC Ma0c220842015-07-31 17:10:59 +080043 continue;
Weiyi Lu16bc6212021-02-09 17:59:26 +080044
45 if (pd->caps & SCPD_SRAM_ISO) {
46 setbits32(pd->pwr_con, SRAM_ISOINT_B);
47 udelay(1);
48 clrbits32(pd->pwr_con, SRAM_CKISO);
49 }
CC Ma0c220842015-07-31 17:10:59 +080050}
51
52void mtcmos_display_power_on(void)
53{
Weiyi Lu7fd93272021-02-09 15:59:02 +080054 int i;
Tristan Shieh0423a2b2018-06-12 15:04:43 +080055
Weiyi Lu7fd93272021-02-09 15:59:02 +080056 for (i = 0; i < ARRAY_SIZE(disp); i++)
57 mtcmos_power_on(&disp[i]);
Tristan Shieh0423a2b2018-06-12 15:04:43 +080058}
59
60void mtcmos_audio_power_on(void)
61{
Weiyi Lu7fd93272021-02-09 15:59:02 +080062 int i;
Tristan Shieh0423a2b2018-06-12 15:04:43 +080063
Weiyi Lu7fd93272021-02-09 15:59:02 +080064 for (i = 0; i < ARRAY_SIZE(audio); i++)
65 mtcmos_power_on(&audio[i]);
CC Ma0c220842015-07-31 17:10:59 +080066}