Commit 983eb370 authored by Zhang Rui's avatar Zhang Rui Committed by Rafael J. Wysocki

thermal/x86_pkg_temp_thermal: Use Intel TCC library

Cleanup the code by using Intel TCC library for TCC (Thermal Control
Circuitry) MSR access.
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 4e3ecc28
...@@ -21,6 +21,7 @@ config X86_PKG_TEMP_THERMAL ...@@ -21,6 +21,7 @@ config X86_PKG_TEMP_THERMAL
depends on X86_THERMAL_VECTOR depends on X86_THERMAL_VECTOR
select THERMAL_GOV_USER_SPACE select THERMAL_GOV_USER_SPACE
select THERMAL_WRITABLE_TRIPS select THERMAL_WRITABLE_TRIPS
select INTEL_TCC
default m default m
help help
Enable this to register CPU digital sensor for package temperature as Enable this to register CPU digital sensor for package temperature as
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/intel_tcc.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/param.h> #include <linux/param.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -104,38 +105,18 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu) ...@@ -104,38 +105,18 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)
return NULL; return NULL;
} }
/*
* tj-max is interesting because threshold is set relative to this
* temperature.
*/
static int get_tj_max(int cpu, u32 *tj_max)
{
u32 eax, edx, val;
int err;
err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
if (err)
return err;
val = (eax >> 16) & 0xff;
*tj_max = val * 1000;
return val ? 0 : -EINVAL;
}
static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
{ {
struct zone_device *zonedev = tzd->devdata; struct zone_device *zonedev = tzd->devdata;
u32 eax, edx; int val;
rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_STATUS, val = intel_tcc_get_temp(zonedev->cpu, true);
&eax, &edx); if (val < 0)
if (eax & 0x80000000) { return val;
*temp = zonedev->tj_max - ((eax >> 16) & 0x7f) * 1000;
pr_debug("sys_get_curr_temp %d\n", *temp); *temp = val * 1000;
return 0; pr_debug("sys_get_curr_temp %d\n", *temp);
} return 0;
return -EINVAL;
} }
static int sys_get_trip_temp(struct thermal_zone_device *tzd, static int sys_get_trip_temp(struct thermal_zone_device *tzd,
...@@ -340,9 +321,9 @@ static int pkg_temp_thermal_device_add(unsigned int cpu) ...@@ -340,9 +321,9 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS); thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS);
err = get_tj_max(cpu, &tj_max); tj_max = intel_tcc_get_tjmax(cpu);
if (err) if (tj_max < 0)
return err; return tj_max;
zonedev = kzalloc(sizeof(*zonedev), GFP_KERNEL); zonedev = kzalloc(sizeof(*zonedev), GFP_KERNEL);
if (!zonedev) if (!zonedev)
...@@ -531,6 +512,7 @@ static void __exit pkg_temp_thermal_exit(void) ...@@ -531,6 +512,7 @@ static void __exit pkg_temp_thermal_exit(void)
} }
module_exit(pkg_temp_thermal_exit) module_exit(pkg_temp_thermal_exit)
MODULE_IMPORT_NS(INTEL_TCC);
MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver"); MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");
MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment