From nobody Tue Apr 7 09:11:38 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD6CA3A5427 for ; Sat, 4 Apr 2026 08:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775292053; cv=none; b=fkIZ4J49GkK7meHYFGN9axMvRUXmduAjkizxEgQPuPfLIk2OOMlihujHEsMvYkxJ1YvYF0Y8zL8NcSVjrlM3RFk8AXwSzcEpbjZR6WnCg/7gtIrepBUYDWmrQQ4zlWwUfpEqsTydsbFQEmqqK3D9ECb/6nPEGXB3AeO+Nnu/PfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775292053; c=relaxed/simple; bh=hhsZ6j19W4o6s/8yEV+HcIniEdGTRY8zKrXFnU1OXxQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Pf7zcVMfw9zzg5xmqs5NoFSabOrSE2hWYAxqZHyQtiqZST7g2Tlr8+vrFdXOEV0G6/WtqT58HpaLKIhpSzGlfbCbHtIpvCm6Cgkyr2uIgZVCYwrtU4XpxPI0T9DmoGnM3avMZF5TpJjaEX8mpepTZoEo0u9SO7SS+d5J8lmkw5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=tNKx9Jir; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tNKx9Jir" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2b2469e5117so13529695ad.1 for ; Sat, 04 Apr 2026 01:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775292050; x=1775896850; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Mq7B89Ewf697Bx8LyU72ArzYBHLBGffy4a2kKVItZjM=; b=tNKx9JirkTeDwIu+ww2hJ3xrJA1qYqAiMYz7BvLNIRZ/tTYVsem/sUWbfCrDl+z00d qu5cIK4N4lxr21gs3r6Icq8dpsLGDsdEIEGKqxqI8hzV6LVhJoQDkczSj2MUbwpgLjOM zaOOg6RZ+12kg4Q4zSn68Ed3gqEoiPwHbeA2WoyKtusekb2Wxn9ji6ljh8PeZwotpEea 6aYQPlRieM+9C+rigAIJuF1XhT510hVdwPpRl+R40zjyPreZofIqbfScQraEsYTMlwlD B9aHHWqfRnlqGZOXflEcL3TeNBXLnugtzjZTUiXBmLsPAgxMDg0xS4KhmgoXd7LpX/62 gS1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775292050; x=1775896850; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Mq7B89Ewf697Bx8LyU72ArzYBHLBGffy4a2kKVItZjM=; b=oMoSGPhX20z/hyDfsCk1I8tYBmRctGZryRGZfmGyIf0edvTW2uMdpCU6O8ZoWEAI33 qbiN4FDE2u+byybKVrUDLRPwy1UC1jfEJkzqXPD1Z5irY/s4aFAkE/fd0R8/7nwVbL2o pcdNaeVgXGEXw+/hZfPMEnT6P3rz4GjfC3dvJniRAAku7S+AKQPo/rhUAbgW7hcsQpw0 R1/1fOkpyK/2zLUd1AwTs/0POxR8sRG03DZ3Ld+O3nsr6Lvib1c+oaCsIa/+osOzWi9q 1Dm4FGx+A9ahXUyGFinUbSG5+WzROtHrv2TKb9rfDAu4DXBONVXDerLOAcj0V4mQ+Bbi swTw== X-Forwarded-Encrypted: i=1; AJvYcCUgXASzA+tuY1OVs6PKhzHJnxGO8LLn7jfmj71jOPezvbfAIaG7QBq1NhOaFhSZQ4AViVLM3Z4rQmHfs9g=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5rmHidzk9XtFiMd20rfhExg4m1nXKTDzEFf/BBkZKdHUnTMV6 IAYooY137VmUwQiZDG3jTM0FFmvSwjvpHqah+Y6/xTO5gMk7mtyrnlvq X-Gm-Gg: AeBDievdt5AjaUNSpY/DlWLmpvJhGon8HO3jfUnw2rkVLvj3w+dHnOSaggc1wgPEG1r dTBoVipJbl+MPMgSE+DG39Tv0gOy/8g5/9KDV/nATEuP3Yd18L2Jzs6vfk7covTN2yuFb4OerOw gZAq6Slmm5ulv1rpf+K4gCdY+XoaIjSoIghjKrx2VkDN42vJadW/0Z9ERpcQ+7Y5r6TG8bbzyl9 73SB8aDOa37RMZw9ngpeXeETU2Di3fFiYFS7fEZ6sdpT3bgtQLUlCQS8VgFkW0Wh1Ml/aJNR8sv gY6l10lXH9FvyUM+gcTd5qWJKs3wSShzwh9dZQXIkZBzpW/KXpj8g1G76DnsB6ikH2RlLEsUAt1 mKk0JHtPP4RrDwAZa5NE1q4Rzxz9ysIXViFC2dnF5dkeOoBObsPY9/nbiCPzClZ9LeXT9nBYNXK 0smabG7IGHc3ybX6H/Mp8yeQm4DyY1UjZik4z6y5+ncN7dWjPEqQ2JCDr4jGFrrY/UKH9ePsMRD Ap326UrchpgtBiVooOFVUtpU7wv2EN8ckORrNXBoQTB8t5B1bXK+KS4xsR/gQ== X-Received: by 2002:a17:903:4b03:b0:2ae:5a38:96bb with SMTP id d9443c01a7336-2b277d633f8mr88046425ad.2.1775292049716; Sat, 04 Apr 2026 01:40:49 -0700 (PDT) Received: from sanjays-pc.govzhome.govindz.co.nz ([203.94.63.0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b274735633sm81277905ad.6.2026.04.04.01.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2026 01:40:49 -0700 (PDT) From: Sanjay Govind To: Dmitry Torokhov , Vicki Pfau , Nilton Perim Neto , Sanjay Govind , Mario Limonciello , Antheas Kapenekakis Cc: "Pierre-Loup A. Griffais" , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] xpad: Overhaul device data for wireless devices Date: Sat, 4 Apr 2026 21:39:27 +1300 Message-ID: <20260404083928.489966-3-sanjay.govind9@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Xbox 360 wireless controllers expose information in the link and capabilities reports. Extract and use the vendor id for wireless controllers, and use the subtype to build a nicer device name and product id. Some xbox 360 controllers put a vid and pid into the stick capability data, so check if this was done, and pull the vid, pid and revision from there. Signed-off-by: Sanjay Govind --- v2: Delay marking device as present until after capabilities or timeout drivers/input/joystick/xpad.c | 162 ++++++++++++++++++++++++++++++++-- 1 file changed, 155 insertions(+), 7 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index bf4accf3f581..c35512c7c199 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -68,6 +68,7 @@ #include #include #include +#include #include #include =20 @@ -94,6 +95,22 @@ #define XTYPE_XBOXONE 3 #define XTYPE_UNKNOWN 4 =20 +#define FLAG_FORCE_FEEDBACK 0x01 + +#define SUBTYPE_GAMEPAD 0x01 +#define SUBTYPE_WHEEL 0x02 +#define SUBTYPE_ARCADE_STICK 0x03 +#define SUBTYPE_FLIGHT_SICK 0x04 +#define SUBTYPE_DANCE_PAD 0x05 +#define SUBTYPE_GUITAR 0x06 +#define SUBTYPE_GUITAR_ALTERNATE 0x07 +#define SUBTYPE_DRUM_KIT 0x08 +#define SUBTYPE_GUITAR_BASS 0x0B +#define SUBTYPE_RB_KEYBOARD 0x0F +#define SUBTYPE_ARCADE_PAD 0x13 +#define SUBTYPE_TURNTABLE 0x17 +#define SUBTYPE_PRO_GUITAR 0x19 + /* Send power-off packet to xpad360w after holding the mode button for thi= s many * seconds */ @@ -795,8 +812,13 @@ struct usb_xpad { int xtype; /* type of xbox device */ int packet_type; /* type of the extended packet */ int pad_nr; /* the order x360 pads were attached */ + u8 sub_type; + u16 flags; + u16 wireless_vid; + u16 wireless_pid; + u16 wireless_version; const char *name; /* name of the device */ - struct work_struct work; /* init/remove device from callback */ + struct delayed_work work; /* init/remove device from callback */ time64_t mode_btn_down_ts; bool delay_init; /* init packets should be delayed */ bool delayed_init_done; @@ -807,6 +829,8 @@ static void xpad_deinit_input(struct usb_xpad *xpad); static int xpad_start_input(struct usb_xpad *xpad); static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num); static void xpad360w_poweroff_controller(struct usb_xpad *xpad); +static int xpad_inquiry_pad_capabilities(struct usb_xpad *xpad); + =20 /* * xpad_process_packet @@ -980,7 +1004,7 @@ static void xpad360_process_packet(struct usb_xpad *xp= ad, struct input_dev *dev, =20 static void xpad_presence_work(struct work_struct *work) { - struct usb_xpad *xpad =3D container_of(work, struct usb_xpad, work); + struct usb_xpad *xpad =3D container_of(work, struct usb_xpad, work.work); int error; =20 if (xpad->pad_present) { @@ -1028,10 +1052,60 @@ static void xpad360w_process_packet(struct usb_xpad= *xpad, u16 cmd, unsigned cha =20 if (xpad->pad_present !=3D present) { xpad->pad_present =3D present; - schedule_work(&xpad->work); + if (present) { + /* + * Delay marking device as present, so we can make sure + * we have received all the information from the capabilities + * report. Some devices don't send one, so the delay + * guarantees that these devices are still initialized. + */ + schedule_delayed_work(&xpad->work, msecs_to_jiffies(500)); + } else { + schedule_delayed_work(&xpad->work, 0); + } } } =20 + /* Link report */ + if (data[0] =3D=3D 0x00 && data[1] =3D=3D 0x0F) { + xpad->sub_type =3D data[25] & 0x7f; + + /* Decode vendor id from link report */ + xpad->wireless_vid =3D ((data[0x16] & 0xf) | data[0x18] << 4) << 8 | dat= a[0x17]; + /* + * x360w controllers on windows put the subtype into the product + * for wheels and gamepads, but it makes sense to do it for all + * subtypes. This will be used if the capabilities report + * doesn't provide us with a product id later. + */ + xpad->wireless_pid =3D 0x02a0 + xpad->sub_type; + xpad->wireless_version =3D 0; + + if ((data[25] & 0x80) !=3D 0) + xpad->flags |=3D FLAG_FORCE_FEEDBACK; + + xpad_inquiry_pad_capabilities(xpad); + } + + /* Capabilities report */ + if (data[0] =3D=3D 0x00 && data[1] =3D=3D 0x05 && data[5] =3D=3D 0x12) { + xpad->flags |=3D data[20]; + /* + * A bunch of vendors started putting vids and pids + * into capabilities data because they can't be + * retrieved by xinput easliy. + * Not all of them do though, so check the vids match + * before extracting that info. + */ + if (get_unaligned_le16(data + 10) =3D=3D xpad->wireless_vid) { + xpad->wireless_pid =3D get_unaligned_le16(data + 12); + xpad->wireless_version =3D get_unaligned_le16(data + 14); + } + /* We got the capabilities report, so mark the device present now */ + cancel_delayed_work(&xpad->work); + schedule_delayed_work(&xpad->work, 0); + } + /* Valid pad data */ if (data[1] !=3D 0x1) return; @@ -1495,6 +1569,31 @@ static int xpad_inquiry_pad_presence(struct usb_xpad= *xpad) return xpad_try_sending_next_out_packet(xpad); } =20 +static int xpad_inquiry_pad_capabilities(struct usb_xpad *xpad) +{ + struct xpad_output_packet *packet =3D + &xpad->out_packets[XPAD_OUT_CMD_IDX]; + + guard(spinlock_irqsave)(&xpad->odata_lock); + + packet->data[0] =3D 0x00; + packet->data[1] =3D 0x00; + packet->data[2] =3D 0x02; + packet->data[3] =3D 0x80; + packet->data[4] =3D 0x00; + packet->data[5] =3D 0x00; + packet->data[6] =3D 0x00; + packet->data[7] =3D 0x00; + packet->data[8] =3D 0x00; + packet->data[9] =3D 0x00; + packet->data[10] =3D 0x00; + packet->data[11] =3D 0x00; + packet->len =3D 12; + packet->pending =3D true; + + return xpad_try_sending_next_out_packet(xpad); +} + static int xpad_start_xbox_one(struct usb_xpad *xpad) { int error; @@ -1893,7 +1992,7 @@ static void xpad360w_stop_input(struct usb_xpad *xpad) usb_kill_urb(xpad->irq_in); =20 /* Make sure we are done with presence work if it was scheduled */ - flush_work(&xpad->work); + flush_delayed_work(&xpad->work); } =20 static int xpad_open(struct input_dev *dev) @@ -1965,8 +2064,57 @@ static int xpad_init_input(struct usb_xpad *xpad) usb_to_input_id(xpad->udev, &input_dev->id); =20 if (xpad->xtype =3D=3D XTYPE_XBOX360W) { - /* x360w controllers and the receiver have different ids */ - input_dev->id.product =3D 0x02a1; + /* If the Link report has provided a vid, it won't be set to 1 */ + if (xpad->wireless_vid !=3D 1) + input_dev->id.vendor =3D xpad->wireless_vid; + if (xpad->wireless_version) + input_dev->id.version =3D xpad->wireless_version; + input_dev->id.product =3D xpad->wireless_pid; + switch (xpad->sub_type) { + case SUBTYPE_GAMEPAD: + input_dev->name =3D "Xbox 360 Wireless Controller"; + break; + case SUBTYPE_WHEEL: + input_dev->name =3D "Xbox 360 Wireless Wheel"; + break; + case SUBTYPE_ARCADE_STICK: + input_dev->name =3D "Xbox 360 Wireless Arcade Stick"; + break; + case SUBTYPE_FLIGHT_SICK: + input_dev->name =3D "Xbox 360 Wireless Flight Stick"; + break; + case SUBTYPE_DANCE_PAD: + input_dev->name =3D "Xbox 360 Wireless Dance Pad"; + break; + case SUBTYPE_GUITAR: + input_dev->name =3D "Xbox 360 Wireless Guitar"; + break; + case SUBTYPE_GUITAR_ALTERNATE: + input_dev->name =3D "Xbox 360 Wireless Alternate Guitar"; + break; + case SUBTYPE_GUITAR_BASS: + input_dev->name =3D "Xbox 360 Wireless Bass Guitar"; + break; + case SUBTYPE_DRUM_KIT: + /* Vendors used force feedback flag to differentiate these */ + if (xpad->flags & FLAG_FORCE_FEEDBACK) + input_dev->name =3D "Xbox 360 Wireless Guitar Hero Drum Kit"; + else + input_dev->name =3D "Xbox 360 Wireless Rock Band Drum Kit"; + break; + case SUBTYPE_RB_KEYBOARD: + input_dev->name =3D "Xbox 360 Wireless Rock Band Keyboard"; + break; + case SUBTYPE_ARCADE_PAD: + input_dev->name =3D "Xbox 360 Wireless Arcade Pad"; + break; + case SUBTYPE_TURNTABLE: + input_dev->name =3D "Xbox 360 Wireless DJ Hero Turntable"; + break; + case SUBTYPE_PRO_GUITAR: + input_dev->name =3D "Xbox 360 Wireless Rock Band Pro Guitar"; + break; + } } =20 input_dev->dev.parent =3D &xpad->intf->dev; @@ -2106,7 +2254,7 @@ static int xpad_probe(struct usb_interface *intf, con= st struct usb_device_id *id xpad->delay_init =3D true; =20 xpad->packet_type =3D PKT_XB; - INIT_WORK(&xpad->work, xpad_presence_work); + INIT_DELAYED_WORK(&xpad->work, xpad_presence_work); =20 if (xpad->xtype =3D=3D XTYPE_UNKNOWN) { if (intf->cur_altsetting->desc.bInterfaceClass =3D=3D USB_CLASS_VENDOR_S= PEC) { --=20 2.53.0