charger-manager.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co., Ltd.
  3. * MyungJoo.Ham <myungjoo.ham@samsung.com>
  4. *
  5. * Charger Manager.
  6. * This framework enables to control and multiple chargers and to
  7. * monitor charging even in the context of suspend-to-RAM with
  8. * an interface combining the chargers.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. **/
  14. #ifndef _CHARGER_MANAGER_H
  15. #define _CHARGER_MANAGER_H
  16. #include <linux/power_supply.h>
  17. #include <linux/extcon.h>
  18. enum data_source {
  19. CM_BATTERY_PRESENT,
  20. CM_NO_BATTERY,
  21. CM_FUEL_GAUGE,
  22. CM_CHARGER_STAT,
  23. };
  24. enum polling_modes {
  25. CM_POLL_DISABLE = 0,
  26. CM_POLL_ALWAYS,
  27. CM_POLL_EXTERNAL_POWER_ONLY,
  28. CM_POLL_CHARGING_ONLY,
  29. };
  30. enum cm_event_types {
  31. CM_EVENT_UNKNOWN = 0,
  32. CM_EVENT_BATT_FULL,
  33. CM_EVENT_BATT_IN,
  34. CM_EVENT_BATT_OUT,
  35. CM_EVENT_EXT_PWR_IN_OUT,
  36. CM_EVENT_CHG_START_STOP,
  37. CM_EVENT_OTHERS,
  38. };
  39. /**
  40. * struct charger_global_desc
  41. * @rtc_name: the name of RTC used to wake up the system from suspend.
  42. * @rtc_only_wakeup:
  43. * If the system is woken up by waekup-sources other than the RTC or
  44. * callbacks, Charger Manager should recognize with
  45. * rtc_only_wakeup() returning false.
  46. * If the RTC given to CM is the only wakeup reason,
  47. * rtc_only_wakeup should return true.
  48. * @assume_timer_stops_in_suspend:
  49. * Assume that the jiffy timer stops in suspend-to-RAM.
  50. * When enabled, CM does not rely on jiffies value in
  51. * suspend_again and assumes that jiffies value does not
  52. * change during suspend.
  53. */
  54. struct charger_global_desc {
  55. char *rtc_name;
  56. bool (*rtc_only_wakeup)(void);
  57. bool assume_timer_stops_in_suspend;
  58. };
  59. /**
  60. * struct charger_cable
  61. * @extcon_name: the name of extcon device.
  62. * @name: the name of charger cable(external connector).
  63. * @extcon_dev: the extcon device.
  64. * @wq: the workqueue to control charger according to the state of
  65. * charger cable. If charger cable is attached, enable charger.
  66. * But if charger cable is detached, disable charger.
  67. * @nb: the notifier block to receive changed state from EXTCON
  68. * (External Connector) when charger cable is attached/detached.
  69. * @attached: the state of charger cable.
  70. * true: the charger cable is attached
  71. * false: the charger cable is detached
  72. * @charger: the instance of struct charger_regulator.
  73. * @cm: the Charger Manager representing the battery.
  74. */
  75. struct charger_cable {
  76. const char *extcon_name;
  77. const char *name;
  78. /* The charger-manager use Exton framework*/
  79. struct extcon_specific_cable_nb extcon_dev;
  80. struct work_struct wq;
  81. struct notifier_block nb;
  82. /* The state of charger cable */
  83. bool attached;
  84. struct charger_regulator *charger;
  85. /*
  86. * Set min/max current of regulator to protect over-current issue
  87. * according to a kind of charger cable when cable is attached.
  88. */
  89. int min_uA;
  90. int max_uA;
  91. struct charger_manager *cm;
  92. };
  93. /**
  94. * struct charger_regulator
  95. * @regulator_name: the name of regulator for using charger.
  96. * @consumer: the regulator consumer for the charger.
  97. * @cables:
  98. * the array of charger cables to enable/disable charger
  99. * and set current limit according to constratint data of
  100. * struct charger_cable if only charger cable included
  101. * in the array of charger cables is attached/detached.
  102. * @num_cables: the number of charger cables.
  103. */
  104. struct charger_regulator {
  105. /* The name of regulator for charging */
  106. const char *regulator_name;
  107. struct regulator *consumer;
  108. /*
  109. * Store constraint information related to current limit,
  110. * each cable have different condition for charging.
  111. */
  112. struct charger_cable *cables;
  113. int num_cables;
  114. };
  115. /**
  116. * struct charger_desc
  117. * @psy_name: the name of power-supply-class for charger manager
  118. * @polling_mode:
  119. * Determine which polling mode will be used
  120. * @fullbatt_vchkdrop_ms:
  121. * @fullbatt_vchkdrop_uV:
  122. * Check voltage drop after the battery is fully charged.
  123. * If it has dropped more than fullbatt_vchkdrop_uV after
  124. * fullbatt_vchkdrop_ms, CM will restart charging.
  125. * @fullbatt_uV: voltage in microvolt
  126. * If it is not being charged and VBATT >= fullbatt_uV,
  127. * it is assumed to be full.
  128. * @polling_interval_ms: interval in millisecond at which
  129. * charger manager will monitor battery health
  130. * @battery_present:
  131. * Specify where information for existance of battery can be obtained
  132. * @psy_charger_stat: the names of power-supply for chargers
  133. * @num_charger_regulator: the number of entries in charger_regulators
  134. * @charger_regulators: array of regulator_bulk_data for chargers
  135. * @psy_fuel_gauge: the name of power-supply for fuel gauge
  136. * @temperature_out_of_range:
  137. * Determine whether the status is overheat or cold or normal.
  138. * return_value > 0: overheat
  139. * return_value == 0: normal
  140. * return_value < 0: cold
  141. * @measure_battery_temp:
  142. * true: measure battery temperature
  143. * false: measure ambient temperature
  144. */
  145. struct charger_desc {
  146. char *psy_name;
  147. enum polling_modes polling_mode;
  148. unsigned int polling_interval_ms;
  149. unsigned int fullbatt_vchkdrop_ms;
  150. unsigned int fullbatt_vchkdrop_uV;
  151. unsigned int fullbatt_uV;
  152. enum data_source battery_present;
  153. char **psy_charger_stat;
  154. int num_charger_regulators;
  155. struct charger_regulator *charger_regulators;
  156. char *psy_fuel_gauge;
  157. int (*temperature_out_of_range)(int *mC);
  158. bool measure_battery_temp;
  159. };
  160. #define PSY_NAME_MAX 30
  161. /**
  162. * struct charger_manager
  163. * @entry: entry for list
  164. * @dev: device pointer
  165. * @desc: instance of charger_desc
  166. * @fuel_gauge: power_supply for fuel gauge
  167. * @charger_stat: array of power_supply for chargers
  168. * @charger_enabled: the state of charger
  169. * @fullbatt_vchk_jiffies_at:
  170. * jiffies at the time full battery check will occur.
  171. * @fullbatt_vchk_uV: voltage in microvolt
  172. * criteria for full battery
  173. * @fullbatt_vchk_work: work queue for full battery check
  174. * @emergency_stop:
  175. * When setting true, stop charging
  176. * @last_temp_mC: the measured temperature in milli-Celsius
  177. * @psy_name_buf: the name of power-supply-class for charger manager
  178. * @charger_psy: power_supply for charger manager
  179. * @status_save_ext_pwr_inserted:
  180. * saved status of external power before entering suspend-to-RAM
  181. * @status_save_batt:
  182. * saved status of battery before entering suspend-to-RAM
  183. */
  184. struct charger_manager {
  185. struct list_head entry;
  186. struct device *dev;
  187. struct charger_desc *desc;
  188. struct power_supply *fuel_gauge;
  189. struct power_supply **charger_stat;
  190. bool charger_enabled;
  191. unsigned long fullbatt_vchk_jiffies_at;
  192. unsigned int fullbatt_vchk_uV;
  193. struct delayed_work fullbatt_vchk_work;
  194. int emergency_stop;
  195. int last_temp_mC;
  196. char psy_name_buf[PSY_NAME_MAX + 1];
  197. struct power_supply charger_psy;
  198. bool status_save_ext_pwr_inserted;
  199. bool status_save_batt;
  200. };
  201. #ifdef CONFIG_CHARGER_MANAGER
  202. extern int setup_charger_manager(struct charger_global_desc *gd);
  203. extern bool cm_suspend_again(void);
  204. extern void cm_notify_event(struct power_supply *psy,
  205. enum cm_event_types type, char *msg);
  206. #else
  207. static inline int setup_charger_manager(struct charger_global_desc *gd)
  208. { return 0; }
  209. static inline bool cm_suspend_again(void) { return false; }
  210. static inline void cm_notify_event(struct power_supply *psy,
  211. enum cm_event_types type, char *msg) { }
  212. #endif
  213. #endif /* _CHARGER_MANAGER_H */