batt-alarm.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* Copyright (c) 2011, 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. /*
  13. * Qualcomm PMIC PM8xxx Battery Alarm driver
  14. *
  15. */
  16. #ifndef __MFD_PM8XXX_BATT_ALARM_H__
  17. #define __MFD_PM8XXX_BATT_ALARM_H__
  18. #include <linux/bitops.h>
  19. #include <linux/errno.h>
  20. #include <linux/notifier.h>
  21. #define PM8XXX_BATT_ALARM_DEV_NAME "pm8xxx-batt-alarm"
  22. /**
  23. * enum pm8xxx_batt_alarm_core_data - PMIC core specific core passed into the
  24. * batter alarm driver as platform data
  25. * @irq_name:
  26. * @reg_addr_batt_alarm_threshold: PMIC threshold register address
  27. * @reg_addr_batt_alarm_ctrl1: PMIC control 1 register address
  28. * @reg_addr_batt_alarm_ctrl2: PMIC control 2 register address
  29. * @reg_addr_batt_alarm_pwm_ctrl: PMIC PWM control register address
  30. */
  31. struct pm8xxx_batt_alarm_core_data {
  32. char *irq_name;
  33. u16 reg_addr_threshold;
  34. u16 reg_addr_ctrl1;
  35. u16 reg_addr_ctrl2;
  36. u16 reg_addr_pwm_ctrl;
  37. };
  38. /**
  39. * enum pm8xxx_batt_alarm_comparator - battery alarm comparator ID values
  40. */
  41. enum pm8xxx_batt_alarm_comparator {
  42. PM8XXX_BATT_ALARM_LOWER_COMPARATOR,
  43. PM8XXX_BATT_ALARM_UPPER_COMPARATOR,
  44. };
  45. /**
  46. * enum pm8xxx_batt_alarm_hold_time - hold time required for out of range
  47. * battery voltage needed to trigger a status change. Enum names denote
  48. * hold time in milliseconds.
  49. */
  50. enum pm8xxx_batt_alarm_hold_time {
  51. PM8XXX_BATT_ALARM_HOLD_TIME_0p125_MS = 0,
  52. PM8XXX_BATT_ALARM_HOLD_TIME_0p25_MS,
  53. PM8XXX_BATT_ALARM_HOLD_TIME_0p5_MS,
  54. PM8XXX_BATT_ALARM_HOLD_TIME_1_MS,
  55. PM8XXX_BATT_ALARM_HOLD_TIME_2_MS,
  56. PM8XXX_BATT_ALARM_HOLD_TIME_4_MS,
  57. PM8XXX_BATT_ALARM_HOLD_TIME_8_MS,
  58. PM8XXX_BATT_ALARM_HOLD_TIME_16_MS,
  59. };
  60. /*
  61. * Bits that are set in the return value of pm8xxx_batt_alarm_status_read
  62. * to indicate crossing of the upper or lower threshold.
  63. */
  64. #define PM8XXX_BATT_ALARM_STATUS_BELOW_LOWER BIT(0)
  65. #define PM8XXX_BATT_ALARM_STATUS_ABOVE_UPPER BIT(1)
  66. #if defined(CONFIG_MFD_PM8XXX_BATT_ALARM) \
  67. || defined(CONFIG_MFD_PM8XXX_BATT_ALARM_MODULE)
  68. /**
  69. * pm8xxx_batt_alarm_enable - enable one of the battery voltage threshold
  70. * comparators
  71. * @comparator: selects which comparator to enable
  72. *
  73. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  74. */
  75. int pm8xxx_batt_alarm_enable(enum pm8xxx_batt_alarm_comparator comparator);
  76. /**
  77. * pm8xxx_batt_alarm_disable - disable one of the battery voltage threshold
  78. * comparators
  79. * @comparator: selects which comparator to disable
  80. *
  81. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  82. */
  83. int pm8xxx_batt_alarm_disable(enum pm8xxx_batt_alarm_comparator comparator);
  84. /**
  85. * pm8xxx_batt_alarm_threshold_set - set the lower and upper alarm thresholds
  86. * @comparator: selects which comparator to set the threshold of
  87. * @threshold_mV: battery voltage threshold in millivolts
  88. * set points = 2500-5675 mV in 25 mV steps
  89. *
  90. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  91. */
  92. int pm8xxx_batt_alarm_threshold_set(
  93. enum pm8xxx_batt_alarm_comparator comparator, int threshold_mV);
  94. /**
  95. * pm8xxx_batt_alarm_status_read - get status of both threshold comparators
  96. *
  97. * RETURNS: < 0 = error
  98. * 0 = battery voltage ok
  99. * BIT(0) set = battery voltage below lower threshold
  100. * BIT(1) set = battery voltage above upper threshold
  101. */
  102. int pm8xxx_batt_alarm_status_read(void);
  103. /**
  104. * pm8xxx_batt_alarm_register_notifier - register a notifier to run when a
  105. * battery voltage change interrupt fires
  106. * @nb: notifier block containing callback function to register
  107. *
  108. * nb->notifier_call must point to a function of this form -
  109. * int (*notifier_call)(struct notifier_block *nb, unsigned long status,
  110. * void *unused);
  111. * "status" will receive the battery alarm status; "unused" will be NULL.
  112. *
  113. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  114. */
  115. int pm8xxx_batt_alarm_register_notifier(struct notifier_block *nb);
  116. /**
  117. * pm8xxx_batt_alarm_unregister_notifier - unregister a notifier that is run
  118. * when a battery voltage change interrupt fires
  119. * @nb: notifier block containing callback function to unregister
  120. *
  121. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  122. */
  123. int pm8xxx_batt_alarm_unregister_notifier(struct notifier_block *nb);
  124. /**
  125. * pm8xxx_batt_alarm_hold_time_set - set hold time of interrupt output *
  126. * @hold_time: amount of time that battery voltage must remain outside of the
  127. * threshold range before the battery alarm interrupt triggers
  128. *
  129. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  130. */
  131. int pm8xxx_batt_alarm_hold_time_set(enum pm8xxx_batt_alarm_hold_time hold_time);
  132. /**
  133. * pm8xxx_batt_alarm_pwm_rate_set - set battery alarm update rate *
  134. * @use_pwm: 1 = use PWM update rate, 0 = comparators always active
  135. * @clock_scaler: PWM clock scaler = 2 to 9
  136. * @clock_divider: PWM clock divider = 2 to 8
  137. *
  138. * This function sets the rate at which the battery alarm module enables
  139. * the threshold comparators. The rate is determined by the following equation:
  140. *
  141. * f_update = (1024 Hz) / (clock_divider * (2 ^ clock_scaler))
  142. *
  143. * Thus, the update rate can range from 0.25 Hz to 128 Hz.
  144. *
  145. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  146. */
  147. int pm8xxx_batt_alarm_pwm_rate_set(int use_pwm, int clock_scaler,
  148. int clock_divider);
  149. #else
  150. static inline int
  151. pm8xxx_batt_alarm_enable(enum pm8xxx_batt_alarm_comparator comparator)
  152. { return -ENODEV; }
  153. static inline int
  154. pm8xxx_batt_alarm_disable(enum pm8xxx_batt_alarm_comparator comparator)
  155. { return -ENODEV; }
  156. static inline int
  157. pm8xxx_batt_alarm_threshold_set(enum pm8xxx_batt_alarm_comparator comparator,
  158. int threshold_mV)
  159. { return -ENODEV; }
  160. static inline int pm8xxx_batt_alarm_status_read(void)
  161. { return -ENODEV; }
  162. static inline int pm8xxx_batt_alarm_register_notifier(struct notifier_block *nb)
  163. { return -ENODEV; }
  164. static inline int
  165. pm8xxx_batt_alarm_unregister_notifier(struct notifier_block *nb)
  166. { return -ENODEV; }
  167. static inline int
  168. pm8xxx_batt_alarm_hold_time_set(enum pm8xxx_batt_alarm_hold_time hold_time)
  169. { return -ENODEV; }
  170. static inline int
  171. pm8xxx_batt_alarm_pwm_rate_set(int use_pwm, int clock_scaler, int clock_divider)
  172. { return -ENODEV; }
  173. #endif
  174. #endif /* __MFD_PM8XXX_BATT_ALARM_H__ */