generic/4.4: remove ISSI SI25CD512 SPI flash support patch
[openwrt.git] / target / linux / mediatek / patches / 0020-thermal-thermal-Add-support-for-hardware-tracked-tri.patch
1 From 346632bc00fe71c269709702fecb474bb22e933e Mon Sep 17 00:00:00 2001
2 From: Sascha Hauer <s.hauer@pengutronix.de>
3 Date: Wed, 13 May 2015 10:52:39 +0200
4 Subject: [PATCH 20/76] thermal: thermal: Add support for hardware-tracked
5  trip points
6
7 This adds support for hardware-tracked trip points to the device tree
8 thermal sensor framework.
9
10 The framework supports an arbitrary number of trip points. Whenever
11 the current temperature is updated, the trip points immediately
12 below and above the current temperature are found. A .set_trips
13 callback is then called with the temperatures. If there is no trip
14 point above or below the current temperature, the passed trip
15 temperature will be -INT_MAX or INT_MAX respectively. In this callback,
16 the driver should program the hardware such that it is notified
17 when either of these trip points are triggered. When a trip point
18 is triggered, the driver should call `thermal_zone_device_update'
19 for the respective thermal zone. This will cause the trip points
20 to be updated again.
21
22 If .set_trips is not implemented, the framework behaves as before.
23
24 This patch is based on an earlier version from Mikko Perttunen
25 <mikko.perttunen@kapsi.fi>
26
27 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
28 ---
29  drivers/thermal/thermal_core.c |   43 ++++++++++++++++++++++++++++++++++++++++
30  include/linux/thermal.h        |    3 +++
31  2 files changed, 46 insertions(+)
32
33 --- a/drivers/thermal/thermal_core.c
34 +++ b/drivers/thermal/thermal_core.c
35 @@ -456,6 +456,45 @@ int thermal_zone_get_temp(struct thermal
36  }
37  EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
38  
39 +static void thermal_zone_set_trips(struct thermal_zone_device *tz)
40 +{
41 +       int low = -INT_MAX;
42 +       int high = INT_MAX;
43 +       int trip_temp, hysteresis;
44 +       int temp = tz->temperature;
45 +       int i;
46 +
47 +       if (!tz->ops->set_trips)
48 +               return;
49 +
50 +       /* No need to change trip points */
51 +       if (temp > tz->prev_low_trip && temp < tz->prev_high_trip)
52 +               return;
53 +
54 +       for (i = 0; i < tz->trips; i++) {
55 +               int trip_low;
56 +
57 +               tz->ops->get_trip_temp(tz, i, &trip_temp);
58 +               tz->ops->get_trip_hyst(tz, i, &hysteresis);
59 +
60 +               trip_low = trip_temp - hysteresis;
61 +
62 +               if (trip_low < temp && trip_low > low)
63 +                       low = trip_low;
64 +
65 +               if (trip_temp > temp && trip_temp < high)
66 +                       high = trip_temp;
67 +       }
68 +
69 +       tz->prev_low_trip = low;
70 +       tz->prev_high_trip = high;
71 +
72 +       dev_dbg(&tz->device, "new temperature boundaries: %d < x < %d\n",
73 +                       low, high);
74 +
75 +       tz->ops->set_trips(tz, low, high);
76 +}
77 +
78  void thermal_zone_device_update(struct thermal_zone_device *tz)
79  {
80         int temp, ret, count;
81 @@ -489,6 +528,8 @@ void thermal_zone_device_update(struct t
82                 dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n",
83                         tz->last_temperature, tz->temperature);
84  
85 +       thermal_zone_set_trips(tz);
86 +
87         for (count = 0; count < tz->trips; count++)
88                 handle_thermal_trip(tz, count);
89  }
90 @@ -1522,6 +1563,8 @@ struct thermal_zone_device *thermal_zone
91         tz->trips = trips;
92         tz->passive_delay = passive_delay;
93         tz->polling_delay = polling_delay;
94 +       tz->prev_low_trip = INT_MAX;
95 +       tz->prev_high_trip = -INT_MAX;
96         /* A new thermal zone needs to be updated anyway. */
97         atomic_set(&tz->need_update, 1);
98  
99 --- a/include/linux/thermal.h
100 +++ b/include/linux/thermal.h
101 @@ -90,6 +90,7 @@ struct thermal_zone_device_ops {
102         int (*unbind) (struct thermal_zone_device *,
103                        struct thermal_cooling_device *);
104         int (*get_temp) (struct thermal_zone_device *, int *);
105 +       int (*set_trips) (struct thermal_zone_device *, int, int);
106         int (*get_mode) (struct thermal_zone_device *,
107                          enum thermal_device_mode *);
108         int (*set_mode) (struct thermal_zone_device *,
109 @@ -184,6 +185,8 @@ struct thermal_zone_device {
110         int last_temperature;
111         int emul_temperature;
112         int passive;
113 +       int prev_low_trip;
114 +       int prev_high_trip;
115         unsigned int forced_passive;
116         atomic_t need_update;
117         const struct thermal_zone_device_ops *ops;