Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
From: Lucas Tanure <tanure@linux.com>
To: Greg KH <greg@kroah.com>
Cc: kernelnewbies <Kernelnewbies@kernelnewbies.org>
Subject: Re: USB Hid driver Help
Date: Mon, 3 Feb 2020 22:00:44 +0000
Message-ID: <CAJX_Q+1zRNRMrUXOSuZiaMd0BA-OoB9xHakkqCk5F_yf9J=o2A@mail.gmail.com> (raw)
In-Reply-To: <20200203201102.GA3888053@kroah.com>

On Mon, Feb 3, 2020 at 8:11 PM Greg KH <greg@kroah.com> wrote:
>
> On Mon, Feb 03, 2020 at 04:32:46PM +0000, Lucas Tanure wrote:
> > Hi,
> >
> > I'm trying to write a Hid driver for MCP2210.
>
> What type of device is this?
It is a USB <-> SPI converter.

>
> > But the USB Hid specification is quite complicated.
>
> The kernel should do it "all for you" already, why do you need to create
> a custom HID driver for this device?
I need a driver that register an SPI controller with in the kernel.
So this SPI controller would receive regmap reads/writes and translate
to USB HID packages and send to the SPI device attached in the other
side of the cable.

>
> What type of HID reports does the device export and why doesn't the
> existing kernel drivers work for you?
I don't know enough yet to answer about HID Reports, but at end of
this e-mail I attached the lsub -v of the device.
I want to use this device in kernel space, registering a SPI
controller. And with this SPI controller another SPI slave device will
be registered.
So, for the SPI slave device it will be like there is no USB in
between itself and the kernel.

>
> > I would like to know how to send and receive data to the device. Any
> > links to a good tutorial ?
>
> HID has the idea of "reports" and data comes in and out in that specific
> format, all depending on how the device describes itself.  There's isn't
> usually a normal "send/receive" type of thing, but it all depends on the
> type of device.
Ok. Reading the datasheet of this device I need to send some 64 byte
arrays to configure the SPI bus.
And after that I start to send reports to communicate with the SPI slave device.

>
> > This is my current driver is attached.
> >
> > Thanks
> > Lucas
>
> > #define DEBUG
> > #include <linux/module.h>
> > #include <linux/hid.h>
> > #include <linux/usb.h>
> >
> > static int mcp2210_probe(struct hid_device *hdev,
> >                        const struct hid_device_id *id)
> > {
> >       struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
> >       int ret = 0;
> >
> >       hid_dbg(hdev, "%s\n", __FUNCTION__);
> >
> >       ret = hid_parse(hdev);
> >       if (ret) {
> >               hid_err(hdev, "parse failed\n");
> >               return ret;
> >       } else {
> >               hid_dbg(hdev, "parse success\n");
> >       }
> >
> >       ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
> >       if (ret) {
> >               hid_err(hdev, "hw start failed\n");
> >               return ret;
> >       } else {
> >               hid_dbg(hdev, "start success\n");
> >       }
>
> Does this all work?
For this version, it`s takes precedence from HID generic driver, wich is great.

>
> What fails?
If I try to execute small test of data communcation:

u8 *buf = kzalloc (64, GFP_KERNEL);
buf[0] = 0x50; //read EEPROM command
buf[1] = 0x03 ; // Address to read

ret = hid_hw_raw_request(hdev, 0, buf, 64, HID_INPUT_REPORT, HID_REQ_GET_REPORT)
ret is -EPIPE.

>
> thanks,
>
> greg k-h

Many Thanks
Lucas

Bus 001 Device 008: ID 04d8:00de Microchip Technology, Inc. MCP2210
USB to SPI Master
Couldn't open device, some information will be missing
Device Descriptor:
 bLength                18
 bDescriptorType         1
 bcdUSB               2.00
 bDeviceClass            0
 bDeviceSubClass         0
 bDeviceProtocol         0
 bMaxPacketSize0         8
 idVendor           0x04d8 Microchip Technology, Inc.
 idProduct          0x00de
 bcdDevice            0.02
 iManufacturer           1
 iProduct                2
 iSerial                 3
 bNumConfigurations      1
 Configuration Descriptor:
   bLength                 9
   bDescriptorType         2
   wTotalLength       0x0029
   bNumInterfaces          1
   bConfigurationValue     1
   iConfiguration          0
   bmAttributes         0x80
     (Bus Powered)
   MaxPower              100mA
   Interface Descriptor:
     bLength                 9
     bDescriptorType         4
     bInterfaceNumber        0
     bAlternateSetting       0
     bNumEndpoints           2
     bInterfaceClass         3 Human Interface Device
     bInterfaceSubClass      0
     bInterfaceProtocol      0
     iInterface              0
       HID Device Descriptor:
         bLength                 9
         bDescriptorType        33
         bcdHID               1.11
         bCountryCode            0 Not supported
         bNumDescriptors         1
         bDescriptorType        34 Report
         wDescriptorLength      29
        Report Descriptors:
          ** UNAVAILABLE **
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x81  EP 1 IN
       bmAttributes            3
         Transfer Type            Interrupt
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               1
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x01  EP 1 OUT
       bmAttributes            3
         Transfer Type            Interrupt
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               1

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

  reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 23:12 Introduction & Query on Newbie Website Status Jack Winch
2020-02-01 12:20 ` Cindy Sue Causey
2020-02-02 23:26 ` Anuz Pratap Singh Tomar
2020-02-03  0:36   ` Rik van Riel
2020-02-03 16:32     ` USB Hid driver Help Lucas Tanure
2020-02-03 20:11       ` Greg KH
2020-02-03 22:00         ` Lucas Tanure [this message]
2020-02-04 13:27           ` Lucas Tanure
2020-02-04 18:15             ` Lucas Tanure
2020-02-03 19:49     ` Introduction & Query on Newbie Website Status Jack Winch
2020-02-03 20:10       ` Rik van Riel
2020-02-05 15:46         ` Jack Winch

Reply instructions:

You may reply publically 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='CAJX_Q+1zRNRMrUXOSuZiaMd0BA-OoB9xHakkqCk5F_yf9J=o2A@mail.gmail.com' \
    --to=tanure@linux.com \
    --cc=Kernelnewbies@kernelnewbies.org \
    --cc=greg@kroah.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

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git