2 * Copyright (c) 2012-2016,2018, The Linux Foundation. All rights reserved.
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.
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.
14 #ifndef __MSM_THERMAL_H
15 #define __MSM_THERMAL_H
17 #include <linux/thermal.h>
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)
35 #define IS_HI_THRESHOLD_SET(_val) (_val & 1)
36 #define IS_LOW_THRESHOLD_SET(_val) (_val & 2)
38 struct msm_thermal_data {
39 struct platform_device *pdev;
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;
55 int32_t vdd_rstr_temp_degC;
56 int32_t vdd_rstr_temp_hyst_degC;
57 int32_t vdd_rstr_sensor_id;
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;
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;
88 struct threshold_info;
89 struct therm_threshold {
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;
99 struct threshold_info {
101 bool thresh_triggered;
102 struct list_head list_ptr;
103 struct therm_threshold *thresh_list;
106 enum device_req_type {
107 DEVICE_REQ_NONE = -1,
108 HOTPLUG_MITIGATION_REQ,
109 CPUFREQ_MITIGATION_REQ,
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;
120 * offline_mask = CPU_MASK_NONE;
122 struct cpufreq_request {
127 union device_request {
128 struct cpufreq_request freq;
129 cpumask_t offline_mask;
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 *);
146 struct device_clnt_data {
147 struct device_manager_data *dev_mgr;
149 union device_request request;
150 struct list_head clnt_ptr;
151 void (*callback)(struct device_clnt_data *,
152 union device_request *req, void *);
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,
163 extern int msm_thermal_set_cluster_freq(uint32_t cluster, uint32_t freq,
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);
172 * sensor_mgr_init_threshold - Initialize thresholds data structure for
173 * sensor(s) with high and low thresholds and
174 * threshold callback.
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.
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.
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.
188 extern int sensor_mgr_init_threshold(struct threshold_info *thresh_inp,
189 int sensor_id, int32_t high_temp,
191 void (*callback)(struct therm_threshold *));
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.
198 * @thresh_inp: Client threshold data structure.
200 * Returns zero on success, negative error number on failure.
202 extern int sensor_mgr_convert_id_and_set_threshold(
203 struct threshold_info *thresh_inp);
205 * sensor_mgr_set_threshold- It sets thermal threshold trips for a sensor.
207 * @zone_id: Thermal zone ID for the sensor.
208 * @threshold: threshold info for the sensor.
210 * Returns zero on success, negative error number on failure.
212 extern int sensor_mgr_set_threshold(uint32_t zone_id,
213 struct sensor_threshold *threshold);
215 * sensor_mgr_remove_threshold- It cancels threshold notification and
216 * removes threshold from sensor manager
219 * @thresh_inp: The threshold info which needs to be removed.
221 extern void sensor_mgr_remove_threshold(struct threshold_info *thresh_inp);
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
228 * @callback: Optional callback pointer for device change notification,
229 * otherwise pass NULL.
231 * Returns client handle structure for that device on success, or NULL
232 * with IS_ERR() condition containing error number.
234 extern struct device_clnt_data *devmgr_register_mitigation_client(
236 const char *device_name,
237 void (*callback)(struct device_clnt_data *,
238 union device_request *, void *));
240 * devmgr_client_request_mitigation - Set a valid mitigation for
242 * @clnt: Client handle for device.
243 * @type: Type of device request populated above.
244 * @req: Valid mitigation request.
246 * Returns zero on successful mitigation update, or negative error number.
248 extern int devmgr_client_request_mitigation(struct device_clnt_data *clnt,
249 enum device_req_type type,
250 union device_request *req);
252 * devmgr_unregister_mitigation_client - Unregister mitigation device
253 * @dev: Client device structure.
254 * @clnt: Client handle for device.
256 extern void devmgr_unregister_mitigation_client(
258 struct device_clnt_data *clnt);
260 static inline int msm_thermal_init(struct msm_thermal_data *pdata)
264 static inline int msm_thermal_device_init(void)
268 static inline int msm_thermal_set_frequency(uint32_t cpu, uint32_t freq,
273 static inline int msm_thermal_set_cluster_freq(uint32_t cluster, uint32_t freq,
278 static inline int msm_thermal_get_freq_plan_size(uint32_t cluster,
279 unsigned int *table_len)
283 static inline int msm_thermal_get_cluster_freq_plan(uint32_t cluster,
284 unsigned int *table_ptr)
288 static inline int msm_thermal_get_cluster_voltage_plan(uint32_t cluster,
293 static inline int sensor_mgr_init_threshold(struct threshold_info *thresh_inp,
294 int sensor_id, int32_t high_temp,
296 void (*callback)(struct therm_threshold *))
300 static inline int sensor_mgr_convert_id_and_set_threshold(
301 struct threshold_info *thresh_inp)
305 static inline int sensor_mgr_set_threshold(uint32_t zone_id,
306 struct sensor_threshold *threshold)
310 static inline void sensor_mgr_remove_threshold(
311 struct threshold_info *thresh_inp)
314 static inline struct device_clnt_data *devmgr_register_mitigation_client(
316 const char *device_name,
317 void (*callback)(struct device_clnt_data *,
318 union device_request *, void *))
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)
329 static inline void devmgr_unregister_mitigation_client(
331 struct device_clnt_data *clnt)
336 #ifdef CONFIG_QCOM_THERMAL_LIMITS_DCVS
337 extern int msm_lmh_dcvsh_sw_notify(int cpu);
339 static inline int msm_lmh_dcvsh_sw_notify(int cpu)
345 #endif /*__MSM_THERMAL_H*/