diff --git a/drivers/misc/mediatek/thermal/Makefile b/drivers/misc/mediatek/thermal/Makefile index 917e58969add..e284eb1fb74f 100644 --- a/drivers/misc/mediatek/thermal/Makefile +++ b/drivers/misc/mediatek/thermal/Makefile @@ -47,13 +47,16 @@ ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/ ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(PDIR) ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/ ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/gpufreq_v1/ +ccflags-y += -I$(srctree)/drivers/misc/mediatek/flashlight/ obj-y += mtk_thermal_monitor.o obj-y += mtk_cooler_shutdown.o ifeq ($(CONFIG_MTK_LEDS), y) # setMaxbrightness() defined in mediatek/kernel/drivers/leds/leds_drv.c only built when CONFIG_MTK_LEDS is set - obj-y += mtk_cooler_backlight.o + # obj-y += mtk_cooler_backlight.o + obj-y += mtk_cooler_backlight_cus.o endif +obj-y += mtk_cooler_flashlight_cus.o obj-y += mtk_cooler_kshutdown.o obj-y += mtk_cooler_cam.o diff --git a/drivers/misc/mediatek/thermal/common/coolers/Makefile b/drivers/misc/mediatek/thermal/common/coolers/Makefile index 140cc372930b..0eb6bd08a5ec 100644 --- a/drivers/misc/mediatek/thermal/common/coolers/Makefile +++ b/drivers/misc/mediatek/thermal/common/coolers/Makefile @@ -38,6 +38,7 @@ ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/ ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/ ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/ppm_v3/src/mach/$(PDIR) +ccflags-y += -I$(srctree)/drivers/power/supply/ ccflags-y += -I$(srctree)/drivers/misc/mediatek/video/include ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/ged/include ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ @@ -92,6 +93,7 @@ obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_v1.o ifeq ($(CONFIG_MTK_DUAL_CHARGER_SUPPORT),y) obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_2nd.o endif + obj-$(CONFIG_THERMAL) += mtk_cooler_atm.o obj-$(CONFIG_THERMAL) += mtk_cooler_dtm.o obj-$(CONFIG_THERMAL) += mtk_cooler_sysrst.o @@ -108,13 +110,14 @@ endif ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_v1.o obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_2nd.o + obj-$(CONFIG_THERMAL) += mtk_cooler_atm.o obj-$(CONFIG_THERMAL) += mtk_cooler_dtm.o obj-$(CONFIG_THERMAL) += mtk_cooler_sysrst.o obj-$(CONFIG_THERMAL) += mtk_cooler_VR_FPS.o endif -ifneq (,$(filter $(CONFIG_MTK_PLATFORM), "mt6785")) +ifneq (,$(filter $(CONFIG_MTK_PLATFORM), "mt6785" "mt6781")) ifeq ($(CONFIG_MTK_THERMAL_PA_VIA_ATCMD),y) obj-$(CONFIG_THERMAL) += mtk_cooler_mutt.o endif @@ -123,6 +126,12 @@ ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_v2.o obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_2nd.o + +obj-$(CONFIG_THERMAL) += mtk_cooler_gpu_cus.o +ifeq ($(CONFIG_MTK_VPU_SUPPORT),y) + obj-$(CONFIG_THERMAL) += mtk_cooler_vpu_cus.o +endif +obj-$(CONFIG_THERMAL) += mtk_cooler_char_curr_cus.o obj-$(CONFIG_THERMAL) += mtk_cooler_atm.o obj-$(CONFIG_THERMAL) += mtk_cooler_dtm.o obj-$(CONFIG_THERMAL) += mtk_cooler_sysrst.o @@ -137,7 +146,6 @@ endif obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_v1.o obj-$(CONFIG_THERMAL) += mtk_cooler_bcct_2nd.o - obj-$(CONFIG_THERMAL) += mtk_cooler_atm.o obj-$(CONFIG_THERMAL) += mtk_cooler_dtm.o obj-$(CONFIG_THERMAL) += mtk_cooler_sysrst.o diff --git a/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_atm.c b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_atm.c index be4f3d0e3f29..d1bcb456edbe 100644 --- a/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_atm.c +++ b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_atm.c @@ -3851,6 +3851,71 @@ static int krtatm_thread(void *arg) } #endif /* FAST_RESPONSE_ATM */ +static void init_ctm_param(void) +{ + int t_K_SUM_TT_HIGH = CLCTM_TT_HIGH; + int t_K_SUM_TT_LOW = CLCTM_TT_LOW; + int t_CATMP_STEADY_TTJ_DELTA = CLCTM_STEADY_TTJ_DELTA; + + ctm_on = CLATM_INIT_CFG_CATM; /* 2: cATM+, 1: cATMv1, 0: off */ + + MAX_TARGET_TJ = CLCTM_TARGET_TJ; + STEADY_TARGET_TJ = CLCTM_TARGET_TJ; + TRIP_TPCB = CLCTM_TPCB_1; + STEADY_TARGET_TPCB = CLCTM_TPCB_2; + MAX_EXIT_TJ = CLCTM_EXIT_TJ; + STEADY_EXIT_TJ = CLCTM_EXIT_TJ; + + COEF_AE = CLCTM_AE; + COEF_BE = CLCTM_BE; + COEF_AX = CLCTM_AX; + COEF_BX = CLCTM_BX; + +#if defined(CATM_TPCB_EXTEND) + if (g_turbo_bin && (STEADY_TARGET_TPCB >= 52000)) { + if (t_TPCB_EXTEND > 0 && t_TPCB_EXTEND < 10000) { + TRIP_TPCB += t_TPCB_EXTEND; + STEADY_TARGET_TPCB += t_TPCB_EXTEND; + COEF_AE = STEADY_TARGET_TJ + + (STEADY_TARGET_TPCB * COEF_BE) / 1000; + COEF_AX = STEADY_EXIT_TJ + + (STEADY_TARGET_TPCB * COEF_BX) / 1000; + TPCB_EXTEND = t_TPCB_EXTEND; + } + } +#endif + + /* +++ cATM+ parameters +++ */ + if (ctm_on == 2) { + if (t_K_SUM_TT_HIGH >= 0 + && t_K_SUM_TT_HIGH < MAX_K_SUM_TT) + K_SUM_TT_HIGH = t_K_SUM_TT_HIGH; + if (t_K_SUM_TT_LOW >= 0 + && t_K_SUM_TT_LOW < MAX_K_SUM_TT) + K_SUM_TT_LOW = t_K_SUM_TT_LOW; + if (t_CATMP_STEADY_TTJ_DELTA >= 0) + CATMP_STEADY_TTJ_DELTA = + t_CATMP_STEADY_TTJ_DELTA; + catmplus_update_params(); + } + /* --- cATM+ parameters --- */ + + /* --- SPA parameters --- */ + thermal_spa_t.t_spa_Tpolicy_info.steady_target_tj = + STEADY_TARGET_TJ; + + thermal_spa_t.t_spa_Tpolicy_info.steady_exit_tj = + STEADY_EXIT_TJ; + +#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT +#if THERMAL_ENABLE_TINYSYS_SSPM && CPT_ADAPTIVE_AP_COOLER && \ + PRECISE_HYBRID_POWER_BUDGET && CONTINUOUS_TM + atm_update_catm_param_to_sspm(); +#endif +#endif + +} + static int __init mtk_cooler_atm_init(void) { int err = 0; @@ -3923,6 +3988,7 @@ static int __init mtk_cooler_atm_init(void) #if 0 reset_gpu_power_history(); #endif + init_ctm_param(); tscpu_dprintk("%s: end\n", __func__); return 0; } diff --git a/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_char_curr_cus.c b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_char_curr_cus.c new file mode 100644 index 000000000000..c8802f77244f --- /dev/null +++ b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_char_curr_cus.c @@ -0,0 +1,333 @@ +/* + * Copyright (C) 2019 MediaTek Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifdef pr_fmt +#undef pr_fmt +#endif +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mt-plat/mtk_thermal_monitor.h" +#if (CONFIG_MTK_GAUGE_VERSION == 30) +#include +#include +#include +#else +#include +#include +#endif + +#if (CONFIG_MTK_GAUGE_VERSION == 30) +static struct charger_consumer *thm_chr_consumer; +#endif + +/*#define CHAR_CURR_INTERVAL 200 interval 200mA */ +#define CHAR_CURR_TABLE_INDEX 16 + +#define mtk_cooler_char_curr_dprintk(fmt, args...) \ + pr_notice("thermal/cooler/char_curr " fmt, ##args) + +static struct thermal_cooling_device +*cl_char_curr_dev = { 0 }; +static unsigned int g_cl_id; +static unsigned int g_char_curr_level; +static unsigned int g_thm_en_charging; +static unsigned int max_char_curr_index; + +/* char_curr_t = charging current table + * -1 : unlimit charging current + * 0 : stop charging + * positive integer: charging current limit (unit: mA) + */ +static int char_curr_t[CHAR_CURR_TABLE_INDEX] = { + -1, 2800, 2600, 2400, 2200, + 2000, 1800, 1600, 1400, 1200, + 1000, 800, 600, 400, 200, + 0 +}; + +static int _cl_char_curr_read(struct seq_file *m, void *v) +{ + int i = 0; + + mtk_cooler_char_curr_dprintk("%s\n", __func__); + seq_printf(m, "charger_current state=%d max=%d\n", + g_char_curr_level, max_char_curr_index); + seq_puts(m, "[index, current]\n"); + for (i = 0; i < max_char_curr_index; i++) + seq_printf(m, "(%4d, %4d)\n", i, char_curr_t[i]); + + return 0; +} + +static int _cl_char_curr_open(struct inode *inode, struct file *file) +{ + return single_open(file, _cl_char_curr_read, PDE_DATA(inode)); +} + +static const struct file_operations _cl_char_curr_fops = { + .owner = THIS_MODULE, + .open = _cl_char_curr_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + + + + +static int mtk_cl_char_curr_get_max_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = max_char_curr_index - 1; + return 0; +} + + static int mtk_cl_char_curr_get_cur_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = g_char_curr_level; + return 0; +} + +static int mtk_cl_char_curr_set_cur_state +(struct thermal_cooling_device *cdev, unsigned long state) +{ + int chr_input_curr_limit = 0; + +#if (CONFIG_MTK_GAUGE_VERSION == 30) + if (state >= max_char_curr_index || state < 0) { + mtk_cooler_char_curr_dprintk("%s: wrong state=%d %d\n", + __func__, (int)state, max_char_curr_index); + } else { + g_char_curr_level = state; + + if (g_char_curr_level == 0) { + chr_input_curr_limit = -1;/* unlimit input current*/ + } else { + chr_input_curr_limit = + char_curr_t[g_char_curr_level] * 1000; + } + + if (chr_input_curr_limit != 0) { + charger_manager_set_input_current_limit( + thm_chr_consumer, 0, chr_input_curr_limit); + mtk_cooler_char_curr_dprintk("%s: l=%d curr=%d\n", + __func__, g_char_curr_level, + chr_input_curr_limit); + + if (g_thm_en_charging == 0) { + g_thm_en_charging = 1; + charger_manager_enable_power_path( + thm_chr_consumer, 0, + g_thm_en_charging); + mtk_cooler_char_curr_dprintk( + "%s: en_charging = %d\n", + __func__, g_thm_en_charging); + } + } else if (chr_input_curr_limit == 0 && g_thm_en_charging) { + g_thm_en_charging = 0; + charger_manager_enable_power_path(thm_chr_consumer, 0, + g_thm_en_charging); + } + } +#endif + return 0; +} + +#if 0 +static int update_char_curr_table(void) +{ + int input_curr = 0, ret = 0, curr_opp, i; +#if 0 + + mutex_lock(thm_chr_mutex); + + ret = charger_manager_get_input_current_limit( + thm_chr_consumer, 0, &input_curr); + mtk_cooler_char_curr_dprintk("%d\n", input_curr); + input_curr /= 1000;/*uA to mA*/ + + if (!ret) { + max_char_curr_index = 0; + memset(char_curr_t, 0, sizeof(char_curr_t)); + curr_opp = input_curr; + for (i = 0; curr_opp > 0; i++) { + max_char_curr_index = i; + char_curr_t[i] = curr_opp; + curr_opp -= CHAR_CURR_INTERVAL; + if (i == CHAR_CURR_TABLE_INDEX - 2) { + i++; + break; + } + } + max_char_curr_index = i; + char_curr_t[i] = 0; + } else { + max_char_curr_index = 0; + memset(char_curr_t, 0, sizeof(char_curr_t)); + mtk_cooler_char_curr_dprintk( + "%s: can't get intput current ret = %d\n", + __func__, ret); + } + + mutex_unlock(thm_chr_mutex); +#else + char_curr_t[0] = -1;/* max current */ + for (i = 0; i < CHAR_CURR_TABLE_INDEX - 1; i++) + char_curr_t[CHAR_CURR_TABLE_INDEX - i - 1] = + i * CHAR_CURR_INTERVAL; +#endif + return ret; +} +#endif + +#if 0 +static int mtk_cl_char_curr_get_available +(struct thermal_cooling_device *cdev, char *available) +{ + int len = 0, i; + + for (i = 0; i < max_char_curr_index; i++) + len += snprintf(available + len, 20, "%d %d\n", + i, char_curr_t[i]); + mtk_cooler_char_curr_dprintk("%s\n", available); + + return 0; +} +#endif +#if (CONFIG_MTK_GAUGE_VERSION == 30) +static int mtkcooler_char_curr_pdrv_probe(struct platform_device *pdev) +{ + mtk_cooler_char_curr_dprintk("%s\n", __func__); + thm_chr_consumer = charger_manager_get_by_name(&pdev->dev, "charger"); + + return 0; +} + +static int mtkcooler_char_curr_pdrv_remove(struct platform_device *pdev) +{ + return 0; +} + +struct platform_device mtk_cooler_char_curr_device = { + .name = "mtk-cooler-char_curr", + .id = -1, +}; + +static struct platform_driver mtk_cooler_char_curr_driver = { + .probe = mtkcooler_char_curr_pdrv_probe, + .remove = mtkcooler_char_curr_pdrv_remove, + .driver = { + .name = "mtk-cooler-char_curr", + .owner = THIS_MODULE, + }, +}; +static int __init mtkcooler_char_curr_late_init(void) +{ + int ret = 0; + + /* register platform device/driver */ + ret = platform_device_register(&mtk_cooler_char_curr_device); + if (ret) { + mtk_cooler_char_curr_dprintk( + "fail to register device @ %s()\n", + __func__); + goto fail; + } + + ret = platform_driver_register(&mtk_cooler_char_curr_driver); + if (ret) { + mtk_cooler_char_curr_dprintk( + "fail to register driver @ %s()\n", + __func__); + goto reg_platform_driver_fail; + } + + return ret; + +reg_platform_driver_fail: + platform_device_unregister(&mtk_cooler_char_curr_device); + +fail: + return ret; +} +#endif + +static struct thermal_cooling_device_ops mtk_cl_char_curr_ops = { + .get_max_state = mtk_cl_char_curr_get_max_state, + .get_cur_state = mtk_cl_char_curr_get_cur_state, + .set_cur_state = mtk_cl_char_curr_set_cur_state, + //.get_available = mtk_cl_char_curr_get_available, +}; + +static int mtk_cooler_char_curr_register_ltf(void) +{ + mtk_cooler_char_curr_dprintk("%s\n", __func__); + + g_cl_id = 0; + cl_char_curr_dev = mtk_thermal_cooling_device_register + ("mtk-cl-char_curr", (void *)&g_cl_id, + &mtk_cl_char_curr_ops); + + return 0; +} + +static void mtk_cooler_char_curr_unregister_ltf(void) +{ + mtk_cooler_char_curr_dprintk("%s\n", __func__); + + if (cl_char_curr_dev) { + mtk_thermal_cooling_device_unregister(cl_char_curr_dev); + cl_char_curr_dev = NULL; + } +} + +static int __init mtk_cooler_char_curr_init(void) +{ + int err = 0; + + err = mtk_cooler_char_curr_register_ltf(); + if (err) + goto err_unreg; + + proc_create("thm_char_curr", 0444, NULL, &_cl_char_curr_fops); + max_char_curr_index = CHAR_CURR_TABLE_INDEX; + g_thm_en_charging = 1; + + return 0; + +err_unreg: + mtk_cooler_char_curr_unregister_ltf(); + return err; +} + +static void __exit mtk_cooler_char_curr_exit(void) +{ + mtk_cooler_char_curr_unregister_ltf(); +} +module_init(mtk_cooler_char_curr_init); +module_exit(mtk_cooler_char_curr_exit); +#if (CONFIG_MTK_GAUGE_VERSION == 30) +late_initcall(mtkcooler_char_curr_late_init); +#endif diff --git a/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_gpu_cus.c b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_gpu_cus.c new file mode 100644 index 000000000000..06e4516c1fad --- /dev/null +++ b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_gpu_cus.c @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2019 MediaTek Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifdef pr_fmt +#undef pr_fmt +#endif +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + + +#include +#include +#include +#include +#include + +#include "mt-plat/mtk_thermal_monitor.h" +#include +#include "mtk_gpufreq.h" + + +#define mtk_cooler_gpu_dprintk(fmt, args...) \ + pr_notice("thermal/cooler/gpu " fmt, ##args) + +static struct thermal_cooling_device +*cl_gpu_dev = { 0 }; +static unsigned int g_cl_id; +static unsigned int g_gpu_level; + +static int mtk_cl_gpu_get_max_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = Num_of_GPU_OPP - gpu_max_opp - 1; + return 0; +} + + static int mtk_cl_gpu_get_cur_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = g_gpu_level; + return 0; +} + +static int mtk_cl_gpu_set_cur_state +(struct thermal_cooling_device *cdev, unsigned long state) +{ + if (mtk_gpu_power != NULL && state >= 0 && state < Num_of_GPU_OPP - gpu_max_opp) { + g_gpu_level = state; + if (g_gpu_level == 0) + mtk_cooler_gpu_dprintk("%d\n", g_gpu_level); + else { + mtk_cooler_gpu_dprintk("%d %d %d\n", g_gpu_level, + mtk_gpu_power[g_gpu_level + gpu_max_opp].gpufreq_khz, + mtk_gpu_power[g_gpu_level + gpu_max_opp].gpufreq_power); + } + + mt_gpufreq_thermal_protect((g_gpu_level == 0) ? 0 : + mtk_gpu_power[g_gpu_level + gpu_max_opp].gpufreq_power); + } else { + mtk_cooler_gpu_dprintk("%s: mtk_gpu_power_table=%p, state=%lu, GPU_OPP=%d\n", + __func__, mtk_gpu_power, state, Num_of_GPU_OPP - gpu_max_opp); + } + + return 0; +} + +#if 0 +static int mtk_cl_gpu_get_available +(struct thermal_cooling_device *cdev, char *available) +{ + int i = 0, len = 0; + + if (mtk_gpu_power != NULL) { + for (i = 0; i < Num_of_GPU_OPP - gpu_max_opp; i++) { + len += snprintf(available+len, 256, "%d %u %u\n", i, mtk_gpu_power[i + gpu_max_opp].gpufreq_khz, mtk_gpu_power[i+gpu_max_opp].gpufreq_power); + mtk_cooler_gpu_dprintk("len=%d\n", len); + mtk_cooler_gpu_dprintk("%u %u\n", mtk_gpu_power[i + gpu_max_opp].gpufreq_khz, mtk_gpu_power[i + gpu_max_opp].gpufreq_power); + } + } else + mtk_cooler_gpu_dprintk("%s: not gpu_power table\n", __func__); + + return 0; +} +#endif + +/* bind fan callbacks to fan device */ +static struct thermal_cooling_device_ops mtk_cl_gpu_ops = { + .get_max_state = mtk_cl_gpu_get_max_state, + .get_cur_state = mtk_cl_gpu_get_cur_state, + .set_cur_state = mtk_cl_gpu_set_cur_state, +//.get_available = mtk_cl_gpu_get_available, +}; + +static int mtk_cooler_gpu_register_ltf(void) +{ + mtk_cooler_gpu_dprintk("%s\n", __func__); + + g_cl_id = 0; + cl_gpu_dev = mtk_thermal_cooling_device_register + ("mtk-cl-gpu", (void *)&g_cl_id, + &mtk_cl_gpu_ops); + + return 0; +} + +static void mtk_cooler_gpu_unregister_ltf(void) +{ + mtk_cooler_gpu_dprintk("%s\n", __func__); + + if (cl_gpu_dev) { + mtk_thermal_cooling_device_unregister(cl_gpu_dev); + cl_gpu_dev = NULL; + } +} + +static int __init mtk_cooler_gpu_init(void) +{ + int err = 0; + + err = mtk_cooler_gpu_register_ltf(); + if (err) + goto err_unreg; + + return 0; + +err_unreg: + mtk_cooler_gpu_unregister_ltf(); + return err; +} + +static void __exit mtk_cooler_gpu_exit(void) +{ + mtk_cooler_gpu_unregister_ltf(); +} +module_init(mtk_cooler_gpu_init); +module_exit(mtk_cooler_gpu_exit); diff --git a/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_vpu_cus.c b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_vpu_cus.c new file mode 100644 index 000000000000..f5c6df4a7861 --- /dev/null +++ b/drivers/misc/mediatek/thermal/common/coolers/mtk_cooler_vpu_cus.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2019 MediaTek Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifdef pr_fmt +#undef pr_fmt +#endif +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + + +#include +#include +#include +#include +#include + +#include "mt-plat/mtk_thermal_monitor.h" +#include +#include "vpu_dvfs.h" + +#define mtk_cooler_vpu_dprintk(fmt, args...) \ + pr_notice("thermal/cooler/vpu " fmt, ##args) + +static struct thermal_cooling_device +*cl_vpu_dev = { 0 }; +static unsigned int g_cl_id; +static unsigned int g_vpu_level; + +static int mtk_cl_vpu_get_max_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + mtk_cooler_vpu_dprintk("%s\n", __func__); + *state = VPU_OPP_NUM - 1; + return 0; +} + + static int mtk_cl_vpu_get_cur_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + mtk_cooler_vpu_dprintk("%s\n", __func__); + + *state = g_vpu_level; + return 0; +} + +static int mtk_cl_vpu_set_cur_state +(struct thermal_cooling_device *cdev, unsigned long state) +{ + if (g_vpu_opp_table != NULL) { + if (state >= 0 && state < VPU_OPP_NUM) + g_vpu_level = state; + if (g_vpu_level != 0) + vpu_thermal_en_throttle_cb(0xff, g_vpu_level); + else + vpu_thermal_dis_throttle_cb(); + } else + mtk_cooler_vpu_dprintk( + "%s: vpu_power table = NULL\n", __func__); + + return 0; +} + +#if 0 +static int mtk_cl_vpu_get_available +(struct thermal_cooling_device *cdev, char *available) +{ + int i = 0, len = 0; + + if (g_vpu_opp_table != NULL) { + for (i = 0; i < VPU_OPP_NUM; i++) + len += snprintf(available+len, 256, "%d %d\n", + i, g_vpu_opp_table[i]); + } else + mtk_cooler_vpu_dprintk( + "%s: vpu_power table = NULL\n", __func__); + + return 0; +} +#endif + +/* bind fan callbacks to fan device */ +static struct thermal_cooling_device_ops mtk_cl_vpu_ops = { + .get_max_state = mtk_cl_vpu_get_max_state, + .get_cur_state = mtk_cl_vpu_get_cur_state, + .set_cur_state = mtk_cl_vpu_set_cur_state, + //.get_available = mtk_cl_vpu_get_available, +}; + +static int mtk_cooler_vpu_register_ltf(void) +{ + mtk_cooler_vpu_dprintk("%s\n", __func__); + + g_cl_id = 0; + cl_vpu_dev = mtk_thermal_cooling_device_register + ("mtk-cl-vpu", (void *)&g_cl_id, + &mtk_cl_vpu_ops); + + return 0; +} + +static void mtk_cooler_vpu_unregister_ltf(void) +{ + if (cl_vpu_dev) { + mtk_thermal_cooling_device_unregister(cl_vpu_dev); + cl_vpu_dev = NULL; + } +} + +static int __init mtk_cooler_vpu_init(void) +{ + int err = 0; + + err = mtk_cooler_vpu_register_ltf(); + if (err) + goto err_unreg; + + return 0; + +err_unreg: + mtk_cooler_vpu_unregister_ltf(); + return err; +} + +static void __exit mtk_cooler_vpu_exit(void) +{ + mtk_cooler_vpu_unregister_ltf(); +} +module_init(mtk_cooler_vpu_init); +module_exit(mtk_cooler_vpu_exit); diff --git a/drivers/misc/mediatek/thermal/common/coolers/mtk_ta.c b/drivers/misc/mediatek/thermal/common/coolers/mtk_ta.c index ca6eb19dee6f..d72b6934b03e 100644 --- a/drivers/misc/mediatek/thermal/common/coolers/mtk_ta.c +++ b/drivers/misc/mediatek/thermal/common/coolers/mtk_ta.c @@ -522,7 +522,7 @@ static int __init ta_init(void) g_tad_pid = 0; init_flag = false; - g_tad_ttj = 0; + g_tad_ttj = CLCTM_TARGET_TJ; g_ta_status = 0; /*add by willcai for the userspace to kernelspace*/ diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c index 542176b51384..362fe84e8a9f 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c @@ -423,7 +423,7 @@ struct thermal_cooling_device *cdev, unsigned long state) /* To trigger data abort to reset the system * for thermal protection. */ - BUG(); + //BUG(); } return 0; } diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_blk_ntc.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_blk_ntc.c new file mode 100644 index 000000000000..47271d9c58ed --- /dev/null +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_blk_ntc.c @@ -0,0 +1,1425 @@ +/* + * Copyright (C) 2017 MediaTek Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "mt-plat/mtk_thermal_monitor.h" +#include "mach/mtk_thermal.h" +#include "mtk_thermal_timer.h" +#include "mt-plat/mtk_thermal_platform.h" +#include +#include +#include + + +/*============================================================= + *Weak functions + *============================================================= + */ +int __attribute__ ((weak)) +IMM_IsAdcInitReady(void) +{ + pr_notice("E_WF: %s doesn't exist\n", __func__); + return 0; +} +int __attribute__ ((weak)) +IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata) +{ + pr_notice("E_WF: %s doesn't exist\n", __func__); + return -1; +} +/*=============================================================*/ +static kuid_t uid = KUIDT_INIT(0); +static kgid_t gid = KGIDT_INIT(1000); +static DEFINE_SEMAPHORE(sem_mutex); + +static unsigned int interval = 1; /* seconds, 0 : no auto polling */ +static int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, + 70000, 65000, 60000, 55000, 50000 }; + +static struct thermal_zone_device *thz_dev; +//static int mtkts_blkntc_debug_log = 1; +static int kernelmode; +static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +static int num_trip; +static char g_bind0[20] = "mtkts_blkntc-sysrst"; +static char g_bind1[20] = { 0 }; +static char g_bind2[20] = { 0 }; +static char g_bind3[20] = { 0 }; +static char g_bind4[20] = { 0 }; +static char g_bind5[20] = { 0 }; +static char g_bind6[20] = { 0 }; +static char g_bind7[20] = { 0 }; +static char g_bind8[20] = { 0 }; +static char g_bind9[20] = { 0 }; + +/** + * If curr_temp >= polling_trip_temp1, use interval + * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, + * use interval*polling_factor1 + * else, use interval*polling_factor2 + */ +static int polling_trip_temp1 = 40000; +static int polling_trip_temp2 = 20000; +static int polling_factor1 = 5000; +static int polling_factor2 = 10000; + +#define MTKTS_BLKNTC_TEMP_CRIT 60000 /* customer need modify /60.000 degree Celsius */ + +#define mtkts_blkntc_dprintk(fmt, args...) \ +do { \ + if (1) { \ + pr_debug("[Thermal/TZ/BLKNTC]" fmt, ##args); \ + } \ +} while (0) + + +#define mtkts_blkntc_printk(fmt, args...) \ +pr_debug("[Thermal/TZ/BLKNTC]" fmt, ##args) + + +/* #define INPUT_PARAM_FROM_USER_AP */ + +/* + * kernel fopen/fclose + */ +/* + *static mm_segment_t oldfs; + * + *static void my_close(int fd) + *{ + * set_fs(oldfs); + * sys_close(fd); + *} + * + *static int my_open(char *fname, int flag) + *{ + * oldfs = get_fs(); + * set_fs(KERNEL_DS); + * return sys_open(fname, flag, 0); + *} + */ + +struct BTS_BLKNTC_TEMPERATURE { + __s32 BTS_BLKNTC_Temp; + __s32 TemperatureR; +}; + +static int g_RAP_pull_up_R = BTS_BLKNTC_RAP_PULL_UP_R; +static int g_TAP_over_critical_low = BTS_BLKNTC_TAP_OVER_CRITICAL_LOW; +static int g_RAP_pull_up_voltage = BTS_BLKNTC_RAP_PULL_UP_VOLTAGE; +static int g_RAP_ntc_table = BTS_BLKNTC_RAP_NTC_TABLE; +static int g_RAP_ADC_channel = 5; +//static int g_AP_TemperatureR; +/* BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table[] = {0}; */ + +static struct BTS_BLKNTC_TEMPERATURE *BTS_BLKNTC_Temperature_Table; +static int ntc_tbl_size; + +/* AP_NTC_BL197 */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table1[] = { + {-40, 74354}, /* FIX_ME */ + {-35, 74354}, /* FIX_ME */ + {-30, 74354}, /* FIX_ME */ + {-25, 74354}, /* FIX_ME */ + {-20, 74354}, + {-15, 57626}, + {-10, 45068}, + {-5, 35548}, + {0, 28267}, + {5, 22650}, + {10, 18280}, + {15, 14855}, + {20, 12151}, + {25, 10000}, /* 10K */ + {30, 8279}, + {35, 6892}, + {40, 5768}, + {45, 4852}, + {50, 4101}, + {55, 3483}, + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970} /* FIX_ME */ +}; + +/* AP_NTC_TSM_1 */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table2[] = { + {-40, 70603}, /* FIX_ME */ + {-35, 70603}, /* FIX_ME */ + {-30, 70603}, /* FIX_ME */ + {-25, 70603}, /* FIX_ME */ + {-20, 70603}, + {-15, 55183}, + {-10, 43499}, + {-5, 34569}, + {0, 27680}, + {5, 22316}, + {10, 18104}, + {15, 14773}, + {20, 12122}, + {25, 10000}, /* 10K */ + {30, 8294}, + {35, 6915}, + {40, 5795}, + {45, 4882}, + {50, 4133}, + {55, 3516}, + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004}, /* FIX_ME */ + {60, 3004} /* FIX_ME */ +}; + +/* AP_NTC_10_SEN_1 */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table3[] = { + {-40, 74354}, /* FIX_ME */ + {-35, 74354}, /* FIX_ME */ + {-30, 74354}, /* FIX_ME */ + {-25, 74354}, /* FIX_ME */ + {-20, 74354}, + {-15, 57626}, + {-10, 45068}, + {-5, 35548}, + {0, 28267}, + {5, 22650}, + {10, 18280}, + {15, 14855}, + {20, 12151}, + {25, 10000}, /* 10K */ + {30, 8279}, + {35, 6892}, + {40, 5768}, + {45, 4852}, + {50, 4101}, + {55, 3483}, + {60, 2970}, + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970}, /* FIX_ME */ + {60, 2970} /* FIX_ME */ +}; + +#if 0 +/* AP_NTC_10 */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table4[] = { + {-20, 68237}, + {-15, 53650}, + {-10, 42506}, + {-5, 33892}, + {0, 27219}, + {5, 22021}, + {10, 17926}, + {15, 14674}, + {20, 12081}, + {25, 10000}, + {30, 8315}, + {35, 6948}, + {40, 5834}, + {45, 4917}, + {50, 4161}, + {55, 3535}, + {60, 3014} +}; +#else +/* AP_NTC_10(TSM0A103F34D1RZ) */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table4[] = { + {-40, 188500}, + {-35, 144290}, + {-30, 111330}, + {-25, 86560}, + {-20, 67790}, + {-15, 53460}, + {-10, 42450}, + {-5, 33930}, + {0, 27280}, + {5, 22070}, + {10, 17960}, + {15, 14700}, + {20, 12090}, + {25, 10000}, /* 10K */ + {30, 8310}, + {35, 6940}, + {40, 5830}, + {45, 4910}, + {50, 4160}, + {55, 3540}, + {60, 3020}, + {65, 2590}, + {70, 2230}, + {75, 1920}, + {80, 1670}, + {85, 1450}, + {90, 1270}, + {95, 1110}, + {100, 975}, + {105, 860}, + {110, 760}, + {115, 674}, + {120, 599}, + {125, 534} +}; +#endif + +/* AP_NTC_47 */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table5[] = { + {-40, 483954}, /* FIX_ME */ + {-35, 483954}, /* FIX_ME */ + {-30, 483954}, /* FIX_ME */ + {-25, 483954}, /* FIX_ME */ + {-20, 483954}, + {-15, 360850}, + {-10, 271697}, + {-5, 206463}, + {0, 158214}, + {5, 122259}, + {10, 95227}, + {15, 74730}, + {20, 59065}, + {25, 47000}, /* 47K */ + {30, 37643}, + {35, 30334}, + {40, 24591}, + {45, 20048}, + {50, 16433}, + {55, 13539}, + {60, 11210}, + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210}, /* FIX_ME */ + {60, 11210} /* FIX_ME */ +}; + + +/* NTCG104EF104F(100K) */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table6[] = { + {-40, 4251000}, + {-35, 3005000}, + {-30, 2149000}, + {-25, 1554000}, + {-20, 1135000}, + {-15, 837800}, + {-10, 624100}, + {-5, 469100}, + {0, 355600}, + {5, 271800}, + {10, 209400}, + {15, 162500}, + {20, 127000}, + {25, 100000}, /* 100K */ + {30, 79230}, + {35, 63180}, + {40, 50680}, + {45, 40900}, + {50, 33190}, + {55, 27090}, + {60, 22220}, + {65, 18320}, + {70, 15180}, + {75, 12640}, + {80, 10580}, + {85, 8887}, + {90, 7500}, + {95, 6357}, + {100, 5410}, + {105, 4623}, + {110, 3965}, + {115, 3415}, + {120, 2951}, + {125, 2560} +}; + +/* NCP15WF104F03RC(100K) */ +static struct BTS_BLKNTC_TEMPERATURE BTS_BLKNTC_Temperature_Table7[] = { + {-40, 4397119}, + {-35, 3088599}, + {-30, 2197225}, + {-25, 1581881}, + {-20, 1151037}, + {-15, 846579}, + {-10, 628988}, + {-5, 471632}, + {0, 357012}, + {5, 272500}, + {10, 209710}, + {15, 162651}, + {20, 127080}, + {25, 100000}, /* 100K */ + {30, 79222}, + {35, 63167}, +#if defined(APPLY_PRECISE_NTC_TABLE) + {40, 50677}, + {41, 48528}, + {42, 46482}, + {43, 44533}, + {44, 42675}, + {45, 40904}, + {46, 39213}, + {47, 37601}, + {48, 36063}, + {49, 34595}, + {50, 33195}, + {51, 31859}, + {52, 30584}, + {53, 29366}, + {54, 28203}, + {55, 27091}, + {56, 26028}, + {57, 25013}, + {58, 24042}, + {59, 23113}, + {60, 22224}, + {61, 21374}, + {62, 20560}, + {63, 19782}, + {64, 19036}, + {65, 18322}, + {66, 17640}, + {67, 16986}, + {68, 16360}, + {69, 15759}, + {70, 15184}, + {71, 14631}, + {72, 14100}, + {73, 13591}, + {74, 13103}, + {75, 12635}, + {76, 12187}, + {77, 11756}, + {78, 11343}, + {79, 10946}, + {80, 10565}, + {81, 10199}, + {82, 9847}, + {83, 9509}, + {84, 9184}, + {85, 8872}, + {86, 8572}, + {87, 8283}, + {88, 8005}, + {89, 7738}, + {90, 7481}, +#else + {40, 50677}, + {45, 40904}, + {50, 33195}, + {55, 27091}, + {60, 22224}, + {65, 18323}, + {70, 15184}, + {75, 12635}, + {80, 10566}, + {85, 8873}, + {90, 7481}, +#endif + {95, 6337}, + {100, 5384}, + {105, 4594}, + {110, 3934}, + {115, 3380}, + {120, 2916}, + {125, 2522} +}; + +static unsigned int cl_dev_sysrst_state_ts_blkntc; +static struct thermal_cooling_device *cl_dev_sysrst_ts_blkntc; + +static int sysrst_ts_blkntc_get_max_state( +struct thermal_cooling_device *cdev, unsigned long *state) +{ + /* tscpu_dprintk("sysrst_ts_blkntc_get_max_state\n"); */ + *state = 1; + return 0; +} + +static int sysrst_ts_blkntc_get_cur_state( +struct thermal_cooling_device *cdev, unsigned long *state) +{ + /* tscpu_dprintk("sysrst_ts_blkntc_get_cur_state\n"); */ + *state = cl_dev_sysrst_state_ts_blkntc; + return 0; +} + +static int sysrst_ts_blkntc_set_cur_state( +struct thermal_cooling_device *cdev, unsigned long state) +{ + cl_dev_sysrst_state_ts_blkntc = state; + + if (cl_dev_sysrst_state_ts_blkntc == 1) { + mtkts_blkntc_printk("sysrst_ts_blkntc_set_cur_state = 1\n"); + mtkts_blkntc_printk("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + mtkts_blkntc_printk("*****************************************\n"); + mtkts_blkntc_printk("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + + /* To trigger data abort to reset the system + * for thermal protection. + */ + /* BUG(); */ + } + return 0; +} + +static struct thermal_cooling_device_ops mtkts_blkntc_cooling_sysrst_ops = { + .get_max_state = sysrst_ts_blkntc_get_max_state, + .get_cur_state = sysrst_ts_blkntc_get_cur_state, + .set_cur_state = sysrst_ts_blkntc_set_cur_state, +}; + +#if 0 +/* convert register to temperature */ +static __s16 mtkts_blkntc_thermistor_conver_temp(__s32 Res) +{ + int i = 0; + int asize = 0; + __s32 RES1 = 0, RES2 = 0; + __s32 TAP_Value = -200, TMP1 = 0, TMP2 = 0; + + asize = (ntc_tbl_size / sizeof(struct BTS_BLKNTC_TEMPERATURE)); + + /* mtkts_blkntc_dprintk("mtkts_blkntc_thermistor_conver_temp() : + * asize = %d, Res = %d\n",asize,Res); + */ + if (Res >= BTS_BLKNTC_Temperature_Table[0].TemperatureR) { + TAP_Value = -40; /* min */ + } else if (Res <= BTS_BLKNTC_Temperature_Table[asize - 1].TemperatureR) { + TAP_Value = 125; /* max */ + } else { + RES1 = BTS_BLKNTC_Temperature_Table[0].TemperatureR; + TMP1 = BTS_BLKNTC_Temperature_Table[0].BTS_BLKNTC_Temp; + /* mtkts_blkntc_dprintk("%d : RES1 = %d,TMP1 = %d\n", + * __LINE__,RES1,TMP1); + */ + + for (i = 0; i < asize; i++) { + if (Res >= BTS_BLKNTC_Temperature_Table[i].TemperatureR) { + RES2 = BTS_BLKNTC_Temperature_Table[i].TemperatureR; + TMP2 = BTS_BLKNTC_Temperature_Table[i].BTS_BLKNTC_Temp; + /* mtkts_blkntc_dprintk("%d :i=%d, RES2 = %d, + * TMP2 = %d\n",__LINE__,i,RES2,TMP2); + */ + break; + } + RES1 = BTS_BLKNTC_Temperature_Table[i].TemperatureR; + TMP1 = BTS_BLKNTC_Temperature_Table[i].BTS_BLKNTC_Temp; + /* mtkts_blkntc_dprintk("%d :i=%d, RES1 = %d,TMP1 = %d\n", + * __LINE__,i,RES1,TMP1); + */ + } + + TAP_Value = (((Res - RES2) * TMP1) + ((RES1 - Res) * TMP2)) + / (RES1 - RES2); + } + +#if 0 + mtkts_blkntc_dprintk( + "mtkts_blkntc_thermistor_conver_temp() : TAP_Value = %d\n", + TAP_Value); + + mtkts_blkntc_dprintk("mtkts_blkntc_thermistor_conver_temp() : Res = %d\n", + Res); + + mtkts_blkntc_dprintk("mtkts_blkntc_thermistor_conver_temp() : RES1 = %d\n", + RES1); + + mtkts_blkntc_dprintk("mtkts_blkntc_thermistor_conver_temp() : RES2 = %d\n", + RES2); + + mtkts_blkntc_dprintk("mtkts_blkntc_thermistor_conver_temp() : TMP1 = %d\n", + TMP1); + + mtkts_blkntc_dprintk("mtkts_blkntc_thermistor_conver_temp() : TMP2 = %d\n", + TMP2); +#endif + + return TAP_Value; +} + +/* convert ADC_AP_temp_volt to register */ +/*Volt to Temp formula same with 6589*/ +int blk_ntc_volt = 0;//xujia add for blk ntc compatible +static __s16 mtk_ts_bts_volt_to_temp(__u32 dwVolt) +{ + __s32 TRes; + __s32 dwVCriAP = 0; + __s32 BTS_BLKNTC_TMP = -100; + + /* SW workaround----------------------------------------------------- + * dwVCriAP = (TAP_OVER_CRITICAL_LOW * 1800) / + * (TAP_OVER_CRITICAL_LOW + 39000); + + * dwVCriAP = (TAP_OVER_CRITICAL_LOW * RAP_PULL_UP_VOLT) / + * (TAP_OVER_CRITICAL_LOW + RAP_PULL_UP_R); + */ + pr_notice("[mtk_ts_bts_volt_to_temp]dwVolt1 =%d\n", dwVolt); + blk_ntc_volt = dwVolt;//xujia add for blk ntc compatible + dwVCriAP = (g_TAP_over_critical_low * g_RAP_pull_up_voltage) + / (g_TAP_over_critical_low + g_RAP_pull_up_R); + + if (dwVolt > dwVCriAP) { + TRes = g_TAP_over_critical_low; + } else { + /* TRes = (39000*dwVolt) / (1800-dwVolt); */ + /* TRes = (RAP_PULL_UP_R*dwVolt) / (RAP_PULL_UP_VOLT-dwVolt); */ + TRes = (g_RAP_pull_up_R * dwVolt) / + (g_RAP_pull_up_voltage - dwVolt); + } + /* ------------------------------------------------------------------ */ + + g_AP_TemperatureR = TRes; + + /* convert register to temperature */ + BTS_BLKNTC_TMP = mtkts_blkntc_thermistor_conver_temp(TRes); + + return BTS_BLKNTC_TMP; +} +#endif +extern int mtkts_lcm_get_hw_temp(void); +static int get_hw_bts_temp(void) +{ +#if 0 + int ret = 0, data[4], i, ret_value = 0, ret_temp = 0, output; + int times = 1, Channel = g_RAP_ADC_channel; /* 6752=0(AUX_IN0_NTC) */ + static int valid_temp; +#if defined(APPLY_AUXADC_CALI_DATA) + int auxadc_cali_temp; +#endif + + if (IMM_IsAdcInitReady() == 0) { + mtkts_blkntc_printk( + "[thermal_auxadc_get_data]: AUXADC is not ready\n"); + return 0; + } + + i = times; + while (i--) { + ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp); + if (ret_value) {/* AUXADC is busy */ +#if defined(APPLY_AUXADC_CALI_DATA) + auxadc_cali_temp = valid_temp; +#else + ret_temp = valid_temp; +#endif + } else { +#if defined(APPLY_AUXADC_CALI_DATA) + /* + * by reference mtk_auxadc.c + * + * convert to volt: + * data[0] = (rawdata * 1500 / (4096 + cali_ge)) / 1000; + * + * convert to mv, need multiply 10: + * data[1] = (rawdata * 150 / (4096 + cali_ge)) % 100; + * + * provide high precision mv: + * data[2] = (rawdata * 1500 / (4096 + cali_ge)) % 1000; + */ + auxadc_cali_temp = data[0]*1000+data[2]; + valid_temp = auxadc_cali_temp; +#else + valid_temp = ret_temp; +#endif + } + +#if defined(APPLY_AUXADC_CALI_DATA) + ret += auxadc_cali_temp; + mtkts_blkntc_dprintk( + "[thermal_auxadc_get_data(AUX_IN0_NTC)]: ret_temp=%d\n", + auxadc_cali_temp); +#else + ret += ret_temp; + mtkts_blkntc_dprintk( + "[thermal_auxadc_get_data(AUX_IN0_NTC)]: ret_temp=%d\n", + ret_temp); +#endif + } + + /* Mt_auxadc_hal.c */ + /* #define VOLTAGE_FULL_RANGE 1500 // VA voltage */ + /* #define AUXADC_PRECISE 4096 // 12 bits */ +#if defined(APPLY_AUXADC_CALI_DATA) +#else + ret = ret * 1500 / 4096; +#endif + /* ret = ret*1800/4096;//82's ADC power */ + mtkts_blkntc_dprintk("APtery output mV = %d\n", ret); + output = mtk_ts_bts_volt_to_temp(ret); + + mtkts_blkntc_dprintk("BTS output temperature = %d\n", output); +#endif + return mtkts_lcm_get_hw_temp(); +} + +static DEFINE_MUTEX(BTS_BLKNTC_lock); +int mtkts_blkntc_get_hw_temp(void) +{ + int t_ret = 0; + + mutex_lock(&BTS_BLKNTC_lock); + + t_ret = get_hw_bts_temp(); + t_ret = t_ret * 1000; + + mutex_unlock(&BTS_BLKNTC_lock); + + if (t_ret > 40000) /* abnormal high temp */ + mtkts_blkntc_printk("T_BLKNTC=%d\n", t_ret); + + mtkts_blkntc_dprintk("[mtkts_blkntc_get_hw_temp] T_BLKNTC, %d\n", t_ret); + return t_ret; +} + +static int mtkts_blkntc_get_temp(struct thermal_zone_device *thermal, int *t) +{ + *t = mtkts_blkntc_get_hw_temp(); + + /* if ((int) *t > 52000) */ + /* mtkts_blkntc_dprintk("T=%d\n", (int) *t); */ + + if ((int)*t >= polling_trip_temp1) + thermal->polling_delay = interval * 1000; + else if ((int)*t < polling_trip_temp2) + thermal->polling_delay = interval * polling_factor2; + else + thermal->polling_delay = interval * polling_factor1; + + return 0; +} + +static int mtkts_blkntc_bind( +struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) +{ + int table_val = 0; + + if (!strcmp(cdev->type, g_bind0)) { + table_val = 0; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind1)) { + table_val = 1; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind2)) { + table_val = 2; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind3)) { + table_val = 3; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind4)) { + table_val = 4; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind5)) { + table_val = 5; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind6)) { + table_val = 6; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind7)) { + table_val = 7; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind8)) { + table_val = 8; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind9)) { + table_val = 9; + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] %s\n", cdev->type); + } else { + return 0; + } + + if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { + mtkts_blkntc_dprintk( + "[mtkts_blkntc_bind] error binding cooling dev\n"); + return -EINVAL; + } + + mtkts_blkntc_dprintk("[mtkts_blkntc_bind] binding OK, %d\n", table_val); + return 0; +} + +static int mtkts_blkntc_unbind(struct thermal_zone_device *thermal, + struct thermal_cooling_device *cdev) +{ + int table_val = 0; + + if (!strcmp(cdev->type, g_bind0)) { + table_val = 0; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind1)) { + table_val = 1; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind2)) { + table_val = 2; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind3)) { + table_val = 3; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind4)) { + table_val = 4; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind5)) { + table_val = 5; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind6)) { + table_val = 6; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind7)) { + table_val = 7; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind8)) { + table_val = 8; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else if (!strcmp(cdev->type, g_bind9)) { + table_val = 9; + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] %s\n", cdev->type); + } else + return 0; + + if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { + mtkts_blkntc_dprintk( + "[mtkts_blkntc_unbind] error unbinding cooling dev\n"); + return -EINVAL; + } + + mtkts_blkntc_dprintk("[mtkts_blkntc_unbind] unbinding OK\n"); + return 0; +} + +static int mtkts_blkntc_get_mode( +struct thermal_zone_device *thermal, enum thermal_device_mode *mode) +{ + *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + return 0; +} + +static int mtkts_blkntc_set_mode( +struct thermal_zone_device *thermal, enum thermal_device_mode mode) +{ + kernelmode = mode; + return 0; +} + +static int mtkts_blkntc_get_trip_type( +struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) +{ + *type = g_THERMAL_TRIP[trip]; + return 0; +} + +static int mtkts_blkntc_get_trip_temp( +struct thermal_zone_device *thermal, int trip, int *temp) +{ + *temp = trip_temp[trip]; + return 0; +} + +static int mtkts_blkntc_get_crit_temp( +struct thermal_zone_device *thermal, int *temperature) +{ + *temperature = MTKTS_BLKNTC_TEMP_CRIT; + return 0; +} + +/* bind callback functions to thermalzone */ +static struct thermal_zone_device_ops mtkts_BTS_BLKNTC_dev_ops = { + .bind = mtkts_blkntc_bind, + .unbind = mtkts_blkntc_unbind, + .get_temp = mtkts_blkntc_get_temp, + .get_mode = mtkts_blkntc_get_mode, + .set_mode = mtkts_blkntc_set_mode, + .get_trip_type = mtkts_blkntc_get_trip_type, + .get_trip_temp = mtkts_blkntc_get_trip_temp, + .get_crit_temp = mtkts_blkntc_get_crit_temp, +}; + + + +static int mtkts_blkntc_read(struct seq_file *m, void *v) +{ + + seq_printf(m, + "[mtkts_blkntc_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,trip_4_temp=%d\n", + trip_temp[0], trip_temp[1], trip_temp[2], + trip_temp[3], trip_temp[4]); + + seq_printf(m, + "trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", + trip_temp[5], trip_temp[6], trip_temp[7], + trip_temp[8], trip_temp[9]); + + seq_printf(m, + "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", + g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], + g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]); + + seq_printf(m, + "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", + g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], + g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]); + + seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", + g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); + + seq_printf(m, + "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", + g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); + + seq_printf(m, + "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", + g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); + + return 0; +} + +static int mtkts_blkntc_register_thermal(void); +static void mtkts_blkntc_unregister_thermal(void); + +static ssize_t mtkts_blkntc_write( +struct file *file, const char __user *buffer, size_t count, loff_t *data) +{ + int len = 0, i; + + struct mtkts_blkntc_data { + int trip[10]; + int t_type[10]; + char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; + char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; + int time_msec; + char desc[512]; + }; + + struct mtkts_blkntc_data *ptr_mtkts_blkntc_data = kmalloc( + sizeof(*ptr_mtkts_blkntc_data), GFP_KERNEL); + + if (ptr_mtkts_blkntc_data == NULL) + return -ENOMEM; + + + len = (count < (sizeof(ptr_mtkts_blkntc_data->desc) - 1)) ? + count : (sizeof(ptr_mtkts_blkntc_data->desc) - 1); + + if (copy_from_user(ptr_mtkts_blkntc_data->desc, buffer, len)) { + kfree(ptr_mtkts_blkntc_data); + return 0; + } + + ptr_mtkts_blkntc_data->desc[len] = '\0'; + + if (sscanf + (ptr_mtkts_blkntc_data->desc, + "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", + &num_trip, + &ptr_mtkts_blkntc_data->trip[0], &ptr_mtkts_blkntc_data->t_type[0], + ptr_mtkts_blkntc_data->bind0, + &ptr_mtkts_blkntc_data->trip[1], &ptr_mtkts_blkntc_data->t_type[1], + ptr_mtkts_blkntc_data->bind1, + &ptr_mtkts_blkntc_data->trip[2], &ptr_mtkts_blkntc_data->t_type[2], + ptr_mtkts_blkntc_data->bind2, + &ptr_mtkts_blkntc_data->trip[3], &ptr_mtkts_blkntc_data->t_type[3], + ptr_mtkts_blkntc_data->bind3, + &ptr_mtkts_blkntc_data->trip[4], &ptr_mtkts_blkntc_data->t_type[4], + ptr_mtkts_blkntc_data->bind4, + &ptr_mtkts_blkntc_data->trip[5], &ptr_mtkts_blkntc_data->t_type[5], + ptr_mtkts_blkntc_data->bind5, + &ptr_mtkts_blkntc_data->trip[6], &ptr_mtkts_blkntc_data->t_type[6], + ptr_mtkts_blkntc_data->bind6, + &ptr_mtkts_blkntc_data->trip[7], &ptr_mtkts_blkntc_data->t_type[7], + ptr_mtkts_blkntc_data->bind7, + &ptr_mtkts_blkntc_data->trip[8], &ptr_mtkts_blkntc_data->t_type[8], + ptr_mtkts_blkntc_data->bind8, + &ptr_mtkts_blkntc_data->trip[9], &ptr_mtkts_blkntc_data->t_type[9], + ptr_mtkts_blkntc_data->bind9, + &ptr_mtkts_blkntc_data->time_msec) == 32) { + + down(&sem_mutex); + mtkts_blkntc_dprintk( + "[mtkts_blkntc_write] mtkts_blkntc_unregister_thermal\n"); + + mtkts_blkntc_unregister_thermal(); + + if (num_trip < 0 || num_trip > 10) { + #ifdef CONFIG_MTK_AEE_FEATURE + aee_kernel_warning_api(__FILE__, __LINE__, + DB_OPT_DEFAULT, "mtkts_blkntc_write", + "Bad argument"); + #endif + mtkts_blkntc_dprintk("[mtkts_blkntc_write] bad argument\n"); + kfree(ptr_mtkts_blkntc_data); + up(&sem_mutex); + return -EINVAL; + } + + for (i = 0; i < num_trip; i++) + g_THERMAL_TRIP[i] = ptr_mtkts_blkntc_data->t_type[i]; + + g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] + = g_bind4[0] = g_bind5[0] = g_bind6[0] + = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0'; + + for (i = 0; i < 20; i++) { + g_bind0[i] = ptr_mtkts_blkntc_data->bind0[i]; + g_bind1[i] = ptr_mtkts_blkntc_data->bind1[i]; + g_bind2[i] = ptr_mtkts_blkntc_data->bind2[i]; + g_bind3[i] = ptr_mtkts_blkntc_data->bind3[i]; + g_bind4[i] = ptr_mtkts_blkntc_data->bind4[i]; + g_bind5[i] = ptr_mtkts_blkntc_data->bind5[i]; + g_bind6[i] = ptr_mtkts_blkntc_data->bind6[i]; + g_bind7[i] = ptr_mtkts_blkntc_data->bind7[i]; + g_bind8[i] = ptr_mtkts_blkntc_data->bind8[i]; + g_bind9[i] = ptr_mtkts_blkntc_data->bind9[i]; + } + + mtkts_blkntc_dprintk( + "[mtkts_blkntc_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", + g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], + g_THERMAL_TRIP[2]); + + mtkts_blkntc_dprintk( + "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", + g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], + g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]); + + mtkts_blkntc_dprintk( + "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", + g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], + g_THERMAL_TRIP[9]); + + mtkts_blkntc_dprintk( + "[mtkts_blkntc_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", + g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); + + mtkts_blkntc_dprintk( + "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", + g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); + + for (i = 0; i < num_trip; i++) + trip_temp[i] = ptr_mtkts_blkntc_data->trip[i]; + + interval = ptr_mtkts_blkntc_data->time_msec / 1000; + + mtkts_blkntc_dprintk( + "[mtkts_blkntc_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", + trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); + + mtkts_blkntc_dprintk( + "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", + trip_temp[4], trip_temp[5], trip_temp[6], + trip_temp[7], trip_temp[8]); + + mtkts_blkntc_dprintk("trip_9_temp=%d,time_ms=%d\n", + trip_temp[9], interval * 1000); + + mtkts_blkntc_dprintk( + "[mtkts_blkntc_write] mtkts_blkntc_register_thermal\n"); + //pr_notice("[mtkts_blkntc_write]blk_ntc_volt = %d\n", blk_ntc_volt); + //xujia add for blk ntc compatible 1.after P1 bind blk ntc and therml policy(V1-P0,V2-P0-1,V3-P1) 2.check ntc in postion or not(ntc volt between 0 and 1.45V) + pr_notice("[mtkts_blkntc_write]mtkts_blkntc_register_thermal\n"); + mtkts_blkntc_register_thermal(); + up(&sem_mutex); + kfree(ptr_mtkts_blkntc_data); + return count; + } + + mtkts_blkntc_dprintk("[mtkts_blkntc_write] bad argument\n"); + #ifdef CONFIG_MTK_AEE_FEATURE + aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, + "mtkts_blkntc_write", + "Bad argument"); + #endif + kfree(ptr_mtkts_blkntc_data); + return -EINVAL; +} + +void mtkts_blkntc_prepare_table(int table_num) +{ + + pr_notice("[Thermal/TZ/BLKNTC2] %s table_num=%d\n", __func__, table_num); + + switch (table_num) { + case 1: /* AP_NTC_BL197 */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table1; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table1); + break; + case 2: /* AP_NTC_TSM_1 */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table2; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table2); + break; + case 3: /* AP_NTC_10_SEN_1 */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table3; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table3); + break; + case 4: /* AP_NTC_10 */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table4; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table4); + break; + case 5: /* AP_NTC_47 */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table5; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table5); + break; + case 6: /* NTCG104EF104F */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table6; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table6); + break; + case 7: /* NCP15WF104F03RC */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table7; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table7); + break; + default: /* AP_NTC_10 */ + BTS_BLKNTC_Temperature_Table = BTS_BLKNTC_Temperature_Table4; + ntc_tbl_size = sizeof(BTS_BLKNTC_Temperature_Table4); + break; + } + + pr_notice("[Thermal/TZ/BLKNTC] %s table_num=%d\n", __func__, table_num); + pr_notice("[Thermal/TZ/BLKNTC1] %s table_num=%d\n", __func__, table_num); +} + +static int mtkts_blkntc_param_read(struct seq_file *m, void *v) +{ + seq_printf(m, "%d\n", g_RAP_pull_up_R); + seq_printf(m, "%d\n", g_RAP_pull_up_voltage); + seq_printf(m, "%d\n", g_TAP_over_critical_low); + seq_printf(m, "%d\n", g_RAP_ntc_table); + seq_printf(m, "%d\n", g_RAP_ADC_channel); + + return 0; +} + + +static ssize_t mtkts_blkntc_param_write( +struct file *file, const char __user *buffer, size_t count, loff_t *data) +{ + int len = 0; + struct mtkts_blkntc_param_data { + char desc[512]; + char pull_R[10], pull_V[10]; + char overcrilow[16]; + char NTC_TABLE[10]; + unsigned int valR, valV, over_cri_low, ntc_table; + unsigned int adc_channel; + }; + + struct mtkts_blkntc_param_data *ptr_mtkts_blkntc_parm_data; + + ptr_mtkts_blkntc_parm_data = kmalloc( + sizeof(*ptr_mtkts_blkntc_parm_data), GFP_KERNEL); + + if (ptr_mtkts_blkntc_parm_data == NULL) + return -ENOMEM; + + /* external pin: 0/1/12/13/14/15, can't use pin:2/3/4/5/6/7/8/9/10/11, + *choose "adc_channel=11" to check if there is any param input + */ + ptr_mtkts_blkntc_parm_data->adc_channel = 11; + + len = (count < (sizeof(ptr_mtkts_blkntc_parm_data->desc) - 1)) ? + count : (sizeof(ptr_mtkts_blkntc_parm_data->desc) - 1); + + if (copy_from_user(ptr_mtkts_blkntc_parm_data->desc, buffer, len)) { + kfree(ptr_mtkts_blkntc_parm_data); + return 0; + } + + ptr_mtkts_blkntc_parm_data->desc[len] = '\0'; + + mtkts_blkntc_dprintk("[mtkts_blkntc_write]\n"); + + if (sscanf + (ptr_mtkts_blkntc_parm_data->desc, "%9s %d %9s %d %15s %d %9s %d %d", + ptr_mtkts_blkntc_parm_data->pull_R, &ptr_mtkts_blkntc_parm_data->valR, + ptr_mtkts_blkntc_parm_data->pull_V, &ptr_mtkts_blkntc_parm_data->valV, + ptr_mtkts_blkntc_parm_data->overcrilow, + &ptr_mtkts_blkntc_parm_data->over_cri_low, + ptr_mtkts_blkntc_parm_data->NTC_TABLE, + &ptr_mtkts_blkntc_parm_data->ntc_table, + &ptr_mtkts_blkntc_parm_data->adc_channel) >= 8) { + + if (!strcmp(ptr_mtkts_blkntc_parm_data->pull_R, "PUP_R")) { + g_RAP_pull_up_R = ptr_mtkts_blkntc_parm_data->valR; + mtkts_blkntc_dprintk("g_RAP_pull_up_R=%d\n", + g_RAP_pull_up_R); + } else { + mtkts_blkntc_printk( + "[mtkts_blkntc_write] bad PUP_R argument\n"); + kfree(ptr_mtkts_blkntc_parm_data); + return -EINVAL; + } + + if (!strcmp(ptr_mtkts_blkntc_parm_data->pull_V, "PUP_VOLT")) { + g_RAP_pull_up_voltage = ptr_mtkts_blkntc_parm_data->valV; + mtkts_blkntc_dprintk("g_Rat_pull_up_voltage=%d\n", + g_RAP_pull_up_voltage); + } else { + mtkts_blkntc_printk( + "[mtkts_blkntc_write] bad PUP_VOLT argument\n"); + kfree(ptr_mtkts_blkntc_parm_data); + return -EINVAL; + } + + if (!strcmp(ptr_mtkts_blkntc_parm_data->overcrilow, + "OVER_CRITICAL_L")) { + g_TAP_over_critical_low = + ptr_mtkts_blkntc_parm_data->over_cri_low; + mtkts_blkntc_dprintk("g_TAP_over_critical_low=%d\n", + g_TAP_over_critical_low); + } else { + mtkts_blkntc_printk( + "[mtkts_blkntc_write] bad OVERCRIT_L argument\n"); + kfree(ptr_mtkts_blkntc_parm_data); + return -EINVAL; + } + + if (!strcmp(ptr_mtkts_blkntc_parm_data->NTC_TABLE, "NTC_TABLE")) { + g_RAP_ntc_table = ptr_mtkts_blkntc_parm_data->ntc_table; + mtkts_blkntc_dprintk("g_RAP_ntc_table=%d\n", + g_RAP_ntc_table); + } else { + mtkts_blkntc_printk( + "[mtkts_blkntc_write] bad NTC_TABLE argument\n"); + kfree(ptr_mtkts_blkntc_parm_data); + return -EINVAL; + } + + /* external pin: 0/1/12/13/14/15, + * can't use pin:2/5/6/7/8/9/10/11, + * choose "adc_channel=11" to check if there is any param input + */ + if ((ptr_mtkts_blkntc_parm_data->adc_channel >= 5) + && (ptr_mtkts_blkntc_parm_data->adc_channel <= 11)) + /* check unsupport pin value, if unsupport, + * set channel = 1 as default setting. + */ + g_RAP_ADC_channel = AUX_IN0_NTC; + else { + /* check if there is any param input, + * if not using default g_RAP_ADC_channel:1 + */ + if (ptr_mtkts_blkntc_parm_data->adc_channel != 11) + g_RAP_ADC_channel = + ptr_mtkts_blkntc_parm_data->adc_channel; + else + g_RAP_ADC_channel = AUX_IN0_NTC; + } + mtkts_blkntc_dprintk("adc_channel=%d\n", + ptr_mtkts_blkntc_parm_data->adc_channel); + mtkts_blkntc_dprintk("g_RAP_ADC_channel=%d\n", + g_RAP_ADC_channel); + + mtkts_blkntc_prepare_table(g_RAP_ntc_table); + + kfree(ptr_mtkts_blkntc_parm_data); + return count; + } + + mtkts_blkntc_printk("[mtkts_blkntc_write] bad argument\n"); + kfree(ptr_mtkts_blkntc_parm_data); + return -EINVAL; +} + +/* int mtkts_blkntc_register_cooler(void) + * { + * cooling devices + * cl_dev_sysrst = mtk_thermal_cooling_device_register( + * "mtkts_blkntctery-sysrst", NULL, + * &mtkts_blkntc_cooling_sysrst_ops); + * return 0; + * } + */ + +#if 0 +static void mtkts_blkntc_cancel_thermal_timer(void) +{ + /* cancel timer + * mtkts_blkntc_printk("mtkts_blkntc_cancel_thermal_timer\n"); + + * stop thermal framework polling when entering deep idle + + * + * We cannot cancel the timer during deepidle and SODI, because + * the battery may suddenly heat up by 3A fast charging. + * + * + *if (thz_dev) + * cancel_delayed_work(&(thz_dev->poll_queue)); + */ +} + + +static void mtkts_blkntc_start_thermal_timer(void) +{ + /* mtkts_blkntc_printk("mtkts_blkntc_start_thermal_timer\n"); + * resume thermal framework polling when leaving deep idle + * + *if (thz_dev != NULL && interval != 0) + * mod_delayed_work(system_freezable_power_efficient_wq, + * &(thz_dev->poll_queue), + * round_jiffies(msecs_to_jiffies(3000))); + */ +} +#endif + +static int mtkts_blkntc_register_thermal(void) +{ + mtkts_blkntc_dprintk("[mtkts_blkntc_register_thermal]\n"); + pr_notice("[mtkts_blkntc_init]mtkts_blkntc_register_thermal\n"); + + /* trips : trip 0~1 */ + thz_dev = mtk_thermal_zone_device_register("backlight_therm", num_trip, NULL, + &mtkts_BTS_BLKNTC_dev_ops, 0, 0, 0, + interval * 1000); + + return 0; +} + +/* void mtkts_blkntc_unregister_cooler(void) */ +/* { */ + /* if (cl_dev_sysrst) { */ + /* mtk_thermal_cooling_device_unregister(cl_dev_sysrst); */ + /* cl_dev_sysrst = NULL; */ + /* } */ +/* } */ +static void mtkts_blkntc_unregister_thermal(void) +{ + mtkts_blkntc_dprintk("[mtkts_blkntc_unregister_thermal]\n"); + + if (thz_dev) { + mtk_thermal_zone_device_unregister(thz_dev); + thz_dev = NULL; + } +} + +static int mtkts_blkntc_open(struct inode *inode, struct file *file) +{ + return single_open(file, mtkts_blkntc_read, NULL); +} + +static const struct file_operations mtkts_blkntc_fops = { + .owner = THIS_MODULE, + .open = mtkts_blkntc_open, + .read = seq_read, + .llseek = seq_lseek, + .write = mtkts_blkntc_write, + .release = single_release, +}; + + +static int mtkts_blkntc_param_open(struct inode *inode, struct file *file) +{ + return single_open(file, mtkts_blkntc_param_read, NULL); +} + +static const struct file_operations mtkts_blkntc_param_fops = { + .owner = THIS_MODULE, + .open = mtkts_blkntc_param_open, + .read = seq_read, + .llseek = seq_lseek, + .write = mtkts_blkntc_param_write, + .release = single_release, +}; + +static int __init mtkts_blkntc_init(void) +{ + struct proc_dir_entry *entry = NULL; + struct proc_dir_entry *mtkts_blkntc_dir = NULL; + /* setup default table */ + mtkts_blkntc_prepare_table(g_RAP_ntc_table); + mtkts_blkntc_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); + if (!mtkts_blkntc_dir) { + mtkts_blkntc_dprintk("[%s]: mkdir /proc/driver/thermal failed\n", + __func__); + } else { + entry = proc_create("backlight_therm_ntc", 0664, mtkts_blkntc_dir, + &mtkts_blkntc_fops); + if (entry) + proc_set_user(entry, uid, gid); + + entry = proc_create("backlight_therm_ntc_param", 0664, mtkts_blkntc_dir, + &mtkts_blkntc_param_fops); + if (entry) + proc_set_user(entry, uid, gid); + + } + + //pr_notice("[mtkts_blkntc_init]blk_ntc_volt = %d\n", blk_ntc_volt); + //xujia add for blk ntc compatible 1.after P1 bind blk ntc and therml policy(V1-P0,V2-P0-1,V3-P1) 2.check ntc in postion or not(ntc volt between 0 and 1.45V) + pr_notice("[mtkts_blkntc_init]mtkts_blkntc_register_thermal\n"); + cl_dev_sysrst_ts_blkntc = mtk_thermal_cooling_device_register( + "backlight_therm", NULL, + &mtkts_blkntc_cooling_sysrst_ops); + mtkts_blkntc_register_thermal(); + return 0; +} + +static void __exit mtkts_blkntc_exit(void) +{ + mtkts_blkntc_dprintk("[mtkts_blkntc_exit]\n"); + if (cl_dev_sysrst_ts_blkntc) { + mtk_thermal_cooling_device_unregister(cl_dev_sysrst_ts_blkntc); + cl_dev_sysrst_ts_blkntc = NULL; + } + + mtkts_blkntc_unregister_thermal(); +} + +module_init(mtkts_blkntc_init); +module_exit(mtkts_blkntc_exit); diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_bts.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_bts.c index 681dbf45a5af..5dd9a9d98974 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_bts.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_bts.c @@ -60,7 +60,7 @@ static kgid_t gid = KGIDT_INIT(1000); static DEFINE_SEMAPHORE(sem_mutex); static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static int trip_temp[10] = { 120000, 110000, 100000, 90000, 80000, +static int trip_temp[10] = { 100000, 96000, 95000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 }; static struct thermal_zone_device *thz_dev; @@ -68,8 +68,8 @@ static int mtkts_bts_debug_log; static int kernelmode; static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static int num_trip; -static char g_bind0[20] = {"mtktsAP-sysrst"}; +static int num_trip = 1; +static char g_bind0[20] = "mtktsAP-sysrst"; static char g_bind1[20] = { 0 }; static char g_bind2[20] = { 0 }; static char g_bind3[20] = { 0 }; diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_btsmdpa.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_btsmdpa.c index 1275dbf47e63..0bd367c46272 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_btsmdpa.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_btsmdpa.c @@ -62,8 +62,8 @@ static int mtkts_btsmdpa_debug_log; static int kernelmode; static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static int num_trip; -static char g_bind0[20] = {"mtk-cl-shutdown02"}; +static int num_trip = 1; +static char g_bind0[20] = "mtk-cl-shutdown02"; static char g_bind1[20] = { 0 }; static char g_bind2[20] = { 0 }; static char g_bind3[20] = { 0 }; diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_charger.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_charger.c index c6c712445d79..a857b1960444 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_charger.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_charger.c @@ -43,9 +43,9 @@ static kgid_t gid = KGIDT_INIT(1000); static DEFINE_SEMAPHORE(sem_mutex); static int kernelmode; -static unsigned int interval; /* seconds, 0 : no auto polling */ +static unsigned int interval = 2; /* seconds, 0 : no auto polling */ static int num_trip = 1; -static int trip_temp[10] = { 125000, 110000, 100000, 90000, 80000, +static int trip_temp[10] = { 120000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 }; static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_cpu_noBank.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_cpu_noBank.c index edf4d03a8208..7134d0cf0752 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_cpu_noBank.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_cpu_noBank.c @@ -415,7 +415,7 @@ int mtk_gpufreq_register(struct mt_gpufreq_power_table_info *freqs, int num) mtk_gpu_power[i].gpufreq_khz = freqs[i].gpufreq_khz; mtk_gpu_power[i].gpufreq_power = freqs[i].gpufreq_power; - tscpu_dprintk("[%d].gpufreq_khz=%u, .gpufreq_power=%u\n", + tscpu_printk("[%d].gpufreq_khz=%u, .gpufreq_power=%u\n", i, freqs[i].gpufreq_khz, freqs[i].gpufreq_power); } diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pa.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pa.c index 5b121dc96a3a..eee0dfb74003 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pa.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pa.c @@ -40,8 +40,8 @@ static kgid_t gid = KGIDT_INIT(1000); static DEFINE_SEMAPHORE(sem_mutex); static int isTimerCancelled; -static unsigned int interval; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 85000, 80000, 70000, 60000, 50000, +static unsigned int interval = 2; /* seconds, 0 : no auto polling */ +static unsigned int trip_temp[10] = { 120000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 5000 }; static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -52,7 +52,7 @@ static struct thermal_cooling_device *cl_dev_sysrst; static int mtktspa_debug_log; static int kernelmode; -static int num_trip; +static int num_trip = 1; static char g_bind0[20] = "mtktspa-sysrst"; static char g_bind1[20] = { 0 }; static char g_bind2[20] = { 0 }; @@ -193,10 +193,10 @@ static void pa_cal_stats(struct timer_list *t) *struct md_info g_pinfo_list[] = *{{"TXPWR_MD1", -127, "db", -127, 0}, * {"TXPWR_MD2", -127, "db", -127, 1}, - * {"RFTEMP_2G_MD1", -32767, "¢XC", -32767, 2}, - * {"RFTEMP_2G_MD2", -32767, "¢XC", -32767, 3}, - * {"RFTEMP_3G_MD1", -32767, "¢XC", -32767, 4}, - * {"RFTEMP_3G_MD2", -32767, "¢XC", -32767, 5}}; + * {"RFTEMP_2G_MD1", -32767, "�XC", -32767, 2}, + * {"RFTEMP_2G_MD2", -32767, "�XC", -32767, 3}, + * {"RFTEMP_3G_MD1", -32767, "�XC", -32767, 4}, + * {"RFTEMP_3G_MD2", -32767, "�XC", -32767, 5}}; */ static DEFINE_MUTEX(TSPA_lock); static int mtktspa_get_hw_temp(void) diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pmic.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pmic.c index bcdafeaffdff..4dba1610a199 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pmic.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_pmic.c @@ -46,7 +46,7 @@ static int polling_factor1 = 5000; static int polling_factor2 = 10000; static unsigned int interval; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 120000, 110000, 100000, 90000, 80000, +static unsigned int trip_temp[10] = { 136000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 }; static unsigned int cl_dev_sysrst_state; @@ -57,8 +57,8 @@ static int kernelmode; static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static int num_trip; -static char g_bind0[20] = { 0 }; +static int num_trip = 1; +static char g_bind0[20] = "mtktspmic-sysrst"; static char g_bind1[20] = { 0 }; static char g_bind2[20] = { 0 }; static char g_bind3[20] = { 0 }; diff --git a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_wmt.c b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_wmt.c index c1748c283ec6..5be9867eb812 100644 --- a/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_wmt.c +++ b/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_wmt.c @@ -116,8 +116,8 @@ static unsigned int tm_wfd_stat; static struct task_struct *pg_task; /* + Cooler info + */ -static int g_num_trip; -static char g_bind0[20] = { 0 }; +static int g_num_trip = 1; +static char g_bind0[20] = "mtktswmt-sysrst"; static char g_bind1[20] = { 0 }; static char g_bind2[20] = { 0 }; static char g_bind3[20] = { 0 }; @@ -142,7 +142,7 @@ static int polling_factor2 = 10; static unsigned int cl_dev_state; static unsigned int cl_pa1_dev_state; static unsigned int cl_pa2_dev_state; -static unsigned int g_trip_temp[COOLER_NUM] = { 125000, 115000, 105000, 85000, +static unsigned int g_trip_temp[COOLER_NUM] = { 120000, 115000, 105000, 85000, 0, 0, 0, 0, 0, 0 }; /* static int g_thro[COOLER_THRO_NUM] = diff --git a/drivers/misc/mediatek/thermal/mt6739/Makefile b/drivers/misc/mediatek/thermal/mt6739/Makefile deleted file mode 100644 index 82fe0cc1efcc..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2015 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6739/inc/clatm_initcfg.h deleted file mode 100644 index f6fe8fdab60f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/clatm_initcfg.h +++ /dev/null @@ -1,56 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (75000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (2000) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (400) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (2000) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (200) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (700) - -#define CLATM_INIT_CFG_1_TARGET_TJ (65000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (3000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (75000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3960) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (600) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (10) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (100) -#define CLATM_USE_MIN_CPU_OPP (1) -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6739/inc/mtk_cooler_setting.h deleted file mode 100644 index c2da3098c9ba..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ - /* mtk_cooler_mutt.c */ -/* 1: turn on MD throttle V2 cooler; 0: turn off */ -#define FEATURE_MUTT_V2 (1) - -/* mtk_cooler_mutt.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6739/inc/mtk_thermal_ipi.h deleted file mode 100644 index 62e19cc60250..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM -#include "sspm_ipi.h" -#include - -#define THERMAL_SLOT_NUM (4) - -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_sspm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6739/inc/mtk_ts_setting.h deleted file mode 100644 index 5721cf77c13e..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/mtk_ts_setting.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (1) - - -/* -* Request HPM in Low temperature condition -*/ -#define THERMAL_LT_SET_HPM (1) - -#if THERMAL_LT_SET_HPM -extern int enter_hpm_temp; -extern int leave_hpm_temp; -extern int enable_hpm_temp; -#endif - -/*In src/mtk_tc.c*/ -extern int get_immediate_ts4_wrap(void); - -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6739/inc/tmp_bts.h deleted file mode 100644 index fe73d1eabbca..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/tmp_bts.h +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) - -#define BTS_RAP_PULL_UP_R 390000 /* 390K,pull up resister */ -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp default value -40 deg */ -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 390000 /* 390K,pull up resister */ -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp default value -40 deg */ -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6739/inc/tscpu_settings.h deleted file mode 100644 index 95ca9107eb02..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/tscpu_settings.h +++ /dev/null @@ -1,689 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include -#include - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned) -1 >> (31 - ((1) ? _bits_))) & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() long long thermal_pTime_us, thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_info(TSCPU_LOG_TAG "%s: %llu us\n", __func__, thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_info(TSCPU_LOG_TAG "Warning: tProfiling uses incorrect %s %d\n", __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -/* Define this in tscpu_settings.h enables this feature. It polls CPU TS in hrtimer and - * run ATM in RT 98 kthread. This is for MT6797 only. - */ -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) - -/* 1: mtk_tc.c supports LVTS; 0: o.w. */ -#define CFG_THERM_LVTS (0) - -/*============================================================= - * Chip related - *============================================================= - */ -/* double check */ -#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ -#define TS_TURN_ON 0xFFFFFFCF /* turn on TS_CON1[5:4] 2'b 00 11001111 -> 0xCF ~(0x30)*/ -#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ - -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define ADDRESS_INDEX_0 103 -#define ADDRESS_INDEX_1 102 -#define ADDRESS_INDEX_2 104 - -#define CLEAR_TEMP 26111 - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - - -/* ADC value to mcu */ -/*chip dependent*/ -#define TEMPADC_MCU1 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_000)) -#define TEMPADC_MCU2 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_001)) -#define TEMPADC_MCU3 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_010)) -#define TEMPADC_ABB ((0x30&TSCON1_bit_4_5_01)|(0x07&TSCON1_bit_0_2_000)) - -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_RAM_CONSOLE -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (0) -/*============================================================= - *REG ACCESS - *============================================================= - */ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | (val), ((void *)addr)) -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & ~(val), ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x88) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x8C) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x94) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ -do { \ - if (tscpu_debug_log == 1) { \ - pr_info(TSCPU_LOG_TAG fmt, ##args); \ - } \ -} while (0) - -#define tscpu_printk(fmt, args...) pr_info(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/*============================================================= - * Structures - *============================================================= - */ -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, - THERMAL_CONTROLLER1, - THERMAL_CONTROLLER_NUM -}; - -struct thermal_controller_speed { - unsigned int tempMonCtl1; - unsigned int tempMonCtl2; - unsigned int tempAhbPoll; -}; - -struct thermal_controller { - enum thermal_sensor ts[TS_ENUM_MAX]; - int ts_number; - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * Shared variables - *============================================================= - */ -/*In src/mtk_tc.c*/ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, -*it means polling_delay will be 1/5 of original interval -*after mtktscpu reports > 65C w/o exit point -*/ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif - -//#if !IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) -struct mt_gpufreq_power_table_info { - unsigned int gpufreq_khz; - unsigned int gpufreq_volt; - unsigned int gpufreq_power; -}; -//#endif - - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int mtk_gpufreq_register(struct mt_gpufreq_power_table_info *freqs, int num); -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature -* tscpu_curr_cpu_temp: current CPUSYS temperature -* tscpu_prev_gpu_temp: previous GPUSYS temperature -* tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_prev_cpu_temp, tscpu_prev_gpu_temp; -extern int tscpu_curr_cpu_temp, tscpu_curr_gpu_temp; -#endif - -#endif - -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif -extern char *adaptive_cooler_name; - -/*common/coolers/mtk_cooler_atm.c*/ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/*common/coolers/mtk_cooler_dtm.c*/ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif - -extern void tscpu_update_tempinfo(void); -extern int tscpu_max_temperature(void); - -/*In src/mtk_tc.c*/ -extern int get_io_reg_base(void); -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp(int tc_num, enum thermal_sensor type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern int tscpu_get_curr_temp(void); -extern int tscpu_get_curr_max_ts_temp(void); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void thermal_disable_all_periodoc_temp_sensing(void); - -/* -*In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c -*It's not our api, ask them to provide header file -*/ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* -*In drivers/misc/mediatek/auxadc/mt_auxadc.c -*It's not our api, ask them to provide header file -*/ -extern int IMM_IsAdcInitReady(void); - -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -#if 1 -extern void __iomem *thermal_base; -extern void __iomem *auxadc_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base -#else -#include -#define AUXADC_BASE_2 AUXADC_BASE -#define THERM_CTRL_BASE_2 THERM_CTRL_BASE -#define PERICFG_BASE_2 PERICFG_BASE -#define APMIXED_BASE_2 APMIXED_BASE -#endif - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) /*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) /*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) /*yes, 0x10000000*/ -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x000) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x004) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x008) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x00C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x010) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x014) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x018) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x01C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x024) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x028) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x02C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x030) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x034) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x038) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x03C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x040) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x044) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x048) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x04C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x050) - -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x054) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x058) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x05C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x060) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x064) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x068) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x06C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x070) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x074) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x078) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x07C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x080) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x084) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x088) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x08C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x090) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x094) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x098) - -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x09C) - -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x0A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x0A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x0A8) - -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x0B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x0B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x0B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x0BC) - -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x0C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x0C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x0C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x0CC) - -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x0F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x0F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x0F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x0FC) - - - -#define TEMPMONCTL0_1 (THERM_CTRL_BASE_2 + 0x100) -#define TEMPMONCTL1_1 (THERM_CTRL_BASE_2 + 0x104) -#define TEMPMONCTL2_1 (THERM_CTRL_BASE_2 + 0x108) -#define TEMPMONINT_1 (THERM_CTRL_BASE_2 + 0x10C) -#define TEMPMONINTSTS_1 (THERM_CTRL_BASE_2 + 0x110) -#define TEMPMONIDET0_1 (THERM_CTRL_BASE_2 + 0x114) -#define TEMPMONIDET1_1 (THERM_CTRL_BASE_2 + 0x118) -#define TEMPMONIDET2_1 (THERM_CTRL_BASE_2 + 0x11C) -#define TEMPH2NTHRE_1 (THERM_CTRL_BASE_2 + 0x124) -#define TEMPHTHRE_1 (THERM_CTRL_BASE_2 + 0x128) -#define TEMPCTHRE_1 (THERM_CTRL_BASE_2 + 0x12C) -#define TEMPOFFSETH_1 (THERM_CTRL_BASE_2 + 0x130) -#define TEMPOFFSETL_1 (THERM_CTRL_BASE_2 + 0x134) -#define TEMPMSRCTL0_1 (THERM_CTRL_BASE_2 + 0x138) -#define TEMPMSRCTL1_1 (THERM_CTRL_BASE_2 + 0x13C) -#define TEMPAHBPOLL_1 (THERM_CTRL_BASE_2 + 0x140) -#define TEMPAHBTO_1 (THERM_CTRL_BASE_2 + 0x144) -#define TEMPADCPNP0_1 (THERM_CTRL_BASE_2 + 0x148) -#define TEMPADCPNP1_1 (THERM_CTRL_BASE_2 + 0x14C) -#define TEMPADCPNP2_1 (THERM_CTRL_BASE_2 + 0x150) - -#define TEMPADCMUX_1 (THERM_CTRL_BASE_2 + 0x154) -#define TEMPADCEXT_1 (THERM_CTRL_BASE_2 + 0x158) -#define TEMPADCEXT1_1 (THERM_CTRL_BASE_2 + 0x15C) -#define TEMPADCEN_1 (THERM_CTRL_BASE_2 + 0x160) -#define TEMPPNPMUXADDR_1 (THERM_CTRL_BASE_2 + 0x164) -#define TEMPADCMUXADDR_1 (THERM_CTRL_BASE_2 + 0x168) -#define TEMPADCEXTADDR_1 (THERM_CTRL_BASE_2 + 0x16C) -#define TEMPADCEXT1ADDR_1 (THERM_CTRL_BASE_2 + 0x170) -#define TEMPADCENADDR_1 (THERM_CTRL_BASE_2 + 0x174) -#define TEMPADCVALIDADDR_1 (THERM_CTRL_BASE_2 + 0x178) -#define TEMPADCVOLTADDR_1 (THERM_CTRL_BASE_2 + 0x17C) -#define TEMPRDCTRL_1 (THERM_CTRL_BASE_2 + 0x180) -#define TEMPADCVALIDMASK_1 (THERM_CTRL_BASE_2 + 0x184) -#define TEMPADCVOLTAGESHIFT_1 (THERM_CTRL_BASE_2 + 0x188) -#define TEMPADCWRITECTRL_1 (THERM_CTRL_BASE_2 + 0x18C) -#define TEMPMSR0_1 (THERM_CTRL_BASE_2 + 0x190) -#define TEMPMSR1_1 (THERM_CTRL_BASE_2 + 0x194) -#define TEMPMSR2_1 (THERM_CTRL_BASE_2 + 0x198) -#define TEMPADCHADDR_1 (THERM_CTRL_BASE_2 + 0x19C) - -#define TEMPIMMD0_1 (THERM_CTRL_BASE_2 + 0x1A0) -#define TEMPIMMD1_1 (THERM_CTRL_BASE_2 + 0x1A4) -#define TEMPIMMD2_1 (THERM_CTRL_BASE_2 + 0x1A8) - -#define TEMPMONIDET3_1 (THERM_CTRL_BASE_2 + 0x1B0) -#define TEMPADCPNP3_1 (THERM_CTRL_BASE_2 + 0x1B4) -#define TEMPMSR3_1 (THERM_CTRL_BASE_2 + 0x1B8) -#define TEMPIMMD3_1 (THERM_CTRL_BASE_2 + 0x1BC) - -#define TEMPPROTCTL_1 (THERM_CTRL_BASE_2 + 0x1C0) -#define TEMPPROTTA_1 (THERM_CTRL_BASE_2 + 0x1C4) -#define TEMPPROTTB_1 (THERM_CTRL_BASE_2 + 0x1C8) -#define TEMPPROTTC_1 (THERM_CTRL_BASE_2 + 0x1CC) - -#define TEMPSPARE0_1 (THERM_CTRL_BASE_2 + 0x1F0) -#define TEMPSPARE1_1 (THERM_CTRL_BASE_2 + 0x1F4) -#define TEMPSPARE2_1 (THERM_CTRL_BASE_2 + 0x1F8) -#define TEMPSPARE3_1 (THERM_CTRL_BASE_2 + 0x1FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ -#define THERMAL_ENABLE_SEN0 0x1 -#define THERMAL_ENABLE_SEN1 0x2 -#define THERMAL_ENABLE_SEN2 0x4 -#define THERMAL_MONCTL0_MASK 0x00000007 - -#define THERMAL_PUNT_MASK 0x00000FFF -#define THERMAL_FSINTVL_MASK 0x03FF0000 -#define THERMAL_SPINTVL_MASK 0x000003FF -#define THERMAL_MON_INT_MASK 0x0007FFFF - -#define THERMAL_MON_CINTSTS0 0x000001 -#define THERMAL_MON_HINTSTS0 0x000002 -#define THERMAL_MON_LOINTSTS0 0x000004 -#define THERMAL_MON_HOINTSTS0 0x000008 -#define THERMAL_MON_NHINTSTS0 0x000010 -#define THERMAL_MON_CINTSTS1 0x000020 -#define THERMAL_MON_HINTSTS1 0x000040 -#define THERMAL_MON_LOINTSTS1 0x000080 -#define THERMAL_MON_HOINTSTS1 0x000100 -#define THERMAL_MON_NHINTSTS1 0x000200 -#define THERMAL_MON_CINTSTS2 0x000400 -#define THERMAL_MON_HINTSTS2 0x000800 -#define THERMAL_MON_LOINTSTS2 0x001000 -#define THERMAL_MON_HOINTSTS2 0x002000 -#define THERMAL_MON_NHINTSTS2 0x004000 -#define THERMAL_MON_TOINTSTS 0x008000 -#define THERMAL_MON_IMMDINTSTS0 0x010000 -#define THERMAL_MON_IMMDINTSTS1 0x020000 -#define THERMAL_MON_IMMDINTSTS2 0x040000 -#define THERMAL_MON_FILTINTSTS0 0x080000 -#define THERMAL_MON_FILTINTSTS1 0x100000 -#define THERMAL_MON_FILTINTSTS2 0x200000 - - -#define THERMAL_tri_SPM_State0 0x20000000 -#define THERMAL_tri_SPM_State1 0x40000000 -#define THERMAL_tri_SPM_State2 0x80000000 - - -#define THERMAL_MSRCTL0_MASK 0x00000007 -#define THERMAL_MSRCTL1_MASK 0x00000038 -#define THERMAL_MSRCTL2_MASK 0x000001C0 - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES CONFIG_NR_CPUS - -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6739/inc/tzbatt_initcfg.h deleted file mode 100644 index 537d3b71d239..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6739/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6739/inc/tzcpu_initcfg.h deleted file mode 100644 index 5abe5a197cdf..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (117000) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6739/src/Makefile b/drivers/misc/mediatek/thermal/mt6739/src/Makefile deleted file mode 100644 index 5b3a80177267..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/src/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright (C) 2015 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(MTK_PLATFORM) -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/$(MTK_PLATFORM)/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ - -obj-$(CONFIG_MTK_LEGACY_THERMAL) += mtk_tc.o -obj-$(CONFIG_MTK_LEGACY_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_MTK_LEGACY_THERMAL) += mtk_ts_6357buck1.o -obj-$(CONFIG_MTK_LEGACY_THERMAL) += mtk_ts_6357buck2.o diff --git a/drivers/misc/mediatek/thermal/mt6739/src/mtk_pmic_efuse.c b/drivers/misc/mediatek/thermal/mt6739/src/mtk_pmic_efuse.c deleted file mode 100644 index 23c4c944cd15..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/src/mtk_pmic_efuse.c +++ /dev/null @@ -1,327 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mtk_thermal_typedefs.h" -#include "mach/mtk_thermal.h" -#include -#include -#include -/*============================================================= - *Local variable definition - *============================================================= - */ -int mtktspmic_debug_log; -/* Cali */ -static __s32 g_o_vts; -static __s32 g_o_vts_2; -static __s32 g_o_vts_3; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; -static __s32 g_slope1 = 1; -static __s32 g_slope2 = 1; -static __s32 g_intercept; -static __s32 g_tsbuck1_slope1 = 1; -static __s32 g_tsbuck1_slope2 = 1; -static __s32 g_tsbuck1_intercept; -static __s32 g_tsbuck2_slope1 = 1; -static __s32 g_tsbuck2_slope2 = 1; -static __s32 g_tsbuck2_intercept; - -static DEFINE_MUTEX(TSPMIC_lock); -static int pre_temp1 = 0, PMIC_counter; -static int pre_tsbuck1_temp1 = 0, tsbuck1_cnt; -static int pre_tsbuck2_temp1 = 0, tsbuck2_cnt; -/*=============================================================*/ - -static __s32 pmic_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2)); - - mtktspmic_dprintk("[pmic_raw_to_temp] t_current=%d\n", t_current); - return t_current; -} - -static __s32 tsbuck1_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck1_intercept + ((g_tsbuck1_slope1 * y_curr) / (g_tsbuck1_slope2)); - - mtktspmic_dprintk("[tsbuck1_raw_to_temp] t_current=%d\n", t_current); - return t_current; -} - -static __s32 tsbuck2_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck2_intercept + ((g_tsbuck2_slope1 * y_curr) / (g_tsbuck2_slope2)); - - mtktspmic_dprintk("[tsbuck2_raw_to_temp] t_current=%d\n", t_current); - return t_current; -} - -static void mtktspmic_read_efuse(void) -{ - mtktspmic_info("[pmic_debug] start\n"); - g_o_vts = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS); - g_o_vts_2 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_2); - g_o_vts_3 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_3); - g_adc_cali_en = pmic_get_register_value(PMIC_AUXADC_EFUSE_ADC_CALI_EN); - g_degc_cali = pmic_get_register_value(PMIC_AUXADC_EFUSE_DEGC_CALI); - g_o_slope_sign = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE_SIGN); - g_o_slope = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE); - g_id = pmic_get_register_value(PMIC_AUXADC_EFUSE_ID); - - mtktspmic_info("[pmic_debug] 6357_efuse: g_o_vts = %d\n", g_o_vts); - mtktspmic_info("[pmic_debug] 6357_efuse: g_o_vts_2 = %d\n", g_o_vts_2); - mtktspmic_info("[pmic_debug] 6357_efuse: g_o_vts_3 = %d\n", g_o_vts_3); - mtktspmic_info("[pmic_debug] 6357_efuse: g_degc_cali = %d\n", g_degc_cali); - mtktspmic_info("[pmic_debug] 6357_efuse: g_adc_cali_en = %d\n", g_adc_cali_en); - mtktspmic_info("[pmic_debug] 6357_efuse: g_o_slope = %d\n", g_o_slope); - mtktspmic_info("[pmic_debug] 6357_efuse: g_o_slope_sign = %d\n", g_o_slope_sign); - mtktspmic_info("[pmic_debug] 6357_efuse: g_id = %d\n", g_id); - - mtktspmic_info("[pmic_debug] end\n"); -} - -void mtktspmic_cali_prepare(void) -{ - mtktspmic_read_efuse(); - - if (g_id == 0) - g_o_slope = 0; - - /* g_adc_cali_en=0;//FIX ME */ - - if (g_adc_cali_en == 0) { /* no calibration */ - mtktspmic_info("[pmic_debug] It isn't calibration values\n"); - g_o_vts = 1600; - g_o_vts_2 = 1600; - g_o_vts_3 = 1600; - g_degc_cali = 50; - g_o_slope = 0; - g_o_slope_sign = 0; - } - - /*SW workaround patch for mt6755 E2*/ - if (g_degc_cali < 38 || g_degc_cali > 60) - g_degc_cali = 53; - - mtktspmic_info("[pmic_debug] g_o_vts = 0x%x\n", g_o_vts); - mtktspmic_info("[pmic_debug] g_o_vts_2 = 0x%x\n", g_o_vts_2); - mtktspmic_info("[pmic_debug] g_o_vts_3 = 0x%x\n", g_o_vts_3); - mtktspmic_info("[pmic_debug] g_degc_cali = 0x%x\n", g_degc_cali); - mtktspmic_info("[pmic_debug] g_adc_cali_en = 0x%x\n", g_adc_cali_en); - mtktspmic_info("[pmic_debug] g_o_slope = 0x%x\n", g_o_slope); - mtktspmic_info("[pmic_debug] g_o_slope_sign = 0x%x\n", g_o_slope_sign); - mtktspmic_info("[pmic_debug] g_id = 0x%x\n", g_id); - -} - -void mtktspmic_cali_prepare2(void) -{ - __s32 vbe_t; - int factor; - - factor = 1681; - - g_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_slope2 = -(factor + g_o_slope); - else - g_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); /*0.001 degree */ - else - g_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); /*0.001 degree */ - - g_intercept = g_intercept + (g_degc_cali * (1000 / 2)); /* 1000 is for 0.1 degree */ - - mtktspmic_info("[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_slope1, g_slope2, g_intercept, vbe_t); - - factor = 1863; - - g_tsbuck1_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck1_slope2 = -(factor + g_o_slope); - else - g_tsbuck1_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_2) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck1_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); /*0.001 degree */ - else - g_tsbuck1_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); /*0.001 degree */ - - g_tsbuck1_intercept = g_tsbuck1_intercept + (g_degc_cali * (1000 / 2)); /* 1000 is for 0.1 degree */ - - mtktspmic_info("[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck1_slope1, g_tsbuck1_slope2, g_tsbuck1_intercept, vbe_t); - - factor = 1863; - - g_tsbuck2_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck2_slope2 = -(factor + g_o_slope); - else - g_tsbuck2_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_3) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck2_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); /*0.001 degree */ - else - g_tsbuck2_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); /*0.001 degree */ - - g_tsbuck2_intercept = g_tsbuck2_intercept + (g_degc_cali * (1000 / 2)); /* 1000 is for 0.1 degree */ - - mtktspmic_info("[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck2_slope1, g_tsbuck2_slope2, g_tsbuck2_intercept, vbe_t); -} - -int mtktspmic_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; - - mutex_lock(&TSPMIC_lock); - - temp = pmic_get_auxadc_value(AUXADC_LIST_MT6357_CHIP_TEMP); - - temp1 = pmic_raw_to_temp(temp); - - mtktspmic_dprintk("[pmic_debug] Raw=%d, T=%d\n", temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("[mtktspmic_get_hw_temp] raw=%d, PMIC T=%d", temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("[mtktspmic_get_hw_temp] temp(%d) too high, drop this data!\n", - temp1); - temp1 = pre_temp1; - } else if ((PMIC_counter != 0) - && (((pre_temp1 - temp1) > 30000) || ((temp1 - pre_temp1) > 30000))) { - mtktspmic_info("[mtktspmic_get_hw_temp] temp diff too large, drop this data\n"); - temp1 = pre_temp1; - } else { - /* update previous temp */ - pre_temp1 = temp1; - mtktspmic_dprintk("[mtktspmic_get_hw_temp] pre_temp1=%d\n", pre_temp1); - - if (PMIC_counter == 0) - PMIC_counter++; - } - - mutex_unlock(&TSPMIC_lock); - - return temp1; -} - -int mt6357tsbuck1_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; - - mutex_lock(&TSPMIC_lock); - - temp = pmic_get_auxadc_value(AUXADC_LIST_MT6357_BUCK1_TEMP); - - temp1 = tsbuck1_raw_to_temp(temp); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck1_temp1; - } else if ((tsbuck1_cnt != 0) - && (((pre_tsbuck1_temp1 - temp1) > 30000) || ((temp1 - pre_tsbuck1_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck1_temp1; - } else { - /* update previous temp */ - pre_tsbuck1_temp1 = temp1; - mtktspmic_dprintk("%s pre_tsbuck1_temp1=%d\n", __func__, pre_tsbuck1_temp1); - - if (tsbuck1_cnt == 0) - tsbuck1_cnt++; - } - - mutex_unlock(&TSPMIC_lock); - - return temp1; -} - -int mt6357tsbuck2_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; - - mutex_lock(&TSPMIC_lock); - - temp = pmic_get_auxadc_value(AUXADC_LIST_MT6357_BUCK2_TEMP); - - temp1 = tsbuck2_raw_to_temp(temp); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck2_temp1; - } else if ((tsbuck2_cnt != 0) - && (((pre_tsbuck2_temp1 - temp1) > 30000) || ((temp1 - pre_tsbuck2_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck2_temp1; - } else { - /* update previous temp */ - pre_tsbuck2_temp1 = temp1; - mtktspmic_dprintk("%s pre_tsbuck2_temp1=%d\n", __func__, pre_tsbuck2_temp1); - - if (tsbuck2_cnt == 0) - tsbuck2_cnt++; - } - - mutex_unlock(&TSPMIC_lock); - - return temp1; -} - diff --git a/drivers/misc/mediatek/thermal/mt6739/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6739/src/mtk_tc.c deleted file mode 100644 index e8f79629ca6e..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/src/mtk_tc.c +++ /dev/null @@ -1,1402 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; 0: turn off */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include -/*============================================================= - * Local variable definition - *============================================================= - */ - -/* -* Bank0: CPU (TS_MCU1) -* Bank1: GPU+SOC+MD (TS_MCU2) -*/ - -int tscpu_ts_temp[TS_ENUM_MAX]; -int tscpu_ts_temp_r[TS_ENUM_MAX]; - -/* chip dependent */ -/* -* TO-DO: I assume AHB bus frequecy is 78MHz. -* Please confirm it. -*/ -/* - * The tscpu_g_tc structure controls the polling rates and sensor mapping tables - * of all thermal controllers. - * If HW thermal controllers are more than you actually needed, you should pay - * attention to default setting of unneeded thermal controllers. - * Otherwise, these unneeded thermal controllers will be initialized and work - * unexpectedly. -*/ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {TS_MCU1, TS_MCU2, TS_MCU3, TS_ABB}, - .ts_number = 4, - .tc_offset = 0x0, - .tc_speed = { - 0x0000000C, - 0x0001003B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {}, - .ts_number = 0, - .tc_offset = 0x100, - .tc_speed = { - 0x0000000C, - 0x0001003B, - 0x0000030D - } /* 4.9ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -static __s32 g_o_vtsmcu3; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[TS_ENUM_MAX] = { 0 }; - -static __u32 calefuse1; -static __u32 calefuse2; -static __u32 calefuse3; - -/** - * If curr_temp >= tscpu_polling_trip_temp1, use interval - * else if cur_temp >= tscpu_polling_trip_temp2 && curr_temp < tscpu_polling_trip_temp1, - * use interval*tscpu_polling_factor1 - * else, use interval*tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, -*it means polling_delay will be 1/5 of original interval -*after mtktscpu reports > 65C w/o exit point -*/ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 2; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature -* tscpu_curr_cpu_temp: current CPUSYS temperature -* tscpu_prev_gpu_temp: previous GPUSYS temperature -* tscpu_curr_gpu_temp: current GPUSYS temperature - */ -int tscpu_prev_cpu_temp = 0, tscpu_prev_gpu_temp = 0; -int tscpu_curr_cpu_temp = 0, tscpu_curr_gpu_temp = 0; -#endif - -static int tscpu_curr_max_ts_temp; - -#if CFG_THERM_LVTS -__u32 lvts_count1_b30c; -__u32 lvts_count2_b30c; -__u32 lvts_count3_b30c; - -__u32 lvts_golden_temp1; -__u32 lvts_golden_temp2; -__u32 lvts_golden_temp3; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum thermal_sensor ts_name); -static void set_tc_trigger_hw_protect(int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ -void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - -void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - -int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -/*=============================================================*/ - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - -#if defined(CONFIG_MTK_CLKMGR) - tscpu_dprintk("%s\n", __func__); - /* ret = enable_clock(MT_CG_PERI_THERM, "THERMAL"); */ -#else - /* Use CCF instead */ - tscpu_dprintk("%s CCF\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); -#endif - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - -#if defined(CONFIG_MTK_CLKMGR) - tscpu_dprintk("%s\n", __func__); - /*ret = disable_clock(MT_CG_PERI_THERM, "THERMAL"); */ -#else - /*Use CCF instead*/ - tscpu_dprintk("%s CCF\n", __func__); - clk_disable_unprepare(therm_main); -#endif - return ret; -} - -/* TODO: FIXME */ -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("get_thermal_slope_intercept\n"); - - /* chip dependent */ - - /* - * If there are two or more sensors in a bank, choose the sensor calibration value of - * the dominant sensor. You can observe it in the thermal doc provided by Thermal DE. - * For example, - * Bank 1 is for SOC + GPU. Observe all scenarios related to GPU tests to - * determine which sensor is the highest temperature in all tests. - * Then, It is the dominant sensor. - * (Confirmed by Thermal DE Alfred Tsai) - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[0]; - break; - case THERMAL_BANK1: - x_roomt = g_x_roomt[1]; - break; - default: /*choose high temp */ - x_roomt = g_x_roomt[0]; - break; - } - - /* - * The equations in this function are confirmed by Thermal DE Alfred Tsai. - * Don't have to change until using next generation thermal sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1650 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1650 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1650 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1650 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - tscpu_printk("[cal] g_o_vtsmcu3 = %d\n", g_o_vtsmcu3); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - -#if CFG_THERM_LVTS - tscpu_printk("[cal] lvts_count1_b30c= %d\n", lvts_count1_b30c); - tscpu_printk("[cal] lvts_count2_b30c= %d\n", lvts_count2_b30c); - tscpu_printk("[cal] lvts_count3_b30c= %d\n", lvts_count3_b30c); - tscpu_printk("[cal] lvts_golden_temp1= %d\n", lvts_golden_temp1); - tscpu_printk("[cal] lvts_golden_temp2= %d\n", lvts_golden_temp2); - tscpu_printk("[cal] lvts_golden_temp3= %d\n", lvts_golden_temp3); -#endif -} - -void eDataCorrector(void) -{ - /* Confirmed with DE Kj Hsiao and DS Lin - * ADC_GE_T [9:0] Default:512 265 ~ 758 - * ADC_OE_T [9:0] Default:512 265 ~ 758 - * O_VTSMCU1(9b) Default:260 -8 ~ 484 - * O_VTSMCU2(9b) Default:260 -8 ~ 484 - * O_VTSMCU3(9b) Default:260 -8 to 484 - * O_VTSABB (9b) Default:260 -8 ~ 484 - * DEGC_cali (6b) Default:40 1 ~ 63 - * ADC_CALI_EN_T (1b) - * O_SLOPE_SIGN (1b) Default:0 - * O_SLOPE (6b) Default:0 - * ID (1b) - */ - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - if (g_o_vtsmcu3 < -8 || g_o_vtsmcu3 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu3\n"); - g_o_vtsmcu3 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2; -#if CFG_THERM_LVTS - __u32 lvtsdevinfo1, lvtsdevinfo2, lvtsdevinfo3; -#endif - - temp0 = get_devinfo_with_index(ADDRESS_INDEX_0); - temp1 = get_devinfo_with_index(ADDRESS_INDEX_1); - temp2 = get_devinfo_with_index(ADDRESS_INDEX_2); - - tscpu_printk("[calibration] temp0=0x%x, temp1=0x%x, temp2=0x%x\n", temp0, temp1, temp2); - - /* - * chip dependent - * ADC_GE_T [9:0] *(temp0)[19:10] - * ADC_OE_T [9:0] *(temp0)[9:0] - */ - g_adc_ge_t = ((temp0 & _BITMASK_(19:10)) >> 10); - g_adc_oe_t = (temp0 & _BITMASK_(9:0)); - - /* - * O_VTSMCU1 (9b) *(temp1)[8:0] - * O_VTSMCU2 (9b) *(temp1)[17:9] - * O_VTSMCU3 (9b) *(temp1)[26:18] - * O_VTS ABB(9b) *(temp2)[8:0] - */ - g_o_vtsmcu1 = (temp1 & _BITMASK_(8:0)); - g_o_vtsmcu2 = ((temp1 & _BITMASK_(17:9)) >> 9); - g_o_vtsmcu3 = ((temp1 & _BITMASK_(26:18)) >> 18); - g_o_vtsabb = (temp2 & _BITMASK_(8:0)); - - /* - * DEGC_cali(6b) *(temp0)[25:20] - * ADC_CALI_EN_T (1b) *(temp1)[28] - */ - g_degc_cali = ((temp0 & _BITMASK_(25:20)) >> 20); - g_adc_cali_en_t = ((temp1 & _BIT_(28)) >> 28); - - /* - * O_SLOPE_SIGN (1b) *(temp1)[29] - * O_SLOPE (6b) *(temp0)[31:26] - */ - g_o_slope_sign = ((temp1 & _BIT_(29)) >> 29); - g_o_slope = ((temp0 & _BITMASK_(31:26)) >> 26); - - /* ID (1b) *(temp1)[27] */ - g_id = ((temp1 & _BIT_(27)) >> 27); - - /* - * Check ID bit - * If ID=0 (TSMC sample) , ignore O_SLOPE EFuse value and set O_SLOPE=0. - * If ID=1 (non-TSMC sample), read O_SLOPE EFuse value for following calculation. - */ - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - g_o_vtsmcu3 = 260; - g_o_vtsabb = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - -#if CFG_THERM_LVTS - /* - * LVTS devinfo: - * 0x0x11F1_01C8 --> 118 - * 0x0x11F1_01CC --> 119 - * 0x0x11F1_07C4 --> 139 - */ - lvtsdevinfo1 = get_devinfo_with_index(118); - lvtsdevinfo2 = get_devinfo_with_index(119); - lvtsdevinfo3 = get_devinfo_with_index(139); - - tscpu_printk("[lvts_cal] 0: 0x%x, 1: 0x%x, 2: 0x%x\n", lvtsdevinfo1, lvtsdevinfo2, lvtsdevinfo3); - - lvts_count1_b30c = (lvtsdevinfo1 & _BITMASK_(23:0)); - lvts_count2_b30c = (lvtsdevinfo2 & _BITMASK_(23:0)); - lvts_count3_b30c = (lvtsdevinfo3 & _BITMASK_(23:0)); - - lvts_golden_temp1 = ((lvtsdevinfo1 & _BITMASK_(31:24)) >> 24); - lvts_golden_temp2 = ((lvtsdevinfo2 & _BITMASK_(31:24)) >> 24); - lvts_golden_temp3 = ((lvtsdevinfo3 & _BITMASK_(31:24)) >> 24); -#endif - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[TS_ENUM_MAX] = { 0 }; - int i = 0; - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[0] = (g_o_vtsmcu1 + 3350 - g_oe); - format[1] = (g_o_vtsmcu2 + 3350 - g_oe); - format[2] = (g_o_vtsmcu3 + 3350 - g_oe); - format[3] = (g_o_vtsabb + 3350 - g_oe); - - for (i = 0; i < TS_ENUM_MAX; i++) - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; /* x_roomt * 10000 */ - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < TS_ENUM_MAX; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum thermal_sensor ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1650+O_slope*10)/10*(18/15)*(1/10000)+X_roomtabb]*Gain*4096 + OE */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1650 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1650 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum thermal_sensor ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n",ts_name,xtoomt); */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) - format_4 = ((format_3 * 1000) / (1650 + g_o_slope * 10)); /* uint = 0.1 deg */ - else - format_4 = ((format_3 * 1000) / (1650 - g_o_slope * 10)); /* uint = 0.1 deg */ - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} - -/* -* Bank0: CPU (TS_MCU1) -* Bank1: GPU+SOC+MD (TS_MCU2) -*/ -int get_immediate_none_wrap(void) -{ - return -127000; -} - -/* chip dependent */ -int get_immediate_cpu_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU1]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_soc_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_md_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpu_wrap, - get_immediate_gpu_wrap -}; - -/* -* Bank0: CPU (TS_MCU1) -* Bank1: GPU+SOC+MD (TS_MCU2) -*/ -/* chip dependent */ -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tsabb_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_ABB]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - get_immediate_ts1_wrap, - get_immediate_ts2_wrap, - get_immediate_ts3_wrap, - get_immediate_tsabb_wrap -}; - -static void thermal_interrupt_handler(int tc_num) -{ - __u32 ret = 0, offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); /* write to clear interrupt status */ - tscpu_dprintk("[tIRQ] thermal_interrupt_handler,tc_num=0x%08x,ret=0x%08x\n", tc_num, ret); - - if (ret & THERMAL_MON_CINTSTS0) - tscpu_dprintk("[thermal_isr]: thermal sensor point 0 - cold interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS0) - tscpu_dprintk("[thermal_isr]: thermal sensor point 0 - hot interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS1) - tscpu_dprintk("[thermal_isr]: thermal sensor point 1 - hot interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS2) - tscpu_dprintk("[thermal_isr]: thermal sensor point 2 - hot interrupt trigger\n"); - - if (ret & THERMAL_tri_SPM_State0) - tscpu_dprintk("[thermal_isr]: Thermal state0 to trigger SPM state0\n"); - - if (ret & THERMAL_tri_SPM_State1) { - tscpu_dprintk("[thermal_isr]: Thermal state1 to trigger SPM state1\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_tri_SPM_State2) - tscpu_printk("[thermal_isr]: Thermal state2 to trigger SPM state2\n"); -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - __u32 ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - - ret = ret & 0xFF; - - tscpu_dprintk("thermal_interrupt_handler : THERMINTST = 0x%x\n", ret); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - mask = 1 << i; - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - __u32 offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - tempMonCtl1 = tscpu_g_tc[tc_num].tc_speed.tempMonCtl1; - tempMonCtl2 = tscpu_g_tc[tc_num].tc_speed.tempMonCtl2; - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.tempAhbPoll; - - /* Calculating period unit in Module clock x 256, and the Module clock */ - /* will be changed to 26M when Infrasys enters Sleep mode. */ - - /*bus clock 66M counting unit is 12 * 1/66M * 256 = 12 * 3.879us = 46.545 us */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - *filt interval is 1 * 46.545us = 46.545us, - *sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /*AHB polling is 781* 1/66M = 11.833us*/ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); /* temperature sampling control, 2 out of 4 samples */ -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); /* temperature sampling control, 4 out of 6 samples */ -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); /* temperature sampling control, 8 out of 10 samples */ -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); /* temperature sampling control, 16 out of 18 samples */ -#else /* default 1 */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); /* temperature sampling control, 1 sample */ -#endif - - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); /* exceed this polling time, IRQ would be inserted */ - - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); /* times for interrupt occurrance for SP2*/ - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); /* AHB address for auxadc mux selection */ - - mt_reg_sync_writel(0x800, offset + TEMPADCEN); /* AHB value for auxadc enable */ - - /* - *AHB address for auxadc enable (channel 0 immediate mode selected) - *this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); /* AHB address for auxadc voltage output */ - - - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); /* read valid & voltage are at the same register */ - /* indicate where the valid bit is (the 12th bit is valid bit and 1 is valid) */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); /* do not need to shift */ -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. -275000 to disable it. - */ -static void set_tc_trigger_hw_protect(int temperature, int temperature2, int tc_num) -{ - int temp = 0; - int raw_high; - enum thermal_sensor ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* temperature2=80000; test only */ - tscpu_dprintk("set_tc_trigger_hw_protect t1=%d t2=%d\n", temperature, temperature2); - - ts_name = tscpu_g_tc[tc_num].ts[0]; - - /* temperature to trigger SPM state2 */ - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); /* disable trigger SPM interrupt */ - - - mt_reg_sync_writel(0x20000, offset + TEMPPROTCTL); /* set hot to wakeup event control */ - - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); /* set hot to HOT wakeup event */ - - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); /* enable trigger Hot SPM interrupt */ -} - -static int read_tc_raw_and_temp(u32 *tempmsr_name, enum thermal_sensor ts_name) -{ - int temp = 0, raw = 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl((tempmsr_name)) & 0x0fff; - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_temp_r[ts_name] = raw; - - return temp * 100; -} - -void tscpu_thermal_read_tc_temp(int tc_num, enum thermal_sensor type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((u32 *)(offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, tscpu_ts_temp[type]); - break; - case 1: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((u32 *)(offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, tscpu_ts_temp[type]); - break; - case 2: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((u32 *)(offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, tscpu_ts_temp[type]); - break; - case 3: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((u32 *)(offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, tscpu_ts_temp[type]); - break; - default: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((u32 *)(offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, tscpu_ts_temp[type]); - break; - } -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); /* write temp to spare register */ - - mt_reg_sync_writel(1, offset + TEMPMONCTL1); /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); /* polling interval to check if temperature sense is ready */ - - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); /* times for interrupt occurrance */ - - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); /* temperature measurement sampling control */ - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) automatically by hw */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); /* AHB address for auxadc voltage output */ - - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); /* read valid & voltage are at the same register */ - /* indicate where the valid bit is (the 12th bit is valid bit and 1 is valid) */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); /* do not need to shift */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); /* enable auxadc mux & pnp write transaction */ - - - /* enable all interrupt except filter sense and immediate sense interrupt */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); /* enable all sensing point(sensing point 2 is unused)*/ - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_debug("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n",temp,cunt); */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_debug("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n",temp,cunt); */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_debug("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n",temp,cunt); */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_debug("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n",temp,cunt); */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum thermal_sensor type) -{ - switch (type) { - case TS_MCU1: - return TEMPADC_MCU1; - case TS_MCU2: - return TEMPADC_MCU2; - case TS_MCU3: - return TEMPADC_MCU3; - case TS_ABB: - return TEMPADC_ABB; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - /* tscpu_printk("thermal_pause_all_periodoc_temp_sensing\n"); */ - - /*config bank0,1,2 */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - /* tscpu_printk("thermal_release_all_periodoc_temp_sensing\n"); */ - - /*config bank0,1,2 */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - /* tscpu_printk("thermal_disable_all_periodoc_temp_sensing\n"); */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - /* tscpu_printk("thermal_disable_all_periodoc_temp_sensing:Bank_%d\n",i); */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); /* disable auxadc channel 11 immediate mode */ - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - int wd_api_ret; - struct wd_api *wd_api; - - tscpu_dprintk("tscpu_config_all_tc_hw_protect,temperature=%d,temperature2=%d,\n", - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /*spend 860~1463 us */ - /*Thermal need to config to direct reset mode - *this API provide by Weiqi Fu(RGU SW owner). - */ - - wd_api_ret = get_wd_api(&wd_api); - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_DIS, WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } - -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_debug("resume time spent, sec : %lu , usec : %lu\n", (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - set_tc_trigger_hw_protect(temperature, temperature2, i); /* Move thermal HW protection ahead... */ - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_EN, WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp |= 0x00000001; /* 1: Enables thermal control software reset */ - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp |= 0x00000001; /* 1: Enable reset Disables thermal control software reset */ - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "current temp:%d\n", tscpu_curr_max_ts_temp); - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_id = %d\n", g_id); - - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - seq_printf(m, "[cal] g_o_vtsmcu3 = %d\n", g_o_vtsmcu3); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < TS_ENUM_MAX; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - seq_printf(m, "calefuse1:0x%x\n", calefuse1); - seq_printf(m, "calefuse2:0x%x\n", calefuse2); - seq_printf(m, "calefuse3:0x%x\n", calefuse3); - - return 0; -} - -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of thermal controller driver - */ - tscpu_prev_cpu_temp = tscpu_curr_cpu_temp; - tscpu_prev_gpu_temp = tscpu_curr_gpu_temp; - - /* It is platform dependent which TS is better to present CPU/GPU temperature */ - tscpu_curr_cpu_temp = tscpu_ts_temp[TS_MCU1]; - - tscpu_curr_gpu_temp = tscpu_ts_temp[TS_MCU2]; -#endif - /* though tscpu_max_temperature is common, put it in mtk_ts_cpu.c is weird. */ - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] thermal_base=0x%p\n",thermal_base); */ - } - - /*get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - /*tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", thermal_irq_number);*/ - if (!thermal_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", thermal_irq_number); - return 0; - } - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - /*tscpu_printk("[THERM_CTRL] auxadc_ts_base=0x%p\n",auxadc_ts_base); */ - } - - - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,infracfg_ao"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - /*tscpu_printk("[THERM_CTRL] infracfg_ao_base=0x%p\n",infracfg_ao_base); */ - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,apmixed"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - /*tscpu_printk("[THERM_CTRL] apmixed_base=0x%p\n", th_apmixed_base); */ - } - - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); /**/ - if (!node) { - pr_err("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_err("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /*Need to confirm with DE*/ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /*The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if ((cg_freq & _BIT_(4)) == 1) - ahbClk = clockSource / 2; - else if ((cg_freq & _BIT_(3)) == 1) - ahbClk = clockSource / 4; - else if ((cg_freq & _BIT_(2)) == 1) - ahbClk = clockSource / 8; - else if ((cg_freq & _BIT_(1)) == 1) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /*tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm);*/ - /*tscpu_printk("AHB bus clock= %d MHz\n", ahbClk);*/ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "cpu %d", - get_immediate_cpu_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6739/src/mtk_ts_6357buck1.c b/drivers/misc/mediatek/thermal/mt6739/src/mtk_ts_6357buck1.c deleted file mode 100644 index d5a8a688e71c..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/src/mtk_ts_6357buck1.c +++ /dev/null @@ -1,517 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static int doing_tz_unregister; -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = "sysrst.6357buck1"; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6357tsbuck1_cur_temp; -/* -*static long int mt6357tsbuck1_start_temp; -*static long int mt6357tsbuck1_end_temp; -*/ -/*=============================================================*/ - -static int mt6357tsbuck1_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6357tsbuck1_get_hw_temp(); - mt6357tsbuck1_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6357tsbuck1_bind(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[mt6357tsbuck1_bind] %s\n", cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[mt6357tsbuck1_bind] error binding cooling dev\n"); - return -EINVAL; - } - - mtktspmic_dprintk("[mt6357tsbuck1_bind] binding OK, %d\n", table_val); - return 0; -} - -static int mt6357tsbuck1_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[mt6357tsbuck1_unbind] %s\n", cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[mt6357tsbuck1_unbind] error unbinding cooling dev\n"); - return -EINVAL; - } - - mtktspmic_dprintk("[mt6357tsbuck1_unbind] unbinding OK\n"); - return 0; -} - -static int mt6357tsbuck1_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6357tsbuck1_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6357tsbuck1_get_trip_type(struct thermal_zone_device *thermal, int trip, - enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6357tsbuck1_get_trip_temp(struct thermal_zone_device *thermal, int trip, - int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6357tsbuck1_get_crit_temp(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6357tsbuck1_dev_ops = { - .bind = mt6357tsbuck1_bind, - .unbind = mt6357tsbuck1_unbind, - .get_temp = mt6357tsbuck1_get_temp, - .get_mode = mt6357tsbuck1_get_mode, - .set_mode = mt6357tsbuck1_set_mode, - .get_trip_type = mt6357tsbuck1_get_trip_type, - .get_trip_temp = mt6357tsbuck1_get_trip_temp, - .get_crit_temp = mt6357tsbuck1_get_crit_temp, -}; - -static int mt6357tsbuck1_sysrst_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6357tsbuck1_sysrst_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6357tsbuck1_sysrst_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("MT6357TSBUCK1 OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - BUG(); -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6357tsbuck1_cooling_sysrst_ops = { - .get_max_state = mt6357tsbuck1_sysrst_get_max_state, - .get_cur_state = mt6357tsbuck1_sysrst_get_cur_state, - .set_cur_state = mt6357tsbuck1_sysrst_set_cur_state, -}; - -static int mt6357tsbuck1_read(struct seq_file *m, void *v) -{ - seq_printf(m, "[mt6357tsbuck1_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - seq_printf(m, "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]); - seq_printf(m, "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6357tsbuck1_register_thermal(void); -static void mt6357tsbuck1_unregister_thermal(void); - -static ssize_t mt6357tsbuck1_write(struct file *file, const char __user *buffer, size_t count, - loff_t *data) -{ - int len = 0; - int i; - - struct mt6357tsbuck1_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6357tsbuck1_data *ptr_mt6357tsbuck1_data; - - ptr_mt6357tsbuck1_data = kmalloc(sizeof(*ptr_mt6357tsbuck1_data), GFP_KERNEL); - - if (ptr_mt6357tsbuck1_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6357tsbuck1_data->desc) - 1)) ? count : (sizeof(ptr_mt6357tsbuck1_data->desc) - 1); - if (copy_from_user(ptr_mt6357tsbuck1_data->desc, buffer, len)) { - kfree(ptr_mt6357tsbuck1_data); - return 0; - } - - ptr_mt6357tsbuck1_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6357tsbuck1_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6357tsbuck1_data->trip[0], &ptr_mt6357tsbuck1_data->t_type[0], ptr_mt6357tsbuck1_data->bind0, - &ptr_mt6357tsbuck1_data->trip[1], &ptr_mt6357tsbuck1_data->t_type[1], ptr_mt6357tsbuck1_data->bind1, - &ptr_mt6357tsbuck1_data->trip[2], &ptr_mt6357tsbuck1_data->t_type[2], ptr_mt6357tsbuck1_data->bind2, - &ptr_mt6357tsbuck1_data->trip[3], &ptr_mt6357tsbuck1_data->t_type[3], ptr_mt6357tsbuck1_data->bind3, - &ptr_mt6357tsbuck1_data->trip[4], &ptr_mt6357tsbuck1_data->t_type[4], ptr_mt6357tsbuck1_data->bind4, - &ptr_mt6357tsbuck1_data->trip[5], &ptr_mt6357tsbuck1_data->t_type[5], ptr_mt6357tsbuck1_data->bind5, - &ptr_mt6357tsbuck1_data->trip[6], &ptr_mt6357tsbuck1_data->t_type[6], ptr_mt6357tsbuck1_data->bind6, - &ptr_mt6357tsbuck1_data->trip[7], &ptr_mt6357tsbuck1_data->t_type[7], ptr_mt6357tsbuck1_data->bind7, - &ptr_mt6357tsbuck1_data->trip[8], &ptr_mt6357tsbuck1_data->t_type[8], ptr_mt6357tsbuck1_data->bind8, - &ptr_mt6357tsbuck1_data->trip[9], &ptr_mt6357tsbuck1_data->t_type[9], ptr_mt6357tsbuck1_data->bind9, - &ptr_mt6357tsbuck1_data->time_msec) == 32) { - - mtktspmic_dprintk("[mt6357tsbuck1_write] mt6357tsbuck1_unregister_thermal\n"); - mt6357tsbuck1_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mt6357tsbuck1_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[mt6357tsbuck1_write] bad argument\n"); - kfree(ptr_mt6357tsbuck1_data); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6357tsbuck1_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] = - g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6357tsbuck1_data->bind0[i]; - g_bind1[i] = ptr_mt6357tsbuck1_data->bind1[i]; - g_bind2[i] = ptr_mt6357tsbuck1_data->bind2[i]; - g_bind3[i] = ptr_mt6357tsbuck1_data->bind3[i]; - g_bind4[i] = ptr_mt6357tsbuck1_data->bind4[i]; - g_bind5[i] = ptr_mt6357tsbuck1_data->bind5[i]; - g_bind6[i] = ptr_mt6357tsbuck1_data->bind6[i]; - g_bind7[i] = ptr_mt6357tsbuck1_data->bind7[i]; - g_bind8[i] = ptr_mt6357tsbuck1_data->bind8[i]; - g_bind9[i] = ptr_mt6357tsbuck1_data->bind9[i]; - } - - mtktspmic_dprintk("[mt6357tsbuck1_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2]); - mtktspmic_dprintk("g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]); - mtktspmic_dprintk("g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - mtktspmic_dprintk("[mt6357tsbuck1_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - mtktspmic_dprintk("cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6357tsbuck1_data->trip[i]; - - interval = ptr_mt6357tsbuck1_data->time_msec / 1000; - - mtktspmic_dprintk("[mt6357tsbuck1_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - mtktspmic_dprintk("trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8]); - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", trip_temp[9], interval * 1000); - - mtktspmic_dprintk("[mt6357tsbuck1_write] mt6357tsbuck1_register_thermal\n"); - mt6357tsbuck1_register_thermal(); - kfree(ptr_mt6357tsbuck1_data); - return count; - } - - mtktspmic_dprintk("[mt6357tsbuck1_write] bad argument\n"); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mt6357tsbuck1_write", - "Bad argument"); - #endif - kfree(ptr_mt6357tsbuck1_data); - return -EINVAL; -} - -static void mt6357tsbuck1_cancel_thermal_timer(void) -{ - /* cancel timer */ - /* pr_debug("mtkts_pmic_cancel_thermal_timer\n"); */ - - /* stop thermal framework polling when entering deep idle */ - if (thz_dev && !doing_tz_unregister) - cancel_delayed_work(&(thz_dev->poll_queue)); -} - -static void mt6357tsbuck1_start_thermal_timer(void) -{ - /* pr_debug("mtkts_pmic_start_thermal_timer\n"); */ - /* resume thermal framework polling when leaving deep idle */ - if (thz_dev != NULL && interval != 0 && !doing_tz_unregister) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); -} - -static int mt6357tsbuck1_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register("sysrst.6357buck1", NULL, - &mt6357tsbuck1_cooling_sysrst_ops); - return 0; -} - -static int mt6357tsbuck1_register_thermal(void) -{ - mtktspmic_dprintk("[mt6357tsbuck1_register_thermal]\n"); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register("mt6357tsbuck1", num_trip, NULL, - &mt6357tsbuck1_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6357tsbuck1_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6357tsbuck1_unregister_thermal(void) -{ - mtktspmic_dprintk("[mt6357tsbuck1_unregister_thermal]\n"); - - if (thz_dev) { - doing_tz_unregister = 1; - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - doing_tz_unregister = 0; - } -} - -static int mt6357tsbuck1_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6357tsbuck1_read, NULL); -} - -static const struct file_operations mt6357tsbuck1_fops = { - .owner = THIS_MODULE, - .open = mt6357tsbuck1_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6357tsbuck1_write, - .release = single_release, -}; - -static int __init mt6357tsbuck1_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6357tsbuck1_dir = NULL; - - mtktspmic_info("[mt6357tsbuck1_init]\n"); - - mtktspmic_cali_prepare(); - mtktspmic_cali_prepare2(); - - err = mt6357tsbuck1_register_cooler(); - if (err) - return err; - err = mt6357tsbuck1_register_thermal(); - if (err) - goto err_unreg; - - mt6357tsbuck1_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6357tsbuck1_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6357buck1", S_IRUGO | S_IWUSR | S_IWGRP, mt6357tsbuck1_dir, - &mt6357tsbuck1_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6357tsbuck1", mt6357tsbuck1_start_thermal_timer, mt6357tsbuck1_cancel_thermal_timer); - - return 0; - -err_unreg: - mt6357tsbuck1_unregister_cooler(); - return err; -} - -static void __exit mt6357tsbuck1_exit(void) -{ - mtktspmic_info("[mt6357tsbuck1_exit]\n"); - mt6357tsbuck1_unregister_thermal(); - mt6357tsbuck1_unregister_cooler(); - mtkTTimer_unregister("mt6357tsbuck1"); -} -module_init(mt6357tsbuck1_init); -module_exit(mt6357tsbuck1_exit); diff --git a/drivers/misc/mediatek/thermal/mt6739/src/mtk_ts_6357buck2.c b/drivers/misc/mediatek/thermal/mt6739/src/mtk_ts_6357buck2.c deleted file mode 100644 index 17ef5f8694cb..000000000000 --- a/drivers/misc/mediatek/thermal/mt6739/src/mtk_ts_6357buck2.c +++ /dev/null @@ -1,517 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static int doing_tz_unregister; -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = "sysrst.6357buck2"; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6357tsbuck2_cur_temp; -/* -*static long int mt6357tsbuck2_start_temp; -*static long int mt6357tsbuck2_end_temp; -*/ -/*=============================================================*/ - -static int mt6357tsbuck2_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6357tsbuck2_get_hw_temp(); - mt6357tsbuck2_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6357tsbuck2_bind(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[mt6357tsbuck2_bind] %s\n", cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[mt6357tsbuck2_bind] error binding cooling dev\n"); - return -EINVAL; - } - - mtktspmic_dprintk("[mt6357tsbuck2_bind] binding OK, %d\n", table_val); - return 0; -} - -static int mt6357tsbuck2_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[mt6357tsbuck2_unbind] %s\n", cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[mt6357tsbuck2_unbind] error unbinding cooling dev\n"); - return -EINVAL; - } - - mtktspmic_dprintk("[mt6357tsbuck2_unbind] unbinding OK\n"); - return 0; -} - -static int mt6357tsbuck2_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6357tsbuck2_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6357tsbuck2_get_trip_type(struct thermal_zone_device *thermal, int trip, - enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6357tsbuck2_get_trip_temp(struct thermal_zone_device *thermal, int trip, - int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6357tsbuck2_get_crit_temp(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6357tsbuck2_dev_ops = { - .bind = mt6357tsbuck2_bind, - .unbind = mt6357tsbuck2_unbind, - .get_temp = mt6357tsbuck2_get_temp, - .get_mode = mt6357tsbuck2_get_mode, - .set_mode = mt6357tsbuck2_set_mode, - .get_trip_type = mt6357tsbuck2_get_trip_type, - .get_trip_temp = mt6357tsbuck2_get_trip_temp, - .get_crit_temp = mt6357tsbuck2_get_crit_temp, -}; - -static int mt6357tsbuck2_sysrst_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6357tsbuck2_sysrst_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6357tsbuck2_sysrst_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("MT6357TSBUCK2 OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - BUG(); -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6357tsbuck2_cooling_sysrst_ops = { - .get_max_state = mt6357tsbuck2_sysrst_get_max_state, - .get_cur_state = mt6357tsbuck2_sysrst_get_cur_state, - .set_cur_state = mt6357tsbuck2_sysrst_set_cur_state, -}; - -static int mt6357tsbuck2_read(struct seq_file *m, void *v) -{ - seq_printf(m, "[mt6357tsbuck2_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - seq_printf(m, "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]); - seq_printf(m, "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6357tsbuck2_register_thermal(void); -static void mt6357tsbuck2_unregister_thermal(void); - -static ssize_t mt6357tsbuck2_write(struct file *file, const char __user *buffer, size_t count, - loff_t *data) -{ - int len = 0; - int i; - - struct mt6357tsbuck2_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6357tsbuck2_data *ptr_mt6357tsbuck2_data; - - ptr_mt6357tsbuck2_data = kmalloc(sizeof(*ptr_mt6357tsbuck2_data), GFP_KERNEL); - - if (ptr_mt6357tsbuck2_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6357tsbuck2_data->desc) - 1)) ? count : (sizeof(ptr_mt6357tsbuck2_data->desc) - 1); - if (copy_from_user(ptr_mt6357tsbuck2_data->desc, buffer, len)) { - kfree(ptr_mt6357tsbuck2_data); - return 0; - } - - ptr_mt6357tsbuck2_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6357tsbuck2_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6357tsbuck2_data->trip[0], &ptr_mt6357tsbuck2_data->t_type[0], ptr_mt6357tsbuck2_data->bind0, - &ptr_mt6357tsbuck2_data->trip[1], &ptr_mt6357tsbuck2_data->t_type[1], ptr_mt6357tsbuck2_data->bind1, - &ptr_mt6357tsbuck2_data->trip[2], &ptr_mt6357tsbuck2_data->t_type[2], ptr_mt6357tsbuck2_data->bind2, - &ptr_mt6357tsbuck2_data->trip[3], &ptr_mt6357tsbuck2_data->t_type[3], ptr_mt6357tsbuck2_data->bind3, - &ptr_mt6357tsbuck2_data->trip[4], &ptr_mt6357tsbuck2_data->t_type[4], ptr_mt6357tsbuck2_data->bind4, - &ptr_mt6357tsbuck2_data->trip[5], &ptr_mt6357tsbuck2_data->t_type[5], ptr_mt6357tsbuck2_data->bind5, - &ptr_mt6357tsbuck2_data->trip[6], &ptr_mt6357tsbuck2_data->t_type[6], ptr_mt6357tsbuck2_data->bind6, - &ptr_mt6357tsbuck2_data->trip[7], &ptr_mt6357tsbuck2_data->t_type[7], ptr_mt6357tsbuck2_data->bind7, - &ptr_mt6357tsbuck2_data->trip[8], &ptr_mt6357tsbuck2_data->t_type[8], ptr_mt6357tsbuck2_data->bind8, - &ptr_mt6357tsbuck2_data->trip[9], &ptr_mt6357tsbuck2_data->t_type[9], ptr_mt6357tsbuck2_data->bind9, - &ptr_mt6357tsbuck2_data->time_msec) == 32) { - - mtktspmic_dprintk("[mt6357tsbuck2_write] mt6357tsbuck2_unregister_thermal\n"); - mt6357tsbuck2_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mt6357tsbuck2_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[mt6357tsbuck2_write] bad argument\n"); - kfree(ptr_mt6357tsbuck2_data); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6357tsbuck2_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] = - g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6357tsbuck2_data->bind0[i]; - g_bind1[i] = ptr_mt6357tsbuck2_data->bind1[i]; - g_bind2[i] = ptr_mt6357tsbuck2_data->bind2[i]; - g_bind3[i] = ptr_mt6357tsbuck2_data->bind3[i]; - g_bind4[i] = ptr_mt6357tsbuck2_data->bind4[i]; - g_bind5[i] = ptr_mt6357tsbuck2_data->bind5[i]; - g_bind6[i] = ptr_mt6357tsbuck2_data->bind6[i]; - g_bind7[i] = ptr_mt6357tsbuck2_data->bind7[i]; - g_bind8[i] = ptr_mt6357tsbuck2_data->bind8[i]; - g_bind9[i] = ptr_mt6357tsbuck2_data->bind9[i]; - } - - mtktspmic_dprintk("[mt6357tsbuck2_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2]); - mtktspmic_dprintk("g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]); - mtktspmic_dprintk("g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - mtktspmic_dprintk("[mt6357tsbuck2_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - mtktspmic_dprintk("cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6357tsbuck2_data->trip[i]; - - interval = ptr_mt6357tsbuck2_data->time_msec / 1000; - - mtktspmic_dprintk("[mt6357tsbuck2_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - mtktspmic_dprintk("trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8]); - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", trip_temp[9], interval * 1000); - - mtktspmic_dprintk("[mt6357tsbuck2_write] mt6357tsbuck2_register_thermal\n"); - mt6357tsbuck2_register_thermal(); - kfree(ptr_mt6357tsbuck2_data); - return count; - } - - mtktspmic_dprintk("[mt6357tsbuck2_write] bad argument\n"); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mt6357tsbuck2_write", - "Bad argument"); - #endif - kfree(ptr_mt6357tsbuck2_data); - return -EINVAL; -} - -static void mt6357tsbuck2_cancel_thermal_timer(void) -{ - /* cancel timer */ - /* pr_debug("mtkts_pmic_cancel_thermal_timer\n"); */ - - /* stop thermal framework polling when entering deep idle */ - if (thz_dev && !doing_tz_unregister) - cancel_delayed_work(&(thz_dev->poll_queue)); -} - -static void mt6357tsbuck2_start_thermal_timer(void) -{ - /* pr_debug("mtkts_pmic_start_thermal_timer\n"); */ - /* resume thermal framework polling when leaving deep idle */ - if (thz_dev != NULL && interval != 0 && !doing_tz_unregister) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); -} - -static int mt6357tsbuck2_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register("sysrst.6357buck2", NULL, - &mt6357tsbuck2_cooling_sysrst_ops); - return 0; -} - -static int mt6357tsbuck2_register_thermal(void) -{ - mtktspmic_dprintk("[mt6357tsbuck2_register_thermal]\n"); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register("mt6357tsbuck2", num_trip, NULL, - &mt6357tsbuck2_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6357tsbuck2_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6357tsbuck2_unregister_thermal(void) -{ - mtktspmic_dprintk("[mt6357tsbuck2_unregister_thermal]\n"); - - if (thz_dev) { - doing_tz_unregister = 1; - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - doing_tz_unregister = 0; - } -} - -static int mt6357tsbuck2_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6357tsbuck2_read, NULL); -} - -static const struct file_operations mt6357tsbuck2_fops = { - .owner = THIS_MODULE, - .open = mt6357tsbuck2_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6357tsbuck2_write, - .release = single_release, -}; - -static int __init mt6357tsbuck2_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6357tsbuck2_dir = NULL; - - mtktspmic_info("[mt6357tsbuck2_init]\n"); - - mtktspmic_cali_prepare(); - mtktspmic_cali_prepare2(); - - err = mt6357tsbuck2_register_cooler(); - if (err) - return err; - err = mt6357tsbuck2_register_thermal(); - if (err) - goto err_unreg; - - mt6357tsbuck2_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6357tsbuck2_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6357buck2", S_IRUGO | S_IWUSR | S_IWGRP, mt6357tsbuck2_dir, - &mt6357tsbuck2_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6357tsbuck2", mt6357tsbuck2_start_thermal_timer, mt6357tsbuck2_cancel_thermal_timer); - - return 0; - -err_unreg: - mt6357tsbuck2_unregister_cooler(); - return err; -} - -static void __exit mt6357tsbuck2_exit(void) -{ - mtktspmic_info("[mt6357tsbuck2_exit]\n"); - mt6357tsbuck2_unregister_thermal(); - mt6357tsbuck2_unregister_cooler(); - mtkTTimer_unregister("mt6357tsbuck2"); -} -module_init(mt6357tsbuck2_init); -module_exit(mt6357tsbuck2_exit); diff --git a/drivers/misc/mediatek/thermal/mt6761/Makefile b/drivers/misc/mediatek/thermal/mt6761/Makefile deleted file mode 100644 index 60b4650e6fc3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2017 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6761/inc/clatm_initcfg.h deleted file mode 100644 index 73f9fca2033b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/clatm_initcfg.h +++ /dev/null @@ -1,56 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (75000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (2000) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (400) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (2000) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (200) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (700) - -#define CLATM_INIT_CFG_1_TARGET_TJ (65000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (3000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (75000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3960) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (600) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (10) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (100) - -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/mach/mtk_thermal.h b/drivers/misc/mediatek/thermal/mt6761/inc/mach/mtk_thermal.h deleted file mode 100644 index 30dfdf5689ad..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/mach/mtk_thermal.h +++ /dev/null @@ -1,142 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __MT6761_THERMAL_H__ -#define __MT6761_THERMAL_H__ - -#include -#include -#include -#include - -#include -#include - -#include "mt-plat/sync_write.h" - -#if IS_ENABLED(CONFIG_MTK_GPU_SUPPORT) -#include "mtk_gpufreq.h" -#endif - -/* - *Bank0: CA7L (TSMCU1) - *Bank3: GPU (TSMCU2) - *Bank4: SoC (TSMCU3) - */ - -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - */ -enum thermal_sensor { - TS_MCU1 = 0, - TS_MCU2, - TS_MCU3, - TS_ENUM_MAX, -}; - -enum thermal_bank_name { - THERMAL_BANK0 = 0, - THERMAL_BANK3 = 1, - THERMAL_BANK4 = 2, - THERMAL_BANK_NUM -}; - -struct TS_PTPOD { - unsigned int ts_MTS; - unsigned int ts_BTS; -}; - -extern int mtktscpu_limited_dmips; -extern int tscpu_get_temperature_range(void); -/* Valid if it returns 1, invalid if it returns 0. */ -extern int tscpu_is_temp_valid(void); - -extern void get_thermal_slope_intercept -(struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); - -extern void set_taklking_flag(bool flag); - -extern int tscpu_get_cpu_temp(void); - -extern int tscpu_get_temp_by_bank(enum thermal_bank_name ts_bank); - -#define THERMAL_WRAP_WR32(val, addr) \ - mt_reg_sync_writel((val), ((void *)addr)) - -extern int get_immediate_gpu_wrap(void); - -extern int get_immediate_cpuL_wrap(void); - -extern int get_immediate_cpuLL_wrap(void); - -extern int get_immediate_mcucci_wrap(void); - -/* Added for DLPT. */ -extern int tscpu_get_min_cpu_pwr(void); - -extern int tscpu_get_min_gpu_pwr(void); - -/* Five thermal sensors. */ -enum mtk_thermal_sensor_cpu_id_met { - MTK_THERMAL_SENSOR_TS1 = 0, - MTK_THERMAL_SENSOR_TS2, - MTK_THERMAL_SENSOR_TS3, - - ATM_CPU_LIMIT, - ATM_GPU_LIMIT, - - MTK_THERMAL_SENSOR_CPU_COUNT -}; - - -extern int tscpu_get_cpu_temp_met(enum mtk_thermal_sensor_cpu_id_met id); - -typedef void (*met_thermalsampler_funcMET)(void); - -extern void mt_thermalsampler_registerCB(met_thermalsampler_funcMET pCB); - -extern void mtkTTimer_cancel_timer(void); - -extern void mtkTTimer_start_timer(void); - -extern int mtkts_bts_get_hw_temp(void); - -extern int get_immediate_ts1_wrap(void); - -extern int get_immediate_ts2_wrap(void); - -extern int get_immediate_ts3_wrap(void); - -extern int get_immediate_ts4_wrap(void); - -extern int get_immediate_ts5_wrap(void); - - -extern int (*get_immediate_tsX[TS_ENUM_MAX])(void); - -extern int is_cpu_power_unlimit(void); /* in mtk_ts_cpu.c */ - -extern int is_cpu_power_min(void); /* in mtk_ts_cpu.c */ - -extern int get_cpu_target_tj(void); - -extern int get_cpu_target_offset(void); - -extern int mtk_gpufreq_register -(struct mt_gpufreq_power_table_info *freqs, int num); - -extern int get_target_tj(void); - -extern int mtk_thermal_get_tpcb_target(void); - -extern void thermal_set_big_core_speed -(unsigned int tempMonCtl1, unsigned int tempMonCtl2, unsigned int tempAhbPoll); - -/* return value(1): cooler of abcct/abcct_lcmoff is deactive, - * and no thermal current limit. - */ -extern int mtk_cooler_is_abcct_unlimit(void); - -#endif /* __MT6761_THERMAL_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_cl_amddulthro.h b/drivers/misc/mediatek/thermal/mt6761/inc/mtk_cl_amddulthro.h deleted file mode 100644 index b0853b87cd30..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_cl_amddulthro.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __MT_CL_AMDDULTHRO_H__ -#define __MT_CL_AMDDULTHRO_H__ - -extern int amddulthro_backoff(int level); - -#endif /* __MT_CL_AMDDULTHRO_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6761/inc/mtk_cooler_setting.h deleted file mode 100644 index 62e43f91d596..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ - /* mtk_cooler_mutt.c */ -/* 1: turn on MD throttle V2 cooler; 0: turn off */ -#define FEATURE_MUTT_V2 (1) - -/* mtk_cooler_mutt.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6761/inc/mtk_thermal_ipi.h deleted file mode 100644 index e0d061d61e8f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM -#include "sspm_ipi.h" -#include - -#define THERMAL_SLOT_NUM (4) - -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_sspm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6761/inc/mtk_ts_setting.h deleted file mode 100644 index 0fd1e45ea7da..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/mtk_ts_setting.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (1) - - -/* - * Request HPM in Low temperature condition - */ -#define THERMAL_LT_SET_HPM (1) - -#if THERMAL_LT_SET_HPM -extern int enter_hpm_temp; -extern int leave_hpm_temp; -extern int enable_hpm_temp; -#endif - -/*In src/mtk_tc.c*/ -extern int get_immediate_ts4_wrap(void); - -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_6311buck.h b/drivers/misc/mediatek/thermal/mt6761/inc/tmp_6311buck.h deleted file mode 100644 index 5dd3d4fcd1bf..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_6311buck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_6311BUCK_H__ -#define __TMP_6311BUCK_H__ - -extern int is_ext_buck_exist(void); - -#endif /* __TMP_6311BUCK_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_battery.h b/drivers/misc/mediatek/thermal/mt6761/inc/tmp_battery.h deleted file mode 100644 index 8f1bf646dc9b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_battery.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_BATTERY_H__ -#define __TMP_BATTERY_H__ - -#include -/* Extern two API functions from battery driver - * to limit max charging current. - */ -/** - * return value means charging current in mA - * -1 means error - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int get_bat_charging_current_level(void); - -/** - * current_limit means limit of charging current in mA - * -1 means no limit - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int set_bat_charging_current_limit(int current_limit); -extern enum charger_type mt_get_charger_type(void); - -extern int read_tbat_value(void); - -#endif /* __TMP_BATTERY_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6761/inc/tmp_bts.h deleted file mode 100644 index e35a13c94aa0..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_bts.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -/* chip dependent */ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) - -#define BTS_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_btscharger.h b/drivers/misc/mediatek/thermal/mt6761/inc/tmp_btscharger.h deleted file mode 100644 index 7a7d463ec0c9..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tmp_btscharger.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#ifndef __TMP_BTS_CHARGER_H__ -#define __TMP_BTS_CHARGER_H__ - -/* chip dependent */ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN2_NTC (2) -/* 390K, pull up resister */ -#define BTSCHARGER_RAP_PULL_UP_R 390000 -/* base on 100K NTC temp - * default value -40 deg - */ -#define BTSCHARGER_TAP_OVER_CRITICAL_LOW 4397119 -/* 1.8V ,pull up voltage */ -#define BTSCHARGER_RAP_PULL_UP_VOLTAGE 1800 -/* default is NCP15WF104F03RC(100K) */ -#define BTSCHARGER_RAP_NTC_TABLE 7 - -#define BTSCHARGER_RAP_ADC_CHANNEL AUX_IN2_NTC /* default is 2 */ -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_CHARGER_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6761/inc/tscpu_settings.h deleted file mode 100644 index 5e9deb8b5b4a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tscpu_settings.h +++ /dev/null @@ -1,750 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - * - */ - -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include -#include - -#include "mach/mtk_thermal.h" - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" -#include - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned int)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned int) -1 >> (31 - ((1) ? \ - _bits_))) & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() long long thermal_pTime_us, \ - thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_notice(TSCPU_LOG_TAG "%s: %llu us\n", \ - __func__, thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_notice(TSCPU_LOG_TAG "Warning: tProfiling " \ - "uses incorrect %s %d\n", __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/*Enable thermal controller CG*/ -#define THERMAL_EBABLE_TC_CG - -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. - * Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -/* Define this in tscpu_settings.h enables this feature. - * It polls CPU TS in hrtimer and run ATM in RT 98 kthread. - */ -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) - -/* 1: mtk_tc.c supports LVTS; 0: o.w. */ -#define CFG_THERM_LVTS (0) - -/*============================================================= - * Chip related - *============================================================= - */ -/* double check */ -//#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE TS_CON0_TM /* depend on CPU design*/ - -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ -#define TS_TURN_ON 0xFFFFFFCF /* turn on TS_CON1[5:4] 2'b 00 - * 11001111 -> 0xCF ~(0x30 - */ -//#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ -#define TS_TURN_OFF 0x30000000 /* turn off thermal*/ - - -/*chip dependent*/ -#define ADDRESS_INDEX_0 101 -#define ADDRESS_INDEX_1 100 -#define ADDRESS_INDEX_2 102 - - -#define CLEAR_TEMP 26111 - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - - -#define TSCON0_bit_29_28_00 0x00000000 /* TSCON0[29:28]=2'b00*/ -#define TSCON0_bit_29_28_01 0x10000000 /* TSCON0[29:28]=2'b01*/ -#define TSCON0_bit_29_28_10 0x20000000 /* TSCON0[29:28]=2'b10*/ -#define TSCON0_bit_29_28_11 0x30000000 /* TSCON0[29:28]=2'b11*/ - -#define TSCON0_bit_29_28_MASK 0x30000000 - -/* ADC value to mcu */ -/*chip dependent*/ -#define TSCPU_NEW_FLOW 1 -#if TSCPU_NEW_FLOW -#define TEMPADC_MCU1 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_000)) -#define TEMPADC_MCU2 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_001)) -#define TEMPADC_MCU3 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_010)) -#define TEMPADC_MCU4 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_011)) -#define TEMPADC_MCU5 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_100)) - -#define TEMPADC_ABB \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_01)|(0x07&TSCON1_bit_0_2_000)) -#else -#define TEMPADC_MCU1 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_000)) -#define TEMPADC_MCU2 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_001)) -#define TEMPADC_MCU3 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_010)) -#define TEMPADC_MCU4 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_011)) -#define TEMPADC_MCU5 ((0x30&TSCON1_bit_4_5_00)|(0x07&TSCON1_bit_0_2_100)) -#define TEMPADC_ABB ((0x30&TSCON1_bit_4_5_01)|(0x07&TSCON1_bit_0_2_000)) -#endif -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_AEE_IPANIC -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (0) -/*============================================================= - *REG ACCESS - *============================================================= - */ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | \ - (val), ((void *)addr)) - -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & \ - ~(val), ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal-legacy" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x88) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x8C) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x94) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ - do { \ - if (tscpu_debug_log == 1) { \ - pr_notice(TSCPU_LOG_TAG fmt, ##args); \ - } \ - } while (0) - -#define tscpu_printk(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/*============================================================= - * Structures - *============================================================= - */ -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, - THERMAL_CONTROLLER1, - THERMAL_CONTROLLER_NUM -}; - -struct thermal_controller_speed { - unsigned int tempMonCtl1; - unsigned int tempMonCtl2; - unsigned int tempAhbPoll; -}; - -struct thermal_controller { - enum thermal_sensor ts[TS_ENUM_MAX]; - int ts_number; - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * Shared variables - *============================================================= - */ -/*In src/mtk_tc.c*/ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - *it means polling_delay will be 1/5 of original interval - *after mtktscpu reports > 65C w/o exit point - */ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif -extern struct platform_device *tscpu_pdev; - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_prev_cpu_temp, tscpu_prev_gpu_temp; -extern int tscpu_curr_cpu_temp, tscpu_curr_gpu_temp; -#endif - -#endif - -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif -extern char *adaptive_cooler_name; - -/*common/coolers/mtk_cooler_atm.c*/ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/*common/coolers/mtk_cooler_dtm.c*/ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif - -extern void tscpu_update_tempinfo(void); -extern int tscpu_max_temperature(void); - -/*In src/mtk_tc.c*/ -extern int get_io_reg_base(void); -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp - (int tc_num, enum thermal_sensor type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler - (int irq, void *dev_id); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern int tscpu_get_curr_temp(void); -extern int tscpu_get_curr_max_ts_temp(void); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void thermal_disable_all_periodoc_temp_sensing(void); - -/* - *In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c - *It's not our api, ask them to provide header file - */ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* - *In drivers/misc/mediatek/auxadc/mt_auxadc.c - *It's not our api, ask them to provide header file - */ -extern int IMM_IsAdcInitReady(void); -#if defined(CATM_TPCB_EXTEND) -extern void mtk_thermal_get_turbo(void); -extern int g_turbo_bin; -#endif -/*aee related*/ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -extern int aee_rr_init_thermal_temp(int num); -extern int aee_rr_rec_thermal_temp(int index, s8 val); -extern void aee_rr_rec_thermal_status(u8 val); -extern void aee_rr_rec_thermal_ATM_status(u8 val); -extern void aee_rr_rec_thermal_ktime(u64 val); - -extern s8 aee_rr_curr_thermal_temp(int index); -extern u8 aee_rr_curr_thermal_status(void); -extern u8 aee_rr_curr_thermal_ATM_status(void); -extern u64 aee_rr_curr_thermal_ktime(void); -#endif -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -#if TSCPU_NEW_FLOW -extern void __iomem *thermal_base; -extern void __iomem *auxadc_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base -#else -#include -#define AUXADC_BASE_2 AUXADC_BASE -#define THERM_CTRL_BASE_2 THERM_CTRL_BASE -#define PERICFG_BASE_2 PERICFG_BASE -#define APMIXED_BASE_2 APMIXED_BASE -#endif - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -/*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) -/*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) -/*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x000) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x004) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x008) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x00C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x010) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x014) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x018) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x01C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x024) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x028) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x02C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x030) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x034) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x038) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x03C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x040) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x044) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x048) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x04C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x050) - -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x054) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x058) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x05C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x060) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x064) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x068) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x06C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x070) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x074) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x078) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x07C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x080) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x084) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x088) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x08C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x090) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x094) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x098) - -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x09C) - -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x0A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x0A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x0A8) - -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x0B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x0B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x0B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x0BC) - -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x0C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x0C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x0C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x0CC) - -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x0F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x0F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x0F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x0FC) - - - -#define TEMPMONCTL0_1 (THERM_CTRL_BASE_2 + 0x100) -#define TEMPMONCTL1_1 (THERM_CTRL_BASE_2 + 0x104) -#define TEMPMONCTL2_1 (THERM_CTRL_BASE_2 + 0x108) -#define TEMPMONINT_1 (THERM_CTRL_BASE_2 + 0x10C) -#define TEMPMONINTSTS_1 (THERM_CTRL_BASE_2 + 0x110) -#define TEMPMONIDET0_1 (THERM_CTRL_BASE_2 + 0x114) -#define TEMPMONIDET1_1 (THERM_CTRL_BASE_2 + 0x118) -#define TEMPMONIDET2_1 (THERM_CTRL_BASE_2 + 0x11C) -#define TEMPH2NTHRE_1 (THERM_CTRL_BASE_2 + 0x124) -#define TEMPHTHRE_1 (THERM_CTRL_BASE_2 + 0x128) -#define TEMPCTHRE_1 (THERM_CTRL_BASE_2 + 0x12C) -#define TEMPOFFSETH_1 (THERM_CTRL_BASE_2 + 0x130) -#define TEMPOFFSETL_1 (THERM_CTRL_BASE_2 + 0x134) -#define TEMPMSRCTL0_1 (THERM_CTRL_BASE_2 + 0x138) -#define TEMPMSRCTL1_1 (THERM_CTRL_BASE_2 + 0x13C) -#define TEMPAHBPOLL_1 (THERM_CTRL_BASE_2 + 0x140) -#define TEMPAHBTO_1 (THERM_CTRL_BASE_2 + 0x144) -#define TEMPADCPNP0_1 (THERM_CTRL_BASE_2 + 0x148) -#define TEMPADCPNP1_1 (THERM_CTRL_BASE_2 + 0x14C) -#define TEMPADCPNP2_1 (THERM_CTRL_BASE_2 + 0x150) - -#define TEMPADCMUX_1 (THERM_CTRL_BASE_2 + 0x154) -#define TEMPADCEXT_1 (THERM_CTRL_BASE_2 + 0x158) -#define TEMPADCEXT1_1 (THERM_CTRL_BASE_2 + 0x15C) -#define TEMPADCEN_1 (THERM_CTRL_BASE_2 + 0x160) -#define TEMPPNPMUXADDR_1 (THERM_CTRL_BASE_2 + 0x164) -#define TEMPADCMUXADDR_1 (THERM_CTRL_BASE_2 + 0x168) -#define TEMPADCEXTADDR_1 (THERM_CTRL_BASE_2 + 0x16C) -#define TEMPADCEXT1ADDR_1 (THERM_CTRL_BASE_2 + 0x170) -#define TEMPADCENADDR_1 (THERM_CTRL_BASE_2 + 0x174) -#define TEMPADCVALIDADDR_1 (THERM_CTRL_BASE_2 + 0x178) -#define TEMPADCVOLTADDR_1 (THERM_CTRL_BASE_2 + 0x17C) -#define TEMPRDCTRL_1 (THERM_CTRL_BASE_2 + 0x180) -#define TEMPADCVALIDMASK_1 (THERM_CTRL_BASE_2 + 0x184) -#define TEMPADCVOLTAGESHIFT_1 (THERM_CTRL_BASE_2 + 0x188) -#define TEMPADCWRITECTRL_1 (THERM_CTRL_BASE_2 + 0x18C) -#define TEMPMSR0_1 (THERM_CTRL_BASE_2 + 0x190) -#define TEMPMSR1_1 (THERM_CTRL_BASE_2 + 0x194) -#define TEMPMSR2_1 (THERM_CTRL_BASE_2 + 0x198) -#define TEMPADCHADDR_1 (THERM_CTRL_BASE_2 + 0x19C) - -#define TEMPIMMD0_1 (THERM_CTRL_BASE_2 + 0x1A0) -#define TEMPIMMD1_1 (THERM_CTRL_BASE_2 + 0x1A4) -#define TEMPIMMD2_1 (THERM_CTRL_BASE_2 + 0x1A8) - -#define TEMPMONIDET3_1 (THERM_CTRL_BASE_2 + 0x1B0) -#define TEMPADCPNP3_1 (THERM_CTRL_BASE_2 + 0x1B4) -#define TEMPMSR3_1 (THERM_CTRL_BASE_2 + 0x1B8) -#define TEMPIMMD3_1 (THERM_CTRL_BASE_2 + 0x1BC) - -#define TEMPPROTCTL_1 (THERM_CTRL_BASE_2 + 0x1C0) -#define TEMPPROTTA_1 (THERM_CTRL_BASE_2 + 0x1C4) -#define TEMPPROTTB_1 (THERM_CTRL_BASE_2 + 0x1C8) -#define TEMPPROTTC_1 (THERM_CTRL_BASE_2 + 0x1CC) - -#define TEMPSPARE0_1 (THERM_CTRL_BASE_2 + 0x1F0) -#define TEMPSPARE1_1 (THERM_CTRL_BASE_2 + 0x1F4) -#define TEMPSPARE2_1 (THERM_CTRL_BASE_2 + 0x1F8) -#define TEMPSPARE3_1 (THERM_CTRL_BASE_2 + 0x1FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ -#define THERMAL_ENABLE_SEN0 0x1 -#define THERMAL_ENABLE_SEN1 0x2 -#define THERMAL_ENABLE_SEN2 0x4 -#define THERMAL_MONCTL0_MASK 0x00000007 - -#define THERMAL_PUNT_MASK 0x00000FFF -#define THERMAL_FSINTVL_MASK 0x03FF0000 -#define THERMAL_SPINTVL_MASK 0x000003FF -#define THERMAL_MON_INT_MASK 0x0007FFFF - -#define THERMAL_MON_CINTSTS0 0x000001 -#define THERMAL_MON_HINTSTS0 0x000002 -#define THERMAL_MON_LOINTSTS0 0x000004 -#define THERMAL_MON_HOINTSTS0 0x000008 -#define THERMAL_MON_NHINTSTS0 0x000010 -#define THERMAL_MON_CINTSTS1 0x000020 -#define THERMAL_MON_HINTSTS1 0x000040 -#define THERMAL_MON_LOINTSTS1 0x000080 -#define THERMAL_MON_HOINTSTS1 0x000100 -#define THERMAL_MON_NHINTSTS1 0x000200 -#define THERMAL_MON_CINTSTS2 0x000400 -#define THERMAL_MON_HINTSTS2 0x000800 -#define THERMAL_MON_LOINTSTS2 0x001000 -#define THERMAL_MON_HOINTSTS2 0x002000 -#define THERMAL_MON_NHINTSTS2 0x004000 -#define THERMAL_MON_TOINTSTS 0x008000 -#define THERMAL_MON_IMMDINTSTS0 0x010000 -#define THERMAL_MON_IMMDINTSTS1 0x020000 -#define THERMAL_MON_IMMDINTSTS2 0x040000 -#define THERMAL_MON_FILTINTSTS0 0x080000 -#define THERMAL_MON_FILTINTSTS1 0x100000 -#define THERMAL_MON_FILTINTSTS2 0x200000 - - -#define THERMAL_tri_SPM_State0 0x20000000 -#define THERMAL_tri_SPM_State1 0x40000000 -#define THERMAL_tri_SPM_State2 0x80000000 - - -#define THERMAL_MSRCTL0_MASK 0x00000007 -#define THERMAL_MSRCTL1_MASK 0x00000038 -#define THERMAL_MSRCTL2_MASK 0x000001C0 - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES CONFIG_NR_CPUS - - -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6761/inc/tzbatt_initcfg.h deleted file mode 100644 index 420c87cdf365..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6761/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6761/inc/tzcpu_initcfg.h deleted file mode 100644 index 206c80e61788..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (117000) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6761/src/Makefile b/drivers/misc/mediatek/thermal/mt6761/src/Makefile deleted file mode 100644 index fd862bdd6b1d..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/src/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (C) 2017 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -#THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(MTK_PLATFORM) -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/mt6761 -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/mt6761 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/mt6761 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/mt6761/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/ -ccflags-y += -I$(srctree)/include/dt-bindings/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/include/ - -obj-$(CONFIG_THERMAL) += mtk_tc.o -#obj-$(CONFIG_THERMAL) += mtk_thermal_ipi.o -obj-$(CONFIG_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_THERMAL) += mtk_ts_6357buck1.o -obj-$(CONFIG_THERMAL) += mtk_ts_6357buck2.o \ No newline at end of file diff --git a/drivers/misc/mediatek/thermal/mt6761/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6761/src/mtk_tc.c deleted file mode 100644 index a3f545de352b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/src/mtk_tc.c +++ /dev/null @@ -1,1689 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -//TODO -//#include -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; - * 0: turn off - */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include - -#define DEBUG_THERMAL_SSPM 0 - -#if DEBUG_THERMAL_SSPM -#include "mtk_thermal_ipi.h" -#endif - -static struct device *tscpu_dev; -int g_turbo_bin; -EXPORT_SYMBOL_GPL(g_turbo_bin); - -/*============================================================= - * Local variable definition - *============================================================= - */ - - -/* - *Bank0: CA7L (TSMCU1) - *Bank3: GPU (TSMCU2) - *Bank4: SoC (TSMCU3) - */ - -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - */ - -int tscpu_ts_temp[TS_ENUM_MAX]; -int tscpu_ts_temp_r[TS_ENUM_MAX]; - -/* chip dependent */ -/* - * TO-DO: I assume AHB bus frequecy is 78MHz. - * Please confirm it. - */ -/* - * The tscpu_g_tc structure controls the polling rates and sensor mapping table - * of all thermal controllers. If HW thermal controllers are more than you - * actually needed, you should pay attention to default setting of unneeded - * thermal controllers. Otherwise, these unneeded thermal controllers will be - * initialized and work unexpectedly. - */ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {TS_MCU1, TS_MCU2, TS_MCU3}, - .ts_number = 3, - .tc_offset = 0x0, - .tc_speed = { - 0x0000000C, - 0x0001003B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {}, - .ts_number = 0, - .tc_offset = 0x100, - .tc_speed = { - 0x0000000C, - 0x0001003B, - 0x0000030D - } /* 4.9ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -static __s32 g_o_vtsmcu3; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[TS_ENUM_MAX] = { 0 }; - -static __u32 calefuse1; -static __u32 calefuse2; -static __u32 calefuse3; - -/** - * If curr_temp >= tscpu_polling_trip_temp1, use interval else if cur_temp >= - * tscpu_polling_trip_temp2 && curr_temp < tscpu_polling_trip_temp1, use - * interval*tscpu_polling_factor1 else, use interval*tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - *it means polling_delay will be 1/5 of original interval - *after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 2; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -int tscpu_prev_cpu_temp = 0, tscpu_prev_gpu_temp = 0; -int tscpu_curr_cpu_temp = 0, tscpu_curr_gpu_temp = 0; -#endif - -static int tscpu_curr_max_ts_temp; - -#if CFG_THERM_LVTS -__u32 lvts_count1_b30c; -__u32 lvts_count2_b30c; -__u32 lvts_count3_b30c; - -__u32 lvts_golden_temp1; -__u32 lvts_golden_temp2; -__u32 lvts_golden_temp3; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum thermal_sensor ts_name); -static void set_tc_trigger_hw_protect - (int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - -/*=============================================================*/ -static int read_nvmem_cell(char *cell_name, u8 *buf, int len) -{ - struct nvmem_cell *cell; - size_t size = 0; - u8 *tmp = NULL; - - if (IS_ERR(buf)) { - tscpu_warn("[%s] buffer fail\n", __func__); - return -EINVAL; - } - - cell = nvmem_cell_get(tscpu_dev, cell_name); - if ((cell == NULL) || (IS_ERR(cell))) { - tscpu_warn("[%s] nvmem_cell_get fail\n", __func__); - return -EINVAL; - } - - tmp = (u8 *)nvmem_cell_read(cell, &size); - if ((tmp == NULL) || (size <= 0)) { - tscpu_warn("[%s] nvmem_cell_read error\n", __func__); - return -EINVAL; - } - - nvmem_cell_put(cell); - - if (len < size) { - tscpu_warn("[%s] buffer too small(%d<%d)\n", - __func__, len, size); - kfree(tmp); - return -EINVAL; - } - - memcpy(buf, tmp, size); - - kfree(tmp); - - return 0; -} -#if defined(CATM_TPCB_EXTEND) -#define CPUFREQ_SEG_CODE_IDX_0 7 - -void mtk_thermal_get_turbo(void) -{ - int cpu_freq_segment_len = 4; - u32 cpu_freq_segment[1] = {0}; - - tscpu_dev = &tscpu_pdev->dev; - read_nvmem_cell("cpu_freq_segment_cell", - (u8 *)&cpu_freq_segment, cpu_freq_segment_len); - g_turbo_bin = (cpu_freq_segment[0] >> 3) & 0x1; - tscpu_printk("%s: turbo: %d\n", __func__, g_turbo_bin); -} -#endif - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - -#if defined(CONFIG_MTK_CLKMGR) - tscpu_dprintk("%s\n", __func__); - /* ret = enable_clock(MT_CG_PERI_THERM, "THERMAL"); */ -#else - /* Use CCF instead */ - tscpu_dprintk("%s CCF\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); -#endif - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - -#if defined(CONFIG_MTK_CLKMGR) - tscpu_dprintk("%s\n", __func__); - /*ret = disable_clock(MT_CG_PERI_THERM, "THERMAL"); */ -#else - /*Use CCF instead*/ - tscpu_dprintk("%s CCF\n", __func__); - clk_disable_unprepare(therm_main); -#endif - return ret; -} - -/* TODO: FIXME */ -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum -thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("%s\n", __func__); - - /* - *Bank0: CA7L (TSMCU1) - *Bank3: GPU (TSMCU2) - *Bank4: SoC (TSMCU3) - */ - - /* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - */ - /* chip dependent */ - - /* - * If there are two or more sensors in a bank, choose the sensor - * calibration value of the dominant sensor. You can observe it in the - * thermal doc provided by Thermal DE. For example, Bank 1 is for SOC - * + GPU. Observe all scenarios related to GPU tests to determine - * which sensor is the highest temperature in all tests. Then, It is - * the dominant sensor. (Confirmed by Thermal DE Alfred Tsai) - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[0]; - break; - case THERMAL_BANK3: - x_roomt = g_x_roomt[1]; - break; - case THERMAL_BANK4: - x_roomt = g_x_roomt[2]; - break; - default: /*choose high temp */ - x_roomt = g_x_roomt[0]; - break; - } - - /* - * The equations in this function are confirmed by Thermal DE Alfred - * Tsai. Don't have to change until using next generation thermal - * sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1653 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1653 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = - ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1653 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1653 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - tscpu_printk("[cal] g_o_vtsmcu3 = %d\n", g_o_vtsmcu3); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - -#if CFG_THERM_LVTS - tscpu_printk("[cal] lvts_count1_b30c= %d\n", lvts_count1_b30c); - tscpu_printk("[cal] lvts_count2_b30c= %d\n", lvts_count2_b30c); - tscpu_printk("[cal] lvts_count3_b30c= %d\n", lvts_count3_b30c); - tscpu_printk("[cal] lvts_golden_temp1= %d\n", lvts_golden_temp1); - tscpu_printk("[cal] lvts_golden_temp2= %d\n", lvts_golden_temp2); - tscpu_printk("[cal] lvts_golden_temp3= %d\n", lvts_golden_temp3); -#endif -} - -void eDataCorrector(void) -{ - - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - if (g_o_vtsmcu3 < -8 || g_o_vtsmcu3 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu3\n"); - g_o_vtsmcu3 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2; - int efuse_len = 12; - __u32 thermal_efuse[3] = {0}; -#if CFG_THERM_LVTS - __u32 lvtsdevinfo1, lvtsdevinfo2, lvtsdevinfo3; - __u32 lvts_efuse[3] = {0}; -#endif - tscpu_dev = &tscpu_pdev->dev; - read_nvmem_cell("thermal_efuse_cell", (u8 *)&thermal_efuse, efuse_len); - temp1 = thermal_efuse[0]; - temp0 = thermal_efuse[1]; - temp2 = thermal_efuse[2]; - pr_notice("[calibration] temp0=0x%x, temp1=0x%x, temp2=0x%x\n", - temp0, temp1, temp2); - /* - * chip dependent - * ADC_GE_T - * ADC_OE_T - */ - g_adc_ge_t = ((temp0 & _BITMASK_(31:22)) >> 22); - g_adc_oe_t = ((temp0 & _BITMASK_(21:12)) >> 12); - - /* - * O_VTSMCU1 - * O_VTSMCU2 - * O_VTSMCU3 - */ - g_o_vtsmcu1 = ((temp1 & _BITMASK_(25:17)) >> 17); - g_o_vtsmcu2 = ((temp1 & _BITMASK_(16:8)) >> 8); - g_o_vtsmcu3 = (temp0 & _BITMASK_(8:0)); - - /* - * DEGC_cali (6b) - * ADC_CALI_EN_T(1b) - */ - g_degc_cali = ((temp1 & _BITMASK_(6:1)) >> 1); - g_adc_cali_en_t = (temp1 & _BIT_(0)); - - /* - * O_SLOPE_SIGN (1b) - * O_SLOPE (6b) - */ - g_o_slope_sign = ((temp1 & _BIT_(7)) >> 7); - g_o_slope = ((temp1 & _BITMASK_(31:26)) >> 26); - - /*ID*/ - g_id = ((temp0 & _BIT_(9)) >> 9); - - - - /* - * Check ID bit - * If ID=0 (TSMC sample) , ignore O_SLOPE EFuse value and set - * O_SLOPE=0. - * If ID=1 (non-TSMC sample), read O_SLOPE EFuse value for following - * calculation. - */ - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - g_o_vtsmcu3 = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - -#if CFG_THERM_LVTS - - lvtsdevinfo1 = get_devinfo_with_index(118); - lvtsdevinfo2 = get_devinfo_with_index(119); - lvtsdevinfo3 = get_devinfo_with_index(139); - - pr_notice("[lvts_cal] 0: 0x%x, 1: 0x%x, 2: 0x%x\n", lvtsdevinfo1, - lvtsdevinfo2, lvtsdevinfo3); - - lvts_count1_b30c = (lvtsdevinfo1 & _BITMASK_(23:0)); - lvts_count2_b30c = (lvtsdevinfo2 & _BITMASK_(23:0)); - lvts_count3_b30c = (lvtsdevinfo3 & _BITMASK_(23:0)); - - lvts_golden_temp1 = ((lvtsdevinfo1 & _BITMASK_(31:24)) >> 24); - lvts_golden_temp2 = ((lvtsdevinfo2 & _BITMASK_(31:24)) >> 24); - lvts_golden_temp3 = ((lvtsdevinfo3 & _BITMASK_(31:24)) >> 24); -#endif - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[TS_ENUM_MAX] = { 0 }; - int i = 0; -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - int count = 0, offset = 0; - struct thermal_ipi_data thermal_data; -#endif -#endif - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[TS_MCU1] = (g_o_vtsmcu1 + 3350 - g_oe); - format[TS_MCU2] = (g_o_vtsmcu2 + 3350 - g_oe); - format[TS_MCU3] = (g_o_vtsmcu3 + 3350 - g_oe); - - for (i = 0; i < TS_ENUM_MAX; i++) { - /* x_roomt * 10000 */ - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; - } - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < TS_ENUM_MAX; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, - g_x_roomt[i]); -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - thermal_data.u.data.arg[0] = g_degc_cali; - thermal_data.u.data.arg[1] = g_o_slope_sign; - thermal_data.u.data.arg[2] = g_o_slope; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_oe; - thermal_data.u.data.arg[1] = g_gain; - thermal_data.u.data.arg[2] = g_x_roomt[0]; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP2, &thermal_data) != 0) - udelay(100); - - for (i = 1 ; i < TS_ENUM_MAX; i++) { - thermal_data.u.data.arg[count] = g_x_roomt[i]; - if (count == (THERMAL_SLOT_NUM - 2)) { - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP3 + offset, - &thermal_data) != 0) - udelay(100); - offset++; - } - count = (count + 1) % (THERMAL_SLOT_NUM - 1); - } - - if (count != 0) { - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP3 + offset, - &thermal_data) != 0) - udelay(100); - } -#endif -#endif -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum thermal_sensor ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1653+O_slope*10)/10*(18/15)* - * (1/10000)+X_roomtabb]*Gain*4096 + OE - */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1653 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1653 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum thermal_sensor ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n", - * ts_name,xtoomt); - */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1653 + g_o_slope * 10)); - else /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1653 - g_o_slope * 10)); - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} - -int get_immediate_none_wrap(void) -{ - return -127000; -} - - -/* - *Bank0: CA7L (TSMCU1) - *Bank3: GPU (TSMCU2) - *Bank4: SoC (TSMCU3) - */ - -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - */ -/* chip dependent */ -int get_immediate_cpuB_wrap(void) -{ - return -127000; -} - -int get_immediate_mcucci_wrap(void) -{ - return -127000; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuLL_wrap(void) -{ - return -127000; -} - -int get_immediate_cpuL_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU1]; - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_coreSoC_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU3]; - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpuL_wrap, - get_immediate_gpu_wrap, - get_immediate_coreSoC_wrap -}; - - - - -/* - *Bank0: CA7L (TSMCU1) - *Bank3: GPU (TSMCU2) - *Bank4: SoC (TSMCU3) - */ - -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - */ - -/* chip dependent */ -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts4_wrap(void) -{ - return -127000; -} - -int get_immediate_ts5_wrap(void) -{ - return -127000; -} - -int get_immediate_ts6_wrap(void) -{ - return -127000; -} - -int get_immediate_ts7_wrap(void) -{ - return -127000; -} - -int get_immediate_ts8_wrap(void) -{ - return -127000; -} - -int get_immediate_tsabb_wrap(void) -{ - return -127000; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - get_immediate_ts1_wrap, - get_immediate_ts2_wrap, - get_immediate_ts3_wrap -}; - -static void thermal_interrupt_handler(int tc_num) -{ - __u32 ret = 0, offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - /* write to clear interrupt status */ - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); - tscpu_dprintk( - "[tIRQ] %s,tc_num=0x%08x,ret=0x%08x\n", __func__, - tc_num, ret); - - if (ret & THERMAL_MON_CINTSTS0) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 0 - cold interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS0) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 0 - hot interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS1) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 1 - hot interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS2) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 2 - hot interrupt trigger\n"); - - if (ret & THERMAL_tri_SPM_State0) - tscpu_dprintk( - "[thermal_isr]: Thermal state0 to trigger SPM state0\n"); - - if (ret & THERMAL_tri_SPM_State1) { - tscpu_dprintk( - "[thermal_isr]: Thermal state1 to trigger SPM state1\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_tri_SPM_State2) - tscpu_printk( - "[thermal_isr]: Thermal state2 to trigger SPM state2\n"); -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - __u32 ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - - ret = ret & 0xFF; - - tscpu_dprintk("thermal_interrupt_handler : THERMINTST = 0x%x\n", ret); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - mask = 1 << i; - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - __u32 offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - tempMonCtl1 = tscpu_g_tc[tc_num].tc_speed.tempMonCtl1; - tempMonCtl2 = tscpu_g_tc[tc_num].tc_speed.tempMonCtl2; - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.tempAhbPoll; - - /* Calculating period unit in Module clock x 256, - * and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* bus clock 66M counting unit is 12 * 1/66M * 256 = - * 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - * filt interval is 1 * 46.545us = 46.545us, - * sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /* AHB polling is 781* 1/66M = 11.833us */ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - /* temperature sampling control, 4 out of 6 samples */ - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - /* temperature sampling control, 8 out of 10 samples */ - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - /* temperature sampling control, 16 out of 18 samples */ - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); -#else /* default 1 */ - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); -#endif - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); - - /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); - - /* AHB value for auxadc enable */ - mt_reg_sync_writel(0x800, offset + TEMPADCEN); - - /* - * AHB address for auxadc enable (channel 0 immediate mode selected) - * this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void set_tc_trigger_hw_protect -(int temperature, int temperature2, int tc_num) -{ - int temp = 0; - int raw_high; - enum thermal_sensor ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* set temp offset to 0x3FF to avoid interrupt false triggered */ - mt_reg_sync_writel( - readl(offset + TEMPPROTCTL) | 0x3FF, - offset + TEMPPROTCTL); - - /* temperature2=80000; test only */ - tscpu_dprintk("%s t1=%d t2=%d\n", __func__, - temperature, temperature2); - - ts_name = tscpu_g_tc[tc_num].ts[0]; - - /* temperature to trigger SPM state2 */ - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); - - /* set hot to wakeup event control */ - mt_reg_sync_writel(0x20000, offset + TEMPPROTCTL); - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); - - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); - - /* clear temp offset */ - mt_reg_sync_writel( - readl(offset + TEMPPROTCTL) & ~0xFFF, - offset + TEMPPROTCTL); -} - -static int read_tc_raw_and_temp(u32 *tempmsr_name, enum thermal_sensor ts_name) -{ - int temp = 0, raw = 0; - - if (thermal_base == 0) - return 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl(tempmsr_name) & 0x0fff; - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_temp_r[ts_name] = raw; - - return temp * 100; -} - -void tscpu_thermal_read_tc_temp(int tc_num, enum thermal_sensor type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, - tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - case 1: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - case 2: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - case 3: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - default: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - } -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - - /* write temp to spare register */ - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); - - /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL1); - - /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); - - /* polling interval to check if temperature sense is ready */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); - - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - - /* temperature measurement sampling control */ - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) - * automatically by hw - */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); - - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); - - /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); - - /* enable auxadc mux & pnp write transaction */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - - - /* enable all interrupt except filter sense and - * immediate sense interrupt - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - /* enable all sensing point(sensing point 2 is unused)*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum thermal_sensor type) -{ - switch (type) { - case TS_MCU1: - return TEMPADC_MCU1; - case TS_MCU2: - return TEMPADC_MCU2; - case TS_MCU3: - return TEMPADC_MCU3; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - /* tscpu_printk("thermal_pause_all_periodoc_temp_sensing\n"); */ - - /* config bank0,1,2 */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - /* tscpu_printk("thermal_release_all_periodoc_temp_sensing\n"); */ - - /*config bank0,1,2 */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - /* tscpu_printk("thermal_disable_all_periodoc_temp_sensing\n"); */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - /* tscpu_printk("thermal_disable_all_periodoc_temp_sensing:" - * "Bank_%d\n",i); - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - - /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); - - /* disable auxadc channel 11 immediate mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - - tscpu_dprintk( - "%s,temperature=%d,temperature2=%d,\n", __func__, - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /* spend 860~1463 us */ - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - //TODO -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_notice("resume time spent, sec : %lu , usec : %lu\n", - (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - set_tc_trigger_hw_protect(temperature, temperature2, i); - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - //TODO -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - int i; -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - struct thermal_ipi_data thermal_data; -#endif -#endif - seq_printf(m, "current temp:%d\n", tscpu_curr_max_ts_temp); - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_id = %d\n", g_id); - - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - seq_printf(m, "[cal] g_o_vtsmcu3 = %d\n", g_o_vtsmcu3); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < TS_ENUM_MAX; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - seq_printf(m, "calefuse1:0x%x\n", calefuse1); - seq_printf(m, "calefuse2:0x%x\n", calefuse2); - seq_printf(m, "calefuse3:0x%x\n", calefuse3); - -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_GET_TEMP, &thermal_data) != 0) - udelay(500); -#endif -#endif - return 0; -} - - -/* - *Bank0: CA7L (TSMCU1) - *Bank3: GPU (TSMCU2) - *Bank4: SoC (TSMCU3) - */ - -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - */ -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of - * thermal controller driver - */ - tscpu_prev_cpu_temp = tscpu_curr_cpu_temp; - tscpu_prev_gpu_temp = tscpu_curr_gpu_temp; - - /* It is platform dependent which TS is better to - * present CPU/GPU temperature - */ - tscpu_curr_cpu_temp = tscpu_ts_temp[TS_MCU1]; - - tscpu_curr_gpu_temp = tscpu_ts_temp[TS_MCU2]; -#endif - /* though tscpu_max_temperature is common, - * put it in mtk_ts_cpu.c is weird. - */ - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] thermal_base=0x%p\n" - * thermal_base); - */ - } - - /* get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - /* tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", - * thermal_irq_number); - */ - if (!thermal_irq_number) { - /* TODO: need check "irq number" */ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_irq_number); - return 0; - } - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6765-auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] auxadc_ts_base=0x%p\n", - * auxadc_ts_base); - */ - } - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6761-infracfg"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] infracfg_ao_base=0x%p\n", - * infracfg_ao_base); - */ - } - - node = of_find_compatible_node(NULL, NULL, - "mediatek,mt6761-apmixedsys"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] apmixed_base=0x%p\n", - * th_apmixed_base); - */ - } - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base=\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); /**/ - if (!node) { - pr_notice("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_notice("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /* Need to confirm with DE */ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /* The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if (cg_freq & _BIT_(4)) - ahbClk = clockSource / 2; - else if (cg_freq & _BIT_(3)) - ahbClk = clockSource / 4; - else if (cg_freq & _BIT_(2)) - ahbClk = clockSource / 8; - else if (cg_freq & _BIT_(1)) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /* tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm); */ - /* tscpu_printk("AHB bus clock= %d MHz\n", ahbClk); */ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "L %d LL %d", - get_immediate_cpuL_wrap(), get_immediate_cpuLL_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6761/src/mtk_ts_6357buck1.c b/drivers/misc/mediatek/thermal/mt6761/src/mtk_ts_6357buck1.c deleted file mode 100644 index f55b0b87534f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/src/mtk_ts_6357buck1.c +++ /dev/null @@ -1,621 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -//#include -#include -#include -#include -#include /* PMIC MFD core header */ -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 - *&& curr_temp < polling_trip_temp1, use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = {150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = "sysrst.6357buck1"; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6357tsbuck1_cur_temp; -/* - *static long int mt6357tsbuck1_start_temp; - *static long int mt6357tsbuck1_end_temp; - */ -/*=============================================================*/ - -static int mt6357tsbuck1_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6357tsbuck1_get_hw_temp(); - mt6357tsbuck1_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6357tsbuck1_bind - (struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6357tsbuck1_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6357tsbuck1_get_mode - (struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6357tsbuck1_set_mode - (struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6357tsbuck1_get_trip_type - (struct thermal_zone_device *thermal, int trip, - enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6357tsbuck1_get_trip_temp - (struct thermal_zone_device *thermal, int trip, - int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6357tsbuck1_get_crit_temp( - struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6357tsbuck1_dev_ops = { - .bind = mt6357tsbuck1_bind, - .unbind = mt6357tsbuck1_unbind, - .get_temp = mt6357tsbuck1_get_temp, - .get_mode = mt6357tsbuck1_get_mode, - .set_mode = mt6357tsbuck1_set_mode, - .get_trip_type = mt6357tsbuck1_get_trip_type, - .get_trip_temp = mt6357tsbuck1_get_trip_temp, - .get_crit_temp = mt6357tsbuck1_get_crit_temp, -}; - -static int mt6357tsbuck1_sysrst_get_max_state - (struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6357tsbuck1_sysrst_get_cur_state( - struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6357tsbuck1_sysrst_set_cur_state( - struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("MT6357TSBUCK1 OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - } - return 0; -} - -static struct thermal_cooling_device_ops mt6357tsbuck1_cooling_sysrst_ops = { - .get_max_state = mt6357tsbuck1_sysrst_get_max_state, - .get_cur_state = mt6357tsbuck1_sysrst_get_cur_state, - .set_cur_state = mt6357tsbuck1_sysrst_set_cur_state, -}; - -static int mt6357tsbuck1_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d, trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d, g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d, g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s, time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6357tsbuck1_register_thermal(void); -static void mt6357tsbuck1_unregister_thermal(void); - -static ssize_t mt6357tsbuck1_write(struct file *file, - const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6357tsbuck1_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6357tsbuck1_data *ptr_mt6357tsbuck1_data; - - ptr_mt6357tsbuck1_data = kmalloc(sizeof(*ptr_mt6357tsbuck1_data), - GFP_KERNEL); - - if (ptr_mt6357tsbuck1_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6357tsbuck1_data->desc) - 1)) ? count : - (sizeof(ptr_mt6357tsbuck1_data->desc) - 1); - if (copy_from_user(ptr_mt6357tsbuck1_data->desc, buffer, len)) { - kfree(ptr_mt6357tsbuck1_data); - return 0; - } - - ptr_mt6357tsbuck1_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6357tsbuck1_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6357tsbuck1_data->trip[0], &ptr_mt6357tsbuck1_data->t_type[0], - ptr_mt6357tsbuck1_data->bind0, - &ptr_mt6357tsbuck1_data->trip[1], &ptr_mt6357tsbuck1_data->t_type[1], - ptr_mt6357tsbuck1_data->bind1, - &ptr_mt6357tsbuck1_data->trip[2], &ptr_mt6357tsbuck1_data->t_type[2], - ptr_mt6357tsbuck1_data->bind2, - &ptr_mt6357tsbuck1_data->trip[3], &ptr_mt6357tsbuck1_data->t_type[3], - ptr_mt6357tsbuck1_data->bind3, - &ptr_mt6357tsbuck1_data->trip[4], &ptr_mt6357tsbuck1_data->t_type[4], - ptr_mt6357tsbuck1_data->bind4, - &ptr_mt6357tsbuck1_data->trip[5], &ptr_mt6357tsbuck1_data->t_type[5], - ptr_mt6357tsbuck1_data->bind5, - &ptr_mt6357tsbuck1_data->trip[6], &ptr_mt6357tsbuck1_data->t_type[6], - ptr_mt6357tsbuck1_data->bind6, - &ptr_mt6357tsbuck1_data->trip[7], &ptr_mt6357tsbuck1_data->t_type[7], - ptr_mt6357tsbuck1_data->bind7, - &ptr_mt6357tsbuck1_data->trip[8], &ptr_mt6357tsbuck1_data->t_type[8], - ptr_mt6357tsbuck1_data->bind8, - &ptr_mt6357tsbuck1_data->trip[9], &ptr_mt6357tsbuck1_data->t_type[9], - ptr_mt6357tsbuck1_data->bind9, - &ptr_mt6357tsbuck1_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6357tsbuck1_unregister_thermal\n", __func__); - mt6357tsbuck1_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api( - __FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck1_write", "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6357tsbuck1_data); - up(&sem_mutex); - return -EINVAL; - } - - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6357tsbuck1_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = - g_bind4[0] = g_bind5[0] = g_bind6[0] = g_bind7[0] = - g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6357tsbuck1_data->bind0[i]; - g_bind1[i] = ptr_mt6357tsbuck1_data->bind1[i]; - g_bind2[i] = ptr_mt6357tsbuck1_data->bind2[i]; - g_bind3[i] = ptr_mt6357tsbuck1_data->bind3[i]; - g_bind4[i] = ptr_mt6357tsbuck1_data->bind4[i]; - g_bind5[i] = ptr_mt6357tsbuck1_data->bind5[i]; - g_bind6[i] = ptr_mt6357tsbuck1_data->bind6[i]; - g_bind7[i] = ptr_mt6357tsbuck1_data->bind7[i]; - g_bind8[i] = ptr_mt6357tsbuck1_data->bind8[i]; - g_bind9[i] = ptr_mt6357tsbuck1_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], - g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6357tsbuck1_data->trip[i]; - - interval = ptr_mt6357tsbuck1_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - mtktspmic_dprintk( - "trip_9_temp=%d,time_ms=%d\n", trip_temp[9], - interval * 1000); - - mtktspmic_dprintk( - "[%s]mt6357tsbuck1_register_thermal\n", __func__); - mt6357tsbuck1_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6357tsbuck1_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck1_write", "Bad argument"); - #endif - kfree(ptr_mt6357tsbuck1_data); - return -EINVAL; -} - -static void mt6357tsbuck1_cancel_thermal_timer(void) -{ - /* cancel timer */ - /* pr_debug("mtkts_pmic_cancel_thermal_timer\n"); */ - - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6357tsbuck1_start_thermal_timer(void) -{ - /* pr_debug("mtkts_pmic_start_thermal_timer\n"); */ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6357tsbuck1_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "sysrst.6357buck1", NULL, &mt6357tsbuck1_cooling_sysrst_ops); - return 0; -} - -static int mt6357tsbuck1_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6357tsbuck1", num_trip, NULL, &mt6357tsbuck1_dev_ops, - 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6357tsbuck1_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6357tsbuck1_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6357tsbuck1_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6357tsbuck1_read, NULL); -} - -static const struct file_operations mt6357tsbuck1_fops = { - .owner = THIS_MODULE, - .open = mt6357tsbuck1_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6357tsbuck1_write, - .release = single_release, -}; -static int mt6357_ts_buck1_probe(struct platform_device *pdev) -{ - int err = 0; - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6357tsbuck1_dir = NULL; - struct mt6397_chip *chip; - - chip = (struct mt6397_chip *)dev_get_drvdata(pdev->dev.parent); - mtktspmic_info("[%s]\n", __func__); - mtktspmic_cali_prepare(chip->regmap); - mtktspmic_cali_prepare2(); - - err = mt6357tsbuck1_register_cooler(); - if (err) - return err; - err = mt6357tsbuck1_register_thermal(); - if (err) - goto err_unreg; - - mt6357tsbuck1_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6357tsbuck1_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6357buck1", 0664, - mt6357tsbuck1_dir, &mt6357tsbuck1_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - mtkTTimer_register("mt6357tsbuck1", - mt6357tsbuck1_start_thermal_timer, - mt6357tsbuck1_cancel_thermal_timer); - - return 0; - -err_unreg: - mt6357tsbuck1_unregister_cooler(); - return err; - -} - -static const struct of_device_id mt6357_ts_buck1_of_match[] = { - {.compatible = "mediatek,mt6357_ts_buck1",}, - {}, -}; - - -MODULE_DEVICE_TABLE(of, mt6357_ts_buck1_of_match); - -static struct platform_driver mt6357_ts_buck1_driver = { - .probe = mt6357_ts_buck1_probe, - .driver = { - .name = "mt6357_ts_buck1", - .of_match_table = mt6357_ts_buck1_of_match, - }, -}; - -static int __init mt6357tsbuck1_init(void) -{ - return platform_driver_register(&mt6357_ts_buck1_driver); -} - -static void __exit mt6357tsbuck1_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6357tsbuck1_unregister_thermal(); - mt6357tsbuck1_unregister_cooler(); - mtkTTimer_unregister("mt6357tsbuck1"); - platform_driver_unregister(&mt6357_ts_buck1_driver); -} -module_init(mt6357tsbuck1_init); -module_exit(mt6357tsbuck1_exit); - -MODULE_DESCRIPTION("MEDIATEK Thermal zone PMIC buck1 temperature sensor"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/mediatek/thermal/mt6761/src/mtk_ts_6357buck2.c b/drivers/misc/mediatek/thermal/mt6761/src/mtk_ts_6357buck2.c deleted file mode 100644 index 6389d5667b9f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6761/src/mtk_ts_6357buck2.c +++ /dev/null @@ -1,626 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -//#include -#include -#include -#include -#include /* PMIC MFD core header */ -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, - 80000, 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = "sysrst.6357buck2"; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6357tsbuck2_cur_temp; -/* - *static long int mt6357tsbuck2_start_temp; - *static long int mt6357tsbuck2_end_temp; - */ -/*=============================================================*/ - -static int mt6357tsbuck2_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6357tsbuck2_get_hw_temp(); - mt6357tsbuck2_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6357tsbuck2_bind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6357tsbuck2_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6357tsbuck2_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6357tsbuck2_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6357tsbuck2_get_trip_type(struct thermal_zone_device *thermal, - int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6357tsbuck2_get_trip_temp(struct thermal_zone_device *thermal, - int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6357tsbuck2_get_crit_temp(struct thermal_zone_device *thermal, - int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6357tsbuck2_dev_ops = { - .bind = mt6357tsbuck2_bind, - .unbind = mt6357tsbuck2_unbind, - .get_temp = mt6357tsbuck2_get_temp, - .get_mode = mt6357tsbuck2_get_mode, - .set_mode = mt6357tsbuck2_set_mode, - .get_trip_type = mt6357tsbuck2_get_trip_type, - .get_trip_temp = mt6357tsbuck2_get_trip_temp, - .get_crit_temp = mt6357tsbuck2_get_crit_temp, -}; - -static int mt6357tsbuck2_sysrst_get_max_state(struct thermal_cooling_device - *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6357tsbuck2_sysrst_get_cur_state(struct thermal_cooling_device - *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6357tsbuck2_sysrst_set_cur_state(struct thermal_cooling_device - *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("MT6357TSBUCK2 OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - } - return 0; -} - -static struct thermal_cooling_device_ops mt6357tsbuck2_cooling_sysrst_ops = { - .get_max_state = mt6357tsbuck2_sysrst_get_max_state, - .get_cur_state = mt6357tsbuck2_sysrst_get_cur_state, - .set_cur_state = mt6357tsbuck2_sysrst_set_cur_state, -}; - -static int mt6357tsbuck2_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d, g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d, g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s, time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6357tsbuck2_register_thermal(void); -static void mt6357tsbuck2_unregister_thermal(void); - -static ssize_t mt6357tsbuck2_write(struct file *file, - const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6357tsbuck2_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6357tsbuck2_data *ptr_mt6357tsbuck2_data; - - ptr_mt6357tsbuck2_data = kmalloc(sizeof(*ptr_mt6357tsbuck2_data), - GFP_KERNEL); - - if (ptr_mt6357tsbuck2_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6357tsbuck2_data->desc) - 1)) ? count : - (sizeof(ptr_mt6357tsbuck2_data->desc) - 1); - if (copy_from_user(ptr_mt6357tsbuck2_data->desc, buffer, len)) { - kfree(ptr_mt6357tsbuck2_data); - return 0; - } - - ptr_mt6357tsbuck2_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6357tsbuck2_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6357tsbuck2_data->trip[0], - &ptr_mt6357tsbuck2_data->t_type[0], - ptr_mt6357tsbuck2_data->bind0, - &ptr_mt6357tsbuck2_data->trip[1], - &ptr_mt6357tsbuck2_data->t_type[1], - ptr_mt6357tsbuck2_data->bind1, - &ptr_mt6357tsbuck2_data->trip[2], - &ptr_mt6357tsbuck2_data->t_type[2], - ptr_mt6357tsbuck2_data->bind2, - &ptr_mt6357tsbuck2_data->trip[3], - &ptr_mt6357tsbuck2_data->t_type[3], - ptr_mt6357tsbuck2_data->bind3, - &ptr_mt6357tsbuck2_data->trip[4], - &ptr_mt6357tsbuck2_data->t_type[4], - ptr_mt6357tsbuck2_data->bind4, - &ptr_mt6357tsbuck2_data->trip[5], - &ptr_mt6357tsbuck2_data->t_type[5], - ptr_mt6357tsbuck2_data->bind5, - &ptr_mt6357tsbuck2_data->trip[6], - &ptr_mt6357tsbuck2_data->t_type[6], - ptr_mt6357tsbuck2_data->bind6, - &ptr_mt6357tsbuck2_data->trip[7], - &ptr_mt6357tsbuck2_data->t_type[7], - ptr_mt6357tsbuck2_data->bind7, - &ptr_mt6357tsbuck2_data->trip[8], - &ptr_mt6357tsbuck2_data->t_type[8], - ptr_mt6357tsbuck2_data->bind8, - &ptr_mt6357tsbuck2_data->trip[9], - &ptr_mt6357tsbuck2_data->t_type[9], - ptr_mt6357tsbuck2_data->bind9, - &ptr_mt6357tsbuck2_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s]mt6357tsbuck2_unregister_thermal\n", __func__); - mt6357tsbuck2_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api( - __FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck2_write", "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6357tsbuck2_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6357tsbuck2_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = - g_bind5[0] = - g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6357tsbuck2_data->bind0[i]; - g_bind1[i] = ptr_mt6357tsbuck2_data->bind1[i]; - g_bind2[i] = ptr_mt6357tsbuck2_data->bind2[i]; - g_bind3[i] = ptr_mt6357tsbuck2_data->bind3[i]; - g_bind4[i] = ptr_mt6357tsbuck2_data->bind4[i]; - g_bind5[i] = ptr_mt6357tsbuck2_data->bind5[i]; - g_bind6[i] = ptr_mt6357tsbuck2_data->bind6[i]; - g_bind7[i] = ptr_mt6357tsbuck2_data->bind7[i]; - g_bind8[i] = ptr_mt6357tsbuck2_data->bind8[i]; - g_bind9[i] = ptr_mt6357tsbuck2_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], - g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6357tsbuck2_data->trip[i]; - - interval = ptr_mt6357tsbuck2_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - mtktspmic_dprintk( - "trip_9_temp=%d,time_ms=%d\n", trip_temp[9], - interval * 1000); - - mtktspmic_dprintk( - "[%s]mt6357tsbuck2_register_thermal\n", __func__); - mt6357tsbuck2_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6357tsbuck2_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck2_write", "Bad argument"); - #endif - kfree(ptr_mt6357tsbuck2_data); - return -EINVAL; -} - -static void mt6357tsbuck2_cancel_thermal_timer(void) -{ - /* cancel timer */ - /* pr_debug("mtkts_pmic_cancel_thermal_timer\n"); */ - - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6357tsbuck2_start_thermal_timer(void) -{ - /* pr_debug("mtkts_pmic_start_thermal_timer\n"); */ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6357tsbuck2_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "sysrst.6357buck2", NULL, &mt6357tsbuck2_cooling_sysrst_ops); - return 0; -} - -static int mt6357tsbuck2_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register("mt6357tsbuck2", - num_trip, NULL, &mt6357tsbuck2_dev_ops, - 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6357tsbuck2_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6357tsbuck2_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6357tsbuck2_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6357tsbuck2_read, NULL); -} - -static const struct file_operations mt6357tsbuck2_fops = { - .owner = THIS_MODULE, - .open = mt6357tsbuck2_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6357tsbuck2_write, - .release = single_release, -}; - -static int mt6357_ts_buck2_probe(struct platform_device *pdev) -{ - int err = 0; - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6357tsbuck2_dir = NULL; - struct mt6397_chip *chip; - - chip = (struct mt6397_chip *)dev_get_drvdata(pdev->dev.parent); - mtktspmic_info("[%s]\n", __func__); - - mtktspmic_cali_prepare(chip->regmap); - mtktspmic_cali_prepare2(); - - err = mt6357tsbuck2_register_cooler(); - if (err) - return err; - err = mt6357tsbuck2_register_thermal(); - if (err) - goto err_unreg; - - mt6357tsbuck2_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6357tsbuck2_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6357buck2", 0664, - mt6357tsbuck2_dir, &mt6357tsbuck2_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6357tsbuck2", mt6357tsbuck2_start_thermal_timer, - mt6357tsbuck2_cancel_thermal_timer); - - return 0; - -err_unreg: - mt6357tsbuck2_unregister_cooler(); - return err; - - -} - -static const struct of_device_id mt6357_ts_buck2_of_match[] = { - {.compatible = "mediatek,mt6357_ts_buck2",}, - {}, -}; - - -MODULE_DEVICE_TABLE(of, mt6357_ts_buck2_of_match); - -static struct platform_driver mt6357_ts_buck2_driver = { - .probe = mt6357_ts_buck2_probe, - .driver = { - .name = "mt6357_ts_buck2", - .of_match_table = mt6357_ts_buck2_of_match, - }, -}; - -static int __init mt6357tsbuck2_init(void) -{ - return platform_driver_register(&mt6357_ts_buck2_driver); -} - -static void __exit mt6357tsbuck2_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6357tsbuck2_unregister_thermal(); - mt6357tsbuck2_unregister_cooler(); - mtkTTimer_unregister("mt6357tsbuck2"); - platform_driver_unregister(&mt6357_ts_buck2_driver); -} -module_init(mt6357tsbuck2_init); -module_exit(mt6357tsbuck2_exit); diff --git a/drivers/misc/mediatek/thermal/mt6765/Makefile b/drivers/misc/mediatek/thermal/mt6765/Makefile deleted file mode 100644 index 60b4650e6fc3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2017 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6765/inc/clatm_initcfg.h deleted file mode 100644 index 73f9fca2033b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/clatm_initcfg.h +++ /dev/null @@ -1,56 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (75000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (2000) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (400) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (2000) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (200) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (700) - -#define CLATM_INIT_CFG_1_TARGET_TJ (65000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (3000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (75000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3960) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (600) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (10) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (100) - -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/mach/mtk_thermal.h b/drivers/misc/mediatek/thermal/mt6765/inc/mach/mtk_thermal.h deleted file mode 100644 index 92d1331d43a9..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/mach/mtk_thermal.h +++ /dev/null @@ -1,144 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __MT6765_THERMAL_H__ -#define __MT6765_THERMAL_H__ - -#include -#include -#include -#include - -#include -#include - -#include "mt-plat/sync_write.h" - -#include "mtk_gpufreq.h" - -/* - * Bank0: CPU-L (TS_MCU1) - * Bank1: CPU-LL (TS_MCU2) - * Bank2: CCI (TS_MCU1 + TS_MCU2) - * Bank3: GPU (TS_MCU3) - * Bank4: SoC (TS_MCU4 + TS_MCU5) - */ -enum thermal_sensor { - TS_MCU1 = 0, - TS_MCU2, - TS_MCU3, - TS_MCU4, - TS_MCU5, - TS_ENUM_MAX, -}; - -enum thermal_bank_name { - THERMAL_BANK0 = 0, - THERMAL_BANK1 = 1, - THERMAL_BANK2 = 2, - THERMAL_BANK3 = 3, - THERMAL_BANK4 = 4, - THERMAL_BANK_NUM -}; - -struct TS_PTPOD { - unsigned int ts_MTS; - unsigned int ts_BTS; -}; - -extern int mtktscpu_limited_dmips; -extern int tscpu_get_temperature_range(void); -/* Valid if it returns 1, invalid if it returns 0. */ -extern int tscpu_is_temp_valid(void); - -extern void get_thermal_slope_intercept -(struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); - -extern void set_taklking_flag(bool flag); - -extern int tscpu_get_cpu_temp(void); - -extern int tscpu_get_temp_by_bank(enum thermal_bank_name ts_bank); - -#define THERMAL_WRAP_WR32(val, addr) \ - mt_reg_sync_writel((val), ((void *)addr)) - -extern int get_immediate_gpu_wrap(void); - -extern int get_immediate_cpuL_wrap(void); - -extern int get_immediate_cpuLL_wrap(void); - -extern int get_immediate_mcucci_wrap(void); - -/* Added for DLPT. */ -extern int tscpu_get_min_cpu_pwr(void); - -extern int tscpu_get_min_gpu_pwr(void); - -/* Five thermal sensors. */ -enum mtk_thermal_sensor_cpu_id_met { - MTK_THERMAL_SENSOR_TS1 = 0, - MTK_THERMAL_SENSOR_TS2, - MTK_THERMAL_SENSOR_TS3, - MTK_THERMAL_SENSOR_TS4, - MTK_THERMAL_SENSOR_TS5, - - ATM_CPU_LIMIT, - ATM_GPU_LIMIT, - - MTK_THERMAL_SENSOR_CPU_COUNT -}; - - -extern int tscpu_get_cpu_temp_met(enum mtk_thermal_sensor_cpu_id_met id); - -typedef void (*met_thermalsampler_funcMET)(void); - -extern void mt_thermalsampler_registerCB(met_thermalsampler_funcMET pCB); - -extern void mtkTTimer_cancel_timer(void); - -extern void mtkTTimer_start_timer(void); - -extern int mtkts_bts_get_hw_temp(void); - -extern int get_immediate_ts1_wrap(void); - -extern int get_immediate_ts2_wrap(void); - -extern int get_immediate_ts3_wrap(void); - -extern int get_immediate_ts4_wrap(void); - -extern int get_immediate_ts5_wrap(void); - - -extern int (*get_immediate_tsX[TS_ENUM_MAX])(void); - -extern int is_cpu_power_unlimit(void); /* in mtk_ts_cpu.c */ - -extern int is_cpu_power_min(void); /* in mtk_ts_cpu.c */ - -extern int get_cpu_target_tj(void); - -extern int get_cpu_target_offset(void); - -extern int mtk_gpufreq_register -(struct mt_gpufreq_power_table_info *freqs, int num); - -extern int get_target_tj(void); - -extern int mtk_thermal_get_tpcb_target(void); - -extern void thermal_set_big_core_speed -(unsigned int tempMonCtl1, unsigned int tempMonCtl2, unsigned int tempAhbPoll); - -/* return value(1): cooler of abcct/abcct_lcmoff is deactive, - * and no thermal current limit. - */ -extern int mtk_cooler_is_abcct_unlimit(void); - -#endif /* __MT6765_THERMAL_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_cl_amddulthro.h b/drivers/misc/mediatek/thermal/mt6765/inc/mtk_cl_amddulthro.h deleted file mode 100644 index b0853b87cd30..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_cl_amddulthro.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __MT_CL_AMDDULTHRO_H__ -#define __MT_CL_AMDDULTHRO_H__ - -extern int amddulthro_backoff(int level); - -#endif /* __MT_CL_AMDDULTHRO_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6765/inc/mtk_cooler_setting.h deleted file mode 100644 index 62e43f91d596..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ - /* mtk_cooler_mutt.c */ -/* 1: turn on MD throttle V2 cooler; 0: turn off */ -#define FEATURE_MUTT_V2 (1) - -/* mtk_cooler_mutt.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6765/inc/mtk_thermal_ipi.h deleted file mode 100644 index e0d061d61e8f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM -#include "sspm_ipi.h" -#include - -#define THERMAL_SLOT_NUM (4) - -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_sspm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6765/inc/mtk_ts_setting.h deleted file mode 100644 index 0fd1e45ea7da..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/mtk_ts_setting.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (1) - - -/* - * Request HPM in Low temperature condition - */ -#define THERMAL_LT_SET_HPM (1) - -#if THERMAL_LT_SET_HPM -extern int enter_hpm_temp; -extern int leave_hpm_temp; -extern int enable_hpm_temp; -#endif - -/*In src/mtk_tc.c*/ -extern int get_immediate_ts4_wrap(void); - -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_6311buck.h b/drivers/misc/mediatek/thermal/mt6765/inc/tmp_6311buck.h deleted file mode 100644 index 5dd3d4fcd1bf..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_6311buck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_6311BUCK_H__ -#define __TMP_6311BUCK_H__ - -extern int is_ext_buck_exist(void); - -#endif /* __TMP_6311BUCK_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_battery.h b/drivers/misc/mediatek/thermal/mt6765/inc/tmp_battery.h deleted file mode 100644 index 8f1bf646dc9b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_battery.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_BATTERY_H__ -#define __TMP_BATTERY_H__ - -#include -/* Extern two API functions from battery driver - * to limit max charging current. - */ -/** - * return value means charging current in mA - * -1 means error - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int get_bat_charging_current_level(void); - -/** - * current_limit means limit of charging current in mA - * -1 means no limit - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int set_bat_charging_current_limit(int current_limit); -extern enum charger_type mt_get_charger_type(void); - -extern int read_tbat_value(void); - -#endif /* __TMP_BATTERY_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6765/inc/tmp_bts.h deleted file mode 100644 index 7a44349891cb..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_bts.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -/* chip dependent */ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) - -#define BTS_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_btscharger.h b/drivers/misc/mediatek/thermal/mt6765/inc/tmp_btscharger.h deleted file mode 100644 index 3e745001b084..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tmp_btscharger.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_BTS_CHARGER_H__ -#define __TMP_BTS_CHARGER_H__ - -/* chip dependent */ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN2_NTC (2) -/* 390K, pull up resister */ -#define BTSCHARGER_RAP_PULL_UP_R 390000 -/* base on 100K NTC temp - * default value -40 deg - */ -#define BTSCHARGER_TAP_OVER_CRITICAL_LOW 4397119 -/* 1.8V ,pull up voltage */ -#define BTSCHARGER_RAP_PULL_UP_VOLTAGE 1800 -/* default is NCP15WF104F03RC(100K) */ -#define BTSCHARGER_RAP_NTC_TABLE 7 - -#define BTSCHARGER_RAP_ADC_CHANNEL AUX_IN2_NTC /* default is 2 */ -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_CHARGER_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6765/inc/tscpu_settings.h deleted file mode 100644 index f7d130fb1b46..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tscpu_settings.h +++ /dev/null @@ -1,725 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include -#include - -#include "mach/mtk_thermal.h" - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" -#include - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned int)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned int) -1 >> (31 - ((1) ? \ - _bits_))) & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() long long thermal_pTime_us, \ - thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_notice(TSCPU_LOG_TAG "%s: %llu us\n", \ - __func__, thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_notice(TSCPU_LOG_TAG "Warning: tProfiling " \ - "uses incorrect %s %d\n", __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/*Enable thermal controller CG*/ -#define THERMAL_EBABLE_TC_CG - -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. - * Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) - -/* 1: mtk_tc.c supports LVTS; 0: o.w. */ -#define CFG_THERM_LVTS (0) - -/*============================================================= - * Chip related - *============================================================= - */ -/* double check */ -//#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE TS_CON0_TM /* depend on CPU design*/ - -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ -#define TS_TURN_ON 0xFFFFFFCF /* turn on TS_CON1[5:4] 2'b 00 - * 11001111 -> 0xCF ~(0x30 - */ -//#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ -#define TS_TURN_OFF 0x30000000 /* turn off thermal*/ - - -/*chip dependent*/ -#define ADDRESS_INDEX_0 101 -#define ADDRESS_INDEX_1 100 -#define ADDRESS_INDEX_2 102 -#define ADDRESS_INDEX_3 111 -#define ADDRESS_INDEX_4 112 - -#define CLEAR_TEMP 26111 - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - - -#define TSCON0_bit_29_28_00 0x00000000 /* TSCON0[29:28]=2'b00*/ -#define TSCON0_bit_29_28_01 0x10000000 /* TSCON0[29:28]=2'b01*/ -#define TSCON0_bit_29_28_10 0x20000000 /* TSCON0[29:28]=2'b10*/ -#define TSCON0_bit_29_28_11 0x30000000 /* TSCON0[29:28]=2'b11*/ - -#define TSCON0_bit_29_28_MASK 0x30000000 - -/* ADC value to mcu */ -/*chip dependent*/ -#define TEMPADC_MCU1 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_000)) -#define TEMPADC_MCU2 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_001)) -#define TEMPADC_MCU3 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_010)) -#define TEMPADC_MCU4 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_011)) -#define TEMPADC_MCU5 \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_00)|(0x07&TSCON1_bit_0_2_100)) - -#define TEMPADC_ABB \ - ((TSCON0_bit_29_28_MASK&TSCON0_bit_29_28_01)|(0x07&TSCON1_bit_0_2_000)) - -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_AEE_IPANIC -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (0) -/*============================================================= - *REG ACCESS - *============================================================= - */ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | \ - (val), ((void *)addr)) - -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & \ - ~(val), ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal-legacy" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x88) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x8C) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x94) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ - do { \ - if (tscpu_debug_log == 1) { \ - pr_notice(TSCPU_LOG_TAG fmt, ##args); \ - } \ - } while (0) - -#define tscpu_printk(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/*============================================================= - * Structures - *============================================================= - */ -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, - THERMAL_CONTROLLER1, - THERMAL_CONTROLLER_NUM -}; - -struct thermal_controller_speed { - unsigned int tempMonCtl1; - unsigned int tempMonCtl2; - unsigned int tempAhbPoll; -}; - -struct thermal_controller { - enum thermal_sensor ts[TS_ENUM_MAX]; - int ts_number; - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * Shared variables - *============================================================= - */ -/*In src/mtk_tc.c*/ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - *it means polling_delay will be 1/5 of original interval - *after mtktscpu reports > 65C w/o exit point - */ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif -extern struct platform_device *tscpu_pdev; - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_prev_cpu_temp, tscpu_prev_gpu_temp; -extern int tscpu_curr_cpu_temp, tscpu_curr_gpu_temp; -#endif - -#endif - -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif -extern char *adaptive_cooler_name; - -/*common/coolers/mtk_cooler_atm.c*/ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/*common/coolers/mtk_cooler_dtm.c*/ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif - -extern void tscpu_update_tempinfo(void); -extern int tscpu_max_temperature(void); - -/*In src/mtk_tc.c*/ -extern int get_io_reg_base(void); -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp - (int tc_num, enum thermal_sensor type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler - (int irq, void *dev_id); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern int tscpu_get_curr_temp(void); -extern int tscpu_get_curr_max_ts_temp(void); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void thermal_disable_all_periodoc_temp_sensing(void); - -/* - *In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c - *It's not our api, ask them to provide header file - */ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* - *In drivers/misc/mediatek/auxadc/mt_auxadc.c - *It's not our api, ask them to provide header file - */ -extern int IMM_IsAdcInitReady(void); -/*aee related*/ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -extern int aee_rr_init_thermal_temp(int num); -extern int aee_rr_rec_thermal_temp(int index, s8 val); -extern void aee_rr_rec_thermal_status(u8 val); -extern void aee_rr_rec_thermal_ATM_status(u8 val); -extern void aee_rr_rec_thermal_ktime(u64 val); - -extern s8 aee_rr_curr_thermal_temp(int index); -extern u8 aee_rr_curr_thermal_status(void); -extern u8 aee_rr_curr_thermal_ATM_status(void); -extern u64 aee_rr_curr_thermal_ktime(void); -#endif -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -extern void __iomem *thermal_base; -extern void __iomem *auxadc_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -/*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) -/*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) -/*yes, 0x10000000*/ -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x000) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x004) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x008) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x00C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x010) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x014) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x018) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x01C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x024) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x028) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x02C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x030) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x034) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x038) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x03C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x040) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x044) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x048) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x04C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x050) - -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x054) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x058) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x05C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x060) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x064) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x068) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x06C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x070) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x074) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x078) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x07C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x080) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x084) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x088) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x08C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x090) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x094) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x098) - -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x09C) - -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x0A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x0A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x0A8) - -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x0B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x0B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x0B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x0BC) - -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x0C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x0C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x0C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x0CC) - -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x0F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x0F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x0F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x0FC) - - - -#define TEMPMONCTL0_1 (THERM_CTRL_BASE_2 + 0x100) -#define TEMPMONCTL1_1 (THERM_CTRL_BASE_2 + 0x104) -#define TEMPMONCTL2_1 (THERM_CTRL_BASE_2 + 0x108) -#define TEMPMONINT_1 (THERM_CTRL_BASE_2 + 0x10C) -#define TEMPMONINTSTS_1 (THERM_CTRL_BASE_2 + 0x110) -#define TEMPMONIDET0_1 (THERM_CTRL_BASE_2 + 0x114) -#define TEMPMONIDET1_1 (THERM_CTRL_BASE_2 + 0x118) -#define TEMPMONIDET2_1 (THERM_CTRL_BASE_2 + 0x11C) -#define TEMPH2NTHRE_1 (THERM_CTRL_BASE_2 + 0x124) -#define TEMPHTHRE_1 (THERM_CTRL_BASE_2 + 0x128) -#define TEMPCTHRE_1 (THERM_CTRL_BASE_2 + 0x12C) -#define TEMPOFFSETH_1 (THERM_CTRL_BASE_2 + 0x130) -#define TEMPOFFSETL_1 (THERM_CTRL_BASE_2 + 0x134) -#define TEMPMSRCTL0_1 (THERM_CTRL_BASE_2 + 0x138) -#define TEMPMSRCTL1_1 (THERM_CTRL_BASE_2 + 0x13C) -#define TEMPAHBPOLL_1 (THERM_CTRL_BASE_2 + 0x140) -#define TEMPAHBTO_1 (THERM_CTRL_BASE_2 + 0x144) -#define TEMPADCPNP0_1 (THERM_CTRL_BASE_2 + 0x148) -#define TEMPADCPNP1_1 (THERM_CTRL_BASE_2 + 0x14C) -#define TEMPADCPNP2_1 (THERM_CTRL_BASE_2 + 0x150) - -#define TEMPADCMUX_1 (THERM_CTRL_BASE_2 + 0x154) -#define TEMPADCEXT_1 (THERM_CTRL_BASE_2 + 0x158) -#define TEMPADCEXT1_1 (THERM_CTRL_BASE_2 + 0x15C) -#define TEMPADCEN_1 (THERM_CTRL_BASE_2 + 0x160) -#define TEMPPNPMUXADDR_1 (THERM_CTRL_BASE_2 + 0x164) -#define TEMPADCMUXADDR_1 (THERM_CTRL_BASE_2 + 0x168) -#define TEMPADCEXTADDR_1 (THERM_CTRL_BASE_2 + 0x16C) -#define TEMPADCEXT1ADDR_1 (THERM_CTRL_BASE_2 + 0x170) -#define TEMPADCENADDR_1 (THERM_CTRL_BASE_2 + 0x174) -#define TEMPADCVALIDADDR_1 (THERM_CTRL_BASE_2 + 0x178) -#define TEMPADCVOLTADDR_1 (THERM_CTRL_BASE_2 + 0x17C) -#define TEMPRDCTRL_1 (THERM_CTRL_BASE_2 + 0x180) -#define TEMPADCVALIDMASK_1 (THERM_CTRL_BASE_2 + 0x184) -#define TEMPADCVOLTAGESHIFT_1 (THERM_CTRL_BASE_2 + 0x188) -#define TEMPADCWRITECTRL_1 (THERM_CTRL_BASE_2 + 0x18C) -#define TEMPMSR0_1 (THERM_CTRL_BASE_2 + 0x190) -#define TEMPMSR1_1 (THERM_CTRL_BASE_2 + 0x194) -#define TEMPMSR2_1 (THERM_CTRL_BASE_2 + 0x198) -#define TEMPADCHADDR_1 (THERM_CTRL_BASE_2 + 0x19C) - -#define TEMPIMMD0_1 (THERM_CTRL_BASE_2 + 0x1A0) -#define TEMPIMMD1_1 (THERM_CTRL_BASE_2 + 0x1A4) -#define TEMPIMMD2_1 (THERM_CTRL_BASE_2 + 0x1A8) - -#define TEMPMONIDET3_1 (THERM_CTRL_BASE_2 + 0x1B0) -#define TEMPADCPNP3_1 (THERM_CTRL_BASE_2 + 0x1B4) -#define TEMPMSR3_1 (THERM_CTRL_BASE_2 + 0x1B8) -#define TEMPIMMD3_1 (THERM_CTRL_BASE_2 + 0x1BC) - -#define TEMPPROTCTL_1 (THERM_CTRL_BASE_2 + 0x1C0) -#define TEMPPROTTA_1 (THERM_CTRL_BASE_2 + 0x1C4) -#define TEMPPROTTB_1 (THERM_CTRL_BASE_2 + 0x1C8) -#define TEMPPROTTC_1 (THERM_CTRL_BASE_2 + 0x1CC) - -#define TEMPSPARE0_1 (THERM_CTRL_BASE_2 + 0x1F0) -#define TEMPSPARE1_1 (THERM_CTRL_BASE_2 + 0x1F4) -#define TEMPSPARE2_1 (THERM_CTRL_BASE_2 + 0x1F8) -#define TEMPSPARE3_1 (THERM_CTRL_BASE_2 + 0x1FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ -#define THERMAL_ENABLE_SEN0 0x1 -#define THERMAL_ENABLE_SEN1 0x2 -#define THERMAL_ENABLE_SEN2 0x4 -#define THERMAL_MONCTL0_MASK 0x00000007 - -#define THERMAL_PUNT_MASK 0x00000FFF -#define THERMAL_FSINTVL_MASK 0x03FF0000 -#define THERMAL_SPINTVL_MASK 0x000003FF -#define THERMAL_MON_INT_MASK 0x0007FFFF - -#define THERMAL_MON_CINTSTS0 0x000001 -#define THERMAL_MON_HINTSTS0 0x000002 -#define THERMAL_MON_LOINTSTS0 0x000004 -#define THERMAL_MON_HOINTSTS0 0x000008 -#define THERMAL_MON_NHINTSTS0 0x000010 -#define THERMAL_MON_CINTSTS1 0x000020 -#define THERMAL_MON_HINTSTS1 0x000040 -#define THERMAL_MON_LOINTSTS1 0x000080 -#define THERMAL_MON_HOINTSTS1 0x000100 -#define THERMAL_MON_NHINTSTS1 0x000200 -#define THERMAL_MON_CINTSTS2 0x000400 -#define THERMAL_MON_HINTSTS2 0x000800 -#define THERMAL_MON_LOINTSTS2 0x001000 -#define THERMAL_MON_HOINTSTS2 0x002000 -#define THERMAL_MON_NHINTSTS2 0x004000 -#define THERMAL_MON_TOINTSTS 0x008000 -#define THERMAL_MON_IMMDINTSTS0 0x010000 -#define THERMAL_MON_IMMDINTSTS1 0x020000 -#define THERMAL_MON_IMMDINTSTS2 0x040000 -#define THERMAL_MON_FILTINTSTS0 0x080000 -#define THERMAL_MON_FILTINTSTS1 0x100000 -#define THERMAL_MON_FILTINTSTS2 0x200000 - - -#define THERMAL_tri_SPM_State0 0x20000000 -#define THERMAL_tri_SPM_State1 0x40000000 -#define THERMAL_tri_SPM_State2 0x80000000 - - -#define THERMAL_MSRCTL0_MASK 0x00000007 -#define THERMAL_MSRCTL1_MASK 0x00000038 -#define THERMAL_MSRCTL2_MASK 0x000001C0 - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES CONFIG_NR_CPUS - -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6765/inc/tzbatt_initcfg.h deleted file mode 100644 index d8c424a8faf5..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6765/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6765/inc/tzcpu_initcfg.h deleted file mode 100644 index 206c80e61788..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (117000) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6765/src/Makefile b/drivers/misc/mediatek/thermal/mt6765/src/Makefile deleted file mode 100644 index edd88a89268a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/src/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# -# Copyright (C) 2017 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(MTK_PLATFORM) -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/mt6765/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/ -ccflags-y += -I$(srctree)/include/dt-bindings/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/include/ - -obj-$(CONFIG_THERMAL) += mtk_tc.o -#obj-$(CONFIG_THERMAL) += mtk_thermal_ipi.o -obj-$(CONFIG_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_THERMAL) += mtk_ts_6357buck1.o -obj-$(CONFIG_THERMAL) += mtk_ts_6357buck2.o diff --git a/drivers/misc/mediatek/thermal/mt6765/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6765/src/mtk_tc.c deleted file mode 100644 index 234d4ccc26b9..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/src/mtk_tc.c +++ /dev/null @@ -1,1740 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - - -//#include -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; - * 0: turn off - */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include - -#define DEBUG_THERMAL_SSPM 0 - -#if DEBUG_THERMAL_SSPM -#include "mtk_thermal_ipi.h" -#endif - -static struct device *tscpu_dev; -/*============================================================= - * Local variable definition - *============================================================= - */ - - -/* - *Bank0: MP0(TSMCU1) (LL) - *Bank1: MP1(TSMCU2) (L) - *Bank2: CCI(TSMCU1,TSMCU2) - *Bank3: GPU(TSMCU3) - *Bank4: SOC(TSMCU4,TSMCU5) - */ -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - * TC1: (TS_MCU5, TS_MCU4) - */ - -int tscpu_ts_temp[TS_ENUM_MAX]; -int tscpu_ts_temp_r[TS_ENUM_MAX]; - -/* chip dependent */ -/* - * TO-DO: I assume AHB bus frequecy is 78MHz. - * Please confirm it. - */ -/* - * The tscpu_g_tc structure controls the polling rates and sensor mapping table - * of all thermal controllers. If HW thermal controllers are more than you - * actually needed, you should pay attention to default setting of unneeded - * thermal controllers. Otherwise, these unneeded thermal controllers will be - * initialized and work unexpectedly. - */ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {TS_MCU1, TS_MCU2, TS_MCU3}, - .ts_number = 3, - .tc_offset = 0x0, - .tc_speed = { - 0x0000000C, - 0x0001003B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {TS_MCU4, TS_MCU5}, - .ts_number = 2, - .tc_offset = 0x100, - .tc_speed = { - 0x0000000C, - 0x0001003B, - 0x0000030D - } /* 4.9ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -static __s32 g_o_vtsmcu3; -static __s32 g_o_vtsmcu4; -static __s32 g_o_vtsmcu5; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[TS_ENUM_MAX] = { 0 }; - -static __u32 calefuse1; -static __u32 calefuse2; -static __u32 calefuse3; - -/** - * If curr_temp >= tscpu_polling_trip_temp1, use interval else if cur_temp >= - * tscpu_polling_trip_temp2 && curr_temp < tscpu_polling_trip_temp1, use - * interval*tscpu_polling_factor1 else, use interval*tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - *it means polling_delay will be 1/5 of original interval - *after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 2; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -int tscpu_prev_cpu_temp = 0, tscpu_prev_gpu_temp = 0; -int tscpu_curr_cpu_temp = 0, tscpu_curr_gpu_temp = 0; -#endif - -static int tscpu_curr_max_ts_temp; - -#if CFG_THERM_LVTS -__u32 lvts_count1_b30c; -__u32 lvts_count2_b30c; -__u32 lvts_count3_b30c; - -__u32 lvts_golden_temp1; -__u32 lvts_golden_temp2; -__u32 lvts_golden_temp3; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum thermal_sensor ts_name); -static void set_tc_trigger_hw_protect - (int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - -/*=============================================================*/ -static int read_nvmem_cell(char *cell_name, u8 *buf, int len) -{ - struct nvmem_cell *cell; - size_t size = 0; - u8 *tmp = NULL; - - if (IS_ERR(buf)) { - tscpu_warn("[%s] buffer fail\n", __func__); - return -EINVAL; - } - - cell = nvmem_cell_get(tscpu_dev, cell_name); - if ((cell == NULL) || (IS_ERR(cell))) { - tscpu_warn("[%s] nvmem_cell_get fail\n", __func__); - return -EINVAL; - } - - tmp = (u8 *)nvmem_cell_read(cell, &size); - if ((tmp == NULL) || (size <= 0)) { - tscpu_warn("[%s] nvmem_cell_read error\n", __func__); - return -EINVAL; - } - - nvmem_cell_put(cell); - - if (len < size) { - tscpu_warn("[%s] buffer too small(%d<%d)\n", - __func__, len, size); - kfree(tmp); - return -EINVAL; - } - - memcpy(buf, tmp, size); - - kfree(tmp); - - return 0; -} - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - -#if defined(CONFIG_MTK_CLKMGR) - tscpu_dprintk("%s\n", __func__); - /* ret = enable_clock(MT_CG_PERI_THERM, "THERMAL"); */ -#else - /* Use CCF instead */ - tscpu_dprintk("%s CCF\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); -#endif - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - -#if defined(CONFIG_MTK_CLKMGR) - tscpu_dprintk("%s\n", __func__); - /*ret = disable_clock(MT_CG_PERI_THERM, "THERMAL"); */ -#else - /*Use CCF instead*/ - tscpu_dprintk("%s CCF\n", __func__); - clk_disable_unprepare(therm_main); -#endif - return ret; -} - -/* TODO: FIXME */ -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum -thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("%s\n", __func__); - - /* - *Bank0: MP0(TSMCU1) (LL) - *Bank1: MP1(TSMCU2) (L) - *Bank2: CCI(TSMCU1,TSMCU2) - *Bank3: GPU(TSMCU3) - *Bank4: SOC(TSMCU4,TSMCU5) - */ - /* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - * TC1: (TS_MCU5, TS_MCU4) - */ - /* chip dependent */ - - /* - * If there are two or more sensors in a bank, choose the sensor - * calibration value of the dominant sensor. You can observe it in the - * thermal doc provided by Thermal DE. For example, Bank 1 is for SOC - * + GPU. Observe all scenarios related to GPU tests to determine - * which sensor is the highest temperature in all tests. Then, It is - * the dominant sensor. (Confirmed by Thermal DE Alfred Tsai) - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[0]; - break; - case THERMAL_BANK1: - x_roomt = g_x_roomt[1]; - break; - case THERMAL_BANK2: - x_roomt = g_x_roomt[1]; - break; - case THERMAL_BANK3: - x_roomt = g_x_roomt[2]; - break; - case THERMAL_BANK4: - x_roomt = g_x_roomt[3];/*TSMCU4 almost same as TSMCU5*/ - break; - default: /*choose high temp */ - x_roomt = g_x_roomt[1]; - break; - } - - /* - * The equations in this function are confirmed by Thermal DE Alfred - * Tsai. Don't have to change until using next generation thermal - * sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1534 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1534 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = - ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1534 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1534 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - tscpu_printk("[cal] g_o_vtsmcu3 = %d\n", g_o_vtsmcu3); - tscpu_printk("[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - tscpu_printk("[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - -#if CFG_THERM_LVTS - tscpu_printk("[cal] lvts_count1_b30c= %d\n", lvts_count1_b30c); - tscpu_printk("[cal] lvts_count2_b30c= %d\n", lvts_count2_b30c); - tscpu_printk("[cal] lvts_count3_b30c= %d\n", lvts_count3_b30c); - tscpu_printk("[cal] lvts_golden_temp1= %d\n", lvts_golden_temp1); - tscpu_printk("[cal] lvts_golden_temp2= %d\n", lvts_golden_temp2); - tscpu_printk("[cal] lvts_golden_temp3= %d\n", lvts_golden_temp3); -#endif -} - -void eDataCorrector(void) -{ - - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - if (g_o_vtsmcu3 < -8 || g_o_vtsmcu3 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu3\n"); - g_o_vtsmcu3 = 260; - } - if (g_o_vtsmcu4 < -8 || g_o_vtsmcu4 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu4\n"); - g_o_vtsmcu4 = 260; - } - if (g_o_vtsmcu5 < -8 || g_o_vtsmcu5 > 484) { /* TODO */ - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu5\n"); - g_o_vtsmcu5 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2; - int efuse_len = 12; - __u32 thermal_efuse[3] = {0}; -#if CFG_THERM_LVTS - __u32 lvtsdevinfo1, lvtsdevinfo2, lvtsdevinfo3; - __u32 lvts_efuse[3] = {0}; -#endif - tscpu_dev = &tscpu_pdev->dev; - read_nvmem_cell("thermal_efuse_cell", (u8 *)&thermal_efuse, efuse_len); - temp1 = thermal_efuse[0]; - temp0 = thermal_efuse[1]; - temp2 = thermal_efuse[2]; - pr_notice("[calibration] temp0=0x%x, temp1=0x%x, temp2=0x%x\n", - temp0, temp1, temp2); - /* - * chip dependent - * ADC_GE_T - * ADC_OE_T - */ - g_adc_ge_t = ((temp0 & _BITMASK_(31:22)) >> 22); - g_adc_oe_t = ((temp0 & _BITMASK_(21:12)) >> 12); - - /* - * O_VTSMCU1 - * O_VTSMCU2 - * O_VTSMCU3 - * O_VTSMCU4 - * O_VTSMCU5 - * O_VTSABB - */ - g_o_vtsmcu1 = ((temp1 & _BITMASK_(25:17)) >> 17); - g_o_vtsmcu2 = ((temp1 & _BITMASK_(16:8)) >> 8); - g_o_vtsmcu3 = (temp0 & _BITMASK_(8:0)); - g_o_vtsmcu4 = ((temp2 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu5 = ((temp2 & _BITMASK_(13:5)) >> 5); - g_o_vtsabb = ((temp2 & _BITMASK_(22:14)) >> 14); - - /* - * DEGC_cali (6b) - * ADC_CALI_EN_T(1b) - */ - g_degc_cali = ((temp1 & _BITMASK_(6:1)) >> 1); - g_adc_cali_en_t = (temp1 & _BIT_(0)); - - /* - * O_SLOPE_SIGN (1b) - * O_SLOPE (6b) - */ - g_o_slope_sign = ((temp1 & _BIT_(7)) >> 7); - g_o_slope = ((temp1 & _BITMASK_(31:26)) >> 26); - - /*ID*/ - g_id = ((temp0 & _BIT_(9)) >> 9); - - - - /* - * Check ID bit - * If ID=0 (TSMC sample) , ignore O_SLOPE EFuse value and set - * O_SLOPE=0. - * If ID=1 (non-TSMC sample), read O_SLOPE EFuse value for following - * calculation. - */ - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - g_o_vtsmcu3 = 260; - g_o_vtsmcu4 = 260; - g_o_vtsmcu5 = 260; - g_o_vtsabb = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - -#if CFG_THERM_LVTS - - lvtsdevinfo1 = get_devinfo_with_index(118); - lvtsdevinfo2 = get_devinfo_with_index(119); - lvtsdevinfo3 = get_devinfo_with_index(139); - - pr_notice("[lvts_cal] 0: 0x%x, 1: 0x%x, 2: 0x%x\n", lvtsdevinfo1, - lvtsdevinfo2, lvtsdevinfo3); - - lvts_count1_b30c = (lvtsdevinfo1 & _BITMASK_(23:0)); - lvts_count2_b30c = (lvtsdevinfo2 & _BITMASK_(23:0)); - lvts_count3_b30c = (lvtsdevinfo3 & _BITMASK_(23:0)); - - lvts_golden_temp1 = ((lvtsdevinfo1 & _BITMASK_(31:24)) >> 24); - lvts_golden_temp2 = ((lvtsdevinfo2 & _BITMASK_(31:24)) >> 24); - lvts_golden_temp3 = ((lvtsdevinfo3 & _BITMASK_(31:24)) >> 24); -#endif - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[TS_ENUM_MAX] = { 0 }; - int i = 0; -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - int count = 0, offset = 0; - struct thermal_ipi_data thermal_data; -#endif -#endif - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[TS_MCU1] = (g_o_vtsmcu1 + 3350 - g_oe); - format[TS_MCU2] = (g_o_vtsmcu2 + 3350 - g_oe); - format[TS_MCU3] = (g_o_vtsmcu3 + 3350 - g_oe); - format[TS_MCU4] = (g_o_vtsmcu4 + 3350 - g_oe); - format[TS_MCU5] = (g_o_vtsmcu5 + 3350 - g_oe); - - for (i = 0; i < TS_ENUM_MAX; i++) { - /* x_roomt * 10000 */ - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; - } - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < TS_ENUM_MAX; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, - g_x_roomt[i]); -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - thermal_data.u.data.arg[0] = g_degc_cali; - thermal_data.u.data.arg[1] = g_o_slope_sign; - thermal_data.u.data.arg[2] = g_o_slope; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_oe; - thermal_data.u.data.arg[1] = g_gain; - thermal_data.u.data.arg[2] = g_x_roomt[0]; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP2, &thermal_data) != 0) - udelay(100); - - for (i = 1 ; i < TS_ENUM_MAX; i++) { - thermal_data.u.data.arg[count] = g_x_roomt[i]; - if (count == (THERMAL_SLOT_NUM - 2)) { - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP3 + offset, - &thermal_data) != 0) - udelay(100); - offset++; - } - count = (count + 1) % (THERMAL_SLOT_NUM - 1); - } - - if (count != 0) { - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP3 + offset, - &thermal_data) != 0) - udelay(100); - } -#endif -#endif -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum thermal_sensor ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1534+O_slope*10)/10*(18/15)* - * (1/10000)+X_roomtabb]*Gain*4096 + OE - */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum thermal_sensor ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n", - * ts_name,xtoomt); - */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 + g_o_slope * 10)); - else /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 - g_o_slope * 10)); - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} - -int get_immediate_none_wrap(void) -{ - return -127000; -} - - - -/* - *Bank0: MP0(TSMCU1) (LL) - *Bank1: MP1(TSMCU2) (L) - *Bank2: CCI(TSMCU1,TSMCU2) - *Bank3: GPU(TSMCU3) - *Bank4: SOC(TSMCU4,TSMCU5) - */ -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - * TC1: (TS_MCU5, TS_MCU4) - */ - -/* chip dependent */ -int get_immediate_cpuB_wrap(void) -{ - return -127000; -} - -int get_immediate_mcucci_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_temp[TS_MCU1], tscpu_ts_temp[TS_MCU2]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU3]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuLL_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU1]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuL_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_coreSoC_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_temp[TS_MCU4], tscpu_ts_temp[TS_MCU5]); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpuLL_wrap, - get_immediate_cpuL_wrap, - get_immediate_mcucci_wrap, - get_immediate_gpu_wrap, - get_immediate_coreSoC_wrap -}; - - - -/* - *Bank0: MP0(TSMCU1) (LL) - *Bank1: MP1(TSMCU2) (L) - *Bank2: CCI(TSMCU1,TSMCU2) - *Bank3: GPU(TSMCU3) - *Bank4: SOC(TSMCU4,TSMCU5) - */ -/* - * TC0: (TS_MCU1, TS_MCU2, TS_MCU3) - * TC1: (TS_MCU5, TS_MCU4) - */ - - -/* chip dependent */ -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts4_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU4]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts5_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_temp[TS_MCU5]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts6_wrap(void) -{ - return -127000; -} - -int get_immediate_ts7_wrap(void) -{ - return -127000; -} - -int get_immediate_ts8_wrap(void) -{ - return -127000; -} - -int get_immediate_tsabb_wrap(void) -{ - return -127000; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - get_immediate_ts1_wrap, - get_immediate_ts2_wrap, - get_immediate_ts3_wrap, - get_immediate_ts4_wrap, - get_immediate_ts5_wrap -}; - -static void thermal_interrupt_handler(int tc_num) -{ - __u32 ret = 0, offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - /* write to clear interrupt status */ - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); - tscpu_dprintk( - "[tIRQ] %s,tc_num=0x%08x,ret=0x%08x\n", __func__, tc_num, ret); - - if (ret & THERMAL_MON_CINTSTS0) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 0 - cold interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS0) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 0 - hot interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS1) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 1 - hot interrupt trigger\n"); - - if (ret & THERMAL_MON_HINTSTS2) - tscpu_dprintk( - "[thermal_isr]: thermal sensor point 2 - hot interrupt trigger\n"); - - if (ret & THERMAL_tri_SPM_State0) - tscpu_dprintk( - "[thermal_isr]: Thermal state0 to trigger SPM state0\n"); - - if (ret & THERMAL_tri_SPM_State1) { - tscpu_dprintk( - "[thermal_isr]: Thermal state1 to trigger SPM state1\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_tri_SPM_State2) - tscpu_printk( - "[thermal_isr]: Thermal state2 to trigger SPM state2\n"); -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - __u32 ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - - ret = ret & 0xFF; - - tscpu_dprintk("thermal_interrupt_handler : THERMINTST = 0x%x\n", ret); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - mask = 1 << i; - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - __u32 offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - tempMonCtl1 = tscpu_g_tc[tc_num].tc_speed.tempMonCtl1; - tempMonCtl2 = tscpu_g_tc[tc_num].tc_speed.tempMonCtl2; - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.tempAhbPoll; - - /* Calculating period unit in Module clock x 256, - * and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* bus clock 66M counting unit is 12 * 1/66M * 256 = - * 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - * filt interval is 1 * 46.545us = 46.545us, - * sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /* AHB polling is 781* 1/66M = 11.833us */ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - /* temperature sampling control, 4 out of 6 samples */ - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - /* temperature sampling control, 8 out of 10 samples */ - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - /* temperature sampling control, 16 out of 18 samples */ - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); -#else /* default 1 */ - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); -#endif - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); - - /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); - - /* AHB value for auxadc enable */ - mt_reg_sync_writel(0x800, offset + TEMPADCEN); - - /* - * AHB address for auxadc enable (channel 0 immediate mode selected) - * this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void set_tc_trigger_hw_protect -(int temperature, int temperature2, int tc_num) -{ - int temp = 0; - int raw_high; - enum thermal_sensor ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* set temp offset to 0x3FF to avoid interrupt false triggered */ - mt_reg_sync_writel( - readl(offset + TEMPPROTCTL) | 0x3FF, - offset + TEMPPROTCTL); - - /* temperature2=80000; test only */ - tscpu_dprintk("%s t1=%d t2=%d\n", __func__, - temperature, temperature2); - - ts_name = tscpu_g_tc[tc_num].ts[0]; - - /* temperature to trigger SPM state2 */ - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); - - /* set hot to wakeup event control */ - mt_reg_sync_writel(0x20000, offset + TEMPPROTCTL); - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); - - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); - - /* clear temp offset */ - mt_reg_sync_writel( - readl(offset + TEMPPROTCTL) & ~0xFFF, - offset + TEMPPROTCTL); -} - -static int read_tc_raw_and_temp(u32 *tempmsr_name, enum thermal_sensor ts_name) -{ - int temp = 0, raw = 0; - - if (thermal_base == 0) - return 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl(tempmsr_name) & 0x0fff; - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_temp_r[ts_name] = raw; - - return temp * 100; -} - -void tscpu_thermal_read_tc_temp(int tc_num, enum thermal_sensor type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, - tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - case 1: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - case 2: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - case 3: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - default: - tscpu_ts_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_temp[type]); - break; - } -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - - /* write temp to spare register */ - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); - - /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL1); - - /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); - - /* polling interval to check if temperature sense is ready */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); - - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - - /* temperature measurement sampling control */ - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) - * automatically by hw - */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); - - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); - - /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); - - /* enable auxadc mux & pnp write transaction */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - - - /* enable all interrupt except filter sense and - * immediate sense interrupt - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - /* enable all sensing point(sensing point 2 is unused)*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum thermal_sensor type) -{ - switch (type) { - case TS_MCU1: - return TEMPADC_MCU1; - case TS_MCU2: - return TEMPADC_MCU2; - case TS_MCU3: - return TEMPADC_MCU3; - case TS_MCU4: - return TEMPADC_MCU4; - case TS_MCU5: - return TEMPADC_MCU5; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - /* tscpu_printk("thermal_pause_all_periodoc_temp_sensing\n"); */ - - /* config bank0,1,2 */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - /* tscpu_printk("thermal_release_all_periodoc_temp_sensing\n"); */ - - /*config bank0,1,2 */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - /* tscpu_printk("thermal_disable_all_periodoc_temp_sensing\n"); */ - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - /* tscpu_printk("thermal_disable_all_periodoc_temp_sensing:" - * "Bank_%d\n",i); - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - - /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); - - /* disable auxadc channel 11 immediate mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - - tscpu_dprintk( - "%s,temperature=%d,temperature2=%d,\n", __func__, - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /* spend 860~1463 us */ - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - //TODO -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_notice("resume time spent, sec : %lu , usec : %lu\n", - (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - set_tc_trigger_hw_protect(temperature, temperature2, i); - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - //TODO -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - int i; -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - struct thermal_ipi_data thermal_data; -#endif -#endif - seq_printf(m, "current temp:%d\n", tscpu_curr_max_ts_temp); - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_id = %d\n", g_id); - - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - seq_printf(m, "[cal] g_o_vtsmcu3 = %d\n", g_o_vtsmcu3); - seq_printf(m, "[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - seq_printf(m, "[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < TS_ENUM_MAX; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - seq_printf(m, "calefuse1:0x%x\n", calefuse1); - seq_printf(m, "calefuse2:0x%x\n", calefuse2); - seq_printf(m, "calefuse3:0x%x\n", calefuse3); - -#if DEBUG_THERMAL_SSPM -#if THERMAL_ENABLE_TINYSYS_SSPM - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_GET_TEMP, &thermal_data) != 0) - udelay(500); -#endif -#endif - return 0; -} - - -/* - * Bank0: MP0(TSMCU4) (LL) - * Bank1: MP1(TSMCU5) (L) - * Bank2: GPU(TSMCU3) - * Bank3: CCI(TSMCU4,TSMCU5) - * Bank4: SOC(TSMCU2) - */ -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of - * thermal controller driver - */ - tscpu_prev_cpu_temp = tscpu_curr_cpu_temp; - tscpu_prev_gpu_temp = tscpu_curr_gpu_temp; - - /* It is platform dependent which TS is better to - * present CPU/GPU temperature - */ - tscpu_curr_cpu_temp = MAX(tscpu_ts_temp[TS_MCU1], - tscpu_ts_temp[TS_MCU2]); - - tscpu_curr_gpu_temp = tscpu_ts_temp[TS_MCU3]; -#endif - /* though tscpu_max_temperature is common, - * put it in mtk_ts_cpu.c is weird. - */ - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] thermal_base=0x%p\n" - * thermal_base); - */ - } - - /* get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - /* tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", - * thermal_irq_number); - */ - if (!thermal_irq_number) { - /* TODO: need check "irq number" */ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_irq_number); - return 0; - } - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6765-auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] auxadc_ts_base=0x%p\n", - * auxadc_ts_base); - */ - } - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6765-infracfg"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] infracfg_ao_base=0x%p\n", - * infracfg_ao_base); - */ - } - - node = of_find_compatible_node(NULL, NULL, - "mediatek,mt6765-apmixedsys"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - /* tscpu_printk("[THERM_CTRL] apmixed_base=0x%p\n", - * th_apmixed_base); - */ - } - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base=\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); /**/ - if (!node) { - pr_notice("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_notice("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /* Need to confirm with DE */ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /* The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if (cg_freq & _BIT_(4)) - ahbClk = clockSource / 2; - else if (cg_freq & _BIT_(3)) - ahbClk = clockSource / 4; - else if (cg_freq & _BIT_(2)) - ahbClk = clockSource / 8; - else if (cg_freq & _BIT_(1)) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /* tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm); */ - /* tscpu_printk("AHB bus clock= %d MHz\n", ahbClk); */ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "L %d LL %d", - get_immediate_cpuL_wrap(), get_immediate_cpuLL_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6765/src/mtk_ts_6357buck1.c b/drivers/misc/mediatek/thermal/mt6765/src/mtk_ts_6357buck1.c deleted file mode 100644 index f55b0b87534f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/src/mtk_ts_6357buck1.c +++ /dev/null @@ -1,621 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -//#include -#include -#include -#include -#include /* PMIC MFD core header */ -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 - *&& curr_temp < polling_trip_temp1, use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = {150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = "sysrst.6357buck1"; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6357tsbuck1_cur_temp; -/* - *static long int mt6357tsbuck1_start_temp; - *static long int mt6357tsbuck1_end_temp; - */ -/*=============================================================*/ - -static int mt6357tsbuck1_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6357tsbuck1_get_hw_temp(); - mt6357tsbuck1_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6357tsbuck1_bind - (struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6357tsbuck1_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6357tsbuck1_get_mode - (struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6357tsbuck1_set_mode - (struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6357tsbuck1_get_trip_type - (struct thermal_zone_device *thermal, int trip, - enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6357tsbuck1_get_trip_temp - (struct thermal_zone_device *thermal, int trip, - int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6357tsbuck1_get_crit_temp( - struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6357tsbuck1_dev_ops = { - .bind = mt6357tsbuck1_bind, - .unbind = mt6357tsbuck1_unbind, - .get_temp = mt6357tsbuck1_get_temp, - .get_mode = mt6357tsbuck1_get_mode, - .set_mode = mt6357tsbuck1_set_mode, - .get_trip_type = mt6357tsbuck1_get_trip_type, - .get_trip_temp = mt6357tsbuck1_get_trip_temp, - .get_crit_temp = mt6357tsbuck1_get_crit_temp, -}; - -static int mt6357tsbuck1_sysrst_get_max_state - (struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6357tsbuck1_sysrst_get_cur_state( - struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6357tsbuck1_sysrst_set_cur_state( - struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("MT6357TSBUCK1 OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - } - return 0; -} - -static struct thermal_cooling_device_ops mt6357tsbuck1_cooling_sysrst_ops = { - .get_max_state = mt6357tsbuck1_sysrst_get_max_state, - .get_cur_state = mt6357tsbuck1_sysrst_get_cur_state, - .set_cur_state = mt6357tsbuck1_sysrst_set_cur_state, -}; - -static int mt6357tsbuck1_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d, trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d, g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d, g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s, time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6357tsbuck1_register_thermal(void); -static void mt6357tsbuck1_unregister_thermal(void); - -static ssize_t mt6357tsbuck1_write(struct file *file, - const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6357tsbuck1_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6357tsbuck1_data *ptr_mt6357tsbuck1_data; - - ptr_mt6357tsbuck1_data = kmalloc(sizeof(*ptr_mt6357tsbuck1_data), - GFP_KERNEL); - - if (ptr_mt6357tsbuck1_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6357tsbuck1_data->desc) - 1)) ? count : - (sizeof(ptr_mt6357tsbuck1_data->desc) - 1); - if (copy_from_user(ptr_mt6357tsbuck1_data->desc, buffer, len)) { - kfree(ptr_mt6357tsbuck1_data); - return 0; - } - - ptr_mt6357tsbuck1_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6357tsbuck1_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6357tsbuck1_data->trip[0], &ptr_mt6357tsbuck1_data->t_type[0], - ptr_mt6357tsbuck1_data->bind0, - &ptr_mt6357tsbuck1_data->trip[1], &ptr_mt6357tsbuck1_data->t_type[1], - ptr_mt6357tsbuck1_data->bind1, - &ptr_mt6357tsbuck1_data->trip[2], &ptr_mt6357tsbuck1_data->t_type[2], - ptr_mt6357tsbuck1_data->bind2, - &ptr_mt6357tsbuck1_data->trip[3], &ptr_mt6357tsbuck1_data->t_type[3], - ptr_mt6357tsbuck1_data->bind3, - &ptr_mt6357tsbuck1_data->trip[4], &ptr_mt6357tsbuck1_data->t_type[4], - ptr_mt6357tsbuck1_data->bind4, - &ptr_mt6357tsbuck1_data->trip[5], &ptr_mt6357tsbuck1_data->t_type[5], - ptr_mt6357tsbuck1_data->bind5, - &ptr_mt6357tsbuck1_data->trip[6], &ptr_mt6357tsbuck1_data->t_type[6], - ptr_mt6357tsbuck1_data->bind6, - &ptr_mt6357tsbuck1_data->trip[7], &ptr_mt6357tsbuck1_data->t_type[7], - ptr_mt6357tsbuck1_data->bind7, - &ptr_mt6357tsbuck1_data->trip[8], &ptr_mt6357tsbuck1_data->t_type[8], - ptr_mt6357tsbuck1_data->bind8, - &ptr_mt6357tsbuck1_data->trip[9], &ptr_mt6357tsbuck1_data->t_type[9], - ptr_mt6357tsbuck1_data->bind9, - &ptr_mt6357tsbuck1_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6357tsbuck1_unregister_thermal\n", __func__); - mt6357tsbuck1_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api( - __FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck1_write", "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6357tsbuck1_data); - up(&sem_mutex); - return -EINVAL; - } - - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6357tsbuck1_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = - g_bind4[0] = g_bind5[0] = g_bind6[0] = g_bind7[0] = - g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6357tsbuck1_data->bind0[i]; - g_bind1[i] = ptr_mt6357tsbuck1_data->bind1[i]; - g_bind2[i] = ptr_mt6357tsbuck1_data->bind2[i]; - g_bind3[i] = ptr_mt6357tsbuck1_data->bind3[i]; - g_bind4[i] = ptr_mt6357tsbuck1_data->bind4[i]; - g_bind5[i] = ptr_mt6357tsbuck1_data->bind5[i]; - g_bind6[i] = ptr_mt6357tsbuck1_data->bind6[i]; - g_bind7[i] = ptr_mt6357tsbuck1_data->bind7[i]; - g_bind8[i] = ptr_mt6357tsbuck1_data->bind8[i]; - g_bind9[i] = ptr_mt6357tsbuck1_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], - g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6357tsbuck1_data->trip[i]; - - interval = ptr_mt6357tsbuck1_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - mtktspmic_dprintk( - "trip_9_temp=%d,time_ms=%d\n", trip_temp[9], - interval * 1000); - - mtktspmic_dprintk( - "[%s]mt6357tsbuck1_register_thermal\n", __func__); - mt6357tsbuck1_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6357tsbuck1_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck1_write", "Bad argument"); - #endif - kfree(ptr_mt6357tsbuck1_data); - return -EINVAL; -} - -static void mt6357tsbuck1_cancel_thermal_timer(void) -{ - /* cancel timer */ - /* pr_debug("mtkts_pmic_cancel_thermal_timer\n"); */ - - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6357tsbuck1_start_thermal_timer(void) -{ - /* pr_debug("mtkts_pmic_start_thermal_timer\n"); */ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6357tsbuck1_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "sysrst.6357buck1", NULL, &mt6357tsbuck1_cooling_sysrst_ops); - return 0; -} - -static int mt6357tsbuck1_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6357tsbuck1", num_trip, NULL, &mt6357tsbuck1_dev_ops, - 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6357tsbuck1_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6357tsbuck1_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6357tsbuck1_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6357tsbuck1_read, NULL); -} - -static const struct file_operations mt6357tsbuck1_fops = { - .owner = THIS_MODULE, - .open = mt6357tsbuck1_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6357tsbuck1_write, - .release = single_release, -}; -static int mt6357_ts_buck1_probe(struct platform_device *pdev) -{ - int err = 0; - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6357tsbuck1_dir = NULL; - struct mt6397_chip *chip; - - chip = (struct mt6397_chip *)dev_get_drvdata(pdev->dev.parent); - mtktspmic_info("[%s]\n", __func__); - mtktspmic_cali_prepare(chip->regmap); - mtktspmic_cali_prepare2(); - - err = mt6357tsbuck1_register_cooler(); - if (err) - return err; - err = mt6357tsbuck1_register_thermal(); - if (err) - goto err_unreg; - - mt6357tsbuck1_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6357tsbuck1_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6357buck1", 0664, - mt6357tsbuck1_dir, &mt6357tsbuck1_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - mtkTTimer_register("mt6357tsbuck1", - mt6357tsbuck1_start_thermal_timer, - mt6357tsbuck1_cancel_thermal_timer); - - return 0; - -err_unreg: - mt6357tsbuck1_unregister_cooler(); - return err; - -} - -static const struct of_device_id mt6357_ts_buck1_of_match[] = { - {.compatible = "mediatek,mt6357_ts_buck1",}, - {}, -}; - - -MODULE_DEVICE_TABLE(of, mt6357_ts_buck1_of_match); - -static struct platform_driver mt6357_ts_buck1_driver = { - .probe = mt6357_ts_buck1_probe, - .driver = { - .name = "mt6357_ts_buck1", - .of_match_table = mt6357_ts_buck1_of_match, - }, -}; - -static int __init mt6357tsbuck1_init(void) -{ - return platform_driver_register(&mt6357_ts_buck1_driver); -} - -static void __exit mt6357tsbuck1_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6357tsbuck1_unregister_thermal(); - mt6357tsbuck1_unregister_cooler(); - mtkTTimer_unregister("mt6357tsbuck1"); - platform_driver_unregister(&mt6357_ts_buck1_driver); -} -module_init(mt6357tsbuck1_init); -module_exit(mt6357tsbuck1_exit); - -MODULE_DESCRIPTION("MEDIATEK Thermal zone PMIC buck1 temperature sensor"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/mediatek/thermal/mt6765/src/mtk_ts_6357buck2.c b/drivers/misc/mediatek/thermal/mt6765/src/mtk_ts_6357buck2.c deleted file mode 100644 index 6389d5667b9f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6765/src/mtk_ts_6357buck2.c +++ /dev/null @@ -1,626 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (C) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -//#include -#include -#include -#include -#include /* PMIC MFD core header */ -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, - 80000, 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = "sysrst.6357buck2"; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6357tsbuck2_cur_temp; -/* - *static long int mt6357tsbuck2_start_temp; - *static long int mt6357tsbuck2_end_temp; - */ -/*=============================================================*/ - -static int mt6357tsbuck2_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6357tsbuck2_get_hw_temp(); - mt6357tsbuck2_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6357tsbuck2_bind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6357tsbuck2_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info("[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6357tsbuck2_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6357tsbuck2_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6357tsbuck2_get_trip_type(struct thermal_zone_device *thermal, - int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6357tsbuck2_get_trip_temp(struct thermal_zone_device *thermal, - int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6357tsbuck2_get_crit_temp(struct thermal_zone_device *thermal, - int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6357tsbuck2_dev_ops = { - .bind = mt6357tsbuck2_bind, - .unbind = mt6357tsbuck2_unbind, - .get_temp = mt6357tsbuck2_get_temp, - .get_mode = mt6357tsbuck2_get_mode, - .set_mode = mt6357tsbuck2_set_mode, - .get_trip_type = mt6357tsbuck2_get_trip_type, - .get_trip_temp = mt6357tsbuck2_get_trip_temp, - .get_crit_temp = mt6357tsbuck2_get_crit_temp, -}; - -static int mt6357tsbuck2_sysrst_get_max_state(struct thermal_cooling_device - *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6357tsbuck2_sysrst_get_cur_state(struct thermal_cooling_device - *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6357tsbuck2_sysrst_set_cur_state(struct thermal_cooling_device - *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("MT6357TSBUCK2 OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - } - return 0; -} - -static struct thermal_cooling_device_ops mt6357tsbuck2_cooling_sysrst_ops = { - .get_max_state = mt6357tsbuck2_sysrst_get_max_state, - .get_cur_state = mt6357tsbuck2_sysrst_get_cur_state, - .set_cur_state = mt6357tsbuck2_sysrst_set_cur_state, -}; - -static int mt6357tsbuck2_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d, g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d, g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s, time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6357tsbuck2_register_thermal(void); -static void mt6357tsbuck2_unregister_thermal(void); - -static ssize_t mt6357tsbuck2_write(struct file *file, - const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6357tsbuck2_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6357tsbuck2_data *ptr_mt6357tsbuck2_data; - - ptr_mt6357tsbuck2_data = kmalloc(sizeof(*ptr_mt6357tsbuck2_data), - GFP_KERNEL); - - if (ptr_mt6357tsbuck2_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6357tsbuck2_data->desc) - 1)) ? count : - (sizeof(ptr_mt6357tsbuck2_data->desc) - 1); - if (copy_from_user(ptr_mt6357tsbuck2_data->desc, buffer, len)) { - kfree(ptr_mt6357tsbuck2_data); - return 0; - } - - ptr_mt6357tsbuck2_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6357tsbuck2_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6357tsbuck2_data->trip[0], - &ptr_mt6357tsbuck2_data->t_type[0], - ptr_mt6357tsbuck2_data->bind0, - &ptr_mt6357tsbuck2_data->trip[1], - &ptr_mt6357tsbuck2_data->t_type[1], - ptr_mt6357tsbuck2_data->bind1, - &ptr_mt6357tsbuck2_data->trip[2], - &ptr_mt6357tsbuck2_data->t_type[2], - ptr_mt6357tsbuck2_data->bind2, - &ptr_mt6357tsbuck2_data->trip[3], - &ptr_mt6357tsbuck2_data->t_type[3], - ptr_mt6357tsbuck2_data->bind3, - &ptr_mt6357tsbuck2_data->trip[4], - &ptr_mt6357tsbuck2_data->t_type[4], - ptr_mt6357tsbuck2_data->bind4, - &ptr_mt6357tsbuck2_data->trip[5], - &ptr_mt6357tsbuck2_data->t_type[5], - ptr_mt6357tsbuck2_data->bind5, - &ptr_mt6357tsbuck2_data->trip[6], - &ptr_mt6357tsbuck2_data->t_type[6], - ptr_mt6357tsbuck2_data->bind6, - &ptr_mt6357tsbuck2_data->trip[7], - &ptr_mt6357tsbuck2_data->t_type[7], - ptr_mt6357tsbuck2_data->bind7, - &ptr_mt6357tsbuck2_data->trip[8], - &ptr_mt6357tsbuck2_data->t_type[8], - ptr_mt6357tsbuck2_data->bind8, - &ptr_mt6357tsbuck2_data->trip[9], - &ptr_mt6357tsbuck2_data->t_type[9], - ptr_mt6357tsbuck2_data->bind9, - &ptr_mt6357tsbuck2_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s]mt6357tsbuck2_unregister_thermal\n", __func__); - mt6357tsbuck2_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api( - __FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck2_write", "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6357tsbuck2_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6357tsbuck2_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = - g_bind5[0] = - g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6357tsbuck2_data->bind0[i]; - g_bind1[i] = ptr_mt6357tsbuck2_data->bind1[i]; - g_bind2[i] = ptr_mt6357tsbuck2_data->bind2[i]; - g_bind3[i] = ptr_mt6357tsbuck2_data->bind3[i]; - g_bind4[i] = ptr_mt6357tsbuck2_data->bind4[i]; - g_bind5[i] = ptr_mt6357tsbuck2_data->bind5[i]; - g_bind6[i] = ptr_mt6357tsbuck2_data->bind6[i]; - g_bind7[i] = ptr_mt6357tsbuck2_data->bind7[i]; - g_bind8[i] = ptr_mt6357tsbuck2_data->bind8[i]; - g_bind9[i] = ptr_mt6357tsbuck2_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], - g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6357tsbuck2_data->trip[i]; - - interval = ptr_mt6357tsbuck2_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - mtktspmic_dprintk( - "trip_9_temp=%d,time_ms=%d\n", trip_temp[9], - interval * 1000); - - mtktspmic_dprintk( - "[%s]mt6357tsbuck2_register_thermal\n", __func__); - mt6357tsbuck2_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6357tsbuck2_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6357tsbuck2_write", "Bad argument"); - #endif - kfree(ptr_mt6357tsbuck2_data); - return -EINVAL; -} - -static void mt6357tsbuck2_cancel_thermal_timer(void) -{ - /* cancel timer */ - /* pr_debug("mtkts_pmic_cancel_thermal_timer\n"); */ - - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6357tsbuck2_start_thermal_timer(void) -{ - /* pr_debug("mtkts_pmic_start_thermal_timer\n"); */ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6357tsbuck2_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "sysrst.6357buck2", NULL, &mt6357tsbuck2_cooling_sysrst_ops); - return 0; -} - -static int mt6357tsbuck2_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register("mt6357tsbuck2", - num_trip, NULL, &mt6357tsbuck2_dev_ops, - 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6357tsbuck2_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6357tsbuck2_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6357tsbuck2_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6357tsbuck2_read, NULL); -} - -static const struct file_operations mt6357tsbuck2_fops = { - .owner = THIS_MODULE, - .open = mt6357tsbuck2_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6357tsbuck2_write, - .release = single_release, -}; - -static int mt6357_ts_buck2_probe(struct platform_device *pdev) -{ - int err = 0; - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6357tsbuck2_dir = NULL; - struct mt6397_chip *chip; - - chip = (struct mt6397_chip *)dev_get_drvdata(pdev->dev.parent); - mtktspmic_info("[%s]\n", __func__); - - mtktspmic_cali_prepare(chip->regmap); - mtktspmic_cali_prepare2(); - - err = mt6357tsbuck2_register_cooler(); - if (err) - return err; - err = mt6357tsbuck2_register_thermal(); - if (err) - goto err_unreg; - - mt6357tsbuck2_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6357tsbuck2_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6357buck2", 0664, - mt6357tsbuck2_dir, &mt6357tsbuck2_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6357tsbuck2", mt6357tsbuck2_start_thermal_timer, - mt6357tsbuck2_cancel_thermal_timer); - - return 0; - -err_unreg: - mt6357tsbuck2_unregister_cooler(); - return err; - - -} - -static const struct of_device_id mt6357_ts_buck2_of_match[] = { - {.compatible = "mediatek,mt6357_ts_buck2",}, - {}, -}; - - -MODULE_DEVICE_TABLE(of, mt6357_ts_buck2_of_match); - -static struct platform_driver mt6357_ts_buck2_driver = { - .probe = mt6357_ts_buck2_probe, - .driver = { - .name = "mt6357_ts_buck2", - .of_match_table = mt6357_ts_buck2_of_match, - }, -}; - -static int __init mt6357tsbuck2_init(void) -{ - return platform_driver_register(&mt6357_ts_buck2_driver); -} - -static void __exit mt6357tsbuck2_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6357tsbuck2_unregister_thermal(); - mt6357tsbuck2_unregister_cooler(); - mtkTTimer_unregister("mt6357tsbuck2"); - platform_driver_unregister(&mt6357_ts_buck2_driver); -} -module_init(mt6357tsbuck2_init); -module_exit(mt6357tsbuck2_exit); diff --git a/drivers/misc/mediatek/thermal/mt6779/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6779/inc/tmp_bts.h deleted file mode 100644 index 78ef0f1f4e91..000000000000 --- a/drivers/misc/mediatek/thermal/mt6779/inc/tmp_bts.h +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 MediaTek Inc. - */ - -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) - -#define BTS_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6781/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6781/inc/clatm_initcfg.h index a410a6da5c55..d2e5837ef0d3 100644 --- a/drivers/misc/mediatek/thermal/mt6781/inc/clatm_initcfg.h +++ b/drivers/misc/mediatek/thermal/mt6781/inc/clatm_initcfg.h @@ -15,9 +15,9 @@ #define CLATM_INIT_CFG_0_THETA_RISE (2) #define CLATM_INIT_CFG_0_THETA_FALL (8) #define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (300) +#define CLATM_INIT_CFG_0_MIN_CPU_PWR (500) #define CLATM_INIT_CFG_0_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (800) +#define CLATM_INIT_CFG_0_MIN_GPU_PWR (300) #define CLATM_INIT_CFG_0_MAX_GPU_PWR (2000) #define CLATM_INIT_CFG_1_TARGET_TJ (65000) @@ -44,7 +44,7 @@ #define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) -#define CLATM_INIT_CFG_CATM (0) +#define CLATM_INIT_CFG_CATM (2) #define CLATM_INIT_CFG_PHPB_CPU_TT (10) #define CLATM_INIT_CFG_PHPB_CPU_TP (50) @@ -55,6 +55,17 @@ #define CLATM_INIT_HRTIMER_POLLING_DELAY (50) #define CLATM_USE_MIN_CPU_OPP (1) +#define CLCTM_TARGET_TJ (90000) +#define CLCTM_TPCB_1 (47000) +#define CLCTM_TPCB_2 (51000) +#define CLCTM_EXIT_TJ (CLCTM_TARGET_TJ - 10000) +#define CLCTM_AE (CLCTM_TARGET_TJ) +#define CLCTM_BE (0) +#define CLCTM_AX (CLCTM_EXIT_TJ) +#define CLCTM_BX (0) +#define CLCTM_TT_HIGH (500) +#define CLCTM_TT_LOW (500) +#define CLCTM_STEADY_TTJ_DELTA (13500) #define CLATM_CONFIGURABLE_TIMER diff --git a/drivers/misc/mediatek/thermal/mt6781/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6781/inc/tmp_bts.h index 2dc291088468..6cd64dc9efae 100644 --- a/drivers/misc/mediatek/thermal/mt6781/inc/tmp_bts.h +++ b/drivers/misc/mediatek/thermal/mt6781/inc/tmp_bts.h @@ -37,7 +37,10 @@ #define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ #define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - +#define BTS_BLKNTC_RAP_PULL_UP_R 390000 /*390k PULL UP resister*/ +#define BTS_BLKNTC_TAP_OVER_CRITICAL_LOW 4397119 /*BASE ON 100K NTC TEMP DEFAULT VALUE - 40 DEG*/ +#define BTS_BLKNTC_RAP_PULL_UP_VOLTAGE 1800 /*1.8v PULL UP VOLTAGE*/ +#define BTS_BLKNTC_RAP_NTC_TABLE 7 /*default is ncp 15wf104f03rc 100k*/ #define BTSNRPA_RAP_PULL_UP_R 100000 /* 100K,pull up resister */ #define BTSNRPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp diff --git a/drivers/misc/mediatek/thermal/mt6781/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6781/inc/tzbatt_initcfg.h index 509964c86f89..eddba620acf6 100644 --- a/drivers/misc/mediatek/thermal/mt6781/inc/tzbatt_initcfg.h +++ b/drivers/misc/mediatek/thermal/mt6781/inc/tzbatt_initcfg.h @@ -9,16 +9,16 @@ #define TZBATT_SET_INIT_CFG (1) #define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) +#define TZBATT_INITCFG_NUM_TRIPS (1) -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" +#define TZBATT_INITCFG_TRIP_0_TEMP (60000) +#define TZBATT_INITCFG_TRIP_0_COOLER "mtktsbattery-sysrst" #define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" +#define TZBATT_INITCFG_TRIP_1_COOLER "" #define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" +#define TZBATT_INITCFG_TRIP_2_COOLER "" #define TZBATT_INITCFG_TRIP_3_TEMP (45000) #define TZBATT_INITCFG_TRIP_3_COOLER "" diff --git a/drivers/misc/mediatek/thermal/mt6781/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6781/inc/tzcpu_initcfg.h index f1ce9369bd91..b90b6131b1eb 100644 --- a/drivers/misc/mediatek/thermal/mt6781/inc/tzcpu_initcfg.h +++ b/drivers/misc/mediatek/thermal/mt6781/inc/tzcpu_initcfg.h @@ -9,22 +9,22 @@ #define TZCPU_SET_INIT_CFG (1) -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) +#define TZCPU_INITCFG_INTERVAL (200) +#define TZCPU_INITCFG_NUM_TRIPS (2) #define TZCPU_INITCFG_TRIP_0_TEMP (113500) #define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" +#define TZCPU_INITCFG_TRIP_1_TEMP (65000) +#define TZCPU_INITCFG_TRIP_1_COOLER "cpu_adaptive_0" -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" +#define TZCPU_INITCFG_TRIP_2_TEMP (64000) +#define TZCPU_INITCFG_TRIP_2_COOLER "" -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" +#define TZCPU_INITCFG_TRIP_3_TEMP (63000) +#define TZCPU_INITCFG_TRIP_3_COOLER "" -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) +#define TZCPU_INITCFG_TRIP_4_TEMP (62000) #define TZCPU_INITCFG_TRIP_4_COOLER "" #define TZCPU_INITCFG_TRIP_5_TEMP (60000) diff --git a/drivers/misc/mediatek/thermal/mt6873/Makefile b/drivers/misc/mediatek/thermal/mt6873/Makefile deleted file mode 100644 index 2a09370d533f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6873/inc/clatm_initcfg.h deleted file mode 100644 index 9ed13e6c295a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/clatm_initcfg.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (75000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (3960) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_1_TARGET_TJ (65000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (3000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (75000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3960) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (600) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (10) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (50) - -#define CLATM_USE_MIN_CPU_OPP (1) -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/mach/mtk_thermal.h b/drivers/misc/mediatek/thermal/mt6873/inc/mach/mtk_thermal.h deleted file mode 100644 index aee7438dcfb7..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/mach/mtk_thermal.h +++ /dev/null @@ -1,251 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#ifndef __MT6785_THERMAL_H__ -#define __MT6785_THERMAL_H__ - -#include -#include -#include -#include - -#include -#include - -#include "mt-plat/sync_write.h" - -#include "mtk_thermal_typedefs.h" - -/* TODO: remove this! */ -/*#define GPUFREQ_NOT_READY*/ - -#ifdef GPUFREQ_NOT_READY -struct mt_gpufreq_power_table_info { - unsigned int gpufreq_khz; - unsigned int gpufreq_volt; - unsigned int gpufreq_power; -}; -#else -#include "mtk_gpufreq.h" -#endif - -/*============================================================= - * LVTS SW Configs - *============================================================= - */ -#define CFG_THERM_LVTS (1) -#define CFG_THERM_NO_AUXADC (1) - -#if CFG_THERM_LVTS -#define CFG_LVTS_DOMINATOR (1) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (1) /* 1, 2, 4, 8, 16 */ -#define LVTS_DEVICE_AUTO_RCK (1) -/*Use bootup "count RC", no need to get "count RC" again after resume*/ -#define CFG_THERM_USE_BOOTUP_COUNT_RC -#else -#define CFG_LVTS_DOMINATOR (0) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (0) -#define LVTS_DEVICE_AUTO_RCK (1) -#endif - -/* - *There is no idle code in kernel since mt6885(big sw). - *Thus, kernel only can use "cpu pm notifier" to do idle scenario things. - * - *Release LVTS in thermal kernel driver - *1. SPM will pause LVTS thermal controllers before closing 26M - *2. After leaving SODI3, SPM will release LVTS thermal controllers - * if controllers were paused properly. - *3. After leaving SODI3, Thermal driver will release LVTS thermal - * controllers if SPM didn't release controller successfully - */ -#define LVTS_CPU_PM_NTFY_CALLBACK - -#if defined(LVTS_CPU_PM_NTFY_CALLBACK) -#define CFG_THERM_SODI3_RELEASE -//#define LVTS_CPU_PM_NTFY_PROFILE -#endif - -/* public thermal sensor enum */ - -enum thermal_sensor { -#if CFG_THERM_LVTS - TS_LVTS1_0 = 0, - TS_LVTS1_1, - TS_LVTS2_0, - TS_LVTS2_1, - TS_LVTS3_0, - TS_LVTS3_1, - TS_LVTS3_2, - TS_LVTS3_3, - TS_LVTS4_0, - TS_LVTS4_1, - TS_LVTS5_0, - TS_LVTS5_1, - TS_LVTS6_0, - TS_LVTS6_1, - TS_LVTS7_0, - TS_LVTS7_1, - TS_LVTS7_2, -#endif - TS_ENUM_MAX -}; - -enum thermal_bank_name { - THERMAL_BANK0 = 0, - THERMAL_BANK1, - THERMAL_BANK2, - THERMAL_BANK3, - THERMAL_BANK4, - THERMAL_BANK5, - THERMAL_BANK_NUM -}; - -struct TS_PTPOD { - unsigned int ts_MTS; - unsigned int ts_BTS; -}; - -extern int mtktscpu_limited_dmips; -extern int tscpu_get_temperature_range(void); - -/* Valid if it returns 1, invalid if it returns 0. */ -extern int tscpu_is_temp_valid(void); - -extern void get_thermal_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); - -#if CFG_THERM_LVTS -extern void get_lvts_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); -#endif - -extern void set_taklking_flag(bool flag); - -extern int tscpu_get_cpu_temp(void); - -extern int tscpu_get_temp_by_bank(enum thermal_bank_name ts_bank); - -#define THERMAL_WRAP_WR32(val, addr) \ - mt_reg_sync_writel((val), ((void *)addr)) - -extern int get_immediate_cpuL_wrap(void); -extern int get_immediate_cpuB_wrap(void); -extern int get_immediate_mcucci_wrap(void); -extern int get_immediate_gpu_wrap(void); -extern int get_immediate_vpu_wrap(void); -extern int get_immediate_top_wrap(void); -extern int get_immediate_md_wrap(void); - -/* Added for DLPT/EARA */ -extern int tscpu_get_min_cpu_pwr(void); -extern int tscpu_get_min_gpu_pwr(void); -extern int tscpu_get_min_vpu_pwr(void); -extern int tscpu_get_min_mdla_pwr(void); - -extern void lvts_ipi_send_efuse_data(void); -extern void lvts_ipi_send_sspm_thermal_thtottle(void); -extern void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend); - -/* Five thermal sensors. */ -enum mtk_thermal_sensor_cpu_id_met { -#if CFG_THERM_LVTS - MTK_THERMAL_SENSOR_LVTS1_0, - MTK_THERMAL_SENSOR_LVTS1_1, - MTK_THERMAL_SENSOR_LVTS2_0, - MTK_THERMAL_SENSOR_LVTS2_1, - MTK_THERMAL_SENSOR_LVTS3_0, - MTK_THERMAL_SENSOR_LVTS3_1, - MTK_THERMAL_SENSOR_LVTS3_2, - MTK_THERMAL_SENSOR_LVTS3_3, - MTK_THERMAL_SENSOR_LVTS4_0, - MTK_THERMAL_SENSOR_LVTS4_1, - MTK_THERMAL_SENSOR_LVTS5_0, - MTK_THERMAL_SENSOR_LVTS5_1, - MTK_THERMAL_SENSOR_LVTS6_0, - MTK_THERMAL_SENSOR_LVTS6_1, - MTK_THERMAL_SENSOR_LVTS7_0, - MTK_THERMAL_SENSOR_LVTS7_1, - MTK_THERMAL_SENSOR_LVTS7_2, -#endif - ATM_CPU_LIMIT, - ATM_GPU_LIMIT, - - MTK_THERMAL_SENSOR_CPU_COUNT -}; - -extern int tscpu_get_cpu_temp_met(enum mtk_thermal_sensor_cpu_id_met id); - -typedef void (*met_thermalsampler_funcMET)(void); - -extern void mt_thermalsampler_registerCB(met_thermalsampler_funcMET pCB); - -extern void mtkTTimer_cancel_timer(void); - -extern void mtkTTimer_start_timer(void); - -extern int mtkts_bts_get_hw_temp(void); - -extern int get_immediate_ts0_wrap(void); -extern int get_immediate_ts1_wrap(void); -extern int get_immediate_ts2_wrap(void); -extern int get_immediate_ts3_wrap(void); -extern int get_immediate_ts4_wrap(void); -extern int get_immediate_ts5_wrap(void); -extern int get_immediate_ts6_wrap(void); -extern int get_immediate_ts7_wrap(void); -extern int get_immediate_ts8_wrap(void); -extern int get_immediate_ts9_wrap(void); - -#if CFG_THERM_LVTS -extern int get_immediate_tslvts1_0_wrap(void); -extern int get_immediate_tslvts1_1_wrap(void); -extern int get_immediate_tslvts2_0_wrap(void); -extern int get_immediate_tslvts2_1_wrap(void); -extern int get_immediate_tslvts3_0_wrap(void); -extern int get_immediate_tslvts3_1_wrap(void); -extern int get_immediate_tslvts3_2_wrap(void); -extern int get_immediate_tslvts3_3_wrap(void); -extern int get_immediate_tslvts4_0_wrap(void); -extern int get_immediate_tslvts4_1_wrap(void); -extern int get_immediate_tslvts5_0_wrap(void); -extern int get_immediate_tslvts5_1_wrap(void); -extern int get_immediate_tslvts6_0_wrap(void); -extern int get_immediate_tslvts6_1_wrap(void); -extern int get_immediate_tslvts7_0_wrap(void); -extern int get_immediate_tslvts7_1_wrap(void); -extern int get_immediate_tslvts7_2_wrap(void); -#endif - -extern int get_immediate_tsabb_wrap(void); - -extern int (*get_immediate_tsX[TS_ENUM_MAX])(void); - -extern int is_cpu_power_unlimit(void); /* in mtk_ts_cpu.c */ - -extern int is_cpu_power_min(void); /* in mtk_ts_cpu.c */ - -extern int get_cpu_target_tj(void); - -extern int get_cpu_target_offset(void); - -extern int mtk_gpufreq_register( - struct mt_gpufreq_power_table_info *freqs, int num); - - -extern int get_target_tj(void); - -extern int mtk_thermal_get_tpcb_target(void); - -extern void thermal_set_big_core_speed( -unsigned int tempMonCtl1, unsigned int tempMonCtl2, unsigned int tempAhbPoll); - -/* - * return value(1): cooler of abcct/abcct_lcmoff is deactive, - * and no thermal current limit. - */ -extern int mtk_cooler_is_abcct_unlimit(void); - -extern int tscpu_kernel_status(void); -#endif /* __MT6785_THERMAL_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_cl_amddulthro.h b/drivers/misc/mediatek/thermal/mt6873/inc/mtk_cl_amddulthro.h deleted file mode 100644 index 7a7c50795c2b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_cl_amddulthro.h +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef __MT_CL_AMDDULTHRO_H__ -#define __MT_CL_AMDDULTHRO_H__ - -extern int amddulthro_backoff(int level); - -#endif /* __MT_CL_AMDDULTHRO_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6873/inc/mtk_cooler_setting.h deleted file mode 100644 index c0bc64b39b51..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - - -/*APU(mdla/vpu) throttle*/ -#define THERMAL_APU_UNLIMIT - -#if defined(THERMAL_APU_UNLIMIT) -extern unsigned int cl_get_apu_status(void); -extern void cl_set_apu_status(int vv); -#endif -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6873/inc/mtk_thermal_ipi.h deleted file mode 100644 index d60c1a8fa202..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (1) -#define THERMAL_SSPM_THERMAL_THROTTLE_SWITCH - -/*Only Big SW need to enable this definition - *Big SW suspend/resume flow: - * suspend: kernel suspend => SSPM suspend - * resume: SSPM resume => kernel resume - */ - -/* THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY means notify tinysys - * to start/stop reading temperature when kernel suspend/resume/shutdown - */ -#define THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY - -/* THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY_ONLY_AT_SHUTDOWN means - * notify tinysys to stop reading temperature only when kernel shutodown - */ -#ifdef THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY -#define THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY_ONLY_AT_SHUTDOWN -#endif - -#define THERMAL_CPUTOEB_USE_PLATFORM_IPI -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (1) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#include - -#define THERMAL_SLOT_NUM (4) -#define BIG_CORE_THRESHOLD_ARRAY_SIZE (3) -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_LVTS_INIT_GRP1, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_mcupm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6873/inc/mtk_ts_setting.h deleted file mode 100644 index 2ab0206ebe34..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/mtk_ts_setting.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (1) -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tmp_6311buck.h b/drivers/misc/mediatek/thermal/mt6873/inc/tmp_6311buck.h deleted file mode 100644 index 7921a3aca125..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tmp_6311buck.h +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef __TMP_6311BUCK_H__ -#define __TMP_6311BUCK_H__ - -extern int is_ext_buck_exist(void); - -#endif /* __TMP_6311BUCK_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tmp_battery.h b/drivers/misc/mediatek/thermal/mt6873/inc/tmp_battery.h deleted file mode 100644 index cd48343778f2..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tmp_battery.h +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef __TMP_BATTERY_H__ -#define __TMP_BATTERY_H__ - -#include -/* Extern two API functions from battery driver - * to limit max charging current. - */ -/** - * return value means charging current in mA - * -1 means error - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int get_bat_charging_current_level(void); - -/** - * current_limit means limit of charging current in mA - * -1 means no limit - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int set_bat_charging_current_limit(int current_limit); -extern enum charger_type mt_get_charger_type(void); - -extern int read_tbat_value(void); - -#endif /* __TMP_BATTERY_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6873/inc/tmp_bts.h deleted file mode 100644 index ac3493380ae1..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tmp_bts.h +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) -#define AUX_IN2_NTC (2) - -#define BTS_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - - -#define BTSNRPA_RAP_PULL_UP_R 100000 /* 100K,pull up resister */ -#define BTSNRPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - *default value -40 deg - */ - -#define BTSNRPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ -#define BTSNRPA_RAP_NTC_TABLE 7 - -#define BTSNRPA_RAP_ADC_CHANNEL AUX_IN2_NTC - - - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_lvts_config.h b/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_lvts_config.h deleted file mode 100644 index e87e09dc20d8..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_lvts_config.h +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#ifndef __TSCPU_LVTS_SETTINGS_H__ -#define __TSCPU_LVTS_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define LVTS_ADDRESS_INDEX_1 116 /* 0x11C101C0 */ -#define LVTS_ADDRESS_INDEX_2 117 /* 0x11C101C4 */ -#define LVTS_ADDRESS_INDEX_3 118 /* 0x11C101C8 */ -#define LVTS_ADDRESS_INDEX_4 119 /* 0x11C101CC */ -#define LVTS_ADDRESS_INDEX_5 190 /* 0x11C101D0 */ -#define LVTS_ADDRESS_INDEX_6 191 /* 0x11C101D4 */ -#define LVTS_ADDRESS_INDEX_7 192 /* 0x11C101D8 */ -#define LVTS_ADDRESS_INDEX_8 193 /* 0x11C101DC */ -#define LVTS_ADDRESS_INDEX_9 194 /* 0x11C101E0 */ -#define LVTS_ADDRESS_INDEX_10 195 /* 0x11C101E4 */ -#define LVTS_ADDRESS_INDEX_11 196 /* 0x11C101E8 */ -#define LVTS_ADDRESS_INDEX_12 197 /* 0x11C101EC */ -#define LVTS_ADDRESS_INDEX_13 198 /* 0x11C101F0 */ -#define LVTS_ADDRESS_INDEX_14 199 /* 0x11C101F4 */ -#define LVTS_ADDRESS_INDEX_15 200 /* 0x11C101F8 */ -#define LVTS_ADDRESS_INDEX_16 201 /* 0x11C101FC */ -#define LVTS_ADDRESS_INDEX_17 202 /* 0x11C10200 */ -#define LVTS_ADDRESS_INDEX_18 203 /* 0x11C10204 */ -#define LVTS_ADDRESS_INDEX_19 204 /* 0x11C10208 */ -#define LVTS_ADDRESS_INDEX_20 205 /* 0x11C1020C */ -#define LVTS_ADDRESS_INDEX_21 206 /* 0x11C10210 */ -#define LVTS_ADDRESS_INDEX_22 207 /* 0x11C10214 */ - - - - -/**************************************************************************** */ -/* LVTS related registers. */ -/**************************************************************************** */ -#define LVTSMONCTL0_0 (THERM_CTRL_BASE_2 + 0x000) -#define LVTSMONCTL1_0 (THERM_CTRL_BASE_2 + 0x004) -#define LVTSMONCTL2_0 (THERM_CTRL_BASE_2 + 0x008) -#define LVTSMONINT_0 (THERM_CTRL_BASE_2 + 0x00C) -#define LVTSMONINTSTS_0 (THERM_CTRL_BASE_2 + 0x010) -#define LVTSMONIDET0_0 (THERM_CTRL_BASE_2 + 0x014) -#define LVTSMONIDET1_0 (THERM_CTRL_BASE_2 + 0x018) -#define LVTSMONIDET2_0 (THERM_CTRL_BASE_2 + 0x01C) -#define LVTSMONIDET3_0 (THERM_CTRL_BASE_2 + 0x020) -#define LVTSH2NTHRE_0 (THERM_CTRL_BASE_2 + 0x024) -#define LVTSHTHRE_0 (THERM_CTRL_BASE_2 + 0x028) -#define LVTSCTHRE_0 (THERM_CTRL_BASE_2 + 0x02C) -#define LVTSOFFSETH_0 (THERM_CTRL_BASE_2 + 0x030) -#define LVTSOFFSETL_0 (THERM_CTRL_BASE_2 + 0x034) -#define LVTSMSRCTL0_0 (THERM_CTRL_BASE_2 + 0x038) -#define LVTSMSRCTL1_0 (THERM_CTRL_BASE_2 + 0x03C) -#define LVTSTSSEL_0 (THERM_CTRL_BASE_2 + 0x040) -#define LVTSDEVICETO_0 (THERM_CTRL_BASE_2 + 0x044) -#define LVTSCALSCALE_0 (THERM_CTRL_BASE_2 + 0x048) -#define LVTS_ID_0 (THERM_CTRL_BASE_2 + 0x04C) -#define LVTS_CONFIG_0 (THERM_CTRL_BASE_2 + 0x050) -#define LVTSEDATA00_0 (THERM_CTRL_BASE_2 + 0x054) -#define LVTSEDATA01_0 (THERM_CTRL_BASE_2 + 0x058) -#define LVTSEDATA02_0 (THERM_CTRL_BASE_2 + 0x05C) -#define LVTSEDATA03_0 (THERM_CTRL_BASE_2 + 0x060) -#define LVTSMSR0_0 (THERM_CTRL_BASE_2 + 0x090) -#define LVTSMSR1_0 (THERM_CTRL_BASE_2 + 0x094) -#define LVTSMSR2_0 (THERM_CTRL_BASE_2 + 0x098) -#define LVTSMSR3_0 (THERM_CTRL_BASE_2 + 0x09C) -#define LVTSIMMD0_0 (THERM_CTRL_BASE_2 + 0x0A0) -#define LVTSIMMD1_0 (THERM_CTRL_BASE_2 + 0x0A4) -#define LVTSIMMD2_0 (THERM_CTRL_BASE_2 + 0x0A8) -#define LVTSIMMD3_0 (THERM_CTRL_BASE_2 + 0x0AC) -#define LVTSRDATA0_0 (THERM_CTRL_BASE_2 + 0x0B0) -#define LVTSRDATA1_0 (THERM_CTRL_BASE_2 + 0x0B4) -#define LVTSRDATA2_0 (THERM_CTRL_BASE_2 + 0x0B8) -#define LVTSRDATA3_0 (THERM_CTRL_BASE_2 + 0x0BC) -#define LVTSPROTCTL_0 (THERM_CTRL_BASE_2 + 0x0C0) -#define LVTSPROTTA_0 (THERM_CTRL_BASE_2 + 0x0C4) -#define LVTSPROTTB_0 (THERM_CTRL_BASE_2 + 0x0C8) -#define LVTSPROTTC_0 (THERM_CTRL_BASE_2 + 0x0CC) -#define LVTSCLKEN_0 (THERM_CTRL_BASE_2 + 0x0E4) -#define LVTSDBGSEL_0 (THERM_CTRL_BASE_2 + 0x0E8) -#define LVTSDBGSIG_0 (THERM_CTRL_BASE_2 + 0x0EC) -#define LVTSSPARE0_0 (THERM_CTRL_BASE_2 + 0x0F0) -#define LVTSSPARE1_0 (THERM_CTRL_BASE_2 + 0x0F4) -#define LVTSSPARE2_0 (THERM_CTRL_BASE_2 + 0x0F8) -#define LVTSSPARE3_0 (THERM_CTRL_BASE_2 + 0x0FC) - -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) - -#endif /* __TSCPU_LVTS_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_settings.h deleted file mode 100644 index a3b7c4728578..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_settings.h +++ /dev/null @@ -1,791 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include "mach/mtk_thermal.h" - -#include -#include - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" -#include "tscpu_tsense_config.h" -#include "tscpu_lvts_config.h" - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned int)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned int) -1 >> (31 - ((1) ? _bits_))) \ - & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() \ - long long thermal_pTime_us, thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_notice(TSCPU_LOG_TAG "%s: %llu us\n", __func__, \ - thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_notice(TSCPU_LOG_TAG \ - "Warning: tProfiling uses incorrect %s %d\n", \ - __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/*Enable thermal controller CG*/ -#define THERMAL_EBABLE_TC_CG - -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. - * Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -/* Define this in tscpu_settings.h enables this feature. - * It polls CPU TS in hrtimer and - * run ATM in RT 98 kthread. This is for MT6799 only. - */ -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) -#define CLEAR_TEMP 26111 - -/* Thermal VPU throttling support */ -#ifdef CONFIG_MTK_APUSYS_VPU -#define THERMAL_VPU_SUPPORT -#endif - -/* Thermal MDLA throttling support */ -#ifdef CONFIG_MTK_APUSYS_MDLA_SUPPORT -#define THERMAL_MDLA_SUPPORT -#endif - -/* EARA_Thermal power budget allocation support */ -#define EARA_THERMAL_SUPPORT - -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_RAM_CONSOLE -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#if CFG_THERM_LVTS -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -#define CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT (1) -#define DYNAMIC_REBOOT_TRIP_TEMP (35000) -#define DYNAMIC_REBOOT_EXIT_TEMP (30000) -#else -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -#endif - -#define DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE (1) - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#define LVTS_FORCE_ERROR_TRIGGER (0) -#define LVTS_NUM_SKIP_SAMPLE (500) - -#define HISTORY_SAMPLES (10) -#define FUTURE_SAMPLES (10) -#define R_BUFFER_SIZE (HISTORY_SAMPLES + FUTURE_SAMPLES + 1) -#define LVTS_ERROR_THRESHOLD (10000) - -#define DUMP_LVTS_REGISTER (0) -#define DUMP_VCORE_VOLTAGE (0) -#endif -#define LVTS_VALID_DATA_TIME_PROFILING (0) - -#define LVTS_USE_DOMINATOR_SENSING_POINT (1) - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (1) -/*============================================================= - *REG ACCESS - *============================================================= - */ -/* double check */ -#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ - -/* turn on TS_CON1[5:4] 2'b 00 11001111 -> 0xCF ~(0x30)*/ -#define TS_TURN_ON 0xFFFFFFCF -#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | (val), \ - ((void *)addr)) - -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & ~(val), \ - ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES (8) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x84) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x90) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif - -/*============================================================= - * Common Structure and Enum - *============================================================= - */ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * LVTS Structure and Enum - *============================================================= - */ -#if CFG_THERM_LVTS - -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1,T2) LVTS1-0, LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -/* private thermal sensor enum */ -enum lvts_sensor_enum { - L_TS_LVTS1_0 = 0, /* LVTS1-0 1*/ - L_TS_LVTS1_1, /* LVTS1-1 2*/ - L_TS_LVTS2_0, /* LVTS2-0 3*/ - L_TS_LVTS2_1, /* LVTS2-1 4*/ - L_TS_LVTS3_0, /* LVTS3-0 5*/ - L_TS_LVTS3_1, /* LVTS3-1 6*/ - L_TS_LVTS3_2, /* LVTS3-2 7*/ - L_TS_LVTS3_3, /* LVTS3-3 8*/ - L_TS_LVTS4_0, /* LVTS4-0 9*/ - L_TS_LVTS4_1, /* LVTS4-1 10*/ - L_TS_LVTS5_0, /* LVTS5-0 11*/ - L_TS_LVTS5_1, /* LVTS5-1 12*/ - L_TS_LVTS6_0, /* LVTS6-0 13*/ - L_TS_LVTS6_1, /* LVTS6-1 14*/ - L_TS_LVTS7_0, /* LVTS7-0 15*/ - L_TS_LVTS7_1, /* LVTS7-1 16*/ - L_TS_LVTS7_2, /* LVTS7-2 17*/ - L_TS_LVTS_NUM -}; - -enum lvts_tc_enum { - LVTS_MCU_CONTROLLER0 = 0,/* LVTSMONCTL0 */ - LVTS_MCU_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_MCU_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_AP_CONTROLLER0, /* LVTSMONCTL0 */ - LVTS_AP_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_AP_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_AP_CONTROLLER3, /* LVTSMONCTL0_3 */ - LVTS_CONTROLLER_NUM -}; - -struct lvts_thermal_controller_speed { - unsigned int group_interval_delay; - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; -}; - -struct lvts_thermal_controller { - enum lvts_sensor_enum ts[4]; /* sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; /* hw protection ref TS (index of the ts array) */ - int tc_offset; - struct lvts_thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Tsense Structure and Enum - *============================================================= - */ -#if !defined(CFG_THERM_NO_AUXADC) -/* private thermal sensor enum */ -enum tsmcu_sensor_enum { - L_TS_MCU0 = 0, - L_TS_MCU1, - L_TS_MCU2, - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - L_TS_MCU4, - L_TS_MCU5, - L_TS_MCU6, - L_TS_MCU7, - L_TS_MCU8, - L_TS_MCU9, - L_TS_ABB, - L_TS_MCU_NUM -}; - -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, /* TEMPMONCTL0 */ - THERMAL_CONTROLLER1, /* TEMPMONCTL0_1 */ - THERMAL_CONTROLLER2, /* TEMPMONCTL0_2 */ - THERMAL_CONTROLLER_NUM -}; -#endif -struct thermal_controller_speed { - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; - unsigned int ahb_polling_interval; -}; -#if CFG_THERM_LVTS -struct thermal_controller { - enum lvts_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#else -struct thermal_controller { - enum tsmcu_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Shared variables - *============================================================= - */ -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern u32 thermal_mcu_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_curr_cpu_temp; -extern int tscpu_curr_gpu_temp; -#endif - -/* - * In src/mtk_tc.c - */ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_sspm_thermal_throttle; -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -#if !defined(CFG_THERM_NO_AUXADC) -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -#endif -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -extern int lvts_hw_protect_enabled; - -#if !defined(CFG_THERM_NO_AUXADC) -/* - * temperature array to store both tsmcu and lvts (if exist) and export them - */ -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ - -/* - * temperature array to store temp of tsmcu sensor - */ -extern int tscpu_ts_mcu_temp[L_TS_MCU_NUM]; -extern int tscpu_ts_mcu_temp_r[L_TS_MCU_NUM]; /* raw data */ -#endif - -#if CFG_THERM_LVTS -/* - * temperature array to store temp of lvts sensor - */ -extern int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -extern int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; /* raw data */ -#endif - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -extern int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#if DUMP_VCORE_VOLTAGE -extern struct regulator *vcore_reg_id; -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern unsigned long long int SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -extern int isTempValid; -extern long long int start_timestamp; -/* count if start_timestamp is bigger than end_timestamp */ -extern int diff_error_count; -#endif -/* - * support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_rawdata_debug_log; -extern int lvts_debug_log; -extern struct lvts_thermal_controller -lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM]; -#endif - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long int thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#endif - -extern char *adaptive_cooler_name; - -/* common/coolers/mtk_cooler_atm.c */ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/* common/coolers/mtk_cooler_dtm.c */ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In mtk_tc_wrapper.c */ -extern int tscpu_get_curr_max_ts_temp(void); -extern int tscpu_max_temperature(void); -extern int tscpu_get_curr_temp(void); -extern int combine_lvts_tsmcu_temp(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int get_io_reg_base(void); - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif -extern void tscpu_update_tempinfo(void); - -#if !defined(CFG_THERM_NO_AUXADC) -/*In src/mtk_tc.c*/ -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp( - int tc_num, enum tsmcu_sensor_enum type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); - -extern int tscpu_dump_cali_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); - -extern void thermal_disable_all_periodoc_temp_sensing(void); -extern void read_all_tc_tsmcu_temperature(void); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -#endif -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern void lvts_tscpu_reset_thermal(void); -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_get_io_reg_base(void); -extern int lvts_max_temperature(void); -extern void lvts_config_all_tc_hw_protect(int temperature, int temperature2); -extern void lvts_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order); -extern void lvts_read_all_tc_temperature(void); -extern void lvts_reset_and_initial(int tc_num); -extern int (*lvts_max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void lvts_thermal_lvts_device_init(void); -extern void lvts_read_temperature(void); -//extern void lvts_read_temperature(int temp0, int temp1); -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_error_info(void); -#endif -extern void lvts_thermal_cal_prepare(void); -extern void lvts_device_identification(void); -extern void lvts_reset_device_and_stop_clk(void); -extern void lvts_read_device_id_rev(void); -extern void lvts_Device_Enable_Init_all_Devices(void); -extern void lvts_device_read_count_RC_N(void); -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -extern void lvts_device_read_count_RC_N_resume(void); -#endif -extern void lvts_device_enable_auto_rck(void); -extern void lvts_efuse_setting(void); -extern void lvts_tscpu_thermal_initial_all_tc(void); -extern void lvts_pause_all_sensing_points(void); -extern void lvts_release_all_sensing_points(void); -extern void lvts_disable_all_sensing_points(void); -extern void lvts_enable_all_sensing_points(void); -extern void read_all_tc_lvts_temperature(void); -extern void lvts_wait_for_all_sensing_point_idle(void); -extern irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -extern int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v); -extern void lvts_sodi3_release_thermal_controller(void); -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -extern void lvts_enable_all_hw_protect(void); -extern void lvts_disable_all_hw_protect(void); -#endif -#endif - -/* - * In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c - * It's not our api, ask them to provide header file - */ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* - * In drivers/misc/mediatek/auxadc/mt_auxadc.c - * It's not our api, ask them to provide header file - */ -extern int IMM_IsAdcInitReady(void); - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern void dump_efuse_data(void); -extern int check_lvts_mcu_efuse(void); -extern int check_auxadc_mcu_efuse(void); -#if DUMP_LVTS_REGISTER -extern void read_controller_reg_before_active(void); -extern void read_controller_reg_when_error(void); -extern void read_device_reg_before_active(void); -extern void read_device_reg_when_error(void); -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_register_value(void); -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern void lvts_dump_time_profiling_result(struct seq_file *m); -#endif -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -extern int tscpu_check_cpu_segment(void); -#endif -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ - do { \ - if (tscpu_debug_log == 1) { \ - pr_notice(TSCPU_LOG_TAG fmt, ##args); \ - } \ - } while (0) - -#define tscpu_printk(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -#define LVTS_LOG_TAG "[Thermal/TZ/LVTS]" -#define LVTS_LOG_REG_TAG "[Thermal/TZ/LVTSREG]" - -#define lvts_reg_print(fmt, args...) pr_notice(LVTS_LOG_REG_TAG fmt, ##args) -#define lvts_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#define lvts_warn(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#if 0 -#define lvts_dbg_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#else -#define lvts_dbg_printk(fmt, args...) \ - do { \ - if (lvts_debug_log == 1) { \ - pr_notice(LVTS_LOG_TAG fmt, ##args); \ - } \ - } while (0) -#endif -#endif - -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -#if 1 -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base -#else -#include -#define AUXADC_BASE_2 AUXADC_BASE -#define THERM_CTRL_BASE_2 THERM_CTRL_BASE -#define PERICFG_BASE_2 PERICFG_BASE -#define APMIXED_BASE_2 APMIXED_BASE -#endif - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) - -#define INFRA_GLOBALCON_RST_4_SET (INFRACFG_AO_BASE_2 + 0x730) -#define INFRA_GLOBALCON_RST_4_CLR (INFRACFG_AO_BASE_2 + 0x734) -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ - -#define THERMAL_COLD_INTERRUPT_0 0x00000001 -#define THERMAL_HOT_INTERRUPT_0 0x00000002 -#define THERMAL_LOW_OFFSET_INTERRUPT_0 0x00000004 -#define THERMAL_HIGH_OFFSET_INTERRUPT_0 0x00000008 -#define THERMAL_HOT2NORMAL_INTERRUPT_0 0x00000010 -#define THERMAL_COLD_INTERRUPT_1 0x00000020 -#define THERMAL_HOT_INTERRUPT_1 0x00000040 -#define THERMAL_LOW_OFFSET_INTERRUPT_1 0x00000080 -#define THERMAL_HIGH_OFFSET_INTERRUPT_1 0x00000100 -#define THERMAL_HOT2NORMAL_INTERRUPT_1 0x00000200 -#define THERMAL_COLD_INTERRUPT_2 0x00000400 -#define THERMAL_HOT_INTERRUPT_2 0x00000800 -#define THERMAL_LOW_OFFSET_INTERRUPT_2 0x00001000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_2 0x00002000 -#define THERMAL_HOT2NORMAL_INTERRUPT_2 0x00004000 -#define THERMAL_AHB_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_DEVICE_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_IMMEDIATE_INTERRUPT_0 0x00010000 -#define THERMAL_IMMEDIATE_INTERRUPT_1 0x00020000 -#define THERMAL_IMMEDIATE_INTERRUPT_2 0x00040000 -#define THERMAL_FILTER_INTERRUPT_0 0x00080000 -#define THERMAL_FILTER_INTERRUPT_1 0x00100000 -#define THERMAL_FILTER_INTERRUPT_2 0x00200000 -#define THERMAL_COLD_INTERRUPT_3 0x00400000 -#define THERMAL_HOT_INTERRUPT_3 0x00800000 -#define THERMAL_LOW_OFFSET_INTERRUPT_3 0x01000000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_3 0x02000000 -#define THERMAL_HOT2NORMAL_INTERRUPT_3 0x04000000 -#define THERMAL_IMMEDIATE_INTERRUPT_3 0x08000000 -#define THERMAL_FILTER_INTERRUPT_3 0x10000000 -#define THERMAL_PROTECTION_STAGE_1 0x20000000 -#define THERMAL_PROTECTION_STAGE_2 0x40000000 -#define THERMAL_PROTECTION_STAGE_3 0x80000000 -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_tsense_config.h b/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_tsense_config.h deleted file mode 100644 index 0b7cb4123ab2..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tscpu_tsense_config.h +++ /dev/null @@ -1,151 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#ifndef __TSCPU_TSENSE_SETTINGS_H__ -#define __TSCPU_TSENSE_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define ADDRESS_INDEX_0 101 /* 184 */ -#define ADDRESS_INDEX_1 100 /* 180 */ -#define ADDRESS_INDEX_2 102 /* 188 */ -#define ADDRESS_INDEX_3 111 /* 1AC */ -#define ADDRESS_INDEX_4 112 /* 1B0 */ - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - -#define TSCON1_bit_0_3_0000 0x00 /*TSCON1[3:0]=4'b0000*/ -#define TSCON1_bit_0_3_0001 0x01 /*TSCON1[3:0]=4'b0001*/ -#define TSCON1_bit_0_3_0010 0x02 /*TSCON1[3:0]=4'b0010*/ -#define TSCON1_bit_0_3_0011 0x03 /*TSCON1[3:0]=4'b0011*/ -#define TSCON1_bit_0_3_0100 0x04 /*TSCON1[3:0]=4'b0100*/ -#define TSCON1_bit_0_3_0101 0x05 /*TSCON1[3:0]=4'b0101*/ -#define TSCON1_bit_0_3_0110 0x06 /*TSCON1[3:0]=4'b0110*/ -#define TSCON1_bit_0_3_0111 0x07 /*TSCON1[3:0]=4'b0111*/ -#define TSCON1_bit_0_3_1000 0x08 /*TSCON1[3:0]=4'b1000*/ -#define TSCON1_bit_0_3_1001 0x09 /*TSCON1[3:0]=4'b1001*/ -#define TSCON1_bit_0_3_1010 0x0A /*TSCON1[3:0]=4'b1010*/ -#define TSCON1_bit_0_3_1011 0x0B /*TSCON1[3:0]=4'b1011*/ -#define TSCON1_bit_0_3_1100 0x0C /*TSCON1[3:0]=4'b1100*/ -#define TSCON1_bit_0_3_1101 0x0D /*TSCON1[3:0]=4'b1101*/ -#define TSCON1_bit_0_3_1110 0x0E /*TSCON1[3:0]=4'b1110*/ -#define TSCON1_bit_0_3_1111 0x0F /*TSCON1[3:0]=4'b1111*/ -#define TSCON1_bit_0_3_MASK 0x0F - -/* ADC value to mcu */ -/*chip dependent*/ -#define TEMPADC_MCU0 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0000)) -#define TEMPADC_MCU1 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0001)) -#define TEMPADC_MCU2 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0010)) -#define TEMPADC_MCU4 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0100)) -#define TEMPADC_MCU5 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0101)) -#define TEMPADC_MCU6 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0110)) -#define TEMPADC_MCU7 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0111)) -#define TEMPADC_MCU8 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1000)) -#define TEMPADC_MCU9 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1001)) -#define TEMPADC_ABB ((0x30&TSCON1_bit_4_5_01)|(0x0F&TSCON1_bit_0_3_0000)) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x800) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x804) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x808) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x80C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x810) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x814) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x818) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x81C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x824) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x828) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x82C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x830) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x834) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x838) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x83C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x840) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x844) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x848) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x84C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x850) -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x854) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x858) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x85C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x860) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x864) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x868) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x86C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x870) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x874) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x878) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x87C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x880) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x884) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x888) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x88C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x890) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x894) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x898) -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x89C) -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x8A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x8A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x8A8) -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x8B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x8B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x8B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x8BC) -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x8C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x8C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x8C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x8CC) -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x8F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x8F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x8F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x8FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) -#endif /* __TSCPU_TSENSE_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6873/inc/tzbatt_initcfg.h deleted file mode 100644 index b4ad1852667b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6873/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6873/inc/tzcpu_initcfg.h deleted file mode 100644 index 22d229f39505..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (117000) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6873/src/Makefile b/drivers/misc/mediatek/thermal/mt6873/src/Makefile deleted file mode 100644 index 296777fd026f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(MTK_PLATFORM) -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/mcupm/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/spm/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/mt3967/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ -ccflags-y += -I$(srctree)/include/dt-bindings/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/gpufreq_v1/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ - -obj-$(CONFIG_THERMAL) += mtk_lvts_tc.o -#obj-$(CONFIG_THERMAL) += mtk_tc.o -obj-$(CONFIG_THERMAL) += mtk_tc_wrapper.o -obj-$(CONFIG_THERMAL) += mtk_thermal_ipi.o -obj-$(CONFIG_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vcore.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vproc.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vgpu.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359tsx.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359dcxo.o -#obj-$(CONFIG_THERMAL) += mtk_ti_6315.o diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_lvts_tc.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_lvts_tc.c deleted file mode 100644 index d129ce436205..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_lvts_tc.c +++ /dev/null @@ -1,2082 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include -#include - -#define __MT_MTK_LVTS_TC_C__ -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_LVTS_TC_C__ - -#include -#include "mtk_thermal_ipi.h" - - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 3; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -int tscpu_debug_log; -int tscpu_sspm_thermal_throttle; -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif -/*============================================================= - * Local variable definition - *============================================================= - */ -/* chip dependent */ -/* - * TO-DO: I assume AHB bus frequecy is 78MHz. - * Please confirm it. - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T4,T5) LVTS1-0, LVTS1-1 - * MCU_BIG(T6,T7) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T0,T1,T2,T3) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T16,T19) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -struct lvts_thermal_controller lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM] = { - [0] = {/*(MCU)*/ - .ts = {L_TS_LVTS1_0, L_TS_LVTS1_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x26D000, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [1] = {/*(MCU)*/ - .ts = {L_TS_LVTS2_0, L_TS_LVTS2_1}, - .ts_number = 2, - .dominator_ts_idx = 0, - .tc_offset = 0x26D100, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [2] = {/*(MCU)*/ - .ts = {L_TS_LVTS3_0, L_TS_LVTS3_1, L_TS_LVTS3_2, L_TS_LVTS3_3}, - .ts_number = 4, - .dominator_ts_idx = 0, - .tc_offset = 0x26D200, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [3] = {/*(AP)*/ - .ts = {L_TS_LVTS4_0, L_TS_LVTS4_1}, - .ts_number = 2, - .dominator_ts_idx = 0, - .tc_offset = 0x0, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [4] = {/*(AP)*/ - .ts = {L_TS_LVTS5_0, L_TS_LVTS5_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x100, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [5] = {/*(AP)*/ - .ts = {L_TS_LVTS6_0, L_TS_LVTS6_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x200, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [6] = {/*(AP)*/ - .ts = {L_TS_LVTS7_0, L_TS_LVTS7_1, L_TS_LVTS7_2}, - .ts_number = 3, - .dominator_ts_idx = 2, - .tc_offset = 0x300, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - } -}; - -static unsigned int g_golden_temp; -static unsigned int g_count_r[L_TS_LVTS_NUM]; -static unsigned int g_count_rc[L_TS_LVTS_NUM]; -static unsigned int g_count_rc_now[L_TS_LVTS_NUM]; -static int g_use_fake_efuse; -int lvts_debug_log; -int lvts_rawdata_debug_log; - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -static int hw_protect_setting_done; -int lvts_hw_protect_enabled; -#endif - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -#define NUM_LVTS_DEVICE_REG (5) -static const unsigned int g_lvts_device_addrs[NUM_LVTS_DEVICE_REG] = { - 0x00, - 0x04, - 0x08, - 0x0C, - 0xF0}; - -static unsigned int g_lvts_device_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; -static unsigned int g_lvts_device_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; - -#define NUM_LVTS_CONTROLLER_REG (17) -static const unsigned int g_lvts_controller_addrs[NUM_LVTS_CONTROLLER_REG] = { - 0x00,//LVTSMONCTL0_0 - 0x04,//LVTSMONCTL1_0 - 0x08,//LVTSMONCTL2_0 - 0x38,//LVTSMSRCTL0_0 - 0x40,//LVTSTSSEL_0 - 0x4C,//LVTS_ID_0 - 0x50,//LVTS_CONFIG_0 - 0x90,//LVTSMSR0_0 - 0x94,//LVTSMSR1_0 - 0x98,//LVTSMSR2_0 - 0x9C,//LVTSMSR3_0 - 0xB0,//LVTSRDATA0_0 - 0xB4,//LVTSRDATA1_0 - 0xB8,//LVTSRDATA2_0 - 0xBC,//LVTSRDATA3_0 - 0xE8,//LVTSDBGSEL_0 - 0xE4};//LVTSCLKEN_0 -static unsigned int g_lvts_controller_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -static unsigned int g_lvts_controller_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -#endif - -#if LVTS_VALID_DATA_TIME_PROFILING -unsigned long long int SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -int isTempValid; -/* latency_array - * {a, b} - * a: a time threshold in milliseconds. if it is -1, it means others. - * b: the number of valid temperature latencies from a phone enters SODI3 to - * to a phone gets a valid temperature of any sensor. - * It is possible a phone enters SODI3 several times without a valid - * temperature data. - */ -#define NUM_TIME_TH (16) /* TODO: know what it is */ -static unsigned int latency_array[NUM_TIME_TH][2] = { - {100, 0}, - {200, 0}, - {300, 0}, - {400, 0}, - {500, 0}, - {600, 0}, - {700, 0}, - {800, 0}, - {900, 0}, - {1000, 0}, - {2000, 0}, - {3000, 0}, - {4000, 0}, - {5000, 0}, - {10000, 0}, - {-1, 0} -}; -long long int start_timestamp; -static long long int end_timestamp, time_diff; -/* count if start_timestamp is bigger than end_timestamp */ -int diff_error_count; -#endif - -#if CFG_THERM_LVTS -#define DEFAULT_EFUSE_GOLDEN_TEMP (50) -#define DEFAULT_EFUSE_COUNT (35000) -#define DEFAULT_EFUSE_COUNT_RC (2750) -#define FAKE_EFUSE_VALUE 0x2B048500 -#define LVTS_COEFF_A_X_1000 (-250460) -#define LVTS_COEFF_B_X_1000 (250460) -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static unsigned int lvts_temp_to_raw(int ret, enum lvts_sensor_enum ts_name); - -static void lvts_set_tc_trigger_hw_protect( - int temperature, int temperature2, int tc_num); -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -void mt_reg_sync_writel_print(unsigned int val, void *addr) -{ - if (lvts_debug_log) - lvts_dbg_printk("### LVTS_REG: addr 0x%p, val 0x%x\n", - addr, val); - - mt_reg_sync_writel(val, addr); -} - -/*=============================================================*/ - -static int lvts_write_device(unsigned int config, unsigned int dev_reg_idx, -unsigned int data, int tc_num) -{ - int offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - dev_reg_idx &= 0xFF; - data &= 0xFF; - - config = config | (dev_reg_idx << 8) | data; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* - * LVTS Device Register Setting take 1us(by 26MHz clock source) - * interface latency to access. - * So we set 2~3us delay could guarantee access complete. - */ - udelay(3); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - - return 1; -} - -static unsigned int lvts_read_device(unsigned int config, -unsigned int dev_reg_idx, int tc_num) -{ - int offset, cnt; - unsigned int data = 0; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - dev_reg_idx &= 0xFF; - - config = config | (dev_reg_idx << 8) | 0x00; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - data = (readl(LVTSRDATA0_0 + offset)); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - - return data; -} -int lvts_raw_to_temp(unsigned int msr_raw, enum lvts_sensor_enum ts_name) -{ - /* This function returns degree mC - * temp[i] = a * MSR_RAW/16384 + GOLDEN_TEMP/2 + b - * a = -250.46 - * b = 250.46 - */ - int temp_mC = 0; - int temp1 = 0; - - temp1 = (LVTS_COEFF_A_X_1000 * ((unsigned long long int)msr_raw)) >> 14; - - temp_mC = temp1 + g_golden_temp * 500 + LVTS_COEFF_B_X_1000; - - return temp_mC; -} -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -static void read_controller_reg_before_active(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_b[i][j] = temp; - } - } - -} - -static void read_controller_reg_when_error(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_e[i][j] = temp; - } - } -} - -static void read_device_reg_before_active(void) -{ - int i, j; - unsigned int addr, data; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - data = lvts_read_device(0x81020000, addr, i); - g_lvts_device_value_b[i][j] = data; - } - } -} - -static void read_device_reg_when_error(void) -{ - int i, j, offset, cnt; - unsigned int addr; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - lvts_write_device(0x81020000, addr, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - g_lvts_device_value_e[i][j] = (readl(LVTSRDATA0_0 - + offset)); - } - } -} - -void clear_lvts_register_value_array(void) -{ - int i, j; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - g_lvts_controller_value_b[i][j] = 0; - g_lvts_controller_value_e[i][j] = 0; - } - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - g_lvts_device_value_b[i][j] = 0; - g_lvts_device_value_e[i][j] = 0; - } - } -} -static void dump_lvts_register_value(void) -{ - int i, j, offset, tc_offset; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][BEFROE][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][BEFORE][TC][DUMP] "); - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) - offset += snprintf(buffer + offset, - sizeof(buffer) - offset, "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_b[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][BEFORE][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) - offset += snprintf(buffer + offset, - sizeof(buffer) - offset, "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_b[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][AFTER][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][AFTER][TC][DUMP] "); - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) - offset += snprintf(buffer + offset, - sizeof(buffer) - offset, "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_e[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][AFTER][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) - offset += snprintf(buffer + offset, - sizeof(buffer) - offset, "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_e[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - } -} - -void dump_lvts_error_info(void) -{ - read_controller_reg_when_error(); - - lvts_disable_all_sensing_points(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -} - -#endif - -static void lvts_device_check_counting_status(int tc_num) -{ - /* Check this when LVTS device is counting for - * a temperature or a RC now - */ - - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; //tc offset - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(25))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_SENSING_STATUS didn't ready\n"); - break; - } - udelay(2); - } - } -} - -#if 0 -static void lvts_device_check_read_write_status(int tc_num) -{ - /* Check this when LVTS device is doing a register - * read or write operation - */ - - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - -} -#endif - -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -void lvts_device_read_count_RC_N_resume(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0x81030000, 0x0D, j, i); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0x78, i); - - /* Wait 8us for device settle + 2us buffer*/ - udelay(10); - /* Kick-off RCK counting */ - lvts_write_device(0x81030000, 0x03, 0x02, i); - /* wait 20us + 10us buffer */ - udelay(30); - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0x81020000, 0x00, i); - - /* Get RCK value from LSB[23:0] */ - g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - } - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0x81030000, 0x0D, 0x10, i); - } - - offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += snprintf(buffer + offset, sizeof(buffer) - offset, - "%d:%d ", i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} -#endif - -void lvts_device_read_count_RC_N(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0x81030000, 0x0D, j, i); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0x78, i); - - /* Wait 8us for device settle + 2us buffer*/ - udelay(10); - /* Kick-off RCK counting */ - lvts_write_device(0x81030000, 0x03, 0x02, i); - /* wait 20us + 10us buffer */ - udelay(30); - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0x81020000, 0x00, i); - - /* Get RCK value from LSB[23:0] */ - g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - } - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0x81030000, 0x0D, 0x10, i); - } - - offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += snprintf(buffer + offset, sizeof(buffer) - offset, - "%d:%d ", i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} - -void lvts_device_enable_auto_rck(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Set LVTS AUTO-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x01, i); - } -} - -void lvts_efuse_setting(void) -{ - __u32 offset; - int i, j, s_index; - int efuse_data; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - s_index = lvts_tscpu_g_tc[i].ts[j]; - -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse_data = - (((unsigned long long int)g_count_rc_now[s_index]) * - g_count_r[s_index]) >> 14; -#else - efuse_data = g_count_r[s_index]; -#endif - - switch (j) { - case 0: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA00_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA00_%d 0x%x\n", - i, readl(LVTSEDATA00_0 + offset)); - break; - - case 1: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA01_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA01_%d 0x%x\n", - i, readl(LVTSEDATA01_0 + offset)); - break; - case 2: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA02_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA02_%d 0x%x\n", - i, readl(LVTSEDATA02_0 + offset)); - break; - case 3: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA03_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA03_%d 0x%x\n", - i, readl(LVTSEDATA03_0 + offset)); - break; - default: - lvts_dbg_printk("%s, illegal ts order : %d!!\n", - __func__, j); - } - } - } - -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -void dump_efuse_data(void) -{ - int i, efuse, offset; - char buffer[512]; - - lvts_printk("[LVTS_ERROR][GOLDEN_TEMP][DUMP] %d\n", g_golden_temp); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_R][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_r[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_rc[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC_NOW][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", - i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][LVTSEDATA][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse = g_count_rc_now[i] * g_count_r[i]; -#else - efuse = g_count_r[i]; -#endif - offset += sprintf(buffer + offset, "%d:%d ", i, efuse); - } - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); -} - -int check_lvts_mcu_efuse(void) -{ - return (g_use_fake_efuse)?(0):(1); -} -#endif - -void lvts_device_identification(void) -{ - int tc_num, data, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Enable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000001, LVTSCLKEN_0 + offset); - - /* Reset All Devices */ - lvts_write_device(0x81030000, 0xFF, 0xFF, tc_num); - /* udelay(100); */ - - /* Read back Dev_ID with Update */ - lvts_write_device(0x85020000, 0xFC, 0x55, tc_num); - - /* Check LVTS device ID */ - data = (readl(LVTS_ID_0 + offset) & _BITMASK_(7:0)); - if (data != (0x81 + tc_num)) - lvts_printk("LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", - tc_num, (0x81 + tc_num), data); - } -} - -void lvts_reset_device_and_stop_clk(void) -{ - __u32 offset; - int tc_num; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Reset All Devices */ - lvts_write_device(0x81030000, 0xFF, 0xFF, tc_num); - - /* Disable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000000, LVTSCLKEN_0 + offset); - } -} - -void lvts_Device_Enable_Init_all_Devices(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Stop Counting (RG_TSFM_ST=0) */ - lvts_write_device(0x81030000, 0x03, 0x00, i); - /* RG_TSFM_LPDLY[1:0]=2' 10 */ - lvts_write_device(0x81030000, 0x07, 0xA6, i); - /* Set LVTS device counting window 20us */ - lvts_write_device(0x81030000, 0x05, 0x00, i); - lvts_write_device(0x81030000, 0x04, 0x20, i); - /* TSV2F_CHOP_CKSEL & TSV2F_EN */ - lvts_write_device(0x81030000, 0x0A, 0x84, i); - /* TSBG_DEM_CKSEL * TSBG_CHOP_EN */ - lvts_write_device(0x81030000, 0x0C, 0x7C, i); - /* Set TS_RSV */ - lvts_write_device(0x81030000, 0x09, 0x8D, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF4, i); - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF4, i); - } -} - -void lvts_thermal_cal_prepare(void) -{ - unsigned int temp[22]; - int i, offset; - char buffer[512]; - - temp[0] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_1); - temp[1] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_2); - temp[2] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_3); - temp[3] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_4); - temp[4] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_5); - temp[5] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_6); - temp[6] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_7); - temp[7] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_8); - temp[8] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_9); - temp[9] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_10); - temp[10] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_11); - temp[11] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_12); - temp[12] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_13); - temp[13] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_14); - temp[14] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_15); - temp[15] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_16); - temp[16] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_17); - temp[17] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_18); - temp[18] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_19); - temp[19] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_20); - temp[20] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_21); - temp[21] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_22); - - - for (i = 0; (i + 5) < 22; i = i + 5) - lvts_printk("[lvts_call] %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x\n", - i, temp[i], i + 1, temp[i + 1], i + 2, temp[i + 2], - i + 3, temp[i + 3], i + 4, temp[i + 4]); - - lvts_printk("[lvts_call] 20: 0x%x, 21: 0x%x\n", temp[20], temp[21]); - - - g_golden_temp = ((temp[0] & _BITMASK_(31:24)) >> 24); - g_count_r[0] = (temp[1] & _BITMASK_(23:0)); - g_count_r[1] = (temp[2] & _BITMASK_(23:0)); - g_count_r[2] = (temp[3] & _BITMASK_(23:0)); - g_count_r[3] = (temp[4] & _BITMASK_(23:0)); - g_count_r[4] = (temp[5] & _BITMASK_(23:0)); - g_count_r[5] = (temp[6] & _BITMASK_(23:0)); - g_count_r[6] = (temp[7] & _BITMASK_(23:0)); - g_count_r[7] = (temp[8] & _BITMASK_(23:0)); - g_count_r[8] = (temp[9] & _BITMASK_(23:0)); - g_count_r[9] = (temp[10] & _BITMASK_(23:0)); - g_count_r[10] = (temp[11] & _BITMASK_(23:0)); - g_count_r[11] = (temp[12] & _BITMASK_(23:0)); - g_count_r[12] = (temp[13] & _BITMASK_(23:0)); - g_count_r[13] = (temp[14] & _BITMASK_(23:0)); - g_count_r[14] = (temp[15] & _BITMASK_(23:0)); - g_count_r[15] = (temp[16] & _BITMASK_(23:0)); - g_count_r[16] = (temp[17] & _BITMASK_(23:0)); - - g_count_rc[0] = (temp[21] & _BITMASK_(23:0)); - - g_count_rc[1] = ((temp[1] & _BITMASK_(31:24)) >> 8) + - ((temp[2] & _BITMASK_(31:24)) >> 16)+ - ((temp[3] & _BITMASK_(31:24)) >> 24); - - g_count_rc[2] = ((temp[4] & _BITMASK_(31:24)) >> 8) + - ((temp[5] & _BITMASK_(31:24)) >> 16) + - ((temp[6] & _BITMASK_(31:24)) >> 24); - - g_count_rc[3] = ((temp[7] & _BITMASK_(31:24)) >> 8) + - ((temp[8] & _BITMASK_(31:24)) >> 16) + - ((temp[9] & _BITMASK_(31:24)) >> 24); - - g_count_rc[4] = ((temp[10] & _BITMASK_(31:24)) >> 8) + - ((temp[11] & _BITMASK_(31:24)) >> 16) + - ((temp[12] & _BITMASK_(31:24)) >> 24); - - g_count_rc[5] = ((temp[13] & _BITMASK_(31:24)) >> 8) + - ((temp[14] & _BITMASK_(31:24)) >> 16) + - ((temp[15] & _BITMASK_(31:24)) >> 24); - - g_count_rc[6] = ((temp[16] & _BITMASK_(31:24)) >> 8) + - ((temp[17] & _BITMASK_(31:24)) >> 16) + - ((temp[18] & _BITMASK_(31:24)) >> 24); - - - for (i = 0; i < L_TS_LVTS_NUM; i++) { - if (i == 0) { - if ((temp[0] & _BITMASK_(7:0)) != 0) - break; - } else { - if (temp[i] != 0) - break; - } - } - - if (i == L_TS_LVTS_NUM) { - /* It means all efuse data are equal to 0 */ - lvts_printk( - "[lvts_cal] This sample is not calibrated, fake !!\n"); - - g_golden_temp = DEFAULT_EFUSE_GOLDEN_TEMP; - for (i = 0; i < L_TS_LVTS_NUM; i++) { - g_count_r[i] = DEFAULT_EFUSE_COUNT; - g_count_rc[i] = DEFAULT_EFUSE_COUNT_RC; - } - - g_use_fake_efuse = 1; - } - - lvts_printk("[lvts_cal] g_golden_temp = %d\n", g_golden_temp); - - offset = snprintf(buffer, sizeof(buffer), - "[lvts_cal] num:g_count_r:g_count_rc "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += snprintf(buffer + offset, sizeof(buffer) - offset, - "%d:%d:%d ", i, g_count_r[i], g_count_rc[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); -} - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -void lvts_ipi_send_efuse_data(void) -{ - struct thermal_ipi_data thermal_data; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = g_golden_temp; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_mcupm(THERMAL_IPI_LVTS_INIT_GRP1, &thermal_data) != 0) - udelay(100); -} -#endif - - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#if defined(THERMAL_SSPM_THERMAL_THROTTLE_SWITCH) -void lvts_ipi_send_sspm_thermal_thtottle(void) -{ - struct thermal_ipi_data thermal_data; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = tscpu_sspm_thermal_throttle; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_mcupm(THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - &thermal_data) != 0) - udelay(100); -} -#endif - -#if defined(THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY) -void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend) -{ - struct thermal_ipi_data thermal_data; - - //lvts_printk("%s, is_suspend %d\n", __func__, is_suspend); - - thermal_data.u.data.arg[0] = is_suspend; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_mcupm(THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - &thermal_data) != 0) - udelay(100); -} -#endif -#endif - -static unsigned int lvts_temp_to_raw(int temp, enum lvts_sensor_enum ts_name) -{ - /* MSR_RAW = ((temp[i] - GOLDEN_TEMP/2 - b) * 16384) / a - * a = -250.46 - * b = 250.46 - */ - unsigned int msr_raw = 0; - - msr_raw = ((long long int)(((long long int)g_golden_temp * 500 + - LVTS_COEFF_B_X_1000 - temp)) << 14)/(-1 * LVTS_COEFF_A_X_1000); - - lvts_dbg_printk("%s msr_raw = 0x%x,temp=%d\n", __func__, msr_raw, temp); - - return msr_raw; -} - -static void lvts_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + LVTSMONINTSTS_0); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + LVTSMONINTSTS_0); - - lvts_printk("[Thermal IRQ] LVTS thermal controller %d, LVTSMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_COLD_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_DEVICE_TIMEOUT_INTERRUPT) - lvts_dbg_printk("[Thermal IRQ]: Device access timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: High offset triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 1 interrupt triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 2 interrupt triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) - lvts_printk("[Thermal IRQ]: Thermal protection stage 3 interrupt triggered, Thermal HW reboot\n"); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - ret = ret & 0x7F; - /* MSB LSB NAME - * 6 6 LVTSINT3 - * 5 5 LVTSINT2 - * 4 4 LVTSINT1 - * 3 3 LVTSINT0 - * 2 2 THERMINT2 - * 1 1 THERMINT1 - * 0 0 THERMINT0 - */ - - lvts_printk("%s : THERMINTST = 0x%x\n", __func__, ret); - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - lvts_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void lvts_configure_polling_speed_and_filter(int tc_num) -{ - __u32 offset, lvtsMonCtl1, lvtsMonCtl2; - - lvts_dbg_printk("%s\n", __func__); - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvtsMonCtl1 = - (((lvts_tscpu_g_tc[tc_num].tc_speed.group_interval_delay - << 20) & _BITMASK_(29:20)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0))); - lvtsMonCtl2 = - (((lvts_tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay - & _BITMASK_(9:0))); - /* - * Calculating period unit in Module clock x 256, and the - * Module clock will be changed to 26M when Infrasys - * enters Sleep mode. - */ - - /* - * bus clock 66M counting unit is - * 12 * 1/66M * 256 = 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel_print(lvtsMonCtl1, offset + LVTSMONCTL1_0); - /* - *filt interval is 1 * 46.545us = 46.545us, - *sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel_print(lvtsMonCtl2, offset + LVTSMONCTL2_0); - - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel_print(0x00000492, offset + LVTSMSRCTL0_0); - - udelay(1); - lvts_dbg_printk( - "%s %d, LVTSMONCTL1_0= 0x%x,LVTSMONCTL2_0= 0x%x,LVTSMSRCTL0_0= 0x%x\n", - __func__, tc_num, - readl(LVTSMONCTL1_0 + offset), - readl(LVTSMONCTL2_0 + offset), - readl(LVTSMSRCTL0_0 + offset)); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -/* - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void lvts_set_tc_trigger_hw_protect( -int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, config, offset; -#if LVTS_USE_DOMINATOR_SENSING_POINT - int d_index; - enum lvts_sensor_enum ts_name; -#endif - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvts_dbg_printk("%s t1=%d t2=%d\n", - __func__, temperature, temperature2); - -#if LVTS_USE_DOMINATOR_SENSING_POINT - if (lvts_tscpu_g_tc[tc_num].dominator_ts_idx < - lvts_tscpu_g_tc[tc_num].ts_number){ - d_index = lvts_tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - lvts_printk( - "Error: LVTS TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - lvts_tscpu_g_tc[tc_num].dominator_ts_idx, - lvts_tscpu_g_tc[tc_num].ts_number); - - lvts_printk("Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - ts_name = lvts_tscpu_g_tc[tc_num].ts[d_index]; - - lvts_dbg_printk("%s # in tc%d , the dominator ts_name is %d\n", - __func__, tc_num, ts_name); - - /* temperature to trigger SPM state2 */ - raw_high = lvts_temp_to_raw(temperature, ts_name); -#else - raw_high = lvts_temp_to_raw(temperature, 0); -#endif - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - temp = readl(offset + LVTSMONINT_0); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print(temp & 0x00000000, - offset + LVTSMONINT_0); -#endif - - temp = readl(offset + LVTSPROTCTL_0) & ~(0xF << 16); -#if LVTS_USE_DOMINATOR_SENSING_POINT - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel_print(temp | config, - offset + LVTSPROTCTL_0); -#else - /* Maximum of 4 sensing points */ - config = (0x1 << 16); - mt_reg_sync_writel_print(temp | config, - offset + LVTSPROTCTL_0); -#endif - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel_print(raw_high, offset + LVTSPROTTC_0); - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print(temp | 0x80000000, - offset + LVTSMONINT_0); -#endif - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -static void dump_lvts_device(int tc_num, __u32 offset) -{ - lvts_printk("%s, LVTS_CONFIG_%d= 0x%x\n", __func__, - tc_num, readl(LVTS_CONFIG_0 + offset)); - udelay(2); - - //read raw data - lvts_printk("%s, LVTSRDATA0_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA0_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA1_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA1_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA2_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA2_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA3_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA3_0 + offset)); -} - -#if LVTS_VALID_DATA_TIME_PROFILING -void lvts_dump_time_profiling_result(struct seq_file *m) -{ - int i, sum; - - seq_printf(m, "SODI3_count= %llu\n", SODI3_count); - seq_printf(m, "noValid_count %llu, %d%%\n", - noValid_count, ((noValid_count * 100) / SODI3_count)); - seq_printf(m, "valid_count %llu, %d%%\n", - (SODI3_count - noValid_count), - (((SODI3_count - noValid_count) * 100) / SODI3_count)); - - sum = 0; - for (i = 0; i < NUM_TIME_TH; i++) - sum += latency_array[i][1]; - - seq_printf(m, "Valid count in latency_array = %d\n", sum); - - for (i = 0; i < NUM_TIME_TH; i++) { - if (i == 0) { - seq_printf(m, "Count valid latency between 0ms ~ %dms: %d, %d%%\n", - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else if (i == (NUM_TIME_TH - 1)) { - seq_printf(m, "Count valid others: %d, %d%%\n", - latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else { - seq_printf(m, "Count valid latency between %dms ~ %dms: %d, %d%%\n", - latency_array[i - 1][0], - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } - } - - /* count if start_timestamp is bigger than end_timestamp */ - seq_printf(m, "diff_error_count= %d\n", diff_error_count); - seq_printf(m, "Current start_timestamp= %lldus\n", start_timestamp); - seq_printf(m, "Current end_timestamp= %lldus\n", end_timestamp); - seq_printf(m, "Current time_diff= %lldus\n", time_diff); -} - -static void lvts_count_valid_temp_latency(long long int time_diff) -{ - /* time_diff is in microseconds */ - int i; - - for (i = 0; i < (NUM_TIME_TH - 1); i++) { - if (time_diff < (((long long int)latency_array[i][0]) - * 1000)) { - latency_array[i][1]++; - break; - } - } - - if (i == (NUM_TIME_TH - 1)) - latency_array[i][1]++; -} -#endif - - -static int lvts_read_tc_raw_and_temp( - u32 *tempmsr_name, enum lvts_sensor_enum ts_name) -{ - int temp = 0, raw = 0, raw1 = 0, raw2 = 0; - - if (thermal_base == 0) - return 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl((tempmsr_name)); - raw1 = (raw & 0x10000) >> 16; //bit 16 : valid bit - raw2 = raw & 0xFFFF; - temp = lvts_raw_to_temp(raw2, ts_name); - - if (raw2 == 0) { - /* 26111 is magic num - * this is to keep system alive for a while - * to wait HW init done, - * because 0 msr raw will translates to 28x'C - * and then 28x'C will trigger a SW reset. - * - * if HW init finish, this msr raw will not be 0, - * system can report normal temperature. - * if wait over 60 times zero, this means something - * wrong with HW, must trigger BUG on and dump useful - * register for debug. - */ - - temp = 26111; - } - - - if (lvts_rawdata_debug_log) { - lvts_printk( - "[LVTS_MSR] ts%d msr_all=%x, valid=%d, msr_temp=%d, temp=%d\n", - ts_name, raw, raw1, raw2, temp); - } - - tscpu_ts_lvts_temp_r[ts_name] = raw2; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_lvts_temp_v[ts_name] = raw1; -#endif -#if LVTS_VALID_DATA_TIME_PROFILING - if (isTempValid == 0 && raw1 != 0 && SODI3_count != 0) { - isTempValid = 1; - end_timestamp = thermal_get_current_time_us(); - time_diff = end_timestamp - start_timestamp; - if (time_diff < 0) { - lvts_printk("[LVTS_ERROR] time_diff = %lldus,start_time= %lldus, end_time= %lldus\n", - time_diff, start_timestamp, end_timestamp); - diff_error_count++; - } else { - lvts_count_valid_temp_latency(time_diff); - } - } -#endif - - return temp; -} - -static void lvts_tscpu_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order) -{ - __u32 offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - if (lvts_rawdata_debug_log) - dump_lvts_device(tc_num, offset); - - switch (order) { - case 0: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 1: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR1_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 2: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR2_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 3: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR3_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - default: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -void read_all_tc_lvts_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) - lvts_tscpu_thermal_read_tc_temp(i, - lvts_tscpu_g_tc[i].ts[j], j); -} - -/* pause ALL periodoc temperature sensing point */ -void lvts_pause_all_sensing_points(void) -{ - int i, temp, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel_print((temp | 0x10E), - offset + LVTSMSRCTL1_0); - } -} - -/* - * lvts_thermal_check_all_sensing_point_idle - - * Check if all sensing points are idle - * Return: 0 if all sensing points are idle - * an error code if one of them is busy - * error code[31:16]: an index of LVTS thermal controller - * error code[2]: bit 10 of LVTSMSRCTL1 - * error code[1]: bit 7 of LVTSMSRCTL1 - * error code[0]: bit 0 of LVTSMSRCTL1 - */ -static int lvts_thermal_check_all_sensing_point_idle(void) -{ - int i, temp, offset, error_code; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* Check if bit10=bit7=bit0=0 */ - if ((temp & 0x481) != 0) { - error_code = (i << 16) + ((temp & _BIT_(10)) >> 8) + - ((temp & _BIT_(7)) >> 6) + - (temp & _BIT_(0)); - - return error_code; - } - } - - return 0; -} - -void lvts_wait_for_all_sensing_point_idle(void) -{ - int cnt, temp; - - cnt = 0; - /* - * Wait until all sensoring points idled. - * No need to check LVTS status when suspend/resume, - * this will spend extra 100us of suspend flow. - * LVTS status will be reset after resume. - */ - while (cnt < 50 && (tscpu_kernel_status() == 0)) { - temp = lvts_thermal_check_all_sensing_point_idle(); - if (temp == 0) - break; - - if ((cnt + 1) % 50 == 0) { - pr_notice("Cnt= %d LVTS TC %d, LVTSMSRCTL1[10,7,0] = %d,%d,%d, LVTSMSRCTL1[10:0] = 0x%x\n", - cnt + 1, (temp >> 16), - ((temp & _BIT_(2)) >> 2), - ((temp & _BIT_(1)) >> 1), - (temp & _BIT_(0)), - (temp & _BITMASK_(10:0))); - } - - udelay(2); - cnt++; - } -} -/* release ALL periodoc temperature sensing point */ -void lvts_release_all_sensing_points(void) -{ - int i = 0, temp; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(((temp & (~0x10E))), - offset + LVTSMSRCTL1_0); - } -} - -void lvts_sodi3_release_thermal_controller(void) -{ - /* SPM will close 26M to saving power during SODI3 - * Because both auxadc thermal controllers and lvts thermal controllers - * need 26M to work properly, it would cause thermal controllers to - * report an abnormal high or low temperature after leaving SODI3 - * - * The SW workaround solution is that - * SPM will pause LVTS thermal controllers before closing 26M, and - * try to release LVTS thermal controllers after leaving SODI3 - * thermal driver check and release LVTS thermal controllers if - * necessary after leaving SODI3 - */ - int i = 0, temp, lvts_paused = 0; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - /*don't need to do release LVTS when suspend/resume*/ - if (tscpu_kernel_status() == 0) { - - /* Check if SPM paused thermal controller */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause - *sensing point 0,1,2,3 - */ - if ((temp & 0x10E) != 0) { - lvts_paused = 1; - pr_notice_ratelimited( - "lvts_paused = %d\n", lvts_paused); - break; - } - } - - /* Return if SPM didn't pause thermal controller or - * released thermal controllers already - */ - if (lvts_paused == 0) - return; - /* Wait until all of LVTS thermal controllers are idle - * Pause operation has to take time to finish. - * if it didn't finish before SPM closed 26M, we have to wait - * until it is finished to make sure all LVTS thermal - * controllers in a correct finite state machine - */ - - lvts_wait_for_all_sensing_point_idle(); - - lvts_release_all_sensing_points(); - } -} - -/* - * disable ALL periodoc temperature sensing point - */ -void lvts_disable_all_sensing_points(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel_print(0x00000000, offset + LVTSMONCTL0_0); - } -} - -void lvts_enable_all_sensing_points(void) -{ - int i, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - - lvts_dbg_printk("%s %d:%d\n", __func__, i, - lvts_tscpu_g_tc[i].ts_number); - - switch (lvts_tscpu_g_tc[i].ts_number) { - case 1: - /* enable sensing point 0 */ - mt_reg_sync_writel_print(0x00000201, - offset + LVTSMONCTL0_0); - break; - case 2: - /* enable sensing point 0,1 */ - mt_reg_sync_writel_print(0x00000203, - offset + LVTSMONCTL0_0); - break; - case 3: - /* enable sensing point 0,1,2 */ - mt_reg_sync_writel_print(0x00000207, - offset + LVTSMONCTL0_0); - break; - case 4: - /* enable sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(0x0000020F, - offset + LVTSMONCTL0_0); - break; - default: - lvts_printk("Error at %s\n", __func__); - break; - } - } -} - -void lvts_tscpu_thermal_initial_all_tc(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - /* set sensor index of LVTS */ - mt_reg_sync_writel_print(0x13121110, LVTSTSSEL_0 + offset); - /* set calculation scale rules */ - mt_reg_sync_writel_print(0x00000300, LVTSCALSCALE_0 + offset); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0xB8, i); - - lvts_configure_polling_speed_and_filter(i); - } - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_controller_reg_before_active(); -#endif -} - -static void lvts_disable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_DIS, WD_REQ_RST_MODE); - - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -static void lvts_enable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_EN, WD_REQ_RST_MODE); - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void lvts_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - - lvts_dbg_printk("%s, temperature=%d,temperature2=%d,\n", - __func__, temperature, temperature2); - - /*spend 860~1463 us */ - /*Thermal need to config to direct reset mode - *this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - lvts_set_tc_trigger_hw_protect(temperature, temperature2, i); - } - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_enable_rgu_reset(); -#else - hw_protect_setting_done = 1; -#endif -} - -void lvts_tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - int temp2 = 0; - - lvts_dbg_printk("%s\n", __func__); - - /* reset AP thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_CLR); - - - - - /* reset MCU thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_SET); - - /* 1: Enables thermal control software reset */ - temp2 |= 0x00001000; - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp2 |= 0x00001000; - - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_CLR); -} - - -void get_lvts_slope_intercept(struct TS_PTPOD *ts_info, enum - thermal_bank_name ts_bank) -{ - struct TS_PTPOD ts_ptpod; - int temp; - - lvts_dbg_printk("%s\n", __func__); - - /* chip dependent */ - - temp = (0 - LVTS_COEFF_A_X_1000) * 2; - temp /= 1000; - ts_ptpod.ts_MTS = temp; - - temp = 500 * g_golden_temp + LVTS_COEFF_B_X_1000; - temp /= 1000; - ts_ptpod.ts_BTS = (temp - 25) * 4; - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - lvts_dbg_printk("(LVTS) ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_lvts_slope_intercept); - -int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "lvts_cal : %d\n", g_use_fake_efuse?0:1); - seq_printf(m, "[lvts_cal] g_golden_temp %d\n", g_golden_temp); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_r%d = 0x%x\n", - i, g_count_r[i]); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_rc%d = 0x%x\n", - i, g_count_rc[i]); - - return 0; -} - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -void lvts_enable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !hw_protect_setting_done - || lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, done=%d, en=%d\n", - __func__, tscpu_is_temp_valid(), - hw_protect_setting_done, lvts_hw_protect_enabled); - return; - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) | 0x80000000, - offset + LVTSMONINT_0); - } - - lvts_enable_rgu_reset(); - - /* clear offset after all HW reset are configured. */ - /* make sure LVTS controller uses latest sensor value to compare */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* clear offset */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) & ~0xFFFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 1; - - lvts_printk("%s: done\n", __func__); -} - -void lvts_disable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, en=%d\n", __func__, - tscpu_is_temp_valid(), lvts_hw_protect_enabled); - return; - } - - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) & 0x7FFFFFFF, - offset + LVTSMONINT_0); - /* set offset to 0x3FFF to avoid interrupt false triggered */ - /* large offset can guarantee temp check is always false */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) | 0x3FFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 0; - - lvts_printk("%s: done\n", __func__); -} -#endif - diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_pmic_efuse.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_pmic_efuse.c deleted file mode 100644 index 08a458fe6cf4..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_pmic_efuse.c +++ /dev/null @@ -1,824 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include -#include -#include -#include - -#if defined(THERMAL_USE_IIO_CHANNEL) -#include -#include -#endif -/*============================================================= - *Local variable definition - *============================================================= - */ -int mtktspmic_debug_log; -/* Cali */ -static __s32 g_o_vts; -static __s32 g_o_vts_2; -static __s32 g_o_vts_3; -static __s32 g_o_vts_4; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; -static __s32 g_slope1 = 1; -static __s32 g_slope2 = 1; -static __s32 g_intercept; -static __s32 g_tsbuck1_slope1 = 1; -static __s32 g_tsbuck1_slope2 = 1; -static __s32 g_tsbuck1_intercept; -static __s32 g_tsbuck2_slope1 = 1; -static __s32 g_tsbuck2_slope2 = 1; -static __s32 g_tsbuck2_intercept; -static __s32 g_tsbuck3_slope1 = 1; -static __s32 g_tsbuck3_slope2 = 1; -static __s32 g_tsbuck3_intercept; - -static DEFINE_MUTEX(TSPMIC_lock); -static int pre_temp1 = 0, PMIC_counter; -static int pre_tsbuck1_temp1 = 0, tsbuck1_cnt; -static int pre_tsbuck2_temp1 = 0, tsbuck2_cnt; -static int pre_tsbuck3_temp1 = 0, tsbuck3_cnt; -static int pre_tstsx_temp1 = 0, tstsx_cnt; -static int pre_tsdcxo_temp1 = 0, tsdcxo_cnt; - -#if defined(THERMAL_USE_IIO_CHANNEL) -struct iio_channel *chan_chip_temp; -struct iio_channel *chan_vcore_temp; -struct iio_channel *chan_vproc_temp; -struct iio_channel *chan_vgpu_temp; -struct iio_channel *chan_tsx_temp; -struct iio_channel *chan_dcxo_temp; -#endif -/*=============================================================*/ - -static __s32 pmic_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck1_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck1_intercept + - ((g_tsbuck1_slope1 * y_curr) / (g_tsbuck1_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck2_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck2_intercept + - ((g_tsbuck2_slope1 * y_curr) / (g_tsbuck2_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck3_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck3_intercept + - ((g_tsbuck3_slope1 * y_curr) / (g_tsbuck3_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static void mtktspmic_read_efuse(void) -{ - mtktspmic_info("[pmic_debug] start\n"); - /* MT6359 */ - g_o_vts = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS); - g_o_vts_2 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_2); - g_o_vts_3 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_3); - g_o_vts_4 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_4); - g_degc_cali = pmic_get_register_value(PMIC_AUXADC_EFUSE_DEGC_CALI); - g_adc_cali_en = pmic_get_register_value(PMIC_AUXADC_EFUSE_ADC_CALI_EN); - g_o_slope_sign = - pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE_SIGN); - g_o_slope = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE); - g_id = pmic_get_register_value(PMIC_AUXADC_EFUSE_ID); - - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts = %d\n", - g_o_vts); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_2 = %d\n", - g_o_vts_2); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_3 = %d\n", - g_o_vts_3); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_4 = %d\n", - g_o_vts_4); - mtktspmic_info("[pmic_debug] 6359_efuse: g_degc_cali = %d\n", - g_degc_cali); - mtktspmic_info("[pmic_debug] 6359_efuse: g_adc_cali_en = %d\n", - g_adc_cali_en); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope_sign = %d\n", - g_o_slope_sign); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope = %d\n", - g_o_slope); - mtktspmic_info("[pmic_debug] 6359_efuse: g_id = %d\n", - g_id); - - mtktspmic_info("[pmic_debug] end\n"); -} - -void mtktspmic_cali_prepare(void) -{ - mtktspmic_read_efuse(); - - if (g_id == 0) - g_o_slope = 0; - - /* g_adc_cali_en=0;//FIX ME */ - - if (g_adc_cali_en == 0) { /* no calibration */ - mtktspmic_info("[pmic_debug] It isn't calibration values\n"); - g_o_vts = 1600; - g_o_vts_2 = 1600; - g_o_vts_3 = 1600; - g_o_vts_4 = 1600; - g_degc_cali = 50; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - if (g_degc_cali < 38 || g_degc_cali > 60) - g_degc_cali = 53; - - mtktspmic_info("[pmic_debug] g_o_vts = 0x%x\n", g_o_vts); - mtktspmic_info("[pmic_debug] g_o_vts_2 = 0x%x\n", g_o_vts_2); - mtktspmic_info("[pmic_debug] g_o_vts_3 = 0x%x\n", g_o_vts_3); - mtktspmic_info("[pmic_debug] g_o_vts_4 = 0x%x\n", g_o_vts_4); - mtktspmic_info("[pmic_debug] g_degc_cali = 0x%x\n", g_degc_cali); - mtktspmic_info("[pmic_debug] g_adc_cali_en = 0x%x\n", g_adc_cali_en); - mtktspmic_info("[pmic_debug] g_o_slope = 0x%x\n", g_o_slope); - mtktspmic_info("[pmic_debug] g_o_slope_sign = 0x%x\n", g_o_slope_sign); - mtktspmic_info("[pmic_debug] g_id = 0x%x\n", g_id); - -} - -void mtktspmic_cali_prepare2(void) -{ - __s32 vbe_t; - int factor; - - factor = 1681; - - g_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_slope2 = -(factor + g_o_slope); - else - g_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_intercept = g_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_slope1, g_slope2, g_intercept, vbe_t); - - factor = 1863; - - g_tsbuck1_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck1_slope2 = -(factor + g_o_slope); - else - g_tsbuck1_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_2) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck1_intercept = g_tsbuck1_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck1_slope1, g_tsbuck1_slope2, g_tsbuck1_intercept, vbe_t); - - factor = 1863; - - g_tsbuck2_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck2_slope2 = -(factor + g_o_slope); - else - g_tsbuck2_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_3) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck2_intercept = g_tsbuck2_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck2_slope1, g_tsbuck2_slope2, g_tsbuck2_intercept, vbe_t); - - factor = 1863; - - g_tsbuck3_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck3_slope2 = -(factor + g_o_slope); - else - g_tsbuck3_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_4) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck3_intercept = g_tsbuck3_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck3_slope1, g_tsbuck3_slope2, g_tsbuck3_intercept, vbe_t); - -} - -#if defined(THERMAL_USE_IIO_CHANNEL) -void mtktspmic_get_from_dts(struct platform_device *pdev) -{ - int ret; - - chan_chip_temp = iio_channel_get(NULL, "AUXADC_CHIP_TEMP"); - if (IS_ERR(chan_chip_temp)) { - ret = PTR_ERR(chan_chip_temp); - pr_notice("AUXADC_CHIP_TEMP get fail, ret=%d\n", ret); - } - - chan_vcore_temp = iio_channel_get(NULL, "AUXADC_VCORE_TEMP"); - if (IS_ERR(chan_vcore_temp)) { - ret = PTR_ERR(chan_vcore_temp); - pr_notice("AUXADC_VCORE_TEMP get fail, ret=%d\n", ret); - } - - chan_vproc_temp = iio_channel_get(NULL, "AUXADC_VPROC_TEMP"); - if (IS_ERR(chan_vproc_temp)) { - ret = PTR_ERR(chan_vproc_temp); - pr_notice("AUXADC_VPROC_TEMP get fail, ret=%d\n", ret); - } - - chan_vgpu_temp = iio_channel_get(NULL, "AUXADC_VGPU_TEMP"); - if (IS_ERR(chan_vgpu_temp)) { - ret = PTR_ERR(chan_vgpu_temp); - pr_notice("AUXADC_VGPU_TEMP get fail, ret=%d\n", ret); - } - - chan_tsx_temp = iio_channel_get(NULL, "AUXADC_TSX_TEMP"); - if (IS_ERR(chan_tsx_temp)) { - ret = PTR_ERR(chan_tsx_temp); - pr_notice("AUXADC_TSX_TEMP get fail, ret=%d\n", ret); - } - - chan_dcxo_temp = iio_channel_get(NULL, "AUXADC_DCXO_TEMP"); - if (IS_ERR(chan_dcxo_temp)) { - ret = PTR_ERR(chan_dcxo_temp); - pr_notice("AUXADC_DCXO_TEMP get fail, ret=%d\n", ret); - } -} -#endif - -int mtktspmic_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_chip_temp)) { - ret = iio_read_channel_processed(chan_chip_temp, &temp); - if (ret < 0) - pr_notice("pmic_chip_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_CHIP_TEMP); -#endif - temp1 = pmic_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("[pmic_debug] Raw=%d, T=%d\n", temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("[%s] raw=%d, PMIC T=%d", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("[%s] temp(%d) too high, drop this data!\n", - __func__, temp1); - temp1 = pre_temp1; - } else if ((PMIC_counter != 0) - && (((pre_temp1 - temp1) > 30000) - || ((temp1 - pre_temp1) > 30000))) { - mtktspmic_info("[%s] temp diff too large, drop this data\n", - __func__); - temp1 = pre_temp1; - } else { - /* update previous temp */ - pre_temp1 = temp1; - mtktspmic_dprintk("[%s] pre_temp1=%d\n", __func__, pre_temp1); - - if (PMIC_counter == 0) - PMIC_counter++; - } - - - return temp1; -} - -int mt6359vcore_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vcore_temp)) { - ret = iio_read_channel_processed(chan_vcore_temp, &temp); - if (ret < 0) - pr_notice("pmic_vcore_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VCORE_TEMP); -#endif - temp1 = tsbuck1_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck1_temp1; - } else if ((tsbuck1_cnt != 0) - && (((pre_tsbuck1_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck1_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck1_temp1; - } else { - /* update previous temp */ - pre_tsbuck1_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck1_temp1=%d\n", __func__, - pre_tsbuck1_temp1); - - if (tsbuck1_cnt == 0) - tsbuck1_cnt++; - } - - return temp1; -} - -int mt6359vproc_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vproc_temp)) { - ret = iio_read_channel_processed(chan_vproc_temp, &temp); - if (ret < 0) - pr_notice("pmic_vproc_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VPROC_TEMP); -#endif - temp1 = tsbuck2_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck2_temp1; - } else if ((tsbuck2_cnt != 0) - && (((pre_tsbuck2_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck2_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck2_temp1; - } else { - /* update previous temp */ - pre_tsbuck2_temp1 = temp1; - mtktspmic_dprintk("%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck2_temp1); - - if (tsbuck2_cnt == 0) - tsbuck2_cnt++; - } - - return temp1; -} - -int mt6359vgpu_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vgpu_temp)) { - ret = iio_read_channel_processed(chan_vgpu_temp, &temp); - if (ret < 0) - pr_notice("pmic_vgpu_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VGPU_TEMP); -#endif - temp1 = tsbuck3_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck3_temp1; - } else if ((tsbuck3_cnt != 0) - && (((pre_tsbuck3_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck3_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck3_temp1; - } else { - /* update previous temp */ - pre_tsbuck3_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck3_temp1); - - if (tsbuck3_cnt == 0) - tsbuck3_cnt++; - } - - return temp1; -} - -static int u_table[126] = { - 64078, - 63972, - 63860, - 63741, - 63614, - 63480, - 63338, - 63188, - 63029, - 62860, - 62683, - 62495, - 62297, - 62089, - 61870, - 61639, - 61396, - 61140, - 60872, - 60591, - 60297, - 59989, - 59667, - 59330, - 58978, - 58612, - 58230, - 57833, - 57420, - 56991, - 56546, - 56083, - 55605, - 55110, - 54598, - 54071, - 53528, - 52968, - 52393, - 51802, - 51195, - 50573, - 49936, - 49285, - 48620, - 47942, - 47251, - 46548, - 45834, - 45110, - 44375, - 43632, - 42880, - 42121, - 41355, - 40584, - 39808, - 39027, - 38245, - 37460, - 36675, - 35891, - 35106, - 34323, - 33543, - 32768, - 31996, - 31229, - 30469, - 29716, - 28968, - 28231, - 27502, - 26780, - 26070, - 25371, - 24683, - 24004, - 23339, - 22682, - 22042, - 21412, - 20795, - 20191, - 19600, - 19023, - 18458, - 17908, - 17369, - 16846, - 16331, - 15834, - 15347, - 14878, - 14415, - 13969, - 13535, - 13111, - 12701, - 12302, - 11914, - 11539, - 11176, - 10822, - 10482, - 10147, - 9827, - 9517, - 9214, - 8922, - 8637, - 8364, - 8098, - 7840, - 7590, - 7354, - 7120, - 6896, - 6674, - 6467, - 6264, - 6065, - 5876, - 5691, - 5510, - 5339 -}; -#define MIN_TSX_TEMP (-40000) -#define MAX_TSX_TEMP (+85000) -/* Original formula is - * u = auxadc raw * 2^16 / (2^32 - 1) - * Because kernel is not able to deal with floating point - * we changed the formula to - * u = auxadc raw * 2^16 / 2^32 - * => u = auxadc raw / 2^16 - * => u * 2^16 = auxadc raw - */ - -static int tsx_u2t(int auxadc_raw) -{ - int i; - int ret = 0; - int u_upper, u_low, t_upper, t_low; - - if (auxadc_raw > u_table[0]) - return (int) MIN_TSX_TEMP; - if (auxadc_raw < u_table[125]) - return (int) MAX_TSX_TEMP; - - for (i = 0; i < 125; i++) { - if (auxadc_raw < u_table[i] && auxadc_raw >= u_table[i+1]) { - u_upper = u_table[i+1]; - u_low = u_table[i]; - - t_upper = (int) MIN_TSX_TEMP + (i+1) * 1000; - t_low = (int) MIN_TSX_TEMP + i * 1000; - - if ((u_upper - u_low) == 0) - /* This case should not happen */ - ret = t_low; - else - ret = t_low + ((t_upper - t_low) * - (auxadc_raw - u_low)) / - (u_upper - u_low); - - break; - } - } - - return ret; -} - -int mt6359tsx_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_tsx_temp)) { - ret = iio_read_channel_raw(chan_tsx_temp, &raw); - if (ret < 0) - pr_notice("pmic_tsx_temp read fail, ret=%d\n", ret); - } - - temp1 = tsx_u2t(raw); -#else - temp1 = 25000; -#endif - - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tstsx_temp1; - } else if ((tstsx_cnt != 0) - && (((pre_tstsx_temp1 - temp1) > 30000) - || ((temp1 - pre_tstsx_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tstsx_temp1; - } else { - /* update previous temp */ - pre_tstsx_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsx_temp1=%d\n", __func__, - pre_tstsx_temp1); - - if (tstsx_cnt == 0) - tstsx_cnt++; - } - - return temp1; -} - -int mt6359dcxo_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_dcxo_temp)) { - ret = iio_read_channel_raw(chan_dcxo_temp, &raw); - if (ret < 0) - pr_notice("pmic_dcxo_temp read fail, ret=%d\n", ret); - } - - /* Temperature (C) = ((auxadc raw/32768*1.8)-0.545)/(-0.0017)+120 */ - /* From dcxo desiger John Chiang */ - temp1 = (((18000000/32768)*raw) - 5450000) / -17 + 120000; - - if (temp1 < -40000) - temp1 = -40000; - else if (temp1 > 120000) - temp1 = 120000; -#else - temp1 = 25000; -#endif - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsdcxo_temp1; - } else if ((tsdcxo_cnt != 0) - && (((pre_tsdcxo_temp1 - temp1) > 30000) - || ((temp1 - pre_tsdcxo_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsdcxo_temp1; - } else { - /* update previous temp */ - pre_tsdcxo_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_dcxo_temp1=%d\n", __func__, - pre_tsdcxo_temp1); - - if (tsdcxo_cnt == 0) - tsdcxo_cnt++; - } - - return temp1; -} diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc.c deleted file mode 100644 index 53a6cd0dda89..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc.c +++ /dev/null @@ -1,1490 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include - -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; - * 0: turn off - */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include -#include "mtk_thermal_ipi.h" -/*============================================================= - * Local variable definition - *============================================================= - */ - -/* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - -/* chip dependent */ -/* TODO: I assume AHB bus frequecy is 78MHz. Please confirm it. - */ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {L_TS_MCU1, L_TS_MCU2, L_TS_MCU4, L_TS_ABB}, - .ts_number = 4, - .dominator_ts_idx = 2, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x0, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {L_TS_MCU5, L_TS_MCU6, L_TS_MCU7, L_TS_MCU0}, - .ts_number = 4, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x100, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [2] = { - .ts = {L_TS_MCU8, L_TS_MCU9}, - .ts_number = 2, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x200, - .tc_speed = { - 0x00C, - 0x001, - 0x008, - 0x0000030D - } /* 1ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu0; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -/* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ -static __s32 g_o_vtsmcu4; -static __s32 g_o_vtsmcu5; -static __s32 g_o_vtsmcu6; -static __s32 g_o_vtsmcu7; -static __s32 g_o_vtsmcu8; -static __s32 g_o_vtsmcu9; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[L_TS_MCU_NUM] = { 0 }; - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name); -static void set_tc_trigger_hw_protect - (int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -/*=============================================================*/ - -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum -thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("%s\n", __func__); - - /* chip dependent */ - - /* If there are two or more sensors in a bank, choose the sensor - * calibration value of the dominant sensor. You can observe it in the - * thermal document provided by Thermal DE. For example, Bank 1 is - * for SOC + GPU. Observe all scenarios related to GPU simulation test - * cases to decide which sensor is the highest temperature in all cases. - * Then, It is the dominant sensor.(Confirmed by Thermal DE Alfred Tsai) - */ - - /* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK1: - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - case THERMAL_BANK2: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK3: - x_roomt = g_x_roomt[L_TS_MCU2]; - break; - case THERMAL_BANK4: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - /* No bank 5 */ - case THERMAL_BANK6: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - case THERMAL_BANK7: - x_roomt = g_x_roomt[L_TS_MCU0]; - break; - default: /* choose the highest simulation hot-spot */ - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - } - - - /* - * The equations in this function are confirmed by Thermal DE Alfred - * Tsai. Don't have to change until using next generation thermal - * sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1534 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1534 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = - ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1534 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1534 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - tscpu_printk("[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - tscpu_printk("[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - tscpu_printk("[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - tscpu_printk("[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - tscpu_printk("[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - tscpu_printk("[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); -} - -void eDataCorrector(void) -{ - - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu0 < -8 || g_o_vtsmcu0 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu0 = 260; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - if (g_o_vtsmcu4 < -8 || g_o_vtsmcu4 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu4\n"); - g_o_vtsmcu4 = 260; - } - if (g_o_vtsmcu5 < -8 || g_o_vtsmcu5 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu5\n"); - g_o_vtsmcu5 = 260; - } - if (g_o_vtsmcu6 < -8 || g_o_vtsmcu6 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu6\n"); - g_o_vtsmcu6 = 260; - } - if (g_o_vtsmcu7 < -8 || g_o_vtsmcu7 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu7\n"); - g_o_vtsmcu7 = 260; - } - if (g_o_vtsmcu8 < -8 || g_o_vtsmcu8 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu8 = 260; - } - if (g_o_vtsmcu9 < -8 || g_o_vtsmcu9 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu9 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2, temp3, temp4; - - temp0 = get_devinfo_with_index(ADDRESS_INDEX_0); /* 0184 */ - temp1 = get_devinfo_with_index(ADDRESS_INDEX_1); /* 0180 */ - temp2 = get_devinfo_with_index(ADDRESS_INDEX_2); /* 0188 */ - temp3 = get_devinfo_with_index(ADDRESS_INDEX_3); /* 01AC */ - temp4 = get_devinfo_with_index(ADDRESS_INDEX_4); /* 01B0 */ - - pr_notice( - "[calibration] tmp0=0x%x, tmp1=0x%x, tmp2=0x%x\n", - temp0, temp1, temp2); - pr_notice( - "[calibration] tmp3=0x%x, tmp4=0x%x\n", - temp3, temp4); - - g_adc_ge_t = ((temp0 & _BITMASK_(31:22)) >> 22); - g_adc_oe_t = ((temp0 & _BITMASK_(21:12)) >> 12); - - - g_o_vtsmcu0 = ((temp1 & _BITMASK_(25:17)) >> 17); - g_o_vtsmcu1 = ((temp1 & _BITMASK_(16:8)) >> 8); - g_o_vtsmcu2 = (temp0 & _BITMASK_(8:0)); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = ((temp2 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu5 = ((temp2 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu6 = ((temp3 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu7 = ((temp3 & _BITMASK_(22:14)) >> 14); - g_o_vtsmcu8 = ((temp3 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu9 = ((temp4 & _BITMASK_(31:23)) >> 23); - g_o_vtsabb = ((temp2 & _BITMASK_(22:14)) >> 14); - - g_degc_cali = ((temp1 & _BITMASK_(6:1)) >> 1); - g_adc_cali_en_t = (temp1 & _BIT_(0)); - g_o_slope_sign = ((temp1 & _BIT_(7)) >> 7); - g_o_slope = ((temp1 & _BITMASK_(31:26)) >> 26); - - g_id = ((temp0 & _BIT_(9)) >> 9); - - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu0 = 260; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = 260; - g_o_vtsmcu5 = 260; - g_o_vtsmcu6 = 260; - g_o_vtsmcu7 = 260; - g_o_vtsmcu8 = 260; - g_o_vtsmcu9 = 260; - g_o_vtsabb = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[L_TS_MCU_NUM] = { 0 }; - int i = 0; -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - struct thermal_ipi_data thermal_data; -#endif - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[0] = (g_o_vtsmcu0 + 3350 - g_oe); - format[1] = (g_o_vtsmcu1 + 3350 - g_oe); - format[2] = (g_o_vtsmcu2 + 3350 - g_oe); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - format[3] = (g_o_vtsmcu4 + 3350 - g_oe); - format[4] = (g_o_vtsmcu5 + 3350 - g_oe); - format[5] = (g_o_vtsmcu6 + 3350 - g_oe); - format[6] = (g_o_vtsmcu7 + 3350 - g_oe); - format[7] = (g_o_vtsmcu8 + 3350 - g_oe); - format[8] = (g_o_vtsmcu9 + 3350 - g_oe); - format[9] = (g_o_vtsabb + 3350 - g_oe); - - for (i = 0; i < L_TS_MCU_NUM; i++) { - /* x_roomt * 10000 */ - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; - } - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, - g_x_roomt[i]); -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - thermal_data.u.data.arg[0] = g_degc_cali; - thermal_data.u.data.arg[1] = g_o_slope_sign; - thermal_data.u.data.arg[2] = g_o_slope; - while (thermal_to_mcupm(THERMAL_IPI_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_oe; - thermal_data.u.data.arg[1] = g_gain; - thermal_data.u.data.arg[2] = g_x_roomt[L_TS_MCU8]; - while (thermal_to_mcupm(THERMAL_IPI_INIT_GRP2, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_x_roomt[L_TS_MCU9]; - while (thermal_to_mcupm(THERMAL_IPI_INIT_GRP3, &thermal_data) != 0) - udelay(100); -#endif -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1534+O_slope*10)/10*(18/15)* - * (1/10000)+X_roomtabb]*Gain*4096 + OE - */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n", - * ts_name,xtoomt); - */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 + g_o_slope * 10)); - else /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 - g_o_slope * 10)); - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} -static void thermal_dump_debug_logs(int tc_num) -{ - int offset; - unsigned int auxadc_data11, ts_con0, ts_con1; - unsigned int tempmsr0, tempmsr1, tempmsr2, tempmsr3; - - offset = tscpu_g_tc[tc_num].tc_offset; - - auxadc_data11 = readl(AUXADC_DAT11_V); - ts_con0 = readl(TS_CON0_TM); - ts_con1 = readl(TS_CON1_TM); - tempmsr0 = readl((offset + TEMPMSR0)); - tempmsr1 = readl((offset + TEMPMSR1)); - tempmsr2 = readl((offset + TEMPMSR2)); - tempmsr3 = readl((offset + TEMPMSR3)); - - tscpu_printk("AUXADC_DAT11 = 0x%x, TS_CON0 = 0x%x, TS_CON1 = 0x%x\n", - auxadc_data11, ts_con0, ts_con1); - tscpu_printk("TEMPMSR0_%d = 0x%x, TEMPMSR1_%d = 0x%x\n", - tc_num, tempmsr0, tc_num, tempmsr1); - tscpu_printk("TEMPMSR2_%d = 0x%x, TEMPMSR3_%d = 0x%x\n", - tc_num, tempmsr2, tc_num, tempmsr3); -} -static void thermal_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); - - tscpu_printk( - "[Thermal IRQ] Auxadc thermal_tc %d, TEMPMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_COLD_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 2\n"); - - if (ret & THERMAL_AHB_TIMEOUT_INTERRUPT) - tscpu_dprintk( - "[Thermal IRQ]: AHB bus timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 1 int triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 2 int triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) { - tscpu_printk( - "[Thermal IRQ]: Thermal protection stage 3 int triggered\n"); - tscpu_printk("[Thermal IRQ]: Thermal HW reboot!!"); - thermal_dump_debug_logs(tc_num); - } -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - ret = ret & 0x7F; - - /* MSB LSB NAME - * 6 6 LVTSINT3 - * 5 5 LVTSINT2 - * 4 4 LVTSINT1 - * 3 3 LVTSINT0 - * 2 2 THERMINT2 - * 1 1 THERMINT1 - * 0 0 THERMINT0 - */ - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - unsigned int offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tempMonCtl1 = (tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0)); - - tempMonCtl2 = (((tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay & - _BITMASK_(9:0))); - - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.ahb_polling_interval; - - /* Calculating period unit in Module clock x 256, - * and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* bus clock 66M counting unit is 12 * 1/66M * 256 = - * 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - * filt interval is 1 * 46.545us = 46.545us, - * sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /* AHB polling is 781* 1/66M = 11.833us */ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - /* temperature sampling control, 4 out of 6 samples */ - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - /* temperature sampling control, 8 out of 10 samples */ - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - /* temperature sampling control, 16 out of 18 samples */ - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); -#else /* default 1 */ - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); -#endif - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); - - /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET3); - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); - - /* AHB value for auxadc enable */ - mt_reg_sync_writel(0x800, offset + TEMPADCEN); - - /* - * AHB address for auxadc enable (channel 0 immediate mode selected) - * this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void set_tc_trigger_hw_protect -(int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, d_index, config; - enum tsmcu_sensor_enum ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* temperature2=80000; test only */ - tscpu_dprintk("%s t1=%d t2=%d\n", __func__, temperature, - temperature2); - - if (tscpu_g_tc[tc_num].dominator_ts_idx < - tscpu_g_tc[tc_num].ts_number){ - d_index = tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - tscpu_printk("Error: Auxadc TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - tscpu_g_tc[tc_num].dominator_ts_idx, - tscpu_g_tc[tc_num].ts_number); - - tscpu_printk("Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - - ts_name = tscpu_g_tc[tc_num].ts[d_index]; - - /* temperature to trigger SPM state2 */ - if (tc_num == THERMAL_CONTROLLER2) - raw_high = temperature_to_raw_room(105000, ts_name); - else - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); - - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel(config, offset + TEMPPROTCTL); - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); - - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); -} - -static int read_tc_raw_and_temp( -u32 *tempmsr_name, enum tsmcu_sensor_enum ts_name) -{ - int temp = 0, raw = 0; -#if CONFIG_LVTS_ERROR_AEE_WARNING - int raw1; -#endif - - if (tempmsr_name == 0) - return 0; - -#if CONFIG_LVTS_ERROR_AEE_WARNING - raw = readl(tempmsr_name); - raw1 = ((raw & _BIT_(15)) >> 15); - raw = raw & 0xFFF; -#else - raw = readl(tempmsr_name) & 0xFFF; -#endif - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_mcu_temp_r[ts_name] = raw; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_mcu_temp_v[ts_name] = raw1; -#endif - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp_r[ts_name] = tscpu_ts_mcu_temp_r[ts_name]; -#endif - return temp * 100; -} - -void tscpu_thermal_read_tc_temp( -int tc_num, enum tsmcu_sensor_enum type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, - tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 1: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 2: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 3: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - default: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - } - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp[type] = tscpu_ts_mcu_temp[type]; -#endif -} - -void read_all_tc_tsmcu_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_read_tc_temp(i, tscpu_g_tc[i].ts[j], j); -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - - /* write temp to spare register */ - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); - - /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL1); - - /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); - - /* polling interval to check if temperature sense is ready */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); - - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - - /* temperature measurement sampling control */ - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) - * automatically by hw - */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); - - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); - - /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); - - /* enable auxadc mux & pnp write transaction */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - - - /* enable all interrupt except filter sense and - * immediate sense interrupt - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - /* enable all sensing point(sensing point 2 is unused)*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum tsmcu_sensor_enum type) -{ - switch (type) { - case L_TS_MCU0: - return TEMPADC_MCU0; - case L_TS_MCU1: - return TEMPADC_MCU1; - case L_TS_MCU2: - return TEMPADC_MCU2; - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - case L_TS_MCU4: - return TEMPADC_MCU4; - case L_TS_MCU5: - return TEMPADC_MCU5; - case L_TS_MCU6: - return TEMPADC_MCU6; - case L_TS_MCU7: - return TEMPADC_MCU7; - case L_TS_MCU8: - return TEMPADC_MCU8; - case L_TS_MCU9: - return TEMPADC_MCU9; - case L_TS_ABB: - return TEMPADC_ABB; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - - /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); - - /* disable auxadc channel 11 immediate mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - int wd_api_ret; - struct wd_api *wd_api; - - tscpu_dprintk("%s,temperature=%d,temperature2=%d\n", __func__, - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /* spend 860~1463 us */ - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - wd_api_ret = get_wd_api(&wd_api); - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_DIS, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_notice("resume time spent, sec : %lu , usec : %lu\n", - (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - set_tc_trigger_hw_protect(temperature, temperature2, i); - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_EN, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - - seq_printf(m, "[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - seq_printf(m, "[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - seq_printf(m, "[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - seq_printf(m, "[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - seq_printf(m, "[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - seq_printf(m, "[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - seq_printf(m, "[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_id = %d\n", g_id); - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - return 0; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -int check_auxadc_mcu_efuse(void) -{ - return g_adc_cali_en_t; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /* Need to confirm with DE */ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /* The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if (cg_freq & _BIT_(4)) - ahbClk = clockSource / 2; - else if (cg_freq & _BIT_(3)) - ahbClk = clockSource / 4; - else if (cg_freq & _BIT_(2)) - ahbClk = clockSource / 8; - else if (cg_freq & _BIT_(1)) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /* tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm); */ - /* tscpu_printk("AHB bus clock= %d MHz\n", ahbClk); */ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "L %d B %d", - get_immediate_cpuL_wrap(), get_immediate_cpuB_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc_wrapper.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc_wrapper.c deleted file mode 100644 index 9a19da9ac3ce..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc_wrapper.c +++ /dev/null @@ -1,1032 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#include -#include -#include -#include -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include "mtk_idle.h" - -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -#include -#endif - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#include -#include -#if DUMP_VCORE_VOLTAGE -#include -#endif -struct lvts_error_data { - int ts_temp[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_r[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_v[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ -#if DUMP_VCORE_VOLTAGE - int vcore_voltage[R_BUFFER_SIZE]; /* A ring buffer */ -#endif - int c_index; /* Current index points to the space to replace.*/ - int e_occurred; /* 1: An error occurred, 0: Nothing happened*/ - int f_count; /* Future count */ - enum thermal_sensor e_mcu; - enum thermal_sensor e_lvts; -}; -struct lvts_error_data g_lvts_e_data; -int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#endif - - -#if CFG_THERM_LVTS -int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; -#endif - -int tscpu_curr_cpu_temp; -int tscpu_curr_gpu_temp; -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -static int ignore_hot_sensor; -#endif - -static int tscpu_curr_max_ts_temp; - -int __attribute__ ((weak)) - mtk_idle_notifier_register(struct notifier_block *n) -{ - return 0; -} - -int get_immediate_none_wrap(void) -{ - return -127000; -} - -/* chip dependent */ -int get_immediate_cpuL_wrap(void) -{ - int curr_temp; - - curr_temp = MAX( - MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_0], - tscpu_ts_lvts_temp[L_TS_LVTS3_1]), - MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_2], - tscpu_ts_lvts_temp[L_TS_LVTS3_3]) - ); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS1_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS1_0], - tscpu_ts_lvts_temp[L_TS_LVTS1_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS2_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS2_0], - tscpu_ts_lvts_temp[L_TS_LVTS2_1]); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_vpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS4_0], - tscpu_ts_lvts_temp[L_TS_LVTS4_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS5_0], - tscpu_ts_lvts_temp[L_TS_LVTS5_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - -int get_immediate_infa_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_0]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_camsys_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_1]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_md_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(MAX(tscpu_ts_lvts_temp[L_TS_LVTS7_0], - tscpu_ts_lvts_temp[L_TS_LVTS7_1]), - tscpu_ts_lvts_temp[L_TS_LVTS7_2]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - - - -/* - * THERMAL_BANK0, //B CPU (LVTS1) - * THERMAL_BANK1, //B CPU (LVTS2) - * THERMAL_BANK2, //L CPU (LVTS3) - * THERMAL_BANK3, //VPU (LVTS4) - * THERMAL_BANK4, //GPU (LVTS5) - * THERMAL_BANK5, //IFRA (LVTS6) - */ - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpuB_LVTS1_wrap, - get_immediate_cpuB_LVTS2_wrap, - get_immediate_cpuL_wrap, - get_immediate_vpu_wrap, - get_immediate_gpu_wrap, - get_immediate_infa_wrap -}; - -int get_immediate_cpuB_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(get_immediate_cpuB_LVTS1_wrap(), - get_immediate_cpuB_LVTS2_wrap()); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - - - -int get_immediate_ts0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts4_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts5_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts6_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts7_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts8_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS7_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts9_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS7_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -#if CFG_THERM_LVTS -int get_immediate_tslvts1_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts1_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts5_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts5_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts6_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS6_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts6_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS6_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts7_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts7_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts7_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} -#endif - -int get_immediate_tsabb_wrap(void) -{ - - return 0; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - -#if CFG_THERM_LVTS - get_immediate_tslvts1_0_wrap, - get_immediate_tslvts1_1_wrap, - get_immediate_tslvts2_0_wrap, - get_immediate_tslvts2_1_wrap, - get_immediate_tslvts3_0_wrap, - get_immediate_tslvts3_1_wrap, - get_immediate_tslvts3_2_wrap, - get_immediate_tslvts3_3_wrap, - get_immediate_tslvts4_0_wrap, - get_immediate_tslvts4_1_wrap, - get_immediate_tslvts5_0_wrap, - get_immediate_tslvts5_1_wrap, - get_immediate_tslvts6_0_wrap, - get_immediate_tslvts6_1_wrap, - get_immediate_tslvts7_0_wrap, - get_immediate_tslvts7_1_wrap, - get_immediate_tslvts7_2_wrap -#endif -}; - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T4,T5) LVTS1-0, LVTS1-1 - * MCU_BIG(T6,T7) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T0,T1,T2,T3) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T16,T19) LVTS7-0, LVTS7-1, LVTS7-2 - */ -int tscpu_max_temperature(void) -{ - int i, j, max = -127000; - - tscpu_dprintk("lvts_max_temperature %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR - if (ignore_hot_sensor == 0 || - !(i == 0 && j == 1)) -#endif - if (max < tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } - } - - return max; -} - - -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of thermal - * controller driver - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T4,T5) LVTS1-0, LVTS1-1 - * MCU_BIG(T6,T7) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T0,T1,T2,T3) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) VTS6-1 - * MDSYS(T14,T16,T19) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_curr_cpu_temp = - MAX( - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS1_0], - tscpu_ts_lvts_temp[TS_LVTS1_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS2_0], - tscpu_ts_lvts_temp[TS_LVTS2_1]) - )), - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS3_0], - tscpu_ts_lvts_temp[TS_LVTS3_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS3_2], - tscpu_ts_lvts_temp[TS_LVTS3_3]) - )) - ); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_lvts_temp[TS_LVTS5_0], - tscpu_ts_lvts_temp[TS_LVTS5_1]); -#endif /* CFG_THERM_LVTS */ -#else - /* It is platform dependent which TS is better to present CPU/GPU - * temperature - */ - tscpu_curr_cpu_temp = MAX( - MAX(MAX(tscpu_ts_temp[TS_MCU5], tscpu_ts_temp[TS_MCU6]), - MAX(tscpu_ts_temp[TS_MCU7], tscpu_ts_temp[TS_MCU8])), - tscpu_ts_temp[TS_MCU9]); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_temp[TS_MCU1], - tscpu_ts_temp[TS_MCU2]); -#endif /* CFG_LVTS_DOMINATOR */ -#endif /* PRECISE_HYBRID_POWER_BUDGET */ - - /* though tscpu_max_temperature is common, put it in mtk_ts_cpu.c is - * weird. - */ - - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -char mcu_s_array[TS_ENUM_MAX][17] = { -#if CFG_THERM_LVTS - "TS_LVTS1_0", - "TS_LVTS1_1", - "TS_LVTS2_0", - "TS_LVTS2_1", - "TS_LVTS3_0", - "TS_LVTS3_1", - "TS_LVTS3_2", - "TS_LVTS3_3", - "TS_LVTS4_0", - "TS_LVTS4_1", - "TS_LVTS5_0", - "TS_LVTS5_1", - "TS_LVTS6_0", - "TS_LVTS6_1", - "TS_LVTS7_0", - "TS_LVTS7_1", - "TS_LVTS7_2" - #endif -}; - -static void dump_lvts_error_info(void) -{ - int i, j, index, e_index, offset; -#if DUMP_LVTS_REGISTER - int cnt, temp; -#endif - enum thermal_sensor mcu_index, lvts_index; - char buffer[512]; - - mcu_index = g_lvts_e_data.e_mcu; - lvts_index = g_lvts_e_data.e_lvts; - index = g_lvts_e_data.c_index; - e_index = (index + HISTORY_SAMPLES + 1) % R_BUFFER_SIZE; - - tscpu_printk("[LVTS_ERROR][DUMP] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - g_lvts_e_data.ts_temp[mcu_index][e_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[lvts_index][e_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index], - LVTS_ERROR_THRESHOLD); - - for (i = TS_MCU1; i <= TS_LVTS4_1; i++) { - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[i]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) - % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[i][index]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - } - - offset = sprintf(buffer, "[LVTS_ERROR][%s_R][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[mcu_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[mcu_index][index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - dump_efuse_data(); -#if DUMP_LVTS_REGISTER - read_controller_reg_when_error(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -#endif -#if DUMP_VCORE_VOLTAGE - offset = sprintf(buffer, "[LVTS_ERROR][Vcore_V][DUMP] ", - mcu_s_array[lvts_index]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.vcore_voltage[index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -#endif -#if DUMP_LVTS_REGISTER - lvts_reset_device_and_stop_clk(); -#endif -#ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, __func__, - "LVTS_ERROR: %s, %s diff: %d\n", mcu_s_array[mcu_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index]); -#endif - - g_lvts_e_data.e_occurred = 0; - g_lvts_e_data.f_count = -1; -#if DUMP_LVTS_REGISTER - clear_lvts_register_value_array(); - - lvts_device_identification(); - lvts_Device_Enable_Init_all_Devices(); - lvts_device_read_count_RC_N(); - lvts_efuse_setting(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - Enable_LVTS_CTRL_for_thermal_Data_Fetch(); - lvts_tscpu_thermal_initial_all_tc(); -#endif -} - -static void check_lvts_error(enum thermal_sensor mcu_index, - enum thermal_sensor lvts_index) -{ - int temp; - - temp = tscpu_ts_temp[mcu_index] - tscpu_ts_temp[lvts_index]; - - if (temp < 0) - temp = temp * -1; - - /*Skip if LVTS thermal controllers doens't ready */ - if (temp > 100000) - return; - - if (temp > LVTS_ERROR_THRESHOLD) { - tscpu_printk("[LVTS_ERROR] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - tscpu_ts_temp[mcu_index], - mcu_s_array[lvts_index], - tscpu_ts_temp[lvts_index], - tscpu_ts_temp[mcu_index] - - tscpu_ts_temp[lvts_index], - LVTS_ERROR_THRESHOLD); - g_lvts_e_data.e_occurred = 1; - g_lvts_e_data.e_mcu = mcu_index; - g_lvts_e_data.e_lvts = lvts_index; - g_lvts_e_data.f_count = -1; - } -} -void dump_lvts_error_data_info(void) -{ - char buffer[512]; - int offset, j; - - tscpu_printk("[LVTS_ERROR] c_index %d, e_occurred %d, f_count %d\n", - g_lvts_e_data.c_index, g_lvts_e_data.e_occurred, - g_lvts_e_data.f_count); - tscpu_printk("[LVTS_ERROR] e_mcu %d, e_lvts %d\n", g_lvts_e_data.e_mcu, - g_lvts_e_data.e_lvts); - - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_raw][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -} -#endif - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - seq_printf(m, "curr_temp = %d\n", tscpu_get_curr_max_ts_temp()); - -#if !defined(CFG_THERM_NO_AUXADC) - tscpu_dump_cali_info(m, v); -#endif - -#if CFG_THERM_LVTS - seq_puts(m, "-----------------\n"); - lvts_tscpu_dump_cali_info(m, v); -#endif - return 0; -} - -static int thermal_idle_notify_call(struct notifier_block *nfb, - unsigned long id, - void *arg) -{ - switch (id) { - case NOTIFY_DPIDLE_ENTER: - break; - case NOTIFY_SOIDLE_ENTER: - break; - case NOTIFY_DPIDLE_LEAVE: - break; - case NOTIFY_SOIDLE_LEAVE: - break; - case NOTIFY_SOIDLE3_ENTER: -#if LVTS_VALID_DATA_TIME_PROFILING - SODI3_count++; - if (SODI3_count != 1 && isTempValid == 0) - noValid_count++; - - if (isTempValid == 1 || SODI3_count == 1) - start_timestamp = thermal_get_current_time_us(); - - isTempValid = 0; -#endif - break; - case NOTIFY_SOIDLE3_LEAVE: -#if CFG_THERM_LVTS - lvts_sodi3_release_thermal_controller(); -#endif - break; - default: - /* do nothing */ - break; - } - return NOTIFY_OK; -} - -static struct notifier_block thermal_idle_nfb = { - .notifier_call = thermal_idle_notify_call, -}; - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - } - - /*tscpu_printk("[THERM_CTRL] thermal_base= 0x%px\n",thermal_base);*/ - - /*get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", - thermal_irq_number); - if (!thermal_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_irq_number); - return 0; - } - - /*get thermal irq num */ - thermal_mcu_irq_number = irq_of_parse_and_map(node, 1); - tscpu_printk("[THERM_CTRL] mcu_irq_num = %d\n", - thermal_mcu_irq_number); - if (!thermal_mcu_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_mcu_irq_number); - return 0; - } - - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - /*tscpu_printk("[THERM_CTRL] phy_base=0x%x\n", thermal_phy_base);*/ - - - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6768-auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,infracfg_ao"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - - if (infracfg_ao_base) - mtk_idle_notifier_register(&thermal_idle_nfb); - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,apmixed"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base=\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); - if (!node) { - pr_notice("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_notice("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); - - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - clk_disable_unprepare(therm_main); - return ret; -} - -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -#define CPU_SEGMENT 7 -int tscpu_check_cpu_segment(void) -{ - int val = (get_devinfo_with_index(CPU_SEGMENT) & 0xFF); - - if (val == 0x30) - ignore_hot_sensor = 1; - else - ignore_hot_sensor = 0; - - return val; -} -#endif - diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_thermal_ipi.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_thermal_ipi.c deleted file mode 100644 index 99d2ff93f356..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_thermal_ipi.c +++ /dev/null @@ -1,404 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#include "mtk_thermal_ipi.h" -#include "mach/mtk_thermal.h" -#include "tscpu_settings.h" -#include "linux/mutex.h" -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -static DEFINE_MUTEX(thermo_sspm_mutex); -static int is_thermal_ipi_registered; -static int ack_data; - -static int register_thermal_ipi(void) -{ -#ifndef THERMAL_CPUTOEB_USE_PLATFORM_IPI - int ret; - - ret = mtk_ipi_register(&mcupm_ipidev, CH_S_PLATFORM, NULL, NULL, - (void *)&ack_data); - if (ret != 0) { - tscpu_printk("%s error ret:%d\n", __func__, ret); - return -1; - } -#endif - is_thermal_ipi_registered = 1; - - return 0; -} - -unsigned int thermal_to_mcupm( - unsigned int cmd, struct thermal_ipi_data *thermal_data) -{ - int ackData = -1; - int ret; - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_INIT_GRP1: - case THERMAL_IPI_INIT_GRP2: - case THERMAL_IPI_INIT_GRP3: - case THERMAL_IPI_INIT_GRP4: - case THERMAL_IPI_INIT_GRP5: - case THERMAL_IPI_INIT_GRP6: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send init cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_LVTS_INIT_GRP1: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) lvts efuse to MCUPM (%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_GET_TEMP: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send get_temp cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_SET_BIG_FREQ_THRESHOLD: - case THERMAL_IPI_GET_BIG_FREQ_THRESHOLD: - thermal_data->cmd = cmd; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("mtk_ipi_send_compl error ret:%d - %d\n", - cmd, ret); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_SET_DIS_THERMAL_THROTTLE: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) disable SSPM thermal throttle(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - case THERMAL_IPI_SUSPEND_RESUME_NOTIFY: - thermal_data->cmd = cmd; - //tscpu_printk("cmd(%d) kernel suspend/resume(%d)\n", - // cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - default: - tscpu_printk("cmd(%d) wrong!!\n", cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ackData; /** It's weird here. What should be returned? */ -} - -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -int atm_to_sspm(unsigned int cmd, int data_len, -struct thermal_ipi_data *thermal_data, int *ackData) -{ - int ret = -1; - - if (data_len < 1 || data_len > 3) { - *ackData = -1; - return ret; - } - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_SET_ATM_CFG_GRP1: - case THERMAL_IPI_SET_ATM_CFG_GRP2: - case THERMAL_IPI_SET_ATM_CFG_GRP3: - case THERMAL_IPI_SET_ATM_CFG_GRP4: - case THERMAL_IPI_SET_ATM_CFG_GRP5: - case THERMAL_IPI_SET_ATM_CFG_GRP6: - case THERMAL_IPI_SET_ATM_CFG_GRP7: - case THERMAL_IPI_SET_ATM_CFG_GRP8: - case THERMAL_IPI_SET_ATM_TTJ: - case THERMAL_IPI_SET_ATM_EN: - case THERMAL_IPI_GET_ATM_CPU_LIMIT: - case THERMAL_IPI_GET_ATM_GPU_LIMIT: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, (data_len+1), 2000); - if ((ret != 0) || (ack_data < 0)) - tscpu_printk("%s cmd %d ret %d ack %d\n", - __func__, cmd, ret, ack_data); - - *ackData = ack_data; - - break; - - default: - tscpu_printk("%s cmd %d err!\n", __func__, cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ret; -} - -static int get_sspm_tz_temp_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_GET_TEMP, &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show current temperature in SSPM UART log\n"); - - return 0; -} - -static int get_sspm_tz_temp_open(struct inode *inode, struct file *file) -{ - return single_open(file, get_sspm_tz_temp_read, NULL); -} - -static const struct file_operations get_sspm_tz_temp_fops = { - .owner = THIS_MODULE, - .open = get_sspm_tz_temp_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static ssize_t set_sspm_big_limit_threshold_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int arrayIndex, bigCoreTj, bigCoreExitTj, bigCoreFreqUpperBound; - struct thermal_ipi_data thermal_data; - - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - - if (sscanf(desc, "%d %d %d", &arrayIndex, &bigCoreTj, - &bigCoreFreqUpperBound) == 3) { - if ((arrayIndex >= BIG_CORE_THRESHOLD_ARRAY_SIZE) || - (arrayIndex < 0)) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreTj; - thermal_data.u.data.arg[2] = bigCoreFreqUpperBound; - - while (thermal_to_mcupm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } else if (sscanf(desc, "%d %d", &arrayIndex, &bigCoreExitTj) == 2) { - if (arrayIndex != -1) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreExitTj; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } - - tscpu_printk("%s bad argument: %s\n", __func__, desc); - return -EINVAL; - -} - -static int set_sspm_big_limit_threshold_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - seq_puts(m, "Use this command to change big core freq limit threshold\n"); - seq_puts(m, " echo arrayIndex BigCoreTj bigCoreFreqUpperBound >\n"); - seq_puts(m, " /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_printf(m, " arrayIndex is not larger than or equal to %d\n", - BIG_CORE_THRESHOLD_ARRAY_SIZE); - seq_puts(m, " BigCoreTj is in m'C\n"); - seq_puts(m, " BigCoreFreqUpperBound is in MHz\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo 0 85000 2050 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, "Use this command to change exit point\n"); - seq_puts(m, " echo -1 BigCoreExitTj > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, " BigCoreExitTj is in m'C\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo -1 75000 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show big core frequency thresholds in SSPM UART log\n"); - - return 0; -} - -static int set_sspm_big_limit_threshold_open(struct inode *inode, - struct file *file) -{ - return single_open(file, set_sspm_big_limit_threshold_read, NULL); -} - -static const struct file_operations set_sspm_big_limit_threshold_fops = { - .owner = THIS_MODULE, - .open = set_sspm_big_limit_threshold_open, - .read = seq_read, - .llseek = seq_lseek, - .write = set_sspm_big_limit_threshold_write, - .release = single_release, -}; -static int __init thermal_ipi_init(void) -{ - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *thermal_ipi_dir = NULL; - - tscpu_printk("[%s]\n", __func__); - - - thermal_ipi_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!thermal_ipi_dir) { - tscpu_printk( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("get_sspm_tz_temp", 444, thermal_ipi_dir, - &get_sspm_tz_temp_fops); - if (entry) - proc_set_user(entry, uid, gid); - entry = - proc_create("set_sspm_big_limit_threshold", 664, - thermal_ipi_dir, &set_sspm_big_limit_threshold_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - return 0; -} - -static void __exit thermal_ipi_exit(void) -{ - tscpu_printk("[%s]\n", __func__); -} - -module_init(thermal_ipi_init); -module_exit(thermal_ipi_exit); -#endif diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ti_6315.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_ti_6315.c deleted file mode 100644 index d56e09105ed7..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ti_6315.c +++ /dev/null @@ -1,328 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - -/* #define INTR_UT */ -/* #define OT_THROTTLE_CPU */ -/* #define OT_THROTTLE_GPU */ - -#define DEFAULT_6315OT_CPU_LIMIT (800) -#define DEFAULT_6315OT_GPU_LIMIT (1000) - -static struct apthermolmt_user ap_6315ot; -static char *ap_6315ot_log = "ap_6315ot"; -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static unsigned int cpu_limit = DEFAULT_6315OT_CPU_LIMIT; -static unsigned int gpu_limit = DEFAULT_6315OT_GPU_LIMIT; - -static int virq_tempL_6; -static int virq_tempH_6; -static int virq_tempL_7; -static int virq_tempH_7; -#ifdef INTR_UT -static int virq_rcs0_6; -static int virq_rcs0_7; -#endif - -static int tpmic6315_intr_probe(struct platform_device *dev); - -static const struct of_device_id tpmic_intr_of_match[] = { - { .compatible = "mediatek,mt6315_therm_intr", }, - { /* sentinel */ } -}; - -MODULE_DEVICE_TABLE(of, tpmic_intr_of_match); - -static struct platform_driver tpmic_intr_pdrv = { - .probe = tpmic6315_intr_probe, - .remove = NULL, - .driver = { - .name = "tpmic6315_intr", - .owner = THIS_MODULE, - .of_match_table = tpmic_intr_of_match, - }, -}; - -static irqreturn_t mt6315_6_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_6); - enable_irq(virq_tempH_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s release cpu limit\n", __func__); - apthermolmt_set_cpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_6_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_6); - enable_irq(virq_tempL_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_6_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static irqreturn_t mt6315_7_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_7); - enable_irq(virq_tempH_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s release gpu limit\n", __func__); - apthermolmt_set_gpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_7_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_7); - enable_irq(virq_tempL_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_7_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static int tpmic6315_intr_probe(struct platform_device *pdev) -{ - struct device_node *node; - int ret = 0; - - node = of_find_matching_node(NULL, tpmic_intr_of_match); - if (!node) - pr_info("@%s: find tpmic_intr node failed\n", __func__); - - virq_tempL_6 = platform_get_irq(pdev, 0); - virq_tempH_6 = platform_get_irq(pdev, 1); - virq_tempL_7 = platform_get_irq(pdev, 3); - virq_tempH_7 = platform_get_irq(pdev, 4); -#ifdef INTR_UT - virq_rcs0_6 = platform_get_irq(pdev, 2); - virq_rcs0_7 = platform_get_irq(pdev, 5); -#endif - -#ifdef INTR_UT - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || virq_rcs0_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0 || virq_rcs0_7 <= 0) { -#else - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0) { -#endif - pr_info("%s: get irq error\n", __func__); - return 0; - } - - pr_info("%s: 6_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 0) - , platform_get_irq_byname(pdev, "6315_6_temp_l")); - pr_info("%s: 6_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 1) - , platform_get_irq_byname(pdev, "6315_6_temp_h")); - pr_info("%s: 7_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 3) - , platform_get_irq_byname(pdev, "6315_7_temp_l")); - pr_info("%s: 7_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 4) - , platform_get_irq_byname(pdev, "6315_7_temp_h")); - -#ifdef INTR_UT - pr_info("%s: 6_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 2) - , platform_get_irq_byname(pdev, "6315_6_rcs0")); - pr_info("%s: 7_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 5) - , platform_get_irq_byname(pdev, "6315_7_rcs0")); -#endif - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_l"), - NULL, mt6315_6_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_h"), - NULL, mt6315_6_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_l"), - NULL, mt6315_7_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_h"), - NULL, mt6315_7_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - -#ifdef INTR_UT - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_rcs0"), - NULL, mt6315_6_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S6_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_rcs0"), - NULL, mt6315_7_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S7_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); -#endif - - disable_irq_nosync(virq_tempL_6); - disable_irq_nosync(virq_tempL_7); - - return 0; -} - -static int cl_6315ot_read(struct seq_file *m, void *v) -{ - - seq_printf(m, "[%s] C/G limit = %d/%d\n", - __func__, cpu_limit, gpu_limit); - - return 0; -} -static ssize_t cl_6315ot_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int c_limit, g_limit; - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - if (sscanf(desc, "%d %d", &c_limit, &g_limit) == 2) { - pr_info("[%s] set C/G limit = %d/%d\n", - __func__, c_limit, g_limit); - cpu_limit = (c_limit != 0) ? c_limit : 0x7FFFFFFF; - gpu_limit = (g_limit != 0) ? g_limit : 0x7FFFFFFF; - - return count; - } - - pr_info("%s bad argument\n", __func__); - return -EINVAL; -} - -static int cl_6315ot_open(struct inode *inode, struct file *file) -{ - return single_open(file, cl_6315ot_read, NULL); -} - -static const struct file_operations cl_6315ot_fops = { - .owner = THIS_MODULE, - .open = cl_6315ot_open, - .read = seq_read, - .llseek = seq_lseek, - .write = cl_6315ot_write, - .release = single_release, -}; - -static int __init mtk_ti_6315_init(void) -{ - int ret = 0; - - /* register platform driver */ - ret = platform_driver_register(&tpmic_intr_pdrv); - if (ret) { - pr_info("fail to register %s driver ~~~\n", __func__); - goto end; - } - - /* create a proc file */ - { - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *dir_entry = NULL; - - dir_entry = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!dir_entry) { - pr_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = proc_create("cl6315ot_limit", 0664, - dir_entry, - &cl_6315ot_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - } - - /* register user to thermal */ - apthermolmt_register_user(&ap_6315ot, ap_6315ot_log); - -end: - return 0; -} - -static void __exit mtk_ti_6315_exit(void) -{ - apthermolmt_unregister_user(&ap_6315ot); - platform_driver_unregister(&tpmic_intr_pdrv); - pr_info("%s\n", __func__); -} - -late_initcall(mtk_ti_6315_init); -module_exit(mtk_ti_6315_exit); diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359dcxo.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359dcxo.c deleted file mode 100644 index b07ffa4178c6..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359dcxo.c +++ /dev/null @@ -1,597 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359dcxo_cur_temp; -/* - *static long int mt6359dcxo_start_temp; - *static long int mt6359dcxo_end_temp; - */ -/*=============================================================*/ - -static int mt6359dcxo_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359dcxo_get_hw_temp(); - mt6359dcxo_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359dcxo_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359dcxo_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359dcxo_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359dcxo_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359dcxo_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359dcxo_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359dcxo_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359dcxo_dev_ops = { - .bind = mt6359dcxo_bind, - .unbind = mt6359dcxo_unbind, - .get_temp = mt6359dcxo_get_temp, - .get_mode = mt6359dcxo_get_mode, - .set_mode = mt6359dcxo_set_mode, - .get_trip_type = mt6359dcxo_get_trip_type, - .get_trip_temp = mt6359dcxo_get_trip_temp, - .get_crit_temp = mt6359dcxo_get_crit_temp, -}; - -static int mt6359dcxo_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359dcxo_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359dcxo_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359dcxo OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359dcxo_cooling_sysrst_ops = { - .get_max_state = mt6359dcxo_sysrst_get_max_state, - .get_cur_state = mt6359dcxo_sysrst_get_cur_state, - .set_cur_state = mt6359dcxo_sysrst_set_cur_state, -}; - -static int mt6359dcxo_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359dcxo_register_thermal(void); -static void mt6359dcxo_unregister_thermal(void); - -static ssize_t mt6359dcxo_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359dcxo_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359dcxo_data *ptr_mt6359dcxo_data; - - ptr_mt6359dcxo_data = - kmalloc(sizeof(*ptr_mt6359dcxo_data), GFP_KERNEL); - - if (ptr_mt6359dcxo_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359dcxo_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359dcxo_data->desc) - 1); - - if (copy_from_user(ptr_mt6359dcxo_data->desc, buffer, len)) { - kfree(ptr_mt6359dcxo_data); - return 0; - } - - ptr_mt6359dcxo_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359dcxo_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359dcxo_data->trip[0], - &ptr_mt6359dcxo_data->t_type[0], - ptr_mt6359dcxo_data->bind0, - &ptr_mt6359dcxo_data->trip[1], - &ptr_mt6359dcxo_data->t_type[1], - ptr_mt6359dcxo_data->bind1, - &ptr_mt6359dcxo_data->trip[2], - &ptr_mt6359dcxo_data->t_type[2], - ptr_mt6359dcxo_data->bind2, - &ptr_mt6359dcxo_data->trip[3], - &ptr_mt6359dcxo_data->t_type[3], - ptr_mt6359dcxo_data->bind3, - &ptr_mt6359dcxo_data->trip[4], - &ptr_mt6359dcxo_data->t_type[4], - ptr_mt6359dcxo_data->bind4, - &ptr_mt6359dcxo_data->trip[5], - &ptr_mt6359dcxo_data->t_type[5], - ptr_mt6359dcxo_data->bind5, - &ptr_mt6359dcxo_data->trip[6], - &ptr_mt6359dcxo_data->t_type[6], - ptr_mt6359dcxo_data->bind6, - &ptr_mt6359dcxo_data->trip[7], - &ptr_mt6359dcxo_data->t_type[7], - ptr_mt6359dcxo_data->bind7, - &ptr_mt6359dcxo_data->trip[8], - &ptr_mt6359dcxo_data->t_type[8], - ptr_mt6359dcxo_data->bind8, - &ptr_mt6359dcxo_data->trip[9], - &ptr_mt6359dcxo_data->t_type[9], - ptr_mt6359dcxo_data->bind9, - &ptr_mt6359dcxo_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359dcxo_unregister_thermal\n", __func__); - mt6359dcxo_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359dcxo_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359dcxo_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359dcxo_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359dcxo_data->bind0[i]; - g_bind1[i] = ptr_mt6359dcxo_data->bind1[i]; - g_bind2[i] = ptr_mt6359dcxo_data->bind2[i]; - g_bind3[i] = ptr_mt6359dcxo_data->bind3[i]; - g_bind4[i] = ptr_mt6359dcxo_data->bind4[i]; - g_bind5[i] = ptr_mt6359dcxo_data->bind5[i]; - g_bind6[i] = ptr_mt6359dcxo_data->bind6[i]; - g_bind7[i] = ptr_mt6359dcxo_data->bind7[i]; - g_bind8[i] = ptr_mt6359dcxo_data->bind8[i]; - g_bind9[i] = ptr_mt6359dcxo_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359dcxo_data->trip[i]; - - interval = ptr_mt6359dcxo_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359dcxo_register_thermal\n", __func__); - - mt6359dcxo_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359dcxo_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359dcxo_write", "Bad argument"); - #endif - kfree(ptr_mt6359dcxo_data); - return -EINVAL; -} - -static void mt6359dcxo_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359dcxo_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359dcxo_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359dcxo-sysrst", NULL, - &mt6359dcxo_cooling_sysrst_ops); - return 0; -} - -static int mt6359dcxo_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359dcxo", num_trip, NULL, - &mt6359dcxo_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359dcxo_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359dcxo_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359dcxo_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359dcxo_read, NULL); -} - -static const struct file_operations mt6359dcxo_fops = { - .owner = THIS_MODULE, - .open = mt6359dcxo_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359dcxo_write, - .release = single_release, -}; - -static int __init mt6359dcxo_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359dcxo_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359dcxo_register_cooler(); - if (err) - return err; - - mt6359dcxo_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359dcxo_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359dcxo", 664, mt6359dcxo_dir, - &mt6359dcxo_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359dcxo", mt6359dcxo_start_thermal_timer, - mt6359dcxo_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359dcxo_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359dcxo_unregister_thermal(); - mt6359dcxo_unregister_cooler(); - mtkTTimer_unregister("mt6359dcxo"); -} -module_init(mt6359dcxo_init); -module_exit(mt6359dcxo_exit); diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359tsx.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359tsx.c deleted file mode 100644 index ebb4a84355a3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359tsx.c +++ /dev/null @@ -1,597 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359tsx_cur_temp; -/* - *static long int mt6359tsx_start_temp; - *static long int mt6359tsx_end_temp; - */ -/*=============================================================*/ - -static int mt6359tsx_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359tsx_get_hw_temp(); - mt6359tsx_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359tsx_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359tsx_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359tsx_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359tsx_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359tsx_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359tsx_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359tsx_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359tsx_dev_ops = { - .bind = mt6359tsx_bind, - .unbind = mt6359tsx_unbind, - .get_temp = mt6359tsx_get_temp, - .get_mode = mt6359tsx_get_mode, - .set_mode = mt6359tsx_set_mode, - .get_trip_type = mt6359tsx_get_trip_type, - .get_trip_temp = mt6359tsx_get_trip_temp, - .get_crit_temp = mt6359tsx_get_crit_temp, -}; - -static int mt6359tsx_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359tsx_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359tsx_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359tsx OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359tsx_cooling_sysrst_ops = { - .get_max_state = mt6359tsx_sysrst_get_max_state, - .get_cur_state = mt6359tsx_sysrst_get_cur_state, - .set_cur_state = mt6359tsx_sysrst_set_cur_state, -}; - -static int mt6359tsx_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359tsx_register_thermal(void); -static void mt6359tsx_unregister_thermal(void); - -static ssize_t mt6359tsx_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359tsx_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359tsx_data *ptr_mt6359tsx_data; - - ptr_mt6359tsx_data = - kmalloc(sizeof(*ptr_mt6359tsx_data), GFP_KERNEL); - - if (ptr_mt6359tsx_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359tsx_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359tsx_data->desc) - 1); - - if (copy_from_user(ptr_mt6359tsx_data->desc, buffer, len)) { - kfree(ptr_mt6359tsx_data); - return 0; - } - - ptr_mt6359tsx_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359tsx_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359tsx_data->trip[0], - &ptr_mt6359tsx_data->t_type[0], - ptr_mt6359tsx_data->bind0, - &ptr_mt6359tsx_data->trip[1], - &ptr_mt6359tsx_data->t_type[1], - ptr_mt6359tsx_data->bind1, - &ptr_mt6359tsx_data->trip[2], - &ptr_mt6359tsx_data->t_type[2], - ptr_mt6359tsx_data->bind2, - &ptr_mt6359tsx_data->trip[3], - &ptr_mt6359tsx_data->t_type[3], - ptr_mt6359tsx_data->bind3, - &ptr_mt6359tsx_data->trip[4], - &ptr_mt6359tsx_data->t_type[4], - ptr_mt6359tsx_data->bind4, - &ptr_mt6359tsx_data->trip[5], - &ptr_mt6359tsx_data->t_type[5], - ptr_mt6359tsx_data->bind5, - &ptr_mt6359tsx_data->trip[6], - &ptr_mt6359tsx_data->t_type[6], - ptr_mt6359tsx_data->bind6, - &ptr_mt6359tsx_data->trip[7], - &ptr_mt6359tsx_data->t_type[7], - ptr_mt6359tsx_data->bind7, - &ptr_mt6359tsx_data->trip[8], - &ptr_mt6359tsx_data->t_type[8], - ptr_mt6359tsx_data->bind8, - &ptr_mt6359tsx_data->trip[9], - &ptr_mt6359tsx_data->t_type[9], - ptr_mt6359tsx_data->bind9, - &ptr_mt6359tsx_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359tsx_unregister_thermal\n", __func__); - mt6359tsx_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359tsx_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359tsx_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359tsx_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359tsx_data->bind0[i]; - g_bind1[i] = ptr_mt6359tsx_data->bind1[i]; - g_bind2[i] = ptr_mt6359tsx_data->bind2[i]; - g_bind3[i] = ptr_mt6359tsx_data->bind3[i]; - g_bind4[i] = ptr_mt6359tsx_data->bind4[i]; - g_bind5[i] = ptr_mt6359tsx_data->bind5[i]; - g_bind6[i] = ptr_mt6359tsx_data->bind6[i]; - g_bind7[i] = ptr_mt6359tsx_data->bind7[i]; - g_bind8[i] = ptr_mt6359tsx_data->bind8[i]; - g_bind9[i] = ptr_mt6359tsx_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359tsx_data->trip[i]; - - interval = ptr_mt6359tsx_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359tsx_register_thermal\n", __func__); - - mt6359tsx_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359tsx_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359tsx_write", "Bad argument"); - #endif - kfree(ptr_mt6359tsx_data); - return -EINVAL; -} - -static void mt6359tsx_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359tsx_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359tsx_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359tsx-sysrst", NULL, - &mt6359tsx_cooling_sysrst_ops); - return 0; -} - -static int mt6359tsx_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359tsx", num_trip, NULL, - &mt6359tsx_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359tsx_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359tsx_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359tsx_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359tsx_read, NULL); -} - -static const struct file_operations mt6359tsx_fops = { - .owner = THIS_MODULE, - .open = mt6359tsx_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359tsx_write, - .release = single_release, -}; - -static int __init mt6359tsx_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359tsx_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359tsx_register_cooler(); - if (err) - return err; - - mt6359tsx_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359tsx_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359tsx", 664, mt6359tsx_dir, - &mt6359tsx_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359tsx", mt6359tsx_start_thermal_timer, - mt6359tsx_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359tsx_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359tsx_unregister_thermal(); - mt6359tsx_unregister_cooler(); - mtkTTimer_unregister("mt6359tsx"); -} -module_init(mt6359tsx_init); -module_exit(mt6359tsx_exit); diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vcore.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vcore.c deleted file mode 100644 index de97228b3353..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vcore.c +++ /dev/null @@ -1,595 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vcore_cur_temp; -/* - *static long int mt6359vcore_start_temp; - *static long int mt6359vcore_end_temp; - */ -/*=============================================================*/ - -static int mt6359vcore_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vcore_get_hw_temp(); - mt6359vcore_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vcore_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vcore_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vcore_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vcore_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vcore_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vcore_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vcore_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vcore_dev_ops = { - .bind = mt6359vcore_bind, - .unbind = mt6359vcore_unbind, - .get_temp = mt6359vcore_get_temp, - .get_mode = mt6359vcore_get_mode, - .set_mode = mt6359vcore_set_mode, - .get_trip_type = mt6359vcore_get_trip_type, - .get_trip_temp = mt6359vcore_get_trip_temp, - .get_crit_temp = mt6359vcore_get_crit_temp, -}; - -static int mt6359vcore_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vcore_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vcore_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vcore OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vcore_cooling_sysrst_ops = { - .get_max_state = mt6359vcore_sysrst_get_max_state, - .get_cur_state = mt6359vcore_sysrst_get_cur_state, - .set_cur_state = mt6359vcore_sysrst_set_cur_state, -}; - -static int mt6359vcore_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vcore_register_thermal(void); -static void mt6359vcore_unregister_thermal(void); - -static ssize_t mt6359vcore_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vcore_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vcore_data *ptr_mt6359vcore_data; - - ptr_mt6359vcore_data = - kmalloc(sizeof(*ptr_mt6359vcore_data), GFP_KERNEL); - - if (ptr_mt6359vcore_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vcore_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vcore_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vcore_data->desc, buffer, len)) { - kfree(ptr_mt6359vcore_data); - return 0; - } - - ptr_mt6359vcore_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vcore_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vcore_data->trip[0], - &ptr_mt6359vcore_data->t_type[0], - ptr_mt6359vcore_data->bind0, - &ptr_mt6359vcore_data->trip[1], - &ptr_mt6359vcore_data->t_type[1], - ptr_mt6359vcore_data->bind1, - &ptr_mt6359vcore_data->trip[2], - &ptr_mt6359vcore_data->t_type[2], - ptr_mt6359vcore_data->bind2, - &ptr_mt6359vcore_data->trip[3], - &ptr_mt6359vcore_data->t_type[3], - ptr_mt6359vcore_data->bind3, - &ptr_mt6359vcore_data->trip[4], - &ptr_mt6359vcore_data->t_type[4], - ptr_mt6359vcore_data->bind4, - &ptr_mt6359vcore_data->trip[5], - &ptr_mt6359vcore_data->t_type[5], - ptr_mt6359vcore_data->bind5, - &ptr_mt6359vcore_data->trip[6], - &ptr_mt6359vcore_data->t_type[6], - ptr_mt6359vcore_data->bind6, - &ptr_mt6359vcore_data->trip[7], - &ptr_mt6359vcore_data->t_type[7], - ptr_mt6359vcore_data->bind7, - &ptr_mt6359vcore_data->trip[8], - &ptr_mt6359vcore_data->t_type[8], - ptr_mt6359vcore_data->bind8, - &ptr_mt6359vcore_data->trip[9], - &ptr_mt6359vcore_data->t_type[9], - ptr_mt6359vcore_data->bind9, - &ptr_mt6359vcore_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vcore_unregister_thermal\n", __func__); - mt6359vcore_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vcore_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - kfree(ptr_mt6359vcore_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vcore_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vcore_data->bind0[i]; - g_bind1[i] = ptr_mt6359vcore_data->bind1[i]; - g_bind2[i] = ptr_mt6359vcore_data->bind2[i]; - g_bind3[i] = ptr_mt6359vcore_data->bind3[i]; - g_bind4[i] = ptr_mt6359vcore_data->bind4[i]; - g_bind5[i] = ptr_mt6359vcore_data->bind5[i]; - g_bind6[i] = ptr_mt6359vcore_data->bind6[i]; - g_bind7[i] = ptr_mt6359vcore_data->bind7[i]; - g_bind8[i] = ptr_mt6359vcore_data->bind8[i]; - g_bind9[i] = ptr_mt6359vcore_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vcore_data->trip[i]; - - interval = ptr_mt6359vcore_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vcore_register_thermal\n", __func__); - - mt6359vcore_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vcore_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vcore_write", "Bad argument"); - #endif - kfree(ptr_mt6359vcore_data); - return -EINVAL; -} - -static void mt6359vcore_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vcore_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vcore_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vcore-sysrst", NULL, - &mt6359vcore_cooling_sysrst_ops); - return 0; -} - -static int mt6359vcore_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vcore", num_trip, NULL, - &mt6359vcore_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vcore_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vcore_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vcore_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vcore_read, NULL); -} - -static const struct file_operations mt6359vcore_fops = { - .owner = THIS_MODULE, - .open = mt6359vcore_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vcore_write, - .release = single_release, -}; - -static int __init mt6359vcore_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vcore_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vcore_register_cooler(); - if (err) - return err; - - mt6359vcore_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vcore_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359vcore", 664, mt6359vcore_dir, - &mt6359vcore_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vcore", mt6359vcore_start_thermal_timer, - mt6359vcore_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vcore_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vcore_unregister_thermal(); - mt6359vcore_unregister_cooler(); - mtkTTimer_unregister("mt6359vcore"); -} -module_init(mt6359vcore_init); -module_exit(mt6359vcore_exit); diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vgpu.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vgpu.c deleted file mode 100644 index da97b43c967a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vgpu.c +++ /dev/null @@ -1,606 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vgpu_cur_temp; -/* - *static long int mt6359vgpu_start_temp; - *static long int mt6359vgpu_end_temp; - */ -/*=============================================================*/ - -static int mt6359vgpu_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vgpu_get_hw_temp(); - mt6359vgpu_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vgpu_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vgpu_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vgpu_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vgpu_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vgpu_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vgpu_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vgpu_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vgpu_dev_ops = { - .bind = mt6359vgpu_bind, - .unbind = mt6359vgpu_unbind, - .get_temp = mt6359vgpu_get_temp, - .get_mode = mt6359vgpu_get_mode, - .set_mode = mt6359vgpu_set_mode, - .get_trip_type = mt6359vgpu_get_trip_type, - .get_trip_temp = mt6359vgpu_get_trip_temp, - .get_crit_temp = mt6359vgpu_get_crit_temp, -}; - -static int mt6359vgpu_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vgpu_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vgpu_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vgpu OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vgpu_cooling_sysrst_ops = { - .get_max_state = mt6359vgpu_sysrst_get_max_state, - .get_cur_state = mt6359vgpu_sysrst_get_cur_state, - .set_cur_state = mt6359vgpu_sysrst_set_cur_state, -}; - -static int mt6359vgpu_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vgpu_register_thermal(void); -static void mt6359vgpu_unregister_thermal(void); - -static ssize_t mt6359vgpu_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vgpu_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vgpu_data *ptr_mt6359vgpu_data; - - ptr_mt6359vgpu_data = - kmalloc(sizeof(*ptr_mt6359vgpu_data), GFP_KERNEL); - - if (ptr_mt6359vgpu_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vgpu_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vgpu_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vgpu_data->desc, buffer, len)) { - kfree(ptr_mt6359vgpu_data); - return 0; - } - - ptr_mt6359vgpu_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vgpu_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vgpu_data->trip[0], - &ptr_mt6359vgpu_data->t_type[0], - ptr_mt6359vgpu_data->bind0, - &ptr_mt6359vgpu_data->trip[1], - &ptr_mt6359vgpu_data->t_type[1], - ptr_mt6359vgpu_data->bind1, - &ptr_mt6359vgpu_data->trip[2], - &ptr_mt6359vgpu_data->t_type[2], - ptr_mt6359vgpu_data->bind2, - &ptr_mt6359vgpu_data->trip[3], - &ptr_mt6359vgpu_data->t_type[3], - ptr_mt6359vgpu_data->bind3, - &ptr_mt6359vgpu_data->trip[4], - &ptr_mt6359vgpu_data->t_type[4], - ptr_mt6359vgpu_data->bind4, - &ptr_mt6359vgpu_data->trip[5], - &ptr_mt6359vgpu_data->t_type[5], - ptr_mt6359vgpu_data->bind5, - &ptr_mt6359vgpu_data->trip[6], - &ptr_mt6359vgpu_data->t_type[6], - ptr_mt6359vgpu_data->bind6, - &ptr_mt6359vgpu_data->trip[7], - &ptr_mt6359vgpu_data->t_type[7], - ptr_mt6359vgpu_data->bind7, - &ptr_mt6359vgpu_data->trip[8], - &ptr_mt6359vgpu_data->t_type[8], - ptr_mt6359vgpu_data->bind8, - &ptr_mt6359vgpu_data->trip[9], - &ptr_mt6359vgpu_data->t_type[9], - ptr_mt6359vgpu_data->bind9, - &ptr_mt6359vgpu_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vgpu_unregister_thermal\n", __func__); - - mt6359vgpu_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vgpu_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vgpu_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vgpu_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vgpu_data->bind0[i]; - g_bind1[i] = ptr_mt6359vgpu_data->bind1[i]; - g_bind2[i] = ptr_mt6359vgpu_data->bind2[i]; - g_bind3[i] = ptr_mt6359vgpu_data->bind3[i]; - g_bind4[i] = ptr_mt6359vgpu_data->bind4[i]; - g_bind5[i] = ptr_mt6359vgpu_data->bind5[i]; - g_bind6[i] = ptr_mt6359vgpu_data->bind6[i]; - g_bind7[i] = ptr_mt6359vgpu_data->bind7[i]; - g_bind8[i] = ptr_mt6359vgpu_data->bind8[i]; - g_bind9[i] = ptr_mt6359vgpu_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vgpu_data->trip[i]; - - interval = ptr_mt6359vgpu_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vgpu_register_thermal\n", __func__); - - mt6359vgpu_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vgpu_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vgpu_write", "Bad argument"); - #endif - kfree(ptr_mt6359vgpu_data); - return -EINVAL; -} - -static void mt6359vgpu_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vgpu_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vgpu_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vgpu-sysrst", NULL, - &mt6359vgpu_cooling_sysrst_ops); - return 0; -} - -static int mt6359vgpu_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vgpu", num_trip, NULL, - &mt6359vgpu_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vgpu_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vgpu_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vgpu_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vgpu_read, NULL); -} - -static const struct file_operations mt6359vgpu_fops = { - .owner = THIS_MODULE, - .open = mt6359vgpu_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vgpu_write, - .release = single_release, -}; - -static int __init mt6359vgpu_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vgpu_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vgpu_register_cooler(); - if (err) - return err; - - mt6359vgpu_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vgpu_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - - } else { - entry = - proc_create("tz6359vgpu", 664, mt6359vgpu_dir, - &mt6359vgpu_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vgpu", mt6359vgpu_start_thermal_timer, - mt6359vgpu_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vgpu_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vgpu_unregister_thermal(); - mt6359vgpu_unregister_cooler(); - mtkTTimer_unregister("mt6359vgpu"); -} -module_init(mt6359vgpu_init); -module_exit(mt6359vgpu_exit); diff --git a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vproc.c b/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vproc.c deleted file mode 100644 index 48ce031106ee..000000000000 --- a/drivers/misc/mediatek/thermal/mt6873/src/mtk_ts_6359vproc.c +++ /dev/null @@ -1,604 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vproc_cur_temp; -/* - *static long int mt6359vproc_start_temp; - *static long int mt6359vproc_end_temp; - */ -/*=============================================================*/ - -static int mt6359vproc_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vproc_get_hw_temp(); - mt6359vproc_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vproc_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vproc_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vproc_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vproc_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vproc_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vproc_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vproc_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vproc_dev_ops = { - .bind = mt6359vproc_bind, - .unbind = mt6359vproc_unbind, - .get_temp = mt6359vproc_get_temp, - .get_mode = mt6359vproc_get_mode, - .set_mode = mt6359vproc_set_mode, - .get_trip_type = mt6359vproc_get_trip_type, - .get_trip_temp = mt6359vproc_get_trip_temp, - .get_crit_temp = mt6359vproc_get_crit_temp, -}; - -static int mt6359vproc_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vproc_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vproc_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vproc OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vproc_cooling_sysrst_ops = { - .get_max_state = mt6359vproc_sysrst_get_max_state, - .get_cur_state = mt6359vproc_sysrst_get_cur_state, - .set_cur_state = mt6359vproc_sysrst_set_cur_state, -}; - -static int mt6359vproc_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vproc_register_thermal(void); -static void mt6359vproc_unregister_thermal(void); - -static ssize_t mt6359vproc_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vproc_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vproc_data *ptr_mt6359vproc_data; - - ptr_mt6359vproc_data = - kmalloc(sizeof(*ptr_mt6359vproc_data), GFP_KERNEL); - - if (ptr_mt6359vproc_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vproc_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vproc_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vproc_data->desc, buffer, len)) { - kfree(ptr_mt6359vproc_data); - return 0; - } - - ptr_mt6359vproc_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vproc_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vproc_data->trip[0], - &ptr_mt6359vproc_data->t_type[0], - ptr_mt6359vproc_data->bind0, - &ptr_mt6359vproc_data->trip[1], - &ptr_mt6359vproc_data->t_type[1], - ptr_mt6359vproc_data->bind1, - &ptr_mt6359vproc_data->trip[2], - &ptr_mt6359vproc_data->t_type[2], - ptr_mt6359vproc_data->bind2, - &ptr_mt6359vproc_data->trip[3], - &ptr_mt6359vproc_data->t_type[3], - ptr_mt6359vproc_data->bind3, - &ptr_mt6359vproc_data->trip[4], - &ptr_mt6359vproc_data->t_type[4], - ptr_mt6359vproc_data->bind4, - &ptr_mt6359vproc_data->trip[5], - &ptr_mt6359vproc_data->t_type[5], - ptr_mt6359vproc_data->bind5, - &ptr_mt6359vproc_data->trip[6], - &ptr_mt6359vproc_data->t_type[6], - ptr_mt6359vproc_data->bind6, - &ptr_mt6359vproc_data->trip[7], - &ptr_mt6359vproc_data->t_type[7], - ptr_mt6359vproc_data->bind7, - &ptr_mt6359vproc_data->trip[8], - &ptr_mt6359vproc_data->t_type[8], - ptr_mt6359vproc_data->bind8, - &ptr_mt6359vproc_data->trip[9], - &ptr_mt6359vproc_data->t_type[9], - ptr_mt6359vproc_data->bind9, - &ptr_mt6359vproc_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk("[%s] mt6359vproc_unregister_thermal\n", - __func__); - - mt6359vproc_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vproc_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vproc_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vproc_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vproc_data->bind0[i]; - g_bind1[i] = ptr_mt6359vproc_data->bind1[i]; - g_bind2[i] = ptr_mt6359vproc_data->bind2[i]; - g_bind3[i] = ptr_mt6359vproc_data->bind3[i]; - g_bind4[i] = ptr_mt6359vproc_data->bind4[i]; - g_bind5[i] = ptr_mt6359vproc_data->bind5[i]; - g_bind6[i] = ptr_mt6359vproc_data->bind6[i]; - g_bind7[i] = ptr_mt6359vproc_data->bind7[i]; - g_bind8[i] = ptr_mt6359vproc_data->bind8[i]; - g_bind9[i] = ptr_mt6359vproc_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vproc_data->trip[i]; - - interval = ptr_mt6359vproc_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk("[%s] mt6359vproc_register_thermal\n", - __func__); - - mt6359vproc_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vproc_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vproc_write", "Bad argument"); - #endif - kfree(ptr_mt6359vproc_data); - return -EINVAL; -} - -static void mt6359vproc_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vproc_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vproc_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vproc-sysrst", NULL, - &mt6359vproc_cooling_sysrst_ops); - return 0; -} - -static int mt6359vproc_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vproc", num_trip, NULL, - &mt6359vproc_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vproc_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vproc_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vproc_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vproc_read, NULL); -} - -static const struct file_operations mt6359vproc_fops = { - .owner = THIS_MODULE, - .open = mt6359vproc_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vproc_write, - .release = single_release, -}; - -static int __init mt6359vproc_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vproc_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vproc_register_cooler(); - if (err) - return err; - - mt6359vproc_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vproc_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6359vproc", 664, mt6359vproc_dir, - &mt6359vproc_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vproc", mt6359vproc_start_thermal_timer, - mt6359vproc_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vproc_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vproc_unregister_thermal(); - mt6359vproc_unregister_cooler(); - mtkTTimer_unregister("mt6359vproc"); -} -module_init(mt6359vproc_init); -module_exit(mt6359vproc_exit); diff --git a/drivers/misc/mediatek/thermal/mt6877/Makefile b/drivers/misc/mediatek/thermal/mt6877/Makefile deleted file mode 100644 index 2a09370d533f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6877/inc/clatm_initcfg.h deleted file mode 100644 index 8a1d1724b035..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/clatm_initcfg.h +++ /dev/null @@ -1,71 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (75000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (3960) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_1_TARGET_TJ (65000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (3000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (75000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3960) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (600) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (50) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (50) - -#define CLATM_USE_MIN_CPU_OPP (1) - -#define CLATM_CONFIGURABLE_TIMER - - - -#define POLLING_TRIP_TEMP0 55000 -#define POLLING_TRIP_TEMP1 45000 -#define POLLING_TRIP_TEMP2 40000 - -#define POLLING_FACTOR0 10 -#define POLLING_FACTOR1 2 -#define POLLING_FACTOR2 4 - - -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/mach/mtk_thermal.h b/drivers/misc/mediatek/thermal/mt6877/inc/mach/mtk_thermal.h deleted file mode 100644 index 84e94915c164..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/mach/mtk_thermal.h +++ /dev/null @@ -1,236 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __MT6785_THERMAL_H__ -#define __MT6785_THERMAL_H__ - -#include -#include -#include -#include - -#include -#include - -#include "mt-plat/sync_write.h" - -#include "mtk_gpufreq.h" - -#include "mtk_thermal_typedefs.h" - -/*============================================================= - * LVTS SW Configs - *============================================================= - */ -#define CFG_THERM_LVTS (1) -#define CFG_THERM_NO_AUXADC (1) - -#if CFG_THERM_LVTS -#define CFG_LVTS_DOMINATOR (1) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (1) /* 1, 2, 4, 8, 16 */ -#define LVTS_DEVICE_AUTO_RCK (0) -#define CFG_LVTS_MCU_INTERRUPT_HANDLER (1) -/*Use bootup "count RC", no need to get "count RC" again after resume*/ -#define CFG_THERM_USE_BOOTUP_COUNT_RC -#else -#define CFG_LVTS_DOMINATOR (0) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (0) -#define LVTS_DEVICE_AUTO_RCK (0) -#endif - -/* - *There is no idle code in kernel since mt6885(big sw). - *Thus, kernel only can use "cpu pm notifier" to do idle scenario things. - * - *Release LVTS in thermal kernel driver - *1. SPM will pause LVTS thermal controllers before closing 26M - *2. After leaving SODI3, SPM will release LVTS thermal controllers - * if controllers were paused properly. - *3. After leaving SODI3, Thermal driver will release LVTS thermal - * controllers if SPM didn't release controller successfully - */ -#define LVTS_CPU_PM_NTFY_CALLBACK - -#if defined(LVTS_CPU_PM_NTFY_CALLBACK) -#define CFG_THERM_SODI3_RELEASE -//#define LVTS_CPU_PM_NTFY_PROFILE -#endif - -/* public thermal sensor enum */ - -enum thermal_sensor { -#if CFG_THERM_LVTS - TS_LVTS1_0 = 0, /* LVTS1-0 Big */ - TS_LVTS1_1, /* LVTS1-1 Big */ - TS_LVTS2_0, /* LVTS2-0 Little */ - TS_LVTS2_1, /* LVTS2-1 Little */ - TS_LVTS2_2, /* LVTS2-2 Little */ - TS_LVTS2_3, /* LVTS2-3 Little */ - TS_LVTS3_0, /* LVTS3-0 GPU */ - TS_LVTS3_1, /* LVTS3-1 GPU */ - TS_LVTS3_2, /* LVTS3-2 VP */ - TS_LVTS3_3, /* LVTS3-3 VP */ - TS_LVTS4_0, /* LVTS4-0 VPU */ - TS_LVTS4_1, /* LVTS4-1 VPU */ - TS_LVTS5_0, /* LVTS5-0 MD-4G */ - TS_LVTS5_1, /* LVTS5-1 MD-5G */ - TS_LVTS5_2, /* LVTS5-2 MD-3G */ - -#endif - TS_ENUM_MAX -}; - -enum thermal_bank_name { - THERMAL_BANK0 = 0, - THERMAL_BANK1, - THERMAL_BANK2, - THERMAL_BANK3, - THERMAL_BANK4, - THERMAL_BANK5, - THERMAL_BANK_NUM -}; - -struct TS_PTPOD { - unsigned int ts_MTS; - unsigned int ts_BTS; -}; - -extern int mtktscpu_limited_dmips; -extern int tscpu_get_temperature_range(void); - -/* Valid if it returns 1, invalid if it returns 0. */ -extern int tscpu_is_temp_valid(void); - -extern void get_thermal_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); - -#if CFG_THERM_LVTS -extern void get_lvts_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); -#endif - -extern void set_taklking_flag(bool flag); - -extern int tscpu_get_cpu_temp(void); - -extern int tscpu_get_temp_by_bank(enum thermal_bank_name ts_bank); - -#define THERMAL_WRAP_WR32(val, addr) \ - mt_reg_sync_writel((val), ((void *)addr)) - -extern int get_immediate_cpuL_wrap(void); -extern int get_immediate_cpuB_wrap(void); -extern int get_immediate_mcucci_wrap(void); -extern int get_immediate_gpu_wrap(void); -extern int get_immediate_vpu_wrap(void); -extern int get_immediate_top_wrap(void); -extern int get_immediate_md_wrap(void); - -/* Added for DLPT/EARA */ -extern int tscpu_get_min_cpu_pwr(void); -extern int tscpu_get_min_gpu_pwr(void); -extern int tscpu_get_min_vpu_pwr(void); -extern int tscpu_get_min_mdla_pwr(void); - -extern void lvts_ipi_send_efuse_data(void); -extern void lvts_ipi_send_sspm_thermal_thtottle(void); -extern void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend); - -/* Five thermal sensors. */ -enum mtk_thermal_sensor_cpu_id_met { -#if CFG_THERM_LVTS - MTK_THERMAL_SENSOR_LVTS1_0, - MTK_THERMAL_SENSOR_LVTS1_1, - MTK_THERMAL_SENSOR_LVTS2_0, - MTK_THERMAL_SENSOR_LVTS2_1, - MTK_THERMAL_SENSOR_LVTS2_2, - MTK_THERMAL_SENSOR_LVTS2_3, - MTK_THERMAL_SENSOR_LVTS3_0, - MTK_THERMAL_SENSOR_LVTS3_1, - MTK_THERMAL_SENSOR_LVTS3_2, - MTK_THERMAL_SENSOR_LVTS3_3, - MTK_THERMAL_SENSOR_LVTS4_0, - MTK_THERMAL_SENSOR_LVTS4_1, - MTK_THERMAL_SENSOR_LVTS5_0, - MTK_THERMAL_SENSOR_LVTS5_1, - MTK_THERMAL_SENSOR_LVTS5_2, -#endif - ATM_CPU_LIMIT, - ATM_GPU_LIMIT, - - MTK_THERMAL_SENSOR_CPU_COUNT -}; - -extern int tscpu_get_cpu_temp_met(enum mtk_thermal_sensor_cpu_id_met id); - -typedef void (*met_thermalsampler_funcMET)(void); - -extern void mt_thermalsampler_registerCB(met_thermalsampler_funcMET pCB); - -extern void mtkTTimer_cancel_timer(void); - -extern void mtkTTimer_start_timer(void); - -extern int mtkts_bts_get_hw_temp(void); - -extern int get_immediate_ts0_wrap(void); -extern int get_immediate_ts1_wrap(void); -extern int get_immediate_ts2_wrap(void); -extern int get_immediate_ts3_wrap(void); -extern int get_immediate_ts4_wrap(void); -extern int get_immediate_ts5_wrap(void); -extern int get_immediate_ts6_wrap(void); -extern int get_immediate_ts7_wrap(void); -extern int get_immediate_ts8_wrap(void); -extern int get_immediate_ts9_wrap(void); - -#if CFG_THERM_LVTS -extern int get_immediate_tslvts1_0_wrap(void); -extern int get_immediate_tslvts1_1_wrap(void); -extern int get_immediate_tslvts2_0_wrap(void); -extern int get_immediate_tslvts2_1_wrap(void); -extern int get_immediate_tslvts2_2_wrap(void); -extern int get_immediate_tslvts2_3_wrap(void); -extern int get_immediate_tslvts3_0_wrap(void); -extern int get_immediate_tslvts3_1_wrap(void); -extern int get_immediate_tslvts3_2_wrap(void); -extern int get_immediate_tslvts3_3_wrap(void); -extern int get_immediate_tslvts4_0_wrap(void); -extern int get_immediate_tslvts4_1_wrap(void); -extern int get_immediate_tslvts5_0_wrap(void); -extern int get_immediate_tslvts5_1_wrap(void); -extern int get_immediate_tslvts5_2_wrap(void); -#endif - -extern int get_immediate_tsabb_wrap(void); - -extern int (*get_immediate_tsX[TS_ENUM_MAX])(void); - -extern int is_cpu_power_unlimit(void); /* in mtk_ts_cpu.c */ - -extern int is_cpu_power_min(void); /* in mtk_ts_cpu.c */ - -extern int get_cpu_target_tj(void); - -extern int get_cpu_target_offset(void); - -extern int mtk_gpufreq_register( - struct mt_gpufreq_power_table_info *freqs, int num); - - -extern int get_target_tj(void); - -extern int mtk_thermal_get_tpcb_target(void); - -extern void thermal_set_big_core_speed( -unsigned int tempMonCtl1, unsigned int tempMonCtl2, unsigned int tempAhbPoll); - -/* - * return value(1): cooler of abcct/abcct_lcmoff is deactive, - * and no thermal current limit. - */ -extern int mtk_cooler_is_abcct_unlimit(void); - -extern int tscpu_kernel_status(void); -#endif /* __MT6785_THERMAL_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_cl_amddulthro.h b/drivers/misc/mediatek/thermal/mt6877/inc/mtk_cl_amddulthro.h deleted file mode 100644 index 3758a5645b66..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_cl_amddulthro.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __MT_CL_AMDDULTHRO_H__ -#define __MT_CL_AMDDULTHRO_H__ - -extern int amddulthro_backoff(int level); - -#endif /* __MT_CL_AMDDULTHRO_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6877/inc/mtk_cooler_setting.h deleted file mode 100644 index 8686e7739980..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - - -/*APU(mdla/vpu) throttle*/ -#define THERMAL_APU_UNLIMIT - -#if defined(THERMAL_APU_UNLIMIT) -extern unsigned int cl_get_apu_status(void); -extern void cl_set_apu_status(int vv); -#endif -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6877/inc/mtk_thermal_ipi.h deleted file mode 100644 index de3475957947..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,90 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#if defined(CONFIG_MTK_TINYSYS_SSPM_SUPPORT) && defined(CONFIG_MTK_TINYSYS_MCUPM_SUPPORT) -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (1) -#define THERMAL_SSPM_THERMAL_THROTTLE_SWITCH - -/*Only Big SW need to enable this definition - *Big SW suspend/resume flow: - * suspend: kernel suspend => SSPM suspend - * resume: SSPM resume => kernel resume - */ - -/* THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY means notify tinysys - * to start/stop reading temperature when kernel suspend/resume/shutdown - */ -#define THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY - -/* THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY_ONLY_AT_SHUTDOWN means - * notify tinysys to stop reading temperature only when kernel shutodown - */ -#ifdef THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY -#define THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY_ONLY_AT_SHUTDOWN -#endif - -#define THERMAL_CPUTOEB_USE_PLATFORM_IPI -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (0) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#include -#include - - -#define THERMAL_SLOT_NUM (4) -#define BIG_CORE_THRESHOLD_ARRAY_SIZE (3) -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_LVTS_INIT_GRP1, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_mcupm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern unsigned int thermal_to_sspm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6877/inc/mtk_ts_setting.h deleted file mode 100644 index fd26f045d1d3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/mtk_ts_setting.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (1) -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tmp_6311buck.h b/drivers/misc/mediatek/thermal/mt6877/inc/tmp_6311buck.h deleted file mode 100644 index b270b82c166f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tmp_6311buck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TMP_6311BUCK_H__ -#define __TMP_6311BUCK_H__ - -extern int is_ext_buck_exist(void); - -#endif /* __TMP_6311BUCK_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tmp_battery.h b/drivers/misc/mediatek/thermal/mt6877/inc/tmp_battery.h deleted file mode 100644 index 36052ddf87fc..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tmp_battery.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TMP_BATTERY_H__ -#define __TMP_BATTERY_H__ - -#include -/* Extern two API functions from battery driver - * to limit max charging current. - */ -/** - * return value means charging current in mA - * -1 means error - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int get_bat_charging_current_level(void); - -/** - * current_limit means limit of charging current in mA - * -1 means no limit - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int set_bat_charging_current_limit(int current_limit); -extern enum charger_type mt_get_charger_type(void); - -extern int read_tbat_value(void); - -#endif /* __TMP_BATTERY_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6877/inc/tmp_bts.h deleted file mode 100644 index 53396fb5418d..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tmp_bts.h +++ /dev/null @@ -1,56 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA -#define APPLY_PRECISE_BTS_TEMP - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) -#define AUX_IN2_NTC (2) - -#define BTS_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - - -#define BTSNRPA_RAP_PULL_UP_R 100000 /* 100K,pull up resister */ -#define BTSNRPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - *default value -40 deg - */ - -#define BTSNRPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ -#define BTSNRPA_RAP_NTC_TABLE 7 - -#define BTSNRPA_RAP_ADC_CHANNEL AUX_IN2_NTC - - - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_lvts_config.h b/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_lvts_config.h deleted file mode 100644 index 69ba549662eb..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_lvts_config.h +++ /dev/null @@ -1,94 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_LVTS_SETTINGS_H__ -#define __TSCPU_LVTS_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define LVTS_ADDRESS_INDEX_1 116 /* 0x11F101C0 */ -#define LVTS_ADDRESS_INDEX_2 117 /* 0x11F101C4 */ -#define LVTS_ADDRESS_INDEX_3 118 /* 0x11F101C8 */ -#define LVTS_ADDRESS_INDEX_4 119 /* 0x11F101CC */ -#define LVTS_ADDRESS_INDEX_5 190 /* 0x11F101D0 */ -#define LVTS_ADDRESS_INDEX_6 191 /* 0x11F101D4 */ -#define LVTS_ADDRESS_INDEX_7 192 /* 0x11F101D8 */ -#define LVTS_ADDRESS_INDEX_8 193 /* 0x11F101DC */ -#define LVTS_ADDRESS_INDEX_9 194 /* 0x11F101E0 */ -#define LVTS_ADDRESS_INDEX_10 195 /* 0x11F101E4 */ -#define LVTS_ADDRESS_INDEX_11 196 /* 0x11F101E8 */ -#define LVTS_ADDRESS_INDEX_12 197 /* 0x11F101EC */ -#define LVTS_ADDRESS_INDEX_13 198 /* 0x11F101F0 */ -#define LVTS_ADDRESS_INDEX_14 199 /* 0x11F101F4 */ -#define LVTS_ADDRESS_INDEX_15 200 /* 0x11F101F8 */ -#define LVTS_ADDRESS_INDEX_16 201 /* 0x11F101FC */ -#define LVTS_ADDRESS_INDEX_17 202 /* 0x11F10200 */ -#define LVTS_ADDRESS_INDEX_18 203 /* 0x11F10204 */ -#define LVTS_ADDRESS_INDEX_19 204 /* 0x11F10208 */ -#define LVTS_ADDRESS_INDEX_20 205 /* 0x11F1020C */ -#define LVTS_ADDRESS_INDEX_21 206 /* 0x11F10210 */ -#define LVTS_ADDRESS_INDEX_22 207 /* 0x11F10214 */ - - - - -/**************************************************************************** */ -/* LVTS related registers. */ -/**************************************************************************** */ -#define LVTSMONCTL0_0 (THERM_CTRL_BASE_2 + 0x000) -#define LVTSMONCTL1_0 (THERM_CTRL_BASE_2 + 0x004) -#define LVTSMONCTL2_0 (THERM_CTRL_BASE_2 + 0x008) -#define LVTSMONINT_0 (THERM_CTRL_BASE_2 + 0x00C) -#define LVTSMONINTSTS_0 (THERM_CTRL_BASE_2 + 0x010) -#define LVTSMONIDET0_0 (THERM_CTRL_BASE_2 + 0x014) -#define LVTSMONIDET1_0 (THERM_CTRL_BASE_2 + 0x018) -#define LVTSMONIDET2_0 (THERM_CTRL_BASE_2 + 0x01C) -#define LVTSMONIDET3_0 (THERM_CTRL_BASE_2 + 0x020) -#define LVTSH2NTHRE_0 (THERM_CTRL_BASE_2 + 0x024) -#define LVTSHTHRE_0 (THERM_CTRL_BASE_2 + 0x028) -#define LVTSCTHRE_0 (THERM_CTRL_BASE_2 + 0x02C) -#define LVTSOFFSETH_0 (THERM_CTRL_BASE_2 + 0x030) -#define LVTSOFFSETL_0 (THERM_CTRL_BASE_2 + 0x034) -#define LVTSMSRCTL0_0 (THERM_CTRL_BASE_2 + 0x038) -#define LVTSMSRCTL1_0 (THERM_CTRL_BASE_2 + 0x03C) -#define LVTSTSSEL_0 (THERM_CTRL_BASE_2 + 0x040) -#define LVTSDEVICETO_0 (THERM_CTRL_BASE_2 + 0x044) -#define LVTSCALSCALE_0 (THERM_CTRL_BASE_2 + 0x048) -#define LVTS_ID_0 (THERM_CTRL_BASE_2 + 0x04C) -#define LVTS_CONFIG_0 (THERM_CTRL_BASE_2 + 0x050) -#define LVTSEDATA00_0 (THERM_CTRL_BASE_2 + 0x054) -#define LVTSEDATA01_0 (THERM_CTRL_BASE_2 + 0x058) -#define LVTSEDATA02_0 (THERM_CTRL_BASE_2 + 0x05C) -#define LVTSEDATA03_0 (THERM_CTRL_BASE_2 + 0x060) -#define LVTSMSR0_0 (THERM_CTRL_BASE_2 + 0x090) -#define LVTSMSR1_0 (THERM_CTRL_BASE_2 + 0x094) -#define LVTSMSR2_0 (THERM_CTRL_BASE_2 + 0x098) -#define LVTSMSR3_0 (THERM_CTRL_BASE_2 + 0x09C) -#define LVTSIMMD0_0 (THERM_CTRL_BASE_2 + 0x0A0) -#define LVTSIMMD1_0 (THERM_CTRL_BASE_2 + 0x0A4) -#define LVTSIMMD2_0 (THERM_CTRL_BASE_2 + 0x0A8) -#define LVTSIMMD3_0 (THERM_CTRL_BASE_2 + 0x0AC) -#define LVTSRDATA0_0 (THERM_CTRL_BASE_2 + 0x0B0) -#define LVTSRDATA1_0 (THERM_CTRL_BASE_2 + 0x0B4) -#define LVTSRDATA2_0 (THERM_CTRL_BASE_2 + 0x0B8) -#define LVTSRDATA3_0 (THERM_CTRL_BASE_2 + 0x0BC) -#define LVTSPROTCTL_0 (THERM_CTRL_BASE_2 + 0x0C0) -#define LVTSPROTTA_0 (THERM_CTRL_BASE_2 + 0x0C4) -#define LVTSPROTTB_0 (THERM_CTRL_BASE_2 + 0x0C8) -#define LVTSPROTTC_0 (THERM_CTRL_BASE_2 + 0x0CC) -#define LVTSCLKEN_0 (THERM_CTRL_BASE_2 + 0x0E4) -#define LVTSDBGSEL_0 (THERM_CTRL_BASE_2 + 0x0E8) -#define LVTSDBGSIG_0 (THERM_CTRL_BASE_2 + 0x0EC) -#define LVTSSPARE0_0 (THERM_CTRL_BASE_2 + 0x0F0) -#define LVTSSPARE1_0 (THERM_CTRL_BASE_2 + 0x0F4) -#define LVTSSPARE2_0 (THERM_CTRL_BASE_2 + 0x0F8) -#define LVTSSPARE3_0 (THERM_CTRL_BASE_2 + 0x0FC) - -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) - -#endif /* __TSCPU_LVTS_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_settings.h deleted file mode 100644 index 0ffb3537560c..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_settings.h +++ /dev/null @@ -1,792 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include "mach/mtk_thermal.h" - -#include -#include - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" -#include "tscpu_tsense_config.h" -#include "tscpu_lvts_config.h" - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned int)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned int) -1 >> (31 - ((1) ? _bits_))) \ - & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() \ - long long thermal_pTime_us, thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_notice(TSCPU_LOG_TAG "%s: %llu us\n", __func__, \ - thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_notice(TSCPU_LOG_TAG \ - "Warning: tProfiling uses incorrect %s %d\n", \ - __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/*Enable thermal controller CG*/ -#define THERMAL_EBABLE_TC_CG - -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. - * Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -/* Define this in tscpu_settings.h enables this feature. - * It polls CPU TS in hrtimer and - * run ATM in RT 98 kthread. This is for MT6799 only. - */ -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) -#define CLEAR_TEMP 26111 - -/* Thermal VPU throttling support */ -#ifdef CONFIG_MTK_APUSYS_VPU -#define THERMAL_VPU_SUPPORT -#endif - -/* Thermal MDLA throttling support */ -#ifdef CONFIG_MTK_APUSYS_MDLA_SUPPORT -#define THERMAL_MDLA_SUPPORT -#endif - -/* EARA_Thermal power budget allocation support*/ -#define EARA_THERMAL_SUPPORT - -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_RAM_CONSOLE -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#if CFG_THERM_LVTS -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -//#define CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT (0) -#define DYNAMIC_REBOOT_TRIP_TEMP (35000) -#define DYNAMIC_REBOOT_EXIT_TEMP (30000) -#else -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -#endif - -#define LVTS_REFINE_MANUAL_RCK_WITH_EFUSE (1) - -#define DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE (1) - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#define LVTS_FORCE_ERROR_TRIGGER (0) -#define LVTS_NUM_SKIP_SAMPLE (500) - -#define HISTORY_SAMPLES (10) -#define FUTURE_SAMPLES (10) -#define R_BUFFER_SIZE (HISTORY_SAMPLES + FUTURE_SAMPLES + 1) -#define LVTS_ERROR_THRESHOLD (10000) - -#define DUMP_LVTS_REGISTER (0) -#define DUMP_VCORE_VOLTAGE (0) -#endif -#define LVTS_VALID_DATA_TIME_PROFILING (0) - -#define LVTS_USE_DOMINATOR_SENSING_POINT (1) - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (0) -/*============================================================= - *REG ACCESS - *============================================================= - */ -/* double check */ -#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ - -/* turn on TS_CON1[5:4] 2'b 00 11001111 -> 0xCF ~(0x30)*/ -#define TS_TURN_ON 0xFFFFFFCF -#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | (val), \ - ((void *)addr)) - -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & ~(val), \ - ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES (8) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x84) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x90) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif - -/*============================================================= - * Common Structure and Enum - *============================================================= - */ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * LVTS Structure and Enum - *============================================================= - */ -#if CFG_THERM_LVTS - -/* - * module LVTS Plan - *===================================================== - * MCU_BIG LVTS1-0, LVTS1-1 - * MCU_LITTLE LVTS2-0, LVTS2-1, LVTS2-2, LVTS2-3 - * GPU LVTS3-0, LVTS3-1 - * SOC TOP LVTS3-2, LVTS3-3 - * VPU LVTS4-0, LVTS4-1 - * MD-4G LVTS5-0 - * MD-5G LVTS5-1 - * MD-3G LVTS5-2 - */ - - -/* private thermal sensor enum */ -enum lvts_sensor_enum { - L_TS_LVTS1_0 = 0, /* LVTS1-0 Big */ - L_TS_LVTS1_1, /* LVTS1-1 Big */ - L_TS_LVTS2_0, /* LVTS2-0 Little */ - L_TS_LVTS2_1, /* LVTS2-1 Little */ - L_TS_LVTS2_2, /* LVTS2-2 Little */ - L_TS_LVTS2_3, /* LVTS2-3 Little */ - L_TS_LVTS3_0, /* LVTS3-0 GPU */ - L_TS_LVTS3_1, /* LVTS3-1 GPU */ - L_TS_LVTS3_2, /* LVTS3-2 VP */ - L_TS_LVTS3_3, /* LVTS3-3 VP */ - L_TS_LVTS4_0, /* LVTS4-0 VPU */ - L_TS_LVTS4_1, /* LVTS4-1 VPU */ - L_TS_LVTS5_0, /* LVTS5-0 MD-4G */ - L_TS_LVTS5_1, /* LVTS5-1 MD-5G */ - L_TS_LVTS5_2, /* LVTS5-2 MD-3G */ - L_TS_LVTS_NUM -}; - - -enum lvts_tc_enum { - LVTS_MCU_CONTROLLER0 = 0,/* LVTSMONCTL0 */ - LVTS_MCU_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_AP_CONTROLLER0, /* LVTSMONCTL0 */ - LVTS_AP_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_AP_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_CONTROLLER_NUM -}; - - -struct lvts_thermal_controller_speed { - unsigned int group_interval_delay; - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; -}; - -struct lvts_thermal_controller { - enum lvts_sensor_enum ts[4]; /* sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; /* hw protection ref TS (index of the ts array) */ - int tc_offset; - struct lvts_thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Tsense Structure and Enum - *============================================================= - */ -#if !defined(CFG_THERM_NO_AUXADC) -/* private thermal sensor enum */ -enum tsmcu_sensor_enum { - L_TS_MCU0 = 0, - L_TS_MCU1, - L_TS_MCU2, - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - L_TS_MCU4, - L_TS_MCU5, - L_TS_MCU6, - L_TS_MCU7, - L_TS_MCU8, - L_TS_MCU9, - L_TS_ABB, - L_TS_MCU_NUM -}; - -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, /* TEMPMONCTL0 */ - THERMAL_CONTROLLER1, /* TEMPMONCTL0_1 */ - THERMAL_CONTROLLER2, /* TEMPMONCTL0_2 */ - THERMAL_CONTROLLER_NUM -}; -#endif -struct thermal_controller_speed { - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; - unsigned int ahb_polling_interval; -}; -#if CFG_THERM_LVTS -struct thermal_controller { - enum lvts_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#else -struct thermal_controller { - enum tsmcu_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Shared variables - *============================================================= - */ -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern u32 thermal_mcu_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_curr_cpu_temp; -extern int tscpu_curr_gpu_temp; -#endif - -/* - * In src/mtk_tc.c - */ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_sspm_thermal_throttle; -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -#if !defined(CFG_THERM_NO_AUXADC) -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -#endif -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -extern int lvts_hw_protect_enabled; - -#if !defined(CFG_THERM_NO_AUXADC) -/* - * temperature array to store both tsmcu and lvts (if exist) and export them - */ -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ - -/* - * temperature array to store temp of tsmcu sensor - */ -extern int tscpu_ts_mcu_temp[L_TS_MCU_NUM]; -extern int tscpu_ts_mcu_temp_r[L_TS_MCU_NUM]; /* raw data */ -#endif - -#if CFG_THERM_LVTS -/* - * temperature array to store temp of lvts sensor - */ -extern int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -extern int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; /* raw data */ -#endif - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -extern int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#if DUMP_VCORE_VOLTAGE -extern struct regulator *vcore_reg_id; -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern unsigned long long int SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -extern int isTempValid; -extern long long int start_timestamp; -/* count if start_timestamp is bigger than end_timestamp */ -extern int diff_error_count; -#endif -/* - * support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_rawdata_debug_log; -extern int lvts_debug_log; -extern struct lvts_thermal_controller -lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM]; -#endif - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long int thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#endif - -extern char *adaptive_cooler_name; - -/* common/coolers/mtk_cooler_atm.c */ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/* common/coolers/mtk_cooler_dtm.c */ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In mtk_tc_wrapper.c */ -extern int tscpu_get_curr_max_ts_temp(void); -extern int tscpu_max_temperature(void); -extern int tscpu_get_curr_temp(void); -extern int combine_lvts_tsmcu_temp(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int get_io_reg_base(void); - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif -extern void tscpu_update_tempinfo(void); - -#if !defined(CFG_THERM_NO_AUXADC) -/*In src/mtk_tc.c*/ -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp( - int tc_num, enum tsmcu_sensor_enum type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); - -extern int tscpu_dump_cali_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); - -extern void thermal_disable_all_periodoc_temp_sensing(void); -extern void read_all_tc_tsmcu_temperature(void); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -#endif -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern void lvts_tscpu_reset_thermal(void); -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_get_io_reg_base(void); -extern int lvts_max_temperature(void); -extern void lvts_config_all_tc_hw_protect(int temperature, int temperature2); -extern void lvts_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order); -extern void lvts_read_all_tc_temperature(void); -extern void lvts_reset_and_initial(int tc_num); -extern int (*lvts_max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void lvts_thermal_lvts_device_init(void); -extern void lvts_read_temperature(void); -//extern void lvts_read_temperature(int temp0, int temp1); -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_error_info(void); -#endif -extern void lvts_thermal_cal_prepare(void); -extern void lvts_device_identification(void); -extern void lvts_reset_device_and_stop_clk(void); -extern void lvts_read_device_id_rev(void); -extern void lvts_Device_Enable_Init_all_Devices(void); -extern void lvts_device_read_count_RC_N(void); -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -extern void lvts_device_read_count_RC_N_resume(void); -#endif -extern void lvts_device_enable_auto_rck(void); -extern void lvts_efuse_setting(void); -extern void lvts_tscpu_thermal_initial_all_tc(void); -extern void lvts_pause_all_sensing_points(void); -extern void lvts_release_all_sensing_points(void); -extern void lvts_disable_all_sensing_points(void); -extern void lvts_enable_all_sensing_points(void); -extern void read_all_tc_lvts_temperature(void); -extern void lvts_wait_for_all_sensing_point_idle(void); -extern irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -extern int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v); -extern void lvts_sodi3_release_thermal_controller(void); -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -extern void lvts_enable_all_hw_protect(void); -extern void lvts_disable_all_hw_protect(void); -#endif -#endif - -/* - * In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c - * It's not our api, ask them to provide header file - */ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* - * In drivers/misc/mediatek/auxadc/mt_auxadc.c - * It's not our api, ask them to provide header file - */ -extern int IMM_IsAdcInitReady(void); - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern void dump_efuse_data(void); -extern int check_lvts_mcu_efuse(void); -extern int check_auxadc_mcu_efuse(void); -#if DUMP_LVTS_REGISTER -extern void read_controller_reg_before_active(void); -extern void read_controller_reg_when_error(void); -extern void read_device_reg_before_active(void); -extern void read_device_reg_when_error(void); -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_register_value(void); -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern void lvts_dump_time_profiling_result(struct seq_file *m); -#endif -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -extern int tscpu_check_cpu_segment(void); -#endif -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ - do { \ - if (tscpu_debug_log == 1) { \ - pr_notice(TSCPU_LOG_TAG fmt, ##args); \ - } \ - } while (0) - -#define tscpu_printk(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -#define LVTS_LOG_TAG "[Thermal/TZ/LVTS]" -#define LVTS_LOG_REG_TAG "[Thermal/TZ/LVTSREG]" - -#define lvts_reg_print(fmt, args...) pr_notice(LVTS_LOG_REG_TAG fmt, ##args) -#define lvts_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#define lvts_warn(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#if 0 -#define lvts_dbg_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#else -#define lvts_dbg_printk(fmt, args...) \ - do { \ - if (lvts_debug_log == 1) { \ - pr_notice(LVTS_LOG_TAG fmt, ##args); \ - } \ - } while (0) -#endif -#endif - -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -#if 1 -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base -#else -#include -#define AUXADC_BASE_2 AUXADC_BASE -#define THERM_CTRL_BASE_2 THERM_CTRL_BASE -#define PERICFG_BASE_2 PERICFG_BASE -#define APMIXED_BASE_2 APMIXED_BASE -#endif - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) - -#define INFRA_GLOBALCON_RST_4_SET (INFRACFG_AO_BASE_2 + 0x730) -#define INFRA_GLOBALCON_RST_4_CLR (INFRACFG_AO_BASE_2 + 0x734) -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ - -#define THERMAL_COLD_INTERRUPT_0 0x00000001 -#define THERMAL_HOT_INTERRUPT_0 0x00000002 -#define THERMAL_LOW_OFFSET_INTERRUPT_0 0x00000004 -#define THERMAL_HIGH_OFFSET_INTERRUPT_0 0x00000008 -#define THERMAL_HOT2NORMAL_INTERRUPT_0 0x00000010 -#define THERMAL_COLD_INTERRUPT_1 0x00000020 -#define THERMAL_HOT_INTERRUPT_1 0x00000040 -#define THERMAL_LOW_OFFSET_INTERRUPT_1 0x00000080 -#define THERMAL_HIGH_OFFSET_INTERRUPT_1 0x00000100 -#define THERMAL_HOT2NORMAL_INTERRUPT_1 0x00000200 -#define THERMAL_COLD_INTERRUPT_2 0x00000400 -#define THERMAL_HOT_INTERRUPT_2 0x00000800 -#define THERMAL_LOW_OFFSET_INTERRUPT_2 0x00001000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_2 0x00002000 -#define THERMAL_HOT2NORMAL_INTERRUPT_2 0x00004000 -#define THERMAL_AHB_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_DEVICE_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_IMMEDIATE_INTERRUPT_0 0x00010000 -#define THERMAL_IMMEDIATE_INTERRUPT_1 0x00020000 -#define THERMAL_IMMEDIATE_INTERRUPT_2 0x00040000 -#define THERMAL_FILTER_INTERRUPT_0 0x00080000 -#define THERMAL_FILTER_INTERRUPT_1 0x00100000 -#define THERMAL_FILTER_INTERRUPT_2 0x00200000 -#define THERMAL_COLD_INTERRUPT_3 0x00400000 -#define THERMAL_HOT_INTERRUPT_3 0x00800000 -#define THERMAL_LOW_OFFSET_INTERRUPT_3 0x01000000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_3 0x02000000 -#define THERMAL_HOT2NORMAL_INTERRUPT_3 0x04000000 -#define THERMAL_IMMEDIATE_INTERRUPT_3 0x08000000 -#define THERMAL_FILTER_INTERRUPT_3 0x10000000 -#define THERMAL_PROTECTION_STAGE_1 0x20000000 -#define THERMAL_PROTECTION_STAGE_2 0x40000000 -#define THERMAL_PROTECTION_STAGE_3 0x80000000 -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_tsense_config.h b/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_tsense_config.h deleted file mode 100644 index f352361e4c35..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tscpu_tsense_config.h +++ /dev/null @@ -1,151 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_TSENSE_SETTINGS_H__ -#define __TSCPU_TSENSE_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define ADDRESS_INDEX_0 101 /* 184 */ -#define ADDRESS_INDEX_1 100 /* 180 */ -#define ADDRESS_INDEX_2 102 /* 188 */ -#define ADDRESS_INDEX_3 111 /* 1AC */ -#define ADDRESS_INDEX_4 112 /* 1B0 */ - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - -#define TSCON1_bit_0_3_0000 0x00 /*TSCON1[3:0]=4'b0000*/ -#define TSCON1_bit_0_3_0001 0x01 /*TSCON1[3:0]=4'b0001*/ -#define TSCON1_bit_0_3_0010 0x02 /*TSCON1[3:0]=4'b0010*/ -#define TSCON1_bit_0_3_0011 0x03 /*TSCON1[3:0]=4'b0011*/ -#define TSCON1_bit_0_3_0100 0x04 /*TSCON1[3:0]=4'b0100*/ -#define TSCON1_bit_0_3_0101 0x05 /*TSCON1[3:0]=4'b0101*/ -#define TSCON1_bit_0_3_0110 0x06 /*TSCON1[3:0]=4'b0110*/ -#define TSCON1_bit_0_3_0111 0x07 /*TSCON1[3:0]=4'b0111*/ -#define TSCON1_bit_0_3_1000 0x08 /*TSCON1[3:0]=4'b1000*/ -#define TSCON1_bit_0_3_1001 0x09 /*TSCON1[3:0]=4'b1001*/ -#define TSCON1_bit_0_3_1010 0x0A /*TSCON1[3:0]=4'b1010*/ -#define TSCON1_bit_0_3_1011 0x0B /*TSCON1[3:0]=4'b1011*/ -#define TSCON1_bit_0_3_1100 0x0C /*TSCON1[3:0]=4'b1100*/ -#define TSCON1_bit_0_3_1101 0x0D /*TSCON1[3:0]=4'b1101*/ -#define TSCON1_bit_0_3_1110 0x0E /*TSCON1[3:0]=4'b1110*/ -#define TSCON1_bit_0_3_1111 0x0F /*TSCON1[3:0]=4'b1111*/ -#define TSCON1_bit_0_3_MASK 0x0F - -/* ADC value to mcu */ -/*chip dependent*/ -#define TEMPADC_MCU0 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0000)) -#define TEMPADC_MCU1 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0001)) -#define TEMPADC_MCU2 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0010)) -#define TEMPADC_MCU4 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0100)) -#define TEMPADC_MCU5 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0101)) -#define TEMPADC_MCU6 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0110)) -#define TEMPADC_MCU7 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0111)) -#define TEMPADC_MCU8 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1000)) -#define TEMPADC_MCU9 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1001)) -#define TEMPADC_ABB ((0x30&TSCON1_bit_4_5_01)|(0x0F&TSCON1_bit_0_3_0000)) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x800) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x804) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x808) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x80C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x810) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x814) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x818) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x81C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x824) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x828) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x82C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x830) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x834) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x838) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x83C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x840) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x844) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x848) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x84C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x850) -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x854) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x858) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x85C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x860) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x864) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x868) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x86C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x870) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x874) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x878) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x87C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x880) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x884) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x888) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x88C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x890) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x894) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x898) -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x89C) -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x8A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x8A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x8A8) -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x8B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x8B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x8B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x8BC) -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x8C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x8C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x8C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x8CC) -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x8F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x8F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x8F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x8FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) -#endif /* __TSCPU_TSENSE_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6877/inc/tzbatt_initcfg.h deleted file mode 100644 index 2c0a2cb08a1a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6877/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6877/inc/tzcpu_initcfg.h deleted file mode 100644 index bac3d593c8f7..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (113500) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6877/src/Makefile b/drivers/misc/mediatek/thermal/mt6877/src/Makefile deleted file mode 100644 index bf32ba967f15..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -ifeq ($(CONFIG_MACH_MT6877),y) - PDIR = mt6877 -else - PDIR = $(MTK_PLATFORM) -endif - -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(PDIR) -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(PDIR) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ifeq ($(CONFIG_MACH_MT6877),y) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/mcupm/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(MTK_PLATFORM) -else -ccflags-y += -I$(srctree)/drivers/misc/mediatek/mcupm/$(PDIR) -endif -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/spm/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/mt3967/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ -ccflags-y += -I$(srctree)/include/dt-bindings/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/gpufreq_v1/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include/ - -obj-$(CONFIG_THERMAL) += mtk_lvts_tc.o -#obj-$(CONFIG_THERMAL) += mtk_tc.o -obj-$(CONFIG_THERMAL) += mtk_tc_wrapper.o -obj-$(CONFIG_THERMAL) += mtk_thermal_ipi.o -obj-$(CONFIG_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vcore.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vproc.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vgpu.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359tsx.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359dcxo.o -#obj-$(CONFIG_THERMAL) += mtk_ti_6315.o diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_lvts_tc.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_lvts_tc.c deleted file mode 100644 index 797ffa3fcdea..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_lvts_tc.c +++ /dev/null @@ -1,2248 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include -#include - -#define __MT_MTK_LVTS_TC_C__ -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_LVTS_TC_C__ - -#include -#include "mtk_thermal_ipi.h" - - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 3; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -int tscpu_debug_log; -int tscpu_sspm_thermal_throttle; -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif -/*============================================================= - * Local variable definition - *============================================================= - */ -/* chip dependent */ -/* - * TO-DO: I assume AHB bus frequecy is 78MHz. - * Please confirm it. - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG LVTS1-0, LVTS1-1 - * MCU_LITTLE LVTS2-0, LVTS2-1, LVTS2-2, LVTS2-3 - * GPU LVTS3-0, LVTS3-1 - * SOC TOP LVTS3-2, LVTS3-3 - * VPU LVTS4-0, LVTS4-1 - * MD-4G LVTS5-0 - * MD-5G LVTS5-1 - * MD-3G LVTS5-2 - */ - -struct lvts_thermal_controller lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM] = { - [0] = {/*(MCU CPU B)*/ - .ts = {L_TS_LVTS1_0, L_TS_LVTS1_1}, - .ts_number = 2, - .dominator_ts_idx = 1, //TODO: need confirm dominator sensor - .tc_offset = 0x26D000, - .tc_speed = { - .group_interval_delay = 0x001, - .period_unit = 0x001, - .filter_interval_delay = 0x001, - .sensor_interval_delay = 0x001 - } - }, - [1] = {/*(MCU CPU L)*/ - .ts = {L_TS_LVTS2_0, L_TS_LVTS2_1, L_TS_LVTS2_2, L_TS_LVTS2_3}, - .ts_number = 4, - .dominator_ts_idx = 2, //TODO: need confirm dominator sensor - .tc_offset = 0x26D100, - .tc_speed = { - .group_interval_delay = 0x001, - .period_unit = 0x00C, - .filter_interval_delay = 0x001, - .sensor_interval_delay = 0x001 - } - }, - [2] = {/*(AP GPU CAM VP)*/ - .ts = {L_TS_LVTS3_0, L_TS_LVTS3_1, L_TS_LVTS3_2, L_TS_LVTS3_3}, - .ts_number = 4, - .dominator_ts_idx = 0, //TODO: need confirm dominator sensor - .tc_offset = 0, - .tc_speed = { - .group_interval_delay = 0x001, - .period_unit = 0x00C, - .filter_interval_delay = 0x001, - .sensor_interval_delay = 0x001 - } - }, - [3] = {/*(AP VPU)*/ - .ts = {L_TS_LVTS4_0, L_TS_LVTS4_1}, - .ts_number = 2, - .dominator_ts_idx = 1, //TODO: need confirm dominator sensor - .tc_offset = 0x100, - .tc_speed = { - .group_interval_delay = 0x001, - .period_unit = 0x00C, - .filter_interval_delay = 0x001, - .sensor_interval_delay = 0x001 - } - }, - [4] = {/*(AP MD4G MD5G MD3G)*/ - .ts = {L_TS_LVTS5_0, L_TS_LVTS5_1, L_TS_LVTS5_2}, - .ts_number = 3, - .dominator_ts_idx = 2, //TODO: need confirm dominator sensor - .tc_offset = 0x200, - .tc_speed = { - .group_interval_delay = 0x001, - .period_unit = 0x00C, - .filter_interval_delay = 0x001, - .sensor_interval_delay = 0x001 - } - } -}; - - -static unsigned int g_golden_temp; -static unsigned int g_count_r[L_TS_LVTS_NUM]; -static unsigned int g_count_rc[L_TS_LVTS_NUM]; -static unsigned int g_count_rc_now[L_TS_LVTS_NUM]; -static int g_use_fake_efuse; -int lvts_debug_log; -int lvts_rawdata_debug_log; - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -static int hw_protect_setting_done; -int lvts_hw_protect_enabled; -#endif - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -#define NUM_LVTS_DEVICE_REG (34) -static const unsigned int g_lvts_device_addrs[NUM_LVTS_DEVICE_REG] = { - 0x00, - 0x01, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x0A, - 0x0B, - 0x0C, - 0x0D, - 0x0E, - 0x10, - 0x11, - 0x12, - 0x13, - 0x14, - 0x15, - 0x16, - 0x17, - 0x18, - 0x19, - 0x1A, - 0x1B, - 0xF0, - 0xF1, - 0xF2, - 0xF3, - 0xFC, - 0xFD, - 0xFF}; - -static unsigned int g_lvts_device_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; -static unsigned int g_lvts_device_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; - -#define NUM_LVTS_CONTROLLER_REG (28) -static const unsigned int g_lvts_controller_addrs[NUM_LVTS_CONTROLLER_REG] = { - 0x00,//LVTSMONCTL0_0 - 0x04,//LVTSMONCTL1_0 - 0x08,//LVTSMONCTL2_0 - 0x0C,//LVTSMONINT_0 - 0x10,//LVTSMONINTSTS_0 - 0x20,//LVTSMONIDET3_0 - 0x38,//LVTSMSRCTL0_0 - 0x3C,//LVTSMSRCTL1_0 - 0x40,//LVTSTSSEL_0 - 0x4C,//LVTS_ID_0 - 0x50,//LVTS_CONFIG_0 - 0x54,//LVTSSEDATA00_0 - 0x58,//LVTSSEDATA01_0 - 0x5C,//LVTSSEDATA02_0 - 0x60,//LVTSSEDATA03_0 - 0x90,//LVTSMSR0_0 - 0x94,//LVTSMSR1_0 - 0x98,//LVTSMSR2_0 - 0x9C,//LVTSMSR3_0 - 0xB0,//LVTSRDATA0_0 - 0xB4,//LVTSRDATA1_0 - 0xB8,//LVTSRDATA2_0 - 0xBC,//LVTSRDATA3_0 - 0xC0,//LVTSPROTCTCTL_0 - 0xCC,//LVTSPROTTC_0 - 0xFC,//LVTSPRRE3_0 - 0xE8,//LVTSDBGSEL_0 - 0xE4};//LVTSCLKEN_0 -static unsigned int g_lvts_controller_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -static unsigned int g_lvts_controller_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -#endif - -#if LVTS_VALID_DATA_TIME_PROFILING -unsigned long long int SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -int isTempValid; -/* latency_array - * {a, b} - * a: a time threshold in milliseconds. if it is -1, it means others. - * b: the number of valid temperature latencies from a phone enters SODI3 to - * to a phone gets a valid temperature of any sensor. - * It is possible a phone enters SODI3 several times without a valid - * temperature data. - */ -#define NUM_TIME_TH (16) /* TODO: know what it is */ -static unsigned int latency_array[NUM_TIME_TH][2] = { - {100, 0}, - {200, 0}, - {300, 0}, - {400, 0}, - {500, 0}, - {600, 0}, - {700, 0}, - {800, 0}, - {900, 0}, - {1000, 0}, - {2000, 0}, - {3000, 0}, - {4000, 0}, - {5000, 0}, - {10000, 0}, - {-1, 0} -}; -long long int start_timestamp; -static long long int end_timestamp, time_diff; -/* count if start_timestamp is bigger than end_timestamp */ -int diff_error_count; -#endif - -#if CFG_THERM_LVTS -#define DEFAULT_EFUSE_GOLDEN_TEMP (50) -#define DEFAULT_EFUSE_COUNT (35000) -#define DEFAULT_EFUSE_COUNT_RC (2750) -#define FAKE_EFUSE_VALUE 0x2B048500 -#define LVTS_COEFF_A_X_1000 (-250460) -#define LVTS_COEFF_B_X_1000 (250460) -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static unsigned int lvts_temp_to_raw(int ret, enum lvts_sensor_enum ts_name); - -static void lvts_set_tc_trigger_hw_protect( - int temperature, int temperature2, int tc_num); -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -void mt_reg_sync_writel_print(unsigned int val, void *addr) -{ - if (lvts_debug_log) - lvts_dbg_printk("### LVTS_REG: addr 0x%p, val 0x%x\n", - addr, val); - - mt_reg_sync_writel(val, addr); -} - -/*=============================================================*/ - -static int lvts_write_device(unsigned int config, unsigned int dev_reg_idx, -unsigned int data, int tc_num) -{ - int offset; - - dev_reg_idx &= 0xFF; - data &= 0xFF; - - config = config | (dev_reg_idx << 8) | data; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* - * LVTS Device Register Setting take 1us(by 26MHz clock source) - * interface latency to access. - * So we set 2~3us delay could guarantee access complete. - */ - udelay(3); - - return 1; -} - -static unsigned int lvts_read_device(unsigned int config, -unsigned int dev_reg_idx, int tc_num) -{ - int offset, cnt; - unsigned int data; - - dev_reg_idx &= 0xFF; - - config = config | (dev_reg_idx << 8) | 0x00; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - data = (readl(LVTSRDATA0_0 + offset)); - - return data; -} -int lvts_raw_to_temp(unsigned int msr_raw, enum lvts_sensor_enum ts_name) -{ - /* This function returns degree mC - * temp[i] = a * MSR_RAW/16384 + GOLDEN_TEMP/2 + b - * a = -250.46 - * b = 250.46 - */ - int temp_mC = 0; - int temp1 = 0; - - temp1 = (LVTS_COEFF_A_X_1000 * ((unsigned long long int)msr_raw)) >> 14; - - temp_mC = temp1 + g_golden_temp * 500 + LVTS_COEFF_B_X_1000; - - return temp_mC; -} -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -static void read_controller_reg_before_active(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_b[i][j] = temp; - } - } - -} - -static void read_controller_reg_when_error(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_e[i][j] = temp; - } - } -} - -static void read_controller_reg_when_error_by_ctrl_num(int ctrl_num) -{ - int j, offset, temp; - - //for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[ctrl_num].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_e[ctrl_num][j] = temp; - } - //} -} - -static void read_device_reg_before_active(void) -{ - int i, j; - unsigned int addr, data; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - data = lvts_read_device(0xC1020000, addr, i); - g_lvts_device_value_b[i][j] = data; - } - } -} - -static void read_device_reg_when_error(void) -{ - int i, j, offset, cnt; - unsigned int addr; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - lvts_write_device(0xC1020000, addr, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - g_lvts_device_value_e[i][j] = (readl(LVTSRDATA0_0 - + offset)); - } - } -} - -static void read_device_reg_when_error_by_ctrl_num(int ctrl_num) -{ - int j, offset, cnt; - unsigned int addr; - - //for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[ctrl_num].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - lvts_write_device(0x81020000, addr, 0x00, ctrl_num); - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - g_lvts_device_value_e[ctrl_num][j] = (readl(LVTSRDATA0_0 - + offset)); - } - //} -} - - -void clear_lvts_register_value_array(void) -{ - int i, j; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - g_lvts_controller_value_b[i][j] = 0; - g_lvts_controller_value_e[i][j] = 0; - } - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - g_lvts_device_value_b[i][j] = 0; - g_lvts_device_value_e[i][j] = 0; - } - } -} - -static void dump_lvts_register_value_by_ctrl_num(int ctrl_num) -{ - int j, offset, tc_offset; - char buffer[512]; - - //for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][BEFROE][CONTROLLER_%d][DUMP]\n", ctrl_num); - tc_offset = lvts_tscpu_g_tc[ctrl_num].tc_offset; //tc offset - - offset = sprintf(buffer, "[LVTS_ERROR][BEFORE][TC][DUMP] "); - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_b[ctrl_num][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][BEFORE][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_b[ctrl_num][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - //} - - //for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][AFTER][CONTROLLER_%d][DUMP]\n", ctrl_num); - tc_offset = lvts_tscpu_g_tc[ctrl_num].tc_offset; //tc offset - - offset = sprintf(buffer, "[LVTS_ERROR][AFTER][TC][DUMP] "); - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_e[ctrl_num][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][AFTER][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_e[ctrl_num][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - //} -} - -static void dump_lvts_register_value(void) -{ - int i, j, offset, tc_offset; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][BEFROE][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = sprintf(buffer, "[LVTS_ERROR][BEFORE][TC][DUMP] "); - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_b[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][BEFORE][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_b[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][AFTER][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = sprintf(buffer, "[LVTS_ERROR][AFTER][TC][DUMP] "); - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_e[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][AFTER][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) - offset += sprintf(buffer + offset, "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_e[i][j]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - } -} - -void dump_lvts_error_info(void) -{ - read_controller_reg_when_error(); - - lvts_disable_all_sensing_points(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -} - -void dump_lvts_error_info_by_ctrl_num(int crtl_num) -{ - read_controller_reg_when_error_by_ctrl_num(crtl_num); - - lvts_disable_all_sensing_points(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error_by_ctrl_num(crtl_num); - dump_lvts_register_value_by_ctrl_num(crtl_num); -} - -#endif - -static void lvts_device_check_counting_status(int tc_num) -{ - /* Check this when LVTS device is counting for - * a temperature or a RC now - */ - - int offset, cnt; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; //tc offset - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(25))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_SENSING_STATUS didn't ready\n"); - break; - } - udelay(2); - } -} - -#if 0 -static void lvts_device_check_read_write_status(int tc_num) -{ - /* Check this when LVTS device is doing a register - * read or write operation - */ - - int offset, cnt; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } -} -#endif - -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -void lvts_device_read_count_RC_N_resume(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - /* Set LVTS Manual-RCK operation */ - lvts_write_device(0xC1030000, 0x0E, 0x00, i); - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0xC1030000, 0x0D, j, i); - /* Set Device Low-Power Single mode */ - lvts_write_device(0xC1030000, 0x06, 0xB8, i); - /* Set Device Counting windows */ - lvts_write_device(0xC1030000, 0x05, 0x00, i); - lvts_write_device(0xC1030000, 0x04, 0x20, i); - /* Kick-off RCK counting */ - lvts_write_device(0xC1030000, 0x03, 0x02, i); - /* wait 40us + 10us buffer */ - udelay(50); - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0xC1020000, 0x00, i); - - /* Get RCK value from LSB[23:0] */ - // not assign new rc value when resume LVTS - //g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0xC1030000, 0x0D, (0x10 | j), i); - } - - } - - offset = sprintf(buffer, "[COUNT_RC_NOW] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", - i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} -#endif - -void lvts_device_read_count_RC_N(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - unsigned int rc_data; - int refine_data_idx[L_TS_LVTS_NUM] = {0}; - /* - * comare count_rc_now with efuse. - * > 6%, use efuse RC instead of count_rc_now - * < 6%, keep count_rc_now value - */ - int count_rc_delta = 0; -#endif - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - /* Set LVTS Manual-RCK operation */ - lvts_write_device(0xC1030000, 0x0E, 0x00, i); - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0xC1030000, 0x0D, j, i); - /* Set Device Low-Power Single mode */ - lvts_write_device(0xC1030000, 0x06, 0xB8, i); - /* Set Device Counting windows */ - lvts_write_device(0xC1030000, 0x05, 0x00, i); - lvts_write_device(0xC1030000, 0x04, 0x20, i); - /* Kick-off RCK counting */ - lvts_write_device(0xC1030000, 0x03, 0x02, i); - /* wait 40us + 10us buffer */ - udelay(50); - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0xC1020000, 0x00, i); - - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - rc_data = (data & _BITMASK_(23:0)); - /* - * if count rc now = 0, use efuse rck insead of - * count_rc_now - */ - if (rc_data == 0) { - refine_data_idx[s_index] = 1; - lvts_printk("+ rc_data %d, s_index=%d", - rc_data, s_index); - } else { - if (g_count_rc[i] > rc_data) - count_rc_delta = - (g_count_rc[i] * 1000) / rc_data; - else - count_rc_delta = - (rc_data * 1000) / g_count_rc[i]; - /* - * if delta > 6%, use efuse rck insead of - * count_rc_now - */ - lvts_printk("- rc_data %d, s_index=%d delta=%d", - rc_data, s_index, count_rc_delta); - - if (count_rc_delta > 1061) { - refine_data_idx[s_index] = 1; - lvts_printk("-delta %d, data_idx[%d]=%d", - count_rc_delta, j, s_index); - } - } - //lvts_printk("i=%d, j=%d, s_index=%d, rc_data=%d\n", - // i, j, s_index, rc_data); - //lvts_printk("(g_count_rc[i]*1000)=%d, rc_delta=%d\n", - // (g_count_rc[i]*1000), count_rc_delta); -#endif - - - /* Get RCK value from LSB[23:0] */ - g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - lvts_printk("-refine_data_idx[%d]=%d\n", - s_index, refine_data_idx[s_index]); - if (refine_data_idx[s_index] == 1) - g_count_rc_now[s_index] = g_count_rc[i]; - -#endif - - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0xC1030000, 0x0D, (0x10 | j), i); - } - - } - - - offset = sprintf(buffer, "[COUNT_RC_NOW] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", - i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} - -void lvts_device_enable_auto_rck(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Set LVTS AUTO-RCK operation */ - lvts_write_device(0xC1030000, 0x0E, 0x01, i); - } -} - -void lvts_efuse_setting(void) -{ - __u32 offset; - int i, j, s_index; - int efuse_data; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - s_index = lvts_tscpu_g_tc[i].ts[j]; - -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse_data = - (((unsigned long long int)g_count_rc_now[s_index]) * - g_count_r[s_index]) >> 14; -#else - efuse_data = g_count_r[s_index]; -#endif - - switch (j) { - case 0: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA00_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA00_%d 0x%x\n", - i, readl(LVTSEDATA00_0 + offset)); - break; - - case 1: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA01_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA01_%d 0x%x\n", - i, readl(LVTSEDATA01_0 + offset)); - break; - case 2: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA02_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA02_%d 0x%x\n", - i, readl(LVTSEDATA02_0 + offset)); - break; - case 3: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA03_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA03_%d 0x%x\n", - i, readl(LVTSEDATA03_0 + offset)); - break; - default: - lvts_dbg_printk("%s, illegal ts order : %d!!\n", - __func__, j); - } - } - } - -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -void dump_efuse_data(void) -{ - int i, efuse, offset; - char buffer[512]; - - lvts_printk("[LVTS_ERROR][GOLDEN_TEMP][DUMP] %d\n", g_golden_temp); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_R][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_r[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_rc[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC_NOW][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", - i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][LVTSEDATA][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse = g_count_rc_now[i] * g_count_r[i]; -#else - efuse = g_count_r[i]; -#endif - offset += sprintf(buffer + offset, "%d:%d ", i, efuse); - } - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); -} - -int check_lvts_mcu_efuse(void) -{ - return (g_use_fake_efuse)?(0):(1); -} -#endif - -void lvts_device_identification(void) -{ - int tc_num, data, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Enable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000001, LVTSCLKEN_0 + offset); - - /* Reset All Devices */ - lvts_write_device(0xC1030000, 0xFF, 0xFF, tc_num); - /* udelay(100); */ - - /* Read back Dev_ID with Update */ - lvts_write_device(0xC5020000, 0xFC, 0x55, tc_num); - - /* Check LVTS device ID */ - data = (readl(LVTS_ID_0 + offset) & _BITMASK_(7:0)); - if (data != (0x81 + tc_num)) - lvts_printk("LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", - tc_num, (0x81 + tc_num), data); - } -} - -void lvts_reset_device_and_stop_clk(void) -{ - __u32 offset; - int tc_num; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Reset All Devices */ - lvts_write_device(0xC1030000, 0xFF, 0xFF, tc_num); - - /* Disable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000000, LVTSCLKEN_0 + offset); - } -} - -void lvts_Device_Enable_Init_all_Devices(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Stop Counting (RG_TSFM_ST=0) */ - lvts_write_device(0xC1030000, 0x03, 0x00, i); - /* RG_TSFM_LPDLY[1:0]=2' 10 */ - lvts_write_device(0xC1030000, 0x07, 0xA6, i); - /* Set LVTS device counting window 20us */ - lvts_write_device(0xC1030000, 0x05, 0x00, i); - lvts_write_device(0xC1030000, 0x04, 0x20, i); - /* TSV2F_CHOP_CKSEL & TSV2F_EN */ - lvts_write_device(0xC1030000, 0x0A, 0x8C, i); - /* TSBG_DEM_CKSEL * TSBG_CHOP_EN */ - lvts_write_device(0xC1030000, 0x0C, 0xFC, i); - /* Set TS_RSV */ - lvts_write_device(0xC1030000, 0x09, 0x8D, i); - /* Set TS_CHOP control */ - lvts_write_device(0xC1030000, 0x08, 0xF1, i); - } -} - -void lvts_thermal_cal_prepare(void) -{ - unsigned int temp[25]; - int i, offset; - char buffer[512]; - - temp[0] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_1); - temp[1] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_2); - temp[2] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_3); - temp[3] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_4); - temp[4] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_5); - temp[5] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_6); - temp[6] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_7); - temp[7] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_8); - temp[8] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_9); - temp[9] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_10); - temp[10] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_11); - temp[11] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_12); - temp[12] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_13); - temp[13] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_14); - temp[14] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_15); - temp[15] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_16); - temp[16] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_20); - temp[17] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_21); - temp[18] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_22); - temp[19] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_2); - temp[20] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_3); - temp[21] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_4); - temp[22] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_5); - temp[23] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_6); - temp[24] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_7); - - - for (i = 0; (i + 5) < 25; i = i + 5) - lvts_printk("[lvts_call] %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x\n", - i, temp[i], i + 1, temp[i + 1], i + 2, temp[i + 2], - i + 3, temp[i + 3], i + 4, temp[i + 4]); - - - - g_golden_temp = ((temp[0] & _BITMASK_(31:24)) >> 24); - g_count_r[0] = (temp[1] & _BITMASK_(23:0)); - g_count_r[1] = (temp[2] & _BITMASK_(23:0)); - g_count_r[2] = (temp[3] & _BITMASK_(23:0)); - g_count_r[3] = (temp[4] & _BITMASK_(23:0)); - g_count_r[4] = (temp[5] & _BITMASK_(23:0)); - g_count_r[5] = (temp[6] & _BITMASK_(23:0)); - g_count_r[6] = (temp[7] & _BITMASK_(23:0)); - g_count_r[7] = (temp[8] & _BITMASK_(23:0)); - g_count_r[8] = (temp[9] & _BITMASK_(23:0)); - g_count_r[9] = (temp[10] & _BITMASK_(23:0)); - g_count_r[10] = (temp[11] & _BITMASK_(23:0)); - g_count_r[11] = (temp[12] & _BITMASK_(23:0)); - g_count_r[12] = (temp[13] & _BITMASK_(23:0)); - g_count_r[13] = (temp[14] & _BITMASK_(23:0)); - g_count_r[14] = (temp[15] & _BITMASK_(23:0)); - - g_count_rc[0] = (temp[16] & _BITMASK_(23:0)); - - g_count_rc[1] = (temp[17] & _BITMASK_(23:0)); - - g_count_rc[2] = (temp[18] & _BITMASK_(23:0)); - - g_count_rc[3] = ((temp[19] & _BITMASK_(31:24)) >> 8) + - ((temp[20] & _BITMASK_(31:24)) >> 16) + - ((temp[21] & _BITMASK_(31:24)) >> 24); - - g_count_rc[4] = ((temp[22] & _BITMASK_(31:24)) >> 8) + - ((temp[23] & _BITMASK_(31:24)) >> 16) + - ((temp[24] & _BITMASK_(31:24)) >> 24); - - - for (i = 0; i < L_TS_LVTS_NUM; i++) { - if (i == 0) { - if ((temp[0] & _BITMASK_(7:0)) != 0) - break; - } else { - if (temp[i] != 0) - break; - } - } - - if (i == L_TS_LVTS_NUM) { - /* It means all efuse data are equal to 0 */ - lvts_printk( - "[lvts_cal] This sample is not calibrated, fake !!\n"); - - g_golden_temp = DEFAULT_EFUSE_GOLDEN_TEMP; - for (i = 0; i < L_TS_LVTS_NUM; i++) { - g_count_r[i] = DEFAULT_EFUSE_COUNT; - g_count_rc[i] = DEFAULT_EFUSE_COUNT_RC; - } - - g_use_fake_efuse = 1; - } - - lvts_printk("[lvts_cal] g_golden_temp = %d\n", g_golden_temp); - - offset = sprintf(buffer, "[lvts_cal] num:g_count_r:g_count_rc "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d:%d ", - i, g_count_r[i], g_count_rc[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); -} - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -void lvts_ipi_send_efuse_data(void) -{ - struct thermal_ipi_data thermal_data; - struct thermal_ipi_data thermal_data_sspm; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = g_golden_temp; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - thermal_data_sspm.u.data.arg[0] = g_golden_temp; - thermal_data_sspm.u.data.arg[1] = 0; - thermal_data_sspm.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_LVTS_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - while (thermal_to_sspm(THERMAL_IPI_LVTS_INIT_GRP1, &thermal_data_sspm) != 0) - udelay(100); -} -#endif - - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#if defined(THERMAL_SSPM_THERMAL_THROTTLE_SWITCH) -void lvts_ipi_send_sspm_thermal_thtottle(void) -{ - struct thermal_ipi_data thermal_data; - struct thermal_ipi_data thermal_data2; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = tscpu_sspm_thermal_throttle; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - thermal_data2.u.data.arg[0] = tscpu_sspm_thermal_throttle; - thermal_data2.u.data.arg[1] = 0; - thermal_data2.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - &thermal_data) != 0) - udelay(100); - - while (thermal_to_sspm(THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - &thermal_data2) != 0) - udelay(100); -} -#endif - -#if defined(THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY) -void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend) -{ - struct thermal_ipi_data thermal_data; - - //lvts_printk("%s, is_suspend %d\n", __func__, is_suspend); - - thermal_data.u.data.arg[0] = is_suspend; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_mcupm(THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - &thermal_data) != 0) - udelay(100); -} -#endif -#endif - -static unsigned int lvts_temp_to_raw(int temp, enum lvts_sensor_enum ts_name) -{ - /* MSR_RAW = ((temp[i] - GOLDEN_TEMP/2 - b) * 16384) / a - * a = -250.46 - * b = 250.46 - */ - unsigned int msr_raw = 0; - - msr_raw = ((long long int)(((long long int)g_golden_temp * 500 + - LVTS_COEFF_B_X_1000 - temp)) << 14)/(-1 * LVTS_COEFF_A_X_1000); - - lvts_dbg_printk("%s msr_raw = 0x%x,temp=%d\n", __func__, msr_raw, temp); - - return msr_raw; -} - -static void lvts_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + LVTSMONINTSTS_0); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + LVTSMONINTSTS_0); - - lvts_printk("[Thermal IRQ] LVTS thermal controller %d, LVTSMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_PROTECTION_STAGE_3) { - lvts_printk("[Thermal IRQ]: Thermal protection stage 3 interrupt triggered, Thermal HW reboot\n"); - dump_lvts_error_info_by_ctrl_num(tc_num); - } - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) { - lvts_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 3\n"); - dump_lvts_error_info_by_ctrl_num(tc_num); - } - - if (ret & THERMAL_COLD_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_DEVICE_TIMEOUT_INTERRUPT) - lvts_dbg_printk("[Thermal IRQ]: Device access timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: High offset triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 1 interrupt triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 2 interrupt triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - -} - -irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, ret_mcu = 0, i, mask = 1; - - ret = readl(THERMINTST + - lvts_tscpu_g_tc[LVTS_AP_CONTROLLER0].tc_offset); - ret = ret & 0x1E; - ret_mcu = readl(THERMINTST + - lvts_tscpu_g_tc[LVTS_MCU_CONTROLLER0].tc_offset); - ret_mcu = ret_mcu & 0x1E; - - /* MSB LSB NAME - * 4 4 LVTSINT3 - * 3 3 LVTSINT2 - * 2 2 LVTSINT1 - * 1 1 LVTSINT0 - * 0 0 THERMINT0 - */ - lvts_printk("%s : THERMINTST = 0x%x THERMINTST_MCU = 0x%x\n", - __func__, ret, ret_mcu); - - ret_mcu = ((ret_mcu >> 1) << LVTS_MCU_CONTROLLER0); - ret = ((ret >> 1) << LVTS_AP_CONTROLLER0); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - mask = 1 << i; - - if (i < LVTS_AP_CONTROLLER0) { - if ((ret_mcu & mask) == 0) - lvts_interrupt_handler(i); - } else { - if ((ret & mask) == 0) - lvts_interrupt_handler(i); - } - } - - return IRQ_HANDLED; -} - -static void lvts_configure_polling_speed_and_filter(int tc_num) -{ - __u32 offset, lvtsMonCtl1, lvtsMonCtl2; - - lvts_dbg_printk("%s\n", __func__); - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvtsMonCtl1 = (((lvts_tscpu_g_tc[tc_num].tc_speed.group_interval_delay - << 20) & _BITMASK_(29:20)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0))); - lvtsMonCtl2 = (((lvts_tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay - & _BITMASK_(9:0))); - /* - * Calculating period unit in Module clock x 256, and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* - * bus clock 66M counting unit is - * 12 * 1/66M * 256 = 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel_print(lvtsMonCtl1, offset + LVTSMONCTL1_0); - /* - *filt interval is 1 * 46.545us = 46.545us, - *sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel_print(lvtsMonCtl2, offset + LVTSMONCTL2_0); - - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel_print(0x0, offset + LVTSMSRCTL0_0); - - udelay(1); - lvts_dbg_printk( - "%s %d, LVTSMONCTL1_0= 0x%x,LVTSMONCTL2_0= 0x%x,LVTSMSRCTL0_0= 0x%x\n", - __func__, tc_num, - readl(LVTSMONCTL1_0 + offset), - readl(LVTSMONCTL2_0 + offset), - readl(LVTSMSRCTL0_0 + offset)); -} - -/* - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void lvts_set_tc_trigger_hw_protect( -int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, config, offset; -#if LVTS_USE_DOMINATOR_SENSING_POINT - int d_index; - enum lvts_sensor_enum ts_name; -#endif - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvts_dbg_printk("%s t1=%d t2=%d\n", - __func__, temperature, temperature2); - -#if LVTS_USE_DOMINATOR_SENSING_POINT - if (lvts_tscpu_g_tc[tc_num].dominator_ts_idx < - lvts_tscpu_g_tc[tc_num].ts_number){ - d_index = lvts_tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - lvts_printk("Error: LVTS TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - lvts_tscpu_g_tc[tc_num].dominator_ts_idx, - lvts_tscpu_g_tc[tc_num].ts_number); - - lvts_printk("Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - ts_name = lvts_tscpu_g_tc[tc_num].ts[d_index]; - - lvts_dbg_printk("%s # in tc%d , the dominator ts_name is %d\n", - __func__, tc_num, ts_name); - - /* temperature to trigger SPM state2 */ - raw_high = lvts_temp_to_raw(temperature, ts_name); -#else - raw_high = lvts_temp_to_raw(temperature, 0); -#endif - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - temp = readl(offset + LVTSMONINT_0); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print(temp & 0x00000000, offset + LVTSMONINT_0); -#endif - - temp = readl(offset + LVTSPROTCTL_0) & ~(0xF << 16); -#if LVTS_USE_DOMINATOR_SENSING_POINT - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel_print(temp | config, offset + LVTSPROTCTL_0); -#else - /* Maximum of 4 sensing points */ - config = (0x1 << 16); - mt_reg_sync_writel_print(temp | config, offset + LVTSPROTCTL_0); -#endif - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel_print(raw_high, offset + LVTSPROTTC_0); - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print(temp | 0x80000000, offset + LVTSMONINT_0); -#endif -} - -static void dump_lvts_device(int tc_num, __u32 offset) -{ - lvts_printk("%s, LVTS_CONFIG_%d= 0x%x\n", __func__, - tc_num, readl(LVTS_CONFIG_0 + offset)); - udelay(2); - - //read raw data - lvts_printk("%s, LVTSRDATA0_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA0_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA1_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA1_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA2_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA2_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA3_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA3_0 + offset)); -} - -#if LVTS_VALID_DATA_TIME_PROFILING -void lvts_dump_time_profiling_result(struct seq_file *m) -{ - int i, sum; - - seq_printf(m, "SODI3_count= %llu\n", SODI3_count); - seq_printf(m, "noValid_count %llu, %d%%\n", - noValid_count, ((noValid_count * 100) / SODI3_count)); - seq_printf(m, "valid_count %llu, %d%%\n", - (SODI3_count - noValid_count), - (((SODI3_count - noValid_count) * 100) / SODI3_count)); - - sum = 0; - for (i = 0; i < NUM_TIME_TH; i++) - sum += latency_array[i][1]; - - seq_printf(m, "Valid count in latency_array = %d\n", sum); - - for (i = 0; i < NUM_TIME_TH; i++) { - if (i == 0) { - seq_printf(m, "Count valid latency between 0ms ~ %dms: %d, %d%%\n", - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else if (i == (NUM_TIME_TH - 1)) { - seq_printf(m, "Count valid others: %d, %d%%\n", - latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else { - seq_printf(m, "Count valid latency between %dms ~ %dms: %d, %d%%\n", - latency_array[i - 1][0], - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } - } - - /* count if start_timestamp is bigger than end_timestamp */ - seq_printf(m, "diff_error_count= %d\n", diff_error_count); - seq_printf(m, "Current start_timestamp= %lldus\n", start_timestamp); - seq_printf(m, "Current end_timestamp= %lldus\n", end_timestamp); - seq_printf(m, "Current time_diff= %lldus\n", time_diff); -} - -static void lvts_count_valid_temp_latency(long long int time_diff) -{ - /* time_diff is in microseconds */ - int i; - - for (i = 0; i < (NUM_TIME_TH - 1); i++) { - if (time_diff < (((long long int)latency_array[i][0]) - * 1000)) { - latency_array[i][1]++; - break; - } - } - - if (i == (NUM_TIME_TH - 1)) - latency_array[i][1]++; -} -#endif - - -static int lvts_read_tc_raw_and_temp( - u32 *tempmsr_name, enum lvts_sensor_enum ts_name) -{ - int temp = 0, raw = 0, raw1 = 0, raw2 = 0; - - if (thermal_base == 0) - return 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl((tempmsr_name)); - raw1 = (raw & 0x10000) >> 16; //bit 16 : valid bit - raw2 = raw & 0xFFFF; - temp = lvts_raw_to_temp(raw2, ts_name); - - if (raw2 == 0) { - /* 26111 is magic num - * this is to keep system alive for a while - * to wait HW init done, - * because 0 msr raw will translates to 28x'C - * and then 28x'C will trigger a SW reset. - * - * if HW init finish, this msr raw will not be 0, - * system can report normal temperature. - * if wait over 60 times zero, this means something - * wrong with HW, must trigger BUG on and dump useful - * register for debug. - */ - - temp = 26111; - } - - - if (lvts_rawdata_debug_log) { - lvts_printk( - "[LVTS_MSR] ts%d msr_all=%x, valid=%d, msr_temp=%d, temp=%d\n", - ts_name, raw, raw1, raw2, temp); - } - - tscpu_ts_lvts_temp_r[ts_name] = raw2; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_lvts_temp_v[ts_name] = raw1; -#endif -#if LVTS_VALID_DATA_TIME_PROFILING - if (isTempValid == 0 && raw1 != 0 && SODI3_count != 0) { - isTempValid = 1; - end_timestamp = thermal_get_current_time_us(); - time_diff = end_timestamp - start_timestamp; - if (time_diff < 0) { - lvts_printk("[LVTS_ERROR] time_diff = %lldus,start_time= %lldus, end_time= %lldus\n", - time_diff, start_timestamp, end_timestamp); - diff_error_count++; - } else { - lvts_count_valid_temp_latency(time_diff); - } - } -#endif - - return temp; -} - -static void lvts_tscpu_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order) -{ - __u32 offset; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - if (lvts_rawdata_debug_log) - dump_lvts_device(tc_num, offset); - - switch (order) { - case 0: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 1: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR1_0), type); - lvts_dbg_printk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 2: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR2_0), type); - lvts_dbg_printk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 3: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR3_0), type); - lvts_dbg_printk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - default: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - } -} - -void read_all_tc_lvts_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) - lvts_tscpu_thermal_read_tc_temp(i, - lvts_tscpu_g_tc[i].ts[j], j); -} - -/* pause ALL periodoc temperature sensing point */ -void lvts_pause_all_sensing_points(void) -{ - int i, temp, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel_print((temp | 0x10E), - offset + LVTSMSRCTL1_0); - } -} - -/* - * lvts_thermal_check_all_sensing_point_idle - - * Check if all sensing points are idle - * Return: 0 if all sensing points are idle - * an error code if one of them is busy - * error code[31:16]: an index of LVTS thermal controller - * error code[2]: bit 10 of LVTSMSRCTL1 - * error code[1]: bit 7 of LVTSMSRCTL1 - * error code[0]: bit 0 of LVTSMSRCTL1 - */ -static int lvts_thermal_check_all_sensing_point_idle(void) -{ - int i, temp, offset, error_code; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* Check if bit10=bit7=bit0=0 */ - if ((temp & 0x481) != 0) { - error_code = (i << 16) + ((temp & _BIT_(10)) >> 8) + - ((temp & _BIT_(7)) >> 6) + - (temp & _BIT_(0)); - - return error_code; - } - } - - return 0; -} - -void lvts_wait_for_all_sensing_point_idle(void) -{ - int cnt, temp; - - cnt = 0; - /* - * Wait until all sensoring points idled. - * No need to check LVTS status when suspend/resume, - * this will spend extra 100us of suspend flow. - * LVTS status will be reset after resume. - */ - while (cnt < 50 && (tscpu_kernel_status() == 0)) { - temp = lvts_thermal_check_all_sensing_point_idle(); - if (temp == 0) - break; - - if ((cnt + 1) % 10 == 0) { - pr_notice("Cnt= %d LVTS TC %d, LVTSMSRCTL1[10,7,0] = %d,%d,%d, LVTSMSRCTL1[10:0] = 0x%x\n", - cnt + 1, (temp >> 16), - ((temp & _BIT_(2)) >> 2), - ((temp & _BIT_(1)) >> 1), - (temp & _BIT_(0)), - (temp & _BITMASK_(10:0))); - } - - udelay(2); - cnt++; - } -} -/* release ALL periodoc temperature sensing point */ -void lvts_release_all_sensing_points(void) -{ - int i = 0, temp; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(((temp & (~0x10E))), - offset + LVTSMSRCTL1_0); - } -} - -void lvts_sodi3_release_thermal_controller(void) -{ - /* SPM will close 26M to saving power during SODI3 - * Because both auxadc thermal controllers and lvts thermal controllers - * need 26M to work properly, it would cause thermal controllers to - * report an abnormal high or low temperature after leaving SODI3 - * - * The SW workaround solution is that - * SPM will pause LVTS thermal controllers before closing 26M, and - * try to release LVTS thermal controllers after leaving SODI3 - * thermal driver check and release LVTS thermal controllers if - * necessary after leaving SODI3 - */ - int i = 0, temp, lvts_paused = 0; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - /*don't need to do release LVTS when suspend/resume*/ - if (tscpu_kernel_status() == 0) { - - /* Check if SPM paused thermal controller */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause - *sensing point 0,1,2,3 - */ - if ((temp & 0x10E) != 0) { - lvts_paused = 1; - pr_notice_ratelimited( - "lvts_paused = %d\n", lvts_paused); - break; - } - } - - /* Return if SPM didn't pause thermal controller or - * released thermal controllers already - */ - if (lvts_paused == 0) - return; - /* Wait until all of LVTS thermal controllers are idle - * Pause operation has to take time to finish. - * if it didn't finish before SPM closed 26M, we have to wait - * until it is finished to make sure all LVTS thermal - * controllers in a correct finite state machine - */ - - lvts_wait_for_all_sensing_point_idle(); - - lvts_release_all_sensing_points(); - } -} - -/* - * disable ALL periodoc temperature sensing point - */ -void lvts_disable_all_sensing_points(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel_print(0x00000000, offset + LVTSMONCTL0_0); - } -} - -void lvts_enable_all_sensing_points(void) -{ - int i, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - - lvts_dbg_printk("%s %d:%d\n", __func__, i, - lvts_tscpu_g_tc[i].ts_number); - - switch (lvts_tscpu_g_tc[i].ts_number) { - case 1: - /* enable sensing point 0 */ - mt_reg_sync_writel_print(0x00000201, - offset + LVTSMONCTL0_0); - break; - case 2: - /* enable sensing point 0,1 */ - mt_reg_sync_writel_print(0x00000203, - offset + LVTSMONCTL0_0); - break; - case 3: - /* enable sensing point 0,1,2 */ - mt_reg_sync_writel_print(0x00000207, - offset + LVTSMONCTL0_0); - break; - case 4: - /* enable sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(0x0000020F, - offset + LVTSMONCTL0_0); - break; - default: - lvts_printk("Error at %s\n", __func__); - break; - } - } -} - -void lvts_tscpu_thermal_initial_all_tc(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - /* set sensor index of LVTS */ - mt_reg_sync_writel_print(0x13121110, LVTSTSSEL_0 + offset); - /* set calculation scale rules */ - mt_reg_sync_writel_print(0x00000300, LVTSCALSCALE_0 + offset); - /* Set Device Single mode */ - lvts_write_device(0xC1030000, 0x06, 0xB8, i); - - lvts_configure_polling_speed_and_filter(i); - } - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_controller_reg_before_active(); -#endif -} - -static void lvts_disable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_DIS, WD_REQ_RST_MODE); - - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -static void lvts_enable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_EN, WD_REQ_RST_MODE); - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void lvts_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - - lvts_dbg_printk("%s, temperature=%d,temperature2=%d,\n", - __func__, temperature, temperature2); - - /*spend 860~1463 us */ - /*Thermal need to config to direct reset mode - *this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - lvts_set_tc_trigger_hw_protect(temperature, temperature2, i); - } - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_enable_rgu_reset(); -#else - hw_protect_setting_done = 1; -#endif -} - -void lvts_tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - int temp2 = 0; - - lvts_dbg_printk("%s\n", __func__); - - /* reset AP thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_CLR); - - - - - /* reset MCU thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_SET); - - /* 1: Enables thermal control software reset */ - temp2 |= 0x00001000; - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp2 |= 0x00001000; - - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_CLR); -} - - -void get_lvts_slope_intercept(struct TS_PTPOD *ts_info, enum - thermal_bank_name ts_bank) -{ - struct TS_PTPOD ts_ptpod; - int temp; - - lvts_dbg_printk("%s\n", __func__); - - /* chip dependent */ - - temp = (0 - LVTS_COEFF_A_X_1000) * 2; - temp /= 1000; - ts_ptpod.ts_MTS = temp; - - temp = 500 * g_golden_temp + LVTS_COEFF_B_X_1000; - temp /= 1000; - ts_ptpod.ts_BTS = (temp - 25) * 4; - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - lvts_dbg_printk("(LVTS) ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_lvts_slope_intercept); - -int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "lvts_cal : %d\n", g_use_fake_efuse?0:1); - seq_printf(m, "[lvts_cal] g_golden_temp %d\n", g_golden_temp); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_r%d = 0x%x\n", - i, g_count_r[i]); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_rc%d = 0x%x\n", - i, g_count_rc[i]); - - return 0; -} - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -void lvts_enable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !hw_protect_setting_done - || lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, done=%d, en=%d\n", - __func__, tscpu_is_temp_valid(), - hw_protect_setting_done, lvts_hw_protect_enabled); - return; - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) | 0x80000000, - offset + LVTSMONINT_0); - } - - lvts_enable_rgu_reset(); - - /* clear offset after all HW reset are configured. */ - /* make sure LVTS controller uses latest sensor value to compare */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* clear offset */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) & ~0xFFFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 1; - - lvts_printk("%s: done\n", __func__); -} - -void lvts_disable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, en=%d\n", __func__, - tscpu_is_temp_valid(), lvts_hw_protect_enabled); - return; - } - - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) & 0x7FFFFFFF, - offset + LVTSMONINT_0); - /* set offset to 0x3FFF to avoid interrupt false triggered */ - /* large offset can guarantee temp check is always false */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) | 0x3FFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 0; - - lvts_printk("%s: done\n", __func__); -} -#endif - diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_pmic_efuse.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_pmic_efuse.c deleted file mode 100644 index 43d6ea915230..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_pmic_efuse.c +++ /dev/null @@ -1,824 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include -#include -#include -#include - -#if defined(THERMAL_USE_IIO_CHANNEL) -#include -#include -#endif -/*============================================================= - *Local variable definition - *============================================================= - */ -int mtktspmic_debug_log; -/* Cali */ -static __s32 g_o_vts; -static __s32 g_o_vts_2; -static __s32 g_o_vts_3; -static __s32 g_o_vts_4; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; -static __s32 g_slope1 = 1; -static __s32 g_slope2 = 1; -static __s32 g_intercept; -static __s32 g_tsbuck1_slope1 = 1; -static __s32 g_tsbuck1_slope2 = 1; -static __s32 g_tsbuck1_intercept; -static __s32 g_tsbuck2_slope1 = 1; -static __s32 g_tsbuck2_slope2 = 1; -static __s32 g_tsbuck2_intercept; -static __s32 g_tsbuck3_slope1 = 1; -static __s32 g_tsbuck3_slope2 = 1; -static __s32 g_tsbuck3_intercept; - -static DEFINE_MUTEX(TSPMIC_lock); -static int pre_temp1 = 0, PMIC_counter; -static int pre_tsbuck1_temp1 = 0, tsbuck1_cnt; -static int pre_tsbuck2_temp1 = 0, tsbuck2_cnt; -static int pre_tsbuck3_temp1 = 0, tsbuck3_cnt; -static int pre_tstsx_temp1 = 0, tstsx_cnt; -static int pre_tsdcxo_temp1 = 0, tsdcxo_cnt; - -#if defined(THERMAL_USE_IIO_CHANNEL) -struct iio_channel *chan_chip_temp; -struct iio_channel *chan_vcore_temp; -struct iio_channel *chan_vproc_temp; -struct iio_channel *chan_vgpu_temp; -struct iio_channel *chan_tsx_temp; -struct iio_channel *chan_dcxo_temp; -#endif -/*=============================================================*/ - -static __s32 pmic_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck1_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck1_intercept + - ((g_tsbuck1_slope1 * y_curr) / (g_tsbuck1_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck2_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck2_intercept + - ((g_tsbuck2_slope1 * y_curr) / (g_tsbuck2_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck3_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck3_intercept + - ((g_tsbuck3_slope1 * y_curr) / (g_tsbuck3_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static void mtktspmic_read_efuse(void) -{ - mtktspmic_info("[pmic_debug] start\n"); - /* MT6359 */ - g_o_vts = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS); - g_o_vts_2 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_2); - g_o_vts_3 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_3); - g_o_vts_4 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_4); - g_degc_cali = pmic_get_register_value(PMIC_AUXADC_EFUSE_DEGC_CALI); - g_adc_cali_en = pmic_get_register_value(PMIC_AUXADC_EFUSE_ADC_CALI_EN); - g_o_slope_sign = - pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE_SIGN); - g_o_slope = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE); - g_id = pmic_get_register_value(PMIC_AUXADC_EFUSE_ID); - - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts = %d\n", - g_o_vts); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_2 = %d\n", - g_o_vts_2); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_3 = %d\n", - g_o_vts_3); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_4 = %d\n", - g_o_vts_4); - mtktspmic_info("[pmic_debug] 6359_efuse: g_degc_cali = %d\n", - g_degc_cali); - mtktspmic_info("[pmic_debug] 6359_efuse: g_adc_cali_en = %d\n", - g_adc_cali_en); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope_sign = %d\n", - g_o_slope_sign); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope = %d\n", - g_o_slope); - mtktspmic_info("[pmic_debug] 6359_efuse: g_id = %d\n", - g_id); - - mtktspmic_info("[pmic_debug] end\n"); -} - -void mtktspmic_cali_prepare(void) -{ - mtktspmic_read_efuse(); - - if (g_id == 0) - g_o_slope = 0; - - /* g_adc_cali_en=0;//FIX ME */ - - if (g_adc_cali_en == 0) { /* no calibration */ - mtktspmic_info("[pmic_debug] It isn't calibration values\n"); - g_o_vts = 1600; - g_o_vts_2 = 1600; - g_o_vts_3 = 1600; - g_o_vts_4 = 1600; - g_degc_cali = 50; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - if (g_degc_cali < 38 || g_degc_cali > 60) - g_degc_cali = 53; - - mtktspmic_info("[pmic_debug] g_o_vts = 0x%x\n", g_o_vts); - mtktspmic_info("[pmic_debug] g_o_vts_2 = 0x%x\n", g_o_vts_2); - mtktspmic_info("[pmic_debug] g_o_vts_3 = 0x%x\n", g_o_vts_3); - mtktspmic_info("[pmic_debug] g_o_vts_4 = 0x%x\n", g_o_vts_4); - mtktspmic_info("[pmic_debug] g_degc_cali = 0x%x\n", g_degc_cali); - mtktspmic_info("[pmic_debug] g_adc_cali_en = 0x%x\n", g_adc_cali_en); - mtktspmic_info("[pmic_debug] g_o_slope = 0x%x\n", g_o_slope); - mtktspmic_info("[pmic_debug] g_o_slope_sign = 0x%x\n", g_o_slope_sign); - mtktspmic_info("[pmic_debug] g_id = 0x%x\n", g_id); - -} - -void mtktspmic_cali_prepare2(void) -{ - __s32 vbe_t; - int factor; - - factor = 1681; - - g_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_slope2 = -(factor + g_o_slope); - else - g_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_intercept = g_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_slope1, g_slope2, g_intercept, vbe_t); - - factor = 1863; - - g_tsbuck1_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck1_slope2 = -(factor + g_o_slope); - else - g_tsbuck1_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_2) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck1_intercept = g_tsbuck1_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck1_slope1, g_tsbuck1_slope2, g_tsbuck1_intercept, vbe_t); - - factor = 1863; - - g_tsbuck2_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck2_slope2 = -(factor + g_o_slope); - else - g_tsbuck2_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_3) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck2_intercept = g_tsbuck2_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck2_slope1, g_tsbuck2_slope2, g_tsbuck2_intercept, vbe_t); - - factor = 1863; - - g_tsbuck3_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck3_slope2 = -(factor + g_o_slope); - else - g_tsbuck3_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_4) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck3_intercept = g_tsbuck3_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck3_slope1, g_tsbuck3_slope2, g_tsbuck3_intercept, vbe_t); - -} - -#if defined(THERMAL_USE_IIO_CHANNEL) -void mtktspmic_get_from_dts(struct platform_device *pdev) -{ - int ret; - - chan_chip_temp = iio_channel_get(NULL, "AUXADC_CHIP_TEMP"); - if (IS_ERR(chan_chip_temp)) { - ret = PTR_ERR(chan_chip_temp); - pr_notice("AUXADC_CHIP_TEMP get fail, ret=%d\n", ret); - } - - chan_vcore_temp = iio_channel_get(NULL, "AUXADC_VCORE_TEMP"); - if (IS_ERR(chan_vcore_temp)) { - ret = PTR_ERR(chan_vcore_temp); - pr_notice("AUXADC_VCORE_TEMP get fail, ret=%d\n", ret); - } - - chan_vproc_temp = iio_channel_get(NULL, "AUXADC_VPROC_TEMP"); - if (IS_ERR(chan_vproc_temp)) { - ret = PTR_ERR(chan_vproc_temp); - pr_notice("AUXADC_VPROC_TEMP get fail, ret=%d\n", ret); - } - - chan_vgpu_temp = iio_channel_get(NULL, "AUXADC_VGPU_TEMP"); - if (IS_ERR(chan_vgpu_temp)) { - ret = PTR_ERR(chan_vgpu_temp); - pr_notice("AUXADC_VGPU_TEMP get fail, ret=%d\n", ret); - } - - chan_tsx_temp = iio_channel_get(NULL, "AUXADC_TSX_TEMP"); - if (IS_ERR(chan_tsx_temp)) { - ret = PTR_ERR(chan_tsx_temp); - pr_notice("AUXADC_TSX_TEMP get fail, ret=%d\n", ret); - } - - chan_dcxo_temp = iio_channel_get(NULL, "AUXADC_DCXO_TEMP"); - if (IS_ERR(chan_dcxo_temp)) { - ret = PTR_ERR(chan_dcxo_temp); - pr_notice("AUXADC_DCXO_TEMP get fail, ret=%d\n", ret); - } -} -#endif - -int mtktspmic_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_chip_temp)) { - ret = iio_read_channel_processed(chan_chip_temp, &temp); - if (ret < 0) - pr_notice("pmic_chip_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_CHIP_TEMP); -#endif - temp1 = pmic_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("[pmic_debug] Raw=%d, T=%d\n", temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("[%s] raw=%d, PMIC T=%d", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("[%s] temp(%d) too high, drop this data!\n", - __func__, temp1); - temp1 = pre_temp1; - } else if ((PMIC_counter != 0) - && (((pre_temp1 - temp1) > 30000) - || ((temp1 - pre_temp1) > 30000))) { - mtktspmic_info("[%s] temp diff too large, drop this data\n", - __func__); - temp1 = pre_temp1; - } else { - /* update previous temp */ - pre_temp1 = temp1; - mtktspmic_dprintk("[%s] pre_temp1=%d\n", __func__, pre_temp1); - - if (PMIC_counter == 0) - PMIC_counter++; - } - - - return temp1; -} - -int mt6359vcore_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vcore_temp)) { - ret = iio_read_channel_processed(chan_vcore_temp, &temp); - if (ret < 0) - pr_notice("pmic_vcore_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VCORE_TEMP); -#endif - temp1 = tsbuck1_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck1_temp1; - } else if ((tsbuck1_cnt != 0) - && (((pre_tsbuck1_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck1_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck1_temp1; - } else { - /* update previous temp */ - pre_tsbuck1_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck1_temp1=%d\n", __func__, - pre_tsbuck1_temp1); - - if (tsbuck1_cnt == 0) - tsbuck1_cnt++; - } - - return temp1; -} - -int mt6359vproc_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vproc_temp)) { - ret = iio_read_channel_processed(chan_vproc_temp, &temp); - if (ret < 0) - pr_notice("pmic_vproc_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VPROC_TEMP); -#endif - temp1 = tsbuck2_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck2_temp1; - } else if ((tsbuck2_cnt != 0) - && (((pre_tsbuck2_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck2_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck2_temp1; - } else { - /* update previous temp */ - pre_tsbuck2_temp1 = temp1; - mtktspmic_dprintk("%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck2_temp1); - - if (tsbuck2_cnt == 0) - tsbuck2_cnt++; - } - - return temp1; -} - -int mt6359vgpu_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vgpu_temp)) { - ret = iio_read_channel_processed(chan_vgpu_temp, &temp); - if (ret < 0) - pr_notice("pmic_vgpu_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VGPU_TEMP); -#endif - temp1 = tsbuck3_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck3_temp1; - } else if ((tsbuck3_cnt != 0) - && (((pre_tsbuck3_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck3_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck3_temp1; - } else { - /* update previous temp */ - pre_tsbuck3_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck3_temp1); - - if (tsbuck3_cnt == 0) - tsbuck3_cnt++; - } - - return temp1; -} - -static int u_table[126] = { - 64078, - 63972, - 63860, - 63741, - 63614, - 63480, - 63338, - 63188, - 63029, - 62860, - 62683, - 62495, - 62297, - 62089, - 61870, - 61639, - 61396, - 61140, - 60872, - 60591, - 60297, - 59989, - 59667, - 59330, - 58978, - 58612, - 58230, - 57833, - 57420, - 56991, - 56546, - 56083, - 55605, - 55110, - 54598, - 54071, - 53528, - 52968, - 52393, - 51802, - 51195, - 50573, - 49936, - 49285, - 48620, - 47942, - 47251, - 46548, - 45834, - 45110, - 44375, - 43632, - 42880, - 42121, - 41355, - 40584, - 39808, - 39027, - 38245, - 37460, - 36675, - 35891, - 35106, - 34323, - 33543, - 32768, - 31996, - 31229, - 30469, - 29716, - 28968, - 28231, - 27502, - 26780, - 26070, - 25371, - 24683, - 24004, - 23339, - 22682, - 22042, - 21412, - 20795, - 20191, - 19600, - 19023, - 18458, - 17908, - 17369, - 16846, - 16331, - 15834, - 15347, - 14878, - 14415, - 13969, - 13535, - 13111, - 12701, - 12302, - 11914, - 11539, - 11176, - 10822, - 10482, - 10147, - 9827, - 9517, - 9214, - 8922, - 8637, - 8364, - 8098, - 7840, - 7590, - 7354, - 7120, - 6896, - 6674, - 6467, - 6264, - 6065, - 5876, - 5691, - 5510, - 5339 -}; -#define MIN_TSX_TEMP (-40000) -#define MAX_TSX_TEMP (+85000) -/* Original formula is - * u = auxadc raw * 2^16 / (2^32 - 1) - * Because kernel is not able to deal with floating point - * we changed the formula to - * u = auxadc raw * 2^16 / 2^32 - * => u = auxadc raw / 2^16 - * => u * 2^16 = auxadc raw - */ - -static int tsx_u2t(int auxadc_raw) -{ - int i; - int ret = 0; - int u_upper, u_low, t_upper, t_low; - - if (auxadc_raw > u_table[0]) - return (int) MIN_TSX_TEMP; - if (auxadc_raw < u_table[125]) - return (int) MAX_TSX_TEMP; - - for (i = 0; i < 125; i++) { - if (auxadc_raw < u_table[i] && auxadc_raw >= u_table[i+1]) { - u_upper = u_table[i+1]; - u_low = u_table[i]; - - t_upper = (int) MIN_TSX_TEMP + (i+1) * 1000; - t_low = (int) MIN_TSX_TEMP + i * 1000; - - if ((u_upper - u_low) == 0) - /* This case should not happen */ - ret = t_low; - else - ret = t_low + ((t_upper - t_low) * - (auxadc_raw - u_low)) / - (u_upper - u_low); - - break; - } - } - - return ret; -} - -int mt6359tsx_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_tsx_temp)) { - ret = iio_read_channel_raw(chan_tsx_temp, &raw); - if (ret < 0) - pr_notice("pmic_tsx_temp read fail, ret=%d\n", ret); - } - - temp1 = tsx_u2t(raw); -#else - temp1 = 25000; -#endif - - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tstsx_temp1; - } else if ((tstsx_cnt != 0) - && (((pre_tstsx_temp1 - temp1) > 30000) - || ((temp1 - pre_tstsx_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tstsx_temp1; - } else { - /* update previous temp */ - pre_tstsx_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsx_temp1=%d\n", __func__, - pre_tstsx_temp1); - - if (tstsx_cnt == 0) - tstsx_cnt++; - } - - return temp1; -} - -int mt6359dcxo_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_dcxo_temp)) { - ret = iio_read_channel_raw(chan_dcxo_temp, &raw); - if (ret < 0) - pr_notice("pmic_dcxo_temp read fail, ret=%d\n", ret); - } - - /* Temperature (C) = ((auxadc raw/32768*1.8)-0.545)/(-0.0017)+120 */ - /* From dcxo desiger John Chiang */ - temp1 = (((18000000/32768)*raw) - 5450000) / -17 + 120000; - - if (temp1 < -40000) - temp1 = -40000; - else if (temp1 > 120000) - temp1 = 120000; -#else - temp1 = 25000; -#endif - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsdcxo_temp1; - } else if ((tsdcxo_cnt != 0) - && (((pre_tsdcxo_temp1 - temp1) > 30000) - || ((temp1 - pre_tsdcxo_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsdcxo_temp1; - } else { - /* update previous temp */ - pre_tsdcxo_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_dcxo_temp1=%d\n", __func__, - pre_tsdcxo_temp1); - - if (tsdcxo_cnt == 0) - tsdcxo_cnt++; - } - - return temp1; -} diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_tc.c deleted file mode 100644 index 5bc8f556675c..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_tc.c +++ /dev/null @@ -1,1490 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include - -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; - * 0: turn off - */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include -#include "mtk_thermal_ipi.h" -/*============================================================= - * Local variable definition - *============================================================= - */ - -/* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - -/* chip dependent */ -/* TODO: I assume AHB bus frequecy is 78MHz. Please confirm it. - */ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {L_TS_MCU1, L_TS_MCU2, L_TS_MCU4, L_TS_ABB}, - .ts_number = 4, - .dominator_ts_idx = 2, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x0, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {L_TS_MCU5, L_TS_MCU6, L_TS_MCU7, L_TS_MCU0}, - .ts_number = 4, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x100, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [2] = { - .ts = {L_TS_MCU8, L_TS_MCU9}, - .ts_number = 2, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x200, - .tc_speed = { - 0x00C, - 0x001, - 0x008, - 0x0000030D - } /* 1ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu0; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -/* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ -static __s32 g_o_vtsmcu4; -static __s32 g_o_vtsmcu5; -static __s32 g_o_vtsmcu6; -static __s32 g_o_vtsmcu7; -static __s32 g_o_vtsmcu8; -static __s32 g_o_vtsmcu9; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[L_TS_MCU_NUM] = { 0 }; - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name); -static void set_tc_trigger_hw_protect - (int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -/*=============================================================*/ - -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum -thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("%s\n", __func__); - - /* chip dependent */ - - /* If there are two or more sensors in a bank, choose the sensor - * calibration value of the dominant sensor. You can observe it in the - * thermal document provided by Thermal DE. For example, Bank 1 is - * for SOC + GPU. Observe all scenarios related to GPU simulation test - * cases to decide which sensor is the highest temperature in all cases. - * Then, It is the dominant sensor.(Confirmed by Thermal DE Alfred Tsai) - */ - - /* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK1: - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - case THERMAL_BANK2: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK3: - x_roomt = g_x_roomt[L_TS_MCU2]; - break; - case THERMAL_BANK4: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - /* No bank 5 */ - case THERMAL_BANK6: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - case THERMAL_BANK7: - x_roomt = g_x_roomt[L_TS_MCU0]; - break; - default: /* choose the highest simulation hot-spot */ - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - } - - - /* - * The equations in this function are confirmed by Thermal DE Alfred - * Tsai. Don't have to change until using next generation thermal - * sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1534 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1534 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = - ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1534 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1534 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - tscpu_printk("[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - tscpu_printk("[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - tscpu_printk("[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - tscpu_printk("[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - tscpu_printk("[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - tscpu_printk("[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); -} - -void eDataCorrector(void) -{ - - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu0 < -8 || g_o_vtsmcu0 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu0 = 260; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - if (g_o_vtsmcu4 < -8 || g_o_vtsmcu4 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu4\n"); - g_o_vtsmcu4 = 260; - } - if (g_o_vtsmcu5 < -8 || g_o_vtsmcu5 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu5\n"); - g_o_vtsmcu5 = 260; - } - if (g_o_vtsmcu6 < -8 || g_o_vtsmcu6 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu6\n"); - g_o_vtsmcu6 = 260; - } - if (g_o_vtsmcu7 < -8 || g_o_vtsmcu7 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu7\n"); - g_o_vtsmcu7 = 260; - } - if (g_o_vtsmcu8 < -8 || g_o_vtsmcu8 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu8 = 260; - } - if (g_o_vtsmcu9 < -8 || g_o_vtsmcu9 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu9 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2, temp3, temp4; - - temp0 = get_devinfo_with_index(ADDRESS_INDEX_0); /* 0184 */ - temp1 = get_devinfo_with_index(ADDRESS_INDEX_1); /* 0180 */ - temp2 = get_devinfo_with_index(ADDRESS_INDEX_2); /* 0188 */ - temp3 = get_devinfo_with_index(ADDRESS_INDEX_3); /* 01AC */ - temp4 = get_devinfo_with_index(ADDRESS_INDEX_4); /* 01B0 */ - - pr_notice( - "[calibration] tmp0=0x%x, tmp1=0x%x, tmp2=0x%x\n", - temp0, temp1, temp2); - pr_notice( - "[calibration] tmp3=0x%x, tmp4=0x%x\n", - temp3, temp4); - - g_adc_ge_t = ((temp0 & _BITMASK_(31:22)) >> 22); - g_adc_oe_t = ((temp0 & _BITMASK_(21:12)) >> 12); - - - g_o_vtsmcu0 = ((temp1 & _BITMASK_(25:17)) >> 17); - g_o_vtsmcu1 = ((temp1 & _BITMASK_(16:8)) >> 8); - g_o_vtsmcu2 = (temp0 & _BITMASK_(8:0)); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = ((temp2 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu5 = ((temp2 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu6 = ((temp3 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu7 = ((temp3 & _BITMASK_(22:14)) >> 14); - g_o_vtsmcu8 = ((temp3 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu9 = ((temp4 & _BITMASK_(31:23)) >> 23); - g_o_vtsabb = ((temp2 & _BITMASK_(22:14)) >> 14); - - g_degc_cali = ((temp1 & _BITMASK_(6:1)) >> 1); - g_adc_cali_en_t = (temp1 & _BIT_(0)); - g_o_slope_sign = ((temp1 & _BIT_(7)) >> 7); - g_o_slope = ((temp1 & _BITMASK_(31:26)) >> 26); - - g_id = ((temp0 & _BIT_(9)) >> 9); - - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu0 = 260; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = 260; - g_o_vtsmcu5 = 260; - g_o_vtsmcu6 = 260; - g_o_vtsmcu7 = 260; - g_o_vtsmcu8 = 260; - g_o_vtsmcu9 = 260; - g_o_vtsabb = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[L_TS_MCU_NUM] = { 0 }; - int i = 0; -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - struct thermal_ipi_data thermal_data; -#endif - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[0] = (g_o_vtsmcu0 + 3350 - g_oe); - format[1] = (g_o_vtsmcu1 + 3350 - g_oe); - format[2] = (g_o_vtsmcu2 + 3350 - g_oe); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - format[3] = (g_o_vtsmcu4 + 3350 - g_oe); - format[4] = (g_o_vtsmcu5 + 3350 - g_oe); - format[5] = (g_o_vtsmcu6 + 3350 - g_oe); - format[6] = (g_o_vtsmcu7 + 3350 - g_oe); - format[7] = (g_o_vtsmcu8 + 3350 - g_oe); - format[8] = (g_o_vtsmcu9 + 3350 - g_oe); - format[9] = (g_o_vtsabb + 3350 - g_oe); - - for (i = 0; i < L_TS_MCU_NUM; i++) { - /* x_roomt * 10000 */ - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; - } - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, - g_x_roomt[i]); -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - thermal_data.u.data.arg[0] = g_degc_cali; - thermal_data.u.data.arg[1] = g_o_slope_sign; - thermal_data.u.data.arg[2] = g_o_slope; - while (thermal_to_mcupm(THERMAL_IPI_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_oe; - thermal_data.u.data.arg[1] = g_gain; - thermal_data.u.data.arg[2] = g_x_roomt[L_TS_MCU8]; - while (thermal_to_mcupm(THERMAL_IPI_INIT_GRP2, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_x_roomt[L_TS_MCU9]; - while (thermal_to_mcupm(THERMAL_IPI_INIT_GRP3, &thermal_data) != 0) - udelay(100); -#endif -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1534+O_slope*10)/10*(18/15)* - * (1/10000)+X_roomtabb]*Gain*4096 + OE - */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n", - * ts_name,xtoomt); - */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 + g_o_slope * 10)); - else /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 - g_o_slope * 10)); - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} -static void thermal_dump_debug_logs(int tc_num) -{ - int offset; - unsigned int auxadc_data11, ts_con0, ts_con1; - unsigned int tempmsr0, tempmsr1, tempmsr2, tempmsr3; - - offset = tscpu_g_tc[tc_num].tc_offset; - - auxadc_data11 = readl(AUXADC_DAT11_V); - ts_con0 = readl(TS_CON0_TM); - ts_con1 = readl(TS_CON1_TM); - tempmsr0 = readl((offset + TEMPMSR0)); - tempmsr1 = readl((offset + TEMPMSR1)); - tempmsr2 = readl((offset + TEMPMSR2)); - tempmsr3 = readl((offset + TEMPMSR3)); - - tscpu_printk("AUXADC_DAT11 = 0x%x, TS_CON0 = 0x%x, TS_CON1 = 0x%x\n", - auxadc_data11, ts_con0, ts_con1); - tscpu_printk("TEMPMSR0_%d = 0x%x, TEMPMSR1_%d = 0x%x\n", - tc_num, tempmsr0, tc_num, tempmsr1); - tscpu_printk("TEMPMSR2_%d = 0x%x, TEMPMSR3_%d = 0x%x\n", - tc_num, tempmsr2, tc_num, tempmsr3); -} -static void thermal_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); - - tscpu_printk( - "[Thermal IRQ] Auxadc thermal_tc %d, TEMPMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_COLD_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 2\n"); - - if (ret & THERMAL_AHB_TIMEOUT_INTERRUPT) - tscpu_dprintk( - "[Thermal IRQ]: AHB bus timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 1 int triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 2 int triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) { - tscpu_printk( - "[Thermal IRQ]: Thermal protection stage 3 int triggered\n"); - tscpu_printk("[Thermal IRQ]: Thermal HW reboot!!"); - thermal_dump_debug_logs(tc_num); - } -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - ret = ret & 0x7F; - - /* MSB LSB NAME - * 6 6 LVTSINT3 - * 5 5 LVTSINT2 - * 4 4 LVTSINT1 - * 3 3 LVTSINT0 - * 2 2 THERMINT2 - * 1 1 THERMINT1 - * 0 0 THERMINT0 - */ - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - unsigned int offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tempMonCtl1 = (tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0)); - - tempMonCtl2 = (((tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay & - _BITMASK_(9:0))); - - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.ahb_polling_interval; - - /* Calculating period unit in Module clock x 256, - * and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* bus clock 66M counting unit is 12 * 1/66M * 256 = - * 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - * filt interval is 1 * 46.545us = 46.545us, - * sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /* AHB polling is 781* 1/66M = 11.833us */ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - /* temperature sampling control, 4 out of 6 samples */ - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - /* temperature sampling control, 8 out of 10 samples */ - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - /* temperature sampling control, 16 out of 18 samples */ - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); -#else /* default 1 */ - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); -#endif - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); - - /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET3); - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); - - /* AHB value for auxadc enable */ - mt_reg_sync_writel(0x800, offset + TEMPADCEN); - - /* - * AHB address for auxadc enable (channel 0 immediate mode selected) - * this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void set_tc_trigger_hw_protect -(int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, d_index, config; - enum tsmcu_sensor_enum ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* temperature2=80000; test only */ - tscpu_dprintk("%s t1=%d t2=%d\n", __func__, temperature, - temperature2); - - if (tscpu_g_tc[tc_num].dominator_ts_idx < - tscpu_g_tc[tc_num].ts_number){ - d_index = tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - tscpu_printk("Error: Auxadc TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - tscpu_g_tc[tc_num].dominator_ts_idx, - tscpu_g_tc[tc_num].ts_number); - - tscpu_printk("Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - - ts_name = tscpu_g_tc[tc_num].ts[d_index]; - - /* temperature to trigger SPM state2 */ - if (tc_num == THERMAL_CONTROLLER2) - raw_high = temperature_to_raw_room(105000, ts_name); - else - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); - - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel(config, offset + TEMPPROTCTL); - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); - - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); -} - -static int read_tc_raw_and_temp( -u32 *tempmsr_name, enum tsmcu_sensor_enum ts_name) -{ - int temp = 0, raw = 0; -#if CONFIG_LVTS_ERROR_AEE_WARNING - int raw1; -#endif - - if (tempmsr_name == 0) - return 0; - -#if CONFIG_LVTS_ERROR_AEE_WARNING - raw = readl(tempmsr_name); - raw1 = ((raw & _BIT_(15)) >> 15); - raw = raw & 0xFFF; -#else - raw = readl(tempmsr_name) & 0xFFF; -#endif - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_mcu_temp_r[ts_name] = raw; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_mcu_temp_v[ts_name] = raw1; -#endif - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp_r[ts_name] = tscpu_ts_mcu_temp_r[ts_name]; -#endif - return temp * 100; -} - -void tscpu_thermal_read_tc_temp( -int tc_num, enum tsmcu_sensor_enum type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, - tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 1: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 2: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 3: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - default: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - } - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp[type] = tscpu_ts_mcu_temp[type]; -#endif -} - -void read_all_tc_tsmcu_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_read_tc_temp(i, tscpu_g_tc[i].ts[j], j); -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - - /* write temp to spare register */ - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); - - /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL1); - - /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); - - /* polling interval to check if temperature sense is ready */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); - - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - - /* temperature measurement sampling control */ - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) - * automatically by hw - */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); - - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); - - /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); - - /* enable auxadc mux & pnp write transaction */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - - - /* enable all interrupt except filter sense and - * immediate sense interrupt - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - /* enable all sensing point(sensing point 2 is unused)*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum tsmcu_sensor_enum type) -{ - switch (type) { - case L_TS_MCU0: - return TEMPADC_MCU0; - case L_TS_MCU1: - return TEMPADC_MCU1; - case L_TS_MCU2: - return TEMPADC_MCU2; - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - case L_TS_MCU4: - return TEMPADC_MCU4; - case L_TS_MCU5: - return TEMPADC_MCU5; - case L_TS_MCU6: - return TEMPADC_MCU6; - case L_TS_MCU7: - return TEMPADC_MCU7; - case L_TS_MCU8: - return TEMPADC_MCU8; - case L_TS_MCU9: - return TEMPADC_MCU9; - case L_TS_ABB: - return TEMPADC_ABB; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - - /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); - - /* disable auxadc channel 11 immediate mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - int wd_api_ret; - struct wd_api *wd_api; - - tscpu_dprintk("%s,temperature=%d,temperature2=%d\n", __func__, - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /* spend 860~1463 us */ - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - wd_api_ret = get_wd_api(&wd_api); - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_DIS, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_notice("resume time spent, sec : %lu , usec : %lu\n", - (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - set_tc_trigger_hw_protect(temperature, temperature2, i); - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_EN, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - - seq_printf(m, "[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - seq_printf(m, "[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - seq_printf(m, "[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - seq_printf(m, "[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - seq_printf(m, "[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - seq_printf(m, "[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - seq_printf(m, "[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_id = %d\n", g_id); - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - return 0; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -int check_auxadc_mcu_efuse(void) -{ - return g_adc_cali_en_t; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /* Need to confirm with DE */ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /* The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if (cg_freq & _BIT_(4)) - ahbClk = clockSource / 2; - else if (cg_freq & _BIT_(3)) - ahbClk = clockSource / 4; - else if (cg_freq & _BIT_(2)) - ahbClk = clockSource / 8; - else if (cg_freq & _BIT_(1)) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /* tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm); */ - /* tscpu_printk("AHB bus clock= %d MHz\n", ahbClk); */ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "L %d B %d", - get_immediate_cpuL_wrap(), get_immediate_cpuB_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_tc_wrapper.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_tc_wrapper.c deleted file mode 100644 index e692168e1615..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_tc_wrapper.c +++ /dev/null @@ -1,1012 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include "mtk_idle.h" - -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -#include -#endif - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#include -#include -#if DUMP_VCORE_VOLTAGE -#include -#endif -struct lvts_error_data { - int ts_temp[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_r[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_v[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ -#if DUMP_VCORE_VOLTAGE - int vcore_voltage[R_BUFFER_SIZE]; /* A ring buffer */ -#endif - int c_index; /* Current index points to the space to replace.*/ - int e_occurred; /* 1: An error occurred, 0: Nothing happened*/ - int f_count; /* Future count */ - enum thermal_sensor e_mcu; - enum thermal_sensor e_lvts; -}; -struct lvts_error_data g_lvts_e_data; -int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#endif - - -#if CFG_THERM_LVTS -int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; -#endif - -int tscpu_curr_cpu_temp; -int tscpu_curr_gpu_temp; -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -static int ignore_hot_sensor; -#endif - -static int tscpu_curr_max_ts_temp; - -int __attribute__ ((weak)) - mtk_idle_notifier_register(struct notifier_block *n) -{ - return 0; -} - -int get_immediate_none_wrap(void) -{ - return -127000; -} - -/* chip dependent */ -int get_immediate_cpuL_wrap(void) -{ - int curr_temp; - - curr_temp = MAX( - MAX(tscpu_ts_lvts_temp[L_TS_LVTS2_0], - tscpu_ts_lvts_temp[L_TS_LVTS2_1]), - MAX(tscpu_ts_lvts_temp[L_TS_LVTS2_2], - tscpu_ts_lvts_temp[L_TS_LVTS2_3]) - ); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS1_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS1_0], - tscpu_ts_lvts_temp[L_TS_LVTS1_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_vpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS4_0], - tscpu_ts_lvts_temp[L_TS_LVTS4_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_0], - tscpu_ts_lvts_temp[L_TS_LVTS3_1]); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - -int get_immediate_infa_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_2]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_camsys_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_2]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_md_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(MAX(tscpu_ts_lvts_temp[L_TS_LVTS5_0], - tscpu_ts_lvts_temp[L_TS_LVTS5_1]), - tscpu_ts_lvts_temp[L_TS_LVTS5_2]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - - -/* - * module LVTS Plan - *===================================================== - * MCU_BIG LVTS1-0, LVTS1-1 - * MCU_LITTLE LVTS2-0, LVTS2-1, LVTS2-2, LVTS2-3 - * GPU LVTS3-0, LVTS3-1 - * SOC TOP LVTS3-2, LVTS3-3 - * VPU LVTS4-0, LVTS4-1 - * MD-4G LVTS5-0 - * MD-5G LVTS5-1 - * MD-3G LVTS5-2 - */ - -/* - * THERMAL_BANK0, //B CPU (LVTS1) - * THERMAL_BANK1, //L CPU (LVTS2) - * THERMAL_BANK2, //GPU (LVTS3) - * THERMAL_BANK3, //VPU (LVTS4) - * THERMAL_BANK4, //MD (LVTS5) - */ - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpuB_LVTS1_wrap, - get_immediate_cpuL_wrap, - get_immediate_gpu_wrap, - get_immediate_vpu_wrap, - get_immediate_md_wrap -}; - -int get_immediate_cpuB_wrap(void) -{ - int curr_temp; - - curr_temp = get_immediate_cpuB_LVTS1_wrap(); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - - - -int get_immediate_ts0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS1_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts4_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts5_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts6_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts7_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts8_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts9_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -#if CFG_THERM_LVTS -int get_immediate_tslvts1_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts1_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} -int get_immediate_tslvts2_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts5_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts5_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} -int get_immediate_tslvts5_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -#endif - -int get_immediate_tsabb_wrap(void) -{ - - return 0; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - -#if CFG_THERM_LVTS - get_immediate_tslvts1_0_wrap, - get_immediate_tslvts1_1_wrap, - get_immediate_tslvts2_0_wrap, - get_immediate_tslvts2_1_wrap, - get_immediate_tslvts2_2_wrap, - get_immediate_tslvts2_3_wrap, - get_immediate_tslvts3_0_wrap, - get_immediate_tslvts3_1_wrap, - get_immediate_tslvts3_2_wrap, - get_immediate_tslvts3_3_wrap, - get_immediate_tslvts4_0_wrap, - get_immediate_tslvts4_1_wrap, - get_immediate_tslvts5_0_wrap, - get_immediate_tslvts5_1_wrap, - get_immediate_tslvts5_2_wrap -#endif -}; - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -#if CFG_THERM_LVTS -int tscpu_max_temperature(void) -{ - int i, j, max = 0; - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_dprintk("lvts_max_temperature %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - if (i == 0 && j == 0) { - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } else { - if (max < tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } - } - } -#endif /* CFG_THERM_LVTS */ -#else - tscpu_dprintk("tscpu_get_temp %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) { - if (i == 0 && j == 0) { - max = tscpu_ts_mcu_temp[tscpu_g_tc[i].ts[j]]; - } else { - if (max < tscpu_ts_mcu_temp[ - tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_mcu_temp[ - tscpu_g_tc[i].ts[j]]; - } - } - } -#endif /* CFG_LVTS_DOMINATOR */ - return max; -} -#endif - -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of thermal - * controller driver - */ - /* - * module LVTS Plan - *===================================================== - * MCU_BIG LVTS1-0, LVTS1-1 - * MCU_LITTLE LVTS2-0, LVTS2-1, LVTS2-2, LVTS2-3 - * GPU LVTS3-0, LVTS3-1 - * SOC TOP LVTS3-2, LVTS3-3 - * VPU LVTS4-0, LVTS4-1 - * MD-4G LVTS5-0 - * MD-5G LVTS5-1 - * MD-3G LVTS5-2 - */ - - - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_curr_cpu_temp = - MAX( - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS2_0], - tscpu_ts_lvts_temp[TS_LVTS2_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS2_2], - tscpu_ts_lvts_temp[TS_LVTS2_3]) - )), - (MAX( - tscpu_ts_lvts_temp[TS_LVTS1_0], - tscpu_ts_lvts_temp[TS_LVTS1_1]) - ) - ); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_lvts_temp[TS_LVTS3_0], - tscpu_ts_lvts_temp[TS_LVTS3_1]); -#endif /* CFG_THERM_LVTS */ -#else - /* It is platform dependent which TS is better to present CPU/GPU - * temperature - */ - tscpu_curr_cpu_temp = MAX( - MAX(MAX(tscpu_ts_temp[TS_MCU5], tscpu_ts_temp[TS_MCU6]), - MAX(tscpu_ts_temp[TS_MCU7], tscpu_ts_temp[TS_MCU8])), - tscpu_ts_temp[TS_MCU9]); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_temp[TS_MCU1], - tscpu_ts_temp[TS_MCU2]); -#endif /* CFG_LVTS_DOMINATOR */ -#endif /* PRECISE_HYBRID_POWER_BUDGET */ - - /* though tscpu_max_temperature is common, put it in mtk_ts_cpu.c is - * weird. - */ - - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -char mcu_s_array[TS_ENUM_MAX][17] = { -#if CFG_THERM_LVTS - "TS_LVTS1_0", - "TS_LVTS1_1", - "TS_LVTS2_0", - "TS_LVTS2_1", - "TS_LVTS2_2", - "TS_LVTS2_3", - "TS_LVTS3_0", - "TS_LVTS3_1", - "TS_LVTS3_2", - "TS_LVTS3_3", - "TS_LVTS4_0", - "TS_LVTS4_1", - "TS_LVTS5_0", - "TS_LVTS5_1", - "TS_LVTS5_2" - #endif -}; - -static void dump_lvts_error_info(void) -{ - int i, j, index, e_index, offset; -#if DUMP_LVTS_REGISTER - int cnt, temp; -#endif - enum thermal_sensor mcu_index, lvts_index; - char buffer[512]; - - mcu_index = g_lvts_e_data.e_mcu; - lvts_index = g_lvts_e_data.e_lvts; - index = g_lvts_e_data.c_index; - e_index = (index + HISTORY_SAMPLES + 1) % R_BUFFER_SIZE; - - tscpu_printk("[LVTS_ERROR][DUMP] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - g_lvts_e_data.ts_temp[mcu_index][e_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[lvts_index][e_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index], - LVTS_ERROR_THRESHOLD); - - for (i = TS_MCU1; i <= TS_LVTS4_1; i++) { - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[i]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) - % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[i][index]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - } - - offset = sprintf(buffer, "[LVTS_ERROR][%s_R][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[mcu_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[mcu_index][index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - dump_efuse_data(); -#if DUMP_LVTS_REGISTER - read_controller_reg_when_error(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -#endif -#if DUMP_VCORE_VOLTAGE - offset = sprintf(buffer, "[LVTS_ERROR][Vcore_V][DUMP] ", - mcu_s_array[lvts_index]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.vcore_voltage[index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -#endif -#if DUMP_LVTS_REGISTER - lvts_reset_device_and_stop_clk(); -#endif -#ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, __func__, - "LVTS_ERROR: %s, %s diff: %d\n", mcu_s_array[mcu_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index]); -#endif - - g_lvts_e_data.e_occurred = 0; - g_lvts_e_data.f_count = -1; -#if DUMP_LVTS_REGISTER - clear_lvts_register_value_array(); - - lvts_device_identification(); - lvts_Device_Enable_Init_all_Devices(); - lvts_device_read_count_RC_N(); - lvts_efuse_setting(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - Enable_LVTS_CTRL_for_thermal_Data_Fetch(); - lvts_tscpu_thermal_initial_all_tc(); -#endif -} - -static void check_lvts_error(enum thermal_sensor mcu_index, - enum thermal_sensor lvts_index) -{ - int temp; - - temp = tscpu_ts_temp[mcu_index] - tscpu_ts_temp[lvts_index]; - - if (temp < 0) - temp = temp * -1; - - /*Skip if LVTS thermal controllers doens't ready */ - if (temp > 100000) - return; - - if (temp > LVTS_ERROR_THRESHOLD) { - tscpu_printk("[LVTS_ERROR] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - tscpu_ts_temp[mcu_index], - mcu_s_array[lvts_index], - tscpu_ts_temp[lvts_index], - tscpu_ts_temp[mcu_index] - - tscpu_ts_temp[lvts_index], - LVTS_ERROR_THRESHOLD); - g_lvts_e_data.e_occurred = 1; - g_lvts_e_data.e_mcu = mcu_index; - g_lvts_e_data.e_lvts = lvts_index; - g_lvts_e_data.f_count = -1; - } -} -void dump_lvts_error_data_info(void) -{ - char buffer[512]; - int offset, j; - - tscpu_printk("[LVTS_ERROR] c_index %d, e_occurred %d, f_count %d\n", - g_lvts_e_data.c_index, g_lvts_e_data.e_occurred, - g_lvts_e_data.f_count); - tscpu_printk("[LVTS_ERROR] e_mcu %d, e_lvts %d\n", g_lvts_e_data.e_mcu, - g_lvts_e_data.e_lvts); - - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_raw][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -} -#endif - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - seq_printf(m, "curr_temp = %d\n", tscpu_get_curr_max_ts_temp()); - -#if !defined(CFG_THERM_NO_AUXADC) - tscpu_dump_cali_info(m, v); -#endif - -#if CFG_THERM_LVTS - seq_puts(m, "-----------------\n"); - lvts_tscpu_dump_cali_info(m, v); -#endif - return 0; -} - -static int thermal_idle_notify_call(struct notifier_block *nfb, - unsigned long id, - void *arg) -{ - switch (id) { - case NOTIFY_DPIDLE_ENTER: - break; - case NOTIFY_SOIDLE_ENTER: - break; - case NOTIFY_DPIDLE_LEAVE: - break; - case NOTIFY_SOIDLE_LEAVE: - break; - case NOTIFY_SOIDLE3_ENTER: -#if LVTS_VALID_DATA_TIME_PROFILING - SODI3_count++; - if (SODI3_count != 1 && isTempValid == 0) - noValid_count++; - - if (isTempValid == 1 || SODI3_count == 1) - start_timestamp = thermal_get_current_time_us(); - - isTempValid = 0; -#endif - break; - case NOTIFY_SOIDLE3_LEAVE: -#if CFG_THERM_LVTS - lvts_sodi3_release_thermal_controller(); -#endif - break; - default: - /* do nothing */ - break; - } - return NOTIFY_OK; -} - -static struct notifier_block thermal_idle_nfb = { - .notifier_call = thermal_idle_notify_call, -}; - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - } - - /*tscpu_printk("[THERM_CTRL] thermal_base= 0x%px\n",thermal_base);*/ - - /*get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", - thermal_irq_number); - if (!thermal_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_irq_number); - return 0; - } - - /*get thermal irq num */ - thermal_mcu_irq_number = irq_of_parse_and_map(node, 1); - tscpu_printk("[THERM_CTRL] mcu_irq_num = %d\n", - thermal_mcu_irq_number); - if (!thermal_mcu_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_mcu_irq_number); - return 0; - } - - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - /*tscpu_printk("[THERM_CTRL] phy_base=0x%x\n", thermal_phy_base);*/ - - - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6768-auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,infracfg_ao"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - - if (infracfg_ao_base) - mtk_idle_notifier_register(&thermal_idle_nfb); - } - - node = of_find_compatible_node(NULL, NULL, - "mediatek,mt6877-apmixedsys"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base=\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); - if (!node) { - pr_notice("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_notice("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); - - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - clk_disable_unprepare(therm_main); - return ret; -} - -#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR -#define CPU_SEGMENT 7 -int tscpu_check_cpu_segment(void) -{ - int val = (get_devinfo_with_index(CPU_SEGMENT) & 0xFF); - - if (val == 0x30) - ignore_hot_sensor = 1; - else - ignore_hot_sensor = 0; - - return val; -} -#endif - diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_thermal_ipi.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_thermal_ipi.c deleted file mode 100644 index 0178335690fa..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_thermal_ipi.c +++ /dev/null @@ -1,550 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include "mtk_thermal_ipi.h" -//#include "mtk_thermal_sspm_ipi.h" -#include "mach/mtk_thermal.h" -#include "tscpu_settings.h" -#include "linux/mutex.h" -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -//#define EARLY_PORTING -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -#ifndef EARLY_PORTING -static DEFINE_MUTEX(thermo_sspm_mutex); -static int is_thermal_ipi_registered; -static int ack_data; - -static int register_thermal_ipi(void) -{ - int ret2; - -#ifndef THERMAL_CPUTOEB_USE_PLATFORM_IPI - int ret; - - ret = mtk_ipi_register(&mcupm_ipidev, CH_S_PLATFORM, NULL, NULL, - (void *)&ack_data); - if (ret != 0) { - tscpu_printk("%s error ret:%d\n", __func__, ret); - return -1; - } -#endif - - ret2 = mtk_ipi_register(&sspm_ipidev, IPIS_C_THERMAL, NULL, NULL, - (void *)&ack_data); - if (ret2 != 0) { - tscpu_printk("%s error ret:%d\n", __func__, ret2); - return -1; - } - is_thermal_ipi_registered = 1; -tscpu_printk("%s ret2:%d\n", __func__, ret2); - return 0; -} -#endif -unsigned int thermal_to_sspm( - unsigned int cmd, struct thermal_ipi_data *thermal_data) -{ - int ackData = -1; - int ret; - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_INIT_GRP1: - case THERMAL_IPI_INIT_GRP2: - case THERMAL_IPI_INIT_GRP3: - case THERMAL_IPI_INIT_GRP4: - case THERMAL_IPI_INIT_GRP5: - case THERMAL_IPI_INIT_GRP6: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send init cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_LVTS_INIT_GRP1: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) lvts efuse to SSPM (%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_GET_TEMP: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send get_temp cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_SET_BIG_FREQ_THRESHOLD: - case THERMAL_IPI_GET_BIG_FREQ_THRESHOLD: - thermal_data->cmd = cmd; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("mtk_ipi_send_compl error ret:%d - %d\n", - cmd, ret); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_SET_DIS_THERMAL_THROTTLE: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) disable SSPM thermal throttle(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - case THERMAL_IPI_SUSPEND_RESUME_NOTIFY: - thermal_data->cmd = cmd; - //tscpu_printk("cmd(%d) kernel suspend/resume(%d)\n", - // cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - default: - tscpu_printk("cmd(%d) wrong!!\n", cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ackData; /** It's weird here. What should be returned? */ -} -unsigned int thermal_to_mcupm( - unsigned int cmd, struct thermal_ipi_data *thermal_data) -{ - -#ifdef EARLY_PORTING - return 0; -#else - int ackData = -1; - int ret; - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_INIT_GRP1: - case THERMAL_IPI_INIT_GRP2: - case THERMAL_IPI_INIT_GRP3: - case THERMAL_IPI_INIT_GRP4: - case THERMAL_IPI_INIT_GRP5: - case THERMAL_IPI_INIT_GRP6: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send init cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_LVTS_INIT_GRP1: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) lvts efuse to MCUPM (%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_GET_TEMP: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send get_temp cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_SET_BIG_FREQ_THRESHOLD: - case THERMAL_IPI_GET_BIG_FREQ_THRESHOLD: - thermal_data->cmd = cmd; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("mtk_ipi_send_compl error ret:%d - %d\n", - cmd, ret); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_SET_DIS_THERMAL_THROTTLE: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) disable SSPM thermal throttle(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - case THERMAL_IPI_SUSPEND_RESUME_NOTIFY: - thermal_data->cmd = cmd; - //tscpu_printk("cmd(%d) kernel suspend/resume(%d)\n", - // cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - default: - tscpu_printk("cmd(%d) wrong!!\n", cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ackData; /** It's weird here. What should be returned? */ -#endif -} - -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -int atm_to_sspm(unsigned int cmd, int data_len, -struct thermal_ipi_data *thermal_data, int *ackData) -{ -#ifdef EARLY_PORTING - return 0; -#else - int ret = -1; - - if (data_len < 1 || data_len > 3) { - *ackData = -1; - return ret; - } - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_SET_ATM_CFG_GRP1: - case THERMAL_IPI_SET_ATM_CFG_GRP2: - case THERMAL_IPI_SET_ATM_CFG_GRP3: - case THERMAL_IPI_SET_ATM_CFG_GRP4: - case THERMAL_IPI_SET_ATM_CFG_GRP5: - case THERMAL_IPI_SET_ATM_CFG_GRP6: - case THERMAL_IPI_SET_ATM_CFG_GRP7: - case THERMAL_IPI_SET_ATM_CFG_GRP8: - case THERMAL_IPI_SET_ATM_TTJ: - case THERMAL_IPI_SET_ATM_EN: - case THERMAL_IPI_GET_ATM_CPU_LIMIT: - case THERMAL_IPI_GET_ATM_GPU_LIMIT: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&mcupm_ipidev, CH_S_PLATFORM, - IPI_SEND_WAIT, thermal_data, (data_len+1), 2000); - if ((ret != 0) || (ack_data < 0)) - tscpu_printk("%s cmd %d ret %d ack %d\n", - __func__, cmd, ret, ack_data); - - *ackData = ack_data; - - break; - - default: - tscpu_printk("%s cmd %d err!\n", __func__, cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ret; -#endif -} - -static int get_sspm_tz_temp_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_GET_TEMP, &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show current temperature in SSPM UART log\n"); - - return 0; -} - -static int get_sspm_tz_temp_open(struct inode *inode, struct file *file) -{ - return single_open(file, get_sspm_tz_temp_read, NULL); -} - -static const struct file_operations get_sspm_tz_temp_fops = { - .owner = THIS_MODULE, - .open = get_sspm_tz_temp_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static ssize_t set_sspm_big_limit_threshold_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int arrayIndex, bigCoreTj, bigCoreExitTj, bigCoreFreqUpperBound; - struct thermal_ipi_data thermal_data; - - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - - if (sscanf(desc, "%d %d %d", &arrayIndex, &bigCoreTj, - &bigCoreFreqUpperBound) == 3) { - if ((arrayIndex >= BIG_CORE_THRESHOLD_ARRAY_SIZE) || - (arrayIndex < 0)) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreTj; - thermal_data.u.data.arg[2] = bigCoreFreqUpperBound; - - while (thermal_to_mcupm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } else if (sscanf(desc, "%d %d", &arrayIndex, &bigCoreExitTj) == 2) { - if (arrayIndex != -1) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreExitTj; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } - - tscpu_printk("%s bad argument: %s\n", __func__, desc); - return -EINVAL; - -} - -static int set_sspm_big_limit_threshold_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - seq_puts(m, "Use this command to change big core freq limit threshold\n"); - seq_puts(m, " echo arrayIndex BigCoreTj bigCoreFreqUpperBound >\n"); - seq_puts(m, " /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_printf(m, " arrayIndex is not larger than or equal to %d\n", - BIG_CORE_THRESHOLD_ARRAY_SIZE); - seq_puts(m, " BigCoreTj is in m'C\n"); - seq_puts(m, " BigCoreFreqUpperBound is in MHz\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo 0 85000 2050 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, "Use this command to change exit point\n"); - seq_puts(m, " echo -1 BigCoreExitTj > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, " BigCoreExitTj is in m'C\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo -1 75000 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_mcupm(THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show big core frequency thresholds in SSPM UART log\n"); - - return 0; -} - -static int set_sspm_big_limit_threshold_open(struct inode *inode, - struct file *file) -{ - return single_open(file, set_sspm_big_limit_threshold_read, NULL); -} - -static const struct file_operations set_sspm_big_limit_threshold_fops = { - .owner = THIS_MODULE, - .open = set_sspm_big_limit_threshold_open, - .read = seq_read, - .llseek = seq_lseek, - .write = set_sspm_big_limit_threshold_write, - .release = single_release, -}; -static int __init thermal_ipi_init(void) -{ - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *thermal_ipi_dir = NULL; - - tscpu_printk("[%s]\n", __func__); - - - thermal_ipi_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!thermal_ipi_dir) { - tscpu_printk( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("get_sspm_tz_temp", 444, thermal_ipi_dir, - &get_sspm_tz_temp_fops); - if (entry) - proc_set_user(entry, uid, gid); - entry = - proc_create("set_sspm_big_limit_threshold", 664, - thermal_ipi_dir, &set_sspm_big_limit_threshold_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - return 0; -} - -static void __exit thermal_ipi_exit(void) -{ - tscpu_printk("[%s]\n", __func__); -} - -module_init(thermal_ipi_init); -module_exit(thermal_ipi_exit); -#endif diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ti_6315.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_ti_6315.c deleted file mode 100644 index 457bcd7bb272..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ti_6315.c +++ /dev/null @@ -1,328 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - -/* #define INTR_UT */ -/* #define OT_THROTTLE_CPU */ -/* #define OT_THROTTLE_GPU */ - -#define DEFAULT_6315OT_CPU_LIMIT (800) -#define DEFAULT_6315OT_GPU_LIMIT (1000) - -static struct apthermolmt_user ap_6315ot; -static char *ap_6315ot_log = "ap_6315ot"; -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static unsigned int cpu_limit = DEFAULT_6315OT_CPU_LIMIT; -static unsigned int gpu_limit = DEFAULT_6315OT_GPU_LIMIT; - -static int virq_tempL_6; -static int virq_tempH_6; -static int virq_tempL_7; -static int virq_tempH_7; -#ifdef INTR_UT -static int virq_rcs0_6; -static int virq_rcs0_7; -#endif - -static int tpmic6315_intr_probe(struct platform_device *dev); - -static const struct of_device_id tpmic_intr_of_match[] = { - { .compatible = "mediatek,mt6315_therm_intr", }, - { /* sentinel */ } -}; - -MODULE_DEVICE_TABLE(of, tpmic_intr_of_match); - -static struct platform_driver tpmic_intr_pdrv = { - .probe = tpmic6315_intr_probe, - .remove = NULL, - .driver = { - .name = "tpmic6315_intr", - .owner = THIS_MODULE, - .of_match_table = tpmic_intr_of_match, - }, -}; - -static irqreturn_t mt6315_6_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_6); - enable_irq(virq_tempH_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s release cpu limit\n", __func__); - apthermolmt_set_cpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_6_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_6); - enable_irq(virq_tempL_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_6_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static irqreturn_t mt6315_7_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_7); - enable_irq(virq_tempH_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s release gpu limit\n", __func__); - apthermolmt_set_gpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_7_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_7); - enable_irq(virq_tempL_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_7_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static int tpmic6315_intr_probe(struct platform_device *pdev) -{ - struct device_node *node; - int ret = 0; - - node = of_find_matching_node(NULL, tpmic_intr_of_match); - if (!node) - pr_info("@%s: find tpmic_intr node failed\n", __func__); - - virq_tempL_6 = platform_get_irq(pdev, 0); - virq_tempH_6 = platform_get_irq(pdev, 1); - virq_tempL_7 = platform_get_irq(pdev, 3); - virq_tempH_7 = platform_get_irq(pdev, 4); -#ifdef INTR_UT - virq_rcs0_6 = platform_get_irq(pdev, 2); - virq_rcs0_7 = platform_get_irq(pdev, 5); -#endif - -#ifdef INTR_UT - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || virq_rcs0_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0 || virq_rcs0_7 <= 0) { -#else - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0) { -#endif - pr_info("%s: get irq error\n", __func__); - return 0; - } - - pr_info("%s: 6_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 0) - , platform_get_irq_byname(pdev, "6315_6_temp_l")); - pr_info("%s: 6_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 1) - , platform_get_irq_byname(pdev, "6315_6_temp_h")); - pr_info("%s: 7_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 3) - , platform_get_irq_byname(pdev, "6315_7_temp_l")); - pr_info("%s: 7_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 4) - , platform_get_irq_byname(pdev, "6315_7_temp_h")); - -#ifdef INTR_UT - pr_info("%s: 6_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 2) - , platform_get_irq_byname(pdev, "6315_6_rcs0")); - pr_info("%s: 7_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 5) - , platform_get_irq_byname(pdev, "6315_7_rcs0")); -#endif - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_l"), - NULL, mt6315_6_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_h"), - NULL, mt6315_6_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_l"), - NULL, mt6315_7_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_h"), - NULL, mt6315_7_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - -#ifdef INTR_UT - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_rcs0"), - NULL, mt6315_6_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S6_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_rcs0"), - NULL, mt6315_7_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S7_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); -#endif - - disable_irq_nosync(virq_tempL_6); - disable_irq_nosync(virq_tempL_7); - - return 0; -} - -static int cl_6315ot_read(struct seq_file *m, void *v) -{ - - seq_printf(m, "[%s] C/G limit = %d/%d\n", - __func__, cpu_limit, gpu_limit); - - return 0; -} -static ssize_t cl_6315ot_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int c_limit, g_limit; - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - if (sscanf(desc, "%d %d", &c_limit, &g_limit) == 2) { - pr_info("[%s] set C/G limit = %d/%d\n", - __func__, c_limit, g_limit); - cpu_limit = (c_limit != 0) ? c_limit : 0x7FFFFFFF; - gpu_limit = (g_limit != 0) ? g_limit : 0x7FFFFFFF; - - return count; - } - - pr_info("%s bad argument\n", __func__); - return -EINVAL; -} - -static int cl_6315ot_open(struct inode *inode, struct file *file) -{ - return single_open(file, cl_6315ot_read, NULL); -} - -static const struct file_operations cl_6315ot_fops = { - .owner = THIS_MODULE, - .open = cl_6315ot_open, - .read = seq_read, - .llseek = seq_lseek, - .write = cl_6315ot_write, - .release = single_release, -}; - -static int __init mtk_ti_6315_init(void) -{ - int ret = 0; - - /* register platform driver */ - ret = platform_driver_register(&tpmic_intr_pdrv); - if (ret) { - pr_info("fail to register %s driver ~~~\n", __func__); - goto end; - } - - /* create a proc file */ - { - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *dir_entry = NULL; - - dir_entry = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!dir_entry) { - pr_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = proc_create("cl6315ot_limit", 0664, - dir_entry, - &cl_6315ot_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - } - - /* register user to thermal */ - apthermolmt_register_user(&ap_6315ot, ap_6315ot_log); - -end: - return 0; -} - -static void __exit mtk_ti_6315_exit(void) -{ - apthermolmt_unregister_user(&ap_6315ot); - platform_driver_unregister(&tpmic_intr_pdrv); - pr_info("%s\n", __func__); -} - -late_initcall(mtk_ti_6315_init); -module_exit(mtk_ti_6315_exit); diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359dcxo.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359dcxo.c deleted file mode 100644 index 6889c7414a50..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359dcxo.c +++ /dev/null @@ -1,597 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359dcxo_cur_temp; -/* - *static long int mt6359dcxo_start_temp; - *static long int mt6359dcxo_end_temp; - */ -/*=============================================================*/ - -static int mt6359dcxo_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359dcxo_get_hw_temp(); - mt6359dcxo_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359dcxo_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359dcxo_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359dcxo_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359dcxo_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359dcxo_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359dcxo_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359dcxo_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359dcxo_dev_ops = { - .bind = mt6359dcxo_bind, - .unbind = mt6359dcxo_unbind, - .get_temp = mt6359dcxo_get_temp, - .get_mode = mt6359dcxo_get_mode, - .set_mode = mt6359dcxo_set_mode, - .get_trip_type = mt6359dcxo_get_trip_type, - .get_trip_temp = mt6359dcxo_get_trip_temp, - .get_crit_temp = mt6359dcxo_get_crit_temp, -}; - -static int mt6359dcxo_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359dcxo_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359dcxo_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359dcxo OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359dcxo_cooling_sysrst_ops = { - .get_max_state = mt6359dcxo_sysrst_get_max_state, - .get_cur_state = mt6359dcxo_sysrst_get_cur_state, - .set_cur_state = mt6359dcxo_sysrst_set_cur_state, -}; - -static int mt6359dcxo_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359dcxo_register_thermal(void); -static void mt6359dcxo_unregister_thermal(void); - -static ssize_t mt6359dcxo_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359dcxo_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359dcxo_data *ptr_mt6359dcxo_data; - - ptr_mt6359dcxo_data = - kmalloc(sizeof(*ptr_mt6359dcxo_data), GFP_KERNEL); - - if (ptr_mt6359dcxo_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359dcxo_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359dcxo_data->desc) - 1); - - if (copy_from_user(ptr_mt6359dcxo_data->desc, buffer, len)) { - kfree(ptr_mt6359dcxo_data); - return 0; - } - - ptr_mt6359dcxo_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359dcxo_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359dcxo_data->trip[0], - &ptr_mt6359dcxo_data->t_type[0], - ptr_mt6359dcxo_data->bind0, - &ptr_mt6359dcxo_data->trip[1], - &ptr_mt6359dcxo_data->t_type[1], - ptr_mt6359dcxo_data->bind1, - &ptr_mt6359dcxo_data->trip[2], - &ptr_mt6359dcxo_data->t_type[2], - ptr_mt6359dcxo_data->bind2, - &ptr_mt6359dcxo_data->trip[3], - &ptr_mt6359dcxo_data->t_type[3], - ptr_mt6359dcxo_data->bind3, - &ptr_mt6359dcxo_data->trip[4], - &ptr_mt6359dcxo_data->t_type[4], - ptr_mt6359dcxo_data->bind4, - &ptr_mt6359dcxo_data->trip[5], - &ptr_mt6359dcxo_data->t_type[5], - ptr_mt6359dcxo_data->bind5, - &ptr_mt6359dcxo_data->trip[6], - &ptr_mt6359dcxo_data->t_type[6], - ptr_mt6359dcxo_data->bind6, - &ptr_mt6359dcxo_data->trip[7], - &ptr_mt6359dcxo_data->t_type[7], - ptr_mt6359dcxo_data->bind7, - &ptr_mt6359dcxo_data->trip[8], - &ptr_mt6359dcxo_data->t_type[8], - ptr_mt6359dcxo_data->bind8, - &ptr_mt6359dcxo_data->trip[9], - &ptr_mt6359dcxo_data->t_type[9], - ptr_mt6359dcxo_data->bind9, - &ptr_mt6359dcxo_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359dcxo_unregister_thermal\n", __func__); - mt6359dcxo_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359dcxo_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359dcxo_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359dcxo_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359dcxo_data->bind0[i]; - g_bind1[i] = ptr_mt6359dcxo_data->bind1[i]; - g_bind2[i] = ptr_mt6359dcxo_data->bind2[i]; - g_bind3[i] = ptr_mt6359dcxo_data->bind3[i]; - g_bind4[i] = ptr_mt6359dcxo_data->bind4[i]; - g_bind5[i] = ptr_mt6359dcxo_data->bind5[i]; - g_bind6[i] = ptr_mt6359dcxo_data->bind6[i]; - g_bind7[i] = ptr_mt6359dcxo_data->bind7[i]; - g_bind8[i] = ptr_mt6359dcxo_data->bind8[i]; - g_bind9[i] = ptr_mt6359dcxo_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359dcxo_data->trip[i]; - - interval = ptr_mt6359dcxo_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359dcxo_register_thermal\n", __func__); - - mt6359dcxo_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359dcxo_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359dcxo_write", "Bad argument"); - #endif - kfree(ptr_mt6359dcxo_data); - return -EINVAL; -} - -static void mt6359dcxo_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359dcxo_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359dcxo_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359dcxo-sysrst", NULL, - &mt6359dcxo_cooling_sysrst_ops); - return 0; -} - -static int mt6359dcxo_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359dcxo", num_trip, NULL, - &mt6359dcxo_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359dcxo_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359dcxo_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359dcxo_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359dcxo_read, NULL); -} - -static const struct file_operations mt6359dcxo_fops = { - .owner = THIS_MODULE, - .open = mt6359dcxo_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359dcxo_write, - .release = single_release, -}; - -static int __init mt6359dcxo_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359dcxo_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359dcxo_register_cooler(); - if (err) - return err; - - mt6359dcxo_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359dcxo_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359dcxo", 664, mt6359dcxo_dir, - &mt6359dcxo_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359dcxo", mt6359dcxo_start_thermal_timer, - mt6359dcxo_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359dcxo_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359dcxo_unregister_thermal(); - mt6359dcxo_unregister_cooler(); - mtkTTimer_unregister("mt6359dcxo"); -} -module_init(mt6359dcxo_init); -module_exit(mt6359dcxo_exit); diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359tsx.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359tsx.c deleted file mode 100644 index d49f021990e7..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359tsx.c +++ /dev/null @@ -1,597 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359tsx_cur_temp; -/* - *static long int mt6359tsx_start_temp; - *static long int mt6359tsx_end_temp; - */ -/*=============================================================*/ - -static int mt6359tsx_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359tsx_get_hw_temp(); - mt6359tsx_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359tsx_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359tsx_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359tsx_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359tsx_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359tsx_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359tsx_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359tsx_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359tsx_dev_ops = { - .bind = mt6359tsx_bind, - .unbind = mt6359tsx_unbind, - .get_temp = mt6359tsx_get_temp, - .get_mode = mt6359tsx_get_mode, - .set_mode = mt6359tsx_set_mode, - .get_trip_type = mt6359tsx_get_trip_type, - .get_trip_temp = mt6359tsx_get_trip_temp, - .get_crit_temp = mt6359tsx_get_crit_temp, -}; - -static int mt6359tsx_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359tsx_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359tsx_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359tsx OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359tsx_cooling_sysrst_ops = { - .get_max_state = mt6359tsx_sysrst_get_max_state, - .get_cur_state = mt6359tsx_sysrst_get_cur_state, - .set_cur_state = mt6359tsx_sysrst_set_cur_state, -}; - -static int mt6359tsx_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359tsx_register_thermal(void); -static void mt6359tsx_unregister_thermal(void); - -static ssize_t mt6359tsx_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359tsx_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359tsx_data *ptr_mt6359tsx_data; - - ptr_mt6359tsx_data = - kmalloc(sizeof(*ptr_mt6359tsx_data), GFP_KERNEL); - - if (ptr_mt6359tsx_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359tsx_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359tsx_data->desc) - 1); - - if (copy_from_user(ptr_mt6359tsx_data->desc, buffer, len)) { - kfree(ptr_mt6359tsx_data); - return 0; - } - - ptr_mt6359tsx_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359tsx_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359tsx_data->trip[0], - &ptr_mt6359tsx_data->t_type[0], - ptr_mt6359tsx_data->bind0, - &ptr_mt6359tsx_data->trip[1], - &ptr_mt6359tsx_data->t_type[1], - ptr_mt6359tsx_data->bind1, - &ptr_mt6359tsx_data->trip[2], - &ptr_mt6359tsx_data->t_type[2], - ptr_mt6359tsx_data->bind2, - &ptr_mt6359tsx_data->trip[3], - &ptr_mt6359tsx_data->t_type[3], - ptr_mt6359tsx_data->bind3, - &ptr_mt6359tsx_data->trip[4], - &ptr_mt6359tsx_data->t_type[4], - ptr_mt6359tsx_data->bind4, - &ptr_mt6359tsx_data->trip[5], - &ptr_mt6359tsx_data->t_type[5], - ptr_mt6359tsx_data->bind5, - &ptr_mt6359tsx_data->trip[6], - &ptr_mt6359tsx_data->t_type[6], - ptr_mt6359tsx_data->bind6, - &ptr_mt6359tsx_data->trip[7], - &ptr_mt6359tsx_data->t_type[7], - ptr_mt6359tsx_data->bind7, - &ptr_mt6359tsx_data->trip[8], - &ptr_mt6359tsx_data->t_type[8], - ptr_mt6359tsx_data->bind8, - &ptr_mt6359tsx_data->trip[9], - &ptr_mt6359tsx_data->t_type[9], - ptr_mt6359tsx_data->bind9, - &ptr_mt6359tsx_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359tsx_unregister_thermal\n", __func__); - mt6359tsx_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359tsx_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359tsx_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359tsx_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359tsx_data->bind0[i]; - g_bind1[i] = ptr_mt6359tsx_data->bind1[i]; - g_bind2[i] = ptr_mt6359tsx_data->bind2[i]; - g_bind3[i] = ptr_mt6359tsx_data->bind3[i]; - g_bind4[i] = ptr_mt6359tsx_data->bind4[i]; - g_bind5[i] = ptr_mt6359tsx_data->bind5[i]; - g_bind6[i] = ptr_mt6359tsx_data->bind6[i]; - g_bind7[i] = ptr_mt6359tsx_data->bind7[i]; - g_bind8[i] = ptr_mt6359tsx_data->bind8[i]; - g_bind9[i] = ptr_mt6359tsx_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359tsx_data->trip[i]; - - interval = ptr_mt6359tsx_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359tsx_register_thermal\n", __func__); - - mt6359tsx_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359tsx_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359tsx_write", "Bad argument"); - #endif - kfree(ptr_mt6359tsx_data); - return -EINVAL; -} - -static void mt6359tsx_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359tsx_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359tsx_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359tsx-sysrst", NULL, - &mt6359tsx_cooling_sysrst_ops); - return 0; -} - -static int mt6359tsx_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359tsx", num_trip, NULL, - &mt6359tsx_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359tsx_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359tsx_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359tsx_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359tsx_read, NULL); -} - -static const struct file_operations mt6359tsx_fops = { - .owner = THIS_MODULE, - .open = mt6359tsx_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359tsx_write, - .release = single_release, -}; - -static int __init mt6359tsx_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359tsx_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359tsx_register_cooler(); - if (err) - return err; - - mt6359tsx_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359tsx_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359tsx", 664, mt6359tsx_dir, - &mt6359tsx_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359tsx", mt6359tsx_start_thermal_timer, - mt6359tsx_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359tsx_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359tsx_unregister_thermal(); - mt6359tsx_unregister_cooler(); - mtkTTimer_unregister("mt6359tsx"); -} -module_init(mt6359tsx_init); -module_exit(mt6359tsx_exit); diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vcore.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vcore.c deleted file mode 100644 index 86b27551b6e2..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vcore.c +++ /dev/null @@ -1,595 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vcore_cur_temp; -/* - *static long int mt6359vcore_start_temp; - *static long int mt6359vcore_end_temp; - */ -/*=============================================================*/ - -static int mt6359vcore_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vcore_get_hw_temp(); - mt6359vcore_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vcore_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vcore_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vcore_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vcore_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vcore_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vcore_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vcore_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vcore_dev_ops = { - .bind = mt6359vcore_bind, - .unbind = mt6359vcore_unbind, - .get_temp = mt6359vcore_get_temp, - .get_mode = mt6359vcore_get_mode, - .set_mode = mt6359vcore_set_mode, - .get_trip_type = mt6359vcore_get_trip_type, - .get_trip_temp = mt6359vcore_get_trip_temp, - .get_crit_temp = mt6359vcore_get_crit_temp, -}; - -static int mt6359vcore_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vcore_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vcore_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vcore OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vcore_cooling_sysrst_ops = { - .get_max_state = mt6359vcore_sysrst_get_max_state, - .get_cur_state = mt6359vcore_sysrst_get_cur_state, - .set_cur_state = mt6359vcore_sysrst_set_cur_state, -}; - -static int mt6359vcore_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vcore_register_thermal(void); -static void mt6359vcore_unregister_thermal(void); - -static ssize_t mt6359vcore_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vcore_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vcore_data *ptr_mt6359vcore_data; - - ptr_mt6359vcore_data = - kmalloc(sizeof(*ptr_mt6359vcore_data), GFP_KERNEL); - - if (ptr_mt6359vcore_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vcore_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vcore_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vcore_data->desc, buffer, len)) { - kfree(ptr_mt6359vcore_data); - return 0; - } - - ptr_mt6359vcore_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vcore_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vcore_data->trip[0], - &ptr_mt6359vcore_data->t_type[0], - ptr_mt6359vcore_data->bind0, - &ptr_mt6359vcore_data->trip[1], - &ptr_mt6359vcore_data->t_type[1], - ptr_mt6359vcore_data->bind1, - &ptr_mt6359vcore_data->trip[2], - &ptr_mt6359vcore_data->t_type[2], - ptr_mt6359vcore_data->bind2, - &ptr_mt6359vcore_data->trip[3], - &ptr_mt6359vcore_data->t_type[3], - ptr_mt6359vcore_data->bind3, - &ptr_mt6359vcore_data->trip[4], - &ptr_mt6359vcore_data->t_type[4], - ptr_mt6359vcore_data->bind4, - &ptr_mt6359vcore_data->trip[5], - &ptr_mt6359vcore_data->t_type[5], - ptr_mt6359vcore_data->bind5, - &ptr_mt6359vcore_data->trip[6], - &ptr_mt6359vcore_data->t_type[6], - ptr_mt6359vcore_data->bind6, - &ptr_mt6359vcore_data->trip[7], - &ptr_mt6359vcore_data->t_type[7], - ptr_mt6359vcore_data->bind7, - &ptr_mt6359vcore_data->trip[8], - &ptr_mt6359vcore_data->t_type[8], - ptr_mt6359vcore_data->bind8, - &ptr_mt6359vcore_data->trip[9], - &ptr_mt6359vcore_data->t_type[9], - ptr_mt6359vcore_data->bind9, - &ptr_mt6359vcore_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vcore_unregister_thermal\n", __func__); - mt6359vcore_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vcore_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - kfree(ptr_mt6359vcore_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vcore_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vcore_data->bind0[i]; - g_bind1[i] = ptr_mt6359vcore_data->bind1[i]; - g_bind2[i] = ptr_mt6359vcore_data->bind2[i]; - g_bind3[i] = ptr_mt6359vcore_data->bind3[i]; - g_bind4[i] = ptr_mt6359vcore_data->bind4[i]; - g_bind5[i] = ptr_mt6359vcore_data->bind5[i]; - g_bind6[i] = ptr_mt6359vcore_data->bind6[i]; - g_bind7[i] = ptr_mt6359vcore_data->bind7[i]; - g_bind8[i] = ptr_mt6359vcore_data->bind8[i]; - g_bind9[i] = ptr_mt6359vcore_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vcore_data->trip[i]; - - interval = ptr_mt6359vcore_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vcore_register_thermal\n", __func__); - - mt6359vcore_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vcore_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vcore_write", "Bad argument"); - #endif - kfree(ptr_mt6359vcore_data); - return -EINVAL; -} - -static void mt6359vcore_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vcore_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vcore_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vcore-sysrst", NULL, - &mt6359vcore_cooling_sysrst_ops); - return 0; -} - -static int mt6359vcore_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vcore", num_trip, NULL, - &mt6359vcore_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vcore_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vcore_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vcore_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vcore_read, NULL); -} - -static const struct file_operations mt6359vcore_fops = { - .owner = THIS_MODULE, - .open = mt6359vcore_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vcore_write, - .release = single_release, -}; - -static int __init mt6359vcore_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vcore_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vcore_register_cooler(); - if (err) - return err; - - mt6359vcore_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vcore_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359vcore", 664, mt6359vcore_dir, - &mt6359vcore_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vcore", mt6359vcore_start_thermal_timer, - mt6359vcore_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vcore_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vcore_unregister_thermal(); - mt6359vcore_unregister_cooler(); - mtkTTimer_unregister("mt6359vcore"); -} -module_init(mt6359vcore_init); -module_exit(mt6359vcore_exit); diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vgpu.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vgpu.c deleted file mode 100644 index 06ed0cb85949..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vgpu.c +++ /dev/null @@ -1,606 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vgpu_cur_temp; -/* - *static long int mt6359vgpu_start_temp; - *static long int mt6359vgpu_end_temp; - */ -/*=============================================================*/ - -static int mt6359vgpu_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vgpu_get_hw_temp(); - mt6359vgpu_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vgpu_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vgpu_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vgpu_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vgpu_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vgpu_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vgpu_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vgpu_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vgpu_dev_ops = { - .bind = mt6359vgpu_bind, - .unbind = mt6359vgpu_unbind, - .get_temp = mt6359vgpu_get_temp, - .get_mode = mt6359vgpu_get_mode, - .set_mode = mt6359vgpu_set_mode, - .get_trip_type = mt6359vgpu_get_trip_type, - .get_trip_temp = mt6359vgpu_get_trip_temp, - .get_crit_temp = mt6359vgpu_get_crit_temp, -}; - -static int mt6359vgpu_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vgpu_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vgpu_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vgpu OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vgpu_cooling_sysrst_ops = { - .get_max_state = mt6359vgpu_sysrst_get_max_state, - .get_cur_state = mt6359vgpu_sysrst_get_cur_state, - .set_cur_state = mt6359vgpu_sysrst_set_cur_state, -}; - -static int mt6359vgpu_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vgpu_register_thermal(void); -static void mt6359vgpu_unregister_thermal(void); - -static ssize_t mt6359vgpu_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vgpu_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vgpu_data *ptr_mt6359vgpu_data; - - ptr_mt6359vgpu_data = - kmalloc(sizeof(*ptr_mt6359vgpu_data), GFP_KERNEL); - - if (ptr_mt6359vgpu_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vgpu_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vgpu_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vgpu_data->desc, buffer, len)) { - kfree(ptr_mt6359vgpu_data); - return 0; - } - - ptr_mt6359vgpu_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vgpu_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vgpu_data->trip[0], - &ptr_mt6359vgpu_data->t_type[0], - ptr_mt6359vgpu_data->bind0, - &ptr_mt6359vgpu_data->trip[1], - &ptr_mt6359vgpu_data->t_type[1], - ptr_mt6359vgpu_data->bind1, - &ptr_mt6359vgpu_data->trip[2], - &ptr_mt6359vgpu_data->t_type[2], - ptr_mt6359vgpu_data->bind2, - &ptr_mt6359vgpu_data->trip[3], - &ptr_mt6359vgpu_data->t_type[3], - ptr_mt6359vgpu_data->bind3, - &ptr_mt6359vgpu_data->trip[4], - &ptr_mt6359vgpu_data->t_type[4], - ptr_mt6359vgpu_data->bind4, - &ptr_mt6359vgpu_data->trip[5], - &ptr_mt6359vgpu_data->t_type[5], - ptr_mt6359vgpu_data->bind5, - &ptr_mt6359vgpu_data->trip[6], - &ptr_mt6359vgpu_data->t_type[6], - ptr_mt6359vgpu_data->bind6, - &ptr_mt6359vgpu_data->trip[7], - &ptr_mt6359vgpu_data->t_type[7], - ptr_mt6359vgpu_data->bind7, - &ptr_mt6359vgpu_data->trip[8], - &ptr_mt6359vgpu_data->t_type[8], - ptr_mt6359vgpu_data->bind8, - &ptr_mt6359vgpu_data->trip[9], - &ptr_mt6359vgpu_data->t_type[9], - ptr_mt6359vgpu_data->bind9, - &ptr_mt6359vgpu_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vgpu_unregister_thermal\n", __func__); - - mt6359vgpu_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vgpu_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vgpu_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vgpu_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vgpu_data->bind0[i]; - g_bind1[i] = ptr_mt6359vgpu_data->bind1[i]; - g_bind2[i] = ptr_mt6359vgpu_data->bind2[i]; - g_bind3[i] = ptr_mt6359vgpu_data->bind3[i]; - g_bind4[i] = ptr_mt6359vgpu_data->bind4[i]; - g_bind5[i] = ptr_mt6359vgpu_data->bind5[i]; - g_bind6[i] = ptr_mt6359vgpu_data->bind6[i]; - g_bind7[i] = ptr_mt6359vgpu_data->bind7[i]; - g_bind8[i] = ptr_mt6359vgpu_data->bind8[i]; - g_bind9[i] = ptr_mt6359vgpu_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vgpu_data->trip[i]; - - interval = ptr_mt6359vgpu_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vgpu_register_thermal\n", __func__); - - mt6359vgpu_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vgpu_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vgpu_write", "Bad argument"); - #endif - kfree(ptr_mt6359vgpu_data); - return -EINVAL; -} - -static void mt6359vgpu_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vgpu_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vgpu_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vgpu-sysrst", NULL, - &mt6359vgpu_cooling_sysrst_ops); - return 0; -} - -static int mt6359vgpu_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vgpu", num_trip, NULL, - &mt6359vgpu_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vgpu_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vgpu_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vgpu_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vgpu_read, NULL); -} - -static const struct file_operations mt6359vgpu_fops = { - .owner = THIS_MODULE, - .open = mt6359vgpu_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vgpu_write, - .release = single_release, -}; - -static int __init mt6359vgpu_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vgpu_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vgpu_register_cooler(); - if (err) - return err; - - mt6359vgpu_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vgpu_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - - } else { - entry = - proc_create("tz6359vgpu", 664, mt6359vgpu_dir, - &mt6359vgpu_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vgpu", mt6359vgpu_start_thermal_timer, - mt6359vgpu_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vgpu_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vgpu_unregister_thermal(); - mt6359vgpu_unregister_cooler(); - mtkTTimer_unregister("mt6359vgpu"); -} -module_init(mt6359vgpu_init); -module_exit(mt6359vgpu_exit); diff --git a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vproc.c b/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vproc.c deleted file mode 100644 index e9be6cf823a3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6877/src/mtk_ts_6359vproc.c +++ /dev/null @@ -1,603 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vproc_cur_temp; -/* - *static long int mt6359vproc_start_temp; - *static long int mt6359vproc_end_temp; - */ -/*=============================================================*/ - -static int mt6359vproc_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vproc_get_hw_temp(); - mt6359vproc_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vproc_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vproc_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vproc_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vproc_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vproc_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vproc_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vproc_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vproc_dev_ops = { - .bind = mt6359vproc_bind, - .unbind = mt6359vproc_unbind, - .get_temp = mt6359vproc_get_temp, - .get_mode = mt6359vproc_get_mode, - .set_mode = mt6359vproc_set_mode, - .get_trip_type = mt6359vproc_get_trip_type, - .get_trip_temp = mt6359vproc_get_trip_temp, - .get_crit_temp = mt6359vproc_get_crit_temp, -}; - -static int mt6359vproc_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vproc_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vproc_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vproc OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vproc_cooling_sysrst_ops = { - .get_max_state = mt6359vproc_sysrst_get_max_state, - .get_cur_state = mt6359vproc_sysrst_get_cur_state, - .set_cur_state = mt6359vproc_sysrst_set_cur_state, -}; - -static int mt6359vproc_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vproc_register_thermal(void); -static void mt6359vproc_unregister_thermal(void); - -static ssize_t mt6359vproc_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vproc_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vproc_data *ptr_mt6359vproc_data; - - ptr_mt6359vproc_data = - kmalloc(sizeof(*ptr_mt6359vproc_data), GFP_KERNEL); - - if (ptr_mt6359vproc_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vproc_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vproc_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vproc_data->desc, buffer, len)) { - kfree(ptr_mt6359vproc_data); - return 0; - } - - ptr_mt6359vproc_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vproc_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vproc_data->trip[0], - &ptr_mt6359vproc_data->t_type[0], - ptr_mt6359vproc_data->bind0, - &ptr_mt6359vproc_data->trip[1], - &ptr_mt6359vproc_data->t_type[1], - ptr_mt6359vproc_data->bind1, - &ptr_mt6359vproc_data->trip[2], - &ptr_mt6359vproc_data->t_type[2], - ptr_mt6359vproc_data->bind2, - &ptr_mt6359vproc_data->trip[3], - &ptr_mt6359vproc_data->t_type[3], - ptr_mt6359vproc_data->bind3, - &ptr_mt6359vproc_data->trip[4], - &ptr_mt6359vproc_data->t_type[4], - ptr_mt6359vproc_data->bind4, - &ptr_mt6359vproc_data->trip[5], - &ptr_mt6359vproc_data->t_type[5], - ptr_mt6359vproc_data->bind5, - &ptr_mt6359vproc_data->trip[6], - &ptr_mt6359vproc_data->t_type[6], - ptr_mt6359vproc_data->bind6, - &ptr_mt6359vproc_data->trip[7], - &ptr_mt6359vproc_data->t_type[7], - ptr_mt6359vproc_data->bind7, - &ptr_mt6359vproc_data->trip[8], - &ptr_mt6359vproc_data->t_type[8], - ptr_mt6359vproc_data->bind8, - &ptr_mt6359vproc_data->trip[9], - &ptr_mt6359vproc_data->t_type[9], - ptr_mt6359vproc_data->bind9, - &ptr_mt6359vproc_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk("[%s] mt6359vproc_unregister_thermal\n", - __func__); - - mt6359vproc_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vproc_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vproc_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vproc_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vproc_data->bind0[i]; - g_bind1[i] = ptr_mt6359vproc_data->bind1[i]; - g_bind2[i] = ptr_mt6359vproc_data->bind2[i]; - g_bind3[i] = ptr_mt6359vproc_data->bind3[i]; - g_bind4[i] = ptr_mt6359vproc_data->bind4[i]; - g_bind5[i] = ptr_mt6359vproc_data->bind5[i]; - g_bind6[i] = ptr_mt6359vproc_data->bind6[i]; - g_bind7[i] = ptr_mt6359vproc_data->bind7[i]; - g_bind8[i] = ptr_mt6359vproc_data->bind8[i]; - g_bind9[i] = ptr_mt6359vproc_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vproc_data->trip[i]; - - interval = ptr_mt6359vproc_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk("[%s] mt6359vproc_register_thermal\n", - __func__); - - mt6359vproc_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vproc_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vproc_write", "Bad argument"); - #endif - kfree(ptr_mt6359vproc_data); - return -EINVAL; -} - -static void mt6359vproc_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vproc_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vproc_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vproc-sysrst", NULL, - &mt6359vproc_cooling_sysrst_ops); - return 0; -} - -static int mt6359vproc_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vproc", num_trip, NULL, - &mt6359vproc_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vproc_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vproc_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vproc_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vproc_read, NULL); -} - -static const struct file_operations mt6359vproc_fops = { - .owner = THIS_MODULE, - .open = mt6359vproc_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vproc_write, - .release = single_release, -}; - -static int __init mt6359vproc_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vproc_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vproc_register_cooler(); - if (err) - return err; - - mt6359vproc_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vproc_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6359vproc", 664, mt6359vproc_dir, - &mt6359vproc_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vproc", mt6359vproc_start_thermal_timer, - mt6359vproc_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vproc_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vproc_unregister_thermal(); - mt6359vproc_unregister_cooler(); - mtkTTimer_unregister("mt6359vproc"); -} -module_init(mt6359vproc_init); -module_exit(mt6359vproc_exit); diff --git a/drivers/misc/mediatek/thermal/mt6885/Makefile b/drivers/misc/mediatek/thermal/mt6885/Makefile deleted file mode 100644 index 2a09370d533f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6885/inc/clatm_initcfg.h deleted file mode 100644 index f3bbdce4fcef..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/clatm_initcfg.h +++ /dev/null @@ -1,57 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (75000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (3960) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_1_TARGET_TJ (65000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (300) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (3000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (75000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3960) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (600) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (3960) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (800) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (2000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (10) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (50) - -#define CLATM_USE_MIN_CPU_OPP (1) -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/mach/mtk_thermal.h b/drivers/misc/mediatek/thermal/mt6885/inc/mach/mtk_thermal.h deleted file mode 100644 index 8541df8980b2..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/mach/mtk_thermal.h +++ /dev/null @@ -1,249 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __MT6885_THERMAL_H__ -#define __MT6885_THERMAL_H__ - -#include -#include -#include -#include - -#include -#include - -#include "mt-plat/sync_write.h" - -#include "mtk_thermal_typedefs.h" - -/* TODO: remove this! */ -/*#define GPUFREQ_NOT_READY*/ - -#ifdef GPUFREQ_NOT_READY -struct mt_gpufreq_power_table_info { - unsigned int gpufreq_khz; - unsigned int gpufreq_volt; - unsigned int gpufreq_power; -}; -#else -#include "mtk_gpufreq.h" -#endif - -/*============================================================= - * LVTS SW Configs - *============================================================= - */ -#define CFG_THERM_LVTS (1) -#define CFG_THERM_NO_AUXADC (1) - - -#if CFG_THERM_LVTS -#define CFG_LVTS_DOMINATOR (1) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (1) /* 1, 2, 4, 8, 16 */ -#define LVTS_DEVICE_AUTO_RCK (0) -/*Use bootup "count RC", no need to get "count RC" again after resume*/ -#define CFG_THERM_USE_BOOTUP_COUNT_RC -#else -#define CFG_LVTS_DOMINATOR (0) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (0) -#define LVTS_DEVICE_AUTO_RCK (1) -#endif - -/* - *There is no idle code in kernel since mt6885(big sw). - *Thus, kernel only can use "cpu pm notifier" to do idle scenario things. - * - *Release LVTS in thermal kernel driver - *1. SPM will pause LVTS thermal controllers before closing 26M - *2. After leaving SODI3, SPM will release LVTS thermal controllers - * if controllers were paused properly. - *3. After leaving SODI3, Thermal driver will release LVTS thermal - * controllers if SPM didn't release controller successfully - */ -#define LVTS_CPU_PM_NTFY_CALLBACK - -#if defined(LVTS_CPU_PM_NTFY_CALLBACK) -#define CFG_THERM_SODI3_RELEASE -//#define LVTS_CPU_PM_NTFY_PROFILE -#endif - -/* public thermal sensor enum */ - -enum thermal_sensor { -#if CFG_THERM_LVTS - TS_LVTS1_0 = 0, - TS_LVTS1_1, - TS_LVTS2_0, - TS_LVTS2_1, - TS_LVTS3_0, - TS_LVTS3_1, - TS_LVTS3_2, - TS_LVTS3_3, - TS_LVTS4_0, - TS_LVTS4_1, - TS_LVTS5_0, - TS_LVTS5_1, - TS_LVTS6_0, - TS_LVTS6_1, - TS_LVTS7_0, - TS_LVTS7_1, - TS_LVTS7_2, -#endif - TS_ENUM_MAX -}; - -enum thermal_bank_name { - THERMAL_BANK0 = 0, - THERMAL_BANK1, - THERMAL_BANK2, - THERMAL_BANK3, - THERMAL_BANK4, - THERMAL_BANK5, - THERMAL_BANK_NUM -}; - -struct TS_PTPOD { - unsigned int ts_MTS; - unsigned int ts_BTS; -}; - -extern int mtktscpu_limited_dmips; -extern int tscpu_get_temperature_range(void); -/* Valid if it returns 1, invalid if it returns 0. */ -extern int tscpu_is_temp_valid(void); - -extern void get_thermal_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); - -#if CFG_THERM_LVTS -extern void get_lvts_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); -#endif - -extern void set_taklking_flag(bool flag); - -extern int tscpu_get_cpu_temp(void); - -extern int tscpu_get_temp_by_bank(enum thermal_bank_name ts_bank); - -#define THERMAL_WRAP_WR32(val, addr) \ - mt_reg_sync_writel((val), ((void *)addr)) - -extern int get_immediate_cpuL_wrap(void); -extern int get_immediate_cpuB_wrap(void); -extern int get_immediate_mcucci_wrap(void); -extern int get_immediate_gpu_wrap(void); -extern int get_immediate_vpu_wrap(void); -extern int get_immediate_top_wrap(void); -extern int get_immediate_md_wrap(void); - -/* Added for DLPT/EARA */ -extern int tscpu_get_min_cpu_pwr(void); -extern int tscpu_get_min_gpu_pwr(void); -extern int tscpu_get_min_vpu_pwr(void); -extern int tscpu_get_min_mdla_pwr(void); - -extern void lvts_ipi_send_efuse_data(void); -extern void lvts_ipi_send_sspm_thermal_thtottle(void); -extern void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend); - -/* Five thermal sensors. */ -enum mtk_thermal_sensor_cpu_id_met { - MTK_THERMAL_SENSOR_TS0 = 0, - MTK_THERMAL_SENSOR_TS1, - MTK_THERMAL_SENSOR_TS2, - /* No TSMCU3 */ - MTK_THERMAL_SENSOR_TS4, - MTK_THERMAL_SENSOR_TS5, - MTK_THERMAL_SENSOR_TS6, - MTK_THERMAL_SENSOR_TS7, - MTK_THERMAL_SENSOR_TS8, - MTK_THERMAL_SENSOR_TS9, -#if CFG_THERM_LVTS - MTK_THERMAL_SENSOR_LVTS1_0, - MTK_THERMAL_SENSOR_LVTS1_1, - MTK_THERMAL_SENSOR_LVTS2_0, - MTK_THERMAL_SENSOR_LVTS2_1, - MTK_THERMAL_SENSOR_LVTS2_2, - MTK_THERMAL_SENSOR_LVTS3_0, - MTK_THERMAL_SENSOR_LVTS3_1, - MTK_THERMAL_SENSOR_LVTS4_0, - /* No LVTS4_1 */ - MTK_THERMAL_SENSOR_LVTS9_0, -#endif - MTK_THERMAL_SENSOR_TSABB, - - ATM_CPU_LIMIT, - ATM_GPU_LIMIT, - - MTK_THERMAL_SENSOR_CPU_COUNT -}; - -extern int tscpu_get_cpu_temp_met(enum mtk_thermal_sensor_cpu_id_met id); - -typedef void (*met_thermalsampler_funcMET)(void); - -extern void mt_thermalsampler_registerCB(met_thermalsampler_funcMET pCB); - -extern void mtkTTimer_cancel_timer(void); - -extern void mtkTTimer_start_timer(void); - -extern int mtkts_bts_get_hw_temp(void); - -extern int get_immediate_ts0_wrap(void); -extern int get_immediate_ts1_wrap(void); -extern int get_immediate_ts2_wrap(void); -extern int get_immediate_ts3_wrap(void); -extern int get_immediate_ts4_wrap(void); -extern int get_immediate_ts5_wrap(void); -extern int get_immediate_ts6_wrap(void); -extern int get_immediate_ts7_wrap(void); -extern int get_immediate_ts8_wrap(void); -extern int get_immediate_ts9_wrap(void); - -#if CFG_THERM_LVTS -extern int get_immediate_tslvts1_0_wrap(void); -extern int get_immediate_tslvts1_1_wrap(void); -extern int get_immediate_tslvts2_0_wrap(void); -extern int get_immediate_tslvts2_1_wrap(void); -extern int get_immediate_tslvts2_2_wrap(void); -extern int get_immediate_tslvts3_0_wrap(void); -extern int get_immediate_tslvts3_1_wrap(void); -extern int get_immediate_tslvts4_0_wrap(void); -/* No LVTS4_1 */ -extern int get_immediate_tslvts9_0_wrap(void); -#endif - -extern int get_immediate_tsabb_wrap(void); - -extern int (*get_immediate_tsX[TS_ENUM_MAX])(void); - -extern int is_cpu_power_unlimit(void); /* in mtk_ts_cpu.c */ - -extern int is_cpu_power_min(void); /* in mtk_ts_cpu.c */ - -extern int get_cpu_target_tj(void); - -extern int get_cpu_target_offset(void); - -extern int mtk_gpufreq_register( - struct mt_gpufreq_power_table_info *freqs, int num); - - -extern int get_target_tj(void); - -extern int mtk_thermal_get_tpcb_target(void); - -extern void thermal_set_big_core_speed( -unsigned int tempMonCtl1, unsigned int tempMonCtl2, unsigned int tempAhbPoll); - -/* - * return value(1): cooler of abcct/abcct_lcmoff is deactive, - * and no thermal current limit. - */ -extern int mtk_cooler_is_abcct_unlimit(void); - -extern int tscpu_kernel_status(void); -#endif /* __MT6785_THERMAL_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_cl_amddulthro.h b/drivers/misc/mediatek/thermal/mt6885/inc/mtk_cl_amddulthro.h deleted file mode 100644 index 3758a5645b66..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_cl_amddulthro.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __MT_CL_AMDDULTHRO_H__ -#define __MT_CL_AMDDULTHRO_H__ - -extern int amddulthro_backoff(int level); - -#endif /* __MT_CL_AMDDULTHRO_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6885/inc/mtk_cooler_setting.h deleted file mode 100644 index 8686e7739980..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - - -/*APU(mdla/vpu) throttle*/ -#define THERMAL_APU_UNLIMIT - -#if defined(THERMAL_APU_UNLIMIT) -extern unsigned int cl_get_apu_status(void); -extern void cl_set_apu_status(int vv); -#endif -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6885/inc/mtk_thermal_ipi.h deleted file mode 100644 index a611ca1d4264..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (1) -#define THERMAL_SSPM_THERMAL_THROTTLE_SWITCH - -/*Only Big SW need to enable this definition - *Big SW suspend/resume flow: - * suspend: kernel suspend => SSPM suspend - * resume: SSPM resume => kernel resume - */ -#define THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (0) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#include - -#define THERMAL_SLOT_NUM (4) -#define BIG_CORE_THRESHOLD_ARRAY_SIZE (3) -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_LVTS_INIT_GRP1, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_sspm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6885/inc/mtk_ts_setting.h deleted file mode 100644 index fd26f045d1d3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/mtk_ts_setting.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (1) -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tmp_6311buck.h b/drivers/misc/mediatek/thermal/mt6885/inc/tmp_6311buck.h deleted file mode 100644 index b270b82c166f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tmp_6311buck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TMP_6311BUCK_H__ -#define __TMP_6311BUCK_H__ - -extern int is_ext_buck_exist(void); - -#endif /* __TMP_6311BUCK_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tmp_battery.h b/drivers/misc/mediatek/thermal/mt6885/inc/tmp_battery.h deleted file mode 100644 index 36052ddf87fc..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tmp_battery.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TMP_BATTERY_H__ -#define __TMP_BATTERY_H__ - -#include -/* Extern two API functions from battery driver - * to limit max charging current. - */ -/** - * return value means charging current in mA - * -1 means error - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int get_bat_charging_current_level(void); - -/** - * current_limit means limit of charging current in mA - * -1 means no limit - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int set_bat_charging_current_limit(int current_limit); -extern enum charger_type mt_get_charger_type(void); - -extern int read_tbat_value(void); - -#endif /* __TMP_BATTERY_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6885/inc/tmp_bts.h deleted file mode 100644 index 6222eaae942e..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tmp_bts.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) -#define AUX_IN2_NTC (2) - -#define BTS_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 390000 /* 390K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - - -#define BTSNRPA_RAP_PULL_UP_R 390000 /* 390K,pull up resister */ -#define BTSNRPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - *default value -40 deg - */ - -#define BTSNRPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ -#define BTSNRPA_RAP_NTC_TABLE 7 - -#define BTSNRPA_RAP_ADC_CHANNEL AUX_IN2_NTC - - - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_lvts_config.h b/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_lvts_config.h deleted file mode 100644 index 0cdcf80f003a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_lvts_config.h +++ /dev/null @@ -1,94 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_LVTS_SETTINGS_H__ -#define __TSCPU_LVTS_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define LVTS_ADDRESS_INDEX_1 116 /* 0x11C101C0 */ -#define LVTS_ADDRESS_INDEX_2 117 /* 0x11C101C4 */ -#define LVTS_ADDRESS_INDEX_3 118 /* 0x11C101C8 */ -#define LVTS_ADDRESS_INDEX_4 119 /* 0x11C101CC */ -#define LVTS_ADDRESS_INDEX_5 190 /* 0x11C101D0 */ -#define LVTS_ADDRESS_INDEX_6 191 /* 0x11C101D4 */ -#define LVTS_ADDRESS_INDEX_7 192 /* 0x11C101D8 */ -#define LVTS_ADDRESS_INDEX_8 193 /* 0x11C101DC */ -#define LVTS_ADDRESS_INDEX_9 194 /* 0x11C101E0 */ -#define LVTS_ADDRESS_INDEX_10 195 /* 0x11C101E4 */ -#define LVTS_ADDRESS_INDEX_11 196 /* 0x11C101E8 */ -#define LVTS_ADDRESS_INDEX_12 197 /* 0x11C101EC */ -#define LVTS_ADDRESS_INDEX_13 198 /* 0x11C101F0 */ -#define LVTS_ADDRESS_INDEX_14 199 /* 0x11C101F4 */ -#define LVTS_ADDRESS_INDEX_15 200 /* 0x11C101F8 */ -#define LVTS_ADDRESS_INDEX_16 201 /* 0x11C101FC */ -#define LVTS_ADDRESS_INDEX_17 202 /* 0x11C10200 */ -#define LVTS_ADDRESS_INDEX_18 203 /* 0x11C10204 */ -#define LVTS_ADDRESS_INDEX_19 204 /* 0x11C10208 */ -#define LVTS_ADDRESS_INDEX_20 205 /* 0x11C1020C */ -#define LVTS_ADDRESS_INDEX_21 206 /* 0x11C10210 */ -#define LVTS_ADDRESS_INDEX_22 207 /* 0x11C10214 */ - - - - -/**************************************************************************** */ -/* LVTS related registers. */ -/**************************************************************************** */ -#define LVTSMONCTL0_0 (THERM_CTRL_BASE_2 + 0x000) -#define LVTSMONCTL1_0 (THERM_CTRL_BASE_2 + 0x004) -#define LVTSMONCTL2_0 (THERM_CTRL_BASE_2 + 0x008) -#define LVTSMONINT_0 (THERM_CTRL_BASE_2 + 0x00C) -#define LVTSMONINTSTS_0 (THERM_CTRL_BASE_2 + 0x010) -#define LVTSMONIDET0_0 (THERM_CTRL_BASE_2 + 0x014) -#define LVTSMONIDET1_0 (THERM_CTRL_BASE_2 + 0x018) -#define LVTSMONIDET2_0 (THERM_CTRL_BASE_2 + 0x01C) -#define LVTSMONIDET3_0 (THERM_CTRL_BASE_2 + 0x020) -#define LVTSH2NTHRE_0 (THERM_CTRL_BASE_2 + 0x024) -#define LVTSHTHRE_0 (THERM_CTRL_BASE_2 + 0x028) -#define LVTSCTHRE_0 (THERM_CTRL_BASE_2 + 0x02C) -#define LVTSOFFSETH_0 (THERM_CTRL_BASE_2 + 0x030) -#define LVTSOFFSETL_0 (THERM_CTRL_BASE_2 + 0x034) -#define LVTSMSRCTL0_0 (THERM_CTRL_BASE_2 + 0x038) -#define LVTSMSRCTL1_0 (THERM_CTRL_BASE_2 + 0x03C) -#define LVTSTSSEL_0 (THERM_CTRL_BASE_2 + 0x040) -#define LVTSDEVICETO_0 (THERM_CTRL_BASE_2 + 0x044) -#define LVTSCALSCALE_0 (THERM_CTRL_BASE_2 + 0x048) -#define LVTS_ID_0 (THERM_CTRL_BASE_2 + 0x04C) -#define LVTS_CONFIG_0 (THERM_CTRL_BASE_2 + 0x050) -#define LVTSEDATA00_0 (THERM_CTRL_BASE_2 + 0x054) -#define LVTSEDATA01_0 (THERM_CTRL_BASE_2 + 0x058) -#define LVTSEDATA02_0 (THERM_CTRL_BASE_2 + 0x05C) -#define LVTSEDATA03_0 (THERM_CTRL_BASE_2 + 0x060) -#define LVTSMSR0_0 (THERM_CTRL_BASE_2 + 0x090) -#define LVTSMSR1_0 (THERM_CTRL_BASE_2 + 0x094) -#define LVTSMSR2_0 (THERM_CTRL_BASE_2 + 0x098) -#define LVTSMSR3_0 (THERM_CTRL_BASE_2 + 0x09C) -#define LVTSIMMD0_0 (THERM_CTRL_BASE_2 + 0x0A0) -#define LVTSIMMD1_0 (THERM_CTRL_BASE_2 + 0x0A4) -#define LVTSIMMD2_0 (THERM_CTRL_BASE_2 + 0x0A8) -#define LVTSIMMD3_0 (THERM_CTRL_BASE_2 + 0x0AC) -#define LVTSRDATA0_0 (THERM_CTRL_BASE_2 + 0x0B0) -#define LVTSRDATA1_0 (THERM_CTRL_BASE_2 + 0x0B4) -#define LVTSRDATA2_0 (THERM_CTRL_BASE_2 + 0x0B8) -#define LVTSRDATA3_0 (THERM_CTRL_BASE_2 + 0x0BC) -#define LVTSPROTCTL_0 (THERM_CTRL_BASE_2 + 0x0C0) -#define LVTSPROTTA_0 (THERM_CTRL_BASE_2 + 0x0C4) -#define LVTSPROTTB_0 (THERM_CTRL_BASE_2 + 0x0C8) -#define LVTSPROTTC_0 (THERM_CTRL_BASE_2 + 0x0CC) -#define LVTSCLKEN_0 (THERM_CTRL_BASE_2 + 0x0E4) -#define LVTSDBGSEL_0 (THERM_CTRL_BASE_2 + 0x0E8) -#define LVTSDBGSIG_0 (THERM_CTRL_BASE_2 + 0x0EC) -#define LVTSSPARE0_0 (THERM_CTRL_BASE_2 + 0x0F0) -#define LVTSSPARE1_0 (THERM_CTRL_BASE_2 + 0x0F4) -#define LVTSSPARE2_0 (THERM_CTRL_BASE_2 + 0x0F8) -#define LVTSSPARE3_0 (THERM_CTRL_BASE_2 + 0x0FC) - -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) - -#endif /* __TSCPU_LVTS_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_settings.h deleted file mode 100644 index e242940908d6..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_settings.h +++ /dev/null @@ -1,795 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include "mach/mtk_thermal.h" - -#include -#include - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" -#include "tscpu_tsense_config.h" -#include "tscpu_lvts_config.h" - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned int)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned int) -1 >> (31 - ((1) ? _bits_))) \ - & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() \ - long long thermal_pTime_us, thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_notice(TSCPU_LOG_TAG "%s: %llu us\n", __func__, \ - thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_notice(TSCPU_LOG_TAG \ - "Warning: tProfiling uses incorrect %s %d\n", \ - __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/*Enable thermal controller CG*/ -#define THERMAL_EBABLE_TC_CG - -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. - * Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -/* Define this in tscpu_settings.h enables this feature. - * It polls CPU TS in hrtimer and - * run ATM in RT 98 kthread. This is for MT6799 only. - */ -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) -#define CLEAR_TEMP 26111 - -/* Thermal VPU throttling support */ -#ifdef CONFIG_MTK_APUSYS_VPU -#define THERMAL_VPU_SUPPORT -#endif - -/* Thermal MDLA throttling support */ -#ifdef CONFIG_MTK_APUSYS_MDLA_SUPPORT -#define THERMAL_MDLA_SUPPORT -#endif - -/* EARA_Thermal power budget allocation support */ -#define EARA_THERMAL_SUPPORT - -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_RAM_CONSOLE -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#if CFG_THERM_LVTS -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -#define CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT (1) -#define DYNAMIC_REBOOT_TRIP_TEMP (35000) -#define DYNAMIC_REBOOT_EXIT_TEMP (30000) -#else -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -#endif - -#define DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE (1) -/* - * if RCK get zero data, - * need to get the same controller's other sensor's average RCK value - * instead of zero data. - */ -#define LVTS_GET_ZERO_RCK_DATA_ISSUE (0) -#define LVTS_REFINE_MANUAL_RCK_WITH_EFUSE (1) - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#define LVTS_FORCE_ERROR_TRIGGER (0) -#define LVTS_NUM_SKIP_SAMPLE (500) - -#define HISTORY_SAMPLES (10) -#define FUTURE_SAMPLES (10) -#define R_BUFFER_SIZE (HISTORY_SAMPLES + FUTURE_SAMPLES + 1) -#define LVTS_ERROR_THRESHOLD (10000) - -#define DUMP_LVTS_REGISTER (0) -#define DUMP_VCORE_VOLTAGE (0) -#endif -#define LVTS_VALID_DATA_TIME_PROFILING (0) - -#define LVTS_USE_DOMINATOR_SENSING_POINT (1) - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (0) -/*============================================================= - *REG ACCESS - *============================================================= - */ -/* double check */ -#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ - -/* turn on TS_CON1[5:4] 2'b 00 11001111 -> 0xCF ~(0x30)*/ -#define TS_TURN_ON 0xFFFFFFCF -#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | (val), \ - ((void *)addr)) - -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & ~(val), \ - ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES (8) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x84) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x90) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif - -/*============================================================= - * Common Structure and Enum - *============================================================= - */ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * LVTS Structure and Enum - *============================================================= - */ -#if CFG_THERM_LVTS - -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1,T2) LVTS1-0, LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -/* private thermal sensor enum */ -enum lvts_sensor_enum { - L_TS_LVTS1_0 = 0, /* LVTS1-0 1*/ - L_TS_LVTS1_1, /* LVTS1-1 2*/ - L_TS_LVTS2_0, /* LVTS2-0 3*/ - L_TS_LVTS2_1, /* LVTS2-1 4*/ - L_TS_LVTS3_0, /* LVTS3-0 5*/ - L_TS_LVTS3_1, /* LVTS3-1 6*/ - L_TS_LVTS3_2, /* LVTS3-2 7*/ - L_TS_LVTS3_3, /* LVTS3-3 8*/ - L_TS_LVTS4_0, /* LVTS4-0 9*/ - L_TS_LVTS4_1, /* LVTS4-1 10*/ - L_TS_LVTS5_0, /* LVTS5-0 11*/ - L_TS_LVTS5_1, /* LVTS5-1 12*/ - L_TS_LVTS6_0, /* LVTS6-0 13*/ - L_TS_LVTS6_1, /* LVTS6-1 14*/ - L_TS_LVTS7_0, /* LVTS7-0 15*/ - L_TS_LVTS7_1, /* LVTS7-1 16*/ - L_TS_LVTS7_2, /* LVTS7-2 17*/ - L_TS_LVTS_NUM -}; - -enum lvts_tc_enum { - LVTS_MCU_CONTROLLER0 = 0,/* LVTSMONCTL0 */ - LVTS_MCU_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_MCU_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_AP_CONTROLLER0, /* LVTSMONCTL0 */ - LVTS_AP_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_AP_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_AP_CONTROLLER3, /* LVTSMONCTL0_3 */ - LVTS_CONTROLLER_NUM -}; - -struct lvts_thermal_controller_speed { - unsigned int group_interval_delay; - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; -}; - -struct lvts_thermal_controller { - enum lvts_sensor_enum ts[4]; /* sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; /* hw protection ref TS (index of the ts array) */ - int tc_offset; - struct lvts_thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Tsense Structure and Enum - *============================================================= - */ -#if !defined(CFG_THERM_NO_AUXADC) -/* private thermal sensor enum */ -enum tsmcu_sensor_enum { - L_TS_MCU0 = 0, - L_TS_MCU1, - L_TS_MCU2, - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - L_TS_MCU4, - L_TS_MCU5, - L_TS_MCU6, - L_TS_MCU7, - L_TS_MCU8, - L_TS_MCU9, - L_TS_ABB, - L_TS_MCU_NUM -}; - -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, /* TEMPMONCTL0 */ - THERMAL_CONTROLLER1, /* TEMPMONCTL0_1 */ - THERMAL_CONTROLLER2, /* TEMPMONCTL0_2 */ - THERMAL_CONTROLLER_NUM -}; -#endif -struct thermal_controller_speed { - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; - unsigned int ahb_polling_interval; -}; -#if CFG_THERM_LVTS -struct thermal_controller { - enum lvts_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#else -struct thermal_controller { - enum tsmcu_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Shared variables - *============================================================= - */ -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern u32 thermal_mcu_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_curr_cpu_temp; -extern int tscpu_curr_gpu_temp; -#endif - -/* - * In src/mtk_tc.c - */ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_sspm_thermal_throttle; -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -#if !defined(CFG_THERM_NO_AUXADC) -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -#endif -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -extern int lvts_hw_protect_enabled; - -#if !defined(CFG_THERM_NO_AUXADC) -/* - * temperature array to store both tsmcu and lvts (if exist) and export them - */ -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ - -/* - * temperature array to store temp of tsmcu sensor - */ -extern int tscpu_ts_mcu_temp[L_TS_MCU_NUM]; -extern int tscpu_ts_mcu_temp_r[L_TS_MCU_NUM]; /* raw data */ -#endif - -#if CFG_THERM_LVTS -/* - * temperature array to store temp of lvts sensor - */ -extern int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -extern int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; /* raw data */ -#endif - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -extern int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#if DUMP_VCORE_VOLTAGE -extern struct regulator *vcore_reg_id; -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern unsigned long long int SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -extern int isTempValid; -extern long long int start_timestamp; -/* count if start_timestamp is bigger than end_timestamp */ -extern int diff_error_count; -#endif -/* - * support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_rawdata_debug_log; -extern int lvts_debug_log; -extern struct lvts_thermal_controller -lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM]; -#endif - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long int thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#endif - -extern char *adaptive_cooler_name; - -/* common/coolers/mtk_cooler_atm.c */ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/* common/coolers/mtk_cooler_dtm.c */ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In mtk_tc_wrapper.c */ -extern int tscpu_get_curr_max_ts_temp(void); -extern int tscpu_max_temperature(void); -extern int tscpu_get_curr_temp(void); -extern int combine_lvts_tsmcu_temp(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int get_io_reg_base(void); - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif -extern void tscpu_update_tempinfo(void); - -#if !defined(CFG_THERM_NO_AUXADC) -/*In src/mtk_tc.c*/ -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp( - int tc_num, enum tsmcu_sensor_enum type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); - -extern int tscpu_dump_cali_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); - -extern void thermal_disable_all_periodoc_temp_sensing(void); -extern void read_all_tc_tsmcu_temperature(void); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -#endif -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern void lvts_tscpu_reset_thermal(void); -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_get_io_reg_base(void); -extern int lvts_max_temperature(void); -extern void lvts_config_all_tc_hw_protect(int temperature, int temperature2); -extern void lvts_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order); -extern void lvts_read_all_tc_temperature(void); -extern void lvts_reset_and_initial(int tc_num); -extern int (*lvts_max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void lvts_thermal_lvts_device_init(void); -extern void lvts_read_temperature(void); -//extern void lvts_read_temperature(int temp0, int temp1); -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_error_info(void); -#endif -extern void lvts_thermal_cal_prepare(void); -extern void lvts_device_identification(void); -extern void lvts_reset_device_and_stop_clk(void); -extern void lvts_read_device_id_rev(void); -extern void lvts_Device_Enable_Init_all_Devices(void); -extern void lvts_device_read_count_RC_N(void); -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -extern void lvts_device_read_count_RC_N_resume(void); -#endif -extern void lvts_device_enable_auto_rck(void); -extern void lvts_efuse_setting(void); -extern void lvts_tscpu_thermal_initial_all_tc(void); -extern void lvts_pause_all_sensing_points(void); -extern void lvts_release_all_sensing_points(void); -extern void lvts_disable_all_sensing_points(void); -extern void lvts_enable_all_sensing_points(void); -extern void read_all_tc_lvts_temperature(void); -extern void lvts_wait_for_all_sensing_point_idle(void); -extern irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -extern int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v); -extern void lvts_sodi3_release_thermal_controller(void); -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -extern void lvts_enable_all_hw_protect(void); -extern void lvts_disable_all_hw_protect(void); -#endif -#endif - -/* - * In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c - * It's not our api, ask them to provide header file - */ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* - * In drivers/misc/mediatek/auxadc/mt_auxadc.c - * It's not our api, ask them to provide header file - */ -extern int IMM_IsAdcInitReady(void); - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern void dump_efuse_data(void); -extern int check_lvts_mcu_efuse(void); -extern int check_auxadc_mcu_efuse(void); -#if DUMP_LVTS_REGISTER -extern void read_controller_reg_before_active(void); -extern void read_controller_reg_when_error(void); -extern void read_device_reg_before_active(void); -extern void read_device_reg_when_error(void); -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_register_value(void); -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern void lvts_dump_time_profiling_result(struct seq_file *m); -#endif -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ - do { \ - if (tscpu_debug_log == 1) { \ - pr_notice(TSCPU_LOG_TAG fmt, ##args); \ - } \ - } while (0) - -#define tscpu_printk(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -#define LVTS_LOG_TAG "[Thermal/TZ/LVTS]" -#define LVTS_LOG_REG_TAG "[Thermal/TZ/LVTSREG]" - -#define lvts_reg_print(fmt, args...) pr_notice(LVTS_LOG_REG_TAG fmt, ##args) -#define lvts_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#define lvts_warn(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#if 0 -#define lvts_dbg_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#else -#define lvts_dbg_printk(fmt, args...) \ - do { \ - if (lvts_debug_log == 1) { \ - pr_notice(LVTS_LOG_TAG fmt, ##args); \ - } \ - } while (0) -#endif -#endif - -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -#if 1 -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base -#else -#include -#define AUXADC_BASE_2 AUXADC_BASE -#define THERM_CTRL_BASE_2 THERM_CTRL_BASE -#define PERICFG_BASE_2 PERICFG_BASE -#define APMIXED_BASE_2 APMIXED_BASE -#endif - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) - -#define INFRA_GLOBALCON_RST_4_SET (INFRACFG_AO_BASE_2 + 0x730) -#define INFRA_GLOBALCON_RST_4_CLR (INFRACFG_AO_BASE_2 + 0x734) -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ - -#define THERMAL_COLD_INTERRUPT_0 0x00000001 -#define THERMAL_HOT_INTERRUPT_0 0x00000002 -#define THERMAL_LOW_OFFSET_INTERRUPT_0 0x00000004 -#define THERMAL_HIGH_OFFSET_INTERRUPT_0 0x00000008 -#define THERMAL_HOT2NORMAL_INTERRUPT_0 0x00000010 -#define THERMAL_COLD_INTERRUPT_1 0x00000020 -#define THERMAL_HOT_INTERRUPT_1 0x00000040 -#define THERMAL_LOW_OFFSET_INTERRUPT_1 0x00000080 -#define THERMAL_HIGH_OFFSET_INTERRUPT_1 0x00000100 -#define THERMAL_HOT2NORMAL_INTERRUPT_1 0x00000200 -#define THERMAL_COLD_INTERRUPT_2 0x00000400 -#define THERMAL_HOT_INTERRUPT_2 0x00000800 -#define THERMAL_LOW_OFFSET_INTERRUPT_2 0x00001000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_2 0x00002000 -#define THERMAL_HOT2NORMAL_INTERRUPT_2 0x00004000 -#define THERMAL_AHB_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_DEVICE_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_IMMEDIATE_INTERRUPT_0 0x00010000 -#define THERMAL_IMMEDIATE_INTERRUPT_1 0x00020000 -#define THERMAL_IMMEDIATE_INTERRUPT_2 0x00040000 -#define THERMAL_FILTER_INTERRUPT_0 0x00080000 -#define THERMAL_FILTER_INTERRUPT_1 0x00100000 -#define THERMAL_FILTER_INTERRUPT_2 0x00200000 -#define THERMAL_COLD_INTERRUPT_3 0x00400000 -#define THERMAL_HOT_INTERRUPT_3 0x00800000 -#define THERMAL_LOW_OFFSET_INTERRUPT_3 0x01000000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_3 0x02000000 -#define THERMAL_HOT2NORMAL_INTERRUPT_3 0x04000000 -#define THERMAL_IMMEDIATE_INTERRUPT_3 0x08000000 -#define THERMAL_FILTER_INTERRUPT_3 0x10000000 -#define THERMAL_PROTECTION_STAGE_1 0x20000000 -#define THERMAL_PROTECTION_STAGE_2 0x40000000 -#define THERMAL_PROTECTION_STAGE_3 0x80000000 -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_tsense_config.h b/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_tsense_config.h deleted file mode 100644 index f352361e4c35..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tscpu_tsense_config.h +++ /dev/null @@ -1,151 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TSCPU_TSENSE_SETTINGS_H__ -#define __TSCPU_TSENSE_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define ADDRESS_INDEX_0 101 /* 184 */ -#define ADDRESS_INDEX_1 100 /* 180 */ -#define ADDRESS_INDEX_2 102 /* 188 */ -#define ADDRESS_INDEX_3 111 /* 1AC */ -#define ADDRESS_INDEX_4 112 /* 1B0 */ - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - -#define TSCON1_bit_0_3_0000 0x00 /*TSCON1[3:0]=4'b0000*/ -#define TSCON1_bit_0_3_0001 0x01 /*TSCON1[3:0]=4'b0001*/ -#define TSCON1_bit_0_3_0010 0x02 /*TSCON1[3:0]=4'b0010*/ -#define TSCON1_bit_0_3_0011 0x03 /*TSCON1[3:0]=4'b0011*/ -#define TSCON1_bit_0_3_0100 0x04 /*TSCON1[3:0]=4'b0100*/ -#define TSCON1_bit_0_3_0101 0x05 /*TSCON1[3:0]=4'b0101*/ -#define TSCON1_bit_0_3_0110 0x06 /*TSCON1[3:0]=4'b0110*/ -#define TSCON1_bit_0_3_0111 0x07 /*TSCON1[3:0]=4'b0111*/ -#define TSCON1_bit_0_3_1000 0x08 /*TSCON1[3:0]=4'b1000*/ -#define TSCON1_bit_0_3_1001 0x09 /*TSCON1[3:0]=4'b1001*/ -#define TSCON1_bit_0_3_1010 0x0A /*TSCON1[3:0]=4'b1010*/ -#define TSCON1_bit_0_3_1011 0x0B /*TSCON1[3:0]=4'b1011*/ -#define TSCON1_bit_0_3_1100 0x0C /*TSCON1[3:0]=4'b1100*/ -#define TSCON1_bit_0_3_1101 0x0D /*TSCON1[3:0]=4'b1101*/ -#define TSCON1_bit_0_3_1110 0x0E /*TSCON1[3:0]=4'b1110*/ -#define TSCON1_bit_0_3_1111 0x0F /*TSCON1[3:0]=4'b1111*/ -#define TSCON1_bit_0_3_MASK 0x0F - -/* ADC value to mcu */ -/*chip dependent*/ -#define TEMPADC_MCU0 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0000)) -#define TEMPADC_MCU1 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0001)) -#define TEMPADC_MCU2 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0010)) -#define TEMPADC_MCU4 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0100)) -#define TEMPADC_MCU5 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0101)) -#define TEMPADC_MCU6 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0110)) -#define TEMPADC_MCU7 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0111)) -#define TEMPADC_MCU8 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1000)) -#define TEMPADC_MCU9 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1001)) -#define TEMPADC_ABB ((0x30&TSCON1_bit_4_5_01)|(0x0F&TSCON1_bit_0_3_0000)) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x800) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x804) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x808) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x80C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x810) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x814) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x818) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x81C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x824) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x828) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x82C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x830) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x834) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x838) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x83C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x840) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x844) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x848) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x84C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x850) -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x854) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x858) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x85C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x860) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x864) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x868) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x86C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x870) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x874) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x878) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x87C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x880) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x884) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x888) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x88C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x890) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x894) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x898) -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x89C) -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x8A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x8A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x8A8) -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x8B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x8B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x8B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x8BC) -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x8C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x8C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x8C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x8CC) -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x8F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x8F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x8F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x8FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) -#endif /* __TSCPU_TSENSE_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6885/inc/tzbatt_initcfg.h deleted file mode 100644 index 2c0a2cb08a1a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6885/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6885/inc/tzcpu_initcfg.h deleted file mode 100644 index 96952a81626b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (117000) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6885/src/Makefile b/drivers/misc/mediatek/thermal/mt6885/src/Makefile deleted file mode 100644 index 8f3ba8c516ea..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(MTK_PLATFORM) -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v1 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/spm/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/mt3967/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ -ccflags-y += -I$(srctree)/include/dt-bindings/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/gpufreq_v1/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/include/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/ - -obj-$(CONFIG_THERMAL) += mtk_lvts_tc.o -#obj-$(CONFIG_THERMAL) += mtk_tc.o -obj-$(CONFIG_THERMAL) += mtk_tc_wrapper.o -obj-$(CONFIG_THERMAL) += mtk_thermal_ipi.o -obj-$(CONFIG_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vcore.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vproc.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vgpu.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359tsx.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359dcxo.o -#obj-$(CONFIG_THERMAL) += mtk_ti_6315.o diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_lvts_tc.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_lvts_tc.c deleted file mode 100644 index 402f540c411a..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_lvts_tc.c +++ /dev/null @@ -1,2276 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include -#include - -#define __MT_MTK_LVTS_TC_C__ -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_LVTS_TC_C__ - -#include -#include "mtk_thermal_ipi.h" - - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 3; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -int tscpu_debug_log; -int tscpu_sspm_thermal_throttle; -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif -/*============================================================= - * Local variable definition - *============================================================= - */ -/* chip dependent */ -/* - * TO-DO: I assume AHB bus frequecy is 78MHz. - * Please confirm it. - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1,T2) LVTS1-0, LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -struct lvts_thermal_controller lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM] = { - [0] = {/*(MCU)*/ - .ts = {L_TS_LVTS1_0, L_TS_LVTS1_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x26D000, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [1] = {/*(MCU)*/ - .ts = {L_TS_LVTS2_0, L_TS_LVTS2_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x26D100, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [2] = {/*(MCU)*/ - .ts = {L_TS_LVTS3_0, L_TS_LVTS3_1, L_TS_LVTS3_2, L_TS_LVTS3_3}, - .ts_number = 4, - .dominator_ts_idx = 1, - .tc_offset = 0x26D200, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [3] = {/*(AP)*/ - .ts = {L_TS_LVTS4_0, L_TS_LVTS4_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x0, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [4] = {/*(AP)*/ - .ts = {L_TS_LVTS5_0, L_TS_LVTS5_1}, - .ts_number = 2, - .dominator_ts_idx = 0, - .tc_offset = 0x100, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [5] = {/*(AP)*/ - .ts = {L_TS_LVTS6_0, L_TS_LVTS6_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x200, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [6] = {/*(AP)*/ - .ts = {L_TS_LVTS7_0, L_TS_LVTS7_1, L_TS_LVTS7_2}, - .ts_number = 3, - .dominator_ts_idx = 1, - .tc_offset = 0x300, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - } -}; - -static unsigned int g_golden_temp; -static unsigned int g_count_r[L_TS_LVTS_NUM]; -static unsigned int g_count_rc[L_TS_LVTS_NUM]; -static unsigned int g_count_rc_now[L_TS_LVTS_NUM]; -static int g_use_fake_efuse; -int lvts_debug_log; -int lvts_rawdata_debug_log; - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -static int hw_protect_setting_done; -int lvts_hw_protect_enabled; -#endif - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -#define NUM_LVTS_DEVICE_REG (5) -static const unsigned int g_lvts_device_addrs[NUM_LVTS_DEVICE_REG] = { - 0x00, - 0x04, - 0x08, - 0x0C, - 0xF0}; - -static unsigned int g_lvts_device_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; -static unsigned int g_lvts_device_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; - -#define NUM_LVTS_CONTROLLER_REG (17) -static const unsigned int g_lvts_controller_addrs[NUM_LVTS_CONTROLLER_REG] = { - 0x00,//LVTSMONCTL0_0 - 0x04,//LVTSMONCTL1_0 - 0x08,//LVTSMONCTL2_0 - 0x38,//LVTSMSRCTL0_0 - 0x40,//LVTSTSSEL_0 - 0x4C,//LVTS_ID_0 - 0x50,//LVTS_CONFIG_0 - 0x90,//LVTSMSR0_0 - 0x94,//LVTSMSR1_0 - 0x98,//LVTSMSR2_0 - 0x9C,//LVTSMSR3_0 - 0xB0,//LVTSRDATA0_0 - 0xB4,//LVTSRDATA1_0 - 0xB8,//LVTSRDATA2_0 - 0xBC,//LVTSRDATA3_0 - 0xE8,//LVTSDBGSEL_0 - 0xE4};//LVTSCLKEN_0 -static unsigned int g_lvts_controller_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -static unsigned int g_lvts_controller_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -#endif - -#if LVTS_VALID_DATA_TIME_PROFILING -unsigned long long int SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -int isTempValid; -/* latency_array - * {a, b} - * a: a time threshold in milliseconds. if it is -1, it means others. - * b: the number of valid temperature latencies from a phone enters SODI3 to - * to a phone gets a valid temperature of any sensor. - * It is possible a phone enters SODI3 several times without a valid - * temperature data. - */ -#define NUM_TIME_TH (16) -static unsigned int latency_array[NUM_TIME_TH][2] = { - {100, 0}, - {200, 0}, - {300, 0}, - {400, 0}, - {500, 0}, - {600, 0}, - {700, 0}, - {800, 0}, - {900, 0}, - {1000, 0}, - {2000, 0}, - {3000, 0}, - {4000, 0}, - {5000, 0}, - {10000, 0}, - {-1, 0} -}; -long long int start_timestamp; -static long long int end_timestamp, time_diff; -/* count if start_timestamp is bigger than end_timestamp */ -int diff_error_count; -#endif - -#if CFG_THERM_LVTS -#define DEFAULT_EFUSE_GOLDEN_TEMP (50) -#define DEFAULT_EFUSE_COUNT (35000) -#define DEFAULT_EFUSE_COUNT_RC (2750) -#define FAKE_EFUSE_VALUE 0x2B048500 -#define LVTS_COEFF_A_X_1000 (-252500) -#define LVTS_COEFF_B_X_1000 (252500) -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static unsigned int lvts_temp_to_raw(int ret, enum lvts_sensor_enum ts_name); - -static void lvts_set_tc_trigger_hw_protect( - int temperature, int temperature2, int tc_num); -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -void mt_reg_sync_writel_print(unsigned int val, void *addr) -{ - if (lvts_debug_log) - lvts_dbg_printk("### LVTS_REG: addr 0x%p, val 0x%x\n", - addr, val); - - mt_reg_sync_writel(val, addr); -} - -/*=============================================================*/ - -static int lvts_write_device(unsigned int config, unsigned int dev_reg_idx, -unsigned int data, int tc_num) -{ - int offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - dev_reg_idx &= 0xFF; - data &= 0xFF; - - config = config | (dev_reg_idx << 8) | data; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* - * LVTS Device Register Setting take 1us(by 26MHz clock source) - * interface latency to access. - * So we set 2~3us delay could guarantee access complete. - */ - udelay(3); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - - return 1; -} - -static unsigned int lvts_read_device(unsigned int config, -unsigned int dev_reg_idx, int tc_num) -{ - int offset, cnt; - unsigned int data = 0; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - dev_reg_idx &= 0xFF; - - config = config | (dev_reg_idx << 8) | 0x00; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - data = (readl(LVTSRDATA0_0 + offset)); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - - return data; -} -int lvts_raw_to_temp(unsigned int msr_raw, enum lvts_sensor_enum ts_name) -{ - /* This function returns degree mC - * temp[i] = a * MSR_RAW/16384 + GOLDEN_TEMP/2 + b - * a = -204.65 - * b = 204.65 - */ - int temp_mC = 0; - int temp1 = 0; - - temp1 = (LVTS_COEFF_A_X_1000 * ((unsigned long long int)msr_raw)) >> 14; - - temp_mC = temp1 + g_golden_temp * 500 + LVTS_COEFF_B_X_1000; - - return temp_mC; -} -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -static void read_controller_reg_before_active(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_b[i][j] = temp; - } - } - -} - -static void read_controller_reg_when_error(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_e[i][j] = temp; - } - } -} - -static void read_device_reg_before_active(void) -{ - int i, j; - unsigned int addr, data; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - data = lvts_read_device(0x81020000, addr, i); - g_lvts_device_value_b[i][j] = data; - } - } -} - -static void read_device_reg_when_error(void) -{ - int i, j, offset, cnt; - unsigned int addr; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - lvts_write_device(0x81020000, addr, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - g_lvts_device_value_e[i][j] = (readl(LVTSRDATA0_0 - + offset)); - } - } -} - -void clear_lvts_register_value_array(void) -{ - int i, j; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - g_lvts_controller_value_b[i][j] = 0; - g_lvts_controller_value_e[i][j] = 0; - } - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - g_lvts_device_value_b[i][j] = 0; - g_lvts_device_value_e[i][j] = 0; - } - } -} - -static void dump_lvts_register_value(void) -{ - int i, j, offset, tc_offset; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][BEFROE][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][BEFORE][TC][DUMP] "); - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_b[i][j]); - } - - lvts_printk("%s\n", buffer); - - - - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][BEFORE][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_b[i][j]); - } - - lvts_printk("%s\n", buffer); - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][AFTER][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][AFTER][TC][DUMP] "); - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_e[i][j]); - } - - lvts_printk("%s\n", buffer); - - - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][AFTER][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_e[i][j]); - } - - lvts_printk("%s\n", buffer); - } -} - -void dump_lvts_error_info(void) -{ - read_controller_reg_when_error(); - - lvts_disable_all_sensing_points(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -} - -#endif - -static void lvts_device_check_counting_status(int tc_num) -{ - /* Check this when LVTS device is counting for - * a temperature or a RC now - */ - - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; //tc offset - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(25))) { - cnt++; - - if (cnt == 100) { - lvts_printk( - "Error: DEVICE_SENSING_STATUS didn't ready\n"); - break; - } - udelay(2); - } - } -} - -static void lvts_device_check_read_write_status(int tc_num) -{ - /* Check this when LVTS device is doing a register - * read or write operation - */ - - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk( - "Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - -} - -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -void lvts_device_read_count_RC_N_resume(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - /* Set LVTS Manual-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x00, i); - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0x81030000, 0x0D, j, i); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0x78, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - lvts_write_device(0x81030000, 0x07, 0xA6, i); - - /* Wait 8us for device settle + 2us buffer*/ - udelay(10); - /* Kick-off RCK counting */ - lvts_write_device(0x81030000, 0x03, 0x02, i); - - /* wait 30ms */ - udelay(30); - - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0x81020000, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - - /* Disable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF1, i); - - lvts_device_check_read_write_status(i); - - /* Get RCK value from LSB[23:0] */ - //g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - } - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0x81030000, 0x0D, 0x10, i); - } - - offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); - - for (i = 0; i < L_TS_LVTS_NUM; i++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "%d:%d ", - i, g_count_rc_now[i]); - } - - lvts_printk("%s\n", buffer); - - - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} -#endif - -void lvts_device_read_count_RC_N(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int k, i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - unsigned int rc_data; - int refine_data_idx[4] = {0}; - /* - * comare count_rc_now with efuse. - * > 6%, use efuse RC instead of count_rc_now - * < 6%, keep count_rc_now value - */ - int count_rc_delta = 0; -#endif - - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - /* Set LVTS Manual-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x00, i); - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - /* - * set 0xff to clear refine_data_idx - * in each thermal controller, - * max sensor num = 4 - */ - for (k = 0; k < 4; k++) - refine_data_idx[k] = 0xff; -#endif - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0x81030000, 0x0D, j, i); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0x78, i); - lvts_write_device(0x81030000, 0x07, 0xA6, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); -// lvts_write_device(0x81030000, 0x07, 0xA6, i); - - /* Wait 8us for device settle + 2us buffer*/ - udelay(10); - - /* Kick-off RCK counting */ - lvts_write_device(0x81030000, 0x03, 0x02, i); - - /* wait 30us */ - udelay(30); - - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0x81020000, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - rc_data = (data & _BITMASK_(23:0)); - - /* - * if count rc now = 0 , use efuse rck insead of - * count_rc_now - */ - if (rc_data == 0) { - refine_data_idx[j] = s_index; - lvts_printk("rc_data %d, data_idx[%d]=%d\n", - rc_data, j, s_index); - } else { - if (g_count_rc[i] > rc_data) - count_rc_delta = - (g_count_rc[i] * 1000) / rc_data; - else - count_rc_delta = - (rc_data * 1000) / g_count_rc[i]; - - /* - * if delta > 6%, use efuse rck insead of - * count_rc_now - */ - if (count_rc_delta > 1061) { - refine_data_idx[j] = s_index; - lvts_printk( - "delta %d, data_idx[%d]=%d\n", - count_rc_delta, j, s_index); - } - } - - - //lvts_printk("i=%d, j=%d, s_index=%d, rc_data=%d\n", - // i, j, s_index, rc_data); - //lvts_printk("(g_count_rc[i]*1000)=%d, rc_delta=%d\n", - // (g_count_rc[i]*1000), count_rc_delta); - -#endif - - - //lvts_printk("i=%d,j=%d, data=%d, s_index=%d\n", - // i, j, (data & _BITMASK_(23:0)), s_index); - - /* Disable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF1, i); - - lvts_device_check_read_write_status(i); - - /* Get RCK value from LSB[23:0] */ - g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - } - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - for (j = 0; j < num_ts; j++) { - if (refine_data_idx[j] != 0xff) { - g_count_rc_now[refine_data_idx[j]] = - g_count_rc[i]; - lvts_printk("refine_data_idx[%d]=%d\n", - j, refine_data_idx[j]); - } - } -#endif - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0x81030000, 0x0D, 0x10, i); - } - - offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "%d:%d ", - i, g_count_rc_now[i]); - } - - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} - -void lvts_device_enable_auto_rck(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Set LVTS AUTO-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x01, i); - } -} - -void lvts_efuse_setting(void) -{ - __u32 offset; - int i, j, s_index; - int efuse_data; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - s_index = lvts_tscpu_g_tc[i].ts[j]; - -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse_data = - (((unsigned long long int)g_count_rc_now[s_index]) * - g_count_r[s_index]) >> 14; -#else - efuse_data = g_count_r[s_index]; -#endif - - switch (j) { - case 0: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA00_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA00_%d 0x%x\n", - i, readl(LVTSEDATA00_0 + offset)); - break; - - case 1: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA01_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA01_%d 0x%x\n", - i, readl(LVTSEDATA01_0 + offset)); - break; - case 2: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA02_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA02_%d 0x%x\n", - i, readl(LVTSEDATA02_0 + offset)); - break; - case 3: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA03_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA03_%d 0x%x\n", - i, readl(LVTSEDATA03_0 + offset)); - break; - default: - lvts_dbg_printk("%s, illegal ts order : %d!!\n", - __func__, j); - } - } - } - -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -void dump_efuse_data(void) -{ - int i, efuse, offset; - char buffer[512]; - - lvts_printk("[LVTS_ERROR][GOLDEN_TEMP][DUMP] %d\n", g_golden_temp); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_R][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_r[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_rc[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC_NOW][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", - i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][LVTSEDATA][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse = g_count_rc_now[i] * g_count_r[i]; -#else - efuse = g_count_r[i]; -#endif - offset += sprintf(buffer + offset, "%d:%d ", i, efuse); - } - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); -} - -int check_lvts_mcu_efuse(void) -{ - return (g_use_fake_efuse)?(0):(1); -} -#endif - -void lvts_device_identification(void) -{ - int tc_num, data, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Enable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000001, LVTSCLKEN_0 + offset); - - /* Reset All Devices */ - lvts_write_device(0x81030000, 0xFF, 0xFF, tc_num); - /* udelay(100); */ - - /* Read back Dev_ID with Update */ - lvts_write_device(0x85020000, 0xFC, 0x55, tc_num); - - /* Check LVTS device ID */ - data = (readl(LVTS_ID_0 + offset) & _BITMASK_(7:0)); - if (data != (0x81 + tc_num)) - lvts_printk("LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", - tc_num, (0x81 + tc_num), data); - } -} - -void lvts_reset_device_and_stop_clk(void) -{ - __u32 offset; - int tc_num; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Reset All Devices */ - lvts_write_device(0x81030000, 0xFF, 0xFF, tc_num); - - /* Disable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000000, LVTSCLKEN_0 + offset); - } -} - -void lvts_Device_Enable_Init_all_Devices(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Release Counting StateMachine */ - lvts_write_device(0x81030000, 0x03, 0x00, i); - /* Set LVTS device counting window 20us */ - lvts_write_device(0x81030000, 0x04, 0x20, i); - lvts_write_device(0x81030000, 0x05, 0x00, i); - /* TSV2F_CHOP_CKSEL & TSV2F_EN */ - lvts_write_device(0x81030000, 0x0A, 0xC4, i); - /* TSBG_DEM_CKSEL * TSBG_CHOP_EN */ - lvts_write_device(0x81030000, 0x0C, 0x7C, i); - /* Set TS_RSV */ - lvts_write_device(0x81030000, 0x09, 0x8D, i); - -#if LVTS_DEVICE_AUTO_RCK == 0 - /* Device low power mode can ignore these settings and - * Device auto RCK mode will force device in low power - * mode - */ - - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - - /* Lantency */ - lvts_write_device(0x81030000, 0x07, 0xA6, i); - -#endif - } -} - -void lvts_thermal_cal_prepare(void) -{ - unsigned int temp[22]; - int i, offset; - char buffer[512]; - - temp[0] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_1); - temp[1] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_2); - temp[2] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_3); - temp[3] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_4); - temp[4] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_5); - temp[5] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_6); - temp[6] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_7); - temp[7] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_8); - temp[8] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_9); - temp[9] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_10); - temp[10] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_11); - temp[11] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_12); - temp[12] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_13); - temp[13] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_14); - temp[14] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_15); - temp[15] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_16); - temp[16] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_17); - temp[17] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_18); - temp[18] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_19); - temp[19] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_20); - temp[20] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_21); - temp[21] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_22); - - - for (i = 0; (i + 5) < 22; i = i + 5) - lvts_printk("[lvts_call] %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x\n", - i, temp[i], i + 1, temp[i + 1], i + 2, temp[i + 2], - i + 3, temp[i + 3], i + 4, temp[i + 4]); - - lvts_printk("[lvts_call] 20: 0x%x, 21: 0x%x\n", temp[20], temp[21]); - - - g_golden_temp = ((temp[0] & _BITMASK_(31:24)) >> 24);//0x11C1_01B4 - g_count_r[0] = (temp[1] & _BITMASK_(23:0)); //0x11C1_01C4,LVTS1_0 - g_count_r[1] = (temp[2] & _BITMASK_(23:0)); //0x11C1_01C8,LVTS1_1 - g_count_r[2] = (temp[3] & _BITMASK_(23:0)); //0x11C1_01CC,LVTS2_0 - g_count_r[3] = (temp[4] & _BITMASK_(23:0)); //0x11C1_01D0,LVTS2_1 - g_count_r[4] = (temp[5] & _BITMASK_(23:0)); //0x11C1_01D4,LVTS3_0 - g_count_r[5] = (temp[6] & _BITMASK_(23:0)); //0x11C1_01D8,LVTS3_1 - g_count_r[6] = (temp[7] & _BITMASK_(23:0)); //0x11C1_01DC,LVTS3_2 - g_count_r[7] = (temp[8] & _BITMASK_(23:0)); //0x11C1_01E0,LVTS3_3 - g_count_r[8] = (temp[9] & _BITMASK_(23:0)); //0x11C1_01E4,LVTS4_0 - g_count_r[9] = (temp[10] & _BITMASK_(23:0)); //0x11C1_01E8,LVTS4_1 - g_count_r[10] = (temp[11] & _BITMASK_(23:0));//0x11C1_01EC,LVTS5_0 - g_count_r[11] = (temp[12] & _BITMASK_(23:0));//0x11C1_01F0,LVTS5_1 - g_count_r[12] = (temp[13] & _BITMASK_(23:0));//0x11C1_01F4,LVTS6_0 - g_count_r[13] = (temp[14] & _BITMASK_(23:0));//0x11C1_01F8,LVTS6_1 - g_count_r[14] = (temp[15] & _BITMASK_(23:0));//0x11C1_01FC,LVTS7_0 - g_count_r[15] = (temp[16] & _BITMASK_(23:0));//0x11C1_0200,LVTS7_1 - g_count_r[16] = (temp[17] & _BITMASK_(23:0));//0x11C1_0204,LVTS7_2 - - /*0214, LVTS1_0_COUNT_RC*/ - g_count_rc[0] = (temp[21] & _BITMASK_(23:0)); - - /*01C4, 01C8, 01CC, LVTS2_0_COUNT_RC*/ - g_count_rc[1] = ((temp[1] & _BITMASK_(31:24)) >> 8) + - ((temp[2] & _BITMASK_(31:24)) >> 16)+ - ((temp[3] & _BITMASK_(31:24)) >> 24); - - /*01D0, 01D4, 01D8, LVTS3_0_COUNT_RC*/ - g_count_rc[2] = ((temp[4] & _BITMASK_(31:24)) >> 8) + - ((temp[5] & _BITMASK_(31:24)) >> 16) + - ((temp[6] & _BITMASK_(31:24)) >> 24); - - /*01DC, 01E0, 01E4, LVTS4_0_COUNT_RC*/ - g_count_rc[3] = ((temp[7] & _BITMASK_(31:24)) >> 8) + - ((temp[8] & _BITMASK_(31:24)) >> 16) + - ((temp[9] & _BITMASK_(31:24)) >> 24); - - /*01E8, 01EC, 01F0, LVTS5_0_COUNT_RC*/ - g_count_rc[4] = ((temp[10] & _BITMASK_(31:24)) >> 8) + - ((temp[11] & _BITMASK_(31:24)) >> 16) + - ((temp[12] & _BITMASK_(31:24)) >> 24); - - /*01F4, 01F8, 01FC, LVTS6_0_COUNT_RC*/ - g_count_rc[5] = ((temp[13] & _BITMASK_(31:24)) >> 8) + - ((temp[14] & _BITMASK_(31:24)) >> 16) + - ((temp[15] & _BITMASK_(31:24)) >> 24); - - /*0200, 0204, 0208, LVTS7_0_COUNT_RC*/ - g_count_rc[6] = ((temp[16] & _BITMASK_(31:24)) >> 8) + - ((temp[17] & _BITMASK_(31:24)) >> 16) + - ((temp[18] & _BITMASK_(31:24)) >> 24); - - - for (i = 0; i < L_TS_LVTS_NUM; i++) { - if (i == 0) { - if ((temp[0] & _BITMASK_(7:0)) != 0) - break; - } else { - if (temp[i] != 0) - break; - } - } - - if (i == L_TS_LVTS_NUM) { - /* It means all efuse data are equal to 0 */ - lvts_printk( - "[lvts_cal] This sample is not calibrated, fake !!\n"); - - g_golden_temp = DEFAULT_EFUSE_GOLDEN_TEMP; - for (i = 0; i < L_TS_LVTS_NUM; i++) { - g_count_r[i] = DEFAULT_EFUSE_COUNT; - g_count_rc[i] = DEFAULT_EFUSE_COUNT_RC; - } - - g_use_fake_efuse = 1; - } - - lvts_printk("[lvts_cal] g_golden_temp = %d\n", g_golden_temp); - - offset = snprintf(buffer, sizeof(buffer), - "[lvts_cal] num:g_count_r:g_count_rc "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "%d:%d:%d ", - i, g_count_r[i], g_count_rc[i]); - } - - lvts_printk("%s\n", buffer); -} - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -void lvts_ipi_send_efuse_data(void) -{ - struct thermal_ipi_data thermal_data; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = g_golden_temp; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_LVTS_INIT_GRP1, &thermal_data) != 0) - udelay(100); -} -#endif - - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#if defined(THERMAL_SSPM_THERMAL_THROTTLE_SWITCH) -void lvts_ipi_send_sspm_thermal_thtottle(void) -{ - struct thermal_ipi_data thermal_data; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = tscpu_sspm_thermal_throttle; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - &thermal_data) != 0) - udelay(100); -} -#endif - -#if defined(THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY) -void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend) -{ - struct thermal_ipi_data thermal_data; - - //lvts_printk("%s, is_suspend %d\n", __func__, is_suspend); - - thermal_data.u.data.arg[0] = is_suspend; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - &thermal_data) != 0) - udelay(100); -} -#endif -#endif - -static unsigned int lvts_temp_to_raw(int temp, enum lvts_sensor_enum ts_name) -{ - /* MSR_RAW = ((temp[i] - GOLDEN_TEMP/2 - b) * 16384) / a - * a = -204.65 - * b = 204.65 - */ - unsigned int msr_raw = 0; - - msr_raw = ((long long int)(((long long int)g_golden_temp * 500 + - LVTS_COEFF_B_X_1000 - temp)) << 14)/(-1 * LVTS_COEFF_A_X_1000); - - lvts_dbg_printk("%s msr_raw = 0x%x,temp=%d\n", __func__, msr_raw, temp); - - return msr_raw; -} - -static void lvts_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + LVTSMONINTSTS_0); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + LVTSMONINTSTS_0); - - lvts_printk("[Thermal IRQ] LVTS thermal controller %d, LVTSMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_COLD_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_DEVICE_TIMEOUT_INTERRUPT) - lvts_dbg_printk("[Thermal IRQ]: Device access timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: High offset triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 1 interrupt triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 2 interrupt triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) - lvts_printk("[Thermal IRQ]: Thermal protection stage 3 interrupt triggered, Thermal HW reboot\n"); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - ret = ret & 0x7F; - /* MSB LSB NAME - * 6 6 LVTSINT3 - * 5 5 LVTSINT2 - * 4 4 LVTSINT1 - * 3 3 LVTSINT0 - * 2 2 THERMINT2 - * 1 1 THERMINT1 - * 0 0 THERMINT0 - */ - - lvts_printk("%s : THERMINTST = 0x%x\n", __func__, ret); - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - lvts_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void lvts_configure_polling_speed_and_filter(int tc_num) -{ - __u32 offset, lvtsMonCtl1, lvtsMonCtl2; - - lvts_dbg_printk("%s\n", __func__); - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvtsMonCtl1 = - (((lvts_tscpu_g_tc[tc_num].tc_speed.group_interval_delay - << 20) & _BITMASK_(29:20)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0))); - lvtsMonCtl2 = - (((lvts_tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay - & _BITMASK_(9:0))); - /* - * Calculating period unit in Module clock x 256, and the - * Module clock will be changed to 26M when Infrasys - * enters Sleep mode. - */ - - /* - * bus clock 66M counting unit is - * 12 * 1/66M * 256 = 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel_print(lvtsMonCtl1, offset + LVTSMONCTL1_0); - /* - *filt interval is 1 * 46.545us = 46.545us, - *sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel_print(lvtsMonCtl2, offset + LVTSMONCTL2_0); - - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel_print(0x00000492, offset + LVTSMSRCTL0_0); - - udelay(1); - lvts_dbg_printk( - "%s %d, LVTSMONCTL1_0= 0x%x,LVTSMONCTL2_0= 0x%x,LVTSMSRCTL0_0= 0x%x\n", - __func__, tc_num, - readl(LVTSMONCTL1_0 + offset), - readl(LVTSMONCTL2_0 + offset), - readl(LVTSMSRCTL0_0 + offset)); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -/* - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void lvts_set_tc_trigger_hw_protect( -int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, config, offset; -#if LVTS_USE_DOMINATOR_SENSING_POINT - unsigned int d_index; - enum lvts_sensor_enum ts_name; -#endif - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvts_dbg_printk("%s t1=%d t2=%d\n", - __func__, temperature, temperature2); - -#if LVTS_USE_DOMINATOR_SENSING_POINT - if (lvts_tscpu_g_tc[tc_num].dominator_ts_idx < - lvts_tscpu_g_tc[tc_num].ts_number){ - d_index = lvts_tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - lvts_printk( - "Error: LVTS TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - lvts_tscpu_g_tc[tc_num].dominator_ts_idx, - lvts_tscpu_g_tc[tc_num].ts_number); - - lvts_printk( - "Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - ts_name = lvts_tscpu_g_tc[tc_num].ts[d_index]; - - lvts_dbg_printk("%s # in tc%d , the dominator ts_name is %d\n", - __func__, tc_num, ts_name); - - /* temperature to trigger SPM state2 */ - raw_high = lvts_temp_to_raw(temperature, ts_name); -#else - raw_high = lvts_temp_to_raw(temperature, 0); -#endif - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - temp = readl(offset + LVTSMONINT_0); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print(temp & 0x00000000, - offset + LVTSMONINT_0); -#endif - - temp = readl(offset + LVTSPROTCTL_0) & ~(0xF << 16); -#if LVTS_USE_DOMINATOR_SENSING_POINT - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel_print(temp | config, - offset + LVTSPROTCTL_0); -#else - /* Maximum of 4 sensing points */ - config = (0x1 << 16); - mt_reg_sync_writel_print(temp | config, - offset + LVTSPROTCTL_0); -#endif - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel_print(raw_high, offset + LVTSPROTTC_0); - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print(temp | 0x80000000, - offset + LVTSMONINT_0); -#endif - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -static void dump_lvts_device(int tc_num, __u32 offset) -{ - lvts_printk("%s, LVTS_CONFIG_%d= 0x%x\n", __func__, - tc_num, readl(LVTS_CONFIG_0 + offset)); - udelay(2); - - //read raw data - lvts_printk("%s, LVTSRDATA0_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA0_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA1_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA1_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA2_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA2_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA3_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA3_0 + offset)); -} - -#if LVTS_VALID_DATA_TIME_PROFILING -void lvts_dump_time_profiling_result(struct seq_file *m) -{ - int i, sum; - - seq_printf(m, "SODI3_count= %llu\n", SODI3_count); - seq_printf(m, "noValid_count %llu, %d%%\n", - noValid_count, ((noValid_count * 100) / SODI3_count)); - seq_printf(m, "valid_count %llu, %d%%\n", - (SODI3_count - noValid_count), - (((SODI3_count - noValid_count) * 100) / SODI3_count)); - - sum = 0; - for (i = 0; i < NUM_TIME_TH; i++) - sum += latency_array[i][1]; - - seq_printf(m, "Valid count in latency_array = %d\n", sum); - - for (i = 0; i < NUM_TIME_TH; i++) { - if (i == 0) { - seq_printf(m, "Count valid latency between 0ms ~ %dms: %d, %d%%\n", - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else if (i == (NUM_TIME_TH - 1)) { - seq_printf(m, "Count valid others: %d, %d%%\n", - latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else { - seq_printf(m, "Count valid latency between %dms ~ %dms: %d, %d%%\n", - latency_array[i - 1][0], - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } - } - - /* count if start_timestamp is bigger than end_timestamp */ - seq_printf(m, "diff_error_count= %d\n", diff_error_count); - seq_printf(m, "Current start_timestamp= %lldus\n", start_timestamp); - seq_printf(m, "Current end_timestamp= %lldus\n", end_timestamp); - seq_printf(m, "Current time_diff= %lldus\n", time_diff); -} - -static void lvts_count_valid_temp_latency(long long int time_diff) -{ - /* time_diff is in microseconds */ - int i; - - for (i = 0; i < (NUM_TIME_TH - 1); i++) { - if (time_diff < (((long long int)latency_array[i][0]) - * 1000)) { - latency_array[i][1]++; - break; - } - } - - if (i == (NUM_TIME_TH - 1)) - latency_array[i][1]++; -} -#endif - - -static int lvts_read_tc_raw_and_temp( - u32 *tempmsr_name, enum lvts_sensor_enum ts_name) -{ - int temp = 0, raw = 0, raw1 = 0, raw2 = 0; - - if (thermal_base == 0) - return 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl((tempmsr_name)); - raw1 = (raw & 0x10000) >> 16; //bit 16 : valid bit - raw2 = raw & 0xFFFF; - temp = lvts_raw_to_temp(raw2, ts_name); - - if (raw2 == 0) { - /* 26111 is magic num - * this is to keep system alive for a while - * to wait HW init done, - * because 0 msr raw will translates to 28x'C - * and then 28x'C will trigger a SW reset. - * - * if HW init finish, this msr raw will not be 0, - * system can report normal temperature. - * if wait over 60 times zero, this means something - * wrong with HW, must trigger BUG on and dump useful - * register for debug. - */ - - temp = 26111; - } - - - if (lvts_rawdata_debug_log) { - lvts_printk( - "[LVTS_MSR] ts%d msr_all=%x, valid=%d, msr_temp=%d, temp=%d\n", - ts_name, raw, raw1, raw2, temp); - } - - tscpu_ts_lvts_temp_r[ts_name] = raw2; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_lvts_temp_v[ts_name] = raw1; -#endif -#if LVTS_VALID_DATA_TIME_PROFILING - if (isTempValid == 0 && raw1 != 0 && SODI3_count != 0) { - isTempValid = 1; - end_timestamp = thermal_get_current_time_us(); - time_diff = end_timestamp - start_timestamp; - if (time_diff < 0) { - lvts_printk("[LVTS_ERROR] time_diff = %lldus,start_time= %lldus, end_time= %lldus\n", - time_diff, start_timestamp, end_timestamp); - diff_error_count++; - } else { - lvts_count_valid_temp_latency(time_diff); - } - } -#endif - - return temp; -} - -static void lvts_tscpu_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order) -{ - __u32 offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - if (lvts_rawdata_debug_log) - dump_lvts_device(tc_num, offset); - - switch (order) { - case 0: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 1: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR1_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 2: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR2_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 3: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR3_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - default: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - -} - -void read_all_tc_lvts_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) - lvts_tscpu_thermal_read_tc_temp(i, - lvts_tscpu_g_tc[i].ts[j], j); -} - -/* pause ALL periodoc temperature sensing point */ -void lvts_pause_all_sensing_points(void) -{ - int i, temp, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel_print((temp | 0x10E), - offset + LVTSMSRCTL1_0); - } -} - -/* - * lvts_thermal_check_all_sensing_point_idle - - * Check if all sensing points are idle - * Return: 0 if all sensing points are idle - * an error code if one of them is busy - * error code[31:16]: an index of LVTS thermal controller - * error code[2]: bit 10 of LVTSMSRCTL1 - * error code[1]: bit 7 of LVTSMSRCTL1 - * error code[0]: bit 0 of LVTSMSRCTL1 - */ -static int lvts_thermal_check_all_sensing_point_idle(void) -{ - int i, temp, offset, error_code; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* Check if bit10=bit7=bit0=0 */ - if ((temp & 0x481) != 0) { - error_code = (i << 16) + ((temp & _BIT_(10)) >> 8) + - ((temp & _BIT_(7)) >> 6) + - (temp & _BIT_(0)); - - return error_code; - } - } - - return 0; -} - -void lvts_wait_for_all_sensing_point_idle(void) -{ - int cnt, temp; - - cnt = 0; - /* - * Wait until all sensoring points idled. - * No need to check LVTS status when suspend/resume, - * this will spend extra 100us of suspend flow. - * LVTS status will be reset after resume. - */ - while (cnt < 50 && (tscpu_kernel_status() == 0)) { - temp = lvts_thermal_check_all_sensing_point_idle(); - if (temp == 0) - break; - - if ((cnt + 1) % 10 == 0) { - pr_notice("Cnt= %d LVTS TC %d, LVTSMSRCTL1[10,7,0] = %d,%d,%d, LVTSMSRCTL1[10:0] = 0x%x\n", - cnt + 1, (temp >> 16), - ((temp & _BIT_(2)) >> 2), - ((temp & _BIT_(1)) >> 1), - (temp & _BIT_(0)), - (temp & _BITMASK_(10:0))); - } - - udelay(2); - cnt++; - } -} -/* release ALL periodoc temperature sensing point */ -void lvts_release_all_sensing_points(void) -{ - int i = 0, temp; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(((temp & (~0x10E))), - offset + LVTSMSRCTL1_0); - } -} - -void lvts_sodi3_release_thermal_controller(void) -{ - /* SPM will close 26M to saving power during SODI3 - * Because both auxadc thermal controllers and lvts thermal controllers - * need 26M to work properly, it would cause thermal controllers to - * report an abnormal high or low temperature after leaving SODI3 - * - * The SW workaround solution is that - * SPM will pause LVTS thermal controllers before closing 26M, and - * try to release LVTS thermal controllers after leaving SODI3 - * thermal driver check and release LVTS thermal controllers if - * necessary after leaving SODI3 - */ - int i = 0, temp, lvts_paused = 0; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - /*don't need to do release LVTS when suspend/resume*/ - if (tscpu_kernel_status() == 0) { - - /* Check if SPM paused thermal controller */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause - *sensing point 0,1,2,3 - */ - if ((temp & 0x10E) != 0) { - lvts_paused = 1; - pr_notice_ratelimited( - "lvts_paused = %d\n", lvts_paused); - break; - } - } - - /* Return if SPM didn't pause thermal controller or - * released thermal controllers already - */ - if (lvts_paused == 0) - return; - /* Wait until all of LVTS thermal controllers are idle - * Pause operation has to take time to finish. - * if it didn't finish before SPM closed 26M, we have to wait - * until it is finished to make sure all LVTS thermal - * controllers in a correct finite state machine - */ - - lvts_wait_for_all_sensing_point_idle(); - - lvts_release_all_sensing_points(); - } -} - -/* - * disable ALL periodoc temperature sensing point - */ -void lvts_disable_all_sensing_points(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel_print(0x00000000, offset + LVTSMONCTL0_0); - } -} - -void lvts_enable_all_sensing_points(void) -{ - int i, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - - lvts_dbg_printk("%s %d:%d\n", __func__, i, - lvts_tscpu_g_tc[i].ts_number); - - switch (lvts_tscpu_g_tc[i].ts_number) { - case 1: - /* enable sensing point 0 */ - mt_reg_sync_writel_print(0x00000201, - offset + LVTSMONCTL0_0); - break; - case 2: - /* enable sensing point 0,1 */ - mt_reg_sync_writel_print(0x00000203, - offset + LVTSMONCTL0_0); - break; - case 3: - /* enable sensing point 0,1,2 */ - mt_reg_sync_writel_print(0x00000207, - offset + LVTSMONCTL0_0); - break; - case 4: - /* enable sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(0x0000020F, - offset + LVTSMONCTL0_0); - break; - default: - lvts_printk("Error at %s\n", __func__); - break; - } - } -} - -void lvts_tscpu_thermal_initial_all_tc(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - /* set sensor index of LVTS */ - mt_reg_sync_writel_print(0x13121110, LVTSTSSEL_0 + offset); - /* set calculation scale rules */ - mt_reg_sync_writel_print(0x00000300, LVTSCALSCALE_0 + offset); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0xB8, i); - - lvts_configure_polling_speed_and_filter(i); - } - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_controller_reg_before_active(); -#endif -} - -static void lvts_disable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_DIS, WD_REQ_RST_MODE); - - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -static void lvts_enable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_EN, WD_REQ_RST_MODE); - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void lvts_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - - lvts_dbg_printk("%s, temperature=%d,temperature2=%d,\n", - __func__, temperature, temperature2); - - /*spend 860~1463 us */ - /*Thermal need to config to direct reset mode - *this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - lvts_set_tc_trigger_hw_protect(temperature, temperature2, i); - } - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_enable_rgu_reset(); -#else - hw_protect_setting_done = 1; -#endif -} - -void lvts_tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - int temp2 = 0; - - lvts_dbg_printk("%s\n", __func__); - - /* reset AP thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_CLR); - - - - - /* reset MCU thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_SET); - - /* 1: Enables thermal control software reset */ - temp2 |= 0x00000400; - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp2 |= 0x00000400; - - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_CLR); -} - - -void get_lvts_slope_intercept(struct TS_PTPOD *ts_info, enum - thermal_bank_name ts_bank) -{ - struct TS_PTPOD ts_ptpod; - int temp; - - lvts_dbg_printk("%s\n", __func__); - - /* chip dependent */ - - temp = (0 - LVTS_COEFF_A_X_1000) * 2; - temp /= 1000; - ts_ptpod.ts_MTS = temp; - - temp = 500 * g_golden_temp + LVTS_COEFF_B_X_1000; - temp /= 1000; - ts_ptpod.ts_BTS = (temp - 25) * 4; - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - lvts_dbg_printk("(LVTS) ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_lvts_slope_intercept); - -int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "lvts_cal : %d\n", g_use_fake_efuse?0:1); - seq_printf(m, "[lvts_cal] g_golden_temp %d\n", g_golden_temp); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_r%d = 0x%x\n", - i, g_count_r[i]); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_rc%d = 0x%x\n", - i, g_count_rc[i]); - - return 0; -} - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -void lvts_enable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !hw_protect_setting_done - || lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, done=%d, en=%d\n", - __func__, tscpu_is_temp_valid(), - hw_protect_setting_done, lvts_hw_protect_enabled); - return; - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) | 0x80000000, - offset + LVTSMONINT_0); - } - - lvts_enable_rgu_reset(); - - /* clear offset after all HW reset are configured. */ - /* make sure LVTS controller uses latest sensor value to compare */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* clear offset */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) & ~0xFFFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 1; - - lvts_printk("%s: done\n", __func__); -} - -void lvts_disable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, en=%d\n", __func__, - tscpu_is_temp_valid(), lvts_hw_protect_enabled); - return; - } - - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) & 0x7FFFFFFF, - offset + LVTSMONINT_0); - /* set offset to 0x3FFF to avoid interrupt false triggered */ - /* large offset can guarantee temp check is always false */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) | 0x3FFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 0; - - lvts_printk("%s: done\n", __func__); -} -#endif - diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_pmic_efuse.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_pmic_efuse.c deleted file mode 100644 index 9ee08b6e719e..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_pmic_efuse.c +++ /dev/null @@ -1,824 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include -#include -#include -#include - -#if defined(THERMAL_USE_IIO_CHANNEL) -#include -#include -#endif -/*============================================================= - *Local variable definition - *============================================================= - */ -int mtktspmic_debug_log; -/* Cali */ -static __s32 g_o_vts; -static __s32 g_o_vts_2; -static __s32 g_o_vts_3; -static __s32 g_o_vts_4; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; -static __s32 g_slope1 = 1; -static __s32 g_slope2 = 1; -static __s32 g_intercept; -static __s32 g_tsbuck1_slope1 = 1; -static __s32 g_tsbuck1_slope2 = 1; -static __s32 g_tsbuck1_intercept; -static __s32 g_tsbuck2_slope1 = 1; -static __s32 g_tsbuck2_slope2 = 1; -static __s32 g_tsbuck2_intercept; -static __s32 g_tsbuck3_slope1 = 1; -static __s32 g_tsbuck3_slope2 = 1; -static __s32 g_tsbuck3_intercept; - -static DEFINE_MUTEX(TSPMIC_lock); -static int pre_temp1 = 0, PMIC_counter; -static int pre_tsbuck1_temp1 = 0, tsbuck1_cnt; -static int pre_tsbuck2_temp1 = 0, tsbuck2_cnt; -static int pre_tsbuck3_temp1 = 0, tsbuck3_cnt; -static int pre_tstsx_temp1 = 0, tstsx_cnt; -static int pre_tsdcxo_temp1 = 0, tsdcxo_cnt; - -#if defined(THERMAL_USE_IIO_CHANNEL) -struct iio_channel *chan_chip_temp; -struct iio_channel *chan_vcore_temp; -struct iio_channel *chan_vproc_temp; -struct iio_channel *chan_vgpu_temp; -struct iio_channel *chan_tsx_temp; -struct iio_channel *chan_dcxo_temp; -#endif -/*=============================================================*/ - -static __s32 pmic_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck1_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck1_intercept + - ((g_tsbuck1_slope1 * y_curr) / (g_tsbuck1_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck2_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck2_intercept + - ((g_tsbuck2_slope1 * y_curr) / (g_tsbuck2_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck3_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck3_intercept + - ((g_tsbuck3_slope1 * y_curr) / (g_tsbuck3_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static void mtktspmic_read_efuse(void) -{ - mtktspmic_info("[pmic_debug] start\n"); - /* MT6359 */ - g_o_vts = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS); - g_o_vts_2 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_2); - g_o_vts_3 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_3); - g_o_vts_4 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_4); - g_degc_cali = pmic_get_register_value(PMIC_AUXADC_EFUSE_DEGC_CALI); - g_adc_cali_en = pmic_get_register_value(PMIC_AUXADC_EFUSE_ADC_CALI_EN); - g_o_slope_sign = - pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE_SIGN); - g_o_slope = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE); - g_id = pmic_get_register_value(PMIC_AUXADC_EFUSE_ID); - - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts = %d\n", - g_o_vts); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_2 = %d\n", - g_o_vts_2); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_3 = %d\n", - g_o_vts_3); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_4 = %d\n", - g_o_vts_4); - mtktspmic_info("[pmic_debug] 6359_efuse: g_degc_cali = %d\n", - g_degc_cali); - mtktspmic_info("[pmic_debug] 6359_efuse: g_adc_cali_en = %d\n", - g_adc_cali_en); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope_sign = %d\n", - g_o_slope_sign); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope = %d\n", - g_o_slope); - mtktspmic_info("[pmic_debug] 6359_efuse: g_id = %d\n", - g_id); - - mtktspmic_info("[pmic_debug] end\n"); -} - -void mtktspmic_cali_prepare(struct regmap *pmic_map) -{ - mtktspmic_read_efuse(); - - if (g_id == 0) - g_o_slope = 0; - - /* g_adc_cali_en=0;//FIX ME */ - - if (g_adc_cali_en == 0) { /* no calibration */ - mtktspmic_info("[pmic_debug] It isn't calibration values\n"); - g_o_vts = 1600; - g_o_vts_2 = 1600; - g_o_vts_3 = 1600; - g_o_vts_4 = 1600; - g_degc_cali = 50; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - if (g_degc_cali < 38 || g_degc_cali > 60) - g_degc_cali = 53; - - mtktspmic_info("[pmic_debug] g_o_vts = 0x%x\n", g_o_vts); - mtktspmic_info("[pmic_debug] g_o_vts_2 = 0x%x\n", g_o_vts_2); - mtktspmic_info("[pmic_debug] g_o_vts_3 = 0x%x\n", g_o_vts_3); - mtktspmic_info("[pmic_debug] g_o_vts_4 = 0x%x\n", g_o_vts_4); - mtktspmic_info("[pmic_debug] g_degc_cali = 0x%x\n", g_degc_cali); - mtktspmic_info("[pmic_debug] g_adc_cali_en = 0x%x\n", g_adc_cali_en); - mtktspmic_info("[pmic_debug] g_o_slope = 0x%x\n", g_o_slope); - mtktspmic_info("[pmic_debug] g_o_slope_sign = 0x%x\n", g_o_slope_sign); - mtktspmic_info("[pmic_debug] g_id = 0x%x\n", g_id); - -} - -void mtktspmic_cali_prepare2(void) -{ - __s32 vbe_t; - int factor; - - factor = 1681; - - g_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_slope2 = -(factor + g_o_slope); - else - g_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_intercept = g_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_slope1, g_slope2, g_intercept, vbe_t); - - factor = 1863; - - g_tsbuck1_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck1_slope2 = -(factor + g_o_slope); - else - g_tsbuck1_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_2) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck1_intercept = g_tsbuck1_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck1_slope1, g_tsbuck1_slope2, g_tsbuck1_intercept, vbe_t); - - factor = 1863; - - g_tsbuck2_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck2_slope2 = -(factor + g_o_slope); - else - g_tsbuck2_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_3) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck2_intercept = g_tsbuck2_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck2_slope1, g_tsbuck2_slope2, g_tsbuck2_intercept, vbe_t); - - factor = 1863; - - g_tsbuck3_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck3_slope2 = -(factor + g_o_slope); - else - g_tsbuck3_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_4) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck3_intercept = g_tsbuck3_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck3_slope1, g_tsbuck3_slope2, g_tsbuck3_intercept, vbe_t); - -} - -#if defined(THERMAL_USE_IIO_CHANNEL) -void mtktspmic_get_from_dts(struct platform_device *pdev) -{ - int ret; - - chan_chip_temp = iio_channel_get(NULL, "AUXADC_CHIP_TEMP"); - if (IS_ERR(chan_chip_temp)) { - ret = PTR_ERR(chan_chip_temp); - pr_notice("AUXADC_CHIP_TEMP get fail, ret=%d\n", ret); - } - - chan_vcore_temp = iio_channel_get(NULL, "AUXADC_VCORE_TEMP"); - if (IS_ERR(chan_vcore_temp)) { - ret = PTR_ERR(chan_vcore_temp); - pr_notice("AUXADC_VCORE_TEMP get fail, ret=%d\n", ret); - } - - chan_vproc_temp = iio_channel_get(NULL, "AUXADC_VPROC_TEMP"); - if (IS_ERR(chan_vproc_temp)) { - ret = PTR_ERR(chan_vproc_temp); - pr_notice("AUXADC_VPROC_TEMP get fail, ret=%d\n", ret); - } - - chan_vgpu_temp = iio_channel_get(NULL, "AUXADC_VGPU_TEMP"); - if (IS_ERR(chan_vgpu_temp)) { - ret = PTR_ERR(chan_vgpu_temp); - pr_notice("AUXADC_VGPU_TEMP get fail, ret=%d\n", ret); - } - - chan_tsx_temp = iio_channel_get(NULL, "AUXADC_TSX_TEMP"); - if (IS_ERR(chan_tsx_temp)) { - ret = PTR_ERR(chan_tsx_temp); - pr_notice("AUXADC_TSX_TEMP get fail, ret=%d\n", ret); - } - - chan_dcxo_temp = iio_channel_get(NULL, "AUXADC_DCXO_TEMP"); - if (IS_ERR(chan_dcxo_temp)) { - ret = PTR_ERR(chan_dcxo_temp); - pr_notice("AUXADC_DCXO_TEMP get fail, ret=%d\n", ret); - } -} -#endif - -int mtktspmic_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_chip_temp)) { - ret = iio_read_channel_processed(chan_chip_temp, &temp); - if (ret < 0) - pr_notice("pmic_chip_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_CHIP_TEMP); -#endif - temp1 = pmic_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("[pmic_debug] Raw=%d, T=%d\n", temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("[%s] raw=%d, PMIC T=%d", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("[%s] temp(%d) too high, drop this data!\n", - __func__, temp1); - temp1 = pre_temp1; - } else if ((PMIC_counter != 0) - && (((pre_temp1 - temp1) > 30000) - || ((temp1 - pre_temp1) > 30000))) { - mtktspmic_info("[%s] temp diff too large, drop this data\n", - __func__); - temp1 = pre_temp1; - } else { - /* update previous temp */ - pre_temp1 = temp1; - mtktspmic_dprintk("[%s] pre_temp1=%d\n", __func__, pre_temp1); - - if (PMIC_counter == 0) - PMIC_counter++; - } - - - return temp1; -} - -int mt6359vcore_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vcore_temp)) { - ret = iio_read_channel_processed(chan_vcore_temp, &temp); - if (ret < 0) - pr_notice("pmic_vcore_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VCORE_TEMP); -#endif - temp1 = tsbuck1_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck1_temp1; - } else if ((tsbuck1_cnt != 0) - && (((pre_tsbuck1_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck1_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck1_temp1; - } else { - /* update previous temp */ - pre_tsbuck1_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck1_temp1=%d\n", __func__, - pre_tsbuck1_temp1); - - if (tsbuck1_cnt == 0) - tsbuck1_cnt++; - } - - return temp1; -} - -int mt6359vproc_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vproc_temp)) { - ret = iio_read_channel_processed(chan_vproc_temp, &temp); - if (ret < 0) - pr_notice("pmic_vproc_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VPROC_TEMP); -#endif - temp1 = tsbuck2_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck2_temp1; - } else if ((tsbuck2_cnt != 0) - && (((pre_tsbuck2_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck2_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck2_temp1; - } else { - /* update previous temp */ - pre_tsbuck2_temp1 = temp1; - mtktspmic_dprintk("%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck2_temp1); - - if (tsbuck2_cnt == 0) - tsbuck2_cnt++; - } - - return temp1; -} - -int mt6359vgpu_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vgpu_temp)) { - ret = iio_read_channel_processed(chan_vgpu_temp, &temp); - if (ret < 0) - pr_notice("pmic_vgpu_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VGPU_TEMP); -#endif - temp1 = tsbuck3_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck3_temp1; - } else if ((tsbuck3_cnt != 0) - && (((pre_tsbuck3_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck3_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck3_temp1; - } else { - /* update previous temp */ - pre_tsbuck3_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck3_temp1); - - if (tsbuck3_cnt == 0) - tsbuck3_cnt++; - } - - return temp1; -} - -static int u_table[126] = { - 64078, - 63972, - 63860, - 63741, - 63614, - 63480, - 63338, - 63188, - 63029, - 62860, - 62683, - 62495, - 62297, - 62089, - 61870, - 61639, - 61396, - 61140, - 60872, - 60591, - 60297, - 59989, - 59667, - 59330, - 58978, - 58612, - 58230, - 57833, - 57420, - 56991, - 56546, - 56083, - 55605, - 55110, - 54598, - 54071, - 53528, - 52968, - 52393, - 51802, - 51195, - 50573, - 49936, - 49285, - 48620, - 47942, - 47251, - 46548, - 45834, - 45110, - 44375, - 43632, - 42880, - 42121, - 41355, - 40584, - 39808, - 39027, - 38245, - 37460, - 36675, - 35891, - 35106, - 34323, - 33543, - 32768, - 31996, - 31229, - 30469, - 29716, - 28968, - 28231, - 27502, - 26780, - 26070, - 25371, - 24683, - 24004, - 23339, - 22682, - 22042, - 21412, - 20795, - 20191, - 19600, - 19023, - 18458, - 17908, - 17369, - 16846, - 16331, - 15834, - 15347, - 14878, - 14415, - 13969, - 13535, - 13111, - 12701, - 12302, - 11914, - 11539, - 11176, - 10822, - 10482, - 10147, - 9827, - 9517, - 9214, - 8922, - 8637, - 8364, - 8098, - 7840, - 7590, - 7354, - 7120, - 6896, - 6674, - 6467, - 6264, - 6065, - 5876, - 5691, - 5510, - 5339 -}; -#define MIN_TSX_TEMP (-40000) -#define MAX_TSX_TEMP (+85000) -/* Original formula is - * u = auxadc raw * 2^16 / (2^32 - 1) - * Because kernel is not able to deal with floating point - * we changed the formula to - * u = auxadc raw * 2^16 / 2^32 - * => u = auxadc raw / 2^16 - * => u * 2^16 = auxadc raw - */ - -static int tsx_u2t(int auxadc_raw) -{ - int i; - int ret = 0; - int u_upper, u_low, t_upper, t_low; - - if (auxadc_raw > u_table[0]) - return (int) MIN_TSX_TEMP; - if (auxadc_raw < u_table[125]) - return (int) MAX_TSX_TEMP; - - for (i = 0; i < 125; i++) { - if (auxadc_raw < u_table[i] && auxadc_raw >= u_table[i+1]) { - u_upper = u_table[i+1]; - u_low = u_table[i]; - - t_upper = (int) MIN_TSX_TEMP + (i+1) * 1000; - t_low = (int) MIN_TSX_TEMP + i * 1000; - - if ((u_upper - u_low) == 0) - /* This case should not happen */ - ret = t_low; - else - ret = t_low + ((t_upper - t_low) * - (auxadc_raw - u_low)) / - (u_upper - u_low); - - break; - } - } - - return ret; -} - -int mt6359tsx_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_tsx_temp)) { - ret = iio_read_channel_raw(chan_tsx_temp, &raw); - if (ret < 0) - pr_notice("pmic_tsx_temp read fail, ret=%d\n", ret); - } - - temp1 = tsx_u2t(raw); -#else - temp1 = 25000; -#endif - - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tstsx_temp1; - } else if ((tstsx_cnt != 0) - && (((pre_tstsx_temp1 - temp1) > 30000) - || ((temp1 - pre_tstsx_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tstsx_temp1; - } else { - /* update previous temp */ - pre_tstsx_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsx_temp1=%d\n", __func__, - pre_tstsx_temp1); - - if (tstsx_cnt == 0) - tstsx_cnt++; - } - - return temp1; -} - -int mt6359dcxo_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_dcxo_temp)) { - ret = iio_read_channel_raw(chan_dcxo_temp, &raw); - if (ret < 0) - pr_notice("pmic_dcxo_temp read fail, ret=%d\n", ret); - } - - /* Temperature (C) = ((auxadc raw/32768*1.8)-0.545)/(-0.0017)+120 */ - /* From dcxo desiger John Chiang */ - temp1 = (((18000000/32768)*raw) - 5450000) / -17 + 120000; - - if (temp1 < -40000) - temp1 = -40000; - else if (temp1 > 120000) - temp1 = 120000; -#else - temp1 = 25000; -#endif - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsdcxo_temp1; - } else if ((tsdcxo_cnt != 0) - && (((pre_tsdcxo_temp1 - temp1) > 30000) - || ((temp1 - pre_tsdcxo_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsdcxo_temp1; - } else { - /* update previous temp */ - pre_tsdcxo_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_dcxo_temp1=%d\n", __func__, - pre_tsdcxo_temp1); - - if (tsdcxo_cnt == 0) - tsdcxo_cnt++; - } - - return temp1; -} diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_tc.c deleted file mode 100644 index e11a59745a2c..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_tc.c +++ /dev/null @@ -1,1490 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include - -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; - * 0: turn off - */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include -#include "mtk_thermal_ipi.h" -/*============================================================= - * Local variable definition - *============================================================= - */ - -/* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - -/* chip dependent */ -/* TODO: I assume AHB bus frequecy is 78MHz. Please confirm it. - */ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {L_TS_MCU1, L_TS_MCU2, L_TS_MCU4, L_TS_ABB}, - .ts_number = 4, - .dominator_ts_idx = 2, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x0, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {L_TS_MCU5, L_TS_MCU6, L_TS_MCU7, L_TS_MCU0}, - .ts_number = 4, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x100, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [2] = { - .ts = {L_TS_MCU8, L_TS_MCU9}, - .ts_number = 2, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x200, - .tc_speed = { - 0x00C, - 0x001, - 0x008, - 0x0000030D - } /* 1ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu0; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -/* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ -static __s32 g_o_vtsmcu4; -static __s32 g_o_vtsmcu5; -static __s32 g_o_vtsmcu6; -static __s32 g_o_vtsmcu7; -static __s32 g_o_vtsmcu8; -static __s32 g_o_vtsmcu9; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[L_TS_MCU_NUM] = { 0 }; - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name); -static void set_tc_trigger_hw_protect - (int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -/*=============================================================*/ - -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum -thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("%s\n", __func__); - - /* chip dependent */ - - /* If there are two or more sensors in a bank, choose the sensor - * calibration value of the dominant sensor. You can observe it in the - * thermal document provided by Thermal DE. For example, Bank 1 is - * for SOC + GPU. Observe all scenarios related to GPU simulation test - * cases to decide which sensor is the highest temperature in all cases. - * Then, It is the dominant sensor.(Confirmed by Thermal DE Alfred Tsai) - */ - - /* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK1: - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - case THERMAL_BANK2: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK3: - x_roomt = g_x_roomt[L_TS_MCU2]; - break; - case THERMAL_BANK4: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - /* No bank 5 */ - case THERMAL_BANK6: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - case THERMAL_BANK7: - x_roomt = g_x_roomt[L_TS_MCU0]; - break; - default: /* choose the highest simulation hot-spot */ - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - } - - - /* - * The equations in this function are confirmed by Thermal DE Alfred - * Tsai. Don't have to change until using next generation thermal - * sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1534 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1534 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = - ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1534 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1534 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - tscpu_printk("[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - tscpu_printk("[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - tscpu_printk("[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - tscpu_printk("[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - tscpu_printk("[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - tscpu_printk("[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); -} - -void eDataCorrector(void) -{ - - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu0 < -8 || g_o_vtsmcu0 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu0 = 260; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - if (g_o_vtsmcu4 < -8 || g_o_vtsmcu4 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu4\n"); - g_o_vtsmcu4 = 260; - } - if (g_o_vtsmcu5 < -8 || g_o_vtsmcu5 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu5\n"); - g_o_vtsmcu5 = 260; - } - if (g_o_vtsmcu6 < -8 || g_o_vtsmcu6 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu6\n"); - g_o_vtsmcu6 = 260; - } - if (g_o_vtsmcu7 < -8 || g_o_vtsmcu7 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu7\n"); - g_o_vtsmcu7 = 260; - } - if (g_o_vtsmcu8 < -8 || g_o_vtsmcu8 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu8 = 260; - } - if (g_o_vtsmcu9 < -8 || g_o_vtsmcu9 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu9 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2, temp3, temp4; - - temp0 = get_devinfo_with_index(ADDRESS_INDEX_0); /* 0184 */ - temp1 = get_devinfo_with_index(ADDRESS_INDEX_1); /* 0180 */ - temp2 = get_devinfo_with_index(ADDRESS_INDEX_2); /* 0188 */ - temp3 = get_devinfo_with_index(ADDRESS_INDEX_3); /* 01AC */ - temp4 = get_devinfo_with_index(ADDRESS_INDEX_4); /* 01B0 */ - - pr_notice( - "[calibration] tmp0=0x%x, tmp1=0x%x, tmp2=0x%x\n", - temp0, temp1, temp2); - pr_notice( - "[calibration] tmp3=0x%x, tmp4=0x%x\n", - temp3, temp4); - - g_adc_ge_t = ((temp0 & _BITMASK_(31:22)) >> 22); - g_adc_oe_t = ((temp0 & _BITMASK_(21:12)) >> 12); - - - g_o_vtsmcu0 = ((temp1 & _BITMASK_(25:17)) >> 17); - g_o_vtsmcu1 = ((temp1 & _BITMASK_(16:8)) >> 8); - g_o_vtsmcu2 = (temp0 & _BITMASK_(8:0)); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = ((temp2 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu5 = ((temp2 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu6 = ((temp3 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu7 = ((temp3 & _BITMASK_(22:14)) >> 14); - g_o_vtsmcu8 = ((temp3 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu9 = ((temp4 & _BITMASK_(31:23)) >> 23); - g_o_vtsabb = ((temp2 & _BITMASK_(22:14)) >> 14); - - g_degc_cali = ((temp1 & _BITMASK_(6:1)) >> 1); - g_adc_cali_en_t = (temp1 & _BIT_(0)); - g_o_slope_sign = ((temp1 & _BIT_(7)) >> 7); - g_o_slope = ((temp1 & _BITMASK_(31:26)) >> 26); - - g_id = ((temp0 & _BIT_(9)) >> 9); - - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu0 = 260; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = 260; - g_o_vtsmcu5 = 260; - g_o_vtsmcu6 = 260; - g_o_vtsmcu7 = 260; - g_o_vtsmcu8 = 260; - g_o_vtsmcu9 = 260; - g_o_vtsabb = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[L_TS_MCU_NUM] = { 0 }; - int i = 0; -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - struct thermal_ipi_data thermal_data; -#endif - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[0] = (g_o_vtsmcu0 + 3350 - g_oe); - format[1] = (g_o_vtsmcu1 + 3350 - g_oe); - format[2] = (g_o_vtsmcu2 + 3350 - g_oe); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - format[3] = (g_o_vtsmcu4 + 3350 - g_oe); - format[4] = (g_o_vtsmcu5 + 3350 - g_oe); - format[5] = (g_o_vtsmcu6 + 3350 - g_oe); - format[6] = (g_o_vtsmcu7 + 3350 - g_oe); - format[7] = (g_o_vtsmcu8 + 3350 - g_oe); - format[8] = (g_o_vtsmcu9 + 3350 - g_oe); - format[9] = (g_o_vtsabb + 3350 - g_oe); - - for (i = 0; i < L_TS_MCU_NUM; i++) { - /* x_roomt * 10000 */ - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; - } - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, - g_x_roomt[i]); -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - thermal_data.u.data.arg[0] = g_degc_cali; - thermal_data.u.data.arg[1] = g_o_slope_sign; - thermal_data.u.data.arg[2] = g_o_slope; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_oe; - thermal_data.u.data.arg[1] = g_gain; - thermal_data.u.data.arg[2] = g_x_roomt[L_TS_MCU8]; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP2, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_x_roomt[L_TS_MCU9]; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP3, &thermal_data) != 0) - udelay(100); -#endif -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1534+O_slope*10)/10*(18/15)* - * (1/10000)+X_roomtabb]*Gain*4096 + OE - */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n", - * ts_name,xtoomt); - */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 + g_o_slope * 10)); - else /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 - g_o_slope * 10)); - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} -static void thermal_dump_debug_logs(int tc_num) -{ - int offset; - unsigned int auxadc_data11, ts_con0, ts_con1; - unsigned int tempmsr0, tempmsr1, tempmsr2, tempmsr3; - - offset = tscpu_g_tc[tc_num].tc_offset; - - auxadc_data11 = readl(AUXADC_DAT11_V); - ts_con0 = readl(TS_CON0_TM); - ts_con1 = readl(TS_CON1_TM); - tempmsr0 = readl((offset + TEMPMSR0)); - tempmsr1 = readl((offset + TEMPMSR1)); - tempmsr2 = readl((offset + TEMPMSR2)); - tempmsr3 = readl((offset + TEMPMSR3)); - - tscpu_printk("AUXADC_DAT11 = 0x%x, TS_CON0 = 0x%x, TS_CON1 = 0x%x\n", - auxadc_data11, ts_con0, ts_con1); - tscpu_printk("TEMPMSR0_%d = 0x%x, TEMPMSR1_%d = 0x%x\n", - tc_num, tempmsr0, tc_num, tempmsr1); - tscpu_printk("TEMPMSR2_%d = 0x%x, TEMPMSR3_%d = 0x%x\n", - tc_num, tempmsr2, tc_num, tempmsr3); -} -static void thermal_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); - - tscpu_printk( - "[Thermal IRQ] Auxadc thermal_tc %d, TEMPMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_COLD_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 2\n"); - - if (ret & THERMAL_AHB_TIMEOUT_INTERRUPT) - tscpu_dprintk( - "[Thermal IRQ]: AHB bus timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 1 int triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 2 int triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) { - tscpu_printk( - "[Thermal IRQ]: Thermal protection stage 3 int triggered\n"); - tscpu_printk("[Thermal IRQ]: Thermal HW reboot!!"); - thermal_dump_debug_logs(tc_num); - } -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - ret = ret & 0x7F; - - /* MSB LSB NAME - * 6 6 LVTSINT3 - * 5 5 LVTSINT2 - * 4 4 LVTSINT1 - * 3 3 LVTSINT0 - * 2 2 THERMINT2 - * 1 1 THERMINT1 - * 0 0 THERMINT0 - */ - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - unsigned int offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tempMonCtl1 = (tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0)); - - tempMonCtl2 = (((tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay & - _BITMASK_(9:0))); - - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.ahb_polling_interval; - - /* Calculating period unit in Module clock x 256, - * and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* bus clock 66M counting unit is 12 * 1/66M * 256 = - * 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - * filt interval is 1 * 46.545us = 46.545us, - * sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /* AHB polling is 781* 1/66M = 11.833us */ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - /* temperature sampling control, 4 out of 6 samples */ - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - /* temperature sampling control, 8 out of 10 samples */ - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - /* temperature sampling control, 16 out of 18 samples */ - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); -#else /* default 1 */ - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); -#endif - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); - - /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET3); - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); - - /* AHB value for auxadc enable */ - mt_reg_sync_writel(0x800, offset + TEMPADCEN); - - /* - * AHB address for auxadc enable (channel 0 immediate mode selected) - * this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void set_tc_trigger_hw_protect -(int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, d_index, config; - enum tsmcu_sensor_enum ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* temperature2=80000; test only */ - tscpu_dprintk("%s t1=%d t2=%d\n", __func__, temperature, - temperature2); - - if (tscpu_g_tc[tc_num].dominator_ts_idx < - tscpu_g_tc[tc_num].ts_number){ - d_index = tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - tscpu_printk("Error: Auxadc TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - tscpu_g_tc[tc_num].dominator_ts_idx, - tscpu_g_tc[tc_num].ts_number); - - tscpu_printk("Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - - ts_name = tscpu_g_tc[tc_num].ts[d_index]; - - /* temperature to trigger SPM state2 */ - if (tc_num == THERMAL_CONTROLLER2) - raw_high = temperature_to_raw_room(105000, ts_name); - else - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); - - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel(config, offset + TEMPPROTCTL); - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); - - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); -} - -static int read_tc_raw_and_temp( -u32 *tempmsr_name, enum tsmcu_sensor_enum ts_name) -{ - int temp = 0, raw = 0; -#if CONFIG_LVTS_ERROR_AEE_WARNING - int raw1; -#endif - - if (tempmsr_name == 0) - return 0; - -#if CONFIG_LVTS_ERROR_AEE_WARNING - raw = readl(tempmsr_name); - raw1 = ((raw & _BIT_(15)) >> 15); - raw = raw & 0xFFF; -#else - raw = readl(tempmsr_name) & 0xFFF; -#endif - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_mcu_temp_r[ts_name] = raw; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_mcu_temp_v[ts_name] = raw1; -#endif - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp_r[ts_name] = tscpu_ts_mcu_temp_r[ts_name]; -#endif - return temp * 100; -} - -void tscpu_thermal_read_tc_temp( -int tc_num, enum tsmcu_sensor_enum type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, - tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 1: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 2: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 3: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - default: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - } - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp[type] = tscpu_ts_mcu_temp[type]; -#endif -} - -void read_all_tc_tsmcu_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_read_tc_temp(i, tscpu_g_tc[i].ts[j], j); -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - - /* write temp to spare register */ - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); - - /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL1); - - /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); - - /* polling interval to check if temperature sense is ready */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); - - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - - /* temperature measurement sampling control */ - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) - * automatically by hw - */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); - - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); - - /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); - - /* enable auxadc mux & pnp write transaction */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - - - /* enable all interrupt except filter sense and - * immediate sense interrupt - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - /* enable all sensing point(sensing point 2 is unused)*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum tsmcu_sensor_enum type) -{ - switch (type) { - case L_TS_MCU0: - return TEMPADC_MCU0; - case L_TS_MCU1: - return TEMPADC_MCU1; - case L_TS_MCU2: - return TEMPADC_MCU2; - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - case L_TS_MCU4: - return TEMPADC_MCU4; - case L_TS_MCU5: - return TEMPADC_MCU5; - case L_TS_MCU6: - return TEMPADC_MCU6; - case L_TS_MCU7: - return TEMPADC_MCU7; - case L_TS_MCU8: - return TEMPADC_MCU8; - case L_TS_MCU9: - return TEMPADC_MCU9; - case L_TS_ABB: - return TEMPADC_ABB; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - - /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); - - /* disable auxadc channel 11 immediate mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - int wd_api_ret; - struct wd_api *wd_api; - - tscpu_dprintk("%s,temperature=%d,temperature2=%d\n", __func__, - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /* spend 860~1463 us */ - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - wd_api_ret = get_wd_api(&wd_api); - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_DIS, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_notice("resume time spent, sec : %lu , usec : %lu\n", - (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - set_tc_trigger_hw_protect(temperature, temperature2, i); - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_EN, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - - seq_printf(m, "[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - seq_printf(m, "[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - seq_printf(m, "[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - seq_printf(m, "[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - seq_printf(m, "[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - seq_printf(m, "[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - seq_printf(m, "[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_id = %d\n", g_id); - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - return 0; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -int check_auxadc_mcu_efuse(void) -{ - return g_adc_cali_en_t; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /* Need to confirm with DE */ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /* The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if (cg_freq & _BIT_(4)) - ahbClk = clockSource / 2; - else if (cg_freq & _BIT_(3)) - ahbClk = clockSource / 4; - else if (cg_freq & _BIT_(2)) - ahbClk = clockSource / 8; - else if (cg_freq & _BIT_(1)) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /* tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm); */ - /* tscpu_printk("AHB bus clock= %d MHz\n", ahbClk); */ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "L %d B %d", - get_immediate_cpuL_wrap(), get_immediate_cpuB_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_tc_wrapper.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_tc_wrapper.c deleted file mode 100644 index b484b961f8ba..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_tc_wrapper.c +++ /dev/null @@ -1,1018 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include "mtk_idle.h" - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#include -#include -#if DUMP_VCORE_VOLTAGE -#include -#endif -struct lvts_error_data { - int ts_temp[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_r[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_v[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ -#if DUMP_VCORE_VOLTAGE - int vcore_voltage[R_BUFFER_SIZE]; /* A ring buffer */ -#endif - int c_index; /* Current index points to the space to replace.*/ - int e_occurred; /* 1: An error occurred, 0: Nothing happened*/ - int f_count; /* Future count */ - enum thermal_sensor e_mcu; - enum thermal_sensor e_lvts; -}; -struct lvts_error_data g_lvts_e_data; -int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#endif - - -#if CFG_THERM_LVTS -int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; -#endif - -int tscpu_curr_cpu_temp; -int tscpu_curr_gpu_temp; - -static int tscpu_curr_max_ts_temp; - -int __attribute__ ((weak)) - mtk_idle_notifier_register(struct notifier_block *n) -{ - return 0; -} - -int get_immediate_none_wrap(void) -{ - return -127000; -} - -/* chip dependent */ -int get_immediate_cpuL_wrap(void) -{ - int curr_temp; - - curr_temp = MAX( - MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_0], - tscpu_ts_lvts_temp[L_TS_LVTS3_1]), - MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_2], - tscpu_ts_lvts_temp[L_TS_LVTS3_3]) - ); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS1_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS1_0], - tscpu_ts_lvts_temp[L_TS_LVTS1_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS2_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS2_0], - tscpu_ts_lvts_temp[L_TS_LVTS2_1]); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_vpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS4_0], - tscpu_ts_lvts_temp[L_TS_LVTS4_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS5_0], - tscpu_ts_lvts_temp[L_TS_LVTS5_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - -int get_immediate_infa_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_0]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_camsys_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_1]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_md_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(MAX(tscpu_ts_lvts_temp[L_TS_LVTS7_0], - tscpu_ts_lvts_temp[L_TS_LVTS7_1]), - tscpu_ts_lvts_temp[L_TS_LVTS7_2]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - - - -/* - * THERMAL_BANK0, //B CPU (LVTS1) - * THERMAL_BANK1, //B CPU (LVTS2) - * THERMAL_BANK2, //L CPU (LVTS3) - * THERMAL_BANK3, //VPU (LVTS4) - * THERMAL_BANK4, //GPU (LVTS5) - * THERMAL_BANK5, //IFRA (LVTS6) - */ - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpuB_LVTS1_wrap, - get_immediate_cpuB_LVTS2_wrap, - get_immediate_cpuL_wrap, - get_immediate_vpu_wrap, - get_immediate_gpu_wrap, - get_immediate_infa_wrap -}; - -int get_immediate_cpuB_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(get_immediate_cpuB_LVTS1_wrap(), - get_immediate_cpuB_LVTS2_wrap()); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - - - -int get_immediate_ts0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts4_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts5_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts6_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts7_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts8_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS7_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts9_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS7_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -#if CFG_THERM_LVTS -int get_immediate_tslvts1_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts1_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts5_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts5_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts6_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS6_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts6_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS6_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts7_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts7_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts7_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} -#endif - -int get_immediate_tsabb_wrap(void) -{ - - return 0; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - -#if CFG_THERM_LVTS - get_immediate_tslvts1_0_wrap, - get_immediate_tslvts1_1_wrap, - get_immediate_tslvts2_0_wrap, - get_immediate_tslvts2_1_wrap, - get_immediate_tslvts3_0_wrap, - get_immediate_tslvts3_1_wrap, - get_immediate_tslvts3_2_wrap, - get_immediate_tslvts3_3_wrap, - get_immediate_tslvts4_0_wrap, - get_immediate_tslvts4_1_wrap, - get_immediate_tslvts5_0_wrap, - get_immediate_tslvts5_1_wrap, - get_immediate_tslvts6_0_wrap, - get_immediate_tslvts6_1_wrap, - get_immediate_tslvts7_0_wrap, - get_immediate_tslvts7_1_wrap, - get_immediate_tslvts7_2_wrap -#endif -}; - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -#if CFG_THERM_LVTS -int tscpu_max_temperature(void) -{ - int i, j, max = 0; - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_dprintk("lvts_max_temperature %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - if (i == 0 && j == 0) { - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } else { - if (max < tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } - } - } -#endif /* CFG_THERM_LVTS */ -#else - tscpu_dprintk("tscpu_get_temp %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) { - if (i == 0 && j == 0) { - max = tscpu_ts_mcu_temp[tscpu_g_tc[i].ts[j]]; - } else { - if (max < tscpu_ts_mcu_temp[ - tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_mcu_temp[ - tscpu_g_tc[i].ts[j]]; - } - } - } -#endif /* CFG_LVTS_DOMINATOR */ - return max; -} -#endif - -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of thermal - * controller driver - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1,T2) LVTS1-0, LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_curr_cpu_temp = - MAX( - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS1_0], - tscpu_ts_lvts_temp[TS_LVTS1_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS2_0], - tscpu_ts_lvts_temp[TS_LVTS2_1]) - )), - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS3_0], - tscpu_ts_lvts_temp[TS_LVTS3_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS3_2], - tscpu_ts_lvts_temp[TS_LVTS3_3]) - )) - ); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_lvts_temp[TS_LVTS5_0], - tscpu_ts_lvts_temp[TS_LVTS5_1]); -#endif /* CFG_THERM_LVTS */ -#else - /* It is platform dependent which TS is better to present CPU/GPU - * temperature - */ - tscpu_curr_cpu_temp = MAX( - MAX(MAX(tscpu_ts_temp[TS_MCU5], tscpu_ts_temp[TS_MCU6]), - MAX(tscpu_ts_temp[TS_MCU7], tscpu_ts_temp[TS_MCU8])), - tscpu_ts_temp[TS_MCU9]); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_temp[TS_MCU1], - tscpu_ts_temp[TS_MCU2]); -#endif /* CFG_LVTS_DOMINATOR */ -#endif /* PRECISE_HYBRID_POWER_BUDGET */ - - /* though tscpu_max_temperature is common, put it in mtk_ts_cpu.c is - * weird. - */ - - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -char mcu_s_array[TS_ENUM_MAX][17] = { -#if CFG_THERM_LVTS - "TS_LVTS1_0", - "TS_LVTS1_1", - "TS_LVTS2_0", - "TS_LVTS2_1", - "TS_LVTS3_0", - "TS_LVTS3_1", - "TS_LVTS3_2", - "TS_LVTS3_3", - "TS_LVTS4_0", - "TS_LVTS4_1", - "TS_LVTS5_0", - "TS_LVTS5_1", - "TS_LVTS6_0", - "TS_LVTS6_1", - "TS_LVTS7_0", - "TS_LVTS7_1", - "TS_LVTS7_2" - #endif -}; - -static void dump_lvts_error_info(void) -{ - int i, j, index, e_index, offset; -#if DUMP_LVTS_REGISTER - int cnt, temp; -#endif - enum thermal_sensor mcu_index, lvts_index; - char buffer[512]; - - mcu_index = g_lvts_e_data.e_mcu; - lvts_index = g_lvts_e_data.e_lvts; - index = g_lvts_e_data.c_index; - e_index = (index + HISTORY_SAMPLES + 1) % R_BUFFER_SIZE; - - tscpu_printk("[LVTS_ERROR][DUMP] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - g_lvts_e_data.ts_temp[mcu_index][e_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[lvts_index][e_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index], - LVTS_ERROR_THRESHOLD); - - for (i = TS_MCU1; i <= TS_LVTS4_1; i++) { - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[i]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) - % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[i][index]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - } - - offset = sprintf(buffer, "[LVTS_ERROR][%s_R][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[mcu_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[mcu_index][index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - dump_efuse_data(); -#if DUMP_LVTS_REGISTER - read_controller_reg_when_error(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -#endif -#if DUMP_VCORE_VOLTAGE - offset = sprintf(buffer, "[LVTS_ERROR][Vcore_V][DUMP] ", - mcu_s_array[lvts_index]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.vcore_voltage[index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -#endif -#if DUMP_LVTS_REGISTER - lvts_reset_device_and_stop_clk(); -#endif -#ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, __func__, - "LVTS_ERROR: %s, %s diff: %d\n", mcu_s_array[mcu_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index]); -#endif - - g_lvts_e_data.e_occurred = 0; - g_lvts_e_data.f_count = -1; -#if DUMP_LVTS_REGISTER - clear_lvts_register_value_array(); - - lvts_device_identification(); - lvts_Device_Enable_Init_all_Devices(); - lvts_device_read_count_RC_N(); - lvts_efuse_setting(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - Enable_LVTS_CTRL_for_thermal_Data_Fetch(); - lvts_tscpu_thermal_initial_all_tc(); -#endif -} - -static void check_lvts_error(enum thermal_sensor mcu_index, - enum thermal_sensor lvts_index) -{ - int temp; - - temp = tscpu_ts_temp[mcu_index] - tscpu_ts_temp[lvts_index]; - - if (temp < 0) - temp = temp * -1; - - /*Skip if LVTS thermal controllers doens't ready */ - if (temp > 100000) - return; - - if (temp > LVTS_ERROR_THRESHOLD) { - tscpu_printk("[LVTS_ERROR] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - tscpu_ts_temp[mcu_index], - mcu_s_array[lvts_index], - tscpu_ts_temp[lvts_index], - tscpu_ts_temp[mcu_index] - - tscpu_ts_temp[lvts_index], - LVTS_ERROR_THRESHOLD); - g_lvts_e_data.e_occurred = 1; - g_lvts_e_data.e_mcu = mcu_index; - g_lvts_e_data.e_lvts = lvts_index; - g_lvts_e_data.f_count = -1; - } -} -void dump_lvts_error_data_info(void) -{ - char buffer[512]; - int offset, j; - - tscpu_printk("[LVTS_ERROR] c_index %d, e_occurred %d, f_count %d\n", - g_lvts_e_data.c_index, g_lvts_e_data.e_occurred, - g_lvts_e_data.f_count); - tscpu_printk("[LVTS_ERROR] e_mcu %d, e_lvts %d\n", g_lvts_e_data.e_mcu, - g_lvts_e_data.e_lvts); - - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_raw][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -} -#endif - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - seq_printf(m, "curr_temp = %d\n", tscpu_get_curr_max_ts_temp()); - -#if !defined(CFG_THERM_NO_AUXADC) - tscpu_dump_cali_info(m, v); -#endif - -#if CFG_THERM_LVTS - seq_puts(m, "-----------------\n"); - lvts_tscpu_dump_cali_info(m, v); -#endif - return 0; -} - -static int thermal_idle_notify_call(struct notifier_block *nfb, - unsigned long id, - void *arg) -{ - switch (id) { - case NOTIFY_DPIDLE_ENTER: - break; - case NOTIFY_SOIDLE_ENTER: - break; - case NOTIFY_DPIDLE_LEAVE: - break; - case NOTIFY_SOIDLE_LEAVE: - break; - case NOTIFY_SOIDLE3_ENTER: -#if LVTS_VALID_DATA_TIME_PROFILING - SODI3_count++; - if (SODI3_count != 1 && isTempValid == 0) - noValid_count++; - - if (isTempValid == 1 || SODI3_count == 1) - start_timestamp = thermal_get_current_time_us(); - - isTempValid = 0; -#endif - break; - case NOTIFY_SOIDLE3_LEAVE: -#if CFG_THERM_LVTS - lvts_sodi3_release_thermal_controller(); -#endif - break; - default: - /* do nothing */ - break; - } - return NOTIFY_OK; -} - -static struct notifier_block thermal_idle_nfb = { - .notifier_call = thermal_idle_notify_call, -}; - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - } - - /*tscpu_printk("[THERM_CTRL] thermal_base= 0x%px\n",thermal_base);*/ - - /*get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", - thermal_irq_number); - if (!thermal_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_irq_number); - return 0; - } - - /*get thermal irq num */ - thermal_mcu_irq_number = irq_of_parse_and_map(node, 1); - tscpu_printk("[THERM_CTRL] mcu_irq_num = %d\n", - thermal_mcu_irq_number); - if (!thermal_mcu_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_mcu_irq_number); - return 0; - } - - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - /*tscpu_printk("[THERM_CTRL] phy_base=0x%x\n", thermal_phy_base);*/ - - - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6768-auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,infracfg_ao"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - - if (infracfg_ao_base) - mtk_idle_notifier_register(&thermal_idle_nfb); - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,apmixed"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base=\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); - if (!node) { - pr_notice("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_notice("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); - - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - clk_disable_unprepare(therm_main); - return ret; -} - diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_thermal_ipi.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_thermal_ipi.c deleted file mode 100644 index b5723b90e7e2..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_thermal_ipi.c +++ /dev/null @@ -1,403 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include "mtk_thermal_ipi.h" -#include "mach/mtk_thermal.h" -#include "tscpu_settings.h" -#include "linux/mutex.h" -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -static DEFINE_MUTEX(thermo_sspm_mutex); -static int is_thermal_ipi_registered; -static int ack_data; - -static int register_thermal_ipi(void) -{ - int ret; - - ret = mtk_ipi_register(&sspm_ipidev, IPIS_C_THERMAL, NULL, NULL, - (void *)&ack_data); - if (ret != 0) { - tscpu_printk("%s error ret:%d\n", __func__, ret); - return -1; - } - - is_thermal_ipi_registered = 1; - - return 0; -} - -unsigned int thermal_to_sspm( - unsigned int cmd, struct thermal_ipi_data *thermal_data) -{ - int ackData = -1; - int ret; - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_INIT_GRP1: - case THERMAL_IPI_INIT_GRP2: - case THERMAL_IPI_INIT_GRP3: - case THERMAL_IPI_INIT_GRP4: - case THERMAL_IPI_INIT_GRP5: - case THERMAL_IPI_INIT_GRP6: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send init cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_LVTS_INIT_GRP1: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) lvts efuse to SSPM (%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_GET_TEMP: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send get_temp cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_SET_BIG_FREQ_THRESHOLD: - case THERMAL_IPI_GET_BIG_FREQ_THRESHOLD: - thermal_data->cmd = cmd; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("mtk_ipi_send_compl error ret:%d - %d\n", - cmd, ret); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_SET_DIS_THERMAL_THROTTLE: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) disable SSPM thermal throttle(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - case THERMAL_IPI_SUSPEND_RESUME_NOTIFY: - thermal_data->cmd = cmd; - //tscpu_printk("cmd(%d) kernel suspend/resume(%d)\n", - // cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - default: - tscpu_printk("cmd(%d) wrong!!\n", cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ackData; /** It's weird here. What should be returned? */ -} - -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -int atm_to_sspm(unsigned int cmd, int data_len, -struct thermal_ipi_data *thermal_data, int *ackData) -{ - int ret = -1; - - if (data_len < 1 || data_len > 3) { - *ackData = -1; - return ret; - } - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_SET_ATM_CFG_GRP1: - case THERMAL_IPI_SET_ATM_CFG_GRP2: - case THERMAL_IPI_SET_ATM_CFG_GRP3: - case THERMAL_IPI_SET_ATM_CFG_GRP4: - case THERMAL_IPI_SET_ATM_CFG_GRP5: - case THERMAL_IPI_SET_ATM_CFG_GRP6: - case THERMAL_IPI_SET_ATM_CFG_GRP7: - case THERMAL_IPI_SET_ATM_CFG_GRP8: - case THERMAL_IPI_SET_ATM_TTJ: - case THERMAL_IPI_SET_ATM_EN: - case THERMAL_IPI_GET_ATM_CPU_LIMIT: - case THERMAL_IPI_GET_ATM_GPU_LIMIT: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, (data_len+1), 2000); - if ((ret != 0) || (ack_data < 0)) - tscpu_printk("%s cmd %d ret %d ack %d\n", - __func__, cmd, ret, ack_data); - - *ackData = ack_data; - - break; - - default: - tscpu_printk("%s cmd %d err!\n", __func__, cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ret; -} - -static int get_sspm_tz_temp_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_sspm(THERMAL_IPI_GET_TEMP, &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show current temperature in SSPM UART log\n"); - - return 0; -} - -static int get_sspm_tz_temp_open(struct inode *inode, struct file *file) -{ - return single_open(file, get_sspm_tz_temp_read, NULL); -} - -static const struct file_operations get_sspm_tz_temp_fops = { - .owner = THIS_MODULE, - .open = get_sspm_tz_temp_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static ssize_t set_sspm_big_limit_threshold_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int arrayIndex, bigCoreTj, bigCoreExitTj, bigCoreFreqUpperBound; - struct thermal_ipi_data thermal_data; - - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - - if (sscanf(desc, "%d %d %d", &arrayIndex, &bigCoreTj, - &bigCoreFreqUpperBound) == 3) { - if ((arrayIndex >= BIG_CORE_THRESHOLD_ARRAY_SIZE) || - (arrayIndex < 0)) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreTj; - thermal_data.u.data.arg[2] = bigCoreFreqUpperBound; - - while (thermal_to_sspm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } else if (sscanf(desc, "%d %d", &arrayIndex, &bigCoreExitTj) == 2) { - if (arrayIndex != -1) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreExitTj; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_sspm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } - - tscpu_printk("%s bad argument: %s\n", __func__, desc); - return -EINVAL; - -} - -static int set_sspm_big_limit_threshold_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - seq_puts(m, "Use this command to change big core freq limit threshold\n"); - seq_puts(m, " echo arrayIndex BigCoreTj bigCoreFreqUpperBound >\n"); - seq_puts(m, " /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_printf(m, " arrayIndex is not larger than or equal to %d\n", - BIG_CORE_THRESHOLD_ARRAY_SIZE); - seq_puts(m, " BigCoreTj is in m'C\n"); - seq_puts(m, " BigCoreFreqUpperBound is in MHz\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo 0 85000 2050 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, "Use this command to change exit point\n"); - seq_puts(m, " echo -1 BigCoreExitTj > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, " BigCoreExitTj is in m'C\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo -1 75000 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_sspm(THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show big core frequency thresholds in SSPM UART log\n"); - - return 0; -} - -static int set_sspm_big_limit_threshold_open(struct inode *inode, - struct file *file) -{ - return single_open(file, set_sspm_big_limit_threshold_read, NULL); -} - -static const struct file_operations set_sspm_big_limit_threshold_fops = { - .owner = THIS_MODULE, - .open = set_sspm_big_limit_threshold_open, - .read = seq_read, - .llseek = seq_lseek, - .write = set_sspm_big_limit_threshold_write, - .release = single_release, -}; -static int __init thermal_ipi_init(void) -{ - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *thermal_ipi_dir = NULL; - - tscpu_printk("[%s]\n", __func__); - - - thermal_ipi_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!thermal_ipi_dir) { - tscpu_printk( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("get_sspm_tz_temp", 444, thermal_ipi_dir, - &get_sspm_tz_temp_fops); - if (entry) - proc_set_user(entry, uid, gid); - entry = - proc_create("set_sspm_big_limit_threshold", 664, - thermal_ipi_dir, &set_sspm_big_limit_threshold_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - return 0; -} - -static void __exit thermal_ipi_exit(void) -{ - tscpu_printk("[%s]\n", __func__); -} - -module_init(thermal_ipi_init); -module_exit(thermal_ipi_exit); -#endif diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ti_6315.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_ti_6315.c deleted file mode 100644 index 457bcd7bb272..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ti_6315.c +++ /dev/null @@ -1,328 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - -/* #define INTR_UT */ -/* #define OT_THROTTLE_CPU */ -/* #define OT_THROTTLE_GPU */ - -#define DEFAULT_6315OT_CPU_LIMIT (800) -#define DEFAULT_6315OT_GPU_LIMIT (1000) - -static struct apthermolmt_user ap_6315ot; -static char *ap_6315ot_log = "ap_6315ot"; -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static unsigned int cpu_limit = DEFAULT_6315OT_CPU_LIMIT; -static unsigned int gpu_limit = DEFAULT_6315OT_GPU_LIMIT; - -static int virq_tempL_6; -static int virq_tempH_6; -static int virq_tempL_7; -static int virq_tempH_7; -#ifdef INTR_UT -static int virq_rcs0_6; -static int virq_rcs0_7; -#endif - -static int tpmic6315_intr_probe(struct platform_device *dev); - -static const struct of_device_id tpmic_intr_of_match[] = { - { .compatible = "mediatek,mt6315_therm_intr", }, - { /* sentinel */ } -}; - -MODULE_DEVICE_TABLE(of, tpmic_intr_of_match); - -static struct platform_driver tpmic_intr_pdrv = { - .probe = tpmic6315_intr_probe, - .remove = NULL, - .driver = { - .name = "tpmic6315_intr", - .owner = THIS_MODULE, - .of_match_table = tpmic_intr_of_match, - }, -}; - -static irqreturn_t mt6315_6_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_6); - enable_irq(virq_tempH_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s release cpu limit\n", __func__); - apthermolmt_set_cpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_6_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_6); - enable_irq(virq_tempL_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_6_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static irqreturn_t mt6315_7_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_7); - enable_irq(virq_tempH_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s release gpu limit\n", __func__); - apthermolmt_set_gpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_7_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_7); - enable_irq(virq_tempL_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_7_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static int tpmic6315_intr_probe(struct platform_device *pdev) -{ - struct device_node *node; - int ret = 0; - - node = of_find_matching_node(NULL, tpmic_intr_of_match); - if (!node) - pr_info("@%s: find tpmic_intr node failed\n", __func__); - - virq_tempL_6 = platform_get_irq(pdev, 0); - virq_tempH_6 = platform_get_irq(pdev, 1); - virq_tempL_7 = platform_get_irq(pdev, 3); - virq_tempH_7 = platform_get_irq(pdev, 4); -#ifdef INTR_UT - virq_rcs0_6 = platform_get_irq(pdev, 2); - virq_rcs0_7 = platform_get_irq(pdev, 5); -#endif - -#ifdef INTR_UT - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || virq_rcs0_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0 || virq_rcs0_7 <= 0) { -#else - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0) { -#endif - pr_info("%s: get irq error\n", __func__); - return 0; - } - - pr_info("%s: 6_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 0) - , platform_get_irq_byname(pdev, "6315_6_temp_l")); - pr_info("%s: 6_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 1) - , platform_get_irq_byname(pdev, "6315_6_temp_h")); - pr_info("%s: 7_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 3) - , platform_get_irq_byname(pdev, "6315_7_temp_l")); - pr_info("%s: 7_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 4) - , platform_get_irq_byname(pdev, "6315_7_temp_h")); - -#ifdef INTR_UT - pr_info("%s: 6_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 2) - , platform_get_irq_byname(pdev, "6315_6_rcs0")); - pr_info("%s: 7_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 5) - , platform_get_irq_byname(pdev, "6315_7_rcs0")); -#endif - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_l"), - NULL, mt6315_6_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_h"), - NULL, mt6315_6_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_l"), - NULL, mt6315_7_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_h"), - NULL, mt6315_7_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - -#ifdef INTR_UT - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_rcs0"), - NULL, mt6315_6_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S6_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_rcs0"), - NULL, mt6315_7_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S7_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); -#endif - - disable_irq_nosync(virq_tempL_6); - disable_irq_nosync(virq_tempL_7); - - return 0; -} - -static int cl_6315ot_read(struct seq_file *m, void *v) -{ - - seq_printf(m, "[%s] C/G limit = %d/%d\n", - __func__, cpu_limit, gpu_limit); - - return 0; -} -static ssize_t cl_6315ot_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int c_limit, g_limit; - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - if (sscanf(desc, "%d %d", &c_limit, &g_limit) == 2) { - pr_info("[%s] set C/G limit = %d/%d\n", - __func__, c_limit, g_limit); - cpu_limit = (c_limit != 0) ? c_limit : 0x7FFFFFFF; - gpu_limit = (g_limit != 0) ? g_limit : 0x7FFFFFFF; - - return count; - } - - pr_info("%s bad argument\n", __func__); - return -EINVAL; -} - -static int cl_6315ot_open(struct inode *inode, struct file *file) -{ - return single_open(file, cl_6315ot_read, NULL); -} - -static const struct file_operations cl_6315ot_fops = { - .owner = THIS_MODULE, - .open = cl_6315ot_open, - .read = seq_read, - .llseek = seq_lseek, - .write = cl_6315ot_write, - .release = single_release, -}; - -static int __init mtk_ti_6315_init(void) -{ - int ret = 0; - - /* register platform driver */ - ret = platform_driver_register(&tpmic_intr_pdrv); - if (ret) { - pr_info("fail to register %s driver ~~~\n", __func__); - goto end; - } - - /* create a proc file */ - { - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *dir_entry = NULL; - - dir_entry = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!dir_entry) { - pr_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = proc_create("cl6315ot_limit", 0664, - dir_entry, - &cl_6315ot_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - } - - /* register user to thermal */ - apthermolmt_register_user(&ap_6315ot, ap_6315ot_log); - -end: - return 0; -} - -static void __exit mtk_ti_6315_exit(void) -{ - apthermolmt_unregister_user(&ap_6315ot); - platform_driver_unregister(&tpmic_intr_pdrv); - pr_info("%s\n", __func__); -} - -late_initcall(mtk_ti_6315_init); -module_exit(mtk_ti_6315_exit); diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359dcxo.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359dcxo.c deleted file mode 100644 index 6889c7414a50..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359dcxo.c +++ /dev/null @@ -1,597 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359dcxo_cur_temp; -/* - *static long int mt6359dcxo_start_temp; - *static long int mt6359dcxo_end_temp; - */ -/*=============================================================*/ - -static int mt6359dcxo_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359dcxo_get_hw_temp(); - mt6359dcxo_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359dcxo_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359dcxo_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359dcxo_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359dcxo_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359dcxo_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359dcxo_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359dcxo_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359dcxo_dev_ops = { - .bind = mt6359dcxo_bind, - .unbind = mt6359dcxo_unbind, - .get_temp = mt6359dcxo_get_temp, - .get_mode = mt6359dcxo_get_mode, - .set_mode = mt6359dcxo_set_mode, - .get_trip_type = mt6359dcxo_get_trip_type, - .get_trip_temp = mt6359dcxo_get_trip_temp, - .get_crit_temp = mt6359dcxo_get_crit_temp, -}; - -static int mt6359dcxo_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359dcxo_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359dcxo_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359dcxo OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359dcxo_cooling_sysrst_ops = { - .get_max_state = mt6359dcxo_sysrst_get_max_state, - .get_cur_state = mt6359dcxo_sysrst_get_cur_state, - .set_cur_state = mt6359dcxo_sysrst_set_cur_state, -}; - -static int mt6359dcxo_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359dcxo_register_thermal(void); -static void mt6359dcxo_unregister_thermal(void); - -static ssize_t mt6359dcxo_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359dcxo_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359dcxo_data *ptr_mt6359dcxo_data; - - ptr_mt6359dcxo_data = - kmalloc(sizeof(*ptr_mt6359dcxo_data), GFP_KERNEL); - - if (ptr_mt6359dcxo_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359dcxo_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359dcxo_data->desc) - 1); - - if (copy_from_user(ptr_mt6359dcxo_data->desc, buffer, len)) { - kfree(ptr_mt6359dcxo_data); - return 0; - } - - ptr_mt6359dcxo_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359dcxo_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359dcxo_data->trip[0], - &ptr_mt6359dcxo_data->t_type[0], - ptr_mt6359dcxo_data->bind0, - &ptr_mt6359dcxo_data->trip[1], - &ptr_mt6359dcxo_data->t_type[1], - ptr_mt6359dcxo_data->bind1, - &ptr_mt6359dcxo_data->trip[2], - &ptr_mt6359dcxo_data->t_type[2], - ptr_mt6359dcxo_data->bind2, - &ptr_mt6359dcxo_data->trip[3], - &ptr_mt6359dcxo_data->t_type[3], - ptr_mt6359dcxo_data->bind3, - &ptr_mt6359dcxo_data->trip[4], - &ptr_mt6359dcxo_data->t_type[4], - ptr_mt6359dcxo_data->bind4, - &ptr_mt6359dcxo_data->trip[5], - &ptr_mt6359dcxo_data->t_type[5], - ptr_mt6359dcxo_data->bind5, - &ptr_mt6359dcxo_data->trip[6], - &ptr_mt6359dcxo_data->t_type[6], - ptr_mt6359dcxo_data->bind6, - &ptr_mt6359dcxo_data->trip[7], - &ptr_mt6359dcxo_data->t_type[7], - ptr_mt6359dcxo_data->bind7, - &ptr_mt6359dcxo_data->trip[8], - &ptr_mt6359dcxo_data->t_type[8], - ptr_mt6359dcxo_data->bind8, - &ptr_mt6359dcxo_data->trip[9], - &ptr_mt6359dcxo_data->t_type[9], - ptr_mt6359dcxo_data->bind9, - &ptr_mt6359dcxo_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359dcxo_unregister_thermal\n", __func__); - mt6359dcxo_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359dcxo_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359dcxo_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359dcxo_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359dcxo_data->bind0[i]; - g_bind1[i] = ptr_mt6359dcxo_data->bind1[i]; - g_bind2[i] = ptr_mt6359dcxo_data->bind2[i]; - g_bind3[i] = ptr_mt6359dcxo_data->bind3[i]; - g_bind4[i] = ptr_mt6359dcxo_data->bind4[i]; - g_bind5[i] = ptr_mt6359dcxo_data->bind5[i]; - g_bind6[i] = ptr_mt6359dcxo_data->bind6[i]; - g_bind7[i] = ptr_mt6359dcxo_data->bind7[i]; - g_bind8[i] = ptr_mt6359dcxo_data->bind8[i]; - g_bind9[i] = ptr_mt6359dcxo_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359dcxo_data->trip[i]; - - interval = ptr_mt6359dcxo_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359dcxo_register_thermal\n", __func__); - - mt6359dcxo_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359dcxo_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359dcxo_write", "Bad argument"); - #endif - kfree(ptr_mt6359dcxo_data); - return -EINVAL; -} - -static void mt6359dcxo_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359dcxo_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359dcxo_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359dcxo-sysrst", NULL, - &mt6359dcxo_cooling_sysrst_ops); - return 0; -} - -static int mt6359dcxo_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359dcxo", num_trip, NULL, - &mt6359dcxo_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359dcxo_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359dcxo_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359dcxo_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359dcxo_read, NULL); -} - -static const struct file_operations mt6359dcxo_fops = { - .owner = THIS_MODULE, - .open = mt6359dcxo_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359dcxo_write, - .release = single_release, -}; - -static int __init mt6359dcxo_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359dcxo_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359dcxo_register_cooler(); - if (err) - return err; - - mt6359dcxo_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359dcxo_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359dcxo", 664, mt6359dcxo_dir, - &mt6359dcxo_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359dcxo", mt6359dcxo_start_thermal_timer, - mt6359dcxo_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359dcxo_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359dcxo_unregister_thermal(); - mt6359dcxo_unregister_cooler(); - mtkTTimer_unregister("mt6359dcxo"); -} -module_init(mt6359dcxo_init); -module_exit(mt6359dcxo_exit); diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359tsx.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359tsx.c deleted file mode 100644 index d49f021990e7..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359tsx.c +++ /dev/null @@ -1,597 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359tsx_cur_temp; -/* - *static long int mt6359tsx_start_temp; - *static long int mt6359tsx_end_temp; - */ -/*=============================================================*/ - -static int mt6359tsx_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359tsx_get_hw_temp(); - mt6359tsx_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359tsx_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359tsx_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359tsx_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359tsx_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359tsx_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359tsx_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359tsx_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359tsx_dev_ops = { - .bind = mt6359tsx_bind, - .unbind = mt6359tsx_unbind, - .get_temp = mt6359tsx_get_temp, - .get_mode = mt6359tsx_get_mode, - .set_mode = mt6359tsx_set_mode, - .get_trip_type = mt6359tsx_get_trip_type, - .get_trip_temp = mt6359tsx_get_trip_temp, - .get_crit_temp = mt6359tsx_get_crit_temp, -}; - -static int mt6359tsx_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359tsx_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359tsx_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359tsx OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359tsx_cooling_sysrst_ops = { - .get_max_state = mt6359tsx_sysrst_get_max_state, - .get_cur_state = mt6359tsx_sysrst_get_cur_state, - .set_cur_state = mt6359tsx_sysrst_set_cur_state, -}; - -static int mt6359tsx_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359tsx_register_thermal(void); -static void mt6359tsx_unregister_thermal(void); - -static ssize_t mt6359tsx_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359tsx_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359tsx_data *ptr_mt6359tsx_data; - - ptr_mt6359tsx_data = - kmalloc(sizeof(*ptr_mt6359tsx_data), GFP_KERNEL); - - if (ptr_mt6359tsx_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359tsx_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359tsx_data->desc) - 1); - - if (copy_from_user(ptr_mt6359tsx_data->desc, buffer, len)) { - kfree(ptr_mt6359tsx_data); - return 0; - } - - ptr_mt6359tsx_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359tsx_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359tsx_data->trip[0], - &ptr_mt6359tsx_data->t_type[0], - ptr_mt6359tsx_data->bind0, - &ptr_mt6359tsx_data->trip[1], - &ptr_mt6359tsx_data->t_type[1], - ptr_mt6359tsx_data->bind1, - &ptr_mt6359tsx_data->trip[2], - &ptr_mt6359tsx_data->t_type[2], - ptr_mt6359tsx_data->bind2, - &ptr_mt6359tsx_data->trip[3], - &ptr_mt6359tsx_data->t_type[3], - ptr_mt6359tsx_data->bind3, - &ptr_mt6359tsx_data->trip[4], - &ptr_mt6359tsx_data->t_type[4], - ptr_mt6359tsx_data->bind4, - &ptr_mt6359tsx_data->trip[5], - &ptr_mt6359tsx_data->t_type[5], - ptr_mt6359tsx_data->bind5, - &ptr_mt6359tsx_data->trip[6], - &ptr_mt6359tsx_data->t_type[6], - ptr_mt6359tsx_data->bind6, - &ptr_mt6359tsx_data->trip[7], - &ptr_mt6359tsx_data->t_type[7], - ptr_mt6359tsx_data->bind7, - &ptr_mt6359tsx_data->trip[8], - &ptr_mt6359tsx_data->t_type[8], - ptr_mt6359tsx_data->bind8, - &ptr_mt6359tsx_data->trip[9], - &ptr_mt6359tsx_data->t_type[9], - ptr_mt6359tsx_data->bind9, - &ptr_mt6359tsx_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359tsx_unregister_thermal\n", __func__); - mt6359tsx_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359tsx_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359tsx_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359tsx_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359tsx_data->bind0[i]; - g_bind1[i] = ptr_mt6359tsx_data->bind1[i]; - g_bind2[i] = ptr_mt6359tsx_data->bind2[i]; - g_bind3[i] = ptr_mt6359tsx_data->bind3[i]; - g_bind4[i] = ptr_mt6359tsx_data->bind4[i]; - g_bind5[i] = ptr_mt6359tsx_data->bind5[i]; - g_bind6[i] = ptr_mt6359tsx_data->bind6[i]; - g_bind7[i] = ptr_mt6359tsx_data->bind7[i]; - g_bind8[i] = ptr_mt6359tsx_data->bind8[i]; - g_bind9[i] = ptr_mt6359tsx_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359tsx_data->trip[i]; - - interval = ptr_mt6359tsx_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359tsx_register_thermal\n", __func__); - - mt6359tsx_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359tsx_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359tsx_write", "Bad argument"); - #endif - kfree(ptr_mt6359tsx_data); - return -EINVAL; -} - -static void mt6359tsx_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359tsx_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359tsx_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359tsx-sysrst", NULL, - &mt6359tsx_cooling_sysrst_ops); - return 0; -} - -static int mt6359tsx_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359tsx", num_trip, NULL, - &mt6359tsx_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359tsx_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359tsx_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359tsx_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359tsx_read, NULL); -} - -static const struct file_operations mt6359tsx_fops = { - .owner = THIS_MODULE, - .open = mt6359tsx_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359tsx_write, - .release = single_release, -}; - -static int __init mt6359tsx_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359tsx_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359tsx_register_cooler(); - if (err) - return err; - - mt6359tsx_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359tsx_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359tsx", 664, mt6359tsx_dir, - &mt6359tsx_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359tsx", mt6359tsx_start_thermal_timer, - mt6359tsx_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359tsx_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359tsx_unregister_thermal(); - mt6359tsx_unregister_cooler(); - mtkTTimer_unregister("mt6359tsx"); -} -module_init(mt6359tsx_init); -module_exit(mt6359tsx_exit); diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vcore.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vcore.c deleted file mode 100644 index 86b27551b6e2..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vcore.c +++ /dev/null @@ -1,595 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vcore_cur_temp; -/* - *static long int mt6359vcore_start_temp; - *static long int mt6359vcore_end_temp; - */ -/*=============================================================*/ - -static int mt6359vcore_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vcore_get_hw_temp(); - mt6359vcore_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vcore_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vcore_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vcore_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vcore_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vcore_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vcore_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vcore_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vcore_dev_ops = { - .bind = mt6359vcore_bind, - .unbind = mt6359vcore_unbind, - .get_temp = mt6359vcore_get_temp, - .get_mode = mt6359vcore_get_mode, - .set_mode = mt6359vcore_set_mode, - .get_trip_type = mt6359vcore_get_trip_type, - .get_trip_temp = mt6359vcore_get_trip_temp, - .get_crit_temp = mt6359vcore_get_crit_temp, -}; - -static int mt6359vcore_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vcore_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vcore_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vcore OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vcore_cooling_sysrst_ops = { - .get_max_state = mt6359vcore_sysrst_get_max_state, - .get_cur_state = mt6359vcore_sysrst_get_cur_state, - .set_cur_state = mt6359vcore_sysrst_set_cur_state, -}; - -static int mt6359vcore_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vcore_register_thermal(void); -static void mt6359vcore_unregister_thermal(void); - -static ssize_t mt6359vcore_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vcore_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vcore_data *ptr_mt6359vcore_data; - - ptr_mt6359vcore_data = - kmalloc(sizeof(*ptr_mt6359vcore_data), GFP_KERNEL); - - if (ptr_mt6359vcore_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vcore_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vcore_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vcore_data->desc, buffer, len)) { - kfree(ptr_mt6359vcore_data); - return 0; - } - - ptr_mt6359vcore_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vcore_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vcore_data->trip[0], - &ptr_mt6359vcore_data->t_type[0], - ptr_mt6359vcore_data->bind0, - &ptr_mt6359vcore_data->trip[1], - &ptr_mt6359vcore_data->t_type[1], - ptr_mt6359vcore_data->bind1, - &ptr_mt6359vcore_data->trip[2], - &ptr_mt6359vcore_data->t_type[2], - ptr_mt6359vcore_data->bind2, - &ptr_mt6359vcore_data->trip[3], - &ptr_mt6359vcore_data->t_type[3], - ptr_mt6359vcore_data->bind3, - &ptr_mt6359vcore_data->trip[4], - &ptr_mt6359vcore_data->t_type[4], - ptr_mt6359vcore_data->bind4, - &ptr_mt6359vcore_data->trip[5], - &ptr_mt6359vcore_data->t_type[5], - ptr_mt6359vcore_data->bind5, - &ptr_mt6359vcore_data->trip[6], - &ptr_mt6359vcore_data->t_type[6], - ptr_mt6359vcore_data->bind6, - &ptr_mt6359vcore_data->trip[7], - &ptr_mt6359vcore_data->t_type[7], - ptr_mt6359vcore_data->bind7, - &ptr_mt6359vcore_data->trip[8], - &ptr_mt6359vcore_data->t_type[8], - ptr_mt6359vcore_data->bind8, - &ptr_mt6359vcore_data->trip[9], - &ptr_mt6359vcore_data->t_type[9], - ptr_mt6359vcore_data->bind9, - &ptr_mt6359vcore_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vcore_unregister_thermal\n", __func__); - mt6359vcore_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vcore_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - kfree(ptr_mt6359vcore_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vcore_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vcore_data->bind0[i]; - g_bind1[i] = ptr_mt6359vcore_data->bind1[i]; - g_bind2[i] = ptr_mt6359vcore_data->bind2[i]; - g_bind3[i] = ptr_mt6359vcore_data->bind3[i]; - g_bind4[i] = ptr_mt6359vcore_data->bind4[i]; - g_bind5[i] = ptr_mt6359vcore_data->bind5[i]; - g_bind6[i] = ptr_mt6359vcore_data->bind6[i]; - g_bind7[i] = ptr_mt6359vcore_data->bind7[i]; - g_bind8[i] = ptr_mt6359vcore_data->bind8[i]; - g_bind9[i] = ptr_mt6359vcore_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vcore_data->trip[i]; - - interval = ptr_mt6359vcore_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vcore_register_thermal\n", __func__); - - mt6359vcore_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vcore_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vcore_write", "Bad argument"); - #endif - kfree(ptr_mt6359vcore_data); - return -EINVAL; -} - -static void mt6359vcore_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vcore_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vcore_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vcore-sysrst", NULL, - &mt6359vcore_cooling_sysrst_ops); - return 0; -} - -static int mt6359vcore_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vcore", num_trip, NULL, - &mt6359vcore_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vcore_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vcore_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vcore_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vcore_read, NULL); -} - -static const struct file_operations mt6359vcore_fops = { - .owner = THIS_MODULE, - .open = mt6359vcore_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vcore_write, - .release = single_release, -}; - -static int __init mt6359vcore_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vcore_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vcore_register_cooler(); - if (err) - return err; - - mt6359vcore_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vcore_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359vcore", 664, mt6359vcore_dir, - &mt6359vcore_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vcore", mt6359vcore_start_thermal_timer, - mt6359vcore_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vcore_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vcore_unregister_thermal(); - mt6359vcore_unregister_cooler(); - mtkTTimer_unregister("mt6359vcore"); -} -module_init(mt6359vcore_init); -module_exit(mt6359vcore_exit); diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vgpu.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vgpu.c deleted file mode 100644 index 06ed0cb85949..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vgpu.c +++ /dev/null @@ -1,606 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vgpu_cur_temp; -/* - *static long int mt6359vgpu_start_temp; - *static long int mt6359vgpu_end_temp; - */ -/*=============================================================*/ - -static int mt6359vgpu_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vgpu_get_hw_temp(); - mt6359vgpu_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vgpu_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vgpu_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vgpu_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vgpu_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vgpu_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vgpu_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vgpu_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vgpu_dev_ops = { - .bind = mt6359vgpu_bind, - .unbind = mt6359vgpu_unbind, - .get_temp = mt6359vgpu_get_temp, - .get_mode = mt6359vgpu_get_mode, - .set_mode = mt6359vgpu_set_mode, - .get_trip_type = mt6359vgpu_get_trip_type, - .get_trip_temp = mt6359vgpu_get_trip_temp, - .get_crit_temp = mt6359vgpu_get_crit_temp, -}; - -static int mt6359vgpu_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vgpu_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vgpu_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vgpu OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vgpu_cooling_sysrst_ops = { - .get_max_state = mt6359vgpu_sysrst_get_max_state, - .get_cur_state = mt6359vgpu_sysrst_get_cur_state, - .set_cur_state = mt6359vgpu_sysrst_set_cur_state, -}; - -static int mt6359vgpu_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vgpu_register_thermal(void); -static void mt6359vgpu_unregister_thermal(void); - -static ssize_t mt6359vgpu_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vgpu_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vgpu_data *ptr_mt6359vgpu_data; - - ptr_mt6359vgpu_data = - kmalloc(sizeof(*ptr_mt6359vgpu_data), GFP_KERNEL); - - if (ptr_mt6359vgpu_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vgpu_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vgpu_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vgpu_data->desc, buffer, len)) { - kfree(ptr_mt6359vgpu_data); - return 0; - } - - ptr_mt6359vgpu_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vgpu_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vgpu_data->trip[0], - &ptr_mt6359vgpu_data->t_type[0], - ptr_mt6359vgpu_data->bind0, - &ptr_mt6359vgpu_data->trip[1], - &ptr_mt6359vgpu_data->t_type[1], - ptr_mt6359vgpu_data->bind1, - &ptr_mt6359vgpu_data->trip[2], - &ptr_mt6359vgpu_data->t_type[2], - ptr_mt6359vgpu_data->bind2, - &ptr_mt6359vgpu_data->trip[3], - &ptr_mt6359vgpu_data->t_type[3], - ptr_mt6359vgpu_data->bind3, - &ptr_mt6359vgpu_data->trip[4], - &ptr_mt6359vgpu_data->t_type[4], - ptr_mt6359vgpu_data->bind4, - &ptr_mt6359vgpu_data->trip[5], - &ptr_mt6359vgpu_data->t_type[5], - ptr_mt6359vgpu_data->bind5, - &ptr_mt6359vgpu_data->trip[6], - &ptr_mt6359vgpu_data->t_type[6], - ptr_mt6359vgpu_data->bind6, - &ptr_mt6359vgpu_data->trip[7], - &ptr_mt6359vgpu_data->t_type[7], - ptr_mt6359vgpu_data->bind7, - &ptr_mt6359vgpu_data->trip[8], - &ptr_mt6359vgpu_data->t_type[8], - ptr_mt6359vgpu_data->bind8, - &ptr_mt6359vgpu_data->trip[9], - &ptr_mt6359vgpu_data->t_type[9], - ptr_mt6359vgpu_data->bind9, - &ptr_mt6359vgpu_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vgpu_unregister_thermal\n", __func__); - - mt6359vgpu_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vgpu_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vgpu_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vgpu_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vgpu_data->bind0[i]; - g_bind1[i] = ptr_mt6359vgpu_data->bind1[i]; - g_bind2[i] = ptr_mt6359vgpu_data->bind2[i]; - g_bind3[i] = ptr_mt6359vgpu_data->bind3[i]; - g_bind4[i] = ptr_mt6359vgpu_data->bind4[i]; - g_bind5[i] = ptr_mt6359vgpu_data->bind5[i]; - g_bind6[i] = ptr_mt6359vgpu_data->bind6[i]; - g_bind7[i] = ptr_mt6359vgpu_data->bind7[i]; - g_bind8[i] = ptr_mt6359vgpu_data->bind8[i]; - g_bind9[i] = ptr_mt6359vgpu_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vgpu_data->trip[i]; - - interval = ptr_mt6359vgpu_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vgpu_register_thermal\n", __func__); - - mt6359vgpu_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vgpu_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vgpu_write", "Bad argument"); - #endif - kfree(ptr_mt6359vgpu_data); - return -EINVAL; -} - -static void mt6359vgpu_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vgpu_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vgpu_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vgpu-sysrst", NULL, - &mt6359vgpu_cooling_sysrst_ops); - return 0; -} - -static int mt6359vgpu_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vgpu", num_trip, NULL, - &mt6359vgpu_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vgpu_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vgpu_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vgpu_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vgpu_read, NULL); -} - -static const struct file_operations mt6359vgpu_fops = { - .owner = THIS_MODULE, - .open = mt6359vgpu_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vgpu_write, - .release = single_release, -}; - -static int __init mt6359vgpu_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vgpu_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vgpu_register_cooler(); - if (err) - return err; - - mt6359vgpu_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vgpu_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - - } else { - entry = - proc_create("tz6359vgpu", 664, mt6359vgpu_dir, - &mt6359vgpu_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vgpu", mt6359vgpu_start_thermal_timer, - mt6359vgpu_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vgpu_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vgpu_unregister_thermal(); - mt6359vgpu_unregister_cooler(); - mtkTTimer_unregister("mt6359vgpu"); -} -module_init(mt6359vgpu_init); -module_exit(mt6359vgpu_exit); diff --git a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vproc.c b/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vproc.c deleted file mode 100644 index e9be6cf823a3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6885/src/mtk_ts_6359vproc.c +++ /dev/null @@ -1,603 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2019 MediaTek Inc. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long int mt6359vproc_cur_temp; -/* - *static long int mt6359vproc_start_temp; - *static long int mt6359vproc_end_temp; - */ -/*=============================================================*/ - -static int mt6359vproc_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vproc_get_hw_temp(); - mt6359vproc_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vproc_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vproc_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vproc_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vproc_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vproc_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vproc_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vproc_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vproc_dev_ops = { - .bind = mt6359vproc_bind, - .unbind = mt6359vproc_unbind, - .get_temp = mt6359vproc_get_temp, - .get_mode = mt6359vproc_get_mode, - .set_mode = mt6359vproc_set_mode, - .get_trip_type = mt6359vproc_get_trip_type, - .get_trip_temp = mt6359vproc_get_trip_temp, - .get_crit_temp = mt6359vproc_get_crit_temp, -}; - -static int mt6359vproc_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vproc_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vproc_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vproc OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - -#if 0 /* temp marked off to check temperature correctness. */ - *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ -#endif - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vproc_cooling_sysrst_ops = { - .get_max_state = mt6359vproc_sysrst_get_max_state, - .get_cur_state = mt6359vproc_sysrst_get_cur_state, - .set_cur_state = mt6359vproc_sysrst_set_cur_state, -}; - -static int mt6359vproc_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vproc_register_thermal(void); -static void mt6359vproc_unregister_thermal(void); - -static ssize_t mt6359vproc_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vproc_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vproc_data *ptr_mt6359vproc_data; - - ptr_mt6359vproc_data = - kmalloc(sizeof(*ptr_mt6359vproc_data), GFP_KERNEL); - - if (ptr_mt6359vproc_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vproc_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vproc_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vproc_data->desc, buffer, len)) { - kfree(ptr_mt6359vproc_data); - return 0; - } - - ptr_mt6359vproc_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vproc_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vproc_data->trip[0], - &ptr_mt6359vproc_data->t_type[0], - ptr_mt6359vproc_data->bind0, - &ptr_mt6359vproc_data->trip[1], - &ptr_mt6359vproc_data->t_type[1], - ptr_mt6359vproc_data->bind1, - &ptr_mt6359vproc_data->trip[2], - &ptr_mt6359vproc_data->t_type[2], - ptr_mt6359vproc_data->bind2, - &ptr_mt6359vproc_data->trip[3], - &ptr_mt6359vproc_data->t_type[3], - ptr_mt6359vproc_data->bind3, - &ptr_mt6359vproc_data->trip[4], - &ptr_mt6359vproc_data->t_type[4], - ptr_mt6359vproc_data->bind4, - &ptr_mt6359vproc_data->trip[5], - &ptr_mt6359vproc_data->t_type[5], - ptr_mt6359vproc_data->bind5, - &ptr_mt6359vproc_data->trip[6], - &ptr_mt6359vproc_data->t_type[6], - ptr_mt6359vproc_data->bind6, - &ptr_mt6359vproc_data->trip[7], - &ptr_mt6359vproc_data->t_type[7], - ptr_mt6359vproc_data->bind7, - &ptr_mt6359vproc_data->trip[8], - &ptr_mt6359vproc_data->t_type[8], - ptr_mt6359vproc_data->bind8, - &ptr_mt6359vproc_data->trip[9], - &ptr_mt6359vproc_data->t_type[9], - ptr_mt6359vproc_data->bind9, - &ptr_mt6359vproc_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk("[%s] mt6359vproc_unregister_thermal\n", - __func__); - - mt6359vproc_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vproc_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vproc_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vproc_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vproc_data->bind0[i]; - g_bind1[i] = ptr_mt6359vproc_data->bind1[i]; - g_bind2[i] = ptr_mt6359vproc_data->bind2[i]; - g_bind3[i] = ptr_mt6359vproc_data->bind3[i]; - g_bind4[i] = ptr_mt6359vproc_data->bind4[i]; - g_bind5[i] = ptr_mt6359vproc_data->bind5[i]; - g_bind6[i] = ptr_mt6359vproc_data->bind6[i]; - g_bind7[i] = ptr_mt6359vproc_data->bind7[i]; - g_bind8[i] = ptr_mt6359vproc_data->bind8[i]; - g_bind9[i] = ptr_mt6359vproc_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vproc_data->trip[i]; - - interval = ptr_mt6359vproc_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk("[%s] mt6359vproc_register_thermal\n", - __func__); - - mt6359vproc_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vproc_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vproc_write", "Bad argument"); - #endif - kfree(ptr_mt6359vproc_data); - return -EINVAL; -} - -static void mt6359vproc_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vproc_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vproc_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vproc-sysrst", NULL, - &mt6359vproc_cooling_sysrst_ops); - return 0; -} - -static int mt6359vproc_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vproc", num_trip, NULL, - &mt6359vproc_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vproc_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vproc_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vproc_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vproc_read, NULL); -} - -static const struct file_operations mt6359vproc_fops = { - .owner = THIS_MODULE, - .open = mt6359vproc_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vproc_write, - .release = single_release, -}; - -static int __init mt6359vproc_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vproc_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vproc_register_cooler(); - if (err) - return err; - - mt6359vproc_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vproc_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6359vproc", 664, mt6359vproc_dir, - &mt6359vproc_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vproc", mt6359vproc_start_thermal_timer, - mt6359vproc_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vproc_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vproc_unregister_thermal(); - mt6359vproc_unregister_cooler(); - mtkTTimer_unregister("mt6359vproc"); -} -module_init(mt6359vproc_init); -module_exit(mt6359vproc_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/Makefile b/drivers/misc/mediatek/thermal/mt6893/Makefile deleted file mode 100644 index 2a09370d533f..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -obj-y += src/ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/clatm_initcfg.h b/drivers/misc/mediatek/thermal/mt6893/inc/clatm_initcfg.h deleted file mode 100644 index 1655b87c61ad..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/clatm_initcfg.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __CLATM_INITCFG_H__ -#define __CLATM_INITCFG_H__ - -#define CLATM_SET_INIT_CFG (1) - -#define CLATM_INIT_CFG_0_TARGET_TJ (85000) -#define CLATM_INIT_CFG_0_EXIT_POINT (10000) -#define CLATM_INIT_CFG_0_FIRST_STEP (5000) -#define CLATM_INIT_CFG_0_THETA_RISE (2) -#define CLATM_INIT_CFG_0_THETA_FALL (8) -#define CLATM_INIT_CFG_0_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_0_MIN_CPU_PWR (500) -#define CLATM_INIT_CFG_0_MAX_CPU_PWR (6000) -#define CLATM_INIT_CFG_0_MIN_GPU_PWR (500) -#define CLATM_INIT_CFG_0_MAX_GPU_PWR (1000) - -#define CLATM_INIT_CFG_1_TARGET_TJ (75000) -#define CLATM_INIT_CFG_1_EXIT_POINT (10000) -#define CLATM_INIT_CFG_1_FIRST_STEP (3000) -#define CLATM_INIT_CFG_1_THETA_RISE (2) -#define CLATM_INIT_CFG_1_THETA_FALL (8) -#define CLATM_INIT_CFG_1_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_1_MIN_CPU_PWR (500) -#define CLATM_INIT_CFG_1_MAX_CPU_PWR (5000) -#define CLATM_INIT_CFG_1_MIN_GPU_PWR (500) -#define CLATM_INIT_CFG_1_MAX_GPU_PWR (1000) - -#define CLATM_INIT_CFG_2_TARGET_TJ (65000) -#define CLATM_INIT_CFG_2_EXIT_POINT (10000) -#define CLATM_INIT_CFG_2_FIRST_STEP (3000) -#define CLATM_INIT_CFG_2_THETA_RISE (2) -#define CLATM_INIT_CFG_2_THETA_FALL (8) -#define CLATM_INIT_CFG_2_MIN_BUDGET_CHG (1) -#define CLATM_INIT_CFG_2_MIN_CPU_PWR (500) -#define CLATM_INIT_CFG_2_MAX_CPU_PWR (4000) -#define CLATM_INIT_CFG_2_MIN_GPU_PWR (500) -#define CLATM_INIT_CFG_2_MAX_GPU_PWR (1000) - -#define CLATM_INIT_CFG_ACTIVE_ATM_COOLER (0) - -#define CLATM_INIT_CFG_CATM (0) - -#define CLATM_INIT_CFG_PHPB_CPU_TT (10) -#define CLATM_INIT_CFG_PHPB_CPU_TP (50) - -#define CLATM_INIT_CFG_PHPB_GPU_TT (80) -#define CLATM_INIT_CFG_PHPB_GPU_TP (80) - -#define CLATM_INIT_HRTIMER_POLLING_DELAY (50) - -#define CLATM_USE_MIN_CPU_OPP (1) - -#define CLATM_CONFIGURABLE_TIMER - - - -#define POLLING_TRIP_TEMP0 55000 -#define POLLING_TRIP_TEMP1 45000 -#define POLLING_TRIP_TEMP2 40000 - -#define POLLING_FACTOR0 10 -#define POLLING_FACTOR1 2 -#define POLLING_FACTOR2 4 - - - - -#endif /* __CLATM_INITCFG_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/mach/mtk_thermal.h b/drivers/misc/mediatek/thermal/mt6893/inc/mach/mtk_thermal.h deleted file mode 100644 index 1264126cec24..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/mach/mtk_thermal.h +++ /dev/null @@ -1,252 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#ifndef __MT6893_THERMAL_H__ -#define __MT6893_THERMAL_H__ - -#include -#include -#include -#include - -#include -#include - -#include "mt-plat/sync_write.h" - -#include "mtk_thermal_typedefs.h" - -/* TODO: remove this! */ -/*#define GPUFREQ_NOT_READY*/ - -#ifdef GPUFREQ_NOT_READY -struct mt_gpufreq_power_table_info { - unsigned int gpufreq_khz; - unsigned int gpufreq_volt; - unsigned int gpufreq_power; -}; -#else -#include "mtk_gpufreq.h" -#endif - -/*============================================================= - * LVTS SW Configs - *============================================================= - */ -#define CFG_THERM_SUSPEND_RESUME_NOIRQ -#define CFG_THERM_LVTS (1) -#define CFG_THERM_NO_AUXADC (1) - -#if CFG_THERM_LVTS -#define CFG_LVTS_DOMINATOR (1) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (1) /* 1, 2, 4, 8, 16 */ -#define LVTS_DEVICE_AUTO_RCK (0) -#define CFG_LVTS_MCU_INTERRUPT_HANDLER (1) -/*Use bootup "count RC", no need to get "count RC" again after resume*/ -#define CFG_THERM_USE_BOOTUP_COUNT_RC -#else -#define CFG_LVTS_DOMINATOR (0) -#define LVTS_THERMAL_CONTROLLER_HW_FILTER (0) -#define LVTS_DEVICE_AUTO_RCK (1) -#endif - -/* - *There is no idle code in kernel since mt6885(big sw). - *Thus, kernel only can use "cpu pm notifier" to do idle scenario things. - * - *Release LVTS in thermal kernel driver - *1. SPM will pause LVTS thermal controllers before closing 26M - *2. After leaving SODI3, SPM will release LVTS thermal controllers - * if controllers were paused properly. - *3. After leaving SODI3, Thermal driver will release LVTS thermal - * controllers if SPM didn't release controller successfully - */ -#define LVTS_CPU_PM_NTFY_CALLBACK - -#if defined(LVTS_CPU_PM_NTFY_CALLBACK) -#define CFG_THERM_SODI3_RELEASE -//#define LVTS_CPU_PM_NTFY_PROFILE -#endif - -/* public thermal sensor enum */ - -enum thermal_sensor { -#if CFG_THERM_LVTS - TS_LVTS1_0 = 0, - TS_LVTS1_1, - TS_LVTS2_0, - TS_LVTS2_1, - TS_LVTS3_0, - TS_LVTS3_1, - TS_LVTS3_2, - TS_LVTS3_3, - TS_LVTS4_0, - TS_LVTS4_1, - TS_LVTS5_0, - TS_LVTS5_1, - TS_LVTS6_0, - TS_LVTS6_1, - TS_LVTS7_0, - TS_LVTS7_1, - TS_LVTS7_2, -#endif - TS_ENUM_MAX -}; - -enum thermal_bank_name { - THERMAL_BANK0 = 0, - THERMAL_BANK1, - THERMAL_BANK2, - THERMAL_BANK3, - THERMAL_BANK4, - THERMAL_BANK5, - THERMAL_BANK_NUM -}; - -struct TS_PTPOD { - unsigned int ts_MTS; - unsigned int ts_BTS; -}; - -extern int mtktscpu_limited_dmips; -extern int tscpu_get_temperature_range(void); -/* Valid if it returns 1, invalid if it returns 0. */ -extern int tscpu_is_temp_valid(void); - -extern void get_thermal_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); - -#if CFG_THERM_LVTS -extern void get_lvts_slope_intercept( - struct TS_PTPOD *ts_info, enum thermal_bank_name ts_bank); -#endif - -extern void set_taklking_flag(bool flag); - -extern int tscpu_get_cpu_temp(void); - -extern int tscpu_get_temp_by_bank(enum thermal_bank_name ts_bank); - -#define THERMAL_WRAP_WR32(val, addr) \ - mt_reg_sync_writel((val), ((void *)addr)) - -extern int get_immediate_cpuL_wrap(void); -extern int get_immediate_cpuB_wrap(void); -extern int get_immediate_mcucci_wrap(void); -extern int get_immediate_gpu_wrap(void); -extern int get_immediate_vpu_wrap(void); -extern int get_immediate_top_wrap(void); -extern int get_immediate_md_wrap(void); - -/* Added for DLPT/EARA */ -extern int tscpu_get_min_cpu_pwr(void); -extern int tscpu_get_min_gpu_pwr(void); -extern int tscpu_get_min_vpu_pwr(void); -extern int tscpu_get_min_mdla_pwr(void); - -extern void lvts_ipi_send_efuse_data(void); -extern void lvts_ipi_send_sspm_thermal_thtottle(void); -extern void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend); - -/* Five thermal sensors. */ -enum mtk_thermal_sensor_cpu_id_met { -#if CFG_THERM_LVTS - MTK_THERMAL_SENSOR_LVTS1_0, - MTK_THERMAL_SENSOR_LVTS1_1, - MTK_THERMAL_SENSOR_LVTS2_0, - MTK_THERMAL_SENSOR_LVTS2_1, - MTK_THERMAL_SENSOR_LVTS3_0, - MTK_THERMAL_SENSOR_LVTS3_1, - MTK_THERMAL_SENSOR_LVTS3_2, - MTK_THERMAL_SENSOR_LVTS3_3, - MTK_THERMAL_SENSOR_LVTS4_0, - MTK_THERMAL_SENSOR_LVTS4_1, - MTK_THERMAL_SENSOR_LVTS5_0, - MTK_THERMAL_SENSOR_LVTS5_1, - MTK_THERMAL_SENSOR_LVTS6_0, - MTK_THERMAL_SENSOR_LVTS6_1, - MTK_THERMAL_SENSOR_LVTS7_0, - MTK_THERMAL_SENSOR_LVTS7_1, - MTK_THERMAL_SENSOR_LVTS7_2, -#endif - ATM_CPU_LIMIT, - ATM_GPU_LIMIT, - - MTK_THERMAL_SENSOR_CPU_COUNT -}; - -extern int tscpu_get_cpu_temp_met(enum mtk_thermal_sensor_cpu_id_met id); - -typedef void (*met_thermalsampler_funcMET)(void); - -extern void mt_thermalsampler_registerCB(met_thermalsampler_funcMET pCB); - -extern void mtkTTimer_cancel_timer(void); - -extern void mtkTTimer_start_timer(void); - -extern int mtkts_bts_get_hw_temp(void); - -extern int get_immediate_ts0_wrap(void); -extern int get_immediate_ts1_wrap(void); -extern int get_immediate_ts2_wrap(void); -extern int get_immediate_ts3_wrap(void); -extern int get_immediate_ts4_wrap(void); -extern int get_immediate_ts5_wrap(void); -extern int get_immediate_ts6_wrap(void); -extern int get_immediate_ts7_wrap(void); -extern int get_immediate_ts8_wrap(void); -extern int get_immediate_ts9_wrap(void); - -#if CFG_THERM_LVTS -extern int get_immediate_tslvts1_0_wrap(void); -extern int get_immediate_tslvts1_1_wrap(void); -extern int get_immediate_tslvts2_0_wrap(void); -extern int get_immediate_tslvts2_1_wrap(void); -extern int get_immediate_tslvts3_0_wrap(void); -extern int get_immediate_tslvts3_1_wrap(void); -extern int get_immediate_tslvts3_2_wrap(void); -extern int get_immediate_tslvts3_3_wrap(void); -extern int get_immediate_tslvts4_0_wrap(void); -extern int get_immediate_tslvts4_1_wrap(void); -extern int get_immediate_tslvts5_0_wrap(void); -extern int get_immediate_tslvts5_1_wrap(void); -extern int get_immediate_tslvts6_0_wrap(void); -extern int get_immediate_tslvts6_1_wrap(void); -extern int get_immediate_tslvts7_0_wrap(void); -extern int get_immediate_tslvts7_1_wrap(void); -extern int get_immediate_tslvts7_2_wrap(void); -#endif - -extern int get_immediate_tsabb_wrap(void); - -extern int (*get_immediate_tsX[TS_ENUM_MAX])(void); - -extern int is_cpu_power_unlimit(void); /* in mtk_ts_cpu.c */ - -extern int is_cpu_power_min(void); /* in mtk_ts_cpu.c */ - -extern int get_cpu_target_tj(void); - -extern int get_cpu_target_offset(void); - -extern int mtk_gpufreq_register( - struct mt_gpufreq_power_table_info *freqs, int num); - - -extern int get_target_tj(void); - -extern int mtk_thermal_get_tpcb_target(void); - -extern void thermal_set_big_core_speed( -unsigned int tempMonCtl1, unsigned int tempMonCtl2, unsigned int tempAhbPoll); - -/* - * return value(1): cooler of abcct/abcct_lcmoff is deactive, - * and no thermal current limit. - */ -extern int mtk_cooler_is_abcct_unlimit(void); - -extern int tscpu_kernel_status(void); -#endif /* __MT6893_THERMAL_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_cl_amddulthro.h b/drivers/misc/mediatek/thermal/mt6893/inc/mtk_cl_amddulthro.h deleted file mode 100644 index f867a7f292bd..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_cl_amddulthro.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __MT_CL_AMDDULTHRO_H__ -#define __MT_CL_AMDDULTHRO_H__ - -extern int amddulthro_backoff(int level); - -#endif /* __MT_CL_AMDDULTHRO_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_cooler_setting.h b/drivers/misc/mediatek/thermal/mt6893/inc/mtk_cooler_setting.h deleted file mode 100644 index 8a8e5b176cb6..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_cooler_setting.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef _MTK_COOLER_SETTING_H -#define _MTK_COOLER_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on MD Thermal Warning Notification; 0: turn off */ -#define FEATURE_THERMAL_DIAG (1) - -/* mtk_cooler_mutt_gen97.c */ -/* 1: turn on adaptive MD throttle cooler; 0: turn off */ -#define FEATURE_ADAPTIVE_MUTT (1) - -/* mtk_ta.c */ -/* 1: turn on SPA; 0: turn off */ -#define FEATURE_SPA (0) - - -/*APU(mdla/vpu) throttle*/ -#define THERMAL_APU_UNLIMIT - -#if defined(THERMAL_APU_UNLIMIT) -extern unsigned int cl_get_apu_status(void); -extern void cl_set_apu_status(int vv); -#endif -#endif /* _MTK_COOLER_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_thermal_ipi.h b/drivers/misc/mediatek/thermal/mt6893/inc/mtk_thermal_ipi.h deleted file mode 100644 index 5a4d310e3405..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_thermal_ipi.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __MTK_THERMAL_IPI_H__ -#define __MTK_THERMAL_IPI_H__ - -#ifdef CONFIG_MTK_TINYSYS_SSPM_SUPPORT -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (1) -#define THERMAL_SSPM_THERMAL_THROTTLE_SWITCH - -/*Only Big SW need to enable this definition - *Big SW suspend/resume flow: - * suspend: kernel suspend => SSPM suspend - * resume: SSPM resume => kernel resume - */ -#define THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY -#else -#define THERMAL_ENABLE_TINYSYS_SSPM (0) -#define THERMAL_ENABLE_ONLY_TZ_SSPM (0) -#endif - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#include - -#define THERMAL_SLOT_NUM (4) -#define BIG_CORE_THRESHOLD_ARRAY_SIZE (3) -/* IPI Msg type */ -enum { - THERMAL_IPI_INIT_GRP1, - THERMAL_IPI_INIT_GRP2, - THERMAL_IPI_INIT_GRP3, - THERMAL_IPI_INIT_GRP4, - THERMAL_IPI_INIT_GRP5, - THERMAL_IPI_INIT_GRP6, - THERMAL_IPI_LVTS_INIT_GRP1, - THERMAL_IPI_GET_TEMP, - THERMAL_IPI_SET_ATM_CFG_GRP1, - THERMAL_IPI_SET_ATM_CFG_GRP2, - THERMAL_IPI_SET_ATM_CFG_GRP3, - THERMAL_IPI_SET_ATM_CFG_GRP4, - THERMAL_IPI_SET_ATM_CFG_GRP5, - THERMAL_IPI_SET_ATM_CFG_GRP6, - THERMAL_IPI_SET_ATM_CFG_GRP7, - THERMAL_IPI_SET_ATM_CFG_GRP8, - THERMAL_IPI_SET_ATM_TTJ, - THERMAL_IPI_SET_ATM_EN, - THERMAL_IPI_GET_ATM_CPU_LIMIT, - THERMAL_IPI_GET_ATM_GPU_LIMIT, - THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - NR_THERMAL_IPI -}; - -/* IPI Msg data structure */ -struct thermal_ipi_data { - unsigned int cmd; - union { - struct { - int arg[THERMAL_SLOT_NUM - 1]; - } data; - } u; -}; -extern unsigned int thermal_to_sspm(unsigned int cmd, - struct thermal_ipi_data *thermal_data); -extern int atm_to_sspm(unsigned int cmd, int data_len, - struct thermal_ipi_data *thermal_data, int *ackData); -#endif /* THERMAL_ENABLE_TINYSYS_SSPM */ -#endif diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_ts_setting.h b/drivers/misc/mediatek/thermal/mt6893/inc/mtk_ts_setting.h deleted file mode 100644 index 850a88c40187..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/mtk_ts_setting.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#ifndef _MTK_TS_SETTING_H -#define _MTK_TS_SETTING_H - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/* mtk_ts_pa.c */ -/* 1: turn on MD UL throughput update; 0: turn off */ -#define Feature_Thro_update (0) -#endif /* _MTK_TS_SETTING_H */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tmp_6311buck.h b/drivers/misc/mediatek/thermal/mt6893/inc/tmp_6311buck.h deleted file mode 100644 index 870c53559fae..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tmp_6311buck.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TMP_6311BUCK_H__ -#define __TMP_6311BUCK_H__ - -extern int is_ext_buck_exist(void); - -#endif /* __TMP_6311BUCK_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tmp_battery.h b/drivers/misc/mediatek/thermal/mt6893/inc/tmp_battery.h deleted file mode 100644 index ffe8d49ec680..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tmp_battery.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TMP_BATTERY_H__ -#define __TMP_BATTERY_H__ - -#include -/* Extern two API functions from battery driver - * to limit max charging current. - */ -/** - * return value means charging current in mA - * -1 means error - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int get_bat_charging_current_level(void); - -/** - * current_limit means limit of charging current in mA - * -1 means no limit - * Implementation in mt_battery.c and mt_battery_fan5405.c - */ -extern int set_bat_charging_current_limit(int current_limit); -extern enum charger_type mt_get_charger_type(void); - -extern int read_tbat_value(void); - -#endif /* __TMP_BATTERY_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tmp_bts.h b/drivers/misc/mediatek/thermal/mt6893/inc/tmp_bts.h deleted file mode 100644 index a51adef6d92b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tmp_bts.h +++ /dev/null @@ -1,57 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TMP_BTS_H__ -#define __TMP_BTS_H__ - -#define APPLY_PRECISE_NTC_TABLE -#define APPLY_AUXADC_CALI_DATA -#define APPLY_PRECISE_BTS_TEMP - -#define AUX_IN0_NTC (0) -#define AUX_IN1_NTC (1) -#define AUX_IN2_NTC (2) - -#define BTS_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ - -#define BTS_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTS_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTS_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTS_RAP_ADC_CHANNEL AUX_IN0_NTC /* default is 0 */ - -#define BTSMDPA_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ - -#define BTSMDPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - * default value -40 deg - */ - -#define BTSMDPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ - -#define BTSMDPA_RAP_NTC_TABLE 7 /* default is NCP15WF104F03RC(100K) */ - -#define BTSMDPA_RAP_ADC_CHANNEL AUX_IN1_NTC /* default is 1 */ - - -#define BTSNRPA_RAP_PULL_UP_R 100000 /* 100K, pull up resister */ -#define BTSNRPA_TAP_OVER_CRITICAL_LOW 4397119 /* base on 100K NTC temp - *default value -40 deg - */ - -#define BTSNRPA_RAP_PULL_UP_VOLTAGE 1800 /* 1.8V ,pull up voltage */ -#define BTSNRPA_RAP_NTC_TABLE 7 - -#define BTSNRPA_RAP_ADC_CHANNEL AUX_IN2_NTC - - - -extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata); -extern int IMM_IsAdcInitReady(void); - -#endif /* __TMP_BTS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_lvts_config.h b/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_lvts_config.h deleted file mode 100644 index 8c4bb51c8376..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_lvts_config.h +++ /dev/null @@ -1,95 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TSCPU_LVTS_SETTINGS_H__ -#define __TSCPU_LVTS_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define LVTS_ADDRESS_INDEX_1 116 /* 0x11C101C0 */ -#define LVTS_ADDRESS_INDEX_2 117 /* 0x11C101C4 */ -#define LVTS_ADDRESS_INDEX_3 118 /* 0x11C101C8 */ -#define LVTS_ADDRESS_INDEX_4 119 /* 0x11C101CC */ -#define LVTS_ADDRESS_INDEX_5 190 /* 0x11C101D0 */ -#define LVTS_ADDRESS_INDEX_6 191 /* 0x11C101D4 */ -#define LVTS_ADDRESS_INDEX_7 192 /* 0x11C101D8 */ -#define LVTS_ADDRESS_INDEX_8 193 /* 0x11C101DC */ -#define LVTS_ADDRESS_INDEX_9 194 /* 0x11C101E0 */ -#define LVTS_ADDRESS_INDEX_10 195 /* 0x11C101E4 */ -#define LVTS_ADDRESS_INDEX_11 196 /* 0x11C101E8 */ -#define LVTS_ADDRESS_INDEX_12 197 /* 0x11C101EC */ -#define LVTS_ADDRESS_INDEX_13 198 /* 0x11C101F0 */ -#define LVTS_ADDRESS_INDEX_14 199 /* 0x11C101F4 */ -#define LVTS_ADDRESS_INDEX_15 200 /* 0x11C101F8 */ -#define LVTS_ADDRESS_INDEX_16 201 /* 0x11C101FC */ -#define LVTS_ADDRESS_INDEX_17 202 /* 0x11C10200 */ -#define LVTS_ADDRESS_INDEX_18 203 /* 0x11C10204 */ -#define LVTS_ADDRESS_INDEX_19 204 /* 0x11C10208 */ -#define LVTS_ADDRESS_INDEX_20 205 /* 0x11C1020C */ -#define LVTS_ADDRESS_INDEX_21 206 /* 0x11C10210 */ -#define LVTS_ADDRESS_INDEX_22 207 /* 0x11C10214 */ - - - - -/**************************************************************************** */ -/* LVTS related registers. */ -/**************************************************************************** */ -#define LVTSMONCTL0_0 (THERM_CTRL_BASE_2 + 0x000) -#define LVTSMONCTL1_0 (THERM_CTRL_BASE_2 + 0x004) -#define LVTSMONCTL2_0 (THERM_CTRL_BASE_2 + 0x008) -#define LVTSMONINT_0 (THERM_CTRL_BASE_2 + 0x00C) -#define LVTSMONINTSTS_0 (THERM_CTRL_BASE_2 + 0x010) -#define LVTSMONIDET0_0 (THERM_CTRL_BASE_2 + 0x014) -#define LVTSMONIDET1_0 (THERM_CTRL_BASE_2 + 0x018) -#define LVTSMONIDET2_0 (THERM_CTRL_BASE_2 + 0x01C) -#define LVTSMONIDET3_0 (THERM_CTRL_BASE_2 + 0x020) -#define LVTSH2NTHRE_0 (THERM_CTRL_BASE_2 + 0x024) -#define LVTSHTHRE_0 (THERM_CTRL_BASE_2 + 0x028) -#define LVTSCTHRE_0 (THERM_CTRL_BASE_2 + 0x02C) -#define LVTSOFFSETH_0 (THERM_CTRL_BASE_2 + 0x030) -#define LVTSOFFSETL_0 (THERM_CTRL_BASE_2 + 0x034) -#define LVTSMSRCTL0_0 (THERM_CTRL_BASE_2 + 0x038) -#define LVTSMSRCTL1_0 (THERM_CTRL_BASE_2 + 0x03C) -#define LVTSTSSEL_0 (THERM_CTRL_BASE_2 + 0x040) -#define LVTSDEVICETO_0 (THERM_CTRL_BASE_2 + 0x044) -#define LVTSCALSCALE_0 (THERM_CTRL_BASE_2 + 0x048) -#define LVTS_ID_0 (THERM_CTRL_BASE_2 + 0x04C) -#define LVTS_CONFIG_0 (THERM_CTRL_BASE_2 + 0x050) -#define LVTSEDATA00_0 (THERM_CTRL_BASE_2 + 0x054) -#define LVTSEDATA01_0 (THERM_CTRL_BASE_2 + 0x058) -#define LVTSEDATA02_0 (THERM_CTRL_BASE_2 + 0x05C) -#define LVTSEDATA03_0 (THERM_CTRL_BASE_2 + 0x060) -#define LVTSMSR0_0 (THERM_CTRL_BASE_2 + 0x090) -#define LVTSMSR1_0 (THERM_CTRL_BASE_2 + 0x094) -#define LVTSMSR2_0 (THERM_CTRL_BASE_2 + 0x098) -#define LVTSMSR3_0 (THERM_CTRL_BASE_2 + 0x09C) -#define LVTSIMMD0_0 (THERM_CTRL_BASE_2 + 0x0A0) -#define LVTSIMMD1_0 (THERM_CTRL_BASE_2 + 0x0A4) -#define LVTSIMMD2_0 (THERM_CTRL_BASE_2 + 0x0A8) -#define LVTSIMMD3_0 (THERM_CTRL_BASE_2 + 0x0AC) -#define LVTSRDATA0_0 (THERM_CTRL_BASE_2 + 0x0B0) -#define LVTSRDATA1_0 (THERM_CTRL_BASE_2 + 0x0B4) -#define LVTSRDATA2_0 (THERM_CTRL_BASE_2 + 0x0B8) -#define LVTSRDATA3_0 (THERM_CTRL_BASE_2 + 0x0BC) -#define LVTSPROTCTL_0 (THERM_CTRL_BASE_2 + 0x0C0) -#define LVTSPROTTA_0 (THERM_CTRL_BASE_2 + 0x0C4) -#define LVTSPROTTB_0 (THERM_CTRL_BASE_2 + 0x0C8) -#define LVTSPROTTC_0 (THERM_CTRL_BASE_2 + 0x0CC) -#define LVTSCLKEN_0 (THERM_CTRL_BASE_2 + 0x0E4) -#define LVTSDBGSEL_0 (THERM_CTRL_BASE_2 + 0x0E8) -#define LVTSDBGSIG_0 (THERM_CTRL_BASE_2 + 0x0EC) -#define LVTSSPARE0_0 (THERM_CTRL_BASE_2 + 0x0F0) -#define LVTSSPARE1_0 (THERM_CTRL_BASE_2 + 0x0F4) -#define LVTSSPARE2_0 (THERM_CTRL_BASE_2 + 0x0F8) -#define LVTSSPARE3_0 (THERM_CTRL_BASE_2 + 0x0FC) - -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) - -#endif /* __TSCPU_LVTS_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_settings.h b/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_settings.h deleted file mode 100644 index 28f7b488a125..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_settings.h +++ /dev/null @@ -1,798 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TSCPU_SETTINGS_H__ -#define __TSCPU_SETTINGS_H__ - -#include "mach/mtk_thermal.h" - -#include -#include - -#include "tzcpu_initcfg.h" -#include "clatm_initcfg.h" -#include "tscpu_tsense_config.h" -#include "tscpu_lvts_config.h" - -/*============================================================= - * Genernal - *============================================================= - */ -#define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_)) -#define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_)) -#define _BIT_(_bit_) (unsigned int)(1 << (_bit_)) -#define _BITMASK_(_bits_) (((unsigned int) -1 >> (31 - ((1) ? _bits_))) \ - & ~((1U << ((0) ? _bits_)) - 1)) - -#define THERMAL_TPROFILE_INIT() \ - long long thermal_pTime_us, thermal_cTime_us, thermal_diff_us - -#define THERMAL_GET_PTIME() {thermal_pTime_us = thermal_get_current_time_us()} - -#define THERMAL_GET_CTIME() {thermal_cTime_us = thermal_get_current_time_us()} - -#define THERMAL_TIME_TH 3000 - -#define THERMAL_IS_TOO_LONG() \ - do { \ - thermal_diff_us = thermal_cTime_us - thermal_pTime_us; \ - if (thermal_diff_us > THERMAL_TIME_TH) { \ - pr_notice(TSCPU_LOG_TAG "%s: %llu us\n", __func__, \ - thermal_diff_us); \ - } else if (thermal_diff_us < 0) { \ - pr_notice(TSCPU_LOG_TAG \ - "Warning: tProfiling uses incorrect %s %d\n", \ - __func__, __LINE__); \ - } \ - } while (0) - -/*============================================================= - * CONFIG (SW related) - *============================================================= - */ -/*Enable thermal controller CG*/ -#define THERMAL_EBABLE_TC_CG - -#define ENALBE_UART_LIMIT (0) -#define TEMP_EN_UART (80000) -#define TEMP_DIS_UART (85000) -#define TEMP_TOLERANCE (0) - -#define ENALBE_SW_FILTER (0) -#define ATM_USES_PPM (1) - -#define THERMAL_GET_AHB_BUS_CLOCK (0) -#define THERMAL_PERFORMANCE_PROFILE (0) - -/* 1: turn on GPIO toggle monitor; 0: turn off */ -#define THERMAL_GPIO_OUT_TOGGLE (0) - -/* 1: turn on adaptive AP cooler; 0: turn off */ -#define CPT_ADAPTIVE_AP_COOLER (1) - -/* 1: turn on supports to MET logging; 0: turn off */ -#define CONFIG_SUPPORT_MET_MTKTSCPU (0) - -/* Thermal controller HW filtering function. - * Only 1, 2, 4, 8, 16 are valid values, - * they means one reading is a avg of X samples - */ -#define THERMAL_CONTROLLER_HW_FILTER (2) /* 1, 2, 4, 8, 16 */ - -/* 1: turn on thermal controller HW thermal protection; 0: turn off */ -#define THERMAL_CONTROLLER_HW_TP (1) - -/* 1: turn on fast polling in this sw module; 0: turn off */ -#define MTKTSCPU_FAST_POLLING (1) - -#if CPT_ADAPTIVE_AP_COOLER -#define MAX_CPT_ADAPTIVE_COOLERS (3) - -#define THERMAL_HEADROOM (0) -#define CONTINUOUS_TM (1) -#define DYNAMIC_GET_GPU_POWER (1) - -/* 1: turn on precise power budgeting; 0: turn off */ -#define PRECISE_HYBRID_POWER_BUDGET (1) - -#define PHPB_DEFAULT_ON (1) -#endif - -/* 1: thermal driver fast polling, use hrtimer; 0: turn off */ -/*#define THERMAL_DRV_FAST_POLL_HRTIMER (1)*/ - -/* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */ -#define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1) - -/* Define this in tscpu_settings.h enables this feature. - * It polls CPU TS in hrtimer and - * run ATM in RT 98 kthread. This is for MT6799 only. - */ -#define FAST_RESPONSE_ATM (1) -#define THERMAL_INIT_VALUE (0xDA1) -#define CLEAR_TEMP 26111 - -/* Thermal VPU throttling support */ -#ifdef CONFIG_MTK_APUSYS_VPU -#define THERMAL_VPU_SUPPORT -#endif - -/* Thermal MDLA throttling support */ -#ifdef CONFIG_MTK_APUSYS_MDLA_SUPPORT -#define THERMAL_MDLA_SUPPORT -#endif - -/* EARA_Thermal power budget allocation support */ -#define EARA_THERMAL_SUPPORT - -#define TS_FILL(n) {#n, n} -/*#define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))*/ -#define MAX_TS_NAME 20 - -#define CPU_COOLER_NUM 34 -#define MTK_TS_CPU_RT (0) - -#ifdef CONFIG_MTK_RAM_CONSOLE -#define CONFIG_THERMAL_AEE_RR_REC (1) -#else -#define CONFIG_THERMAL_AEE_RR_REC (0) -#endif - -#if CFG_THERM_LVTS -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -//#define CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT (0) -#define DYNAMIC_REBOOT_TRIP_TEMP (35000) -#define DYNAMIC_REBOOT_EXIT_TEMP (30000) -#else -#define CONFIG_LVTS_ERROR_AEE_WARNING (0) -#endif - -#define DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE (1) -/* - * if RCK get zero data, - * need to get the same controller's other sensor's average RCK value - * instead of zero data. - */ -#define LVTS_GET_ZERO_RCK_DATA_ISSUE (0) -#define LVTS_REFINE_MANUAL_RCK_WITH_EFUSE (1) - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#define LVTS_FORCE_ERROR_TRIGGER (0) -#define LVTS_NUM_SKIP_SAMPLE (500) - -#define HISTORY_SAMPLES (10) -#define FUTURE_SAMPLES (10) -#define R_BUFFER_SIZE (HISTORY_SAMPLES + FUTURE_SAMPLES + 1) -#define LVTS_ERROR_THRESHOLD (10000) - -#define DUMP_LVTS_REGISTER (0) -#define DUMP_VCORE_VOLTAGE (0) -#endif -#define LVTS_VALID_DATA_TIME_PROFILING (0) - -#define LVTS_USE_DOMINATOR_SENSING_POINT (1) - -#define CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR (0) -/*============================================================= - *REG ACCESS - *============================================================= - */ -/* double check */ -#define TS_CONFIGURE TS_CON1_TM /* depend on CPU design*/ -#define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design*/ - -/* turn on TS_CON1[5:4] 2'b 00 11001111 -> 0xCF ~(0x30)*/ -#define TS_TURN_ON 0xFFFFFFCF -#define TS_TURN_OFF 0x00000030 /* turn off thermal*/ - -#define thermal_setl(addr, val) mt_reg_sync_writel(readl(addr) | (val), \ - ((void *)addr)) - -#define thermal_clrl(addr, val) mt_reg_sync_writel(readl(addr) & ~(val), \ - ((void *)addr)) - -#define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */ - -#define y_curr_repeat_times 1 -#define THERMAL_NAME "mtk-thermal" - -#define TS_MS_TO_NS(x) (x * 1000 * 1000) - -/*cpu core nums*/ -#define TZCPU_NO_CPU_CORES (8) - -#if THERMAL_GET_AHB_BUS_CLOCK -#define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x84) -#define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x90) - -#define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80) -#define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70) -#endif - -/*============================================================= - * Common Structure and Enum - *============================================================= - */ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -enum thermal_state { - TSCPU_SUSPEND = 0, - TSCPU_RESUME = 1, - TSCPU_NORMAL = 2, - TSCPU_INIT = 3, - TSCPU_PAUSE = 4, - TSCPU_RELEASE = 5 -}; -enum atm_state { - ATM_WAKEUP = 0, - ATM_CPULIMIT = 1, - ATM_GPULIMIT = 2, - ATM_DONE = 3, -}; -#endif - -struct mtk_cpu_power_info { - unsigned int cpufreq_khz; - unsigned int cpufreq_ncpu; - unsigned int cpufreq_power; -}; - -/*============================================================= - * LVTS Structure and Enum - *============================================================= - */ -#if CFG_THERM_LVTS - -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1,T2) LVTS1-0, LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -/* private thermal sensor enum */ -enum lvts_sensor_enum { - L_TS_LVTS1_0 = 0, /* LVTS1-0 1*/ - L_TS_LVTS1_1, /* LVTS1-1 2*/ - L_TS_LVTS2_0, /* LVTS2-0 3*/ - L_TS_LVTS2_1, /* LVTS2-1 4*/ - L_TS_LVTS3_0, /* LVTS3-0 5*/ - L_TS_LVTS3_1, /* LVTS3-1 6*/ - L_TS_LVTS3_2, /* LVTS3-2 7*/ - L_TS_LVTS3_3, /* LVTS3-3 8*/ - L_TS_LVTS4_0, /* LVTS4-0 9*/ - L_TS_LVTS4_1, /* LVTS4-1 10*/ - L_TS_LVTS5_0, /* LVTS5-0 11*/ - L_TS_LVTS5_1, /* LVTS5-1 12*/ - L_TS_LVTS6_0, /* LVTS6-0 13*/ - L_TS_LVTS6_1, /* LVTS6-1 14*/ - L_TS_LVTS7_0, /* LVTS7-0 15*/ - L_TS_LVTS7_1, /* LVTS7-1 16*/ - L_TS_LVTS7_2, /* LVTS7-2 17*/ - L_TS_LVTS_NUM -}; - -enum lvts_tc_enum { - LVTS_MCU_CONTROLLER0 = 0,/* LVTSMONCTL0 */ - LVTS_MCU_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_MCU_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_AP_CONTROLLER0, /* LVTSMONCTL0 */ - LVTS_AP_CONTROLLER1, /* LVTSMONCTL0_1 */ - LVTS_AP_CONTROLLER2, /* LVTSMONCTL0_2 */ - LVTS_AP_CONTROLLER3, /* LVTSMONCTL0_3 */ - LVTS_CONTROLLER_NUM -}; - -struct lvts_thermal_controller_speed { - unsigned int group_interval_delay; - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; -}; - -struct lvts_thermal_controller { - enum lvts_sensor_enum ts[4]; /* sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; /* hw protection ref TS (index of the ts array) */ - int tc_offset; - struct lvts_thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Tsense Structure and Enum - *============================================================= - */ -#if !defined(CFG_THERM_NO_AUXADC) -/* private thermal sensor enum */ -enum tsmcu_sensor_enum { - L_TS_MCU0 = 0, - L_TS_MCU1, - L_TS_MCU2, - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - L_TS_MCU4, - L_TS_MCU5, - L_TS_MCU6, - L_TS_MCU7, - L_TS_MCU8, - L_TS_MCU9, - L_TS_ABB, - L_TS_MCU_NUM -}; - -enum thermal_controller_name { - THERMAL_CONTROLLER0 = 0, /* TEMPMONCTL0 */ - THERMAL_CONTROLLER1, /* TEMPMONCTL0_1 */ - THERMAL_CONTROLLER2, /* TEMPMONCTL0_2 */ - THERMAL_CONTROLLER_NUM -}; -#endif -struct thermal_controller_speed { - unsigned int period_unit; - unsigned int filter_interval_delay; - unsigned int sensor_interval_delay; - unsigned int ahb_polling_interval; -}; -#if CFG_THERM_LVTS -struct thermal_controller { - enum lvts_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; - -#else -struct thermal_controller { - enum tsmcu_sensor_enum ts[4]; /* Sensor point 0 ~ 3 */ - int ts_number; - int dominator_ts_idx; //hw protection ref TS (index of the ts array) - int tc_offset; - struct thermal_controller_speed tc_speed; -}; -#endif - -/*============================================================= - * Shared variables - *============================================================= - */ -#ifdef CONFIG_OF -extern u32 thermal_irq_number; -extern u32 thermal_mcu_irq_number; -extern void __iomem *thermal_base; -extern void __iomem *auxadc_ts_base; -extern void __iomem *infracfg_ao_base; -extern void __iomem *th_apmixed_base; -extern void __iomem *INFRACFG_AO_base; - -extern int thermal_phy_base; -extern int auxadc_ts_phy_base; -extern int apmixed_phy_base; -extern int pericfg_phy_base; -#endif - -#if PRECISE_HYBRID_POWER_BUDGET -/* tscpu_prev_cpu_temp: previous CPUSYS temperature - * tscpu_curr_cpu_temp: current CPUSYS temperature - * tscpu_prev_gpu_temp: previous GPUSYS temperature - * tscpu_curr_gpu_temp: current GPUSYS temperature - */ -extern int tscpu_curr_cpu_temp; -extern int tscpu_curr_gpu_temp; -#endif - -/* - * In src/mtk_tc.c - */ -extern int temp_eUART; -extern int temp_dUART; - -extern int tscpu_sspm_thermal_throttle; -extern int tscpu_debug_log; -extern const struct of_device_id mt_thermal_of_match[2]; -#if !defined(CFG_THERM_NO_AUXADC) -extern struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM]; -#endif -extern int tscpu_polling_trip_temp1; -extern int tscpu_polling_trip_temp2; -extern int tscpu_polling_factor1; -extern int tscpu_polling_factor2; - -extern int lvts_hw_protect_enabled; - -#if !defined(CFG_THERM_NO_AUXADC) -/* - * temperature array to store both tsmcu and lvts (if exist) and export them - */ -extern int tscpu_ts_temp[TS_ENUM_MAX]; -extern int tscpu_ts_temp_r[TS_ENUM_MAX]; /* raw data */ - -/* - * temperature array to store temp of tsmcu sensor - */ -extern int tscpu_ts_mcu_temp[L_TS_MCU_NUM]; -extern int tscpu_ts_mcu_temp_r[L_TS_MCU_NUM]; /* raw data */ -#endif - -#if CFG_THERM_LVTS -/* - * temperature array to store temp of lvts sensor - */ -extern int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -extern int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; /* raw data */ -#endif - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -extern int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#if DUMP_VCORE_VOLTAGE -extern struct regulator *vcore_reg_id; -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern unsigned long long SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -extern int isTempValid; -extern long long start_timestamp; -/* count if start_timestamp is bigger than end_timestamp */ -extern int diff_error_count; -#endif -/* - * support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_rawdata_debug_log; -extern int lvts_debug_log; -extern struct lvts_thermal_controller -lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM]; -#endif - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -extern int fast_polling_trip_temp; -extern int fast_polling_trip_temp_high; -extern int fast_polling_factor; -extern int tscpu_cur_fp_factor; -extern int tscpu_next_fp_factor; -#endif - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern long long thermal_get_current_time_us(void); -extern void tscpu_workqueue_cancel_timer(void); -extern void tscpu_workqueue_start_timer(void); - -extern void __iomem *therm_clk_infracfg_ao_base; -extern int Num_of_GPU_OPP; -extern int gpu_max_opp; -extern struct mt_gpufreq_power_table_info *mtk_gpu_power; -extern int tscpu_read_curr_temp; -#if MTKTSCPU_FAST_POLLING -extern int tscpu_cur_fp_factor; -#endif - -#if !defined(CONFIG_MTK_CLKMGR) -extern struct clk *therm_main; /* main clock for Thermal*/ -#endif - -#if CPT_ADAPTIVE_AP_COOLER -extern int tscpu_g_curr_temp; -extern int tscpu_g_prev_temp; -#if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1) -extern int bts_cur_temp; /* in mtk_ts_bts.c */ -#endif - -#endif - -extern char *adaptive_cooler_name; - -/* common/coolers/mtk_cooler_atm.c */ -extern unsigned int adaptive_cpu_power_limit; -extern unsigned int adaptive_gpu_power_limit; -extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS]; -#ifdef FAST_RESPONSE_ATM -extern void atm_cancel_hrtimer(void); -extern void atm_restart_hrtimer(void); -#endif - -/* common/coolers/mtk_cooler_dtm.c */ -extern unsigned int static_cpu_power_limit; -extern unsigned int static_gpu_power_limit; -extern int tscpu_cpu_dmips[CPU_COOLER_NUM]; -/*============================================================= - * Shared functions - *============================================================= - */ -/*In mtk_tc_wrapper.c */ -extern int tscpu_get_curr_max_ts_temp(void); -extern int tscpu_max_temperature(void); -extern int tscpu_get_curr_temp(void); -extern int combine_lvts_tsmcu_temp(void); -extern int tscpu_read_temperature_info(struct seq_file *m, void *v); -extern int get_io_reg_base(void); - -/*In common/thermal_zones/mtk_ts_cpu.c*/ -extern void thermal_init_interrupt_for_UART(int temp_e, int temp_d); -extern void tscpu_update_tempinfo(void); -#if THERMAL_GPIO_OUT_TOGGLE -void tscpu_set_GPIO_toggle_for_monitor(void); -#endif -extern void tscpu_update_tempinfo(void); - -#if !defined(CFG_THERM_NO_AUXADC) -/*In src/mtk_tc.c*/ -extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2); -extern void tscpu_reset_thermal(void); -extern void tscpu_thermal_initial_all_tc(void); -extern void tscpu_thermal_read_tc_temp( - int tc_num, enum tsmcu_sensor_enum type, int order); -extern void tscpu_thermal_cal_prepare(void); -extern void tscpu_thermal_cal_prepare_2(unsigned int ret); - -extern int tscpu_dump_cali_info(struct seq_file *m, void *v); -extern int tscpu_thermal_fast_init(int tc_num); -extern void thermal_get_AHB_clk_info(void); -extern void print_risky_temps(char *prefix, int offset, int printLevel); -extern void thermal_pause_all_periodoc_temp_sensing(void); -extern void thermal_release_all_periodoc_temp_sensing(void); - -extern void thermal_disable_all_periodoc_temp_sensing(void); -extern void read_all_tc_tsmcu_temperature(void); -extern irqreturn_t tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -#endif -extern int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern int tscpu_thermal_clock_on(void); -extern int tscpu_thermal_clock_off(void); -extern void lvts_tscpu_reset_thermal(void); -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -extern int lvts_get_io_reg_base(void); -extern int lvts_max_temperature(void); -extern void lvts_config_all_tc_hw_protect(int temperature, int temperature2); -extern void lvts_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order); -extern void lvts_read_all_tc_temperature(void); -extern void lvts_reset_and_initial(int tc_num); -extern int (*lvts_max_temperature_in_bank[THERMAL_BANK_NUM])(void); -extern void lvts_thermal_lvts_device_init(void); -extern void lvts_read_temperature(void); -//extern void lvts_read_temperature(int temp0, int temp1); -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_error_info(void); -#endif -extern void lvts_thermal_cal_prepare(void); -extern void lvts_device_identification(void); -extern void lvts_reset_device_and_stop_clk(void); -extern void lvts_read_device_id_rev(void); -extern void lvts_Device_Enable_Init_all_Devices(void); -extern void lvts_device_read_count_RC_N(void); -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -extern void lvts_device_read_count_RC_N_resume(void); -#endif -extern void lvts_device_enable_auto_rck(void); -extern void lvts_efuse_setting(void); -extern void lvts_tscpu_thermal_initial_all_tc(void); -extern void lvts_pause_all_sensing_points(void); -extern void lvts_release_all_sensing_points(void); -extern void lvts_disable_all_sensing_points(void); -extern void lvts_enable_all_sensing_points(void); -extern void read_all_tc_lvts_temperature(void); -extern void lvts_wait_for_all_sensing_point_idle(void); -extern irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler( -int irq, void *dev_id); -extern int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v); -extern void lvts_sodi3_release_thermal_controller(void); -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -extern void lvts_enable_all_hw_protect(void); -extern void lvts_disable_all_hw_protect(void); -#endif -#endif - -/* - * In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c - * It's not our api, ask them to provide header file - */ -extern bool mtk_get_gpu_loading(unsigned int *pLoading); -/* - * In drivers/misc/mediatek/auxadc/mt_auxadc.c - * It's not our api, ask them to provide header file - */ -extern int IMM_IsAdcInitReady(void); - -#if CONFIG_LVTS_ERROR_AEE_WARNING -extern void dump_efuse_data(void); -extern int check_lvts_mcu_efuse(void); -extern int check_auxadc_mcu_efuse(void); -#if DUMP_LVTS_REGISTER -extern void read_controller_reg_before_active(void); -extern void read_controller_reg_when_error(void); -extern void read_device_reg_before_active(void); -extern void read_device_reg_when_error(void); -extern void clear_lvts_register_value_array(void); -extern void dump_lvts_register_value(void); -#endif -#endif -#if LVTS_VALID_DATA_TIME_PROFILING -extern void lvts_dump_time_profiling_result(struct seq_file *m); -#endif -/*aee related*/ -#if (CONFIG_THERMAL_AEE_RR_REC == 1) -extern int aee_rr_init_thermal_temp(int num); -extern int aee_rr_rec_thermal_temp(int index, s8 val); -extern void aee_rr_rec_thermal_status(u8 val); -extern void aee_rr_rec_thermal_ATM_status(u8 val); -extern void aee_rr_rec_thermal_ktime(u64 val); - -extern s8 aee_rr_curr_thermal_temp(int index); -extern u8 aee_rr_curr_thermal_status(void); -extern u8 aee_rr_curr_thermal_ATM_status(void); -extern u64 aee_rr_curr_thermal_ktime(void); -#endif - -/*============================================================= - *LOG - *============================================================= - */ -#define TSCPU_LOG_TAG "[Thermal/TZ/CPU]" - -#define tscpu_dprintk(fmt, args...) \ - do { \ - if (tscpu_debug_log == 1) { \ - pr_notice(TSCPU_LOG_TAG fmt, ##args); \ - } \ - } while (0) - -#define tscpu_printk(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) -#define tscpu_warn(fmt, args...) pr_notice(TSCPU_LOG_TAG fmt, ##args) - -/* - * Support LVTS - */ -#if CFG_THERM_LVTS -#define LVTS_LOG_TAG "[Thermal/TZ/LVTS]" -#define LVTS_LOG_REG_TAG "[Thermal/TZ/LVTSREG]" - -#define lvts_reg_print(fmt, args...) pr_notice(LVTS_LOG_REG_TAG fmt, ##args) -#define lvts_printk(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#define lvts_warn(fmt, args...) pr_notice(LVTS_LOG_TAG fmt, ##args) -#define lvts_dbg_printk(fmt, args...) \ - do { \ - if (lvts_debug_log == 1) { \ - pr_notice(LVTS_LOG_TAG fmt, ##args); \ - } \ - } while (0) -#endif - -/*============================================================= - * Register macro for internal use - *============================================================= - */ - -#define THERM_CTRL_BASE_2 thermal_base -#define AUXADC_BASE_2 auxadc_ts_base -#define INFRACFG_AO_BASE_2 infracfg_ao_base -#define APMIXED_BASE_2 th_apmixed_base - -/******************************************************************************* - * AUXADC Register Definition - ***************************************************************************** - */ - -#define AUXADC_CON0_V (AUXADC_BASE_2 + 0x000) -#define AUXADC_CON1_V (AUXADC_BASE_2 + 0x004) -#define AUXADC_CON1_SET_V (AUXADC_BASE_2 + 0x008) -#define AUXADC_CON1_CLR_V (AUXADC_BASE_2 + 0x00C) -#define AUXADC_CON2_V (AUXADC_BASE_2 + 0x010) -/*#define AUXADC_CON3_V (AUXADC_BASE_2 + 0x014)*/ -#define AUXADC_DAT0_V (AUXADC_BASE_2 + 0x014) -#define AUXADC_DAT1_V (AUXADC_BASE_2 + 0x018) -#define AUXADC_DAT2_V (AUXADC_BASE_2 + 0x01C) -#define AUXADC_DAT3_V (AUXADC_BASE_2 + 0x020) -#define AUXADC_DAT4_V (AUXADC_BASE_2 + 0x024) -#define AUXADC_DAT5_V (AUXADC_BASE_2 + 0x028) -#define AUXADC_DAT6_V (AUXADC_BASE_2 + 0x02C) -#define AUXADC_DAT7_V (AUXADC_BASE_2 + 0x030) -#define AUXADC_DAT8_V (AUXADC_BASE_2 + 0x034) -#define AUXADC_DAT9_V (AUXADC_BASE_2 + 0x038) -#define AUXADC_DAT10_V (AUXADC_BASE_2 + 0x03C) -#define AUXADC_DAT11_V (AUXADC_BASE_2 + 0x040) -#define AUXADC_MISC_V (AUXADC_BASE_2 + 0x094) - -#define AUXADC_CON0_P (auxadc_ts_phy_base + 0x000) -#define AUXADC_CON1_P (auxadc_ts_phy_base + 0x004) -#define AUXADC_CON1_SET_P (auxadc_ts_phy_base + 0x008) -#define AUXADC_CON1_CLR_P (auxadc_ts_phy_base + 0x00C) -#define AUXADC_CON2_P (auxadc_ts_phy_base + 0x010) -/*#define AUXADC_CON3_P (auxadc_ts_phy_base + 0x014)*/ -#define AUXADC_DAT0_P (auxadc_ts_phy_base + 0x014) -#define AUXADC_DAT1_P (auxadc_ts_phy_base + 0x018) -#define AUXADC_DAT2_P (auxadc_ts_phy_base + 0x01C) -#define AUXADC_DAT3_P (auxadc_ts_phy_base + 0x020) -#define AUXADC_DAT4_P (auxadc_ts_phy_base + 0x024) -#define AUXADC_DAT5_P (auxadc_ts_phy_base + 0x028) -#define AUXADC_DAT6_P (auxadc_ts_phy_base + 0x02C) -#define AUXADC_DAT7_P (auxadc_ts_phy_base + 0x030) -#define AUXADC_DAT8_P (auxadc_ts_phy_base + 0x034) -#define AUXADC_DAT9_P (auxadc_ts_phy_base + 0x038) -#define AUXADC_DAT10_P (auxadc_ts_phy_base + 0x03C) -#define AUXADC_DAT11_P (auxadc_ts_phy_base + 0x040) - -#define AUXADC_MISC_P (auxadc_ts_phy_base + 0x094) - -/******************************************************************************* - * Peripheral Configuration Register Definition - ***************************************************************************** - */ - -/*APB Module infracfg_ao*/ -#define INFRA_GLOBALCON_RST_0_SET (INFRACFG_AO_BASE_2 + 0x120) -#define INFRA_GLOBALCON_RST_0_CLR (INFRACFG_AO_BASE_2 + 0x124) -#define INFRA_GLOBALCON_RST_0_STA (INFRACFG_AO_BASE_2 + 0x128) - -#define INFRA_GLOBALCON_RST_4_SET (INFRACFG_AO_BASE_2 + 0x730) -#define INFRA_GLOBALCON_RST_4_CLR (INFRACFG_AO_BASE_2 + 0x734) -/******************************************************************************* - * APMixedSys Configuration Register Definition - ***************************************************************************** - */ -/* TODO: check base addr. */ -#define TS_CON0_TM (APMIXED_BASE_2 + 0x600) /*yes 0x10212000*/ -#define TS_CON1_TM (APMIXED_BASE_2 + 0x604) -#define TS_CON0_P (apmixed_phy_base + 0x600) -#define TS_CON1_P (apmixed_phy_base + 0x604) - -/******************************************************************************* - * Thermal Controller Register Mask Definition - ***************************************************************************** - */ - -#define THERMAL_COLD_INTERRUPT_0 0x00000001 -#define THERMAL_HOT_INTERRUPT_0 0x00000002 -#define THERMAL_LOW_OFFSET_INTERRUPT_0 0x00000004 -#define THERMAL_HIGH_OFFSET_INTERRUPT_0 0x00000008 -#define THERMAL_HOT2NORMAL_INTERRUPT_0 0x00000010 -#define THERMAL_COLD_INTERRUPT_1 0x00000020 -#define THERMAL_HOT_INTERRUPT_1 0x00000040 -#define THERMAL_LOW_OFFSET_INTERRUPT_1 0x00000080 -#define THERMAL_HIGH_OFFSET_INTERRUPT_1 0x00000100 -#define THERMAL_HOT2NORMAL_INTERRUPT_1 0x00000200 -#define THERMAL_COLD_INTERRUPT_2 0x00000400 -#define THERMAL_HOT_INTERRUPT_2 0x00000800 -#define THERMAL_LOW_OFFSET_INTERRUPT_2 0x00001000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_2 0x00002000 -#define THERMAL_HOT2NORMAL_INTERRUPT_2 0x00004000 -#define THERMAL_AHB_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_DEVICE_TIMEOUT_INTERRUPT 0x00008000 -#define THERMAL_IMMEDIATE_INTERRUPT_0 0x00010000 -#define THERMAL_IMMEDIATE_INTERRUPT_1 0x00020000 -#define THERMAL_IMMEDIATE_INTERRUPT_2 0x00040000 -#define THERMAL_FILTER_INTERRUPT_0 0x00080000 -#define THERMAL_FILTER_INTERRUPT_1 0x00100000 -#define THERMAL_FILTER_INTERRUPT_2 0x00200000 -#define THERMAL_COLD_INTERRUPT_3 0x00400000 -#define THERMAL_HOT_INTERRUPT_3 0x00800000 -#define THERMAL_LOW_OFFSET_INTERRUPT_3 0x01000000 -#define THERMAL_HIGH_OFFSET_INTERRUPT_3 0x02000000 -#define THERMAL_HOT2NORMAL_INTERRUPT_3 0x04000000 -#define THERMAL_IMMEDIATE_INTERRUPT_3 0x08000000 -#define THERMAL_FILTER_INTERRUPT_3 0x10000000 -#define THERMAL_PROTECTION_STAGE_1 0x20000000 -#define THERMAL_PROTECTION_STAGE_2 0x40000000 -#define THERMAL_PROTECTION_STAGE_3 0x80000000 -#endif /* __TSCPU_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_tsense_config.h b/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_tsense_config.h deleted file mode 100644 index 1bc4aac0ae00..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tscpu_tsense_config.h +++ /dev/null @@ -1,152 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TSCPU_TSENSE_SETTINGS_H__ -#define __TSCPU_TSENSE_SETTINGS_H__ - -/*============================================================= - * Chip related - *============================================================= - */ -/* chip dependent */ -/* TODO: change to new reg addr. */ -#define ADDRESS_INDEX_0 101 /* 184 */ -#define ADDRESS_INDEX_1 100 /* 180 */ -#define ADDRESS_INDEX_2 102 /* 188 */ -#define ADDRESS_INDEX_3 111 /* 1AC */ -#define ADDRESS_INDEX_4 112 /* 1B0 */ - -/* TSCON1 bit table */ -#define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00*/ -#define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01*/ -#define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10*/ -#define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11*/ -#define TSCON0_bit_6_7_MASK 0xc0 - -#define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00*/ -#define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01*/ -#define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10*/ -#define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11*/ -#define TSCON1_bit_4_5_MASK 0x30 - -#define TSCON1_bit_0_2_000 0x00 /*TSCON1[2:0]=3'b000*/ -#define TSCON1_bit_0_2_001 0x01 /*TSCON1[2:0]=3'b001*/ -#define TSCON1_bit_0_2_010 0x02 /*TSCON1[2:0]=3'b010*/ -#define TSCON1_bit_0_2_011 0x03 /*TSCON1[2:0]=3'b011*/ -#define TSCON1_bit_0_2_100 0x04 /*TSCON1[2:0]=3'b100*/ -#define TSCON1_bit_0_2_101 0x05 /*TSCON1[2:0]=3'b101*/ -#define TSCON1_bit_0_2_110 0x06 /*TSCON1[2:0]=3'b110*/ -#define TSCON1_bit_0_2_111 0x07 /*TSCON1[2:0]=3'b111*/ -#define TSCON1_bit_0_2_MASK 0x07 - -#define TSCON1_bit_0_3_0000 0x00 /*TSCON1[3:0]=4'b0000*/ -#define TSCON1_bit_0_3_0001 0x01 /*TSCON1[3:0]=4'b0001*/ -#define TSCON1_bit_0_3_0010 0x02 /*TSCON1[3:0]=4'b0010*/ -#define TSCON1_bit_0_3_0011 0x03 /*TSCON1[3:0]=4'b0011*/ -#define TSCON1_bit_0_3_0100 0x04 /*TSCON1[3:0]=4'b0100*/ -#define TSCON1_bit_0_3_0101 0x05 /*TSCON1[3:0]=4'b0101*/ -#define TSCON1_bit_0_3_0110 0x06 /*TSCON1[3:0]=4'b0110*/ -#define TSCON1_bit_0_3_0111 0x07 /*TSCON1[3:0]=4'b0111*/ -#define TSCON1_bit_0_3_1000 0x08 /*TSCON1[3:0]=4'b1000*/ -#define TSCON1_bit_0_3_1001 0x09 /*TSCON1[3:0]=4'b1001*/ -#define TSCON1_bit_0_3_1010 0x0A /*TSCON1[3:0]=4'b1010*/ -#define TSCON1_bit_0_3_1011 0x0B /*TSCON1[3:0]=4'b1011*/ -#define TSCON1_bit_0_3_1100 0x0C /*TSCON1[3:0]=4'b1100*/ -#define TSCON1_bit_0_3_1101 0x0D /*TSCON1[3:0]=4'b1101*/ -#define TSCON1_bit_0_3_1110 0x0E /*TSCON1[3:0]=4'b1110*/ -#define TSCON1_bit_0_3_1111 0x0F /*TSCON1[3:0]=4'b1111*/ -#define TSCON1_bit_0_3_MASK 0x0F - -/* ADC value to mcu */ -/*chip dependent*/ -#define TEMPADC_MCU0 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0000)) -#define TEMPADC_MCU1 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0001)) -#define TEMPADC_MCU2 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0010)) -#define TEMPADC_MCU4 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0100)) -#define TEMPADC_MCU5 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0101)) -#define TEMPADC_MCU6 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0110)) -#define TEMPADC_MCU7 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_0111)) -#define TEMPADC_MCU8 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1000)) -#define TEMPADC_MCU9 ((0x30&TSCON1_bit_4_5_00)|(0x0F&TSCON1_bit_0_3_1001)) -#define TEMPADC_ABB ((0x30&TSCON1_bit_4_5_01)|(0x0F&TSCON1_bit_0_3_0000)) - -/******************************************************************************* - * Thermal Controller Register Definition - ***************************************************************************** - */ -#define TEMPMONCTL0 (THERM_CTRL_BASE_2 + 0x800) -#define TEMPMONCTL1 (THERM_CTRL_BASE_2 + 0x804) -#define TEMPMONCTL2 (THERM_CTRL_BASE_2 + 0x808) -#define TEMPMONINT (THERM_CTRL_BASE_2 + 0x80C) -#define TEMPMONINTSTS (THERM_CTRL_BASE_2 + 0x810) -#define TEMPMONIDET0 (THERM_CTRL_BASE_2 + 0x814) -#define TEMPMONIDET1 (THERM_CTRL_BASE_2 + 0x818) -#define TEMPMONIDET2 (THERM_CTRL_BASE_2 + 0x81C) -#define TEMPH2NTHRE (THERM_CTRL_BASE_2 + 0x824) -#define TEMPHTHRE (THERM_CTRL_BASE_2 + 0x828) -#define TEMPCTHRE (THERM_CTRL_BASE_2 + 0x82C) -#define TEMPOFFSETH (THERM_CTRL_BASE_2 + 0x830) -#define TEMPOFFSETL (THERM_CTRL_BASE_2 + 0x834) -#define TEMPMSRCTL0 (THERM_CTRL_BASE_2 + 0x838) -#define TEMPMSRCTL1 (THERM_CTRL_BASE_2 + 0x83C) -#define TEMPAHBPOLL (THERM_CTRL_BASE_2 + 0x840) -#define TEMPAHBTO (THERM_CTRL_BASE_2 + 0x844) -#define TEMPADCPNP0 (THERM_CTRL_BASE_2 + 0x848) -#define TEMPADCPNP1 (THERM_CTRL_BASE_2 + 0x84C) -#define TEMPADCPNP2 (THERM_CTRL_BASE_2 + 0x850) -#define TEMPADCMUX (THERM_CTRL_BASE_2 + 0x854) -#define TEMPADCEXT (THERM_CTRL_BASE_2 + 0x858) -#define TEMPADCEXT1 (THERM_CTRL_BASE_2 + 0x85C) -#define TEMPADCEN (THERM_CTRL_BASE_2 + 0x860) -#define TEMPPNPMUXADDR (THERM_CTRL_BASE_2 + 0x864) -#define TEMPADCMUXADDR (THERM_CTRL_BASE_2 + 0x868) -#define TEMPADCEXTADDR (THERM_CTRL_BASE_2 + 0x86C) -#define TEMPADCEXT1ADDR (THERM_CTRL_BASE_2 + 0x870) -#define TEMPADCENADDR (THERM_CTRL_BASE_2 + 0x874) -#define TEMPADCVALIDADDR (THERM_CTRL_BASE_2 + 0x878) -#define TEMPADCVOLTADDR (THERM_CTRL_BASE_2 + 0x87C) -#define TEMPRDCTRL (THERM_CTRL_BASE_2 + 0x880) -#define TEMPADCVALIDMASK (THERM_CTRL_BASE_2 + 0x884) -#define TEMPADCVOLTAGESHIFT (THERM_CTRL_BASE_2 + 0x888) -#define TEMPADCWRITECTRL (THERM_CTRL_BASE_2 + 0x88C) -#define TEMPMSR0 (THERM_CTRL_BASE_2 + 0x890) -#define TEMPMSR1 (THERM_CTRL_BASE_2 + 0x894) -#define TEMPMSR2 (THERM_CTRL_BASE_2 + 0x898) -#define TEMPADCHADDR (THERM_CTRL_BASE_2 + 0x89C) -#define TEMPIMMD0 (THERM_CTRL_BASE_2 + 0x8A0) -#define TEMPIMMD1 (THERM_CTRL_BASE_2 + 0x8A4) -#define TEMPIMMD2 (THERM_CTRL_BASE_2 + 0x8A8) -#define TEMPMONIDET3 (THERM_CTRL_BASE_2 + 0x8B0) -#define TEMPADCPNP3 (THERM_CTRL_BASE_2 + 0x8B4) -#define TEMPMSR3 (THERM_CTRL_BASE_2 + 0x8B8) -#define TEMPIMMD3 (THERM_CTRL_BASE_2 + 0x8BC) -#define TEMPPROTCTL (THERM_CTRL_BASE_2 + 0x8C0) -#define TEMPPROTTA (THERM_CTRL_BASE_2 + 0x8C4) -#define TEMPPROTTB (THERM_CTRL_BASE_2 + 0x8C8) -#define TEMPPROTTC (THERM_CTRL_BASE_2 + 0x8CC) -#define TEMPSPARE0 (THERM_CTRL_BASE_2 + 0x8F0) -#define TEMPSPARE1 (THERM_CTRL_BASE_2 + 0x8F4) -#define TEMPSPARE2 (THERM_CTRL_BASE_2 + 0x8F8) -#define TEMPSPARE3 (THERM_CTRL_BASE_2 + 0x8FC) - -#define PTPCORESEL (THERM_CTRL_BASE_2 + 0xF00) -#define THERMINTST (THERM_CTRL_BASE_2 + 0xF04) -#define PTPODINTST (THERM_CTRL_BASE_2 + 0xF08) -#define THSTAGE0ST (THERM_CTRL_BASE_2 + 0xF0C) -#define THSTAGE1ST (THERM_CTRL_BASE_2 + 0xF10) -#define THSTAGE2ST (THERM_CTRL_BASE_2 + 0xF14) -#define THAHBST0 (THERM_CTRL_BASE_2 + 0xF18) -#define THAHBST1 (THERM_CTRL_BASE_2 + 0xF1C) -#define PTPSPARE0 (THERM_CTRL_BASE_2 + 0xF20) -#define PTPSPARE1 (THERM_CTRL_BASE_2 + 0xF24) -#define PTPSPARE2 (THERM_CTRL_BASE_2 + 0xF28) -#define PTPSPARE3 (THERM_CTRL_BASE_2 + 0xF2C) -#define THSLPEVEB (THERM_CTRL_BASE_2 + 0xF30) - -#define PTPSPARE0_P (thermal_phy_base + 0xF20) -#define PTPSPARE1_P (thermal_phy_base + 0xF24) -#define PTPSPARE2_P (thermal_phy_base + 0xF28) -#define PTPSPARE3_P (thermal_phy_base + 0xF2C) -#endif /* __TSCPU_TSENSE_SETTINGS_H__ */ diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tzbatt_initcfg.h b/drivers/misc/mediatek/thermal/mt6893/inc/tzbatt_initcfg.h deleted file mode 100644 index d99180d717ca..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tzbatt_initcfg.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TZBATT_INITCFG_H__ -#define __TZBATT_INITCFG_H__ - -#define TZBATT_SET_INIT_CFG (1) - -#define TZBATT_INITCFG_INTERVAL (1) -#define TZBATT_INITCFG_NUM_TRIPS (3) - -#define TZBATT_INITCFG_TRIP_0_TEMP (49000) -#define TZBATT_INITCFG_TRIP_0_COOLER "mtk-cl-bcct02" - -#define TZBATT_INITCFG_TRIP_1_TEMP (48000) -#define TZBATT_INITCFG_TRIP_1_COOLER "mtk-cl-bcct01" - -#define TZBATT_INITCFG_TRIP_2_TEMP (46000) -#define TZBATT_INITCFG_TRIP_2_COOLER "mtk-cl-bcct00" - -#define TZBATT_INITCFG_TRIP_3_TEMP (45000) -#define TZBATT_INITCFG_TRIP_3_COOLER "" - -#define TZBATT_INITCFG_TRIP_4_TEMP (44000) -#define TZBATT_INITCFG_TRIP_4_COOLER "" - -#define TZBATT_INITCFG_TRIP_5_TEMP (43000) -#define TZBATT_INITCFG_TRIP_5_COOLER "" - -#define TZBATT_INITCFG_TRIP_6_TEMP (42000) -#define TZBATT_INITCFG_TRIP_6_COOLER "" - -#define TZBATT_INITCFG_TRIP_7_TEMP (41000) -#define TZBATT_INITCFG_TRIP_7_COOLER "" - -#define TZBATT_INITCFG_TRIP_8_TEMP (40000) -#define TZBATT_INITCFG_TRIP_8_COOLER "" - -#define TZBATT_INITCFG_TRIP_9_TEMP (39000) -#define TZBATT_INITCFG_TRIP_9_COOLER "" - -#endif /* __TZBATT_INITCFG_H__ */ - diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/tzcpu_initcfg.h b/drivers/misc/mediatek/thermal/mt6893/inc/tzcpu_initcfg.h deleted file mode 100644 index da97e1f252aa..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/tzcpu_initcfg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#ifndef __TZCPU_INITCFG_H__ -#define __TZCPU_INITCFG_H__ - -#define TZCPU_SET_INIT_CFG (1) - -#define TZCPU_INITCFG_INTERVAL (40) -#define TZCPU_INITCFG_NUM_TRIPS (4) - -#define TZCPU_INITCFG_TRIP_0_TEMP (117000) -#define TZCPU_INITCFG_TRIP_0_COOLER "mtktscpu-sysrst" - -#define TZCPU_INITCFG_TRIP_1_TEMP (95000) -#define TZCPU_INITCFG_TRIP_1_COOLER "cpu00" - -#define TZCPU_INITCFG_TRIP_2_TEMP (85000) -#define TZCPU_INITCFG_TRIP_2_COOLER "cpu03" - -#define TZCPU_INITCFG_TRIP_3_TEMP (65000) -#define TZCPU_INITCFG_TRIP_3_COOLER "cpu_adaptive_0" - -#define TZCPU_INITCFG_TRIP_4_TEMP (63000) -#define TZCPU_INITCFG_TRIP_4_COOLER "" - -#define TZCPU_INITCFG_TRIP_5_TEMP (60000) -#define TZCPU_INITCFG_TRIP_5_COOLER "" - -#define TZCPU_INITCFG_TRIP_6_TEMP (55000) -#define TZCPU_INITCFG_TRIP_6_COOLER "" - -#define TZCPU_INITCFG_TRIP_7_TEMP (50000) -#define TZCPU_INITCFG_TRIP_7_COOLER "" - -#define TZCPU_INITCFG_TRIP_8_TEMP (45000) -#define TZCPU_INITCFG_TRIP_8_COOLER "" - -#define TZCPU_INITCFG_TRIP_9_TEMP (40000) -#define TZCPU_INITCFG_TRIP_9_COOLER "" - - -#endif /* __TZCPU_INITCFG_H__ */ - - diff --git a/drivers/misc/mediatek/thermal/mt6893/inc/vtskin_temp.h b/drivers/misc/mediatek/thermal/mt6893/inc/vtskin_temp.h deleted file mode 100644 index dfe1cbea1d8b..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/inc/vtskin_temp.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2020 MediaTek Inc. - */ - -#ifndef __VTSKIN_TEMP_H__ -#define __VTSKIN_TEMP_H__ - -#define MAX_VTSKIN_REF_NUM 10 - -enum vtskin_operation { - OP_COEF, - OP_MAX, - OP_NUM, -}; - -struct vtskin_coef { - char sensor_name[THERMAL_NAME_LENGTH + 1]; - long long sensor_coef; -}; - -struct vtskin_tz_param { - char tz_name[THERMAL_NAME_LENGTH + 1]; - enum vtskin_operation operation; - unsigned int ref_num; - struct vtskin_coef vtskin_ref[MAX_VTSKIN_REF_NUM]; -}; - -struct vtskin_data { - struct device *dev; - struct mutex lock; - int num_sensor; - struct vtskin_tz_param *params; -}; - -struct vtskin_temp_tz { - unsigned int id; - struct vtskin_data *skin_data; - struct vtskin_tz_param *skin_param; -}; - -extern struct vtskin_data *plat_vtskin_info; - -#endif diff --git a/drivers/misc/mediatek/thermal/mt6893/src/Makefile b/drivers/misc/mediatek/thermal/mt6893/src/Makefile deleted file mode 100644 index a02915079004..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Copyright (C) 2018 MediaTek Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -ifeq ($(CONFIG_MACH_MT6893),y) - PDIR = mt6893 -else - PDIR = $(MTK_PLATFORM) -endif - -THERMAL_CHIP_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/thermal/$(PDIR) -ccflags-y += -I$(THERMAL_CHIP_DRIVER_DIR)/inc -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/gpu/hal/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/fakeHeader/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v1 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(MTK_PLATFORM) -ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2 -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/spm/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/eem_v2/mt3967/inc/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/thermal/common/inc/ -ccflags-y += -I$(srctree)/drivers/gpu/mediatek/gpufreq/include/ -ccflags-y += -I$(srctree)/include/dt-bindings/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/gpufreq_v1/ -ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include/ - -obj-$(CONFIG_THERMAL) += mtk_lvts_tc.o -#obj-$(CONFIG_THERMAL) += mtk_tc.o -obj-$(CONFIG_THERMAL) += mtk_tc_wrapper.o -obj-$(CONFIG_THERMAL) += mtk_thermal_ipi.o -obj-$(CONFIG_THERMAL) += mtk_pmic_efuse.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vcore.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vproc.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359vgpu.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359tsx.o -obj-$(CONFIG_THERMAL) += mtk_ts_6359dcxo.o -obj-$(CONFIG_THERMAL) += mtk_ti_6315.o -obj-$(CONFIG_THERMAL) += vtskin_temp.o \ No newline at end of file diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_lvts_tc.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_lvts_tc.c deleted file mode 100644 index 1e925968ea33..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_lvts_tc.c +++ /dev/null @@ -1,2290 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2019 MediaTek Inc. - */ -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include -#include - -#define __MT_MTK_LVTS_TC_C__ -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_LVTS_TC_C__ - -#include -#include "mtk_thermal_ipi.h" - - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 3; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -int tscpu_debug_log; -int tscpu_sspm_thermal_throttle; -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif -/*============================================================= - * Local variable definition - *============================================================= - */ -/* chip dependent */ -/* - * TO-DO: I assume AHB bus frequecy is 78MHz. - * Please confirm it. - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1) LVTS1-0 - * MCU_BIGBIG(T2) LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -struct lvts_thermal_controller lvts_tscpu_g_tc[LVTS_CONTROLLER_NUM] = { - [0] = {/*(MCU)*/ - .ts = {L_TS_LVTS1_0, L_TS_LVTS1_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x26D000, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [1] = {/*(MCU)*/ - .ts = {L_TS_LVTS2_0, L_TS_LVTS2_1}, - .ts_number = 2, - .dominator_ts_idx = 0, - .tc_offset = 0x26D100, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [2] = {/*(MCU)*/ - .ts = {L_TS_LVTS3_0, L_TS_LVTS3_1, L_TS_LVTS3_2, L_TS_LVTS3_3}, - .ts_number = 4, - .dominator_ts_idx = 1, - .tc_offset = 0x26D200, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [3] = {/*(AP)*/ - .ts = {L_TS_LVTS4_0, L_TS_LVTS4_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x0, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [4] = {/*(AP)*/ - .ts = {L_TS_LVTS5_0, L_TS_LVTS5_1}, - .ts_number = 2, - .dominator_ts_idx = 1, - .tc_offset = 0x100, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [5] = {/*(AP)*/ - .ts = {L_TS_LVTS6_0, L_TS_LVTS6_1}, - .ts_number = 2, - .dominator_ts_idx = 0, - .tc_offset = 0x200, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - }, - [6] = {/*(AP)*/ - .ts = {L_TS_LVTS7_0, L_TS_LVTS7_1, L_TS_LVTS7_2}, - .ts_number = 3, - .dominator_ts_idx = 0, - .tc_offset = 0x300, - .tc_speed = { - 0x001, - 0x00C, - 0x001, - 0x001 - } - } -}; - -static unsigned int g_golden_temp; -static unsigned int g_count_r[L_TS_LVTS_NUM]; -static unsigned int g_count_rc[L_TS_LVTS_NUM]; -static unsigned int g_count_rc_now[L_TS_LVTS_NUM]; -static int g_use_fake_efuse; -int lvts_debug_log; -int lvts_rawdata_debug_log; - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -static int hw_protect_setting_done; -int lvts_hw_protect_enabled; -#endif - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -#define NUM_LVTS_DEVICE_REG (34) -static const unsigned int g_lvts_device_addrs[NUM_LVTS_DEVICE_REG] = { - 0x00, - 0x01, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x0A, - 0x0B, - 0x0C, - 0x0D, - 0x0E, - 0x10, - 0x11, - 0x12, - 0x13, - 0x14, - 0x15, - 0x16, - 0x17, - 0x18, - 0x19, - 0x1A, - 0x1B, - 0xF0, - 0xF1, - 0xF2, - 0xF3, - 0xFC, - 0xFD, - 0xFF}; - -static unsigned int g_lvts_device_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; -static unsigned int g_lvts_device_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_DEVICE_REG]; - -#define NUM_LVTS_CONTROLLER_REG (28) -static const unsigned int g_lvts_controller_addrs[NUM_LVTS_CONTROLLER_REG] = { - 0x00,//LVTSMONCTL0_0 - 0x04,//LVTSMONCTL1_0 - 0x08,//LVTSMONCTL2_0 - 0x0C,//LVTSMONINT_0 - 0x10,//LVTSMONINTSTS_0 - 0x20,//LVTSMONIDET3_0 - 0x38,//LVTSMSRCTL0_0 - 0x3C,//LVTSMSRCTL1_0 - 0x40,//LVTSTSSEL_0 - 0x4C,//LVTS_ID_0 - 0x50,//LVTS_CONFIG_0 - 0x54,//LVTSSEDATA00_0 - 0x58,//LVTSSEDATA01_0 - 0x5C,//LVTSSEDATA02_0 - 0x60,//LVTSSEDATA03_0 - 0x90,//LVTSMSR0_0 - 0x94,//LVTSMSR1_0 - 0x98,//LVTSMSR2_0 - 0x9C,//LVTSMSR3_0 - 0xB0,//LVTSRDATA0_0 - 0xB4,//LVTSRDATA1_0 - 0xB8,//LVTSRDATA2_0 - 0xBC,//LVTSRDATA3_0 - 0xC0,//LVTSPROTCTCTL_0 - 0xCC,//LVTSPROTTC_0 - 0xFC,//LVTSPRRE3_0 - 0xE8,//LVTSDBGSEL_0 - 0xE4};//LVTSCLKEN_0 -static unsigned int g_lvts_controller_value_b[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -static unsigned int g_lvts_controller_value_e[LVTS_CONTROLLER_NUM] - [NUM_LVTS_CONTROLLER_REG]; -#endif - -#if LVTS_VALID_DATA_TIME_PROFILING -unsigned long long SODI3_count, noValid_count; -/* If isTempValid is 0, it means no valid temperature data - * between two SODI3 entry points. - */ -int isTempValid; -/* latency_array - * {a, b} - * a: a time threshold in milliseconds. if it is -1, it means others. - * b: the number of valid temperature latencies from a phone enters SODI3 to - * to a phone gets a valid temperature of any sensor. - * It is possible a phone enters SODI3 several times without a valid - * temperature data. - */ -#define NUM_TIME_TH (16) -static unsigned int latency_array[NUM_TIME_TH][2] = { - {100, 0}, - {200, 0}, - {300, 0}, - {400, 0}, - {500, 0}, - {600, 0}, - {700, 0}, - {800, 0}, - {900, 0}, - {1000, 0}, - {2000, 0}, - {3000, 0}, - {4000, 0}, - {5000, 0}, - {10000, 0}, - {-1, 0} -}; -long long start_timestamp; -static long long end_timestamp, time_diff; -/* count if start_timestamp is bigger than end_timestamp */ -int diff_error_count; -#endif - -#if CFG_THERM_LVTS -#define DEFAULT_EFUSE_GOLDEN_TEMP (50) -#define DEFAULT_EFUSE_COUNT (35000) -#define DEFAULT_EFUSE_COUNT_RC (2750) -#define FAKE_EFUSE_VALUE 0x2B048500 -#define LVTS_COEFF_A_X_1000 (-252500) -#define LVTS_COEFF_B_X_1000 (252500) -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static unsigned int lvts_temp_to_raw(int ret, enum lvts_sensor_enum ts_name); - -static void lvts_set_tc_trigger_hw_protect( - int temperature, int temperature2, int tc_num); -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -void mt_reg_sync_writel_print(unsigned int val, void *addr) -{ - if (lvts_debug_log) - lvts_dbg_printk("### LVTS_REG: addr 0x%p, val 0x%x\n", - addr, val); - - mt_reg_sync_writel(val, addr); -} - -/*=============================================================*/ - -static int lvts_write_device(unsigned int config, unsigned int dev_reg_idx, -unsigned int data, int tc_num) -{ - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - dev_reg_idx &= 0xFF; - data &= 0xFF; - - config = config | (dev_reg_idx << 8) | data; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* - * LVTS Device Register Setting take 1us(by 26MHz clock source) - * interface latency to access. - * So we set 2~3us delay could guarantee access complete. - */ - udelay(3); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("write err: status not ready, reg0x%x\n", - dev_reg_idx); - break; - } - udelay(2); - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - - return 1; -} - -static unsigned int lvts_read_device(unsigned int config, -unsigned int dev_reg_idx, int tc_num) -{ - int offset, cnt; - unsigned int data = 0; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - dev_reg_idx &= 0xFF; - - config = config | (dev_reg_idx << 8) | 0x00; - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - mt_reg_sync_writel_print(config, LVTS_CONFIG_0 + offset); - - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("read err: status not ready, reg0x%x\n", - dev_reg_idx); - break; - } - udelay(2); - } - - data = (readl(LVTSRDATA0_0 + offset)); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - - return data; -} -int lvts_raw_to_temp(unsigned int msr_raw, enum lvts_sensor_enum ts_name) -{ - /* This function returns degree mC - * temp[i] = a * MSR_RAW/16384 + GOLDEN_TEMP/2 + b - * a = -252.5 - * b = 252.5 - */ - int temp_mC = 0; - int temp1 = 0; - - temp1 = (LVTS_COEFF_A_X_1000 * ((unsigned long long)msr_raw)) >> 14; - - temp_mC = temp1 + g_golden_temp * 500 + LVTS_COEFF_B_X_1000; - - return temp_mC; -} -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE -static void read_controller_reg_before_active(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_b[i][j] = temp; - } - } - -} - -static void read_controller_reg_when_error(void) -{ - int i, j, offset, temp; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - temp = readl(LVTSMONCTL0_0 + g_lvts_controller_addrs[j] - + offset); - g_lvts_controller_value_e[i][j] = temp; - } - } -} - -static void read_device_reg_before_active(void) -{ - int i, j; - unsigned int addr, data; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - data = lvts_read_device(0x81020000, addr, i); - g_lvts_device_value_b[i][j] = data; - } - } -} - -static void read_device_reg_when_error(void) -{ - int i, j, offset, cnt; - unsigned int addr; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - addr = g_lvts_device_addrs[j]; - lvts_write_device(0x81020000, addr, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - /* Check ASIF bus status for transaction finished - * Wait until DEVICE_ACCESS_START = 0 - */ - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk("Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - - g_lvts_device_value_e[i][j] = (readl(LVTSRDATA0_0 - + offset)); - } - } -} - -void clear_lvts_register_value_array(void) -{ - int i, j; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - g_lvts_controller_value_b[i][j] = 0; - g_lvts_controller_value_e[i][j] = 0; - } - - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - g_lvts_device_value_b[i][j] = 0; - g_lvts_device_value_e[i][j] = 0; - } - } -} - -static void dump_lvts_register_value(void) -{ - int i, j, offset, tc_offset; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - lvts_printk("[LVTS_ERROR][AFTER][CONTROLLER_%d][DUMP]\n", i); - tc_offset = lvts_tscpu_g_tc[i].tc_offset; //tc offset - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][AFTER][TC][DUMP] "); - - for (j = 0; j < NUM_LVTS_CONTROLLER_REG; j++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, - __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "0x%x:%x ", - tc_offset + g_lvts_controller_addrs[j], - g_lvts_controller_value_e[i][j]); - } - - lvts_printk("%s\n", buffer); - - offset = snprintf(buffer, sizeof(buffer), - "[LVTS_ERROR][AFTER][DEVICE][DUMP] "); - for (j = 0; j < NUM_LVTS_DEVICE_REG; j++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, - __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "0x%x:%x ", - g_lvts_device_addrs[j], - g_lvts_device_value_e[i][j]); - } - - lvts_printk("%s\n", buffer); - } -} - -void dump_lvts_error_info(void) -{ - read_controller_reg_when_error(); - - lvts_disable_all_sensing_points(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -} - -#endif - -static void lvts_device_check_counting_status(int tc_num) -{ - /* Check this when LVTS device is counting for - * a temperature or a RC now - */ - - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; //tc offset - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(25))) { - cnt++; - - if (cnt == 100) { - lvts_printk( - "Error: DEVICE_SENSING_STATUS didn't ready\n"); - break; - } - udelay(2); - } - } -} - -static void lvts_device_check_read_write_status(int tc_num) -{ - /* Check this when LVTS device is doing a register - * read or write operation - */ - - int offset, cnt; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - cnt = 0; - while ((readl(LVTS_CONFIG_0 + offset) & _BIT_(24))) { - cnt++; - - if (cnt == 100) { - lvts_printk( - "Error: DEVICE_ACCESS_START didn't ready\n"); - break; - } - udelay(2); - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - -} - -#if defined(CFG_THERM_USE_BOOTUP_COUNT_RC) -void lvts_device_read_count_RC_N_resume(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - /* Set LVTS Manual-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x00, i); - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0x81030000, 0x0D, j, i); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0x78, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - lvts_write_device(0x81030000, 0x07, 0xA6, i); - - /* Wait 8us for device settle + 2us buffer*/ - udelay(10); - /* Kick-off RCK counting */ - lvts_write_device(0x81030000, 0x03, 0x02, i); - - /* wait 30ms */ - udelay(30); - - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0x81020000, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - - /* Disable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF1, i); - - lvts_device_check_read_write_status(i); - - /* Get RCK value from LSB[23:0] */ - //g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - } - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0x81030000, 0x0D, 0x10, i); - } - - offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); - - for (i = 0; i < L_TS_LVTS_NUM; i++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "%d:%d ", - i, g_count_rc_now[i]); - } - - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} -#endif - -void lvts_device_read_count_RC_N(void) -{ - /* Resistor-Capacitor Calibration */ - /* count_RC_N: count RC now */ - int k, i, j, offset, num_ts, s_index; - unsigned int data; - char buffer[512]; - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - unsigned int rc_data; - int refine_data_idx[4] = {0}; - /* - * comare count_rc_now with efuse. - * > 6%, use efuse RC instead of count_rc_now - * < 6%, keep count_rc_now value - */ - int count_rc_delta = 0; -#endif - - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - num_ts = lvts_tscpu_g_tc[i].ts_number; - - /* Set LVTS Manual-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x00, i); - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - /* - * set 0xff to clear refine_data_idx - * in each thermal controller, - * max sensor num = 4 - */ - for (k = 0; k < 4; k++) - refine_data_idx[k] = 0xff; -#endif - - for (j = 0; j < num_ts; j++) { - s_index = lvts_tscpu_g_tc[i].ts[j]; - - /* Select sensor-N with RCK */ - lvts_write_device(0x81030000, 0x0D, j, i); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0x78, i); - lvts_write_device(0x81030000, 0x07, 0xA6, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); -// lvts_write_device(0x81030000, 0x07, 0xA6, i); - - /* Wait 8us for device settle + 2us buffer*/ - udelay(10); - - /* Kick-off RCK counting */ - lvts_write_device(0x81030000, 0x03, 0x02, i); - - /* wait 30us */ - udelay(30); - - lvts_device_check_counting_status(i); - - /* Get RCK count data (sensor-N) */ - data = lvts_read_device(0x81020000, 0x00, i); - /* wait 2us + 3us buffer*/ - udelay(5); - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - rc_data = (data & _BITMASK_(23:0)); - - /* - * if count rc now = 0 , use efuse rck insead of - * count_rc_now - */ - if (rc_data == 0) { - refine_data_idx[j] = s_index; - lvts_printk("rc_data %d, data_idx[%d]=%d\n", - rc_data, j, s_index); - } else { - if (g_count_rc[i] > rc_data) - count_rc_delta = - (g_count_rc[i] * 1000) / rc_data; - else - count_rc_delta = - (rc_data * 1000) / g_count_rc[i]; - - /* - * if delta > 6%, use efuse rck insead of - * count_rc_now - */ - if (count_rc_delta > 1061) { - refine_data_idx[j] = s_index; - lvts_printk( - "delta %d, data_idx[%d]=%d\n", - count_rc_delta, j, s_index); - } - } - - - //lvts_printk("i=%d, j=%d, s_index=%d, rc_data=%d\n", - // i, j, s_index, rc_data); - //lvts_printk("(g_count_rc[i]*1000)=%d, rc_delta=%d\n", - // (g_count_rc[i]*1000), count_rc_delta); - -#endif - - - //lvts_printk("i=%d,j=%d, data=%d, s_index=%d\n", - // i, j, (data & _BITMASK_(23:0)), s_index); - - /* Disable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF1, i); - - lvts_device_check_read_write_status(i); - - /* Get RCK value from LSB[23:0] */ - g_count_rc_now[s_index] = (data & _BITMASK_(23:0)); - } - -#if LVTS_REFINE_MANUAL_RCK_WITH_EFUSE - for (j = 0; j < num_ts; j++) { - if (refine_data_idx[j] != 0xff) { - g_count_rc_now[refine_data_idx[j]] = - g_count_rc[i]; - lvts_printk("refine_data_idx[%d]=%d\n", - j, refine_data_idx[j]); - } - } -#endif - - /* Recover Setting for Normal Access on - * temperature fetch - */ - /* Select Sensor-N without RCK */ - lvts_write_device(0x81030000, 0x0D, 0x10, i); - } - - offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "%d:%d ", - i, g_count_rc_now[i]); - } - - lvts_printk("%s\n", buffer); - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_device_reg_before_active(); -#endif -} - -void lvts_device_enable_auto_rck(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Set LVTS AUTO-RCK operation */ - lvts_write_device(0x81030000, 0x0E, 0x01, i); - } -} - -void lvts_efuse_setting(void) -{ - __u32 offset; - int i, j, s_index; - int efuse_data; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - s_index = lvts_tscpu_g_tc[i].ts[j]; - -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse_data = - (((unsigned long long)g_count_rc_now[s_index]) * - g_count_r[s_index]) >> 14; -#else - efuse_data = g_count_r[s_index]; -#endif - - switch (j) { - case 0: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA00_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA00_%d 0x%x\n", - i, readl(LVTSEDATA00_0 + offset)); - break; - - case 1: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA01_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA01_%d 0x%x\n", - i, readl(LVTSEDATA01_0 + offset)); - break; - case 2: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA02_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA02_%d 0x%x\n", - i, readl(LVTSEDATA02_0 + offset)); - break; - case 3: - mt_reg_sync_writel_print(efuse_data, - LVTSEDATA03_0 + offset); - lvts_dbg_printk("efuse LVTSEDATA03_%d 0x%x\n", - i, readl(LVTSEDATA03_0 + offset)); - break; - default: - lvts_dbg_printk("%s, illegal ts order : %d!!\n", - __func__, j); - } - } - } - -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -void dump_efuse_data(void) -{ - int i, efuse, offset; - char buffer[512]; - - lvts_printk("[LVTS_ERROR][GOLDEN_TEMP][DUMP] %d\n", g_golden_temp); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_R][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_r[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", i, g_count_rc[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][COUNT_RC_NOW][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) - offset += sprintf(buffer + offset, "%d:%d ", - i, g_count_rc_now[i]); - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][LVTSEDATA][DUMP] "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { -#if LVTS_DEVICE_AUTO_RCK == 0 - efuse = g_count_rc_now[i] * g_count_r[i]; -#else - efuse = g_count_r[i]; -#endif - offset += sprintf(buffer + offset, "%d:%d ", i, efuse); - } - - buffer[offset] = '\0'; - lvts_printk("%s\n", buffer); -} - -int check_lvts_mcu_efuse(void) -{ - return (g_use_fake_efuse)?(0):(1); -} -#endif - -void lvts_device_identification(void) -{ - int tc_num, data, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Enable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000001, LVTSCLKEN_0 + offset); - - /* Reset All Devices */ - lvts_write_device(0x81030000, 0xFF, 0xFF, tc_num); - /* udelay(100); */ - - /* Read back Dev_ID with Update */ - lvts_write_device(0x85020000, 0xFC, 0x55, tc_num); - - /* Check LVTS device ID */ - data = (readl(LVTS_ID_0 + offset) & _BITMASK_(7:0)); - if (data != (0x81 + tc_num)) - lvts_printk("LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", - tc_num, (0x81 + tc_num), data); - } -} - -void lvts_reset_device_and_stop_clk(void) -{ - __u32 offset; - int tc_num; - - lvts_dbg_printk("%s\n", __func__); - - for (tc_num = 0; tc_num < ARRAY_SIZE(lvts_tscpu_g_tc); tc_num++) { - - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - /* Reset All Devices */ - lvts_write_device(0x81030000, 0xFF, 0xFF, tc_num); - - /* Disable LVTS_CTRL Clock */ - mt_reg_sync_writel_print(0x00000000, LVTSCLKEN_0 + offset); - } -} - -void lvts_Device_Enable_Init_all_Devices(void) -{ - int i; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - /* Release Counting StateMachine */ - lvts_write_device(0x81030000, 0x03, 0x00, i); - /* Set LVTS device counting window 20us */ - lvts_write_device(0x81030000, 0x04, 0x20, i); - lvts_write_device(0x81030000, 0x05, 0x00, i); - /* TSV2F_CHOP_CKSEL & TSV2F_EN */ - lvts_write_device(0x81030000, 0x0A, 0xC4, i); - /* TSBG_DEM_CKSEL * TSBG_CHOP_EN */ - lvts_write_device(0x81030000, 0x0C, 0x7C, i); - /* Set TS_RSV */ - lvts_write_device(0x81030000, 0x09, 0x8D, i); - -#if LVTS_DEVICE_AUTO_RCK == 0 - /* Device low power mode can ignore these settings and - * Device auto RCK mode will force device in low power - * mode - */ - - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - /* Toggle TSDIV_EN & TSVCO_TG */ - lvts_write_device(0x81030000, 0x08, 0xFC, i); - /* Enable TS_EN */ - lvts_write_device(0x81030000, 0x08, 0xF5, i); - - /* Lantency */ - lvts_write_device(0x81030000, 0x07, 0xA6, i); - -#endif - } -} - -void lvts_thermal_cal_prepare(void) -{ - unsigned int temp[22]; - int i, offset; - char buffer[512]; - - temp[0] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_1); - temp[1] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_2); - temp[2] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_3); - temp[3] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_4); - temp[4] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_5); - temp[5] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_6); - temp[6] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_7); - temp[7] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_8); - temp[8] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_9); - temp[9] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_10); - temp[10] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_11); - temp[11] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_12); - temp[12] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_13); - temp[13] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_14); - temp[14] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_15); - temp[15] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_16); - temp[16] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_17); - temp[17] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_18); - temp[18] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_19); - temp[19] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_20); - temp[20] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_21); - temp[21] = get_devinfo_with_index(LVTS_ADDRESS_INDEX_22); - - - for (i = 0; (i + 5) < 22; i = i + 5) - lvts_printk("[lvts_call] %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x, %d: 0x%x\n", - i, temp[i], i + 1, temp[i + 1], i + 2, temp[i + 2], - i + 3, temp[i + 3], i + 4, temp[i + 4]); - - lvts_printk("[lvts_call] 20: 0x%x, 21: 0x%x\n", temp[20], temp[21]); - - - g_golden_temp = ((temp[0] & _BITMASK_(31:24)) >> 24); - g_count_r[0] = (temp[1] & _BITMASK_(23:0)); - g_count_r[1] = (temp[2] & _BITMASK_(23:0)); - g_count_r[2] = (temp[3] & _BITMASK_(23:0)); - g_count_r[3] = (temp[4] & _BITMASK_(23:0)); - g_count_r[4] = (temp[5] & _BITMASK_(23:0)); - g_count_r[5] = (temp[6] & _BITMASK_(23:0)); - g_count_r[6] = (temp[7] & _BITMASK_(23:0)); - g_count_r[7] = (temp[8] & _BITMASK_(23:0)); - g_count_r[8] = (temp[9] & _BITMASK_(23:0)); - g_count_r[9] = (temp[10] & _BITMASK_(23:0)); - g_count_r[10] = (temp[11] & _BITMASK_(23:0)); - g_count_r[11] = (temp[12] & _BITMASK_(23:0)); - g_count_r[12] = (temp[13] & _BITMASK_(23:0)); - g_count_r[13] = (temp[14] & _BITMASK_(23:0)); - g_count_r[14] = (temp[15] & _BITMASK_(23:0)); - g_count_r[15] = (temp[16] & _BITMASK_(23:0)); - g_count_r[16] = (temp[17] & _BITMASK_(23:0)); - - g_count_rc[0] = (temp[21] & _BITMASK_(23:0)); - - g_count_rc[1] = ((temp[1] & _BITMASK_(31:24)) >> 8) + - ((temp[2] & _BITMASK_(31:24)) >> 16)+ - ((temp[3] & _BITMASK_(31:24)) >> 24); - - g_count_rc[2] = ((temp[4] & _BITMASK_(31:24)) >> 8) + - ((temp[5] & _BITMASK_(31:24)) >> 16) + - ((temp[6] & _BITMASK_(31:24)) >> 24); - - g_count_rc[3] = ((temp[7] & _BITMASK_(31:24)) >> 8) + - ((temp[8] & _BITMASK_(31:24)) >> 16) + - ((temp[9] & _BITMASK_(31:24)) >> 24); - - g_count_rc[4] = ((temp[10] & _BITMASK_(31:24)) >> 8) + - ((temp[11] & _BITMASK_(31:24)) >> 16) + - ((temp[12] & _BITMASK_(31:24)) >> 24); - - g_count_rc[5] = ((temp[13] & _BITMASK_(31:24)) >> 8) + - ((temp[14] & _BITMASK_(31:24)) >> 16) + - ((temp[15] & _BITMASK_(31:24)) >> 24); - - g_count_rc[6] = ((temp[16] & _BITMASK_(31:24)) >> 8) + - ((temp[17] & _BITMASK_(31:24)) >> 16) + - ((temp[18] & _BITMASK_(31:24)) >> 24); - - - for (i = 0; i < L_TS_LVTS_NUM; i++) { - if (i == 0) { - if ((temp[0] & _BITMASK_(7:0)) != 0) - break; - } else { - if (temp[i] != 0) - break; - } - } - - if (i == L_TS_LVTS_NUM) { - /* It means all efuse data are equal to 0 */ - lvts_printk( - "[lvts_cal] This sample is not calibrated, fake !!\n"); - - g_golden_temp = DEFAULT_EFUSE_GOLDEN_TEMP; - for (i = 0; i < L_TS_LVTS_NUM; i++) { - g_count_r[i] = DEFAULT_EFUSE_COUNT; - g_count_rc[i] = DEFAULT_EFUSE_COUNT_RC; - } - - g_use_fake_efuse = 1; - } - - lvts_printk("[lvts_cal] g_golden_temp = %d\n", g_golden_temp); - - offset = snprintf(buffer, sizeof(buffer), - "[lvts_cal] num:g_count_r:g_count_rc "); - for (i = 0; i < L_TS_LVTS_NUM; i++) { - - if (((sizeof(buffer) - offset) <= 0) || (offset < 0)) { - lvts_printk("%s %d error\n", __func__, __LINE__); - break; - } - - offset += snprintf(buffer + offset, - (sizeof(buffer) - offset), "%d:%d:%d ", - i, g_count_r[i], g_count_rc[i]); - } - - lvts_printk("%s\n", buffer); -} - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -void lvts_ipi_send_efuse_data(void) -{ - struct thermal_ipi_data thermal_data; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = g_golden_temp; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_LVTS_INIT_GRP1, &thermal_data) != 0) - udelay(100); -} -#endif - - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -#if defined(THERMAL_SSPM_THERMAL_THROTTLE_SWITCH) -void lvts_ipi_send_sspm_thermal_thtottle(void) -{ - struct thermal_ipi_data thermal_data; - - lvts_printk("%s\n", __func__); - - thermal_data.u.data.arg[0] = tscpu_sspm_thermal_throttle; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_SET_DIS_THERMAL_THROTTLE, - &thermal_data) != 0) - udelay(100); -} -#endif - -#if defined(THERMAL_KERNEL_SUSPEND_RESUME_NOTIFY) -void lvts_ipi_send_sspm_thermal_suspend_resume(int is_suspend) -{ - struct thermal_ipi_data thermal_data; - - //lvts_printk("%s, is_suspend %d\n", __func__, is_suspend); - - thermal_data.u.data.arg[0] = is_suspend; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - while (thermal_to_sspm(THERMAL_IPI_SUSPEND_RESUME_NOTIFY, - &thermal_data) != 0) - udelay(100); -} -#endif -#endif - -static unsigned int lvts_temp_to_raw(int temp, enum lvts_sensor_enum ts_name) -{ - /* MSR_RAW = ((temp[i] - GOLDEN_TEMP/2 - b) * 16384) / a - * a = -252.5 - * b = 252.5 - */ - unsigned int msr_raw = 0; - - msr_raw = ((long long)(((long long)g_golden_temp * 500 + - LVTS_COEFF_B_X_1000 - temp)) << 14)/(-1 * LVTS_COEFF_A_X_1000); - - lvts_dbg_printk("%s msr_raw = 0x%x,temp=%d\n", __func__, msr_raw, temp); - - return msr_raw; -} - -static void lvts_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + LVTSMONINTSTS_0); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + LVTSMONINTSTS_0); - - lvts_printk("[Thermal IRQ] LVTS thermal controller %d, LVTSMONINTSTS=0x%08x\n", - tc_num, ret); - - dump_lvts_error_info(); - - if (ret & THERMAL_COLD_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: High offset interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_DEVICE_TIMEOUT_INTERRUPT) - lvts_dbg_printk("[Thermal IRQ]: Device access timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Cold interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Low offset interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: High offset triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Hot to normal interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Immediate sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - lvts_dbg_printk("[Thermal IRQ]: Filter sense interrupt triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 1 interrupt triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - lvts_dbg_printk("[Thermal IRQ]: Thermal protection stage 2 interrupt triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) - lvts_printk("[Thermal IRQ]: Thermal protection stage 3 interrupt triggered, Thermal HW reboot\n"); - - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -irqreturn_t lvts_tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, ret_mcu = 0, i, mask = 1; - - ret = readl(THERMINTST + - lvts_tscpu_g_tc[LVTS_AP_CONTROLLER0].tc_offset); - ret = ret & 0x1E; - ret_mcu = readl(THERMINTST + - lvts_tscpu_g_tc[LVTS_MCU_CONTROLLER0].tc_offset); - ret_mcu = ret_mcu & 0x1E; - - /* MSB LSB NAME - * 4 4 LVTSINT3 - * 3 3 LVTSINT2 - * 2 2 LVTSINT1 - * 1 1 LVTSINT0 - * 0 0 THERMINT0 - */ - lvts_printk("%s : THERMINTST = 0x%x THERMINTST_MCU = 0x%x\n", - __func__, ret, ret_mcu); - - ret = ((ret_mcu >> 1) << LVTS_MCU_CONTROLLER0) | - ((ret >> 1) << LVTS_AP_CONTROLLER0); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - lvts_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void lvts_configure_polling_speed_and_filter(int tc_num) -{ - __u32 offset, lvtsMonCtl1, lvtsMonCtl2; - - lvts_dbg_printk("%s\n", __func__); - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvtsMonCtl1 = - (((lvts_tscpu_g_tc[tc_num].tc_speed.group_interval_delay - << 20) & _BITMASK_(29:20)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0))); - lvtsMonCtl2 = - (((lvts_tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (lvts_tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay - & _BITMASK_(9:0))); - /* - * Calculating period unit in Module clock x 256, and the - * Module clock will be changed to 26M when Infrasys - * enters Sleep mode. - */ - - /* - * bus clock 66M counting unit is - * 12 * 1/66M * 256 = 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel_print(lvtsMonCtl1, offset + LVTSMONCTL1_0); - /* - *filt interval is 1 * 46.545us = 46.545us, - *sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel_print(lvtsMonCtl2, offset + LVTSMONCTL2_0); - - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel_print(0x00000492, offset + LVTSMSRCTL0_0); - - udelay(1); - lvts_dbg_printk( - "%s %d, LVTSMONCTL1_0= 0x%x,LVTSMONCTL2_0= 0x%x,LVTSMSRCTL0_0= 0x%x\n", - __func__, tc_num, - readl(LVTSMONCTL1_0 + offset), - readl(LVTSMONCTL2_0 + offset), - readl(LVTSMSRCTL0_0 + offset)); - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -/* - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void lvts_set_tc_trigger_hw_protect( -int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, config, offset; -#if LVTS_USE_DOMINATOR_SENSING_POINT - unsigned int d_index; - enum lvts_sensor_enum ts_name; -#endif - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - lvts_dbg_printk("%s t1=%d t2=%d\n", - __func__, temperature, temperature2); - -#if LVTS_USE_DOMINATOR_SENSING_POINT - if (lvts_tscpu_g_tc[tc_num].dominator_ts_idx < - lvts_tscpu_g_tc[tc_num].ts_number){ - d_index = lvts_tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - lvts_printk( - "Error: LVTS TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - lvts_tscpu_g_tc[tc_num].dominator_ts_idx, - lvts_tscpu_g_tc[tc_num].ts_number); - - lvts_printk( - "Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - ts_name = lvts_tscpu_g_tc[tc_num].ts[d_index]; - - lvts_dbg_printk("%s # in tc%d , the dominator ts_name is %d\n", - __func__, tc_num, ts_name); - - /* temperature to trigger SPM state2 */ - raw_high = lvts_temp_to_raw(temperature, ts_name); -#else - raw_high = lvts_temp_to_raw(temperature, 0); -#endif - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - temp = readl(offset + LVTSMONINT_0); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print(temp & 0x00000000, - offset + LVTSMONINT_0); -#endif - - temp = readl(offset + LVTSPROTCTL_0) & ~(0xF << 16); -#if LVTS_USE_DOMINATOR_SENSING_POINT - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel_print(temp | config, - offset + LVTSPROTCTL_0); -#else - /* Maximum of 4 sensing points */ - config = (0x1 << 16); - mt_reg_sync_writel_print(temp | config, - offset + LVTSPROTCTL_0); -#endif - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel_print(raw_high, offset + LVTSPROTTC_0); - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print(temp | 0x80000000, - offset + LVTSMONINT_0); -#endif - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); -} - -static void dump_lvts_device(int tc_num, __u32 offset) -{ - lvts_printk("%s, LVTS_CONFIG_%d= 0x%x\n", __func__, - tc_num, readl(LVTS_CONFIG_0 + offset)); - udelay(2); - - //read raw data - lvts_printk("%s, LVTSRDATA0_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA0_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA1_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA1_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA2_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA2_0 + offset)); - - udelay(2); - lvts_printk("%s, LVTSRDATA3_%d= 0x%x\n", __func__, - tc_num, readl(LVTSRDATA3_0 + offset)); -} - -#if LVTS_VALID_DATA_TIME_PROFILING -void lvts_dump_time_profiling_result(struct seq_file *m) -{ - int i, sum; - - seq_printf(m, "SODI3_count= %llu\n", SODI3_count); - seq_printf(m, "noValid_count %llu, %d%%\n", - noValid_count, ((noValid_count * 100) / SODI3_count)); - seq_printf(m, "valid_count %llu, %d%%\n", - (SODI3_count - noValid_count), - (((SODI3_count - noValid_count) * 100) / SODI3_count)); - - sum = 0; - for (i = 0; i < NUM_TIME_TH; i++) - sum += latency_array[i][1]; - - seq_printf(m, "Valid count in latency_array = %d\n", sum); - - for (i = 0; i < NUM_TIME_TH; i++) { - if (i == 0) { - seq_printf(m, "Count valid latency between 0ms ~ %dms: %d, %d%%\n", - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else if (i == (NUM_TIME_TH - 1)) { - seq_printf(m, "Count valid others: %d, %d%%\n", - latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } else { - seq_printf(m, "Count valid latency between %dms ~ %dms: %d, %d%%\n", - latency_array[i - 1][0], - latency_array[i][0], latency_array[i][1], - ((latency_array[i][1] * 100) / sum)); - } - } - - /* count if start_timestamp is bigger than end_timestamp */ - seq_printf(m, "diff_error_count= %d\n", diff_error_count); - seq_printf(m, "Current start_timestamp= %lldus\n", start_timestamp); - seq_printf(m, "Current end_timestamp= %lldus\n", end_timestamp); - seq_printf(m, "Current time_diff= %lldus\n", time_diff); -} - -static void lvts_count_valid_temp_latency(long long time_diff) -{ - /* time_diff is in microseconds */ - int i; - - for (i = 0; i < (NUM_TIME_TH - 1); i++) { - if (time_diff < (((long long)latency_array[i][0]) - * 1000)) { - latency_array[i][1]++; - break; - } - } - - if (i == (NUM_TIME_TH - 1)) - latency_array[i][1]++; -} -#endif - - -static int lvts_read_tc_raw_and_temp( - u32 *tempmsr_name, enum lvts_sensor_enum ts_name) -{ - int temp = 0, raw = 0, raw1 = 0, raw2 = 0; - - if (thermal_base == 0) - return 0; - - if (tempmsr_name == 0) - return 0; - - raw = readl((tempmsr_name)); - raw1 = (raw & 0x10000) >> 16; //bit 16 : valid bit - raw2 = raw & 0xFFFF; - temp = lvts_raw_to_temp(raw2, ts_name); - - if (raw2 == 0) { - /* 26111 is magic num - * this is to keep system alive for a while - * to wait HW init done, - * because 0 msr raw will translates to 28x'C - * and then 28x'C will trigger a SW reset. - * - * if HW init finish, this msr raw will not be 0, - * system can report normal temperature. - * if wait over 60 times zero, this means something - * wrong with HW, must trigger BUG on and dump useful - * register for debug. - */ - - temp = 26111; - } - - - if (lvts_rawdata_debug_log) { - lvts_printk( - "[LVTS_MSR] ts%d msr_all=%x, valid=%d, msr_temp=%d, temp=%d\n", - ts_name, raw, raw1, raw2, temp); - } - - tscpu_ts_lvts_temp_r[ts_name] = raw2; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_lvts_temp_v[ts_name] = raw1; -#endif -#if LVTS_VALID_DATA_TIME_PROFILING - if (isTempValid == 0 && raw1 != 0 && SODI3_count != 0) { - isTempValid = 1; - end_timestamp = thermal_get_current_time_us(); - time_diff = end_timestamp - start_timestamp; - if (time_diff < 0) { - lvts_printk("[LVTS_ERROR] time_diff = %lldus,start_time= %lldus, end_time= %lldus\n", - time_diff, start_timestamp, end_timestamp); - diff_error_count++; - } else { - lvts_count_valid_temp_latency(time_diff); - } - } -#endif - - return temp; -} - -static void lvts_tscpu_thermal_read_tc_temp( - int tc_num, enum lvts_sensor_enum type, int order) -{ - __u32 offset; - - if (tc_num < ARRAY_SIZE(lvts_tscpu_g_tc) && (tc_num >= 0)) { - offset = lvts_tscpu_g_tc[tc_num].tc_offset; - - if (lvts_rawdata_debug_log) - dump_lvts_device(tc_num, offset); - - switch (order) { - case 0: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 1: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR1_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 2: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR2_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - case 3: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR3_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - default: - tscpu_ts_lvts_temp[type] = - lvts_read_tc_raw_and_temp((offset + LVTSMSR0_0), type); - lvts_dbg_printk( - "%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_lvts_temp[type]); - break; - } - } else - pr_notice("Error: %d wrong tc_num value: %d\n", - __LINE__, tc_num); - -} - -void read_all_tc_lvts_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) - lvts_tscpu_thermal_read_tc_temp(i, - lvts_tscpu_g_tc[i].ts[j], j); -} - -/* pause ALL periodoc temperature sensing point */ -void lvts_pause_all_sensing_points(void) -{ - int i, temp, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel_print((temp | 0x10E), - offset + LVTSMSRCTL1_0); - } -} - -/* - * lvts_thermal_check_all_sensing_point_idle - - * Check if all sensing points are idle - * Return: 0 if all sensing points are idle - * an error code if one of them is busy - * error code[31:16]: an index of LVTS thermal controller - * error code[2]: bit 10 of LVTSMSRCTL1 - * error code[1]: bit 7 of LVTSMSRCTL1 - * error code[0]: bit 0 of LVTSMSRCTL1 - */ -static int lvts_thermal_check_all_sensing_point_idle(void) -{ - int i, temp, offset, error_code; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* Check if bit10=bit7=bit0=0 */ - if ((temp & 0x481) != 0) { - error_code = (i << 16) + ((temp & _BIT_(10)) >> 8) + - ((temp & _BIT_(7)) >> 6) + - (temp & _BIT_(0)); - - return error_code; - } - } - - return 0; -} - -void lvts_wait_for_all_sensing_point_idle(void) -{ - int cnt, temp; - - cnt = 0; - /* - * Wait until all sensoring points idled. - * No need to check LVTS status when suspend/resume, - * this will spend extra 100us of suspend flow. - * LVTS status will be reset after resume. - */ - while (cnt < 50 && (tscpu_kernel_status() == 0)) { - temp = lvts_thermal_check_all_sensing_point_idle(); - if (temp == 0) - break; - - if ((cnt + 1) % 10 == 0) { - pr_notice("Cnt= %d LVTS TC %d, LVTSMSRCTL1[10,7,0] = %d,%d,%d, LVTSMSRCTL1[10:0] = 0x%x\n", - cnt + 1, (temp >> 16), - ((temp & _BIT_(2)) >> 2), - ((temp & _BIT_(1)) >> 1), - (temp & _BIT_(0)), - (temp & _BITMASK_(10:0))); - } - - udelay(2); - cnt++; - } -} -/* release ALL periodoc temperature sensing point */ -void lvts_release_all_sensing_points(void) -{ - int i = 0, temp; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(((temp & (~0x10E))), - offset + LVTSMSRCTL1_0); - } -} - -void lvts_sodi3_release_thermal_controller(void) -{ - /* SPM will close 26M to saving power during SODI3 - * Because both auxadc thermal controllers and lvts thermal controllers - * need 26M to work properly, it would cause thermal controllers to - * report an abnormal high or low temperature after leaving SODI3 - * - * The SW workaround solution is that - * SPM will pause LVTS thermal controllers before closing 26M, and - * try to release LVTS thermal controllers after leaving SODI3 - * thermal driver check and release LVTS thermal controllers if - * necessary after leaving SODI3 - */ - int i = 0, temp, lvts_paused = 0; - __u32 offset; - - lvts_dbg_printk("%s\n", __func__); - - /*don't need to do release LVTS when suspend/resume*/ - if (tscpu_kernel_status() == 0) { - - /* Check if SPM paused thermal controller */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - temp = readl(offset + LVTSMSRCTL1_0); - /* set bit8=bit1=bit2=bit3=1 to pause - *sensing point 0,1,2,3 - */ - if ((temp & 0x10E) != 0) { - lvts_paused = 1; - pr_notice_ratelimited( - "lvts_paused = %d\n", lvts_paused); - break; - } - } - - /* Return if SPM didn't pause thermal controller or - * released thermal controllers already - */ - if (lvts_paused == 0) - return; - /* Wait until all of LVTS thermal controllers are idle - * Pause operation has to take time to finish. - * if it didn't finish before SPM closed 26M, we have to wait - * until it is finished to make sure all LVTS thermal - * controllers in a correct finite state machine - */ - - lvts_wait_for_all_sensing_point_idle(); - - lvts_release_all_sensing_points(); - } -} - -/* - * disable ALL periodoc temperature sensing point - */ -void lvts_disable_all_sensing_points(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel_print(0x00000000, offset + LVTSMONCTL0_0); - } -} - -void lvts_enable_all_sensing_points(void) -{ - int i, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - - offset = lvts_tscpu_g_tc[i].tc_offset; - - lvts_dbg_printk("%s %d:%d\n", __func__, i, - lvts_tscpu_g_tc[i].ts_number); - - switch (lvts_tscpu_g_tc[i].ts_number) { - case 1: - /* enable sensing point 0 */ - mt_reg_sync_writel_print(0x00000201, - offset + LVTSMONCTL0_0); - break; - case 2: - /* enable sensing point 0,1 */ - mt_reg_sync_writel_print(0x00000203, - offset + LVTSMONCTL0_0); - break; - case 3: - /* enable sensing point 0,1,2 */ - mt_reg_sync_writel_print(0x00000207, - offset + LVTSMONCTL0_0); - break; - case 4: - /* enable sensing point 0,1,2,3*/ - mt_reg_sync_writel_print(0x0000020F, - offset + LVTSMONCTL0_0); - break; - default: - lvts_printk("Error at %s\n", __func__); - break; - } - } -} - -void lvts_tscpu_thermal_initial_all_tc(void) -{ - int i = 0, offset; - - lvts_dbg_printk("%s\n", __func__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - offset = lvts_tscpu_g_tc[i].tc_offset; - - /* set sensor index of LVTS */ - mt_reg_sync_writel_print(0x13121110, LVTSTSSEL_0 + offset); - /* set calculation scale rules */ - mt_reg_sync_writel_print(0x00000300, LVTSCALSCALE_0 + offset); - /* Set Device Single mode */ - lvts_write_device(0x81030000, 0x06, 0xB8, i); - - lvts_configure_polling_speed_and_filter(i); - } - -#if DUMP_LVTS_REGISTER_FOR_ZERO_RAW_ISSUE - read_controller_reg_before_active(); -#endif -} - -static void lvts_disable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_DIS, WD_REQ_RST_MODE); - - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -static void lvts_enable_rgu_reset(void) -{ - struct wd_api *wd_api; - - if (get_wd_api(&wd_api) >= 0) { - /* reset mode */ - wd_api->wd_thermal_direct_mode_config( - WD_REQ_EN, WD_REQ_RST_MODE); - } else { - lvts_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void lvts_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - - lvts_dbg_printk("%s, temperature=%d,temperature2=%d,\n", - __func__, temperature, temperature2); - - /*spend 860~1463 us */ - /*Thermal need to config to direct reset mode - *this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - lvts_set_tc_trigger_hw_protect(temperature, temperature2, i); - } - -#ifndef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - lvts_enable_rgu_reset(); -#else - hw_protect_setting_done = 1; -#endif -} - -void lvts_tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - int temp2 = 0; - - lvts_dbg_printk("%s\n", __func__); - - /* reset AP thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel_print(temp, INFRA_GLOBALCON_RST_0_CLR); - - - - - /* reset MCU thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_SET); - - /* 1: Enables thermal control software reset */ - temp2 |= 0x00000400; - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp2 = readl(INFRA_GLOBALCON_RST_4_CLR); - - /* 1: Enable reset Disables thermal control software reset */ - temp2 |= 0x00000400; - - mt_reg_sync_writel_print(temp2, INFRA_GLOBALCON_RST_4_CLR); -} - - -void get_lvts_slope_intercept(struct TS_PTPOD *ts_info, enum - thermal_bank_name ts_bank) -{ - struct TS_PTPOD ts_ptpod; - int temp; - - lvts_dbg_printk("%s\n", __func__); - - /* chip dependent */ - - temp = (0 - LVTS_COEFF_A_X_1000) * 2; - temp /= 1000; - ts_ptpod.ts_MTS = temp; - - temp = 500 * g_golden_temp + LVTS_COEFF_B_X_1000; - temp /= 1000; - ts_ptpod.ts_BTS = (temp - 25) * 4; - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - lvts_dbg_printk("(LVTS) ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_lvts_slope_intercept); - -int lvts_tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "lvts_cal : %d\n", g_use_fake_efuse?0:1); - seq_printf(m, "[lvts_cal] g_golden_temp %d\n", g_golden_temp); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_r%d = 0x%x\n", - i, g_count_r[i]); - - for (i = 0; i < L_TS_LVTS_NUM; i++) - seq_printf(m, "[lvts_cal] g_count_rc%d = 0x%x\n", - i, g_count_rc[i]); - - return 0; -} - -#ifdef CONFIG_LVTS_DYNAMIC_ENABLE_REBOOT -void lvts_enable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !hw_protect_setting_done - || lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, done=%d, en=%d\n", - __func__, tscpu_is_temp_valid(), - hw_protect_setting_done, lvts_hw_protect_enabled); - return; - } - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) | 0x80000000, - offset + LVTSMONINT_0); - } - - lvts_enable_rgu_reset(); - - /* clear offset after all HW reset are configured. */ - /* make sure LVTS controller uses latest sensor value to compare */ - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* clear offset */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) & ~0xFFFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 1; - - lvts_printk("%s: done\n", __func__); -} - -void lvts_disable_all_hw_protect(void) -{ - int i, offset; - - if (!tscpu_is_temp_valid() || !lvts_hw_protect_enabled) { - lvts_dbg_printk("%s: skip, valid=%d, en=%d\n", __func__, - tscpu_is_temp_valid(), lvts_hw_protect_enabled); - return; - } - - lvts_disable_rgu_reset(); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - if (lvts_tscpu_g_tc[i].ts_number == 0) - continue; - - offset = lvts_tscpu_g_tc[i].tc_offset; - /* disable trigger SPM interrupt */ - mt_reg_sync_writel_print( - readl(offset + LVTSMONINT_0) & 0x7FFFFFFF, - offset + LVTSMONINT_0); - /* set offset to 0x3FFF to avoid interrupt false triggered */ - /* large offset can guarantee temp check is always false */ - mt_reg_sync_writel_print( - readl(offset + LVTSPROTCTL_0) | 0x3FFF, - offset + LVTSPROTCTL_0); - } - - lvts_hw_protect_enabled = 0; - - lvts_printk("%s: done\n", __func__); -} -#endif - diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_pmic_efuse.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_pmic_efuse.c deleted file mode 100644 index 966d39c906f8..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_pmic_efuse.c +++ /dev/null @@ -1,823 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include -#include -#include -#include - -#if defined(THERMAL_USE_IIO_CHANNEL) -#include -#include -#endif -/*============================================================= - *Local variable definition - *============================================================= - */ -int mtktspmic_debug_log; -/* Cali */ -static __s32 g_o_vts; -static __s32 g_o_vts_2; -static __s32 g_o_vts_3; -static __s32 g_o_vts_4; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; -static __s32 g_slope1 = 1; -static __s32 g_slope2 = 1; -static __s32 g_intercept; -static __s32 g_tsbuck1_slope1 = 1; -static __s32 g_tsbuck1_slope2 = 1; -static __s32 g_tsbuck1_intercept; -static __s32 g_tsbuck2_slope1 = 1; -static __s32 g_tsbuck2_slope2 = 1; -static __s32 g_tsbuck2_intercept; -static __s32 g_tsbuck3_slope1 = 1; -static __s32 g_tsbuck3_slope2 = 1; -static __s32 g_tsbuck3_intercept; - -static DEFINE_MUTEX(TSPMIC_lock); -static int pre_temp1 = 0, PMIC_counter; -static int pre_tsbuck1_temp1 = 0, tsbuck1_cnt; -static int pre_tsbuck2_temp1 = 0, tsbuck2_cnt; -static int pre_tsbuck3_temp1 = 0, tsbuck3_cnt; -static int pre_tstsx_temp1 = 0, tstsx_cnt; -static int pre_tsdcxo_temp1 = 0, tsdcxo_cnt; - -#if defined(THERMAL_USE_IIO_CHANNEL) -struct iio_channel *chan_chip_temp; -struct iio_channel *chan_vcore_temp; -struct iio_channel *chan_vproc_temp; -struct iio_channel *chan_vgpu_temp; -struct iio_channel *chan_tsx_temp; -struct iio_channel *chan_dcxo_temp; -#endif -/*=============================================================*/ - -static __s32 pmic_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck1_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck1_intercept + - ((g_tsbuck1_slope1 * y_curr) / (g_tsbuck1_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck2_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck2_intercept + - ((g_tsbuck2_slope1 * y_curr) / (g_tsbuck2_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static __s32 tsbuck3_raw_to_temp(__u32 ret) -{ - __s32 t_current; - - __s32 y_curr = ret; - - t_current = g_tsbuck3_intercept + - ((g_tsbuck3_slope1 * y_curr) / (g_tsbuck3_slope2)); - - mtktspmic_dprintk("[%s] t_current=%d\n", __func__, t_current); - return t_current; -} - -static void mtktspmic_read_efuse(void) -{ - mtktspmic_info("[pmic_debug] start\n"); - /* MT6359 */ - g_o_vts = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS); - g_o_vts_2 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_2); - g_o_vts_3 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_3); - g_o_vts_4 = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_VTS_4); - g_degc_cali = pmic_get_register_value(PMIC_AUXADC_EFUSE_DEGC_CALI); - g_adc_cali_en = pmic_get_register_value(PMIC_AUXADC_EFUSE_ADC_CALI_EN); - g_o_slope_sign = - pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE_SIGN); - g_o_slope = pmic_get_register_value(PMIC_AUXADC_EFUSE_O_SLOPE); - g_id = pmic_get_register_value(PMIC_AUXADC_EFUSE_ID); - - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts = %d\n", - g_o_vts); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_2 = %d\n", - g_o_vts_2); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_3 = %d\n", - g_o_vts_3); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_vts_4 = %d\n", - g_o_vts_4); - mtktspmic_info("[pmic_debug] 6359_efuse: g_degc_cali = %d\n", - g_degc_cali); - mtktspmic_info("[pmic_debug] 6359_efuse: g_adc_cali_en = %d\n", - g_adc_cali_en); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope_sign = %d\n", - g_o_slope_sign); - mtktspmic_info("[pmic_debug] 6359_efuse: g_o_slope = %d\n", - g_o_slope); - mtktspmic_info("[pmic_debug] 6359_efuse: g_id = %d\n", - g_id); - - mtktspmic_info("[pmic_debug] end\n"); -} - -void mtktspmic_cali_prepare(void) -{ - mtktspmic_read_efuse(); - - if (g_id == 0) - g_o_slope = 0; - - /* g_adc_cali_en=0;//FIX ME */ - - if (g_adc_cali_en == 0) { /* no calibration */ - mtktspmic_info("[pmic_debug] It isn't calibration values\n"); - g_o_vts = 1600; - g_o_vts_2 = 1600; - g_o_vts_3 = 1600; - g_o_vts_4 = 1600; - g_degc_cali = 50; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - if (g_degc_cali < 38 || g_degc_cali > 60) - g_degc_cali = 53; - - mtktspmic_info("[pmic_debug] g_o_vts = 0x%x\n", g_o_vts); - mtktspmic_info("[pmic_debug] g_o_vts_2 = 0x%x\n", g_o_vts_2); - mtktspmic_info("[pmic_debug] g_o_vts_3 = 0x%x\n", g_o_vts_3); - mtktspmic_info("[pmic_debug] g_o_vts_4 = 0x%x\n", g_o_vts_4); - mtktspmic_info("[pmic_debug] g_degc_cali = 0x%x\n", g_degc_cali); - mtktspmic_info("[pmic_debug] g_adc_cali_en = 0x%x\n", g_adc_cali_en); - mtktspmic_info("[pmic_debug] g_o_slope = 0x%x\n", g_o_slope); - mtktspmic_info("[pmic_debug] g_o_slope_sign = 0x%x\n", g_o_slope_sign); - mtktspmic_info("[pmic_debug] g_id = 0x%x\n", g_id); - -} - -void mtktspmic_cali_prepare2(void) -{ - __s32 vbe_t; - int factor; - - factor = 1681; - - g_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_slope2 = -(factor + g_o_slope); - else - g_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_intercept = (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_intercept = (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_intercept = g_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_slope1, g_slope2, g_intercept, vbe_t); - - factor = 1863; - - g_tsbuck1_slope1 = (100 * 1000 * 10); /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck1_slope2 = -(factor + g_o_slope); - else - g_tsbuck1_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_2) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck1_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck1_intercept = g_tsbuck1_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck1_slope1, g_tsbuck1_slope2, g_tsbuck1_intercept, vbe_t); - - factor = 1863; - - g_tsbuck2_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck2_slope2 = -(factor + g_o_slope); - else - g_tsbuck2_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_3) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck2_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck2_intercept = g_tsbuck2_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck2_slope1, g_tsbuck2_slope2, g_tsbuck2_intercept, vbe_t); - - factor = 1863; - - g_tsbuck3_slope1 = (100 * 1000 * 10); - /* 1000 is for 0.001 degree */ - - if (g_o_slope_sign == 0) - g_tsbuck3_slope2 = -(factor + g_o_slope); - else - g_tsbuck3_slope2 = -(factor - g_o_slope); - - vbe_t = (-1) * ((((g_o_vts_4) * 1800)) / 4096) * 1000; - - if (g_o_slope_sign == 0) - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor + g_o_slope * 10)); - /*0.001 degree */ - else - g_tsbuck3_intercept = - (vbe_t * 1000) / (-(factor - g_o_slope * 10)); - /*0.001 degree */ - - g_tsbuck3_intercept = g_tsbuck3_intercept + (g_degc_cali * (1000 / 2)); - /* 1000 is for 0.1 degree */ - - mtktspmic_info( - "[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n", - g_tsbuck3_slope1, g_tsbuck3_slope2, g_tsbuck3_intercept, vbe_t); - -} - -#if defined(THERMAL_USE_IIO_CHANNEL) -void mtktspmic_get_from_dts(struct platform_device *pdev) -{ - int ret; - - chan_chip_temp = iio_channel_get(NULL, "AUXADC_CHIP_TEMP"); - if (IS_ERR(chan_chip_temp)) { - ret = PTR_ERR(chan_chip_temp); - pr_notice("AUXADC_CHIP_TEMP get fail, ret=%d\n", ret); - } - - chan_vcore_temp = iio_channel_get(NULL, "AUXADC_VCORE_TEMP"); - if (IS_ERR(chan_vcore_temp)) { - ret = PTR_ERR(chan_vcore_temp); - pr_notice("AUXADC_VCORE_TEMP get fail, ret=%d\n", ret); - } - - chan_vproc_temp = iio_channel_get(NULL, "AUXADC_VPROC_TEMP"); - if (IS_ERR(chan_vproc_temp)) { - ret = PTR_ERR(chan_vproc_temp); - pr_notice("AUXADC_VPROC_TEMP get fail, ret=%d\n", ret); - } - - chan_vgpu_temp = iio_channel_get(NULL, "AUXADC_VGPU_TEMP"); - if (IS_ERR(chan_vgpu_temp)) { - ret = PTR_ERR(chan_vgpu_temp); - pr_notice("AUXADC_VGPU_TEMP get fail, ret=%d\n", ret); - } - - chan_tsx_temp = iio_channel_get(NULL, "AUXADC_TSX_TEMP"); - if (IS_ERR(chan_tsx_temp)) { - ret = PTR_ERR(chan_tsx_temp); - pr_notice("AUXADC_TSX_TEMP get fail, ret=%d\n", ret); - } - - chan_dcxo_temp = iio_channel_get(NULL, "AUXADC_DCXO_TEMP"); - if (IS_ERR(chan_dcxo_temp)) { - ret = PTR_ERR(chan_dcxo_temp); - pr_notice("AUXADC_DCXO_TEMP get fail, ret=%d\n", ret); - } -} -#endif - -int mtktspmic_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_chip_temp)) { - ret = iio_read_channel_processed(chan_chip_temp, &temp); - if (ret < 0) - pr_notice("pmic_chip_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_CHIP_TEMP); -#endif - temp1 = pmic_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("[pmic_debug] Raw=%d, T=%d\n", temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("[%s] raw=%d, PMIC T=%d", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("[%s] temp(%d) too high, drop this data!\n", - __func__, temp1); - temp1 = pre_temp1; - } else if ((PMIC_counter != 0) - && (((pre_temp1 - temp1) > 30000) - || ((temp1 - pre_temp1) > 30000))) { - mtktspmic_info("[%s] temp diff too large, drop this data\n", - __func__); - temp1 = pre_temp1; - } else { - /* update previous temp */ - pre_temp1 = temp1; - mtktspmic_dprintk("[%s] pre_temp1=%d\n", __func__, pre_temp1); - - if (PMIC_counter == 0) - PMIC_counter++; - } - - - return temp1; -} - -int mt6359vcore_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vcore_temp)) { - ret = iio_read_channel_processed(chan_vcore_temp, &temp); - if (ret < 0) - pr_notice("pmic_vcore_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VCORE_TEMP); -#endif - temp1 = tsbuck1_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck1_temp1; - } else if ((tsbuck1_cnt != 0) - && (((pre_tsbuck1_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck1_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck1_temp1; - } else { - /* update previous temp */ - pre_tsbuck1_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck1_temp1=%d\n", __func__, - pre_tsbuck1_temp1); - - if (tsbuck1_cnt == 0) - tsbuck1_cnt++; - } - - return temp1; -} - -int mt6359vproc_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vproc_temp)) { - ret = iio_read_channel_processed(chan_vproc_temp, &temp); - if (ret < 0) - pr_notice("pmic_vproc_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VPROC_TEMP); -#endif - temp1 = tsbuck2_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck2_temp1; - } else if ((tsbuck2_cnt != 0) - && (((pre_tsbuck2_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck2_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck2_temp1; - } else { - /* update previous temp */ - pre_tsbuck2_temp1 = temp1; - mtktspmic_dprintk("%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck2_temp1); - - if (tsbuck2_cnt == 0) - tsbuck2_cnt++; - } - - return temp1; -} - -int mt6359vgpu_get_hw_temp(void) -{ - int temp = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_vgpu_temp)) { - ret = iio_read_channel_processed(chan_vgpu_temp, &temp); - if (ret < 0) - pr_notice("pmic_vgpu_temp read fail, ret=%d\n", ret); - } -#else - temp = pmic_get_auxadc_value(AUXADC_LIST_VGPU_TEMP); -#endif - temp1 = tsbuck3_raw_to_temp(temp); - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, temp, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsbuck3_temp1; - } else if ((tsbuck3_cnt != 0) - && (((pre_tsbuck3_temp1 - temp1) > 30000) - || ((temp1 - pre_tsbuck3_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsbuck3_temp1; - } else { - /* update previous temp */ - pre_tsbuck3_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsbuck2_temp1=%d\n", __func__, - pre_tsbuck3_temp1); - - if (tsbuck3_cnt == 0) - tsbuck3_cnt++; - } - - return temp1; -} - -static int u_table[126] = { - 64078, - 63972, - 63860, - 63741, - 63614, - 63480, - 63338, - 63188, - 63029, - 62860, - 62683, - 62495, - 62297, - 62089, - 61870, - 61639, - 61396, - 61140, - 60872, - 60591, - 60297, - 59989, - 59667, - 59330, - 58978, - 58612, - 58230, - 57833, - 57420, - 56991, - 56546, - 56083, - 55605, - 55110, - 54598, - 54071, - 53528, - 52968, - 52393, - 51802, - 51195, - 50573, - 49936, - 49285, - 48620, - 47942, - 47251, - 46548, - 45834, - 45110, - 44375, - 43632, - 42880, - 42121, - 41355, - 40584, - 39808, - 39027, - 38245, - 37460, - 36675, - 35891, - 35106, - 34323, - 33543, - 32768, - 31996, - 31229, - 30469, - 29716, - 28968, - 28231, - 27502, - 26780, - 26070, - 25371, - 24683, - 24004, - 23339, - 22682, - 22042, - 21412, - 20795, - 20191, - 19600, - 19023, - 18458, - 17908, - 17369, - 16846, - 16331, - 15834, - 15347, - 14878, - 14415, - 13969, - 13535, - 13111, - 12701, - 12302, - 11914, - 11539, - 11176, - 10822, - 10482, - 10147, - 9827, - 9517, - 9214, - 8922, - 8637, - 8364, - 8098, - 7840, - 7590, - 7354, - 7120, - 6896, - 6674, - 6467, - 6264, - 6065, - 5876, - 5691, - 5510, - 5339 -}; -#define MIN_TSX_TEMP (-40000) -#define MAX_TSX_TEMP (+85000) -/* Original formula is - * u = auxadc raw * 2^16 / (2^32 - 1) - * Because kernel is not able to deal with floating point - * we changed the formula to - * u = auxadc raw * 2^16 / 2^32 - * => u = auxadc raw / 2^16 - * => u * 2^16 = auxadc raw - */ - -static int tsx_u2t(int auxadc_raw) -{ - int i; - int ret = 0; - int u_upper, u_low, t_upper, t_low; - - if (auxadc_raw > u_table[0]) - return (int) MIN_TSX_TEMP; - if (auxadc_raw < u_table[125]) - return (int) MAX_TSX_TEMP; - - for (i = 0; i < 125; i++) { - if (auxadc_raw < u_table[i] && auxadc_raw >= u_table[i+1]) { - u_upper = u_table[i+1]; - u_low = u_table[i]; - - t_upper = (int) MIN_TSX_TEMP + (i+1) * 1000; - t_low = (int) MIN_TSX_TEMP + i * 1000; - - if ((u_upper - u_low) == 0) - /* This case should not happen */ - ret = t_low; - else - ret = t_low + ((t_upper - t_low) * - (auxadc_raw - u_low)) / - (u_upper - u_low); - - break; - } - } - - return ret; -} - -int mt6359tsx_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_tsx_temp)) { - ret = iio_read_channel_raw(chan_tsx_temp, &raw); - if (ret < 0) - pr_notice("pmic_tsx_temp read fail, ret=%d\n", ret); - } - - temp1 = tsx_u2t(raw); -#else - temp1 = 25000; -#endif - - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tstsx_temp1; - } else if ((tstsx_cnt != 0) - && (((pre_tstsx_temp1 - temp1) > 30000) - || ((temp1 - pre_tstsx_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tstsx_temp1; - } else { - /* update previous temp */ - pre_tstsx_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_tsx_temp1=%d\n", __func__, - pre_tstsx_temp1); - - if (tstsx_cnt == 0) - tstsx_cnt++; - } - - return temp1; -} - -int mt6359dcxo_get_hw_temp(void) -{ - int raw = 0, temp1 = 0; -#if defined(THERMAL_USE_IIO_CHANNEL) - int ret; -#endif - - mutex_lock(&TSPMIC_lock); -#if defined(THERMAL_USE_IIO_CHANNEL) - if (!IS_ERR(chan_dcxo_temp)) { - ret = iio_read_channel_raw(chan_dcxo_temp, &raw); - if (ret < 0) - pr_notice("pmic_dcxo_temp read fail, ret=%d\n", ret); - } - - /* Temperature (C) = ((auxadc raw/32768*1.8)-0.545)/(-0.0017)+120 */ - /* From dcxo desiger John Chiang */ - temp1 = (((18000000/32768)*raw) - 5450000) / -17 + 120000; - - if (temp1 < -40000) - temp1 = -40000; - else if (temp1 > 120000) - temp1 = 120000; -#else - temp1 = 25000; -#endif - mutex_unlock(&TSPMIC_lock); - - mtktspmic_dprintk("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 100000) || (temp1 < -30000)) - mtktspmic_info("%s raw=%d T=%d\n", __func__, raw, temp1); - - if ((temp1 > 150000) || (temp1 < -50000)) { - mtktspmic_info("%s T=%d too high, drop it!\n", __func__, - temp1); - temp1 = pre_tsdcxo_temp1; - } else if ((tsdcxo_cnt != 0) - && (((pre_tsdcxo_temp1 - temp1) > 30000) - || ((temp1 - pre_tsdcxo_temp1) > 30000))) { - mtktspmic_info("%s delta temp too large, drop it!\n", __func__); - temp1 = pre_tsdcxo_temp1; - } else { - /* update previous temp */ - pre_tsdcxo_temp1 = temp1; - mtktspmic_dprintk( - "%s pre_dcxo_temp1=%d\n", __func__, - pre_tsdcxo_temp1); - - if (tsdcxo_cnt == 0) - tsdcxo_cnt++; - } - - return temp1; -} diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_tc.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_tc.c deleted file mode 100644 index 1a8ff31e3dcc..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_tc.c +++ /dev/null @@ -1,1489 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -/* #define DEBUG 1 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include "mach/mtk_thermal.h" -#include - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include - -#include - -#define __MT_MTK_TS_CPU_C__ -#include - -/* 1: turn on RT kthread for thermal protection in this sw module; - * 0: turn off - */ -#if MTK_TS_CPU_RT -#include -#include -#endif - -#ifdef CONFIG_OF -#include -#include -#include -#endif -#define __MT_MTK_TS_CPU_C__ - -#include -#include "mtk_thermal_ipi.h" -/*============================================================= - * Local variable definition - *============================================================= - */ - -/* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - -/* chip dependent */ -/* TODO: I assume AHB bus frequecy is 78MHz. Please confirm it. - */ -struct thermal_controller tscpu_g_tc[THERMAL_CONTROLLER_NUM] = { - [0] = { - .ts = {L_TS_MCU1, L_TS_MCU2, L_TS_MCU4, L_TS_ABB}, - .ts_number = 4, - .dominator_ts_idx = 2, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x0, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [1] = { - .ts = {L_TS_MCU5, L_TS_MCU6, L_TS_MCU7, L_TS_MCU0}, - .ts_number = 4, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x100, - .tc_speed = { - 0x00C, - 0x001, - 0x03B, - 0x0000030D - } /* 4.9ms */ - }, - [2] = { - .ts = {L_TS_MCU8, L_TS_MCU9}, - .ts_number = 2, - .dominator_ts_idx = 1, //hw protection ref TS (idx of .ts arr) - .tc_offset = 0x200, - .tc_speed = { - 0x00C, - 0x001, - 0x008, - 0x0000030D - } /* 1ms */ - } -}; - -#ifdef CONFIG_OF -const struct of_device_id mt_thermal_of_match[2] = { - {.compatible = "mediatek,therm_ctrl",}, - {}, -}; -#endif - -int tscpu_debug_log; - -#if MTK_TS_CPU_RT -static struct task_struct *ktp_thread_handle; -#endif - -static __s32 g_adc_ge_t; -static __s32 g_adc_oe_t; -static __s32 g_o_vtsmcu0; -static __s32 g_o_vtsmcu1; -static __s32 g_o_vtsmcu2; -/* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ -static __s32 g_o_vtsmcu4; -static __s32 g_o_vtsmcu5; -static __s32 g_o_vtsmcu6; -static __s32 g_o_vtsmcu7; -static __s32 g_o_vtsmcu8; -static __s32 g_o_vtsmcu9; -static __s32 g_o_vtsabb; -static __s32 g_degc_cali; -static __s32 g_adc_cali_en_t; -static __s32 g_o_slope; -static __s32 g_o_slope_sign; -static __s32 g_id; - -static __s32 g_ge; -static __s32 g_oe; -static __s32 g_gain; - -static __s32 g_x_roomt[L_TS_MCU_NUM] = { 0 }; - -/** - * curr_temp >= tscpu_polling_trip_temp1: - * polling interval = interval - * tscpu_polling_trip_temp1 > cur_temp >= tscpu_polling_trip_temp2: - * polling interval = interval * tscpu_polling_factor1 - * tscpu_polling_trip_temp2 > cur_temp: - * polling interval = interval * tscpu_polling_factor2 - */ -/* chip dependent */ -int tscpu_polling_trip_temp1 = 40000; -int tscpu_polling_trip_temp2 = 20000; -int tscpu_polling_factor1 = 1; -int tscpu_polling_factor2 = 4; - -#if MTKTSCPU_FAST_POLLING -/* Combined fast_polling_trip_temp and fast_polling_factor, - * it means polling_delay will be 1/5 of original interval - * after mtktscpu reports > 65C w/o exit point - */ -int fast_polling_trip_temp = 60000; -int fast_polling_trip_temp_high = 60000; /* deprecaed */ -int fast_polling_factor = 1; -int tscpu_cur_fp_factor = 1; -int tscpu_next_fp_factor = 1; -#endif - -/*============================================================= - * Local function declartation - *============================================================= - */ -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name); -static void set_tc_trigger_hw_protect - (int temperature, int temperature2, int tc_num); - -/*============================================================= - *Weak functions - *============================================================= - */ - void __attribute__ ((weak)) -mt_ptp_lock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - void __attribute__ ((weak)) -mt_ptp_unlock(unsigned long *flags) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); -} - - int __attribute__ ((weak)) -get_wd_api(struct wd_api **obj) -{ - pr_notice("[Power/CPU_Thermal]%s doesn't exist\n", __func__); - return -1; -} - -/*=============================================================*/ - -void get_thermal_slope_intercept(struct TS_PTPOD *ts_info, enum -thermal_bank_name ts_bank) -{ - unsigned int temp0, temp1, temp2; - struct TS_PTPOD ts_ptpod; - __s32 x_roomt; - - tscpu_dprintk("%s\n", __func__); - - /* chip dependent */ - - /* If there are two or more sensors in a bank, choose the sensor - * calibration value of the dominant sensor. You can observe it in the - * thermal document provided by Thermal DE. For example, Bank 1 is - * for SOC + GPU. Observe all scenarios related to GPU simulation test - * cases to decide which sensor is the highest temperature in all cases. - * Then, It is the dominant sensor.(Confirmed by Thermal DE Alfred Tsai) - */ - - /* - * PTP# module TSMCU Plan - * 0 MCU_LITTLE TSMCU-5,6,7 - * 1 MCU_BIG TSMCU-8,9 - * 2 MCU_CCI TSMCU-5,6,7 - * 3 MFG(GPU) TSMCU-1,2 - * 4 VPU TSMCU-4 - * No PTP bank 5 - * 6 TOP TSMCU-1,2,4 - * 7 MD TSMCU-0 - */ - - switch (ts_bank) { - case THERMAL_BANK0: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK1: - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - case THERMAL_BANK2: - x_roomt = g_x_roomt[L_TS_MCU6]; - break; - case THERMAL_BANK3: - x_roomt = g_x_roomt[L_TS_MCU2]; - break; - case THERMAL_BANK4: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - /* No bank 5 */ - case THERMAL_BANK6: - x_roomt = g_x_roomt[L_TS_MCU4]; - break; - case THERMAL_BANK7: - x_roomt = g_x_roomt[L_TS_MCU0]; - break; - default: /* choose the highest simulation hot-spot */ - x_roomt = g_x_roomt[L_TS_MCU9]; - break; - } - - - /* - * The equations in this function are confirmed by Thermal DE Alfred - * Tsai. Don't have to change until using next generation thermal - * sensors. - */ - - temp0 = (10000 * 100000 / g_gain) * 15 / 18; - - if (g_o_slope_sign == 0) - temp1 = (temp0 * 10) / (1534 + g_o_slope * 10); - else - temp1 = (temp0 * 10) / (1534 - g_o_slope * 10); - - ts_ptpod.ts_MTS = temp1; - - temp0 = (g_degc_cali * 10 / 2); - temp1 = - ((10000 * 100000 / 4096 / g_gain) * g_oe + x_roomt * 10) * 15 / 18; - - if (g_o_slope_sign == 0) - temp2 = temp1 * 100 / (1534 + g_o_slope * 10); - else - temp2 = temp1 * 100 / (1534 - g_o_slope * 10); - - ts_ptpod.ts_BTS = (temp0 + temp2 - 250) * 4 / 10; - - - ts_info->ts_MTS = ts_ptpod.ts_MTS; - ts_info->ts_BTS = ts_ptpod.ts_BTS; - tscpu_dprintk("ts_MTS=%d, ts_BTS=%d\n", - ts_ptpod.ts_MTS, ts_ptpod.ts_BTS); -} -EXPORT_SYMBOL(get_thermal_slope_intercept); - -/* chip dependent */ -void mtkts_dump_cali_info(void) -{ - tscpu_printk("[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - tscpu_printk("[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - tscpu_printk("[cal] g_degc_cali = %d\n", g_degc_cali); - tscpu_printk("[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - tscpu_printk("[cal] g_o_slope = %d\n", g_o_slope); - tscpu_printk("[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - tscpu_printk("[cal] g_id = %d\n", g_id); - - tscpu_printk("[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - tscpu_printk("[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - tscpu_printk("[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - tscpu_printk("[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - tscpu_printk("[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - tscpu_printk("[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - tscpu_printk("[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - tscpu_printk("[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - tscpu_printk("[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - tscpu_printk("[cal] g_o_vtsabb = %d\n", g_o_vtsabb); -} - -void eDataCorrector(void) -{ - - if (g_adc_ge_t < 265 || g_adc_ge_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_ge_t\n"); - g_adc_ge_t = 512; - } - if (g_adc_oe_t < 265 || g_adc_oe_t > 758) { - tscpu_warn("[thermal] Bad efuse data, g_adc_oe_t\n"); - g_adc_oe_t = 512; - } - if (g_o_vtsmcu0 < -8 || g_o_vtsmcu0 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu0 = 260; - } - if (g_o_vtsmcu1 < -8 || g_o_vtsmcu1 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu1\n"); - g_o_vtsmcu1 = 260; - } - if (g_o_vtsmcu2 < -8 || g_o_vtsmcu2 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu2\n"); - g_o_vtsmcu2 = 260; - } - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - if (g_o_vtsmcu4 < -8 || g_o_vtsmcu4 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu4\n"); - g_o_vtsmcu4 = 260; - } - if (g_o_vtsmcu5 < -8 || g_o_vtsmcu5 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu5\n"); - g_o_vtsmcu5 = 260; - } - if (g_o_vtsmcu6 < -8 || g_o_vtsmcu6 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu6\n"); - g_o_vtsmcu6 = 260; - } - if (g_o_vtsmcu7 < -8 || g_o_vtsmcu7 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu7\n"); - g_o_vtsmcu7 = 260; - } - if (g_o_vtsmcu8 < -8 || g_o_vtsmcu8 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu8 = 260; - } - if (g_o_vtsmcu9 < -8 || g_o_vtsmcu9 > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsmcu8\n"); - g_o_vtsmcu9 = 260; - } - if (g_o_vtsabb < -8 || g_o_vtsabb > 484) { - tscpu_warn("[thermal] Bad efuse data, g_o_vtsabb\n"); - g_o_vtsabb = 260; - } - if (g_degc_cali < 1 || g_degc_cali > 63) { - tscpu_warn("[thermal] Bad efuse data, g_degc_cali\n"); - g_degc_cali = 40; - } -} -void tscpu_thermal_cal_prepare(void) -{ - __u32 temp0, temp1, temp2, temp3, temp4; - - temp0 = get_devinfo_with_index(ADDRESS_INDEX_0); /* 0184 */ - temp1 = get_devinfo_with_index(ADDRESS_INDEX_1); /* 0180 */ - temp2 = get_devinfo_with_index(ADDRESS_INDEX_2); /* 0188 */ - temp3 = get_devinfo_with_index(ADDRESS_INDEX_3); /* 01AC */ - temp4 = get_devinfo_with_index(ADDRESS_INDEX_4); /* 01B0 */ - - pr_notice( - "[calibration] tmp0=0x%x, tmp1=0x%x, tmp2=0x%x\n", - temp0, temp1, temp2); - pr_notice( - "[calibration] tmp3=0x%x, tmp4=0x%x\n", - temp3, temp4); - - g_adc_ge_t = ((temp0 & _BITMASK_(31:22)) >> 22); - g_adc_oe_t = ((temp0 & _BITMASK_(21:12)) >> 12); - - - g_o_vtsmcu0 = ((temp1 & _BITMASK_(25:17)) >> 17); - g_o_vtsmcu1 = ((temp1 & _BITMASK_(16:8)) >> 8); - g_o_vtsmcu2 = (temp0 & _BITMASK_(8:0)); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = ((temp2 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu5 = ((temp2 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu6 = ((temp3 & _BITMASK_(31:23)) >> 23); - g_o_vtsmcu7 = ((temp3 & _BITMASK_(22:14)) >> 14); - g_o_vtsmcu8 = ((temp3 & _BITMASK_(13:5)) >> 5); - g_o_vtsmcu9 = ((temp4 & _BITMASK_(31:23)) >> 23); - g_o_vtsabb = ((temp2 & _BITMASK_(22:14)) >> 14); - - g_degc_cali = ((temp1 & _BITMASK_(6:1)) >> 1); - g_adc_cali_en_t = (temp1 & _BIT_(0)); - g_o_slope_sign = ((temp1 & _BIT_(7)) >> 7); - g_o_slope = ((temp1 & _BITMASK_(31:26)) >> 26); - - g_id = ((temp0 & _BIT_(9)) >> 9); - - if (g_id == 0) - g_o_slope = 0; - - if (g_adc_cali_en_t == 1) { - /*thermal_enable = true; */ - eDataCorrector(); - } else { - tscpu_warn("This sample is not Thermal calibrated\n"); - g_adc_ge_t = 512; - g_adc_oe_t = 512; - g_o_vtsmcu0 = 260; - g_o_vtsmcu1 = 260; - g_o_vtsmcu2 = 260; - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - g_o_vtsmcu4 = 260; - g_o_vtsmcu5 = 260; - g_o_vtsmcu6 = 260; - g_o_vtsmcu7 = 260; - g_o_vtsmcu8 = 260; - g_o_vtsmcu9 = 260; - g_o_vtsabb = 260; - g_degc_cali = 40; - g_o_slope_sign = 0; - g_o_slope = 0; - } - - mtkts_dump_cali_info(); -} - -void tscpu_thermal_cal_prepare_2(__u32 ret) -{ - __s32 format[L_TS_MCU_NUM] = { 0 }; - int i = 0; -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - struct thermal_ipi_data thermal_data; -#endif - - /* tscpu_printk("tscpu_thermal_cal_prepare_2\n"); */ - g_ge = ((g_adc_ge_t - 512) * 10000) / 4096; /* ge * 10000 */ - g_oe = (g_adc_oe_t - 512); - - g_gain = (10000 + g_ge); - - format[0] = (g_o_vtsmcu0 + 3350 - g_oe); - format[1] = (g_o_vtsmcu1 + 3350 - g_oe); - format[2] = (g_o_vtsmcu2 + 3350 - g_oe); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - format[3] = (g_o_vtsmcu4 + 3350 - g_oe); - format[4] = (g_o_vtsmcu5 + 3350 - g_oe); - format[5] = (g_o_vtsmcu6 + 3350 - g_oe); - format[6] = (g_o_vtsmcu7 + 3350 - g_oe); - format[7] = (g_o_vtsmcu8 + 3350 - g_oe); - format[8] = (g_o_vtsmcu9 + 3350 - g_oe); - format[9] = (g_o_vtsabb + 3350 - g_oe); - - for (i = 0; i < L_TS_MCU_NUM; i++) { - /* x_roomt * 10000 */ - g_x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / g_gain; - } - - tscpu_printk("[T_De][cal] g_ge = %d\n", g_ge); - tscpu_printk("[T_De][cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - tscpu_printk("[T_De][cal] g_x_roomt%d = %d\n", i, - g_x_roomt[i]); -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM - thermal_data.u.data.arg[0] = g_degc_cali; - thermal_data.u.data.arg[1] = g_o_slope_sign; - thermal_data.u.data.arg[2] = g_o_slope; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP1, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_oe; - thermal_data.u.data.arg[1] = g_gain; - thermal_data.u.data.arg[2] = g_x_roomt[L_TS_MCU8]; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP2, &thermal_data) != 0) - udelay(100); - - thermal_data.u.data.arg[0] = g_x_roomt[L_TS_MCU9]; - while (thermal_to_sspm(THERMAL_IPI_INIT_GRP3, &thermal_data) != 0) - udelay(100); -#endif -} - -#if THERMAL_CONTROLLER_HW_TP -static __s32 temperature_to_raw_room(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - /* Ycurr = [(Tcurr - DEGC_cali/2)*(1534+O_slope*10)/10*(18/15)* - * (1/10000)+X_roomtabb]*Gain*4096 + OE - */ - - __s32 t_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - - /* tscpu_dprintk("temperature_to_raw_room\n"); */ - - if (g_o_slope_sign == 0) { /* O_SLOPE is Positive. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 + g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } else { /* O_SLOPE is Negative. */ - format_1 = t_curr - (g_degc_cali * 1000 / 2); - format_2 = format_1 * (1534 - g_o_slope * 10) / 10 * 18 / 15; - format_2 = format_2 - 2 * format_2; - - format_3 = format_2 / 1000 + g_x_roomt[ts_name] * 10; - format_4 = (format_3 * 4096 / 10000 * g_gain) / 100000 + g_oe; - } - - return format_4; -} -#endif - -static __s32 raw_to_temperature_roomt(__u32 ret, enum tsmcu_sensor_enum ts_name) -{ - __s32 t_current = 0; - __s32 y_curr = ret; - __s32 format_1 = 0; - __s32 format_2 = 0; - __s32 format_3 = 0; - __s32 format_4 = 0; - __s32 xtoomt = 0; - - xtoomt = g_x_roomt[ts_name]; - - /* tscpu_dprintk("raw_to_temperature_room,ts_num=%d,xtoomt=%d\n", - * ts_name,xtoomt); - */ - - if (ret == 0) - return 0; - - format_1 = ((g_degc_cali * 10) >> 1); - format_2 = (y_curr - g_oe); - - format_3 = (((((format_2) * 10000) >> 12) * 10000) / g_gain) - xtoomt; - format_3 = format_3 * 15 / 18; - - - if (g_o_slope_sign == 0) /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 + g_o_slope * 10)); - else /* uint = 0.1 deg */ - format_4 = ((format_3 * 1000) / (1534 - g_o_slope * 10)); - - format_4 = format_4 - (format_4 << 1); - - t_current = format_1 + format_4; /* uint = 0.1 deg */ - - /* tscpu_dprintk("raw_to_temperature_room,t_current=%d\n",t_current); */ - return t_current; -} -static void thermal_dump_debug_logs(int tc_num) -{ - int offset; - unsigned int auxadc_data11, ts_con0, ts_con1; - unsigned int tempmsr0, tempmsr1, tempmsr2, tempmsr3; - - offset = tscpu_g_tc[tc_num].tc_offset; - - auxadc_data11 = readl(AUXADC_DAT11_V); - ts_con0 = readl(TS_CON0_TM); - ts_con1 = readl(TS_CON1_TM); - tempmsr0 = readl((offset + TEMPMSR0)); - tempmsr1 = readl((offset + TEMPMSR1)); - tempmsr2 = readl((offset + TEMPMSR2)); - tempmsr3 = readl((offset + TEMPMSR3)); - - tscpu_printk("AUXADC_DAT11 = 0x%x, TS_CON0 = 0x%x, TS_CON1 = 0x%x\n", - auxadc_data11, ts_con0, ts_con1); - tscpu_printk("TEMPMSR0_%d = 0x%x, TEMPMSR1_%d = 0x%x\n", - tc_num, tempmsr0, tc_num, tempmsr1); - tscpu_printk("TEMPMSR2_%d = 0x%x, TEMPMSR3_%d = 0x%x\n", - tc_num, tempmsr2, tc_num, tempmsr3); -} -static void thermal_interrupt_handler(int tc_num) -{ - unsigned int ret = 0; - int offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - ret = readl(offset + TEMPMONINTSTS); - /* Write back to clear interrupt status */ - mt_reg_sync_writel(ret, offset + TEMPMONINTSTS); - - tscpu_printk( - "[Thermal IRQ] Auxadc thermal_tc %d, TEMPMONINTSTS=0x%08x\n", - tc_num, ret); - - if (ret & THERMAL_COLD_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 0\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 0\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 0\n"); - - if (ret & THERMAL_COLD_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 1\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 1\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 1\n"); - - if (ret & THERMAL_COLD_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 2\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 2\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 2\n"); - - if (ret & THERMAL_AHB_TIMEOUT_INTERRUPT) - tscpu_dprintk( - "[Thermal IRQ]: AHB bus timeout triggered\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 0\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 1\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 2\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_0) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 0\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_1) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 1\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_2) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 2\n"); - - if (ret & THERMAL_COLD_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Cold int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot int triggered, sensor point 3\n"); - - if (ret & THERMAL_LOW_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Low offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HIGH_OFFSET_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: High offset int triggered, sensor point 3\n"); - - if (ret & THERMAL_HOT2NORMAL_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Hot2Normal int triggered, sensor point 3\n"); - - if (ret & THERMAL_IMMEDIATE_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Immediate int triggered, sensor point 3\n"); - - if (ret & THERMAL_FILTER_INTERRUPT_3) - tscpu_dprintk( - "[Thermal IRQ]: Filter int triggered, sensor point 3\n"); - - if (ret & THERMAL_PROTECTION_STAGE_1) - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 1 int triggered\n"); - - if (ret & THERMAL_PROTECTION_STAGE_2) { - tscpu_dprintk( - "[Thermal IRQ]: Thermal protection stage 2 int triggered\n"); -#if MTK_TS_CPU_RT - wake_up_process(ktp_thread_handle); -#endif - } - - if (ret & THERMAL_PROTECTION_STAGE_3) { - tscpu_printk( - "[Thermal IRQ]: Thermal protection stage 3 int triggered\n"); - tscpu_printk("[Thermal IRQ]: Thermal HW reboot!!"); - thermal_dump_debug_logs(tc_num); - } -} - -irqreturn_t tscpu_thermal_all_tc_interrupt_handler(int irq, void *dev_id) -{ - unsigned int ret = 0, i, mask = 1; - - ret = readl(THERMINTST); - ret = ret & 0x7F; - - /* MSB LSB NAME - * 6 6 LVTSINT3 - * 5 5 LVTSINT2 - * 4 4 LVTSINT1 - * 3 3 LVTSINT0 - * 2 2 THERMINT2 - * 1 1 THERMINT1 - * 0 0 THERMINT0 - */ - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - mask = 1 << i; - - if ((ret & mask) == 0) - thermal_interrupt_handler(i); - } - - return IRQ_HANDLED; -} - -static void thermal_reset_and_initial(int tc_num) -{ - unsigned int offset, tempMonCtl1, tempMonCtl2, tempAhbPoll; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tempMonCtl1 = (tscpu_g_tc[tc_num].tc_speed.period_unit & - _BITMASK_(9:0)); - - tempMonCtl2 = (((tscpu_g_tc[tc_num].tc_speed.filter_interval_delay - << 16) & _BITMASK_(25:16)) | - (tscpu_g_tc[tc_num].tc_speed.sensor_interval_delay & - _BITMASK_(9:0))); - - tempAhbPoll = tscpu_g_tc[tc_num].tc_speed.ahb_polling_interval; - - /* Calculating period unit in Module clock x 256, - * and the Module clock - * will be changed to 26M when Infrasys enters Sleep mode. - */ - - /* bus clock 66M counting unit is 12 * 1/66M * 256 = - * 12 * 3.879us = 46.545 us - */ - mt_reg_sync_writel(tempMonCtl1, offset + TEMPMONCTL1); - /* - * filt interval is 1 * 46.545us = 46.545us, - * sen interval is 429 * 46.545us = 19.968ms - */ - mt_reg_sync_writel(tempMonCtl2, offset + TEMPMONCTL2); - /* AHB polling is 781* 1/66M = 11.833us */ - mt_reg_sync_writel(tempAhbPoll, offset + TEMPAHBPOLL); - -#if THERMAL_CONTROLLER_HW_FILTER == 2 - /* temperature sampling control, 2 out of 4 samples */ - mt_reg_sync_writel(0x00000492, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 4 - /* temperature sampling control, 4 out of 6 samples */ - mt_reg_sync_writel(0x000006DB, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 8 - /* temperature sampling control, 8 out of 10 samples */ - mt_reg_sync_writel(0x00000924, offset + TEMPMSRCTL0); -#elif THERMAL_CONTROLLER_HW_FILTER == 16 - /* temperature sampling control, 16 out of 18 samples */ - mt_reg_sync_writel(0x00000B6D, offset + TEMPMSRCTL0); -#else /* default 1 */ - /* temperature sampling control, 1 sample */ - mt_reg_sync_writel(0x00000000, offset + TEMPMSRCTL0); -#endif - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0xFFFFFFFF, offset + TEMPAHBTO); - - /* times for interrupt occurrance for SP0*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - /* times for interrupt occurrance for SP1*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET2); - /* times for interrupt occurrance for SP2*/ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET3); - - mt_reg_sync_writel(0x800, offset + TEMPADCMUX); - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) AUXADC_CON1_CLR_P, - offset + TEMPADCMUXADDR); - - /* AHB value for auxadc enable */ - mt_reg_sync_writel(0x800, offset + TEMPADCEN); - - /* - * AHB address for auxadc enable (channel 0 immediate mode selected) - * this value will be stored to TEMPADCENADDR automatically by hw - */ - mt_reg_sync_writel((__u32) AUXADC_CON1_SET_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) AUXADC_DAT11_P, - offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); -} - -/** - * temperature2 to set the middle threshold for interrupting CPU. - * -275000 to disable it. - */ -static void set_tc_trigger_hw_protect -(int temperature, int temperature2, int tc_num) -{ - int temp = 0, raw_high, d_index, config; - enum tsmcu_sensor_enum ts_name; - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - /* temperature2=80000; test only */ - tscpu_dprintk("%s t1=%d t2=%d\n", __func__, temperature, - temperature2); - - if (tscpu_g_tc[tc_num].dominator_ts_idx < - tscpu_g_tc[tc_num].ts_number){ - d_index = tscpu_g_tc[tc_num].dominator_ts_idx; - } else { - tscpu_printk("Error: Auxadc TC%d, dominator_ts_idx = %d should smaller than ts_number = %d\n", - tc_num, - tscpu_g_tc[tc_num].dominator_ts_idx, - tscpu_g_tc[tc_num].ts_number); - - tscpu_printk("Use the sensor point 0 as the dominated sensor\n"); - d_index = 0; - } - - - ts_name = tscpu_g_tc[tc_num].ts[d_index]; - - /* temperature to trigger SPM state2 */ - if (tc_num == THERMAL_CONTROLLER2) - raw_high = temperature_to_raw_room(105000, ts_name); - else - raw_high = temperature_to_raw_room(temperature, ts_name); - - temp = readl(offset + TEMPMONINT); - /* disable trigger SPM interrupt */ - mt_reg_sync_writel(temp & 0x00000000, offset + TEMPMONINT); - - /* Select protection sensor */ - config = ((d_index << 2) + 0x2) << 16; - mt_reg_sync_writel(config, offset + TEMPPROTCTL); - - /* set hot to HOT wakeup event */ - mt_reg_sync_writel(raw_high, offset + TEMPPROTTC); - - /* enable trigger Hot SPM interrupt */ - mt_reg_sync_writel(temp | 0x80000000, offset + TEMPMONINT); -} - -static int read_tc_raw_and_temp( -u32 *tempmsr_name, enum tsmcu_sensor_enum ts_name) -{ - int temp = 0, raw = 0; -#if CONFIG_LVTS_ERROR_AEE_WARNING - int raw1; -#endif - - if (tempmsr_name == 0) - return 0; - -#if CONFIG_LVTS_ERROR_AEE_WARNING - raw = readl(tempmsr_name); - raw1 = ((raw & _BIT_(15)) >> 15); - raw = raw & 0xFFF; -#else - raw = readl(tempmsr_name) & 0xFFF; -#endif - temp = raw_to_temperature_roomt(raw, ts_name); - - tscpu_dprintk("read_tc_raw_temp,ts_raw=%d,temp=%d\n", raw, temp * 100); - tscpu_ts_mcu_temp_r[ts_name] = raw; -#if CONFIG_LVTS_ERROR_AEE_WARNING - tscpu_ts_mcu_temp_v[ts_name] = raw1; -#endif - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp_r[ts_name] = tscpu_ts_mcu_temp_r[ts_name]; -#endif - return temp * 100; -} - -void tscpu_thermal_read_tc_temp( -int tc_num, enum tsmcu_sensor_enum type, int order) -{ - __u32 offset; - - tscpu_dprintk("%s tc_num %d type %d order %d\n", __func__, - tc_num, type, order); - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (order) { - case 0: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 1: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR1), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 2: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR2), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - case 3: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR3), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - default: - tscpu_ts_mcu_temp[type] = - read_tc_raw_and_temp((offset + TEMPMSR0), type); - tscpu_dprintk("%s order %d tc_num %d type %d temp %d\n", - __func__, order, tc_num, type, - tscpu_ts_mcu_temp[type]); - break; - } - -#if CFG_THERM_LVTS == (0) - tscpu_ts_temp[type] = tscpu_ts_mcu_temp[type]; -#endif -} - -void read_all_tc_tsmcu_temperature(void) -{ - int i = 0, j = 0; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_read_tc_temp(i, tscpu_g_tc[i].ts[j], j); -} - -int tscpu_thermal_fast_init(int tc_num) -{ - __u32 temp = 0, cunt = 0, offset = 0; - - offset = tscpu_g_tc[tc_num].tc_offset; - - temp = THERMAL_INIT_VALUE; - - /* write temp to spare register */ - mt_reg_sync_writel((0x00001000 + temp), PTPSPARE2); - - /* counting unit is 320 * 31.25us = 10ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL1); - - /* sensing interval is 200 * 10ms = 2000ms */ - mt_reg_sync_writel(1, offset + TEMPMONCTL2); - - /* polling interval to check if temperature sense is ready */ - mt_reg_sync_writel(1, offset + TEMPAHBPOLL); - - /* exceed this polling time, IRQ would be inserted */ - mt_reg_sync_writel(0x000000FF, offset + TEMPAHBTO); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET0); - - /* times for interrupt occurrance */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONIDET1); - - /* temperature measurement sampling control */ - mt_reg_sync_writel(0x0000000, offset + TEMPMSRCTL0); - - /* this value will be stored to TEMPPNPMUXADDR (TEMPSPARE0) - * automatically by hw - */ - mt_reg_sync_writel(0x1, offset + TEMPADCPNP0); - mt_reg_sync_writel(0x2, offset + TEMPADCPNP1); - mt_reg_sync_writel(0x3, offset + TEMPADCPNP2); - mt_reg_sync_writel(0x4, offset + TEMPADCPNP3); - - /* AHB address for pnp sensor mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPPNPMUXADDR); - - /* AHB address for auxadc mux selection */ - mt_reg_sync_writel((__u32) PTPSPARE0_P, offset + TEMPADCMUXADDR); - - /* AHB address for auxadc enable */ - mt_reg_sync_writel((__u32) PTPSPARE1_P, offset + TEMPADCENADDR); - - /* AHB address for auxadc valid bit */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVALIDADDR); - - /* AHB address for auxadc voltage output */ - mt_reg_sync_writel((__u32) PTPSPARE2_P, offset + TEMPADCVOLTADDR); - - /* read valid & voltage are at the same register */ - mt_reg_sync_writel(0x0, offset + TEMPRDCTRL); - - /* indicate where the valid bit is (the 12th bit - * is valid bit and 1 is valid) - */ - mt_reg_sync_writel(0x0000002C, offset + TEMPADCVALIDMASK); - - /* do not need to shift */ - mt_reg_sync_writel(0x0, offset + TEMPADCVOLTAGESHIFT); - - /* enable auxadc mux & pnp write transaction */ - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - - - /* enable all interrupt except filter sense and - * immediate sense interrupt - */ - mt_reg_sync_writel(0x00000000, offset + TEMPMONINT); - - /* enable all sensing point(sensing point 2 is unused)*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - - - cunt = 0; - temp = readl(offset + TEMPMSR0) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]0 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR0) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR1) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]1 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR1) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR2) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]2 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR2) & 0x0fff; - } - - cunt = 0; - temp = readl(offset + TEMPMSR3) & 0x0fff; - while (temp != THERMAL_INIT_VALUE && cunt < 20) { - cunt++; - /* pr_notice("[Power/CPU_Thermal]3 temp=%d,cunt=%d\n", - * temp,cunt); - */ - temp = readl(offset + TEMPMSR3) & 0x0fff; - } - - return 0; -} - -int tscpu_thermal_ADCValueOfMcu(enum tsmcu_sensor_enum type) -{ - switch (type) { - case L_TS_MCU0: - return TEMPADC_MCU0; - case L_TS_MCU1: - return TEMPADC_MCU1; - case L_TS_MCU2: - return TEMPADC_MCU2; - /* There is no TSMCU3 in MT6785 compared with MT6779 */ - case L_TS_MCU4: - return TEMPADC_MCU4; - case L_TS_MCU5: - return TEMPADC_MCU5; - case L_TS_MCU6: - return TEMPADC_MCU6; - case L_TS_MCU7: - return TEMPADC_MCU7; - case L_TS_MCU8: - return TEMPADC_MCU8; - case L_TS_MCU9: - return TEMPADC_MCU9; - case L_TS_ABB: - return TEMPADC_ABB; - default: - return TEMPADC_MCU1; - } -} - -/* pause ALL periodoc temperature sensing point */ -void thermal_pause_all_periodoc_temp_sensing(void) -{ - int i, temp, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - temp = readl(offset + TEMPMSRCTL1); - /* set bit8=bit1=bit2=bit3=1 to pause sensing point 0,1,2,3 */ - mt_reg_sync_writel((temp | 0x10E), offset + TEMPMSRCTL1); - } -} - -/* release ALL periodoc temperature sensing point */ -void thermal_release_all_periodoc_temp_sensing(void) -{ - int i = 0, temp; - __u32 offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - - temp = readl(offset + TEMPMSRCTL1); - /* set bit1=bit2=bit3=bit8=0 to release sensing point 0,1,2,3*/ - mt_reg_sync_writel(((temp & (~0x10E))), offset + TEMPMSRCTL1); - } -} - -static void tscpu_thermal_enable_all_periodoc_sensing_point(int tc_num) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - switch (tscpu_g_tc[tc_num].ts_number) { - case 1: - /* enable periodoc temperature sensing point 0 */ - mt_reg_sync_writel(0x00000001, offset + TEMPMONCTL0); - break; - case 2: - /* enable periodoc temperature sensing point 0,1 */ - mt_reg_sync_writel(0x00000003, offset + TEMPMONCTL0); - break; - case 3: - /* enable periodoc temperature sensing point 0,1,2 */ - mt_reg_sync_writel(0x00000007, offset + TEMPMONCTL0); - break; - case 4: - /* enable periodoc temperature sensing point 0,1,2,3*/ - mt_reg_sync_writel(0x0000000F, offset + TEMPMONCTL0); - break; - default: - tscpu_printk("Error at %s\n", __func__); - break; - } -} - -/* disable ALL periodoc temperature sensing point */ -void thermal_disable_all_periodoc_temp_sensing(void) -{ - int i = 0, offset; - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - mt_reg_sync_writel(0x00000000, offset + TEMPMONCTL0); - } -} - -static void tscpu_thermal_tempADCPNP(int tc_num, int adc, int order) -{ - __u32 offset; - - offset = tscpu_g_tc[tc_num].tc_offset; - - tscpu_dprintk("%s adc %x, order %d\n", __func__, adc, order); - - switch (order) { - case 0: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - case 1: - mt_reg_sync_writel(adc, offset + TEMPADCPNP1); - break; - case 2: - mt_reg_sync_writel(adc, offset + TEMPADCPNP2); - break; - case 3: - mt_reg_sync_writel(adc, offset + TEMPADCPNP3); - break; - default: - mt_reg_sync_writel(adc, offset + TEMPADCPNP0); - break; - } -} - -void tscpu_thermal_initial_all_tc(void) -{ - int i, j = 0; - __u32 temp = 0, offset; - - /* AuxADC Initialization,ref MT6592_AUXADC.doc */ - temp = readl(AUXADC_CON0_V); /* Auto set enable for CH11 */ - temp &= 0xFFFFF7FF; /* 0: Not AUTOSET mode */ - - /* disable auxadc channel 11 synchronous mode */ - mt_reg_sync_writel(temp, AUXADC_CON0_V); - - /* disable auxadc channel 11 immediate mode */ - mt_reg_sync_writel(0x800, AUXADC_CON1_CLR_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - offset = tscpu_g_tc[i].tc_offset; - thermal_reset_and_initial(i); - - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) - tscpu_thermal_tempADCPNP(i, tscpu_thermal_ADCValueOfMcu - (tscpu_g_tc[i].ts[j]), j); - - mt_reg_sync_writel(TS_CONFIGURE_P, offset + TEMPPNPMUXADDR); - mt_reg_sync_writel(0x3, offset + TEMPADCWRITECTRL); - } - - mt_reg_sync_writel(0x800, AUXADC_CON1_SET_V); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - - tscpu_thermal_enable_all_periodoc_sensing_point(i); - } -} - -void tscpu_config_all_tc_hw_protect(int temperature, int temperature2) -{ - int i = 0; - int wd_api_ret; - struct wd_api *wd_api; - - tscpu_dprintk("%s,temperature=%d,temperature2=%d\n", __func__, - temperature, temperature2); - -#if THERMAL_PERFORMANCE_PROFILE - struct timeval begin, end; - unsigned long val; - - do_gettimeofday(&begin); -#endif - /* spend 860~1463 us */ - /* Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - wd_api_ret = get_wd_api(&wd_api); - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_DIS, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -#if THERMAL_PERFORMANCE_PROFILE - do_gettimeofday(&end); - - /* Get milliseconds */ - pr_notice("resume time spent, sec : %lu , usec : %lu\n", - (end.tv_sec - begin.tv_sec), - (end.tv_usec - begin.tv_usec)); -#endif - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - if (tscpu_g_tc[i].ts_number == 0) - continue; - /* Move thermal HW protection ahead... */ - set_tc_trigger_hw_protect(temperature, temperature2, i); - } - - /*Thermal need to config to direct reset mode - * this API provide by Weiqi Fu(RGU SW owner). - */ - if (wd_api_ret >= 0) { - wd_api->wd_thermal_direct_mode_config(WD_REQ_EN, - WD_REQ_RST_MODE); /* reset mode */ - } else { - tscpu_warn("%d FAILED TO GET WD API\n", __LINE__); - WARN_ON_ONCE(1); - } -} - -void tscpu_reset_thermal(void) -{ - /* chip dependent, Have to confirm with DE */ - - int temp = 0; - /* reset thremal ctrl */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_SET? */ - temp = readl(INFRA_GLOBALCON_RST_0_SET); - - /* 1: Enables thermal control software reset */ - temp |= 0x00000001; - - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_SET); - - /* TODO: How long to set the reset bit? */ - - /* un reset */ - /* TODO: Is it necessary to read INFRA_GLOBALCON_RST_0_CLR? */ - temp = readl(INFRA_GLOBALCON_RST_0_CLR); - /* 1: Enable reset Disables thermal control software reset */ - temp |= 0x00000001; - mt_reg_sync_writel(temp, INFRA_GLOBALCON_RST_0_CLR); -} - -int tscpu_dump_cali_info(struct seq_file *m, void *v) -{ - int i; - - seq_printf(m, "[cal] g_adc_ge_t = %d\n", g_adc_ge_t); - seq_printf(m, "[cal] g_adc_oe_t = %d\n", g_adc_oe_t); - - seq_printf(m, "[cal] g_o_vtsmcu0 = %d\n", g_o_vtsmcu0); - seq_printf(m, "[cal] g_o_vtsmcu1 = %d\n", g_o_vtsmcu1); - seq_printf(m, "[cal] g_o_vtsmcu2 = %d\n", g_o_vtsmcu2); - /* There is no g_o_vtsmcu3 in MT6785 compared with MT6779 */ - seq_printf(m, "[cal] g_o_vtsmcu4 = %d\n", g_o_vtsmcu4); - seq_printf(m, "[cal] g_o_vtsmcu5 = %d\n", g_o_vtsmcu5); - seq_printf(m, "[cal] g_o_vtsmcu6 = %d\n", g_o_vtsmcu6); - seq_printf(m, "[cal] g_o_vtsmcu7 = %d\n", g_o_vtsmcu7); - seq_printf(m, "[cal] g_o_vtsmcu8 = %d\n", g_o_vtsmcu8); - seq_printf(m, "[cal] g_o_vtsmcu9 = %d\n", g_o_vtsmcu9); - seq_printf(m, "[cal] g_o_vtsabb = %d\n", g_o_vtsabb); - - seq_printf(m, "[cal] g_degc_cali = %d\n", g_degc_cali); - seq_printf(m, "[cal] g_adc_cali_en_t = %d\n", g_adc_cali_en_t); - seq_printf(m, "[cal] g_o_slope_sign = %d\n", g_o_slope_sign); - seq_printf(m, "[cal] g_o_slope = %d\n", g_o_slope); - seq_printf(m, "[cal] g_id = %d\n", g_id); - seq_printf(m, "[cal] g_ge = %d\n", g_ge); - seq_printf(m, "[cal] g_gain = %d\n", g_gain); - - for (i = 0; i < L_TS_MCU_NUM; i++) - seq_printf(m, "[cal] g_x_roomt%d = %d\n", i, g_x_roomt[i]); - - return 0; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -int check_auxadc_mcu_efuse(void) -{ - return g_adc_cali_en_t; -} -#endif - -#if THERMAL_GET_AHB_BUS_CLOCK -void thermal_get_AHB_clk_info(void) -{ - int cg = 0, dcm = 0, cg_freq = 0; - int clockSource = 136, ahbClk = 0; /* Need to confirm with DE */ - - cg = readl(THERMAL_CG); - dcm = readl(THERMAL_DCM); - - /* The following rule may change, you need to confirm with DE. - * These are for mt6759, and confirmed with DE Justin Gu - */ - cg_freq = dcm & _BITMASK_(9:5); - - if (cg_freq & _BIT_(4)) - ahbClk = clockSource / 2; - else if (cg_freq & _BIT_(3)) - ahbClk = clockSource / 4; - else if (cg_freq & _BIT_(2)) - ahbClk = clockSource / 8; - else if (cg_freq & _BIT_(1)) - ahbClk = clockSource / 16; - else - ahbClk = clockSource / 32; - - /* tscpu_printk("cg %d dcm %d\n", ((cg & _BIT_(10)) >> 10), dcm); */ - /* tscpu_printk("AHB bus clock= %d MHz\n", ahbClk); */ -} -#endif - -/* chip dependent */ -void print_risky_temps(char *prefix, int offset, int printLevel) -{ - sprintf((prefix + offset), "L %d B %d", - get_immediate_cpuL_wrap(), get_immediate_cpuB_wrap()); - - switch (printLevel) { - case 0: - tscpu_dprintk("%s\n", prefix); - break; - case 1: - tscpu_warn("%s\n", prefix); - break; - default: - tscpu_dprintk("%s\n", prefix); - } -} - diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_tc_wrapper.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_tc_wrapper.c deleted file mode 100644 index e3320d9a0730..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_tc_wrapper.c +++ /dev/null @@ -1,1016 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include - -#ifdef CONFIG_OF -#include -#include -#include -#endif - -#if defined(CONFIG_MTK_CLKMGR) -#include -#else -#include -#endif - -#include -#include "mtk_idle.h" - -#if CONFIG_LVTS_ERROR_AEE_WARNING -#include -#include -#if DUMP_VCORE_VOLTAGE -#include -#endif -struct lvts_error_data { - int ts_temp[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_r[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ - int ts_temp_v[TS_ENUM_MAX][R_BUFFER_SIZE]; /* A ring buffer */ -#if DUMP_VCORE_VOLTAGE - int vcore_voltage[R_BUFFER_SIZE]; /* A ring buffer */ -#endif - int c_index; /* Current index points to the space to replace.*/ - int e_occurred; /* 1: An error occurred, 0: Nothing happened*/ - int f_count; /* Future count */ - enum thermal_sensor e_mcu; - enum thermal_sensor e_lvts; -}; -struct lvts_error_data g_lvts_e_data; -int tscpu_ts_mcu_temp_v[L_TS_MCU_NUM]; -int tscpu_ts_lvts_temp_v[L_TS_LVTS_NUM]; -#endif - - -#if CFG_THERM_LVTS -int tscpu_ts_lvts_temp[L_TS_LVTS_NUM]; -int tscpu_ts_lvts_temp_r[L_TS_LVTS_NUM]; -#endif - -int tscpu_curr_cpu_temp; -int tscpu_curr_gpu_temp; - -static int tscpu_curr_max_ts_temp; - -int __attribute__ ((weak)) - mtk_idle_notifier_register(struct notifier_block *n) -{ - return 0; -} - -int get_immediate_none_wrap(void) -{ - return -127000; -} - -/* chip dependent */ -int get_immediate_cpuL_wrap(void) -{ - int curr_temp; - - curr_temp = MAX( - MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_0], - tscpu_ts_lvts_temp[L_TS_LVTS3_1]), - MAX(tscpu_ts_lvts_temp[L_TS_LVTS3_2], - tscpu_ts_lvts_temp[L_TS_LVTS3_3]) - ); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS1_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS1_0], - tscpu_ts_lvts_temp[L_TS_LVTS1_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_cpuB_LVTS2_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS2_0], - tscpu_ts_lvts_temp[L_TS_LVTS2_1]); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_vpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS4_0], - tscpu_ts_lvts_temp[L_TS_LVTS4_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_gpu_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(tscpu_ts_lvts_temp[L_TS_LVTS5_0], - tscpu_ts_lvts_temp[L_TS_LVTS5_1]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - -int get_immediate_infa_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_0]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_camsys_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_1]; - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_md_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(MAX(tscpu_ts_lvts_temp[L_TS_LVTS7_0], - tscpu_ts_lvts_temp[L_TS_LVTS7_1]), - tscpu_ts_lvts_temp[L_TS_LVTS7_2]); - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; - -} - - - -/* - * THERMAL_BANK0, //B CPU (LVTS1) - * THERMAL_BANK1, //B CPU (LVTS2) - * THERMAL_BANK2, //L CPU (LVTS3) - * THERMAL_BANK3, //VPU (LVTS4) - * THERMAL_BANK4, //GPU (LVTS5) - * THERMAL_BANK5, //IFRA (LVTS6) - */ - -int (*max_temperature_in_bank[THERMAL_BANK_NUM])(void) = { - get_immediate_cpuB_LVTS1_wrap, - get_immediate_cpuB_LVTS2_wrap, - get_immediate_cpuL_wrap, - get_immediate_vpu_wrap, - get_immediate_gpu_wrap, - get_immediate_infa_wrap -}; - -int get_immediate_cpuB_wrap(void) -{ - int curr_temp; - - curr_temp = MAX(get_immediate_cpuB_LVTS1_wrap(), - get_immediate_cpuB_LVTS2_wrap()); - - - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts4_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts5_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts6_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts7_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS6_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts8_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS7_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_ts9_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[L_TS_LVTS7_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -#if CFG_THERM_LVTS -int get_immediate_tslvts1_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts1_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts2_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS2_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts3_3_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS3_3]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts4_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS4_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts5_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts5_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS5_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts6_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS6_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts6_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS6_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - - -int get_immediate_tslvts7_0_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_0]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts7_1_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_1]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} - -int get_immediate_tslvts7_2_wrap(void) -{ - int curr_temp; - - curr_temp = tscpu_ts_lvts_temp[TS_LVTS7_2]; - tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp); - - return curr_temp; -} -#endif - -int get_immediate_tsabb_wrap(void) -{ - - return 0; -} - -int (*get_immediate_tsX[TS_ENUM_MAX])(void) = { - -#if CFG_THERM_LVTS - get_immediate_tslvts1_0_wrap, - get_immediate_tslvts1_1_wrap, - get_immediate_tslvts2_0_wrap, - get_immediate_tslvts2_1_wrap, - get_immediate_tslvts3_0_wrap, - get_immediate_tslvts3_1_wrap, - get_immediate_tslvts3_2_wrap, - get_immediate_tslvts3_3_wrap, - get_immediate_tslvts4_0_wrap, - get_immediate_tslvts4_1_wrap, - get_immediate_tslvts5_0_wrap, - get_immediate_tslvts5_1_wrap, - get_immediate_tslvts6_0_wrap, - get_immediate_tslvts6_1_wrap, - get_immediate_tslvts7_0_wrap, - get_immediate_tslvts7_1_wrap, - get_immediate_tslvts7_2_wrap -#endif -}; - -/** - * this only returns latest stored max ts temp but not updated from TC. - */ -int tscpu_get_curr_max_ts_temp(void) -{ - return tscpu_curr_max_ts_temp; -} - -#if CFG_THERM_LVTS -int tscpu_max_temperature(void) -{ - int i, j, max = 0; - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_dprintk("lvts_max_temperature %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(lvts_tscpu_g_tc); i++) { - for (j = 0; j < lvts_tscpu_g_tc[i].ts_number; j++) { - if (i == 0 && j == 0) { - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } else { - if (max < tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_lvts_temp[ - lvts_tscpu_g_tc[i].ts[j]]; - } - } - } -#endif /* CFG_THERM_LVTS */ -#else - tscpu_dprintk("tscpu_get_temp %s, %d\n", __func__, __LINE__); - - for (i = 0; i < ARRAY_SIZE(tscpu_g_tc); i++) { - for (j = 0; j < tscpu_g_tc[i].ts_number; j++) { - if (i == 0 && j == 0) { - max = tscpu_ts_mcu_temp[tscpu_g_tc[i].ts[j]]; - } else { - if (max < tscpu_ts_mcu_temp[ - tscpu_g_tc[i].ts[j]]) - max = tscpu_ts_mcu_temp[ - tscpu_g_tc[i].ts[j]]; - } - } - } -#endif /* CFG_LVTS_DOMINATOR */ - return max; -} -#endif - -int tscpu_get_curr_temp(void) -{ - tscpu_update_tempinfo(); - -#if PRECISE_HYBRID_POWER_BUDGET - /* update CPU/GPU temp data whenever TZ times out... - * If the update timing is aligned to TZ polling, - * this segment should be moved to TZ code instead of thermal - * controller driver - */ -/* - * module LVTS Plan - *===================================================== - * MCU_BIG(T1) LVTS1-0 - * MCU_BIGBIG(T2) LVTS1-1 - * MCU_BIG(T3,T4) LVTS2-0, LVTS2-1 - * MCU_LITTLE(T5,T6,T7,T8) LVTS3-0, LVTS3-1, LVTS3-2, LVTS3-3 - * VPU_MLDA(T9,T10) LVTS4-0, LVTS4-1 - * GPU(T11,T12) LVTS5-0, LVTS5-1 - * INFA(T13) LVTS6-0 - * CAMSYS(T18) LVTS6-1 - * MDSYS(T14,T15,T20) LVTS7-0, LVTS7-1, LVTS7-2 - */ - -#if CFG_LVTS_DOMINATOR -#if CFG_THERM_LVTS - tscpu_curr_cpu_temp = - MAX( - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS1_0], - tscpu_ts_lvts_temp[TS_LVTS1_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS2_0], - tscpu_ts_lvts_temp[TS_LVTS2_1]) - )), - (MAX( - MAX(tscpu_ts_lvts_temp[TS_LVTS3_0], - tscpu_ts_lvts_temp[TS_LVTS3_1]), - MAX(tscpu_ts_lvts_temp[TS_LVTS3_2], - tscpu_ts_lvts_temp[TS_LVTS3_3]) - )) - ); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_lvts_temp[TS_LVTS5_0], - tscpu_ts_lvts_temp[TS_LVTS5_1]); -#endif /* CFG_THERM_LVTS */ -#else - /* It is platform dependent which TS is better to present CPU/GPU - * temperature - */ - tscpu_curr_cpu_temp = MAX( - MAX(MAX(tscpu_ts_temp[TS_MCU5], tscpu_ts_temp[TS_MCU6]), - MAX(tscpu_ts_temp[TS_MCU7], tscpu_ts_temp[TS_MCU8])), - tscpu_ts_temp[TS_MCU9]); - - tscpu_curr_gpu_temp = MAX(tscpu_ts_temp[TS_MCU1], - tscpu_ts_temp[TS_MCU2]); -#endif /* CFG_LVTS_DOMINATOR */ -#endif /* PRECISE_HYBRID_POWER_BUDGET */ - - /* though tscpu_max_temperature is common, put it in mtk_ts_cpu.c is - * weird. - */ - - tscpu_curr_max_ts_temp = tscpu_max_temperature(); - - return tscpu_curr_max_ts_temp; -} - -#if CONFIG_LVTS_ERROR_AEE_WARNING -char mcu_s_array[TS_ENUM_MAX][17] = { -#if CFG_THERM_LVTS - "TS_LVTS1_0", - "TS_LVTS1_1", - "TS_LVTS2_0", - "TS_LVTS2_1", - "TS_LVTS3_0", - "TS_LVTS3_1", - "TS_LVTS3_2", - "TS_LVTS3_3", - "TS_LVTS4_0", - "TS_LVTS4_1", - "TS_LVTS5_0", - "TS_LVTS5_1", - "TS_LVTS6_0", - "TS_LVTS6_1", - "TS_LVTS7_0", - "TS_LVTS7_1", - "TS_LVTS7_2" - #endif -}; - -static void dump_lvts_error_info(void) -{ - int i, j, index, e_index, offset; -#if DUMP_LVTS_REGISTER - int cnt, temp; -#endif - enum thermal_sensor mcu_index, lvts_index; - char buffer[512]; - - mcu_index = g_lvts_e_data.e_mcu; - lvts_index = g_lvts_e_data.e_lvts; - index = g_lvts_e_data.c_index; - e_index = (index + HISTORY_SAMPLES + 1) % R_BUFFER_SIZE; - - tscpu_printk("[LVTS_ERROR][DUMP] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - g_lvts_e_data.ts_temp[mcu_index][e_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[lvts_index][e_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index], - LVTS_ERROR_THRESHOLD); - - for (i = TS_MCU1; i <= TS_LVTS4_1; i++) { - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[i]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) - % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[i][index]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - } - - offset = sprintf(buffer, "[LVTS_ERROR][%s_R][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[mcu_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[mcu_index][index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_V][DUMP] ", - mcu_s_array[lvts_index]); - - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_v[lvts_index][index]); - } - - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - dump_efuse_data(); -#if DUMP_LVTS_REGISTER - read_controller_reg_when_error(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - lvts_wait_for_all_sensing_point_idle(); - - read_device_reg_when_error(); - dump_lvts_register_value(); -#endif -#if DUMP_VCORE_VOLTAGE - offset = sprintf(buffer, "[LVTS_ERROR][Vcore_V][DUMP] ", - mcu_s_array[lvts_index]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - index = (g_lvts_e_data.c_index + 1 + j) % R_BUFFER_SIZE; - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.vcore_voltage[index]); - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -#endif -#if DUMP_LVTS_REGISTER - lvts_reset_device_and_stop_clk(); -#endif -#ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, __func__, - "LVTS_ERROR: %s, %s diff: %d\n", mcu_s_array[mcu_index], - mcu_s_array[lvts_index], - g_lvts_e_data.ts_temp[mcu_index][e_index] - - g_lvts_e_data.ts_temp[lvts_index][e_index]); -#endif - - g_lvts_e_data.e_occurred = 0; - g_lvts_e_data.f_count = -1; -#if DUMP_LVTS_REGISTER - clear_lvts_register_value_array(); - - lvts_device_identification(); - lvts_Device_Enable_Init_all_Devices(); - lvts_device_read_count_RC_N(); - lvts_efuse_setting(); - - lvts_thermal_disable_all_periodoc_temp_sensing(); - Enable_LVTS_CTRL_for_thermal_Data_Fetch(); - lvts_tscpu_thermal_initial_all_tc(); -#endif -} - -static void check_lvts_error(enum thermal_sensor mcu_index, - enum thermal_sensor lvts_index) -{ - int temp; - - temp = tscpu_ts_temp[mcu_index] - tscpu_ts_temp[lvts_index]; - - if (temp < 0) - temp = temp * -1; - - /*Skip if LVTS thermal controllers doens't ready */ - if (temp > 100000) - return; - - if (temp > LVTS_ERROR_THRESHOLD) { - tscpu_printk("[LVTS_ERROR] %s:%d and %s:%d error: |%d| > %d\n", - mcu_s_array[mcu_index], - tscpu_ts_temp[mcu_index], - mcu_s_array[lvts_index], - tscpu_ts_temp[lvts_index], - tscpu_ts_temp[mcu_index] - - tscpu_ts_temp[lvts_index], - LVTS_ERROR_THRESHOLD); - g_lvts_e_data.e_occurred = 1; - g_lvts_e_data.e_mcu = mcu_index; - g_lvts_e_data.e_lvts = lvts_index; - g_lvts_e_data.f_count = -1; - } -} -void dump_lvts_error_data_info(void) -{ - char buffer[512]; - int offset, j; - - tscpu_printk("[LVTS_ERROR] c_index %d, e_occurred %d, f_count %d\n", - g_lvts_e_data.c_index, g_lvts_e_data.e_occurred, - g_lvts_e_data.f_count); - tscpu_printk("[LVTS_ERROR] e_mcu %d, e_lvts %d\n", g_lvts_e_data.e_mcu, - g_lvts_e_data.e_lvts); - - offset = sprintf(buffer, "[LVTS_ERROR][%s][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); - - offset = sprintf(buffer, "[LVTS_ERROR][%s_raw][DUMP] ", - mcu_s_array[TS_LVTS1_0]); - for (j = 0; j < R_BUFFER_SIZE; j++) { - offset += sprintf(buffer + offset, "%d ", - g_lvts_e_data.ts_temp_r[TS_LVTS1_0][j]); - - } - buffer[offset] = '\0'; - tscpu_printk("%s\n", buffer); -} -#endif - -int tscpu_read_temperature_info(struct seq_file *m, void *v) -{ - seq_printf(m, "curr_temp = %d\n", tscpu_get_curr_max_ts_temp()); - -#if !defined(CFG_THERM_NO_AUXADC) - tscpu_dump_cali_info(m, v); -#endif - -#if CFG_THERM_LVTS - seq_puts(m, "-----------------\n"); - lvts_tscpu_dump_cali_info(m, v); -#endif - return 0; -} - -static int thermal_idle_notify_call(struct notifier_block *nfb, - unsigned long id, - void *arg) -{ - switch (id) { - case NOTIFY_DPIDLE_ENTER: - break; - case NOTIFY_SOIDLE_ENTER: - break; - case NOTIFY_DPIDLE_LEAVE: - break; - case NOTIFY_SOIDLE_LEAVE: - break; - case NOTIFY_SOIDLE3_ENTER: -#if LVTS_VALID_DATA_TIME_PROFILING - SODI3_count++; - if (SODI3_count != 1 && isTempValid == 0) - noValid_count++; - - if (isTempValid == 1 || SODI3_count == 1) - start_timestamp = thermal_get_current_time_us(); - - isTempValid = 0; -#endif - break; - case NOTIFY_SOIDLE3_LEAVE: -#if CFG_THERM_LVTS - lvts_sodi3_release_thermal_controller(); -#endif - break; - default: - /* do nothing */ - break; - } - return NOTIFY_OK; -} - -static struct notifier_block thermal_idle_nfb = { - .notifier_call = thermal_idle_notify_call, -}; - -#ifdef CONFIG_OF -int get_io_reg_base(void) -{ - struct device_node *node = NULL; - - node = of_find_compatible_node(NULL, NULL, "mediatek,therm_ctrl"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - thermal_base = of_iomap(node, 0); - } - - /*tscpu_printk("[THERM_CTRL] thermal_base= 0x%px\n",thermal_base);*/ - - /*get thermal irq num */ - thermal_irq_number = irq_of_parse_and_map(node, 0); - tscpu_printk("[THERM_CTRL] thermal_irq_number=%d\n", - thermal_irq_number); - if (!thermal_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_irq_number); - return 0; - } - - /*get thermal irq num */ - thermal_mcu_irq_number = irq_of_parse_and_map(node, 1); - tscpu_printk("[THERM_CTRL] mcu_irq_num = %d\n", - thermal_mcu_irq_number); - if (!thermal_mcu_irq_number) { - /*TODO: need check "irq number"*/ - tscpu_printk("[THERM_CTRL] get irqnr failed=%d\n", - thermal_mcu_irq_number); - return 0; - } - - - if (of_property_read_u32_index(node, "reg", 1, &thermal_phy_base)) { - tscpu_printk("[THERM_CTRL] config error thermal_phy_base\n"); - return 0; - } - - /*tscpu_printk("[THERM_CTRL] phy_base=0x%x\n", thermal_phy_base);*/ - - - - node = of_find_compatible_node(NULL, NULL, "mediatek,mt6768-auxadc"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - auxadc_ts_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &auxadc_ts_phy_base)) { - tscpu_printk("[THERM_CTRL] config error auxadc_ts_phy_base\n"); - return 0; - } - - node = of_find_compatible_node(NULL, NULL, "mediatek,infracfg_ao"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - infracfg_ao_base = of_iomap(node, 0); - - if (infracfg_ao_base) - mtk_idle_notifier_register(&thermal_idle_nfb); - } - - node = of_find_compatible_node(NULL, NULL, - "mediatek,mt6893-apmixedsys"); - WARN_ON_ONCE(node == 0); - if (node) { - /* Setup IO addresses */ - th_apmixed_base = of_iomap(node, 0); - } - - if (of_property_read_u32_index(node, "reg", 1, &apmixed_phy_base)) { - tscpu_printk("[THERM_CTRL] config error apmixed_phy_base=\n"); - return 0; - } - -#if THERMAL_GET_AHB_BUS_CLOCK - /* TODO: If this is required, it needs to confirm which node to read. */ - node = of_find_compatible_node(NULL, NULL, "mediatek,infrasys"); - if (!node) { - pr_notice("[CLK_INFRACFG_AO] find node failed\n"); - return 0; - } - therm_clk_infracfg_ao_base = of_iomap(node, 0); - if (!therm_clk_infracfg_ao_base) { - pr_notice("[CLK_INFRACFG_AO] base failed\n"); - return 0; - } -#endif - return 1; -} -#endif - -/* chip dependent */ -int tscpu_thermal_clock_on(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - ret = clk_prepare_enable(therm_main); - if (ret) - tscpu_printk("Cannot enable thermal clock.\n"); - - return ret; -} - -/* chip dependent */ -int tscpu_thermal_clock_off(void) -{ - int ret = -1; - - /* Use CCF */ - tscpu_printk("%s\n", __func__); - clk_disable_unprepare(therm_main); - return ret; -} - diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_thermal_ipi.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_thermal_ipi.c deleted file mode 100644 index 0ebc8ef421ff..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_thermal_ipi.c +++ /dev/null @@ -1,402 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include "mtk_thermal_ipi.h" -#include "mach/mtk_thermal.h" -#include "tscpu_settings.h" -#include "linux/mutex.h" -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - -#if THERMAL_ENABLE_TINYSYS_SSPM || THERMAL_ENABLE_ONLY_TZ_SSPM -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -static DEFINE_MUTEX(thermo_sspm_mutex); -static int is_thermal_ipi_registered; -static int ack_data; - -static int register_thermal_ipi(void) -{ - int ret; - - ret = mtk_ipi_register(&sspm_ipidev, IPIS_C_THERMAL, NULL, NULL, - (void *)&ack_data); - if (ret != 0) { - tscpu_printk("%s error ret:%d\n", __func__, ret); - return -1; - } - - is_thermal_ipi_registered = 1; - - return 0; -} - -unsigned int thermal_to_sspm( - unsigned int cmd, struct thermal_ipi_data *thermal_data) -{ - int ackData = -1; - int ret; - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_INIT_GRP1: - case THERMAL_IPI_INIT_GRP2: - case THERMAL_IPI_INIT_GRP3: - case THERMAL_IPI_INIT_GRP4: - case THERMAL_IPI_INIT_GRP5: - case THERMAL_IPI_INIT_GRP6: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send init cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_LVTS_INIT_GRP1: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) lvts efuse to SSPM (%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_GET_TEMP: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - if (ret != 0) - tscpu_printk("send get_temp cmd(%d) error ret:%d\n", - cmd, ret); - else if (ack_data < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - break; - case THERMAL_IPI_SET_BIG_FREQ_THRESHOLD: - case THERMAL_IPI_GET_BIG_FREQ_THRESHOLD: - thermal_data->cmd = cmd; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("mtk_ipi_send_compl error ret:%d - %d\n", - cmd, ret); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - case THERMAL_IPI_SET_DIS_THERMAL_THROTTLE: - thermal_data->cmd = cmd; - tscpu_printk("cmd(%d) disable SSPM thermal throttle(%d)\n", - cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - case THERMAL_IPI_SUSPEND_RESUME_NOTIFY: - thermal_data->cmd = cmd; - //tscpu_printk("cmd(%d) kernel suspend/resume(%d)\n", - // cmd, ack_data); - - ackData = ack_data; - - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, THERMAL_SLOT_NUM, 2000); - - if (ret != 0) - tscpu_printk("sspm_ipi_send err cmd %d,ret:%d - %d\n", - cmd, ret, ackData); - else if (ackData < 0) - tscpu_printk("cmd(%d) return error(%d)\n", - cmd, ackData); - break; - - default: - tscpu_printk("cmd(%d) wrong!!\n", cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ackData; /** It's weird here. What should be returned? */ -} - -/* ipi_send() return code - * IPI_DONE 0 - * IPI_RETURN 1 - * IPI_BUSY -1 - * IPI_TIMEOUT_AVL -2 - * IPI_TIMEOUT_ACK -3 - * IPI_MODULE_ID_ERROR -4 - * IPI_HW_ERROR -5 - */ -int atm_to_sspm(unsigned int cmd, int data_len, -struct thermal_ipi_data *thermal_data, int *ackData) -{ - int ret = -1; - - if (data_len < 1 || data_len > 3) { - *ackData = -1; - return ret; - } - - mutex_lock(&thermo_sspm_mutex); - - if (!is_thermal_ipi_registered) { - if (register_thermal_ipi() != 0) - goto end; - } - - switch (cmd) { - case THERMAL_IPI_SET_ATM_CFG_GRP1: - case THERMAL_IPI_SET_ATM_CFG_GRP2: - case THERMAL_IPI_SET_ATM_CFG_GRP3: - case THERMAL_IPI_SET_ATM_CFG_GRP4: - case THERMAL_IPI_SET_ATM_CFG_GRP5: - case THERMAL_IPI_SET_ATM_CFG_GRP6: - case THERMAL_IPI_SET_ATM_CFG_GRP7: - case THERMAL_IPI_SET_ATM_CFG_GRP8: - case THERMAL_IPI_SET_ATM_TTJ: - case THERMAL_IPI_SET_ATM_EN: - case THERMAL_IPI_GET_ATM_CPU_LIMIT: - case THERMAL_IPI_GET_ATM_GPU_LIMIT: - thermal_data->cmd = cmd; - ret = mtk_ipi_send_compl(&sspm_ipidev, IPIS_C_THERMAL, - IPI_SEND_POLLING, thermal_data, (data_len+1), 2000); - if ((ret != 0) || (ack_data < 0)) - tscpu_printk("%s cmd %d ret %d ack %d\n", - __func__, cmd, ret, ack_data); - - *ackData = ack_data; - - break; - - default: - tscpu_printk("%s cmd %d err!\n", __func__, cmd); - break; - } - -end: - mutex_unlock(&thermo_sspm_mutex); - - return ret; -} - -static int get_sspm_tz_temp_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_sspm(THERMAL_IPI_GET_TEMP, &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show current temperature in SSPM UART log\n"); - - return 0; -} - -static int get_sspm_tz_temp_open(struct inode *inode, struct file *file) -{ - return single_open(file, get_sspm_tz_temp_read, NULL); -} - -static const struct file_operations get_sspm_tz_temp_fops = { - .owner = THIS_MODULE, - .open = get_sspm_tz_temp_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static ssize_t set_sspm_big_limit_threshold_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int arrayIndex, bigCoreTj, bigCoreExitTj, bigCoreFreqUpperBound; - struct thermal_ipi_data thermal_data; - - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - - if (sscanf(desc, "%d %d %d", &arrayIndex, &bigCoreTj, - &bigCoreFreqUpperBound) == 3) { - if ((arrayIndex >= BIG_CORE_THRESHOLD_ARRAY_SIZE) || - (arrayIndex < 0)) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreTj; - thermal_data.u.data.arg[2] = bigCoreFreqUpperBound; - - while (thermal_to_sspm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } else if (sscanf(desc, "%d %d", &arrayIndex, &bigCoreExitTj) == 2) { - if (arrayIndex != -1) { - tscpu_printk("%s invalid array index: %s\n", - __func__, desc); - - return -EINVAL; - } - - thermal_data.u.data.arg[0] = arrayIndex; - thermal_data.u.data.arg[1] = bigCoreExitTj; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_sspm(THERMAL_IPI_SET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - return count; - } - - tscpu_printk("%s bad argument: %s\n", __func__, desc); - return -EINVAL; - -} - -static int set_sspm_big_limit_threshold_read(struct seq_file *m, void *v) -{ - struct thermal_ipi_data thermal_data; - - seq_puts(m, "Use this command to change big core freq limit threshold\n"); - seq_puts(m, " echo arrayIndex BigCoreTj bigCoreFreqUpperBound >\n"); - seq_puts(m, " /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_printf(m, " arrayIndex is not larger than or equal to %d\n", - BIG_CORE_THRESHOLD_ARRAY_SIZE); - seq_puts(m, " BigCoreTj is in m'C\n"); - seq_puts(m, " BigCoreFreqUpperBound is in MHz\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo 0 85000 2050 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, "Use this command to change exit point\n"); - seq_puts(m, " echo -1 BigCoreExitTj > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - seq_puts(m, " BigCoreExitTj is in m'C\n"); - seq_puts(m, " For example:\n"); - seq_puts(m, " echo -1 75000 > /proc/driver/thermal/set_sspm_big_limit_threshold\n"); - - thermal_data.u.data.arg[0] = 0; - thermal_data.u.data.arg[1] = 0; - thermal_data.u.data.arg[2] = 0; - - while (thermal_to_sspm(THERMAL_IPI_GET_BIG_FREQ_THRESHOLD, - &thermal_data) != 0) - udelay(500); - - seq_puts(m, "Show big core frequency thresholds in SSPM UART log\n"); - - return 0; -} - -static int set_sspm_big_limit_threshold_open(struct inode *inode, - struct file *file) -{ - return single_open(file, set_sspm_big_limit_threshold_read, NULL); -} - -static const struct file_operations set_sspm_big_limit_threshold_fops = { - .owner = THIS_MODULE, - .open = set_sspm_big_limit_threshold_open, - .read = seq_read, - .llseek = seq_lseek, - .write = set_sspm_big_limit_threshold_write, - .release = single_release, -}; -static int __init thermal_ipi_init(void) -{ - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *thermal_ipi_dir = NULL; - - tscpu_printk("[%s]\n", __func__); - - - thermal_ipi_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!thermal_ipi_dir) { - tscpu_printk( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("get_sspm_tz_temp", 444, thermal_ipi_dir, - &get_sspm_tz_temp_fops); - if (entry) - proc_set_user(entry, uid, gid); - entry = - proc_create("set_sspm_big_limit_threshold", 664, - thermal_ipi_dir, &set_sspm_big_limit_threshold_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - return 0; -} - -static void __exit thermal_ipi_exit(void) -{ - tscpu_printk("[%s]\n", __func__); -} - -module_init(thermal_ipi_init); -module_exit(thermal_ipi_exit); -#endif diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ti_6315.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_ti_6315.c deleted file mode 100644 index e50b577c1deb..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ti_6315.c +++ /dev/null @@ -1,329 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" - - -/* #define INTR_UT */ -/* #define OT_THROTTLE_CPU */ -/* #define OT_THROTTLE_GPU */ - -#define DEFAULT_6315OT_CPU_LIMIT (800) -#define DEFAULT_6315OT_GPU_LIMIT (1000) - -static struct apthermolmt_user ap_6315ot; -static char *ap_6315ot_log = "ap_6315ot"; -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static unsigned int cpu_limit = DEFAULT_6315OT_CPU_LIMIT; -static unsigned int gpu_limit = DEFAULT_6315OT_GPU_LIMIT; - -static int virq_tempL_6; -static int virq_tempH_6; -static int virq_tempL_7; -static int virq_tempH_7; -#ifdef INTR_UT -static int virq_rcs0_6; -static int virq_rcs0_7; -#endif - -static int tpmic6315_intr_probe(struct platform_device *dev); - -static const struct of_device_id tpmic_intr_of_match[] = { - { .compatible = "mediatek,mt6315_therm_intr", }, - { /* sentinel */ } -}; - -MODULE_DEVICE_TABLE(of, tpmic_intr_of_match); - -static struct platform_driver tpmic_intr_pdrv = { - .probe = tpmic6315_intr_probe, - .remove = NULL, - .driver = { - .name = "tpmic6315_intr", - .owner = THIS_MODULE, - .of_match_table = tpmic_intr_of_match, - }, -}; - -static irqreturn_t mt6315_6_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_6); - enable_irq(virq_tempH_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s release cpu limit\n", __func__); - apthermolmt_set_cpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_6_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_6 CPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_6); - enable_irq(virq_tempL_6); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_6_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_CPU - pr_info("%s set cpu limit=%d\n", __func__, cpu_limit); - apthermolmt_set_cpu_power_limit(&ap_6315ot, cpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static irqreturn_t mt6315_7_temp_l_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU under 110D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempL_7); - enable_irq(virq_tempH_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s release gpu limit\n", __func__); - apthermolmt_set_gpu_power_limit(&ap_6315ot, 0x7FFFFFFF); -#endif - return IRQ_HANDLED; -} - -static irqreturn_t mt6315_7_temp_h_int_handler(int irq, void *data) -{ - pr_info("%s 6315_7 GPU over 125D, irq=%d\n", __func__, irq); - disable_irq_nosync(virq_tempH_7); - enable_irq(virq_tempL_7); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} - -#ifdef INTR_UT -static irqreturn_t mt6315_7_rcs0_handler(int irq, void *data) -{ - pr_info("%s irq=%d\n", __func__, irq); -#ifdef OT_THROTTLE_GPU - pr_info("%s set gpu limit=%d\n", __func__, gpu_limit); - apthermolmt_set_gpu_power_limit(&ap_6315ot, gpu_limit); -#endif - return IRQ_HANDLED; -} -#endif - -static int tpmic6315_intr_probe(struct platform_device *pdev) -{ - struct device_node *node; - int ret = 0; - - node = of_find_matching_node(NULL, tpmic_intr_of_match); - if (!node) - pr_info("@%s: find tpmic_intr node failed\n", __func__); - - virq_tempL_6 = platform_get_irq(pdev, 0); - virq_tempH_6 = platform_get_irq(pdev, 1); - virq_tempL_7 = platform_get_irq(pdev, 3); - virq_tempH_7 = platform_get_irq(pdev, 4); -#ifdef INTR_UT - virq_rcs0_6 = platform_get_irq(pdev, 2); - virq_rcs0_7 = platform_get_irq(pdev, 5); -#endif - -#ifdef INTR_UT - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || virq_rcs0_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0 || virq_rcs0_7 <= 0) { -#else - if (virq_tempL_6 <= 0 || virq_tempH_6 <= 0 || - virq_tempL_7 <= 0 || virq_tempH_7 <= 0) { -#endif - pr_info("%s: get irq error\n", __func__); - return 0; - } - - pr_info("%s: 6_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 0) - , platform_get_irq_byname(pdev, "6315_6_temp_l")); - pr_info("%s: 6_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 1) - , platform_get_irq_byname(pdev, "6315_6_temp_h")); - pr_info("%s: 7_temp_back_110D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 3) - , platform_get_irq_byname(pdev, "6315_7_temp_l")); - pr_info("%s: 7_temp_over_125D = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 4) - , platform_get_irq_byname(pdev, "6315_7_temp_h")); - -#ifdef INTR_UT - pr_info("%s: 6_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 2) - , platform_get_irq_byname(pdev, "6315_6_rcs0")); - pr_info("%s: 7_rcs0 = %d(%d)\n" - , __func__ - , platform_get_irq(pdev, 5) - , platform_get_irq_byname(pdev, "6315_7_rcs0")); -#endif - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_l"), - NULL, mt6315_6_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_temp_h"), - NULL, mt6315_6_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S6_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_l"), - NULL, mt6315_7_temp_l_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_L", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_temp_h"), - NULL, mt6315_7_temp_h_int_handler, IRQF_TRIGGER_NONE, - "6315_S7_TEMP_H", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - -#ifdef INTR_UT - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_6_rcs0"), - NULL, mt6315_6_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S6_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); - - ret = devm_request_threaded_irq(&pdev->dev, - platform_get_irq_byname(pdev, "6315_7_rcs0"), - NULL, mt6315_7_rcs0_handler, IRQF_TRIGGER_NONE, - "6315_S7_RCS0", NULL); - if (ret < 0) - dev_notice(&pdev->dev, "request test irq fail\n"); -#endif - - disable_irq_nosync(virq_tempL_6); - disable_irq_nosync(virq_tempL_7); - - return 0; -} - -static int cl_6315ot_read(struct seq_file *m, void *v) -{ - - seq_printf(m, "[%s] C/G limit = %d/%d\n", - __func__, cpu_limit, gpu_limit); - - return 0; -} -static ssize_t cl_6315ot_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - char desc[128]; - int len = 0; - int c_limit, g_limit; - - len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); - if (copy_from_user(desc, buffer, len)) - return 0; - - desc[len] = '\0'; - if (sscanf(desc, "%d %d", &c_limit, &g_limit) == 2) { - pr_info("[%s] set C/G limit = %d/%d\n", - __func__, c_limit, g_limit); - cpu_limit = (c_limit != 0) ? c_limit : 0x7FFFFFFF; - gpu_limit = (g_limit != 0) ? g_limit : 0x7FFFFFFF; - - return count; - } - - pr_info("%s bad argument\n", __func__); - return -EINVAL; -} - -static int cl_6315ot_open(struct inode *inode, struct file *file) -{ - return single_open(file, cl_6315ot_read, NULL); -} - -static const struct file_operations cl_6315ot_fops = { - .owner = THIS_MODULE, - .open = cl_6315ot_open, - .read = seq_read, - .llseek = seq_lseek, - .write = cl_6315ot_write, - .release = single_release, -}; - -static int __init mtk_ti_6315_init(void) -{ - int ret = 0; - - /* register platform driver */ - ret = platform_driver_register(&tpmic_intr_pdrv); - if (ret) { - pr_info("fail to register %s driver ~~~\n", __func__); - goto end; - } - - /* create a proc file */ - { - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *dir_entry = NULL; - - dir_entry = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!dir_entry) { - pr_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = proc_create("cl6315ot_limit", 0664, - dir_entry, - &cl_6315ot_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - } - - /* register user to thermal */ - apthermolmt_register_user(&ap_6315ot, ap_6315ot_log); - -end: - return 0; -} - -static void __exit mtk_ti_6315_exit(void) -{ - apthermolmt_unregister_user(&ap_6315ot); - platform_driver_unregister(&tpmic_intr_pdrv); - pr_info("%s\n", __func__); -} - -late_initcall(mtk_ti_6315_init); -module_exit(mtk_ti_6315_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359dcxo.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359dcxo.c deleted file mode 100644 index bd41e1cf208e..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359dcxo.c +++ /dev/null @@ -1,597 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6359dcxo_cur_temp; -/* - *static long mt6359dcxo_start_temp; - *static long mt6359dcxo_end_temp; - */ -/*=============================================================*/ - -static int mt6359dcxo_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359dcxo_get_hw_temp(); - mt6359dcxo_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359dcxo_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359dcxo_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359dcxo_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359dcxo_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359dcxo_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359dcxo_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359dcxo_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359dcxo_dev_ops = { - .bind = mt6359dcxo_bind, - .unbind = mt6359dcxo_unbind, - .get_temp = mt6359dcxo_get_temp, - .get_mode = mt6359dcxo_get_mode, - .set_mode = mt6359dcxo_set_mode, - .get_trip_type = mt6359dcxo_get_trip_type, - .get_trip_temp = mt6359dcxo_get_trip_temp, - .get_crit_temp = mt6359dcxo_get_crit_temp, -}; - -static int mt6359dcxo_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359dcxo_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359dcxo_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359dcxo OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - /* temp marked off to check temperature correctness. */ - // *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ - - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359dcxo_cooling_sysrst_ops = { - .get_max_state = mt6359dcxo_sysrst_get_max_state, - .get_cur_state = mt6359dcxo_sysrst_get_cur_state, - .set_cur_state = mt6359dcxo_sysrst_set_cur_state, -}; - -static int mt6359dcxo_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359dcxo_register_thermal(void); -static void mt6359dcxo_unregister_thermal(void); - -static ssize_t mt6359dcxo_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359dcxo_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359dcxo_data *ptr_mt6359dcxo_data; - - ptr_mt6359dcxo_data = - kmalloc(sizeof(*ptr_mt6359dcxo_data), GFP_KERNEL); - - if (ptr_mt6359dcxo_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359dcxo_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359dcxo_data->desc) - 1); - - if (copy_from_user(ptr_mt6359dcxo_data->desc, buffer, len)) { - kfree(ptr_mt6359dcxo_data); - return 0; - } - - ptr_mt6359dcxo_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359dcxo_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359dcxo_data->trip[0], - &ptr_mt6359dcxo_data->t_type[0], - ptr_mt6359dcxo_data->bind0, - &ptr_mt6359dcxo_data->trip[1], - &ptr_mt6359dcxo_data->t_type[1], - ptr_mt6359dcxo_data->bind1, - &ptr_mt6359dcxo_data->trip[2], - &ptr_mt6359dcxo_data->t_type[2], - ptr_mt6359dcxo_data->bind2, - &ptr_mt6359dcxo_data->trip[3], - &ptr_mt6359dcxo_data->t_type[3], - ptr_mt6359dcxo_data->bind3, - &ptr_mt6359dcxo_data->trip[4], - &ptr_mt6359dcxo_data->t_type[4], - ptr_mt6359dcxo_data->bind4, - &ptr_mt6359dcxo_data->trip[5], - &ptr_mt6359dcxo_data->t_type[5], - ptr_mt6359dcxo_data->bind5, - &ptr_mt6359dcxo_data->trip[6], - &ptr_mt6359dcxo_data->t_type[6], - ptr_mt6359dcxo_data->bind6, - &ptr_mt6359dcxo_data->trip[7], - &ptr_mt6359dcxo_data->t_type[7], - ptr_mt6359dcxo_data->bind7, - &ptr_mt6359dcxo_data->trip[8], - &ptr_mt6359dcxo_data->t_type[8], - ptr_mt6359dcxo_data->bind8, - &ptr_mt6359dcxo_data->trip[9], - &ptr_mt6359dcxo_data->t_type[9], - ptr_mt6359dcxo_data->bind9, - &ptr_mt6359dcxo_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359dcxo_unregister_thermal\n", __func__); - mt6359dcxo_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359dcxo_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359dcxo_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359dcxo_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359dcxo_data->bind0[i]; - g_bind1[i] = ptr_mt6359dcxo_data->bind1[i]; - g_bind2[i] = ptr_mt6359dcxo_data->bind2[i]; - g_bind3[i] = ptr_mt6359dcxo_data->bind3[i]; - g_bind4[i] = ptr_mt6359dcxo_data->bind4[i]; - g_bind5[i] = ptr_mt6359dcxo_data->bind5[i]; - g_bind6[i] = ptr_mt6359dcxo_data->bind6[i]; - g_bind7[i] = ptr_mt6359dcxo_data->bind7[i]; - g_bind8[i] = ptr_mt6359dcxo_data->bind8[i]; - g_bind9[i] = ptr_mt6359dcxo_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359dcxo_data->trip[i]; - - interval = ptr_mt6359dcxo_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359dcxo_register_thermal\n", __func__); - - mt6359dcxo_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359dcxo_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359dcxo_write", "Bad argument"); - #endif - kfree(ptr_mt6359dcxo_data); - return -EINVAL; -} - -static void mt6359dcxo_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359dcxo_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359dcxo_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359dcxo-sysrst", NULL, - &mt6359dcxo_cooling_sysrst_ops); - return 0; -} - -static int mt6359dcxo_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359dcxo", num_trip, NULL, - &mt6359dcxo_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359dcxo_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359dcxo_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359dcxo_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359dcxo_read, NULL); -} - -static const struct file_operations mt6359dcxo_fops = { - .owner = THIS_MODULE, - .open = mt6359dcxo_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359dcxo_write, - .release = single_release, -}; - -static int __init mt6359dcxo_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359dcxo_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359dcxo_register_cooler(); - if (err) - return err; - - mt6359dcxo_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359dcxo_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359dcxo", 664, mt6359dcxo_dir, - &mt6359dcxo_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359dcxo", mt6359dcxo_start_thermal_timer, - mt6359dcxo_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359dcxo_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359dcxo_unregister_thermal(); - mt6359dcxo_unregister_cooler(); - mtkTTimer_unregister("mt6359dcxo"); -} -module_init(mt6359dcxo_init); -module_exit(mt6359dcxo_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359tsx.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359tsx.c deleted file mode 100644 index 6f792bd5ebc6..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359tsx.c +++ /dev/null @@ -1,597 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6359tsx_cur_temp; -/* - *static long mt6359tsx_start_temp; - *static long mt6359tsx_end_temp; - */ -/*=============================================================*/ - -static int mt6359tsx_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359tsx_get_hw_temp(); - mt6359tsx_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359tsx_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359tsx_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359tsx_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359tsx_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359tsx_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359tsx_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359tsx_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359tsx_dev_ops = { - .bind = mt6359tsx_bind, - .unbind = mt6359tsx_unbind, - .get_temp = mt6359tsx_get_temp, - .get_mode = mt6359tsx_get_mode, - .set_mode = mt6359tsx_set_mode, - .get_trip_type = mt6359tsx_get_trip_type, - .get_trip_temp = mt6359tsx_get_trip_temp, - .get_crit_temp = mt6359tsx_get_crit_temp, -}; - -static int mt6359tsx_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359tsx_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359tsx_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359tsx OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - /* temp marked off to check temperature correctness. */ - // *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359tsx_cooling_sysrst_ops = { - .get_max_state = mt6359tsx_sysrst_get_max_state, - .get_cur_state = mt6359tsx_sysrst_get_cur_state, - .set_cur_state = mt6359tsx_sysrst_set_cur_state, -}; - -static int mt6359tsx_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359tsx_register_thermal(void); -static void mt6359tsx_unregister_thermal(void); - -static ssize_t mt6359tsx_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359tsx_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359tsx_data *ptr_mt6359tsx_data; - - ptr_mt6359tsx_data = - kmalloc(sizeof(*ptr_mt6359tsx_data), GFP_KERNEL); - - if (ptr_mt6359tsx_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359tsx_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359tsx_data->desc) - 1); - - if (copy_from_user(ptr_mt6359tsx_data->desc, buffer, len)) { - kfree(ptr_mt6359tsx_data); - return 0; - } - - ptr_mt6359tsx_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359tsx_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359tsx_data->trip[0], - &ptr_mt6359tsx_data->t_type[0], - ptr_mt6359tsx_data->bind0, - &ptr_mt6359tsx_data->trip[1], - &ptr_mt6359tsx_data->t_type[1], - ptr_mt6359tsx_data->bind1, - &ptr_mt6359tsx_data->trip[2], - &ptr_mt6359tsx_data->t_type[2], - ptr_mt6359tsx_data->bind2, - &ptr_mt6359tsx_data->trip[3], - &ptr_mt6359tsx_data->t_type[3], - ptr_mt6359tsx_data->bind3, - &ptr_mt6359tsx_data->trip[4], - &ptr_mt6359tsx_data->t_type[4], - ptr_mt6359tsx_data->bind4, - &ptr_mt6359tsx_data->trip[5], - &ptr_mt6359tsx_data->t_type[5], - ptr_mt6359tsx_data->bind5, - &ptr_mt6359tsx_data->trip[6], - &ptr_mt6359tsx_data->t_type[6], - ptr_mt6359tsx_data->bind6, - &ptr_mt6359tsx_data->trip[7], - &ptr_mt6359tsx_data->t_type[7], - ptr_mt6359tsx_data->bind7, - &ptr_mt6359tsx_data->trip[8], - &ptr_mt6359tsx_data->t_type[8], - ptr_mt6359tsx_data->bind8, - &ptr_mt6359tsx_data->trip[9], - &ptr_mt6359tsx_data->t_type[9], - ptr_mt6359tsx_data->bind9, - &ptr_mt6359tsx_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359tsx_unregister_thermal\n", __func__); - mt6359tsx_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359tsx_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - kfree(ptr_mt6359tsx_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359tsx_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359tsx_data->bind0[i]; - g_bind1[i] = ptr_mt6359tsx_data->bind1[i]; - g_bind2[i] = ptr_mt6359tsx_data->bind2[i]; - g_bind3[i] = ptr_mt6359tsx_data->bind3[i]; - g_bind4[i] = ptr_mt6359tsx_data->bind4[i]; - g_bind5[i] = ptr_mt6359tsx_data->bind5[i]; - g_bind6[i] = ptr_mt6359tsx_data->bind6[i]; - g_bind7[i] = ptr_mt6359tsx_data->bind7[i]; - g_bind8[i] = ptr_mt6359tsx_data->bind8[i]; - g_bind9[i] = ptr_mt6359tsx_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359tsx_data->trip[i]; - - interval = ptr_mt6359tsx_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359tsx_register_thermal\n", __func__); - - mt6359tsx_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359tsx_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359tsx_write", "Bad argument"); - #endif - kfree(ptr_mt6359tsx_data); - return -EINVAL; -} - -static void mt6359tsx_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359tsx_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359tsx_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359tsx-sysrst", NULL, - &mt6359tsx_cooling_sysrst_ops); - return 0; -} - -static int mt6359tsx_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359tsx", num_trip, NULL, - &mt6359tsx_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359tsx_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359tsx_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359tsx_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359tsx_read, NULL); -} - -static const struct file_operations mt6359tsx_fops = { - .owner = THIS_MODULE, - .open = mt6359tsx_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359tsx_write, - .release = single_release, -}; - -static int __init mt6359tsx_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359tsx_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359tsx_register_cooler(); - if (err) - return err; - - mt6359tsx_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359tsx_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359tsx", 664, mt6359tsx_dir, - &mt6359tsx_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359tsx", mt6359tsx_start_thermal_timer, - mt6359tsx_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359tsx_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359tsx_unregister_thermal(); - mt6359tsx_unregister_cooler(); - mtkTTimer_unregister("mt6359tsx"); -} -module_init(mt6359tsx_init); -module_exit(mt6359tsx_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vcore.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vcore.c deleted file mode 100644 index bb2634ebcab5..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vcore.c +++ /dev/null @@ -1,594 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6359vcore_cur_temp; -/* - *static long mt6359vcore_start_temp; - *static long mt6359vcore_end_temp; - */ -/*=============================================================*/ - -static int mt6359vcore_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vcore_get_hw_temp(); - mt6359vcore_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vcore_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vcore_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vcore_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vcore_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vcore_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vcore_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vcore_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vcore_dev_ops = { - .bind = mt6359vcore_bind, - .unbind = mt6359vcore_unbind, - .get_temp = mt6359vcore_get_temp, - .get_mode = mt6359vcore_get_mode, - .set_mode = mt6359vcore_set_mode, - .get_trip_type = mt6359vcore_get_trip_type, - .get_trip_temp = mt6359vcore_get_trip_temp, - .get_crit_temp = mt6359vcore_get_crit_temp, -}; - -static int mt6359vcore_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vcore_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vcore_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vcore OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - /* temp marked off to check temperature correctness. */ - // *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vcore_cooling_sysrst_ops = { - .get_max_state = mt6359vcore_sysrst_get_max_state, - .get_cur_state = mt6359vcore_sysrst_get_cur_state, - .set_cur_state = mt6359vcore_sysrst_set_cur_state, -}; - -static int mt6359vcore_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vcore_register_thermal(void); -static void mt6359vcore_unregister_thermal(void); - -static ssize_t mt6359vcore_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vcore_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vcore_data *ptr_mt6359vcore_data; - - ptr_mt6359vcore_data = - kmalloc(sizeof(*ptr_mt6359vcore_data), GFP_KERNEL); - - if (ptr_mt6359vcore_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vcore_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vcore_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vcore_data->desc, buffer, len)) { - kfree(ptr_mt6359vcore_data); - return 0; - } - - ptr_mt6359vcore_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vcore_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vcore_data->trip[0], - &ptr_mt6359vcore_data->t_type[0], - ptr_mt6359vcore_data->bind0, - &ptr_mt6359vcore_data->trip[1], - &ptr_mt6359vcore_data->t_type[1], - ptr_mt6359vcore_data->bind1, - &ptr_mt6359vcore_data->trip[2], - &ptr_mt6359vcore_data->t_type[2], - ptr_mt6359vcore_data->bind2, - &ptr_mt6359vcore_data->trip[3], - &ptr_mt6359vcore_data->t_type[3], - ptr_mt6359vcore_data->bind3, - &ptr_mt6359vcore_data->trip[4], - &ptr_mt6359vcore_data->t_type[4], - ptr_mt6359vcore_data->bind4, - &ptr_mt6359vcore_data->trip[5], - &ptr_mt6359vcore_data->t_type[5], - ptr_mt6359vcore_data->bind5, - &ptr_mt6359vcore_data->trip[6], - &ptr_mt6359vcore_data->t_type[6], - ptr_mt6359vcore_data->bind6, - &ptr_mt6359vcore_data->trip[7], - &ptr_mt6359vcore_data->t_type[7], - ptr_mt6359vcore_data->bind7, - &ptr_mt6359vcore_data->trip[8], - &ptr_mt6359vcore_data->t_type[8], - ptr_mt6359vcore_data->bind8, - &ptr_mt6359vcore_data->trip[9], - &ptr_mt6359vcore_data->t_type[9], - ptr_mt6359vcore_data->bind9, - &ptr_mt6359vcore_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vcore_unregister_thermal\n", __func__); - mt6359vcore_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vcore_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - kfree(ptr_mt6359vcore_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vcore_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vcore_data->bind0[i]; - g_bind1[i] = ptr_mt6359vcore_data->bind1[i]; - g_bind2[i] = ptr_mt6359vcore_data->bind2[i]; - g_bind3[i] = ptr_mt6359vcore_data->bind3[i]; - g_bind4[i] = ptr_mt6359vcore_data->bind4[i]; - g_bind5[i] = ptr_mt6359vcore_data->bind5[i]; - g_bind6[i] = ptr_mt6359vcore_data->bind6[i]; - g_bind7[i] = ptr_mt6359vcore_data->bind7[i]; - g_bind8[i] = ptr_mt6359vcore_data->bind8[i]; - g_bind9[i] = ptr_mt6359vcore_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vcore_data->trip[i]; - - interval = ptr_mt6359vcore_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vcore_register_thermal\n", __func__); - - mt6359vcore_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vcore_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vcore_write", "Bad argument"); - #endif - kfree(ptr_mt6359vcore_data); - return -EINVAL; -} - -static void mt6359vcore_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vcore_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vcore_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vcore-sysrst", NULL, - &mt6359vcore_cooling_sysrst_ops); - return 0; -} - -static int mt6359vcore_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vcore", num_trip, NULL, - &mt6359vcore_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vcore_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vcore_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vcore_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vcore_read, NULL); -} - -static const struct file_operations mt6359vcore_fops = { - .owner = THIS_MODULE, - .open = mt6359vcore_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vcore_write, - .release = single_release, -}; - -static int __init mt6359vcore_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vcore_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vcore_register_cooler(); - if (err) - return err; - - mt6359vcore_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vcore_dir) { - mtktspmic_info( - "[%s]: mkdir /proc/driver/thermal failed\n", __func__); - } else { - entry = - proc_create("tz6359vcore", 664, mt6359vcore_dir, - &mt6359vcore_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vcore", mt6359vcore_start_thermal_timer, - mt6359vcore_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vcore_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vcore_unregister_thermal(); - mt6359vcore_unregister_cooler(); - mtkTTimer_unregister("mt6359vcore"); -} -module_init(mt6359vcore_init); -module_exit(mt6359vcore_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vgpu.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vgpu.c deleted file mode 100644 index 48aa96b320e9..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vgpu.c +++ /dev/null @@ -1,605 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6359vgpu_cur_temp; -/* - *static long mt6359vgpu_start_temp; - *static long mt6359vgpu_end_temp; - */ -/*=============================================================*/ - -static int mt6359vgpu_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vgpu_get_hw_temp(); - mt6359vgpu_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vgpu_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vgpu_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vgpu_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vgpu_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vgpu_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vgpu_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vgpu_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vgpu_dev_ops = { - .bind = mt6359vgpu_bind, - .unbind = mt6359vgpu_unbind, - .get_temp = mt6359vgpu_get_temp, - .get_mode = mt6359vgpu_get_mode, - .set_mode = mt6359vgpu_set_mode, - .get_trip_type = mt6359vgpu_get_trip_type, - .get_trip_temp = mt6359vgpu_get_trip_temp, - .get_crit_temp = mt6359vgpu_get_crit_temp, -}; - -static int mt6359vgpu_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vgpu_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vgpu_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vgpu OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - /* temp marked off to check temperature correctness. */ - // *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vgpu_cooling_sysrst_ops = { - .get_max_state = mt6359vgpu_sysrst_get_max_state, - .get_cur_state = mt6359vgpu_sysrst_get_cur_state, - .set_cur_state = mt6359vgpu_sysrst_set_cur_state, -}; - -static int mt6359vgpu_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vgpu_register_thermal(void); -static void mt6359vgpu_unregister_thermal(void); - -static ssize_t mt6359vgpu_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vgpu_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vgpu_data *ptr_mt6359vgpu_data; - - ptr_mt6359vgpu_data = - kmalloc(sizeof(*ptr_mt6359vgpu_data), GFP_KERNEL); - - if (ptr_mt6359vgpu_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vgpu_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vgpu_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vgpu_data->desc, buffer, len)) { - kfree(ptr_mt6359vgpu_data); - return 0; - } - - ptr_mt6359vgpu_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vgpu_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vgpu_data->trip[0], - &ptr_mt6359vgpu_data->t_type[0], - ptr_mt6359vgpu_data->bind0, - &ptr_mt6359vgpu_data->trip[1], - &ptr_mt6359vgpu_data->t_type[1], - ptr_mt6359vgpu_data->bind1, - &ptr_mt6359vgpu_data->trip[2], - &ptr_mt6359vgpu_data->t_type[2], - ptr_mt6359vgpu_data->bind2, - &ptr_mt6359vgpu_data->trip[3], - &ptr_mt6359vgpu_data->t_type[3], - ptr_mt6359vgpu_data->bind3, - &ptr_mt6359vgpu_data->trip[4], - &ptr_mt6359vgpu_data->t_type[4], - ptr_mt6359vgpu_data->bind4, - &ptr_mt6359vgpu_data->trip[5], - &ptr_mt6359vgpu_data->t_type[5], - ptr_mt6359vgpu_data->bind5, - &ptr_mt6359vgpu_data->trip[6], - &ptr_mt6359vgpu_data->t_type[6], - ptr_mt6359vgpu_data->bind6, - &ptr_mt6359vgpu_data->trip[7], - &ptr_mt6359vgpu_data->t_type[7], - ptr_mt6359vgpu_data->bind7, - &ptr_mt6359vgpu_data->trip[8], - &ptr_mt6359vgpu_data->t_type[8], - ptr_mt6359vgpu_data->bind8, - &ptr_mt6359vgpu_data->trip[9], - &ptr_mt6359vgpu_data->t_type[9], - ptr_mt6359vgpu_data->bind9, - &ptr_mt6359vgpu_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk( - "[%s] mt6359vgpu_unregister_thermal\n", __func__); - - mt6359vgpu_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vgpu_write", - "Bad argument"); - #endif - mtktspmic_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vgpu_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vgpu_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vgpu_data->bind0[i]; - g_bind1[i] = ptr_mt6359vgpu_data->bind1[i]; - g_bind2[i] = ptr_mt6359vgpu_data->bind2[i]; - g_bind3[i] = ptr_mt6359vgpu_data->bind3[i]; - g_bind4[i] = ptr_mt6359vgpu_data->bind4[i]; - g_bind5[i] = ptr_mt6359vgpu_data->bind5[i]; - g_bind6[i] = ptr_mt6359vgpu_data->bind6[i]; - g_bind7[i] = ptr_mt6359vgpu_data->bind7[i]; - g_bind8[i] = ptr_mt6359vgpu_data->bind8[i]; - g_bind9[i] = ptr_mt6359vgpu_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vgpu_data->trip[i]; - - interval = ptr_mt6359vgpu_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk( - "[%s] mt6359vgpu_register_thermal\n", __func__); - - mt6359vgpu_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vgpu_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vgpu_write", "Bad argument"); - #endif - kfree(ptr_mt6359vgpu_data); - return -EINVAL; -} - -static void mt6359vgpu_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vgpu_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vgpu_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vgpu-sysrst", NULL, - &mt6359vgpu_cooling_sysrst_ops); - return 0; -} - -static int mt6359vgpu_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vgpu", num_trip, NULL, - &mt6359vgpu_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vgpu_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vgpu_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vgpu_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vgpu_read, NULL); -} - -static const struct file_operations mt6359vgpu_fops = { - .owner = THIS_MODULE, - .open = mt6359vgpu_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vgpu_write, - .release = single_release, -}; - -static int __init mt6359vgpu_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vgpu_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vgpu_register_cooler(); - if (err) - return err; - - mt6359vgpu_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vgpu_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - - } else { - entry = - proc_create("tz6359vgpu", 664, mt6359vgpu_dir, - &mt6359vgpu_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vgpu", mt6359vgpu_start_thermal_timer, - mt6359vgpu_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vgpu_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vgpu_unregister_thermal(); - mt6359vgpu_unregister_cooler(); - mtkTTimer_unregister("mt6359vgpu"); -} -module_init(mt6359vgpu_init); -module_exit(mt6359vgpu_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vproc.c b/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vproc.c deleted file mode 100644 index 87eedf7a7ea3..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/mtk_ts_6359vproc.c +++ /dev/null @@ -1,602 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mt-plat/mtk_thermal_monitor.h" -#include "mach/mtk_thermal.h" -#include "mtk_thermal_timer.h" -#include -#include -#include -#include - -/*============================================================= - *Local variable definition - *============================================================= - */ -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); -static int isTimerCancelled; - -/** - * If curr_temp >= polling_trip_temp1, use interval - * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, - * use interval*polling_factor1 - * else, use interval*polling_factor2 - */ -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ -static unsigned int trip_temp[10] = { 150000, 110000, 100000, 90000, 80000, - 70000, 65000, 60000, 55000, 50000 }; - -static unsigned int cl_dev_sysrst_state; -static struct thermal_zone_device *thz_dev; - -static struct thermal_cooling_device *cl_dev_sysrst; -static int kernelmode; - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static int num_trip = 1; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - -static long mt6359vproc_cur_temp; -/* - *static long mt6359vproc_start_temp; - *static long mt6359vproc_end_temp; - */ -/*=============================================================*/ - -static int mt6359vproc_get_temp(struct thermal_zone_device *thermal, int *t) -{ - *t = mt6359vproc_get_hw_temp(); - mt6359vproc_cur_temp = *t; - - if ((int)*t >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*t < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - - return 0; -} - -static int mt6359vproc_bind -(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mt6359vproc_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktspmic_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktspmic_info( - "[%s] error unbinding cooling dev\n", __func__); - return -EINVAL; - } - - mtktspmic_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - -static int mt6359vproc_get_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mt6359vproc_set_mode -(struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - -static int mt6359vproc_get_trip_type -(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mt6359vproc_get_trip_temp -(struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -static int mt6359vproc_get_crit_temp -(struct thermal_zone_device *thermal, int *temperature) -{ - *temperature = mtktspmic_TEMP_CRIT; - return 0; -} - -/* bind callback functions to thermalzone */ -static struct thermal_zone_device_ops mt6359vproc_dev_ops = { - .bind = mt6359vproc_bind, - .unbind = mt6359vproc_unbind, - .get_temp = mt6359vproc_get_temp, - .get_mode = mt6359vproc_get_mode, - .set_mode = mt6359vproc_set_mode, - .get_trip_type = mt6359vproc_get_trip_type, - .get_trip_temp = mt6359vproc_get_trip_temp, - .get_crit_temp = mt6359vproc_get_crit_temp, -}; - -static int mt6359vproc_sysrst_get_max_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int mt6359vproc_sysrst_get_cur_state -(struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int mt6359vproc_sysrst_set_cur_state -(struct thermal_cooling_device *cdev, unsigned long state) -{ - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - mtktspmic_info("mt6359vproc OT: reset, reset, reset!!!"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - mtktspmic_info("*****************************************"); - mtktspmic_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - /* temp marked off to check temperature correctness. */ - // *(unsigned int *)0x0 = 0xdead; - /* To trigger data abort to reset the system for thermal protection. */ - } - return 0; -} - -static struct thermal_cooling_device_ops mt6359vproc_cooling_sysrst_ops = { - .get_max_state = mt6359vproc_sysrst_get_max_state, - .get_cur_state = mt6359vproc_sysrst_get_cur_state, - .set_cur_state = mt6359vproc_sysrst_set_cur_state, -}; - -static int mt6359vproc_read(struct seq_file *m, void *v) -{ - seq_printf(m, - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], - g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - -static int mt6359vproc_register_thermal(void); -static void mt6359vproc_unregister_thermal(void); - -static ssize_t mt6359vproc_write -(struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0; - int i; - - struct mt6359vproc_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - struct mt6359vproc_data *ptr_mt6359vproc_data; - - ptr_mt6359vproc_data = - kmalloc(sizeof(*ptr_mt6359vproc_data), GFP_KERNEL); - - if (ptr_mt6359vproc_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mt6359vproc_data->desc) - 1)) ? - count : (sizeof(ptr_mt6359vproc_data->desc) - 1); - - if (copy_from_user(ptr_mt6359vproc_data->desc, buffer, len)) { - kfree(ptr_mt6359vproc_data); - return 0; - } - - ptr_mt6359vproc_data->desc[len] = '\0'; - - if (sscanf - (ptr_mt6359vproc_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mt6359vproc_data->trip[0], - &ptr_mt6359vproc_data->t_type[0], - ptr_mt6359vproc_data->bind0, - &ptr_mt6359vproc_data->trip[1], - &ptr_mt6359vproc_data->t_type[1], - ptr_mt6359vproc_data->bind1, - &ptr_mt6359vproc_data->trip[2], - &ptr_mt6359vproc_data->t_type[2], - ptr_mt6359vproc_data->bind2, - &ptr_mt6359vproc_data->trip[3], - &ptr_mt6359vproc_data->t_type[3], - ptr_mt6359vproc_data->bind3, - &ptr_mt6359vproc_data->trip[4], - &ptr_mt6359vproc_data->t_type[4], - ptr_mt6359vproc_data->bind4, - &ptr_mt6359vproc_data->trip[5], - &ptr_mt6359vproc_data->t_type[5], - ptr_mt6359vproc_data->bind5, - &ptr_mt6359vproc_data->trip[6], - &ptr_mt6359vproc_data->t_type[6], - ptr_mt6359vproc_data->bind6, - &ptr_mt6359vproc_data->trip[7], - &ptr_mt6359vproc_data->t_type[7], - ptr_mt6359vproc_data->bind7, - &ptr_mt6359vproc_data->trip[8], - &ptr_mt6359vproc_data->t_type[8], - ptr_mt6359vproc_data->bind8, - &ptr_mt6359vproc_data->trip[9], - &ptr_mt6359vproc_data->t_type[9], - ptr_mt6359vproc_data->bind9, - &ptr_mt6359vproc_data->time_msec) == 32) { - - down(&sem_mutex); - mtktspmic_dprintk("[%s] mt6359vproc_unregister_thermal\n", - __func__); - - mt6359vproc_unregister_thermal(); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mt6359vproc_write", - "Bad argument"); - #endif - mtktspmic_dprintk("[%s] bad argument\n", __func__); - - kfree(ptr_mt6359vproc_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mt6359vproc_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] - = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] - = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mt6359vproc_data->bind0[i]; - g_bind1[i] = ptr_mt6359vproc_data->bind1[i]; - g_bind2[i] = ptr_mt6359vproc_data->bind2[i]; - g_bind3[i] = ptr_mt6359vproc_data->bind3[i]; - g_bind4[i] = ptr_mt6359vproc_data->bind4[i]; - g_bind5[i] = ptr_mt6359vproc_data->bind5[i]; - g_bind6[i] = ptr_mt6359vproc_data->bind6[i]; - g_bind7[i] = ptr_mt6359vproc_data->bind7[i]; - g_bind8[i] = ptr_mt6359vproc_data->bind8[i]; - g_bind9[i] = ptr_mt6359vproc_data->bind9[i]; - } - - mtktspmic_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", - __func__, g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", - g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6]); - - mtktspmic_dprintk( - "g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], - g_THERMAL_TRIP[9]); - - mtktspmic_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,", - __func__, g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - mtktspmic_dprintk( - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mt6359vproc_data->trip[i]; - - interval = ptr_mt6359vproc_data->time_msec / 1000; - - mtktspmic_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", - __func__, trip_temp[0], trip_temp[1], trip_temp[2], - trip_temp[3]); - - mtktspmic_dprintk( - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", - trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], - trip_temp[8]); - - mtktspmic_dprintk("trip_9_temp=%d,time_ms=%d\n", - trip_temp[9], interval * 1000); - - mtktspmic_dprintk("[%s] mt6359vproc_register_thermal\n", - __func__); - - mt6359vproc_register_thermal(); - up(&sem_mutex); - kfree(ptr_mt6359vproc_data); - return count; - } - - mtktspmic_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mt6359vproc_write", "Bad argument"); - #endif - kfree(ptr_mt6359vproc_data); - return -EINVAL; -} - -static void mt6359vproc_cancel_thermal_timer(void) -{ - /* stop thermal framework polling when entering deep idle */ - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev) { - cancel_delayed_work(&(thz_dev->poll_queue)); - isTimerCancelled = 1; - } - - up(&sem_mutex); -} - -static void mt6359vproc_start_thermal_timer(void) -{ - /* resume thermal framework polling when leaving deep idle */ - if (!isTimerCancelled) - return; - - isTimerCancelled = 0; - - if (down_trylock(&sem_mutex)) - return; - - if (thz_dev != NULL && interval != 0) - mod_delayed_work(system_freezable_power_efficient_wq, - &(thz_dev->poll_queue), - round_jiffies(msecs_to_jiffies(1000))); - - up(&sem_mutex); -} - -static int mt6359vproc_register_cooler(void) -{ - cl_dev_sysrst = mtk_thermal_cooling_device_register( - "mt6359vproc-sysrst", NULL, - &mt6359vproc_cooling_sysrst_ops); - return 0; -} - -static int mt6359vproc_register_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - /* trips : trip 0~2 */ - thz_dev = mtk_thermal_zone_device_register( - "mt6359vproc", num_trip, NULL, - &mt6359vproc_dev_ops, 0, 0, 0, interval * 1000); - - return 0; -} - -static void mt6359vproc_unregister_cooler(void) -{ - if (cl_dev_sysrst) { - mtk_thermal_cooling_device_unregister(cl_dev_sysrst); - cl_dev_sysrst = NULL; - } -} - -static void mt6359vproc_unregister_thermal(void) -{ - mtktspmic_dprintk("[%s]\n", __func__); - - if (thz_dev) { - mtk_thermal_zone_device_unregister(thz_dev); - thz_dev = NULL; - } -} - -static int mt6359vproc_open(struct inode *inode, struct file *file) -{ - return single_open(file, mt6359vproc_read, NULL); -} - -static const struct file_operations mt6359vproc_fops = { - .owner = THIS_MODULE, - .open = mt6359vproc_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mt6359vproc_write, - .release = single_release, -}; - -static int __init mt6359vproc_init(void) -{ - int err = 0; - - struct proc_dir_entry *entry = NULL; - struct proc_dir_entry *mt6359vproc_dir = NULL; - - mtktspmic_info("[%s]\n", __func__); - - err = mt6359vproc_register_cooler(); - if (err) - return err; - - mt6359vproc_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mt6359vproc_dir) { - mtktspmic_info("[%s]: mkdir /proc/driver/thermal failed\n", - __func__); - } else { - entry = - proc_create("tz6359vproc", 664, mt6359vproc_dir, - &mt6359vproc_fops); - if (entry) - proc_set_user(entry, uid, gid); - } - - mtkTTimer_register("mt6359vproc", mt6359vproc_start_thermal_timer, - mt6359vproc_cancel_thermal_timer); - - return 0; -} - -static void __exit mt6359vproc_exit(void) -{ - mtktspmic_info("[%s]\n", __func__); - mt6359vproc_unregister_thermal(); - mt6359vproc_unregister_cooler(); - mtkTTimer_unregister("mt6359vproc"); -} -module_init(mt6359vproc_init); -module_exit(mt6359vproc_exit); diff --git a/drivers/misc/mediatek/thermal/mt6893/src/vtskin_temp.c b/drivers/misc/mediatek/thermal/mt6893/src/vtskin_temp.c deleted file mode 100644 index b57f4b0080d9..000000000000 --- a/drivers/misc/mediatek/thermal/mt6893/src/vtskin_temp.c +++ /dev/null @@ -1,2224 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright (c) 2021 MediaTek Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vtskin_temp.h" -#include "mt-plat/mtk_thermal_monitor.h" -#include -#include -#include -#include -#ifdef CONFIG_PM -#include -#endif - - - -static DEFINE_MUTEX(vtskin_mutex); - - -static kuid_t uid = KUIDT_INIT(0); -static kgid_t gid = KGIDT_INIT(1000); -static DEFINE_SEMAPHORE(sem_mutex); - - -static int mtktsvtskin_debug_log = 1; -static unsigned int cl_dev_sysrst_state; - -#define VTSKIN_MAX_INDEX 0 -#define VTSKIN1_INDEX 1 -#define VTSKIN2_INDEX 2 -#define VTSKIN3_INDEX 3 - - -struct thermal_zone_device *thz_dev0; -struct thermal_zone_device *thz_dev1; -struct thermal_zone_device *thz_dev2; -struct thermal_zone_device *thz_dev3; - - -#define mtktsvtskin_TEMP_CRIT 100000 /* 100.000 degree Celsius */ -static int kernelmode; - -//Common to all vtskin - -static unsigned int interval = 1; /* seconds, 0 : no auto polling */ - - - -//Vtskin-max - -static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -//Trip tempratures - -static int trip_temp[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -//coolers -static int num_trip ; -static char g_bind0[20] = { 0 }; -static char g_bind1[20] = { 0 }; -static char g_bind2[20] = { 0 }; -static char g_bind3[20] = { 0 }; -static char g_bind4[20] = { 0 }; -static char g_bind5[20] = { 0 }; -static char g_bind6[20] = { 0 }; -static char g_bind7[20] = { 0 }; -static char g_bind8[20] = { 0 }; -static char g_bind9[20] = { 0 }; - - - - -//Vtskin1 - - -static int g_THERMAL_TRIP1[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -//Trip tempratures - -static int trip_temp1[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -//coolers -static int num_trip1 ; -static char g_bind10[20] = { 0 }; -static char g_bind11[20] = { 0 }; -static char g_bind12[20] = { 0 }; -static char g_bind13[20] = { 0 }; -static char g_bind14[20] = { 0 }; -static char g_bind15[20] = { 0 }; -static char g_bind16[20] = { 0 }; -static char g_bind17[20] = { 0 }; -static char g_bind18[20] = { 0 }; -static char g_bind19[20] = { 0 }; - - - - - -//Vtskin2 - - -static int g_THERMAL_TRIP2[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -//Trip tempratures - -static int trip_temp2[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -//coolers -static int num_trip2 ; -static char g_bind20[20] = { 0 }; -static char g_bind21[20] = { 0 }; -static char g_bind22[20] = { 0 }; -static char g_bind23[20] = { 0 }; -static char g_bind24[20] = { 0 }; -static char g_bind25[20] = { 0 }; -static char g_bind26[20] = { 0 }; -static char g_bind27[20] = { 0 }; -static char g_bind28[20] = { 0 }; -static char g_bind29[20] = { 0 }; - - - - -//Vtskin3 - -static int g_THERMAL_TRIP3[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -//Trip tempratures - -static int trip_temp3[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -//coolers -static int num_trip3 ; -static char g_bind30[20] = { 0 }; -static char g_bind31[20] = { 0 }; -static char g_bind32[20] = { 0 }; -static char g_bind33[20] = { 0 }; -static char g_bind34[20] = { 0 }; -static char g_bind35[20] = { 0 }; -static char g_bind36[20] = { 0 }; -static char g_bind37[20] = { 0 }; -static char g_bind38[20] = { 0 }; -static char g_bind39[20] = { 0 }; - - - -//Poling factor - -static int polling_trip_temp1 = 40000; -static int polling_trip_temp2 = 20000; -static int polling_factor1 = 5000; -static int polling_factor2 = 10000; - -static int g_resume_done = 1; - - - -#define mtktsvtskin_dprintk(fmt, args...) \ -do { \ - if (mtktsvtskin_debug_log) { \ - pr_notice("[Thermal/TZ/VTSKIN]" fmt, ##args); \ - } \ -} while (0) - -#define mtktsvtskin_printk(fmt, args...) \ -pr_notice("[Thermal/TZ/VTSKIN]" fmt, ##args) - - -//change to enum - -static int mtk_thermal_get_vtksin_idx(char *type) -{ - if (strncmp(type, "vtskin-max", 10) == 0) - return 0; - else if (strncmp(type, "vtskin1", 7) == 0) - return 1; - else if (strncmp(type, "vtskin2", 7) == 0) - return 2; - else if (strncmp(type, "vtskin3", 7) == 0) - return 3; - else if (strncmp(type, "vtskin4", 7) == 0) - return 4; - else if (strncmp(type, "vtskin5", 7) == 0) - return 5; - else if (strncmp(type, "vtskin6", 7) == 0) - return 6; - return -1; -} - - -char *mtk_thermal_get_vtksin_tz_name(int id) -{ - - if (id == 0) - return "vtskin-max"; - else if (id == 1) - return "vtskin1"; - else if (id == 2) - return "vtskin2"; - else if (id == 3) - return "vtskin3"; - else if (id == 4) - return "vtskin4"; - else if (id == 5) - return "vtskin5"; - else if (id == 6) - return "vtskin6"; - - return NULL; -} - - -char *mtk_thermal_get_vtksin_tz_proc_name(int id) -{ - - if (id == 0) - return "tzvtskin-max"; - else if (id == 1) - return "tzvtskin1"; - else if (id == 2) - return "tzvtskin2"; - else if (id == 3) - return "tzvtskin3"; - else if (id == 4) - return "tzvtskin4"; - else if (id == 5) - return "tzvtskin5"; - else if (id == 6) - return "tzvtskin6"; - - return NULL; -} - - -enum mt6893_vtskin_sensor_enum { - MT6893_VTSKIN_MAX, - MT6893_VTSKIN_1, - MT6893_VTSKIN_2, - MT6893_VTSKIN_3, - MT6893_VTSKIN_4, - MT6893_VTSKIN_5, - MT6893_VTSKIN_6, - MT6893_VTSKIN_NUM, -}; -struct vtskin_tz_param mt6893_vtskin_params[] = { - [MT6893_VTSKIN_MAX] = { - .ref_num = 0, - .operation = OP_MAX, - }, - [MT6893_VTSKIN_1] = { - .ref_num = 0, - .operation = OP_COEF, - }, - [MT6893_VTSKIN_2] = { - .ref_num = 0, - .operation = OP_COEF, - }, - [MT6893_VTSKIN_3] = { - .ref_num = 0, - .operation = OP_COEF, - }, - [MT6893_VTSKIN_4] = { - .ref_num = 0, - .operation = OP_COEF, - }, - [MT6893_VTSKIN_5] = { - .ref_num = 0, - .operation = OP_COEF, - }, - [MT6893_VTSKIN_6] = { - .ref_num = 0, - .operation = OP_COEF, - } -}; -static struct vtskin_data mt6893_vtskin_data = { - .num_sensor = MT6893_VTSKIN_NUM, - .params = mt6893_vtskin_params, -}; - - - -static int tsvtskin_sysrst_get_max_state( -struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = 1; - return 0; -} - -static int tsvtskin_sysrst_get_cur_state( -struct thermal_cooling_device *cdev, unsigned long *state) -{ - *state = cl_dev_sysrst_state; - return 0; -} - -static int tsvtskin_sysrst_set_cur_state( -struct thermal_cooling_device *cdev, unsigned long state) -{ - - cl_dev_sysrst_state = state; - if (cl_dev_sysrst_state == 1) { - pr_notice("Power/vtskin: reset, reset, reset!!!"); - pr_notice("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - pr_notice("*****************************************"); - pr_notice("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - - /* To trigger data abort to reset the system - * for thermal protection. - */ - BUG_ON(1); - } - return 0; -} - - -static struct thermal_cooling_device_ops mtktsvtskin_cooling_sysrst_ops = { - .get_max_state = tsvtskin_sysrst_get_max_state, - .get_cur_state = tsvtskin_sysrst_get_cur_state, - .set_cur_state = tsvtskin_sysrst_set_cur_state, -}; - - - - -int mtktsvtskin_register_cooler(int id) -{ - /* cooling devices */ - char tz_name[20] = {0}; - - strcpy(tz_name,mtk_thermal_get_vtksin_tz_name(id)); - mtk_thermal_cooling_device_register( - strcat(tz_name,"-sysrst"), NULL, - &mtktsvtskin_cooling_sysrst_ops); - return 0; -} - -static struct vtskin_data *parse_dt(struct platform_device *pdev) -{ - struct device_node *root, *vtskin_map, *vtskin_child_map; - int count = 0; - int num_sensor = 0; - struct vtskin_tz_param *params; - struct device *dev = &pdev->dev; - - root = pdev->dev.of_node; - of_property_read_u32(root, "num-sensor", &num_sensor); - pr_notice("vtskin num_sensor %d\n", num_sensor); - mt6893_vtskin_data.num_sensor = num_sensor; - mt6893_vtskin_data.dev = dev; - mt6893_vtskin_data.params = devm_kzalloc(dev, num_sensor*sizeof(*params), GFP_KERNEL); - if(!mt6893_vtskin_data.params){ - pr_notice("Error: Failed to allocate memory\n"); - return NULL; - } - for_each_child_of_node(root, vtskin_map) { - int ref_num = 0; - char *operation = NULL; - int child_count = 0; - - of_property_read_u32(vtskin_map, "ref-num", &ref_num); - pr_notice("vtskin ref_num %d\n", ref_num); - mt6893_vtskin_data.params[count].ref_num= ref_num; - of_property_read_string(vtskin_map, "operation", (const char **)&operation); - pr_notice(" vtskin operation %s\n", operation); - - if (!strcmp(operation, "OP_COEF")) - mt6893_vtskin_data.params[count].operation = OP_COEF; - else if(!strcmp(operation, "OP_MAX")) - mt6893_vtskin_data.params[count].operation = OP_MAX; - else - pr_notice("vtskin wrong coefficient %s\n", operation); - - for_each_child_of_node(vtskin_map, vtskin_child_map){ - char *sensor_name = NULL; - int sensor_coeff = 0; - - of_property_read_string(vtskin_child_map, "sensor-name", - (const char **)&sensor_name); - of_property_read_s32(vtskin_child_map, "sensor-coeff", &sensor_coeff); - pr_notice("vtskin sensor-name %s\n", sensor_name); - pr_notice("vtskin sensor-coeff %lld\n", sensor_coeff); - strcpy( - mt6893_vtskin_data.params[count].vtskin_ref[child_count].sensor_name, - sensor_name); - mt6893_vtskin_data.params[count].vtskin_ref[child_count].sensor_coef = - sensor_coeff; - child_count++; - } - count++; - } - return &mt6893_vtskin_data; -} - - - - - - - -static int mtktsvtskin3_bind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind30)) { - table_val = 0; - pr_notice("g_bind0 [%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind31)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind32)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind33)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind34)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind35)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind36)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind37)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind38)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind39)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - pr_notice("mtktsvtskin_bind called return 0\n"); - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - pr_notice( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - pr_notice("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mtktsvtskin3_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind30)) { - table_val = 0; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind31)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind32)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind33)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind34)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind35)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind36)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind37)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind38)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind39)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktsvtskin_dprintk( - "[%s] error unbinding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktsvtskin_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - - - - -static int mtktsvtskin2_bind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind20)) { - table_val = 0; - pr_notice("g_bind0 [%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind21)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind22)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind23)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind24)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind25)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind26)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind27)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind28)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind29)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - pr_notice("mtktsvtskin_bind called return 0\n"); - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - pr_notice( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - pr_notice("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mtktsvtskin2_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind20)) { - table_val = 0; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind21)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind22)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind23)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind24)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind25)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind26)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind27)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind28)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind29)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktsvtskin_dprintk( - "[%s] error unbinding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktsvtskin_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - - - - -static int mtktsvtskin1_bind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind10)) { - table_val = 0; - pr_notice("g_bind0 [%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind11)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind12)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind13)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind14)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind15)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind16)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind17)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind18)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind19)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - pr_notice("mtktsvtskin_bind called return 0\n"); - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - pr_notice( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - pr_notice("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mtktsvtskin1_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - if (!strcmp(cdev->type, g_bind10)) { - table_val = 0; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind11)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind12)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind13)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind14)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind15)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind16)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind17)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind18)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind19)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktsvtskin_dprintk( - "[%s] error unbinding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktsvtskin_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - - -static int mtktsvtskin_bind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - pr_notice("g_bind0 [%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else { - return 0; - } - - if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) { - pr_notice( - "[%s] error binding cooling dev\n", __func__); - return -EINVAL; - } - - pr_notice("[%s] binding OK, %d\n", __func__, table_val); - return 0; -} - -static int mtktsvtskin_unbind(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) -{ - int table_val = 0; - - int id = mtk_thermal_get_vtksin_idx(thermal->type); - if(id == 0) - return 0; - - if (!strcmp(cdev->type, g_bind0)) { - table_val = 0; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind1)) { - table_val = 1; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind2)) { - table_val = 2; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind3)) { - table_val = 3; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind4)) { - table_val = 4; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind5)) { - table_val = 5; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind6)) { - table_val = 6; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind7)) { - table_val = 7; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind8)) { - table_val = 8; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else if (!strcmp(cdev->type, g_bind9)) { - table_val = 9; - mtktsvtskin_dprintk("[%s] %s\n", __func__, cdev->type); - } else - return 0; - - if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) { - mtktsvtskin_dprintk( - "[%s] error unbinding cooling dev\n", __func__); - - return -EINVAL; - } - - mtktsvtskin_dprintk("[%s] unbinding OK\n", __func__); - return 0; -} - - -//Common to all Vtskin - -static int mtktsvtskin_get_temp(struct thermal_zone_device *thermal, int *temp) -{ - - struct vtskin_data *skin_data = &mt6893_vtskin_data; - struct vtskin_tz_param *skin_param = skin_data->params; - struct thermal_zone_device *tzd; - long long vtskin = 0, coef; - int tz_temp, i, ret; - char *sensor_name; - int id = mtk_thermal_get_vtksin_idx(thermal->type); - - if (!g_resume_done){ - *temp = THERMAL_TEMP_INVALID; - return 0; - } - if (skin_param[id].ref_num == 0) { - *temp = THERMAL_TEMP_INVALID; - return 0; - } - for (i = 0; i < skin_param[id].ref_num; i++) { - sensor_name = skin_param[id].vtskin_ref[i].sensor_name; - if (!sensor_name) { - pr_notice("get sensor name fail %d\n", i); - *temp = THERMAL_TEMP_INVALID; - return -EINVAL; - } - pr_notice("vtskin_get_temp sensor_name %s\n", sensor_name); - tzd = thermal_zone_get_zone_by_name(sensor_name); - if (IS_ERR_OR_NULL(tzd) || !tzd->ops->get_temp) { - pr_notice("get %s temp fail\n", sensor_name); - *temp = THERMAL_TEMP_INVALID; - return -EINVAL; - } - ret = tzd->ops->get_temp(tzd, &tz_temp); - if (ret < 0) { - pr_notice("%s get_temp fail %d\n", sensor_name, ret); - *temp = THERMAL_TEMP_INVALID; - return -EINVAL; - } - if (skin_param[id].operation == OP_MAX) { - if (i == 0) - *temp = THERMAL_TEMP_INVALID; - if (tz_temp > *temp) - *temp = tz_temp; - - pr_notice("get tz_temp %d\n", *temp); - } else if (skin_param[id].operation == OP_COEF) { - coef = skin_param[id].vtskin_ref[i].sensor_coef; - pr_notice("sensor_coef: %d\n", coef); - vtskin += tz_temp * coef; - if (i == skin_param[id].ref_num - 1){ - pr_notice(" divide by vtskin / 10"); - *temp = (int)(vtskin / 10); - } - } - } - - - - if ((int)*temp >= polling_trip_temp1) - thermal->polling_delay = interval * 1000; - else if ((int)*temp < polling_trip_temp2) - thermal->polling_delay = interval * polling_factor2; - else - thermal->polling_delay = interval * polling_factor1; - return 0; -} - - - - - - -//Common to all Vtskin - -static int mtktsvtskin_get_mode( -struct thermal_zone_device *thermal, enum thermal_device_mode *mode) -{ - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; - return 0; -} - -static int mtktsvtskin_set_mode( -struct thermal_zone_device *thermal, enum thermal_device_mode mode) -{ - kernelmode = mode; - return 0; -} - - -static int mtktsvtskin_get_crit_temp(struct thermal_zone_device *thermal, - int *temperature) -{ - *temperature = mtktsvtskin_TEMP_CRIT; - return 0; -} - - - //vtskin-max - - -static int mtktsvtskin_get_trip_type( -struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP[trip]; - return 0; -} - -static int mtktsvtskinget_trip_temp( -struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp[trip]; - return 0; -} - -//vtskin1 - -static int mtktsvtskin1_get_trip_type( -struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP1[trip]; - return 0; -} - -static int mtktsvtskin1_get_trip_temp( -struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp1[trip]; - return 0; -} - - - -//vtskin2 - -static int mtktsvtskin2_get_trip_type( -struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP2[trip]; - return 0; -} - -static int mtktsvtskin2_get_trip_temp( -struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp2[trip]; - return 0; -} - - - -//vtskin3 - -static int mtktsvtskin3_get_trip_type( -struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) -{ - *type = g_THERMAL_TRIP3[trip]; - return 0; -} - -static int mtktsvtskin3_get_trip_temp( -struct thermal_zone_device *thermal, int trip, int *temp) -{ - *temp = trip_temp3[trip]; - return 0; -} - - -static struct thermal_zone_device_ops mtktsvtskin3_dev_ops = { - .bind = mtktsvtskin3_bind, - .unbind = mtktsvtskin3_unbind, - .get_temp = mtktsvtskin_get_temp, - .get_mode = mtktsvtskin_get_mode, - .set_mode = mtktsvtskin_set_mode, - .get_trip_type = mtktsvtskin3_get_trip_type, - .get_trip_temp = mtktsvtskin3_get_trip_temp, - .get_crit_temp = mtktsvtskin_get_crit_temp, -}; - - - -static struct thermal_zone_device_ops mtktsvtskin2_dev_ops = { - .bind = mtktsvtskin2_bind, - .unbind = mtktsvtskin2_unbind, - .get_temp = mtktsvtskin_get_temp, - .get_mode = mtktsvtskin_get_mode, - .set_mode = mtktsvtskin_set_mode, - .get_trip_type = mtktsvtskin2_get_trip_type, - .get_trip_temp = mtktsvtskin2_get_trip_temp, - .get_crit_temp = mtktsvtskin_get_crit_temp, -}; - - -static struct thermal_zone_device_ops mtktsvtskin1_dev_ops = { - .bind = mtktsvtskin1_bind, - .unbind = mtktsvtskin1_unbind, - .get_temp = mtktsvtskin_get_temp, - .get_mode = mtktsvtskin_get_mode, - .set_mode = mtktsvtskin_set_mode, - .get_trip_type = mtktsvtskin1_get_trip_type, - .get_trip_temp = mtktsvtskin1_get_trip_temp, - .get_crit_temp = mtktsvtskin_get_crit_temp, -}; - - -static struct thermal_zone_device_ops mtktsvtskin_max_dev_ops = { - .bind = mtktsvtskin_bind, - .unbind = mtktsvtskin_unbind, - .get_temp = mtktsvtskin_get_temp, - .get_mode = mtktsvtskin_get_mode, - .set_mode = mtktsvtskin_set_mode, - .get_trip_type = mtktsvtskin_get_trip_type, - .get_trip_temp = mtktsvtskinget_trip_temp, - .get_crit_temp = mtktsvtskin_get_crit_temp, -}; - - - -void mtktsvtskin_max_register_thermal(void) -{ - - - int i = VTSKIN_MAX_INDEX, ret; - struct vtskin_data *skin_data = &mt6893_vtskin_data; - - - - thz_dev0= mtk_thermal_zone_device_register(mtk_thermal_get_vtksin_tz_name(i), num_trip, - NULL, &mtktsvtskin_max_dev_ops, - 0, 0, 0, interval * 1000); - - if (IS_ERR(thz_dev0)) - pr_notice("Thermal zone register vtskin max fail"); - - ret = snprintf(skin_data->params[i].tz_name, THERMAL_NAME_LENGTH, thz_dev0->type); - if (ret < 0) - pr_notice("copy tz_name fail %s\n", thz_dev0->type); - - - -} - - -void mtktsvtskin1_register_thermal(void) -{ - - - int i = VTSKIN1_INDEX, ret; - struct vtskin_data *skin_data = &mt6893_vtskin_data; - - - thz_dev1= mtk_thermal_zone_device_register(mtk_thermal_get_vtksin_tz_name(i), num_trip1, - NULL, &mtktsvtskin1_dev_ops, - 0, 0, 0, interval * 1000); - - if (IS_ERR(thz_dev1)) - pr_notice("Thermal zone register fail"); - - ret = snprintf(skin_data->params[i].tz_name, THERMAL_NAME_LENGTH, thz_dev1->type); - if (ret < 0) - pr_notice("copy tz_name fail %s\n", thz_dev1->type); - - - -} - - -void mtktsvtskin2_register_thermal(void) -{ - - - int i = VTSKIN2_INDEX , ret; - struct vtskin_data *skin_data = &mt6893_vtskin_data; - - - thz_dev2= mtk_thermal_zone_device_register(mtk_thermal_get_vtksin_tz_name(i), num_trip2, - NULL, &mtktsvtskin2_dev_ops, - 0, 0, 0, interval * 1000); - - if (IS_ERR(thz_dev2)) - pr_notice("Thermal zone register fail"); - - ret = snprintf(skin_data->params[i].tz_name, THERMAL_NAME_LENGTH, thz_dev2->type); - if (ret < 0) - pr_notice("copy tz_name fail %s\n", thz_dev2->type); - - - -} - - -void mtktsvtskin3_register_thermal(void) -{ - - - int i = VTSKIN3_INDEX , ret; - struct vtskin_data *skin_data = &mt6893_vtskin_data; - - thz_dev3= mtk_thermal_zone_device_register(mtk_thermal_get_vtksin_tz_name(i), num_trip3, - NULL, &mtktsvtskin3_dev_ops, - 0, 0, 0, interval * 1000); - - if (IS_ERR(thz_dev3)) - pr_notice("Thermal zone register fail"); - - ret = snprintf(skin_data->params[i].tz_name, THERMAL_NAME_LENGTH, thz_dev3->type); - if (ret < 0) - pr_notice("copy tz_name fail %s\n", thz_dev3->type); - - - -} - - - - -static void mtktsvtskin_max_unregister_thermal(void) -{ - mtktsvtskin_dprintk("[%s]\n", __func__); - - if (thz_dev0) { - mtk_thermal_zone_device_unregister(thz_dev0); - thz_dev0 = NULL; - } -} - - -static void mtktsvtskin1_unregister_thermal(void) -{ - mtktsvtskin_dprintk("[%s]\n", __func__); - - if (thz_dev1) { - mtk_thermal_zone_device_unregister(thz_dev1); - thz_dev1 = NULL; - } -} - - -static void mtktsvtskin2_unregister_thermal(void) -{ - mtktsvtskin_dprintk("[%s]\n", __func__); - - if (thz_dev2) { - mtk_thermal_zone_device_unregister(thz_dev2); - thz_dev2 = NULL; - } -} - - -static void mtktsvtskin3_unregister_thermal(void) -{ - mtktsvtskin_dprintk("[%s]\n", __func__); - - if (thz_dev3) { - mtk_thermal_zone_device_unregister(thz_dev3); - thz_dev3 = NULL; - } -} - - -static ssize_t mtktsvtskin3_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0, i; - struct mtktsvtskin_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - - struct mtktsvtskin_data *ptr_mtktsvtskin_data = kmalloc( - sizeof(*ptr_mtktsvtskin_data), GFP_KERNEL); - - - pr_notice("num_trip3 mtktsvtskin_write [%d]\n",count); - - if (ptr_mtktsvtskin_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mtktsvtskin_data->desc) - 1)) ? - count : (sizeof(ptr_mtktsvtskin_data->desc) - 1); - - if (copy_from_user(ptr_mtktsvtskin_data->desc, buffer, len)) { - kfree(ptr_mtktsvtskin_data); - return 0; - } - - ptr_mtktsvtskin_data->desc[len] = '\0'; - - if (sscanf - (ptr_mtktsvtskin_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip3, - &ptr_mtktsvtskin_data->trip[0], - &ptr_mtktsvtskin_data->t_type[0], - ptr_mtktsvtskin_data->bind0, - &ptr_mtktsvtskin_data->trip[1], - &ptr_mtktsvtskin_data->t_type[1], - ptr_mtktsvtskin_data->bind1, - &ptr_mtktsvtskin_data->trip[2], - &ptr_mtktsvtskin_data->t_type[2], - ptr_mtktsvtskin_data->bind2, - &ptr_mtktsvtskin_data->trip[3], - &ptr_mtktsvtskin_data->t_type[3], - ptr_mtktsvtskin_data->bind3, - &ptr_mtktsvtskin_data->trip[4], - &ptr_mtktsvtskin_data->t_type[4], - ptr_mtktsvtskin_data->bind4, - &ptr_mtktsvtskin_data->trip[5], - &ptr_mtktsvtskin_data->t_type[5], - ptr_mtktsvtskin_data->bind5, - &ptr_mtktsvtskin_data->trip[6], - &ptr_mtktsvtskin_data->t_type[6], - ptr_mtktsvtskin_data->bind6, - &ptr_mtktsvtskin_data->trip[7], - &ptr_mtktsvtskin_data->t_type[7], - ptr_mtktsvtskin_data->bind7, - &ptr_mtktsvtskin_data->trip[8], - &ptr_mtktsvtskin_data->t_type[8], - ptr_mtktsvtskin_data->bind8, - &ptr_mtktsvtskin_data->trip[9], - &ptr_mtktsvtskin_data->t_type[9], - ptr_mtktsvtskin_data->bind9, - &ptr_mtktsvtskin_data->time_msec) == 32) { - - down(&sem_mutex); - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_unregister_thermal\n", - __func__); - - mtktsvtskin3_unregister_thermal(); - pr_notice("num_trip3 mtktsvtskin_write [%d]\n",num_trip3); - - if (num_trip3 < 0 || num_trip3 > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mtktsvtskin3_write", - "Bad argument"); - #endif - mtktsvtskin_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mtktsvtskin_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip3; i++) - g_THERMAL_TRIP3[i] = ptr_mtktsvtskin_data->t_type[i]; - - g_bind30[0] = g_bind31[0] = g_bind32[0] = g_bind33[0] - = g_bind34[0] = g_bind35[0] = g_bind36[0] = g_bind37[0] - = g_bind38[0] = g_bind39[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind30[i] = ptr_mtktsvtskin_data->bind0[i]; - g_bind31[i] = ptr_mtktsvtskin_data->bind1[i]; - g_bind32[i] = ptr_mtktsvtskin_data->bind2[i]; - g_bind33[i] = ptr_mtktsvtskin_data->bind3[i]; - g_bind34[i] = ptr_mtktsvtskin_data->bind4[i]; - g_bind35[i] = ptr_mtktsvtskin_data->bind5[i]; - g_bind36[i] = ptr_mtktsvtskin_data->bind6[i]; - g_bind37[i] = ptr_mtktsvtskin_data->bind7[i]; - g_bind38[i] = ptr_mtktsvtskin_data->bind8[i]; - g_bind39[i] = ptr_mtktsvtskin_data->bind9[i]; - } - - mtktsvtskin_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,", - __func__, - g_THERMAL_TRIP3[0], g_THERMAL_TRIP3[1]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,", - g_THERMAL_TRIP3[2], g_THERMAL_TRIP3[3], - g_THERMAL_TRIP3[4]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP3[5], g_THERMAL_TRIP3[6], - g_THERMAL_TRIP3[7]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP3[8], g_THERMAL_TRIP3[9]); - - mtktsvtskin_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,", - __func__, - g_bind30, g_bind31, g_bind32, g_bind33); - - mtktsvtskin_dprintk( - "cooldev4=%s,cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind34, g_bind35, g_bind36, g_bind37, g_bind38, g_bind39); - - for (i = 0; i < num_trip3; i++) - trip_temp3[i] = ptr_mtktsvtskin_data->trip[i]; - - interval = ptr_mtktsvtskin_data->time_msec / 1000; - - mtktsvtskin_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,", - __func__, - trip_temp3[0], trip_temp3[1], trip_temp3[2]); - - mtktsvtskin_dprintk( - "trip_3_temp=%d,trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,", - trip_temp3[3], trip_temp3[4], trip_temp3[5], - trip_temp3[6], trip_temp3[7]); - - mtktsvtskin_dprintk( - "trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n", - trip_temp3[8], trip_temp3[9], interval * 1000); - - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_register_thermal\n", __func__); - - mtktsvtskin3_register_thermal(); - - up(&sem_mutex); - - kfree(ptr_mtktsvtskin_data); - return count; - } - - mtktsvtskin_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mtktsvtskin3_write", "Bad argument"); - #endif - kfree(ptr_mtktsvtskin_data); - return -EINVAL; -} - -static int mtktsvtskin3_read(struct seq_file *m, void *v) -{ - - seq_printf(m, - "[mtktsvtskin_read3] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - trip_temp3[0], trip_temp3[1], trip_temp3[2], trip_temp3[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp3[4], trip_temp3[5], trip_temp3[6], - trip_temp3[7], trip_temp3[8], trip_temp3[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,", - g_THERMAL_TRIP3[0], g_THERMAL_TRIP3[1], - g_THERMAL_TRIP3[2], g_THERMAL_TRIP3[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP3[4], g_THERMAL_TRIP3[5], - g_THERMAL_TRIP3[6], g_THERMAL_TRIP3[7]); - - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP3[8], g_THERMAL_TRIP3[9]); - - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind30, g_bind31, g_bind32, g_bind33, g_bind34); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind35, g_bind36, g_bind37, g_bind38, g_bind39, interval * 1000); - - return 0; -} - - - -static ssize_t mtktsvtskin2_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0, i; - struct mtktsvtskin_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - - struct mtktsvtskin_data *ptr_mtktsvtskin_data = kmalloc( - sizeof(*ptr_mtktsvtskin_data), GFP_KERNEL); - - - pr_notice("num_trip2 mtktsvtskin_write [%d]\n",count); - - if (ptr_mtktsvtskin_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mtktsvtskin_data->desc) - 1)) ? - count : (sizeof(ptr_mtktsvtskin_data->desc) - 1); - - if (copy_from_user(ptr_mtktsvtskin_data->desc, buffer, len)) { - kfree(ptr_mtktsvtskin_data); - return 0; - } - - ptr_mtktsvtskin_data->desc[len] = '\0'; - - if (sscanf - (ptr_mtktsvtskin_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip2, - &ptr_mtktsvtskin_data->trip[0], - &ptr_mtktsvtskin_data->t_type[0], - ptr_mtktsvtskin_data->bind0, - &ptr_mtktsvtskin_data->trip[1], - &ptr_mtktsvtskin_data->t_type[1], - ptr_mtktsvtskin_data->bind1, - &ptr_mtktsvtskin_data->trip[2], - &ptr_mtktsvtskin_data->t_type[2], - ptr_mtktsvtskin_data->bind2, - &ptr_mtktsvtskin_data->trip[3], - &ptr_mtktsvtskin_data->t_type[3], - ptr_mtktsvtskin_data->bind3, - &ptr_mtktsvtskin_data->trip[4], - &ptr_mtktsvtskin_data->t_type[4], - ptr_mtktsvtskin_data->bind4, - &ptr_mtktsvtskin_data->trip[5], - &ptr_mtktsvtskin_data->t_type[5], - ptr_mtktsvtskin_data->bind5, - &ptr_mtktsvtskin_data->trip[6], - &ptr_mtktsvtskin_data->t_type[6], - ptr_mtktsvtskin_data->bind6, - &ptr_mtktsvtskin_data->trip[7], - &ptr_mtktsvtskin_data->t_type[7], - ptr_mtktsvtskin_data->bind7, - &ptr_mtktsvtskin_data->trip[8], - &ptr_mtktsvtskin_data->t_type[8], - ptr_mtktsvtskin_data->bind8, - &ptr_mtktsvtskin_data->trip[9], - &ptr_mtktsvtskin_data->t_type[9], - ptr_mtktsvtskin_data->bind9, - &ptr_mtktsvtskin_data->time_msec) == 32) { - - down(&sem_mutex); - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_unregister_thermal\n", - __func__); - - mtktsvtskin2_unregister_thermal(); - pr_notice("num_trip2 mtktsvtskin_write [%d]\n",num_trip2); - - if (num_trip2 < 0 || num_trip2 > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mtktsvtskin2_write", - "Bad argument"); - #endif - mtktsvtskin_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mtktsvtskin_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip2; i++) - g_THERMAL_TRIP2[i] = ptr_mtktsvtskin_data->t_type[i]; - - g_bind20[0] = g_bind21[0] = g_bind22[0] = g_bind23[0] - = g_bind24[0] = g_bind25[0] = g_bind26[0] = g_bind27[0] - = g_bind28[0] = g_bind29[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind20[i] = ptr_mtktsvtskin_data->bind0[i]; - g_bind21[i] = ptr_mtktsvtskin_data->bind1[i]; - g_bind22[i] = ptr_mtktsvtskin_data->bind2[i]; - g_bind23[i] = ptr_mtktsvtskin_data->bind3[i]; - g_bind24[i] = ptr_mtktsvtskin_data->bind4[i]; - g_bind25[i] = ptr_mtktsvtskin_data->bind5[i]; - g_bind26[i] = ptr_mtktsvtskin_data->bind6[i]; - g_bind27[i] = ptr_mtktsvtskin_data->bind7[i]; - g_bind28[i] = ptr_mtktsvtskin_data->bind8[i]; - g_bind29[i] = ptr_mtktsvtskin_data->bind9[i]; - } - - mtktsvtskin_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,", - __func__, - g_THERMAL_TRIP2[0], g_THERMAL_TRIP2[1]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,", - g_THERMAL_TRIP2[2], g_THERMAL_TRIP2[3], - g_THERMAL_TRIP2[4]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP2[5], g_THERMAL_TRIP2[6], - g_THERMAL_TRIP2[7]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP2[8], g_THERMAL_TRIP2[9]); - - mtktsvtskin_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,", - __func__, - g_bind20, g_bind21, g_bind22, g_bind23); - - mtktsvtskin_dprintk( - "cooldev4=%s,cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind24, g_bind25, g_bind26, g_bind27, g_bind28, g_bind29); - - for (i = 0; i < num_trip2; i++) - trip_temp2[i] = ptr_mtktsvtskin_data->trip[i]; - - interval = ptr_mtktsvtskin_data->time_msec / 1000; - - mtktsvtskin_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,", - __func__, - trip_temp2[0], trip_temp2[1], trip_temp2[2]); - - mtktsvtskin_dprintk( - "trip_3_temp=%d,trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,", - trip_temp2[3], trip_temp2[4], trip_temp2[5], - trip_temp2[6], trip_temp2[7]); - - mtktsvtskin_dprintk( - "trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n", - trip_temp2[8], trip_temp2[9], interval * 1000); - - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_register_thermal\n", __func__); - - mtktsvtskin2_register_thermal(); - - up(&sem_mutex); - - kfree(ptr_mtktsvtskin_data); - return count; - } - - mtktsvtskin_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mtktsvtskin2_write", "Bad argument"); - #endif - kfree(ptr_mtktsvtskin_data); - return -EINVAL; -} - -static int mtktsvtskin2_read(struct seq_file *m, void *v) -{ - - seq_printf(m, - "[mtktsvtskin_read2] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - trip_temp2[0], trip_temp2[1], trip_temp2[2], trip_temp2[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp2[4], trip_temp2[5], trip_temp2[6], - trip_temp2[7], trip_temp2[8], trip_temp2[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,", - g_THERMAL_TRIP2[0], g_THERMAL_TRIP2[1], - g_THERMAL_TRIP2[2], g_THERMAL_TRIP2[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP2[4], g_THERMAL_TRIP2[5], - g_THERMAL_TRIP2[6], g_THERMAL_TRIP2[7]); - - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP2[8], g_THERMAL_TRIP2[9]); - - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind20, g_bind21, g_bind22, g_bind23, g_bind24); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind25, g_bind26, g_bind27, g_bind28, g_bind29, interval * 1000); - - return 0; -} - - -static ssize_t mtktsvtskin1_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0, i; - struct mtktsvtskin_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - - - - - struct mtktsvtskin_data *ptr_mtktsvtskin_data = kmalloc( - sizeof(*ptr_mtktsvtskin_data), GFP_KERNEL); - - - pr_notice("num_trip1 mtktsvtskin_write[%d]\n",count); - - if (ptr_mtktsvtskin_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mtktsvtskin_data->desc) - 1)) ? - count : (sizeof(ptr_mtktsvtskin_data->desc) - 1); - - if (copy_from_user(ptr_mtktsvtskin_data->desc, buffer, len)) { - kfree(ptr_mtktsvtskin_data); - return 0; - } - - ptr_mtktsvtskin_data->desc[len] = '\0'; - - if (sscanf - (ptr_mtktsvtskin_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip1, - &ptr_mtktsvtskin_data->trip[0], - &ptr_mtktsvtskin_data->t_type[0], - ptr_mtktsvtskin_data->bind0, - &ptr_mtktsvtskin_data->trip[1], - &ptr_mtktsvtskin_data->t_type[1], - ptr_mtktsvtskin_data->bind1, - &ptr_mtktsvtskin_data->trip[2], - &ptr_mtktsvtskin_data->t_type[2], - ptr_mtktsvtskin_data->bind2, - &ptr_mtktsvtskin_data->trip[3], - &ptr_mtktsvtskin_data->t_type[3], - ptr_mtktsvtskin_data->bind3, - &ptr_mtktsvtskin_data->trip[4], - &ptr_mtktsvtskin_data->t_type[4], - ptr_mtktsvtskin_data->bind4, - &ptr_mtktsvtskin_data->trip[5], - &ptr_mtktsvtskin_data->t_type[5], - ptr_mtktsvtskin_data->bind5, - &ptr_mtktsvtskin_data->trip[6], - &ptr_mtktsvtskin_data->t_type[6], - ptr_mtktsvtskin_data->bind6, - &ptr_mtktsvtskin_data->trip[7], - &ptr_mtktsvtskin_data->t_type[7], - ptr_mtktsvtskin_data->bind7, - &ptr_mtktsvtskin_data->trip[8], - &ptr_mtktsvtskin_data->t_type[8], - ptr_mtktsvtskin_data->bind8, - &ptr_mtktsvtskin_data->trip[9], - &ptr_mtktsvtskin_data->t_type[9], - ptr_mtktsvtskin_data->bind9, - &ptr_mtktsvtskin_data->time_msec) == 32) { - - down(&sem_mutex); - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_unregister_thermal\n",__func__); - - mtktsvtskin1_unregister_thermal(); - pr_notice("num_trip1 mtktsvtskin_write [%d]\n",num_trip1); - - if (num_trip1 < 0 || num_trip1 > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mtktsvtskin1_write", - "Bad argument"); - #endif - mtktsvtskin_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mtktsvtskin_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip1; i++) - g_THERMAL_TRIP1[i] = ptr_mtktsvtskin_data->t_type[i]; - - g_bind10[0] = g_bind11[0] = g_bind12[0] = g_bind13[0] - = g_bind14[0] = g_bind15[0] = g_bind16[0] = g_bind17[0] - = g_bind18[0] = g_bind19[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind10[i] = ptr_mtktsvtskin_data->bind0[i]; - g_bind11[i] = ptr_mtktsvtskin_data->bind1[i]; - g_bind12[i] = ptr_mtktsvtskin_data->bind2[i]; - g_bind13[i] = ptr_mtktsvtskin_data->bind3[i]; - g_bind14[i] = ptr_mtktsvtskin_data->bind4[i]; - g_bind15[i] = ptr_mtktsvtskin_data->bind5[i]; - g_bind16[i] = ptr_mtktsvtskin_data->bind6[i]; - g_bind17[i] = ptr_mtktsvtskin_data->bind7[i]; - g_bind18[i] = ptr_mtktsvtskin_data->bind8[i]; - g_bind19[i] = ptr_mtktsvtskin_data->bind9[i]; - } - - mtktsvtskin_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,", - __func__, - g_THERMAL_TRIP1[0], g_THERMAL_TRIP1[1]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,", - g_THERMAL_TRIP1[2], g_THERMAL_TRIP1[3], - g_THERMAL_TRIP1[4]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP1[5], g_THERMAL_TRIP1[6], - g_THERMAL_TRIP1[7]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP1[8], g_THERMAL_TRIP1[9]); - - mtktsvtskin_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,", - __func__, - g_bind10, g_bind11, g_bind12, g_bind13); - - mtktsvtskin_dprintk( - "cooldev4=%s,cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind14, g_bind15, g_bind16, g_bind17, g_bind18, g_bind19); - - for (i = 0; i < num_trip1; i++) - trip_temp1[i] = ptr_mtktsvtskin_data->trip[i]; - - interval = ptr_mtktsvtskin_data->time_msec / 1000; - - mtktsvtskin_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,", - __func__, - trip_temp1[0], trip_temp1[1], trip_temp1[2]); - - mtktsvtskin_dprintk( - "trip_3_temp=%d,trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,", - trip_temp1[3], trip_temp1[4], trip_temp1[5], - trip_temp1[6], trip_temp1[7]); - - mtktsvtskin_dprintk( - "trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n", - trip_temp1[8], trip_temp1[9], interval * 1000); - - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_register_thermal\n", __func__); - - - mtktsvtskin1_register_thermal(); - up(&sem_mutex); - - kfree(ptr_mtktsvtskin_data); - return count; - } - - mtktsvtskin_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mtktsvtskin1_write", "Bad argument"); - #endif - kfree(ptr_mtktsvtskin_data); - return -EINVAL; -} - -static int mtktsvtskin1_read(struct seq_file *m, void *v) -{ - - seq_printf(m, - "[mtktsvtskin_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - trip_temp1[0], trip_temp1[1], trip_temp1[2], trip_temp1[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp1[4], trip_temp1[5], trip_temp1[6], - trip_temp1[7], trip_temp1[8], trip_temp1[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,", - g_THERMAL_TRIP1[0], g_THERMAL_TRIP1[1], - g_THERMAL_TRIP1[2], g_THERMAL_TRIP1[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP1[4], g_THERMAL_TRIP1[5], - g_THERMAL_TRIP1[6], g_THERMAL_TRIP1[7]); - - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP1[8], g_THERMAL_TRIP1[9]); - - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind10, g_bind11, g_bind12, g_bind13, g_bind14); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind15, g_bind16, g_bind17, g_bind18, g_bind19, interval * 1000); - - return 0; -} - - -static ssize_t mtktsvtskin0_write( -struct file *file, const char __user *buffer, size_t count, loff_t *data) -{ - int len = 0, i; - struct mtktsvtskin_data { - int trip[10]; - int t_type[10]; - char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; - char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; - int time_msec; - char desc[512]; - }; - - - struct mtktsvtskin_data *ptr_mtktsvtskin_data = kmalloc( - sizeof(*ptr_mtktsvtskin_data), GFP_KERNEL); - - pr_notice("num_trip mtktsvtskin_write [%d]\n",count); - - if (ptr_mtktsvtskin_data == NULL) - return -ENOMEM; - - len = (count < (sizeof(ptr_mtktsvtskin_data->desc) - 1)) ? - count : (sizeof(ptr_mtktsvtskin_data->desc) - 1); - - if (copy_from_user(ptr_mtktsvtskin_data->desc, buffer, len)) { - kfree(ptr_mtktsvtskin_data); - return 0; - } - - ptr_mtktsvtskin_data->desc[len] = '\0'; - - if (sscanf - (ptr_mtktsvtskin_data->desc, - "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", - &num_trip, - &ptr_mtktsvtskin_data->trip[0], - &ptr_mtktsvtskin_data->t_type[0], - ptr_mtktsvtskin_data->bind0, - &ptr_mtktsvtskin_data->trip[1], - &ptr_mtktsvtskin_data->t_type[1], - ptr_mtktsvtskin_data->bind1, - &ptr_mtktsvtskin_data->trip[2], - &ptr_mtktsvtskin_data->t_type[2], - ptr_mtktsvtskin_data->bind2, - &ptr_mtktsvtskin_data->trip[3], - &ptr_mtktsvtskin_data->t_type[3], - ptr_mtktsvtskin_data->bind3, - &ptr_mtktsvtskin_data->trip[4], - &ptr_mtktsvtskin_data->t_type[4], - ptr_mtktsvtskin_data->bind4, - &ptr_mtktsvtskin_data->trip[5], - &ptr_mtktsvtskin_data->t_type[5], - ptr_mtktsvtskin_data->bind5, - &ptr_mtktsvtskin_data->trip[6], - &ptr_mtktsvtskin_data->t_type[6], - ptr_mtktsvtskin_data->bind6, - &ptr_mtktsvtskin_data->trip[7], - &ptr_mtktsvtskin_data->t_type[7], - ptr_mtktsvtskin_data->bind7, - &ptr_mtktsvtskin_data->trip[8], - &ptr_mtktsvtskin_data->t_type[8], - ptr_mtktsvtskin_data->bind8, - &ptr_mtktsvtskin_data->trip[9], - &ptr_mtktsvtskin_data->t_type[9], - ptr_mtktsvtskin_data->bind9, - &ptr_mtktsvtskin_data->time_msec) == 32) { - - down(&sem_mutex); - mtktsvtskin_dprintk( - "[%s] mtktsvtskin0_unregister_thermal\n",__func__); - - mtktsvtskin_max_unregister_thermal(); - pr_notice("num_trip mtktsvtskin_write[%d]\n", num_trip); - - if (num_trip < 0 || num_trip > 10) { - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, - DB_OPT_DEFAULT, "mtktsvtskin0_write", - "Bad argument"); - #endif - mtktsvtskin_dprintk( - "[%s] bad argument\n", __func__); - - kfree(ptr_mtktsvtskin_data); - up(&sem_mutex); - return -EINVAL; - } - - for (i = 0; i < num_trip; i++) - g_THERMAL_TRIP[i] = ptr_mtktsvtskin_data->t_type[i]; - - g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] - = g_bind4[0] = g_bind5[0] = g_bind6[0] = g_bind7[0] - = g_bind8[0] = g_bind9[0] = '\0'; - - for (i = 0; i < 20; i++) { - g_bind0[i] = ptr_mtktsvtskin_data->bind0[i]; - g_bind1[i] = ptr_mtktsvtskin_data->bind1[i]; - g_bind2[i] = ptr_mtktsvtskin_data->bind2[i]; - g_bind3[i] = ptr_mtktsvtskin_data->bind3[i]; - g_bind4[i] = ptr_mtktsvtskin_data->bind4[i]; - g_bind5[i] = ptr_mtktsvtskin_data->bind5[i]; - g_bind6[i] = ptr_mtktsvtskin_data->bind6[i]; - g_bind7[i] = ptr_mtktsvtskin_data->bind7[i]; - g_bind8[i] = ptr_mtktsvtskin_data->bind8[i]; - g_bind9[i] = ptr_mtktsvtskin_data->bind9[i]; - } - - mtktsvtskin_dprintk( - "[%s] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,", - __func__, - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,", - g_THERMAL_TRIP[2], g_THERMAL_TRIP[3], - g_THERMAL_TRIP[4]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], - g_THERMAL_TRIP[7]); - - mtktsvtskin_dprintk( - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - mtktsvtskin_dprintk( - "[%s] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,", - __func__, - g_bind0, g_bind1, g_bind2, g_bind3); - - mtktsvtskin_dprintk( - "cooldev4=%s,cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", - g_bind4, g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); - - for (i = 0; i < num_trip; i++) - trip_temp[i] = ptr_mtktsvtskin_data->trip[i]; - - interval = ptr_mtktsvtskin_data->time_msec / 1000; - - mtktsvtskin_dprintk( - "[%s] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,", - __func__, - trip_temp[0], trip_temp[1], trip_temp[2]); - - mtktsvtskin_dprintk( - "trip_3_temp=%d,trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,", - trip_temp[3], trip_temp[4], trip_temp[5], - trip_temp[6], trip_temp[7]); - - mtktsvtskin_dprintk( - "trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n", - trip_temp[8], trip_temp[9], interval * 1000); - - mtktsvtskin_dprintk( - "[%s] mtktsvtskin_register_thermal\n", __func__); - - mtktsvtskin_max_register_thermal(); - up(&sem_mutex); - - kfree(ptr_mtktsvtskin_data); - return count; - } - - mtktsvtskin_dprintk("[%s] bad argument\n", __func__); - #ifdef CONFIG_MTK_AEE_FEATURE - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, - "mtktsvtskin0_write", "Bad argument"); - #endif - kfree(ptr_mtktsvtskin_data); - return -EINVAL; -} - -static int mtktsvtskin0_read(struct seq_file *m, void *v) -{ - - seq_printf(m, - "[mtktsvtskin_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n", - trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); - - seq_printf(m, - "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n", - trip_temp[4], trip_temp[5], trip_temp[6], - trip_temp[7], trip_temp[8], trip_temp[9]); - - seq_printf(m, - "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,", - g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], - g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]); - - seq_printf(m, - "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,", - g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], - g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]); - - seq_printf(m, - "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", - g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); - - - seq_printf(m, - "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n", - g_bind0, g_bind1, g_bind2, g_bind3, g_bind4); - - seq_printf(m, - "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n", - g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000); - - return 0; -} - - -static int mtkts_vtskin_open(struct inode *inode, struct file *file) -{ - return single_open(file, mtktsvtskin0_read, NULL); -} - - -static int mtkts_vtskin1_open(struct inode *inode, struct file *file) -{ - return single_open(file, mtktsvtskin1_read, NULL); -} - -static int mtkts_vtskin2_open(struct inode *inode, struct file *file) -{ - return single_open(file, mtktsvtskin2_read, NULL); -} - - -static int mtkts_vtskin3_open(struct inode *inode, struct file *file) -{ - return single_open(file, mtktsvtskin3_read, NULL); -} - - - - - - - -static const struct file_operations mtkts_vtskin_max_fops = { - .owner = THIS_MODULE, - .open = mtkts_vtskin_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mtktsvtskin0_write, - .release = single_release, -}; - - -static const struct file_operations mtkts_vtskin1_fops = { - .owner = THIS_MODULE, - .open = mtkts_vtskin1_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mtktsvtskin1_write, - .release = single_release, -}; - -static const struct file_operations mtkts_vtskin2_fops = { - .owner = THIS_MODULE, - .open = mtkts_vtskin2_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mtktsvtskin2_write, - .release = single_release, -}; - -static const struct file_operations mtkts_vtskin3_fops = { - .owner = THIS_MODULE, - .open = mtkts_vtskin3_open, - .read = seq_read, - .llseek = seq_lseek, - .write = mtktsvtskin3_write, - .release = single_release, -}; - - - -#ifdef CONFIG_PM -static int vtskin_pm_event( - struct notifier_block *notifier, - unsigned long pm_event, void *unused) -{ - switch (pm_event) { - case PM_SUSPEND_PREPARE: - mutex_lock(&vtskin_mutex); - g_resume_done = 0; - mutex_unlock(&vtskin_mutex); - break; - case PM_POST_SUSPEND: - mutex_lock(&vtskin_mutex); - g_resume_done = 1; - mutex_unlock(&vtskin_mutex); - break; - } - return NOTIFY_OK; -} - -static struct notifier_block vtskin_pm_notifier_func = { - .notifier_call = vtskin_pm_event, - .priority = 0, -}; -#endif - - -static int vtskin_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - //struct vtskin_temp_tz *skin_tz; - struct vtskin_data *skin_data; - //struct thermal_zone_device *tzdev; - struct proc_dir_entry *mtktsvtskin_dir = NULL; - struct proc_dir_entry *entry = NULL; - int i; //ret; -#ifdef CONFIG_PM - int ret = -1; -#endif - - - if (!pdev->dev.of_node) { - pr_notice("Only DT based supported\n"); - return -ENODEV; - } - pr_notice(" vtskin probe called"); - - skin_data = parse_dt(pdev); - if (!skin_data) - pr_notice("Error: Failed to get lvts platform data\n"); - - skin_data->dev = dev; - platform_set_drvdata(pdev, skin_data); - - for (i = 0; i < skin_data->num_sensor; i++) - mtktsvtskin_register_cooler(i); - - mtktsvtskin_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); - if (!mtktsvtskin_dir) { - pr_notice("%s mkdir /proc/driver/thermal failed\n",__func__); - return -1; - } - - entry = proc_create(mtk_thermal_get_vtksin_tz_proc_name(VTSKIN_MAX_INDEX), - 0664, mtktsvtskin_dir, &mtkts_vtskin_max_fops); - if (entry) - proc_set_user(entry, uid, gid); - - entry = proc_create(mtk_thermal_get_vtksin_tz_proc_name(VTSKIN1_INDEX), - 0664, mtktsvtskin_dir, &mtkts_vtskin1_fops); - if (entry) - proc_set_user(entry, uid, gid); - - entry = proc_create(mtk_thermal_get_vtksin_tz_proc_name(VTSKIN2_INDEX), - 0664, mtktsvtskin_dir, &mtkts_vtskin2_fops); - if (entry) - proc_set_user(entry, uid, gid); - - entry = proc_create(mtk_thermal_get_vtksin_tz_proc_name(VTSKIN3_INDEX), - 0664, mtktsvtskin_dir, &mtkts_vtskin3_fops); - if (entry) - proc_set_user(entry, uid, gid); - -#ifdef CONFIG_PM - ret = register_pm_notifier(&vtskin_pm_notifier_func); - if (ret) - pr_notice("Failed to register dctm PM notifier.\n"); -#endif - - - - pr_notice("vtkin probe completed"); - return 0; -} - -static const struct of_device_id vtskin_of_match[] = { - { - .compatible = "mediatek,mt6893-virtual-tskin", - }, - {}, -}; -MODULE_DEVICE_TABLE(of, vtskin_of_match); -static struct platform_driver vtskin_driver = { - .probe = vtskin_probe, - .driver = { - .name = "mtk-virtual-tskin", - .of_match_table = vtskin_of_match, - }, -}; -module_platform_driver(vtskin_driver); -MODULE_AUTHOR("Utkarsh Tripathi "); -MODULE_DESCRIPTION("Mediatek on virtual tskin driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/mediatek/thermal/mtk_cooler_backlight_cus.c b/drivers/misc/mediatek/thermal/mtk_cooler_backlight_cus.c new file mode 100644 index 000000000000..f9172c533642 --- /dev/null +++ b/drivers/misc/mediatek/thermal/mtk_cooler_backlight_cus.c @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2017 MediaTek Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifdef pr_fmt +#undef pr_fmt +#endif +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + + +#include +#include +#include +#include +#include + +#include "mt-plat/mtk_thermal_monitor.h" + +#define BACKLIGHT_COOLER_NR 1 +#define MAX_BACKLIGHT_BRIGHTNESS 2047 + +#define mtk_cooler_backlight_dprintk(fmt, args...) \ + pr_notice("thermal/cooler/backlight " fmt, ##args) + + +static struct thermal_cooling_device +*cl_backlight_dev[BACKLIGHT_COOLER_NR] = { 0 }; +static unsigned int g_cl_id[BACKLIGHT_COOLER_NR]; +static unsigned int g_backlight_level; + +static int mtk_cl_backlight_get_max_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = MAX_BACKLIGHT_BRIGHTNESS; + return 0; +} + +static int mtk_cl_backlight_get_cur_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = g_backlight_level; + return 0; +} + +extern int mt_leds_brightness_thermal_set(char *name, int brightness); +static int mtk_cl_backlight_set_cur_state +(struct thermal_cooling_device *cdev, unsigned long state) +{ + int ret = -1; + + ret = mt_leds_brightness_thermal_set("lcd-backlight", state); + if (ret > 0) { + g_backlight_level = state; + } + mtk_cooler_backlight_dprintk("%s: %d\n", __func__, g_backlight_level); + + return 0; +} +# if 0 +static int mtk_cl_backlight_get_available +(struct thermal_cooling_device *cdev, char *available) +{ + *available = 255; + snprintf(available, 4, "%d\n", MAX_BACKLIGHT_BRIGHTNESS); + return 0; +} +#endif + +/* bind fan callbacks to fan device */ +static struct thermal_cooling_device_ops mtk_cl_backlight_ops = { + .get_max_state = mtk_cl_backlight_get_max_state, + .get_cur_state = mtk_cl_backlight_get_cur_state, + .set_cur_state = mtk_cl_backlight_set_cur_state, + //.get_available = mtk_cl_backlight_get_available, +}; + +static int mtk_cooler_backlight_register_ltf(void) +{ + int i; + + mtk_cooler_backlight_dprintk("register ltf\n"); + + for (i = 0; i < BACKLIGHT_COOLER_NR; i++) { + char temp[20] = { 0 }; + + sprintf(temp, "mtk-cl-backlight"); + /* /< Cooler Name: mtk-cl-backlight01 */ + + g_cl_id[i] = i; + cl_backlight_dev[i] = mtk_thermal_cooling_device_register + (temp, (void *)&g_cl_id[i], + &mtk_cl_backlight_ops); + } + + return 0; +} + +static void mtk_cooler_backlight_unregister_ltf(void) +{ + int i; + + mtk_cooler_backlight_dprintk("unregister ltf\n"); + + for (i = 0; i < BACKLIGHT_COOLER_NR; i++) { + if (cl_backlight_dev[i]) { + mtk_thermal_cooling_device_unregister + (cl_backlight_dev[i]); + cl_backlight_dev[i] = NULL; + } + } +} + +static int __init mtk_cooler_backlight_init(void) +{ + int err = 0; + + mtk_cooler_backlight_dprintk("init\n"); + g_backlight_level = MAX_BACKLIGHT_BRIGHTNESS; + + err = mtk_cooler_backlight_register_ltf(); + if (err) + goto err_unreg; + + return 0; + +err_unreg: + mtk_cooler_backlight_unregister_ltf(); + return err; +} + +static void __exit mtk_cooler_backlight_exit(void) +{ + mtk_cooler_backlight_dprintk("exit\n"); + + mtk_cooler_backlight_unregister_ltf(); +} +module_init(mtk_cooler_backlight_init); +module_exit(mtk_cooler_backlight_exit); diff --git a/drivers/misc/mediatek/thermal/mtk_cooler_flashlight_cus.c b/drivers/misc/mediatek/thermal/mtk_cooler_flashlight_cus.c new file mode 100644 index 000000000000..2f34eef8dff6 --- /dev/null +++ b/drivers/misc/mediatek/thermal/mtk_cooler_flashlight_cus.c @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2017 MediaTek Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifdef pr_fmt +#undef pr_fmt +#endif +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + + +#include +#include +#include +#include +#include + +#include "mt-plat/mtk_thermal_monitor.h" + +#include "flashlight-core.h" + +#define mtk_cooler_flashlight_dprintk(fmt, args...) \ + pr_notice("thermal/cooler/flashlight " fmt, ##args) + +#define FLASHLIGHT_COOLER_NR 1 + +static struct thermal_cooling_device +*cl_flashlight_dev[FLASHLIGHT_COOLER_NR] = { 0 }; +static unsigned int g_cl_id[FLASHLIGHT_COOLER_NR]; +static unsigned int g_flashlight_level; +static unsigned int g_max_flashlight_level; + +static int mtk_cl_flashlight_get_max_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = g_max_flashlight_level; + return 0; +} + + static int mtk_cl_flashlight_get_cur_state +(struct thermal_cooling_device *cdev, unsigned long *state) +{ + *state = g_flashlight_level; + return 0; +} + +static int mtk_cl_flashlight_set_cur_state +(struct thermal_cooling_device *cdev, unsigned long state) +{ + if (state < g_max_flashlight_level) { + flashlight_set_cooler_level(state); + g_flashlight_level = state; + mtk_cooler_flashlight_dprintk("%s: %d\n", __func__,g_flashlight_level); + } + + return 0; +} +#if 0 +static int mtk_cl_flashlight_get_available +(struct thermal_cooling_device *cdev, char *available) +{ + *available = g_max_flashlight_level; + return 0; +} +#endif + +/* bind fan callbacks to fan device */ +static struct thermal_cooling_device_ops mtk_cl_flashlight_ops = { + .get_max_state = mtk_cl_flashlight_get_max_state, + .get_cur_state = mtk_cl_flashlight_get_cur_state, + .set_cur_state = mtk_cl_flashlight_set_cur_state, + //.get_available = mtk_cl_flashlight_get_available, +}; + +static int mtk_cooler_flashlight_register_ltf(void) +{ + int i; + + mtk_cooler_flashlight_dprintk("register ltf\n"); + + for (i = 0; i < FLASHLIGHT_COOLER_NR; i++) { + char temp[20] = { 0 }; + + sprintf(temp, "mtk-cl-flashlight"); + + g_cl_id[i] = i; + cl_flashlight_dev[i] = mtk_thermal_cooling_device_register + (temp, (void *)&g_cl_id[i], + &mtk_cl_flashlight_ops); + } + + return 0; +} + +static void mtk_cooler_flashlight_unregister_ltf(void) +{ + int i; + + mtk_cooler_flashlight_dprintk("unregister ltf\n"); + + for (i = 0; i < FLASHLIGHT_COOLER_NR; i++) { + if (cl_flashlight_dev[i]) { + mtk_thermal_cooling_device_unregister + (cl_flashlight_dev[i]); + cl_flashlight_dev[i] = NULL; + } + } +} + +static int __init mtk_cooler_flashlight_init(void) +{ + int err = 0; + + mtk_cooler_flashlight_dprintk("init\n"); + + err = mtk_cooler_flashlight_register_ltf(); + if (err) + goto err_unreg; + + return 0; + +err_unreg: + mtk_cooler_flashlight_unregister_ltf(); + return err; +} + +static void __exit mtk_cooler_flashlight_exit(void) +{ + mtk_cooler_flashlight_dprintk("exit\n"); + + mtk_cooler_flashlight_unregister_ltf(); +} + +static int __init mtk_cooler_flashlight_late_init(void) +{ + g_max_flashlight_level = flashlight_get_max_duty(); + g_flashlight_level = g_max_flashlight_level; + + return 0; +} + + +module_init(mtk_cooler_flashlight_init); +module_exit(mtk_cooler_flashlight_exit); +late_initcall(mtk_cooler_flashlight_late_init); diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index be1195fdce80..498f986d8e5b 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -115,10 +115,10 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, unsigned long event, void *data) { struct cpufreq_policy *policy = data; - unsigned long clipped_freq; + unsigned long clipped_freq = ULONG_MAX; struct cpufreq_cooling_device *cpufreq_cdev; - if (event != CPUFREQ_ADJUST) + if (event != CPUFREQ_THERMAL) return NOTIFY_DONE; mutex_lock(&cooling_list_lock); @@ -141,12 +141,12 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, * But, if clipped_freq is greater than policy->max, we don't * need to do anything. */ - clipped_freq = cpufreq_cdev->clipped_freq; - - if (policy->max > clipped_freq) - cpufreq_verify_within_limits(policy, 0, clipped_freq); + if (clipped_freq > cpufreq_cdev->clipped_freq) { + clipped_freq = cpufreq_cdev->clipped_freq; + } break; } + cpufreq_verify_within_limits(policy, 0, clipped_freq); mutex_unlock(&cooling_list_lock); return NOTIFY_OK; @@ -336,7 +336,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, /* Check if the old cooling action is same as new cooling action */ if (cpufreq_cdev->cpufreq_state == state) - return 0; + return cpufreq_cdev->max_level; clip_freq = get_state_freq(cpufreq_cdev, state); cpufreq_cdev->cpufreq_state = state; @@ -346,16 +346,40 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, * can handle the CPU freq mitigation, if not, notify cpufreq * framework. */ - if (cpufreq_cdev->plat_ops && - cpufreq_cdev->plat_ops->ceil_limit) - cpufreq_cdev->plat_ops->ceil_limit(cpufreq_cdev->policy->cpu, - clip_freq); - else + if (cpufreq_cdev->plat_ops && cpufreq_cdev->plat_ops->ceil_limit) { + cpufreq_cdev->plat_ops->ceil_limit(cpufreq_cdev->policy->cpu, clip_freq); + } else { + get_online_cpus(); cpufreq_update_policy(cpufreq_cdev->policy->cpu); - + put_online_cpus(); + } return 0; } +void cpu_limits_set_level(unsigned int cpu, unsigned int max_freq) +{ + struct cpufreq_cooling_device *cpufreq_cdev; + struct thermal_cooling_device *cdev; + unsigned int cdev_cpu; + unsigned int level; + list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) { + sscanf(cpufreq_cdev->cdev->type, "thermal-cpufreq-%d", &cdev_cpu); + if (cdev_cpu == cpu) { + for (level = 0; level <= cpufreq_cdev->max_level; level++) { + int target_freq = get_state_freq(cpufreq_cdev, level); + pr_err("%s: %d not part of any cooling device\n", __func__, target_freq); + if (max_freq >= target_freq) { + cdev = cpufreq_cdev->cdev; + if (cdev) + cdev->ops->set_cur_state(cdev, level); + break; + } + } + break; + } + } +} + #ifdef CONFIG_ENERGY_MODEL /** * cpufreq_get_requested_power() - get the current power diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 8b05f9e31f3a..adf86dddf37b 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -23,11 +23,19 @@ #include #include +#include +#ifdef CONFIG_FB +#include +#include +#endif + #define CREATE_TRACE_POINTS #include #include "thermal_core.h" #include "thermal_hwmon.h" +#include "../misc/mediatek/base/power/include/ppm_v3/mtk_ppm_api.h" +#define CPU_LIMITS_PARAM_NUM 2 MODULE_AUTHOR("Zhang Rui"); MODULE_DESCRIPTION("Generic thermal management sysfs support"); @@ -49,6 +57,22 @@ static bool power_off_triggered; static struct thermal_governor *def_governor; +#ifdef CONFIG_FB +struct screen_monitor { + struct notifier_block thermal_notifier; + int screen_state; +}; +struct screen_monitor sm; +#endif +static atomic_t switch_mode = ATOMIC_INIT(-1); +static atomic_t temp_state = ATOMIC_INIT(0); +static atomic_t lighter_event = ATOMIC_INIT(0); +static char boost_buf[128]; +static struct device thermal_message_dev; +const char *board_sensor; +static char board_sensor_temp[128]; +static atomic_t switch_flash = ATOMIC_INIT(0); + /* * Governor section: set of functions to handle thermal governors * @@ -122,6 +146,47 @@ static int thermal_set_governor(struct thermal_zone_device *tz, return ret; } +int thermal_zone_device_set_policy(struct thermal_zone_device *tz, + char *policy) +{ + struct thermal_governor *gov; + int ret = -EINVAL; + + mutex_lock(&thermal_governor_lock); + mutex_lock(&tz->lock); + + gov = __find_governor(strim(policy)); + if (!gov) + goto exit; + + ret = thermal_set_governor(tz, gov); + +exit: + mutex_unlock(&tz->lock); + mutex_unlock(&thermal_governor_lock); + + return ret; +} + +int thermal_build_list_of_policies(char *buf) +{ + struct thermal_governor *pos; + ssize_t count = 0; + ssize_t size = PAGE_SIZE; + + mutex_lock(&thermal_governor_lock); + + list_for_each_entry(pos, &thermal_governor_list, governor_list) { + size = PAGE_SIZE - count; + count += scnprintf(buf + count, size, "%s ", pos->name); + } + count += scnprintf(buf + count, size, "\n"); + + mutex_unlock(&thermal_governor_lock); + + return count; +} + int thermal_register_governor(struct thermal_governor *governor) { int err; @@ -202,46 +267,6 @@ exit: mutex_unlock(&thermal_governor_lock); } -int thermal_zone_device_set_policy(struct thermal_zone_device *tz, - char *policy) -{ - struct thermal_governor *gov; - int ret = -EINVAL; - - mutex_lock(&thermal_governor_lock); - mutex_lock(&tz->lock); - - gov = __find_governor(strim(policy)); - if (!gov) - goto exit; - - ret = thermal_set_governor(tz, gov); - -exit: - mutex_unlock(&tz->lock); - mutex_unlock(&thermal_governor_lock); - - return ret; -} - -int thermal_build_list_of_policies(char *buf) -{ - struct thermal_governor *pos; - ssize_t count = 0; - - mutex_lock(&thermal_governor_lock); - - list_for_each_entry(pos, &thermal_governor_list, governor_list) { - count += scnprintf(buf + count, PAGE_SIZE - count, "%s ", - pos->name); - } - count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); - - mutex_unlock(&thermal_governor_lock); - - return count; -} - static int __init thermal_register_governors(void) { int result; @@ -891,6 +916,232 @@ static struct class thermal_class = { .dev_release = thermal_release, }; +static ssize_t +thermal_sconfig_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&switch_mode)); +} +static ssize_t +thermal_sconfig_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + int val = -1; + val = simple_strtol(buf, NULL, 10); + atomic_set(&switch_mode, val); + return len; +} +static DEVICE_ATTR(sconfig, 0664, + thermal_sconfig_show, thermal_sconfig_store); +static ssize_t +thermal_boost_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, boost_buf); +} +static ssize_t +thermal_boost_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + int ret; + ret = snprintf(boost_buf, PAGE_SIZE, buf); + return len; +} +static DEVICE_ATTR(boost, 0644, + thermal_boost_show, thermal_boost_store); +static ssize_t +thermal_temp_state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&temp_state)); +} +static ssize_t +thermal_temp_state_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + int val = -1; + val = simple_strtol(buf, NULL, 10); + atomic_set(&temp_state, val); + return len; +} +static DEVICE_ATTR(temp_state, 0664, + thermal_temp_state_show, thermal_temp_state_store); +static ssize_t +thermal_lighter_event_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&lighter_event)); +} +static ssize_t +thermal_lighter_event_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + int val = -1; + val = simple_strtol(buf, NULL, 10); + atomic_set(&lighter_event, val); + return len; +} +static DEVICE_ATTR(lighter_event, 0664, + thermal_lighter_event_show, thermal_lighter_event_store); +static ssize_t +cpu_limits_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return 0; +} +static ssize_t +cpu_limits_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + unsigned int cpu; + unsigned int max; + if (sscanf(buf, "cpu%u %u", &cpu, &max) != CPU_LIMITS_PARAM_NUM) { + pr_err("input param error, can not prase param\n"); + return -EINVAL; + } + if (cpu >= 0 && cpu <= 5) + cpu = 0; + else + cpu = 1; + mt_ppm_sysboost_set_freq_limit(BOOST_BY_XM_THERMAL, cpu, -1, max); + return len; +} +static DEVICE_ATTR(cpu_limits, 0664, + cpu_limits_show, cpu_limits_store); +#ifdef CONFIG_FB +static ssize_t +thermal_screen_state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", sm.screen_state); +} +static DEVICE_ATTR(screen_state, 0664, + thermal_screen_state_show, NULL); +#endif +static ssize_t +thermal_board_sensor_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + if (!board_sensor) + board_sensor = "invalid"; + return snprintf(buf, PAGE_SIZE, "%s", board_sensor); +} +static DEVICE_ATTR(board_sensor, 0664, + thermal_board_sensor_show, NULL); +static ssize_t +thermal_board_sensor_temp_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, board_sensor_temp); +} +static ssize_t +thermal_board_sensor_temp_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + snprintf(board_sensor_temp, PAGE_SIZE, buf); + return len; +} +static DEVICE_ATTR(board_sensor_temp, 0664, + thermal_board_sensor_temp_show, thermal_board_sensor_temp_store); + +static ssize_t +thermal_flash_state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&switch_flash)); +} + +static ssize_t +thermal_flash_state_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + int flash_val = 0; + flash_val = simple_strtol(buf, NULL, 10); + atomic_set(&switch_flash, flash_val); + return len; +} +static DEVICE_ATTR(flash_state, 0664, + thermal_flash_state_show, thermal_flash_state_store); + +static int create_thermal_message_node(void) +{ + int ret = 0; + thermal_message_dev.class = &thermal_class; + dev_set_name(&thermal_message_dev, "thermal_message"); + ret = device_register(&thermal_message_dev); + if (!ret) { + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_sconfig.attr); + if (ret < 0) + pr_warn("Thermal: create sconfig node failed\n"); + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_boost.attr); + if (ret < 0) + pr_warn("Thermal: create boost node failed\n"); + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_temp_state.attr); + if (ret < 0) + pr_warn("Thermal: create temp state node failed\n"); + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_lighter_event.attr); + if (ret < 0) + pr_warn("Thermal: create lighter event node failed\n"); + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_cpu_limits.attr); + if (ret < 0) + pr_warn("Thermal: create cpu limits node failed\n"); +#ifdef CONFIG_FB + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_screen_state.attr); + if (ret < 0) + pr_warn("Thermal: create screen state node failed\n"); +#endif + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_board_sensor.attr); + if (ret < 0) + pr_warn("Thermal: create board sensor node failed\n"); + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_board_sensor_temp.attr); + if (ret < 0) + pr_warn("Thermal: create board sensor temp node failed\n"); + ret = sysfs_create_file(&thermal_message_dev.kobj, &dev_attr_flash_state.attr); + if (ret < 0) + pr_warn("Thermal: create flash state node failed\n"); + } + return ret; +} +static void destroy_thermal_message_node(void) +{ + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_board_sensor_temp.attr); + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_board_sensor.attr); + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_cpu_limits.attr); + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_temp_state.attr); + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_lighter_event.attr); + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_boost.attr); + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_sconfig.attr); +#ifdef CONFIG_FB + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_screen_state.attr); +#endif + sysfs_remove_file(&thermal_message_dev.kobj, &dev_attr_flash_state.attr); + device_unregister(&thermal_message_dev); +} +#ifdef CONFIG_FB +static int screen_state_for_thermal_callback(struct notifier_block *nb, unsigned long val, void *data) +{ + struct fb_event *evdata = data; + unsigned int blank; + if (val != FB_EARLY_EVENT_BLANK || !evdata || !evdata->data) + return 0; + blank = *(int *)(evdata->data); + switch (blank) { + case FB_BLANK_POWERDOWN: + sm.screen_state = 0; + pr_warn("%s: FB_BLANK_POWERDOWN\n", __func__); + break; + case FB_BLANK_UNBLANK: + sm.screen_state = 1; + pr_warn("%s: FB_BLANK_UNBLANK\n", __func__); + break; + default: + break; + } + sysfs_notify(&thermal_message_dev.kobj, NULL, "screen_state"); + return NOTIFY_OK; +} +#endif + static inline void print_bind_err_msg(struct thermal_zone_device *tz, struct thermal_cooling_device *cdev, int ret) @@ -1605,6 +1856,18 @@ static struct notifier_block thermal_pm_nb = { .notifier_call = thermal_pm_notify, }; +static int of_parse_thermal_message(void) +{ + struct device_node *np; + np = of_find_node_by_name(NULL, "thermal-message"); + if (!np) + return -EINVAL; + if (of_property_read_string(np, "board-sensor", &board_sensor)) + return -EINVAL; + pr_info("%s board sensor: %s\n", __func__, board_sensor); + return 0; +} + static int __init thermal_init(void) { int result; @@ -1618,6 +1881,22 @@ static int __init thermal_init(void) if (result) goto unregister_governors; +#ifdef CONFIG_FB + sm.thermal_notifier.notifier_call = screen_state_for_thermal_callback; + if (fb_register_client(&sm.thermal_notifier) < 0) { + pr_warn("Thermal: register screen state callback failed\n"); + } +#endif + result = of_parse_thermal_message(); + if (result) + pr_warn("Thermal: Can not parse thermal message node, return %d\n", + result); + + result = create_thermal_message_node(); + if (result) + pr_warn("Thermal: create thermal message node failed, return %d\n", + result); + result = genetlink_init(); if (result) goto unregister_class; @@ -1655,6 +1934,10 @@ static void __exit thermal_exit(void) genetlink_exit(); class_unregister(&thermal_class); thermal_unregister_governors(); + destroy_thermal_message_node(); +#ifdef CONFIG_FB + fb_unregister_client(&sm.thermal_notifier); +#endif ida_destroy(&thermal_tz_ida); ida_destroy(&thermal_cdev_ida); mutex_destroy(&thermal_list_lock); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 23dad4931991..23f53c4a04a9 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -428,6 +428,7 @@ static inline void cpufreq_resume(void) {} /* Transition notifiers */ #define CPUFREQ_PRECHANGE (0) #define CPUFREQ_POSTCHANGE (1) +#define CPUFREQ_THERMAL (2) /* Policy Notifiers */ #define CPUFREQ_ADJUST (0) diff --git a/include/uapi/linux/thermal.h b/include/uapi/linux/thermal.h index 96218378dda8..7950ba5573cf 100644 --- a/include/uapi/linux/thermal.h +++ b/include/uapi/linux/thermal.h @@ -4,6 +4,8 @@ #define THERMAL_NAME_LENGTH 20 +#define THERMAL_AVAILABLE_STATE_LENGTH 512 + /* Adding event notification support elements */ #define THERMAL_GENL_FAMILY_NAME "thermal_event" #define THERMAL_GENL_VERSION 0x01