From patchwork Mon Jan 15 14:45:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Staudt X-Patchwork-Id: 188216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1751635dyc; Mon, 15 Jan 2024 06:55:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEba/84NQQ7Pz0MZnmLDq85LrBGiPklD5q6gq55yFTvKIshczmYs8Aq6l4JKeEIYkSKzO3o X-Received: by 2002:a05:6a00:3d44:b0:6da:63a5:3f32 with SMTP id lp4-20020a056a003d4400b006da63a53f32mr3313483pfb.66.1705330539641; Mon, 15 Jan 2024 06:55:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330539; cv=none; d=google.com; s=arc-20160816; b=MxKzYX7TkZ/kVh0KtYGUq7fbaGYy10ZAwchJzk08p+wuXtVhA5vhtvqpx1ESMO/vTU 1lrW/I13OVx+Spe9M+k4A1o3AMN1YvaoSXiJA8DYJFMhyV2TzEzBYKko8vimsMIqb4bM n7ft8PyFYYXQO9yaPWwTB6qUNbQJNlWBEn62EBwF/wgfXlHE/BjvoJbuloYHRLYXjFMU RFacj7yA1YtfstWdrZUAookZOjF6igqUW7sk9FNJCRIVfMRAfb8aL9WmjU1x0eeWDj+y x28zbKIXNWTWiWClUNJUZj/pcyPXEWMxL2YbkBTG80Yeg1aPUKJM7n3Ir7P3/vFsgfzq GFIA== ARC-Message-Signature: i=1; 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=2fNoNO7qQPplzoaYS5Jc51nKUXMYB6w4HZ1sYBKQ6cU=; fh=3M1PHg4byxu2MygWip944LqLZSq0Urk5Qa4iYXrexb8=; b=K1+0G+KaPzKSbSTOE0jGrew90pkczXVeeopGuRROTTkcfKMXFo39xqeWUQs1yonaAE BwvesB9WvSZ2n2KDTUqhLQROhLJBCUdM4MyIDSk9Dm/+wSCUkWvkJ4SZpfA/tuVoYK5n eb9DyGh2kxiHjdv46VJOsO5XOLARl3kX2isGBJ7qrwqGaqx6ZdE4i5TZc8Tka5yAioHK tx7ZO38xZSwkmZ6zpxYPRw4neOmvCura/bMkidik+FmadaO6nodljSXCU1LNhqTXeMoY PKAqeBrN9TqS9NKHrl35CJNKd6YeoBEgNHL+n9u97vb+rG3AaWRUDsE7sNrXKfx9iywH eYMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26140-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26140-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d22-20020a63f256000000b005ca4098bf66si8884033pgk.637.2024.01.15.06.55.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:55:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26140-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26140-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26140-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7BA4CB21EFE for ; Mon, 15 Jan 2024 14:52:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEE8818E2F; Mon, 15 Jan 2024 14:49:01 +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 1634D17BB2; Mon, 15 Jan 2024 14:48:58 +0000 (UTC) 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 17DA8101651; Mon, 15 Jan 2024 14:48:54 +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 v1 5/7] HID: playstation: DS4: Parse minimal report 0x01 Date: Mon, 15 Jan 2024 23:45:36 +0900 Message-Id: <20240115144538.12018-6-max@enpas.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240115144538.12018-1-max@enpas.org> References: <20240115144538.12018-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: 1788168676119148124 X-GMAIL-MSGID: 1788168676119148124 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 2bf44bd3cc8a..086b0768fa51 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 @@ -2198,6 +2200,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 @@ -2225,6 +2228,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; @@ -2258,6 +2273,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) + goto finish_minimal; + /* 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]); @@ -2365,6 +2383,7 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report * ps_dev->battery_status = battery_status; spin_unlock_irqrestore(&ps_dev->lock, flags); +finish_minimal: return 0; }