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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 6009BC2D0B1 for ; Tue, 4 Feb 2020 13:28:19 +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 F050520661 for ; Tue, 4 Feb 2020 13:28:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F050520661 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.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 1iyyF0-0002p4-Md; Tue, 04 Feb 2020 08:27:46 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1iyyEy-0002ox-VE for Kernelnewbies@kernelnewbies.org; Tue, 04 Feb 2020 08:27:45 -0500 Received: by mail-vs1-f66.google.com with SMTP id a2so11322659vso.3 for ; Tue, 04 Feb 2020 05:27:44 -0800 (PST) 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:reply-to :from:date:message-id:subject:to:cc; bh=yOt4iav+Wks7ewpWsU2gN8jLh1uQQIs8Tu04HD3v57U=; b=m7kt74Fp8/Vry2cFcnioTBDS78ByZAkJ3NoNBkIjWHafOqqAeP/cGdSbernP7spgEt BlKJZBgAnG9XyT4jDg2Nog5/35qfKxHciCc8l78/dQk4Gf7ADS/xJxzEu7fRzumUMN7c nassLJe/RzeMl328cEd1t2NbXVC/7zxrBbvhj5C06dpBfExyVW/Bzpxz6WQ9n0EZ9CBg X6uX9fcVBoARimcHLIpGNQ3Wa6zStn/kK46weaAPQuYiq8Q6aj1KCp3wG43nCbZ5qUiT TwN0CcWOk8HIAxanibBa9fYK9aZ2cRgVgpJlUXX7NvQpre/XZP7V4i3tBow3BUMQ2qOC eSTA== X-Gm-Message-State: APjAAAWVlO0VkXWbvmx5iHsB223di/EOQJDx35TFXXzWNPOSLu5gbf8G VpeHj4XKFX033BpD1Fxm4pd8ZMkr1Gc= X-Google-Smtp-Source: APXvYqwcI27oQXyCZxCujHjxzDqfMFgrc0qAcBH+raP6/wOHmQOttW5L1ksee1fzTpxivvXPOW7MpA== X-Received: by 2002:a67:f315:: with SMTP id p21mr19344274vsf.39.1580822858698; Tue, 04 Feb 2020 05:27:38 -0800 (PST) Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com. [209.85.217.48]) by smtp.gmail.com with ESMTPSA id m82sm7131379vke.30.2020.02.04.05.27.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Feb 2020 05:27:38 -0800 (PST) Received: by mail-vs1-f48.google.com with SMTP id a2so11322470vso.3 for ; Tue, 04 Feb 2020 05:27:38 -0800 (PST) X-Received: by 2002:a05:6102:310c:: with SMTP id e12mr17409572vsh.226.1580822857880; Tue, 04 Feb 2020 05:27:37 -0800 (PST) MIME-Version: 1.0 References: <9c5082fe870a01cac0b1a7861c0c5a74e794963f.camel@surriel.com> <20200203201102.GA3888053@kroah.com> In-Reply-To: From: Lucas Tanure Date: Tue, 4 Feb 2020 13:27:26 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: USB Hid driver Help To: Greg KH 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: , Reply-To: tanure@linux.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Mon, Feb 3, 2020 at 10:00 PM Lucas Tanure wrote: > > On Mon, Feb 3, 2020 at 8:11 PM Greg KH 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 > > > #include > > > #include > > > > > > 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 Hi, If I use hid_hw_output_report I can write my 64 bytes buffer to the device. And I would expect a 64 bytes answer from the device, but I don't know how to get it. How do I know where my output data is going to ? Control Pipe or Interrupt Pipe ? How to I get the answer data from the device ? Thanks Lucas 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; //struct hid_report *report = kzalloc(sizeof(struct hid_report), GFP_KERNEL); u8 *buf = kzalloc(64, GFP_KERNEL); u8 *buf2 = kzalloc(64, GFP_KERNEL); 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"); } ret = hid_hw_open(hdev); hid_dbg(hdev, "hid_hw_open %d\n", ret); buf[0] = 0x50; buf[1] = 0x07; ret = hid_hw_output_report(hdev, buf, 64); hid_dbg(hdev, "hid_hw_output_report %d back [%x][%x][%x][%x]\n", ret, buf[0], buf[1], buf[2], buf[3]); //dmesg prints ret 0 ret = hid_hw_raw_request(hdev, 0x81, buf2, 64, HID_INPUT_REPORT, HID_REQ_SET_REPORT); hid_dbg(hdev, "hid_input_report %d back [%x][%x][%x][%x]\n", ret, buf2[0], buf2[1], buf2[2], buf2[3]); //dmesg prints ret -32 kfree(buf); kfree(buf2); return 0; } Dmesg: [ 72.991830] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: mcp2210_probe [ 73.001793] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: parse success [ 73.020234] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: hiddev96,hidraw0: USB HID v1.11 Device [Microchip Technology Inc. MCP2210 USB-to-SPI Master] on usb-3f980000.usb-1.3/input0 [ 73.039798] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: start success [ 73.111858] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: hid_hw_open 0 [ 73.126599] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: hid_hw_output_report 64 back [50][7][0][0] [ 73.140170] MCP2210 USB SPI Driver 0003:04D8:00DE.0002: hid_input_report -32 back [81][0][0][0] _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies