charger-manager.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. Charger Manager
  2. (C) 2011 MyungJoo Ham <myungjoo.ham@samsung.com>, GPL
  3. Charger Manager provides in-kernel battery charger management that
  4. requires temperature monitoring during suspend-to-RAM state
  5. and where each battery may have multiple chargers attached and the userland
  6. wants to look at the aggregated information of the multiple chargers.
  7. Charger Manager is a platform_driver with power-supply-class entries.
  8. An instance of Charger Manager (a platform-device created with Charger-Manager)
  9. represents an independent battery with chargers. If there are multiple
  10. batteries with their own chargers acting independently in a system,
  11. the system may need multiple instances of Charger Manager.
  12. 1. Introduction
  13. ===============
  14. Charger Manager supports the following:
  15. * Support for multiple chargers (e.g., a device with USB, AC, and solar panels)
  16. A system may have multiple chargers (or power sources) and some of
  17. they may be activated at the same time. Each charger may have its
  18. own power-supply-class and each power-supply-class can provide
  19. different information about the battery status. This framework
  20. aggregates charger-related information from multiple sources and
  21. shows combined information as a single power-supply-class.
  22. * Support for in suspend-to-RAM polling (with suspend_again callback)
  23. While the battery is being charged and the system is in suspend-to-RAM,
  24. we may need to monitor the battery health by looking at the ambient or
  25. battery temperature. We can accomplish this by waking up the system
  26. periodically. However, such a method wakes up devices unncessary for
  27. monitoring the battery health and tasks, and user processes that are
  28. supposed to be kept suspended. That, in turn, incurs unnecessary power
  29. consumption and slow down charging process. Or even, such peak power
  30. consumption can stop chargers in the middle of charging
  31. (external power input < device power consumption), which not
  32. only affects the charging time, but the lifespan of the battery.
  33. Charger Manager provides a function "cm_suspend_again" that can be
  34. used as suspend_again callback of platform_suspend_ops. If the platform
  35. requires tasks other than cm_suspend_again, it may implement its own
  36. suspend_again callback that calls cm_suspend_again in the middle.
  37. Normally, the platform will need to resume and suspend some devices
  38. that are used by Charger Manager.
  39. 2. Global Charger-Manager Data related with suspend_again
  40. ========================================================
  41. In order to setup Charger Manager with suspend-again feature
  42. (in-suspend monitoring), the user should provide charger_global_desc
  43. with setup_charger_manager(struct charger_global_desc *).
  44. This charger_global_desc data for in-suspend monitoring is global
  45. as the name suggests. Thus, the user needs to provide only once even
  46. if there are multiple batteries. If there are multiple batteries, the
  47. multiple instances of Charger Manager share the same charger_global_desc
  48. and it will manage in-suspend monitoring for all instances of Charger Manager.
  49. The user needs to provide all the two entries properly in order to activate
  50. in-suspend monitoring:
  51. struct charger_global_desc {
  52. char *rtc_name;
  53. : The name of rtc (e.g., "rtc0") used to wakeup the system from
  54. suspend for Charger Manager. The alarm interrupt (AIE) of the rtc
  55. should be able to wake up the system from suspend. Charger Manager
  56. saves and restores the alarm value and use the previously-defined
  57. alarm if it is going to go off earlier than Charger Manager so that
  58. Charger Manager does not interfere with previously-defined alarms.
  59. bool (*rtc_only_wakeup)(void);
  60. : This callback should let CM know whether
  61. the wakeup-from-suspend is caused only by the alarm of "rtc" in the
  62. same struct. If there is any other wakeup source triggered the
  63. wakeup, it should return false. If the "rtc" is the only wakeup
  64. reason, it should return true.
  65. };
  66. 3. How to setup suspend_again
  67. =============================
  68. Charger Manager provides a function "extern bool cm_suspend_again(void)".
  69. When cm_suspend_again is called, it monitors every battery. The suspend_ops
  70. callback of the system's platform_suspend_ops can call cm_suspend_again
  71. function to know whether Charger Manager wants to suspend again or not.
  72. If there are no other devices or tasks that want to use suspend_again
  73. feature, the platform_suspend_ops may directly refer to cm_suspend_again
  74. for its suspend_again callback.
  75. The cm_suspend_again() returns true (meaning "I want to suspend again")
  76. if the system was woken up by Charger Manager and the polling
  77. (in-suspend monitoring) results in "normal".
  78. 4. Charger-Manager Data (struct charger_desc)
  79. =============================================
  80. For each battery charged independently from other batteries (if a series of
  81. batteries are charged by a single charger, they are counted as one independent
  82. battery), an instance of Charger Manager is attached to it.
  83. struct charger_desc {
  84. char *psy_name;
  85. : The power-supply-class name of the battery. Default is
  86. "battery" if psy_name is NULL. Users can access the psy entries
  87. at "/sys/class/power_supply/[psy_name]/".
  88. enum polling_modes polling_mode;
  89. : CM_POLL_DISABLE: do not poll this battery.
  90. CM_POLL_ALWAYS: always poll this battery.
  91. CM_POLL_EXTERNAL_POWER_ONLY: poll this battery if and only if
  92. an external power source is attached.
  93. CM_POLL_CHARGING_ONLY: poll this battery if and only if the
  94. battery is being charged.
  95. unsigned int fullbatt_uV;
  96. : If specified with a non-zero value, Charger Manager assumes
  97. that the battery is full (capacity = 100) if the battery is not being
  98. charged and the battery voltage is equal to or greater than
  99. fullbatt_uV.
  100. unsigned int polling_interval_ms;
  101. : Required polling interval in ms. Charger Manager will poll
  102. this battery every polling_interval_ms or more frequently.
  103. enum data_source battery_present;
  104. CM_FUEL_GAUGE: get battery presence information from fuel gauge.
  105. CM_CHARGER_STAT: get battery presence from chargers.
  106. char **psy_charger_stat;
  107. : An array ending with NULL that has power-supply-class names of
  108. chargers. Each power-supply-class should provide "PRESENT" (if
  109. battery_present is "CM_CHARGER_STAT"), "ONLINE" (shows whether an
  110. external power source is attached or not), and "STATUS" (shows whether
  111. the battery is {"FULL" or not FULL} or {"FULL", "Charging",
  112. "Discharging", "NotCharging"}).
  113. int num_charger_regulators;
  114. struct regulator_bulk_data *charger_regulators;
  115. : Regulators representing the chargers in the form for
  116. regulator framework's bulk functions.
  117. char *psy_fuel_gauge;
  118. : Power-supply-class name of the fuel gauge.
  119. int (*temperature_out_of_range)(int *mC);
  120. bool measure_battery_temp;
  121. : This callback returns 0 if the temperature is safe for charging,
  122. a positive number if it is too hot to charge, and a negative number
  123. if it is too cold to charge. With the variable mC, the callback returns
  124. the temperature in 1/1000 of centigrade.
  125. The source of temperature can be battery or ambient one according to
  126. the value of measure_battery_temp.
  127. };
  128. 5. Other Considerations
  129. =======================
  130. At the charger/battery-related events such as battery-pulled-out,
  131. charger-pulled-out, charger-inserted, DCIN-over/under-voltage, charger-stopped,
  132. and others critical to chargers, the system should be configured to wake up.
  133. At least the following should wake up the system from a suspend:
  134. a) charger-on/off b) external-power-in/out c) battery-in/out (while charging)
  135. It is usually accomplished by configuring the PMIC as a wakeup source.