Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux

Pull ACPI & Thermal updates from Len Brown:
 "The generic Linux thermal layer is gaining some new capabilities
  (generic cooling via cpufreq) and some new customers (ARM).

  Also, an ACPI EC bug fix plus a regression fix."

* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux: (30 commits)
  tools/power/acpi/acpidump: remove duplicated include from acpidump.c
  ACPI idle, CPU hotplug: Fix NULL pointer dereference during hotplug
  cpuidle / ACPI: fix potential NULL pointer dereference
  ACPI: EC: Add a quirk for CLEVO M720T/M730T laptop
  ACPI: EC: Make the GPE storm threshold a module parameter
  thermal: Exynos: Fix NULL pointer dereference in exynos_unregister_thermal()
  Thermal: Fix bug on cpu_cooling, cooling device's id conflict problem.
  thermal: exynos: Use devm_* functions
  ARM: exynos: add thermal sensor driver platform data support
  thermal: exynos: register the tmu sensor with the kernel thermal layer
  thermal: exynos5: add exynos5250 thermal sensor driver support
  hwmon: exynos4: move thermal sensor driver to driver/thermal directory
  thermal: add generic cpufreq cooling implementation
  Fix a build error.
  thermal: Fix potential NULL pointer accesses
  thermal: add Renesas R-Car thermal sensor support
  thermal: fix potential out-of-bounds memory access
  Thermal: Introduce locking for cdev.thermal_instances list.
  Thermal: Unify the code for both active and passive cooling
  Thermal: Introduce simple arbitrator for setting device cooling state
  ...
This commit is contained in:
Linus Torvalds
2012-10-13 11:27:59 +09:00
25 changed files with 2205 additions and 736 deletions
+32
View File
@@ -0,0 +1,32 @@
CPU cooling APIs How To
===================================
Written by Amit Daniel Kachhap <amit.kachhap@linaro.org>
Updated: 12 May 2012
Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
0. Introduction
The generic cpu cooling(freq clipping) provides registration/unregistration APIs
to the caller. The binding of the cooling devices to the trip point is left for
the user. The registration APIs returns the cooling device pointer.
1. cpu cooling APIs
1.1 cpufreq registration/unregistration APIs
1.1.1 struct thermal_cooling_device *cpufreq_cooling_register(
struct cpumask *clip_cpus)
This interface function registers the cpufreq cooling device with the name
"thermal-cpufreq-%x". This api can support multiple instances of cpufreq
cooling devices.
clip_cpus: cpumask of cpus where the frequency constraints will happen.
1.1.2 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
This interface function unregisters the "thermal-cpufreq-%x" cooling device.
cdev: Cooling device pointer which has to be unregistered.
@@ -46,36 +46,7 @@ The threshold levels are defined as follows:
The threshold and each trigger_level are set
through the corresponding registers.
When an interrupt occurs, this driver notify user space of
one of four threshold levels for the interrupt
through kobject_uevent_env and sysfs_notify functions.
When an interrupt occurs, this driver notify kernel thermal framework
with the function exynos4_report_trigger.
Although an interrupt condition for level_0 can be set,
it is not notified to user space through sysfs_notify function.
Sysfs Interface
---------------
name name of the temperature sensor
RO
temp1_input temperature
RO
temp1_max temperature for level_1 interrupt
RO
temp1_crit temperature for level_2 interrupt
RO
temp1_emergency temperature for level_3 interrupt
RO
temp1_max_alarm alarm for level_1 interrupt
RO
temp1_crit_alarm
alarm for level_2 interrupt
RO
temp1_emergency_alarm
alarm for level_3 interrupt
RO
it can be used to synchronize the cooling action.
+8 -1
View File
@@ -84,7 +84,8 @@ temperature) and throttle appropriate devices.
1.3 interface for binding a thermal zone device with a thermal cooling device
1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
int trip, struct thermal_cooling_device *cdev);
int trip, struct thermal_cooling_device *cdev,
unsigned long upper, unsigned long lower);
This interface function bind a thermal cooling device to the certain trip
point of a thermal zone device.
@@ -93,6 +94,12 @@ temperature) and throttle appropriate devices.
cdev: thermal cooling device
trip: indicates which trip point the cooling devices is associated with
in this thermal zone.
upper:the Maximum cooling state for this trip point.
THERMAL_NO_LIMIT means no upper limit,
and the cooling device can be in max_state.
lower:the Minimum cooling state can be used for this trip point.
THERMAL_NO_LIMIT means no lower limit,
and the cooling device can be in cooling state 0.
1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
int trip, struct thermal_cooling_device *cdev);
+25 -5
View File
@@ -71,9 +71,6 @@ enum ec_command {
#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
#define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */
#define ACPI_EC_STORM_THRESHOLD 8 /* number of false interrupts
per one transaction */
enum {
EC_FLAGS_QUERY_PENDING, /* Query is pending */
EC_FLAGS_GPE_STORM, /* GPE storm detected */
@@ -87,6 +84,15 @@ static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY;
module_param(ec_delay, uint, 0644);
MODULE_PARM_DESC(ec_delay, "Timeout(ms) waited until an EC command completes");
/*
* If the number of false interrupts per one transaction exceeds
* this threshold, will think there is a GPE storm happened and
* will disable the GPE for normal transaction.
*/
static unsigned int ec_storm_threshold __read_mostly = 8;
module_param(ec_storm_threshold, uint, 0644);
MODULE_PARM_DESC(ec_storm_threshold, "Maxim false GPE numbers not considered as GPE storm");
/* If we find an EC via the ECDT, we need to keep a ptr to its context */
/* External interfaces use first EC only, so remember */
typedef int (*acpi_ec_query_func) (void *data);
@@ -319,7 +325,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
msleep(1);
/* It is safe to enable the GPE outside of the transaction. */
acpi_enable_gpe(NULL, ec->gpe);
} else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) {
} else if (t->irq_count > ec_storm_threshold) {
pr_info(PREFIX "GPE storm detected, "
"transactions will use polling mode\n");
set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
@@ -924,6 +930,17 @@ static int ec_flag_msi(const struct dmi_system_id *id)
return 0;
}
/*
* Clevo M720 notebook actually works ok with IRQ mode, if we lifted
* the GPE storm threshold back to 20
*/
static int ec_enlarge_storm_threshold(const struct dmi_system_id *id)
{
pr_debug("Setting the EC GPE storm threshold to 20\n");
ec_storm_threshold = 20;
return 0;
}
static struct dmi_system_id __initdata ec_dmi_table[] = {
{
ec_skip_dsdt_scan, "Compal JFL92", {
@@ -955,10 +972,13 @@ static struct dmi_system_id __initdata ec_dmi_table[] = {
{
ec_validate_ecdt, "ASUS hardware", {
DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc.") }, NULL},
{
ec_enlarge_storm_threshold, "CLEVO hardware", {
DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL},
{},
};
int __init acpi_ec_ecdt_probe(void)
{
acpi_status status;
+2 -1
View File
@@ -1132,7 +1132,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
int acpi_processor_hotplug(struct acpi_processor *pr)
{
int ret = 0;
struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id);
struct cpuidle_device *dev;
if (disabled_by_idle_boot_param())
return 0;
@@ -1147,6 +1147,7 @@ int acpi_processor_hotplug(struct acpi_processor *pr)
if (!pr->flags.power_setup_done)
return -ENODEV;
dev = per_cpu(acpi_cpuidle_device, pr->id);
cpuidle_pause_and_lock();
cpuidle_disable_device(dev);
acpi_processor_get_power_info(pr);
+71 -22
View File
@@ -708,6 +708,40 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
return -EINVAL;
}
static int thermal_get_trend(struct thermal_zone_device *thermal,
int trip, enum thermal_trend *trend)
{
struct acpi_thermal *tz = thermal->devdata;
enum thermal_trip_type type;
int i;
if (thermal_get_trip_type(thermal, trip, &type))
return -EINVAL;
if (type == THERMAL_TRIP_ACTIVE) {
/* aggressive active cooling */
*trend = THERMAL_TREND_RAISING;
return 0;
}
/*
* tz->temperature has already been updated by generic thermal layer,
* before this callback being invoked
*/
i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
+ (tz->trips.passive.tc2
* (tz->temperature - tz->trips.passive.temperature));
if (i > 0)
*trend = THERMAL_TREND_RAISING;
else if (i < 0)
*trend = THERMAL_TREND_DROPPING;
else
*trend = THERMAL_TREND_STABLE;
return 0;
}
static int thermal_notify(struct thermal_zone_device *thermal, int trip,
enum thermal_trip_type trip_type)
{
@@ -731,11 +765,9 @@ static int thermal_notify(struct thermal_zone_device *thermal, int trip,
return 0;
}
typedef int (*cb)(struct thermal_zone_device *, int,
struct thermal_cooling_device *);
static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev,
cb action)
bool bind)
{
struct acpi_device *device = cdev->devdata;
struct acpi_thermal *tz = thermal->devdata;
@@ -759,11 +791,19 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
i++) {
handle = tz->trips.passive.devices.handles[i];
status = acpi_bus_get_device(handle, &dev);
if (ACPI_SUCCESS(status) && (dev == device)) {
result = action(thermal, trip, cdev);
if (result)
goto failed;
}
if (ACPI_FAILURE(status) || dev != device)
continue;
if (bind)
result =
thermal_zone_bind_cooling_device
(thermal, trip, cdev,
THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
else
result =
thermal_zone_unbind_cooling_device
(thermal, trip, cdev);
if (result)
goto failed;
}
}
@@ -776,11 +816,17 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
j++) {
handle = tz->trips.active[i].devices.handles[j];
status = acpi_bus_get_device(handle, &dev);
if (ACPI_SUCCESS(status) && (dev == device)) {
result = action(thermal, trip, cdev);
if (result)
goto failed;
}
if (ACPI_FAILURE(status) || dev != device)
continue;
if (bind)
result = thermal_zone_bind_cooling_device
(thermal, trip, cdev,
THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
else
result = thermal_zone_unbind_cooling_device
(thermal, trip, cdev);
if (result)
goto failed;
}
}
@@ -788,7 +834,14 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
handle = tz->devices.handles[i];
status = acpi_bus_get_device(handle, &dev);
if (ACPI_SUCCESS(status) && (dev == device)) {
result = action(thermal, -1, cdev);
if (bind)
result = thermal_zone_bind_cooling_device
(thermal, -1, cdev,
THERMAL_NO_LIMIT,
THERMAL_NO_LIMIT);
else
result = thermal_zone_unbind_cooling_device
(thermal, -1, cdev);
if (result)
goto failed;
}
@@ -802,16 +855,14 @@ static int
acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
{
return acpi_thermal_cooling_device_cb(thermal, cdev,
thermal_zone_bind_cooling_device);
return acpi_thermal_cooling_device_cb(thermal, cdev, true);
}
static int
acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
{
return acpi_thermal_cooling_device_cb(thermal, cdev,
thermal_zone_unbind_cooling_device);
return acpi_thermal_cooling_device_cb(thermal, cdev, false);
}
static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
@@ -823,6 +874,7 @@ static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
.get_trip_type = thermal_get_trip_type,
.get_trip_temp = thermal_get_trip_temp,
.get_crit_temp = thermal_get_crit_temp,
.get_trend = thermal_get_trend,
.notify = thermal_notify,
};
@@ -849,15 +901,12 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
tz->thermal_zone =
thermal_zone_device_register("acpitz", trips, 0, tz,
&acpi_thermal_zone_ops,
tz->trips.passive.tc1,
tz->trips.passive.tc2,
tz->trips.passive.tsp*100,
tz->polling_frequency*100);
else
tz->thermal_zone =
thermal_zone_device_register("acpitz", trips, 0, tz,
&acpi_thermal_zone_ops,
0, 0, 0,
&acpi_thermal_zone_ops, 0,
tz->polling_frequency*100);
if (IS_ERR(tz->thermal_zone))
return -ENODEV;
+1 -1
View File
@@ -368,7 +368,7 @@ EXPORT_SYMBOL_GPL(cpuidle_enable_device);
*/
void cpuidle_disable_device(struct cpuidle_device *dev)
{
if (!dev->enabled)
if (!dev || !dev->enabled)
return;
if (!cpuidle_get_driver() || !cpuidle_curr_governor)
return;
-10
View File
@@ -334,16 +334,6 @@ config SENSORS_DA9052_ADC
This driver can also be built as module. If so, the module
will be called da9052-hwmon.
config SENSORS_EXYNOS4_TMU
tristate "Temperature sensor on Samsung EXYNOS4"
depends on ARCH_EXYNOS4
help
If you say yes here you get support for TMU (Thermal Management
Unit) on SAMSUNG EXYNOS4 series of SoC.
This driver can also be built as a module. If so, the module
will be called exynos4-tmu.
config SENSORS_I5K_AMB
tristate "FB-DIMM AMB temperature sensor on Intel 5000 series chipsets"
depends on PCI
-1
View File
@@ -50,7 +50,6 @@ obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o
obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o
obj-$(CONFIG_SENSORS_EMC6W201) += emc6w201.o
obj-$(CONFIG_SENSORS_EXYNOS4_TMU) += exynos4_tmu.o
obj-$(CONFIG_SENSORS_F71805F) += f71805f.o
obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o
obj-$(CONFIG_SENSORS_F75375S) += f75375s.o
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -329,7 +329,8 @@ static int acerhdf_bind(struct thermal_zone_device *thermal,
if (cdev != cl_dev)
return 0;
if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
if (thermal_zone_bind_cooling_device(thermal, 0, cdev,
THERMAL_NO_LIMIT, THERMAL_NO_LIMIT)) {
pr_err("error binding cooling dev\n");
return -EINVAL;
}
@@ -661,7 +662,7 @@ static int acerhdf_register_thermal(void)
return -EINVAL;
thz_dev = thermal_zone_device_register("acerhdf", 1, 0, NULL,
&acerhdf_dev_ops, 0, 0, 0,
&acerhdf_dev_ops, 0,
(kernelmode) ? interval*1000 : 0);
if (IS_ERR(thz_dev))
return -EINVAL;
+1 -1
View File
@@ -502,7 +502,7 @@ static int mid_thermal_probe(struct platform_device *pdev)
goto err;
}
pinfo->tzd[i] = thermal_zone_device_register(name[i],
0, 0, td_info, &tzd_ops, 0, 0, 0, 0);
0, 0, td_info, &tzd_ops, 0, 0);
if (IS_ERR(pinfo->tzd[i])) {
kfree(td_info);
ret = PTR_ERR(pinfo->tzd[i]);
+1 -1
View File
@@ -201,7 +201,7 @@ static int psy_register_thermal(struct power_supply *psy)
for (i = 0; i < psy->num_properties; i++) {
if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) {
psy->tzd = thermal_zone_device_register(psy->name, 0, 0,
psy, &psy_tzd_ops, 0, 0, 0, 0);
psy, &psy_tzd_ops, 0, 0);
if (IS_ERR(psy->tzd))
return PTR_ERR(psy->tzd);
break;
@@ -126,7 +126,9 @@ static int omap_thermal_bind(struct thermal_zone_device *thermal,
/* TODO: bind with min and max states */
/* Simple thing, two trips, one passive another critical */
return thermal_zone_bind_cooling_device(thermal, 0, cdev);
return thermal_zone_bind_cooling_device(thermal, 0, cdev,
THERMAL_NO_LIMIT,
THERMAL_NO_LIMIT);
}
/* Unbind callback functions for thermal zone */
@@ -268,7 +270,6 @@ int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
/* Create thermal zone */
data->omap_thermal = thermal_zone_device_register(domain,
OMAP_TRIP_NUMBER, 0, data, &omap_thermal_ops,
1, 2, /*TODO: remove this when FW allows */
FAST_TEMP_MONITORING_RATE,
FAST_TEMP_MONITORING_RATE);
if (IS_ERR_OR_NULL(data->omap_thermal)) {
+26
View File
@@ -19,6 +19,17 @@ config THERMAL_HWMON
depends on HWMON=y || HWMON=THERMAL
default y
config CPU_THERMAL
bool "generic cpu cooling support"
depends on THERMAL && CPU_FREQ
help
This implements the generic cpu cooling mechanism through frequency
reduction, cpu hotplug and any other ways of reducing temperature. An
ACPI version of this already exists(drivers/acpi/processor_thermal.c).
This will be useful for platforms using the generic thermal interface
and not the ACPI interface.
If you want this support, you should say Y here.
config SPEAR_THERMAL
bool "SPEAr thermal sensor driver"
depends on THERMAL
@@ -27,3 +38,18 @@ config SPEAR_THERMAL
help
Enable this to plug the SPEAr thermal sensor driver into the Linux
thermal framework
config RCAR_THERMAL
tristate "Renesas R-Car thermal driver"
depends on THERMAL
depends on ARCH_SHMOBILE
help
Enable this to plug the R-Car thermal sensor driver into the Linux
thermal framework
config EXYNOS_THERMAL
tristate "Temperature sensor on Samsung EXYNOS"
depends on (ARCH_EXYNOS4 || ARCH_EXYNOS5) && THERMAL
help
If you say yes here you get support for TMU (Thermal Managment
Unit) on SAMSUNG EXYNOS series of SoC.
+4 -1
View File
@@ -3,4 +3,7 @@
#
obj-$(CONFIG_THERMAL) += thermal_sys.o
obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o
obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o
obj-$(CONFIG_EXYNOS_THERMAL) += exynos_thermal.o
+449
View File
@@ -0,0 +1,449 @@
/*
* linux/drivers/thermal/cpu_cooling.c
*
* Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
* Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 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 of the License.
*
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <linux/cpufreq.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/cpu.h>
#include <linux/cpu_cooling.h>
/**
* struct cpufreq_cooling_device
* @id: unique integer value corresponding to each cpufreq_cooling_device
* registered.
* @cool_dev: thermal_cooling_device pointer to keep track of the the
* egistered cooling device.
* @cpufreq_state: integer value representing the current state of cpufreq
* cooling devices.
* @cpufreq_val: integer value representing the absolute value of the clipped
* frequency.
* @allowed_cpus: all the cpus involved for this cpufreq_cooling_device.
* @node: list_head to link all cpufreq_cooling_device together.
*
* This structure is required for keeping information of each
* cpufreq_cooling_device registered as a list whose head is represented by
* cooling_cpufreq_list. In order to prevent corruption of this list a
* mutex lock cooling_cpufreq_lock is used.
*/
struct cpufreq_cooling_device {
int id;
struct thermal_cooling_device *cool_dev;
unsigned int cpufreq_state;
unsigned int cpufreq_val;
struct cpumask allowed_cpus;
struct list_head node;
};
static LIST_HEAD(cooling_cpufreq_list);
static DEFINE_IDR(cpufreq_idr);
static struct mutex cooling_cpufreq_lock;
/* notify_table passes value to the CPUFREQ_ADJUST callback function. */
#define NOTIFY_INVALID NULL
struct cpufreq_cooling_device *notify_device;
/**
* get_idr - function to get a unique id.
* @idr: struct idr * handle used to create a id.
* @id: int * value generated by this function.
*/
static int get_idr(struct idr *idr, int *id)
{
int err;
again:
if (unlikely(idr_pre_get(idr, GFP_KERNEL) == 0))
return -ENOMEM;
mutex_lock(&cooling_cpufreq_lock);
err = idr_get_new(idr, NULL, id);
mutex_unlock(&cooling_cpufreq_lock);
if (unlikely(err == -EAGAIN))
goto again;
else if (unlikely(err))
return err;
*id = *id & MAX_IDR_MASK;
return 0;
}
/**
* release_idr - function to free the unique id.
* @idr: struct idr * handle used for creating the id.
* @id: int value representing the unique id.
*/
static void release_idr(struct idr *idr, int id)
{
mutex_lock(&cooling_cpufreq_lock);
idr_remove(idr, id);
mutex_unlock(&cooling_cpufreq_lock);
}
/* Below code defines functions to be used for cpufreq as cooling device */
/**
* is_cpufreq_valid - function to check if a cpu has frequency transition policy.
* @cpu: cpu for which check is needed.
*/
static int is_cpufreq_valid(int cpu)
{
struct cpufreq_policy policy;
return !cpufreq_get_policy(&policy, cpu);
}
/**
* get_cpu_frequency - get the absolute value of frequency from level.
* @cpu: cpu for which frequency is fetched.
* @level: level of frequency of the CPU
* e.g level=1 --> 1st MAX FREQ, LEVEL=2 ---> 2nd MAX FREQ, .... etc
*/
static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level)
{
int ret = 0, i = 0;
unsigned long level_index;
bool descend = false;
struct cpufreq_frequency_table *table =
cpufreq_frequency_get_table(cpu);
if (!table)
return ret;
while (table[i].frequency != CPUFREQ_TABLE_END) {
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
continue;
/*check if table in ascending or descending order*/
if ((table[i + 1].frequency != CPUFREQ_TABLE_END) &&
(table[i + 1].frequency < table[i].frequency)
&& !descend) {
descend = true;
}
/*return if level matched and table in descending order*/
if (descend && i == level)
return table[i].frequency;
i++;
}
i--;
if (level > i || descend)
return ret;
level_index = i - level;
/*Scan the table in reverse order and match the level*/
while (i >= 0) {
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
continue;
/*return if level matched*/
if (i == level_index)
return table[i].frequency;
i--;
}
return ret;
}
/**
* cpufreq_apply_cooling - function to apply frequency clipping.
* @cpufreq_device: cpufreq_cooling_device pointer containing frequency
* clipping data.
* @cooling_state: value of the cooling state.
*/
static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device,
unsigned long cooling_state)
{
unsigned int cpuid, clip_freq;
struct cpumask *maskPtr = &cpufreq_device->allowed_cpus;
unsigned int cpu = cpumask_any(maskPtr);
/* Check if the old cooling action is same as new cooling action */
if (cpufreq_device->cpufreq_state == cooling_state)
return 0;
clip_freq = get_cpu_frequency(cpu, cooling_state);
if (!clip_freq)
return -EINVAL;
cpufreq_device->cpufreq_state = cooling_state;
cpufreq_device->cpufreq_val = clip_freq;
notify_device = cpufreq_device;
for_each_cpu(cpuid, maskPtr) {
if (is_cpufreq_valid(cpuid))
cpufreq_update_policy(cpuid);
}
notify_device = NOTIFY_INVALID;
return 0;
}
/**
* cpufreq_thermal_notifier - notifier callback for cpufreq policy change.
* @nb: struct notifier_block * with callback info.
* @event: value showing cpufreq event for which this function invoked.
* @data: callback-specific data
*/
static int cpufreq_thermal_notifier(struct notifier_block *nb,
unsigned long event, void *data)
{
struct cpufreq_policy *policy = data;
unsigned long max_freq = 0;
if (event != CPUFREQ_ADJUST || notify_device == NOTIFY_INVALID)
return 0;
if (cpumask_test_cpu(policy->cpu, &notify_device->allowed_cpus))
max_freq = notify_device->cpufreq_val;
/* Never exceed user_policy.max*/
if (max_freq > policy->user_policy.max)
max_freq = policy->user_policy.max;
if (policy->max != max_freq)
cpufreq_verify_within_limits(policy, 0, max_freq);
return 0;
}
/*
* cpufreq cooling device callback functions are defined below
*/
/**
* cpufreq_get_max_state - callback function to get the max cooling state.
* @cdev: thermal cooling device pointer.
* @state: fill this variable with the max cooling state.
*/
static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
int ret = -EINVAL, i = 0;
struct cpufreq_cooling_device *cpufreq_device;
struct cpumask *maskPtr;
unsigned int cpu;
struct cpufreq_frequency_table *table;
mutex_lock(&cooling_cpufreq_lock);
list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) {
if (cpufreq_device && cpufreq_device->cool_dev == cdev)
break;
}
if (cpufreq_device == NULL)
goto return_get_max_state;
maskPtr = &cpufreq_device->allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
if (!table) {
*state = 0;
ret = 0;
goto return_get_max_state;
}
while (table[i].frequency != CPUFREQ_TABLE_END) {
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
continue;
i++;
}
if (i > 0) {
*state = --i;
ret = 0;
}
return_get_max_state:
mutex_unlock(&cooling_cpufreq_lock);
return ret;
}
/**
* cpufreq_get_cur_state - callback function to get the current cooling state.
* @cdev: thermal cooling device pointer.
* @state: fill this variable with the current cooling state.
*/
static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
int ret = -EINVAL;
struct cpufreq_cooling_device *cpufreq_device;
mutex_lock(&cooling_cpufreq_lock);
list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) {
if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
*state = cpufreq_device->cpufreq_state;
ret = 0;
break;
}
}
mutex_unlock(&cooling_cpufreq_lock);
return ret;
}
/**
* cpufreq_set_cur_state - callback function to set the current cooling state.
* @cdev: thermal cooling device pointer.
* @state: set this variable to the current cooling state.
*/
static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
{
int ret = -EINVAL;
struct cpufreq_cooling_device *cpufreq_device;
mutex_lock(&cooling_cpufreq_lock);
list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) {
if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
ret = 0;
break;
}
}
if (!ret)
ret = cpufreq_apply_cooling(cpufreq_device, state);
mutex_unlock(&cooling_cpufreq_lock);
return ret;
}
/* Bind cpufreq callbacks to thermal cooling device ops */
static struct thermal_cooling_device_ops const cpufreq_cooling_ops = {
.get_max_state = cpufreq_get_max_state,
.get_cur_state = cpufreq_get_cur_state,
.set_cur_state = cpufreq_set_cur_state,
};
/* Notifier for cpufreq policy change */
static struct notifier_block thermal_cpufreq_notifier_block = {
.notifier_call = cpufreq_thermal_notifier,
};
/**
* cpufreq_cooling_register - function to create cpufreq cooling device.
* @clip_cpus: cpumask of cpus where the frequency constraints will happen.
*/
struct thermal_cooling_device *cpufreq_cooling_register(
struct cpumask *clip_cpus)
{
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node)
cpufreq_dev_count++;
/*Verify that all the clip cpus have same freq_min, freq_max limit*/
for_each_cpu(i, clip_cpus) {
/*continue if cpufreq policy not found and not return error*/
if (!cpufreq_get_policy(&policy, i))
continue;
if (min == 0 && max == 0) {
min = policy.cpuinfo.min_freq;
max = policy.cpuinfo.max_freq;
} else {
if (min != policy.cpuinfo.min_freq ||
max != policy.cpuinfo.max_freq)
return ERR_PTR(-EINVAL);
}
}
cpufreq_dev = kzalloc(sizeof(struct cpufreq_cooling_device),
GFP_KERNEL);
if (!cpufreq_dev)
return ERR_PTR(-ENOMEM);
cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus);
if (cpufreq_dev_count == 0)
mutex_init(&cooling_cpufreq_lock);
ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
if (ret) {
kfree(cpufreq_dev);
return ERR_PTR(-EINVAL);
}
sprintf(dev_name, "thermal-cpufreq-%d", cpufreq_dev->id);
cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev,
&cpufreq_cooling_ops);
if (!cool_dev) {
release_idr(&cpufreq_idr, cpufreq_dev->id);
kfree(cpufreq_dev);
return ERR_PTR(-EINVAL);
}
cpufreq_dev->cool_dev = cool_dev;
cpufreq_dev->cpufreq_state = 0;
mutex_lock(&cooling_cpufreq_lock);
list_add_tail(&cpufreq_dev->node, &cooling_cpufreq_list);
/* Register the notifier for first cpufreq cooling device */
if (cpufreq_dev_count == 0)
cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER);
mutex_unlock(&cooling_cpufreq_lock);
return cool_dev;
}
EXPORT_SYMBOL(cpufreq_cooling_register);
/**
* cpufreq_cooling_unregister - function to remove cpufreq cooling device.
* @cdev: thermal cooling device pointer.
*/
void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
{
struct cpufreq_cooling_device *cpufreq_dev = NULL;
unsigned int cpufreq_dev_count = 0;
mutex_lock(&cooling_cpufreq_lock);
list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node) {
if (cpufreq_dev && cpufreq_dev->cool_dev == cdev)
break;
cpufreq_dev_count++;
}
if (!cpufreq_dev || cpufreq_dev->cool_dev != cdev) {
mutex_unlock(&cooling_cpufreq_lock);
return;
}
list_del(&cpufreq_dev->node);
/* Unregister the notifier for the last cpufreq cooling device */
if (cpufreq_dev_count == 1) {
cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER);
}
mutex_unlock(&cooling_cpufreq_lock);
thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
release_idr(&cpufreq_idr, cpufreq_dev->id);
if (cpufreq_dev_count == 1)
mutex_destroy(&cooling_cpufreq_lock);
kfree(cpufreq_dev);
}
EXPORT_SYMBOL(cpufreq_cooling_unregister);
File diff suppressed because it is too large Load Diff
+260
View File
@@ -0,0 +1,260 @@
/*
* R-Car THS/TSC thermal sensor driver
*
* Copyright (C) 2012 Renesas Solutions Corp.
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.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 of the License.
*
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/thermal.h>
#define THSCR 0x2c
#define THSSR 0x30
/* THSCR */
#define CPTAP 0xf
/* THSSR */
#define CTEMP 0x3f
struct rcar_thermal_priv {
void __iomem *base;
struct device *dev;
spinlock_t lock;
u32 comp;
};
/*
* basic functions
*/
static u32 rcar_thermal_read(struct rcar_thermal_priv *priv, u32 reg)
{
unsigned long flags;
u32 ret;
spin_lock_irqsave(&priv->lock, flags);
ret = ioread32(priv->base + reg);
spin_unlock_irqrestore(&priv->lock, flags);
return ret;
}
#if 0 /* no user at this point */
static void rcar_thermal_write(struct rcar_thermal_priv *priv,
u32 reg, u32 data)
{
unsigned long flags;
spin_lock_irqsave(&priv->lock, flags);
iowrite32(data, priv->base + reg);
spin_unlock_irqrestore(&priv->lock, flags);
}
#endif
static void rcar_thermal_bset(struct rcar_thermal_priv *priv, u32 reg,
u32 mask, u32 data)
{
unsigned long flags;
u32 val;
spin_lock_irqsave(&priv->lock, flags);
val = ioread32(priv->base + reg);
val &= ~mask;
val |= (data & mask);
iowrite32(val, priv->base + reg);
spin_unlock_irqrestore(&priv->lock, flags);
}
/*
* zone device functions
*/
static int rcar_thermal_get_temp(struct thermal_zone_device *zone,
unsigned long *temp)
{
struct rcar_thermal_priv *priv = zone->devdata;
int val, min, max, tmp;
tmp = -200; /* default */
while (1) {
if (priv->comp < 1 || priv->comp > 12) {
dev_err(priv->dev,
"THSSR invalid data (%d)\n", priv->comp);
priv->comp = 4; /* for next thermal */
return -EINVAL;
}
/*
* THS comparator offset and the reference temperature
*
* Comparator | reference | Temperature field
* offset | temperature | measurement
* | (degrees C) | (degrees C)
* -------------+---------------+-------------------
* 1 | -45 | -45 to -30
* 2 | -30 | -30 to -15
* 3 | -15 | -15 to 0
* 4 | 0 | 0 to +15
* 5 | +15 | +15 to +30
* 6 | +30 | +30 to +45
* 7 | +45 | +45 to +60
* 8 | +60 | +60 to +75
* 9 | +75 | +75 to +90
* 10 | +90 | +90 to +105
* 11 | +105 | +105 to +120
* 12 | +120 | +120 to +135
*/
/* calculate thermal limitation */
min = (priv->comp * 15) - 60;
max = min + 15;
/*
* we need to wait 300us after changing comparator offset
* to get stable temperature.
* see "Usage Notes" on datasheet
*/
rcar_thermal_bset(priv, THSCR, CPTAP, priv->comp);
udelay(300);
/* calculate current temperature */
val = rcar_thermal_read(priv, THSSR) & CTEMP;
val = (val * 5) - 65;
dev_dbg(priv->dev, "comp/min/max/val = %d/%d/%d/%d\n",
priv->comp, min, max, val);
/*
* If val is same as min/max, then,
* it should try again on next comparator.
* But the val might be correct temperature.
* Keep it on "tmp" and compare with next val.
*/
if (tmp == val)
break;
if (val <= min) {
tmp = min;
priv->comp--; /* try again */
} else if (val >= max) {
tmp = max;
priv->comp++; /* try again */
} else {
tmp = val;
break;
}
}
*temp = tmp;
return 0;
}
static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
.get_temp = rcar_thermal_get_temp,
};
/*
* platform functions
*/
static int rcar_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *zone;
struct rcar_thermal_priv *priv;
struct resource *res;
int ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "Could not get platform resource\n");
return -ENODEV;
}
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) {
dev_err(&pdev->dev, "Could not allocate priv\n");
return -ENOMEM;
}
priv->comp = 4; /* basic setup */
priv->dev = &pdev->dev;
spin_lock_init(&priv->lock);
priv->base = devm_ioremap_nocache(&pdev->dev,
res->start, resource_size(res));
if (!priv->base) {
dev_err(&pdev->dev, "Unable to ioremap thermal register\n");
ret = -ENOMEM;
goto error_free_priv;
}
zone = thermal_zone_device_register("rcar_thermal", 0, priv,
&rcar_thermal_zone_ops, 0, 0);
if (IS_ERR(zone)) {
dev_err(&pdev->dev, "thermal zone device is NULL\n");
ret = PTR_ERR(zone);
goto error_iounmap;
}
platform_set_drvdata(pdev, zone);
dev_info(&pdev->dev, "proved\n");
return 0;
error_iounmap:
devm_iounmap(&pdev->dev, priv->base);
error_free_priv:
devm_kfree(&pdev->dev, priv);
return ret;
}
static int rcar_thermal_remove(struct platform_device *pdev)
{
struct thermal_zone_device *zone = platform_get_drvdata(pdev);
struct rcar_thermal_priv *priv = zone->devdata;
thermal_zone_device_unregister(zone);
platform_set_drvdata(pdev, NULL);
devm_iounmap(&pdev->dev, priv->base);
devm_kfree(&pdev->dev, priv);
return 0;
}
static struct platform_driver rcar_thermal_driver = {
.driver = {
.name = "rcar_thermal",
},
.probe = rcar_thermal_probe,
.remove = rcar_thermal_remove,
};
module_platform_driver(rcar_thermal_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("R-Car THS/TSC thermal sensor driver");
MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
+1 -1
View File
@@ -147,7 +147,7 @@ static int spear_thermal_probe(struct platform_device *pdev)
writel_relaxed(stdev->flags, stdev->thermal_base);
spear_thermal = thermal_zone_device_register("spear_thermal", 0, 0,
stdev, &ops, 0, 0, 0, 0);
stdev, &ops, 0, 0);
if (IS_ERR(spear_thermal)) {
dev_err(&pdev->dev, "thermal zone device is NULL\n");
ret = PTR_ERR(spear_thermal);

Some files were not shown because too many files have changed in this diff Show More