Commit 0043ee40 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux

Pull thermal updates from Zhang Rui:

 - Fix a race condition when updating cooling device, which may lead to
   a situation where a thermal governor never updates the cooling
   device.  From Michele Di Giorgio.

 - Fix a zero division error when disabling the forced idle injection
   from the intel powerclamp.  From Petr Mladek.

 - Add suspend/resume callback for intel_pch_thermal thermal driver.
   From Srinivas Pandruvada.

 - Another two fixes for clocking cooling driver and hwmon sysfs I/F.
   From Michele Di Giorgio and Kuninori Morimoto.

[ Hmm.  That suspend/resume callback for intel_pch_thermal doesn't look
  like a fix, but I'm letting it slide..  - Linus ]

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux:
  thermal: clock_cooling: Fix missing mutex_init()
  thermal: hwmon: EXPORT_SYMBOL_GPL for thermal hwmon sysfs
  thermal: fix race condition when updating cooling device
  thermal/powerclamp: Prevent division by zero when counting interval
  thermal: intel_pch_thermal: Add suspend/resume callback
parents 4ef870e3 1577ddfa
...@@ -426,6 +426,7 @@ clock_cooling_register(struct device *dev, const char *clock_name) ...@@ -426,6 +426,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
if (!ccdev) if (!ccdev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
mutex_init(&ccdev->lock);
ccdev->dev = dev; ccdev->dev = dev;
ccdev->clk = devm_clk_get(dev, clock_name); ccdev->clk = devm_clk_get(dev, clock_name);
if (IS_ERR(ccdev->clk)) if (IS_ERR(ccdev->clk))
......
...@@ -116,7 +116,9 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip) ...@@ -116,7 +116,9 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
instance->target = get_target_state(tz, cdev, percentage, instance->target = get_target_state(tz, cdev, percentage,
cur_trip_level); cur_trip_level);
mutex_lock(&instance->cdev->lock);
instance->cdev->updated = false; instance->cdev->updated = false;
mutex_unlock(&instance->cdev->lock);
thermal_cdev_update(cdev); thermal_cdev_update(cdev);
} }
return 0; return 0;
......
...@@ -71,7 +71,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) ...@@ -71,7 +71,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
dev_dbg(&instance->cdev->device, "target=%d\n", dev_dbg(&instance->cdev->device, "target=%d\n",
(int)instance->target); (int)instance->target);
mutex_lock(&instance->cdev->lock);
instance->cdev->updated = false; /* cdev needs update */ instance->cdev->updated = false; /* cdev needs update */
mutex_unlock(&instance->cdev->lock);
} }
mutex_unlock(&tz->lock); mutex_unlock(&tz->lock);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/thermal.h> #include <linux/thermal.h>
#include <linux/pm.h>
/* Intel PCH thermal Device IDs */ /* Intel PCH thermal Device IDs */
#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ #define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
...@@ -65,6 +66,7 @@ struct pch_thermal_device { ...@@ -65,6 +66,7 @@ struct pch_thermal_device {
unsigned long crt_temp; unsigned long crt_temp;
int hot_trip_id; int hot_trip_id;
unsigned long hot_temp; unsigned long hot_temp;
bool bios_enabled;
}; };
static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
...@@ -75,8 +77,10 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) ...@@ -75,8 +77,10 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
*nr_trips = 0; *nr_trips = 0;
/* Check if BIOS has already enabled thermal sensor */ /* Check if BIOS has already enabled thermal sensor */
if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) {
ptd->bios_enabled = true;
goto read_trips; goto read_trips;
}
tsel = readb(ptd->hw_base + WPT_TSEL); tsel = readb(ptd->hw_base + WPT_TSEL);
/* /*
...@@ -130,9 +134,39 @@ static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp) ...@@ -130,9 +134,39 @@ static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp)
return 0; return 0;
} }
static int pch_wpt_suspend(struct pch_thermal_device *ptd)
{
u8 tsel;
if (ptd->bios_enabled)
return 0;
tsel = readb(ptd->hw_base + WPT_TSEL);
writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
return 0;
}
static int pch_wpt_resume(struct pch_thermal_device *ptd)
{
u8 tsel;
if (ptd->bios_enabled)
return 0;
tsel = readb(ptd->hw_base + WPT_TSEL);
writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
return 0;
}
struct pch_dev_ops { struct pch_dev_ops {
int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips); int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips);
int (*get_temp)(struct pch_thermal_device *ptd, int *temp); int (*get_temp)(struct pch_thermal_device *ptd, int *temp);
int (*suspend)(struct pch_thermal_device *ptd);
int (*resume)(struct pch_thermal_device *ptd);
}; };
...@@ -140,6 +174,8 @@ struct pch_dev_ops { ...@@ -140,6 +174,8 @@ struct pch_dev_ops {
static const struct pch_dev_ops pch_dev_ops_wpt = { static const struct pch_dev_ops pch_dev_ops_wpt = {
.hw_init = pch_wpt_init, .hw_init = pch_wpt_init,
.get_temp = pch_wpt_get_temp, .get_temp = pch_wpt_get_temp,
.suspend = pch_wpt_suspend,
.resume = pch_wpt_resume,
}; };
static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp) static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
...@@ -269,6 +305,22 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev) ...@@ -269,6 +305,22 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev)
pci_disable_device(pdev); pci_disable_device(pdev);
} }
static int intel_pch_thermal_suspend(struct device *device)
{
struct pci_dev *pdev = to_pci_dev(device);
struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
return ptd->ops->suspend(ptd);
}
static int intel_pch_thermal_resume(struct device *device)
{
struct pci_dev *pdev = to_pci_dev(device);
struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
return ptd->ops->resume(ptd);
}
static struct pci_device_id intel_pch_thermal_id[] = { static struct pci_device_id intel_pch_thermal_id[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) }, { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
...@@ -276,11 +328,17 @@ static struct pci_device_id intel_pch_thermal_id[] = { ...@@ -276,11 +328,17 @@ static struct pci_device_id intel_pch_thermal_id[] = {
}; };
MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id); MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
static const struct dev_pm_ops intel_pch_pm_ops = {
.suspend = intel_pch_thermal_suspend,
.resume = intel_pch_thermal_resume,
};
static struct pci_driver intel_pch_thermal_driver = { static struct pci_driver intel_pch_thermal_driver = {
.name = "intel_pch_thermal", .name = "intel_pch_thermal",
.id_table = intel_pch_thermal_id, .id_table = intel_pch_thermal_id,
.probe = intel_pch_thermal_probe, .probe = intel_pch_thermal_probe,
.remove = intel_pch_thermal_remove, .remove = intel_pch_thermal_remove,
.driver.pm = &intel_pch_pm_ops,
}; };
module_pci_driver(intel_pch_thermal_driver); module_pci_driver(intel_pch_thermal_driver);
......
...@@ -388,7 +388,7 @@ static int clamp_thread(void *arg) ...@@ -388,7 +388,7 @@ static int clamp_thread(void *arg)
int sleeptime; int sleeptime;
unsigned long target_jiffies; unsigned long target_jiffies;
unsigned int guard; unsigned int guard;
unsigned int compensation = 0; unsigned int compensated_ratio;
int interval; /* jiffies to sleep for each attempt */ int interval; /* jiffies to sleep for each attempt */
unsigned int duration_jiffies = msecs_to_jiffies(duration); unsigned int duration_jiffies = msecs_to_jiffies(duration);
unsigned int window_size_now; unsigned int window_size_now;
...@@ -409,8 +409,11 @@ static int clamp_thread(void *arg) ...@@ -409,8 +409,11 @@ static int clamp_thread(void *arg)
* c-states, thus we need to compensate the injected idle ratio * c-states, thus we need to compensate the injected idle ratio
* to achieve the actual target reported by the HW. * to achieve the actual target reported by the HW.
*/ */
compensation = get_compensation(target_ratio); compensated_ratio = target_ratio +
interval = duration_jiffies*100/(target_ratio+compensation); get_compensation(target_ratio);
if (compensated_ratio <= 0)
compensated_ratio = 1;
interval = duration_jiffies * 100 / compensated_ratio;
/* align idle time */ /* align idle time */
target_jiffies = roundup(jiffies, interval); target_jiffies = roundup(jiffies, interval);
...@@ -647,8 +650,8 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev, ...@@ -647,8 +650,8 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
goto exit_set; goto exit_set;
} else if (set_target_ratio > 0 && new_target_ratio == 0) { } else if (set_target_ratio > 0 && new_target_ratio == 0) {
pr_info("Stop forced idle injection\n"); pr_info("Stop forced idle injection\n");
set_target_ratio = 0;
end_power_clamp(); end_power_clamp();
set_target_ratio = 0;
} else /* adjust currently running */ { } else /* adjust currently running */ {
set_target_ratio = new_target_ratio; set_target_ratio = new_target_ratio;
/* make new set_target_ratio visible to other cpus */ /* make new set_target_ratio visible to other cpus */
......
...@@ -529,7 +529,9 @@ static void allow_maximum_power(struct thermal_zone_device *tz) ...@@ -529,7 +529,9 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
continue; continue;
instance->target = 0; instance->target = 0;
mutex_lock(&instance->cdev->lock);
instance->cdev->updated = false; instance->cdev->updated = false;
mutex_unlock(&instance->cdev->lock);
thermal_cdev_update(instance->cdev); thermal_cdev_update(instance->cdev);
} }
} }
......
...@@ -175,7 +175,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) ...@@ -175,7 +175,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
update_passive_instance(tz, trip_type, -1); update_passive_instance(tz, trip_type, -1);
instance->initialized = true; instance->initialized = true;
mutex_lock(&instance->cdev->lock);
instance->cdev->updated = false; /* cdev needs update */ instance->cdev->updated = false; /* cdev needs update */
mutex_unlock(&instance->cdev->lock);
} }
mutex_unlock(&tz->lock); mutex_unlock(&tz->lock);
......
...@@ -1093,7 +1093,9 @@ int power_actor_set_power(struct thermal_cooling_device *cdev, ...@@ -1093,7 +1093,9 @@ int power_actor_set_power(struct thermal_cooling_device *cdev,
return ret; return ret;
instance->target = state; instance->target = state;
mutex_lock(&cdev->lock);
cdev->updated = false; cdev->updated = false;
mutex_unlock(&cdev->lock);
thermal_cdev_update(cdev); thermal_cdev_update(cdev);
return 0; return 0;
...@@ -1623,11 +1625,13 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) ...@@ -1623,11 +1625,13 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
struct thermal_instance *instance; struct thermal_instance *instance;
unsigned long target = 0; unsigned long target = 0;
mutex_lock(&cdev->lock);
/* cooling device is updated*/ /* cooling device is updated*/
if (cdev->updated) if (cdev->updated) {
mutex_unlock(&cdev->lock);
return; return;
}
mutex_lock(&cdev->lock);
/* Make sure cdev enters the deepest cooling state */ /* Make sure cdev enters the deepest cooling state */
list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
dev_dbg(&cdev->device, "zone%d->target=%lu\n", dev_dbg(&cdev->device, "zone%d->target=%lu\n",
...@@ -1637,9 +1641,9 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) ...@@ -1637,9 +1641,9 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
if (instance->target > target) if (instance->target > target)
target = instance->target; target = instance->target;
} }
mutex_unlock(&cdev->lock);
cdev->ops->set_cur_state(cdev, target); cdev->ops->set_cur_state(cdev, target);
cdev->updated = true; cdev->updated = true;
mutex_unlock(&cdev->lock);
trace_cdev_update(cdev, target); trace_cdev_update(cdev, target);
dev_dbg(&cdev->device, "set to state %lu\n", target); dev_dbg(&cdev->device, "set to state %lu\n", target);
} }
......
...@@ -232,6 +232,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) ...@@ -232,6 +232,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
return result; return result;
} }
EXPORT_SYMBOL_GPL(thermal_add_hwmon_sysfs);
void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
{ {
...@@ -270,3 +271,4 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) ...@@ -270,3 +271,4 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
hwmon_device_unregister(hwmon->device); hwmon_device_unregister(hwmon->device);
kfree(hwmon); kfree(hwmon);
} }
EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs);
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