2

I am new to driver development. However, I purchased an OSR USB FX2 Learning Kit, which comes with sample codes for Windows kernel/user mode driver. However, I am writing the driver in Linux (Ubuntu 12). I have successfully been able to send control commands and receive the return of control commands from the device. I also have been able to successfully send and read data over the BULK OUT/IN endpoints the device supports.

There is only one more experiment I have yet to complete. The device has the following endpoints:

1. BULK (OUT) --> Address 0x06
2. BULK (IN)  --> Address 0x88
3. INTERRUPT (IN) --> Address 0x81

I am unable to figure out how to find the IRQ number for the INTERRUPT (IN) endpoint. I understand how to install an IRQ handler using:

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

and write the handler with the correct function prototype. However, I am wondering how I would find what IRQ line (IRQ number) the device is interrupting on? That is, how do I determine what the value of the argument unsigned int irq in the request_irq function above should be? I read through the book "Linux Device Drivers, Third Edition" how the IRQ number is determined for parallel ports. However, how does this work for USB and how would I go about probing or finding out what this number should be for the USB device?

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
Haleeq Usman
  • 811
  • 9
  • 11

1 Answers1

1

You don't need to deal with interrupts for writing a USB device driver, if you would like a good tutorial on it have a look at

http://www.linuxforu.com/2011/10/usb-drivers-in-linux-1/

which is an excellent starting point to learn how to write USB drivers;

If you have specific issues as you go along; post them we'll see how it goes :)

EDIT

you can use platform_get_irq or platform_get_irq_byname to get the irq for the device.

EDIT 2:

I also point you to http://lwn.net/images/pdf/LDD3/ch10.pdf for your viewing pleasure :-) Shows you how to retrieve IRQs assigned to devices.

Ahmed Masud
  • 21,655
  • 3
  • 33
  • 58
  • The link you posted of the "pen driver" has only two endpoints: BULK IN/OUT. So it makes sense why that article does not address interrupts. However, my device has three endpoints: BULK IN/OUT and an INTERRUPT IN. Therefore, the device can send an interrupt to the host when a switch is flipped from on/off (vice-versa). How else can I detect when the user has flipped the switch? I know I can continuously poll for changes to the switches configuration (relative to the last recorded configuration value), however that does not seem to be the best way to go about it. – Haleeq Usman May 18 '13 at 16:04
  • I believe you call platform_get_irq() and platform_get_irq_byname() after you have installed an IRQ handler using request_irq(). The devname and dev_id you provide to request_irq() become the arguments to platform_get_irq() and platform_get_irq_byname(), respectively. However my issue is determining what IRQ the device will interrupt on to install the IRQ Handler. Also, To confirm this, I tried using both functions and received "-6" as a return value, error code -6 is -ENXIO, which means "No such device or address", which makes sense since the IRQ handler was not yet created. – Haleeq Usman May 18 '13 at 18:41
  • Hmm I briefly read this chapter before. Let me take another look at it and get back to you. Thanks. – Haleeq Usman May 18 '13 at 18:52
  • 1
    So I believe you were sort of right in your first reply. I tried creating an IRQ handler on all available IRQ lines (trial/error) and was unable to find a single one that the OSR FX2 USB device interrupts on. However, I did find an open source implementation on github (see: http://sourceforge.net/projects/osrfx2/). I noticed that they poll the interrupt endpoint as opposed to creating an IRQ handler over a particular line. Therefore, the USB device uses a sort of "virtual" interrupt line (only words that come to mind to describe it). So everything happens on the endpoints. Makes sense! Thanks. – Haleeq Usman May 19 '13 at 15:15
  • P.S. When I said "I know I can continuously poll for changes to the switches configuration ... however that does not seem to be the best way to go about it" in my first comment, what I meant was: I would create a thread that continuously sends a CONTROL (READ) command to the USB device requesting the current switch configurations. Then it would compare it to the last read configuration value, and if there was a change, then it would set a global variable to true. Another thread would change it to false upon processing. However, polling the interrupt endpoint makes much more sense. – Haleeq Usman May 19 '13 at 15:32
  • 3
    USB interrupt transfers are not at all related to IRQs. Interrupt transfers are initiated by the host, so polling the interrupt endpoint is the best way to proceed. – markgz May 22 '13 at 00:57