0.功能介绍
0.1 device wakeup 功能
代表这个设备可以将系统从suspend中唤醒,比如gpio电源按键、有手势识别功能的tp双击能够将系统唤醒等
0.2 wake_lock电源锁
可以阻止系统休眠进入suspend、比如usb插入时系统不会休眠
1. 涉及代码
1.1 设备具有唤醒功能
device_init_wakeup(struct device *dev, bool val);
device_may_wakeup
device_wakeup_enable(struct device *dev);
device_wakeup_disable(struct device *dev);
device_set_wakeup_capable(struct device *dev, bool capable);
device_set_wakeup_enable(struct device *dev, bool enable);
pm_stay_awake(struct device *dev);
pm_relax(struct device *dev);
pm_wakeup_event(struct device *dev, unsigned int msec);
1.2 将一个中断设置为可将系统唤醒
enable_irq_wake
1.3 wake_lock电源锁
wake_lock_init
wake_lock_active
wake_lock
wake_unlock
wake_lock_destroy
wake_lock_timeout
2.demo
2.1系统按键唤醒功能
// drivers/input/misc/gpio_keys.c
gpio_keys_probe
device_init_wakeup(&pdev->dev, wakeup);
----------
gpio_keys_suspend
if (device_may_wakeup(dev))
enable_irq_wake(bdata->irq);
2.2 usb wake_lock功能
otg_wakelock_init
wake_lock_init(&vbus_lock.wakelock, WAKE_LOCK_SUSPEND, vbus_lock.name);
----------
static void otgwl_hold(struct otgwl_lock *lock)
{
if (!lock->held) {
wake_lock(&lock->wakelock);
lock->held = true;
}
}
----------
static void otgwl_drop(struct otgwl_lock *lock)
{
if (lock->held) {
wake_unlock(&lock->wakelock);
lock->held = false;
}
}