tsens.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  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. #define ONE_PT_CALIB 0x1
  16. #define ONE_PT_CALIB2 0x2
  17. #define TWO_PT_CALIB 0x3
  18. #include <linux/thermal.h>
  19. struct tsens_device;
  20. struct tsens_sensor {
  21. struct tsens_device *tmdev;
  22. struct thermal_zone_device *tzd;
  23. int offset;
  24. int id;
  25. int hw_id;
  26. int slope;
  27. u32 status;
  28. };
  29. /**
  30. * struct tsens_ops - operations as supported by the tsens device
  31. * @init: Function to initialize the tsens device
  32. * @calibrate: Function to calibrate the tsens device
  33. * @get_temp: Function which returns the temp in millidegC
  34. * @enable: Function to enable (clocks/power) tsens device
  35. * @disable: Function to disable the tsens device
  36. * @suspend: Function to suspend the tsens device
  37. * @resume: Function to resume the tsens device
  38. * @get_trend: Function to get the thermal/temp trend
  39. */
  40. struct tsens_ops {
  41. /* mandatory callbacks */
  42. int (*init)(struct tsens_device *);
  43. int (*calibrate)(struct tsens_device *);
  44. int (*get_temp)(struct tsens_device *, int, int *);
  45. /* optional callbacks */
  46. int (*enable)(struct tsens_device *, int);
  47. void (*disable)(struct tsens_device *);
  48. int (*suspend)(struct tsens_device *);
  49. int (*resume)(struct tsens_device *);
  50. int (*get_trend)(struct tsens_device *, int, enum thermal_trend *);
  51. };
  52. /**
  53. * struct tsens_data - tsens instance specific data
  54. * @num_sensors: Max number of sensors supported by platform
  55. * @ops: operations the tsens instance supports
  56. * @hw_ids: Subset of sensors ids supported by platform, if not the first n
  57. */
  58. struct tsens_data {
  59. const u32 num_sensors;
  60. const struct tsens_ops *ops;
  61. unsigned int *hw_ids;
  62. };
  63. /* Registers to be saved/restored across a context loss */
  64. struct tsens_context {
  65. int threshold;
  66. int control;
  67. };
  68. struct tsens_device {
  69. struct device *dev;
  70. u32 num_sensors;
  71. struct regmap *map;
  72. u32 tm_offset;
  73. struct tsens_context ctx;
  74. const struct tsens_ops *ops;
  75. struct tsens_sensor sensor[0];
  76. };
  77. char *qfprom_read(struct device *, const char *);
  78. void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);
  79. int init_common(struct tsens_device *);
  80. int get_temp_common(struct tsens_device *, int, int *);
  81. /* TSENS v1 targets */
  82. extern const struct tsens_data data_8916, data_8974, data_8960;
  83. /* TSENS v2 targets */
  84. extern const struct tsens_data data_8996, data_tsens_v2;
  85. #endif /* __QCOM_TSENS_H__ */