From patchwork Wed Feb 7 16:36:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Staudt X-Patchwork-Id: 197982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2354750dyb; Wed, 7 Feb 2024 08:38:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEObvhR2q4mU2LN9pIOCaChFkwcjsmyE1BnKJdmaVKynkJX2j3bvuQt7/sCaWi1ryTjyE0q X-Received: by 2002:ac8:5745:0:b0:42b:ebf7:d207 with SMTP id 5-20020ac85745000000b0042bebf7d207mr12302123qtx.29.1707323929686; Wed, 07 Feb 2024 08:38:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707323929; cv=pass; d=google.com; s=arc-20160816; b=lIMSe8UYRgfSaaNMXaPnpwEXVvuIGS8RKznDFwRwCurxcdFt2alsn2HyqPGIQqaa9r OXxxndTe0TTdskVcjHGBHad39a3Yd0XuOGeikE+IwxntvpZOfezw1mcItBbvgUcOJDkw 7bU56lU0WM4H3cd4ZW5T/UlURvZFcZlZLOyE28Ax/tJTnIAMg6GbcTWnmprYcwnd9YhR pHL4RGcK9NuvzpWrsiDZEJk2byykUpFddtsW5qiFJrXmDSjc8oxZ6adMDORKvp3FK2Bo cR94Vqawy05Xan8c/hWBNSnm5+9irBbWb9xNOl3YDkRyxUQKt8EoolvwcqKgPNK4csgt 6S2w== 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=DYcxHMp8TVrNLZx0/+JngQEllD7xCCB/A6RdEAC4xcA=; fh=PNvzbpw3oMXduP9ctf9aNQ0ZOdjOZK0YPmZc9NkB9Mg=; b=xmSgs1BI0+oGQKBe0etzkqAI1UPG9cY6G57N87iuL2neBbhucVDWib0V6QL+FBr2iX 1l1vv2JAsKma6Hq6+yoN6dxCdksGMUL0ri+sB4XALkjPx2AX5mEDqRqMoDNideHGJm6G KX1FKxT2yVRfqWx2kZ8Bj/ibKP06LXvgR0SlLfRyES3H6rcXBBDcbVDs3B4pKwqINGFz 5CceU7OCtG8qYlKVOLrNlr38v5xq4CNHz+EvsaP1Vbqo8iiezD0AaS9+J4yofjIHBRK0 6/r8QDbC4ZP+qX5gN/1e7FYb01lqTg20fP/GxKRJF+qYmadeLZfm443H0uy22YyRWvjp InWw==; 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-56779-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56779-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUoKgMsSszs8/CjmMlzR19GOLF0WkZpfqhjUHaTNnVHVTurgZdynWxWqrNfDG6hnyjwMd4SLtlx3u9Xr9Ly6M4J2P7NGQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e9-20020ac85989000000b0042c3a23133fsi1420081qte.572.2024.02.07.08.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:38:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56779-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=enpas.org); spf=pass (google.com: domain of linux-kernel+bounces-56779-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56779-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 793D91C212F8 for ; Wed, 7 Feb 2024 16:38:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17E9E82D9E; Wed, 7 Feb 2024 16:37:44 +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 D3B1881AD4; Wed, 7 Feb 2024 16:37:40 +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=1707323862; cv=none; b=lsgA6ji51vbOQ41K0RLVnTFCnC/MCqQGnlCdPhUCcghMof2nTpPgUBgCfYHfl7tgwptbagEfEXjJKj7L0HizGySCxVVrJdC2Jmrr6Cj+k3SyVwhFM34uL70IprlkPYe5lbQUY0jcd+Zo6EN+NPbZDY/IAVm0nrOR6A0LnNEMQHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707323862; c=relaxed/simple; bh=6ibKIqdKNK6p4jvhKmJBITPzh/ZNI0jwLkDjKmkAYQ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JD718r7I+pwTZ1I6RaIEJZnoSzRwRDFGKCvR5OXDBBq+7kG4f34zACfNRGYvLTy3Xwy6FriKxN0ME+MGF3rHZ91gkP5HDTcJqfOYkWt8FF0hsYw8FXHBSWRgDBt1Ia+BWczYXclB0gD+ijmtCzWfPksvF2e1AbB55yY6lOzedhY= 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 EC8F2100BC6; Wed, 7 Feb 2024 16:37:36 +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 4/5] HID: playstation: DS4: Parse minimal report 0x01 Date: Thu, 8 Feb 2024 01:36:46 +0900 Message-Id: <20240207163647.15792-5-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: 1790258897045938231 X-GMAIL-MSGID: 1790258897045938231 Some third-party controllers never switch to the full 0x11 report. They keep sending the short 0x01 report, so let's parse that instead. Signed-off-by: Max Staudt --- drivers/hid/hid-playstation.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 53bfc2828a61..6b0f25688657 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -287,6 +287,8 @@ struct dualsense_output_report { #define DS4_INPUT_REPORT_USB 0x01 #define DS4_INPUT_REPORT_USB_SIZE 64 +#define DS4_INPUT_REPORT_BT_MINIMAL 0x01 +#define DS4_INPUT_REPORT_BT_MINIMAL_SIZE 10 #define DS4_INPUT_REPORT_BT 0x11 #define DS4_INPUT_REPORT_BT_SIZE 78 #define DS4_OUTPUT_REPORT_USB 0x05 @@ -2196,6 +2198,7 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report * int battery_status, i, j; uint16_t sensor_timestamp; unsigned long flags; + bool is_minimal = false; /* * DualShock4 in USB uses the full HID report for reportID 1, but @@ -2223,6 +2226,18 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report * ds4_report = &bt->common; num_touch_reports = bt->num_touch_reports; touch_reports = bt->touch_reports; + } else if (hdev->bus == BUS_BLUETOOTH && + report->id == DS4_INPUT_REPORT_BT_MINIMAL && + size == DS4_INPUT_REPORT_BT_MINIMAL_SIZE) { + /* Some third-party pads never switch to the full 0x11 report. + * The short 0x01 report is 10 bytes long: + * u8 report_id == 0x01 + * u8 first_bytes_of_full_report[9] + * So let's reuse the full report parser, and stop it after + * parsing the buttons. + */ + ds4_report = (struct dualshock4_input_report_common *)&data[1]; + is_minimal = true; } else { hid_err(hdev, "Unhandled reportID=%d\n", report->id); return -1; @@ -2256,6 +2271,9 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report * input_report_key(ds4->gamepad, BTN_MODE, ds4_report->buttons[2] & DS_BUTTONS2_PS_HOME); input_sync(ds4->gamepad); + if (is_minimal) + return 0; + /* Parse and calibrate gyroscope data. */ for (i = 0; i < ARRAY_SIZE(ds4_report->gyro); i++) { int raw_data = (short)le16_to_cpu(ds4_report->gyro[i]);