[Linux 基础] -- device wakeup 功能 & wake_lock 电源锁

0. 功能介绍

 0.1 device wakeup 功能

代表这个设备可以将系统从 suspend 中唤醒,比如 gpio 电源按键、有手势识别功能的 tp 双击能够将系统唤醒等


0.2 wake_lock 电源锁

可以阻止系统休眠进入 suspend、比如 usb 插入时系统不会休眠


1. 涉及代码

1.1 设备具有唤醒功能

 /* include/linux/pm_wakeup.h */
 device_init_wakeup(struct device *dev, bool val);  // 初始化设备能不能唤醒系统,并且使用这个功能 
 device_may_wakeup   // 判断设备设备能不能够别唤醒,并且使用这个功能
 device_wakeup_enable(struct device *dev);  // Enable given device to be a wakeup source
 device_wakeup_disable(struct device *dev);
 device_set_wakeup_capable(struct device *dev, bool capable);
 device_set_wakeup_enable(struct device *dev, bool enable);  //Enable or disable a device to wake up the system.
 pm_stay_awake(struct device *dev);
 pm_relax(struct device *dev);
 pm_wakeup_event(struct device *dev, unsigned int msec);

1.2 将一个中断设置为可将系统唤醒

//include/linux/interrupt.h
enable_irq_wake

1.3 wake_lock 电源锁

// include/linux/wakelock.h

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

// probe中将设备设置为可将系统唤醒
gpio_keys_probe
     device_init_wakeup(&pdev->dev, wakeup);


----------
// 当设备suspend时,将其触发的中断设置为可以将系统唤醒并且使能
gpio_keys_suspend
    if (device_may_wakeup(dev))
        enable_irq_wake(bdata->irq);

2.2 usb wake_lock 功能

//drivers/usb/phy/otg-wakelock.c

otg_wakelock_init
  wake_lock_init(&vbus_lock.wakelock, WAKE_LOCK_SUSPEND, vbus_lock.name);  // init


----------
static void otgwl_hold(struct otgwl_lock *lock)
{
    if (!lock->held) {
        wake_lock(&lock->wakelock);    // lock
        lock->held = true;
    }
}


----------
static void otgwl_drop(struct otgwl_lock *lock)
{
    if (lock->held) {
        wake_unlock(&lock->wakelock);  // unlock
        lock->held = false;
    }
}

 

 

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值