All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Rojtberg <rojtberg@gmail.com>
To: linux-input@vger.kernel.org, pgriffais@valvesoftware.com,
	dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org
Subject: Re: [PATCH 10/15] Input: xpad: use ida() for finding the pad_nr
Date: Fri, 2 Oct 2015 00:53:26 +0200	[thread overview]
Message-ID: <560DB966.8080602@gmail.com> (raw)
In-Reply-To: <1443733046-29610-11-git-send-email-rojtberg@gmail.com>

sorry, I messed up this one. This would be the correct patch.
Should I re-spin the whole series or would it be too much noise?

Subject: [PATCH 10/15] Input: xpad: use ida() for finding the pad_nr

The pad_nr corresponds to the lit up LED on the controller. Therefore
there should be no gaps when enumerating. Currently a LED is only
re-assigned after a controller is re-connected 4 times.

This patch uses ida to track connected pads - this way we can re-assign
freed up pad number immediately.

Consider the following case:
1. pad A is connected and gets pad_nr = 0
2. pad B is connected and gets pad_nr = 1
3. pad A is disconnected
4. pad A is connected again

using ida_simple_get() controller A now correctly gets pad_nr = 0 again.

Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
---
  drivers/input/joystick/xpad.c | 30 +++++++++++++++++++++++-------
  1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 31bcd78..b83ea3c 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -342,11 +342,13 @@ struct usb_xpad {

      int mapping;            /* map d-pad to buttons or to axes */
      int xtype;            /* type of xbox device */
-    unsigned long pad_nr;        /* the order x360 pads were attached */
+    int pad_nr;            /* the order x360 pads were attached */
      const char *name;        /* name of the device */
      struct work_struct work;    /* init/remove device from callback */
  };

+static DEFINE_IDA(xpad_pad_seq);
+
  static int xpad_init_input(struct usb_xpad *xpad);
  static void xpad_deinit_input(struct usb_xpad *xpad);

@@ -946,6 +948,16 @@ static void xpad_send_led_command(struct usb_xpad 
*xpad, int command)
   */
  static void xpad_identify_controller(struct usb_xpad *xpad)
  {
+    if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W)
+        return;
+
+    xpad->pad_nr = ida_simple_get(&xpad_pad_seq, 0, 0, GFP_KERNEL);
+
+    if(xpad->pad_nr < 0) {
+        dev_dbg(&xpad->dev->dev, "%s - ida_get failed\n", __func__);
+        return;
+    }
+
      xpad_send_led_command(xpad, (xpad->pad_nr % 4) + 2);
  }

@@ -960,7 +972,6 @@ static void xpad_led_set(struct led_classdev *led_cdev,

  static int xpad_led_probe(struct usb_xpad *xpad)
  {
-    static atomic_t led_seq = ATOMIC_INIT(-1);
      struct xpad_led *led;
      struct led_classdev *led_cdev;
      int error;
@@ -972,9 +983,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
      if (!led)
          return -ENOMEM;

-    xpad->pad_nr = atomic_inc_return(&led_seq);
-
-    snprintf(led->name, sizeof(led->name), "xpad%lu", xpad->pad_nr);
+    snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr);
      led->xpad = xpad;

      led_cdev = &led->led_cdev;
@@ -1132,6 +1141,8 @@ static int xpad_init_input(struct usb_xpad *xpad)
              xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
      }

+    xpad_identify_controller(xpad);
+
      error = xpad_init_ff(xpad);
      if (error)
          goto fail_init_ff;
@@ -1144,8 +1155,6 @@ static int xpad_init_input(struct usb_xpad *xpad)
      if (error)
          goto fail_input_register;

-    xpad_identify_controller(xpad);
-
      return 0;

  fail_input_register:
@@ -1305,6 +1314,13 @@ static void xpad_deinit_input(struct usb_xpad *xpad)
  {
      xpad_led_disconnect(xpad);
      input_unregister_device(xpad->dev);
+
+    if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W)
+        return;
+
+    if(xpad->pad_nr > -1) {
+        ida_simple_remove(&xpad_pad_seq, xpad->pad_nr);
+    }
  }

  static void xpad_disconnect(struct usb_interface *intf)
-- 
1.9.1


  reply	other threads:[~2015-10-01 22:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01 20:57 [PATCH 00/15] Input: xpad: updates Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 01/15] Input: xpad: add Covert Forces edition of the Xbox One controller Pavel Rojtberg
2015-10-10 16:42   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 02/15] Input: xpad: fix Razer Atrox Arcade Stick button mapping Pavel Rojtberg
2015-10-10 16:43   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 03/15] Input: xpad: clarify LED enumeration Pavel Rojtberg
2015-10-10 16:44   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 04/15] Input: xpad: remove needless bulk out URB used for LED setup Pavel Rojtberg
2015-10-10 16:45   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 05/15] Input: xpad: factor out URB submission in xpad_play_effect Pavel Rojtberg
2015-10-10 16:45   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 06/15] Input: xpad: x360w: report dpad as buttons and axes Pavel Rojtberg
2015-10-10 16:45   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 07/15] Input: xpad: move the input device creation to a new function Pavel Rojtberg
2015-10-10 18:00   ` Dmitry Torokhov
2015-10-15 19:19     ` Pavel Rojtberg
2015-10-17 16:49       ` Dmitry Torokhov
2015-10-17 18:08         ` Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 08/15] Input: xpad: query Wireless controller state at init Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 09/15] Input: xpad: handle "present" and "gone" correctly Pavel Rojtberg
2015-10-10 16:42   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 10/15] Input: xpad: use ida() for finding the pad_nr Pavel Rojtberg
2015-10-01 22:53   ` Pavel Rojtberg [this message]
2015-10-10 17:06     ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 11/15] Input: xpad: do not submit active URBs Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 12/15] Input: xpad: replace mutex by spinlock Pavel Rojtberg
2015-10-10 18:10   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 13/15] Input: xpad: re-submit pending ff and led requests Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 14/15] Input: xpad: workaround dead irq_out after suspend/ resume Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 15/15] Input: xpad: update Xbox One Force Feedback Support Pavel Rojtberg

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=560DB966.8080602@gmail.com \
    --to=rojtberg@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-input@vger.kernel.org \
    --cc=pgriffais@valvesoftware.com \
    /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.