ccadc.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __PMIC8XXX_CCADC_H__
  13. #define __PMIC8XXX_CCADC_H__
  14. #include <linux/mfd/pm8xxx/core.h>
  15. #define PM8XXX_CCADC_DEV_NAME "pm8xxx-ccadc"
  16. struct pm8xxx_ccadc_core_data {
  17. unsigned int batt_temp_channel;
  18. };
  19. /**
  20. * struct pm8xxx_ccadc_platform_data -
  21. * @ccadc_cdata: core data for the ccadc driver containing channel info
  22. * @r_sense_uohm: sense resistor value in (micro Ohms)
  23. * @calib_delay_ms: how often should the adc calculate gain and offset
  24. * @periodic_wakeup: a flag to indicate that this system wakeups periodically
  25. * for calibration/other housekeeping activities. The ccadc
  26. * does a quick calibration while resuming
  27. */
  28. struct pm8xxx_ccadc_platform_data {
  29. struct pm8xxx_ccadc_core_data ccadc_cdata;
  30. int r_sense_uohm;
  31. unsigned int calib_delay_ms;
  32. bool periodic_wakeup;
  33. };
  34. #define CCADC_READING_RESOLUTION_N 542535
  35. #define CCADC_READING_RESOLUTION_D 100000
  36. static inline s64 pm8xxx_ccadc_reading_to_microvolt(int revision, s64 cc)
  37. {
  38. return div_s64(cc * CCADC_READING_RESOLUTION_N,
  39. CCADC_READING_RESOLUTION_D);
  40. }
  41. #if defined(CONFIG_PM8XXX_CCADC) || defined(CONFIG_PM8XXX_CCADC_MODULE)
  42. /**
  43. * pm8xxx_cc_adjust_for_gain - the function to adjust the voltage read from
  44. * ccadc for gain compensation
  45. * @v: the voltage which needs to be gain compensated in microVolts
  46. *
  47. *
  48. * RETURNS: gain compensated voltage
  49. */
  50. s64 pm8xxx_cc_adjust_for_gain(s64 uv);
  51. /**
  52. * pm8xxx_calib_ccadc - calibration for ccadc. This will calculate gain
  53. * and offset and reprogram them in the appropriate
  54. * registers
  55. */
  56. void pm8xxx_calib_ccadc(void);
  57. /**
  58. * pm8xxx_ccadc_get_battery_current - return the battery current based on vsense
  59. * resitor in microamperes
  60. * @result: The pointer where the voltage will be updated. A -ve
  61. * result means that the current is flowing in
  62. * the battery - during battery charging
  63. *
  64. * RETURNS: Error code if there was a problem reading vsense, Zero otherwise
  65. * The result won't be updated in case of an error.
  66. *
  67. */
  68. int pm8xxx_ccadc_get_battery_current(int *bat_current);
  69. #else
  70. static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv)
  71. {
  72. return -ENXIO;
  73. }
  74. static inline void pm8xxx_calib_ccadc(void)
  75. {
  76. }
  77. static inline int pm8xxx_ccadc_get_battery_current(int *bat_current)
  78. {
  79. return -ENXIO;
  80. }
  81. #endif
  82. #endif /* __PMIC8XXX_CCADC_H__ */