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