Rajendra Nayak | 9066073 | 2016-05-05 14:21:39 +0530 | [diff] [blame] | 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 | |
Sascha Hauer | e78eaf4 | 2016-06-22 16:42:03 +0800 | [diff] [blame] | 20 | #include <linux/thermal.h> |
| 21 | |
Rajendra Nayak | 9066073 | 2016-05-05 14:21:39 +0530 | [diff] [blame] | 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 *); |
Sascha Hauer | e78eaf4 | 2016-06-22 16:42:03 +0800 | [diff] [blame] | 55 | int (*get_trend)(struct tsens_device *, int, enum thermal_trend *); |
Rajendra Nayak | 9066073 | 2016-05-05 14:21:39 +0530 | [diff] [blame] | 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; |
Amit Kucheria | 5b12839 | 2018-07-18 12:13:09 +0530 | [diff] [blame] | 80 | u32 tm_offset; |
Rajendra Nayak | 9066073 | 2016-05-05 14:21:39 +0530 | [diff] [blame] | 81 | struct tsens_context ctx; |
Rajendra Nayak | 9066073 | 2016-05-05 14:21:39 +0530 | [diff] [blame] | 82 | const struct tsens_ops *ops; |
| 83 | struct tsens_sensor sensor[0]; |
| 84 | }; |
| 85 | |
| 86 | char *qfprom_read(struct device *, const char *); |
| 87 | void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32); |
| 88 | int init_common(struct tsens_device *); |
| 89 | int get_temp_common(struct tsens_device *, int, int *); |
| 90 | |
Amit Kucheria | 191dc74 | 2018-07-18 12:13:12 +0530 | [diff] [blame] | 91 | /* TSENS v1 targets */ |
| 92 | extern const struct tsens_data data_8916, data_8974, data_8960; |
| 93 | /* TSENS v2 targets */ |
| 94 | extern const struct tsens_data data_8996, data_tsens_v2; |
Rajendra Nayak | 840a5bd | 2016-05-05 14:21:40 +0530 | [diff] [blame] | 95 | |
Rajendra Nayak | 9066073 | 2016-05-05 14:21:39 +0530 | [diff] [blame] | 96 | #endif /* __QCOM_TSENS_H__ */ |