tsens.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __QCOM_TSENS_H__
  6. #define __QCOM_TSENS_H__
  7. #define ONE_PT_CALIB 0x1
  8. #define ONE_PT_CALIB2 0x2
  9. #define TWO_PT_CALIB 0x3
  10. #include <linux/thermal.h>
  11. struct tsens_device;
  12. struct tsens_sensor {
  13. struct tsens_device *tmdev;
  14. struct thermal_zone_device *tzd;
  15. int offset;
  16. int id;
  17. int hw_id;
  18. int slope;
  19. u32 status;
  20. };
  21. /**
  22. * struct tsens_ops - operations as supported by the tsens device
  23. * @init: Function to initialize the tsens device
  24. * @calibrate: Function to calibrate the tsens device
  25. * @get_temp: Function which returns the temp in millidegC
  26. * @enable: Function to enable (clocks/power) tsens device
  27. * @disable: Function to disable the tsens device
  28. * @suspend: Function to suspend the tsens device
  29. * @resume: Function to resume the tsens device
  30. * @get_trend: Function to get the thermal/temp trend
  31. */
  32. struct tsens_ops {
  33. /* mandatory callbacks */
  34. int (*init)(struct tsens_device *);
  35. int (*calibrate)(struct tsens_device *);
  36. int (*get_temp)(struct tsens_device *, int, int *);
  37. /* optional callbacks */
  38. int (*enable)(struct tsens_device *, int);
  39. void (*disable)(struct tsens_device *);
  40. int (*suspend)(struct tsens_device *);
  41. int (*resume)(struct tsens_device *);
  42. int (*get_trend)(struct tsens_device *, int, enum thermal_trend *);
  43. };
  44. enum reg_list {
  45. SROT_CTRL_OFFSET,
  46. REG_ARRAY_SIZE,
  47. };
  48. /**
  49. * struct tsens_data - tsens instance specific data
  50. * @num_sensors: Max number of sensors supported by platform
  51. * @ops: operations the tsens instance supports
  52. * @hw_ids: Subset of sensors ids supported by platform, if not the first n
  53. * @reg_offsets: Register offsets for commonly used registers
  54. */
  55. struct tsens_data {
  56. const u32 num_sensors;
  57. const struct tsens_ops *ops;
  58. const u16 reg_offsets[REG_ARRAY_SIZE];
  59. unsigned int *hw_ids;
  60. };
  61. /* Registers to be saved/restored across a context loss */
  62. struct tsens_context {
  63. int threshold;
  64. int control;
  65. };
  66. struct tsens_device {
  67. struct device *dev;
  68. u32 num_sensors;
  69. struct regmap *tm_map;
  70. struct regmap *srot_map;
  71. u32 tm_offset;
  72. u16 reg_offsets[REG_ARRAY_SIZE];
  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__ */