Matthew
Matthew

Reputation: 442

Use custom driver over an existing driver

I'm learning how to write linux drivers and pick a usb stick i had laying around. For a while I was struggling with getting the probe function to be called when I plugged it in.

What happens is probe will be called when I unplug it,or atleast the printk inside isn't called until then. Then the disconnect function is called. Using bind and unbind for the drivers in /sys/bus/usb/drivers does the same thing.

May 24 21:09:12 localhost.localdomain kernel: probed
May 24 21:09:12 localhost.localdomain kernel: usb 1-2: USB disconnect, device number 16
May 24 21:09:12 localhost.localdomain kernel: discconect usb

If I do rmmod uas and rmmod usb-storage then plug in the thumb drive it works as expected. I'm guessing these two existing modules are causing some kind of problem. Is there a way to get the drive to use my driver over usb-storage? the module uas and usb-storage seem to come back too on their own.

Upvotes: 0

Views: 1069

Answers (1)

Arvind Yadav
Arvind Yadav

Reputation: 421

There is one driver already register for this device. So you will have to unregistered current driver. Otherwise your device will use register driver.

  1. Run lsmod command, it will display all modules that are currently loaded in the Linux kernel.
  2. Run modprobe -r <current register driver> - remove the currently loaded module.
  3. Run insmod <your driver *.ko> - will register your driver.

Now connect your device. Kernel will match your device id and if your driver has same id. It will call your driver probe.

Once you done with your driver and want to load previous kernel driver again.

  1. Run rmmod <your driver module> - will remove your driver.
  2. Run modprobe <prevous driver module> - will load previous module.

It'll applicable for all drivers. Use all commands with sudo if you are not in root.

Upvotes: 2

Related Questions