Linux之device wakeup

Linux的device wakeup

设备可以将系统从suspend状态唤醒,比如gpio,power key,tp,wifi/bt wakeup等,这些都可以将系统从suspend状态唤醒。

1)相关函数
 device_init_wakeup(struct device *dev, bool val);  // 初始化设备能不能唤醒系统,通常在设备初始化时使能,在remove时禁用
 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.

2)唤醒必须有中断源,以下是常使用的中断函数

int gpiod_to_irq(const struct gpio_desc *desc) //gpio转中断

void disable_irq(unsigned int irq);//禁用中断

void enable_irq(unsigned int irq);//使能中断

int request_threaded_irq(unsigned int irq, irq_handler_t handler,
                     irq_handler_t thread_fn,
                     unsigned long flags, const char *name, void *dev);

//其中参数thread_fn 是中断线程处理函数,类似中断的下半部,只是系统帮你做了,你只需要实现业务处理

int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
            const char *name, void *dev) 

//和上面request_threaded_irq的区别,中断处理函数handler作为上半部,不能耗时,把耗时操作放到tasklet或者workqueue

int request_any_context_irq(unsigned int irq, irq_handler_t handler,
                        unsigned long flags, const char *name, void *dev_id);

3)命令查看硬件中断命令:

cat /proc/interrupts

查看软件中断:

cat /proc/softirqs

4)有这样一种情况,中断触发后,中断处理函数一开始disable了中断,然后在下半部执行一个比较耗时的操作,而此时如果系统休眠了,因为上面已经禁用了中断,那将永远唤醒不了设备了,所以此时我们可以首先调用pm_stay_awake,来增加休眠计数,这样可以阻止系统进入休眠,同样,在中断下半部,处理完以后,调用pm_relax减少计数

 pm_stay_awake(struct device *dev);
 pm_relax(struct device *dev);
 pm_wakeup_event(struct device *dev, unsigned int msec);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 gpio-keyc的基础上改写的旋转按钮 ec11的驱动,已经经过了测试。可自定义左旋和右旋的键值。如果按键值输入是第三个引脚,也支持按键操作 补存的头文件: gpio_ec11.h #ifndef _GPIO_EC11_H #define _GPIO_EC11_H struct device; struct gpio_desc; /** * struct gpio_ec11_button - configuration parameters * @leftcode: ec11 left direction input event code (KEY_*, SW_*) * @rightcode: ec11 right direction input event code (KEY_*, SW_*) * @gpio: %-1 if this key does not support gpio * @gpio: %-1 if this key does not support gpio * @active_low: %true indicates that button is considered * depressed when gpio is low * @desc: label that will be attached to button's gpio * @type: input event type (%EV_KEY, %EV_SW, %EV_ABS) * @wakeup: configure the button as a wake-up source * @debounce_interval: debounce ticks interval in msecs * @can_disable: %true indicates that userspace is allowed to * disable button via sysfs * @value: axis value for %EV_ABS * @irq: Irq number in case of interrupt keys * @gpiod: GPIO descriptor */ struct gpio_ec11_button { unsigned int code; unsigned int leftcode; /*记录左旋键值*/ unsigned int rightcode; /*记录右旋键值*/ int gpio; /*旋转编码器A引脚的gpio号*/ int subgpio; /*旋转编码器B引脚的gpio号*/ int active_low; const char *desc; unsigned int type; int wakeup; int debounce_interval; bool can_disable; int value; unsigned int irq; unsigned int irq_flags; struct gpio_desc *gpiod; }; /** * struct gpio_ec11_platform_data - platform data for gpio_ec11 driver * @buttons: pointer to array of &gpio;_keys_button structures * describing buttons attached to the device * @nbuttons: number of elements in @buttons array * @poll_interval: polling interval in msecs - for polling driver only * @rep: enable input subsystem auto repeat * @enable: platform hook for enabling the device * @disable: platform hook for disabling the device * @name: input device name */ struct gpio_ec11_platform_data { struct gpio_ec11_button *buttons; int nbuttons; unsigned int poll_interval; unsigned int rep:1; int (*enable)(

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值