Re: [RFC PATCH 1/2] power: Charger-Manager: add initial Charger-Manager driver

2011-11-28 Thread Haojian Zhuang
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

Re: [RFC PATCH 1/2] power: Charger-Manager: add initial Charger-Manager driver

2011-11-28 Thread Haojian Zhuang
On Tue, Nov 29, 2011 at 1:00 PM, MyungJoo Ham  wrote:
> On Tue, Nov 29, 2011 at 1:41 PM, Haojian Zhuang
>  wrote:
>> 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.
>>>
>
>> Donggeun,
>>
>> I think that this patch is good for saving energy for charging while
>> suspend. I think that this driver also works under android. I have
>> some concerns on rtc wakeup.
>>
>> As we know, RTC event doesn't link to timer events in kernel. But
>> Android did. Android transfered timer event to rtc event while it
>> suspend. So it will occupy one rtc device.
>>
>> Whatever the device is phone or tablet, it may cost another rtc device
>> if it wants to implement power-up alarm feature. If we want to support
>> the charger manager feature, we have to add another rtc device. I
>> think that it's very hard to find any current platform with three rtc
>> devices. How about implement the similar mechanism like android?
>> Charger manager can register wakeup event into alarm mechanism like
>> android. And we only need two rtc devices.
>>
>> Loop more guys: list-arm-kernel & linaro.
>>
>> Thanks
>> Haojianbelow patch and comment whether
>
> Hello Haojian,
>
> No, we do not need to add another RTC device due to the usage of RTC
> alarm from another device drivers or processes.
> We can share an RTC device with others as long as others do not set
> RTC alarm in the suspend-to-RAM context (specifically from prepare ops
> to complete ops).
> The reason why we have created cm_setup_timer() looking that awfully
> complex is to let it coexist with other RTC alarm events and share the
> precious RTC device.
> Anyway, why do we even need two RTC devices in general?
>
If we want the device to implement power-up alarm, we need two rtc devices.

Let me use an example in Android system.
1. Application set time interval to receive mail after 10 minutes.
2. Android suspend and it convert the timer event into RTC event.
3. Battery is removed. After a while, we put the battery back. The
battery insertion won't trigger phone up since it's depend on custom
scenario.
4. 10 minutes interval past and phone will be powered up since rtc
wakeup. Absolutely it's incorrect. We only need a resume event, not a
power up event.

If we have two rtc devices, one is external rtc and the other is
contained in SoC. While battery removed, only SoC rtc will lost power
and external rtc can keep status for a long time. So let's check the
item #4.
4. Since status is lost in SoC rtc, system won't wakeup while 10
minutes interval past.

> If the RTC subsystem supports registering multiple alarm events,
> that'd be nice and will make this one simpler as well; however, we do
> not have it here for now.
>
> We save previous RTC alarm if the configuration data says so
> (rtc_wkalarm_save.enabled) and previously set alarm is later than the
> current alarm and restore the RTC alarm value at wakeup.
>
> If the previously set RTC alarm is earlier than the timer setup of
> Charger Manager, we do not load the alarm value of Charger Manager and
> let the previously set RTC alarm be active for a wakeup.
>
But it's a little complex, isn't it?

>
> Cheers!
> MyungJoo
>

___
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev