From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C1C4C83000 for ; Wed, 29 Apr 2020 00:27:46 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3ED4120737 for ; Wed, 29 Apr 2020 00:27:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XlxIUVMm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3ED4120737 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.92.3) (envelope-from ) id 1jTaZ7-0002YH-OR; Tue, 28 Apr 2020 20:27:05 -0400 Received: from mail-ej1-x641.google.com ([2a00:1450:4864:20::641]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1jTaZ4-0002Y1-Ld for kernelnewbies@kernelnewbies.org; Tue, 28 Apr 2020 20:27:02 -0400 Received: by mail-ej1-x641.google.com with SMTP id a2so152849ejx.5 for ; Tue, 28 Apr 2020 17:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UJZ4dnmiKbcI8eCF2d3xS/r8nI2DsqFr9mdBfFaTYvs=; b=XlxIUVMmUG3EJRWc7eUpjPY8KK5z6BvwIMPISRPPeUTaBS6f1AOu0r49p8/W1nyWWT Kv3eu0wSd/q7eTY/Zpe7ntfrS5T9GTJHFUZ1Ukn4/gIlQcQZK8MaEj3CQHNU8F68TgLk 0+rJXEIKMmyXdI3OFJbu93R3yLoX4Lv3lRq4nPbLKJwk37OHNQ67tdL0a4kiXDsbpcML CjIpXKH/uWaGgyOB5FRgrd9EJH7PM5NZu4ADLaBgtShCX5yTAKg4vdjvQKUoRZ+rd1Vu cVP7fKq7txjfZfim5vQfftNFP6UnH4fMCZHnoCVniw2Fk0yy3rofWpJJtkrVVxoqncww wf9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UJZ4dnmiKbcI8eCF2d3xS/r8nI2DsqFr9mdBfFaTYvs=; b=YErPSNCSz6qo0IRnONC7vpuTOjTXKPnAPHokDHTmkrIa/2Ec/cJYA+glNnhc0+qOSK b67StYepPtjxd40ACgA/IRyQWE7RnVqcoP9ii7ErG5q+ofCqUC+aKEOqPYJvC6V7NHVE o+NW7Re9/dx+2jCvAn2xDXHo4b5lFO9Or0n48TXRrs8/9emfvEV+Vn6bsVm7f4NsqZhp 5F8CMJ03iaZYB+8fN0uinE8VnLZ/o4xomUr+FiTeprMLV7kdPVoixt3ekrP00HIct3WJ f5tGR0r+aekxF0tuvm60IYsLvbDkmYipHxwFvqK5OZreA3z6n02yZAZwTWtBzDOdP5Lu xkHw== X-Gm-Message-State: AGi0PuYTReJ/QKRa/3HzFmhq0FDJRUKGoeACUN9zZHEK9KKes5eAEgM1 qEDRJju3zo6KGTJagQSgL1XWS6q0Jt6d7UaUiqE= X-Google-Smtp-Source: APiQypKYVLPU8AnNUPGgIKO0frojEOOk8Xka76l+ItIXMba8gIxK/anuETuuAqp+wu57dh6h9OsLKhL0dHjRg+j2EXY= X-Received: by 2002:a17:907:9481:: with SMTP id dm1mr365827ejc.268.1588119958246; Tue, 28 Apr 2020 17:25:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Aruna Hewapathirane Date: Tue, 28 Apr 2020 20:25:47 -0400 Message-ID: Subject: Re: USB driver To: Sohaib Mhmd Cc: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============5959881132271727962==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============5959881132271727962== Content-Type: multipart/alternative; boundary="000000000000f8d7d805a462fd8b" --000000000000f8d7d805a462fd8b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable >> On Sat, Apr 25, 2020 at 1:46 AM Sohaib Mhmd wrote: >> Hi everyone, I made a very simple USB driver , >> 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 , 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 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=C2=AE 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 2 - unbind hid-generic ( from a root terminal ) 3 - bind ( from a root terminal ) 4 - check dmesg ( should show your probe has been called ) 5 - unbind ( 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=C2=AE Nano Transceiver v2.0 Syste= m 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 ) --000000000000f8d7d805a462fd8b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>> On Sat, Apr 25, 2020 at 1:46 AM Sohaib Mhmd = <xunilams@gmail.= com> wrote:
>> Hi everyone, I made a very simple USB driver,
>> but the p= roblem is that the probe and=C2=A0disconnect functions never was called.
>> I tried to google for this problem but unfortu= nately:
>> 1- I don't use=C2=A0usb-storage, it's a key= board! (but anyway the same problem exists with any usb-based device)=C2=A0= and all driver on my machine are=C2=A0=C2=A0bluetooth related drive (i thin= k!) (as you see from lsmod | grep usb)
>> 2- I = tried to rmmod=C2=A0usbhid but I get error:=C2=A0ERROR: Module usbhid is= builtin.
>> I tried to search for "usbhid= " in .config file to remove it but I didn't find anything.

= >> What=C2=A0should I do?
>> thanks, smalinux

=
Hello Sohaib,

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

The reason your probe and disco= nnect functions are never called is because the hid-generic driver has clai= med your device. This is the default behavior.
Since usbhid i= s builtin you are unable to unload it using rmmod. But you can unbind it. T= he steps are below:

1 - sudo modprobe <your= _kernel_module>
2 - unbind hid-generic=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ( from a root terminal )
3 - bind <your_kernel_module>= =C2=A0=C2=A0=C2=A0 ( from a root terminal )
4 - check dmesg= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ( sho= uld show your probe has been called )
5 - unbind <your_ker= nel_module> ( from a root terminal )
6 - check dmesg =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 ( 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 Microso= ft=C2=AE Nano Transceiver v2.0 System=20 Control as=20 /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/ter= minal:
echo "3-3:1.2" > =C2=A0/sys/bus/usb/drivers/usbhid/u= nbind

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

You should se= e dmesg telling you the probe function has been called now.

<= /div>
To unbind your driver from a root shell:
echo "3-3= :1.2" > =C2=A0/sys/bus/usb/drivers/'my first usb driver'/un= bind=C2=A0=C2=A0=C2=A0 // 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 yo= u pull out your device and plug it back in usbhid will be triggered. To sto= p that you can from a root terminal:
echo '0' > /sys/bus/hid/= drivers_autoprobe=C2=A0=C2=A0

Good luck - Aru= na ( If you have the kernel source why not re-compile ? Look for CONFIG_USB= _HID in Make menuconfig )



<= /div>



--000000000000f8d7d805a462fd8b-- --===============5959881132271727962== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============5959881132271727962==--