qcom-vadc-common.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Code shared between the different Qualcomm PMIC voltage ADCs
  4. */
  5. #ifndef QCOM_VADC_COMMON_H
  6. #define QCOM_VADC_COMMON_H
  7. #define VADC_CONV_TIME_MIN_US 2000
  8. #define VADC_CONV_TIME_MAX_US 2100
  9. /* Min ADC code represents 0V */
  10. #define VADC_MIN_ADC_CODE 0x6000
  11. /* Max ADC code represents full-scale range of 1.8V */
  12. #define VADC_MAX_ADC_CODE 0xa800
  13. #define VADC_ABSOLUTE_RANGE_UV 625000
  14. #define VADC_RATIOMETRIC_RANGE 1800
  15. #define VADC_DEF_PRESCALING 0 /* 1:1 */
  16. #define VADC_DEF_DECIMATION 0 /* 512 */
  17. #define VADC_DEF_HW_SETTLE_TIME 0 /* 0 us */
  18. #define VADC_DEF_AVG_SAMPLES 0 /* 1 sample */
  19. #define VADC_DEF_CALIB_TYPE VADC_CALIB_ABSOLUTE
  20. #define VADC_DECIMATION_MIN 512
  21. #define VADC_DECIMATION_MAX 4096
  22. #define VADC_HW_SETTLE_DELAY_MAX 10000
  23. #define VADC_AVG_SAMPLES_MAX 512
  24. #define KELVINMIL_CELSIUSMIL 273150
  25. #define PMI_CHG_SCALE_1 -138890
  26. #define PMI_CHG_SCALE_2 391750000000LL
  27. /**
  28. * struct vadc_map_pt - Map the graph representation for ADC channel
  29. * @x: Represent the ADC digitized code.
  30. * @y: Represent the physical data which can be temperature, voltage,
  31. * resistance.
  32. */
  33. struct vadc_map_pt {
  34. s32 x;
  35. s32 y;
  36. };
  37. /*
  38. * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels.
  39. * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for
  40. * calibration.
  41. */
  42. enum vadc_calibration {
  43. VADC_CALIB_ABSOLUTE = 0,
  44. VADC_CALIB_RATIOMETRIC
  45. };
  46. /**
  47. * struct vadc_linear_graph - Represent ADC characteristics.
  48. * @dy: numerator slope to calculate the gain.
  49. * @dx: denominator slope to calculate the gain.
  50. * @gnd: A/D word of the ground reference used for the channel.
  51. *
  52. * Each ADC device has different offset and gain parameters which are
  53. * computed to calibrate the device.
  54. */
  55. struct vadc_linear_graph {
  56. s32 dy;
  57. s32 dx;
  58. s32 gnd;
  59. };
  60. /**
  61. * struct vadc_prescale_ratio - Represent scaling ratio for ADC input.
  62. * @num: the inverse numerator of the gain applied to the input channel.
  63. * @den: the inverse denominator of the gain applied to the input channel.
  64. */
  65. struct vadc_prescale_ratio {
  66. u32 num;
  67. u32 den;
  68. };
  69. /**
  70. * enum vadc_scale_fn_type - Scaling function to convert ADC code to
  71. * physical scaled units for the channel.
  72. * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV).
  73. * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC.
  74. * Uses a mapping table with 100K pullup.
  75. * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
  76. * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC.
  77. * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp
  78. */
  79. enum vadc_scale_fn_type {
  80. SCALE_DEFAULT = 0,
  81. SCALE_THERM_100K_PULLUP,
  82. SCALE_PMIC_THERM,
  83. SCALE_XOTHERM,
  84. SCALE_PMI_CHG_TEMP,
  85. };
  86. int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
  87. const struct vadc_linear_graph *calib_graph,
  88. const struct vadc_prescale_ratio *prescale,
  89. bool absolute,
  90. u16 adc_code, int *result_mdec);
  91. int qcom_vadc_decimation_from_dt(u32 value);
  92. #endif /* QCOM_VADC_COMMON_H */