forked from Minki/linux
17e8351a77
The thermal code uses int, long and unsigned long for temperatures in different places. Using an unsigned type limits the thermal framework to positive temperatures without need. Also several drivers currently will report temperatures near UINT_MAX for temperatures below 0°C. This will probably immediately shut the machine down due to overtemperature if started below 0°C. 'long' is 64bit on several architectures. This is not needed since INT_MAX °mC is above the melting point of all known materials. Consistently use a plain 'int' for temperatures throughout the thermal code and the drivers. This only changes the places in the drivers where the temperature is passed around as pointer, when drivers internally use another type this is not changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com> Reviewed-by: Darren Hart <dvhart@linux.intel.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Peter Feuerer <peter@piie.net> Cc: Punit Agrawal <punit.agrawal@arm.com> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Jean Delvare <jdelvare@suse.de> Cc: Peter Feuerer <peter@piie.net> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Lukasz Majewski <l.majewski@samsung.com> Cc: Stephen Warren <swarren@wwwdotorg.org> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: linux-acpi@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-omap@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org Cc: Guenter Roeck <linux@roeck-us.net> Cc: Rafael J. Wysocki <rjw@rjwysocki.net> Cc: Maxime Ripard <maxime.ripard@free-electrons.com> Cc: Darren Hart <dvhart@infradead.org> Cc: lm-sensors@lm-sensors.org Signed-off-by: Zhang Rui <rui.zhang@intel.com>
131 lines
3.6 KiB
C
131 lines
3.6 KiB
C
/*
|
|
* gov_bang_bang.c - A simple thermal throttling governor using hysteresis
|
|
*
|
|
* Copyright (C) 2014 Peter Feuerer <peter@piie.net>
|
|
*
|
|
* Based on step_wise.c with following Copyrights:
|
|
* Copyright (C) 2012 Intel Corp
|
|
* Copyright (C) 2012 Durgadoss R <durgadoss.r@intel.com>
|
|
*
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, version 2.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
|
* the GNU General Public License for more details.
|
|
*
|
|
*/
|
|
|
|
#include <linux/thermal.h>
|
|
|
|
#include "thermal_core.h"
|
|
|
|
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
|
|
{
|
|
int trip_temp, trip_hyst;
|
|
struct thermal_instance *instance;
|
|
|
|
tz->ops->get_trip_temp(tz, trip, &trip_temp);
|
|
tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
|
|
|
|
dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
|
|
trip, trip_temp, tz->temperature,
|
|
trip_hyst);
|
|
|
|
mutex_lock(&tz->lock);
|
|
|
|
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
|
|
if (instance->trip != trip)
|
|
continue;
|
|
|
|
/* in case fan is in initial state, switch the fan off */
|
|
if (instance->target == THERMAL_NO_TARGET)
|
|
instance->target = 0;
|
|
|
|
/* in case fan is neither on nor off set the fan to active */
|
|
if (instance->target != 0 && instance->target != 1) {
|
|
pr_warn("Thermal instance %s controlled by bang-bang has unexpected state: %ld\n",
|
|
instance->name, instance->target);
|
|
instance->target = 1;
|
|
}
|
|
|
|
/*
|
|
* enable fan when temperature exceeds trip_temp and disable
|
|
* the fan in case it falls below trip_temp minus hysteresis
|
|
*/
|
|
if (instance->target == 0 && tz->temperature >= trip_temp)
|
|
instance->target = 1;
|
|
else if (instance->target == 1 &&
|
|
tz->temperature < trip_temp - trip_hyst)
|
|
instance->target = 0;
|
|
|
|
dev_dbg(&instance->cdev->device, "target=%d\n",
|
|
(int)instance->target);
|
|
|
|
instance->cdev->updated = false; /* cdev needs update */
|
|
}
|
|
|
|
mutex_unlock(&tz->lock);
|
|
}
|
|
|
|
/**
|
|
* bang_bang_control - controls devices associated with the given zone
|
|
* @tz - thermal_zone_device
|
|
* @trip - the trip point
|
|
*
|
|
* Regulation Logic: a two point regulation, deliver cooling state depending
|
|
* on the previous state shown in this diagram:
|
|
*
|
|
* Fan: OFF ON
|
|
*
|
|
* |
|
|
* |
|
|
* trip_temp: +---->+
|
|
* | | ^
|
|
* | | |
|
|
* | | Temperature
|
|
* (trip_temp - hyst): +<----+
|
|
* |
|
|
* |
|
|
* |
|
|
*
|
|
* * If the fan is not running and temperature exceeds trip_temp, the fan
|
|
* gets turned on.
|
|
* * In case the fan is running, temperature must fall below
|
|
* (trip_temp - hyst) so that the fan gets turned off again.
|
|
*
|
|
*/
|
|
static int bang_bang_control(struct thermal_zone_device *tz, int trip)
|
|
{
|
|
struct thermal_instance *instance;
|
|
|
|
thermal_zone_trip_update(tz, trip);
|
|
|
|
mutex_lock(&tz->lock);
|
|
|
|
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
|
|
thermal_cdev_update(instance->cdev);
|
|
|
|
mutex_unlock(&tz->lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct thermal_governor thermal_gov_bang_bang = {
|
|
.name = "bang_bang",
|
|
.throttle = bang_bang_control,
|
|
};
|
|
|
|
int thermal_gov_bang_bang_register(void)
|
|
{
|
|
return thermal_register_governor(&thermal_gov_bang_bang);
|
|
}
|
|
|
|
void thermal_gov_bang_bang_unregister(void)
|
|
{
|
|
thermal_unregister_governor(&thermal_gov_bang_bang);
|
|
}
|