Initial commit: Linux kernel 4.19 for Unplugged OS

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

No files matched your search

@@ -0,0 +1,41 @@
#
# 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
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,824 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <mt-plat/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mt-plat/mtk_thermal_monitor.h"
#include "mach/mtk_thermal.h"
#include <mt-plat/upmu_common.h>
#include <mt-plat/mtk_auxadc_intf.h>
#include <mach/mtk_pmic.h>
#include <tspmic_settings.h>
#if defined(THERMAL_USE_IIO_CHANNEL)
#include <iio/mt635x-auxadc.h>
#include <linux/iio/consumer.h>
#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;
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,997 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/seq_file.h>
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#endif
#if defined(CONFIG_MTK_CLKMGR)
#include <mach/mtk_clkmgr.h>
#else
#include <linux/clk.h>
#endif
#include <tscpu_settings.h>
#include "mtk_idle.h"
#if CFG_THERMAL_KERNEL_IGNORE_HOT_SENSOR
#include <mt-plat/mtk_devinfo.h>
#endif
#if CONFIG_LVTS_ERROR_AEE_WARNING
#include <mt-plat/aee.h>
#include <linux/delay.h>
#if DUMP_VCORE_VOLTAGE
#include <linux/regulator/consumer.h>
#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_LVTS1_0],
tscpu_ts_lvts_temp[L_TS_LVTS1_1]),
MAX(tscpu_ts_lvts_temp[L_TS_LVTS1_2],
tscpu_ts_lvts_temp[L_TS_LVTS1_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_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 = tscpu_ts_lvts_temp[L_TS_LVTS4_0];
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_lvts_temp[L_TS_LVTS3_0];
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_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_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_LITTLE LVTS1-0, LVTS1-1, LVTS1-2, LVTS1-3
* MCU_BIG LVTS2-0, LVTS2-1
* GPU LVTS3-0
* CAM LVTS3-1
* SOC TOP LVTS3-2, LVTS3-3
* VPU LVTS4-0
* MD-4G LVTS5-0
* MD-5G LVTS5-1
* MD-3G LVTS5-2
*/
/*
* THERMAL_BANK0, //L CPU (LVTS1)
* THERMAL_BANK1, //B 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_LVTS1_2];
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_LVTS1_3];
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_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_LVTS2_1];
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_tslvts1_2_wrap(void)
{
int curr_temp;
curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_2];
tscpu_dprintk("%s curr_temp=%d\n", __func__, curr_temp);
return curr_temp;
}
int get_immediate_tslvts1_3_wrap(void)
{
int curr_temp;
curr_temp = tscpu_ts_lvts_temp[TS_LVTS1_3];
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_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_tslvts1_2_wrap,
get_immediate_tslvts1_3_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_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_LITTLE LVTS1-0, LVTS1-1, LVTS1-2, LVTS1-3
* MCU_BIG LVTS2-0, LVTS2-1
* GPU LVTS3-0
* CAM LVTS3-1
* SOC TOP LVTS3-2, LVTS3-3
* VPU LVTS4-0
* 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_LVTS1_0],
tscpu_ts_lvts_temp[TS_LVTS1_1]),
MAX(tscpu_ts_lvts_temp[TS_LVTS1_2],
tscpu_ts_lvts_temp[TS_LVTS1_3])
)),
(MAX(
tscpu_ts_lvts_temp[TS_LVTS2_0],
tscpu_ts_lvts_temp[TS_LVTS2_1])
)
);
tscpu_curr_gpu_temp = tscpu_ts_lvts_temp[TS_LVTS3_0];
#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_LVTS1_2",
"TS_LVTS1_3",
"TS_LVTS2_0",
"TS_LVTS2_1",
"TS_LVTS3_0",
"TS_LVTS3_1",
"TS_LVTS3_2",
"TS_LVTS3_3",
"TS_LVTS4_0",
"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,mt6853-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
@@ -0,0 +1,414 @@
// 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 <linux/proc_fs.h>
#include <linux/uidgid.h>
#include <linux/delay.h>
#include <linux/seq_file.h>
#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)
{
#ifndef THERMAL_CPUSYS_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;
}
#endif
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
@@ -0,0 +1,327 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/uaccess.h>
#include <linux/proc_fs.h>
#include <ap_thermal_limit.h>
#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);
@@ -0,0 +1,597 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <mt-plat/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mt-plat/mtk_thermal_monitor.h"
#include "mach/mtk_thermal.h"
#include "mtk_thermal_timer.h"
#include <mt-plat/upmu_common.h>
#include <tspmic_settings.h>
#include <linux/uidgid.h>
#include <linux/slab.h>
/*=============================================================
*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);
@@ -0,0 +1,597 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <mt-plat/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mt-plat/mtk_thermal_monitor.h"
#include "mach/mtk_thermal.h"
#include "mtk_thermal_timer.h"
#include <mt-plat/upmu_common.h>
#include <tspmic_settings.h>
#include <linux/uidgid.h>
#include <linux/slab.h>
/*=============================================================
*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);
@@ -0,0 +1,595 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <mt-plat/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mt-plat/mtk_thermal_monitor.h"
#include "mach/mtk_thermal.h"
#include "mtk_thermal_timer.h"
#include <mt-plat/upmu_common.h>
#include <tspmic_settings.h>
#include <linux/uidgid.h>
#include <linux/slab.h>
/*=============================================================
*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);
@@ -0,0 +1,607 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <mt-plat/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mt-plat/mtk_thermal_monitor.h"
#include "mach/mtk_thermal.h"
#include "mtk_thermal_timer.h"
#include <mt-plat/upmu_common.h>
#include <tspmic_settings.h>
#include <linux/uidgid.h>
#include <linux/slab.h>
/*=============================================================
*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);
@@ -0,0 +1,604 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <mt-plat/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mt-plat/mtk_thermal_monitor.h"
#include "mach/mtk_thermal.h"
#include "mtk_thermal_timer.h"
#include <mt-plat/upmu_common.h>
#include <tspmic_settings.h>
#include <linux/uidgid.h>
#include <linux/slab.h>
/*=============================================================
*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);