Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

@@ -0,0 +1,17 @@
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/lpm/inc/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/lpm/mtk_lpm_trace_event/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/lpm/modules/include/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/lpm/modules/include/mt6779/
BUILD_MTK_LPM_PLAT_MODUDLE_NAME=mtk-lpm-plat-$(strip $(subst ",, $(CONFIG_MTK_LPM_MODULE_NAME)))
obj-$(CONFIG_MTK_LPM_MT6779) += ${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}.o
${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}-y += mt6779.o
${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}-y += mtk_lp_plat_apmcu.o
${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}-y += mtk_lp_plat_apmcu_mbox.o
${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}-y += mt6779_ipi_sspm.o
${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}-y += idles/mt6779_mcusys.o
${BUILD_MTK_LPM_PLAT_MODUDLE_NAME}-y += suspend/mt6779_suspend.o
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/cpuidle.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/cpu_pm.h>
#include <linux/sched/clock.h>
#include <asm/cpuidle.h>
#include <asm/suspend.h>
#include <mtk_lpm.h>
#include <mtk_lpm_call.h>
#include <mtk_lpm_type.h>
#include <mtk_lpm_call_type.h>
#include <mtk_lpm_module.h>
#include <mtk_lpm_common.h>
#include <mtk_resource_constraint_v1.h>
#include <mtk_lp_plat_apmcu.h>
#include "mt6779.h"
#define MCUSY_DUMP_INFO_INTERVAL_NS 5000000000
#define IS_NEED_ISSUER(delta_ns)\
(delta_ns > MCUSY_DUMP_INFO_INTERVAL_NS)
static u64 mt6779_mcusysoff_last_ns;
static unsigned int mt6779_mcusys_status;
int mt6779_mcusys_prompt(int cpu, const struct mtk_lpm_issuer *issuer)
{
int bRet = 0;
mtk_lp_plat_set_mcusys_off(cpu);
if (mtk_lp_plat_is_mcusys_off()) {
unsigned int mcusys_status = 0;
unsigned int smc_res = 0;
smc_res = mtk_lpm_smc_cpu_pm(MCUSYS_STATUS, MT_LPM_SMC_ACT_GET,
MCUSYS_STATUS_PDN, 0);
if (MT_RM_STATUS_CHECK(smc_res, VCORE_LP_CLK_26M_OFF))
mcusys_status = (PLAT_VCORE_LP_MODE
| PLAT_PMIC_VCORE_SRCLKEN0
| PLAT_MCUSYS_PROTECTED);
else if (MT_RM_STATUS_CHECK(smc_res, VCORE_LP_CLK_26M_ON))
mcusys_status = (PLAT_VCORE_LP_MODE
| PLAT_MAINPLL_OFF
| PLAT_PMIC_VCORE_SRCLKEN2
| PLAT_MCUSYS_PROTECTED);
else if (MT_RM_STATUS_CHECK(smc_res, MAINPLL_OFF))
mcusys_status = (PLAT_MAINPLL_OFF
| PLAT_MCUSYS_PROTECTED);
else if (MT_RM_STATUS_CHECK(smc_res, DRAM_OFF) |
MT_RM_STATUS_CHECK(smc_res, CPU_BUCK_OFF))
mcusys_status = (PLAT_MCUSYS_PROTECTED);
else
mcusys_status = 0;
mt6779_mcusys_status = mcusys_status;
if (mt6779_mcusys_status != 0)
mt6779_do_mcusys_prepare_pdn(mt6779_mcusys_status,
&smc_res);
}
return bRet;
}
void mt6779_mcusys_reflect(int cpu, const struct mtk_lpm_issuer *issuer)
{
if (mtk_lp_plat_is_mcusys_off()) {
if (mt6779_mcusys_status != 0) {
mt6779_do_mcusys_prepare_on();
mt6779_mcusys_status = 0;
}
if (issuer) {
u64 delta_ns = sched_clock() - mt6779_mcusysoff_last_ns;
if (IS_NEED_ISSUER(delta_ns)) {
issuer->log(MT_LPM_ISSUER_CPUIDLE,
"MCUSYSOFF", NULL);
mt6779_mcusysoff_last_ns = sched_clock();
}
}
}
mtk_lp_plat_clr_mcusys_off(cpu);
}
struct mtk_lpm_model mt6779_model_mcusys = {
.flag = MTK_LP_REQ_NONE,
.op = {
.prompt = mt6779_mcusys_prompt,
.reflect = mt6779_mcusys_reflect,
.prepare_resume = NULL,
.prepare_enter = NULL,
}
};
int __init mt6779_model_mcusys_init(void)
{
mtk_lp_model_register("mcusysoff", &mt6779_model_mcusys);
return 0;
}
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MT6779_MCUSYS_H__
#define __MT6779_MCUSYS_H__
int mt6779_model_mcusys_init(void);
#endif
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <mtk_lp_plat_apmcu.h>
#include "mt6779.h"
#include "mt6779_ipi_sspm.h"
#include <idles/mt6779_mcusys.h>
#include <suspend/mt6779_suspend.h>
static unsigned int mt6779_lp_pwr_state;
/*
* Please make sure the race condition protection upfront
* when calling mtk_lp_plat_do_mcusys_prepare_pdn()
*/
int mt6779_do_mcusys_prepare_pdn(unsigned int status,
unsigned int *resource_req)
{
mt6779_sspm_notify_enter(status);
mt6779_lp_pwr_state |= (status | PLAT_GIC_MASKED
| PLAT_MCUSYSOFF_PREPARED);
return 0;
}
/*
* Please make sure the race condition protection upfront
* when calling mtk_lp_plat_do_mcusys_prepare_on()
*/
static int __mt6779_do_mcusys_prepare_on(unsigned int clr_status)
{
mt6779_sspm_notify_leave(clr_status);
mt6779_lp_pwr_state &= ~(clr_status | PLAT_GIC_MASKED
| PLAT_MCUSYSOFF_PREPARED);
return 0;
}
int mt6779_do_mcusys_prepare_on(void)
{
unsigned int status = mt6779_lp_pwr_state;
return __mt6779_do_mcusys_prepare_on(status);
}
int mt6779_do_mcusys_prepare_on_ex(unsigned int clr_status)
{
return __mt6779_do_mcusys_prepare_on(clr_status);
}
static int mt6779_init(void)
{
mtk_lp_plat_apmcu_init();
mt6779_model_mcusys_init();
mt6779_model_suspend_init();
return 0;
}
static int mt6779_early_init(void)
{
mtk_lp_plat_apmcu_early_init();
return 0;
}
static int __init mtk_lpm_mt6779_init(void)
{
mt6779_early_init();
mt6779_init();
return 0;
}
static void __exit mtk_lpm_mt6779_exit(void)
{
}
module_init(mtk_lpm_mt6779_init);
module_exit(mtk_lpm_mt6779_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Mediatek LPM mt6779");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MT6779_H__
#define __MT6779_H__
#include <linux/delay.h>
#include <mtk_lpm_type.h>
#include <mt6779_common.h>
int mt6779_do_mcusys_prepare_pdn(unsigned int status,
unsigned int *resource_req);
int mt6779_do_mcusys_prepare_on_ex(unsigned int clr_status);
int mt6779_do_mcusys_prepare_on(void);
#endif
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MT6779_COMMON_H__
#define __MT6779_COMMON_H__
#include <linux/delay.h>
#include <linux/printk.h>
#include <mtk_lpm_type.h>
/* Platform pwr state */
#define PLAT_XO_UFS_OFF (1<<1L)
#define PLAT_CLKBUF_ENTER_BBLPM (1<<2L)
#define PLAT_SUSPEND (1<<8L)
#define PLAT_MCUSYS_PROTECTED (1<<9L)
#define PLAT_CLUSTER_PROTECTED (1<<10L)
#define PLAT_VCORE_LP_MODE (1<<11L)
#define PLAT_PMIC_VCORE_SRCLKEN0 (1<<12L)
#define PLAT_PMIC_VCORE_SRCLKEN2 (1<<13L)
#define PLAT_MAINPLL_OFF (1<<27L)
#define PLAT_AP_WDT_RST_MODE (1<<28L)
#define PLAT_MCUSYSOFF_PREPARED (1<<29L)
#define PLAT_GIC_MASKED (1<<30L)
#define PLAT_PROTECTED_FAIL (1<<31L)
#endif
@@ -0,0 +1,137 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
//#include <mtk_lpm_trace.h>
#include <sspm_ipi.h>
#include <mtk_ipi_sspm_v1.h>
#include "mt6779_ipi_sspm.h"
#include "mt6779_common.h"
static int _mt6779_ipi_sspm_send(int flags, unsigned int cmd)
{
int ret;
#if defined(CONFIG_MTK_TINYSYS_SSPM_SUPPORT)
struct plat_spm_data spm_d;
if ((flags == SSPM_NOTIFY_ENTER)
|| (flags == SSPM_NOTIFY_ENTER_ASYNC)) {
spm_d.cmd = (cmd & PLAT_SUSPEND) ?
SSPM_SPM_SUSPEND :
(cmd & PLAT_PMIC_VCORE_SRCLKEN0) ?
SSPM_SPM_ENTER_SODI3 :
(cmd & PLAT_PMIC_VCORE_SRCLKEN2) ?
SSPM_SPM_DPIDLE_ENTER : SSPM_SPM_ENTER_SODI;
} else if ((flags == SSPM_NOTIFY_LEAVE)
|| (flags == SSPM_NOTIFY_LEAVE_ASYNC)) {
spm_d.cmd = (cmd & PLAT_SUSPEND) ?
SSPM_SPM_RESUME :
(cmd & PLAT_PMIC_VCORE_SRCLKEN0) ?
SSPM_SPM_LEAVE_SODI3 :
(cmd & PLAT_PMIC_VCORE_SRCLKEN2) ?
SSPM_SPM_DPIDLE_LEAVE : SSPM_SPM_LEAVE_SODI;
}
spm_d.u.suspend.spm_opt = (cmd & PLAT_VCORE_LP_MODE) ?
PLAT_PWR_OPT_VCORE_LP_MODE : 0;
spm_d.u.suspend.spm_opt |= (cmd & PLAT_XO_UFS_OFF) ?
PLAT_PWR_OPT_XO_UFS_OFF : 0;
spm_d.u.suspend.spm_opt |= (cmd & PLAT_CLKBUF_ENTER_BBLPM) ?
PLAT_PWR_OPT_CLKBUF_ENTER_BBLPM : 0;
if ((flags == SSPM_NOTIFY_ENTER_ASYNC)
|| (flags == SSPM_NOTIFY_LEAVE_ASYNC)) {
ret = -1;
//ret = sspm_ipi_send_async(IPI_ID_SPM_SUSPEND, IPI_OPT_DEFAUT,
// &spm_d, SSPM_SPM_DATA_LEN);
if (ret != 0)
pr_info("[name:spm&]#@# %s(%d) async(cmd:0x%x) ret %d\n",
__func__, __LINE__, spm_d.cmd, ret);
} else {
int ack_data = 0;
ret = -1;
//ret = sspm_ipi_send_sync(IPI_ID_SPM_SUSPEND, IPI_OPT_POLLING,
// &spm_d, SSPM_SPM_DATA_LEN,
// &ack_data, 1);
if (ret != 0)
pr_info("[name:spm&]#@# %s(%d) sync(cmd:0x%x) ret %d\n",
__func__, __LINE__, spm_d.cmd, ret);
else if (ack_data < 0) {
ret = ack_data;
pr_info("[name:spm&]#@# %s(%d) sync cmd:0x%x ret %d\n",
__func__, __LINE__, spm_d.cmd, ret);
}
}
#else
pr_info("[name:spm&]#@# %s(%d) TINYSYS_SSPM_SUPPORT is not support\n",
__func__, __LINE__);
#endif /* if defined(CONFIG_MTK_TINYSYS_SSPM_SUPPORT) */
return ret;
}
static int _mt6779_ipi_sspm_response(int flags, unsigned int cmd)
{
int ret = 0;
#if defined(CONFIG_MTK_TINYSYS_SSPM_SUPPORT)
int ack_data = 0;
if ((flags == SSPM_NOTIFY_ENTER_ASYNC)
|| (flags == SSPM_NOTIFY_LEAVE_ASYNC))
ret = -1;
//ret = sspm_ipi_send_async_wait(IPI_ID_SPM_SUSPEND,
// IPI_OPT_DEFAUT, &ack_data);
else
return 0;
if (ret != 0)
pr_info("[name:spm&]#@# %s(%d) async_wait(cmd:0x%x) ret %d\n",
__func__, __LINE__, cmd, ret);
else if (ack_data < 0) {
ret = ack_data;
pr_info("[name:spm&]#@# %s(%d) async_waitcmd(%d) return %d\n",
__func__, __LINE__, cmd, ret);
}
#else
pr_info("[name:spm&]#@# %s(%d) TINYSYS_SSPM_SUPPORT is not support\n",
__func__, __LINE__);
#endif /* if defined(CONFIG_MTK_TINYSYS_SSPM_SUPPORT) */
return ret;
}
int mt6779_sspm_notify_enter(unsigned int cmd)
{
return _mt6779_ipi_sspm_send(SSPM_NOTIFY_ENTER, cmd);
}
int mt6779_sspm_notify_leave(unsigned int cmd)
{
return _mt6779_ipi_sspm_send(SSPM_NOTIFY_LEAVE, cmd);
}
int mt6779_sspm_notify_ansyc_enter(unsigned int cmd)
{
return _mt6779_ipi_sspm_send(SSPM_NOTIFY_ENTER_ASYNC, cmd);
}
int mt6779_sspm_notify_ansyc_enter_respone(void)
{
return _mt6779_ipi_sspm_response(SSPM_NOTIFY_ENTER_ASYNC, 0);
}
int mt6779_sspm_notify_ansyc_leave(unsigned int cmd)
{
return _mt6779_ipi_sspm_send(SSPM_NOTIFY_LEAVE_ASYNC, cmd);
}
int mt6779_sspm_notify_ansyc_leave_respone(void)
{
return _mt6779_ipi_sspm_response(SSPM_NOTIFY_LEAVE_ASYNC, 0);
}
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MT6779_IPI_SSPM__
#define __MT6779_IPI_SSPM__
int mt6779_sspm_notify_enter(unsigned int cmd);
int mt6779_sspm_notify_leave(unsigned int cmd);
int mt6779_sspm_notify_ansyc_enter(unsigned int cmd);
int mt6779_sspm_notify_ansyc_enter_respone(void);
int mt6779_sspm_notify_ansyc_leave(unsigned int cmd);
int mt6779_sspm_notify_ansyc_leave_respone(void);
#endif
@@ -0,0 +1,341 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_address.h>
#include <linux/cpu.h>
#include <linux/pm_qos.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/time.h>
#include <mtk_lpm.h>
#include <mtk_lp_plat_reg.h>
#include <mtk_lp_plat_apmcu.h>
#include <mtk_lp_plat_apmcu_mbox.h>
void __iomem *cpu_pm_mcusys_base;
void __iomem *cpu_pm_syssram_base;
#define plat_node_ready() (cpu_pm_mcusys_base && cpu_pm_syssram_base)
#define OF_CPU_PM_CTRL(_offset) (cpu_pm_mcusys_base + (_offset))
#define BOOT_TIME_LIMIT 60
static struct task_struct *mtk_lp_plat_task;
/* qos */
static struct pm_qos_request mtk_lp_plat_qos_req;
#define mtk_lp_plat_qos_init()\
pm_qos_add_request(&mtk_lp_plat_qos_req,\
PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE)
#define mtk_cpu_off_block()\
pm_qos_update_request(&mtk_lp_plat_qos_req, 2)
#define mtk_cpu_off_allow()\
pm_qos_update_request(&mtk_lp_plat_qos_req, PM_QOS_DEFAULT_VALUE)
#define mtk_lp_plat_qos_uninit()\
pm_qos_remove_request(&mtk_lp_plat_qos_req)
#define CHK(cond) WARN_ON(cond)
#define PWR_LVL_BIT(v) BIT(4 * v)
#define PWR_LVL_MASK(v) (0xF << (4 * (v)))
#define PWR_LVL0 (PWR_LVL_BIT(0))
#define PWR_LVL1 (PWR_LVL_BIT(1) | PWR_LVL0)
#define PWR_LVL2 (PWR_LVL_BIT(2) | PWR_LVL1)
#define PWR_LVL3 (PWR_LVL_BIT(3) | PWR_LVL2)
#define CORE_LVL PWR_LVL0
#define CLUSTER_LVL PWR_LVL1
#define MCUSYS_LVL PWR_LVL2
#define BUS26M_LVL PWR_LVL3
#define MAX_PWR_LVL MCUSYS_LVL
struct mtk_lp_device {
unsigned int pwr_lvl_mask;
union {
struct {
u32 core:4;
u32 cluster:4;
u32 mcusys:4;
u32 bus26m:4;
};
u32 lvl;
} pwr_on;
struct mtk_lp_device *parent;
};
static struct mtk_lp_device lp_dev_cpu[NR_CPUS];
static struct mtk_lp_device lp_dev_cluster[nr_cluster_ids];
static struct mtk_lp_device lp_dev_mcusys;
static void _mtk_lp_plat_inc_pwr_cnt(struct mtk_lp_device *dev,
unsigned int lvl)
{
unsigned int lvl_cnt;
lvl_cnt = lvl & dev->pwr_lvl_mask;
if (!lvl_cnt)
return;
/**
* Exclusive read-modify-write is ensured by
* mtk_lp_mod_locker in idle flow
* mtk_lp_plat_qos_req in hot-plug flow
*/
dev->pwr_on.lvl += lvl_cnt;
CHK(dev->pwr_on.core >= nr_cpu_ids);
if (dev->parent)
_mtk_lp_plat_inc_pwr_cnt(dev->parent, lvl);
}
static void _mtk_lp_plat_dec_pwr_cnt(struct mtk_lp_device *dev,
unsigned int lvl)
{
unsigned int lvl_cnt;
lvl_cnt = lvl & dev->pwr_lvl_mask;
if (!lvl_cnt)
return;
/**
* Exclusive read-modify-write is ensured by
* mtk_lp_mod_locker in idle flow
* mtk_lp_plat_qos_req in hot-plug flow
*/
dev->pwr_on.lvl -= lvl_cnt;
CHK((dev->pwr_on.lvl & BIT(31)));
if (dev->parent)
_mtk_lp_plat_dec_pwr_cnt(dev->parent, lvl);
}
#define mtk_lp_plat_set_off_lvl(cpu, lvl) \
do { \
if (likely(cpu < nr_cpu_ids)) \
_mtk_lp_plat_dec_pwr_cnt(&lp_dev_cpu[cpu], lvl); \
} while (0)
#define mtk_lp_plat_clr_off_lvl(cpu, lvl) \
do { \
if (likely(cpu < nr_cpu_ids)) \
_mtk_lp_plat_inc_pwr_cnt(&lp_dev_cpu[cpu], lvl); \
} while (0)
void mtk_lp_plat_set_mcusys_off(int cpu)
{
mtk_lp_plat_set_off_lvl(cpu, MCUSYS_LVL);
}
void mtk_lp_plat_clr_mcusys_off(int cpu)
{
mtk_lp_plat_clr_off_lvl(cpu, MCUSYS_LVL);
}
void mtk_lp_plat_set_cluster_off(int cpu)
{
mtk_lp_plat_set_off_lvl(cpu, CLUSTER_LVL);
}
void mtk_lp_plat_clr_cluster_off(int cpu)
{
mtk_lp_plat_clr_off_lvl(cpu, CLUSTER_LVL);
}
static inline void mtk_lp_dev_get_cpus_online(void)
{
int i;
for_each_online_cpu(i)
mtk_lp_plat_clr_off_lvl(i, MAX_PWR_LVL);
}
static void mtk_lp_dev_set_cpus_off(void)
{
int i;
lp_dev_mcusys.pwr_on.lvl = 0;
for (i = 0; i < nr_cluster_ids; i++)
lp_dev_cluster[i].pwr_on.lvl = 0;
for (i = 0; i < nr_cpu_ids; i++)
lp_dev_cpu[i].pwr_on.lvl = 0;
}
bool mtk_lp_plat_is_mcusys_off(void)
{
return !lp_dev_mcusys.pwr_on.mcusys;
}
bool mtk_lp_plat_is_cluster_off(int cpu)
{
if (unlikely(cpu >= nr_cpu_ids || !lp_dev_cpu[cpu].parent))
return false;
return !lp_dev_cpu[cpu].parent->pwr_on.cluster;
}
static int mtk_lp_cpuhp_notify_enter(unsigned int cpu)
{
mtk_cpu_off_block();
return 0;
}
static int mtk_lp_cpuhp_notify_leave(unsigned int cpu)
{
mtk_lp_dev_set_cpus_off();
mtk_lp_dev_get_cpus_online();
mtk_cpu_off_allow();
return 0;
}
static void mtk_lp_plat_cpuhp_init(void)
{
cpuhp_setup_state_nocalls(CPUHP_BP_PREPARE_DYN_END, "cpuidle_cb",
mtk_lp_cpuhp_notify_enter,
mtk_lp_cpuhp_notify_leave);
cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "cpuidle_cb",
mtk_lp_cpuhp_notify_leave,
mtk_lp_cpuhp_notify_enter);
}
static int mtk_lp_plat_wait_depd_condition(void *arg)
{
struct timespec uptime;
bool mcupm_rdy = false;
bool boot_time_pass = false;
mtk_wait_mbox_init_done();
mtk_notify_subsys_ap_ready();
do {
msleep(1000);
if (!mcupm_rdy && mtk_mcupm_is_ready())
mcupm_rdy = true;
if (!boot_time_pass) {
get_monotonic_boottime(&uptime);
if ((unsigned int)uptime.tv_sec > BOOT_TIME_LIMIT)
boot_time_pass = true;
}
} while (!(mcupm_rdy && boot_time_pass));
mtk_cpu_off_allow();
mtk_lp_plat_cpuhp_init();
return 0;
}
static void __init mtk_lp_plat_pwr_dev_init(void)
{
struct mtk_lp_device *dev;
int i, cluster_id;
for (i = 0; i < nr_cpu_ids; i++) {
dev = &lp_dev_cpu[i];
dev->pwr_lvl_mask = PWR_LVL_MASK(0);
cluster_id = get_physical_cluster_id(i);
if (cluster_id < nr_cluster_ids)
dev->parent = &lp_dev_cluster[cluster_id];
}
for (i = 0; i < nr_cluster_ids; i++) {
dev = &lp_dev_cluster[i];
dev->pwr_lvl_mask = PWR_LVL_MASK(1);
dev->parent = &lp_dev_mcusys;
}
lp_dev_mcusys.pwr_lvl_mask = PWR_LVL_MASK(2);
mtk_lp_dev_get_cpus_online();
}
static int __init mtk_lp_plat_mcusys_ctrl_init(void)
{
struct device_node *node = NULL;
cpu_pm_mcusys_base = NULL;
cpu_pm_syssram_base = NULL;
node = of_find_compatible_node(NULL, NULL,
"mediatek,mcusys-ctrl");
if (node) {
cpu_pm_mcusys_base = of_iomap(node, 0);
of_node_put(node);
}
node = of_find_compatible_node(NULL, NULL,
"mediatek,cpupm-sysram");
if (node) {
cpu_pm_syssram_base = of_iomap(node, 0);
of_node_put(node);
}
return plat_node_ready() ? 0 : -1;
}
int __init mtk_lp_plat_apmcu_init(void)
{
if (!plat_node_ready()) {
mtk_lp_plat_qos_uninit();
return 0;
}
mtk_lp_plat_pwr_dev_init();
mtk_lp_plat_task = kthread_create(mtk_lp_plat_wait_depd_condition,
NULL, "mtk_lp_plat_wait_rdy");
if (!IS_ERR(mtk_lp_plat_task))
wake_up_process(mtk_lp_plat_task);
else
pr_notice("Create thread fail @ %s()\n", __func__);
return 0;
}
int __init mtk_lp_plat_apmcu_early_init(void)
{
if (mtk_lp_plat_mcusys_ctrl_init() != 0) {
pr_notice("%s(): Not support\n", __func__);
return 0;
}
mtk_lp_plat_qos_init();
if (cpu_pm_syssram_base) {
memset_io((void __iomem *)
(cpu_pm_syssram_base + LP_PM_SYSRAM_INFO_OFS),
0,
LP_PM_SYSRAM_SIZE - LP_PM_SYSRAM_INFO_OFS);
}
mtk_cpu_off_block();
return 0;
}
@@ -0,0 +1,187 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/workqueue.h>
#include <linux/delay.h>
#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT
#include <sspm_common.h>
#include <sspm_mbox.h>
#endif
#include <mtk_lp_plat_apmcu_mbox.h>
struct mbox_ops {
void (*write)(int id, int *buf, unsigned int len);
void (*read)(int id, int *buf, unsigned int len);
};
static void apmcu_sspm_mailbox_write(int id, int *buf, unsigned int len)
{
#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT
//if (is_sspm_ready())
// sspm_mbox_write(APMCU_SSPM_MBOX_ID, id, (void *)buf, len);
#endif
}
static void apmcu_sspm_mailbox_read(int id, int *buf, unsigned int len)
{
#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT
//if (is_sspm_ready())
// sspm_mbox_read(APMCU_SSPM_MBOX_ID, id, (void *)buf, len);
#endif
}
static void apmcu_mcupm_mailbox_write(int id, int *buf, unsigned int len)
{
#ifdef CONFIG_MTK_TINYSYS_MCUPM_SUPPORT
mcupm_mbox_write(APMCU_MCUPM_MBOX_ID, id, (void *)buf, len);
#endif
}
static void apmcu_mcupm_mailbox_read(int id, int *buf, unsigned int len)
{
#ifdef CONFIG_MTK_TINYSYS_MCUPM_SUPPORT
mcupm_mbox_read(APMCU_MCUPM_MBOX_ID, id, (void *)buf, len);
#endif
}
static struct mbox_ops mbox[NF_MBOX] = {
[MBOX_SSPM] = {
.write = apmcu_sspm_mailbox_write,
.read = apmcu_sspm_mailbox_read
},
[MBOX_MCUPM] = {
.write = apmcu_mcupm_mailbox_write,
.read = apmcu_mcupm_mailbox_read
},
};
void mtk_set_sspm_lp_cmd(void *buf)
{
mbox[MBOX_SSPM].write(APMCU_SSPM_MBOX_SPM_CMD,
(int *)buf,
APMCU_SSPM_MBOX_SPM_CMD_SIZE);
}
void mtk_clr_sspm_lp_cmd(void)
{
int buf[APMCU_SSPM_MBOX_SPM_CMD_SIZE] = {0};
mbox[MBOX_SSPM].write(APMCU_SSPM_MBOX_SPM_CMD,
(int *)buf,
APMCU_SSPM_MBOX_SPM_CMD_SIZE);
}
void mtk_mcupm_pwr_ctrl_en(int dev)
{
unsigned int en_mask = 0;
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_PWR_CTRL_EN, &en_mask, 1);
en_mask |= (dev & MCUPM_PWR_CTRL_MASK);
mbox[MBOX_MCUPM].write(APMCU_MCUPM_MBOX_PWR_CTRL_EN, &en_mask, 1);
}
EXPORT_SYMBOL(mtk_mcupm_pwr_ctrl_en);
void mtk_mcupm_pwr_ctrl_dis(int dev)
{
unsigned int en_mask = 0;
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_PWR_CTRL_EN, &en_mask, 1);
en_mask &= ~(dev & MCUPM_PWR_CTRL_MASK);
mbox[MBOX_MCUPM].write(APMCU_MCUPM_MBOX_PWR_CTRL_EN, &en_mask, 1);
}
EXPORT_SYMBOL(mtk_mcupm_pwr_ctrl_dis);
void mtk_set_mcupm_pll_mode(unsigned int mode)
{
if (mode < NF_MCUPM_ARMPLL_MODE)
mbox[MBOX_MCUPM].write(APMCU_MCUPM_MBOX_ARMPLL_MODE, &mode, 1);
}
EXPORT_SYMBOL(mtk_set_mcupm_pll_mode);
int mtk_get_mcupm_pll_mode(void)
{
int mode = 0;
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_ARMPLL_MODE, &mode, 1);
return mode;
}
EXPORT_SYMBOL(mtk_get_mcupm_pll_mode);
void mtk_set_mcupm_buck_mode(unsigned int mode)
{
if (mode < NF_MCUPM_BUCK_MODE)
mbox[MBOX_MCUPM].write(APMCU_MCUPM_MBOX_BUCK_MODE, &mode, 1);
}
EXPORT_SYMBOL(mtk_set_mcupm_buck_mode);
int mtk_get_mcupm_buck_mode(void)
{
int mode = 0;
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_BUCK_MODE, &mode, 1);
return mode;
}
EXPORT_SYMBOL(mtk_get_mcupm_buck_mode);
void mtk_set_preferred_cpu_wakeup(int cpu)
{
if (cpu_online(cpu))
mbox[MBOX_MCUPM].write(APMCU_MCUPM_MBOX_WAKEUP_CPU, &cpu, 1);
}
int mtk_get_preferred_cpu_wakeup(void)
{
int cpu = -1;
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_WAKEUP_CPU, &cpu, 1);
return cpu;
}
bool mtk_mcupm_is_ready(void)
{
int sta = MCUPM_TASK_INIT_FINISH;
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_TASK_STA, &sta, 1);
return sta == MCUPM_TASK_WAIT || sta == MCUPM_TASK_INIT_FINISH;
}
void mtk_wait_mbox_init_done(void)
{
int sta = MCUPM_TASK_INIT;
while (1) {
mbox[MBOX_MCUPM].read(APMCU_MCUPM_MBOX_TASK_STA, &sta, 1);
if (sta == MCUPM_TASK_INIT)
break;
msleep(1000);
}
mtk_set_mcupm_pll_mode(MCUPM_ARMPLL_OFF);
mtk_set_mcupm_buck_mode(MCUPM_BUCK_OFF_MODE);
mtk_mcupm_pwr_ctrl_en(MCUPM_MCUSYS_CTRL);
/* mtk_mcupm_pwr_ctrl_en(MCUPM_BUCK_CTRL); */
/* mtk_mcupm_pwr_ctrl_en(MCUPM_ARMPLL_CTRL); */
}
void mtk_notify_subsys_ap_ready(void)
{
int ready = 1;
mbox[MBOX_SSPM].write(APMCU_SSPM_MBOX_AP_READY, &ready, 1);
mbox[MBOX_MCUPM].write(APMCU_MCUPM_MBOX_AP_READY, &ready, 1);
}
@@ -0,0 +1,100 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/cpuidle.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/cpu_pm.h>
#include <linux/syscore_ops.h>
#include <asm/cpuidle.h>
#include <asm/suspend.h>
#include <mtk_lpm.h>
#include <mtk_lpm_module.h>
#include <mtk_lpm_call.h>
#include <mtk_lpm_type.h>
#include <mtk_lpm_call_type.h>
#include "mt6779.h"
#include "mt6779_suspend.h"
unsigned int mt6779_suspend_status;
static inline int mt6779_suspend_common_enter(unsigned int *susp_status)
{
unsigned int status = PLAT_VCORE_LP_MODE
| PLAT_PMIC_VCORE_SRCLKEN0
| PLAT_SUSPEND;
/* maybe need to stop sspm/mcupm mcdi task here */
if (susp_status)
*susp_status = status;
return 0;
}
static inline int mt6779_suspend_common_resume(unsigned int susp_status)
{
/* Implement suspend common flow here */
return 0;
}
int mt6779_suspend_prompt(int cpu, const struct mtk_lpm_issuer *issuer)
{
int ret = 0;
unsigned int spm_res = 0;
mt6779_suspend_status = 0;
pr_info("[name:spm&][%s:%d] - prepare suspend enter\n",
__func__, __LINE__);
ret = mt6779_suspend_common_enter(&mt6779_suspend_status);
if (ret)
goto PLAT_LEAVE_SUSPEND;
/* Legacy SSPM flow, spm sw resource request flow */
mt6779_do_mcusys_prepare_pdn(mt6779_suspend_status, &spm_res);
pr_info("[name:spm&][%s:%d] - suspend enter\n",
__func__, __LINE__);
PLAT_LEAVE_SUSPEND:
return ret;
}
void mt6779_suspend_reflect(int cpu,
const struct mtk_lpm_issuer *issuer)
{
pr_info("[name:spm&][%s:%d] - prepare suspend resume\n",
__func__, __LINE__);
mt6779_suspend_common_resume(mt6779_suspend_status);
mt6779_do_mcusys_prepare_on();
pr_info("[name:spm&][%s:%d] - suspend resume\n",
__func__, __LINE__);
if (issuer)
issuer->log(MT_LPM_ISSUER_CPUIDLE, "SUSPEND", NULL);
}
struct mtk_lpm_model mt6779_model_suspend = {
.flag = MTK_LP_REQ_NONE,
.op = {
.prompt = mt6779_suspend_prompt,
.reflect = mt6779_suspend_reflect,
}
};
int __init mt6779_model_suspend_init(void)
{
mtk_lpm_suspend_registry("suspend", &mt6779_model_suspend);
return 0;
}
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MT6779_SUSPEND_H__
#define __MT6779_SUSPEND_H__
int mt6779_model_suspend_init(void);
#endif