request_threaded_irq() is used in the driver why not request_irq()? What are the differences between two?

為{幸葍}努か 提交于 2020-01-12 08:44:08

问题


I posted this is the thread which discussed about request_threaded_irq but I did not get any reply. So I am posting it freshly.

I am working on a touchscreen driver for capacitive touchscree. It used request_threaded_irq() call instead of request_irq(). I could not understand the basic difference betweeen two. It says :-

Name

request_threaded_irq — allocate an interrupt line

Synopsis

int request_threaded_irq (unsigned int irq, irq_handler_t handler,irq_handler_t thread_fn, unsigned long irqflags, const char *devname, void *dev_id);

Arguments

  1. irq - Interrupt line to allocate
  2. handler - Function to be called when the IRQ occurs. Primary handler for threaded interrupts If NULL and thread_fn != NULL the default primary handler is installed
  3. thread_fn - Function called from the irq handler thread If NULL, no irq thread is created
  4. irqflags - Interrupt type flags
  5. devname - An ascii name for the claiming device
  6. dev_id - A cookie passed back to the handler function

the Handler and Thread_fn arguments are the ones which are confusing. Also there is no work function defined in the driver.

Here is the driver which I am refering to.

Can somebody help me in understanding this?


回答1:


The request_threaded_irq() function was added to allow developers to split interrupt handling code into two parts. One part that will execute with interrupts blocked, and a second part that can be done by a kernel thread without interrupts blocked. For details of why, you can read this:

http://lwn.net/Articles/302043/

In your case, the driver you linked to does this:

err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread,
                           IRQF_TRIGGER_RISING, "touch_reset_key", ts);

By passing NULL for the second arg, "handler", the argument to thread_fn, or the function cy8ctmg110_irq_thread() will be called when the interrupt is detected.

For you, choosing which request irq function will depend on what your driver needs to do in interrupt context.




回答2:


Another important aspect: "If you want to set up a threaded irq handler for your device then you need to supply handler and thread_fn. handler is still called in hard interrupt context and has to check whether the interrupt originates from the device. If yes it needs to disable the interrupt on the device and return IRQ_WAKE_THREAD which will wake up the handler thread and run thread_fn."

Source: https://www.kernel.org/doc/htmldocs/genericirq.html



来源:https://stackoverflow.com/questions/7685294/request-threaded-irq-is-used-in-the-driver-why-not-request-irq-what-are-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!