From patchwork Mon Jan 13 12:49:13 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: 13937288 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 E6A5822A4CB; Mon, 13 Jan 2025 12:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772570; cv=none; b=cjWeZuO445o12b0bE8LF3uYC8017NWLEfPk4YX7Zwjh2B1B2JYjEBjdtUvn2yrT6yj10d3WRhECpvGmrKveHtYIFEcRUYVYIcrWxqy3YdK4HKE8zif77t98mO4M91KXLNtbXz8QyKZDwerfkX8Ty467eoqX1dsS3gGOR9z7m5aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772570; c=relaxed/simple; bh=jDcU44t+RpJaW8DPohsIrrmW08J61xcy+LYp4sKM5TA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RKvuIsXNvtmR2D9tU/6p7+t/mTv5FVvUR4oxWPNjgaXaA+ksVVt+OLRnjvuqexV3ssaSZwe4I3TOSByNYtF3Y8YT7GEMOTBmtoxYNi7bYpXxHFx3AwZRGNU3Bi5nDT8kuUV8Io/Hz6+hxX8/0W7Xe8yr9v5KurtNfFrFZIuaUEE= 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=EbojYvtd; arc=none smtp.client-ip=209.85.208.169 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="EbojYvtd" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-30241e6b540so2731081fa.3; Mon, 13 Jan 2025 04:49:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772567; x=1737377367; 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=aNNAyMRmshrubPz9yPwpc08vZXKHWV883jBnZhjOG0g=; b=EbojYvtdC67BUsaNYrOL+9Wvyzh8lmDZ95mWd70oL8IfNy5niAsgwTHkrFg6LZG3Xw gygnpfKrSQiqpNjn1zbLwCFUd8+4nfwbK/EXzj7cjMyhrcrYru/O2FhZI3TaSBVeRNcb Ugvxy/ehXaTO5HOkztUdy0SjzjBZ1zn4RpIgshm4lzX7apXoKRo5hAz0X9XiIMSqZFWb vLoSihWsZ3cKZHiaH3ivnNmyDTJApQr8WK9JtQBOOQ8KwTdYlkrf5XNVR0jteNi6iXpQ sHyUmFSgX3m2/dG6bKlof24a7TKbGjltAKDi9UdzQGNwQtNRKc8GIFOU+jQmg29ahue2 1/IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772567; x=1737377367; 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=aNNAyMRmshrubPz9yPwpc08vZXKHWV883jBnZhjOG0g=; b=ezOZ3BjmNdXIUKRrH/bfO1EEe+s7gb2wzdyvYQxvMhi1psLtma1IRbJwI/MIwA9TI5 dUkQvJ3Hw/iHnhKBAw2QOxe+oVcgJLZgK07OvcnChctvvL7ayQNYFeDmtPByJMEf55Fe /Yz4exDJWw7bugnqJslYZrf5MZddvgwKcBWNiG1jrIN5CDIYcIvnlYWMKhcbgbTcjWlv 5wJ1rSiylu8AauArMClHW9be8z2slL4bfAicNziHCkodT6+Xqfgy+2MPYUxkRP1J54JA hGy0K5o68455JseyvfZVuMKA3RCtwqv79ykpnv49eixdofhJOUfaKnTynkw0ggHtt6FY Bz3g== X-Forwarded-Encrypted: i=1; AJvYcCU4gcUiInKN+C9ZAuVwIACu6WeP6btXI0W8oZbxtblW6SRmUQR0FIBIfMLRaKDTFgNXekhanh2YblBlOA==@vger.kernel.org, AJvYcCU6XFn4OPHy5jDWhQ9mH8RTi9tURoCbZsU4IcKe3MRt3n/kLWwLntDC9yrUiTFXCTL276EwciT+o6S2@vger.kernel.org X-Gm-Message-State: AOJu0YyWlxG0vyFmlsGuaWj0+SDwSF/nYLPrsYwNVOcd+zhBnbewW1Qn trctSGehRnUyTwH4pSvOaWnJngyUZHApSd0QRZx292Ic/v9kj/R0p5vy8PfD X-Gm-Gg: ASbGncs7TEwJkZkMU6/h+ucsxEpJA4gUgNcyCaSd7OKIlqCngsmwjk3/ArQTUXzGyGN wsqWYaE8HdAHtiSoeTR+11/+xyPaHBynsVIYd4Cs44X6oFCDpjepKbQkC7V6edE3AQF574+B43E fvW7vKTWH1fWLl70jgVVWjEPOaxCl7eAM+P+eDAnvuj+Anje0RTi67HyZ+kyVL+P05n+DoscG0B Icy+HsGMbe6Yb7gTm3D9TTUWmvXIlvSuaNp8hKuS/iGlscb1Teu8mAVWxjgyLcZlZshrhzOxgos uodg1NxY9p8z3Y7IUIObmkCnSlY= X-Google-Smtp-Source: AGHT+IFCqHtRA8LzLykfDnW2G1hxZdh9U6PjruFMBcdicLPTnrhSKu/hLYDMDOa3EJr2nwzIVuM2pw== X-Received: by 2002:a05:651c:1991:b0:302:40ee:4c34 with SMTP id 38308e7fff4ca-305f456c8camr23719601fa.4.1736772566770; Mon, 13 Jan 2025 04:49:26 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:26 -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 v4 01/11] HID: pidff: Convert infinite length from Linux API to PID standard Date: Mon, 13 Jan 2025 13:49:13 +0100 Message-ID: <20250113124923.234060-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:14 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: 13937289 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 F357B1C3BEA; Mon, 13 Jan 2025 12:49:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772572; cv=none; b=EyGkkkjzDNgaI5ApRJwt0attjTB6HbfLZHlOyvi54fkOgJ/0wVPLhibyP8lsclQN9/94mxiLrXdG8Q7FDXRFZheU+3+XvnogeAAE8NEVBGCCgBzjnmuhKQT5E7vVU0E09nJKVdFiLnzF3K4SXluYSfwoRy4NIihhpK7tNDrUgt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772572; c=relaxed/simple; bh=/+jLhZcLoQEgUQACr+Amn7gI2OvYFrMDEDkQ6DUX/ko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Eh0p4xHAqWhStw24GxgD9Q8o3iS2QUmU+JuGljwAi4mLBOEzbsZoovv4wcp9RyizUaAfNlC28XqzoiZaxtW1l/puq/1QLMaUrb8AcTjHQncjDzyLVoKH2bleARPCKLFguuL9PXAhaLHLQ11k5JW0xDVbz/w5jwK/8tNoeFOmu+w= 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=CcKwN8x/; arc=none smtp.client-ip=209.85.208.172 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="CcKwN8x/" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-303548a9332so1879911fa.1; Mon, 13 Jan 2025 04:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772568; x=1737377368; 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=3qGnSXpK3gnCtwYCvW+DUBbmmLGb3BYTBH7tqE4+zHo=; b=CcKwN8x/3EI3J+/vRjJTbcRsgOEXpLzQfi6pNBDiMRKlRx0HH2034cqB4dC7Xoz4jW LE61EfJzaAqI4vYaqNnCfOrfRY8z4AvT02AUzebw1XPnuwsPw7nz9oOeWWvwYNUB9i+k AX3wuF7kQzVHtqz9Ts+KDGnfOrY+P4usLzOmnX3Zwgnq2haVxtqD8tXDflftjAzxV0F/ DqU8Qu+dUDsM/1OvE3HNdVkz58hh3IQ7oSfJjVtfioX0qhp8VHhDKDhpsQNe/IH5gGO1 h/hpjgJNi/qn+bD6R01ZNopmVqwN1losbUkpS23jSI5QrCdk1topU5ND1JdBg33JVZw/ hF2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772568; x=1737377368; 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=3qGnSXpK3gnCtwYCvW+DUBbmmLGb3BYTBH7tqE4+zHo=; b=AKaQsUzShDMjcNhQ11QAOvMLj6PleMWLgxBnIaYogL2W/TrS5ggIpvhE0a2Zo+yjM5 iPFUSJJXqe9+IToXsNBKc5s58kenrDqNHpoxUDBgNnHknXiuvPZzv89cQTH4DnTxISK1 /SIeqOqj9IOSJZHSUJdsWoNq0wTQqnDYwsh/bOcQgZYo+3B65oDofd4bhKJ53SaznGSK gvolDeTPQ+Mozt0soFihTatDUXHriAeJq3duI9W7Ngi7ZIb3IzU+ybJy7+b8s8vW7JW8 zYzYkrJf1XyfsmWQKnNzA5/GdF83gzqn+LyeeWlNRtSzflebTORZXW/A+ixnEgG9sXLt aHtQ== X-Forwarded-Encrypted: i=1; AJvYcCV1MImRncI6olFup3+zMHeB6431+hrBWz7YjbrZo/9dt5KzbLdcF/1VsqmWQbZg00QcqMSfD4mX0YB4ng==@vger.kernel.org, AJvYcCXWpFe3Vv+qEfeNsUeCmSxc3xF7B3HI5dxl/O/8FsiBOULqhYNncgBItqlcxf4BUH2l19KXXEeXvppZ@vger.kernel.org X-Gm-Message-State: AOJu0YzD3lGw2aP2goIlkguCkd//5d6+YjxhU8XETVFfCzgXPB+vM9lo Mug3dO+9xKx8wbPIlYwMztslqjNV5Y61w9lz0ndqF+H2ydiowYk9 X-Gm-Gg: ASbGncvCbC9fEKXSt/HIChYWUvy61e/gll0rhSt/36rN35vmZmX6lEnwhK3ejMoxIP/ nkzWRtuuapq7XzYVMtpGCKpNfUe8iI10P0ApwewWrIBMCzDj4IM9PdA9eS6NegQGv+UksoSkrvs bEnh3XpIZGVlVLZXdn7Oh9e3SzFxHTCbtJgVHzSEhs4gRH24m/YnXxfDrbIRbFQGhHq6ITuP7z1 a7pkwblhovbLje12+dWp9DdBeBZwrYL5Crju+Re142szKRD3jvZKaaXZmSi7fJ3Tqyrar2cD8F+ IrJ1ODGOIzBWkZ5SBAr36zu5lNQ= X-Google-Smtp-Source: AGHT+IEf1gt4wTM7Wp6+h7CttpZ0BBPYilkBhC30/6Bb57FoZi/MxkP/pDxcaka/6S1WlkrEAQLfaw== X-Received: by 2002:a2e:a54b:0:b0:2ff:c3d2:b0a0 with SMTP id 38308e7fff4ca-305f45591d2mr22451381fa.5.1736772567947; Mon, 13 Jan 2025 04:49:27 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:27 -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 v4 02/11] HID: pidff: Do not send effect envelope if it's empty Date: Mon, 13 Jan 2025 13:49:14 +0100 Message-ID: <20250113124923.234060-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:15 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: 13937290 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 4CB58231A37; Mon, 13 Jan 2025 12:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772573; cv=none; b=F0MJVhVTfOghaBP2bbZeudX+H49sW3gP8qvGMb+k6+nljCrhy/Dh4quI1niumVIRACQXoFj683E9e+Iah4aFzPD8dUt8uQF0h56RtsjxJQLY5UGNoIl0LWRXm81JHs6nrrby405wr1rbVwC/GoXYa4Wt0LMn3BU78a9Mw/dc4aU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772573; c=relaxed/simple; bh=uOwis6hlmUdqAPx3OOxs0TSSf9/smLnpoV7RYqQCfiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rUUIL2QfBNoYArwgLbUK2DLwL68LL4S22Nb37Kwln8vAB4YJlLnnP1v7VggJ/MhtrdjCdX5MDxLOE13J6BkQnKQWWj+PnSmUNlKmxKeDCaj9e3/EUMQqcnsDyo65IWtC0MP+1GnJTh1K4KpHRPLNrE9S+dWgiwhH5U/ompBwMHk= 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=R0BTyP3H; arc=none smtp.client-ip=209.85.208.173 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="R0BTyP3H" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-3021ab1f26cso2044861fa.0; Mon, 13 Jan 2025 04:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772569; x=1737377369; 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=LSwTM4rkg6mTg+sXCxlqhdfHW0+DFt/7r9xemMl90Kk=; b=R0BTyP3H9epmYsmdtkBZdHaETrWlKQcYwu0qCr5LultUPFUrcUu38hhAr1WNFI+oPy Pd5jl9Rb3uYQ01w6a/AO9u7PuTABCmPt+5VXrMtsj6hsztDJnMcTy9KbpWSX88r58ymd Uq9yeBbC5/r5T/uDnszS/rBYxMPNwgtDqFxYcO9GZ7jeJccAAZXB6Q0aAObCdT43FkxB yb5kCxOL0dawmTQNbw2tb5oQnLW7oqnyA9WWCz7UMU8tdY45ReVMcvRbiLsGa8UMmSwI XO6UrhBBhnx5q5gAvH4/QbdOorJMiYiPmJl+7yc9IoUlgjBDuX9NNaL3ZC2JPoFewPXV +Vgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772569; x=1737377369; 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=LSwTM4rkg6mTg+sXCxlqhdfHW0+DFt/7r9xemMl90Kk=; b=I/c73M65yKZ6+mrnQ4Gm+cccbdguC4wZXwoAd34xpv2GRASnZB4HTljzvFbhrhSJs3 4S/gI9oxf/uzyapuEX7wjKtPpcmT67ocy4BsvN22rKV7zpuTjOHj7WC5skOrMEsRWYCW uS5sjqwgWsPlcGHCI/FfLtItdcZc/W+lFsPPidMCT1/phctbPgQHjyApJRKdPHhaM5sB mv5OxSD+CAmcQ/09cNHhIbAgsABxqRs8lKdNln1bN5U4lq8tyojW9LEbbXWt9qF3PtOo X2Y6IeXnsA1Q2pdtktycfpfDYA2aj24h2jD7YJC10Y8jmgWzmMUHEgBlxE9rb7CVm7oX EdHg== X-Forwarded-Encrypted: i=1; AJvYcCV6gq1XFNxVhy/VLUMyvDFWAVu+JmWPh9p8ZndfCcOgW4qGFIur6XbHzFEToGa8odofU4+x/wxOAdk7qw==@vger.kernel.org, AJvYcCXLBKSQPBvrTmZVPauSi8teCbBTxHTvYaiabTLS20pb7ZTbOfySxEiViq8isjTtLo68cfceLM9UmARm@vger.kernel.org X-Gm-Message-State: AOJu0YzkiICl2ULAHy5k38hBG+XD+4YzlbF34Tqx5nDYJYNYSnnLgfZL QuQQDEivtGo6c0nvIULvuiIEAa+Q9aa/ldwvAdNqH0ySOh7uGS9fY3UOq0IG X-Gm-Gg: ASbGncun/MWCmjJw8N9m+AJlYFpoiRiYhhiaYgGUUiXB1wfE+1aX0jfsEXuX5TRZ5xV 25+QOSh5RWaYVfd2Lte3oPH8y8CSgWjvANwjyfJlEcGYVPyBmAjSE50RgWGZYBppuxLO4VIxKRP AF8MJgEP8IAhYefe6UyqP7eecCPFe/sxF+hKwQ1O8Vvn2KF4J0uxbOSx0vWcuY2qdY/7fpYbr6D 6JKAAzL7tKAkSAlryoaSuyMTNVQJHEcYHEq636GkpU6C3J0u3yCKKFoXV4EALPedOZun0VA20av 6Vi1fPhkBNoJAGpDBHZM4eRNm4A= X-Google-Smtp-Source: AGHT+IHiVd2xCGBg6PTUNYGR0as/ejQpqtdA0mnIhHJS9C7BEM9tFM1+vhSkMEzCkw+WO9Wl2KExmg== X-Received: by 2002:a05:651c:b29:b0:302:2bd8:2685 with SMTP id 38308e7fff4ca-305f45cb6c2mr22485621fa.8.1736772569106; Mon, 13 Jan 2025 04:49:29 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:28 -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 v4 03/11] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Mon, 13 Jan 2025 13:49:15 +0100 Message-ID: <20250113124923.234060-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:16 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: 13937291 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 1A198231CA4; Mon, 13 Jan 2025 12:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772574; cv=none; b=LMmHg5k7xrEEDzJHyEgWcqp7h/2fhl5laZbjHHFiCOXTHjmYwqrAqyix6eLeKAanddi7X2L5Ie5/piomUoKxljQiuA71CPtFzpxrNTovQ2a+p/qlIpukvg/9/F183T36Txjgiib+cAgZVN+a+VEAJ72loYBS/i5jZM5zWonSn54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772574; c=relaxed/simple; bh=+d0HyMNOkMms/+4S3y7y1zKcr7KT2SdwpQQHRu+KIa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kbd5N7Jf0buI0IRsDvFcE9Fe4i18Cc77IWusTaVv646FN3Qp/X0PJ6hhu47mZk692RSzrSh/NUSBHNH6WiGtnUw/cViPxOJBxZl3zguh47Ra6EGDGbpMpZf8c/LN2sfGYG4gC6m5H/u5LY4/wrO8Br8ZkBcRAlmxH06N5/08w6g= 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=cXPYvudV; arc=none smtp.client-ip=209.85.208.174 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="cXPYvudV" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-30167f66717so2493891fa.2; Mon, 13 Jan 2025 04:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772570; x=1737377370; 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=zVDn/ZwrDtBQBWFoygwf2iIYwvUq1iC1Us9noUk0/hs=; b=cXPYvudVipuf2STufdhAULOwXwmeMO6XXaD+F15O6zdY/LsQOkIFT6jYJwc5T97wIn wGm77avcl3IzaQQUU2dIhH6iFCWk2ipqIbJsRLV3KIY6LJf5IlRTSLKsj0RGwLhSpmWk e9HROQc2G73jI6LtFdaLbKwkeXqTK3PTDShAoRJD008BtO5KcEjb9QOH1nWnALZgIpuV T6fZ6T8jwXI2FfW3AU+4uUtWRS3+9OzyWvyn7oeDBC5w/xeJ45LaBveVZpUg1Iut4uyj uxO0LFJ3Ofr97vloPqOmb1bBYoh+cgSjTHU1jtK5kBfvonWOTFqcU/DoPrXrAnBFWJQp g2tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772570; x=1737377370; 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=zVDn/ZwrDtBQBWFoygwf2iIYwvUq1iC1Us9noUk0/hs=; b=dJJ/eyzb7keLP7vLxk1XOwSLeBtcUiGzomWo/cJ/9cqnQWoUBa7Cp184CWy0F+O7qQ Nf69CqF1/Yt5X64uajlD5NKXBuLbTbiQL2n+KoHavk6GpHs1pzctB0/e6WH2oKlXBmpx zQA8W5N0uu1+LWQKKGYyl/MGvz3A8SxZkue/iOWoy9Gs1zxbByaibHCjOdTDEVpHIX6x tdUhht4JKD2vBclWTyNIMTm30qjBoZ/zb/DpVM0tMQJAc7sHrSVIvLfFEGttVtk6/frz YgdVhtUW3NO6SV1JxSb9GKbErzdrKBDI9DBLCs4eYP+TADXPKW9sL3q38aBjYWu6sxsD dK9w== X-Forwarded-Encrypted: i=1; AJvYcCW3eQdHr23X4Mq69sgqY2ABJBCIWGGiBGmABC5DnbiqHRtZhZdGiChKs4VJoqTN07C/YfrdcEubAGXv@vger.kernel.org, AJvYcCWo0Zeji/gc5Wx6/3pnF+P+uJUrEkgoNSkkrhN5lnT11erB1cn3zqpXnxasBzzOPGKjyg3iMB3H4RFuKQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzcFmLnQO13alp8VEGI2ZKDm7nndklEPhbLOcLvd75WeW1vWbqP 219RK+Qc47A3hier9V7vaVVAdtRiay+akMtpAQUlYbKMWsBnNFvEQlgD/E54 X-Gm-Gg: ASbGncseh/GYsedHFpQr5wMpbL96h5r8yyTMWTz8/1m+peW/YzCqGSagzHmxmxjJpmy 7jCiX+k4PWAh8wasXejNyxFQm0W82CWu3MFAoy/GzyjUqPJP9cA9n7FfTT2+Mi8CycFlnlJEOip ywDAa0SToLNs4S/+UiWf5gqn/lvM0v/rkOydjzTesiRsbmMxKOIQY2cqIBV88RhR/TREHH4YjwW H6X70ToBoSDtJ+hLMjqMAkFm72ZtAaTb0Q4bI9bRaq3k98vclu5g2ZlCxEGZkOebgdOId6urG27 B41JrUPokjkW0qRJxv496zWCqos= X-Google-Smtp-Source: AGHT+IEe3KYLwI5AcMsLKpiz+B9j/Zy1FZpvNCRe7DrMLW4zHeMF+P7TY8XVEbDZvRC1pFKyPDeGWQ== X-Received: by 2002:a2e:b8c8:0:b0:302:1c90:58e0 with SMTP id 38308e7fff4ca-305f45446e7mr24810411fa.1.1736772570018; Mon, 13 Jan 2025 04:49:30 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:29 -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 v4 04/11] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Mon, 13 Jan 2025 13:49:16 +0100 Message-ID: <20250113124923.234060-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:17 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: 13937292 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 73BFF233D90; Mon, 13 Jan 2025 12:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772575; cv=none; b=PknFZGkDs6Ov5cfDxghfJoNH1NKTIrCDAlgXdUDktG60dHstF3G8P84D3xEREVA1zpDBj92fng8CpmTwaZ4RiSHP3jnKQFceTeV0wYo+7gmFGu/cg9z437z0O/9eac39Je3LIWopsrmUv2BMu5uD1wSY5PRBfWhH2qe4qeypbSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772575; c=relaxed/simple; bh=Ot+y3KAsKJiQTHl+yJ5iu8oBxm8Q1YEO2CdizgQfEQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZmQT01YrYYJ/6A86Lnp0PXmXNT3BzRhDJmhlQP3//V+62OnJiwZZWU8qCaIitKcPnCUj4XV/hmBG1sv8vbY0Cdss9YHX8io6IX5cfu0JmHyMHHcitNPr+2CxyO3sch/2tveVM0ig2+h1QPvePGGAHXCPsNssp1qKbtVpEU9EKeE= 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=QOOUFN/U; arc=none smtp.client-ip=209.85.167.44 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="QOOUFN/U" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-54019dfd6f1so503642e87.0; Mon, 13 Jan 2025 04:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772571; x=1737377371; 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=krUoUcBu6WwcLldC7P4K+sSvUl9VNjkZj8hK1ckmfVQ=; b=QOOUFN/ULuir3NiNyhaNK4LA8osUgzULbF0egcENF+iLYvzhwQ3Pe9yUBtQNEBmFFl MMM+ysZyFk0wVxvsyY9dRSm3PtyPVkWGK4N/goBbQRZtCsNuVx7ybsAODwcQQXZitiUG IjXm10yIVlkf4EFwNQOzYENEQqlbQCWTecrdO96uc0gzkyK2JhiWTxxbWsuP+Bn/LZhZ VBl8wSG0/72pCi/bwDWD0LVfClpQ7rSQsO7DBAaOETg56sWSm7DKnIKT2dF/B+A6P4H6 EAgMaGCvhF2IW8NPkO+BYybsXWHLFLJchUC2B4LYin21ha2n7oUgZ7eOkFpaaXkFuzyc aNXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772571; x=1737377371; 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=krUoUcBu6WwcLldC7P4K+sSvUl9VNjkZj8hK1ckmfVQ=; b=UJFFwoZhqOy2EmaNrwbt1DizEDRVcyKNMmHh5mF6GRb4bVrfV74b2FjCjrH0gZ6A5V m+/oUac25A3wg5xKOiJHaiBKCek4yyTAEJG1GLrTWx8ojPah7cJrLtgOOv3jiaBNCu+K ozho13Yhn8Yo600Qfby0X2ANjvPUj67neymcYEEWLCMAOoMnr4wbMCQ3kiBUg3HknTjP uCAwplHgW0ya+x3YQh7Sh/4w6v2uarrxVD2dGko9sdb1kg37wUARuYmBOteSI7BG/Tzy QhHOpDESa6U5G/2CkTGHgUGiM7B9UtYk8kuM7edjseqsjdfuu95oybAA+8/3h9KcIA3V l7EA== X-Forwarded-Encrypted: i=1; AJvYcCUwPhv2OVuyqDSFj3yeFKUbASs0QTQsETDaELxEkLOVjPhElVNERH73wQbbaGl5EOYaUlPFv+jn33H9@vger.kernel.org, AJvYcCXivc6tCVnsRiyimUDonWsfy7fo7sfxzhKjGdS5YxgjTQu1DmRHj5rGBNZMO0stBOYO73Nbq2MYJTXYRw==@vger.kernel.org X-Gm-Message-State: AOJu0Yyb6XoJ2wL6XhHbDrus13tLOTcLHiljWM86SUGPrYOCUoL9hwo9 bUnXoA7oIuiCy6vyY69Mltkl9fT+Od82jVQgF6OUyVwu/80E2VMt X-Gm-Gg: ASbGncsxgS7WOxs4Snvjnlx/VFlGTRLEoh5v2eaOpEIhr9sXfa0jyjjNJsWnVMdBS55 /VV9JDspgIdI5+zsa28VO68ZzOSmSTaJCuOJA0w7b0rXGDJSe+fGYS2YlTTj5M/xUxOiuXOV6Oo vbviXzLFOcH9YjEEKWhlQRuMbeNUHZqzY9enDmMjmM8cPS/D0QHmQdIChjfZpiZWx4J+1SkvtJv 5NMxQw9omTU/wLqGIFxyN3JMq6QmVLxp0Fb8bBmr874wcMRSkygsuuz8FLscwBKT6Yszi/psw7D uVNjMTC3THpvvj/obStQsU+Zrdg= X-Google-Smtp-Source: AGHT+IHxJkO7EO/2VDGR9wppmTw5M6zyH7tElw1ncOX7yJW+0ZiubtK5/7WoMdS4gABuSdUfOF2LzQ== X-Received: by 2002:a2e:bea5:0:b0:300:29ed:b7c1 with SMTP id 38308e7fff4ca-305f45db428mr26137911fa.7.1736772571163; Mon, 13 Jan 2025 04:49:31 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:30 -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 v4 05/11] HID: pidff: Add MISSING_PBO quirk and its detection Date: Mon, 13 Jan 2025 13:49:17 +0100 Message-ID: <20250113124923.234060-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:18 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: 13937293 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 9280C2343AE; Mon, 13 Jan 2025 12:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772576; cv=none; b=G9fQMgztIDRJINOJn54RvFjVPgnzMQa8VLBlR/C0rY1lzaXGwqoWZJ0C56Dt3LFiR7cis8xwcbRcERQyXPQakzuOHXRTa7xeGTSog2zNl3ReKZivtTUHBzEh2pVhwNZ58eKk33kLi4STPX/0to+rHWByiN5cxfMmbyVt+vZiErw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772576; c=relaxed/simple; bh=mIV6vVTLgoqMdIh6ptgFHVykZQegUSWZ88SkxLdjZS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iajdJv3zNHaI66PHSengWqE4ILxTh0ruQyCrNj0vkL396abGEpeIwoISyANDVhIz4ZDp3KkDWl8WleJS1AqCrTnJl1rXpN3X5W2BHvrwUPLHDiTRjVVjBCk/eq3nLSL1J22HWMGaNVIznBiZ3DtdvMjD4WrW5eJSxIrqGM6VPGc= 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=etHV8lWa; arc=none smtp.client-ip=209.85.167.53 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="etHV8lWa" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5401c2bb7ccso448208e87.0; Mon, 13 Jan 2025 04:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772573; x=1737377373; 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=5AmMrfDKAOcMysNhMtuiAGss7W3D6be+68Km4J+O6cE=; b=etHV8lWakQmo2CQvoOkj2k2zXTZJtV7/w0Xq9NZhMCH9XWarK/XmGg2I3Z5N7L3HA0 FNhiL0fbAuRwFRhnGZ3LMp6DiE0B+tCz62szoIoAqpBI31zxPrFzZLS6VZWGc8va6IdC lcDiq/e9oNxZ4FUZ+YHRPTFJMFgVOWVuoHQ7fuUHgC6dLTapAgVKMiSoLaXs/qy0RIDG V2MPdK/kKPq4OQsSlE+q62090FUjGP9UfFoer3MqwjxLkAGwCg4+iSpVCtVdciuLYnTw 7ilJ1fD/X+Vn4X9JGHieg4qJCRrP6OEY0jQjlodQOvBDHEYhc2nmgyapRdaPk3ZgHKFj 0dJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772573; x=1737377373; 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=5AmMrfDKAOcMysNhMtuiAGss7W3D6be+68Km4J+O6cE=; b=HKFgxGUMG5Pvb82f8ZWiRMZ3TV6MK8lgtO03P2PYebEPaXPv/rCu7vHvvd/Hc6jgg8 XrrfztBfD0JiT47Kb5qFqLG0SIKCTzJdo2vZ5rUN3T0neYjHbX8pmQFzA05H0vLo8gOp J1SV9VNmwUokz4o1CLorj6J5wlu8zwGbxbvI8o2Y+X0bQojgcuM+kbKU88lwLT6eb9fy 74F8hKNGyKvaG649ZdvwuKuDVJUMtivcD9lrPdx5yoe09NHqWldAvzbvfh+b3BuYJYge 2rcY5uEjRw+sBHsK9/OGApcTsu8zzhoJQHogsubx0vCf5qenH621OLDiCedz4N5c1GWc F2lQ== X-Forwarded-Encrypted: i=1; AJvYcCUCCLE0O/fId5GeU00+oTugjvL7gGn995B4MYtdFn90Ans8RaGRacs7ocI23LjOemznb7jOagi33T4WHA==@vger.kernel.org, AJvYcCXNDWN8zUCHoYomEWZgg2JyH0Ss6PiHMQH/kOFnnXKIIofog99b6xiCwMcBm92x/lz3vo/RtJZH1ylr@vger.kernel.org X-Gm-Message-State: AOJu0Yz4TlLXPCi1ojkMso5dkQBm8drH6W/27i5nUluFLZZ+CDLaXI1c Zl3tNChHd2aWZifxTSqIxoaVtSYUGaXCYFo7twqZWrsSBKz6tLNv X-Gm-Gg: ASbGncvpIw59ujkh0lkgXGtQ+9Xovfa80HZ16kj6WBj3TF9x16v74HzPP2GGzJ2uNn4 BJitqF29J21y2l9uqb3j07OZjklzz0hw24SPdFz8cDTdY3VPQh8KJB0lnx0V0vKlaKQtsgUXAld TrXC+wu9A7IWgZyKU05vCaAXPp6faP7RdbOEGDsu1Md81LB/zc+qi/vVeQumOCAi3vmIzjIArVR bxKTE094RqfvXVZpNMKcuQpws1zRWkYz/VDAZr63UPM7XcjS6075AJBhuVQTwhQ3l0r1dVNcZeZ 7NlHnGlJhQk3zClNVpntj925rK0= X-Google-Smtp-Source: AGHT+IE+QVxc/eMSAAQHH3siCOUD9cLG+hVBDAULZS0cs62WnoJ66dhfSz6BJbdIvMgnLki7ksZJgg== X-Received: by 2002:a05:6512:4013:b0:542:1137:6124 with SMTP id 2adb3069b0e04-54284546adamr2330911e87.5.1736772572463; Mon, 13 Jan 2025 04:49:32 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:31 -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 v4 06/11] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Mon, 13 Jan 2025 13:49:18 +0100 Message-ID: <20250113124923.234060-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:19 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: 13937294 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 C3DFC22F167; Mon, 13 Jan 2025 12:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772577; cv=none; b=f9pS0979ka/Bz/8ePkVWocOestR6nwP4ri121lFr3ng6AVJNoVqUdDeAu3cpxY2PtXYkwlkYyBkSKvuIYrjSSyeYvlEqr2H6tu+YW9FzaPSlc9G8TDGXoc7Hch+57wuN37N0EAy0CmOkBM5dGptPU5h/0mPdV0jVvu3owrBE8lI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772577; c=relaxed/simple; bh=xv6/VQKKA0wTXkJKfLOQzDXvF9vfFdmkb7fI5OWPcB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KI/PLaPMB0WJIwpUorgzLOUA+8JuYj+e50uYp6+srNsLEreSrlRHgEYcg3uZWtGskR4rQDSxW1jXqzaRnRRfwUYzcHKmqOoZuNqgZAvzvnJL395i1sQmQw9GymbErSisKgQuoRO5sVlRd2+afQpOyt+bYcan5qZfQ2S6ZreRY8U= 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=WXzoAN5L; arc=none smtp.client-ip=209.85.208.179 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="WXzoAN5L" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-30223aa0b9bso3534701fa.0; Mon, 13 Jan 2025 04:49:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772574; x=1737377374; 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=D5cu8uBGIOCWVagxBiV8PBceULf5DWlODfYWU4tPWDM=; b=WXzoAN5Lc0M6TuqGsNEsc5v9jtDaSwtIoWQ2qu6y4yVBRzTVT4fVzOWiLlrdKiBcTF G28eRnHf9E3nIQlLouqd1FcjqJcmQFlUn9FD8RPNpcNkj98kzg939+quco5h+a9tYDAf U8VaueQ6QKXCU6mNAbzRju3WC81WGme/fpix9Q6NpybLJFYz1zs4clheF+pjTxtVaLS9 lm9d/MS65WHL4FGjVIyNLVBL3Y9RNOa43vzmIfzw0TizIZrbWROTlmtEMkB/6sNXBH4U hufi7OYxsaWkRWNAZE/aGJOJI+d2NlTfB0sGsjTdXXciCWxfVT+Ah7+UZOHNuofrf73R jUzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772574; x=1737377374; 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=D5cu8uBGIOCWVagxBiV8PBceULf5DWlODfYWU4tPWDM=; b=wrYsJQubEVEWtr+98iIy9XPFVsguKBPjyFB1C+sT5+SrRb6DDKUCTa+kNHucwWvwXM mpz88IYe03OQLEHQ/9cre4OJ++3gE3BXp8TkEaxqW5sgwRYE2yPUfryLjR9xHppFvU7d cEutpRanLb6eCn0k1oeIDHGNBp2hDXE7Y/oHZ2mDYM92j4rfKATCeGjVZ5NXSCSrMvDR LnrLBHgzJIHjcFZ/vLkoFBXyenp6CaTglNkjgyT6q6d08BObMTbodTsPVuUXyb2wD0V4 +yv1Ihh3RlvpPRqHUy4ovUbQlphmZI5QNLT4506ntljatLSN+SEYTv2uHworucm3rAu2 Zv2g== X-Forwarded-Encrypted: i=1; AJvYcCUVgw8W1aH8UYqTUsUPgjoapzYG1Q8emJoyo02zcd4Vh8onm4dLNtpQuW/8r8sqalQhgSASu2i7LxFq4g==@vger.kernel.org, AJvYcCUwypbXjwSw65/jOoIrPw2VBOyHfiV365fhiiWhPwBfdyaU5dTckFtsWNJ+5+vYc+eqeOV4stY+oiql@vger.kernel.org X-Gm-Message-State: AOJu0YxdiRESabJSWtxtKC6AV5kEhyRSBxggVpzKhl/JJC8OvCh6p4Kj 5kGApErb33SovEMZBIlFS9x8xCc4CtGqIwwhJObL2vcN01sRLVPR X-Gm-Gg: ASbGnctqOE1dRFMZeklqwhzTb+hzGsmyA93o/tA98H6t2jqgovY9qA/tAKW9fccG5nn QKlv81nVMRz2rIodBRUhRKssZxV59wxl4r+AqydX7+TqFIgv7RgnwYn/pnmKgJd/JO92FyuMV6/ A7RgyHwrA6zu/s3z/IAGF9Lwt46y4T6jHoqY8G9WVyAMC1ivCpkupOE3rxyrupdQlmToqlvCOBl OTkPxr06O49UHbKekHqUqLlc0a2U5VCIkd3ElqirBy5565yqZGJyUyhw/Fg4OPdTJWul9pXpQUu 8RQyo3M2oaEMeq9i9Rf60biFNpM= X-Google-Smtp-Source: AGHT+IG0F/2fvIYEoTGAT8x44dCcAydVTW1FIzhXpv04gFC+MpfV+1CWaqvE3aQJETUKU3/woYS0Hw== X-Received: by 2002:a05:651c:2120:b0:2ff:d396:a73f with SMTP id 38308e7fff4ca-305f457bf06mr19461101fa.5.1736772573713; Mon, 13 Jan 2025 04:49:33 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:33 -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 v4 07/11] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Mon, 13 Jan 2025 13:49:19 +0100 Message-ID: <20250113124923.234060-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:20 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: 13937295 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 3BF03235BFE; Mon, 13 Jan 2025 12:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772579; cv=none; b=g3X3lF4ZA5xuZ1lTaArZqNIjz32Khdwm5mr9LbwAkFufIeexxLmupYzigcci6WhQv3TtvGsjcz8AejkcBI3jDajwxHDUogcnAGZQA8LHYzEJ7uiYdtno1iQ5eWgXxno6fvV4PYuf5CUSRDfRwgDorCRBIGo+KMapSfqWuNzgx9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772579; c=relaxed/simple; bh=IaypjfdSOe8nS4otI9Be/27/cxLcxi0UpgFYsqF8KKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u3wEQtO/mzZZ0Or50AZ3va2sF7aJXuWGOaR97MMQ9X2RxuYPyMyg11v0D2ZKN3fIP0Fxd84JDzAy4KNO/uo1Z+bAwEiliZnr3uI2UgfCPz0QKvG2ej1UNEbq1bFxtHMoUHVM47UUX4e0DCjt0EhVJgBaVoTSSVkdpqp/Xb/J9s0= 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=N6ya6S1n; arc=none smtp.client-ip=209.85.208.177 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="N6ya6S1n" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-30600722804so2546921fa.1; Mon, 13 Jan 2025 04:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772575; x=1737377375; 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=sAkPBKIk6Eax1YHZili/NnZHZkLHuP8KZdGBQcPKewo=; b=N6ya6S1nkH14e6BoKvolnrpU6BLvC8TEvHKEg4ZYKJzcY2PNqf6DUf3jxdgb8yT5mW HsoQI0NUEgx6c6jJRgjZfaZo7wSeyOr/tMp8vU48Wh2TJbjpfbjCGOE4yBQmh5L3PsTT 3vUBd5QwwYcODgM4sZxfFaZB+/ZcNuLjl9EWv+S8nqEdUhxHqJWGRgvAP8t2K/A6SJHl YcdCaRnXDNGZyLpk0L9QCcz4gCKMe16OcDg8O29ak3ESN/KVa4iuSqaIz97AZ5TbWF3E oMXte1VdolM5NiZkKBwzQrH/r8BB4jcxlpHtDZjAi5kj5vecja/qeNNsa5TNN/lbOPin peVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772575; x=1737377375; 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=sAkPBKIk6Eax1YHZili/NnZHZkLHuP8KZdGBQcPKewo=; b=qUU1erOxJqj3Z9k5mS5yFT1GAVos99uk5vrTp1vSZgEyAVgktuGBdOyHbbTwsGppAr D8iNzvBPhh/sqCYuFzRon/D+Uux8sN5t6k+ixzdfxWJopfDNj7DUN32dgxvRp6ssY1cU jFpOZARzKIVkpcq34x1qBy2rftTX0UUwUMnJFoT+5NmtT06cKKZ7ZT3q8YBXyI/mC/D3 2iaDCziUeGnX+sJZL7gVbtCKAzfXKiGsn5ASbJalHCosaMSWTB0ijOh3JvsxeF8Owoea XZDbym0puClqVIv+wbVPHVuBNrYUASoRWa7HeZUeuLIQugRNCNMxvGNTv1Mg99FMykG2 FLpA== X-Forwarded-Encrypted: i=1; AJvYcCVBL5v2XMPilJu/+HD2fHlGatBVtIaI/CSqbt6pBFWqropnu+VckLT0IcCS4+qnPf/VBYePVsvgdi3zjw==@vger.kernel.org, AJvYcCXeLhGWOO3XMc6pjN1hYItWH/SBq25MVTdR5OxEGSaVHiLOIknSdOQlZvJhbunsT7YQBcpyacbdPr54@vger.kernel.org X-Gm-Message-State: AOJu0YxqF4DmYWqwZBBjPoojGMNcA0YFnH7nyIBG2B60K7iysrDPPP5M er06GkphSIFJQoC5UpoxzBgbn1hS5f7xPV2qQk7joqu+V9P30F15 X-Gm-Gg: ASbGncumlgKx3V8o8nSeWb0Sex2beiOOvkQZdjLbDDpy14afjiTdazkVsQjfoe+6Ynt gR5KVdOalqqgN16pLGTC7tOGoRsDwTZxaN98z0FXxPcLIxO6I0AVVsPl44JB7mkNo9RR1MX2chd kqbL2TxWoZ2FxjVc3QzX1UvtEHQzNAKU1b1epK8W6mDlNoN52Bbr2rca2PpkSAlhHYaQ+F07mZe xRU7AKuRYpY/oPQuMRp7u0liNyekLqZ52Zckh6eawY9uf9v6zKXWD8rUjrt9kDDFM3YeyCoD0rj RQ1gCDKVdg3uUU7yfe933hL3VRU= X-Google-Smtp-Source: AGHT+IG30YU4e24YJv9/9dVjXcMTLLOtQm5ebP8+gwTcC/nl+e+sCqpxFXJj547Pur75Pv/I9UHecQ== X-Received: by 2002:a05:651c:1544:b0:302:3356:54e2 with SMTP id 38308e7fff4ca-305f45f262amr23011861fa.10.1736772575130; Mon, 13 Jan 2025 04:49:35 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:34 -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 v4 08/11] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Mon, 13 Jan 2025 13:49:20 +0100 Message-ID: <20250113124923.234060-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:21 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: 13937296 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 6614522F172; Mon, 13 Jan 2025 12:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772580; cv=none; b=lvAZ8hk5S4YDAqneoVlVCmWLN8hUUphC1bSlcpxcgDY3sEc5ae9rH1IavMdHaZOqyjINdYDXnSgEen8yepRhW0hB9vu+0At8ZfAJrlV8eJ2YYs3gLugkm8RzRYFBwmuKPGfw0346TCpfFxIK/i5SNZz4f86P+mJU1JvF0VwLS14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772580; c=relaxed/simple; bh=DTD8npC2tT5CKjvqy3NpxhPsQ+q3o3IVUsvsbOeN+rA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WQvIxN5j0/EUA68HfXy92gDOUvp0+LkIIgJ2gTLNiZg/XAQzc0BZxkWK8yFj0uzoNQnwgzUMWRqNZc1wAhfv4WgIBEfAP+LlGdp5I3K/XgPwk/BaAT1XBvk8Cg7V7LhtAo0lLV9koBMnfH+BK7A/xoSiNy3b1pauY+SJ4flLTHs= 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=HXFheBlW; arc=none smtp.client-ip=209.85.208.180 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="HXFheBlW" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-3023fcface6so1556501fa.3; Mon, 13 Jan 2025 04:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772577; x=1737377377; 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=w6G/EW/lJLx8t/n629o9TjBmdmTTqR53NzQNGoY0G0w=; b=HXFheBlWeh7lYNi27MLnTBEufCOD76xoaEKZYDlPY3Bt+Ena5j1rV88mmKDBOiyEwq rqL8oRExTdi+NxSUxp8mf3aj9Me0p+BMedyd2O5bdHxRbmdXr9W7EhiEvJAkiFphk7Ni FY/4VyGu4EL6Co0jtoDVwAKJOE7cQyoqCTHz+O41x2Bt2t8DsHZvjncopoMj3GRYKGeA qBNmlUmHsD90kY33f/IRtM3c8oWnLrgj+hirFGPgWu2n+hwIxk6QrMOeCqF96azv5j4T 5dwDpGeKch/WndLgIJslBygVnbUHMOunANb9AZyUdwId2HF4spJjpEBDoynS1QvJuRHj nS6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772577; x=1737377377; 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=w6G/EW/lJLx8t/n629o9TjBmdmTTqR53NzQNGoY0G0w=; b=cvZLUCIKADH4VIuoCGLvS03hStx18aNmtq17bODaQEu15G/SyvWEc4vBWSVNZ8z2oO Nrc3NdRgicLbgxyAh/+9DUxwtSNjZldQkgjnhQ3o4JBahg77fwi7ruJa1T0lT0U6aDqK oIbRua/hUfdmCIeuVykjsS68fNsaBlZW1juEjcZ3o7zTun6YEg5xmktErYCrSvtO8nXf Vz/Fe6qH80faNS1etw9KrCbMlVULNTRjKywoTnjtiCisHSnw8FJSSdxe8MF6fULR6Oj3 mkH7abOF8H/cQrSDqYee04Bp6HwA6IPEIZcCTUgMEntPtk1ITdywXxJRxEqEFKRSoJAn o7ew== X-Forwarded-Encrypted: i=1; AJvYcCV0xitJZ8O3u3yMc9yZyKLuVtIsHb2K77I8JwynLasIL4ytEk2xoBzy6s5gjrdvAY8d0OLgty/isnnEuQ==@vger.kernel.org, AJvYcCWFG9myjBJXXLXdTQWxWO8ZU4VXPtK6iisxMqxOI7uezGio2SFX7SrZA7Nta+fgienAD1ONP7hZpyj1@vger.kernel.org X-Gm-Message-State: AOJu0Yx0PvC4QN3R7/HU3ztSM3K3+08Z7bQ7k2ZTBWKJEARPPTucNEtF pdPAry18vv0cIFjRdMaDA3mBtAcOkW5XEdy0KnPV6BadN+Y2j/Fu X-Gm-Gg: ASbGncu+BLJmSFLTh01uVapeFdiTGgTANF1s3dpgJgqLHI4YagHf0CIPbiyOs2T5DB1 hry/IkKjRtME30XUkHXrsMoHSAFCqz0o00Z9RbIY2hSGSDAaQlHuODXY2A+DauZeAF/q9uLUzy1 q8akkndC0gj9h4k3sr6fgz9MwT9FnausmuXjYSOHt0W0M29O0EcA7lK+wWWp+u938GU1O8/darB JOFO1UVKCHf+6+pF2tKmWnipxrMb8X+vQWLEbg9nl5r5ma8qRvTTESbHCifqX+vBBERHK3AuaeU 92zhqMo83m+KDaAbQBul43sbOLQ= X-Google-Smtp-Source: AGHT+IFIMEkSvqj6oZUEqc7d4TtjmbM+Jr0BTlxRP2P+OJeFcgH7J56BnnfoLzj0XBdiHOcybgE+AA== X-Received: by 2002:a2e:a99d:0:b0:300:38ff:f8ce with SMTP id 38308e7fff4ca-305f453a40cmr23660371fa.2.1736772576431; Mon, 13 Jan 2025 04:49:36 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:35 -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 v4 09/11] HID: pidff: Stop all effects before enabling actuators Date: Mon, 13 Jan 2025 13:49:21 +0100 Message-ID: <20250113124923.234060-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:22 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: 13937297 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 BF251231C80; Mon, 13 Jan 2025 12:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772581; cv=none; b=pZi/LCOwTGCj6wnS8QUBk1ZBmI2QXSP7Rtb5QKjyVuUNpaKOv5Nb2v+YbPi3HwWx87P3yCpaVT8dJct6xUjzPveCu2vZ4XVnaS6vjyPy5LvHCdejWLvFg7uaqOjMqZscvfJG0MeKtVMPF8U47Ugd8w3saT7AsG8BMKtTbLsqCQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772581; c=relaxed/simple; bh=8Ai6MHLLfUNdYTV4eukBW97XboF2ZkeyBx2Oclw6RsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gF6QkxGi0hQY9bN0ABgWcu4A1LsIt34OzJ4B00mUCAbwAEQuDJfuHvcCppAfxvfPUtILyLiIXp6GP2kMRy3XVakbnk1LcPFex9EHTx+gdirHZeyJUnS/EyzwNP8jvR1pZh5wBM1mlcnoIdThE18myzbHRtTuMBvZj/Fivb9nW9o= 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=KOD2jVot; arc=none smtp.client-ip=209.85.167.44 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="KOD2jVot" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-53e395932c6so430525e87.2; Mon, 13 Jan 2025 04:49:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772578; x=1737377378; 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=ngugzYbBqdvyqcWs61z02MKyeKB0wNRHW1tziXtBtJo=; b=KOD2jVotO5FkNGugrnTrYVlJPZDVvRWIDkC+Cvon0ZCZfhxUBLVMamaGV1d74l5zDw 1w0Hazx7w6larkbf9/O4wc408y7PFaUXE3QHw7kA0ZV+GLyWl/P0ViE/MvTIkOepzyLL Pl3nHM4UFqoyIw6BpIt0j6BqmSsSHX0xs7VLa02/kWmnTTfyyUVa0OVafwBF7bhhavu0 jG+NHzdWThGVD034D57dg3WVRsf5uBeufU8ySzinxVCU5iix2cjpYwAa4Jg1Ae4qtt/a cncObnoPtM6DcspROnBEjvrFTtErEZmmMiY1munuM7r89nrgQ7A/FeZYz0U8haYq7r/1 fi9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772578; x=1737377378; 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=ngugzYbBqdvyqcWs61z02MKyeKB0wNRHW1tziXtBtJo=; b=xQJWEObuh8MqWXXOJPusEi6idd+zuf13nE+78k0oWCS00z/jcRHnfaRTpYWnBB+Ftf qqfWRhas47tHKLEGt1WG36pdMYal0YF1UR3y9SqMNwVH7VTkoZ59/Vl1AoPVcMhkuBpU 1cgTQ1sX5ZR1oYvZ/FkFEftXTcxMJxJLQE/3PeW89vH1XoaBYOLSDnzzoaChzr/HO84t 555EfiTsQBUUiCAUySmb4DyRKi2b09aeUGJoWOh8TAmukxyok2QkKhenDLI9wZJJhjja wKrXwFt3G1hXU6fueEVWHvsproExWgYOTQ0mNmrZZiESeTBUyzyEj+XHVuJZl/HjUuAo c6ng== X-Forwarded-Encrypted: i=1; AJvYcCVy34t7IRob2RhFcg1OWHzaBEmvq+GbKHPumv+lYX2Uif6vpfmos9o3/iFMpHqh6GmqaS9sBjMB+iLu0g==@vger.kernel.org, AJvYcCVzWOC0hNte3Zi3YTJqCjSSuJyfqaSPgdEHSQtYeIw1zqI5XlgZ2qEsQv8BtFE8UzWFMAnpyeBl4X4Y@vger.kernel.org X-Gm-Message-State: AOJu0Yw4ciFcj+4Tu9FH4NjVpSMGpm3pwNzb9y1A/dRNNuDHtynwGpX4 LWYRhsZfJFzyHeNTX0RoI8oRZlkXwNNzqn6TpqNjl0jnzf1wcXZH X-Gm-Gg: ASbGncuDxQ1g7psy48VAXOR7a5v5z586MWUhhT0LWT/Z1gOZhl1JPFlxO7imCfI34h6 xbMqvwjF6KwXaPNcFEenqP/uJ27ePvK4RUkeDw8BqgHLEfGuxVWpp6c6+m5N0DNSV1/MvEYb6n8 NuHS+6mOf0H5sGAHbmcZGVT/y2LwgesO6KSBQRmRTAMr2/eg4riHVRnoj9pMEVn0GFRpqHxGNOv RdfUd0LwMMdTpdrNqDoUqI09BHGYlrcz0jxwRydkvoaxbbq3O815TNo4C3jH1NHWDy1H/00S+Ne YnhtRStNshbJxMF0nrNsIyQEug8= X-Google-Smtp-Source: AGHT+IFU+uAiO2DdeBkRhAGKP19tDPZB0a7bnA0zWQIIOEzwpIfsMBTTdkHCM7cUIqVwZr+F9SHvnQ== X-Received: by 2002:a05:6512:1081:b0:542:2998:ac88 with SMTP id 2adb3069b0e04-542845116eemr2282255e87.1.1736772577625; Mon, 13 Jan 2025 04:49:37 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:36 -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 v4 10/11] HID: Add hid-universal-pidff driver and supported device ids Date: Mon, 13 Jan 2025 13:49:22 +0100 Message-ID: <20250113124923.234060-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@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 Mon Jan 13 12:49:23 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: 13937298 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 C400022A4D2; Mon, 13 Jan 2025 12:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772582; cv=none; b=eW3dSC8lhu9FSBn0SFuJeE4eryyUzrc22jLad1hogpKOFhDSv/YKJ1EvK9rLsc0HBNA9z32osFAKZaRo7K8WIceszeslv7SE2XHSYndPFaV5bqA0FUQlxXMNtqkIxj+OrOreu6ADgFclucDQ+QyDp+PcpG5YVkVd5yHbq0J9RMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772582; c=relaxed/simple; bh=AsqtBCn/763fag4qo+cCuu2010gu/LUWczGp21PxJdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F7XPM3VTwg/pPc7MaBojUcmb9XqHxmXVFpW9M+9vdM+BAoRWvTMvBnR9hZh0HK+PNQ72bN4qXaLUhqM2wjtGD6DZA+QNZQy8smMljYevygLqNeMVuQB+mWz+2Ru4VlPBanNU3UU6CXC4PmiWW3HzQpdthyxvCs2KD/XRq6CloZA= 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=Mj9BrStD; arc=none smtp.client-ip=209.85.208.177 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="Mj9BrStD" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-30156c52c25so2416211fa.0; Mon, 13 Jan 2025 04:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772579; x=1737377379; 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=dZFzKdNYm2y3H3rB33WTR2xrLGfvEaCqZxtdd9rlq9E=; b=Mj9BrStDYrNiCxr45d9caiQ9cugAiGR55rPT+UJcwvyYiRPlQqrtwKJxNE7+Yar6Ru o0pJaacie+6CtkhTBANiLDrk8DFEvvtq1p/K1c6pYivUo2KVx2vjeheX6P09wVxj8Tic NDqouuCC1gVUJDc5Cu7H0Z06GTWGr9ZHsuXAdxgC0EG5I8YAG4vedmwosLSMKWl/bNKg RkyHO7qTLsqIkfA7L8so7gteSNsj/4A8kvMqrfSalCyoDqCc9nzXou/CNSwvp8ezBrz6 R6kOlqse5CVMExNNG864zj8+v18TmdncHeUZhmnHST2NcN4h6tS41iLZq9/M5RSWPzMT bAzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772579; x=1737377379; 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=dZFzKdNYm2y3H3rB33WTR2xrLGfvEaCqZxtdd9rlq9E=; b=HJN7hh07NBBg7q3BS77h71rIGSVbuFNQCKMWM3123PacHDK4ofmVa8MP76XjTrtYiR fFzhVNr2sO83qlpsvikQT0SEUDK5WSJNss1Lysg9FLIDNhdCOBDqpPbiodOOGCK1U5zz CoXLagpkYnAud9WjDTOQzXBx5dWu845tZ6aFgorZAb9DNPU5z6LV7W4OPYjq/A/D06fV CQBynx1inTAB4g8EtVVFE69x2B9FQKVvpaWA6W2iMzS8r7hjJiNjdfADHx1Rr5b600ge 1VnISQxay1aSpKHybyK7W7IdUYCHRLS7Qy6uMrFZlivrkYsrJdPO62TJWSdE5KOH4eND TeyA== X-Forwarded-Encrypted: i=1; AJvYcCVorj7ofxR4S3/YtjBCDCA2RTt/exdBsmVUloZUVJeWL57mj47BPnEY47rIbWEF0PbpS7lu6UF+deyo@vger.kernel.org, AJvYcCWLavvtvDx92SKDQf9NauBeaKzK4YqG3IAC2qlyQCne+VIXSptMiwZggm/R7CSFxRn/kfA0J8m9zZrgcw==@vger.kernel.org X-Gm-Message-State: AOJu0YyPvZFGcqdvT0HQrsgsWEZ/XHow3NrCblG+Q8WEMciYqCW1ItuA LYq4d0AqSFzFXxleyQy384wAoBSDUUblkiG0psHSIQKSMvvAEFCH X-Gm-Gg: ASbGncvess+5Jv0iiTlJKjuE3QURJmNYTrTH4xPYGYgapM8iNDPTzvJE5Yd78xVQFkz 0mOs+mrGZhF1EV43fcD0tnal3e5k/mV2WQuq7WhcMql0MLEqZOi/ss1t7BybEk05QzOFbRBK5W9 6ds6ulSAT9F/185A+EKZeABY4M3YuH8OC3IDeoIXEraCD4d6K2qQYFBKnhlH/4/aXECMc3OgB/D vqkHYGowpcAOh96A69bstF2l0Mn6EcVRKnPaKz5UDSyHDNnHSB2mHotYr8p7Y4KDU6NywWPnLJ4 k0qJJTt5vCQwOs1MvzEd0tIXvLU= X-Google-Smtp-Source: AGHT+IGYPxX6Ph06tSbiahG+i/xvxxzUSZjFXa2hgtW1G53OKDh3RUuU4CubkFsaL5doUpgWExA4bg== X-Received: by 2002:a2e:be21:0:b0:300:38ff:f8e1 with SMTP id 38308e7fff4ca-305f4543831mr23133101fa.2.1736772578824; Mon, 13 Jan 2025 04:49:38 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:38 -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 v4 11/11] =?utf-8?q?MAINTAINERS=3A_Add_Tomasz_Paku=C5=82a_as?= =?utf-8?q?_hid-universal-pidff_maintainer?= Date: Mon, 13 Jan 2025 13:49:23 +0100 Message-ID: <20250113124923.234060-12-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- 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