public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Valentin <benpicco@zedat.fu-berlin.de>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers/input/joystick/xpad.c: Add rumble support for original xbox controller
Date: Fri, 8 Jan 2010 11:26:10 +0100	[thread overview]
Message-ID: <20100108112610.0b78785b@piBook> (raw)
In-Reply-To: <20100108075054.GA3696@core.coreip.homeip.net>

[-- Attachment #1: Type: text/plain, Size: 3513 bytes --]

On Thu, 7 Jan 2010 23:50:54 -0800
Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:

> Thank you for your patch. Could I please have your "Signed-off-by: "
> so I can apply it? Also, if you have any more patches ofr in put
> devices, could you please CC linux-input@vger.kernel.org?

This way?

Signed-off-by: Benjamin Valentin <benpicco@zedat.fu-berlin.de>

--- /usr/src/linux-source-2.6.33/drivers/input/joystick/xpad.c
2010-01-08 02:56:59.365851076 +0100 +++ xpad.c	2010-01-08
03:13:38.477835651 +0100 @@ -505,7 +505,7 @@
 	struct usb_endpoint_descriptor *ep_irq_out;
 	int error = -ENOMEM;
 
-	if (xpad->xtype != XTYPE_XBOX360)
+	if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX)
 		return 0;
 
 	xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN,
@@ -535,13 +535,13 @@
 
 static void xpad_stop_output(struct usb_xpad *xpad)
 {
-	if (xpad->xtype == XTYPE_XBOX360)
+	if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype != XTYPE_XBOX)
 		usb_kill_urb(xpad->irq_out);
 }
 
 static void xpad_deinit_output(struct usb_xpad *xpad)
 {
-	if (xpad->xtype == XTYPE_XBOX360) {
+	if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype != XTYPE_XBOX)
{ usb_free_urb(xpad->irq_out);
 		usb_buffer_free(xpad->udev, XPAD_PKT_LEN,
 				xpad->odata, xpad->odata_dma);
@@ -554,24 +554,43 @@
 #endif
 
 #ifdef CONFIG_JOYSTICK_XPAD_FF
-static int xpad_play_effect(struct input_dev *dev, void *data,
-			    struct ff_effect *effect)
+static int xpad_send_rumble(struct usb_xpad *xpad, unsigned char left,
unsigned char right) {
+	switch(xpad->xtype) {
+		case XTYPE_XBOX:
+			xpad->odata[0] = 0x00;
+			xpad->odata[1] = 0x06;
+			xpad->odata[2] = 0x00;
+			xpad->odata[3] = left;  // left actuator
+			xpad->odata[4] = 0x00;
+			xpad->odata[5] = right; // right actuator
+			xpad->irq_out->transfer_buffer_length = 6;
+			return usb_submit_urb(xpad->irq_out,
GFP_KERNEL);
+		case XTYPE_XBOX360:
+			xpad->odata[0] = 0x00;
+			xpad->odata[1] = 0x08;
+			xpad->odata[2] = 0x00;
+			xpad->odata[3] = left;  // left actuator?
+			xpad->odata[4] = right; // right actuator?
+			xpad->odata[5] = 0x00;
+			xpad->odata[6] = 0x00;
+			xpad->odata[7] = 0x00;
+			xpad->irq_out->transfer_buffer_length = 8;
+			return usb_submit_urb(xpad->irq_out,
GFP_KERNEL);
+		default:
+			dbg("%s - rumble command sent to unsupported
xpad type: %d", 
+				__func__, xpad->xtype);
+			return 0;
+		}
+}
+
+static int xpad_play_effect(struct input_dev *dev, void *data, struct
ff_effect *effect) {
 	struct usb_xpad *xpad = input_get_drvdata(dev);
 
 	if (effect->type == FF_RUMBLE) {
-		__u16 strong = effect->u.rumble.strong_magnitude;
-		__u16 weak = effect->u.rumble.weak_magnitude;
-		xpad->odata[0] = 0x00;
-		xpad->odata[1] = 0x08;
-		xpad->odata[2] = 0x00;
-		xpad->odata[3] = strong / 256;
-		xpad->odata[4] = weak / 256;
-		xpad->odata[5] = 0x00;
-		xpad->odata[6] = 0x00;
-		xpad->odata[7] = 0x00;
-		xpad->irq_out->transfer_buffer_length = 8;
-		usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+		unsigned char strong =
effect->u.rumble.strong_magnitude / 256;
+		unsigned char weak   =
effect->u.rumble.weak_magnitude / 256;
+		xpad_send_rumble(xpad, strong, weak);
 	}
 
 	return 0;
@@ -579,7 +598,7 @@
 
 static int xpad_init_ff(struct usb_xpad *xpad)
 {
-	if (xpad->xtype != XTYPE_XBOX360)
+	if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX)
 		return 0;
 
 	input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2010-01-08 10:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08  2:32 [PATCH] drivers/input/joystick/xpad.c: Add rumble support for original xbox controller Benjamin Valentin
2010-01-08  7:50 ` Dmitry Torokhov
2010-01-08 10:26   ` Benjamin Valentin [this message]
2010-01-10  7:56     ` Dmitry Torokhov
2010-01-10 18:11       ` Benjamin Valentin
2010-01-10 19:56         ` Dmitry Torokhov
2010-01-10 20:48           ` Benjamin Valentin
2010-01-13 21:31           ` Benjamin Valentin

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=20100108112610.0b78785b@piBook \
    --to=benpicco@zedat.fu-berlin.de \
    --cc=dmitry.torokhov@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox