blob: 911c1978892b3bf6797cf707f3d523ea9c50a628 [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
Sascha Hauere78eaf42016-06-22 16:42:03 +080020#include <linux/thermal.h>
21
Rajendra Nayak90660732016-05-05 14:21:39 +053022struct tsens_device;
23
24struct 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 */
45struct 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 Hauere78eaf42016-06-22 16:42:03 +080055 int (*get_trend)(struct tsens_device *, int, enum thermal_trend *);
Rajendra Nayak90660732016-05-05 14:21:39 +053056};
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 */
64struct 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 */
71struct tsens_context {
72 int threshold;
73 int control;
74};
75
76struct 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
87char *qfprom_read(struct device *, const char *);
88void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);
89int init_common(struct tsens_device *);
90int get_temp_common(struct tsens_device *, int, int *);
91
Rajendra Nayakd059c732016-05-05 14:21:44 +053092extern const struct tsens_data data_8916, data_8974, data_8960, data_8996;
Rajendra Nayak840a5bd2016-05-05 14:21:40 +053093
Rajendra Nayak90660732016-05-05 14:21:39 +053094#endif /* __QCOM_TSENS_H__ */