diff options
Diffstat (limited to 'drivers/thermal')
-rw-r--r-- | drivers/thermal/Kconfig | 9 | ||||
-rw-r--r-- | drivers/thermal/Makefile | 1 | ||||
-rw-r--r-- | drivers/thermal/cpu_cooling.c | 11 | ||||
-rw-r--r-- | drivers/thermal/imx_thermal.c | 32 | ||||
-rw-r--r-- | drivers/thermal/int3403_thermal.c | 237 | ||||
-rw-r--r-- | drivers/thermal/samsung/exynos_thermal_common.c | 2 | ||||
-rw-r--r-- | drivers/thermal/samsung/exynos_tmu.c | 1 | ||||
-rw-r--r-- | drivers/thermal/step_wise.c | 6 | ||||
-rw-r--r-- | drivers/thermal/thermal_core.c | 6 | ||||
-rw-r--r-- | drivers/thermal/x86_pkg_temp_thermal.c | 2 |
10 files changed, 288 insertions, 19 deletions
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 3feb5377fbf6..35c066489a19 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -135,7 +135,7 @@ config SPEAR_THERMAL config RCAR_THERMAL tristate "Renesas R-Car thermal driver" - depends on ARCH_SHMOBILE + depends on ARCH_SHMOBILE || COMPILE_TEST help Enable this to plug the R-Car thermal sensor driver into the Linux thermal framework. @@ -206,6 +206,13 @@ config X86_PKG_TEMP_THERMAL two trip points which can be set by user to get notifications via thermal notification methods. +config ACPI_INT3403_THERMAL + tristate "ACPI INT3403 thermal driver" + depends on X86 && ACPI + help + This driver uses ACPI INT3403 device objects. If present, it will + register each INT3403 thermal sensor as a thermal zone. + menu "Texas Instruments thermal drivers" source "drivers/thermal/ti-soc-thermal/Kconfig" endmenu diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 4b03956b929c..54e4ec9eb5df 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/ +obj-$(CONFIG_ACPI_INT3403_THERMAL) += int3403_thermal.o diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index a6cb5531403f..4246262c4bd2 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -174,6 +174,13 @@ static int get_property(unsigned int cpu, unsigned long input, max_level++; } + /* No valid cpu frequency entry */ + if (max_level == 0) + return -EINVAL; + + /* max_level is an index, not a counter */ + max_level--; + /* get max level */ if (property == GET_MAXL) { *output = (unsigned int)max_level; @@ -181,7 +188,7 @@ static int get_property(unsigned int cpu, unsigned long input, } if (property == GET_FREQ) - level = descend ? input : (max_level - input - 1); + level = descend ? input : (max_level - input); for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { /* ignore invalid entry */ @@ -197,7 +204,7 @@ static int get_property(unsigned int cpu, unsigned long input, if (property == GET_LEVEL && (unsigned int)input == freq) { /* get level by frequency */ - *output = descend ? j : (max_level - j - 1); + *output = descend ? j : (max_level - j); return 0; } if (property == GET_FREQ && level == j) { diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 1d6c801c1eb9..77a962f1837b 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -490,27 +490,30 @@ static int imx_thermal_suspend(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); struct regmap *map = data->tempmon; - u32 val; - regmap_read(map, TEMPSENSE0, &val); - if ((val & TEMPSENSE0_POWER_DOWN) == 0) { - /* - * If a measurement is taking place, wait for a long enough - * time for it to finish, and then check again. If it still - * does not finish, something must go wrong. - */ - udelay(50); - regmap_read(map, TEMPSENSE0, &val); - if ((val & TEMPSENSE0_POWER_DOWN) == 0) - return -ETIMEDOUT; - } + /* + * Need to disable thermal sensor, otherwise, when thermal core + * try to get temperature before thermal sensor resume, a wrong + * temperature will be read as the thermal sensor is powered + * down. + */ + regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); + regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); + data->mode = THERMAL_DEVICE_DISABLED; return 0; } static int imx_thermal_resume(struct device *dev) { - /* Nothing to do for now */ + struct imx_thermal_data *data = dev_get_drvdata(dev); + struct regmap *map = data->tempmon; + + /* Enabled thermal sensor after resume */ + regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); + regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + data->mode = THERMAL_DEVICE_ENABLED; + return 0; } #endif @@ -522,6 +525,7 @@ static const struct of_device_id of_imx_thermal_match[] = { { .compatible = "fsl,imx6q-tempmon", }, { /* end */ } }; +MODULE_DEVICE_TABLE(of, of_imx_thermal_match); static struct platform_driver imx_thermal = { .driver = { diff --git a/drivers/thermal/int3403_thermal.c b/drivers/thermal/int3403_thermal.c new file mode 100644 index 000000000000..1301681d9a77 --- /dev/null +++ b/drivers/thermal/int3403_thermal.c @@ -0,0 +1,237 @@ +/* + * ACPI INT3403 thermal driver + * Copyright (c) 2013, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/acpi.h> +#include <linux/thermal.h> + +#define INT3403_TYPE_SENSOR 0x03 +#define INT3403_PERF_CHANGED_EVENT 0x80 +#define INT3403_THERMAL_EVENT 0x90 + +#define DECI_KELVIN_TO_MILLI_CELSIUS(t, off) (((t) - (off)) * 100) +#define KELVIN_OFFSET 2732 +#define MILLI_CELSIUS_TO_DECI_KELVIN(t, off) (((t) / 100) + (off)) + +#define ACPI_INT3403_CLASS "int3403" +#define ACPI_INT3403_FILE_STATE "state" + +struct int3403_sensor { + struct thermal_zone_device *tzone; + unsigned long *thresholds; +}; + +static int sys_get_curr_temp(struct thermal_zone_device *tzone, + unsigned long *temp) +{ + struct acpi_device *device = tzone->devdata; + unsigned long long tmp; + acpi_status status; + + status = acpi_evaluate_integer(device->handle, "_TMP", NULL, &tmp); + if (ACPI_FAILURE(status)) + return -EIO; + + *temp = DECI_KELVIN_TO_MILLI_CELSIUS(tmp, KELVIN_OFFSET); + + return 0; +} + +static int sys_get_trip_hyst(struct thermal_zone_device *tzone, + int trip, unsigned long *temp) +{ + struct acpi_device *device = tzone->devdata; + unsigned long long hyst; + acpi_status status; + + status = acpi_evaluate_integer(device->handle, "GTSH", NULL, &hyst); + if (ACPI_FAILURE(status)) + return -EIO; + + *temp = DECI_KELVIN_TO_MILLI_CELSIUS(hyst, KELVIN_OFFSET); + + return 0; +} + +static int sys_get_trip_temp(struct thermal_zone_device *tzone, + int trip, unsigned long *temp) +{ + struct acpi_device *device = tzone->devdata; + struct int3403_sensor *obj = acpi_driver_data(device); + + /* + * get_trip_temp is a mandatory callback but + * PATx method doesn't return any value, so return + * cached value, which was last set from user space. + */ + *temp = obj->thresholds[trip]; + + return 0; +} + +static int sys_get_trip_type(struct thermal_zone_device *thermal, + int trip, enum thermal_trip_type *type) +{ + /* Mandatory callback, may not mean much here */ + *type = THERMAL_TRIP_PASSIVE; + + return 0; +} + +int sys_set_trip_temp(struct thermal_zone_device *tzone, int trip, + unsigned long temp) +{ + struct acpi_device *device = tzone->devdata; + acpi_status status; + char name[10]; + int ret = 0; + struct int3403_sensor *obj = acpi_driver_data(device); + + snprintf(name, sizeof(name), "PAT%d", trip); + if (acpi_has_method(device->handle, name)) { + status = acpi_execute_simple_method(device->handle, name, + MILLI_CELSIUS_TO_DECI_KELVIN(temp, + KELVIN_OFFSET)); + if (ACPI_FAILURE(status)) + ret = -EIO; + else + obj->thresholds[trip] = temp; + } else { + ret = -EIO; + dev_err(&device->dev, "sys_set_trip_temp: method not found\n"); + } + + return ret; +} + +static struct thermal_zone_device_ops tzone_ops = { + .get_temp = sys_get_curr_temp, + .get_trip_temp = sys_get_trip_temp, + .get_trip_type = sys_get_trip_type, + .set_trip_temp = sys_set_trip_temp, + .get_trip_hyst = sys_get_trip_hyst, +}; + +static void acpi_thermal_notify(struct acpi_device *device, u32 event) +{ + struct int3403_sensor *obj; + + if (!device) + return; + + obj = acpi_driver_data(device); + if (!obj) + return; + + switch (event) { + case INT3403_PERF_CHANGED_EVENT: + break; + case INT3403_THERMAL_EVENT: + thermal_zone_device_update(obj->tzone); + break; + default: + dev_err(&device->dev, "Unsupported event [0x%x]\n", event); + break; + } +} + +static int acpi_int3403_add(struct acpi_device *device) +{ + int result = 0; + unsigned long long ptyp; + acpi_status status; + struct int3403_sensor *obj; + unsigned long long trip_cnt; + int trip_mask = 0; + + if (!device) + return -EINVAL; + + status = acpi_evaluate_integer(device->handle, "PTYP", NULL, &ptyp); + if (ACPI_FAILURE(status)) + return -EINVAL; + + if (ptyp != INT3403_TYPE_SENSOR) + return -EINVAL; + + obj = devm_kzalloc(&device->dev, sizeof(*obj), GFP_KERNEL); + if (!obj) + return -ENOMEM; + + device->driver_data = obj; + + status = acpi_evaluate_integer(device->handle, "PATC", NULL, + &trip_cnt); + if (ACPI_FAILURE(status)) + trip_cnt = 0; + + if (trip_cnt) { + /* We have to cache, thresholds can't be readback */ + obj->thresholds = devm_kzalloc(&device->dev, + sizeof(*obj->thresholds) * trip_cnt, + GFP_KERNEL); + if (!obj->thresholds) + return -ENOMEM; + trip_mask = BIT(trip_cnt) - 1; + } + obj->tzone = thermal_zone_device_register(acpi_device_bid(device), + trip_cnt, trip_mask, device, &tzone_ops, + NULL, 0, 0); + if (IS_ERR(obj->tzone)) { + result = PTR_ERR(obj->tzone); + return result; + } + + strcpy(acpi_device_name(device), "INT3403"); + strcpy(acpi_device_class(device), ACPI_INT3403_CLASS); + + return 0; +} + +static int acpi_int3403_remove(struct acpi_device *device) +{ + struct int3403_sensor *obj; + + obj = acpi_driver_data(device); + thermal_zone_device_unregister(obj->tzone); + + return 0; +} + +ACPI_MODULE_NAME("int3403"); +static const struct acpi_device_id int3403_device_ids[] = { + {"INT3403", 0}, + {"", 0}, +}; +MODULE_DEVICE_TABLE(acpi, int3403_device_ids); + +static struct acpi_driver acpi_int3403_driver = { + .name = "INT3403", + .class = ACPI_INT3403_CLASS, + .ids = int3403_device_ids, + .ops = { + .add = acpi_int3403_add, + .remove = acpi_int3403_remove, + .notify = acpi_thermal_notify, + }, +}; + +module_acpi_driver(acpi_int3403_driver); + +MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("ACPI INT3403 thermal driver"); diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c index c2301da08ac7..3f5ad25ddca8 100644 --- a/drivers/thermal/samsung/exynos_thermal_common.c +++ b/drivers/thermal/samsung/exynos_thermal_common.c @@ -280,7 +280,7 @@ static int exynos_get_trend(struct thermal_zone_device *thermal, return 0; } /* Operation callback functions for thermal zone */ -static struct thermal_zone_device_ops const exynos_dev_ops = { +static struct thermal_zone_device_ops exynos_dev_ops = { .bind = exynos_bind, .unbind = exynos_unbind, .get_temp = exynos_get_temp, diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 32f38b90c4f6..0d96a510389f 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -205,6 +205,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev) skip_calib_data: if (pdata->max_trigger_level > MAX_THRESHOLD_LEVS) { dev_err(&pdev->dev, "Invalid max trigger level\n"); + ret = -EINVAL; goto out; } diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index d89e781b0a18..f251521baaa2 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -60,6 +60,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, */ cdev->ops->get_cur_state(cdev, &cur_state); next_target = instance->target; + dev_dbg(&cdev->device, "cur_state=%ld\n", cur_state); switch (trend) { case THERMAL_TREND_RAISING: @@ -131,6 +132,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) if (tz->temperature >= trip_temp) throttle = true; + dev_dbg(&tz->device, "Trip%d[type=%d,temp=%ld]:trend=%d,throttle=%d\n", + trip, trip_type, trip_temp, trend, throttle); + mutex_lock(&tz->lock); list_for_each_entry(instance, &tz->thermal_instances, tz_node) { @@ -139,6 +143,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) old_target = instance->target; instance->target = get_target_state(instance, trend, throttle); + dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n", + old_target, (int)instance->target); if (old_target == instance->target) continue; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e381d521c355..a621e90cbf40 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -451,6 +451,9 @@ static void update_temperature(struct thermal_zone_device *tz) tz->last_temperature = tz->temperature; tz->temperature = temp; mutex_unlock(&tz->lock); + + dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n", + tz->last_temperature, tz->temperature); } void thermal_zone_device_update(struct thermal_zone_device *tz) @@ -1260,6 +1263,8 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) mutex_lock(&cdev->lock); /* Make sure cdev enters the deepest cooling state */ list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { + dev_dbg(&cdev->device, "zone%d->target=%lu\n", + instance->tz->id, instance->target); if (instance->target == THERMAL_NO_TARGET) continue; if (instance->target > target) @@ -1268,6 +1273,7 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) mutex_unlock(&cdev->lock); cdev->ops->set_cur_state(cdev, target); cdev->updated = true; + dev_dbg(&cdev->device, "set to state %lu\n", target); } EXPORT_SYMBOL(thermal_cdev_update); diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c index 7722cb9d5a80..972e1c73722a 100644 --- a/drivers/thermal/x86_pkg_temp_thermal.c +++ b/drivers/thermal/x86_pkg_temp_thermal.c @@ -215,7 +215,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, return 0; } -int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, +static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, unsigned long temp) { u32 l, h; |