tsens.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. struct regmap_field *status_field;
  73. struct tsens_context ctx;
  74. bool trdy;
  75. const struct tsens_ops *ops;
  76. struct tsens_sensor sensor[0];
  77. };
  78. char *qfprom_read(struct device *, const char *);
  79. void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);
  80. int init_common(struct tsens_device *);
  81. int get_temp_common(struct tsens_device *, int, int *);
  82. extern const struct tsens_data data_8916, data_8974, data_8960, data_8996;
  83. #endif /* __QCOM_TSENS_H__ */