unbind device from usbhid and bind to your own driver

1

0

OS: Debian 8

Problem: I'm writing usb driver module for my microcontroller, custom usb HID, but when I plug it to laptop it binds to usbhid driver, if I do rmmod usbhid it also disconnects a mouse and it's not very nice) I can unbind it via

sudo sh -c 'echo -n "1-3:1.0" > /sys/bus/usb/drivers/usbhid/unbind'

, however it's not interesting to do it every time i plug my device in. Even after I wrote a script, I've got that it not fun to run it again and again. Is it possible to unbind my device from usbhid driver automatically?

Anton Rak

Posted 2016-10-18T18:41:26.600

Reputation: 11

1add your script to a custom udev rule, then udev will run your script on every plug. – Ipor Sircer – 2016-10-18T18:43:06.273

Answers

0

It was not easy to find the real cool solution, but I've done it. The solution doesn't deal with udev. We need to say to hid core that it shouldn't touch our device. It possible to do it in 2 ways depending either usbhid compiled as a module, or not. Check out this:

https://unix.stackexchange.com/questions/55495/prevent-usbhid-from-claiming-usb-device

https://askubuntu.com/questions/605251/dkms-installed-kernel-module-but-not-working-after-reboot/606359#606359

PS "GRUB_CMDLINE_LINUX_DEFAULT contains command line arguments to the linux kernel. You can put as many as you want there provided they are separated by a space."

Hopefully, it will save someone's time, since I spent great amount of time to find this, i think, excellent solution.

Best regards, anon

Anton Rak

Posted 2016-10-18T18:41:26.600

Reputation: 11

0

You could blacklist the driver so it does not load and bind to the device on boot. If other modules that have a dependency on it, they will fail to load.

https://askubuntu.com/questions/110341/how-to-blacklist-kernel-modules

Kyle H

Posted 2016-10-18T18:41:26.600

Reputation: 338

Yep, but it's a default hid driver that control my mice, and it's at all not a good idea to suppress a hid driver – Anton Rak – 2016-10-20T19:01:06.073

I agree. udev is the way to go. just for testing and writing a usb driver module you could go this way to avoid a learning curve if you didn't know udev. – Kyle H – 2016-10-20T19:07:03.590

Thanks for answer) I already got a basics of udev) and in general I used to do this curves since I installed Linux:D – Anton Rak – 2016-10-20T19:11:40.383

I already solved it. In the case u interested, check the solution below. – Anton Rak – 2016-10-20T19:12:54.107