All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michal Malý" <madcatxster@devoid-pointer.net>
To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: dmitry.torokhov@gmail.com, jikos@kernel.org, elias.vds@gmail.com,
	edwin@velds.nl, simon@mungewell.org,
	"Michal Malý" <madcatxster@devoid-pointer.net>
Subject: [PATCH 2/2] Use usb_skelswitch module to switch Logitech G920 Racing Wheel to HID mode.
Date: Sat, 23 Jan 2016 11:35:11 +0100	[thread overview]
Message-ID: <1453545311-5721-3-git-send-email-madcatxster@devoid-pointer.net> (raw)
In-Reply-To: <1453545311-5721-1-git-send-email-madcatxster@devoid-pointer.net>

Tested-by: Elias Vanderstuyft <elias.vds@gmail.com>
Signed-off-by: Michal Malý <madcatxster@devoid-pointer.net>
---
 drivers/usb/common/Kconfig          |  2 ++
 drivers/usb/common/usb-skelswitch.c | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/drivers/usb/common/Kconfig b/drivers/usb/common/Kconfig
index 6d9ec79..8ae9a1e 100644
--- a/drivers/usb/common/Kconfig
+++ b/drivers/usb/common/Kconfig
@@ -11,5 +11,7 @@ config USB_SKELSWITCH
 	  appear as a generic USB device.
 
 	  Say Y if you intend to use a device that requires this initial switch.
+	  Devices that currently require this module:
+	   - Logitech G920 Racing Wheel
 
 endif # USB_COMMON
diff --git a/drivers/usb/common/usb-skelswitch.c b/drivers/usb/common/usb-skelswitch.c
index ae72068..fc85c70 100644
--- a/drivers/usb/common/usb-skelswitch.c
+++ b/drivers/usb/common/usb-skelswitch.c
@@ -14,10 +14,70 @@ struct usb_skelswitch_vendor {
 };
 
 static const struct usb_device_id usb_skelswitch_table[] = {
+	{ USB_DEVICE(0x046d, 0xc261) },
 	{ }
 };
 
+MODULE_DEVICE_TABLE(usb, usb_skelswitch_table);
+
+static int usb_skelswitch_lg_g920(struct usb_interface *intf)
+{
+	struct usb_host_interface *iface_desc;
+	struct usb_endpoint_descriptor *endpoint;
+	struct usb_device *udev;
+	int idx;
+	int ret;
+	int xferred;
+	size_t buffer_size;
+	unsigned char cmd[] = { 0x0f, 0x00, 0x01, 0x01, 0x42 };
+	const size_t cmd_len = ARRAY_SIZE(cmd);
+	u8 intr_out_addr = 0;
+
+	udev = usb_get_dev(interface_to_usbdev(intf));
+	iface_desc = intf->cur_altsetting;
+	for (idx = 0; idx < iface_desc->desc.bNumEndpoints; idx++) {
+		endpoint = &iface_desc->endpoint[idx].desc;
+
+		if (usb_endpoint_is_int_out(endpoint)) {
+			intr_out_addr = endpoint->bEndpointAddress;
+			buffer_size = usb_endpoint_maxp(endpoint);
+			break;
+		}
+	}
+
+	if (!intr_out_addr) {
+		dev_err(&udev->dev, "Logitech G920 - No interrupt out endpoint found");
+		return -ENODEV;
+	}
+
+	if (buffer_size < cmd_len) {
+		dev_err(&udev->dev, "usb_skelswitch: Logitech G920 - Output buffer is too small");
+		return -ENODEV;
+	}
+
+
+	ret = usb_interrupt_msg(udev, usb_sndintpipe(udev, intr_out_addr),
+				cmd, cmd_len, &xferred, USB_CTRL_SET_TIMEOUT);
+
+	if (ret) {
+		dev_err(&udev->dev, "LG G920: Failed to submit URB, errno: %d", ret);
+		return ret;
+	}
+	if (xferred != cmd_len) {
+		dev_err(&udev->dev, "LG G920: Incorrect number of bytes transferred: %d", xferred);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static const struct usb_skelswitch_product usb_skelswitch_logitech_devs[] = {
+	{ 0xc261, usb_skelswitch_lg_g920 },
+	{ 0, NULL }
+};
+
 static const struct usb_skelswitch_vendor usb_skelswitch_vendors[] = {
+	{ 0x046d, usb_skelswitch_logitech_devs },
 	{ 0, NULL }
 };
 
-- 
2.7.0

  parent reply	other threads:[~2016-01-23 10:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-23 10:35 [PATCH 0/2] Add a skeleton module to perform a basic initialization on certain USB devices Michal Malý
2016-01-23 10:35 ` [PATCH 1/2] Add usb_skelswitch skeleton module to do basic initialization of devices that at first appear as a generic USB device Michal Malý
2016-01-23 10:35 ` Michal Malý [this message]
2016-01-23 12:46 ` [PATCH 0/2] Add a skeleton module to perform a basic initialization on certain USB devices Bjørn Mork
2016-01-23 15:56   ` Michal Malý
2016-01-23 16:39     ` Greg KH
2016-01-24 22:05       ` Oliver Neukum
2016-01-24 22:48         ` Greg KH
2016-01-25 11:27           ` Oliver Neukum
2016-01-25 14:17     ` Jiri Kosina
2016-01-25 21:02       ` Michal Malý

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=1453545311-5721-3-git-send-email-madcatxster@devoid-pointer.net \
    --to=madcatxster@devoid-pointer.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=edwin@velds.nl \
    --cc=elias.vds@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=simon@mungewell.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.