From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 B065F27A476 for ; Sat, 4 Apr 2026 05:33:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775280822; cv=none; b=p6UDu0M8Xn6BU4wY721tsNPoc/QxlRxZRFtcLxeZxgb8TacPHI0gucCSdEWrSklwOi66j4pf5oubCXvy7KzffnpAoOSqGBnzkcIrHjg5oyrA0lcYLpKMulJtk0/kHqViqh8x9fEdmrRE9ADJkN8qWAQ4fMVwE2iffBMgb0v/w7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775280822; c=relaxed/simple; bh=B996usIYCBCo60/EadERLeQsxWJx5uu/hycNx/jtU8I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Kqzzu/aTaHk1CYiN86LuSQRVZznppjQo4wMsdIsuRMAFAygUFNX0zVF9RwWHQUI6dVZHSi2opvm5LSpqH4jR+ONISLOBHQROz8+HdCYIB8ZI+KgaQNWgP1vBXiTEsmTd1/sCOJrh7fq/OAYjD5FKG3kVzJw9u0OvYi9b9CVSvPU= 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=NPRBWe5q; arc=none smtp.client-ip=74.125.82.182 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="NPRBWe5q" Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-2c15849aa2cso2855931eec.0 for ; Fri, 03 Apr 2026 22:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775280820; x=1775885620; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/L+igkv/Dr4KK1K3dBsA3AYj3MMuYuKDe+OnJWJOtJw=; b=NPRBWe5qxXXneVw6VgKzjGlM5SDiRf5oDQw+a2Hu2sAq/DZUY3Rd8dHH1tIbybgarE h5cWjqnkf4V/Ve5fSiTNfJ4LJ7OhYEwyBwOWC3Xmqe4UfuyNBQq7Reji44KvuGejVRg6 +WnmgvfDbn0bMNEpLMmd7u4maef6bDNBm3KoZV66FczUElomQKHisUAPbL3LLYSKlbN5 tZ30UNWW9pkE01O1B6X9LoU4MRuq+nMfor1ExT6G1Lg4uG5ZZl19obEgxWre7XbNknvE iA/q+IZcTvr4ZR4IFROxoCe9NQ9PvjIAHSrS6E42k4S3bpsdq9h0rGHzpYgFpTlcst4D 0WGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775280820; x=1775885620; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/L+igkv/Dr4KK1K3dBsA3AYj3MMuYuKDe+OnJWJOtJw=; b=J+djYBMaOiGuOoHKjzYqCJD+B5t3W4TWich2mK4f21wJhPsmr2rp7b7CPn+ttcH8yb Qf/9duwyovmTFM7HrlwRU4yMsu08kq6nihXUZzZPXjHn2PF7WRXsMSYdJ59wu/AUEg6K LZ1wCLxsPimd3kPEnHLF6st5y31MFu5Eh/A7brK6CpqSmYXfXaKm5hwwoptMR2oPpfvQ JRkbhCwHRDBnRc+EThvYvVToxPIfEqx4fLK/dLl8MY30LpRhNFK9VYORC3EM0Ix2RwDo bAcTupr0v5bT0GM/IlVG1ogKyZcYl8XglPLpvMfFpkdlRojjebqXILKEGl1LNW4SgQN5 EX/w== X-Forwarded-Encrypted: i=1; AJvYcCVMwK4CZou38h8vi0w3cm/KAdjFXrzWt/A1Xhp0cqYQpPN4tE8mJd5NIHGZDJ6TEgI4dRaBFSQnZOOJAVY=@vger.kernel.org X-Gm-Message-State: AOJu0YzZHBVIGBWy/YinL2kM4FjB1kHOfswUlYwUn5O0AC7U3irVbjpT SMA+l0dfrbAcdnTTCwBadngvZyzUzZei99jAebwU079hXrfaKRO9DfeO X-Gm-Gg: AeBDiestCgSzRoMJWUQNhkqL0bJUK0y8ipjSRxle2lZuuNm8I9a+x6oSFuTKnSYTtjp 9tMy++9g6iBRa8OWuT9npgHn0Jr6TXPzz1ePYK8S7sUmTetB7sJbc5z9zKFlLgNddeXVHtMRNDb d8cF0loVeSB8WevcSCa5kUfMhg3Sp+yitJdGYRaj35G5QuuToIuE210FXMMo+73ZftQZEVxav98 OU1Z342gm2hX7nYDjIo4/TYfVoR6ssjhvkuJfTTjnpD+Jd+9yotj8h7dwSNf9yfxZ9b2w/MAjKi BFXvF84ZxpwLdL6waWA8sMrkq1Yan0GATviYJNx2lD6eXpk26mf3kLmXxqJWuE2hqLm6JGeEwb0 s8xIIVUJR/6umIvOk2CJrhFuyp7OBrSElPA3B3OcL1VsdY6Cy+n0rMrap1geA3jZRBxsM7klILM 7GcGKXTvwLAvPsK7dy0OkFJ5ejWYQUi9j5AT3+676TgUwPizz6kbK1Jtxkpeig3Yzs X-Received: by 2002:a05:7300:5725:b0:2c5:60d0:703b with SMTP id 5a478bee46e88-2cbfa5be05emr2998884eec.14.1775280819603; Fri, 03 Apr 2026 22:33:39 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:2357:9278:e4dd:85f2]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca792f3f54sm6808763eec.7.2026.04.03.22.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2026 22:33:37 -0700 (PDT) Date: Fri, 3 Apr 2026 22:33:33 -0700 From: Dmitry Torokhov To: Sanjay Govind Cc: Vicki Pfau , Nilton Perim Neto , Mario Limonciello , "Pierre-Loup A. Griffais" , Antheas Kapenekakis , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xpad: Overhaul device data for wireless devices Message-ID: References: <20260314075034.1488655-2-sanjay.govind9@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260314075034.1488655-2-sanjay.govind9@gmail.com> Hi Sanjay, On Sat, Mar 14, 2026 at 08:50:32PM +1300, Sanjay Govind wrote: > 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 > --- > drivers/input/joystick/xpad.c | 138 +++++++++++++++++++++++++++++++++- > 1 file changed, 135 insertions(+), 3 deletions(-) > > diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c > index bf4accf3f581..2490eb21a534 100644 > --- a/drivers/input/joystick/xpad.c > +++ b/drivers/input/joystick/xpad.c > @@ -94,6 +94,22 @@ > #define XTYPE_XBOXONE 3 > #define XTYPE_UNKNOWN 4 > > +#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 this many > * seconds > */ > @@ -795,6 +811,9 @@ 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; > const char *name; /* name of the device */ > struct work_struct work; /* init/remove device from callback */ > time64_t mode_btn_down_ts; > @@ -807,6 +826,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); > + > > /* > * xpad_process_packet > @@ -1026,12 +1047,46 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha > if (data[0] & 0x08) { > present = (data[1] & 0x80) != 0; > > - if (xpad->pad_present != present) { > + /* delay prescence until after we get the link report */ s/prescence/presence But I would say "Only handle no longer being present here. When a controller appears mark it as present only after receiving link report". > + if (!present && xpad->pad_present) { > xpad->pad_present = present; > schedule_work(&xpad->work); > } > } > > + /* Link report */ > + if (data[0] == 0x00 && data[1] == 0x0F) { > + xpad->sub_type = data[25] & 0x7f; > + > + /* Decode vendor id from link report */ > + xpad->wireless_vid = ((data[0x16] & 0xf) | data[0x18] << 4) << 8 | data[0x17]; > + > + if ((data[25] & 0x80) != 0) > + xpad->flags |= FLAG_FORCE_FEEDBACK; > + > + if (!xpad->pad_present) { > + xpad->pad_present = true; > + schedule_work(&xpad->work); > + } > + xpad_inquiry_pad_capabilities(xpad); > + } > + > + /* Capabilities report */ > + if (data[0] == 0x00 && data[1] == 0x05 && data[5] == 0x12) { > + xpad->flags |= data[20]; > + /* > + * A bunch of vendors started putting vids and pids > + * into capabilities data because they can't be > + * retrieved by xinput easliy. easily. > + * Not all of them do though, so check the vids match > + * before extracting that info. > + */ > + if (((data[11] << 8) | data[10]) == xpad->wireless_vid) { get_unaaligned_le16() > + xpad->dev->id.product = (data[13] << 8) | data[12]; get_unaligned_le16() > + xpad->dev->id.version = (data[15] << 8) | data[14]; get_unaligned_le16() However you should not change product and version once input device is registered. So you should delay not until after link packet is received, but until after capabilities packet. You might need an enum instead of bool for controller state. > + } > + } > + > /* Valid pad data */ > if (data[1] != 0x1) > return; > @@ -1495,6 +1550,31 @@ static int xpad_inquiry_pad_presence(struct usb_xpad *xpad) > return xpad_try_sending_next_out_packet(xpad); > } > > +static int xpad_inquiry_pad_capabilities(struct usb_xpad *xpad) > +{ > + struct xpad_output_packet *packet = > + &xpad->out_packets[XPAD_OUT_CMD_IDX]; > + > + guard(spinlock_irqsave)(&xpad->odata_lock); > + > + packet->data[0] = 0x00; > + packet->data[1] = 0x00; > + packet->data[2] = 0x02; > + packet->data[3] = 0x80; > + packet->data[4] = 0x00; > + packet->data[5] = 0x00; > + packet->data[6] = 0x00; > + packet->data[7] = 0x00; > + packet->data[8] = 0x00; > + packet->data[9] = 0x00; > + packet->data[10] = 0x00; > + packet->data[11] = 0x00; > + packet->len = 12; > + packet->pending = true; > + > + return xpad_try_sending_next_out_packet(xpad); > +} > + > static int xpad_start_xbox_one(struct usb_xpad *xpad) > { > int error; > @@ -1965,8 +2045,60 @@ static int xpad_init_input(struct usb_xpad *xpad) > usb_to_input_id(xpad->udev, &input_dev->id); > > if (xpad->xtype == XTYPE_XBOX360W) { > - /* x360w controllers and the receiver have different ids */ > - input_dev->id.product = 0x02a1; > + /* > + * x360w controllers on windows put the subtype into the product > + * for wheels and gamepads, but it makes sense to do it for all > + * subtypes > + */ > + input_dev->id.product = 0x02a0 + xpad->sub_type; Another option is to use version field... > + /* If the Link report has provided a vid, it won't be set to 1 */ > + if (xpad->wireless_vid != 1) > + input_dev->id.vendor = xpad->wireless_vid; > + switch (xpad->sub_type) { > + case SUBTYPE_GAMEPAD: > + input_dev->name = "Xbox 360 Wireless Controller"; > + break; > + case SUBTYPE_WHEEL: > + input_dev->name = "Xbox 360 Wireless Wheel"; > + break; > + case SUBTYPE_ARCADE_STICK: > + input_dev->name = "Xbox 360 Wireless Arcade Stick"; > + break; > + case SUBTYPE_FLIGHT_SICK: > + input_dev->name = "Xbox 360 Wireless Flight Stick"; > + break; > + case SUBTYPE_DANCE_PAD: > + input_dev->name = "Xbox 360 Wireless Dance Pad"; > + break; > + case SUBTYPE_GUITAR: > + input_dev->name = "Xbox 360 Wireless Guitar"; > + break; > + case SUBTYPE_GUITAR_ALTERNATE: > + input_dev->name = "Xbox 360 Wireless Alternate Guitar"; > + break; > + case SUBTYPE_GUITAR_BASS: > + input_dev->name = "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 = "Xbox 360 Wireless Guitar Hero Drum Kit"; > + else > + input_dev->name = "Xbox 360 Wireless Rock Band Drum Kit"; > + break; > + case SUBTYPE_RB_KEYBOARD: > + input_dev->name = "Xbox 360 Wireless Rock Band Keyboard"; > + break; > + case SUBTYPE_ARCADE_PAD: > + input_dev->name = "Xbox 360 Wireless Arcade Pad"; > + break; > + case SUBTYPE_TURNTABLE: > + input_dev->name = "Xbox 360 Wireless DJ Hero Turntable"; > + break; > + case SUBTYPE_PRO_GUITAR: > + input_dev->name = "Xbox 360 Wireless Rock Band Pro Guitar"; > + break; > + } Maybe have an array of [type] = "Name" instead of this switch? Thanks. -- Dmitry