qcom-vadc-common.h 2.9 KB

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