Commit b29bdba5 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 management update from Zhang Rui:
 "The most important one is to build thermal core and governor and cpu
  cooling code into one module.  This fixes a regression that thermal
  core does not work if it is built as module, since 3.7.  I'll backport
  them to stable kernel once those changes are in upstream.

  The largest batch is the thermal kernel-doc & coding style
  updates/cleanups from Eduardo.

  Highlights:

   - build all thermal framework code into one module to fix a
     regression that thermal does not work if it is built as module.

   - Marvell Armada 370/XP thermal sensor driver

   - thermal core/cpu cooling kernel-doc & coding style updates and
     cleanups.

   - Add Eduardo Valentin as thermal sub-maintainer, both in mailing
     list and patchwork.  He will help me on arm thermal drivers."

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux: (68 commits)
  thermal: db8500_cpufreq_cooling: remove usage of IS_ERR_OR_NULL()
  thermal: thermal_core: remove usage of IS_ERR_OR_NULL
  thermal: cpu_cooling: improve line breaking
  thermal: cpu_cooling: alignment improvements
  thermal: cpu_cooling: remove checkpatch.pl warning
  thermal: cpu_cooling: remove trailing blank line
  thermal: cpu_cooling: align on open parenthesis
  thermal: cpu_cooling: standardize comment style
  thermal: cpu_cooling: standardize end of function
  thermal: cpu_cooling: remove trailing white spaces
  Thermal: update documentation for thermal_zone_device_register
  thermal: update kernel-doc for thermal_zone_device_register
  thermal: update kernel-doc for create_trip_attrs
  thermal: update kernel-doc for thermal_cooling_device_register
  thermal: update kernel-doc for thermal_zone_unbind_cooling_device
  thermal: update kernel-doc for thermal_zone_bind_cooling_device
  thermal: use EXPORT_SYMBOL_GPL
  thermal: rename notify_thermal_framework to thermal_notify_framework
  thermal: update driver license
  thermal: use strlcpy instead of strcpy
  ...
parents e0fd9aff de6558dc
* Marvell Armada 370/XP thermal management
Required properties:
- compatible: Should be set to one of the following:
marvell,armada370-thermal
marvell,armadaxp-thermal
- reg: Device's register space.
Two entries are expected, see the examples below.
The first one is required for the sensor register;
the second one is required for the control register
to be used for sensor initialization (a.k.a. calibration).
Example:
thermal@d0018300 {
compatible = "marvell,armada370-thermal";
reg = <0xd0018300 0x4
0xd0018304 0x4>;
status = "okay";
};
...@@ -13,11 +13,11 @@ Thermal emulation mode supports software debug for TMU's operation. User can set ...@@ -13,11 +13,11 @@ Thermal emulation mode supports software debug for TMU's operation. User can set
manually with software code and TMU will read current temperature from user value not from manually with software code and TMU will read current temperature from user value not from
sensor's value. sensor's value.
Enabling CONFIG_EXYNOS_THERMAL_EMUL option will make this support in available. Enabling CONFIG_THERMAL_EMULATION option will make this support available.
When it's enabled, sysfs node will be created under When it's enabled, sysfs node will be created as
/sys/bus/platform/devices/'exynos device name'/ with name of 'emulation'. /sys/devices/virtual/thermal/thermal_zone'zone id'/emul_temp.
The sysfs node, 'emulation', will contain value 0 for the initial state. When you input any The sysfs node, 'emul_node', will contain value 0 for the initial state. When you input any
temperature you want to update to sysfs node, it automatically enable emulation mode and temperature you want to update to sysfs node, it automatically enable emulation mode and
current temperature will be changed into it. current temperature will be changed into it.
(Exynos also supports user changable delay time which would be used to delay of (Exynos also supports user changable delay time which would be used to delay of
......
...@@ -31,15 +31,17 @@ temperature) and throttle appropriate devices. ...@@ -31,15 +31,17 @@ temperature) and throttle appropriate devices.
1. thermal sysfs driver interface functions 1. thermal sysfs driver interface functions
1.1 thermal zone device interface 1.1 thermal zone device interface
1.1.1 struct thermal_zone_device *thermal_zone_device_register(char *name, 1.1.1 struct thermal_zone_device *thermal_zone_device_register(char *type,
int trips, int mask, void *devdata, int trips, int mask, void *devdata,
struct thermal_zone_device_ops *ops) struct thermal_zone_device_ops *ops,
const struct thermal_zone_params *tzp,
int passive_delay, int polling_delay))
This interface function adds a new thermal zone device (sensor) to This interface function adds a new thermal zone device (sensor) to
/sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
thermal cooling devices registered at the same time. thermal cooling devices registered at the same time.
name: the thermal zone name. type: the thermal zone type.
trips: the total number of trip points this thermal zone supports. trips: the total number of trip points this thermal zone supports.
mask: Bit string: If 'n'th bit is set, then trip point 'n' is writeable. mask: Bit string: If 'n'th bit is set, then trip point 'n' is writeable.
devdata: device private data devdata: device private data
...@@ -57,6 +59,12 @@ temperature) and throttle appropriate devices. ...@@ -57,6 +59,12 @@ temperature) and throttle appropriate devices.
will be fired. will be fired.
.set_emul_temp: set the emulation temperature which helps in debugging .set_emul_temp: set the emulation temperature which helps in debugging
different threshold temperature points. different threshold temperature points.
tzp: thermal zone platform parameters.
passive_delay: number of milliseconds to wait between polls when
performing passive cooling.
polling_delay: number of milliseconds to wait between polls when checking
whether trip points have been crossed (0 for interrupt driven systems).
1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz) 1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
...@@ -265,6 +273,10 @@ emul_temp ...@@ -265,6 +273,10 @@ emul_temp
Unit: millidegree Celsius Unit: millidegree Celsius
WO, Optional WO, Optional
WARNING: Be careful while enabling this option on production systems,
because userland can easily disable the thermal policy by simply
flooding this sysfs node with low temperature values.
***************************** *****************************
* Cooling device attributes * * Cooling device attributes *
***************************** *****************************
...@@ -363,7 +375,7 @@ This function returns the thermal_instance corresponding to a given ...@@ -363,7 +375,7 @@ This function returns the thermal_instance corresponding to a given
{thermal_zone, cooling_device, trip_point} combination. Returns NULL {thermal_zone, cooling_device, trip_point} combination. Returns NULL
if such an instance does not exist. if such an instance does not exist.
5.3:notify_thermal_framework: 5.3:thermal_notify_framework:
This function handles the trip events from sensor drivers. It starts This function handles the trip events from sensor drivers. It starts
throttling the cooling devices according to the policy configured. throttling the cooling devices according to the policy configured.
For CRITICAL and HOT trip points, this notifies the respective drivers, For CRITICAL and HOT trip points, this notifies the respective drivers,
...@@ -375,11 +387,3 @@ platform data is provided, this uses the step_wise throttling policy. ...@@ -375,11 +387,3 @@ platform data is provided, this uses the step_wise throttling policy.
This function serves as an arbitrator to set the state of a cooling This function serves as an arbitrator to set the state of a cooling
device. It sets the cooling device to the deepest cooling state if device. It sets the cooling device to the deepest cooling state if
possible. possible.
5.5:thermal_register_governor:
This function lets the various thermal governors to register themselves
with the Thermal framework. At run time, depending on a zone's platform
data, a particular governor is used for throttling.
5.6:thermal_unregister_governor:
This function unregisters a governor from the thermal framework.
...@@ -8029,11 +8029,14 @@ F: arch/xtensa/ ...@@ -8029,11 +8029,14 @@ F: arch/xtensa/
THERMAL THERMAL
M: Zhang Rui <rui.zhang@intel.com> M: Zhang Rui <rui.zhang@intel.com>
M: Eduardo Valentin <eduardo.valentin@ti.com>
L: linux-pm@vger.kernel.org L: linux-pm@vger.kernel.org
T: git git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git
Q: https://patchwork.kernel.org/project/linux-pm/list/
S: Supported S: Supported
F: drivers/thermal/ F: drivers/thermal/
F: include/linux/thermal.h F: include/linux/thermal.h
F: include/linux/cpu_cooling.h
THINGM BLINK(1) USB RGB LED DRIVER THINGM BLINK(1) USB RGB LED DRIVER
M: Vivien Didelot <vivien.didelot@savoirfairelinux.com> M: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
......
...@@ -67,15 +67,16 @@ config THERMAL_GOV_USER_SPACE ...@@ -67,15 +67,16 @@ config THERMAL_GOV_USER_SPACE
Enable this to let the user space manage the platform thermals. Enable this to let the user space manage the platform thermals.
config CPU_THERMAL config CPU_THERMAL
tristate "generic cpu cooling support" bool "generic cpu cooling support"
depends on CPU_FREQ depends on CPU_FREQ
select CPU_FREQ_TABLE select CPU_FREQ_TABLE
help help
This implements the generic cpu cooling mechanism through frequency This implements the generic cpu cooling mechanism through frequency
reduction, cpu hotplug and any other ways of reducing temperature. An reduction. An ACPI version of this already exists
ACPI version of this already exists(drivers/acpi/processor_thermal.c). (drivers/acpi/processor_thermal.c).
This will be useful for platforms using the generic thermal interface This will be useful for platforms using the generic thermal interface
and not the ACPI interface. and not the ACPI interface.
If you want this support, you should say Y here. If you want this support, you should say Y here.
config THERMAL_EMULATION config THERMAL_EMULATION
...@@ -86,6 +87,10 @@ config THERMAL_EMULATION ...@@ -86,6 +87,10 @@ config THERMAL_EMULATION
user can manually input temperature and test the different trip user can manually input temperature and test the different trip
threshold behaviour for simulation purpose. threshold behaviour for simulation purpose.
WARNING: Be careful while enabling this option on production systems,
because userland can easily disable the thermal policy by simply
flooding this sysfs node with low temperature values.
config SPEAR_THERMAL config SPEAR_THERMAL
bool "SPEAr thermal sensor driver" bool "SPEAr thermal sensor driver"
depends on PLAT_SPEAR depends on PLAT_SPEAR
...@@ -117,15 +122,6 @@ config EXYNOS_THERMAL ...@@ -117,15 +122,6 @@ config EXYNOS_THERMAL
If you say yes here you get support for TMU (Thermal Management If you say yes here you get support for TMU (Thermal Management
Unit) on SAMSUNG EXYNOS series of SoC. Unit) on SAMSUNG EXYNOS series of SoC.
config EXYNOS_THERMAL_EMUL
bool "EXYNOS TMU emulation mode support"
depends on EXYNOS_THERMAL
help
Exynos 4412 and 4414 and 5 series has emulation mode on TMU.
Enable this option will be make sysfs node in exynos thermal platform
device directory to support emulation mode. With emulation mode sysfs
node, you can manually input temperature to TMU for simulation purpose.
config DOVE_THERMAL config DOVE_THERMAL
tristate "Temperature sensor on Marvell Dove SoCs" tristate "Temperature sensor on Marvell Dove SoCs"
depends on ARCH_DOVE depends on ARCH_DOVE
...@@ -144,6 +140,14 @@ config DB8500_THERMAL ...@@ -144,6 +140,14 @@ config DB8500_THERMAL
created. Cooling devices can be bound to the trip points to cool this created. Cooling devices can be bound to the trip points to cool this
thermal zone if trip points reached. thermal zone if trip points reached.
config ARMADA_THERMAL
tristate "Armada 370/XP thermal management"
depends on ARCH_MVEBU
depends on OF
help
Enable this option if you want to have support for thermal management
controller present in Armada 370 and Armada XP SoC.
config DB8500_CPUFREQ_COOLING config DB8500_CPUFREQ_COOLING
tristate "DB8500 cpufreq cooling" tristate "DB8500 cpufreq cooling"
depends on ARCH_U8500 depends on ARCH_U8500
......
...@@ -3,14 +3,15 @@ ...@@ -3,14 +3,15 @@
# #
obj-$(CONFIG_THERMAL) += thermal_sys.o obj-$(CONFIG_THERMAL) += thermal_sys.o
thermal_sys-y += thermal_core.o
# governors # governors
obj-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o
obj-$(CONFIG_THERMAL_GOV_STEP_WISE) += step_wise.o thermal_sys-$(CONFIG_THERMAL_GOV_STEP_WISE) += step_wise.o
obj-$(CONFIG_THERMAL_GOV_USER_SPACE) += user_space.o thermal_sys-$(CONFIG_THERMAL_GOV_USER_SPACE) += user_space.o
# cpufreq cooling # cpufreq cooling
obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o
# platform thermal drivers # platform thermal drivers
obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
...@@ -19,6 +20,7 @@ obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o ...@@ -19,6 +20,7 @@ obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o
obj-$(CONFIG_EXYNOS_THERMAL) += exynos_thermal.o obj-$(CONFIG_EXYNOS_THERMAL) += exynos_thermal.o
obj-$(CONFIG_DOVE_THERMAL) += dove_thermal.o obj-$(CONFIG_DOVE_THERMAL) += dove_thermal.o
obj-$(CONFIG_DB8500_THERMAL) += db8500_thermal.o obj-$(CONFIG_DB8500_THERMAL) += db8500_thermal.o
obj-$(CONFIG_ARMADA_THERMAL) += armada_thermal.o
obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
/*
* Marvell Armada 370/XP thermal sensor driver
*
* Copyright (C) 2013 Marvell
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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/device.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include <linux/thermal.h>
#define THERMAL_VALID_OFFSET 9
#define THERMAL_VALID_MASK 0x1
#define THERMAL_TEMP_OFFSET 10
#define THERMAL_TEMP_MASK 0x1ff
/* Thermal Manager Control and Status Register */
#define PMU_TDC0_SW_RST_MASK (0x1 << 1)
#define PMU_TM_DISABLE_OFFS 0
#define PMU_TM_DISABLE_MASK (0x1 << PMU_TM_DISABLE_OFFS)
#define PMU_TDC0_REF_CAL_CNT_OFFS 11
#define PMU_TDC0_REF_CAL_CNT_MASK (0x1ff << PMU_TDC0_REF_CAL_CNT_OFFS)
#define PMU_TDC0_OTF_CAL_MASK (0x1 << 30)
#define PMU_TDC0_START_CAL_MASK (0x1 << 25)
struct armada_thermal_ops;
/* Marvell EBU Thermal Sensor Dev Structure */
struct armada_thermal_priv {
void __iomem *sensor;
void __iomem *control;
struct armada_thermal_ops *ops;
};
struct armada_thermal_ops {
/* Initialize the sensor */
void (*init_sensor)(struct armada_thermal_priv *);
/* Test for a valid sensor value (optional) */
bool (*is_valid)(struct armada_thermal_priv *);
};
static void armadaxp_init_sensor(struct armada_thermal_priv *priv)
{
unsigned long reg;
reg = readl_relaxed(priv->control);
reg |= PMU_TDC0_OTF_CAL_MASK;
writel(reg, priv->control);
/* Reference calibration value */
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
writel(reg, priv->control);
/* Reset the sensor */
reg = readl_relaxed(priv->control);
writel((reg | PMU_TDC0_SW_RST_MASK), priv->control);
writel(reg, priv->control);
/* Enable the sensor */
reg = readl_relaxed(priv->sensor);
reg &= ~PMU_TM_DISABLE_MASK;
writel(reg, priv->sensor);
}
static void armada370_init_sensor(struct armada_thermal_priv *priv)
{
unsigned long reg;
reg = readl_relaxed(priv->control);
reg |= PMU_TDC0_OTF_CAL_MASK;
writel(reg, priv->control);
/* Reference calibration value */
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
writel(reg, priv->control);
reg &= ~PMU_TDC0_START_CAL_MASK;
writel(reg, priv->control);
mdelay(10);
}
static bool armada_is_valid(struct armada_thermal_priv *priv)
{
unsigned long reg = readl_relaxed(priv->sensor);
return (reg >> THERMAL_VALID_OFFSET) & THERMAL_VALID_MASK;
}
static int armada_get_temp(struct thermal_zone_device *thermal,
unsigned long *temp)
{
struct armada_thermal_priv *priv = thermal->devdata;
unsigned long reg;
/* Valid check */
if (priv->ops->is_valid && !priv->ops->is_valid(priv)) {
dev_err(&thermal->device,
"Temperature sensor reading not valid\n");
return -EIO;
}
reg = readl_relaxed(priv->sensor);
reg = (reg >> THERMAL_TEMP_OFFSET) & THERMAL_TEMP_MASK;
*temp = (3153000000UL - (10000000UL*reg)) / 13825;
return 0;
}
static struct thermal_zone_device_ops ops = {
.get_temp = armada_get_temp,
};
static const struct armada_thermal_ops armadaxp_ops = {
.init_sensor = armadaxp_init_sensor,
};
static const struct armada_thermal_ops armada370_ops = {
.is_valid = armada_is_valid,
.init_sensor = armada370_init_sensor,
};
static const struct of_device_id armada_thermal_id_table[] = {
{
.compatible = "marvell,armadaxp-thermal",
.data = &armadaxp_ops,
},
{
.compatible = "marvell,armada370-thermal",
.data = &armada370_ops,
},
{
/* sentinel */
},
};
MODULE_DEVICE_TABLE(of, armada_thermal_id_table);
static int armada_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *thermal;
const struct of_device_id *match;
struct armada_thermal_priv *priv;
struct resource *res;
match = of_match_device(armada_thermal_id_table, &pdev->dev);
if (!match)
return -ENODEV;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "Failed to get platform resource\n");
return -ENODEV;
}
priv->sensor = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->sensor))
return PTR_ERR(priv->sensor);
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (!res) {
dev_err(&pdev->dev, "Failed to get platform resource\n");
return -ENODEV;
}
priv->control = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->control))
return PTR_ERR(priv->control);
priv->ops = (struct armada_thermal_ops *)match->data;
priv->ops->init_sensor(priv);
thermal = thermal_zone_device_register("armada_thermal", 0, 0,
priv, &ops, NULL, 0, 0);
if (IS_ERR(thermal)) {
dev_err(&pdev->dev,
"Failed to register thermal zone device\n");
return PTR_ERR(thermal);
}
platform_set_drvdata(pdev, thermal);
return 0;
}
static int armada_thermal_exit(struct platform_device *pdev)
{
struct thermal_zone_device *armada_thermal =
platform_get_drvdata(pdev);
thermal_zone_device_unregister(armada_thermal);
platform_set_drvdata(pdev, NULL);
return 0;
}
static struct platform_driver armada_thermal_driver = {
.probe = armada_thermal_probe,
.remove = armada_thermal_exit,
.driver = {
.name = "armada_thermal",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(armada_thermal_id_table),
},
};
module_platform_driver(armada_thermal_driver);
MODULE_AUTHOR("Ezequiel Garcia <ezequiel.garcia@free-electrons.com>");
MODULE_DESCRIPTION("Armada 370/XP thermal driver");
MODULE_LICENSE("GPL v2");
This diff is collapsed.
...@@ -37,7 +37,7 @@ static int db8500_cpufreq_cooling_probe(struct platform_device *pdev) ...@@ -37,7 +37,7 @@ static int db8500_cpufreq_cooling_probe(struct platform_device *pdev)
cpumask_set_cpu(0, &mask_val); cpumask_set_cpu(0, &mask_val);
cdev = cpufreq_cooling_register(&mask_val); cdev = cpufreq_cooling_register(&mask_val);
if (IS_ERR_OR_NULL(cdev)) { if (IS_ERR(cdev)) {
dev_err(&pdev->dev, "Failed to register cooling device\n"); dev_err(&pdev->dev, "Failed to register cooling device\n");
return PTR_ERR(cdev); return PTR_ERR(cdev);
} }
......
...@@ -419,7 +419,8 @@ static int db8500_thermal_probe(struct platform_device *pdev) ...@@ -419,7 +419,8 @@ static int db8500_thermal_probe(struct platform_device *pdev)
low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW"); low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");
if (low_irq < 0) { if (low_irq < 0) {
dev_err(&pdev->dev, "Get IRQ_HOTMON_LOW failed.\n"); dev_err(&pdev->dev, "Get IRQ_HOTMON_LOW failed.\n");
return low_irq; ret = low_irq;
goto out_unlock;
} }
ret = devm_request_threaded_irq(&pdev->dev, low_irq, NULL, ret = devm_request_threaded_irq(&pdev->dev, low_irq, NULL,
...@@ -427,13 +428,14 @@ static int db8500_thermal_probe(struct platform_device *pdev) ...@@ -427,13 +428,14 @@ static int db8500_thermal_probe(struct platform_device *pdev)
"dbx500_temp_low", pzone); "dbx500_temp_low", pzone);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Failed to allocate temp low irq.\n"); dev_err(&pdev->dev, "Failed to allocate temp low irq.\n");
return ret; goto out_unlock;
} }
high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH"); high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
if (high_irq < 0) { if (high_irq < 0) {
dev_err(&pdev->dev, "Get IRQ_HOTMON_HIGH failed.\n"); dev_err(&pdev->dev, "Get IRQ_HOTMON_HIGH failed.\n");
return high_irq; ret = high_irq;
goto out_unlock;
} }
ret = devm_request_threaded_irq(&pdev->dev, high_irq, NULL, ret = devm_request_threaded_irq(&pdev->dev, high_irq, NULL,
...@@ -441,15 +443,16 @@ static int db8500_thermal_probe(struct platform_device *pdev) ...@@ -441,15 +443,16 @@ static int db8500_thermal_probe(struct platform_device *pdev)
"dbx500_temp_high", pzone); "dbx500_temp_high", pzone);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Failed to allocate temp high irq.\n"); dev_err(&pdev->dev, "Failed to allocate temp high irq.\n");
return ret; goto out_unlock;
} }
pzone->therm_dev = thermal_zone_device_register("db8500_thermal_zone", pzone->therm_dev = thermal_zone_device_register("db8500_thermal_zone",
ptrips->num_trips, 0, pzone, &thdev_ops, NULL, 0, 0); ptrips->num_trips, 0, pzone, &thdev_ops, NULL, 0, 0);
if (IS_ERR_OR_NULL(pzone->therm_dev)) { if (IS_ERR(pzone->therm_dev)) {
dev_err(&pdev->dev, "Register thermal zone device failed.\n"); dev_err(&pdev->dev, "Register thermal zone device failed.\n");
return PTR_ERR(pzone->therm_dev); ret = PTR_ERR(pzone->therm_dev);
goto out_unlock;
} }
dev_info(&pdev->dev, "Thermal zone device registered.\n"); dev_info(&pdev->dev, "Thermal zone device registered.\n");
...@@ -461,9 +464,11 @@ static int db8500_thermal_probe(struct platform_device *pdev) ...@@ -461,9 +464,11 @@ static int db8500_thermal_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, pzone); platform_set_drvdata(pdev, pzone);
pzone->mode = THERMAL_DEVICE_ENABLED; pzone->mode = THERMAL_DEVICE_ENABLED;
out_unlock:
mutex_unlock(&pzone->th_lock); mutex_unlock(&pzone->th_lock);
return 0; return ret;
} }
static int db8500_thermal_remove(struct platform_device *pdev) static int db8500_thermal_remove(struct platform_device *pdev)
......
...@@ -107,12 +107,13 @@ static int dove_get_temp(struct thermal_zone_device *thermal, ...@@ -107,12 +107,13 @@ static int dove_get_temp(struct thermal_zone_device *thermal,
} }
/* /*
* Calculate temperature. See Section 8.10.1 of 88AP510, * Calculate temperature. According to Marvell internal
* Documentation/arm/Marvell/README * documentation the formula for this is:
* Celsius = (322-reg)/1.3625
*/ */
reg = readl_relaxed(priv->sensor); reg = readl_relaxed(priv->sensor);
reg = (reg >> DOVE_THERMAL_TEMP_OFFSET) & DOVE_THERMAL_TEMP_MASK; reg = (reg >> DOVE_THERMAL_TEMP_OFFSET) & DOVE_THERMAL_TEMP_MASK;
*temp = ((2281638UL - (7298*reg)) / 10); *temp = ((3220000000UL - (10000000UL * reg)) / 13625);
return 0; return 0;
} }
......
...@@ -98,13 +98,13 @@ ...@@ -98,13 +98,13 @@
#define IDLE_INTERVAL 10000 #define IDLE_INTERVAL 10000
#define MCELSIUS 1000 #define MCELSIUS 1000
#ifdef CONFIG_EXYNOS_THERMAL_EMUL #ifdef CONFIG_THERMAL_EMULATION
#define EXYNOS_EMUL_TIME 0x57F0 #define EXYNOS_EMUL_TIME 0x57F0
#define EXYNOS_EMUL_TIME_SHIFT 16 #define EXYNOS_EMUL_TIME_SHIFT 16
#define EXYNOS_EMUL_DATA_SHIFT 8 #define EXYNOS_EMUL_DATA_SHIFT 8
#define EXYNOS_EMUL_DATA_MASK 0xFF #define EXYNOS_EMUL_DATA_MASK 0xFF
#define EXYNOS_EMUL_ENABLE 0x1 #define EXYNOS_EMUL_ENABLE 0x1
#endif /* CONFIG_EXYNOS_THERMAL_EMUL */ #endif /* CONFIG_THERMAL_EMULATION */
/* CPU Zone information */ /* CPU Zone information */
#define PANIC_ZONE 4 #define PANIC_ZONE 4
...@@ -143,6 +143,7 @@ struct thermal_cooling_conf { ...@@ -143,6 +143,7 @@ struct thermal_cooling_conf {
struct thermal_sensor_conf { struct thermal_sensor_conf {
char name[SENSOR_NAME_LEN]; char name[SENSOR_NAME_LEN];
int (*read_temperature)(void *data); int (*read_temperature)(void *data);
int (*write_emul_temp)(void *drv_data, unsigned long temp);
struct thermal_trip_point_conf trip_data; struct thermal_trip_point_conf trip_data;
struct thermal_cooling_conf cooling_data; struct thermal_cooling_conf cooling_data;
void *private_data; void *private_data;
...@@ -240,26 +241,6 @@ static int exynos_get_crit_temp(struct thermal_zone_device *thermal, ...@@ -240,26 +241,6 @@ static int exynos_get_crit_temp(struct thermal_zone_device *thermal,
return ret; return ret;
} }
static int exynos_get_frequency_level(unsigned int cpu, unsigned int freq)
{
int i = 0, ret = -EINVAL;
struct cpufreq_frequency_table *table = NULL;
#ifdef CONFIG_CPU_FREQ
table = cpufreq_frequency_get_table(cpu);
#endif
if (!table)
return ret;
while (table[i].frequency != CPUFREQ_TABLE_END) {
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
continue;
if (table[i].frequency == freq)
return i;
i++;
}
return ret;
}
/* Bind callback functions for thermal zone */ /* Bind callback functions for thermal zone */
static int exynos_bind(struct thermal_zone_device *thermal, static int exynos_bind(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev) struct thermal_cooling_device *cdev)
...@@ -286,8 +267,8 @@ static int exynos_bind(struct thermal_zone_device *thermal, ...@@ -286,8 +267,8 @@ static int exynos_bind(struct thermal_zone_device *thermal,
/* Bind the thermal zone to the cpufreq cooling device */ /* Bind the thermal zone to the cpufreq cooling device */
for (i = 0; i < tab_size; i++) { for (i = 0; i < tab_size; i++) {
clip_data = (struct freq_clip_table *)&(tab_ptr[i]); clip_data = (struct freq_clip_table *)&(tab_ptr[i]);
level = exynos_get_frequency_level(0, clip_data->freq_clip_max); level = cpufreq_cooling_get_level(0, clip_data->freq_clip_max);
if (level < 0) if (level == THERMAL_CSTATE_INVALID)
return 0; return 0;
switch (GET_ZONE(i)) { switch (GET_ZONE(i)) {
case MONITOR_ZONE: case MONITOR_ZONE:
...@@ -367,6 +348,23 @@ static int exynos_get_temp(struct thermal_zone_device *thermal, ...@@ -367,6 +348,23 @@ static int exynos_get_temp(struct thermal_zone_device *thermal,
return 0; return 0;
} }
/* Get temperature callback functions for thermal zone */
static int exynos_set_emul_temp(struct thermal_zone_device *thermal,
unsigned long temp)
{
void *data;
int ret = -EINVAL;
if (!th_zone->sensor_conf) {
pr_info("Temperature sensor not initialised\n");
return -EINVAL;
}
data = th_zone->sensor_conf->private_data;
if (th_zone->sensor_conf->write_emul_temp)
ret = th_zone->sensor_conf->write_emul_temp(data, temp);
return ret;
}
/* Get the temperature trend */ /* Get the temperature trend */
static int exynos_get_trend(struct thermal_zone_device *thermal, static int exynos_get_trend(struct thermal_zone_device *thermal,
int trip, enum thermal_trend *trend) int trip, enum thermal_trend *trend)
...@@ -390,6 +388,7 @@ static struct thermal_zone_device_ops const exynos_dev_ops = { ...@@ -390,6 +388,7 @@ static struct thermal_zone_device_ops const exynos_dev_ops = {
.bind = exynos_bind, .bind = exynos_bind,
.unbind = exynos_unbind, .unbind = exynos_unbind,
.get_temp = exynos_get_temp, .get_temp = exynos_get_temp,
.set_emul_temp = exynos_set_emul_temp,
.get_trend = exynos_get_trend, .get_trend = exynos_get_trend,
.get_mode = exynos_get_mode, .get_mode = exynos_get_mode,
.set_mode = exynos_set_mode, .set_mode = exynos_set_mode,
...@@ -712,6 +711,47 @@ static int exynos_tmu_read(struct exynos_tmu_data *data) ...@@ -712,6 +711,47 @@ static int exynos_tmu_read(struct exynos_tmu_data *data)
return temp; return temp;
} }
#ifdef CONFIG_THERMAL_EMULATION
static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp)
{
struct exynos_tmu_data *data = drv_data;
unsigned int reg;
int ret = -EINVAL;
if (data->soc == SOC_ARCH_EXYNOS4210)
goto out;
if (temp && temp < MCELSIUS)
goto out;
mutex_lock(&data->lock);
clk_enable(data->clk);
reg = readl(data->base + EXYNOS_EMUL_CON);
if (temp) {
temp /= MCELSIUS;
reg = (EXYNOS_EMUL_TIME << EXYNOS_EMUL_TIME_SHIFT) |
(temp_to_code(data, temp)
<< EXYNOS_EMUL_DATA_SHIFT) | EXYNOS_EMUL_ENABLE;
} else {
reg &= ~EXYNOS_EMUL_ENABLE;
}
writel(reg, data->base + EXYNOS_EMUL_CON);
clk_disable(data->clk);
mutex_unlock(&data->lock);
return 0;
out:
return ret;
}
#else
static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp)
{ return -EINVAL; }
#endif/*CONFIG_THERMAL_EMULATION*/
static void exynos_tmu_work(struct work_struct *work) static void exynos_tmu_work(struct work_struct *work)
{ {
struct exynos_tmu_data *data = container_of(work, struct exynos_tmu_data *data = container_of(work,
...@@ -745,6 +785,7 @@ static irqreturn_t exynos_tmu_irq(int irq, void *id) ...@@ -745,6 +785,7 @@ static irqreturn_t exynos_tmu_irq(int irq, void *id)
static struct thermal_sensor_conf exynos_sensor_conf = { static struct thermal_sensor_conf exynos_sensor_conf = {
.name = "exynos-therm", .name = "exynos-therm",
.read_temperature = (int (*)(void *))exynos_tmu_read, .read_temperature = (int (*)(void *))exynos_tmu_read,
.write_emul_temp = exynos_tmu_set_emulation,
}; };
#if defined(CONFIG_CPU_EXYNOS4210) #if defined(CONFIG_CPU_EXYNOS4210)
...@@ -813,6 +854,10 @@ static const struct of_device_id exynos_tmu_match[] = { ...@@ -813,6 +854,10 @@ static const struct of_device_id exynos_tmu_match[] = {
.compatible = "samsung,exynos4210-tmu", .compatible = "samsung,exynos4210-tmu",
.data = (void *)EXYNOS4210_TMU_DRV_DATA, .data = (void *)EXYNOS4210_TMU_DRV_DATA,
}, },
{
.compatible = "samsung,exynos4412-tmu",
.data = (void *)EXYNOS_TMU_DRV_DATA,
},
{ {
.compatible = "samsung,exynos5250-tmu", .compatible = "samsung,exynos5250-tmu",
.data = (void *)EXYNOS_TMU_DRV_DATA, .data = (void *)EXYNOS_TMU_DRV_DATA,
...@@ -851,93 +896,6 @@ static inline struct exynos_tmu_platform_data *exynos_get_driver_data( ...@@ -851,93 +896,6 @@ static inline struct exynos_tmu_platform_data *exynos_get_driver_data(
platform_get_device_id(pdev)->driver_data; platform_get_device_id(pdev)->driver_data;
} }
#ifdef CONFIG_EXYNOS_THERMAL_EMUL
static ssize_t exynos_tmu_emulation_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct platform_device *pdev = container_of(dev,
struct platform_device, dev);
struct exynos_tmu_data *data = platform_get_drvdata(pdev);
unsigned int reg;
u8 temp_code;
int temp = 0;
if (data->soc == SOC_ARCH_EXYNOS4210)
goto out;
mutex_lock(&data->lock);
clk_enable(data->clk);
reg = readl(data->base + EXYNOS_EMUL_CON);
clk_disable(data->clk);
mutex_unlock(&data->lock);
if (reg & EXYNOS_EMUL_ENABLE) {
reg >>= EXYNOS_EMUL_DATA_SHIFT;
temp_code = reg & EXYNOS_EMUL_DATA_MASK;
temp = code_to_temp(data, temp_code);
}
out:
return sprintf(buf, "%d\n", temp * MCELSIUS);
}
static ssize_t exynos_tmu_emulation_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct platform_device *pdev = container_of(dev,
struct platform_device, dev);
struct exynos_tmu_data *data = platform_get_drvdata(pdev);
unsigned int reg;
int temp;
if (data->soc == SOC_ARCH_EXYNOS4210)
goto out;
if (!sscanf(buf, "%d\n", &temp) || temp < 0)
return -EINVAL;
mutex_lock(&data->lock);
clk_enable(data->clk);
reg = readl(data->base + EXYNOS_EMUL_CON);
if (temp) {
/* Both CELSIUS and MCELSIUS type are available for input */
if (temp > MCELSIUS)
temp /= MCELSIUS;
reg = (EXYNOS_EMUL_TIME << EXYNOS_EMUL_TIME_SHIFT) |
(temp_to_code(data, (temp / MCELSIUS))
<< EXYNOS_EMUL_DATA_SHIFT) | EXYNOS_EMUL_ENABLE;
} else {
reg &= ~EXYNOS_EMUL_ENABLE;
}
writel(reg, data->base + EXYNOS_EMUL_CON);
clk_disable(data->clk);
mutex_unlock(&data->lock);
out:
return count;
}
static DEVICE_ATTR(emulation, 0644, exynos_tmu_emulation_show,
exynos_tmu_emulation_store);
static int create_emulation_sysfs(struct device *dev)
{
return device_create_file(dev, &dev_attr_emulation);
}
static void remove_emulation_sysfs(struct device *dev)
{
device_remove_file(dev, &dev_attr_emulation);
}
#else
static inline int create_emulation_sysfs(struct device *dev) { return 0; }
static inline void remove_emulation_sysfs(struct device *dev) {}
#endif
static int exynos_tmu_probe(struct platform_device *pdev) static int exynos_tmu_probe(struct platform_device *pdev)
{ {
struct exynos_tmu_data *data; struct exynos_tmu_data *data;
...@@ -983,12 +941,16 @@ static int exynos_tmu_probe(struct platform_device *pdev) ...@@ -983,12 +941,16 @@ static int exynos_tmu_probe(struct platform_device *pdev)
return ret; return ret;
} }
data->clk = clk_get(NULL, "tmu_apbif"); data->clk = devm_clk_get(&pdev->dev, "tmu_apbif");
if (IS_ERR(data->clk)) { if (IS_ERR(data->clk)) {
dev_err(&pdev->dev, "Failed to get clock\n"); dev_err(&pdev->dev, "Failed to get clock\n");
return PTR_ERR(data->clk); return PTR_ERR(data->clk);
} }
ret = clk_prepare(data->clk);
if (ret)
return ret;
if (pdata->type == SOC_ARCH_EXYNOS || if (pdata->type == SOC_ARCH_EXYNOS ||
pdata->type == SOC_ARCH_EXYNOS4210) pdata->type == SOC_ARCH_EXYNOS4210)
data->soc = pdata->type; data->soc = pdata->type;
...@@ -1037,14 +999,10 @@ static int exynos_tmu_probe(struct platform_device *pdev) ...@@ -1037,14 +999,10 @@ static int exynos_tmu_probe(struct platform_device *pdev)
goto err_clk; goto err_clk;
} }
ret = create_emulation_sysfs(&pdev->dev);
if (ret)
dev_err(&pdev->dev, "Failed to create emulation mode sysfs node\n");
return 0; return 0;
err_clk: err_clk:
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
clk_put(data->clk); clk_unprepare(data->clk);
return ret; return ret;
} }
...@@ -1052,13 +1010,11 @@ static int exynos_tmu_remove(struct platform_device *pdev) ...@@ -1052,13 +1010,11 @@ static int exynos_tmu_remove(struct platform_device *pdev)
{ {
struct exynos_tmu_data *data = platform_get_drvdata(pdev); struct exynos_tmu_data *data = platform_get_drvdata(pdev);
remove_emulation_sysfs(&pdev->dev);
exynos_tmu_control(pdev, false); exynos_tmu_control(pdev, false);
exynos_unregister_thermal(); exynos_unregister_thermal();
clk_put(data->clk); clk_unprepare(data->clk);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
......
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/ */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/thermal.h> #include <linux/thermal.h>
#include "thermal_core.h" #include "thermal_core.h"
...@@ -111,23 +108,15 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip) ...@@ -111,23 +108,15 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
static struct thermal_governor thermal_gov_fair_share = { static struct thermal_governor thermal_gov_fair_share = {
.name = "fair_share", .name = "fair_share",
.throttle = fair_share_throttle, .throttle = fair_share_throttle,
.owner = THIS_MODULE,
}; };
static int __init thermal_gov_fair_share_init(void) int thermal_gov_fair_share_register(void)
{ {
return thermal_register_governor(&thermal_gov_fair_share); return thermal_register_governor(&thermal_gov_fair_share);
} }
static void __exit thermal_gov_fair_share_exit(void) void thermal_gov_fair_share_unregister(void)
{ {
thermal_unregister_governor(&thermal_gov_fair_share); thermal_unregister_governor(&thermal_gov_fair_share);
} }
/* This should load after thermal framework */
fs_initcall(thermal_gov_fair_share_init);
module_exit(thermal_gov_fair_share_exit);
MODULE_AUTHOR("Durgadoss R");
MODULE_DESCRIPTION("A simple weight based thermal throttling governor");
MODULE_LICENSE("GPL");
...@@ -41,21 +41,21 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal, ...@@ -41,21 +41,21 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal,
reg = readl_relaxed(priv->sensor); reg = readl_relaxed(priv->sensor);
/* Valid check */ /* Valid check */
if (!(reg >> KIRKWOOD_THERMAL_VALID_OFFSET) & if (!((reg >> KIRKWOOD_THERMAL_VALID_OFFSET) &
KIRKWOOD_THERMAL_VALID_MASK) { KIRKWOOD_THERMAL_VALID_MASK)) {
dev_err(&thermal->device, dev_err(&thermal->device,
"Temperature sensor reading not valid\n"); "Temperature sensor reading not valid\n");
return -EIO; return -EIO;
} }
/* /*
* Calculate temperature. See Section 8.10.1 of the 88AP510, * Calculate temperature. According to Marvell internal
* datasheet, which has the same sensor. * documentation the formula for this is:
* Documentation/arm/Marvell/README * Celsius = (322-reg)/1.3625
*/ */
reg = (reg >> KIRKWOOD_THERMAL_TEMP_OFFSET) & reg = (reg >> KIRKWOOD_THERMAL_TEMP_OFFSET) &
KIRKWOOD_THERMAL_TEMP_MASK; KIRKWOOD_THERMAL_TEMP_MASK;
*temp = ((2281638UL - (7298*reg)) / 10); *temp = ((3220000000UL - (10000000UL * reg)) / 13625);
return 0; return 0;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -377,6 +378,9 @@ static int rcar_thermal_probe(struct platform_device *pdev) ...@@ -377,6 +378,9 @@ static int rcar_thermal_probe(struct platform_device *pdev)
spin_lock_init(&common->lock); spin_lock_init(&common->lock);
common->dev = dev; common->dev = dev;
pm_runtime_enable(dev);
pm_runtime_get_sync(dev);
irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (irq) { if (irq) {
int ret; int ret;
...@@ -419,12 +423,15 @@ static int rcar_thermal_probe(struct platform_device *pdev) ...@@ -419,12 +423,15 @@ static int rcar_thermal_probe(struct platform_device *pdev)
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
dev_err(dev, "Could not allocate priv\n"); dev_err(dev, "Could not allocate priv\n");
return -ENOMEM; ret = -ENOMEM;
goto error_unregister;
} }
priv->base = devm_ioremap_resource(dev, res); priv->base = devm_ioremap_resource(dev, res);
if (IS_ERR(priv->base)) if (IS_ERR(priv->base)) {
return PTR_ERR(priv->base); ret = PTR_ERR(priv->base);
goto error_unregister;
}
priv->common = common; priv->common = common;
priv->id = i; priv->id = i;
...@@ -443,10 +450,10 @@ static int rcar_thermal_probe(struct platform_device *pdev) ...@@ -443,10 +450,10 @@ static int rcar_thermal_probe(struct platform_device *pdev)
goto error_unregister; goto error_unregister;
} }
list_move_tail(&priv->list, &common->head);
if (rcar_has_irq_support(priv)) if (rcar_has_irq_support(priv))
rcar_thermal_irq_enable(priv); rcar_thermal_irq_enable(priv);
list_move_tail(&priv->list, &common->head);
} }
platform_set_drvdata(pdev, common); platform_set_drvdata(pdev, common);
...@@ -456,8 +463,14 @@ static int rcar_thermal_probe(struct platform_device *pdev) ...@@ -456,8 +463,14 @@ static int rcar_thermal_probe(struct platform_device *pdev)
return 0; return 0;
error_unregister: error_unregister:
rcar_thermal_for_each_priv(priv, common) rcar_thermal_for_each_priv(priv, common) {
thermal_zone_device_unregister(priv->zone); thermal_zone_device_unregister(priv->zone);
if (rcar_has_irq_support(priv))
rcar_thermal_irq_disable(priv);
}
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
return ret; return ret;
} }
...@@ -465,13 +478,20 @@ static int rcar_thermal_probe(struct platform_device *pdev) ...@@ -465,13 +478,20 @@ static int rcar_thermal_probe(struct platform_device *pdev)
static int rcar_thermal_remove(struct platform_device *pdev) static int rcar_thermal_remove(struct platform_device *pdev)
{ {
struct rcar_thermal_common *common = platform_get_drvdata(pdev); struct rcar_thermal_common *common = platform_get_drvdata(pdev);
struct device *dev = &pdev->dev;
struct rcar_thermal_priv *priv; struct rcar_thermal_priv *priv;
rcar_thermal_for_each_priv(priv, common) rcar_thermal_for_each_priv(priv, common) {
thermal_zone_device_unregister(priv->zone); thermal_zone_device_unregister(priv->zone);
if (rcar_has_irq_support(priv))
rcar_thermal_irq_disable(priv);
}
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
return 0; return 0;
} }
......
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/ */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/thermal.h> #include <linux/thermal.h>
#include "thermal_core.h" #include "thermal_core.h"
...@@ -59,9 +56,12 @@ static unsigned long get_target_state(struct thermal_instance *instance, ...@@ -59,9 +56,12 @@ static unsigned long get_target_state(struct thermal_instance *instance,
switch (trend) { switch (trend) {
case THERMAL_TREND_RAISING: case THERMAL_TREND_RAISING:
if (throttle) if (throttle) {
cur_state = cur_state < instance->upper ? cur_state = cur_state < instance->upper ?
(cur_state + 1) : instance->upper; (cur_state + 1) : instance->upper;
if (cur_state < instance->lower)
cur_state = instance->lower;
}
break; break;
case THERMAL_TREND_RAISE_FULL: case THERMAL_TREND_RAISE_FULL:
if (throttle) if (throttle)
...@@ -71,8 +71,11 @@ static unsigned long get_target_state(struct thermal_instance *instance, ...@@ -71,8 +71,11 @@ static unsigned long get_target_state(struct thermal_instance *instance,
if (cur_state == instance->lower) { if (cur_state == instance->lower) {
if (!throttle) if (!throttle)
cur_state = -1; cur_state = -1;
} else } else {
cur_state -= 1; cur_state -= 1;
if (cur_state > instance->upper)
cur_state = instance->upper;
}
break; break;
case THERMAL_TREND_DROP_FULL: case THERMAL_TREND_DROP_FULL:
if (cur_state == instance->lower) { if (cur_state == instance->lower) {
...@@ -180,23 +183,14 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip) ...@@ -180,23 +183,14 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip)
static struct thermal_governor thermal_gov_step_wise = { static struct thermal_governor thermal_gov_step_wise = {
.name = "step_wise", .name = "step_wise",
.throttle = step_wise_throttle, .throttle = step_wise_throttle,
.owner = THIS_MODULE,
}; };
static int __init thermal_gov_step_wise_init(void) int thermal_gov_step_wise_register(void)
{ {
return thermal_register_governor(&thermal_gov_step_wise); return thermal_register_governor(&thermal_gov_step_wise);
} }
static void __exit thermal_gov_step_wise_exit(void) void thermal_gov_step_wise_unregister(void)
{ {
thermal_unregister_governor(&thermal_gov_step_wise); thermal_unregister_governor(&thermal_gov_step_wise);
} }
/* This should load after thermal framework */
fs_initcall(thermal_gov_step_wise_init);
module_exit(thermal_gov_step_wise_exit);
MODULE_AUTHOR("Durgadoss R");
MODULE_DESCRIPTION("A step-by-step thermal throttling governor");
MODULE_LICENSE("GPL");
...@@ -50,4 +50,31 @@ struct thermal_instance { ...@@ -50,4 +50,31 @@ struct thermal_instance {
struct list_head cdev_node; /* node in cdev->thermal_instances */ struct list_head cdev_node; /* node in cdev->thermal_instances */
}; };
int thermal_register_governor(struct thermal_governor *);
void thermal_unregister_governor(struct thermal_governor *);
#ifdef CONFIG_THERMAL_GOV_STEP_WISE
int thermal_gov_step_wise_register(void);
void thermal_gov_step_wise_unregister(void);
#else
static inline int thermal_gov_step_wise_register(void) { return 0; }
static inline void thermal_gov_step_wise_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_STEP_WISE */
#ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
int thermal_gov_fair_share_register(void);
void thermal_gov_fair_share_unregister(void);
#else
static inline int thermal_gov_fair_share_register(void) { return 0; }
static inline void thermal_gov_fair_share_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_FAIR_SHARE */
#ifdef CONFIG_THERMAL_GOV_USER_SPACE
int thermal_gov_user_space_register(void);
void thermal_gov_user_space_unregister(void);
#else
static inline int thermal_gov_user_space_register(void) { return 0; }
static inline void thermal_gov_user_space_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_USER_SPACE */
#endif /* __THERMAL_CORE_H__ */ #endif /* __THERMAL_CORE_H__ */
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/ */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/thermal.h> #include <linux/thermal.h>
#include "thermal_core.h" #include "thermal_core.h"
...@@ -46,23 +43,15 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip) ...@@ -46,23 +43,15 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip)
static struct thermal_governor thermal_gov_user_space = { static struct thermal_governor thermal_gov_user_space = {
.name = "user_space", .name = "user_space",
.throttle = notify_user_space, .throttle = notify_user_space,
.owner = THIS_MODULE,
}; };
static int __init thermal_gov_user_space_init(void) int thermal_gov_user_space_register(void)
{ {
return thermal_register_governor(&thermal_gov_user_space); return thermal_register_governor(&thermal_gov_user_space);
} }
static void __exit thermal_gov_user_space_exit(void) void thermal_gov_user_space_unregister(void)
{ {
thermal_unregister_governor(&thermal_gov_user_space); thermal_unregister_governor(&thermal_gov_user_space);
} }
/* This should load after thermal framework */
fs_initcall(thermal_gov_user_space_init);
module_exit(thermal_gov_user_space_exit);
MODULE_AUTHOR("Durgadoss R");
MODULE_DESCRIPTION("A user space Thermal notifier");
MODULE_LICENSE("GPL");
...@@ -25,34 +25,39 @@ ...@@ -25,34 +25,39 @@
#define __CPU_COOLING_H__ #define __CPU_COOLING_H__
#include <linux/thermal.h> #include <linux/thermal.h>
#include <linux/cpumask.h>
#define CPUFREQ_COOLING_START 0 #ifdef CONFIG_CPU_THERMAL
#define CPUFREQ_COOLING_STOP 1
#if defined(CONFIG_CPU_THERMAL) || defined(CONFIG_CPU_THERMAL_MODULE)
/** /**
* cpufreq_cooling_register - function to create cpufreq cooling device. * cpufreq_cooling_register - function to create cpufreq cooling device.
* @clip_cpus: cpumask of cpus where the frequency constraints will happen * @clip_cpus: cpumask of cpus where the frequency constraints will happen
*/ */
struct thermal_cooling_device *cpufreq_cooling_register( struct thermal_cooling_device *
const struct cpumask *clip_cpus); cpufreq_cooling_register(const struct cpumask *clip_cpus);
/** /**
* cpufreq_cooling_unregister - function to remove cpufreq cooling device. * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
* @cdev: thermal cooling device pointer. * @cdev: thermal cooling device pointer.
*/ */
void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev); void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev);
unsigned long cpufreq_cooling_get_level(unsigned int, unsigned int);
#else /* !CONFIG_CPU_THERMAL */ #else /* !CONFIG_CPU_THERMAL */
static inline struct thermal_cooling_device *cpufreq_cooling_register( static inline struct thermal_cooling_device *
const struct cpumask *clip_cpus) cpufreq_cooling_register(const struct cpumask *clip_cpus)
{ {
return NULL; return NULL;
} }
static inline void cpufreq_cooling_unregister( static inline
struct thermal_cooling_device *cdev) void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
{ {
return; return;
} }
static inline
unsigned long cpufreq_cooling_get_level(unsigned int, unsigned int)
{
return THERMAL_CSTATE_INVALID;
}
#endif /* CONFIG_CPU_THERMAL */ #endif /* CONFIG_CPU_THERMAL */
#endif /* __CPU_COOLING_H__ */ #endif /* __CPU_COOLING_H__ */
...@@ -33,8 +33,11 @@ ...@@ -33,8 +33,11 @@
#define THERMAL_MAX_TRIPS 12 #define THERMAL_MAX_TRIPS 12
#define THERMAL_NAME_LENGTH 20 #define THERMAL_NAME_LENGTH 20
/* invalid cooling state */
#define THERMAL_CSTATE_INVALID -1UL
/* No upper/lower limit requirement */ /* No upper/lower limit requirement */
#define THERMAL_NO_LIMIT -1UL #define THERMAL_NO_LIMIT THERMAL_CSTATE_INVALID
/* 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) ? \
...@@ -184,7 +187,6 @@ struct thermal_governor { ...@@ -184,7 +187,6 @@ struct thermal_governor {
char name[THERMAL_NAME_LENGTH]; char name[THERMAL_NAME_LENGTH];
int (*throttle)(struct thermal_zone_device *tz, int trip); int (*throttle)(struct thermal_zone_device *tz, int trip);
struct list_head governor_list; struct list_head governor_list;
struct module *owner;
}; };
/* Structure that holds binding parameters for a zone */ /* Structure that holds binding parameters for a zone */
...@@ -237,21 +239,20 @@ void thermal_zone_device_update(struct thermal_zone_device *); ...@@ -237,21 +239,20 @@ void thermal_zone_device_update(struct thermal_zone_device *);
struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
const struct thermal_cooling_device_ops *); const struct thermal_cooling_device_ops *);
void thermal_cooling_device_unregister(struct thermal_cooling_device *); void thermal_cooling_device_unregister(struct thermal_cooling_device *);
struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp);
int get_tz_trend(struct thermal_zone_device *, int); int get_tz_trend(struct thermal_zone_device *, int);
struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
struct thermal_cooling_device *, int); struct thermal_cooling_device *, int);
void thermal_cdev_update(struct thermal_cooling_device *); void thermal_cdev_update(struct thermal_cooling_device *);
void notify_thermal_framework(struct thermal_zone_device *, int); void thermal_notify_framework(struct thermal_zone_device *, int);
int thermal_register_governor(struct thermal_governor *);
void thermal_unregister_governor(struct thermal_governor *);
#ifdef CONFIG_NET #ifdef CONFIG_NET
extern int thermal_generate_netlink_event(struct thermal_zone_device *tz, extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,
enum events event); enum events event);
#else #else
static int thermal_generate_netlink_event(struct thermal_zone_device *tz, static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz,
enum events event) enum events event)
{ {
return 0; return 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