c - request_irq中的dev_id参数是什么?

标签 c linux linux-device-driver embedded-linux interrupt

在函数声明中

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 是“输入”参数还是“输出”参数? 我们从哪里得到这个数字?

最佳答案

Dev_id 是一个输入参数,必须是全局唯一的。通常设备数据结构的地址用作Dev_id
如果中断线路未共享,则它的值为 NULL。它仅在共享中断线时才有意义。共享时,此参数唯一标识共享 IRQ 上的中断处理程序

但最近为了更快地处理中断,linux 内核已移动到request_threaded_irq

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

设备结构是:

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 };

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

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 code

关于c - request_irq中的dev_id参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22471142/

相关文章:

c - 当 snprintf 返回的值超过其大小参数时,如何获取格式化输出的最后一个字符?

Linux 追加到文件中的单行

linux - rmmod时是否需要devm_iounmap,哪个模块使用devm* api?

c - 添加用户空间头文件以生成文件

c - 将新行写入文件

C:没有错误,编译成功,但不运行

c - shmget : Operation not permitted

linux - Linux 中的应用程序计数器? (和 OSX?)

c++ - 获取错误 'char16_t and char32_t undeclared'

linux - 未检测到 MC7455 sierra 无线 PCI