Commit 32c9edc4 authored by Zhang Rui's avatar Zhang Rui

Merge branch 'fixes' of...

Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal into thermal-soc
parents 59c56eb6 503ccc3f
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com) * Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
* Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org> * Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org>
* *
* Copyright (C) 2014 Viresh Kumar <viresh.kumar@linaro.org>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -28,6 +30,20 @@ ...@@ -28,6 +30,20 @@
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/cpu_cooling.h> #include <linux/cpu_cooling.h>
/*
* Cooling state <-> CPUFreq frequency
*
* Cooling states are translated to frequencies throughout this driver and this
* is the relation between them.
*
* Highest cooling state corresponds to lowest possible frequency.
*
* i.e.
* level 0 --> 1st Max Freq
* level 1 --> 2nd Max Freq
* ...
*/
/** /**
* struct cpufreq_cooling_device - data for cooling device with cpufreq * struct cpufreq_cooling_device - data for cooling device with cpufreq
* @id: unique integer value corresponding to each cpufreq_cooling_device * @id: unique integer value corresponding to each cpufreq_cooling_device
...@@ -38,25 +54,26 @@ ...@@ -38,25 +54,26 @@
* cooling devices. * cooling devices.
* @cpufreq_val: integer value representing the absolute value of the clipped * @cpufreq_val: integer value representing the absolute value of the clipped
* frequency. * frequency.
* @max_level: maximum cooling level. One less than total number of valid
* cpufreq frequencies.
* @allowed_cpus: all the cpus involved for this cpufreq_cooling_device. * @allowed_cpus: all the cpus involved for this cpufreq_cooling_device.
* *
* This structure is required for keeping information of each * This structure is required for keeping information of each registered
* cpufreq_cooling_device registered. In order to prevent corruption of this a * cpufreq_cooling_device.
* mutex lock cooling_cpufreq_lock is used.
*/ */
struct cpufreq_cooling_device { struct cpufreq_cooling_device {
int id; int id;
struct thermal_cooling_device *cool_dev; struct thermal_cooling_device *cool_dev;
unsigned int cpufreq_state; unsigned int cpufreq_state;
unsigned int cpufreq_val; unsigned int cpufreq_val;
unsigned int max_level;
unsigned int *freq_table; /* In descending order */
struct cpumask allowed_cpus; struct cpumask allowed_cpus;
struct list_head node; struct list_head node;
}; };
static DEFINE_IDR(cpufreq_idr); static DEFINE_IDR(cpufreq_idr);
static DEFINE_MUTEX(cooling_cpufreq_lock); static DEFINE_MUTEX(cooling_cpufreq_lock);
static unsigned int cpufreq_dev_count;
static LIST_HEAD(cpufreq_dev_list); static LIST_HEAD(cpufreq_dev_list);
/** /**
...@@ -98,120 +115,30 @@ static void release_idr(struct idr *idr, int id) ...@@ -98,120 +115,30 @@ static void release_idr(struct idr *idr, int id)
/* Below code defines functions to be used for cpufreq as cooling device */ /* Below code defines functions to be used for cpufreq as cooling device */
/** /**
* is_cpufreq_valid - function to check frequency transitioning capability. * get_level: Find the level for a particular frequency
* @cpu: cpu for which check is needed. * @cpufreq_dev: cpufreq_dev for which the property is required
* @freq: Frequency
* *
* This function will check the current state of the system if * Return: level on success, THERMAL_CSTATE_INVALID on error.
* it is capable of changing the frequency for a given @cpu.
*
* Return: 0 if the system is not currently capable of changing
* the frequency of given cpu. !0 in case the frequency is changeable.
*/ */
static int is_cpufreq_valid(int cpu) static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev,
unsigned int freq)
{ {
struct cpufreq_policy policy; unsigned long level;
return !cpufreq_get_policy(&policy, cpu);
}
enum cpufreq_cooling_property {
GET_LEVEL,
GET_FREQ,
GET_MAXL,
};
/**
* get_property - fetch a property of interest for a give cpu.
* @cpu: cpu for which the property is required
* @input: query parameter
* @output: query return
* @property: type of query (frequency, level, max level)
*
* This is the common function to
* 1. get maximum cpu cooling states
* 2. translate frequency to cooling state
* 3. translate cooling state to frequency
* Note that the code may be not in good shape
* but it is written in this way in order to:
* a) reduce duplicate code as most of the code can be shared.
* b) make sure the logic is consistent when translating between
* cooling states and frequencies.
*
* Return: 0 on success, -EINVAL when invalid parameters are passed.
*/
static int get_property(unsigned int cpu, unsigned long input,
unsigned int *output,
enum cpufreq_cooling_property property)
{
int i;
unsigned long max_level = 0, level = 0;
unsigned int freq = CPUFREQ_ENTRY_INVALID;
int descend = -1;
struct cpufreq_frequency_table *pos, *table =
cpufreq_frequency_get_table(cpu);
if (!output)
return -EINVAL;
if (!table)
return -EINVAL;
cpufreq_for_each_valid_entry(pos, table) {
/* ignore duplicate entry */
if (freq == pos->frequency)
continue;
/* get the frequency order */
if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)
descend = freq > pos->frequency;
freq = pos->frequency;
max_level++;
}
/* No valid cpu frequency entry */
if (max_level == 0)
return -EINVAL;
/* max_level is an index, not a counter */ for (level = 0; level <= cpufreq_dev->max_level; level++) {
max_level--; if (freq == cpufreq_dev->freq_table[level])
return level;
/* get max level */ if (freq > cpufreq_dev->freq_table[level])
if (property == GET_MAXL) { break;
*output = (unsigned int)max_level;
return 0;
} }
if (property == GET_FREQ) return THERMAL_CSTATE_INVALID;
level = descend ? input : (max_level - input);
i = 0;
cpufreq_for_each_valid_entry(pos, table) {
/* ignore duplicate entry */
if (freq == pos->frequency)
continue;
/* now we have a valid frequency entry */
freq = pos->frequency;
if (property == GET_LEVEL && (unsigned int)input == freq) {
/* get level by frequency */
*output = descend ? i : (max_level - i);
return 0;
}
if (property == GET_FREQ && level == i) {
/* get frequency by level */
*output = freq;
return 0;
}
i++;
}
return -EINVAL;
} }
/** /**
* cpufreq_cooling_get_level - for a give cpu, return the cooling level. * cpufreq_cooling_get_level - for a given cpu, return the cooling level.
* @cpu: cpu for which the level is required * @cpu: cpu for which the level is required
* @freq: the frequency of interest * @freq: the frequency of interest
* *
...@@ -223,77 +150,21 @@ static int get_property(unsigned int cpu, unsigned long input, ...@@ -223,77 +150,21 @@ static int get_property(unsigned int cpu, unsigned long input,
*/ */
unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
{ {
unsigned int val; struct cpufreq_cooling_device *cpufreq_dev;
if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL))
return THERMAL_CSTATE_INVALID;
return (unsigned long)val;
}
EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level);
/**
* get_cpu_frequency - get the absolute value of frequency from level.
* @cpu: cpu for which frequency is fetched.
* @level: cooling level
*
* This function matches cooling level with frequency. Based on a cooling level
* of frequency, equals cooling state of cpu cooling device, it will return
* the corresponding frequency.
* e.g level=0 --> 1st MAX FREQ, level=1 ---> 2nd MAX FREQ, .... etc
*
* Return: 0 on error, the corresponding frequency otherwise.
*/
static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level)
{
int ret = 0;
unsigned int freq;
ret = get_property(cpu, level, &freq, GET_FREQ);
if (ret)
return 0;
return freq;
}
/**
* 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.
*
* Function used to make sure the cpufreq layer is aware of current thermal
* limits. The limits are applied by updating the cpufreq policy.
*
* Return: 0 on success, an error code otherwise (-EINVAL in case wrong
* cooling state).
*/
static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device,
unsigned long cooling_state)
{
unsigned int cpuid, clip_freq;
struct cpumask *mask = &cpufreq_device->allowed_cpus;
unsigned int cpu = cpumask_any(mask);
/* 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;
for_each_cpu(cpuid, mask) { mutex_lock(&cooling_cpufreq_lock);
if (is_cpufreq_valid(cpuid)) list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) {
cpufreq_update_policy(cpuid); if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) {
mutex_unlock(&cooling_cpufreq_lock);
return get_level(cpufreq_dev, freq);
}
} }
mutex_unlock(&cooling_cpufreq_lock);
return 0; pr_err("%s: cpu:%d not part of any cooling device\n", __func__, cpu);
return THERMAL_CSTATE_INVALID;
} }
EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level);
/** /**
* cpufreq_thermal_notifier - notifier callback for cpufreq policy change. * cpufreq_thermal_notifier - notifier callback for cpufreq policy change.
...@@ -323,11 +194,6 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, ...@@ -323,11 +194,6 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
&cpufreq_dev->allowed_cpus)) &cpufreq_dev->allowed_cpus))
continue; continue;
if (!cpufreq_dev->cpufreq_val)
cpufreq_dev->cpufreq_val = get_cpu_frequency(
cpumask_any(&cpufreq_dev->allowed_cpus),
cpufreq_dev->cpufreq_state);
max_freq = cpufreq_dev->cpufreq_val; max_freq = cpufreq_dev->cpufreq_val;
if (policy->max != max_freq) if (policy->max != max_freq)
...@@ -354,19 +220,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, ...@@ -354,19 +220,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state) unsigned long *state)
{ {
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
struct cpumask *mask = &cpufreq_device->allowed_cpus;
unsigned int cpu;
unsigned int count = 0;
int ret;
cpu = cpumask_any(mask);
ret = get_property(cpu, 0, &count, GET_MAXL);
if (count > 0) *state = cpufreq_device->max_level;
*state = count; return 0;
return ret;
} }
/** /**
...@@ -403,8 +259,24 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, ...@@ -403,8 +259,24 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state) unsigned long state)
{ {
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
unsigned int cpu = cpumask_any(&cpufreq_device->allowed_cpus);
unsigned int clip_freq;
/* Request state should be less than max_level */
if (WARN_ON(state > cpufreq_device->max_level))
return -EINVAL;
/* Check if the old cooling action is same as new cooling action */
if (cpufreq_device->cpufreq_state == state)
return 0;
return cpufreq_apply_cooling(cpufreq_device, state); clip_freq = cpufreq_device->freq_table[state];
cpufreq_device->cpufreq_state = state;
cpufreq_device->cpufreq_val = clip_freq;
cpufreq_update_policy(cpu);
return 0;
} }
/* Bind cpufreq callbacks to thermal cooling device ops */ /* Bind cpufreq callbacks to thermal cooling device ops */
...@@ -419,10 +291,25 @@ static struct notifier_block thermal_cpufreq_notifier_block = { ...@@ -419,10 +291,25 @@ static struct notifier_block thermal_cpufreq_notifier_block = {
.notifier_call = cpufreq_thermal_notifier, .notifier_call = cpufreq_thermal_notifier,
}; };
static unsigned int find_next_max(struct cpufreq_frequency_table *table,
unsigned int prev_max)
{
struct cpufreq_frequency_table *pos;
unsigned int max = 0;
cpufreq_for_each_valid_entry(pos, table) {
if (pos->frequency > max && pos->frequency < prev_max)
max = pos->frequency;
}
return max;
}
/** /**
* __cpufreq_cooling_register - helper function to create cpufreq cooling device * __cpufreq_cooling_register - helper function to create cpufreq cooling device
* @np: a valid struct device_node to the cooling device device tree node * @np: a valid struct device_node to the cooling device device tree node
* @clip_cpus: cpumask of cpus where the frequency constraints will happen. * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
* Normally this should be same as cpufreq policy->related_cpus.
* *
* This interface function registers the cpufreq cooling device with the name * This interface function registers the cpufreq cooling device with the name
* "thermal-cpufreq-%x". This api can support multiple instances of cpufreq * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
...@@ -437,37 +324,42 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -437,37 +324,42 @@ __cpufreq_cooling_register(struct device_node *np,
const struct cpumask *clip_cpus) const struct cpumask *clip_cpus)
{ {
struct thermal_cooling_device *cool_dev; struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL; struct cpufreq_cooling_device *cpufreq_dev;
unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH]; char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i; struct cpufreq_frequency_table *pos, *table;
struct cpufreq_policy policy; unsigned int freq, i;
int ret;
/* Verify that all the clip cpus have same freq_min, freq_max limit */ table = cpufreq_frequency_get_table(cpumask_first(clip_cpus));
for_each_cpu(i, clip_cpus) { if (!table) {
/* continue if cpufreq policy not found and not return error */ pr_debug("%s: CPUFreq table not found\n", __func__);
if (!cpufreq_get_policy(&policy, i)) return ERR_PTR(-EPROBE_DEFER);
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); cpufreq_dev = kzalloc(sizeof(*cpufreq_dev), GFP_KERNEL);
if (!cpufreq_dev) if (!cpufreq_dev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
/* Find max levels */
cpufreq_for_each_valid_entry(pos, table)
cpufreq_dev->max_level++;
cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) *
cpufreq_dev->max_level, GFP_KERNEL);
if (!cpufreq_dev->freq_table) {
cool_dev = ERR_PTR(-ENOMEM);
goto free_cdev;
}
/* max_level is an index, not a counter */
cpufreq_dev->max_level--;
cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus);
ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
if (ret) { if (ret) {
kfree(cpufreq_dev); cool_dev = ERR_PTR(ret);
return ERR_PTR(-EINVAL); goto free_table;
} }
snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d",
...@@ -475,24 +367,43 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -475,24 +367,43 @@ __cpufreq_cooling_register(struct device_node *np,
cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
&cpufreq_cooling_ops); &cpufreq_cooling_ops);
if (IS_ERR(cool_dev)) { if (IS_ERR(cool_dev))
release_idr(&cpufreq_idr, cpufreq_dev->id); goto remove_idr;
kfree(cpufreq_dev);
return cool_dev; /* Fill freq-table in descending order of frequencies */
for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) {
freq = find_next_max(table, freq);
cpufreq_dev->freq_table[i] = freq;
/* Warn for duplicate entries */
if (!freq)
pr_warn("%s: table has duplicate entries\n", __func__);
else
pr_debug("%s: freq:%u KHz\n", __func__, freq);
} }
cpufreq_dev->cpufreq_val = cpufreq_dev->freq_table[0];
cpufreq_dev->cool_dev = cool_dev; cpufreq_dev->cool_dev = cool_dev;
cpufreq_dev->cpufreq_state = 0;
mutex_lock(&cooling_cpufreq_lock); mutex_lock(&cooling_cpufreq_lock);
/* Register the notifier for first cpufreq cooling device */ /* Register the notifier for first cpufreq cooling device */
if (cpufreq_dev_count == 0) if (list_empty(&cpufreq_dev_list))
cpufreq_register_notifier(&thermal_cpufreq_notifier_block, cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER); CPUFREQ_POLICY_NOTIFIER);
cpufreq_dev_count++;
list_add(&cpufreq_dev->node, &cpufreq_dev_list); list_add(&cpufreq_dev->node, &cpufreq_dev_list);
mutex_unlock(&cooling_cpufreq_lock); mutex_unlock(&cooling_cpufreq_lock);
return cool_dev;
remove_idr:
release_idr(&cpufreq_idr, cpufreq_dev->id);
free_table:
kfree(cpufreq_dev->freq_table);
free_cdev:
kfree(cpufreq_dev);
return cool_dev; return cool_dev;
} }
...@@ -554,16 +465,16 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) ...@@ -554,16 +465,16 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
cpufreq_dev = cdev->devdata; cpufreq_dev = cdev->devdata;
mutex_lock(&cooling_cpufreq_lock); mutex_lock(&cooling_cpufreq_lock);
list_del(&cpufreq_dev->node); list_del(&cpufreq_dev->node);
cpufreq_dev_count--;
/* Unregister the notifier for the last cpufreq cooling device */ /* Unregister the notifier for the last cpufreq cooling device */
if (cpufreq_dev_count == 0) if (list_empty(&cpufreq_dev_list))
cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER); CPUFREQ_POLICY_NOTIFIER);
mutex_unlock(&cooling_cpufreq_lock); mutex_unlock(&cooling_cpufreq_lock);
thermal_cooling_device_unregister(cpufreq_dev->cool_dev); thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
release_idr(&cpufreq_idr, cpufreq_dev->id); release_idr(&cpufreq_idr, cpufreq_dev->id);
kfree(cpufreq_dev->freq_table);
kfree(cpufreq_dev); kfree(cpufreq_dev);
} }
EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister); EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister);
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
*/ */
#include <linux/cpu_cooling.h> #include <linux/cpu_cooling.h>
#include <linux/cpufreq.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
...@@ -28,18 +27,17 @@ ...@@ -28,18 +27,17 @@
static int db8500_cpufreq_cooling_probe(struct platform_device *pdev) static int db8500_cpufreq_cooling_probe(struct platform_device *pdev)
{ {
struct thermal_cooling_device *cdev; struct thermal_cooling_device *cdev;
struct cpumask mask_val;
/* make sure cpufreq driver has been initialized */
if (!cpufreq_frequency_get_table(0))
return -EPROBE_DEFER;
cpumask_set_cpu(0, &mask_val);
cdev = cpufreq_cooling_register(&mask_val);
cdev = cpufreq_cooling_register(cpu_present_mask);
if (IS_ERR(cdev)) { if (IS_ERR(cdev)) {
dev_err(&pdev->dev, "Failed to register cooling device\n"); int ret = PTR_ERR(cdev);
return PTR_ERR(cdev);
if (ret != -EPROBE_DEFER)
dev_err(&pdev->dev,
"Failed to register cooling device %d\n",
ret);
return ret;
} }
platform_set_drvdata(pdev, cdev); platform_set_drvdata(pdev, cdev);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/cpu_cooling.h> #include <linux/cpu_cooling.h>
#include <linux/cpufreq.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -454,15 +453,10 @@ static int imx_thermal_probe(struct platform_device *pdev) ...@@ -454,15 +453,10 @@ static int imx_thermal_probe(struct platform_device *pdev)
const struct of_device_id *of_id = const struct of_device_id *of_id =
of_match_device(of_imx_thermal_match, &pdev->dev); of_match_device(of_imx_thermal_match, &pdev->dev);
struct imx_thermal_data *data; struct imx_thermal_data *data;
struct cpumask clip_cpus;
struct regmap *map; struct regmap *map;
int measure_freq; int measure_freq;
int ret; int ret;
if (!cpufreq_get_current_driver()) {
dev_dbg(&pdev->dev, "no cpufreq driver!");
return -EPROBE_DEFER;
}
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -516,12 +510,13 @@ static int imx_thermal_probe(struct platform_device *pdev) ...@@ -516,12 +510,13 @@ static int imx_thermal_probe(struct platform_device *pdev)
regmap_write(map, MISC0 + REG_SET, MISC0_REFTOP_SELBIASOFF); regmap_write(map, MISC0 + REG_SET, MISC0_REFTOP_SELBIASOFF);
regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN);
cpumask_set_cpu(0, &clip_cpus); data->cdev = cpufreq_cooling_register(cpu_present_mask);
data->cdev = cpufreq_cooling_register(&clip_cpus);
if (IS_ERR(data->cdev)) { if (IS_ERR(data->cdev)) {
ret = PTR_ERR(data->cdev); ret = PTR_ERR(data->cdev);
dev_err(&pdev->dev, if (ret != -EPROBE_DEFER)
"failed to register cpufreq cooling device: %d\n", ret); dev_err(&pdev->dev,
"failed to register cpufreq cooling device: %d\n",
ret);
return ret; return ret;
} }
......
config EXYNOS_THERMAL config EXYNOS_THERMAL
tristate "Exynos thermal management unit driver" tristate "Exynos thermal management unit driver"
depends on ARCH_HAS_BANDGAP && OF depends on OF
help help
If you say yes here you get support for the TMU (Thermal Management If you say yes here you get support for the TMU (Thermal Management
Unit) driver for SAMSUNG EXYNOS series of SoCs. This driver initialises Unit) driver for SAMSUNG EXYNOS series of SoCs. This driver initialises
......
...@@ -347,7 +347,6 @@ void exynos_report_trigger(struct thermal_sensor_conf *conf) ...@@ -347,7 +347,6 @@ void exynos_report_trigger(struct thermal_sensor_conf *conf)
int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf) int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf)
{ {
int ret; int ret;
struct cpumask mask_val;
struct exynos_thermal_zone *th_zone; struct exynos_thermal_zone *th_zone;
if (!sensor_conf || !sensor_conf->read_temperature) { if (!sensor_conf || !sensor_conf->read_temperature) {
...@@ -367,13 +366,14 @@ int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf) ...@@ -367,13 +366,14 @@ int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf)
* sensor * sensor
*/ */
if (sensor_conf->cooling_data.freq_clip_count > 0) { if (sensor_conf->cooling_data.freq_clip_count > 0) {
cpumask_set_cpu(0, &mask_val);
th_zone->cool_dev[th_zone->cool_dev_size] = th_zone->cool_dev[th_zone->cool_dev_size] =
cpufreq_cooling_register(&mask_val); cpufreq_cooling_register(cpu_present_mask);
if (IS_ERR(th_zone->cool_dev[th_zone->cool_dev_size])) { if (IS_ERR(th_zone->cool_dev[th_zone->cool_dev_size])) {
dev_err(sensor_conf->dev, ret = PTR_ERR(th_zone->cool_dev[th_zone->cool_dev_size]);
"Failed to register cpufreq cooling device\n"); if (ret != -EPROBE_DEFER)
ret = -EINVAL; dev_err(sensor_conf->dev,
"Failed to register cpufreq cooling device: %d\n",
ret);
goto err_unregister; goto err_unregister;
} }
th_zone->cool_dev_size++; th_zone->cool_dev_size++;
......
...@@ -927,7 +927,10 @@ static int exynos_tmu_probe(struct platform_device *pdev) ...@@ -927,7 +927,10 @@ static int exynos_tmu_probe(struct platform_device *pdev)
/* Register the sensor with thermal management interface */ /* Register the sensor with thermal management interface */
ret = exynos_register_thermal(sensor_conf); ret = exynos_register_thermal(sensor_conf);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to register thermal interface\n"); if (ret != -EPROBE_DEFER)
dev_err(&pdev->dev,
"Failed to register thermal interface: %d\n",
ret);
goto err_clk; goto err_clk;
} }
data->reg_conf = sensor_conf; data->reg_conf = sensor_conf;
......
...@@ -930,7 +930,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, ...@@ -930,7 +930,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
struct thermal_zone_device *pos1; struct thermal_zone_device *pos1;
struct thermal_cooling_device *pos2; struct thermal_cooling_device *pos2;
unsigned long max_state; unsigned long max_state;
int result; int result, ret;
if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
return -EINVAL; return -EINVAL;
...@@ -947,7 +947,9 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, ...@@ -947,7 +947,9 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
if (tz != pos1 || cdev != pos2) if (tz != pos1 || cdev != pos2)
return -EINVAL; return -EINVAL;
cdev->ops->get_max_state(cdev, &max_state); ret = cdev->ops->get_max_state(cdev, &max_state);
if (ret)
return ret;
/* lower default 0, upper default max_state */ /* lower default 0, upper default max_state */
lower = lower == THERMAL_NO_LIMIT ? 0 : lower; lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/thermal.h> #include <linux/thermal.h>
#include <linux/cpufreq.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/cpu_cooling.h> #include <linux/cpu_cooling.h>
#include <linux/of.h> #include <linux/of.h>
...@@ -407,17 +406,17 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) ...@@ -407,17 +406,17 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
if (!data) if (!data)
return -EINVAL; return -EINVAL;
if (!cpufreq_get_current_driver()) {
dev_dbg(bgp->dev, "no cpufreq driver yet\n");
return -EPROBE_DEFER;
}
/* Register cooling device */ /* Register cooling device */
data->cool_dev = cpufreq_cooling_register(cpu_present_mask); data->cool_dev = cpufreq_cooling_register(cpu_present_mask);
if (IS_ERR(data->cool_dev)) { if (IS_ERR(data->cool_dev)) {
dev_err(bgp->dev, int ret = PTR_ERR(data->cool_dev);
"Failed to register cpufreq cooling device\n");
return PTR_ERR(data->cool_dev); if (ret != -EPROBE_DEFER)
dev_err(bgp->dev,
"Failed to register cpu cooling device %d\n",
ret);
return ret;
} }
ti_bandgap_set_sensor_data(bgp, id, data); ti_bandgap_set_sensor_data(bgp, id, data);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#define _DT_BINDINGS_THERMAL_THERMAL_H #define _DT_BINDINGS_THERMAL_THERMAL_H
/* On cooling devices upper and lower limits */ /* On cooling devices upper and lower limits */
#define THERMAL_NO_LIMIT (-1UL) #define THERMAL_NO_LIMIT (~0)
#endif #endif
...@@ -50,7 +50,7 @@ static inline struct thermal_cooling_device * ...@@ -50,7 +50,7 @@ static inline struct thermal_cooling_device *
of_cpufreq_cooling_register(struct device_node *np, of_cpufreq_cooling_register(struct device_node *np,
const struct cpumask *clip_cpus) const struct cpumask *clip_cpus)
{ {
return NULL; return ERR_PTR(-ENOSYS);
} }
#endif #endif
...@@ -65,13 +65,13 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq); ...@@ -65,13 +65,13 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq);
static inline struct thermal_cooling_device * static inline struct thermal_cooling_device *
cpufreq_cooling_register(const struct cpumask *clip_cpus) cpufreq_cooling_register(const struct cpumask *clip_cpus)
{ {
return NULL; return ERR_PTR(-ENOSYS);
} }
static inline struct thermal_cooling_device * static inline struct thermal_cooling_device *
of_cpufreq_cooling_register(struct device_node *np, of_cpufreq_cooling_register(struct device_node *np,
const struct cpumask *clip_cpus) const struct cpumask *clip_cpus)
{ {
return NULL; return ERR_PTR(-ENOSYS);
} }
static inline static inline
void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#define THERMAL_CSTATE_INVALID -1UL #define THERMAL_CSTATE_INVALID -1UL
/* No upper/lower limit requirement */ /* No upper/lower limit requirement */
#define THERMAL_NO_LIMIT THERMAL_CSTATE_INVALID #define THERMAL_NO_LIMIT ((u32)~0)
/* Unit conversion macros */ /* Unit conversion macros */
#define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \ #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \
......
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