Merge branch 'linux-linaro-lsk' into linux-linaro-lsk-android
authorMark Brown <broonie@linaro.org>
Fri, 4 Apr 2014 10:53:18 +0000 (11:53 +0100)
committerMark Brown <broonie@linaro.org>
Fri, 4 Apr 2014 10:53:18 +0000 (11:53 +0100)
36 files changed:
Documentation/devicetree/bindings/thermal/thermal.txt [new file with mode: 0644]
Documentation/thermal/sysfs-api.txt
MAINTAINERS
Makefile
arch/x86/include/asm/topology.h
drivers/block/aoe/aoecmd.c
drivers/hwmon/lm75.c
drivers/hwmon/tmp102.c
drivers/input/mouse/cypress_ps2.c
drivers/input/mouse/synaptics.c
drivers/input/mousedev.c
drivers/net/ethernet/marvell/mvneta.c
drivers/thermal/Kconfig
drivers/thermal/Makefile
drivers/thermal/cpu_cooling.c
drivers/thermal/of-thermal.c [new file with mode: 0644]
drivers/thermal/step_wise.c
drivers/thermal/thermal_core.c
drivers/thermal/thermal_core.h
drivers/thermal/thermal_hwmon.c [new file with mode: 0644]
drivers/thermal/thermal_hwmon.h [new file with mode: 0644]
drivers/vfio/vfio_iommu_type1.c
fs/ext4/inode.c
fs/proc/page.c
include/dt-bindings/thermal/thermal.h [new file with mode: 0644]
include/linux/bitops.h
include/linux/cpu_cooling.h
include/linux/huge_mm.h
include/linux/mm.h
include/linux/thermal.h
mm/ksm.c
mm/memory-failure.c
mm/page_alloc.c
mm/swap.c
net/netfilter/nf_conntrack_proto_dccp.c
virt/kvm/kvm_main.c

diff --git a/Documentation/devicetree/bindings/thermal/thermal.txt b/Documentation/devicetree/bindings/thermal/thermal.txt
new file mode 100644 (file)
index 0000000..f5db6b7
--- /dev/null
@@ -0,0 +1,595 @@
+* Thermal Framework Device Tree descriptor
+
+This file describes a generic binding to provide a way of
+defining hardware thermal structure using device tree.
+A thermal structure includes thermal zones and their components,
+such as trip points, polling intervals, sensors and cooling devices
+binding descriptors.
+
+The target of device tree thermal descriptors is to describe only
+the hardware thermal aspects. The thermal device tree bindings are
+not about how the system must control or which algorithm or policy
+must be taken in place.
+
+There are five types of nodes involved to describe thermal bindings:
+- thermal sensors: devices which may be used to take temperature
+  measurements.
+- cooling devices: devices which may be used to dissipate heat.
+- trip points: describe key temperatures at which cooling is recommended. The
+  set of points should be chosen based on hardware limits.
+- cooling maps: used to describe links between trip points and cooling devices;
+- thermal zones: used to describe thermal data within the hardware;
+
+The following is a description of each of these node types.
+
+* Thermal sensor devices
+
+Thermal sensor devices are nodes providing temperature sensing capabilities on
+thermal zones. Typical devices are I2C ADC converters and bandgaps. These are
+nodes providing temperature data to thermal zones. Thermal sensor devices may
+control one or more internal sensors.
+
+Required property:
+- #thermal-sensor-cells: Used to provide sensor device specific information
+  Type: unsigned        while referring to it. Typically 0 on thermal sensor
+  Size: one cell        nodes with only one sensor, and at least 1 on nodes
+                        with several internal sensors, in order
+                        to identify uniquely the sensor instances within
+                        the IC. See thermal zone binding for more details
+                        on how consumers refer to sensor devices.
+
+* Cooling device nodes
+
+Cooling devices are nodes providing control on power dissipation. There
+are essentially two ways to provide control on power dissipation. First
+is by means of regulating device performance, which is known as passive
+cooling. A typical passive cooling is a CPU that has dynamic voltage and
+frequency scaling (DVFS), and uses lower frequencies as cooling states.
+Second is by means of activating devices in order to remove
+the dissipated heat, which is known as active cooling, e.g. regulating
+fan speeds. In both cases, cooling devices shall have a way to determine
+the state of cooling in which the device is.
+
+Any cooling device has a range of cooling states (i.e. different levels
+of heat dissipation). For example a fan's cooling states correspond to
+the different fan speeds possible. Cooling states are referred to by
+single unsigned integers, where larger numbers mean greater heat
+dissipation. The precise set of cooling states associated with a device
+(as referred to be the cooling-min-state and cooling-max-state
+properties) should be defined in a particular device's binding.
+For more examples of cooling devices, refer to the example sections below.
+
+Required properties:
+- cooling-min-state:   An integer indicating the smallest
+  Type: unsigned       cooling state accepted. Typically 0.
+  Size: one cell
+
+- cooling-max-state:   An integer indicating the largest
+  Type: unsigned       cooling state accepted.
+  Size: one cell
+
+- #cooling-cells:      Used to provide cooling device specific information
+  Type: unsigned       while referring to it. Must be at least 2, in order
+  Size: one cell       to specify minimum and maximum cooling state used
+                       in the reference. The first cell is the minimum
+                       cooling state requested and the second cell is
+                       the maximum cooling state requested in the reference.
+                       See Cooling device maps section below for more details
+                       on how consumers refer to cooling devices.
+
+* Trip points
+
+The trip node is a node to describe a point in the temperature domain
+in which the system takes an action. This node describes just the point,
+not the action.
+
+Required properties:
+- temperature:         An integer indicating the trip temperature level,
+  Type: signed         in millicelsius.
+  Size: one cell
+
+- hysteresis:          A low hysteresis value on temperature property (above).
+  Type: unsigned       This is a relative value, in millicelsius.
+  Size: one cell
+
+- type:                        a string containing the trip type. Expected values are:
+       "active":       A trip point to enable active cooling
+       "passive":      A trip point to enable passive cooling
+       "hot":          A trip point to notify emergency
+       "critical":     Hardware not reliable.
+  Type: string
+
+* Cooling device maps
+
+The cooling device maps node is a node to describe how cooling devices
+get assigned to trip points of the zone. The cooling devices are expected
+to be loaded in the target system.
+
+Required properties:
+- cooling-device:      A phandle of a cooling device with its specifier,
+  Type: phandle +      referring to which cooling device is used in this
+    cooling specifier  binding. In the cooling specifier, the first cell
+                       is the minimum cooling state and the second cell
+                       is the maximum cooling state used in this map.
+- trip:                        A phandle of a trip point node within the same thermal
+  Type: phandle of     zone.
+   trip point node
+
+Optional property:
+- contribution:                The cooling contribution to the thermal zone of the
+  Type: unsigned       referred cooling device at the referred trip point.
+  Size: one cell       The contribution is a ratio of the sum
+                       of all cooling contributions within a thermal zone.
+
+Note: Using the THERMAL_NO_LIMIT (-1UL) constant in the cooling-device phandle
+limit specifier means:
+(i)   - minimum state allowed for minimum cooling state used in the reference.
+(ii)  - maximum state allowed for maximum cooling state used in the reference.
+Refer to include/dt-bindings/thermal/thermal.h for definition of this constant.
+
+* Thermal zone nodes
+
+The thermal zone node is the node containing all the required info
+for describing a thermal zone, including its cooling device bindings. The
+thermal zone node must contain, apart from its own properties, one sub-node
+containing trip nodes and one sub-node containing all the zone cooling maps.
+
+Required properties:
+- polling-delay:       The maximum number of milliseconds to wait between polls
+  Type: unsigned       when checking this thermal zone.
+  Size: one cell
+
+- polling-delay-passive: The maximum number of milliseconds to wait
+  Type: unsigned       between polls when performing passive cooling.
+  Size: one cell
+
+- thermal-sensors:     A list of thermal sensor phandles and sensor specifier
+  Type: list of        used while monitoring the thermal zone.
+  phandles + sensor
+  specifier
+
+- trips:               A sub-node which is a container of only trip point nodes
+  Type: sub-node       required to describe the thermal zone.
+
+- cooling-maps:                A sub-node which is a container of only cooling device
+  Type: sub-node       map nodes, used to describe the relation between trips
+                       and cooling devices.
+
+Optional property:
+- coefficients:                An array of integers (one signed cell) containing
+  Type: array          coefficients to compose a linear relation between
+  Elem size: one cell  the sensors listed in the thermal-sensors property.
+  Elem type: signed    Coefficients defaults to 1, in case this property
+                       is not specified. A simple linear polynomial is used:
+                       Z = c0 * x0 + c1 + x1 + ... + c(n-1) * x(n-1) + cn.
+
+                       The coefficients are ordered and they match with sensors
+                       by means of sensor ID. Additional coefficients are
+                       interpreted as constant offset.
+
+Note: The delay properties are bound to the maximum dT/dt (temperature
+derivative over time) in two situations for a thermal zone:
+(i)  - when passive cooling is activated (polling-delay-passive); and
+(ii) - when the zone just needs to be monitored (polling-delay) or
+when active cooling is activated.
+
+The maximum dT/dt is highly bound to hardware power consumption and dissipation
+capability. The delays should be chosen to account for said max dT/dt,
+such that a device does not cross several trip boundaries unexpectedly
+between polls. Choosing the right polling delays shall avoid having the
+device in temperature ranges that may damage the silicon structures and
+reduce silicon lifetime.
+
+* The thermal-zones node
+
+The "thermal-zones" node is a container for all thermal zone nodes. It shall
+contain only sub-nodes describing thermal zones as in the section
+"Thermal zone nodes". The "thermal-zones" node appears under "/".
+
+* Examples
+
+Below are several examples on how to use thermal data descriptors
+using device tree bindings:
+
+(a) - CPU thermal zone
+
+The CPU thermal zone example below describes how to setup one thermal zone
+using one single sensor as temperature source and many cooling devices and
+power dissipation control sources.
+
+#include <dt-bindings/thermal/thermal.h>
+
+cpus {
+       /*
+        * Here is an example of describing a cooling device for a DVFS
+        * capable CPU. The CPU node describes its four OPPs.
+        * The cooling states possible are 0..3, and they are
+        * used as OPP indexes. The minimum cooling state is 0, which means
+        * all four OPPs can be available to the system. The maximum
+        * cooling state is 3, which means only the lowest OPPs (198MHz@0.85V)
+        * can be available in the system.
+        */
+       cpu0: cpu@0 {
+               ...
+               operating-points = <
+                       /* kHz    uV */
+                       970000  1200000
+                       792000  1100000
+                       396000  950000
+                       198000  850000
+               >;
+               cooling-min-state = <0>;
+               cooling-max-state = <3>;
+               #cooling-cells = <2>; /* min followed by max */
+       };
+       ...
+};
+
+&i2c1 {
+       ...
+       /*
+        * A simple fan controller which supports 10 speeds of operation
+        * (represented as 0-9).
+        */
+       fan0: fan@0x48 {
+               ...
+               cooling-min-state = <0>;
+               cooling-max-state = <9>;
+               #cooling-cells = <2>; /* min followed by max */
+       };
+};
+
+ocp {
+       ...
+       /*
+        * A simple IC with a single bandgap temperature sensor.
+        */
+       bandgap0: bandgap@0x0000ED00 {
+               ...
+               #thermal-sensor-cells = <0>;
+       };
+};
+
+thermal-zones {
+       cpu-thermal: cpu-thermal {
+               polling-delay-passive = <250>; /* milliseconds */
+               polling-delay = <1000>; /* milliseconds */
+
+               thermal-sensors = <&bandgap0>;
+
+               trips {
+                       cpu-alert0: cpu-alert {
+                               temperature = <90000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "active";
+                       };
+                       cpu-alert1: cpu-alert {
+                               temperature = <100000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       };
+                       cpu-crit: cpu-crit {
+                               temperature = <125000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "critical";
+                       };
+               };
+
+               cooling-maps {
+                       map0 {
+                               trip = <&cpu-alert0>;
+                               cooling-device = <&fan0 THERMAL_NO_LIMITS 4>;
+                       };
+                       map1 {
+                               trip = <&cpu-alert1>;
+                               cooling-device = <&fan0 5 THERMAL_NO_LIMITS>;
+                       };
+                       map2 {
+                               trip = <&cpu-alert1>;
+                               cooling-device =
+                                   <&cpu0 THERMAL_NO_LIMITS THERMAL_NO_LIMITS>;
+                       };
+               };
+       };
+};
+
+In the example above, the ADC sensor (bandgap0) at address 0x0000ED00 is
+used to monitor the zone 'cpu-thermal' using its sole sensor. A fan
+device (fan0) is controlled via I2C bus 1, at address 0x48, and has ten
+different cooling states 0-9. It is used to remove the heat out of
+the thermal zone 'cpu-thermal' using its cooling states
+from its minimum to 4, when it reaches trip point 'cpu-alert0'
+at 90C, as an example of active cooling. The same cooling device is used at
+'cpu-alert1', but from 5 to its maximum state. The cpu@0 device is also
+linked to the same thermal zone, 'cpu-thermal', as a passive cooling device,
+using all its cooling states at trip point 'cpu-alert1',
+which is a trip point at 100C. On the thermal zone 'cpu-thermal', at the
+temperature of 125C, represented by the trip point 'cpu-crit', the silicon
+is not reliable anymore.
+
+(b) - IC with several internal sensors
+
+The example below describes how to deploy several thermal zones based off a
+single sensor IC, assuming it has several internal sensors. This is a common
+case on SoC designs with several internal IPs that may need different thermal
+requirements, and thus may have their own sensor to monitor or detect internal
+hotspots in their silicon.
+
+#include <dt-bindings/thermal/thermal.h>
+
+ocp {
+       ...
+       /*
+        * A simple IC with several bandgap temperature sensors.
+        */
+       bandgap0: bandgap@0x0000ED00 {
+               ...
+               #thermal-sensor-cells = <1>;
+       };
+};
+
+thermal-zones {
+       cpu-thermal: cpu-thermal {
+               polling-delay-passive = <250>; /* milliseconds */
+               polling-delay = <1000>; /* milliseconds */
+
+                               /* sensor       ID */
+               thermal-sensors = <&bandgap0     0>;
+
+               trips {
+                       /* each zone within the SoC may have its own trips */
+                       cpu-alert: cpu-alert {
+                               temperature = <100000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       };
+                       cpu-crit: cpu-crit {
+                               temperature = <125000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "critical";
+                       };
+               };
+
+               cooling-maps {
+                       /* each zone within the SoC may have its own cooling */
+                       ...
+               };
+       };
+
+       gpu-thermal: gpu-thermal {
+               polling-delay-passive = <120>; /* milliseconds */
+               polling-delay = <1000>; /* milliseconds */
+
+                               /* sensor       ID */
+               thermal-sensors = <&bandgap0     1>;
+
+               trips {
+                       /* each zone within the SoC may have its own trips */
+                       gpu-alert: gpu-alert {
+                               temperature = <90000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       };
+                       gpu-crit: gpu-crit {
+                               temperature = <105000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "critical";
+                       };
+               };
+
+               cooling-maps {
+                       /* each zone within the SoC may have its own cooling */
+                       ...
+               };
+       };
+
+       dsp-thermal: dsp-thermal {
+               polling-delay-passive = <50>; /* milliseconds */
+               polling-delay = <1000>; /* milliseconds */
+
+                               /* sensor       ID */
+               thermal-sensors = <&bandgap0     2>;
+
+               trips {
+                       /* each zone within the SoC may have its own trips */
+                       dsp-alert: gpu-alert {
+                               temperature = <90000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       };
+                       dsp-crit: gpu-crit {
+                               temperature = <135000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "critical";
+                       };
+               };
+
+               cooling-maps {
+                       /* each zone within the SoC may have its own cooling */
+                       ...
+               };
+       };
+};
+
+In the example above, there is one bandgap IC which has the capability to
+monitor three sensors. The hardware has been designed so that sensors are
+placed on different places in the DIE to monitor different temperature
+hotspots: one for CPU thermal zone, one for GPU thermal zone and the
+other to monitor a DSP thermal zone.
+
+Thus, there is a need to assign each sensor provided by the bandgap IC
+to different thermal zones. This is achieved by means of using the
+#thermal-sensor-cells property and using the first cell of the sensor
+specifier as sensor ID. In the example, then, <bandgap 0> is used to
+monitor CPU thermal zone, <bandgap 1> is used to monitor GPU thermal
+zone and <bandgap 2> is used to monitor DSP thermal zone. Each zone
+may be uncorrelated, having its own dT/dt requirements, trips
+and cooling maps.
+
+
+(c) - Several sensors within one single thermal zone
+
+The example below illustrates how to use more than one sensor within
+one thermal zone.
+
+#include <dt-bindings/thermal/thermal.h>
+
+&i2c1 {
+       ...
+       /*
+        * A simple IC with a single temperature sensor.
+        */
+       adc: sensor@0x49 {
+               ...
+               #thermal-sensor-cells = <0>;
+       };
+};
+
+ocp {
+       ...
+       /*
+        * A simple IC with a single bandgap temperature sensor.
+        */
+       bandgap0: bandgap@0x0000ED00 {
+               ...
+               #thermal-sensor-cells = <0>;
+       };
+};
+
+thermal-zones {
+       cpu-thermal: cpu-thermal {
+               polling-delay-passive = <250>; /* milliseconds */
+               polling-delay = <1000>; /* milliseconds */
+
+               thermal-sensors = <&bandgap0>,  /* cpu */
+                                 <&adc>;       /* pcb north */
+
+               /* hotspot = 100 * bandgap - 120 * adc + 484 */
+               coefficients =          <100    -120    484>;
+
+               trips {
+                       ...
+               };
+
+               cooling-maps {
+                       ...
+               };
+       };
+};
+
+In some cases, there is a need to use more than one sensor to extrapolate
+a thermal hotspot in the silicon. The above example illustrates this situation.
+For instance, it may be the case that a sensor external to CPU IP may be placed
+close to CPU hotspot and together with internal CPU sensor, it is used
+to determine the hotspot. Assuming this is the case for the above example,
+the hypothetical extrapolation rule would be:
+               hotspot = 100 * bandgap - 120 * adc + 484
+
+In other context, the same idea can be used to add fixed offset. For instance,
+consider the hotspot extrapolation rule below:
+               hotspot = 1 * adc + 6000
+
+In the above equation, the hotspot is always 6C higher than what is read
+from the ADC sensor. The binding would be then:
+        thermal-sensors =  <&adc>;
+
+               /* hotspot = 1 * adc + 6000 */
+       coefficients =          <1      6000>;
+
+(d) - Board thermal
+
+The board thermal example below illustrates how to setup one thermal zone
+with many sensors and many cooling devices.
+
+#include <dt-bindings/thermal/thermal.h>
+
+&i2c1 {
+       ...
+       /*
+        * An IC with several temperature sensor.
+        */
+       adc-dummy: sensor@0x50 {
+               ...
+               #thermal-sensor-cells = <1>; /* sensor internal ID */
+       };
+};
+
+thermal-zones {
+       batt-thermal {
+               polling-delay-passive = <500>; /* milliseconds */
+               polling-delay = <2500>; /* milliseconds */
+
+                               /* sensor       ID */
+               thermal-sensors = <&adc-dummy     4>;
+
+               trips {
+                       ...
+               };
+
+               cooling-maps {
+                       ...
+               };
+       };
+
+       board-thermal: board-thermal {
+               polling-delay-passive = <1000>; /* milliseconds */
+               polling-delay = <2500>; /* milliseconds */
+
+                               /* sensor       ID */
+               thermal-sensors = <&adc-dummy     0>, /* pcb top edge */
+                                 <&adc-dummy     1>, /* lcd */
+                                 <&adc-dymmy     2>; /* back cover */
+               /*
+                * An array of coefficients describing the sensor
+                * linear relation. E.g.:
+                * z = c1*x1 + c2*x2 + c3*x3
+                */
+               coefficients =          <1200   -345    890>;
+
+               trips {
+                       /* Trips are based on resulting linear equation */
+                       cpu-trip: cpu-trip {
+                               temperature = <60000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       };
+                       gpu-trip: gpu-trip {
+                               temperature = <55000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       }
+                       lcd-trip: lcp-trip {
+                               temperature = <53000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "passive";
+                       };
+                       crit-trip: crit-trip {
+                               temperature = <68000>; /* millicelsius */
+                               hysteresis = <2000>; /* millicelsius */
+                               type = "critical";
+                       };
+               };
+
+               cooling-maps {
+                       map0 {
+                               trip = <&cpu-trip>;
+                               cooling-device = <&cpu0 0 2>;
+                               contribution = <55>;
+                       };
+                       map1 {
+                               trip = <&gpu-trip>;
+                               cooling-device = <&gpu0 0 2>;
+                               contribution = <20>;
+                       };
+                       map2 {
+                               trip = <&lcd-trip>;
+                               cooling-device = <&lcd0 5 10>;
+                               contribution = <15>;
+                       };
+               };
+       };
+};
+
+The above example is a mix of previous examples, a sensor IP with several internal
+sensors used to monitor different zones, one of them is composed by several sensors and
+with different cooling devices.
index a71bd5b90fe89ad68cc01d93e655bc7b79d69467..37c54863f611c469810e827bc0df773e010aa07f 100644 (file)
@@ -142,6 +142,11 @@ temperature) and throttle appropriate devices.
     This is an optional feature where some platforms can choose not to
     provide this data.
     .governor_name: Name of the thermal governor used for this zone
+    .no_hwmon: a boolean to indicate if the thermal to hwmon sysfs interface
+               is required. when no_hwmon == false, a hwmon sysfs interface
+               will be created. when no_hwmon == true, nothing will be done.
+               In case the thermal_zone_params is NULL, the hwmon interface
+               will be created (for backward compatibility).
     .num_tbps: Number of thermal_bind_params entries for this zone
     .tbp: thermal_bind_params entries
 
index 48c748080c96ee5bb52e26d6a2b4bd2ab001c62d..0c204dd7c12b2de1bcb36236847411b5a89a0513 100644 (file)
@@ -8073,6 +8073,7 @@ S:      Supported
 F:      drivers/thermal/
 F:      include/linux/thermal.h
 F:      include/linux/cpu_cooling.h
+F:      Documentation/devicetree/bindings/thermal/
 
 THINGM BLINK(1) USB RGB LED DRIVER
 M:     Vivien Didelot <vivien.didelot@savoirfairelinux.com>
index 06b31fce1ff57fc406f156d6c3ed0f7a7abc9d3b..b5f4ef30f6e640acc501451a9ae7f9f268463da7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 VERSION = 3
 PATCHLEVEL = 10
-SUBLEVEL = 35
+SUBLEVEL = 36
 EXTRAVERSION =
 NAME = TOSSUG Baby Fish
 
index 095b21507b6a005130dc07a58464d15eaf1ceb94..60bd2748a7c92e0dfd8a36c2e0e9baabd355773c 100644 (file)
@@ -119,9 +119,10 @@ static inline void setup_node_to_cpumask_map(void) { }
 
 extern const struct cpumask *cpu_coregroup_mask(int cpu);
 
-#ifdef ENABLE_TOPO_DEFINES
 #define topology_physical_package_id(cpu)      (cpu_data(cpu).phys_proc_id)
 #define topology_core_id(cpu)                  (cpu_data(cpu).cpu_core_id)
+
+#ifdef ENABLE_TOPO_DEFINES
 #define topology_core_cpumask(cpu)             (per_cpu(cpu_core_map, cpu))
 #define topology_thread_cpumask(cpu)           (per_cpu(cpu_sibling_map, cpu))
 
index fc803ecbbce4a2d9d12a27d6a822f70a42b7732d..31262732db23b851a6570bbab43a49717762b26c 100644 (file)
@@ -899,7 +899,7 @@ bio_pageinc(struct bio *bio)
                 * but this has never been seen here.
                 */
                if (unlikely(PageCompound(page)))
-                       if (compound_trans_head(page) != page) {
+                       if (compound_head(page) != page) {
                                pr_crit("page tail used for block I/O\n");
                                BUG();
                        }
index c03b490bba813287d1d6368338743b450f34e687..1d3600aa4ca5d49c4e872cbb93316d7a9c793b8b 100644 (file)
@@ -27,6 +27,8 @@
 #include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/thermal.h>
 #include "lm75.h"
 
 
@@ -70,6 +72,7 @@ static const u8 LM75_REG_TEMP[3] = {
 /* Each client has this additional data */
 struct lm75_data {
        struct device           *hwmon_dev;
+       struct thermal_zone_device      *tz;
        struct mutex            update_lock;
        u8                      orig_conf;
        u8                      resolution;     /* In bits, between 9 and 12 */
@@ -90,22 +93,36 @@ static struct lm75_data *lm75_update_device(struct device *dev);
 
 /*-----------------------------------------------------------------------*/
 
+static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
+{
+       return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
+}
+
 /* sysfs attributes for hwmon */
 
+static int lm75_read_temp(void *dev, long *temp)
+{
+       struct lm75_data *data = lm75_update_device(dev);
+
+       if (IS_ERR(data))
+               return PTR_ERR(data);
+
+       *temp = lm75_reg_to_mc(data->temp[0], data->resolution);
+
+       return 0;
+}
+
 static ssize_t show_temp(struct device *dev, struct device_attribute *da,
                         char *buf)
 {
        struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
        struct lm75_data *data = lm75_update_device(dev);
-       long temp;
 
        if (IS_ERR(data))
                return PTR_ERR(data);
 
-       temp = ((data->temp[attr->index] >> (16 - data->resolution)) * 1000)
-              >> (data->resolution - 8);
-
-       return sprintf(buf, "%ld\n", temp);
+       return sprintf(buf, "%ld\n", lm75_reg_to_mc(data->temp[attr->index],
+                                                   data->resolution));
 }
 
 static ssize_t set_temp(struct device *dev, struct device_attribute *da,
@@ -271,6 +288,13 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
                goto exit_remove;
        }
 
+       data->tz = thermal_zone_of_sensor_register(&client->dev,
+                                                  0,
+                                                  &client->dev,
+                                                  lm75_read_temp, NULL);
+       if (IS_ERR(data->tz))
+               data->tz = NULL;
+
        dev_info(&client->dev, "%s: sensor '%s'\n",
                 dev_name(data->hwmon_dev), client->name);
 
@@ -285,6 +309,7 @@ static int lm75_remove(struct i2c_client *client)
 {
        struct lm75_data *data = i2c_get_clientdata(client);
 
+       thermal_zone_of_sensor_unregister(&client->dev, data->tz);
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &lm75_group);
        lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
index d7b47abf37fe88c259da4f3d7dd73a766af7b9f7..6748b4583e7b35c2381ecaa3afa29748247b4f1c 100644 (file)
@@ -27,6 +27,8 @@
 #include <linux/mutex.h>
 #include <linux/device.h>
 #include <linux/jiffies.h>
+#include <linux/thermal.h>
+#include <linux/of.h>
 
 #define        DRIVER_NAME "tmp102"
 
@@ -50,6 +52,7 @@
 
 struct tmp102 {
        struct device *hwmon_dev;
+       struct thermal_zone_device *tz;
        struct mutex lock;
        u16 config_orig;
        unsigned long last_update;
@@ -93,6 +96,15 @@ static struct tmp102 *tmp102_update_device(struct i2c_client *client)
        return tmp102;
 }
 
+static int tmp102_read_temp(void *dev, long *temp)
+{
+       struct tmp102 *tmp102 = tmp102_update_device(to_i2c_client(dev));
+
+       *temp = tmp102->temp[0];
+
+       return 0;
+}
+
 static ssize_t tmp102_show_temp(struct device *dev,
                                struct device_attribute *attr,
                                char *buf)
@@ -204,6 +216,12 @@ static int tmp102_probe(struct i2c_client *client,
                goto fail_remove_sysfs;
        }
 
+       tmp102->tz = thermal_zone_of_sensor_register(&client->dev, 0,
+                                                    &client->dev,
+                                                    tmp102_read_temp, NULL);
+       if (IS_ERR(tmp102->tz))
+               tmp102->tz = NULL;
+
        dev_info(&client->dev, "initialized\n");
 
        return 0;
@@ -220,6 +238,7 @@ static int tmp102_remove(struct i2c_client *client)
 {
        struct tmp102 *tmp102 = i2c_get_clientdata(client);
 
+       thermal_zone_of_sensor_unregister(&client->dev, tmp102->tz);
        hwmon_device_unregister(tmp102->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group);
 
index 888a81a7ea3d50b394260f5348d9155c1e331964..0aaea7ad6cee22116b269fdd9f200e66746c2a75 100644 (file)
@@ -410,7 +410,6 @@ static int cypress_set_input_params(struct input_dev *input,
        __clear_bit(REL_X, input->relbit);
        __clear_bit(REL_Y, input->relbit);
 
-       __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
        __set_bit(EV_KEY, input->evbit);
        __set_bit(BTN_LEFT, input->keybit);
        __set_bit(BTN_RIGHT, input->keybit);
index b2420ae19e148039147a33081a651d718e8d2e4d..c69c81608f43bde1596d7865cf67855c5b768dff 100644 (file)
@@ -265,11 +265,22 @@ static int synaptics_identify(struct psmouse *psmouse)
  * Read touchpad resolution and maximum reported coordinates
  * Resolution is left zero if touchpad does not support the query
  */
+
+static const int *quirk_min_max;
+
 static int synaptics_resolution(struct psmouse *psmouse)
 {
        struct synaptics_data *priv = psmouse->private;
        unsigned char resp[3];
 
+       if (quirk_min_max) {
+               priv->x_min = quirk_min_max[0];
+               priv->x_max = quirk_min_max[1];
+               priv->y_min = quirk_min_max[2];
+               priv->y_max = quirk_min_max[3];
+               return 0;
+       }
+
        if (SYN_ID_MAJOR(priv->identity) < 4)
                return 0;
 
@@ -1485,10 +1496,54 @@ static const struct dmi_system_id __initconst olpc_dmi_table[] = {
        { }
 };
 
+static const struct dmi_system_id min_max_dmi_table[] __initconst = {
+#if defined(CONFIG_DMI)
+       {
+               /* Lenovo ThinkPad Helix */
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Helix"),
+               },
+               .driver_data = (int []){1024, 5052, 2258, 4832},
+       },
+       {
+               /* Lenovo ThinkPad X240 */
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X240"),
+               },
+               .driver_data = (int []){1232, 5710, 1156, 4696},
+       },
+       {
+               /* Lenovo ThinkPad T440s */
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T440"),
+               },
+               .driver_data = (int []){1024, 5112, 2024, 4832},
+       },
+       {
+               /* Lenovo ThinkPad T540p */
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T540"),
+               },
+               .driver_data = (int []){1024, 5056, 2058, 4832},
+       },
+#endif
+       { }
+};
+
 void __init synaptics_module_init(void)
 {
+       const struct dmi_system_id *min_max_dmi;
+
        impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
        broken_olpc_ec = dmi_check_system(olpc_dmi_table);
+
+       min_max_dmi = dmi_first_match(min_max_dmi_table);
+       if (min_max_dmi)
+               quirk_min_max = min_max_dmi->driver_data;
 }
 
 static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
index 4c842c320c2ede9f2bf42d507ee5c91f00eef7e3..b604564dec5c9a5d8d154ac18a61c02341f77e5d 100644 (file)
@@ -67,7 +67,6 @@ struct mousedev {
        struct device dev;
        struct cdev cdev;
        bool exist;
-       bool is_mixdev;
 
        struct list_head mixdev_node;
        bool opened_by_mixdev;
@@ -77,6 +76,9 @@ struct mousedev {
        int old_x[4], old_y[4];
        int frac_dx, frac_dy;
        unsigned long touch;
+
+       int (*open_device)(struct mousedev *mousedev);
+       void (*close_device)(struct mousedev *mousedev);
 };
 
 enum mousedev_emul {
@@ -116,9 +118,6 @@ static unsigned char mousedev_imex_seq[] = { 0xf3, 200, 0xf3, 200, 0xf3, 80 };
 static struct mousedev *mousedev_mix;
 static LIST_HEAD(mousedev_mix_list);
 
-static void mixdev_open_devices(void);
-static void mixdev_close_devices(void);
-
 #define fx(i)  (mousedev->old_x[(mousedev->pkt_count - (i)) & 03])
 #define fy(i)  (mousedev->old_y[(mousedev->pkt_count - (i)) & 03])
 
@@ -428,9 +427,7 @@ static int mousedev_open_device(struct mousedev *mousedev)
        if (retval)
                return retval;
 
-       if (mousedev->is_mixdev)
-               mixdev_open_devices();
-       else if (!mousedev->exist)
+       if (!mousedev->exist)
                retval = -ENODEV;
        else if (!mousedev->open++) {
                retval = input_open_device(&mousedev->handle);
@@ -446,9 +443,7 @@ static void mousedev_close_device(struct mousedev *mousedev)
 {
        mutex_lock(&mousedev->mutex);
 
-       if (mousedev->is_mixdev)
-               mixdev_close_devices();
-       else if (mousedev->exist && !--mousedev->open)
+       if (mousedev->exist && !--mousedev->open)
                input_close_device(&mousedev->handle);
 
        mutex_unlock(&mousedev->mutex);
@@ -459,21 +454,29 @@ static void mousedev_close_device(struct mousedev *mousedev)
  * stream. Note that this function is called with mousedev_mix->mutex
  * held.
  */
-static void mixdev_open_devices(void)
+static int mixdev_open_devices(struct mousedev *mixdev)
 {
-       struct mousedev *mousedev;
+       int error;
+
+       error = mutex_lock_interruptible(&mixdev->mutex);
+       if (error)
+               return error;
 
-       if (mousedev_mix->open++)
-               return;
+       if (!mixdev->open++) {
+               struct mousedev *mousedev;
 
-       list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
-               if (!mousedev->opened_by_mixdev) {
-                       if (mousedev_open_device(mousedev))
-                               continue;
+               list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
+                       if (!mousedev->opened_by_mixdev) {
+                               if (mousedev_open_device(mousedev))
+                                       continue;
 
-                       mousedev->opened_by_mixdev = true;
+                               mousedev->opened_by_mixdev = true;
+                       }
                }
        }
+
+       mutex_unlock(&mixdev->mutex);
+       return 0;
 }
 
 /*
@@ -481,19 +484,22 @@ static void mixdev_open_devices(void)
  * device. Note that this function is called with mousedev_mix->mutex
  * held.
  */
-static void mixdev_close_devices(void)
+static void mixdev_close_devices(struct mousedev *mixdev)
 {
-       struct mousedev *mousedev;
+       mutex_lock(&mixdev->mutex);
 
-       if (--mousedev_mix->open)
-               return;
+       if (!--mixdev->open) {
+               struct mousedev *mousedev;
 
-       list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
-               if (mousedev->opened_by_mixdev) {
-                       mousedev->opened_by_mixdev = false;
-                       mousedev_close_device(mousedev);
+               list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
+                       if (mousedev->opened_by_mixdev) {
+                               mousedev->opened_by_mixdev = false;
+                               mousedev_close_device(mousedev);
+                       }
                }
        }
+
+       mutex_unlock(&mixdev->mutex);
 }
 
 
@@ -522,7 +528,7 @@ static int mousedev_release(struct inode *inode, struct file *file)
        mousedev_detach_client(mousedev, client);
        kfree(client);
 
-       mousedev_close_device(mousedev);
+       mousedev->close_device(mousedev);
 
        return 0;
 }
@@ -550,7 +556,7 @@ static int mousedev_open(struct inode *inode, struct file *file)
        client->mousedev = mousedev;
        mousedev_attach_client(mousedev, client);
 
-       error = mousedev_open_device(mousedev);
+       error = mousedev->open_device(mousedev);
        if (error)
                goto err_free_client;
 
@@ -861,16 +867,21 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
 
        if (mixdev) {
                dev_set_name(&mousedev->dev, "mice");
+
+               mousedev->open_device = mixdev_open_devices;
+               mousedev->close_device = mixdev_close_devices;
        } else {
                int dev_no = minor;
                /* Normalize device number if it falls into legacy range */
                if (dev_no < MOUSEDEV_MINOR_BASE + MOUSEDEV_MINORS)
                        dev_no -= MOUSEDEV_MINOR_BASE;
                dev_set_name(&mousedev->dev, "mouse%d", dev_no);
+
+               mousedev->open_device = mousedev_open_device;
+               mousedev->close_device = mousedev_close_device;
        }
 
        mousedev->exist = true;
-       mousedev->is_mixdev = mixdev;
        mousedev->handle.dev = input_get_device(dev);
        mousedev->handle.name = dev_name(&mousedev->dev);
        mousedev->handle.handler = handler;
@@ -919,7 +930,7 @@ static void mousedev_destroy(struct mousedev *mousedev)
        device_del(&mousedev->dev);
        mousedev_cleanup(mousedev);
        input_free_minor(MINOR(mousedev->dev.devt));
-       if (!mousedev->is_mixdev)
+       if (mousedev != mousedev_mix)
                input_unregister_handle(&mousedev->handle);
        put_device(&mousedev->dev);
 }
index 254f255204f96c7d4662ca9a244d31f4dc05a324..a602aeeb3acb09a6622540d306d09897e5714aa1 100644 (file)
 #define      MVNETA_GMAC_MAX_RX_SIZE_MASK        0x7ffc
 #define      MVNETA_GMAC0_PORT_ENABLE            BIT(0)
 #define MVNETA_GMAC_CTRL_2                       0x2c08
-#define      MVNETA_GMAC2_PSC_ENABLE             BIT(3)
+#define      MVNETA_GMAC2_PCS_ENABLE             BIT(3)
 #define      MVNETA_GMAC2_PORT_RGMII             BIT(4)
 #define      MVNETA_GMAC2_PORT_RESET             BIT(6)
 #define MVNETA_GMAC_STATUS                       0x2c10
@@ -655,7 +655,7 @@ static void mvneta_port_sgmii_config(struct mvneta_port *pp)
        u32 val;
 
        val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
-       val |= MVNETA_GMAC2_PSC_ENABLE;
+       val |= MVNETA_GMAC2_PCS_ENABLE;
        mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
 }
 
index 5e3c02554d99574f7fb8d62b130235789b1ab66d..e92e1dcb6e3fff525f14a4fc6b7efe2f66d8de28 100644 (file)
@@ -17,8 +17,30 @@ if THERMAL
 
 config THERMAL_HWMON
        bool
+       prompt "Expose thermal sensors as hwmon device"
        depends on HWMON=y || HWMON=THERMAL
        default y
+       help
+         In case a sensor is registered with the thermal
+         framework, this option will also register it
+         as a hwmon. The sensor will then have the common
+         hwmon sysfs interface.
+
+         Say 'Y' here if you want all thermal sensors to
+         have hwmon sysfs interface too.
+
+config THERMAL_OF
+       bool
+       prompt "APIs to parse thermal data out of device tree"
+       depends on OF
+       default y
+       help
+         This options provides helpers to add the support to
+         read and parse thermal data definitions out of the
+         device tree blob.
+
+         Say 'Y' here if you need to build thermal infrastructure
+         based on device tree.
 
 choice
        prompt "Default Thermal governor"
@@ -69,6 +91,7 @@ config THERMAL_GOV_USER_SPACE
 config CPU_THERMAL
        bool "generic cpu cooling support"
        depends on CPU_FREQ
+       depends on THERMAL_OF
        select CPU_FREQ_TABLE
        help
          This implements the generic cpu cooling mechanism through frequency
index c054d410ac3f001e7192f63c0bf65767d55b22b3..71f8eef49c1cd82851d5654bdecd8839fa065e68 100644 (file)
@@ -5,6 +5,10 @@
 obj-$(CONFIG_THERMAL)          += thermal_sys.o
 thermal_sys-y                  += thermal_core.o
 
+# interface to/from other layers providing sensors
+thermal_sys-$(CONFIG_THERMAL_HWMON)            += thermal_hwmon.o
+thermal_sys-$(CONFIG_THERMAL_OF)               += of-thermal.o
+
 # governors
 thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE)   += fair_share.o
 thermal_sys-$(CONFIG_THERMAL_GOV_STEP_WISE)    += step_wise.o
index c94bf2e5de629419c8e00e29f2cf23ac4507c365..78de7947afac39b7585977088010d407f81a8063 100644 (file)
@@ -415,18 +415,21 @@ static struct notifier_block thermal_cpufreq_notifier_block = {
 };
 
 /**
- * cpufreq_cooling_register - 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
  * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
  *
  * This interface function registers the cpufreq cooling device with the name
  * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
- * cooling devices.
+ * cooling devices. It also gives the opportunity to link the cooling device
+ * with a device tree node, in order to bind it via the thermal DT code.
  *
  * Return: a valid struct thermal_cooling_device pointer on success,
  * on failure, it returns a corresponding ERR_PTR().
  */
-struct thermal_cooling_device *
-cpufreq_cooling_register(const struct cpumask *clip_cpus)
+static struct thermal_cooling_device *
+__cpufreq_cooling_register(struct device_node *np,
+                          const struct cpumask *clip_cpus)
 {
        struct thermal_cooling_device *cool_dev;
        struct cpufreq_cooling_device *cpufreq_dev = NULL;
@@ -465,9 +468,9 @@ cpufreq_cooling_register(const struct cpumask *clip_cpus)
        snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d",
                 cpufreq_dev->id);
 
-       cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev,
-                                                  &cpufreq_cooling_ops);
-       if (!cool_dev) {
+       cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
+                                                     &cpufreq_cooling_ops);
+       if (IS_ERR(cool_dev)) {
                release_idr(&cpufreq_idr, cpufreq_dev->id);
                kfree(cpufreq_dev);
                return ERR_PTR(-EINVAL);
@@ -486,8 +489,49 @@ cpufreq_cooling_register(const struct cpumask *clip_cpus)
 
        return cool_dev;
 }
+
+/**
+ * cpufreq_cooling_register - function to create cpufreq cooling device.
+ * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
+ *
+ * This interface function registers the cpufreq cooling device with the name
+ * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
+ * cooling devices.
+ *
+ * Return: a valid struct thermal_cooling_device pointer on success,
+ * on failure, it returns a corresponding ERR_PTR().
+ */
+struct thermal_cooling_device *
+cpufreq_cooling_register(const struct cpumask *clip_cpus)
+{
+       return __cpufreq_cooling_register(NULL, clip_cpus);
+}
 EXPORT_SYMBOL_GPL(cpufreq_cooling_register);
 
+/**
+ * of_cpufreq_cooling_register - function to create cpufreq cooling device.
+ * @np: a valid struct device_node to the cooling device device tree node
+ * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
+ *
+ * This interface function registers the cpufreq cooling device with the name
+ * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
+ * cooling devices. Using this API, the cpufreq cooling device will be
+ * linked to the device tree node provided.
+ *
+ * Return: a valid struct thermal_cooling_device pointer on success,
+ * on failure, it returns a corresponding ERR_PTR().
+ */
+struct thermal_cooling_device *
+of_cpufreq_cooling_register(struct device_node *np,
+                           const struct cpumask *clip_cpus)
+{
+       if (!np)
+               return ERR_PTR(-EINVAL);
+
+       return __cpufreq_cooling_register(np, clip_cpus);
+}
+EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register);
+
 /**
  * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
  * @cdev: thermal cooling device pointer.
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
new file mode 100644 (file)
index 0000000..04b1be7
--- /dev/null
@@ -0,0 +1,849 @@
+/*
+ *  of-thermal.c - Generic Thermal Management device tree support.
+ *
+ *  Copyright (C) 2013 Texas Instruments
+ *  Copyright (C) 2013 Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ *
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#include <linux/thermal.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/string.h>
+
+#include "thermal_core.h"
+
+/***   Private data structures to represent thermal device tree data ***/
+
+/**
+ * struct __thermal_trip - representation of a point in temperature domain
+ * @np: pointer to struct device_node that this trip point was created from
+ * @temperature: temperature value in miliCelsius
+ * @hysteresis: relative hysteresis in miliCelsius
+ * @type: trip point type
+ */
+
+struct __thermal_trip {
+       struct device_node *np;
+       unsigned long int temperature;
+       unsigned long int hysteresis;
+       enum thermal_trip_type type;
+};
+
+/**
+ * struct __thermal_bind_param - a match between trip and cooling device
+ * @cooling_device: a pointer to identify the referred cooling device
+ * @trip_id: the trip point index
+ * @usage: the percentage (from 0 to 100) of cooling contribution
+ * @min: minimum cooling state used at this trip point
+ * @max: maximum cooling state used at this trip point
+ */
+
+struct __thermal_bind_params {
+       struct device_node *cooling_device;
+       unsigned int trip_id;
+       unsigned int usage;
+       unsigned long min;
+       unsigned long max;
+};
+
+/**
+ * struct __thermal_zone - internal representation of a thermal zone
+ * @mode: current thermal zone device mode (enabled/disabled)
+ * @passive_delay: polling interval while passive cooling is activated
+ * @polling_delay: zone polling interval
+ * @ntrips: number of trip points
+ * @trips: an array of trip points (0..ntrips - 1)
+ * @num_tbps: number of thermal bind params
+ * @tbps: an array of thermal bind params (0..num_tbps - 1)
+ * @sensor_data: sensor private data used while reading temperature and trend
+ * @get_temp: sensor callback to read temperature
+ * @get_trend: sensor callback to read temperature trend
+ */
+
+struct __thermal_zone {
+       enum thermal_device_mode mode;
+       int passive_delay;
+       int polling_delay;
+
+       /* trip data */
+       int ntrips;
+       struct __thermal_trip *trips;
+
+       /* cooling binding data */
+       int num_tbps;
+       struct __thermal_bind_params *tbps;
+
+       /* sensor interface */
+       void *sensor_data;
+       int (*get_temp)(void *, long *);
+       int (*get_trend)(void *, long *);
+};
+
+/***   DT thermal zone device callbacks   ***/
+
+static int of_thermal_get_temp(struct thermal_zone_device *tz,
+                              unsigned long *temp)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       if (!data->get_temp)
+               return -EINVAL;
+
+       return data->get_temp(data->sensor_data, temp);
+}
+
+static int of_thermal_get_trend(struct thermal_zone_device *tz, int trip,
+                               enum thermal_trend *trend)
+{
+       struct __thermal_zone *data = tz->devdata;
+       long dev_trend;
+       int r;
+
+       if (!data->get_trend)
+               return -EINVAL;
+
+       r = data->get_trend(data->sensor_data, &dev_trend);
+       if (r)
+               return r;
+
+       /* TODO: These intervals might have some thresholds, but in core code */
+       if (dev_trend > 0)
+               *trend = THERMAL_TREND_RAISING;
+       else if (dev_trend < 0)
+               *trend = THERMAL_TREND_DROPPING;
+       else
+               *trend = THERMAL_TREND_STABLE;
+
+       return 0;
+}
+
+static int of_thermal_bind(struct thermal_zone_device *thermal,
+                          struct thermal_cooling_device *cdev)
+{
+       struct __thermal_zone *data = thermal->devdata;
+       int i;
+
+       if (!data || IS_ERR(data))
+               return -ENODEV;
+
+       /* find where to bind */
+       for (i = 0; i < data->num_tbps; i++) {
+               struct __thermal_bind_params *tbp = data->tbps + i;
+
+               if (tbp->cooling_device == cdev->np) {
+                       int ret;
+
+                       ret = thermal_zone_bind_cooling_device(thermal,
+                                               tbp->trip_id, cdev,
+                                               tbp->min,
+                                               tbp->max);
+                       if (ret)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int of_thermal_unbind(struct thermal_zone_device *thermal,
+                            struct thermal_cooling_device *cdev)
+{
+       struct __thermal_zone *data = thermal->devdata;
+       int i;
+
+       if (!data || IS_ERR(data))
+               return -ENODEV;
+
+       /* find where to unbind */
+       for (i = 0; i < data->num_tbps; i++) {
+               struct __thermal_bind_params *tbp = data->tbps + i;
+
+               if (tbp->cooling_device == cdev->np) {
+                       int ret;
+
+                       ret = thermal_zone_unbind_cooling_device(thermal,
+                                               tbp->trip_id, cdev);
+                       if (ret)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int of_thermal_get_mode(struct thermal_zone_device *tz,
+                              enum thermal_device_mode *mode)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       *mode = data->mode;
+
+       return 0;
+}
+
+static int of_thermal_set_mode(struct thermal_zone_device *tz,
+                              enum thermal_device_mode mode)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       mutex_lock(&tz->lock);
+
+       if (mode == THERMAL_DEVICE_ENABLED)
+               tz->polling_delay = data->polling_delay;
+       else
+               tz->polling_delay = 0;
+
+       mutex_unlock(&tz->lock);
+
+       data->mode = mode;
+       thermal_zone_device_update(tz);
+
+       return 0;
+}
+
+static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,
+                                   enum thermal_trip_type *type)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       if (trip >= data->ntrips || trip < 0)
+               return -EDOM;
+
+       *type = data->trips[trip].type;
+
+       return 0;
+}
+
+static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip,
+                                   unsigned long *temp)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       if (trip >= data->ntrips || trip < 0)
+               return -EDOM;
+
+       *temp = data->trips[trip].temperature;
+
+       return 0;
+}
+
+static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
+                                   unsigned long temp)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       if (trip >= data->ntrips || trip < 0)
+               return -EDOM;
+
+       /* thermal framework should take care of data->mask & (1 << trip) */
+       data->trips[trip].temperature = temp;
+
+       return 0;
+}
+
+static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,
+                                   unsigned long *hyst)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       if (trip >= data->ntrips || trip < 0)
+               return -EDOM;
+
+       *hyst = data->trips[trip].hysteresis;
+
+       return 0;
+}
+
+static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,
+                                   unsigned long hyst)
+{
+       struct __thermal_zone *data = tz->devdata;
+
+       if (trip >= data->ntrips || trip < 0)
+               return -EDOM;
+
+       /* thermal framework should take care of data->mask & (1 << trip) */
+       data->trips[trip].hysteresis = hyst;
+
+       return 0;
+}
+
+static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
+                                   unsigned long *temp)
+{
+       struct __thermal_zone *data = tz->devdata;
+       int i;
+
+       for (i = 0; i < data->ntrips; i++)
+               if (data->trips[i].type == THERMAL_TRIP_CRITICAL) {
+                       *temp = data->trips[i].temperature;
+                       return 0;
+               }
+
+       return -EINVAL;
+}
+
+static struct thermal_zone_device_ops of_thermal_ops = {
+       .get_mode = of_thermal_get_mode,
+       .set_mode = of_thermal_set_mode,
+
+       .get_trip_type = of_thermal_get_trip_type,
+       .get_trip_temp = of_thermal_get_trip_temp,
+       .set_trip_temp = of_thermal_set_trip_temp,
+       .get_trip_hyst = of_thermal_get_trip_hyst,
+       .set_trip_hyst = of_thermal_set_trip_hyst,
+       .get_crit_temp = of_thermal_get_crit_temp,
+
+       .bind = of_thermal_bind,
+       .unbind = of_thermal_unbind,
+};
+
+/***   sensor API   ***/
+
+static struct thermal_zone_device *
+thermal_zone_of_add_sensor(struct device_node *zone,
+                          struct device_node *sensor, void *data,
+                          int (*get_temp)(void *, long *),
+                          int (*get_trend)(void *, long *))
+{
+       struct thermal_zone_device *tzd;
+       struct __thermal_zone *tz;
+
+       tzd = thermal_zone_get_zone_by_name(zone->name);
+       if (IS_ERR(tzd))
+               return ERR_PTR(-EPROBE_DEFER);
+
+       tz = tzd->devdata;
+
+       mutex_lock(&tzd->lock);
+       tz->get_temp = get_temp;
+       tz->get_trend = get_trend;
+       tz->sensor_data = data;
+
+       tzd->ops->get_temp = of_thermal_get_temp;
+       tzd->ops->get_trend = of_thermal_get_trend;
+       mutex_unlock(&tzd->lock);
+
+       return tzd;
+}
+
+/**
+ * thermal_zone_of_sensor_register - registers a sensor to a DT thermal zone
+ * @dev: a valid struct device pointer of a sensor device. Must contain
+ *       a valid .of_node, for the sensor node.
+ * @sensor_id: a sensor identifier, in case the sensor IP has more
+ *             than one sensors
+ * @data: a private pointer (owned by the caller) that will be passed
+ *        back, when a temperature reading is needed.
+ * @get_temp: a pointer to a function that reads the sensor temperature.
+ * @get_trend: a pointer to a function that reads the sensor temperature trend.
+ *
+ * This function will search the list of thermal zones described in device
+ * tree and look for the zone that refer to the sensor device pointed by
+ * @dev->of_node as temperature providers. For the zone pointing to the
+ * sensor node, the sensor will be added to the DT thermal zone device.
+ *
+ * The thermal zone temperature is provided by the @get_temp function
+ * pointer. When called, it will have the private pointer @data back.
+ *
+ * The thermal zone temperature trend is provided by the @get_trend function
+ * pointer. When called, it will have the private pointer @data back.
+ *
+ * TODO:
+ * 01 - This function must enqueue the new sensor instead of using
+ * it as the only source of temperature values.
+ *
+ * 02 - There must be a way to match the sensor with all thermal zones
+ * that refer to it.
+ *
+ * Return: On success returns a valid struct thermal_zone_device,
+ * otherwise, it returns a corresponding ERR_PTR(). Caller must
+ * check the return value with help of IS_ERR() helper.
+ */
+struct thermal_zone_device *
+thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
+                               void *data, int (*get_temp)(void *, long *),
+                               int (*get_trend)(void *, long *))
+{
+       struct device_node *np, *child, *sensor_np;
+
+       np = of_find_node_by_name(NULL, "thermal-zones");
+       if (!np)
+               return ERR_PTR(-ENODEV);
+
+       if (!dev || !dev->of_node)
+               return ERR_PTR(-EINVAL);
+
+       sensor_np = dev->of_node;
+
+       for_each_child_of_node(np, child) {
+               struct of_phandle_args sensor_specs;
+               int ret, id;
+
+               /* For now, thermal framework supports only 1 sensor per zone */
+               ret = of_parse_phandle_with_args(child, "thermal-sensors",
+                                                "#thermal-sensor-cells",
+                                                0, &sensor_specs);
+               if (ret)
+                       continue;
+
+               if (sensor_specs.args_count >= 1) {
+                       id = sensor_specs.args[0];
+                       WARN(sensor_specs.args_count > 1,
+                            "%s: too many cells in sensor specifier %d\n",
+                            sensor_specs.np->name, sensor_specs.args_count);
+               } else {
+                       id = 0;
+               }
+
+               if (sensor_specs.np == sensor_np && id == sensor_id) {
+                       of_node_put(np);
+                       return thermal_zone_of_add_sensor(child, sensor_np,
+                                                         data,
+                                                         get_temp,
+                                                         get_trend);
+               }
+       }
+       of_node_put(np);
+
+       return ERR_PTR(-ENODEV);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register);
+
+/**
+ * thermal_zone_of_sensor_unregister - unregisters a sensor from a DT thermal zone
+ * @dev: a valid struct device pointer of a sensor device. Must contain
+ *       a valid .of_node, for the sensor node.
+ * @tzd: a pointer to struct thermal_zone_device where the sensor is registered.
+ *
+ * This function removes the sensor callbacks and private data from the
+ * thermal zone device registered with thermal_zone_of_sensor_register()
+ * API. It will also silent the zone by remove the .get_temp() and .get_trend()
+ * thermal zone device callbacks.
+ *
+ * TODO: When the support to several sensors per zone is added, this
+ * function must search the sensor list based on @dev parameter.
+ *
+ */
+void thermal_zone_of_sensor_unregister(struct device *dev,
+                                      struct thermal_zone_device *tzd)
+{
+       struct __thermal_zone *tz;
+
+       if (!dev || !tzd || !tzd->devdata)
+               return;
+
+       tz = tzd->devdata;
+
+       /* no __thermal_zone, nothing to be done */
+       if (!tz)
+               return;
+
+       mutex_lock(&tzd->lock);
+       tzd->ops->get_temp = NULL;
+       tzd->ops->get_trend = NULL;
+
+       tz->get_temp = NULL;
+       tz->get_trend = NULL;
+       tz->sensor_data = NULL;
+       mutex_unlock(&tzd->lock);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister);
+
+/***   functions parsing device tree nodes   ***/
+
+/**
+ * thermal_of_populate_bind_params - parse and fill cooling map data
+ * @np: DT node containing a cooling-map node
+ * @__tbp: data structure to be filled with cooling map info
+ * @trips: array of thermal zone trip points
+ * @ntrips: number of trip points inside trips.
+ *
+ * This function parses a cooling-map type of node represented by
+ * @np parameter and fills the read data into @__tbp data structure.
+ * It needs the already parsed array of trip points of the thermal zone
+ * in consideration.
+ *
+ * Return: 0 on success, proper error code otherwise
+ */
+static int thermal_of_populate_bind_params(struct device_node *np,
+                                          struct __thermal_bind_params *__tbp,
+                                          struct __thermal_trip *trips,
+                                          int ntrips)
+{
+       struct of_phandle_args cooling_spec;
+       struct device_node *trip;
+       int ret, i;
+       u32 prop;
+
+       /* Default weight. Usage is optional */
+       __tbp->usage = 0;
+       ret = of_property_read_u32(np, "contribution", &prop);
+       if (ret == 0)
+               __tbp->usage = prop;
+
+       trip = of_parse_phandle(np, "trip", 0);
+       if (!trip) {
+               pr_err("missing trip property\n");
+               return -ENODEV;
+       }
+
+       /* match using device_node */
+       for (i = 0; i < ntrips; i++)
+               if (trip == trips[i].np) {
+                       __tbp->trip_id = i;
+                       break;
+               }
+
+       if (i == ntrips) {
+               ret = -ENODEV;
+               goto end;
+       }
+
+       ret = of_parse_phandle_with_args(np, "cooling-device", "#cooling-cells",
+                                        0, &cooling_spec);
+       if (ret < 0) {
+               pr_err("missing cooling_device property\n");
+               goto end;
+       }
+       __tbp->cooling_device = cooling_spec.np;
+       if (cooling_spec.args_count >= 2) { /* at least min and max */
+               __tbp->min = cooling_spec.args[0];
+               __tbp->max = cooling_spec.args[1];
+       } else {
+               pr_err("wrong reference to cooling device, missing limits\n");
+       }
+
+end:
+       of_node_put(trip);
+
+       return ret;
+}
+
+/**
+ * It maps 'enum thermal_trip_type' found in include/linux/thermal.h
+ * into the device tree binding of 'trip', property type.
+ */
+static const char * const trip_types[] = {
+       [THERMAL_TRIP_ACTIVE]   = "active",
+       [THERMAL_TRIP_PASSIVE]  = "passive",
+       [THERMAL_TRIP_HOT]      = "hot",
+       [THERMAL_TRIP_CRITICAL] = "critical",
+};
+
+/**
+ * thermal_of_get_trip_type - Get phy mode for given device_node
+ * @np:        Pointer to the given device_node
+ * @type: Pointer to resulting trip type
+ *
+ * The function gets trip type string from property 'type',
+ * and store its index in trip_types table in @type,
+ *
+ * Return: 0 on success, or errno in error case.
+ */
+static int thermal_of_get_trip_type(struct device_node *np,
+                                   enum thermal_trip_type *type)
+{
+       const char *t;
+       int err, i;
+
+       err = of_property_read_string(np, "type", &t);
+       if (err < 0)
+               return err;
+
+       for (i = 0; i < ARRAY_SIZE(trip_types); i++)
+               if (!strcasecmp(t, trip_types[i])) {
+                       *type = i;
+                       return 0;
+               }
+
+       return -ENODEV;
+}
+
+/**
+ * thermal_of_populate_trip - parse and fill one trip point data
+ * @np: DT node containing a trip point node
+ * @trip: trip point data structure to be filled up
+ *
+ * This function parses a trip point type of node represented by
+ * @np parameter and fills the read data into @trip data structure.
+ *
+ * Return: 0 on success, proper error code otherwise
+ */
+static int thermal_of_populate_trip(struct device_node *np,
+                                   struct __thermal_trip *trip)
+{
+       int prop;
+       int ret;
+
+       ret = of_property_read_u32(np, "temperature", &prop);
+       if (ret < 0) {
+               pr_err("missing temperature property\n");
+               return ret;
+       }
+       trip->temperature = prop;
+
+       ret = of_property_read_u32(np, "hysteresis", &prop);
+       if (ret < 0) {
+               pr_err("missing hysteresis property\n");
+               return ret;
+       }
+       trip->hysteresis = prop;
+
+       ret = thermal_of_get_trip_type(np, &trip->type);
+       if (ret < 0) {
+               pr_err("wrong trip type property\n");
+               return ret;
+       }
+
+       /* Required for cooling map matching */
+       trip->np = np;
+
+       return 0;
+}
+
+/**
+ * thermal_of_build_thermal_zone - parse and fill one thermal zone data
+ * @np: DT node containing a thermal zone node
+ *
+ * This function parses a thermal zone type of node represented by
+ * @np parameter and fills the read data into a __thermal_zone data structure
+ * and return this pointer.
+ *
+ * TODO: Missing properties to parse: thermal-sensor-names and coefficients
+ *
+ * Return: On success returns a valid struct __thermal_zone,
+ * otherwise, it returns a corresponding ERR_PTR(). Caller must
+ * check the return value with help of IS_ERR() helper.
+ */
+static struct __thermal_zone *
+thermal_of_build_thermal_zone(struct device_node *np)
+{
+       struct device_node *child = NULL, *gchild;
+       struct __thermal_zone *tz;
+       int ret, i;
+       u32 prop;
+
+       if (!np) {
+               pr_err("no thermal zone np\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       tz = kzalloc(sizeof(*tz), GFP_KERNEL);
+       if (!tz)
+               return ERR_PTR(-ENOMEM);
+
+       ret = of_property_read_u32(np, "polling-delay-passive", &prop);
+       if (ret < 0) {
+               pr_err("missing polling-delay-passive property\n");
+               goto free_tz;
+       }
+       tz->passive_delay = prop;
+
+       ret = of_property_read_u32(np, "polling-delay", &prop);
+       if (ret < 0) {
+               pr_err("missing polling-delay property\n");
+               goto free_tz;
+       }
+       tz->polling_delay = prop;
+
+       /* trips */
+       child = of_get_child_by_name(np, "trips");
+
+       /* No trips provided */
+       if (!child)
+               goto finish;
+
+       tz->ntrips = of_get_child_count(child);
+       if (tz->ntrips == 0) /* must have at least one child */
+               goto finish;
+
+       tz->trips = kzalloc(tz->ntrips * sizeof(*tz->trips), GFP_KERNEL);
+       if (!tz->trips) {
+               ret = -ENOMEM;
+               goto free_tz;
+       }
+
+       i = 0;
+       for_each_child_of_node(child, gchild) {
+               ret = thermal_of_populate_trip(gchild, &tz->trips[i++]);
+               if (ret)
+                       goto free_trips;
+       }
+
+       of_node_put(child);
+
+       /* cooling-maps */
+       child = of_get_child_by_name(np, "cooling-maps");
+
+       /* cooling-maps not provided */
+       if (!child)
+               goto finish;
+
+       tz->num_tbps = of_get_child_count(child);
+       if (tz->num_tbps == 0)
+               goto finish;
+
+       tz->tbps = kzalloc(tz->num_tbps * sizeof(*tz->tbps), GFP_KERNEL);
+       if (!tz->tbps) {
+               ret = -ENOMEM;
+               goto free_trips;
+       }
+
+       i = 0;
+       for_each_child_of_node(child, gchild)
+               ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++],
+                                                     tz->trips, tz->ntrips);
+               if (ret)
+                       goto free_tbps;
+
+finish:
+       of_node_put(child);
+       tz->mode = THERMAL_DEVICE_DISABLED;
+
+       return tz;
+
+free_tbps:
+       kfree(tz->tbps);
+free_trips:
+       kfree(tz->trips);
+free_tz:
+       kfree(tz);
+       of_node_put(child);
+
+       return ERR_PTR(ret);
+}
+
+static inline void of_thermal_free_zone(struct __thermal_zone *tz)
+{
+       kfree(tz->tbps);
+       kfree(tz->trips);
+       kfree(tz);
+}
+
+/**
+ * of_parse_thermal_zones - parse device tree thermal data
+ *
+ * Initialization function that can be called by machine initialization
+ * code to parse thermal data and populate the thermal framework
+ * with hardware thermal zones info. This function only parses thermal zones.
+ * Cooling devices and sensor devices nodes are supposed to be parsed
+ * by their respective drivers.
+ *
+ * Return: 0 on success, proper error code otherwise
+ *
+ */
+int __init of_parse_thermal_zones(void)
+{
+       struct device_node *np, *child;
+       struct __thermal_zone *tz;
+       struct thermal_zone_device_ops *ops;
+
+       np = of_find_node_by_name(NULL, "thermal-zones");
+       if (!np) {
+               pr_debug("unable to find thermal zones\n");
+               return 0; /* Run successfully on systems without thermal DT */
+       }
+
+       for_each_child_of_node(np, child) {
+               struct thermal_zone_device *zone;
+               struct thermal_zone_params *tzp;
+
+               tz = thermal_of_build_thermal_zone(child);
+               if (IS_ERR(tz)) {
+                       pr_err("failed to build thermal zone %s: %ld\n",
+                              child->name,
+                              PTR_ERR(tz));
+                       continue;
+               }
+
+               ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL);
+               if (!ops)
+                       goto exit_free;
+
+               tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
+               if (!tzp) {
+                       kfree(ops);
+                       goto exit_free;
+               }
+
+               /* No hwmon because there might be hwmon drivers registering */
+               tzp->no_hwmon = true;
+
+               zone = thermal_zone_device_register(child->name, tz->ntrips,
+                                                   0, tz,
+                                                   ops, tzp,
+                                                   tz->passive_delay,
+                                                   tz->polling_delay);
+               if (IS_ERR(zone)) {
+                       pr_err("Failed to build %s zone %ld\n", child->name,
+                              PTR_ERR(zone));
+                       kfree(tzp);
+                       kfree(ops);
+                       of_thermal_free_zone(tz);
+                       /* attempting to build remaining zones still */
+               }
+       }
+
+       return 0;
+
+exit_free:
+       of_thermal_free_zone(tz);
+
+       /* no memory available, so free what we have built */
+       of_thermal_destroy_zones();
+
+       return -ENOMEM;
+}
+
+/**
+ * of_thermal_destroy_zones - remove all zones parsed and allocated resources
+ *
+ * Finds all zones parsed and added to the thermal framework and remove them
+ * from the system, together with their resources.
+ *
+ */
+void of_thermal_destroy_zones(void)
+{
+       struct device_node *np, *child;
+
+       np = of_find_node_by_name(NULL, "thermal-zones");
+       if (!np) {
+               pr_err("unable to find thermal zones\n");
+               return;
+       }
+
+       for_each_child_of_node(np, child) {
+               struct thermal_zone_device *zone;
+
+               zone = thermal_zone_get_zone_by_name(child->name);
+               if (IS_ERR(zone))
+                       continue;
+
+               thermal_zone_device_unregister(zone);
+               kfree(zone->tzp);
+               kfree(zone->ops);
+               of_thermal_free_zone(zone->devdata);
+       }
+}
index 4d4ddae1a99183cee9705f24e7acdc91cde62cc6..c83a3097ef908207e654de29d989189fc537f249 100644 (file)
@@ -53,6 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
        unsigned long cur_state;
 
        cdev->ops->get_cur_state(cdev, &cur_state);
+       dev_dbg(&cdev->device, "cur_state=%ld\n", cur_state);
 
        switch (trend) {
        case THERMAL_TREND_RAISING:
@@ -124,6 +125,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
        if (tz->temperature >= trip_temp)
                throttle = true;
 
+       dev_dbg(&tz->device, "Trip%d[type=%d,temp=%ld]:trend=%d,throttle=%d\n",
+                               trip, trip_type, trip_temp, trend, throttle);
+
        mutex_lock(&tz->lock);
 
        list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
@@ -132,6 +136,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
 
                old_target = instance->target;
                instance->target = get_target_state(instance, trend, throttle);
+               dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n",
+                                       old_target, (int)instance->target);
 
                /* Activate a passive thermal instance */
                if (old_target == THERMAL_NO_TARGET &&
index d755440791b7ce0a01d3e186e423ed6769fcc8be..83cc99bb5aeb71076155a05649bb0b397bbf0bd8 100644 (file)
 #include <linux/idr.h>
 #include <linux/thermal.h>
 #include <linux/reboot.h>
+#include <linux/string.h>
+#include <linux/of.h>
 #include <net/netlink.h>
 #include <net/genetlink.h>
 
 #include "thermal_core.h"
+#include "thermal_hwmon.h"
 
 MODULE_AUTHOR("Zhang Rui");
 MODULE_DESCRIPTION("Generic thermal management sysfs support");
@@ -388,7 +391,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
        enum thermal_trip_type type;
 #endif
 
-       if (!tz || IS_ERR(tz))
+       if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
                goto exit;
 
        mutex_lock(&tz->lock);
@@ -435,12 +438,18 @@ static void update_temperature(struct thermal_zone_device *tz)
        tz->last_temperature = tz->temperature;
        tz->temperature = temp;
        mutex_unlock(&tz->lock);
+
+       dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n",
+                               tz->last_temperature, tz->temperature);
 }
 
 void thermal_zone_device_update(struct thermal_zone_device *tz)
 {
        int count;
 
+       if (!tz->ops->get_temp)
+               return;
+
        update_temperature(tz);
 
        for (count = 0; count < tz->trips; count++)
@@ -854,260 +863,6 @@ thermal_cooling_device_trip_point_show(struct device *dev,
 
 /* Device management */
 
-#if defined(CONFIG_THERMAL_HWMON)
-
-/* hwmon sys I/F */
-#include <linux/hwmon.h>
-
-/* thermal zone devices with the same type share one hwmon device */
-struct thermal_hwmon_device {
-       char type[THERMAL_NAME_LENGTH];
-       struct device *device;
-       int count;
-       struct list_head tz_list;
-       struct list_head node;
-};
-
-struct thermal_hwmon_attr {
-       struct device_attribute attr;
-       char name[16];
-};
-
-/* one temperature input for each thermal zone */
-struct thermal_hwmon_temp {
-       struct list_head hwmon_node;
-       struct thermal_zone_device *tz;
-       struct thermal_hwmon_attr temp_input;   /* hwmon sys attr */
-       struct thermal_hwmon_attr temp_crit;    /* hwmon sys attr */
-};
-
-static LIST_HEAD(thermal_hwmon_list);
-
-static ssize_t
-name_show(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
-       return sprintf(buf, "%s\n", hwmon->type);
-}
-static DEVICE_ATTR(name, 0444, name_show, NULL);
-
-static ssize_t
-temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       long temperature;
-       int ret;
-       struct thermal_hwmon_attr *hwmon_attr
-                       = container_of(attr, struct thermal_hwmon_attr, attr);
-       struct thermal_hwmon_temp *temp
-                       = container_of(hwmon_attr, struct thermal_hwmon_temp,
-                                      temp_input);
-       struct thermal_zone_device *tz = temp->tz;
-
-       ret = thermal_zone_get_temp(tz, &temperature);
-
-       if (ret)
-               return ret;
-
-       return sprintf(buf, "%ld\n", temperature);
-}
-
-static ssize_t
-temp_crit_show(struct device *dev, struct device_attribute *attr,
-               char *buf)
-{
-       struct thermal_hwmon_attr *hwmon_attr
-                       = container_of(attr, struct thermal_hwmon_attr, attr);
-       struct thermal_hwmon_temp *temp
-                       = container_of(hwmon_attr, struct thermal_hwmon_temp,
-                                      temp_crit);
-       struct thermal_zone_device *tz = temp->tz;
-       long temperature;
-       int ret;
-
-       ret = tz->ops->get_trip_temp(tz, 0, &temperature);
-       if (ret)
-               return ret;
-
-       return sprintf(buf, "%ld\n", temperature);
-}
-
-
-static struct thermal_hwmon_device *
-thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)
-{
-       struct thermal_hwmon_device *hwmon;
-
-       mutex_lock(&thermal_list_lock);
-       list_for_each_entry(hwmon, &thermal_hwmon_list, node)
-               if (!strcmp(hwmon->type, tz->type)) {
-                       mutex_unlock(&thermal_list_lock);
-                       return hwmon;
-               }
-       mutex_unlock(&thermal_list_lock);
-
-       return NULL;
-}
-
-/* Find the temperature input matching a given thermal zone */
-static struct thermal_hwmon_temp *
-thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
-                         const struct thermal_zone_device *tz)
-{
-       struct thermal_hwmon_temp *temp;
-
-       mutex_lock(&thermal_list_lock);
-       list_for_each_entry(temp, &hwmon->tz_list, hwmon_node)
-               if (temp->tz == tz) {
-                       mutex_unlock(&thermal_list_lock);
-                       return temp;
-               }
-       mutex_unlock(&thermal_list_lock);
-
-       return NULL;
-}
-
-static int
-thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
-{
-       struct thermal_hwmon_device *hwmon;
-       struct thermal_hwmon_temp *temp;
-       int new_hwmon_device = 1;
-       int result;
-
-       hwmon = thermal_hwmon_lookup_by_type(tz);
-       if (hwmon) {
-               new_hwmon_device = 0;
-               goto register_sys_interface;
-       }
-
-       hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL);
-       if (!hwmon)
-               return -ENOMEM;
-
-       INIT_LIST_HEAD(&hwmon->tz_list);
-       strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
-       hwmon->device = hwmon_device_register(NULL);
-       if (IS_ERR(hwmon->device)) {
-               result = PTR_ERR(hwmon->device);
-               goto free_mem;
-       }
-       dev_set_drvdata(hwmon->device, hwmon);
-       result = device_create_file(hwmon->device, &dev_attr_name);
-       if (result)
-               goto free_mem;
-
- register_sys_interface:
-       temp = kzalloc(sizeof(struct thermal_hwmon_temp), GFP_KERNEL);
-       if (!temp) {
-               result = -ENOMEM;
-               goto unregister_name;
-       }
-
-       temp->tz = tz;
-       hwmon->count++;
-
-       snprintf(temp->temp_input.name, sizeof(temp->temp_input.name),
-                "temp%d_input", hwmon->count);
-       temp->temp_input.attr.attr.name = temp->temp_input.name;
-       temp->temp_input.attr.attr.mode = 0444;
-       temp->temp_input.attr.show = temp_input_show;
-       sysfs_attr_init(&temp->temp_input.attr.attr);
-       result = device_create_file(hwmon->device, &temp->temp_input.attr);
-       if (result)
-               goto free_temp_mem;
-
-       if (tz->ops->get_crit_temp) {
-               unsigned long temperature;
-               if (!tz->ops->get_crit_temp(tz, &temperature)) {
-                       snprintf(temp->temp_crit.name,
-                                sizeof(temp->temp_crit.name),
-                               "temp%d_crit", hwmon->count);
-                       temp->temp_crit.attr.attr.name = temp->temp_crit.name;
-                       temp->temp_crit.attr.attr.mode = 0444;
-                       temp->temp_crit.attr.show = temp_crit_show;
-                       sysfs_attr_init(&temp->temp_crit.attr.attr);
-                       result = device_create_file(hwmon->device,
-                                                   &temp->temp_crit.attr);
-                       if (result)
-                               goto unregister_input;
-               }
-       }
-
-       mutex_lock(&thermal_list_lock);
-       if (new_hwmon_device)
-               list_add_tail(&hwmon->node, &thermal_hwmon_list);
-       list_add_tail(&temp->hwmon_node, &hwmon->tz_list);
-       mutex_unlock(&thermal_list_lock);
-
-       return 0;
-
- unregister_input:
-       device_remove_file(hwmon->device, &temp->temp_input.attr);
- free_temp_mem:
-       kfree(temp);
- unregister_name:
-       if (new_hwmon_device) {
-               device_remove_file(hwmon->device, &dev_attr_name);
-               hwmon_device_unregister(hwmon->device);
-       }
- free_mem:
-       if (new_hwmon_device)
-               kfree(hwmon);
-
-       return result;
-}
-
-static void
-thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
-{
-       struct thermal_hwmon_device *hwmon;
-       struct thermal_hwmon_temp *temp;
-
-       hwmon = thermal_hwmon_lookup_by_type(tz);
-       if (unlikely(!hwmon)) {
-               /* Should never happen... */
-               dev_dbg(&tz->device, "hwmon device lookup failed!\n");
-               return;
-       }
-
-       temp = thermal_hwmon_lookup_temp(hwmon, tz);
-       if (unlikely(!temp)) {
-               /* Should never happen... */
-               dev_dbg(&tz->device, "temperature input lookup failed!\n");
-               return;
-       }
-
-       device_remove_file(hwmon->device, &temp->temp_input.attr);
-       if (tz->ops->get_crit_temp)
-               device_remove_file(hwmon->device, &temp->temp_crit.attr);
-
-       mutex_lock(&thermal_list_lock);
-       list_del(&temp->hwmon_node);
-       kfree(temp);
-       if (!list_empty(&hwmon->tz_list)) {
-               mutex_unlock(&thermal_list_lock);
-               return;
-       }
-       list_del(&hwmon->node);
-       mutex_unlock(&thermal_list_lock);
-
-       device_remove_file(hwmon->device, &dev_attr_name);
-       hwmon_device_unregister(hwmon->device);
-       kfree(hwmon);
-}
-#else
-static int
-thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
-{
-       return 0;
-}
-
-static void
-thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
-{
-}
-#endif
-
 /**
  * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
  * @tz:                pointer to struct thermal_zone_device
@@ -1287,7 +1042,8 @@ static struct class thermal_class = {
 };
 
 /**
- * thermal_cooling_device_register() - register a new thermal cooling device
+ * __thermal_cooling_device_register() - register a new thermal cooling device
+ * @np:                a pointer to a device tree node.
  * @type:      the thermal cooling device type.
  * @devdata:   device private data.
  * @ops:               standard thermal cooling devices callbacks.
@@ -1295,13 +1051,16 @@ static struct class thermal_class = {
  * This interface function adds a new thermal cooling device (fan/processor/...)
  * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
  * to all the thermal zone devices registered at the same time.
+ * It also gives the opportunity to link the cooling device to a device tree
+ * node, so that it can be bound to a thermal zone created out of device tree.
  *
  * Return: a pointer to the created struct thermal_cooling_device or an
  * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
  */
-struct thermal_cooling_device *
-thermal_cooling_device_register(char *type, void *devdata,
-                               const struct thermal_cooling_device_ops *ops)
+static struct thermal_cooling_device *
+__thermal_cooling_device_register(struct device_node *np,
+                                 char *type, void *devdata,
+                                 const struct thermal_cooling_device_ops *ops)
 {
        struct thermal_cooling_device *cdev;
        int result;
@@ -1326,6 +1085,7 @@ thermal_cooling_device_register(char *type, void *devdata,
        strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
        mutex_init(&cdev->lock);
        INIT_LIST_HEAD(&cdev->thermal_instances);
+       cdev->np = np;
        cdev->ops = ops;
        cdev->updated = true;
        cdev->device.class = &thermal_class;
@@ -1368,8 +1128,52 @@ unregister:
        device_unregister(&cdev->device);
        return ERR_PTR(result);
 }
+
+/**
+ * thermal_cooling_device_register() - register a new thermal cooling device
+ * @type:      the thermal cooling device type.
+ * @devdata:   device private data.
+ * @ops:               standard thermal cooling devices callbacks.
+ *
+ * This interface function adds a new thermal cooling device (fan/processor/...)
+ * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
+ * to all the thermal zone devices registered at the same time.
+ *
+ * Return: a pointer to the created struct thermal_cooling_device or an
+ * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
+ */
+struct thermal_cooling_device *
+thermal_cooling_device_register(char *type, void *devdata,
+                               const struct thermal_cooling_device_ops *ops)
+{
+       return __thermal_cooling_device_register(NULL, type, devdata, ops);
+}
 EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
 
+/**
+ * thermal_of_cooling_device_register() - register an OF thermal cooling device
+ * @np:                a pointer to a device tree node.
+ * @type:      the thermal cooling device type.
+ * @devdata:   device private data.
+ * @ops:               standard thermal cooling devices callbacks.
+ *
+ * This function will register a cooling device with device tree node reference.
+ * This interface function adds a new thermal cooling device (fan/processor/...)
+ * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
+ * to all the thermal zone devices registered at the same time.
+ *
+ * Return: a pointer to the created struct thermal_cooling_device or an
+ * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
+ */
+struct thermal_cooling_device *
+thermal_of_cooling_device_register(struct device_node *np,
+                                  char *type, void *devdata,
+                                  const struct thermal_cooling_device_ops *ops)
+{
+       return __thermal_cooling_device_register(np, type, devdata, ops);
+}
+EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);
+
 /**
  * thermal_cooling_device_unregister - removes the registered thermal cooling device
  * @cdev:      the thermal cooling device to remove.
@@ -1442,6 +1246,8 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
        mutex_lock(&cdev->lock);
        /* Make sure cdev enters the deepest cooling state */
        list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
+               dev_dbg(&cdev->device, "zone%d->target=%lu\n",
+                               instance->tz->id, instance->target);
                if (instance->target == THERMAL_NO_TARGET)
                        continue;
                if (instance->target > target)
@@ -1450,6 +1256,7 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
        mutex_unlock(&cdev->lock);
        cdev->ops->set_cur_state(cdev, target);
        cdev->updated = true;
+       dev_dbg(&cdev->device, "set to state %lu\n", target);
 }
 EXPORT_SYMBOL(thermal_cdev_update);
 
@@ -1605,7 +1412,7 @@ static void remove_trip_attrs(struct thermal_zone_device *tz)
  */
 struct thermal_zone_device *thermal_zone_device_register(const char *type,
        int trips, int mask, void *devdata,
-       const struct thermal_zone_device_ops *ops,
+       struct thermal_zone_device_ops *ops,
        const struct thermal_zone_params *tzp,
        int passive_delay, int polling_delay)
 {
@@ -1621,7 +1428,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
        if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
                return ERR_PTR(-EINVAL);
 
-       if (!ops || !ops->get_temp)
+       if (!ops)
                return ERR_PTR(-EINVAL);
 
        if (trips > 0 && !ops->get_trip_type)
@@ -1710,9 +1517,11 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 
        mutex_unlock(&thermal_governor_lock);
 
-       result = thermal_add_hwmon_sysfs(tz);
-       if (result)
-               goto unregister;
+       if (!tz->tzp || !tz->tzp->no_hwmon) {
+               result = thermal_add_hwmon_sysfs(tz);
+               if (result)
+                       goto unregister;
+       }
 
        mutex_lock(&thermal_list_lock);
        list_add_tail(&tz->node, &thermal_tz_list);
@@ -1723,6 +1532,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 
        INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check);
 
+       if (!tz->ops->get_temp)
+               thermal_zone_device_set_polling(tz, 0);
+
        thermal_zone_device_update(tz);
 
        if (!result)
@@ -1980,8 +1792,14 @@ static int __init thermal_init(void)
        if (result)
                goto unregister_class;
 
+       result = of_parse_thermal_zones();
+       if (result)
+               goto exit_netlink;
+
        return 0;
 
+exit_netlink:
+       genetlink_exit();
 unregister_governors:
        thermal_unregister_governors();
 unregister_class:
@@ -1997,6 +1815,7 @@ error:
 
 static void __exit thermal_exit(void)
 {
+       of_thermal_destroy_zones();
        genetlink_exit();
        class_unregister(&thermal_class);
        thermal_unregister_governors();
index 7cf2f66262517a0bfcc2727dee8232edcd2ec6d7..3db339fb636f375f9be670bd6f827776ed8d017d 100644 (file)
@@ -77,4 +77,13 @@ 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 */
 
+/* device tree support */
+#ifdef CONFIG_THERMAL_OF
+int of_parse_thermal_zones(void);
+void of_thermal_destroy_zones(void);
+#else
+static inline int of_parse_thermal_zones(void) { return 0; }
+static inline void of_thermal_destroy_zones(void) { }
+#endif
+
 #endif /* __THERMAL_CORE_H__ */
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
new file mode 100644 (file)
index 0000000..fdb0719
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ *  thermal_hwmon.c - Generic Thermal Management hwmon support.
+ *
+ *  Code based on Intel thermal_core.c. Copyrights of the original code:
+ *  Copyright (C) 2008 Intel Corp
+ *  Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
+ *  Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
+ *
+ *  Copyright (C) 2013 Texas Instruments
+ *  Copyright (C) 2013 Eduardo Valentin <eduardo.valentin@ti.com>
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#include <linux/hwmon.h>
+#include <linux/thermal.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include "thermal_hwmon.h"
+
+/* hwmon sys I/F */
+/* thermal zone devices with the same type share one hwmon device */
+struct thermal_hwmon_device {
+       char type[THERMAL_NAME_LENGTH];
+       struct device *device;
+       int count;
+       struct list_head tz_list;
+       struct list_head node;
+};
+
+struct thermal_hwmon_attr {
+       struct device_attribute attr;
+       char name[16];
+};
+
+/* one temperature input for each thermal zone */
+struct thermal_hwmon_temp {
+       struct list_head hwmon_node;
+       struct thermal_zone_device *tz;
+       struct thermal_hwmon_attr temp_input;   /* hwmon sys attr */
+       struct thermal_hwmon_attr temp_crit;    /* hwmon sys attr */
+};
+
+static LIST_HEAD(thermal_hwmon_list);
+
+static DEFINE_MUTEX(thermal_hwmon_list_lock);
+
+static ssize_t
+name_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
+       return sprintf(buf, "%s\n", hwmon->type);
+}
+static DEVICE_ATTR(name, 0444, name_show, NULL);
+
+static ssize_t
+temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       long temperature;
+       int ret;
+       struct thermal_hwmon_attr *hwmon_attr
+                       = container_of(attr, struct thermal_hwmon_attr, attr);
+       struct thermal_hwmon_temp *temp
+                       = container_of(hwmon_attr, struct thermal_hwmon_temp,
+                                      temp_input);
+       struct thermal_zone_device *tz = temp->tz;
+
+       ret = thermal_zone_get_temp(tz, &temperature);
+
+       if (ret)
+               return ret;
+
+       return sprintf(buf, "%ld\n", temperature);
+}
+
+static ssize_t
+temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct thermal_hwmon_attr *hwmon_attr
+                       = container_of(attr, struct thermal_hwmon_attr, attr);
+       struct thermal_hwmon_temp *temp
+                       = container_of(hwmon_attr, struct thermal_hwmon_temp,
+                                      temp_crit);
+       struct thermal_zone_device *tz = temp->tz;
+       long temperature;
+       int ret;
+
+       ret = tz->ops->get_trip_temp(tz, 0, &temperature);
+       if (ret)
+               return ret;
+
+       return sprintf(buf, "%ld\n", temperature);
+}
+
+
+static struct thermal_hwmon_device *
+thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)
+{
+       struct thermal_hwmon_device *hwmon;
+
+       mutex_lock(&thermal_hwmon_list_lock);
+       list_for_each_entry(hwmon, &thermal_hwmon_list, node)
+               if (!strcmp(hwmon->type, tz->type)) {
+                       mutex_unlock(&thermal_hwmon_list_lock);
+                       return hwmon;
+               }
+       mutex_unlock(&thermal_hwmon_list_lock);
+
+       return NULL;
+}
+
+/* Find the temperature input matching a given thermal zone */
+static struct thermal_hwmon_temp *
+thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
+                         const struct thermal_zone_device *tz)
+{
+       struct thermal_hwmon_temp *temp;
+
+       mutex_lock(&thermal_hwmon_list_lock);
+       list_for_each_entry(temp, &hwmon->tz_list, hwmon_node)
+               if (temp->tz == tz) {
+                       mutex_unlock(&thermal_hwmon_list_lock);
+                       return temp;
+               }
+       mutex_unlock(&thermal_hwmon_list_lock);
+
+       return NULL;
+}
+
+int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
+{
+       struct thermal_hwmon_device *hwmon;
+       struct thermal_hwmon_temp *temp;
+       int new_hwmon_device = 1;
+       int result;
+
+       hwmon = thermal_hwmon_lookup_by_type(tz);
+       if (hwmon) {
+               new_hwmon_device = 0;
+               goto register_sys_interface;
+       }
+
+       hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL);
+       if (!hwmon)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&hwmon->tz_list);
+       strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
+       hwmon->device = hwmon_device_register(NULL);
+       if (IS_ERR(hwmon->device)) {
+               result = PTR_ERR(hwmon->device);
+               goto free_mem;
+       }
+       dev_set_drvdata(hwmon->device, hwmon);
+       result = device_create_file(hwmon->device, &dev_attr_name);
+       if (result)
+               goto free_mem;
+
+ register_sys_interface:
+       temp = kzalloc(sizeof(*temp), GFP_KERNEL);
+       if (!temp) {
+               result = -ENOMEM;
+               goto unregister_name;
+       }
+
+       temp->tz = tz;
+       hwmon->count++;
+
+       snprintf(temp->temp_input.name, sizeof(temp->temp_input.name),
+                "temp%d_input", hwmon->count);
+       temp->temp_input.attr.attr.name = temp->temp_input.name;
+       temp->temp_input.attr.attr.mode = 0444;
+       temp->temp_input.attr.show = temp_input_show;
+       sysfs_attr_init(&temp->temp_input.attr.attr);
+       result = device_create_file(hwmon->device, &temp->temp_input.attr);
+       if (result)
+               goto free_temp_mem;
+
+       if (tz->ops->get_crit_temp) {
+               unsigned long temperature;
+               if (!tz->ops->get_crit_temp(tz, &temperature)) {
+                       snprintf(temp->temp_crit.name,
+                                sizeof(temp->temp_crit.name),
+                               "temp%d_crit", hwmon->count);
+                       temp->temp_crit.attr.attr.name = temp->temp_crit.name;
+                       temp->temp_crit.attr.attr.mode = 0444;
+                       temp->temp_crit.attr.show = temp_crit_show;
+                       sysfs_attr_init(&temp->temp_crit.attr.attr);
+                       result = device_create_file(hwmon->device,
+                                                   &temp->temp_crit.attr);
+                       if (result)
+                               goto unregister_input;
+               }
+       }
+
+       mutex_lock(&thermal_hwmon_list_lock);
+       if (new_hwmon_device)
+               list_add_tail(&hwmon->node, &thermal_hwmon_list);
+       list_add_tail(&temp->hwmon_node, &hwmon->tz_list);
+       mutex_unlock(&thermal_hwmon_list_lock);
+
+       return 0;
+
+ unregister_input:
+       device_remove_file(hwmon->device, &temp->temp_input.attr);
+ free_temp_mem:
+       kfree(temp);
+ unregister_name:
+       if (new_hwmon_device) {
+               device_remove_file(hwmon->device, &dev_attr_name);
+               hwmon_device_unregister(hwmon->device);
+       }
+ free_mem:
+       if (new_hwmon_device)
+               kfree(hwmon);
+
+       return result;
+}
+
+void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
+{
+       struct thermal_hwmon_device *hwmon;
+       struct thermal_hwmon_temp *temp;
+
+       hwmon = thermal_hwmon_lookup_by_type(tz);
+       if (unlikely(!hwmon)) {
+               /* Should never happen... */
+               dev_dbg(&tz->device, "hwmon device lookup failed!\n");
+               return;
+       }
+
+       temp = thermal_hwmon_lookup_temp(hwmon, tz);
+       if (unlikely(!temp)) {
+               /* Should never happen... */
+               dev_dbg(&tz->device, "temperature input lookup failed!\n");
+               return;
+       }
+
+       device_remove_file(hwmon->device, &temp->temp_input.attr);
+       if (tz->ops->get_crit_temp)
+               device_remove_file(hwmon->device, &temp->temp_crit.attr);
+
+       mutex_lock(&thermal_hwmon_list_lock);
+       list_del(&temp->hwmon_node);
+       kfree(temp);
+       if (!list_empty(&hwmon->tz_list)) {
+               mutex_unlock(&thermal_hwmon_list_lock);
+               return;
+       }
+       list_del(&hwmon->node);
+       mutex_unlock(&thermal_hwmon_list_lock);
+
+       device_remove_file(hwmon->device, &dev_attr_name);
+       hwmon_device_unregister(hwmon->device);
+       kfree(hwmon);
+}
diff --git a/drivers/thermal/thermal_hwmon.h b/drivers/thermal/thermal_hwmon.h
new file mode 100644 (file)
index 0000000..c798fdb
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  thermal_hwmon.h - Generic Thermal Management hwmon support.
+ *
+ *  Code based on Intel thermal_core.c. Copyrights of the original code:
+ *  Copyright (C) 2008 Intel Corp
+ *  Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
+ *  Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
+ *
+ *  Copyright (C) 2013 Texas Instruments
+ *  Copyright (C) 2013 Eduardo Valentin <eduardo.valentin@ti.com>
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#ifndef __THERMAL_HWMON_H__
+#define __THERMAL_HWMON_H__
+
+#include <linux/thermal.h>
+
+#ifdef CONFIG_THERMAL_HWMON
+int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz);
+void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz);
+#else
+static int
+thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
+{
+       return 0;
+}
+
+static void
+thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
+{
+}
+#endif
+
+#endif /* __THERMAL_HWMON_H__ */
index 6f3fbc48a6c73a2fc27d847176874ad65b68d83c..22080eb6aff658c12a821fd050f7e58df5fe84dd 100644 (file)
@@ -138,12 +138,12 @@ static bool is_invalid_reserved_pfn(unsigned long pfn)
        if (pfn_valid(pfn)) {
                bool reserved;
                struct page *tail = pfn_to_page(pfn);
-               struct page *head = compound_trans_head(tail);
+               struct page *head = compound_head(tail);
                reserved = !!(PageReserved(head));
                if (head != tail) {
                        /*
                         * "head" is not a dangling pointer
-                        * (compound_trans_head takes care of that)
+                        * (compound_head takes care of that)
                         * but the hugepage may have been split
                         * from under us (and we may not hold a
                         * reference count on the head page so it can
index 21dff8f236f699047c20c8245c2d5fe286f825b2..f9e11df768d595d1a01d1e60e72d630617d25656 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/slab.h>
 #include <linux/ratelimit.h>
 #include <linux/aio.h>
+#include <linux/bitops.h>
 
 #include "ext4_jbd2.h"
 #include "xattr.h"
@@ -4044,18 +4045,20 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
 void ext4_set_inode_flags(struct inode *inode)
 {
        unsigned int flags = EXT4_I(inode)->i_flags;
+       unsigned int new_fl = 0;
 
-       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
        if (flags & EXT4_SYNC_FL)
-               inode->i_flags |= S_SYNC;
+               new_fl |= S_SYNC;
        if (flags & EXT4_APPEND_FL)
-               inode->i_flags |= S_APPEND;
+               new_fl |= S_APPEND;
        if (flags & EXT4_IMMUTABLE_FL)
-               inode->i_flags |= S_IMMUTABLE;
+               new_fl |= S_IMMUTABLE;
        if (flags & EXT4_NOATIME_FL)
-               inode->i_flags |= S_NOATIME;
+               new_fl |= S_NOATIME;
        if (flags & EXT4_DIRSYNC_FL)
-               inode->i_flags |= S_DIRSYNC;
+               new_fl |= S_DIRSYNC;
+       set_mask_bits(&inode->i_flags,
+                     S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
 }
 
 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
index b8730d9ebaee651244d0d7e46e687792b46b0c9f..2a8cc94bb641b65196b75a29c077f09253a7b727 100644 (file)
@@ -121,7 +121,7 @@ u64 stable_page_flags(struct page *page)
         * just checks PG_head/PG_tail, so we need to check PageLRU to make
         * sure a given page is a thp, not a non-huge compound page.
         */
-       else if (PageTransCompound(page) && PageLRU(compound_trans_head(page)))
+       else if (PageTransCompound(page) && PageLRU(compound_head(page)))
                u |= 1 << KPF_THP;
 
        /*
diff --git a/include/dt-bindings/thermal/thermal.h b/include/dt-bindings/thermal/thermal.h
new file mode 100644 (file)
index 0000000..59822a9
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * This header provides constants for most thermal bindings.
+ *
+ * Copyright (C) 2013 Texas Instruments
+ *     Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * GPLv2 only
+ */
+
+#ifndef _DT_BINDINGS_THERMAL_THERMAL_H
+#define _DT_BINDINGS_THERMAL_THERMAL_H
+
+/* On cooling devices upper and lower limits */
+#define THERMAL_NO_LIMIT               (-1UL)
+
+#endif
+
index a3b6b82108b9ad239dd1dda1abe6c8e3f585d3b3..c1dde8e00d2508a1b356b026a5f00be246495324 100644 (file)
@@ -185,6 +185,21 @@ static inline unsigned long __ffs64(u64 word)
 
 #ifdef __KERNEL__
 
+#ifndef set_mask_bits
+#define set_mask_bits(ptr, _mask, _bits)       \
+({                                                             \
+       const typeof(*ptr) mask = (_mask), bits = (_bits);      \
+       typeof(*ptr) old, new;                                  \
+                                                               \
+       do {                                                    \
+               old = ACCESS_ONCE(*ptr);                        \
+               new = (old & ~mask) | bits;                     \
+       } while (cmpxchg(ptr, old, new) != old);                \
+                                                               \
+       new;                                                    \
+})
+#endif
+
 #ifndef find_last_bit
 /**
  * find_last_bit - find the last set bit in a memory region
index a5d52eea82326010feac703f4f7f971801daf6ae..c303d383def1146589a30c980d2c8dadd1bd89cc 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef __CPU_COOLING_H__
 #define __CPU_COOLING_H__
 
+#include <linux/of.h>
 #include <linux/thermal.h>
 #include <linux/cpumask.h>
 
 struct thermal_cooling_device *
 cpufreq_cooling_register(const struct cpumask *clip_cpus);
 
+/**
+ * of_cpufreq_cooling_register - create cpufreq cooling device based on DT.
+ * @np: a valid struct device_node to the cooling device device tree node.
+ * @clip_cpus: cpumask of cpus where the frequency constraints will happen
+ */
+#ifdef CONFIG_THERMAL_OF
+struct thermal_cooling_device *
+of_cpufreq_cooling_register(struct device_node *np,
+                           const struct cpumask *clip_cpus);
+#else
+static inline struct thermal_cooling_device *
+of_cpufreq_cooling_register(struct device_node *np,
+                           const struct cpumask *clip_cpus)
+{
+       return NULL;
+}
+#endif
+
 /**
  * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
  * @cdev: thermal cooling device pointer.
@@ -48,6 +67,12 @@ cpufreq_cooling_register(const struct cpumask *clip_cpus)
 {
        return NULL;
 }
+static inline struct thermal_cooling_device *
+of_cpufreq_cooling_register(struct device_node *np,
+                           const struct cpumask *clip_cpus)
+{
+       return NULL;
+}
 static inline
 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
 {
index 528454c2caa91b17cbb5761de006418909de2046..a193bb3e4138f006dea22ade54eea7192d2cc7f6 100644 (file)
@@ -159,23 +159,6 @@ static inline int hpage_nr_pages(struct page *page)
                return HPAGE_PMD_NR;
        return 1;
 }
-static inline struct page *compound_trans_head(struct page *page)
-{
-       if (PageTail(page)) {
-               struct page *head;
-               head = page->first_page;
-               smp_rmb();
-               /*
-                * head may be a dangling pointer.
-                * __split_huge_page_refcount clears PageTail before
-                * overwriting first_page, so if PageTail is still
-                * there it means the head pointer isn't dangling.
-                */
-               if (PageTail(page))
-                       return head;
-       }
-       return page;
-}
 
 extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
                                unsigned long addr, pmd_t pmd, pmd_t *pmdp);
@@ -205,7 +188,6 @@ static inline int split_huge_page(struct page *page)
        do { } while (0)
 #define split_huge_page_pmd_mm(__mm, __address, __pmd) \
        do { } while (0)
-#define compound_trans_head(page) compound_head(page)
 static inline int hugepage_madvise(struct vm_area_struct *vma,
                                   unsigned long *vm_flags, int advice)
 {
index 7c2d3355eca9df1b47db6b0014339172323c4516..fc3883852f9e9e58e17f69bf374b37d6fef312c8 100644 (file)
@@ -361,8 +361,18 @@ static inline void compound_unlock_irqrestore(struct page *page,
 
 static inline struct page *compound_head(struct page *page)
 {
-       if (unlikely(PageTail(page)))
-               return page->first_page;
+       if (unlikely(PageTail(page))) {
+               struct page *head = page->first_page;
+
+               /*
+                * page->first_page may be a dangling pointer to an old
+                * compound page, so recheck that it is still a tail
+                * page before returning.
+                */
+               smp_rmb();
+               if (likely(PageTail(page)))
+                       return head;
+       }
        return page;
 }
 
index a386a1cbb6e1c912667ef7433ea608a003832940..55fce47b0095092445dee997854d8170984dd803 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef __THERMAL_H__
 #define __THERMAL_H__
 
+#include <linux/of.h>
 #include <linux/idr.h>
 #include <linux/device.h>
 #include <linux/workqueue.h>
@@ -143,6 +144,7 @@ struct thermal_cooling_device {
        int id;
        char type[THERMAL_NAME_LENGTH];
        struct device device;
+       struct device_node *np;
        void *devdata;
        const struct thermal_cooling_device_ops *ops;
        bool updated; /* true if the cooling device does not need update */
@@ -172,7 +174,7 @@ struct thermal_zone_device {
        int emul_temperature;
        int passive;
        unsigned int forced_passive;
-       const struct thermal_zone_device_ops *ops;
+       struct thermal_zone_device_ops *ops;
        const struct thermal_zone_params *tzp;
        struct thermal_governor *governor;
        struct list_head thermal_instances;
@@ -214,6 +216,14 @@ struct thermal_bind_params {
 /* Structure to define Thermal Zone parameters */
 struct thermal_zone_params {
        char governor_name[THERMAL_NAME_LENGTH];
+
+       /*
+        * a boolean to indicate if the thermal to hwmon sysfs interface
+        * is required. when no_hwmon == false, a hwmon sysfs interface
+        * will be created. when no_hwmon == true, nothing will be done
+        */
+       bool no_hwmon;
+
        int num_tbps;   /* Number of tbp entries */
        struct thermal_bind_params *tbp;
 };
@@ -224,8 +234,31 @@ struct thermal_genl_event {
 };
 
 /* Function declarations */
+#ifdef CONFIG_THERMAL_OF
+struct thermal_zone_device *
+thermal_zone_of_sensor_register(struct device *dev, int id,
+                               void *data, int (*get_temp)(void *, long *),
+                               int (*get_trend)(void *, long *));
+void thermal_zone_of_sensor_unregister(struct device *dev,
+                                      struct thermal_zone_device *tz);
+#else
+static inline struct thermal_zone_device *
+thermal_zone_of_sensor_register(struct device *dev, int id,
+                               void *data, int (*get_temp)(void *, long *),
+                               int (*get_trend)(void *, long *))
+{
+       return NULL;
+}
+
+static inline
+void thermal_zone_of_sensor_unregister(struct device *dev,
+                                      struct thermal_zone_device *tz)
+{
+}
+
+#endif
 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
-               void *, const struct thermal_zone_device_ops *,
+               void *, struct thermal_zone_device_ops *,
                const struct thermal_zone_params *, int, int);
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
@@ -238,6 +271,9 @@ void thermal_zone_device_update(struct thermal_zone_device *);
 
 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
                const struct thermal_cooling_device_ops *);
+struct thermal_cooling_device *
+thermal_of_cooling_device_register(struct device_node *np, char *, void *,
+                                  const struct thermal_cooling_device_ops *);
 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);
index b6afe0c440d8b3e500f4a09e2875491c7d70199a..784d1e4bc3852ef0598708263ad39aaa01f46885 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -444,7 +444,7 @@ static void break_cow(struct rmap_item *rmap_item)
 static struct page *page_trans_compound_anon(struct page *page)
 {
        if (PageTransCompound(page)) {
-               struct page *head = compound_trans_head(page);
+               struct page *head = compound_head(page);
                /*
                 * head may actually be splitted and freed from under
                 * us but it's ok here.
index e386beefc994a8c789e6ca35d5fb7e276946b39f..59c62fa75c5aabea493afb710a1c5fb181532b75 100644 (file)
@@ -1544,7 +1544,7 @@ int soft_offline_page(struct page *page, int flags)
 {
        int ret;
        unsigned long pfn = page_to_pfn(page);
-       struct page *hpage = compound_trans_head(page);
+       struct page *hpage = compound_head(page);
 
        if (PageHWPoison(page)) {
                pr_info("soft offline: %#lx page already poisoned\n", pfn);
index 82e897fc291f53b4d2a9202efddfb871fa6f9609..4cfdc64482c85a59dc3e242ef793bcbfb5456315 100644 (file)
@@ -373,9 +373,11 @@ void prep_compound_page(struct page *page, unsigned long order)
        __SetPageHead(page);
        for (i = 1; i < nr_pages; i++) {
                struct page *p = page + i;
-               __SetPageTail(p);
                set_page_count(p, 0);
                p->first_page = page;
+               /* Make sure p->first_page is always valid for PageTail() */
+               smp_wmb();
+               __SetPageTail(p);
        }
 }
 
index ea58dbde788ed6fdee09243be247841f57a68da9..4e35f3ff0427107023b95ca2222c9fd663d3eba7 100644 (file)
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -81,7 +81,7 @@ static void put_compound_page(struct page *page)
 {
        if (unlikely(PageTail(page))) {
                /* __split_huge_page_refcount can run under us */
-               struct page *page_head = compound_trans_head(page);
+               struct page *page_head = compound_head(page);
 
                if (likely(page != page_head &&
                           get_page_unless_zero(page_head))) {
@@ -219,7 +219,7 @@ bool __get_page_tail(struct page *page)
         */
        unsigned long flags;
        bool got = false;
-       struct page *page_head = compound_trans_head(page);
+       struct page *page_head = compound_head(page);
 
        if (likely(page != page_head && get_page_unless_zero(page_head))) {
                /* Ref to put_compound_page() comment. */
index a99b6c3427b0ce3e06458cb1fd37bc3bfac98723..59359bec328acce9ee7d8ca247b61b26f48e537e 100644 (file)
@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
        const char *msg;
        u_int8_t state;
 
-       dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
+       dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
        BUG_ON(dh == NULL);
 
        state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
        u_int8_t type, old_state, new_state;
        enum ct_dccp_roles role;
 
-       dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
+       dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
        BUG_ON(dh == NULL);
        type = dh->dccph_type;
 
@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
        unsigned int cscov;
        const char *msg;
 
-       dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
+       dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
        if (dh == NULL) {
                msg = "nf_ct_dccp: short packet ";
                goto out_invalid;
index eb99458f5b6841fc7a904e5a44e1dc6af8bec0b4..8cf1cd2fadaab1260df022ba4248c92a47e82724 100644 (file)
@@ -105,12 +105,12 @@ bool kvm_is_mmio_pfn(pfn_t pfn)
        if (pfn_valid(pfn)) {
                int reserved;
                struct page *tail = pfn_to_page(pfn);
-               struct page *head = compound_trans_head(tail);
+               struct page *head = compound_head(tail);
                reserved = PageReserved(head);
                if (head != tail) {
                        /*
                         * "head" is not a dangling pointer
-                        * (compound_trans_head takes care of that)
+                        * (compound_head takes care of that)
                         * but the hugepage may have been splitted
                         * from under us (and we may not hold a
                         * reference count on the head page so it can