OSDN Git Service

devfreq_boost: Introduce devfreq boost driver
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / msm_thermal.h
1 /*
2  * Copyright (c) 2012-2016,2018, The Linux Foundation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 and
6  * only version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #ifndef __MSM_THERMAL_H
15 #define __MSM_THERMAL_H
16
17 #include <linux/thermal.h>
18
19 #define MAX_THRESHOLD  2
20 #define TSENS_NAME_MAX 20
21 #define MONITOR_ALL_TSENS -1
22 #define HOTPLUG_DEVICE "hotplug"
23 #define CPU0_DEVICE     "cpu0"
24 #define CPU1_DEVICE     "cpu1"
25 #define CPU2_DEVICE     "cpu2"
26 #define CPU3_DEVICE     "cpu3"
27 #define CPU4_DEVICE     "cpu4"
28 #define CPU5_DEVICE     "cpu5"
29 #define CPU6_DEVICE     "cpu6"
30 #define CPU7_DEVICE     "cpu7"
31 #define CPUFREQ_MAX_NO_MITIGATION     UINT_MAX
32 #define CPUFREQ_MIN_NO_MITIGATION     0
33 #define HOTPLUG_NO_MITIGATION(_mask)  cpumask_clear(_mask)
34
35 #define IS_HI_THRESHOLD_SET(_val) (_val & 1)
36 #define IS_LOW_THRESHOLD_SET(_val) (_val & 2)
37
38 struct msm_thermal_data {
39         struct platform_device *pdev;
40         uint32_t sensor_id;
41         uint32_t poll_ms;
42         int32_t limit_temp_degC;
43         int32_t temp_hysteresis_degC;
44         uint32_t bootup_freq_step;
45         uint32_t bootup_freq_control_mask;
46         int32_t core_limit_temp_degC;
47         int32_t core_temp_hysteresis_degC;
48         int32_t hotplug_temp_degC;
49         int32_t hotplug_temp_hysteresis_degC;
50         uint32_t core_control_mask;
51         uint32_t freq_mitig_temp_degc;
52         uint32_t freq_mitig_temp_hysteresis_degc;
53         uint32_t freq_mitig_control_mask;
54         uint32_t freq_limit;
55         int32_t vdd_rstr_temp_degC;
56         int32_t vdd_rstr_temp_hyst_degC;
57         int32_t vdd_rstr_sensor_id;
58         int32_t vdd_mx_min;
59         int32_t vdd_cx_min;
60         int32_t psm_temp_degC;
61         int32_t psm_temp_hyst_degC;
62         int32_t ocr_temp_degC;
63         int32_t ocr_temp_hyst_degC;
64         uint32_t ocr_sensor_id;
65         int32_t phase_rpm_resource_type;
66         int32_t phase_rpm_resource_id;
67         int32_t gfx_phase_warm_temp_degC;
68         int32_t gfx_phase_warm_temp_hyst_degC;
69         int32_t gfx_phase_hot_temp_degC;
70         int32_t gfx_phase_hot_temp_hyst_degC;
71         int32_t gfx_sensor;
72         int32_t gfx_phase_request_key;
73         int32_t cx_phase_hot_temp_degC;
74         int32_t cx_phase_hot_temp_hyst_degC;
75         int32_t cx_phase_request_key;
76         int32_t vdd_mx_temp_degC;
77         int32_t vdd_mx_temp_hyst_degC;
78         int32_t vdd_mx_sensor_id;
79         int32_t therm_reset_temp_degC;
80 };
81
82 enum sensor_id_type {
83         THERM_ZONE_ID,
84         THERM_TSENS_ID,
85         THERM_ID_MAX_NR,
86 };
87
88 struct threshold_info;
89 struct therm_threshold {
90         int32_t                     sensor_id;
91         enum sensor_id_type         id_type;
92         struct sensor_threshold     threshold[MAX_THRESHOLD];
93         int32_t                     trip_triggered;
94         void (*notify)(struct therm_threshold *);
95         struct threshold_info       *parent;
96         int32_t                     cur_state;
97 };
98
99 struct threshold_info {
100         uint32_t                     thresh_ct;
101         bool                         thresh_triggered;
102         struct list_head             list_ptr;
103         struct therm_threshold       *thresh_list;
104 };
105
106 enum device_req_type {
107         DEVICE_REQ_NONE = -1,
108         HOTPLUG_MITIGATION_REQ,
109         CPUFREQ_MITIGATION_REQ,
110         DEVICE_REQ_MAX,
111 };
112
113 /**
114  * For frequency mitigation request, if client is interested
115  * only in one, either max_freq or min_freq, update default
116  * value for other one also for mitigation request.
117  * Default value for request structure variables:
118  *   max_freq = UINT_MAX;
119  *   min_freq = 0;
120  *   offline_mask =  CPU_MASK_NONE;
121  */
122 struct cpufreq_request {
123         uint32_t                     max_freq;
124         uint32_t                     min_freq;
125 };
126
127 union device_request {
128         struct cpufreq_request       freq;
129         cpumask_t                    offline_mask;
130 };
131
132 struct device_clnt_data;
133 struct device_manager_data {
134         char                         device_name[TSENS_NAME_MAX];
135         union device_request         active_req;
136         struct list_head             client_list;
137         struct list_head             dev_ptr;
138         struct mutex                 clnt_lock;
139         int (*request_validate)(struct device_clnt_data *,
140                         union device_request *,
141                         enum device_req_type);
142         int (*update)(struct device_manager_data *);
143         void                         *data;
144 };
145
146 struct device_clnt_data {
147         struct device_manager_data   *dev_mgr;
148         bool                         req_active;
149         union device_request         request;
150         struct list_head             clnt_ptr;
151         void (*callback)(struct device_clnt_data *,
152                         union device_request *req, void *);
153         void                         *usr_data;
154 };
155
156 #ifdef CONFIG_THERMAL_MONITOR
157 extern int msm_thermal_ioctl_init(void);
158 extern void msm_thermal_ioctl_cleanup(void);
159 extern int msm_thermal_init(struct msm_thermal_data *pdata);
160 extern int msm_thermal_device_init(void);
161 extern int msm_thermal_set_frequency(uint32_t cpu, uint32_t freq,
162         bool is_max);
163 extern int msm_thermal_set_cluster_freq(uint32_t cluster, uint32_t freq,
164         bool is_max);
165 extern int msm_thermal_get_freq_plan_size(uint32_t cluster,
166         unsigned int *table_len);
167 extern int msm_thermal_get_cluster_freq_plan(uint32_t cluster,
168         unsigned int *table_ptr);
169 extern int msm_thermal_get_cluster_voltage_plan(uint32_t cluster,
170         uint32_t *table_ptr);
171 /**
172  * sensor_mgr_init_threshold - Initialize thresholds data structure for
173  *                             sensor(s) with high and low thresholds and
174  *                             threshold callback.
175  *
176  * @thresh_inp: Client threshold data structure.
177  * @sensor_id: Sensor h/w ID to be monitored. Use MONITOR_ALL_TSENS
178  *             to monitor all temperature sensors.
179  *
180  * @high_temp: Trigger threshold value for sensor_id or all sensors.
181  * @low_temp: Clear threshold value for sensor_id or all sensors.
182  * @callback: Callback pointer for threshold notification.
183  *
184  * Returns which threshold is set on success, negative error number
185  * on failure. MACRO IS_HI_THRESHOLD_SET/IS_LOW_THRESHOLD_SET can be used
186  * to decipher which threshold being set.
187  */
188 extern int sensor_mgr_init_threshold(struct threshold_info *thresh_inp,
189                                 int sensor_id, int32_t high_temp,
190                                 int32_t low_temp,
191                                 void (*callback)(struct therm_threshold *));
192 /**
193  * sensor_mgr_convert_id_and_set_threshold - It accepts sensor h/w ID, converts
194  *                                           it to sensor zone id and sets
195  *                                           thermal threshold for those
196  *                                           sensors listed in threshold info.
197  *
198  * @thresh_inp: Client threshold data structure.
199  *
200  * Returns zero on success, negative error number on failure.
201  */
202 extern int sensor_mgr_convert_id_and_set_threshold(
203                                 struct threshold_info *thresh_inp);
204 /**
205  * sensor_mgr_set_threshold- It sets thermal threshold trips for a sensor.
206  *
207  * @zone_id: Thermal zone ID for the sensor.
208  * @threshold: threshold info for the sensor.
209  *
210  * Returns zero on success, negative error number on failure.
211  */
212 extern int sensor_mgr_set_threshold(uint32_t zone_id,
213                                 struct sensor_threshold *threshold);
214 /**
215  * sensor_mgr_remove_threshold- It cancels threshold notification and
216  *                              removes threshold from sensor manager
217  *                              threshold list.
218  *
219  * @thresh_inp: The threshold info which needs to be removed.
220  */
221 extern void sensor_mgr_remove_threshold(struct threshold_info *thresh_inp);
222 /**
223  * devmgr_register_mitigation_client - Register for a device and
224  *                                     gets a handle for mitigation.
225  * @dev: Client device structure.
226  * @device_name: Mitgation device name which the client is interested
227  *               to mitigate.
228  * @callback: Optional callback pointer for device change notification,
229  *            otherwise pass NULL.
230  *
231  * Returns client handle structure for that device on success, or NULL
232  * with IS_ERR() condition containing error number.
233  */
234 extern struct device_clnt_data *devmgr_register_mitigation_client(
235                                 struct device *dev,
236                                 const char *device_name,
237                                 void (*callback)(struct device_clnt_data *,
238                                 union device_request *, void *));
239 /**
240  * devmgr_client_request_mitigation -  Set a valid mitigation for
241  *                                     registered device.
242  * @clnt: Client handle for device.
243  * @type: Type of device request populated above.
244  * @req:  Valid mitigation request.
245  *
246  * Returns zero on successful mitigation update, or negative error number.
247  */
248 extern int devmgr_client_request_mitigation(struct device_clnt_data *clnt,
249                                                 enum device_req_type type,
250                                                 union device_request *req);
251 /**
252  * devmgr_unregister_mitigation_client - Unregister mitigation device
253  * @dev: Client device structure.
254  * @clnt: Client handle for device.
255  */
256 extern void devmgr_unregister_mitigation_client(
257                                         struct device *dev,
258                                         struct device_clnt_data *clnt);
259 #else
260 static inline int msm_thermal_init(struct msm_thermal_data *pdata)
261 {
262         return -ENOSYS;
263 }
264 static inline int msm_thermal_device_init(void)
265 {
266         return -ENOSYS;
267 }
268 static inline int msm_thermal_set_frequency(uint32_t cpu, uint32_t freq,
269         bool is_max)
270 {
271         return -ENOSYS;
272 }
273 static inline int msm_thermal_set_cluster_freq(uint32_t cluster, uint32_t freq,
274         bool is_max)
275 {
276         return -ENOSYS;
277 }
278 static inline int msm_thermal_get_freq_plan_size(uint32_t cluster,
279         unsigned int *table_len)
280 {
281         return -ENOSYS;
282 }
283 static inline int msm_thermal_get_cluster_freq_plan(uint32_t cluster,
284         unsigned int *table_ptr)
285 {
286         return -ENOSYS;
287 }
288 static inline int msm_thermal_get_cluster_voltage_plan(uint32_t cluster,
289         uint32_t *table_ptr)
290 {
291         return -ENOSYS;
292 }
293 static inline int sensor_mgr_init_threshold(struct threshold_info *thresh_inp,
294                                 int sensor_id, int32_t high_temp,
295                                 int32_t low_temp,
296                                 void (*callback)(struct therm_threshold *))
297 {
298         return -ENOSYS;
299 }
300 static inline int sensor_mgr_convert_id_and_set_threshold(
301                         struct threshold_info *thresh_inp)
302 {
303         return -ENOSYS;
304 }
305 static inline int sensor_mgr_set_threshold(uint32_t zone_id,
306                         struct sensor_threshold *threshold)
307 {
308         return -ENOSYS;
309 }
310 static inline void sensor_mgr_remove_threshold(
311                                 struct threshold_info *thresh_inp)
312 {
313 }
314 static inline struct device_clnt_data *devmgr_register_mitigation_client(
315                                 struct device *dev,
316                                 const char *device_name,
317                                 void (*callback)(struct device_clnt_data *,
318                                 union device_request *, void *))
319 {
320         return NULL;
321 }
322 static inline int devmgr_client_request_mitigation(
323                                         struct device_clnt_data *clnt,
324                                         enum device_req_type type,
325                                         union device_request *req)
326 {
327         return -ENOSYS;
328 }
329 static inline void devmgr_unregister_mitigation_client(
330                                         struct device *dev,
331                                         struct device_clnt_data *clnt)
332 {
333 }
334 #endif
335
336 #ifdef CONFIG_QCOM_THERMAL_LIMITS_DCVS
337 extern int msm_lmh_dcvsh_sw_notify(int cpu);
338 #else
339 static inline int msm_lmh_dcvsh_sw_notify(int cpu)
340 {
341         return -ENODEV;
342 }
343 #endif
344
345 #endif /*__MSM_THERMAL_H*/