From patchwork Sun Jan 19 13:12:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944446 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 D06C51C3BE7; Sun, 19 Jan 2025 13:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292445; cv=none; b=N5rd0L/uUaAEICwpBfsRnuATvqhWkpmFclmSbwHpGAQ4/vqCWq8knUQ1Fzq1y9EbN0jgemrR+HkeqB45NkbtCOUSGucMS+iTLOKODBENfyhzcyiXy4a6MCmAtNxlgdI+CAVmwUJfgLJqv+UgvKvtGx/ghWQXBXr2fl16y+LTdlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292445; c=relaxed/simple; bh=Dd8c/Dwq0fW1g9FPnwxGp41GFWRhEdc/TuF9ZVt+ZAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z+O8mIj8AwN2MPH/mxF2dInyzGLXEVJk6YvNbOUhl0MlwJVo39jOjFCZOD2fXRB8BkTXx4kkLKw5N9mfK8eTjvVY4WSywf1Ebe8rZD+o/DjRj+VMHMkyHRMymetArFHrngTajSM4a6psoO1zZD0kUV41BS3HlHOJvTXJau7hRrU= 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=IWCYSHdo; arc=none smtp.client-ip=209.85.208.54 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="IWCYSHdo" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d3da226a2aso649837a12.0; Sun, 19 Jan 2025 05:14:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292442; x=1737897242; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wx/v/RBt7IbO+aABg3VmqdraDDzoSLZZYAQhG1MP8wA=; b=IWCYSHdoKkitJ5me9JZexFi8lIweCq4LS4IzbVJOND7bLzZWJPswwBf6b2qwnDz1mp VUaNZzbVF7XBUWYm6f/GmGd9HEXx9BHC4jeB79QEeIhHpjmfEaKoTedw/78CM7DoObm/ nfreljq75jcOudv2hgGUVtX/8+QNsc6aqrosRdOVnjK1IdvMRvArfXcmrAaGBuKO5/jX YosloBNvQUBGdQRDlvw5QZdUMXljLG/ooPgC99vCACdXgpKSLf8DA5g6TTA+c+RjOJjR 60i8VpZrVE1jHKMwDnwZeZBogBSDUj/YgwqsLDwlVjX9Se3/roR0T/lIZKiQYyVU0D4w Y0zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292442; x=1737897242; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wx/v/RBt7IbO+aABg3VmqdraDDzoSLZZYAQhG1MP8wA=; b=JJVAGVvtyI6mzBrXGlrHIwMrQVNBer3JfrblsMEbGswIF0uoBnhvOHBS3rrhsxuyVW WymgGQxWSw5hPlzTIMFfOb4wEm2cyDheTiS0sXfRWledEbw56HIgKWo8Nz/Z7z0zhO22 gQJWyvF5Scy1wP/qRXySZpi7EQBVTbBSeu0eZ39Ezh2MYAQfnGMwk88JzUKEbLn7TWKx qa2/BXO5zOvWtbllBSIkxty/fumOEtoZ6g5bkSLX7lAZ12SEUYQ8b/Z/mLWB09m5aUNA y+4qDvYW8qzXX5uha7YALzm0dUfjSgEFyKz37RRL+iFBwyGq2W/c57sIqfe/u6ZgkI79 2bPg== X-Forwarded-Encrypted: i=1; AJvYcCW9inHacwgFuzJLpEDeRKQgq5WdqTP5BHUPE1Wmw6/3Ta3w6oqYbq/SRvnLgNcsvXbl/YP4rZ/Y4A3k9w==@vger.kernel.org, AJvYcCWIIR+c53xt2GMe2fsHAht0sep5xuRjaWZcNCvPcgqvJvepXXGdoIN/s1XDpjkW1LwrVDXO/iQWnP4E@vger.kernel.org X-Gm-Message-State: AOJu0YxWqdKrWSUa/NzufsQJ8ES+GQJ/xSzJfOwkLzeWKrL+P5ypgKdv FBv57L1d/UDlxBTUCN69d7AjH3rozg7/FNqD4+n20A7KQ218NSqyaJNKPypT X-Gm-Gg: ASbGncuWHQQRWsJgH1ezTj8cCuC4j4GoWvla6J/yGBYrqYca4Vz0J8lvmPG46nsNAa6 Ll2QgFR+nvKor1fVlfggaYrKvQ8DCpNNvmO+RzKxw1LCtXCmMhwteZEp1LQJjga0YENoq1Z1Lmn 0ODo9tEMARRB1KS4HQZpGtYI9eV8hiOPMtAZ9QIJuiYv9srQcAp+8rqHnSwZqLlE8z1WRu+ShT7 402+vpRbtGXBpXtg7U7uxMnc831PnxI4XKgAYxahIDBT7Ll7KMJEHZUqGrjwLqYGmeS2ZlfckDs sEmpugui9IA4pYKbkA+8807nX1ydhv4gQ+XpZTRd X-Google-Smtp-Source: AGHT+IHOUcTy3/IAgVSjy24oKmLcXmNqD+fSkwV7sBQqMR6eXVC+JvLwyOSiJpbKXXIZAY4ftc3rqw== X-Received: by 2002:a17:907:d0c:b0:aa6:273c:a616 with SMTP id a640c23a62f3a-ab38b26512emr355415366b.4.1737292441796; Sun, 19 Jan 2025 05:14:01 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:00 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 01/12] HID: pidff: Convert infinite length from Linux API to PID standard Date: Sun, 19 Jan 2025 14:12:52 +0100 Message-ID: <20250119131356.1006582-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux defines 0 length as infinite in its force feedback API while USB PID defines NULL (0xffff). Most PID devices do not expect a 0-length effect and can't interpret it as infinite. This change fixes Force Feedback for most PID compliant devices. As most games depend on updating the values of already playing infinite effects, this is crucial to ensure they will actually work. Previously, users had to rely on third-party software to do this conversion and make their PID devices usable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3b4ee21cd811..3899d72a0b02 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -301,7 +301,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; pidff->set_effect_type->value[0] = pidff->create_new_effect_type->value[0]; - pidff->set_effect[PID_DURATION].value[0] = effect->replay.length; + + // Convert infinite length from Linux API (0) + // to PID standard (NULL) if needed + pidff->set_effect[PID_DURATION].value[0] = + effect->replay.length == 0 ? 0xffff : effect->replay.length; + pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button; pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = effect->trigger.interval; From patchwork Sun Jan 19 13:12:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944447 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 E24CC1DEFD8; Sun, 19 Jan 2025 13:14:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292446; cv=none; b=RkISXgwI5c4f57X65cCTdmcVqcAGd6lCg8U37cCfgb3X/jU9AVP3rTB+xFQR/HqBdVusLkDaGjAw4MJVUhOHBXI+7XjqO2aMpklyNRkvX8CwzBrtxTjBmZQ5AVr78srjXC/SAfTQhTfvbWt93g8BR7BUIf7dLPoFvQwVXWFUwng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292446; c=relaxed/simple; bh=hO16TzVqb5tj1+/tTTtpg/9gXWGHQ75X9yytJHjMq0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H8rxR2DlIfzFSQGeSp1pjguvLm1WIJoO365uN7nFb3bTRn+E0Xo+hNUyldopdCfMvrt/I9X35/m+8NrBlX/GO49AowYwwz3j+Nmy8cUlfY8wlcBih82MILk6Iv2eob1V1KAtPUadRnzAjf6F45ynu/1QoY4PNsNExxoOM5ZeStE= 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=YfhQp+Co; arc=none smtp.client-ip=209.85.208.42 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="YfhQp+Co" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5d44550adb7so639175a12.2; Sun, 19 Jan 2025 05:14:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292443; x=1737897243; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=butHZSIttOBt4Y00NnVVBUDnKFliuYeU3sUg3vrDx2Y=; b=YfhQp+CoishW/eduxkUoskCh4mIWWpJMNyLWhdgIELYypowoPszP8TGRKltUvH6EWG jM/FqmJOic9VRJ8zgmLPQHaPWz1TjpYhTARthJz3nRQhBwriekbVd+wOT8kUhM92XOgy iFl1se/ewayNDGvsDEbBqv1PKAHH8mn/cKC99Hmz7AVvvybB3VzWUQzqQ0+KydEtG/U1 oiY9B0UkskIV6B+X/hxmVr7uiE3G1hqb16UYGpzaEhX96soKMQ5OJmIweTEqQdpNze1M DGApJpzi8FqDdkBhAtA4oMDPwKRhoLdXNgoQq1jNw30ITJJObARZ7fpmlayT181drw74 DYlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292443; x=1737897243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=butHZSIttOBt4Y00NnVVBUDnKFliuYeU3sUg3vrDx2Y=; b=ug/PWcSX7PPyVkrp8YB1CHAFIaZQEyppGnUNn2Wc/AD+17opuW//8dH9HI0chaXILw dliXhPYNLuaalv83+70npW1TbwdsO1priP3XyRP47k5/m7i/Oi6OBCaYZl4+z6qWKKT4 Yk9jsp3Yx0R5/O68lDjnLcVyk0mPIpxKpXUo1/mxKy706xNZrnO8nfHiSueU1l9HWTE1 qs3YObZSI2yRCs3lw5rSRrauUATF7qcYJg/4FFANMXYP+K6Oigo9oF5Xw40+sz6YI6xR FAG31O+7QJeF35ROqKzMaL7xvZ8GosYLxEovOaHwDSHgGOmJzMBbe1NKAy/kKE+ArwP2 ywWQ== X-Forwarded-Encrypted: i=1; AJvYcCVD+YrbBegcS8+xAbGf7zBOFGMzAQIddFr62bv94h5SDiA2k2nh5ic8IZfJPHJ3EJ3MHy7vJEcgN+IuUg==@vger.kernel.org, AJvYcCW3rkQXIRjs2Li01RkWwxcbge02Eon3SSzLTPBeYxixc84SysfmVvyK30Ond6YAR5RcmkMhxhcPpP+2@vger.kernel.org X-Gm-Message-State: AOJu0YwUfKhVSedIeiVyXOkV56UFDNU5QMBrH6BLQf0hZBBJV1q4uVcG dJj+2DOo7QaLGwyzytI5zvfKGzjWG8HGqhjcw5piry7jYCdjAO8dN1p9mTwf X-Gm-Gg: ASbGncsiL60xyzIT77jEw31owpQ3oYVF0AH0+4cNz6bKFRQf+jb6WVercdCVp0OmsOo LyhTRebtvD+tg0bBVq7BCSKCqLLR0kXnL/W2H4KvgEXES2cAKuA4tM3UCzPNiZBtDVEnSg9tmee maxIc0IDO3Y/MoKbU2cAcH8+m+JEZgum87SPKfUtkPHvskbchxT7doQ+Sx0s8boV9CrCX4Qb7N5 aumLAObBnEhNCwPcXunu3eF7Q/zr6bEz+q0yM3RQonCuIGCkXn1jenIxPrXUKqKhOagUmV7ghEv ZXQbVwVLjZFkEv4KxHfs7TUHCwzJeUulKrhFRpIwtom6QNnvroA= X-Google-Smtp-Source: AGHT+IHyHuNLm+9inx8nLXegf7u8+9dWpDarccmSVIWb+SP+2Bq7u5fCOKWXoy6FiEcUzRR4E0cTfw== X-Received: by 2002:a17:907:7f8d:b0:aa6:9c29:86d1 with SMTP id a640c23a62f3a-ab38b0b962fmr249568166b.3.1737292442923; Sun, 19 Jan 2025 05:14:02 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:02 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 02/12] HID: pidff: Do not send effect envelope if it's empty Date: Sun, 19 Jan 2025 14:12:53 +0100 Message-ID: <20250119131356.1006582-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Envelope struct is always initialized, but the envelope itself is optional as described in USB PID Device class definition 1.0. 5.1.1.1 Type Specific Block Offsets ... 4) Effects that do not use Condition Blocks use 1 Parameter Block and an *optional* Envelope Block. Sending out "empty" envelope breaks force feedback on some devices with games that use SINE effect + offset to emulate constant force effect, as well as generally breaking Constant/Periodic effects. One of the affected brands is Moza Racing. This change prevents the envelope from being sent if it contains all 0 values while keeping the old behavior of only sending it, if it differs from the old one. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3899d72a0b02..cf8163d92ea4 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -261,10 +261,19 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, static int pidff_needs_set_envelope(struct ff_envelope *envelope, struct ff_envelope *old) { - return envelope->attack_level != old->attack_level || - envelope->fade_level != old->fade_level || + bool needs_new_envelope; + needs_new_envelope = envelope->attack_level != 0 || + envelope->fade_level != 0 || + envelope->attack_length != 0 || + envelope->fade_length != 0; + + if (!needs_new_envelope || !old) + return needs_new_envelope; + + return envelope->attack_level != old->attack_level || + envelope->fade_level != old->fade_level || envelope->attack_length != old->attack_length || - envelope->fade_length != old->fade_length; + envelope->fade_length != old->fade_length; } /* @@ -579,11 +588,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_constant(effect, old)) pidff_set_constant_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.constant.envelope, - &old->u.constant.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.constant.envelope); + if (pidff_needs_set_envelope(&effect->u.constant.envelope, + &old->u.constant.envelope)) + pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; case FF_PERIODIC: @@ -618,11 +625,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_periodic(effect, old)) pidff_set_periodic_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.periodic.envelope, - &old->u.periodic.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.periodic.envelope); + if (pidff_needs_set_envelope(&effect->u.periodic.envelope, + &old->u.periodic.envelope)) + pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; case FF_RAMP: @@ -636,11 +641,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_ramp(effect, old)) pidff_set_ramp_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.ramp.envelope, - &old->u.ramp.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.ramp.envelope); + if (pidff_needs_set_envelope(&effect->u.ramp.envelope, + &old->u.ramp.envelope)) + pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; case FF_SPRING: From patchwork Sun Jan 19 13:12:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944448 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 243181DEFF1; Sun, 19 Jan 2025 13:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292447; cv=none; b=GCJT253nsWwqp6bNgsFFhGZlu33JMbh6+XuQWKIft/5FWCm4lHPHKLojd7yNAeZorZ5ItVrgPhourYfq9WlMtohgQBWC65sRrq+HnL1AWMQ0QceKif9YdxY1VQdlYVmhhn71OnPzWHQ4plS2oSMRE49Xs5itvNu4QuY+WPCjo5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292447; c=relaxed/simple; bh=tX0xwiqubMUtVTEE13a3DRP9BEnROsOPIqV3yaPQzR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n9WC+ljavdCSRQi2zDeGJDDvmKxP0YeMzuku78C024ktIvlYOJ0PGi+TxDo3m1OB2SOkfRdSP4b+cP4t+0WG455B75uSvXkovNtIjUW3TAzme7sCCtoXbMtX465To502VD+cfoUJcZV/clDUwE2SgQrDO6B8MkYBdA7YlZE2XXc= 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=XG3aJcHE; arc=none smtp.client-ip=209.85.208.47 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="XG3aJcHE" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d3ce64e7e5so555986a12.0; Sun, 19 Jan 2025 05:14:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292445; x=1737897245; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R4vjqbs4sDqi11WPqww56N1NIcuf8IdhEvhhCCLSYJE=; b=XG3aJcHEJAxk4D5ukA4kbARwNIngvzpMCjdix4kFIg8B55yWGTLnnCANpQxKo80Vfu pPQ+KX95AbI1J9SKsgfShLwWYo3SGx2XcXWPbZZq9KM+Z/2LHwrvYAjccGhJFeaaFZNU Sl6vgJznjr+3wD5OlXIIFH3vwRxU8OXnFLJCtDJzr24H3o9t0FfiNLMyKlonnPxUUMYM SiygY5vHjwrupZMILxgRgEeTNk+aJ0AOX0uqRXJycEfuScBgElI9Z8IxnG7JWktHMXy/ QLoXXfFmoUp1heFdlF6aXeZ/CWoIpUC//mScKB0dsk0dXt/+VEZsYBY4OB1Uev/d8aEN v27A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292445; x=1737897245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R4vjqbs4sDqi11WPqww56N1NIcuf8IdhEvhhCCLSYJE=; b=nxauGJewLJplCfwH1fCtx5uV+cEbMb1H5uMEKB1Wm1MAHNIGuTyPp/2PZnL9Mb3tGx gowTfneir51/lphezB/plFzIE5bscMXDzcdwAV3eirrds7gVieWCQEczS2gkcVWOxjZ/ GKIyRbrPUJ3hnCNq9/1qsl+eGi/X5Gp0hxKUWAjIwEKNdcCrSiJawPtJGiphof/JRqQ0 xoLwUugE+ZX3BpPzxhHXovvPbj+RV3LFm85lef0lb22UKvZvMakBkBiya92SNzn9iRTT VQz0uEWIVCarzVEMx17/hx2J/kQwBxzewLEcgBiCgjXXKNWqKZkxreC1yZyzs2EBPqFT MONQ== X-Forwarded-Encrypted: i=1; AJvYcCVCjDCHC+dusXJx9bqpWjcj7pclwQJPFxMAORCpQxgFPu0uByPzvRs73yNK13yeRt/L8e1eDnLDSC48CA==@vger.kernel.org, AJvYcCVJsG+Mv8kCgbQ2iEidH7tPVqvjJnkFboGarvlmEudVob92xmiIwhZHJKEQ1GqmOn0Qd7zAcajTezDS@vger.kernel.org X-Gm-Message-State: AOJu0Yz70O+QumKWAGsKmcqi5mzDEDNrPljRCnDR4sUyqzTx41Gz9ZHF a7ULxjJ6w4pT3QYssRsy0KBPaYhTMaz3rLq64zFJYzrqdpP9CrbF X-Gm-Gg: ASbGncsb8dxig4pXyS0ssAc1u+P0UupYyVxHRrhnz0dfY9GdL62vZqauo/CO29Jmnxi I2upL6dW2tt2938scyNaO83TipcFnv49kgpUuUHzp/1wT4WHQ0DZfHUBHiolYuQQcxu4YCQc5mp pbi7TmIsi0aTR3AqK4K8EvD8lqIkodz5vNcpfOoRfUifvxS/j/gve88xiAAN4z7xFSJgQv5kfYn hP7SkzasGk0dbW51Qw/UeJev24XirJaMh1+4gMvqXSK564GTJYqQFCjCUrrxlSZQNH2vbrKjntV vxS67XSAKlYEm2FQKCQVX0P9Rw9ezsT1LRwWPHcU X-Google-Smtp-Source: AGHT+IFkf7rxHfLv5+x0gNuq2of2jQjChcIKQ4fV7D6hBjClOYmJeq3kqwY4++XYs7zibxLtx0p02Q== X-Received: by 2002:a17:907:7f0a:b0:aa6:ab00:7b9d with SMTP id a640c23a62f3a-ab38b26f478mr264631466b.4.1737292444349; Sun, 19 Jan 2025 05:14:04 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:03 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 03/12] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Sun, 19 Jan 2025 14:12:54 +0100 Message-ID: <20250119131356.1006582-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This ensures the effect can actually be played on the connected force feedback device. Adds clamping functions used instead of rescaling, as we don't want to change the characteristics of the periodic effects. Fixes edge cases found on Moza Racing and some other hardware where the effects would not play if the period is outside the defined logical range. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index cf8163d92ea4..7af7744e3cf2 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -205,6 +205,36 @@ static int pidff_rescale_signed(int i, struct hid_field *field) field->logical_minimum / -0x8000; } +/* + * Clamp minimum value for the given field + */ +static int pidff_clamp_min(int i, struct hid_field *field) +{ + int ret = i < field->logical_minimum ? field->logical_minimum : i; + pr_debug("clamped min value from %d to %d\n", i, ret); + return ret; +} + +/* + * Clamp maximum value for the given field + */ +static int pidff_clamp_max(int i, struct hid_field *field) +{ + int ret = i > field->logical_maximum ? field->logical_maximum : i; + pr_debug("clamped max value from %d to %d\n", i, ret); + return ret; +} + +/* + * Clamp value for the given field + */ +static int pidff_clamp(int i, struct hid_field *field) +{ + i = pidff_clamp_min(i, field); + i = pidff_clamp_max(i, field); + return i; +} + static void pidff_set(struct pidff_usage *usage, u16 value) { usage->value[0] = pidff_rescale(value, 0xffff, usage->field); @@ -357,7 +387,11 @@ static void pidff_set_periodic_report(struct pidff_device *pidff, pidff_set_signed(&pidff->set_periodic[PID_OFFSET], effect->u.periodic.offset); pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); - pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period; + + // Clamp period to ensure the device can play the effect + pidff->set_periodic[PID_PERIOD].value[0] = + pidff_clamp(effect->u.periodic.period, + pidff->set_periodic[PID_PERIOD].field); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], HID_REQ_SET_REPORT); From patchwork Sun Jan 19 13:12:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944449 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 CEBEB1DEFD8; Sun, 19 Jan 2025 13:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292449; cv=none; b=MuT4E3ltRRIvtX1I0F5i3b+Zs1oUq+E0LGUEkLCxBXX90DHHtsCOUqkpfGqUUwM0KOOlSfNJMDD6sqb1dCqrnrNSmju80OYJ4XSJv5+UuE9lUuBYpeCOyPZbBGBtKAH/jH1c/D7di3VTFScpNoWrNEiRY0m/NBWNoocc6fdWxS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292449; c=relaxed/simple; bh=d7geDuANMQE2cpSBpz5nYXaht95cBAlASu6QKliEqf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SyES5BIqjQDix90KJfN1Pr6Ev5Prix+iGPiYy7smYrfoAvS8QqjDBG2k5ZMJ5dwDzcbPbUHZ4V4BMFvkixX9s3StVXmldaH+k92hxMEHn8QmelocobMrJ91R9a2X/rOeHBXL6i+/1WJaZB2VPOy8nNTmp4WEOus/4+4NUsh2Mhg= 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=nB/0g5F5; arc=none smtp.client-ip=209.85.208.47 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="nB/0g5F5" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d3da226a2aso649844a12.0; Sun, 19 Jan 2025 05:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292446; x=1737897246; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=44UOE+PBo4WycrOHHhjEW68JP7Cxd1EJOMJ/d6eUVsA=; b=nB/0g5F5sU3GuaIfA+JQAcy/Uev1hQfaxFsJAkpNTddLFWc8IQq3J79quLmZ4jNtKU FmD+Hx4oSJ9h3FLGgVjfWcJ8AJHz6DZwaoW6kxaL5RFoXxU03NZ0Ix8Qx7wjQmY6YDsn puGat6kzMOmSYn0H+zF5ZHddwmTXb3yySCqiMtPRenkIJdz0cY7qaA4JZwgc2mWISv/d 8gi2qLUgmWwM7Kup3MKPbkZwAMT+E5URO7qnOED1vL73tyTundgIvI1le78xEyiPFR5O dqsrqi948toNcOfUQSBKF5/4QDCFNU96fDRrvoSRpdDedFfq5ct+s1zsJhc3B0SZqFMP FHxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292446; x=1737897246; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=44UOE+PBo4WycrOHHhjEW68JP7Cxd1EJOMJ/d6eUVsA=; b=FOssjs94z4zMjnMEeeOoeBuXXM8aBcNwGoeznj/vk3WAAc1wS+Mv4yZmojkW8p1KYa BeKt7P8DWaoB8IoKAm8Pw/3JH+CM3ZEl6xZIogd4Hhnat0dDWtZUneOgwNaWv5OH0L8X ytohXEOHNIUJxOwKm8WnAT/30hdZFE/niQ1DvUgxzFicW6I3N3tB5VpNueMq4vR2DTQS 1duyui/noTC1elaK81GaggWAMT2xk13vUZ/HnRUuSD9iHBc6uv3ojoZTrY1FAexx0XYA E0UHl4/ymNzJGaglRnEtBXEem9PRL7x36Q58PA/QcFPXaTNxKTn3gOQGvamfR3CYc+xj ZNMA== X-Forwarded-Encrypted: i=1; AJvYcCUgUX9NAR0Z9bSrVy36SzU3Cvwjth3EIvESdKSjhkrGxHhbFkj8IAllJTZWRD5plx/Lwjr7mo0dh/VD@vger.kernel.org, AJvYcCVh2cWMO67aJxgplgqJtvktQcPvEps8Vm1g7wWIpn8B25SIbHm7iybwxmfG+NMgwCtPXdeWF5O3EgAqVQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yxdfr48SA6EhmkWSe3+5OpAj3HGOw7dmG6opsTuo88A/rlbuWxe +cUphdIPrCRoG/TzGH+Uk46Oh5W3EM6PorTjeVwkvaTwoZmCo0P7K42dXpLF X-Gm-Gg: ASbGncv86vhzKnw+zmODY2ipCFVU+zxEwku02T87COAFk/1QrpstjNdiaHmwPdIM96W 4FZ5iHHZ7W5v3XgxTD5p9o354JkSwzAP6pjQjIRducwVPqMs9gRNLNFvKY8wWYanmkIMBQE+uCD KUv76fUGN33J2vPDQK/dqriAvKR8fYb0Vtwr917/VISwjPULQ3Rn3/QMQltH/amJlZzAfMSoLt8 44eXHrQZY9Uc7xeJhwYXE97lg0RpjmlVSzWqPqo4iXzEEDUAlh2E0mZHt3hN5B06AmKYN/XWJTq IfZ5OJuFz0SgqGxKrAz54mZJrA36GdPCI2s0C7VA X-Google-Smtp-Source: AGHT+IGAq4xErmmp5ifHFlgN565RHTq4aRI8sJpkmtZtzTpW/He8YUiv8WzdCsSR408wdphI+1ycAQ== X-Received: by 2002:a17:907:1c1a:b0:a9a:8216:2f4d with SMTP id a640c23a62f3a-ab38b1d4b80mr309774066b.3.1737292445875; Sun, 19 Jan 2025 05:14:05 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:04 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 04/12] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Sun, 19 Jan 2025 14:12:55 +0100 Message-ID: <20250119131356.1006582-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 33 ++++++++++++++++++++++++++++----- include/linux/hid.h | 3 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 7af7744e3cf2..28f42f30e2b3 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -184,6 +184,8 @@ struct pidff_device { int operation_id[sizeof(pidff_effect_operation_status)]; int pid_id[PID_EFFECTS_MAX]; + + u32 quirks; }; /* @@ -355,7 +357,10 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->effect_direction->value[0] = pidff_rescale(effect->direction, 0xffff, pidff->effect_direction); - pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -778,7 +783,10 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0; pidff_set(&pidff->set_effect[PID_GAIN], magnitude); pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->set_effect[PID_START_DELAY].value[0] = 0; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = 0; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -801,6 +809,7 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { int i, j, k, found; + int return_value = 0; for (k = 0; k < count; k++) { found = 0; @@ -825,12 +834,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, if (found) break; } - if (!found && strict) { + if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) { + pr_debug("Delay field not found, but that's OK\n"); + pr_debug("Setting MISSING_DELAY quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; + } + else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; } } - return 0; + return return_value; } /* @@ -1105,11 +1119,19 @@ static int pidff_find_effects(struct pidff_device *pidff, static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { int envelope_ok = 0; + int status = 0; - if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { + // Save info about the device not having the DELAY ffb field. + status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1); + if (status == -1) { hid_err(pidff->hid, "unknown set_effect report layout\n"); return -ENODEV; } + pidff->quirks |= status; + + if (status & HID_PIDFF_QUIRK_MISSING_DELAY) + hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n"); + PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { @@ -1353,6 +1375,7 @@ int hid_pidff_init(struct hid_device *hid) ff->playback = pidff_playback; hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula \n"); + hid_dbg(dev, "Active quirks mask: %x", pidff->quirks); hid_device_io_stop(hid); diff --git a/include/linux/hid.h b/include/linux/hid.h index d11e9c9a5f15..94ad5a510639 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1227,6 +1227,9 @@ int hid_pidff_init(struct hid_device *hid); #define hid_pidff_init NULL #endif +/* HID PIDFF quirks */ +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) + #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) #define hid_err(hid, fmt, ...) \ From patchwork Sun Jan 19 13:12:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944450 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 24A711DED77; Sun, 19 Jan 2025 13:14:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292450; cv=none; b=AIgHpONICIZsk5gXcKhScy02MoyYoPGm59K3G2KzzFja5kJXz7udUBGeUrFxH0/bsBq+Cbc+/zzSKyQPcnwuw7Q3K2dzIkpFhbbyCkfUi/XZd27FruvhWA5WKJNpeX4WFiFkSIbacuJeCGwGiIMC7vrhUv6qXBg9FNV88FHWVNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292450; c=relaxed/simple; bh=f+YNJKvymOAQY/YbO81rkVu3Eq5JnmaLmGDoKgXnrlk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RlwspAynIr6Zw4E+Va3JYtRA0/UZmdhhk002MqWPppDOM9dONPUPzHW9BFJm4grYBi9UjeAb6s4NsQEgKTzwcM9Q/MTeaBegE66lv+iS/xwvUx+AahuKf97k3GkSmZQIK9taf0FhQIY2Hcdf7q9vikc9FTvCZ3ojcmlVzFsVpfg= 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=M7j16T2L; arc=none smtp.client-ip=209.85.208.47 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="M7j16T2L" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5db67d1bf0bso628025a12.0; Sun, 19 Jan 2025 05:14:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292448; x=1737897248; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UQAq8vRZlQfX30KmqHs7KQdjhtqm3WAvW25rBYVEIic=; b=M7j16T2LMb9W4U5trnbXHFiR9/cVM8TmuXCCGCB8GIhtTqikdm0mVuuNpav9zYJbPM oxdSRgJk92R1PuGjHp/K8TwAeDdz+8bwrHhXoj4M/FUFHNQI5TyFaNK1ER0mgaeojBo2 7btVN38l8dEw2Rk03y7Fr8RDosWu2c97Uai0l8u98t+b69eqZU9uAZdgUKIMXL9VCQ4q 5cFOQFEEh5mJmlrBi5DhngdirzWCfBNF0OL2JLiWwRAvBUObcJJnhMUwuAK1yhbYLkUi EgAODiae2I9dAWjGJSMntGKm1ONYmChwVsH7AOzY0xy7ToILfojy90kkpsupI+AuNkbF bnpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292448; x=1737897248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UQAq8vRZlQfX30KmqHs7KQdjhtqm3WAvW25rBYVEIic=; b=Pp5VM5RDmGhkrDdzgQw1kqYTkdL0+AfIjitzeR3MbVKTuwG4ZhOgK50imGLnJ9bb0d /lU1ohcKGZSRhvvvsckkRgn+ZGXvrBcn0cLgxy+2VNyHWAFnVYylK+pxGCZq2ej0u9a1 jwfbpPebi3y0THAYVnuX/PmUUBFzzkGIL6hzxVfHlT7xt7HcunZL2avvTWE2PE8I9KNF HSrng8K8WW4rznkX6S5GJ8wMSlhc397nFwy5HYhnfAxqRF5dUmQKINqto/tNTSRgvSiO Hy19UHhtBgHoKUiU0IpWucFwSFfUMYrMPmRbMwNQ1lE2m/9Hrt5MWyGSP2YvpsfNkDOg 5QGQ== X-Forwarded-Encrypted: i=1; AJvYcCUmycgrxX5EfLwIpbQvrtfIpsJLYaXUgaf5NRMS9CMasvw2mqP82uYHhxJEnZng9mZhR1sIn8G9/e98@vger.kernel.org, AJvYcCVlrEc3rLGDxdQMl7DyXetk3V4nh5dmgXuYTHN0Sx4noplpZJS3/tajE/KNWOHzW8qisK4/nsOONYtI7w==@vger.kernel.org X-Gm-Message-State: AOJu0YxiJ2VBdnzzwamJm77yU7jF83kL0sRMJB2cpUg35pnW7ZW1x7j2 M/rE2H19L9rspVx9ZSIFvGD4UZZt0wD2AthNSkJ6WLGw6wb1PshZQwCJcy/A X-Gm-Gg: ASbGncs5H0H0Ld9EsMVMkQBrLTHYAXyjbFLsAjCFhhw8qpc09M+uKRXquieUX61ZugN NK5lEIweDWNTm5C46VpKlp/CHKTEdsQ+IFbYNYy8X7kg+mk77SYZgBQhrax5tWuUBu9+rQNNt+c U0b8uQXh9VJoMwcmtJ7X0IjrcrAbfLY7V/5I4f5eEPCsHhRxignxZEFylhtrSO6tmfIpDBkGnNP C9zK8JUe/tFcv7V2RRMjw2JJoftdPZHWFqk1vxC8BFykiOzjn65EXbrDj1sTkMW8hK99u94RZrK Tlb0hjbRg1D3oPIxEC0TMZUux1Vb4yz2NRx2xt4c X-Google-Smtp-Source: AGHT+IEL7FjufhVzApXcJ8MDy5tKrNjRIoTh5zU/VOQ0ARdnJz6S+vnl0XOCFv/jI1r/LCC8EO1Dnw== X-Received: by 2002:a17:907:3f29:b0:ab3:7812:b3c2 with SMTP id a640c23a62f3a-ab38b1b471emr353429066b.2.1737292447346; Sun, 19 Jan 2025 05:14:07 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:06 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 05/12] HID: pidff: Add MISSING_PBO quirk and its detection Date: Sun, 19 Jan 2025 14:12:56 +0100 Message-ID: <20250119131356.1006582-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices with only one axis are missing PARAMETER_BLOCK_OFFSET field for conditional effects. They can only have one axis, so we're limiting the max_axis when setting the report for those effects. Automatic detection ensures compatibility even if such device won't be explicitly defined in the kernel. Fixes initialization of VRS DirectForce PRO and possibly other devices. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 46 +++++++++++++++++++++------------- include/linux/hid.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 28f42f30e2b3..d792a07b5a5d 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -421,12 +421,19 @@ static int pidff_needs_set_periodic(struct ff_effect *effect, static void pidff_set_condition_report(struct pidff_device *pidff, struct ff_effect *effect) { - int i; + unsigned char i; + + // Devices missing Parameter Block Offset can only have one axis + unsigned char max_axis = pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO ? 1 : 2; pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] = pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; - for (i = 0; i < 2; i++) { + for (i = 0; i < max_axis; i++) { + // Omit Parameter Block Offset if missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO)) + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET], effect->u.condition[i].center); @@ -839,6 +846,11 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, pr_debug("Setting MISSING_DELAY quirk\n"); return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; } + else if (!found && table[k] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) { + pr_debug("PBO field not found, but that's OK\n"); + pr_debug("Setting MISSING_PBO quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_PBO; + } else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; @@ -1118,7 +1130,6 @@ static int pidff_find_effects(struct pidff_device *pidff, */ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { - int envelope_ok = 0; int status = 0; // Save info about the device not having the DELAY ffb field. @@ -1149,13 +1160,10 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) return -ENODEV; } - if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) - envelope_ok = 1; - if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev)) return -ENODEV; - if (!envelope_ok) { + if (PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) { if (test_and_clear_bit(FF_CONSTANT, dev->ffbit)) hid_warn(pidff->hid, "has constant effect but no envelope\n"); @@ -1180,16 +1188,20 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) clear_bit(FF_RAMP, dev->ffbit); } - if ((test_bit(FF_SPRING, dev->ffbit) || - test_bit(FF_DAMPER, dev->ffbit) || - test_bit(FF_FRICTION, dev->ffbit) || - test_bit(FF_INERTIA, dev->ffbit)) && - PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) { - hid_warn(pidff->hid, "unknown condition effect layout\n"); - clear_bit(FF_SPRING, dev->ffbit); - clear_bit(FF_DAMPER, dev->ffbit); - clear_bit(FF_FRICTION, dev->ffbit); - clear_bit(FF_INERTIA, dev->ffbit); + if (test_bit(FF_SPRING, dev->ffbit) || + test_bit(FF_DAMPER, dev->ffbit) || + test_bit(FF_FRICTION, dev->ffbit) || + test_bit(FF_INERTIA, dev->ffbit)) { + status = PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1); + + if (status < 0) { + hid_warn(pidff->hid, "unknown condition effect layout\n"); + clear_bit(FF_SPRING, dev->ffbit); + clear_bit(FF_DAMPER, dev->ffbit); + clear_bit(FF_FRICTION, dev->ffbit); + clear_bit(FF_INERTIA, dev->ffbit); + } + pidff->quirks |= status; } if (test_bit(FF_PERIODIC, dev->ffbit) && diff --git a/include/linux/hid.h b/include/linux/hid.h index 94ad5a510639..29f0a91f505f 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1229,6 +1229,7 @@ int hid_pidff_init(struct hid_device *hid); /* HID PIDFF quirks */ #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sun Jan 19 13:12:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944451 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 09A151DF260; Sun, 19 Jan 2025 13:14:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292451; cv=none; b=U93NjVNErj1VUyXgyTesx0nUXpQbgEKx07VVvN5QGUsx5+A/UlenkwlIep0kPRreaJOzUI4WrsRvWYzj4aGkY1QzUZn43V6uRlzUX3enXm0W+lqXKj25F7r51hcteb65v69L/tsiVZAlRC6H61zeVQU3e3StKq0R0hLBQ+cUBJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292451; c=relaxed/simple; bh=9OkxGMM/TGcKcRwWGvqe/IYhGFYH0CY4+dFUcgVVilA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KHYZEBC8dgLbjXybhJH0NzceIxGICNXWGIILSjRosh3JLAT43MWutATA33nYBCAlDR2JCh5KqEa9u3dMcpfUTn2FXNuVPlUcGSHRqeeK+ZrGWTt4Y9qiNW9w/Ytjrqfs+ukrbahmhvqRj4Vqm/LLABTrkq6YgaeNPyvGBA+pQPM= 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=T/QycSEe; arc=none smtp.client-ip=209.85.208.41 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="T/QycSEe" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5d3e5c225aaso649010a12.3; Sun, 19 Jan 2025 05:14:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292448; x=1737897248; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fx9O1Rr6bGhNTFg2p+wdoPNtoibDRRuNmGD7dH6Cr/Q=; b=T/QycSEey2h1M9JslAY16eqHFTrNzOHLZVegse8zzFody+HEddpfT3WzTagQwTrnXM jE5z63Pd/Rue8iJPR3BxJWo2MSa9lzoHykVt6KIMppOD81StCdhJVkCkJNBnF731SGdN WdVpQ57z3Ulw2SrJkYjDP/wlB/arovbkXr2bfARZjDExb7OpU4Kbumf+fniE0dhbslEU odrnG5l7htg6PXbESYX3p6Pc4URtOCB9F74kaYiNY30kS0/22Wb3qpSzdvTeB8rsUPfW vkZ9x2FZPEdp5HNlGuz9L2XU6j8Ysggkh5ecKLLA3E865L416junuB+78ZDnfGSF3P7y J00g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292448; x=1737897248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fx9O1Rr6bGhNTFg2p+wdoPNtoibDRRuNmGD7dH6Cr/Q=; b=Z+0CDuKMLXpX9DYzabN2krIdjGExfrjNI4fRnsC+487zmN2nd0z/hOd4O5W12Zr5tL eaM4NWKIWsvcgSpjfdY5raZmj6Zd7oi9/TN0qi4Ac/yNIhoV1QDY2vV09xDgSglqI5N+ tfM8dVVLpsOAPrUP+g0d/tCNU8NGb9IW9j7KSY8H7KZnQq3JoIVBLnPxZYbT+BUJVQ9d 3t/O0sih8H8BSmJPCvXuv+9BD23JP4a0JLqfRo7g8UIyvSr6kCwcR118UeogkQQ2AvKJ NF/evH8CBtXZ7WjHmd4eQV8PFV0XcQDIjZTNgXlgh9PpvFNCmDppVpR/h9tC2OCR3nFq uTTg== X-Forwarded-Encrypted: i=1; AJvYcCUvx9P0/ZNDldnL4uXC8v8KcOsfTToL3X+QSl5/rBJ2WuSEhYXKOObSv3ixdF+08wFn12FxT5y/5T4dFA==@vger.kernel.org, AJvYcCV99cQ+CjKWmsyUuR/cfvKJPPMpsxuPUnL7rNAkNkkV/1ULC3ytA4GRUA06JAfhYT9z5mat3bh5+O+Y@vger.kernel.org X-Gm-Message-State: AOJu0Yw5YTTI+kfcD+zCS/WPRj7a/94mftylOneMv2vhKOvKIH2TIXZG wy85y/s8xuoNpsp4tgcgzC5f+B19IgK8QakVLWu2Ffo0s1kZopKG X-Gm-Gg: ASbGncv9fSXuRWoF4TtSWc+hTtTamggKB1w/hgZWfYbcKkCD3tARUFQ9uam0tslwRHc SH0fV1702SmCf+hMgVdbBAgwiIUr9ozm3o4T5Z98EX/Cs1R+rPcUI+GKYNHqt3kKKPlkCbuAF2M 2YQqKRR3bqvRE0R8LjkdtFm0fnaJ4yVoFcIHMMrHTWwnvV9H4yifTHCsC9GSwkt4CyulvYd6LKg I7pqEvKlba/9wlj0SNnteyDiPtgzqhBVU1vlU9BGGbLXdTOY9wJWtSTL0pn+Bd7TmbkYR0OLhBO izRBijgkXNxrrIKqJRbvfv7MWXI8ZdJAnckjWXwd X-Google-Smtp-Source: AGHT+IEesJ9GVcp+VUrILhjU6mxoodHH28y+Q91Ulex9zVM00flzkVAI6ALq0/8U6IQWV9JQQM9KrQ== X-Received: by 2002:a17:906:f59e:b0:a99:a6e0:fa0b with SMTP id a640c23a62f3a-ab38b24bd88mr294164166b.5.1737292448197; Sun, 19 Jan 2025 05:14:08 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:07 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 06/12] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Sun, 19 Jan 2025 14:12:57 +0100 Message-ID: <20250119131356.1006582-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With this quirk, a PID device isn't required to have the PID_DEVICE_CONTROL field available. Some devices like VRS Direct Force Pro do not implement PID_DEVICE_CONTROL in their descriptors while still having the necessary control fields like PID_ENABLE_ACTUATORS or PID_RESET. Fixes initialization of VRS Direct Force Pro Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 3 ++- include/linux/hid.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index d792a07b5a5d..53b16a4e54a6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1000,7 +1000,8 @@ static int pidff_find_special_fields(struct pidff_device *pidff) 0x57, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, 1); + 0x96, pidff->quirks & HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL ? 0 : 1); + pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], 0x8b, 1); diff --git a/include/linux/hid.h b/include/linux/hid.h index 29f0a91f505f..2af9db0296d1 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1228,8 +1228,9 @@ int hid_pidff_init(struct hid_device *hid); #endif /* HID PIDFF quirks */ -#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) -#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sun Jan 19 13:12:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944452 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 B43891DF276; Sun, 19 Jan 2025 13:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292453; cv=none; b=HVvPpJpFDjkhXY+WoxlTJQMy84JebuKyEuR3ncq4/c2hwd2wZnPeIp6KYOBdLooOnmhrZVztcmlRw4pEmM9byTaYTPHqVgn2XFce2vPoAwstjdYL3UpEY2Owcxqh38sevAHDyFLlL1MupDIC+hhSOvgCwlkBXXWD5kJdf4cX1NM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292453; c=relaxed/simple; bh=ozLOBf+HgXIdD1CSxTdGgwHIY8gHldGUPDjNzKsNMgg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sXfUJnCA0x4hKUG1Wr6966l2EcxeidB96p/hDzAPBAbpvPIgrR6KgPyUQVXq3t/n0fhbdnopuJ3XEXiPLFenolg9XfoY7UTakQIdFdBdD3n15Cxd9za9cG9LIhEWPKjC3+97ah9lVw6Hx4I+LVGV+OLpoOmbfFKqmMT4yBJjkmk= 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=YwwGA7jM; arc=none smtp.client-ip=209.85.208.52 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="YwwGA7jM" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d9f842f237so662201a12.1; Sun, 19 Jan 2025 05:14:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292450; x=1737897250; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AKygA3bnrgOWG91lmMVcCS4m4zZ5VN+Yzt3sSqeFq/Q=; b=YwwGA7jMryLmJLcuFWpYooS+aooMD+6qInhUSiYeJIJOi/dLdvJ4zVmhLT4JdfCuI5 lFP251Vl4sVEw+SQieL9rSLg8nn/vpWC7STnooANNL6LZLOnpo/5L9xC7M/+ZxsoIJH7 +pmEZC8Ro7gUQD/q9D8zKvR4+pbT9J4Jedra+4S3n8MstyuS5eHWTQPQpT8dK8h0tFnD 0Y1kPmY+avjrCWX8gJI01xmcvt0nWYrqurIiXLSe8q9NivyYY8CHdz5E34ziB7okBw/T XropgzLoGoaj1vWNWCw1Ws3lwMKCrKTs3UJlMqEySAjqynAzdX0yXZphd5sdV7U0uK2t h8HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292450; x=1737897250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AKygA3bnrgOWG91lmMVcCS4m4zZ5VN+Yzt3sSqeFq/Q=; b=p3tjiPz3Ce+EBzVPofwGcDcOerVGViOB///Qi3j98nRJkpxEdhbOBwqUDVIQAqdHvl GnMYbl2t/p+RloBwCYQ7iofXjrYaSLO2RG49y9pP0of6be03TiWBUOv1+1DKpVVHUxT4 eivQ3vXAw/m5lKMYGR5IOcTbZ8gs12cpEgN2HMwTIMQ/z0xAZah7K3zAvoiNgiMnoJVP a25aKXn6Bbd34nX33yZ60k5C0+il/WCEEaqGqYMdc+RTUJkdy0v2v6MWdO+2wXzUfKcU Vtb+KVnbQpSo4ToQ7sRRaABCBhRSLm6OZE5RGOCGl6WNyvRNTDo6ZjG6hV3cUoOc57+N hmuw== X-Forwarded-Encrypted: i=1; AJvYcCW2HOYeuMum97On4phB1+SdfvBuDGuyjJst7zt8I2kLRHYOsp5aZKtyrlYMyFjz8zakSmNS6T8JUHqmnQ==@vger.kernel.org, AJvYcCWbGnl8xO/JFaG+TAAFx8/tK0n1tS6ona1b1sAioZXT0VwMSx5h4Nmo1RqhdtC7jvjtmMKcI15Ml/zl@vger.kernel.org X-Gm-Message-State: AOJu0YzPeIDWvBavk1rNnwUn7BimXAwtVdM2Iw4uWlQ8lslj09qEqpTc gJed3cX+7Z5lE1TdA51LdLi9Xm524wcSN8cMprDUgS38SEnS7j0I X-Gm-Gg: ASbGncvwn7o1pn1bGH+ICGU2el/MjVafKLYE235mXK07lCDKxYmjDK9XLiG42TW36yu 5zNoUsCqnQ8bf38zzaqJPHyv7wy6YH4at9gGPTmUcoPb7uXPAr1Mr00jAYizG2UCAQ+zWnKLaaK hqsbbvTrfvA5HK4LT9Ojw1FYVBYBbhQZv78V4LL68Bqt/b4SkfMr8Ea6F0TbNODqZga7Pxeu6Ic P5BqSZmldzkvlxEHUEF2j8vSVG/Esz9IqBiTPNkyMAVL2Q+w3IXPL7yfiSWahTC9h2yslv3uodn 2s9sCh/MR/+KU0wb4Z7Wuojs7Hgbl8GoPWEdy3au X-Google-Smtp-Source: AGHT+IHdOuRt4mB1GxMgwzUCqG+oC8jdRtX/Dme9EjgOQo4P23XlRIPBkby1dyxzrbjaJ5luqa05PQ== X-Received: by 2002:a17:907:9803:b0:aa5:163c:69cb with SMTP id a640c23a62f3a-ab38b49a5cbmr271095466b.12.1737292449840; Sun, 19 Jan 2025 05:14:09 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:08 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 07/12] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Sun, 19 Jan 2025 14:12:58 +0100 Message-ID: <20250119131356.1006582-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 15 ++++++++++++++- include/linux/hid.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 53b16a4e54a6..5a328860685b 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1299,8 +1299,9 @@ static int pidff_check_autocenter(struct pidff_device *pidff, /* * Check if the device is PID and initialize it + * Set initial quirks */ -int hid_pidff_init(struct hid_device *hid) +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) { struct pidff_device *pidff; struct hid_input *hidinput = list_entry(hid->inputs.next, @@ -1322,6 +1323,7 @@ int hid_pidff_init(struct hid_device *hid) return -ENOMEM; pidff->hid = hid; + pidff->quirks = initial_quirks; hid_device_io_start(hid); @@ -1400,3 +1402,14 @@ int hid_pidff_init(struct hid_device *hid) kfree(pidff); return error; } +EXPORT_SYMBOL_GPL(hid_pidff_init_with_quirks); + +/* + * Check if the device is PID and initialize it + * Wrapper made to keep the compatibility with old + * init function + */ +int hid_pidff_init(struct hid_device *hid) +{ + return hid_pidff_init_with_quirks(hid, 0); +} diff --git a/include/linux/hid.h b/include/linux/hid.h index 2af9db0296d1..93233c5b75a6 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1223,8 +1223,10 @@ void hid_quirks_exit(__u16 bus); #ifdef CONFIG_HID_PID int hid_pidff_init(struct hid_device *hid); +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #else #define hid_pidff_init NULL +#define hid_pidff_init_with_quirks NULL #endif /* HID PIDFF quirks */ From patchwork Sun Jan 19 13:12:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944453 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 291B91DEFE6; Sun, 19 Jan 2025 13:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292454; cv=none; b=nqCgDsQDVZlNrPPzUrobl1jkQ3wVZwslaLwnGzu53/IJj0LwZjkknn759WwmZxNMDQwhSAegV7pDAICi3+i9ZGJ7ZE0TW9+Vsjq6i1EyjeO4vF8yJMnvb72aqqzCt9+UKDXtF45+xRhGk7cnIuBh8ZbW1sR8ZLQVC7hNQMgVJQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292454; c=relaxed/simple; bh=U4XSO6HItdH3Y3O7RBAUoXbyGVlgQEw0plNllelDQLM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fg05ylbRQu2gtEXLCF8tIvUOPztbmg6VrrHVs1+bH89e/ruAIY8DxcG/JVu4bvFbtSf4tYZFPLfZpYqV17yDwRfGTRuS43kJrmDEeYSYr0RFgbm5bfjZFs/V1CqvjLdGlPq9+Kg9RXN3OlSSiOEpMT1GYYdlQNsjjK9U/AZyNxA= 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=MWUWT5kU; arc=none smtp.client-ip=209.85.218.45 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="MWUWT5kU" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-aa676e4f36cso54112866b.2; Sun, 19 Jan 2025 05:14:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292451; x=1737897251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Iwy5DXoHYpEPu+oArSeioLqlrlfN3CCAJZ+CyGwF6oc=; b=MWUWT5kUnZWdRFzHsnwOaVzLSnXmgZ4uJbKROUnD2gcEVKoA+HPcCQOTxcyllK69tT au7AMxFVhTJ/Ce0fKkt3Yw+kstacJwctPUe0T1dudchpNGnQP1HSFdYUL9cxecVGFl6V YAaBVf3awvEUk4gDl1tkaiekAlgrhH6AYtgZMgKCYsZIJX3LtJfjw3N1dXLsdy8ZYGxB HoITDBfYKMWwgXTJrZYVodpbAG9fo4CCXpNzwjCukyrg/oHqneEfVNaTMpI1Ypu3B2CZ RYBanLNjep+gq9Lcc+3hDkMcD/fARD6qUR/BL8ArInlErILWtlBTWdxDxN5tBX2kM5nv FBXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292451; x=1737897251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Iwy5DXoHYpEPu+oArSeioLqlrlfN3CCAJZ+CyGwF6oc=; b=CIWqabyO8P11sn5YZDi7XYKrUWExspzTqF4t854aR3krXsNc4iKSgeQv6NqbUXXg8l ZSrUMXEI4UfuPZLGcGuT4w8rTfWuj0YtYvz16RA5JcyyKTkrB2rCvIzYxHdAx6AelS1h WCGUzdi1+p7XtOLwVThTccF0NqP7MmIB05g1TX/ISsVJRwa2JQ/hM175HAutMUjh7qKE CG3B6BHH/BZD1RoIQwY6sYwskes4ca12g07MuWnMz+RrIvN5n1whAGsp7PfA/iRODCYo UFpyGqw+aWj8XdQB3Hnj6Xu/J4zByw8sgALb3zLvMWDC2YoX460MFNzVqMPpFAdNVXT5 EMJg== X-Forwarded-Encrypted: i=1; AJvYcCVNQ3VY97MS6yDswIQQHNi+JWiVoIrf6XxUJeQ9gqqj47MXLRaWtcwrjdaCBPNbHjzp9AZFQiTCsvJl9g==@vger.kernel.org, AJvYcCW1IVUQKaCmNOSDR2Ee74wiLgIJGajergJxGHGATZwfdj8cqLcYi2rcxoZhVWIAQzD0FdZUW3lgedzj@vger.kernel.org X-Gm-Message-State: AOJu0YzRPDoHc4UC3Rrt27LSBUHhbygYi+sQswv5VZCiAsw9hBvb/IGd H5RjJUrzQCLEoMgD0PnFgGreZa8lYQPWBPPMU+4Y95N4Q4J3bO+A X-Gm-Gg: ASbGncsMiDJKJymcHFehGPmrbjZ5s2sZDNbWRuxbF20h0G1lMvH/y5V3I6FXep8XZ3E uvPLH86oBxRx42qhLCrPxzsCYccv3i6gSjAzMlnr7riTRj9tfdp5K2jQzD6WncxShMaf3HnMSnD fm4YGdAk8O92W4mWLBAnB6sCSLSqMp1lPtg2qbqJcmOGHwRNuRY5rgi0g6oTF3jXkozHcPZD09g c25vAsKmlcJo14lgd8aBSWhfFt5PCujPT22qZAz1lSOKYPE2SR7JLZFhvjd46LAxkCtSHXERIOY QBS2B7Y/HFGuW6MiDGUYOhRrDd7UBGKCn8WitNZg X-Google-Smtp-Source: AGHT+IFxMANnRPEC8EbAW/IxoIi+sV9QMKsjmaDKba+dfq8F5Yi/p5lfojXZX48u07DjU5UaVsM4XQ== X-Received: by 2002:a17:906:d553:b0:aab:fcbb:da37 with SMTP id a640c23a62f3a-ab38b49928emr307379066b.11.1737292451247; Sun, 19 Jan 2025 05:14:11 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:10 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 08/12] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Sun, 19 Jan 2025 14:12:59 +0100 Message-ID: <20250119131356.1006582-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> SDL -> Linux API translation, and this value can be incorrect. This can lead to partial/complete loss of Force Feedback or even unexpected force reversal. Sadly, this quirk can't be detected automatically without sending out effects that would move an axis. This fixes FFB on Moza Racing devices and others where effect direction is not simply ignored. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 12 +++++++++--- include/linux/hid.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 5a328860685b..6b4c4ecf4943 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -136,6 +136,9 @@ static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; #define PID_EFFECT_STOP 1 static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b }; +/* Polar direction 90 degrees (North) */ +#define PIDFF_FIXED_WHEEL_DIRECTION 0x4000 + struct pidff_usage { struct hid_field *field; s32 *value; @@ -354,9 +357,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->set_effect[PID_GAIN].value[0] = pidff->set_effect[PID_GAIN].field->logical_maximum; pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->effect_direction->value[0] = - pidff_rescale(effect->direction, 0xffff, - pidff->effect_direction); + + // Use fixed direction if needed + pidff->effect_direction->value[0] = pidff_rescale( + pidff->quirks & HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION ? + PIDFF_FIXED_WHEEL_DIRECTION : effect->direction, + 0xffff, pidff->effect_direction); // Omit setting delay field if it's missing if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) diff --git a/include/linux/hid.h b/include/linux/hid.h index 93233c5b75a6..5237f9040950 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1233,6 +1233,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) +#define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sun Jan 19 13:13:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944454 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 629201DF731; Sun, 19 Jan 2025 13:14:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292456; cv=none; b=b24HSx4VJFkvC4ZHdxHNqJPOJMU1c9DVkZonmJlEnQOt+7KKw0MnASHWBmHSIpdg4oX9Plq5AwgUU80PeSyRsBcs2gjrKsuKn/akR3Blu0sSTRgrqGTCJBlv0KUAOwcTyS35I8SViIFIl2YuNHSz/gPW7lx7I+hpFm1YfjnX2d0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292456; c=relaxed/simple; bh=sE1wG2MzsF5AXI0uMU1EmAKL9ibe6BkNsGz3+hAYNnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=svGuLUunsxOEOvOCSx7dEnUjHtNrnBB5YV14ObxprAYg6NkQJKQNEjtVDADvShxEcfSEObeEjOjH4YsfuAwpEXB1QbSsoSVEw9eh0WnZuvFYI9cIp0sTVazg1M/kC6bi2jxg6pz/zoe8bruN7k6KiPstE7ifn/F4O6Q8NY8n+6I= 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=JIHtre4q; arc=none smtp.client-ip=209.85.208.43 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="JIHtre4q" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5d3ea2a5a9fso561408a12.2; Sun, 19 Jan 2025 05:14:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292453; x=1737897253; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zOUgFxoQTFAjXcydLrtUiE3FRvCWB7EkDAPknhRAiQY=; b=JIHtre4q/4WchtLd2Akuh/9IxWLri34LcwuzluEz0dX+0QFYMjLMkbWp0AAuV7n3SA DR6LDXKVvx8y2SCo6EGrbWG4Vq8FCfX0I78O1dN4JzQHAhSSwinjG74RZXLWrxXF3jLh Y0YheGPZIOzqbvOWiWdUTmUQJzUMxPX2KXI373nJOkPNz/bnoVZHAfcdRgKd6VccC6bb s3CAAARsGTwLX3vyBk5ydjd+g3wAND8hWTpLSnTiiyiiBgxi6Z7pARpOi6i4gHvhREny jwfTkYr2VE939W+DVLbnR/+Y40xjNG7vVFM/zaJgs1lLnCm+eQmq67ILLCMwO4AuCh7P ubNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292453; x=1737897253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zOUgFxoQTFAjXcydLrtUiE3FRvCWB7EkDAPknhRAiQY=; b=L2/p7kMqF4rtDrOkbhjdnaOxZhcB9rp972H31Rc2tlwsp5z3uMQiaKG39BtNVbAxKA V5VlaCmo5GpMaXDw6nZeXMwh4zjMuLb+Z5KgybsZuX8+RkKYT0u+Ne6x9SxkotjUJ/vW 9zvifyZ7CxLBq0IxWIX3eretRehmqoxd9+M11jsq7bDAcUT8Tguysg781iK/yQjIoFuf kDSY/I0/Meb8NY/KD6PyaebXNVoXKI+6sYywEVzHwO/q+PbsaRot72BZNXZfbJZNquz6 sw/iigOF4lc2AbQ4neQSOen6BiIN32ysOKv5ttGQBdq1cZocCIa3k/jCn+kQ5wh7RKbP acfw== X-Forwarded-Encrypted: i=1; AJvYcCW0RQ64koAzf78baEiG2dXtfwypm0lv/iJemPVI0ayqV+0Fmely95bkeSww10SAbe75a/aBAjqgJZmugQ==@vger.kernel.org, AJvYcCXstxmuJhT4l3QeCExNEAn1Wcb3RPFF0Elck5ms21urUODmoiIbMm5nMLjqxyGOee3NmR5HTN0+8X5T@vger.kernel.org X-Gm-Message-State: AOJu0YzHCnvQ1m7c3SX14i3a1bpb77VbE+yXfbL4D1+IcMMEgW7r/gly ffKESAAEpHXHzvMKOqOkfAH9K1V0xqaZG0nYtAXSD3jFIPUajheT X-Gm-Gg: ASbGncsHmHpR3Ai5A55wU65VJlPRuNBxMNz6poHBgyA/Q0ieMhJ0wS/BmNmkAjeBdQv g9ynBGWHBOqTm36nXi3xTA5756CxaXcqy9AbHRAu9H57yClhgAjJCvUV5WOoiz2FwBkaNAgzs2i jAwCJCLFU3HoxwsMQe+WXE9VSFUreOXWFSZZ24s0UmtfmG6gujadg49lhLOZV8R6X18qwEBXUaF QqJBxcTTPjOVJe6TbCbty8lO6gJIJiNaUS9kL1c+phmapiGasza4cqRa8Dj+C6DtZImLuh2Z3pZ t4sTJmzyX8Py32GpRVKXFfXC+lp3N2OJ/rqZ9eUw X-Google-Smtp-Source: AGHT+IEOnJMw/lNJimPnU6WghcELjDe/DOMcrEYspYwtQCTr5Oep85kTfXKDEQzwzHP7T1UWOlFp/A== X-Received: by 2002:a17:907:7f0a:b0:aa6:ab00:7b9d with SMTP id a640c23a62f3a-ab38b26f478mr264644466b.4.1737292452369; Sun, 19 Jan 2025 05:14:12 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:11 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 09/12] HID: pidff: Stop all effects before enabling actuators Date: Sun, 19 Jan 2025 14:13:00 +0100 Message-ID: <20250119131356.1006582-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some PID compliant devices automatically play effects after boot (i.e. autocenter spring) that prevent the rendering of other effects since it is done outside the kernel driver. This makes sure all the effects currently played are stopped after resetting the device. It brings compatibility to the Brunner CLS-P joystick and others Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 6b4c4ecf4943..25ae80f68507 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -109,8 +109,9 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; /* Special field key tables used to put special field keys into arrays */ #define PID_ENABLE_ACTUATORS 0 -#define PID_RESET 1 -static const u8 pidff_device_control[] = { 0x97, 0x9a }; +#define PID_STOP_ALL_EFFECTS 1 +#define PID_RESET 2 +static const u8 pidff_device_control[] = { 0x97, 0x99, 0x9a }; #define PID_CONSTANT 0 #define PID_RAMP 1 @@ -1240,6 +1241,10 @@ static void pidff_reset(struct pidff_device *pidff) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_STOP_ALL_EFFECTS]; + hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); + hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_ENABLE_ACTUATORS]; hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); From patchwork Sun Jan 19 13:13:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944455 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 69B431DF740; Sun, 19 Jan 2025 13:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292458; cv=none; b=WJMer8K07OisS6mtoP6ZVR0KAqMyK20tM0QP91F+5gUJB+Sj52kkErU0xYcAuN2oCnQzMPfjfvt7IXB2lc8/UGp7JjmBSL+1FkxfbOPxL2fzAx1szwIAwdSCfmtwtFCurVpAQQOEAcowg13/esu7V1QvdUBH0GDYNK8A0eU2QZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292458; c=relaxed/simple; bh=5O6+A9/8muwiHs6jmr8CR4NhE34g5Ohn2N6QGh1gtBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LMYVVsEOnjnY0zc1DpQoARXRlTHHN3qQUHFGHQp/3LfNj7sITKDpdF2BI6NiNo/9/R6Dw5eakXx9Svx76eAAzMKxxZ8WmTaPYi7F57RIV5O/BIAChpTVMMsiBIIufYB89l0vOJPgvVIvHdCpQAHFYvdCmmeMIrmfdsUiGCGFxE8= 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=jEveaVMP; arc=none smtp.client-ip=209.85.208.50 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="jEveaVMP" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5d3da226a2aso649866a12.0; Sun, 19 Jan 2025 05:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292454; x=1737897254; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RjRcri7+dbrHf8BT0YdfBRzc/LKUF2yCKpsEYPu1KZ0=; b=jEveaVMPoNUVKrIyikLwquK9Qgo6qQoX+4rmiPYO6c8bttLpXo7u3Bd+0LuYf43Aqe 4e6xni7A7OUtZ29uWmiVNcDUSlOSXuhKCcM0HuBwOAWVv/qhZ+1l2Wn1qknT3yZqRIJg HYFWn32xHei65bMC4ein76/vHoTz4GAisoVB+NisivPCK0ZQojFnr3A0+s3EzFlmZeLM ruc4Yj1Z5m3LYGZXlUjYDprwj83uwWhUOCLika6yRFiHnG/92YXYc/900sLFBEVEabXl gDwyXDCBMRgnMyOlWb1BEqoX0cg3tJPoysc+j74kw2bVqFjmys4pGZTis07vJ7/JuSJl Gicw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292454; x=1737897254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RjRcri7+dbrHf8BT0YdfBRzc/LKUF2yCKpsEYPu1KZ0=; b=YB+I7csq99CW2bu6UrQLM1lcdr9Flg2dUkUNlmgGry0zGGuP7mFZTIJ73ZhLh4gWMI SUQWP+adpnyrhOjEY9+gkGkpGttvlRdHw21aV4h6VZxwdVkQs1lqAnSJLkf4+WNmNfUI L7j+mKT6w6w4vkbAXGnFX1P67rWSENo5/OlAzqOBskYeNXk5nnV35AhZ8EPOQR8sHMV2 c0WGnp1S7p7u2qYIXFWJgrGO9+dKVQiLZhJKJzkkBoPJnGZGwr3oPUBJlF5T6XeB89wV EpwwgmxUZxJ8P7UBIVFNJOppGfqm4FPqgufRps9pm3LFTqNff1JQdrADJNB8wWsBhOmM QqFw== X-Forwarded-Encrypted: i=1; AJvYcCWyxD5/hzu5bsny9ktcWvYDT7jHh2zbqNOxSADOtHrph54ek5FHSU4qZcFBsOFGSJi3S5qpFFLN+TOxjA==@vger.kernel.org, AJvYcCXRhnVZ6F8hYSO8DB0GdArflPIpe49NXCPgGnsKN2cW8fv3J/GO3Q2vrmBdLY+tZkudfcp6VgGbtlrm@vger.kernel.org X-Gm-Message-State: AOJu0YwxGb1cKxCRVExpnExUlGu+x4Ub0DnsovDpmOe7YbPhmUBesgY0 G8VEl1CaFt2Jq9yJaklFsNgm2/L5FWtyVJWHlb1hitposKgNncbR X-Gm-Gg: ASbGnct6t3QFjzFpKwxMzBrBeQgNFiXzvlZ4KZyirOrJWWhYMgWwoJSLe+Qc8miEvez zln1TY1O4KfPT71xEMdzY3xeIpYyUwwjPnGegrAKK54aBCIhoeAhmvqv/6dVXWtYmgM3/bBB4Oy b2/M9jcpxnHQAzk+AlKrQqftZr8FBIIdIehXvKjgSgkBbbZmf4bt5LXq/aO6YM5xvx0njbt2i+y DmeyXtyUdXOvvyBzaf25zmn0Snxxf6w5wT1IBhjSdRVORqgJBCphwOD55D/10ax0BLC4UvKGmmv dl+itXsZexqH3I6fdgQpfZkDxMGCXfbhrvlByyh8 X-Google-Smtp-Source: AGHT+IEbA4BJocGGL2XQCxFx55NoUtjmMyy1HBDM5uRu/A5ZGYJVJYB9Q+eiaezHJpjXFb5NmMGdbw== X-Received: by 2002:a17:907:6d1f:b0:aa6:9b81:e7aa with SMTP id a640c23a62f3a-ab38b32037amr355302366b.7.1737292453546; Sun, 19 Jan 2025 05:14:13 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:12 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 10/12] HID: Add hid-universal-pidff driver and supported device ids Date: Sun, 19 Jan 2025 14:13:01 +0100 Message-ID: <20250119131356.1006582-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend pidff compatibility, usable button range, fix device descriptors, manage pidff quirks and set improved fuzz/flat default for high precision devices. As many of PID devices are quite similar and not dependent on custom drivers, this one can handle all of PID devices which need special care. Numerous sim racing/sim flight bases report a lot of buttons in excess of 100. Moza Racing exposes 128 of them and thus the need to extend the available range. All the included devices were tested and confirmed working with the help of the sim racing community. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/Kconfig | 14 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 29 +++++ drivers/hid/hid-universal-pidff.c | 188 ++++++++++++++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 drivers/hid/hid-universal-pidff.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 4d2a89d65b65..59d8da16f5b4 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -1217,6 +1217,20 @@ config HID_U2FZERO allow setting the brightness to anything but 1, which will trigger a single blink and immediately reset back to 0. +config HID_UNIVERSAL_PIDFF + tristate "universal-pidff: extended USB PID driver compatibility and usage" + depends on USB_HID + depends on HID_PID + help + Extended PID support for selected devices. + + Contains report fixups, extended usable button range and + pidff quirk management to extend compatibility with slightly + non-compliant USB PID devices and better fuzz/flat values for + high precision direct drive devices. + + Supports Moza Racing, Cammus, VRS, FFBeast and more. + config HID_WACOM tristate "Wacom Intuos/Graphire tablet support (USB)" depends on USB_HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 24de45f3677d..919d6a146077 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -140,6 +140,7 @@ hid-uclogic-objs := hid-uclogic-core.o \ hid-uclogic-params.o obj-$(CONFIG_HID_UCLOGIC) += hid-uclogic.o obj-$(CONFIG_HID_UDRAW_PS3) += hid-udraw-ps3.o +obj-$(CONFIG_HID_UNIVERSAL_PIDFF) += hid-universal-pidff.o obj-$(CONFIG_HID_LED) += hid-led.o obj-$(CONFIG_HID_XIAOMI) += hid-xiaomi.o obj-$(CONFIG_HID_XINMO) += hid-xinmo.o diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 1f47fda809b9..af74dbca69fd 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -261,6 +261,10 @@ #define USB_DEVICE_ID_BTC_EMPREX_REMOTE 0x5578 #define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577 +#define USB_VENDOR_ID_CAMMUS 0x3416 +#define USB_DEVICE_ID_CAMMUS_C5 0x0301 +#define USB_DEVICE_ID_CAMMUS_C12 0x0302 + #define USB_VENDOR_ID_CANDO 0x2087 #define USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH 0x0703 #define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01 @@ -452,6 +456,11 @@ #define USB_VENDOR_ID_EVISION 0x320f #define USB_DEVICE_ID_EVISION_ICL01 0x5041 +#define USB_VENDOR_ID_FFBEAST 0x045b +#define USB_DEVICE_ID_FFBEAST_JOYSTICK 0x58f9 +#define USB_DEVICE_ID_FFBEAST_RUDDER 0x5968 +#define USB_DEVICE_ID_FFBEAST_WHEEL 0x59d7 + #define USB_VENDOR_ID_FLATFROG 0x25b5 #define USB_DEVICE_ID_MULTITOUCH_3200 0x0002 @@ -817,6 +826,11 @@ #define I2C_DEVICE_ID_LG_8001 0x8001 #define I2C_DEVICE_ID_LG_7010 0x7010 +#define USB_VENDOR_ID_LITE_STAR 0x11ff +#define USB_DEVICE_ID_PXN_V12 0x1212 +#define USB_DEVICE_ID_PXN_V12_LITE 0x1112 +#define USB_DEVICE_ID_PXN_V12_LITE_2 0x1211 + #define USB_VENDOR_ID_LOGITECH 0x046d #define USB_DEVICE_ID_LOGITECH_Z_10_SPK 0x0a07 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e @@ -964,6 +978,18 @@ #define USB_VENDOR_ID_MONTEREY 0x0566 #define USB_DEVICE_ID_GENIUS_KB29E 0x3004 +#define USB_VENDOR_ID_MOZA 0x346e +#define USB_DEVICE_ID_MOZA_R3 0x0005 +#define USB_DEVICE_ID_MOZA_R5 0x0004 +#define USB_DEVICE_ID_MOZA_R9 0x0002 +#define USB_DEVICE_ID_MOZA_R12 0x0006 +#define USB_DEVICE_ID_MOZA_R16_R21 0x0000 +#define USB_DEVICE_ID_MOZA_R3_ALT 0x0015 +#define USB_DEVICE_ID_MOZA_R5_ALT 0x0014 +#define USB_DEVICE_ID_MOZA_R9_ALT 0x0012 +#define USB_DEVICE_ID_MOZA_R12_ALT 0x0016 +#define USB_DEVICE_ID_MOZA_R16_R21_ALT 0x0010 + #define USB_VENDOR_ID_MSI 0x1770 #define USB_DEVICE_ID_MSI_GT683R_LED_PANEL 0xff00 @@ -1373,6 +1399,9 @@ #define USB_DEVICE_ID_VELLEMAN_K8061_FIRST 0x8061 #define USB_DEVICE_ID_VELLEMAN_K8061_LAST 0x8068 +#define USB_VENDOR_ID_VRS 0x0483 +#define USB_DEVICE_ID_VRS_DFP 0xa355 + #define USB_VENDOR_ID_VTL 0x0306 #define USB_DEVICE_ID_VTL_MULTITOUCH_FF3F 0xff3f diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c new file mode 100644 index 000000000000..0f81df9a019b --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID UNIVERSAL PIDFF + * hid-pidff wrapper for PID-enabled devices + * Handles device reports, quirks and extends usable button range + * + * Copyright (c) 2024 Makarenko Oleg + * Copyright (c) 2024 Tomasz Pakuła + */ + +#include +#include +#include +#include +#include "hid-ids.h" + +#define JOY_RANGE (BTN_DEAD - BTN_JOYSTICK + 1) + +static const u8 *moza_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) +{ + // Fix data type on PID Device Control + if (rdesc[1002] == 0x91 && rdesc[1003] == 0x02) { + rdesc[1003] = 0x00; // Fix header, it needs to be Array. + } + return rdesc; +} + + +static const u8 *universal_pidff_report_fixup(struct hid_device *hdev, __u8 *rdesc, + unsigned int *rsize) +{ + if (hdev->vendor == USB_VENDOR_ID_MOZA) { + return moza_report_fixup(hdev, rdesc, rsize); + } + return rdesc; +} + +/* + * Map buttons manually to extend the default joystick buttn limit + */ +static int universal_pidff_input_mapping(struct hid_device *hdev, + struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + // Let the default behavior handle mapping if usage is not a button + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) + return 0; + + int button = ((usage->hid - 1) & HID_USAGE); + int code = button + BTN_JOYSTICK; + + // Detect the end of JOYSTICK buttons range + // KEY_NEXT_FAVORITE = 0x270 + if (code > BTN_DEAD) + code = button + KEY_NEXT_FAVORITE - JOY_RANGE; + + // Map overflowing buttons to KEY_RESERVED to not ignore + // them and let them still trigger MSC_SCAN + if (code > KEY_MAX) + code = KEY_RESERVED; + + hid_map_usage(hi, usage, bit, max, EV_KEY, code); + hid_dbg(hdev, "Button %d: usage %d", button, code); + return 1; +} + + +/* + * Check if the device is PID and initialize it + * Add quirks after initialisation + */ +static int universal_pidff_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + int error; + error = hid_parse(hdev); + if (error) { + hid_err(hdev, "HID parse failed\n"); + goto err; + } + + error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + if (error) { + hid_err(hdev, "HID hw start failed\n"); + goto err; + } + + // Check if HID_PID support is enabled + int (*init_function)(struct hid_device *, __u32); + init_function = hid_pidff_init_with_quirks; + + if (!init_function) { + hid_warn(hdev, "HID_PID support not enabled!\n"); + return 0; + } + + error = init_function(hdev, id->driver_data); + if (error) { + hid_warn(hdev, "Force Feedback initialization failed\n"); + goto err; + } + + hid_info(hdev, "Universal pidff driver loaded sucesfully!"); + + return 0; +err: + return error; +} + +static int universal_pidff_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + // Remove fuzz and deadzone from the wheel/joystick axis + struct input_dev *input = hidinput->input; + input_set_abs_params(input, ABS_X, + input->absinfo[ABS_X].minimum, input->absinfo[ABS_X].maximum, 0, 0); + + // Decrease fuzz and deadzone on additional axes + // Default Linux values are 255 for fuzz and 4096 for flat (deadzone) + int axis; + for (axis = ABS_Y; axis <= ABS_BRAKE; axis++) { + if (!test_bit(axis, input->absbit)) + continue; + + input_set_abs_params(input, axis, + input->absinfo[axis].minimum, + input->absinfo[axis].maximum, 8, 0); + } + + // Remove fuzz and deadzone from the second joystick axis + if (hdev->vendor == USB_VENDOR_ID_FFBEAST && + hdev->product == USB_DEVICE_ID_FFBEAST_JOYSTICK) + input_set_abs_params(input, ABS_Y, + input->absinfo[ABS_Y].minimum, + input->absinfo[ABS_Y].maximum, 0, 0); + + return 0; +} + +static const struct hid_device_id universal_pidff_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C5) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_VRS, USB_DEVICE_ID_VRS_DFP), + .driver_data = HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, + { } +}; +MODULE_DEVICE_TABLE(hid, universal_pidff_devices); + +static struct hid_driver universal_pidff = { + .name = "hid-universal-pidff", + .id_table = universal_pidff_devices, + .input_mapping = universal_pidff_input_mapping, + .probe = universal_pidff_probe, + .input_configured = universal_pidff_input_configured, + .report_fixup = universal_pidff_report_fixup +}; +module_hid_driver(universal_pidff); + +MODULE_DESCRIPTION("Universal driver for PID Force Feedback devices"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Makarenko Oleg "); +MODULE_AUTHOR("Tomasz Pakuła "); From patchwork Sun Jan 19 13:13:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944456 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 747701A296; Sun, 19 Jan 2025 13:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292459; cv=none; b=SLw4pb4J2x617OYau5m+Fr4G0c+i/QG+VXvMfgoIStig8DG2ehmF1/kBdlstEA95BeL1chdGU10xrRq0c2/B9oLI6aaKW02o3uSH1W9a/n93JVjaq6cYYBjRuimQ/jNMXhFAsZAAkdIiF0D0W737JI1qvYY+hXWfSPkgl1QBO2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292459; c=relaxed/simple; bh=X3oKAxgWxe+mG27lNFrl/Y7mzZe6FgJZQ2Qc1O2lB3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rUYhcz3ULaNauZOBtKhRN0BC6RerNw1uuYH8K9w24kOh6XUZEXFUcyo6Cgy1EAutdUj1C0RdXqjbg2qpnjvfbLDhDQPkUfH8czRqguQYH75gvc0n/cL9iq1Xkz4Ou+1eHplDEjUQnAoCAv08ZygGHHhbxXrAQMup/mL2wtJ3LMw= 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=WAMneQLK; arc=none smtp.client-ip=209.85.208.51 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="WAMneQLK" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5d3ce64e7e5so555994a12.0; Sun, 19 Jan 2025 05:14:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292455; x=1737897255; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YCCUBNWASTjznoIXvGN8A5Fk5P/E/6o9JpFjC/mi7rk=; b=WAMneQLKX+/5n5IhDIVxu5jpxoJ8w5KtN4WCqDl/YPqiIQA+ZI6NvoaESnkBq9kmOx Z9pA0kuewrVWrE6pbolMdc5U+/yxACbJqrkjiCN9xv5txCrNGR9czFDhhlVLTqOCWY55 zh1+RkXnYG46W5GOizH5b0zhoyyg5nnWWjpkUHrgaCDMusnzo86zI7D8RwGBq6ZJ2qYK fAlsVy+VXrQDiZCiI9wDNqseKMvaPlT3nTgP4mxDkuTeYc79FJuwsecEiYLlLun0iT8i 9g2+6w/Ycaw/wbcWPB8RI/NCS8ZAcljsFd9e4o/LR+yfYIXrEHcd/4zXjbZxG2U6XphS fcOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292455; x=1737897255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YCCUBNWASTjznoIXvGN8A5Fk5P/E/6o9JpFjC/mi7rk=; b=QbjZE3ON7V8PZy1+XKo2AMxnCKlaagLzs3ve9xlTLIiNA7EdC8xaV/qECfNpUTuUQe ZG7NlEPa067xIHCG2eyAdR0aqhwZNnCZtNJootk3G/dpV2tjHvidRroPlrfGXFU46Hnh 7WcOUIcGuP5K0w791ImH7vJqk06Wguv4HGo/U1Bgs6DK+1yL8bJspmPeFLhHJ4NUkcst CWE+AaNXLcuzjuQ1wY+IYFyIWzO3Z5BWEDnRmo4UcZzoevCE3nie5ofv/1Mnm4V/RXbU nwPji93le6kwAdBqM8zagv2SEQrgexEOa0ZcB3hTdLF96mbpd9xF2V5frzXbFNxV33kE EqXQ== X-Forwarded-Encrypted: i=1; AJvYcCUDWU5VpnFkOBiBlh7S/frrwDvmFx/nns6zbGPQMQU6V9LSq8P0Rl5KpcaSjbIDUeUek6CsBoO2YrzB@vger.kernel.org, AJvYcCXQKGTk6vTgPdo/JB7byoSdAUDf8EO1p0KS2HKBkYRnJumRodI4fcP5ZxzEvh1zjylh6PLCj7eKQqcO/w==@vger.kernel.org X-Gm-Message-State: AOJu0YwQ2TcohOdnk6ZlzksxD0DV4tmPq4n3/BCh6o5PEsQUnGmKSYPf TXvIwYlsFaObddqjCAZdOuaIGIUNr8d8jXEIXK08Jb8WNqErhEOg X-Gm-Gg: ASbGncthEh/mCPSCDUH/lD5ZMww4J68NegQ4/DUDz7qfLqY4VUUcKiwo9pfmAsxoStB e3RRZf8B0iTfzjWTgTO25oszlv1jRe6iP9wx7GUokwiXDvyqveIBVGSZLNj6vlCh9uqJJxqBppT VjiRRBH2NnnJj6okKkrunGjFxLpnjuKmqx+1BYQtOWqscivfaYDidXpDfqxAoAIG6r9HHQipwsG Q6e/vgo8aCNF0fNiQdZKv6xjBpJ2RBC7GZ9Rs8wP8NAntFToleZaFi73d2YNB/1/rC7pW/hTD10 ii5v7lo5x/j8GW+bqfzAi/dEP8y0mTuSvfH5fG0O X-Google-Smtp-Source: AGHT+IEzMxVyBIYMH2rTEmj0ysUnUj4pxn6lE5tRahZTA3EvhJmLUlV1xK0boOcSUGCFy5YXWZEJ3A== X-Received: by 2002:a05:6402:2811:b0:5cf:6635:858f with SMTP id 4fb4d7f45d1cf-5db7d2f8aacmr3152457a12.3.1737292454640; Sun, 19 Jan 2025 05:14:14 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:14 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 11/12] MAINTAINERS: Add entry for hid-universal-pidff driver Date: Sun, 19 Jan 2025 14:13:02 +0100 Message-ID: <20250119131356.1006582-12-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the MAINTAINERS entries for the driver --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 910305c11e8a..0a6ee05b6467 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10212,6 +10212,12 @@ F: drivers/hid/hid-sensor-* F: drivers/iio/*/hid-* F: include/linux/hid-sensor-* +HID UNIVERSAL PIDFF DRIVER +M: Tomasz Pakuła +L: linux-input@vger.kernel.org +S: Maintained +F: drivers/hid/hid-universal-pidff.c + HID VRC-2 CAR CONTROLLER DRIVER M: Marcus Folkesson L: linux-input@vger.kernel.org From patchwork Sun Jan 19 13:13:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 13944457 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 EE8131DEFFE; Sun, 19 Jan 2025 13:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292459; cv=none; b=KM80tOjr9NLN1cNJG6SmwjEcBPpOJtooJ5JFkVoeef1QynIYazm+q5DojBnz0V3wumRQc9bEelEtdaUqKvqq4Ou2W/P8BpcHd+zTGz2LvH+BoJX+Uob3wEL1UBCh+EReB0WtQDzdsySBUe25BjIe82Kv946y8BkT3w0ffWCIxTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737292459; c=relaxed/simple; bh=baKIhE3EwBlffiv4Dx06TQfFD02Ta/s4Hjza4/+CU5c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s8L77Bi7PVqDZ2ZI4paWTUhXah1BC6fYFhxJ3NDMwK3zci6uFP1NXVJRgzb2vsJyvBrSK0MJYZffy4NssoLu1aoJxbSzFcTbttwqBHQaP5DbcqOe5bim3WW12ST8NjS1QMEHMk+XkesxmJVs1rYjoItmSJOn1uoaHkq5SKS/+QQ= 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=OUjg8cLu; arc=none smtp.client-ip=209.85.218.52 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="OUjg8cLu" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-aa69599b4b0so56165766b.3; Sun, 19 Jan 2025 05:14:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737292456; x=1737897256; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oxPuw0e1s36n/dMAKXeCayCcn+ITRVITseAsXfLW/bc=; b=OUjg8cLu0fU7XnPSm7a1g3sqeeV/mEWdDF0FVnOZ70SDtq1ZgcahbOJxr2qGFn6dTw aYgb6bNlxzwrzIs81H8BcW4Tc7x9yK/+jWbb583bTxiXvHwc5GK7f/V5WgV5lSXbFNoq zwf/gVcRowNOP5ajRsYNeWLvq/w2Cn8+6EBjchoJbKfPM2gCAgDRFrVf5hJQ+i0iJbDG OJAWQS3BomH5CRp1Hr0D6uzg9VUq8I5Mu1FRLJvijG0EJJVqCbU1JYCb1OZLA00Z4D3T fXeFsYM5D3hM9sgxPmyRKAT4PEgY0UoUnOpdwZbECJ2acasWEAQuY84CYYhVhuYueuUC //8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737292456; x=1737897256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oxPuw0e1s36n/dMAKXeCayCcn+ITRVITseAsXfLW/bc=; b=EKEOiix6j24pJxgFWpjT/sB+R/C4tY0oS1wSx2bLr4R7fq4GhxtA8UZ/AZMrPMuK3w iZqA1SCUKhMMl2nbqZJxSKZwgzX1B8HAXYG1Km/7DDvpgWEBFm7C2D3t+4Qoio0Mufd2 X9ronrQLrXTApDhUrJzeTMdh6QN/7mMgXr7S3pvHFco6Gvx83y++9kOEWoUncSgUjbnp AwwjcACI1Pd9oZSUIuMbzZKJLyeTVH8QJda6wBNfaETGgUvJk6TfSKa8ZPD95gChOn2S +Mm4QbOop24cET8D6i/KfxL2hA7k4Qt9utd3KetCT44e3ItDYI3POcdMAat6lBuyvTlv fRTQ== X-Forwarded-Encrypted: i=1; AJvYcCVktDIX8PfLZxP9eqTs+evYvgISKRL04UMmp8cezOLiE61ASQQ4+oCurc/7cUiqnGCuyr4QekWaESDwVQ==@vger.kernel.org, AJvYcCX/kXTs7y2qEwSwEHk9j3084heNuCng15eMliFaVqFDrAxCk4I+BlmhDVPglQPk6lbeseu31DpCnTU+@vger.kernel.org X-Gm-Message-State: AOJu0YzXZnqQb94//16UMBz9Ct9io3PvFFs5AEGgyO/REAFk7eZEzVtQ eMT6iTevYucewusK2F+IwFlHqFsQpYxgUZAbml+CTh3nVwmgbnnE X-Gm-Gg: ASbGncuozoGlgCGOgIbZQXH4dIf2enzmcmehJWaJ7mHBzB2iop+YPsDnbtC78oi3DQ4 D+6PdC6SC/rEe3KKpRIgK7TxaGQ/jzq1Si9mUZoD0OJigP3TdkW9pLRlKa4F2p4HvdeFfRhWbRO CiA0oP4khYEB0jANFysVI7UNxl+XokgiqYi+9HTso+OUDNkzRgtvDIC+cLp9PbGoBwOZGrlMRK9 9YgidabzHe68MHeO1Or6tU3u5q0+ylu5Bw7tLCDGQZyTDGuTDtPuMPi1xgNmZYvLaggOeHJI5OR 7Ht9Ve7Z1tJxKh/ZeVXJvB2JM3iBoh6HLie0W5q+ X-Google-Smtp-Source: AGHT+IGO2yZVSbp6iVAMIJlriJ2AKiGMQ29nynehDDzivNli5ihEXXyyXWHh0FVbv5Ver1iz6qVkYQ== X-Received: by 2002:a17:907:2d0e:b0:ab3:8a8a:7fff with SMTP id a640c23a62f3a-ab38b2998b5mr342269366b.6.1737292456056; Sun, 19 Jan 2025 05:14:16 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384d27117sm481155966b.75.2025.01.19.05.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 05:14:15 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v5 12/12] HID: pidff: Add PERIODIC_SINE_ONLY quirk Date: Sun, 19 Jan 2025 14:13:03 +0100 Message-ID: <20250119131356.1006582-13-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> References: <20250119131356.1006582-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices only support SINE periodic effect although they advertise support for all PERIODIC effect in their HID descriptor. Some just do nothing when trying to play such an effect (upload goes fine), some express undefined behavior like turning to one side. This quirk forces all the periodic effects to be uploaded as SINE. This is acceptable as all these effects are similar in nature and are mostly used as rumble. SINE is the most popular with others seldom used (especially SAW_UP and SAW_DOWN). Fixes periodic effects for PXN and LITE STAR wheels --- drivers/hid/hid-universal-pidff.c | 9 ++++++--- drivers/hid/usbhid/hid-pidff.c | 3 +++ include/linux/hid.h | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c index 0f81df9a019b..c0f890e21521 100644 --- a/drivers/hid/hid-universal-pidff.c +++ b/drivers/hid/hid-universal-pidff.c @@ -165,9 +165,12 @@ static const struct hid_device_id universal_pidff_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, { } }; MODULE_DEVICE_TABLE(hid, universal_pidff_devices); diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 25ae80f68507..8c4eda67bdb0 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -669,6 +669,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, return -EINVAL; } + if (pidff->quirks & HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY) + type_id = PID_SINE; + error = pidff_request_effect_upload(pidff, pidff->type_id[type_id]); if (error) diff --git a/include/linux/hid.h b/include/linux/hid.h index 5237f9040950..fbc1b6e46e0a 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1234,6 +1234,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) #define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) +#define HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY BIT(4) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__)