olpc_battery: Add wakeup support
authorDaniel Drake <dsd@laptop.org>
Wed, 10 Aug 2011 20:46:02 +0000 (21:46 +0100)
committerAnton Vorontsov <cbouatmailru@gmail.com>
Fri, 19 Aug 2011 17:03:25 +0000 (21:03 +0400)
Battery and AC events can now be used to wake up the system from suspend.

Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-by: Andres Salomon <dilinger@queued.net>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
drivers/power/olpc_battery.c

index 9972268fea72eaf2a8f5ed70dc5acdd374e9e631..46a2f07edab10cf47ef40eee8438e66d9474ac0c 100644 (file)
@@ -533,6 +533,24 @@ void olpc_battery_trigger_uevent(unsigned long cause)
                kobject_uevent(&olpc_bat.dev->kobj, KOBJ_CHANGE);
 }
 
+static int olpc_battery_suspend(struct platform_device *pdev,
+                               pm_message_t state)
+{
+       if (device_may_wakeup(olpc_ac.dev))
+               olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
+       else
+               olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
+
+       if (device_may_wakeup(olpc_bat.dev))
+               olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
+                                  | EC_SCI_SRC_BATERR);
+       else
+               olpc_ec_wakeup_clear(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
+                                    | EC_SCI_SRC_BATERR);
+
+       return 0;
+}
+
 static int __devinit olpc_battery_probe(struct platform_device *pdev)
 {
        int ret;
@@ -578,6 +596,11 @@ static int __devinit olpc_battery_probe(struct platform_device *pdev)
        if (ret)
                goto error_failed;
 
+       if (olpc_ec_wakeup_available()) {
+               device_set_wakeup_capable(olpc_ac.dev, true);
+               device_set_wakeup_capable(olpc_bat.dev, true);
+       }
+
        return 0;
 
 error_failed:
@@ -612,6 +635,7 @@ static struct platform_driver olpc_battery_drv = {
        },
        .probe = olpc_battery_probe,
        .remove = __devexit_p(olpc_battery_remove),
+       .suspend = olpc_battery_suspend,
 };
 
 static int __init olpc_bat_init(void)