request_irq中的dev_id参数是什么? [英] What is dev_id parameter in request_irq?

查看:102
本文介绍了request_irq中的dev_id参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在函数声明中

int request_irq(unsigned int irq,
                irqreturn_t (*handler)(int, void *, struct pt_regs *),
                unsigned long irqflags,
                const char *devname,
                void *dev_id);

dev_id是"in"参数还是"out"参数? 我们从哪里得到这个号码?

Is dev_id an 'in' parameter or an 'out' parameter ? Where do we get this number from ?

推荐答案

Dev_id是输入参数,并且必须是全局唯一的.通常,设备数据结构的地址用作Dev_id.
如果不共享中断线,则其值为NULL.仅当共享中断线时,它才具有相关性.共享时,此参数唯一地标识共享IRQ上的interrupt handler.

Dev_id is an input argument and must be globally unique. Normally the address of the device data structure is used as the Dev_id.
It has value NULL if the interrupt line is NOT shared. It holds relevance only when the interrupt line is being shared. When it is shared, this parameter uniquely identifies the interrupt handler on the shared IRQ.

但是最近为了更快地处理中断,Linux内核已移至request_threaded_irq.

例如,在Linux内核中,用于wm8903音频编解码器的i2c驱动程序以以下方式使用此API-使用request_threaded_irq(),但使用dev_id相同.

For eg, in the linux kernel, i2c driver for wm8903 audio codec uses this API in the following manner - using request_threaded_irq() but use of dev_id is identical.

设备结构为:

117 struct wm8903_priv {
118         struct wm8903_platform_data *pdata;
119         struct device *dev;
120         struct snd_soc_codec *codec;
121         struct regmap *regmap;
122 
123         int sysclk;
124         int irq;
125 
126         int fs;
127         int deemph;
128 
129         int dcs_pending;
130         int dcs_cache[4];
131 
132         /* Reference count */
133         int class_w_users;
134 
135         struct snd_soc_jack *mic_jack;
136         int mic_det;
137         int mic_short;
138         int mic_last_report;
139         int mic_delay;
140 
141 #ifdef CONFIG_GPIOLIB
142         struct gpio_chip gpio_chip;
143 #endif
144 };

处理程序定义一个指向该结构的指针:

The handler defines a pointer to this struct:

2029         struct wm8903_priv *wm8903; //this is the dev_id parameter

然后调用request_threaded_irq(),

 ret = request_threaded_irq(i2c->irq, NULL, wm8903_irq,
2156                                            trigger | IRQF_ONESHOT,
2157                                            "wm8903", wm8903);

lxr代码

这篇关于request_irq中的dev_id参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆