From patchwork Wed Feb 7 16:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Staudt X-Patchwork-Id: 197983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2356268dyb; Wed, 7 Feb 2024 08:41:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHskcEeV4Tvgr/M/7B8W4BtcJjueGgZ6l2DSb+YtZM+ANuALBiOgMXXzDIKWdwRCalfKc9 X-Received: by 2002:a17:903:228b:b0:1d9:f313:60a2 with SMTP id b11-20020a170903228b00b001d9f31360a2mr1904242plh.38.1707324082491; Wed, 07 Feb 2024 08:41:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707324082; cv=pass; d=google.com; s=arc-20160816; b=qF3a7LgZCy0UB0BZuPPcJj4aXhxFp96Yq6wsmkeaLprbZiSZQrMym0ei2bKFWaFrTR LpQlp4ZPOrb4yedqpRf5T6aL0a6Pj6lJxHXZOSk1c4VZfM59MtCy66qwtv/fFWBDlsXa 2g5O0rd2aUCPS3gQGzDtO0gy0K+w9dXhxhQVmIOIAm3oBCA1OFLm7okkT5LLM+ECbBAj WdvzkGZrcIWB4GJMFJI8hoGDvcKBVDS2jSESivAAKkLv891iwjnSZftb2WFuJdl2i3+V iEnMYNnPKAbsf85Z69LyYyelsPUhNxEiZ6DagnZ951ft83wmb0T2nnnXwK745Bm8AwMO Jalw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Bx9vOdRmfjlnuTOwtrMELPnt4tiBPeQAgv5einhly1o=; fh=zxWovfB/STfZ6PsjXtdCUZCHY231sk8S+/fxB+TrASA=; b=ytYazUIHs5EEW+/+8fVw+GWXhOd7yWTYf01WsjgE6TCpD1HbzLW/jstTuEXKHEDDQd wSHxHgdZYavYW6uj1Ph3FXKzpXfcnn/9MsNncBgxG1PMHfAFBj2UxLulQiUckeOINu8h ne5+Ok3CmCNI0wjtpjp1PQyynb3c84LjRGYDJQ4VvSWPxeKUoqFfkB2U1bNEMwQ7wqP/ 8JK8C2RzQ0kKgHzD7KYQwsb7qLd30hXCBV4QjMqyP1jowOM4WzHsJvE6o2yNN8QfSJmX Rs6yCRAWPk5WM7p2hygtLNn1nkPp9x5u1p5UaTPvJ1C3KKYEfk/5OxuBXLvSa/1621AO M0gA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=enpas.org); spf=pass (google.com: domain of linux-kernel+bounces-56781-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56781-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUXKqJYVBPJPLdvC89cQpLDF9ZM1CP+7QUp/P2eRrA/OiV+OWSsCy9ovrTfuSVcFyMDvuWyhVy7z7dqi3Vcg8lIhhYLvA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n5-20020a170902e54500b001d51f6f28cesi2110658plf.142.2024.02.07.08.41.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:41:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56781-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=enpas.org); spf=pass (google.com: domain of linux-kernel+bounces-56781-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56781-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D358F288BE2 for ; Wed, 7 Feb 2024 16:39:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4860683CCD; Wed, 7 Feb 2024 16:37:46 +0000 (UTC) Received: from mail.enpas.org (zhong.enpas.org [46.38.239.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42AD982D6C; Wed, 7 Feb 2024 16:37:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.38.239.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707323864; cv=none; b=rB+YTvR+82XREK8CPXpm1N9RRJ580uKL6YIEkb998tMcl0A1l88LCqeS29SP+xEw4QIG7Mjkzj7CUF++BmK4vA8AWVlra4R9V/LpVkMLmbQwEZAYxS0of5FlZDO/asKHw4gFK+PtOtmZP9H6KIbWKYypcHT6hZzXwIXBrKq+Xc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707323864; c=relaxed/simple; bh=ht0PP+NQoSopSGNlDo9KrMKWZ0EUv1IshXzKGdpnxi0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pt7Ti4GW2G5xD7fGJ34i3jPIswU9581RQEI2QhiJaGFCCN9skFDiiZOUsDhG7TgdhekBiIARr9741D3Vi9fYRr8hkXotjUem69cZQZ5ed8YZ3lZ+Z824hOe8mNvCFLJ8rehj9H2IJAWrOi5AO1RENBGM0fE0ZuQqjdfDx3l45UM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=enpas.org; spf=pass smtp.mailfrom=enpas.org; arc=none smtp.client-ip=46.38.239.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=enpas.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=enpas.org Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail.enpas.org (Postfix) with ESMTPSA id 84677100072; Wed, 7 Feb 2024 16:37:39 +0000 (UTC) From: Max Staudt To: Roderick Colenbrander , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, max@enpas.org Subject: [PATCH v2 5/5] HID: playstation: Simplify device type ID Date: Thu, 8 Feb 2024 01:36:47 +0900 Message-Id: <20240207163647.15792-6-max@enpas.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240207163647.15792-1-max@enpas.org> References: <20240207163647.15792-1-max@enpas.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790259057048344967 X-GMAIL-MSGID: 1790259057048344967 Distinguish PS4/PS5 type controllers using .driver_data in MODULE_DEVICE_TABLE rather than by VID/PID. This allows adding compatible controllers with different VID/PID. Signed-off-by: Max Staudt --- drivers/hid/hid-playstation.c | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 6b0f25688657..edc46fc02e9a 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -27,6 +27,11 @@ static DEFINE_IDA(ps_player_id_allocator); #define HID_PLAYSTATION_VERSION_PATCH 0x8000 +enum PS_TYPE { + PS_TYPE_PS4_DUALSHOCK4, + PS_TYPE_PS5_DUALSENSE, +}; + /* Base class for playstation devices. */ struct ps_device { struct list_head list; @@ -2687,17 +2692,14 @@ static int ps_probe(struct hid_device *hdev, const struct hid_device_id *id) goto err_stop; } - if (hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER || - hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER_2 || - hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) { + if (id->driver_data == PS_TYPE_PS4_DUALSHOCK4) { dev = dualshock4_create(hdev); if (IS_ERR(dev)) { hid_err(hdev, "Failed to create dualshock4.\n"); ret = PTR_ERR(dev); goto err_close; } - } else if (hdev->product == USB_DEVICE_ID_SONY_PS5_CONTROLLER || - hdev->product == USB_DEVICE_ID_SONY_PS5_CONTROLLER_2) { + } else if (id->driver_data == PS_TYPE_PS5_DUALSENSE) { dev = dualsense_create(hdev); if (IS_ERR(dev)) { hid_err(hdev, "Failed to create dualsense.\n"); @@ -2731,16 +2733,26 @@ static void ps_remove(struct hid_device *hdev) static const struct hid_device_id ps_devices[] = { /* Sony DualShock 4 controllers for PS4 */ - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), + .driver_data = PS_TYPE_PS4_DUALSHOCK4 }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), + .driver_data = PS_TYPE_PS4_DUALSHOCK4 }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2), + .driver_data = PS_TYPE_PS4_DUALSHOCK4 }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2), + .driver_data = PS_TYPE_PS4_DUALSHOCK4 }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE), + .driver_data = PS_TYPE_PS4_DUALSHOCK4 }, + /* Sony DualSense controllers for PS5 */ - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER), + .driver_data = PS_TYPE_PS5_DUALSENSE }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER), + .driver_data = PS_TYPE_PS5_DUALSENSE }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2), + .driver_data = PS_TYPE_PS5_DUALSENSE }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2), + .driver_data = PS_TYPE_PS5_DUALSENSE }, { } }; MODULE_DEVICE_TABLE(hid, ps_devices);