tsens.h 4.2 KB

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