Jishnu Prakash | b520366 | 2019-03-08 13:06:23 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 2 | * |
Siddartha Mohanadoss | cd8aa0b | 2017-04-06 15:17:46 -0700 | [diff] [blame] | 3 | * 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 Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 6 | * |
| 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 Mohanadoss | cd8aa0b | 2017-04-06 15:17:46 -0700 | [diff] [blame] | 11 | * |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 12 | */ |
| 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 |
Chinkit Kumar,Kirti Kumar Parmar | 253de88 | 2018-06-06 00:11:56 +0530 | [diff] [blame] | 26 | #define TSENS_NUM_SENSORS_8937 11 |
| 27 | #define TSENS_NUM_SENSORS_8909 5 |
Siddartha Mohanadoss | 07b1061 | 2017-04-07 14:53:45 -0700 | [diff] [blame] | 28 | #define TSENS_CONTROLLER_ID(n) (n) |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 29 | #define TSENS_CTRL_ADDR(n) (n) |
Siddartha Mohanadoss | 07b1061 | 2017-04-07 14:53:45 -0700 | [diff] [blame] | 30 | #define TSENS_TM_SN_STATUS(n) ((n) + 0xa0) |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 31 | |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 32 | #define ONE_PT_CALIB 0x1 |
| 33 | #define ONE_PT_CALIB2 0x2 |
| 34 | #define TWO_PT_CALIB 0x3 |
| 35 | |
Chinkit Kumar,Kirti Kumar Parmar | 253de88 | 2018-06-06 00:11:56 +0530 | [diff] [blame] | 36 | #define SLOPE_FACTOR 1000 |
| 37 | #define SLOPE_DEFAULT 3200 |
| 38 | |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 39 | enum tsens_dbg_type { |
| 40 | TSENS_DBG_POLL, |
| 41 | TSENS_DBG_LOG_TEMP_READS, |
| 42 | TSENS_DBG_LOG_INTERRUPT_TIMESTAMP, |
Siddartha Mohanadoss | 64a5da3 | 2017-05-09 11:09:51 -0700 | [diff] [blame] | 43 | TSENS_DBG_LOG_BUS_ID_DATA, |
Ashok Jammigumpula | a1b7ec1 | 2017-11-23 15:37:44 +0530 | [diff] [blame] | 44 | TSENS_DBG_MTC_DATA, |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 45 | TSENS_DBG_LOG_MAX |
| 46 | }; |
| 47 | |
| 48 | #define tsens_sec_to_msec_value 1000 |
| 49 | |
| 50 | struct tsens_device; |
| 51 | |
| 52 | #if defined(CONFIG_THERMAL_TSENS) |
| 53 | int tsens2xxx_dbg(struct tsens_device *data, u32 id, u32 dbg_type, int *temp); |
| 54 | #else |
| 55 | static inline int tsens2xxx_dbg(struct tsens_device *data, u32 id, |
| 56 | u32 dbg_type, int *temp) |
| 57 | { return -ENXIO; } |
| 58 | #endif |
| 59 | |
| 60 | struct tsens_dbg { |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 61 | u32 idx; |
| 62 | unsigned long long time_stmp[DEBUG_SIZE]; |
| 63 | unsigned long temp[DEBUG_SIZE]; |
| 64 | }; |
| 65 | |
| 66 | struct tsens_dbg_context { |
| 67 | struct tsens_device *tmdev; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 68 | struct tsens_dbg sensor_dbg_info[TSENS_MAX_SENSORS]; |
| 69 | int tsens_critical_wd_cnt; |
Rama Krishna Phani A | 6ad6633 | 2017-10-25 21:20:04 +0530 | [diff] [blame] | 70 | u32 irq_idx; |
| 71 | unsigned long long irq_time_stmp[DEBUG_SIZE]; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 72 | struct delayed_work tsens_critical_poll_test; |
| 73 | }; |
| 74 | |
| 75 | struct tsens_context { |
Jishnu Prakash | b520366 | 2019-03-08 13:06:23 +0530 | [diff] [blame] | 76 | enum thermal_trip_activation_mode high_th_state; |
| 77 | enum thermal_trip_activation_mode low_th_state; |
| 78 | enum thermal_trip_activation_mode crit_th_state; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 79 | int high_temp; |
| 80 | int low_temp; |
| 81 | int crit_temp; |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 82 | int high_adc_code; |
| 83 | int low_adc_code; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | struct tsens_sensor { |
| 87 | struct tsens_device *tmdev; |
| 88 | struct thermal_zone_device *tzd; |
| 89 | u32 hw_id; |
| 90 | u32 id; |
| 91 | const char *sensor_name; |
| 92 | struct tsens_context thr_state; |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 93 | int offset; |
| 94 | int slope; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | /** |
| 98 | * struct tsens_ops - operations as supported by the tsens device |
| 99 | * @init: Function to initialize the tsens device |
| 100 | * @get_temp: Function which returns the temp in millidegC |
| 101 | */ |
| 102 | struct tsens_ops { |
| 103 | int (*hw_init)(struct tsens_device *); |
| 104 | int (*get_temp)(struct tsens_sensor *, int *); |
Siddartha Mohanadoss | 07b1061 | 2017-04-07 14:53:45 -0700 | [diff] [blame] | 105 | int (*set_trips)(struct tsens_sensor *, int, int); |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 106 | int (*interrupts_reg)(struct tsens_device *); |
| 107 | int (*dbg)(struct tsens_device *, u32, u32, int *); |
Siddartha Mohanadoss | f86413d | 2017-07-18 13:44:31 -0700 | [diff] [blame] | 108 | int (*sensor_en)(struct tsens_device *, u32); |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 109 | int (*calibrate)(struct tsens_device *); |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct tsens_irqs { |
| 113 | const char *name; |
| 114 | irqreturn_t (*handler)(int, void *); |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * struct tsens_data - tsens instance specific data |
| 119 | * @num_sensors: Max number of sensors supported by platform |
| 120 | * @ops: operations the tsens instance supports |
| 121 | * @hw_ids: Subset of sensors ids supported by platform, if not the first n |
| 122 | */ |
| 123 | struct tsens_data { |
| 124 | const u32 num_sensors; |
| 125 | const struct tsens_ops *ops; |
| 126 | unsigned int *hw_ids; |
| 127 | u32 temp_factor; |
| 128 | bool cycle_monitor; |
Siddartha Mohanadoss | 64a5da3 | 2017-05-09 11:09:51 -0700 | [diff] [blame] | 129 | u32 cycle_compltn_monitor_mask; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 130 | bool wd_bark; |
Siddartha Mohanadoss | 64a5da3 | 2017-05-09 11:09:51 -0700 | [diff] [blame] | 131 | u32 wd_bark_mask; |
Ashok Jammigumpula | a1b7ec1 | 2017-11-23 15:37:44 +0530 | [diff] [blame] | 132 | bool mtc; |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 133 | bool valid_status_check; |
Siva Kumar Akkireddi | ee8aed9 | 2018-04-09 17:06:05 +0530 | [diff] [blame] | 134 | u32 ver_major; |
| 135 | u32 ver_minor; |
Ashok Jammigumpula | a1b7ec1 | 2017-11-23 15:37:44 +0530 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | struct tsens_mtc_sysfs { |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 139 | u32 zone_log; |
Ashok Jammigumpula | a1b7ec1 | 2017-11-23 15:37:44 +0530 | [diff] [blame] | 140 | int zone_mtc; |
| 141 | int th1; |
| 142 | int th2; |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 143 | u32 zone_hist; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | struct tsens_device { |
| 147 | struct device *dev; |
| 148 | struct platform_device *pdev; |
| 149 | struct list_head list; |
Chinkit Kumar,Kirti Kumar Parmar | 253de88 | 2018-06-06 00:11:56 +0530 | [diff] [blame] | 150 | bool prev_reading_avail; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 151 | struct regmap *map; |
| 152 | struct regmap_field *status_field; |
Siddartha Mohanadoss | 07b1061 | 2017-04-07 14:53:45 -0700 | [diff] [blame] | 153 | void __iomem *tsens_srot_addr; |
| 154 | void __iomem *tsens_tm_addr; |
Rama Krishna Phani A | e677c1c | 2018-01-31 18:51:43 +0530 | [diff] [blame] | 155 | void __iomem *tsens_calib_addr; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 156 | const struct tsens_ops *ops; |
| 157 | struct tsens_dbg_context tsens_dbg; |
| 158 | spinlock_t tsens_crit_lock; |
| 159 | spinlock_t tsens_upp_low_lock; |
| 160 | const struct tsens_data *ctrl_data; |
Jishnu Prakash | 53c2124 | 2018-05-16 10:42:15 +0530 | [diff] [blame] | 161 | struct tsens_mtc_sysfs mtcsys; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 162 | struct tsens_sensor sensor[0]; |
| 163 | }; |
| 164 | |
| 165 | extern const struct tsens_data data_tsens2xxx, data_tsens23xx, data_tsens24xx; |
Chinkit Kumar,Kirti Kumar Parmar | 253de88 | 2018-06-06 00:11:56 +0530 | [diff] [blame] | 166 | extern const struct tsens_data data_tsens14xx, data_tsens1xxx_8909; |
Ashok Jammigumpula | a1b7ec1 | 2017-11-23 15:37:44 +0530 | [diff] [blame] | 167 | extern struct list_head tsens_device_list; |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 168 | |
Chinkit Kumar,Kirti Kumar Parmar | 253de88 | 2018-06-06 00:11:56 +0530 | [diff] [blame] | 169 | extern int calibrate_8937(struct tsens_device *tmdev); |
| 170 | extern int calibrate_8909(struct tsens_device *tmdev); |
| 171 | |
Siddartha Mohanadoss | 41b4cd9 | 2017-02-21 14:34:23 -0800 | [diff] [blame] | 172 | #endif /* __QCOM_TSENS_H__ */ |