{
enable_irq_wake(irq);
}
static int smcdef_resume(struct device *dev)
{
disable_irq_wake(irq);
}
static int smcdef_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
/* ... */
request_thread_irq(irq,
smcdef_event_handler,
NULL,
IRQF_TRIGGER_FALLING,
"smcdef",
pdata);
return 0;
}
static int smcdef_remove(struct i2c_client *client)
{
return 0;
}
static const struct of_device_id smcdef_dt_ids[] = {
{.compatible = "wowo,smcdef" },
{ }
};
MODULE_DEVICE_TABLE(of, smcdef_dt_ids);
static SIMPLE_DEV_PM_OPS(smcdef_pm_ops, smcdef_suspend, smcdef_resume);
static struct i2c_driver smcdef_driver = {
.driver = {
.name= "smcdef",
.of_match_table = of_match_ptr(smcdef_dt_ids),
.pm= &smcdef_pm_ops,
},
.probe = smcdef_probe,
.remove = smcdef_remove,
};
module_i2c_driver(smcdef_driver);
MODULE_AUTHOR("smcdef");
MODULE_DESCRIPTION("IRQ test");
MODULE_LICENSE("GPL");
在probe函数中通过request_thread_irq接口注册驱动的中断服务函数smcdef_event_handler,注意这里smcdef_event_handler的执行环境是中断上下文,thread_fn的方式下面也会介绍。
2.1. enable_irq_wake
当系统睡眠(echo "mem" > /sys/power/state)的时候,回想一下suspend的流程就会知道,最终会调用smcdef_suspend使能中断唤醒功能。enable_irq_wake主要工作是在irq_set_irq_wake中完成,代码如下:
int irq_set_irq_wake(unsigned int irq, unsigned int on)
{
unsigned long flags;
struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
int ret = 0;
/* wakeup-capable irqs can be shared between drivers that
* don‘t need to have the same sleep mode behaviors.
*/
if (on) {
if (desc->wake_depth++ == 0) {
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-77051-2.html
美国只是虚张声势