On Thu, Nov 17, 2011 at 6:13 PM, Donggeun Kim wrote:
> Because battery health monitoring should be done even when suspended,
> it needs to wake up and suspend periodically. Thus, userspace battery
> monitoring may incur too much overhead; every device and task is woken
> up periodically. Charger Manager uses suspend-again to provide
> in-suspend monitoring.
>
> This patch allows to monitor battery health in-suspend state.
>
> Signed-off-by: Donggeun Kim
> Signed-off-by: MyungJoo Ham
> Signed-off-by: Kyungmin Park
> ---
> Documentation/power/charger-manager.txt | 150 ++
> drivers/power/Kconfig | 9 +
> drivers/power/Makefile | 1 +
> drivers/power/charger-manager.c | 771
> +++
> include/linux/power/charger-manager.h | 131 ++
> 5 files changed, 1062 insertions(+), 0 deletions(-)
> create mode 100644 Documentation/power/charger-manager.txt
> create mode 100644 drivers/power/charger-manager.c
> create mode 100644 include/linux/power/charger-manager.h
>
> diff --git a/Documentation/power/charger-manager.txt
> b/Documentation/power/charger-manager.txt
> new file mode 100644
> index 000..99630e5
> --- /dev/null
> +++ b/Documentation/power/charger-manager.txt
> @@ -0,0 +1,150 @@
> +Charger Manager
> + (C) 2011 MyungJoo Ham , GPL
> +
> +Charger Manager provides in-kernel battery charger management that
> +requires temperature monitoring during suspend-to-RAM state
> +and where each battery may have multiple chargers attached and the userland
> +wants to look at the aggregated information of the multiple chargers.
> +
> +Charger Manager is a platform_driver with power-supply-class entries.
> +An instance of Charger Manager (a platform-device created with
> Charger-Manager)
> +represents an independent battery with chargers. If there are multiple
> +batteries with their own chargers acting independently in a system,
> +the system may need multiple instances of Charger Manager.
> +
> +1. Introduction
> +===
> +
> +Charger Manager supports the following:
> +
> +* Support for multiple chargers (e.g., a device with USB, AC, and solar
> panels)
> + A system may have multiple chargers (or power sources) and some of
> + they may be activated at the same time. Each charger may have its
> + own power-supply-class and each power-supply-class can provide
> + different information about the battery status. This framework
> + aggregates charger-related information from multiple sources and
> + shows combined information as a single power-supply-class.
> +
> +* Support for in suspend-to-RAM polling (with suspend_again callback)
> + While the battery is being charged and the system is in
> suspend-to-RAM,
> + we may need to monitor the battery health by looking at the ambient or
> + battery temperature. We can accomplish this by waking up the system
> + periodically. However, such a method wakes up devices unncessary for
> + monitoring the battery health and tasks, and user processes that are
> + supposed to be kept suspended. That, in turn, incurs unnecessary power
> + consumption and slow down charging process. Or even, such peak power
> + consumption can stop chargers in the middle of charging
> + (external power input < device power consumption), which not
> + only affects the charging time, but the lifespan of the battery.
> +
> + Charger Manager provides a function "cm_suspend_again" that can be
> + used as suspend_again callback of platform_suspend_ops. If the
> platform
> + requires tasks other than cm_suspend_again, it may implement its own
> + suspend_again callback that calls cm_suspend_again in the middle.
> + Normally, the platform will need to resume and suspend some devices
> + that are used by Charger Manager.
> +
> +2. Global Charger-Manager Data related with suspend_again
> +
> +In order to setup Charger Manager with suspend-again feature
> +(in-suspend monitoring), the user should provide charger_global_desc
> +with setup_charger_manager(struct charger_global_desc *).
> +This charger_global_desc data for in-suspend monitoring is global
> +as the name suggests. Thus, the user needs to provide only once even
> +if there are multiple batteries. If there are multiple batteries, the
> +multiple instances of Charger Manager share the same charger_global_desc
> +and it will manage in-suspend monitoring for all instances of Charger
> Manager.
> +
> +The user needs to provide all the three entries properly in order to activate
> +in-suspend monitoring:
> +
> +struct charger_global_desc {
> +
> +char *rtc;
> + : The name of rtc (e.g., "rtc0") used to wakeup the system from
> + suspend for Charger Manager. The alarm interrupt (AIE) of the rtc
> + should be able to wake up the system from suspen