Bug 10337

Summary: xbox driver moves axis y backwards
Product: Drivers Reporter: Charles Joseph Christie II (cchris0396)
Component: Input DevicesAssignee: Anssi Hannula (anssi.hannula)
Status: CLOSED CODE_FIX    
Severity: normal CC: anssi.hannula, cchris0396
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.24 Subsystem:
Regression: --- Bisected commit-id:
Attachments: The new xbox controller driver
xpad: fix inverted Y and RY axes

Description Charles Joseph Christie II 2008-03-26 20:51:13 UTC
Earliest failing kernel version: 2.6.2* something
Distribution: Gentoo Linux
Hardware Environment: 64-bit Intel chipset
Software Environment: 64-bit 2.6.24 kernel
Problem Description: The official Xbox and Xbox360 controllers both seem to exhibit the behavior of reversing the up and down on the Y axis on the left analog stick. It would be nice to get this fixed, as I would like to actually USE my $50 controller.

Steps to reproduce: Plug an Xbox controller in. Play a game. Up and down will be reversed.
Comment 1 Anssi Hannula 2008-03-27 02:46:31 UTC
As far as I can see, the right analog stick has reversed up and down as well (on xbox360 at least).
Are you sure this is not the case for you as well?
Comment 2 Charles Joseph Christie II 2008-03-27 04:27:24 UTC
I haven't tried the right stick yet. Most of my games use 1 stick.
Comment 3 Charles Joseph Christie II 2008-03-27 04:29:57 UTC
Actually, after viewing the controller information in the KDE Control Center's joystick screen, I realize that the right stick is also reversed on the Y axis! Not only that, but the D pad is also reversed on the Y axis!
Comment 4 Anssi Hannula 2008-03-27 08:36:13 UTC
You said that the left stick is reversed with both xbox and xbox360 controllers. Does the reversed right stick also apply to both or only xbox360?

The fact that Dpad is reversed seems quite strange, as it seems to be correct to other people. How exactly did you determine it is wrong using the KDE Control Center applet? Could you use jstest or evtest and see if up/down is negative/positive as it should be?
Comment 5 Charles Joseph Christie II 2008-03-27 09:14:28 UTC
I don't have an original xbox controller to test with, although I am sure it exhibits the same problems (I tested it a while back). The 360 controller reports all Y values on all axis backwards. The KDE Control Center's Joystick module showed the same information, and SDLjoytestGL showed the same information as well. My games all also confirm this. All Y values on the xpad drivers are reversed.
Comment 6 Anssi Hannula 2008-03-27 09:20:15 UTC
How do you know that original xbox controllers also have right stick reversed, if you only tested the left stick?

Regarding Dpad:
Are you using a vanilla kernel or a patched one? If patched, which one?

Could you post the output in kernel log when you plug in your device?
Comment 7 Charles Joseph Christie II 2008-03-27 09:34:01 UTC
My original xbox controllers seemed to have the same problems in the earlier versions of the kernel, in Gentoo Linux x86. I do remember now that, while I was playing around in the KDE control center a few kernel versions ago, that Y was backwards on both sticks on the original controllers as well. But I had mostly used the driver to use dance mats on my computer, so I wasn't too concerned about it.

But now, I have an xbox 360 controller (I might buy an xbox 360 dance mat later, too ;) ) and now I notice that things are screwy. 

As for kernel patches, the problem was evident in Gentoo Linux both x86 gentoo kernels and x86_64 tuxonice kernels, as well as PCLinuxOS kernels from 2007 and 2008 (but xbox360 controllers aren't working in the PCLinuxOS kernel yet, but I tested the original xbox controller on all of these). 

The bug seems too widespread to be the fault of any patches...

And, my dmesg output when plugging in my controller:
usb 4-2: new full speed USB device using uhci_hcd and address 3
usb 4-2: configuration #1 chosen from 1 choice
input: Microsoft X-Box 360 pad as /class/input/input9
Comment 8 Anssi Hannula 2008-03-27 09:42:18 UTC
Okay, so we need to flip the Y axises of the sticks on original xbox as well (I've already sent patches to do it on xbox360).

I'm not sure what to do with the DPAD, though, as the current handling works okay for other users.
Could you please provide the output of jstest or evtest when pressing the DPAD buttons?
Comment 9 Charles Joseph Christie II 2008-03-27 11:06:26 UTC
Well, I don't know if it's acting different than what it's supposed to act like. I just noticed the same numbers for the Y axis on the dpad as on the sticks, and the numbers for the sticks were backwards, so... But then again, if people are setting the dpad like buttons, it shouldn't matter, really. But if they want to use it as an axis, they may have problems. I'm not an expert on how joysticks should work, but the same reversed negative numbers I got on the sticks I got on the dpad. I can't print the output until I am back in my room (I'm in class right now ;) )
Comment 10 Charles Joseph Christie II 2008-03-27 11:07:16 UTC
Oh, and when you're done, where can I get the patches? Or will they be in the next kernel version?
Comment 11 Charles Joseph Christie II 2008-03-27 16:00:05 UTC
Dpad output for jstest:
Axis 7: -32767 when pushing UP
Axis 7: 32767 when pushing DOWN

Which seems backwards to me.
Comment 12 Charles Joseph Christie II 2008-03-27 16:34:06 UTC
Also, if you view my original bug (http://bugzilla.kernel.org/show_bug.cgi?id=7193) it looks like someone has submitted a new driver update.
Comment 13 Anssi Hannula 2008-03-27 17:55:15 UTC
Negative for up is *correct*, positive for down is *correct* for game controllers.

Could you confirm whether you have up as negative or positive with the sticks?
Comment 14 Charles Joseph Christie II 2008-03-28 04:19:35 UTC
With the sticks, I get positive for up and negative for down on both.

However, that driver update in my last comment has code to detect whether the right thumbstick needs to be flipped (and they already fixed the left one being inverted), supports the wireless controller, stops blinking xbox light, uses /proc for enabling and disabling mouse and rumble features, and fun stuff like that. It really looks promising, and it also looks like most of the work is done for you. ;)
Comment 15 Charles Joseph Christie II 2008-03-28 04:23:09 UTC
Created attachment 15478 [details]
The new xbox controller driver

This driver is the latest one from the xbox linux project, the one I made mention of. Perhaps, every once in a while, you guys could take a peek at their driver page (http://xbox.cvs.sourceforge.net/xbox-linux/kernel-2.6/drivers/usb/input/?hideattic=1) and see if the driver is updated.
Comment 16 Anssi Hannula 2008-03-28 11:07:58 UTC
I don't see any detection there. It always flips left stick, but leaves to right stick alone (probably wrong). Note that the kernel xpad driver had already it right, but there was apparently some confusion whether up is positive or negative and it got broken when the intention was to "fix" it.

There is already a patch for xbox360 wireless controller support, however it has not yet been applied (dunno why, I resent it few feeks ago).

Are you sure the blinking xbox light is stopped immediately? With our driver, AFAICS it blinks but stops blinking when you open the device in any application (then the led corresponding to gamepad number is lit up). Also, with our driver one can control the leds oneself (via echoing numbers to /sys/class/leds/something/brightness). With a quick look I don't see the xboxlinux driver doing it differently.

I don't think setting any mouse features belongs in the kernel, as this is not a mouse device. If something like it is added to the kernel, it has to be a generic interface applied to all devices.

You are correct that xbox rumble is not supported by our driver, however xbox360 rumble is supported. The original xbox rumble is in my TODO list, as the code is available from xbox linux project.

Back to the topic now :)
Okay, I'll send a patch to input maintainer to reverse stick Y axes on both xbox and xbox360 then. Thanks for the report.
Comment 17 Anssi Hannula 2008-03-28 11:09:44 UTC
Created attachment 15480 [details]
xpad: fix inverted Y and RY axes

Here is the patch for reference. Sent to linux-input@ as "[patch 2/7, rev2] xpad: fix inverted Y and RY axes".
Comment 18 Charles Joseph Christie II 2008-03-28 15:32:04 UTC
Sweet. What about the other changes made in the newer xbox linux xpad driver? Will that be updated any time soon? Not that we need all of the features in the driver; as we are actually using computers, and thus have mice, we don't really need things like mouse emulation. ;)
Comment 19 Anssi Hannula 2008-03-28 15:35:42 UTC
Well, the xboxlinux version of the driver is quite different from the in-kernel driver, even if they originally were the same. I'm not aware of any other missing features from the in-kernel driver except the original xbox rumble support. I'll be able to implement that in the next few weeks at the earliest, probably a little later.
Comment 20 Charles Joseph Christie II 2008-03-29 06:12:37 UTC
oops, I read their "todo" section by mistake, thinking that it was the "changes" section :P
Comment 21 Charles Joseph Christie II 2008-03-29 06:14:44 UTC
Oh, and I tested that patch, and it works perfectly!
Comment 22 Anssi Hannula 2008-04-07 21:08:28 UTC
The fix has been applied into input subsystem git tree, and will be merged into 2.6.26.

Thanks for the report.