blob: 3b1b6ae82a47dbb26281ea89944e62d42c238ed5 [file] [log] [blame]
Rajendra Nayak90660732016-05-05 14:21:39 +05301/*
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
20struct tsens_device;
21
22struct tsens_sensor {
23 struct tsens_device *tmdev;
24 struct thermal_zone_device *tzd;
25 int offset;
26 int id;
27 int hw_id;
28 int slope;
29 u32 status;
30};
31
32/**
33 * struct tsens_ops - operations as supported by the tsens device
34 * @init: Function to initialize the tsens device
35 * @calibrate: Function to calibrate the tsens device
36 * @get_temp: Function which returns the temp in millidegC
37 * @enable: Function to enable (clocks/power) tsens device
38 * @disable: Function to disable the tsens device
39 * @suspend: Function to suspend the tsens device
40 * @resume: Function to resume the tsens device
41 * @get_trend: Function to get the thermal/temp trend
42 */
43struct tsens_ops {
44 /* mandatory callbacks */
45 int (*init)(struct tsens_device *);
46 int (*calibrate)(struct tsens_device *);
47 int (*get_temp)(struct tsens_device *, int, int *);
48 /* optional callbacks */
49 int (*enable)(struct tsens_device *, int);
50 void (*disable)(struct tsens_device *);
51 int (*suspend)(struct tsens_device *);
52 int (*resume)(struct tsens_device *);
53 int (*get_trend)(struct tsens_device *, int, long *);
54};
55
56/**
57 * struct tsens_data - tsens instance specific data
58 * @num_sensors: Max number of sensors supported by platform
59 * @ops: operations the tsens instance supports
60 * @hw_ids: Subset of sensors ids supported by platform, if not the first n
61 */
62struct tsens_data {
63 const u32 num_sensors;
64 const struct tsens_ops *ops;
65 unsigned int *hw_ids;
66};
67
68/* Registers to be saved/restored across a context loss */
69struct tsens_context {
70 int threshold;
71 int control;
72};
73
74struct tsens_device {
75 struct device *dev;
76 u32 num_sensors;
77 struct regmap *map;
78 struct regmap_field *status_field;
79 struct tsens_context ctx;
80 bool trdy;
81 const struct tsens_ops *ops;
82 struct tsens_sensor sensor[0];
83};
84
85char *qfprom_read(struct device *, const char *);
86void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);
87int init_common(struct tsens_device *);
88int get_temp_common(struct tsens_device *, int, int *);
89
90#endif /* __QCOM_TSENS_H__ */