views:

19

answers:

2

Hello, I am writing a usb driver (for a gamepad) on linux, and when I plug it in, ti loads usbhid. How can I make it so it loads my driver (gp_driver)? I did the unbind usbhid and bind to my driver trick, but I don't want to do it every single time.

Should I have my driver already loaded? Should I code something in my driver? I have the vendor and product id in my driver..

thanks

A: 

According to this Linux Journal article, you need to have:

  1. A pointer to the module owner of your driver
  2. The name of the USB driver
  3. A list of the USB IDs this driver should provide
  4. A probe() function
  5. A disconnect() function

Now, I suspect, because it is loading the standard driver, you may not have either 3, 4, or maybe you haven't registered the driver with the USB subsystem at all.

I've never written a USB driver before (only hacked char/mem.c), but this info might come in handy.

new123456
A: 

You will want to create a udev rule for your device, which can take care of creating your device file, setting permissions on the device file, and loading relevant drivers.

Resources

Example

Taken from: http://plugcomputer.org/plugwiki/index.php/Load_Serial_Drivers_Automatically_Using_udev

# if no driver has claimed the interface yet, load ftdi_sio
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_interface", \
        ATTRS{idVendor}=="9e88", ATTRS{idProduct}=="9e8f", \
        DRIVER=="", \
        RUN+="/sbin/modprobe -b ftdi_sio"
Noah Watkins