Commit 1a1ff8b9 authored by Jimmy Huang's avatar Jimmy Huang Committed by Yidi Lin
Browse files

mt8173: Implement subsystem power control logic in ARM TF



1. Add SiP calls for subsystem power on/off and check support
2. Add subsystem power control related initialization in
   bl31_plat_setup.c
3. Add subsystem power on/off and power ack waiting functions
4. Update PCM code for subsystem physical power control logic

Change-Id: Ia0ebb1964c8f9758159bcf17c1813d76ef52cf64
Signed-off-by: default avataryt.lee <yt.lee@mediatek.com>
parent 8e53ec53
......@@ -55,6 +55,18 @@ static uint64_t mediatek_sip_handler(uint32_t smc_fid,
ret = mt_sip_set_authorized_sreg((uint32_t)x1, (uint32_t)x2);
SMC_RET1(handle, ret);
case MTK_SIP_PWR_ON_MTCMOS:
ret = mt_sip_pwr_on_mtcmos((uint32_t)x1);
SMC_RET1(handle, ret);
case MTK_SIP_PWR_OFF_MTCMOS:
ret = mt_sip_pwr_off_mtcmos((uint32_t)x1);
SMC_RET1(handle, ret);
case MTK_SIP_PWR_MTCMOS_SUPPORT:
ret = mt_sip_pwr_mtcmos_support();
SMC_RET1(handle, ret);
default:
ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
break;
......
......@@ -43,10 +43,13 @@
#define MTK_SIP_SVC_VERSION_MINOR 0x1
/* Number of Mediatek SiP Calls implemented */
#define MTK_SIP_NUM_CALLS 1
#define MTK_SIP_NUM_CALLS 4
/* Mediatek SiP Service Calls function IDs */
#define MTK_SIP_SET_AUTHORIZED_SECURE_REG 0x82000001
#define MTK_SIP_PWR_ON_MTCMOS 0x82000402
#define MTK_SIP_PWR_OFF_MTCMOS 0x82000403
#define MTK_SIP_PWR_MTCMOS_SUPPORT 0x82000404
/* Mediatek SiP Calls error code */
enum {
......@@ -62,5 +65,7 @@ enum {
* Return MTK_SIP_E_SUCCESS on success, and MTK_SIP_E_INVALID_PARAM on failure.
*/
uint64_t mt_sip_set_authorized_sreg(uint32_t sreg, uint32_t val);
uint64_t mt_sip_pwr_on_mtcmos(uint32_t val);
uint64_t mt_sip_pwr_off_mtcmos(uint32_t val);
uint64_t mt_sip_pwr_mtcmos_support(void);
#endif /* __PLAT_SIP_SVC_H__ */
......@@ -29,8 +29,11 @@
*/
#include <mmio.h>
#include <mt8173_def.h>
#include <debug.h>
#include <mtcmos.h>
#include <spm.h>
#include <spm_mcdi.h>
#include <delay_timer.h>
enum {
SRAM_ISOINT_B = 1U << 6,
......@@ -64,6 +67,63 @@ enum {
AUD_PWR_STA_MASK = 0x1 << 24,
};
#define SPM_VDE_PWR_CON 0x0210
#define SPM_MFG_PWR_CON 0x0214
#define SPM_VEN_PWR_CON 0x0230
#define SPM_ISP_PWR_CON 0x0238
#define SPM_DIS_PWR_CON 0x023c
#define SPM_VEN2_PWR_CON 0x0298
#define SPM_AUDIO_PWR_CON 0x029c
#define SPM_MFG_2D_PWR_CON 0x02c0
#define SPM_MFG_ASYNC_PWR_CON 0x02c4
#define SPM_USB_PWR_CON 0x02cc
#define MTCMOS_CTRL_SUCCESS 0
#define MTCMOS_CTRL_ERROR -1
#define MTCMOS_CTRL_EN (0x1 << 18)
#define VDE_PWR_ON 0
#define VEN_PWR_ON 1
#define ISP_PWR_ON 2
#define DIS_PWR_ON 3
#define VEN2_PWR_ON 4
#define AUDIO_PWR_ON 5
#define MFG_ASYNC_PWR_ON 6
#define MFG_2D_PWR_ON 7
#define MFG_PWR_ON 8
#define USB_PWR_ON 9
#define VDE_PWR_OFF 10
#define VEN_PWR_OFF 11
#define ISP_PWR_OFF 12
#define DIS_PWR_OFF 13
#define VEN2_PWR_OFF 14
#define AUDIO_PWR_OFF 15
#define MFG_ASYNC_PWR_OFF 16
#define MFG_2D_PWR_OFF 17
#define MFG_PWR_OFF 18
#define USB_PWR_OFF 19
#define VDE_PWR_CON_PWR_STA 7
#define VEN_PWR_CON_PWR_STA 21
#define ISP_PWR_CON_PWR_STA 5
#define DIS_PWR_CON_PWR_STA 3
#define VEN2_PWR_CON_PWR_STA 20
#define AUDIO_PWR_CON_PWR_STA 24
#define MFG_ASYNC_PWR_CON_PWR_STA 23
#define MFG_2D_PWR_CON_PWR_STA 22
#define MFG_PWR_CON_PWR_STA 4
#define USB_PWR_CON_PWR_STA 25
/*
* Timeout if the ack is not signled after 1 second.
* According to designer, one mtcmos operation should be done
* around 10us.
*/
#define MTCMOS_ACK_POLLING_MAX_COUNT 10000
#define MTCMOS_ACK_POLLING_INTERVAL 10
static void mtcmos_ctrl_little_off(unsigned int linear_id)
{
uint32_t reg_pwr_con;
......@@ -120,3 +180,117 @@ void mtcmos_little_cpu_off(void)
mtcmos_ctrl_little_off(2);
mtcmos_ctrl_little_off(3);
}
uint32_t wait_mtcmos_ack(uint32_t on, uint32_t mtcmos_sta, uint32_t spm_pwr_sta)
{
int i = 0;
uint32_t cmp, pwr_sta, pwr_sta_2nd;
while (1) {
cmp = (mmio_read_32(SPM_PCM_PASR_DPD_3) >> mtcmos_sta) & 1;
pwr_sta = (mmio_read_32(SPM_PWR_STATUS) >> spm_pwr_sta) & 1;
pwr_sta_2nd =
(mmio_read_32(SPM_PWR_STATUS_2ND) >> spm_pwr_sta) & 1;
if ((cmp == on) && (pwr_sta == on) && (pwr_sta_2nd == on)) {
mmio_write_32(SPM_PCM_RESERVE2, 0);
return MTCMOS_CTRL_SUCCESS;
}
udelay(MTCMOS_ACK_POLLING_INTERVAL);
i++;
if (i > MTCMOS_ACK_POLLING_MAX_COUNT) {
INFO("MTCMOS control failed(%d), SPM_PWR_STA(%d),\n"
"SPM_PCM_RESERVE=0x%x,SPM_PCM_RESERVE2=0x%x,\n"
"SPM_PWR_STATUS=0x%x,SPM_PWR_STATUS_2ND=0x%x\n"
"SPM_PCM_PASR_DPD_3 = 0x%x\n",
on, spm_pwr_sta, mmio_read_32(SPM_PCM_RESERVE),
mmio_read_32(SPM_PCM_RESERVE2),
mmio_read_32(SPM_PWR_STATUS),
mmio_read_32(SPM_PWR_STATUS_2ND),
mmio_read_32(SPM_PCM_PASR_DPD_3));
mmio_write_32(SPM_PCM_RESERVE2, 0);
return MTCMOS_CTRL_ERROR;
}
}
}
uint32_t mtcmos_non_cpu_ctrl(uint32_t on, uint32_t mtcmos_num)
{
uint32_t ret = MTCMOS_CTRL_SUCCESS;
uint32_t power_on;
uint32_t power_off;
uint32_t power_status;
spm_lock_get();
spm_mcdi_prepare_for_mtcmos();
mmio_setbits_32(SPM_PCM_RESERVE, MTCMOS_CTRL_EN);
switch (mtcmos_num) {
case SPM_VDE_PWR_CON:
power_on = VDE_PWR_ON;
power_off = VDE_PWR_OFF;
power_status = VDE_PWR_CON_PWR_STA;
break;
case SPM_MFG_PWR_CON:
power_on = MFG_PWR_ON;
power_off = MFG_PWR_OFF;
power_status = MFG_PWR_CON_PWR_STA;
break;
case SPM_VEN_PWR_CON:
power_on = VEN_PWR_ON;
power_off = VEN_PWR_OFF;
power_status = VEN_PWR_CON_PWR_STA;
break;
case SPM_ISP_PWR_CON:
power_on = ISP_PWR_ON;
power_off = ISP_PWR_OFF;
power_status = ISP_PWR_CON_PWR_STA;
break;
case SPM_DIS_PWR_CON:
power_on = DIS_PWR_ON;
power_off = DIS_PWR_OFF;
power_status = DIS_PWR_CON_PWR_STA;
break;
case SPM_VEN2_PWR_CON:
power_on = VEN2_PWR_ON;
power_off = VEN2_PWR_OFF;
power_status = VEN2_PWR_CON_PWR_STA;
break;
case SPM_AUDIO_PWR_CON:
power_on = AUDIO_PWR_ON;
power_off = AUDIO_PWR_OFF;
power_status = AUDIO_PWR_CON_PWR_STA;
break;
case SPM_MFG_2D_PWR_CON:
power_on = MFG_2D_PWR_ON;
power_off = MFG_2D_PWR_OFF;
power_status = MFG_2D_PWR_CON_PWR_STA;
break;
case SPM_MFG_ASYNC_PWR_CON:
power_on = MFG_ASYNC_PWR_ON;
power_off = MFG_ASYNC_PWR_OFF;
power_status = MFG_ASYNC_PWR_CON_PWR_STA;
break;
case SPM_USB_PWR_CON:
power_on = USB_PWR_ON;
power_off = USB_PWR_OFF;
power_status = USB_PWR_CON_PWR_STA;
break;
default:
ret = MTCMOS_CTRL_ERROR;
INFO("No mapping MTCMOS(%d), ret = %d\n", mtcmos_num, ret);
break;
}
if (ret == MTCMOS_CTRL_SUCCESS) {
mmio_setbits_32(SPM_PCM_RESERVE2, on ?
(1 << power_on) : (1 << power_off));
ret = wait_mtcmos_ack(on, power_on, power_status);
VERBOSE("0x%x(%d), PWR_STATUS(0x%x), ret(%d)\n",
power_on, on, mmio_read_32(SPM_PWR_STATUS), ret);
}
mmio_clrbits_32(SPM_PCM_RESERVE, MTCMOS_CTRL_EN);
spm_lock_release();
return ret;
}
......@@ -37,5 +37,6 @@
* during CPU_ON psci call.
*/
void mtcmos_little_cpu_off(void);
uint32_t mtcmos_non_cpu_ctrl(uint32_t on, uint32_t mtcmos_num);
#endif /* __MTCMOS_H__ */
This diff is collapsed.
......@@ -31,6 +31,7 @@
#define __SPM_MCDI_H__
void spm_mcdi_wakeup_all_cores(void);
void spm_mcdi_prepare_for_mtcmos(void);
void spm_mcdi_prepare_for_off_state(unsigned long mpidr, unsigned int afflvl);
void spm_mcdi_finish_for_on_state(unsigned long mpidr, unsigned int afflvl);
......
......@@ -29,6 +29,7 @@
*/
#include <mmio.h>
#include <mtk_sip_svc.h>
#include <mtcmos.h>
/* Authorized secure register list */
enum {
......@@ -55,3 +56,30 @@ uint64_t mt_sip_set_authorized_sreg(uint32_t sreg, uint32_t val)
return MTK_SIP_E_INVALID_PARAM;
}
uint64_t mt_sip_pwr_on_mtcmos(uint32_t val)
{
uint32_t ret;
ret = mtcmos_non_cpu_ctrl(1, val);
if (ret)
return MTK_SIP_E_INVALID_PARAM;
else
return MTK_SIP_E_SUCCESS;
}
uint64_t mt_sip_pwr_off_mtcmos(uint32_t val)
{
uint32_t ret;
ret = mtcmos_non_cpu_ctrl(0, val);
if (ret)
return MTK_SIP_E_INVALID_PARAM;
else
return MTK_SIP_E_SUCCESS;
}
uint64_t mt_sip_pwr_mtcmos_support(void)
{
return MTK_SIP_E_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment