msm-charger.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Copyright (c) 2010-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. #ifndef __MSM_CHARGER_H__
  14. #define __MSM_CHARGER_H__
  15. #include <linux/power_supply.h>
  16. enum {
  17. CHG_TYPE_USB,
  18. CHG_TYPE_AC
  19. };
  20. enum msm_hardware_charger_event {
  21. CHG_INSERTED_EVENT,
  22. CHG_ENUMERATED_EVENT,
  23. CHG_REMOVED_EVENT,
  24. CHG_DONE_EVENT,
  25. CHG_BATT_BEGIN_FAST_CHARGING,
  26. CHG_BATT_CHG_RESUME,
  27. CHG_BATT_TEMP_OUTOFRANGE,
  28. CHG_BATT_TEMP_INRANGE,
  29. CHG_BATT_INSERTED,
  30. CHG_BATT_REMOVED,
  31. CHG_BATT_STATUS_CHANGE,
  32. CHG_BATT_NEEDS_RECHARGING,
  33. };
  34. /**
  35. * enum hardware_charger_state
  36. * @CHG_ABSENT_STATE: charger cable is unplugged
  37. * @CHG_PRESENT_STATE: charger cable is plugged but charge current isnt drawn
  38. * @CHG_READY_STATE: charger cable is plugged and kernel knows how much current
  39. * it can draw
  40. * @CHG_CHARGING_STATE: charger cable is plugged and current is drawn for
  41. * charging
  42. */
  43. enum msm_hardware_charger_state {
  44. CHG_ABSENT_STATE,
  45. CHG_PRESENT_STATE,
  46. CHG_READY_STATE,
  47. CHG_CHARGING_STATE,
  48. };
  49. struct msm_hardware_charger {
  50. int type;
  51. int rating;
  52. const char *name;
  53. int (*start_charging) (struct msm_hardware_charger *hw_chg,
  54. int chg_voltage, int chg_current);
  55. int (*stop_charging) (struct msm_hardware_charger *hw_chg);
  56. int (*charging_switched) (struct msm_hardware_charger *hw_chg);
  57. void (*start_system_current) (struct msm_hardware_charger *hw_chg,
  58. int chg_current);
  59. void (*stop_system_current) (struct msm_hardware_charger *hw_chg);
  60. void *charger_private; /* used by the msm_charger.c */
  61. };
  62. struct msm_battery_gauge {
  63. int (*get_battery_mvolts) (void);
  64. int (*get_battery_temperature) (void);
  65. int (*is_battery_present) (void);
  66. int (*is_battery_temp_within_range) (void);
  67. int (*is_battery_id_valid) (void);
  68. int (*get_battery_status)(void);
  69. int (*get_batt_remaining_capacity) (void);
  70. int (*monitor_for_recharging) (void);
  71. };
  72. /**
  73. * struct msm_charger_platform_data
  74. * @safety_time: max charging time in minutes
  75. * @update_time: how often the userland be updated of the charging progress
  76. * @max_voltage: the max voltage the battery should be charged upto
  77. * @min_voltage: the voltage where charging method switches from trickle to fast
  78. * @get_batt_capacity_percent: a board specific function to return battery
  79. * capacity. Can be null - a default one will be used
  80. */
  81. struct msm_charger_platform_data {
  82. unsigned int safety_time;
  83. unsigned int update_time;
  84. unsigned int max_voltage;
  85. unsigned int min_voltage;
  86. unsigned int (*get_batt_capacity_percent) (void);
  87. };
  88. typedef void (*notify_vbus_state) (int);
  89. #if defined(CONFIG_BATTERY_MSM8X60) || defined(CONFIG_BATTERY_MSM8X60_MODULE)
  90. void msm_battery_gauge_register(struct msm_battery_gauge *batt_gauge);
  91. void msm_battery_gauge_unregister(struct msm_battery_gauge *batt_gauge);
  92. int msm_charger_register(struct msm_hardware_charger *hw_chg);
  93. int msm_charger_unregister(struct msm_hardware_charger *hw_chg);
  94. int msm_charger_notify_event(struct msm_hardware_charger *hw_chg,
  95. enum msm_hardware_charger_event event);
  96. void msm_charger_vbus_draw(unsigned int mA);
  97. int msm_charger_register_vbus_sn(void (*callback)(int));
  98. void msm_charger_unregister_vbus_sn(void (*callback)(int));
  99. #else
  100. static inline void msm_battery_gauge_register(struct msm_battery_gauge *gauge)
  101. {
  102. }
  103. static inline void msm_battery_gauge_unregister(struct msm_battery_gauge *gauge)
  104. {
  105. }
  106. static inline int msm_charger_register(struct msm_hardware_charger *hw_chg)
  107. {
  108. return -ENXIO;
  109. }
  110. static inline int msm_charger_unregister(struct msm_hardware_charger *hw_chg)
  111. {
  112. return -ENXIO;
  113. }
  114. static inline int msm_charger_notify_event(struct msm_hardware_charger *hw_chg,
  115. enum msm_hardware_charger_event event)
  116. {
  117. return -ENXIO;
  118. }
  119. static inline void msm_charger_vbus_draw(unsigned int mA)
  120. {
  121. }
  122. static inline int msm_charger_register_vbus_sn(void (*callback)(int))
  123. {
  124. return -ENXIO;
  125. }
  126. static inline void msm_charger_unregister_vbus_sn(void (*callback)(int))
  127. {
  128. }
  129. #endif
  130. #endif /* __MSM_CHARGER_H__ */