All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Benjamin Tissoires <benjamin.tissoires@gmail.com>,
	Jiri Kosina <jkosina@suse.cz>,
	David Herrmann <dh.herrmann@gmail.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 11/14] HID: sony: remove hid_output_raw_report calls
Date: Mon, 10 Feb 2014 12:58:56 -0500	[thread overview]
Message-ID: <1392055139-19631-12-git-send-email-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <1392055139-19631-1-git-send-email-benjamin.tissoires@redhat.com>

We can not directly change the underlying struct hid_ll_driver here
as we did for hdev->hid_output_raw_report.
So allocate a struct ll_driver, and replace the old one when removing
the device.
To get a fully functional driver, we must also split the function
sixaxis_usb_output_raw_report() in 2, one regarding output_report, and
the other for raw_request.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-sony.c | 75 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 52 insertions(+), 23 deletions(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index d980943..dbbcd0c8 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -507,6 +507,8 @@ struct sony_sc {
 	struct work_struct state_worker;
 	struct power_supply battery;
 
+	struct hid_ll_driver *prev_ll_driver;
+
 #ifdef CONFIG_SONY_FF
 	__u8 left;
 	__u8 right;
@@ -760,38 +762,52 @@ static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
 
 /*
  * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP
- * like it should according to usbhid/hid-core.c::usbhid_output_raw_report()
+ * like it should according to usbhid/hid-core.c::usbhid_output_report()
  * so we need to override that forcing HID Output Reports on the Control EP.
- *
- * There is also another issue about HID Output Reports via USB, the Sixaxis
- * does not want the report_id as part of the data packet, so we have to
- * discard buf[0] when sending the actual control message, even for numbered
- * reports, humpf!
  */
-static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf,
-		size_t count, unsigned char report_type)
+static int sixaxis_usb_output_report(struct hid_device *hid, __u8 *buf,
+		size_t count)
+{
+	return hid_hw_raw_request(hid, buf[0], buf, count, HID_OUTPUT_REPORT,
+		HID_REQ_SET_REPORT);
+}
+
+/*
+ * There is also another issue about the SET_REPORT command via USB,
+ * the Sixaxis does not want the report_id as part of the data packet, so
+ * we have to discard buf[0] when sending the actual control message, even
+ * for numbered reports, humpf!
+ */
+static int sixaxis_usb_raw_request(struct hid_device *hid,
+				   unsigned char reportnum, __u8 *buf,
+				   size_t len, unsigned char rtype, int reqtype)
 {
 	struct usb_interface *intf = to_usb_interface(hid->dev.parent);
 	struct usb_device *dev = interface_to_usbdev(intf);
 	struct usb_host_interface *interface = intf->cur_altsetting;
-	int report_id = buf[0];
 	int ret;
+	u8 usb_dir;
+	unsigned int usb_pipe;
 
-	if (report_type == HID_OUTPUT_REPORT) {
+	if (reqtype == HID_REQ_SET_REPORT) {
 		/* Don't send the Report ID */
 		buf++;
-		count--;
+		len--;
+		usb_dir = USB_DIR_OUT;
+		usb_pipe = usb_sndctrlpipe(dev, 0);
+	} else {
+		usb_dir = USB_DIR_IN;
+		usb_pipe = usb_rcvctrlpipe(dev, 0);
 	}
 
-	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) | report_id,
-		interface->desc.bInterfaceNumber, buf, count,
+	ret = usb_control_msg(dev, usb_pipe, reqtype,
+		usb_dir | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+		((rtype + 1) << 8) | reportnum,
+		interface->desc.bInterfaceNumber, buf, len,
 		USB_CTRL_SET_TIMEOUT);
 
-	/* Count also the Report ID, in case of an Output report. */
-	if (ret > 0 && report_type == HID_OUTPUT_REPORT)
+	/* Count also the Report ID. */
+	if (ret > 0 && reqtype == HID_REQ_SET_REPORT)
 		ret++;
 
 	return ret;
@@ -1047,7 +1063,7 @@ static void sixaxis_state_worker(struct work_struct *work)
 	buf[10] |= sc->led_state[2] << 3;
 	buf[10] |= sc->led_state[3] << 4;
 
-	hid_output_raw_report(sc->hdev, buf, sizeof(buf), HID_OUTPUT_REPORT);
+	hid_hw_output_report(sc->hdev, buf, sizeof(buf));
 }
 
 static void dualshock4_state_worker(struct work_struct *work)
@@ -1254,6 +1270,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	unsigned long quirks = id->driver_data;
 	struct sony_sc *sc;
 	unsigned int connect_mask = HID_CONNECT_DEFAULT;
+	struct hid_ll_driver *ll_driver;
 
 	sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
 	if (sc == NULL) {
@@ -1285,13 +1302,20 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	}
 
 	if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
-		hdev->hid_output_raw_report = sixaxis_usb_output_raw_report;
+		ll_driver = devm_kzalloc(&hdev->dev, sizeof(*ll_driver),
+					     GFP_KERNEL);
+		if (ll_driver == NULL)
+			return -ENOMEM;
+		sc->prev_ll_driver = hdev->ll_driver;
+		*ll_driver = *hdev->ll_driver;
+		hdev->ll_driver = ll_driver;
+		ll_driver->output_report = sixaxis_usb_output_report;
+		ll_driver->raw_request = sixaxis_usb_raw_request;
 		ret = sixaxis_set_operational_usb(hdev);
 		INIT_WORK(&sc->state_worker, sixaxis_state_worker);
-	}
-	else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
+	} else if (sc->quirks & SIXAXIS_CONTROLLER_BT) {
 		ret = sixaxis_set_operational_bt(hdev);
-	else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
+	} else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
 		/* Report 5 (31 bytes) is used to send data to the controller via USB */
 		ret = sony_set_output_report(sc, 0x05, 248);
 		if (ret < 0)
@@ -1339,6 +1363,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
 err_close:
 	hid_hw_close(hdev);
 err_stop:
+	if (sc->prev_ll_driver)
+		hdev->ll_driver = sc->prev_ll_driver;
 	if (sc->quirks & SONY_LED_SUPPORT)
 		sony_leds_remove(hdev);
 	if (sc->quirks & SONY_BATTERY_SUPPORT)
@@ -1351,6 +1377,9 @@ static void sony_remove(struct hid_device *hdev)
 {
 	struct sony_sc *sc = hid_get_drvdata(hdev);
 
+	if (sc->prev_ll_driver)
+		hdev->ll_driver = sc->prev_ll_driver;
+
 	if (sc->quirks & SONY_LED_SUPPORT)
 		sony_leds_remove(hdev);
 
-- 
1.8.3.1


  parent reply	other threads:[~2014-02-10 18:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10 17:58 [PATCH 00/14] HID: low-level transport cleanup, round 2 Benjamin Tissoires
2014-02-10 17:58 ` [PATCH 01/14] HID: uHID: remove duplicated code Benjamin Tissoires
2014-02-12 10:17   ` David Herrmann
2014-02-10 17:58 ` [PATCH 02/14] HID: uHID: implement .raw_request Benjamin Tissoires
2014-02-12 10:18   ` David Herrmann
2014-02-10 17:58 ` [PATCH 03/14] HID: core: implement generic .request() Benjamin Tissoires
2014-02-12 10:25   ` David Herrmann
2014-02-13 15:21     ` Benjamin Tissoires
2014-02-16 16:43       ` David Herrmann
2014-02-10 17:58 ` [PATCH 04/14] HID: i2c-hid: implement ll_driver transport-layer callbacks Benjamin Tissoires
2014-02-12 10:29   ` David Herrmann
2014-02-10 17:58 ` [PATCH 05/14] HID: i2c-hid: use generic .request() implementation Benjamin Tissoires
2014-02-12 10:30   ` David Herrmann
2014-02-13 15:14     ` Benjamin Tissoires
2014-02-10 17:58 ` [PATCH 06/14] HID: usbhid: change return error of usbhid_output_report Benjamin Tissoires
2014-02-12 10:31   ` David Herrmann
2014-02-10 17:58 ` [PATCH 07/14] HID: input: hid-input remove hid_output_raw_report call Benjamin Tissoires
2014-02-12 10:35   ` David Herrmann
2014-02-13 15:38     ` Benjamin Tissoires
2014-02-10 17:58 ` [PATCH 08/14] HID: logitech-dj: " Benjamin Tissoires
2014-02-12 10:36   ` David Herrmann
2014-02-10 17:58 ` [PATCH 09/14] HID: replace hid_output_raw_report with hid_hw_raw_request for feature requests Benjamin Tissoires
2014-02-10 17:58 ` [PATCH 10/14] HID: wiimote: replace hid_output_raw_report with hid_hw_output_report for output requests Benjamin Tissoires
2014-02-12 10:39   ` David Herrmann
2014-02-10 17:58 ` Benjamin Tissoires [this message]
2014-02-12 10:47   ` [PATCH 11/14] HID: sony: remove hid_output_raw_report calls David Herrmann
2014-02-13 15:46     ` Benjamin Tissoires
2014-02-10 17:58 ` [PATCH 12/14] HID: hidraw: replace hid_output_raw_report() calls by appropriates ones Benjamin Tissoires
2014-02-12 10:49   ` David Herrmann
2014-02-13 15:16     ` Benjamin Tissoires
2014-02-10 17:58 ` [PATCH 13/14] HID: remove hid_output_raw_report Benjamin Tissoires
2014-02-12 10:50   ` David Herrmann
2014-02-10 17:58 ` [PATCH 14/14] HID: core: check parameters when sending/receiving data from the device Benjamin Tissoires
2014-02-12 10:51   ` David Herrmann
2014-02-17 14:01 ` [PATCH 00/14] HID: low-level transport cleanup, round 2 Jiri Kosina

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=1392055139-19631-12-git-send-email-benjamin.tissoires@redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=benjamin.tissoires@gmail.com \
    --cc=dh.herrmann@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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.