adc-tm-clients.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __QCOM_ADC_TM_H_CLIENTS__
  6. #define __QCOM_ADC_TM_H_CLIENTS__
  7. #include <linux/err.h>
  8. #include <linux/types.h>
  9. struct adc_tm_chip;
  10. struct adc5_chip;
  11. /**
  12. * enum adc_tm_state - This lets the client know whether the threshold
  13. * that was crossed was high/low.
  14. * %ADC_TM_HIGH_STATE: Client is notified of crossing the requested high
  15. * voltage threshold.
  16. * %ADC_TM_COOL_STATE: Client is notified of crossing the requested cool
  17. * temperature threshold.
  18. * %ADC_TM_LOW_STATE: Client is notified of crossing the requested low
  19. * voltage threshold.
  20. * %ADC_TM_WARM_STATE: Client is notified of crossing the requested high
  21. * temperature threshold.
  22. */
  23. enum adc_tm_state {
  24. ADC_TM_HIGH_STATE = 0,
  25. ADC_TM_COOL_STATE = ADC_TM_HIGH_STATE,
  26. ADC_TM_LOW_STATE,
  27. ADC_TM_WARM_STATE = ADC_TM_LOW_STATE,
  28. ADC_TM_STATE_NUM,
  29. };
  30. /**
  31. * enum adc_tm_state_request - Request to enable/disable the corresponding
  32. * high/low voltage/temperature thresholds.
  33. * %ADC_TM_HIGH_THR_ENABLE: Enable high voltage threshold.
  34. * %ADC_TM_COOL_THR_ENABLE = Enables cool temperature threshold.
  35. * %ADC_TM_LOW_THR_ENABLE: Enable low voltage/temperature threshold.
  36. * %ADC_TM_WARM_THR_ENABLE = Enables warm temperature threshold.
  37. * %ADC_TM_HIGH_LOW_THR_ENABLE: Enable high and low voltage/temperature
  38. * threshold.
  39. * %ADC_TM_HIGH_THR_DISABLE: Disable high voltage/temperature threshold.
  40. * %ADC_TM_COOL_THR_ENABLE = Disables cool temperature threshold.
  41. * %ADC_TM_LOW_THR_DISABLE: Disable low voltage/temperature threshold.
  42. * %ADC_TM_WARM_THR_ENABLE = Disables warm temperature threshold.
  43. * %ADC_TM_HIGH_THR_DISABLE: Disable high and low voltage/temperature
  44. * threshold.
  45. */
  46. enum adc_tm_state_request {
  47. ADC_TM_HIGH_THR_ENABLE = 0,
  48. ADC_TM_COOL_THR_ENABLE = ADC_TM_HIGH_THR_ENABLE,
  49. ADC_TM_LOW_THR_ENABLE,
  50. ADC_TM_WARM_THR_ENABLE = ADC_TM_LOW_THR_ENABLE,
  51. ADC_TM_HIGH_LOW_THR_ENABLE,
  52. ADC_TM_HIGH_THR_DISABLE,
  53. ADC_TM_COOL_THR_DISABLE = ADC_TM_HIGH_THR_DISABLE,
  54. ADC_TM_LOW_THR_DISABLE,
  55. ADC_TM_WARM_THR_DISABLE = ADC_TM_LOW_THR_DISABLE,
  56. ADC_TM_HIGH_LOW_THR_DISABLE,
  57. ADC_TM_THR_NUM,
  58. };
  59. struct adc_tm_param {
  60. unsigned long id;
  61. int low_thr;
  62. int high_thr;
  63. uint32_t channel;
  64. enum adc_tm_state_request state_request;
  65. void *btm_ctx;
  66. void (*threshold_notification)(enum adc_tm_state state,
  67. void *ctx);
  68. };
  69. struct device;
  70. /* Public API */
  71. #if IS_ENABLED(CONFIG_QCOM_SPMI_ADC5_GEN3)
  72. struct adc5_chip *get_adc_tm_gen3(struct device *dev, const char *name);
  73. int32_t adc_tm_channel_measure_gen3(struct adc5_chip *chip,
  74. struct adc_tm_param *param);
  75. int32_t adc_tm_disable_chan_meas_gen3(struct adc5_chip *chip,
  76. struct adc_tm_param *param);
  77. #else
  78. static inline struct adc5_chip *get_adc_tm_gen3(
  79. struct device *dev, const char *name)
  80. { return ERR_PTR(-ENXIO); }
  81. static inline int32_t adc_tm_channel_measure_gen3(
  82. struct adc5_chip *chip,
  83. struct adc_tm_param *param)
  84. { return -ENXIO; }
  85. static inline int32_t adc_tm_disable_chan_meas_gen3(
  86. struct adc5_chip *chip,
  87. struct adc_tm_param *param)
  88. { return -ENXIO; }
  89. #endif
  90. #endif /* __QCOM_ADC_TM_H_CLIENTS__ */