1 /* 2 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 3 * 4 * This software is licensed under the terms of the GNU General Public 5 * License version 2, as published by the Free Software Foundation, and 6 * may be copied, distributed, and modified under those terms. 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 #ifndef __QCOM_TSENS_H__ 14 #define __QCOM_TSENS_H__ 15 16 #define ONE_PT_CALIB 0x1 17 #define ONE_PT_CALIB2 0x2 18 #define TWO_PT_CALIB 0x3 19 20 #include <linux/thermal.h> 21 22 struct tsens_device; 23 24 struct tsens_sensor { 25 struct tsens_device *tmdev; 26 struct thermal_zone_device *tzd; 27 int offset; 28 int id; 29 int hw_id; 30 int slope; 31 u32 status; 32 }; 33 34 /** 35 * struct tsens_ops - operations as supported by the tsens device 36 * @init: Function to initialize the tsens device 37 * @calibrate: Function to calibrate the tsens device 38 * @get_temp: Function which returns the temp in millidegC 39 * @enable: Function to enable (clocks/power) tsens device 40 * @disable: Function to disable the tsens device 41 * @suspend: Function to suspend the tsens device 42 * @resume: Function to resume the tsens device 43 * @get_trend: Function to get the thermal/temp trend 44 */ 45 struct tsens_ops { 46 /* mandatory callbacks */ 47 int (*init)(struct tsens_device *); 48 int (*calibrate)(struct tsens_device *); 49 int (*get_temp)(struct tsens_device *, int, int *); 50 /* optional callbacks */ 51 int (*enable)(struct tsens_device *, int); 52 void (*disable)(struct tsens_device *); 53 int (*suspend)(struct tsens_device *); 54 int (*resume)(struct tsens_device *); 55 int (*get_trend)(struct tsens_device *, int, enum thermal_trend *); 56 }; 57 58 /** 59 * struct tsens_data - tsens instance specific data 60 * @num_sensors: Max number of sensors supported by platform 61 * @ops: operations the tsens instance supports 62 * @hw_ids: Subset of sensors ids supported by platform, if not the first n 63 */ 64 struct tsens_data { 65 const u32 num_sensors; 66 const struct tsens_ops *ops; 67 unsigned int *hw_ids; 68 }; 69 70 /* Registers to be saved/restored across a context loss */ 71 struct tsens_context { 72 int threshold; 73 int control; 74 }; 75 76 struct tsens_device { 77 struct device *dev; 78 u32 num_sensors; 79 struct regmap *map; 80 struct regmap_field *status_field; 81 struct tsens_context ctx; 82 bool trdy; 83 const struct tsens_ops *ops; 84 struct tsens_sensor sensor[0]; 85 }; 86 87 char *qfprom_read(struct device *, const char *); 88 void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32); 89 int init_common(struct tsens_device *); 90 int get_temp_common(struct tsens_device *, int, int *); 91 92 extern const struct tsens_data data_8916, data_8974, data_8960, data_8996; 93 94 #endif /* __QCOM_TSENS_H__ */ 95