linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] hidraw: Use Interrupt Endpoint for OUT Transfers if Available
@ 2010-05-16 22:07 Alan Ott
  2010-05-18  8:44 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Ott @ 2010-05-16 22:07 UTC (permalink / raw)
  To: Jiri Kosina, Marcel Holtmann, Alan Stern, H Hartley Sweeten,
	David Fries
  Cc: linux-usb, linux-input, linux-kernel

From: Alan Ott <alan@signal11.us>

This patch makes the hidraw driver use the first Interrupt OUT endpoint for
HID transfers to the device if such an endpoint exists. This is consistent
with the behavior of the hiddev driver, and the logic is similar.

Signed-off-by: Alan Ott <alan@signal11.us>
---
I believe this to be consistent with the section 4.4 of the HID 1.11
specification located at:
    http://www.usb.org/developers/devclass_docs/HID1_11.pdf

>From the specification (page numbered 10, the 20th page of the document
(xpdf page 20)):

   The Interrupt Out pipe is optional. If a device declares an Interrupt Out
   endpoint then Output reports are transmitted by the host to the device
   through the Interrupt Out endpoint. If no Interrupt Out endpoint is
   declared then Output reports are transmitted to a device through the
   Control endpoint, using Set_Report(Output) requests.

This is also consistent with the way the Windows HID library (hid.dll)
works.

Please let me know if I'm off-base here, or have misread the standard.

Alan.

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 56d06cd..6fd833d 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -807,16 +807,36 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
 	struct usb_host_interface *interface = intf->cur_altsetting;
 	int ret;
 
-	ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
-		HID_REQ_SET_REPORT,
-		USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
-		((report_type + 1) << 8) | *buf,
-		interface->desc.bInterfaceNumber, buf + 1, count - 1,
-		USB_CTRL_SET_TIMEOUT);
-
-	/* count also the report id */
-	if (ret > 0)
-		ret++;
+	if (usbhid->urbout) {
+		int actual_length;
+		int skipped_report_id = 0;
+		if (buf[0] == 0x0) {
+			/* Don't send the Report ID */
+			buf++;
+			count--;
+			skipped_report_id = 1;
+		}
+		ret = usb_interrupt_msg(dev, usbhid->urbout->pipe,
+			buf, count, &actual_length,
+			USB_CTRL_SET_TIMEOUT);
+		/* return the number of bytes transferred */
+		if (ret == 0) {
+			ret = actual_length;
+			/* count also the report id */
+			if (skipped_report_id)
+				ret++;
+		}
+	} else {
+		ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+			HID_REQ_SET_REPORT,
+			USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+			((report_type + 1) << 8) | *buf,
+			interface->desc.bInterfaceNumber, buf + 1, count - 1,
+			USB_CTRL_SET_TIMEOUT);
+		/* count also the report id */
+		if (ret > 0)
+			ret++;
+	}
 
 	return ret;
 }




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] hidraw: Use Interrupt Endpoint for OUT Transfers if Available
  2010-05-16 22:07 [PATCH 1/1] hidraw: Use Interrupt Endpoint for OUT Transfers if Available Alan Ott
@ 2010-05-18  8:44 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2010-05-18  8:44 UTC (permalink / raw)
  To: Alan Ott
  Cc: Marcel Holtmann, Alan Stern, H Hartley Sweeten, David Fries,
	linux-usb, linux-input, linux-kernel

On Sun, 16 May 2010, Alan Ott wrote:

> From: Alan Ott <alan@signal11.us>
> 
> This patch makes the hidraw driver use the first Interrupt OUT endpoint for
> HID transfers to the device if such an endpoint exists. This is consistent
> with the behavior of the hiddev driver, and the logic is similar.
> 
> Signed-off-by: Alan Ott <alan@signal11.us>
> ---
> I believe this to be consistent with the section 4.4 of the HID 1.11
> specification located at:
>     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
> 
> >From the specification (page numbered 10, the 20th page of the document
> (xpdf page 20)):
> 
>    The Interrupt Out pipe is optional. If a device declares an Interrupt Out
>    endpoint then Output reports are transmitted by the host to the device
>    through the Interrupt Out endpoint. If no Interrupt Out endpoint is
>    declared then Output reports are transmitted to a device through the
>    Control endpoint, using Set_Report(Output) requests.
> 
> This is also consistent with the way the Windows HID library (hid.dll)
> works.

Yes, this definitely is a proper improvement. Thanks Alan, I have queued 
the patch.

-- 
Jiri Kosina
SUSE Labs, Novell Inc.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-18  8:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-16 22:07 [PATCH 1/1] hidraw: Use Interrupt Endpoint for OUT Transfers if Available Alan Ott
2010-05-18  8:44 ` Jiri Kosina

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).