kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Aruna Hewapathirane <aruna.hewapathirane@gmail.com>
To: Sohaib Mhmd <xunilams@gmail.com>
Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: USB driver
Date: Tue, 28 Apr 2020 20:25:47 -0400	[thread overview]
Message-ID: <CAFSeFg8QiE_MkRgpO4ER12Oo_jutwKPHZukOg3CJ+eHJ=ABT6g@mail.gmail.com> (raw)
In-Reply-To: <CAL06vpE_0-uTQpzaB64s1dzNQV8NPQS_UKbu--dP0Zm_1gWWiw@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3020 bytes --]

>> On Sat, Apr 25, 2020 at 1:46 AM Sohaib Mhmd <xunilams@gmail.com> wrote:
>> Hi everyone, I made a very simple USB driver
<https://gist.github.com/smalinux/3d6a5b000a32b97250b2d0c86b90711b>,
>> but the problem is that the probe and disconnect functions never was
called.
>> I tried to google for this problem but unfortunately:
>> 1- I don't use usb-storage <https://stackoverflow.com/a/31071943/5688267>,
it's a keyboard! (but anyway the same problem exists with any usb-based
device) and all driver on my machine are  bluetooth related drive (i
think!) (as you see from lsmod | grep usb)
>> 2- I tried to rmmod usbhid <https://stackoverflow.com/a/4204608/5688267>
but I get error: ERROR: Module usbhid is builtin.
>> I tried to search for "usbhid" in .config file to remove it but I didn't
find anything.

>> What should I do?
>> thanks, smalinux

Hello Sohaib,

Looking at the very last line of your dmesg output :
[ 4545.614471] hid-generic 0003:045E:0800.000C: input,hiddev96,hidraw2: USB
HID v1.11 Device [Microsoft Microsoft® Nano Transceiver v2.0] on
usb-0000:00:14.0-3/input2

The reason your probe and disconnect functions are never called is because
the hid-generic driver has claimed your device. This is the default
behavior.
Since usbhid is builtin you are unable to unload it using rmmod. But you
can unbind it. The steps are below:

1 - sudo modprobe <your_kernel_module>
2 - unbind hid-generic                  ( from a root terminal )
3 - bind <your_kernel_module>    ( from a root terminal )
4 - check dmesg                         ( should show your probe has been
called )
5 - unbind <your_kernel_module> ( from a root terminal )
6 - check dmesg                         ( should show your disconnect has
been called )

Clear the log buffer with dmesg -c then run dmesg -w.

Now find your bus id. Your bus id is 3-3:1.2 from your second last dmesg
output.
[ 4545.613190] input: Microsoft Microsoft® Nano Transceiver v2.0 System
Control as
/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.2/0003:045E:0800.000C/input/input49

To unbind from hid-generic from a root shell/terminal:
echo "3-3:1.2" >  /sys/bus/usb/drivers/usbhid/unbind

Now to bind to your driver from a root shell:
echo "3-3:1.2" >  /sys/bus/usb/drivers/'my first usb driver'/bind    // you
need the single quotes because of the spaces in your driver name

You should see dmesg telling you the probe function has been called now.

To unbind your driver from a root shell:
echo "3-3:1.2" >  /sys/bus/usb/drivers/'my first usb driver'/unbind    //
you need the single quotes because of the spaces in your driver name

and now dmesg should show you the disconnect function has been called.

If you pull out your device and plug it back in usbhid will be triggered.
To stop that you can from a root terminal:
echo '0' > /sys/bus/hid/drivers_autoprobe

Good luck - Aruna ( If you have the kernel source why not re-compile ? Look
for CONFIG_USB_HID in Make menuconfig )

[-- Attachment #1.2: Type: text/html, Size: 4006 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      parent reply	other threads:[~2020-04-29  0:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-25  5:44 USB driver Sohaib Mhmd
2020-04-25  7:00 ` Greg KH
2020-04-25  7:45   ` Sohaib Mhmd
2020-04-25  8:05     ` Greg KH
2020-04-29  0:25 ` Aruna Hewapathirane [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFSeFg8QiE_MkRgpO4ER12Oo_jutwKPHZukOg3CJ+eHJ=ABT6g@mail.gmail.com' \
    --to=aruna.hewapathirane@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=xunilams@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).