blob: 3b9b01a9f7504cf29b952660a2e35eb1bd821f14 [file] [log] [blame]
Siddartha Mohanadosscd8aa0b2017-04-06 15:17:46 -07001/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -08002 *
Siddartha Mohanadosscd8aa0b2017-04-06 15:17:46 -07003 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -08006 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
Siddartha Mohanadosscd8aa0b2017-04-06 15:17:46 -070011 *
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -080012 */
13#ifndef __QCOM_TSENS_H__
14#define __QCOM_TSENS_H__
15
16#include <linux/kernel.h>
17#include <linux/thermal.h>
18#include <linux/interrupt.h>
19#include <linux/types.h>
20#include <linux/workqueue.h>
21#include <linux/io.h>
22#include <linux/delay.h>
23
24#define DEBUG_SIZE 10
25#define TSENS_MAX_SENSORS 16
Siddartha Mohanadoss07b10612017-04-07 14:53:45 -070026#define TSENS_CONTROLLER_ID(n) (n)
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -080027#define TSENS_CTRL_ADDR(n) (n)
Siddartha Mohanadoss07b10612017-04-07 14:53:45 -070028#define TSENS_TM_SN_STATUS(n) ((n) + 0xa0)
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -080029
30enum tsens_dbg_type {
31 TSENS_DBG_POLL,
32 TSENS_DBG_LOG_TEMP_READS,
33 TSENS_DBG_LOG_INTERRUPT_TIMESTAMP,
34 TSENS_DBG_LOG_MAX
35};
36
37#define tsens_sec_to_msec_value 1000
38
39struct tsens_device;
40
41#if defined(CONFIG_THERMAL_TSENS)
42int tsens2xxx_dbg(struct tsens_device *data, u32 id, u32 dbg_type, int *temp);
43#else
44static inline int tsens2xxx_dbg(struct tsens_device *data, u32 id,
45 u32 dbg_type, int *temp)
46{ return -ENXIO; }
47#endif
48
49struct tsens_dbg {
50 u32 dbg_count[DEBUG_SIZE];
51 u32 idx;
52 unsigned long long time_stmp[DEBUG_SIZE];
53 unsigned long temp[DEBUG_SIZE];
54};
55
56struct tsens_dbg_context {
57 struct tsens_device *tmdev;
58 struct tsens_dbg tsens_thread_iq_dbg;
59 struct tsens_dbg sensor_dbg_info[TSENS_MAX_SENSORS];
60 int tsens_critical_wd_cnt;
61 struct delayed_work tsens_critical_poll_test;
62};
63
64struct tsens_context {
65 enum thermal_device_mode high_th_state;
66 enum thermal_device_mode low_th_state;
67 enum thermal_device_mode crit_th_state;
68 int high_temp;
69 int low_temp;
70 int crit_temp;
71};
72
73struct tsens_sensor {
74 struct tsens_device *tmdev;
75 struct thermal_zone_device *tzd;
76 u32 hw_id;
77 u32 id;
78 const char *sensor_name;
79 struct tsens_context thr_state;
80};
81
82/**
83 * struct tsens_ops - operations as supported by the tsens device
84 * @init: Function to initialize the tsens device
85 * @get_temp: Function which returns the temp in millidegC
86 */
87struct tsens_ops {
88 int (*hw_init)(struct tsens_device *);
89 int (*get_temp)(struct tsens_sensor *, int *);
Siddartha Mohanadoss07b10612017-04-07 14:53:45 -070090 int (*set_trips)(struct tsens_sensor *, int, int);
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -080091 int (*interrupts_reg)(struct tsens_device *);
92 int (*dbg)(struct tsens_device *, u32, u32, int *);
93};
94
95struct tsens_irqs {
96 const char *name;
97 irqreturn_t (*handler)(int, void *);
98};
99
100/**
101 * struct tsens_data - tsens instance specific data
102 * @num_sensors: Max number of sensors supported by platform
103 * @ops: operations the tsens instance supports
104 * @hw_ids: Subset of sensors ids supported by platform, if not the first n
105 */
106struct tsens_data {
107 const u32 num_sensors;
108 const struct tsens_ops *ops;
109 unsigned int *hw_ids;
110 u32 temp_factor;
111 bool cycle_monitor;
112 u32 cycle_compltn_monitor_val;
113 bool wd_bark;
114 u32 wd_bark_val;
115};
116
117struct tsens_device {
118 struct device *dev;
119 struct platform_device *pdev;
120 struct list_head list;
121 u32 num_sensors;
122 struct regmap *map;
123 struct regmap_field *status_field;
Siddartha Mohanadoss07b10612017-04-07 14:53:45 -0700124 void __iomem *tsens_srot_addr;
125 void __iomem *tsens_tm_addr;
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -0800126 const struct tsens_ops *ops;
127 struct tsens_dbg_context tsens_dbg;
128 spinlock_t tsens_crit_lock;
129 spinlock_t tsens_upp_low_lock;
130 const struct tsens_data *ctrl_data;
131 struct tsens_sensor sensor[0];
132};
133
134extern const struct tsens_data data_tsens2xxx, data_tsens23xx, data_tsens24xx;
135
136#endif /* __QCOM_TSENS_H__ */