From patchwork Sat Jan 25 22:25: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: 859993 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F12F52066DB; Sat, 25 Jan 2025 22:25:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843937; cv=none; b=lJPhz+nOnMpAoOVAGgJA/fW9hAqUmm8Ko5ZGa1R9g1JPHYtRoUvR4N5kFB8P4i+/1AFo0unYRY9wg6zD5PwewL5W7qUyEfv6qXGPcdU+hBN/mUPMZ+5bhmNLJeMC/6ZDfbDTlDhsFLtYJgmet1lUU1Eyng3UqHn1szH9g3TM4tE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843937; c=relaxed/simple; bh=DhKOlDN0J91JsCofHQMVQCBR/3u/HEqZUulpq4EyNyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SAfuvVW+xhvcUL+RFzESyoNedwW634WgsjcbevlzftmHs0ikFFcyIaduAR2t26nzFXGDXzHTXfp8ksDm+FaslkrLyEvZgn7nytW90vn5zJ7dEJlzOb3CkUu9nmqRnI+j00eMmAze5Voa1G1UxpNfuHglSvsyVVAzlDazo9bmZb0= 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=ULl+jr/J; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ULl+jr/J" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-aa6647a7556so63025966b.2; Sat, 25 Jan 2025 14:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843934; x=1738448734; 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=ssFFA6NC5w0PkH/hxlG/5x9jpkiDdQm3Ywo45Mto8CY=; b=ULl+jr/JuhOxZ0meMsSbaCx7oaNpoBEWQQ0mNhAwo5QZAOCtUsVdd6DKCLXUopdg0G /fPFa3VKs5K/fX7WAtJUK+G/yPULFPMZKjJGHhNsKsuYMfmfIeqdyWB8BKCKn4k+mPv+ 9Dyp9Yw1CCYA+UKIaK/t6TRx8bcfc+RNB0xVrVIQsi/x/4RGlTmrz/ikMK3+nSi4x6UR 8/ny8mNRvHKXlqXRAB+6twhrhZy1X4PpSJ/FqF1bPi2Glb3pGWe4zhqjALqSrpaEGbyh kmdkvLoKCjuLyx7+RZrLLKjo1x9lTpOkxPU7nqe88PChwR/+yhk9P75H8NpttnCjcFc5 av0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843934; x=1738448734; 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=ssFFA6NC5w0PkH/hxlG/5x9jpkiDdQm3Ywo45Mto8CY=; b=pC0wTHOW/i7oTmN6tEX2GZcomsy7Ekgkxo5beNnKabRTNIPkoMRLFA10wv4+lsRV15 KzHcd9MlGBam5rb1YTi4d8IfuWeey3Jg82lLaTBby/Gb/kqznTJEaMFusZC/LPUlvYK+ LfQKlXojZjFhycPa4vqzUjLCr9Rk8tYwPFtkQHEWWkySI3ThAP7QTVi+1QilpL0J+AE0 JEL4Ry52QgV+tGM9XM5N2IPFV+TBJlp97XV5PEmf7nvstr1aJFLdpXdJIMZ1WDYBhJtE nqxyYF+tmy9zShuPVAb9gfRic5+wFHRCy8WTfhAC6ggMkeEat8HgMeQyadFXXLdBqfsn ok3Q== X-Forwarded-Encrypted: i=1; AJvYcCV0oLY3vmRcwP+SQlFGloSNusQWmnjUNdsuX02QvO0btLC5CZG0Kd0/a1VhTGZbr6Dhd2qVP+5i6h07yw==@vger.kernel.org, AJvYcCX//aN2c/pDbTeFzSDbezASCneQdTm/MLJ4mSxBG9JyCuKaXWxH/ZfSkP+apyhN+4lbyel466vS2qhb@vger.kernel.org X-Gm-Message-State: AOJu0YzjkjuSATRZdI4Gao5BBedgD21LLN4fY1IIltXN3XpeGK95j9j/ v3cDUxAmZ2QYuWAsMYKxpjisbLA6ose10kRh8B8TNbiV8CqN9me0 X-Gm-Gg: ASbGncuYXVI6vvlT/fX6yoCa709vuViQLsd+kf8Ui0EMTLojwQfWv6C7DYhFh8QHvEN HgOTHwPGUsy61xtQ5anhLuSpLOOJbf/mO00cpbulYWZWe6qjytm/WCGJUXEmdTe2Rtha8+3SRcS B7+unDepwjF9VUuwpgXl6WHz9Wf7KN2qUwrFQZLOmBJwcr1trZ2XvmjiVDqdAJyIVUglc8TFyUl qrsFPSPJyX40op0SZ/c3gp++Xq7e0UrYG2l7p5CZBTleHZbbi+FoenFWGkG6e3xV1R5MPY1Dp02 lMMqEyP1P0kYnsvkT7uk3cPb0oSfU+GWV7xYW4tc+xEgJIXOO4ofmXPnXAL25w== X-Google-Smtp-Source: AGHT+IEQINPHzFomOilX+j16FdHzw/+Am7mg9VZNpIwO3dfNOUVWyhXKJUjhD27p8TpkrcWREsCqEw== X-Received: by 2002:a17:907:97d4:b0:aa6:6f12:aa45 with SMTP id a640c23a62f3a-ab6515b6a78mr563317666b.7.1737843933933; Sat, 25 Jan 2025 14:25: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 a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:33 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 01/17] HID: pidff: Convert infinite length from Linux API to PID standard Date: Sat, 25 Jan 2025 23:25:14 +0100 Message-ID: <20250125222530.45944-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux defines 0 length as infinite in its force feedback API while USB PID defines NULL (0xffff). Most PID devices do not expect a 0-length effect and can't interpret it as infinite. This change fixes Force Feedback for most PID compliant devices. As most games depend on updating the values of already playing infinite effects, this is crucial to ensure they will actually work. Previously, users had to rely on third-party software to do this conversion and make their PID devices usable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3b4ee21cd811..5fe4422bb5ba 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -21,6 +21,7 @@ #include "usbhid.h" #define PID_EFFECTS_MAX 64 +#define PID_INFINITE 0xffff /* Report usage table used to put reports into an array */ @@ -301,7 +302,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 ? PID_INFINITE : 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 Sat Jan 25 22:25: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: 860150 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 7B9C22066E9; Sat, 25 Jan 2025 22:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843939; cv=none; b=IhASwHZ1SAta/GNvg82ydybqpQfeVWLeo9wHhPKMBPkQ1zkwT6u3NCUI1Bv7cZNB/ZeFA9NcjFIF5ndNAzPm3QQDOIlbKstYaPXjw1Y9r55a6ShujPLY/xhKeEJ2gzv3VtB+dbh7KW6GrPIs0z3h49sv+jUpVo9v2ENNqONnlmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843939; c=relaxed/simple; bh=wrRItE2ic9yO01lxSjZ9vLP2VpN3f7PJWhO595t/Rq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FLwkThMhK8dRKKsiyzlP8qDlhhQCK52HgS6roifkFiArCbacaVPMlkuzGco07KpHzYP2Y4DEiulfYDd6Mkx1onGqGiM6B0zygHKgV/SKH5KtIy7urJz2olXoysucOPFUH5kgHksJRZMU13UDWhQ4Fy70RO0H4uRISDryxzoFYVw= 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=RQiQM+MD; arc=none smtp.client-ip=209.85.208.46 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="RQiQM+MD" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5d3cfa1da14so643450a12.1; Sat, 25 Jan 2025 14:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843936; x=1738448736; 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=BiBNwqEUd/4ZH7tEeMX6WGp4FpHjqtvRbtcFv1yfMq4=; b=RQiQM+MDa9b3h7WdE6M78wrWEGcWyNiEi+x4gK/9KRTwRTXCafohdoltVJcMwtCVDr mj/S6ZStuSP3jkrzaE0426m1Ii4KHE3CHLhmv1l3RInzWX587y/nhX9pJxG5xssZwxCk bkzx6QSHgUe0Bp7GeNP5FO3cBYwawbM0nvBEWVlmnb80FMxsroAyMH8b6f2owKyaWNrw TQ/5mJ3T4pW7OqVSt6X734iPa/RHTz3V7+ofu9UiYnpg7+bRKoSZRRHjcRnCXjyjIigR 30N4RC2xJTZdDrILbwxi8d14l/31M4vPgE9fcMjNWu2lEa+MCl3bRn64QHzGegkLDvny 2LTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843936; x=1738448736; 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=BiBNwqEUd/4ZH7tEeMX6WGp4FpHjqtvRbtcFv1yfMq4=; b=h1bPlIlyQ/QY3/d7SrkBnh0ap+L3cgOzy+I/Q1Eb1zQa479AhTmC48L17elQ3L1Myg I2k9WZH0gJuLWTegIj/O6ZUXwIDF0Z4r7UqeJNqAC60sbb32sjINqJBkkOARWLu7tb9Y BoTph/rnZ5CDfhQSoiOoy/PxZOiAbXWa0EqFei1oReakXX/tZqxGzBovDU7u1uYlQ4Jl F6hF5jkIWXsOfhAN8FyhFu8VGRh46oRSxzm3IC36NxZF6JV8TvHMBiHlKp5a79LTTzdM ZZVNruzEcyhf4rp66P8BYW3+KVGHTulsHWNzGZWjSI0ZzwedzqTen6JUdssO6eCZ/9XK KggA== X-Forwarded-Encrypted: i=1; AJvYcCUOd90TtjWqvncjmtMxVN8kaC2+GWoDX84E7j+LscXfXFcJvgZynZdLfHOa0d5z18L99Z03S3nNuXlyEA==@vger.kernel.org, AJvYcCW6LTLRxib0F0B3KVcteOhTmRwc8s1hp9uA5suFDR7j9LwXPTeAe8WXo9GZzBoHHJXcuQVbtDgr2Ygn@vger.kernel.org X-Gm-Message-State: AOJu0YyZxZynuak1grAskmZu0+oyiABOgEU/NIBMMnv3FhFxLKuTeNSl aqzrsWwJO/PpQBU8J0788g76MM52y5QIqV2NNixaz1Z2ANymJ9V+ X-Gm-Gg: ASbGncskB/BYMuf3tiAxuroXppeeqRQcgT0OurV23bgqlz407Y2HiVzjI4HVcwN5jjJ d3RUPP6OGrlll6MGXPA6GBKqLY9if3zKzQCBJqHE81CJbiTwkXKql9lDrMGRbs7jLW/GhSjKcg/ O8u6Y5JqFR9+zYnC3c1KE4LbM8lN5WrqEq/mgRTHIGn+Rm6WfTd10YHoqlR4UEqPQEMPizbgbTN kZbzwEqV8/n10BZQkhwP3QqgGrwoHbTxKtAhKZ7drR0/NJfoQL1njADqDvHO53P3zq+PT83eJ3g EfqWm20U1F+U6cxbs5IgYvoppzQLJ/cOgrQ9Q6nnGFNwFStvk8w= X-Google-Smtp-Source: AGHT+IGbgp5PaceqqgDL0Xm39RKogaVaECKfIPRcR+1Qk3qfNQBsExTa6MbrNzrbPR2Ev8dbJHrBtw== X-Received: by 2002:a17:906:528d:b0:ab6:5558:474a with SMTP id a640c23a62f3a-ab655584a5fmr504208666b.8.1737843935429; Sat, 25 Jan 2025 14:25: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 a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:34 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 02/17] HID: pidff: Do not send effect envelope if it's empty Date: Sat, 25 Jan 2025 23:25:15 +0100 Message-ID: <20250125222530.45944-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Envelope struct is always initialized, but the envelope itself is optional as described in USB PID Device class definition 1.0. 5.1.1.1 Type Specific Block Offsets ... 4) Effects that do not use Condition Blocks use 1 Parameter Block and an *optional* Envelope Block. Sending out "empty" envelope breaks force feedback on some devices with games that use SINE effect + offset to emulate constant force effect, as well as generally breaking Constant/Periodic effects. One of the affected brands is Moza Racing. This change prevents the envelope from being sent if it contains all 0 values while keeping the old behavior of only sending it, if it differs from the old one. Changes in v6: - Simplify the checks to make them clearer - Fix possible null pointer dereference while calling pidff_needs_set_envelope Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 5fe4422bb5ba..a01c1b2ab2f4 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -262,10 +262,22 @@ 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) + return false; + + if (!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; } /* @@ -580,11 +592,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 ? &old->u.constant.envelope : NULL)) + pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; case FF_PERIODIC: @@ -619,11 +629,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 ? &old->u.periodic.envelope : NULL)) + pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; case FF_RAMP: @@ -637,11 +645,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 ? &old->u.ramp.envelope : NULL)) + pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; case FF_SPRING: From patchwork Sat Jan 25 22:25: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: 859992 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9157B2066F9; Sat, 25 Jan 2025 22:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843940; cv=none; b=MZ3EtxgYI5koA1RGxMa6Q3pp5xcKFk3C8rBUFOxbott2GtP0et7PbSktjWGcMS9iN9G64W4lURrCx/uTU8ozPl7pgvlyyiWfLh5Wen2OXUfqDCL7i8IVFDEr5BP8Brob4hPBSvDPJFsj0QeoMHX4NFagBMkp5mcJiuP9WUtfLLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843940; c=relaxed/simple; bh=CGtZyHW/IhLJ8G2ImtmjQ9/dyeUyd5xFN1CHprzhZSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YHd2elqcRSAyL2c+Bj0NMnTt/qTx/Pcj4+w2Su4n74Bg/PczfxQiw2xFQBAuHjbygs96Y8+nnjtX+MHSV0JfkKMNLhMIsQKM5YmDHujQGDx/M8gm+Xg2h4RxnYf6ShYEKTLqasb3dXEXAV/+xjHtFPhLIK7mcbxAZri9vzAsik8= 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=IYKDvDbe; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IYKDvDbe" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5d3e5c225aaso687831a12.3; Sat, 25 Jan 2025 14:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843937; x=1738448737; 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=bCzGE/w6ShAbewfgFQBX/+PHxEYx9n5v+vKkrVVffh0=; b=IYKDvDbe/DWKvBQ7c180PkdTLwIqwoyTEp7h8w78kPaDoJjdkwlNzpMX3TUkxbA/DS 4pA+K8FRetGs5aGNVx95dejFB26ZRM7G4zqle22bbGbaufa23skiTHZJj2rv5VjhsXqK a0pg/QAiCKZPPz60mEdz/Yww3fymZ079tVpYr8wezysuAMyLb7RzGxIONJHIYeEczyRW ne1gLJBM93s9ZNdWwFA9tv572WrVbgFWY+8nxsy+qVWEXTn6Af/tVV0S++32tChJFprU BqbmmB7RPHX2U+QX5BQ0RoIoOkTUASwjKtybXGqEHLWfCYskINJO/V9eMDqtClis2C8G MtPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843937; x=1738448737; 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=bCzGE/w6ShAbewfgFQBX/+PHxEYx9n5v+vKkrVVffh0=; b=Lg8sBF1P6dLg1NMkl1WHU2WIKQqhZyYjlx2Oqk6uxhvvQecLFcGQeKU5pdDjElP0j/ pjaIHKrF36pvuCQ9NHDHlXbgPFZbJWEtmb04FBM5WsvL0/PM0XKwv6fZOhhRSzyZKXVu svwaWZ2bUTNK/NDdxBubjqcFGQmz4lL9eYKaeWfJ/fD01UC0du+qNCEOhrhXlk+fBgyF 2U1eu7R4sFkD5ZtEESy6ntczumMqqvj/6zQOJGyM4fCo1Z1jNgRT2tvQmStpeXEws0/G wikAsXpuOXtm/S36MuiUfsf3pbrM4uqhRgwDkkJAX6XmAR5z33MMX2D+/2/1IW+fr14o kB4w== X-Forwarded-Encrypted: i=1; AJvYcCUOQ3wNtEJG81YhyphRVuSBc38GfFm5sdOb4w+rcbTDYgmdWIqffAfNmEZL1xZSjMkg92ZRcFiq99tnSg==@vger.kernel.org, AJvYcCXpfsRVMy2ujOpef8XAwGfKhw1PQfsyGhzHYo8h+n3Cd1fkIcxzYrDEraZLdJ7kAFleOSB4ylPiodwX@vger.kernel.org X-Gm-Message-State: AOJu0Yxx9hkBhZk1QDYg/v063mbx1sxXEVnlV4KwejKUKUqMDZJDzttw sQC4+gGUiUPyqJ8kRwB7psdtJltVdUtDcqWDLFdN7X8BROtjZwkB X-Gm-Gg: ASbGncsknyXquvcTq7GY3+A5tqBQDIDDA+n0Bcwc+R2cxldGeu+AZbXfgeXva1IojAN RTGExZS6MO71fMIyKGZxxPgebXWlD+nt2GIiaIUljEYt1DCH+CiCzfVe+0Yv+oWJTNffIEuNW2c IymNa/SJFuBDWVi2dsxhfL7aPvkvy6dpjqsi0ARQ78wJYFrDi2pnrwhFuEk8PeRUTohAhEWDXbC j3tDrz+k2XKhFldZUpfC5eYJBEtre35+v4D1G6ZWbkF+reUtWkVP/gHvfnIWTrPexZg5FKDfZFV X6emWU2fQedAA3fVQy4d55uVru3egxQr2WosCh//wqGpSMef6WA= X-Google-Smtp-Source: AGHT+IG6L76WXOnBEYR2BaZbN4Cb6yQTQK7X0KAFpy35uHWYpoGtpduVrbJwGvhwL+vKT0nQ7kfing== X-Received: by 2002:a17:907:3da1:b0:a9a:1a17:e1cc with SMTP id a640c23a62f3a-ab38aefa8d4mr1170214266b.0.1737843936588; Sat, 25 Jan 2025 14:25: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 a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:36 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 03/17] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Sat, 25 Jan 2025 23:25:16 +0100 Message-ID: <20250125222530.45944-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This ensures the effect can actually be played on the connected force feedback device. Adds clamping functions used instead of rescaling, as we don't want to change the characteristics of the periodic effects. Fixes edge cases found on Moza Racing and some other hardware where the effects would not play if the period is outside the defined logical range. Changes in v6: - Use in-kernel clamp macro instead of a custom solution Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index a01c1b2ab2f4..488e6a6a14a6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -15,10 +15,9 @@ #include #include #include - #include +#include -#include "usbhid.h" #define PID_EFFECTS_MAX 64 #define PID_INFINITE 0xffff @@ -187,6 +186,16 @@ struct pidff_device { int pid_id[PID_EFFECTS_MAX]; }; +/* + * Clamp value for a given field + */ +static s32 pidff_clamp(s32 i, struct hid_field *field) +{ + s32 clamped = clamp(i, field->logical_minimum, field->logical_maximum); + pr_debug("clamped from %d to %d", i, clamped); + return clamped; +} + /* * Scale an unsigned value with range 0..max for the given field */ @@ -361,7 +370,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 Sat Jan 25 22:25: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: 860149 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 A0051206F05; Sat, 25 Jan 2025 22:25:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843941; cv=none; b=NNtWHBWiqjruvUUpgwMoE0eR54WH6kbJDJmq3nsDZ+Ea6k9w/7XFh8dtHrm8sBRjlDTFF2e9VcWik+90oq8exBGPZgsbBdJeJqFBA3dLpm8hFhLWOUXn1P7sJwY4v5DWrZRSfVdvqNOJkG+VoE0EATvzy3gxsLML9QJqmjSXjDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843941; c=relaxed/simple; bh=r2HpBPQDjRrVyhEvSIOGQAE936KzKNRVsJ73B7MzFOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L59q3ymRaVEeTqB/Fj0i6o+Af4fnX2h/tNgyFKDNsAbwT/gMcR6sUPAfQgfD+gEkrbSMB9kZzTalUdZr7FqyiuZLQzpnPQ6ZXEp3Wt3vMA7vMLx9GpF/0SBGKuEVftFZjurhjVURsMGII0RuD7UrLVVQehm6+g0LKbPg8+hWecQ= 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=hJIoYQki; arc=none smtp.client-ip=209.85.218.48 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="hJIoYQki" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aa6647a7556so63026366b.2; Sat, 25 Jan 2025 14:25:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843938; x=1738448738; 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=CQvhEKzM5pHRizGyFJEW6UlDPPbtCBt3Q8hUG+OtEJw=; b=hJIoYQkign4Dhun0alFFQGQ5qwQO7R4skkD8/+4urG1aNhPHg0SDALXu2QIrUqYjqE +t4u/gjXuVlnmtuj5MxtqGzkWJc94LyAejyNed2YITqher4YOT7SOttg491t5kw+bNzw cdhEFvb0taeOjKBGmRCpbPMz5w5hueNRoY9SMUDibiRl7NQPNGLyehbPKyiPiTJMs5HO DVe+Xuu3XQcirUjdxNxskFG1GTKSq5D3MMF8sGw/F1eGDwLPgQDjy1y/KQblr1kGuiNW +7eGLTHXmFpurNRcNpp21I3xOuITL8xAhKCd2TYhsc1eJJ+WtIaNq095T7vKFXWXQIdP YZBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843938; x=1738448738; 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=CQvhEKzM5pHRizGyFJEW6UlDPPbtCBt3Q8hUG+OtEJw=; b=XYhSAz1hJCLNDlPQLUziJt0rDYGx92XT+3oBmHBgHNw1rIr31fNGa9+XVHvhDzuDQz gj5pqtXqJVhG3kntJIP8XifImtlG/8CWR5zN+uZpDc7T7xFKhhxXUFE5NYjPS7iVOtfA gzFFpQlJQff/O1qdNwP26V3mOuNmR1O064KyCqjiRpPCNlMCgIYWJin0BCDl4Ftwl0SF ts2BCxj+Z7J4Zzbhc8GU4vrzJuNk2Uy94amxDgm2D+EZDNpSnk/pQIowjPbhuqwx19JN YIrpweAOnmjnuZ+JsA/5RKn459im/UuBjwfvNlJYFzhTYzKlyT7+zlPYhoJ1uGEA2vz+ RjdA== X-Forwarded-Encrypted: i=1; AJvYcCVaelJe3hL0wO2vty1Q0/eRwauvZ9aUZhcWU1scuqwLGgZ5zXVhp+XU+151KOBJIw1Ydope7Yxp4ZYfMw==@vger.kernel.org, AJvYcCXY7/suBxBVRsmmY1oEktEcNgiind29rUDGNdoUOOGHgji/vImGG6KsQzVcDX4I5LQgp4jtMMfcuF8J@vger.kernel.org X-Gm-Message-State: AOJu0YyE+SjfJOhx1OLbTo98d7VuQ7L9rPw6un5kRPLG0XYENhy4rAPK 8lGfp8zEtQ1dgaYAjcVJBaCM9CAOEM0jnL6qYO4eKU1bgMQVlyvC X-Gm-Gg: ASbGncthouUC/NoWGUz6wHQKOp6Bjft+xJ04v1laNNead6E96NOmOeXSz414tZL4V+n zev5uaZcWo9PQUTRaK0Hc9l4hUWpZPrIMSSEWLOE76Sh6ybeiSdkQAiiklY78sg8vIcTfKUjspo W6Bd1vSq2y8KTcXwJVvhfNk1+1mjTET5R+clU8/51rBDe7PxZTvTlXv3QY0F7+jh1cw25rmUE6p b0aa7wflDdzENk75RLl0XuaZKJBbXzZ6C5AcVUKstg4PyQqpW9AA5WF3Wv+1qzA2UOUPVVqsnOL IGEXdJgR/S2a/S43wrdh/prxPrCnspMaHTIZ/pEHceAEoty4sdoT9kl+eiy3pg== X-Google-Smtp-Source: AGHT+IG+oZYpMqKN4HUOrASc+ZNr6PQG3+Opt+CCgz4R253JiKL6E/9yk2vYXpm8+kHSPEBMua2xfA== X-Received: by 2002:a17:906:6a06:b0:aa6:6e2e:b7f with SMTP id a640c23a62f3a-ab65139dd94mr625144066b.0.1737843937705; Sat, 25 Jan 2025 14:25: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 a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:37 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 04/17] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Sat, 25 Jan 2025 23:25:17 +0100 Message-ID: <20250125222530.45944-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 33 ++++++++++++++++++++++++++++----- include/linux/hid.h | 3 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 488e6a6a14a6..e2e431dec936 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; }; /* @@ -338,7 +340,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); @@ -761,7 +766,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); @@ -784,6 +792,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; @@ -808,12 +817,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; } /* @@ -1088,11 +1102,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) { @@ -1336,6 +1358,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: 0x%x\n", 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 Sat Jan 25 22:25: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: 859991 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 2BD50206F1A; Sat, 25 Jan 2025 22:25:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843943; cv=none; b=U3cxjgZ3ugAd+QBGRk1rCUTV+q/wch+HHbIYS5eiHy0i73nWrIEYL89bZAxCiMtBqroBs1vhb3lABgKDzmuH4qfBuCRrQxNokTyS3VNKpf/InyntgAWomtAgz4q0p9nZmRhH08REszF7tIY19I70F6JEFW5uTeZwxvm+ag+3F94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843943; c=relaxed/simple; bh=8GmzhpaMxYiy8UkJ/MzDUSAv38faldGoZ9y5VIJO0dk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q1IYij3CmtBLTHFrXzII/laHia4H0BAisedBclK3qgZmysDorn35U84bTLaPnsAfh1VdPivqw4sNiOOzMfgJoyM5oM9OefAzl7wbi+BEFoFIHYTUXuPODXrM65YDeapjJ73BAAAbWbw/51cFe0vJXgYR1xszR2mN6++03onJd5I= 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=OF9yu3JS; arc=none smtp.client-ip=209.85.218.48 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="OF9yu3JS" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-ab69712eaffso8519966b.3; Sat, 25 Jan 2025 14:25:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843939; x=1738448739; 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=LxiAHTud/zEPLuazvDKVn1LXHelcgSwsXbJXagSiwyo=; b=OF9yu3JS3hGNSqVyNFcXBnB6o2IrQJxxKb/n9Lq9wnLYKl4N8gyQz6RDj6uFyJUspt z4dwa/nZkVHVhdGzUfV1kjEBpKZNQbTeKG7eaQ6CfOPcGWORz5IHwG1EuBf1ALqX0D40 FzxSmq4D59F66QbEg/GuWNHrQmUQSGpGYwAYDXFlfkFtsFOJgWv04V9SZAgc/xdHZpMh l4VlXHat6eQF2bLuORh1/h4VtnUf8w2tZWYhE+QimEgvi614niBtJQWe7bH6vy42wI// qJVVW7dW8mPVi8I0m5FxjJpgaHjefN0D/IEF7rvNoDKznNtWCm8pHnRzICmvx8zmrr9a M6wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843939; x=1738448739; 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=LxiAHTud/zEPLuazvDKVn1LXHelcgSwsXbJXagSiwyo=; b=LNsJheOQytmzIZdK03VUnMMyF8966jxHF+Vkfc3GQJOdt1LMZHTX7rOI9tQ2RGBPvI Zp7TwQV8Umr7EQ+Wuccn5UtSq6XqbXNF+j5P6U/TdRSk26VLIrBXYxqGRqc9w/Nol7zt OViXaAzExDduPP8UbxjPxpnL+L/i+1xTeAUGzXRYozCngO0YMIjslyWl8xspAiIDLb/K 4iM5pNq6WJZ57Gipzvp24h0ZF5emxbWiy/gwqwVZBbyxaWqPrRKI92EkBulrPlj2COIa PHFxlJJpmXXUax4IVb6xkAR3cszIUg6brc0XvLMszVxVtuWZxmi7k+54BV8H1YIOi96/ rplw== X-Forwarded-Encrypted: i=1; AJvYcCUiMtG+DOVNx5NPgcUVaamgDvJ9XElEgKbt8LB6toWOR7GfCgH3bqG5w/c1Ad02AfJ7OCi90BTDrjhrtw==@vger.kernel.org, AJvYcCVMQXIP0Ktos/rqHeLHNNQFSdIofffBPwEZC7tflkvH6qKxMthb5JoIPeKkgfNB/3c5ujpCMWSt2Ma5@vger.kernel.org X-Gm-Message-State: AOJu0YzoRDlbPT5FTrgCJrauxcrqIRMNQ8MFjefPpAxjcvKbY8+ktnbV Zo3iV4iPlrCnZ1KHpKeE6E2So5soFQy6cU1RyQT8jdbJXrUpYCUK X-Gm-Gg: ASbGncu0co/Q2IhGnKtF1jIcJf6QGKiGGHkWxP8598DrBqxPAOM5WkuZ+hZOFk5JKd7 cblVrXMOpwjdEkHjP4Hj/kOPStwQQwoejsshVnTTcKe8dmAMkGIDwB6k3wMTax1utXBXQK0j6Yt 3HkVIRQ5xIK3PF4F/SksubSvWydTTij/Q/pMacGRv03ImMonbsjYRK15lhxrQQY6H9KEIxtTVV9 k/Y38u1rmqg1924SCyMO0E0YbZwZ4AurfL3wbEgUcE4HWpBpaGOnW+orUxfZvNf7vabl2XH0W1f TfjlyqJrajrMbrBzPW1uZni8gANlcJU5T2wQljeUEM86O4s+vw8= X-Google-Smtp-Source: AGHT+IHlkkc1SxaySKtyjml9NIeYfx0sKppwRd3NTXFQ/ul/lLjwZaFKI2OM5gtNRWGmKZdTNWEgkQ== X-Received: by 2002:a17:907:3f0a:b0:aa6:ab00:7b9d with SMTP id a640c23a62f3a-ab651587b33mr664885766b.4.1737843939342; Sat, 25 Jan 2025 14:25:39 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:38 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 05/17] HID: pidff: Add MISSING_PBO quirk and its detection Date: Sat, 25 Jan 2025 23:25:18 +0100 Message-ID: <20250125222530.45944-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices with only one axis are missing PARAMETER_BLOCK_OFFSET field for conditional effects. They can only have one axis, so we're limiting the max_axis when setting the report for those effects. Automatic detection ensures compatibility even if such device won't be explicitly defined in the kernel. Fixes initialization of VRS DirectForce PRO and possibly other devices. Changes in v6: - Fixed NULL pointer dereference. When PBO is missing, make sure not to set it anyway Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 47 +++++++++++++++++++++------------- include/linux/hid.h | 1 + 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index e2e431dec936..89a1b6a55c1b 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -404,13 +404,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; + int i, max_axis; + + /* Devices missing Parameter Block Offset can only have one axis */ + 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++) { - pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = 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_signed(&pidff->set_condition[PID_CP_OFFSET], effect->u.condition[i].center); pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT], @@ -822,6 +828,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; @@ -1101,7 +1112,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. */ @@ -1132,13 +1142,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"); @@ -1163,16 +1170,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 Sat Jan 25 22:25: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: 860148 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.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 3317E206F2D; Sat, 25 Jan 2025 22:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843943; cv=none; b=hmF3a30sq+VrKreJTdXi4wlEQBQyw1rijaYqQd8bqo+A7YJqTsg7NtARkl+gaesHbI1qQlqWZ+kPR0XkpyJrQMp1rj5xbaGHhiyh2ptfEZTOXHWQnZpIKY+hn0M1FDfLlWVyIy9M/0gYC+wvmVB7I9z5R8cFSuX+yFZES3150iE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843943; c=relaxed/simple; bh=dwCcjto78uvhV6q6g4fAZmQ++Yk3NSDQ80/OcX+fJyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dggxhqWBCw/nyOeMonHS3ISSAPFiHVmcelzo3fqI/BAVsELssFBE4vaANsynfr5V5dWxJ6s2X/eavil1g4IMffI8Z1v57WoUKaU3h5a1VMS+SbC/oL2TotaTrHMcWQ5MTMUwZqPgu6+VWGV/frc91THgTrceg37mpR2ui5Ryl1w= 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=lafTPp5z; arc=none smtp.client-ip=209.85.208.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="lafTPp5z" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5d3e5c225aaso687835a12.3; Sat, 25 Jan 2025 14:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843940; x=1738448740; 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=Yn3SV24FXGrk6D9U/sonjVWTrzb/5doNCYeJXjxGMWM=; b=lafTPp5zRDqwqfU2gE66xcV2eVzPFJScrJZsnzUGQMvKZ/rJuAYW1s9efbGXiRwWVZ F625dExyNLXB1H4BOMo+rasSEvot12eeaIpUYSxHESf7mRlRJH4A4y+G/lcKi/nspuxr Mh5jyyqHfaCFBbj2OA5RxKEpsTOOG3FH/0Kcy5KrbmssRPDw+4gVxGhQJkZAbIvELd/h YE8aWOxbU7O808jT1OoOJE4qRQded/wy8dT39CiKHnlxZo3kED8OcE0IeaN/hWCnIHo7 o5C/NQiJ7qVn6vl4Cc16yS37YMCEuMAcEai+dmtnkiN5cj9FSk1jAsMj5zgb/kEeaFzc Kbgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843940; x=1738448740; 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=Yn3SV24FXGrk6D9U/sonjVWTrzb/5doNCYeJXjxGMWM=; b=cU2p1cwtoxi5CR/vNUlwUy+HwTFwXwMBGAetL7d4q5aFflVu2QfSHYISF5HO2/Lmll X1JLMniI4QIoq3yAW5hrlxZut10SWcEXh7Sxt0zsG8N3hkNblGSV1V4IGUFq63rU7xNP X/mBhWBzc4IpUWctHNsdRPGMQOW1iqwAikzqYs9NBalpoSoqrx3WnoqFt8h9kdo2e1A9 ds0hqzUwqg6wNuKy1vEPA4CzFoBkhV2d/2BxW1DUpbQ0SUR6DXeOCOhgeHdOXhHXm7re YkuZkgyAcRDWyGyVKcpDHe7jUMMLJhgEmttwGUofT8dtJPGreBBPbjcW82o9Ih1yhTFv Zz3g== X-Forwarded-Encrypted: i=1; AJvYcCU9Hj47OIUNro/ng6RI4/aNCWXg2aUGG4yPxj8NMHCPCNm+ABiNaNiIfPPBlZGRISNO1uBaDkvERG5CFg==@vger.kernel.org, AJvYcCW7s78FebSArGPOw45iglitej2HPUmt3Wsn4mJ9bMPVfDHKEDcobaoxfzO6HwxEa4VFJSLeKXtZy14E@vger.kernel.org X-Gm-Message-State: AOJu0YyLxdVE79N3tG8NRqpuhGB6vKDqzFP0KmQlK3XwCtD13NiE8QAn keYJZQeJxXbgqhnS0NqHSip8258Mbh7sdXEJYI6a4CAQRGn1QS10 X-Gm-Gg: ASbGncvS7SZA6846+qsEayDRDZZ+OiRzf+xctdVSDGhevlqvPDChxumyqsSO2jHw2nu fRhnmJrNo/ZsGnFbg2ovLxwx4AbcFTKt3Li5GeU1bVHPpDk9L5KfTZvC44LeMLcjmsa7z9mwKaI AeDJOUb0H3Xb89HCU+uQYSF+YS/Ln4USnlBwXWblby78Ay7pLw8hpZ3DatYghdl7XzzEtFonGYS bU4Hh8/xwyh+yUA55hjT3wSgCCYe/ao2z3rpqgTm8d+nwTH0guiXJfNkLmlzw5AXOAQvh/1CBMh g3KglFot2iO4/QSX+IKvP+JXv0qhECh8tv32huKILdtyjFeIPzc= X-Google-Smtp-Source: AGHT+IHtUOwNTzy0tAzq/qeoGL6CKWP/WHQYkZX6ruEYQ4CUkP7L2CuRqZGvthdh+kssRkX0q/sAng== X-Received: by 2002:a17:907:3da1:b0:a9a:1a17:e1cc with SMTP id a640c23a62f3a-ab38aefa8d4mr1170216966b.0.1737843940444; Sat, 25 Jan 2025 14:25:40 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:40 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 06/17] HID: pidff: Add PERMISSIVE_CONTROL quirk Date: Sat, 25 Jan 2025 23:25:19 +0100 Message-ID: <20250125222530.45944-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With this quirk, a PID device isn't required to have a strict logical_minimum of 1 for the the PID_DEVICE_CONTROL usage page. Some devices come with weird values in their device descriptors and this quirk enables their initialization even if the logical minimum of the DEVICE_CONTROL page is not 1. Fixes initialization of VRS Direct Force Pro Changes in v6: - Change quirk name to better reflect it's intention 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 89a1b6a55c1b..3f429936d537 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -982,7 +982,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_PERMISSIVE_CONTROL)); + 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..92a484f65a87 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_PERMISSIVE_CONTROL BIT(2) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sat Jan 25 22:25: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: 859990 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 94B1B2066E4; Sat, 25 Jan 2025 22:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843946; cv=none; b=HpGrUksEqijZokKzBay42pq3zekAqzHWlMIaWIySWE3PbFbh12idW+Ht4YRhdLvmA4ETMTB+Gd2aCskTLkKQoNU0zbT7HVrQINHyKc54NWOL+TgU7W3JeWUsg5iNZt/nNSfYSpk3s3jVxQPYQaT2NzNDwdEywoSwtdauYc2zwnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843946; c=relaxed/simple; bh=lhNyDbqPT/A5BuGm77CZdSiqP3jG/Vu6qUEGM5mTO38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TL0aX9qCcDIx9OU75CXGCRwFLhaG/Ujm6aACoxoln1WDuBz/rG6edSh/IUhYDEV8Ikgoe9frPKDT+dcme03w5GjtH3ZCVbq21AZUe/wHYb1V8FJRnXBGzCkZSkik71r8vfg5NgHZ/u2MTlulXt26E8B90MyjXQi9AzO87i6Ac+A= 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=SROOn2lc; arc=none smtp.client-ip=209.85.218.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="SROOn2lc" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-ab30614c1d6so61134266b.1; Sat, 25 Jan 2025 14:25:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843942; x=1738448742; 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=gmnykWrVlt0sJdJV1uVzbEe7K1M5/Cz3pmV3NtFHvbM=; b=SROOn2lcc0cI8dxaspGi47bCCpvMnm/k7H5v0pI0R7t52XiDxLC/SbE8ktLqX3t5n/ QmP0M8d8fIT+CtAjO+hjm9jZPAFSlRhSkR8N4oLSD28CpFMqpZbk7sYn6zSJsqwooPtn 9/2bnu0pkJzdq6g/QIQAY7pkVr0THFG9ELy8/9IX7LH0uuXil/hS/kxwgpV8mVTB1wau nC9o/vy7LJwH2Vtf0MBTi3xnja9+hixGdpW08XeqknW0sXJ2dlstfXXrdc8vzUhkkWT8 K+eUlwYaDVce+DlxumULDbpyEglu2JAJ/O5ZmRscncTkZpqq1/+ocK5oIAQYhV6HhPzQ ROYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843942; x=1738448742; 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=gmnykWrVlt0sJdJV1uVzbEe7K1M5/Cz3pmV3NtFHvbM=; b=Uw4O9nJGbGb+VDdM/brpOiz7tMsAzOyWzmGdP6YQBbk+EJVKZc9tg1Utz/peRZI/jO Dq+r/LAArlj34V1YyY2LWSZlI8+d4mKfd4J/AsMcpUSQrKvskesiJD3ZUYGUJM8C4wK1 ZyWGFB95Sc37YQ6dB44QaaKxkPl7ku62KoR11uFOcvjDBd4uPF1raUrLLe9VI8o7568O 9UyVywEL0qOVBpVu17CS4FwrNcHMTQyTtgcimAbXgHzzJfP//34oqBv0lGZ9hKp4Edqf vAKy8cg9lNi/bDdO4IOBxSICP20+2Eul5hGTXs/Y0HwTjQozihMX3v9eN59nP4VJtRI/ MZDA== X-Forwarded-Encrypted: i=1; AJvYcCWGS0RiyhjdijhSfJf5jttik7b0zji1s+itD2LtLDdvH+SBHXgWFfCHBVPKzVXqlf6B5/mhszTbhb9EFQ==@vger.kernel.org, AJvYcCXznWHUtb/g3L7z4VhiDkJjneXQOqJ58/XGZjP490Q6V9ZQvu4wjJKiK5Kr3UU5Q1d+PkoY2MZuH2wB@vger.kernel.org X-Gm-Message-State: AOJu0YxTb+VoDyFaoHMYv4Ra71dn0w+bzPPuLmrXu/ulp9Nc1Xs1zM9n 0saKX0eUdyWMbClPqMVC2gag6OkRgaokPnhi3aLsWNNb4KHHwy4W X-Gm-Gg: ASbGncvqMJUwc5qmnF4nfCmp1Ae0izZrR4uO/I7NpwKPSrD5zlq3ZJ3pd0pQHSBL2gq aRFOsZ2M2W18UxQHIhhHJ8HRnmNq/Y8Cz8R7Q4vmqZw06Xq23rQ2v8kYFb9sGUjtQp7gVHXzMWb 0KanFPXIcp4OGquXC35JZRyCrwa5gBZ+x4f2fIzeHdPA/ujNmPIPQBlCr70eUBqahMDugHKYsu9 U5OSi4Ug0yy2wk8gS2Gt5yRUX+HJrKLMUtTUVhZU5dJwp3Y7m81DxLy1zwwXGVoL+TuzFdNZ4za xwwQ8aDOdvVtcjdCBccTzbyQie1aRfscUJyO20qGtasODFABHFc= X-Google-Smtp-Source: AGHT+IF6KtGnHcD4d603Q4TS9ycR6P93F4Jnz9431WOD4+3YutAFIdXozpzO2c/2MsIsHO+nnJwAXQ== X-Received: by 2002:a17:907:7d92:b0:aae:c058:b8d5 with SMTP id a640c23a62f3a-ab651653889mr670134366b.10.1737843941565; Sat, 25 Jan 2025 14:25:41 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:41 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 07/17] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Sat, 25 Jan 2025 23:25:20 +0100 Message-ID: <20250125222530.45944-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 15 ++++++++++++++- include/linux/hid.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3f429936d537..298a971c63fd 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1281,8 +1281,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, @@ -1304,6 +1305,7 @@ int hid_pidff_init(struct hid_device *hid) return -ENOMEM; pidff->hid = hid; + pidff->quirks = initial_quirks; hid_device_io_start(hid); @@ -1382,3 +1384,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 92a484f65a87..e6e9081d7dac 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 Sat Jan 25 22:25: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: 860147 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.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 B8652207649; Sat, 25 Jan 2025 22:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843946; cv=none; b=q7vRstucI98AGvVAgCUbyMWf4pRLcmS4B/9FNXDmvCjwoYhLWbgW8OrBYktz1/fTj+2AkZtEl8QpE9o4Xd2h3c5UYER75eTrCVOdTPjpSizP7negCqKoDFHG/BZ+X8YJIi+TA2mDPNZv7TjqEyxk83JIulP8aq4IK7evyTHy1YQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843946; c=relaxed/simple; bh=sfJp+cEStH0iOHMy+L5yy3UCQpbG3St448sBy3TIeoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ez7agktzNTNiTfndL2qbbm7jXNAj2Br88gzoW5VfCLfC5Z1Noi009JvryZHYsxYELBUCo0vYjlGTCXxuYI9mZL040zBwyn2pn3DUC/wYZsqYNHpPMEZiebl0NgQYnW7Qiw6VZJxzBUzH9ISf8VkreljQgT2fCXBqPu1+n1ka1IU= 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=bForWo8G; arc=none smtp.client-ip=209.85.208.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="bForWo8G" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5db67d1bf0bso834475a12.0; Sat, 25 Jan 2025 14:25:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843943; x=1738448743; 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=D7ipsiTl1dRTYPh+Rs2vHcEMW70oojF4sOlian54NsU=; b=bForWo8G5NB6Afx/SkCFeSYt4ld0NY1CJLuMH2/TX372GYT0EGLUR2CuEkzjveo/L6 M8ZxG3Bp9W8MJFMpFcWxbfxRrL4PzmwIQyKaeX9HWv3M/MLajyeH/BOCzRfhzw+yyXAJ /RFlMYGJ57Zx3oelylzYCCo0VXcksGfJfgUCf8AcTLw/Zg7qgyPlthMImhv7Rdy0QxAA UyQjJsoK2LSeVZQB+3bkYN3h+ENuvIsSY/C7WeFSsK8daDO1KjFvnWwIFaXNt+jEI2SI +pwm6lMn5P7Oc6UtQd3IqikaqPo/zzk+HwDY2vLlfoxWJYPbg3dMdyJNkc7m9RROENUD vDDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843943; x=1738448743; 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=D7ipsiTl1dRTYPh+Rs2vHcEMW70oojF4sOlian54NsU=; b=D7tcWTkU7iM6d0dkKQn4J4WY9Z0GgMFS7uXT0t7PHqciD2NLYBPdYlEWwppFIP+qAM lagdOUzOYIaetPDnM/wCwWc4vdNju8a0neF5H2RzpSSuzvaSAxYhrKJYl6rFIGShFTw9 51R4agcXKrhukkMuU7+J97UoBIUNDnBPEvKhLJWnqiW8gzjmygAP/iU83d0GU4qHs1qK A59LM2SBFV0LDh3HCaNJjV0nIFmLk04cpkrlih3QbxED3Kix0NPi0RVxgTJGRwbqdNjZ +ldSolwfTftfdgaizUxklh9+biPe4PDqg5DBq8G+XiH+9HK5CSWEtutlYsbpiJL1fG+Y gnIQ== X-Forwarded-Encrypted: i=1; AJvYcCUMpZgXm5PhE8hgUf1IIKumC4iwAeoGoyz/aM8/Ig2qbNJJvs4SCKn2MpwZWEjv2WjjcZvIQX5zmoOYAA==@vger.kernel.org, AJvYcCWadQtxICEc1pFS347YCY3hkbOnabX1jpkF/IOam8MnTnPacIWGpaRwfbDgk+tcnPkn1sXAWdkZWq2z@vger.kernel.org X-Gm-Message-State: AOJu0YzW49JCBnJ1MWhLfMEo5m5F678gGs2I5x+f0Pt4v5MJY6cKLheN qQwUEJ2NkTk76xJeMbsOiXUdYShyckuLuSNXKxaHKXEaC1/yvp3piivI9IMc X-Gm-Gg: ASbGncsSlSESvzi9wPNOFrdj54gAAKIZJSxaHYAOqyy7zUyZBbqbt6NiU7N7xp2bj7h APzo7oLeSmuJ0GBi2tB/6sZqej2BrHsQ5WmY617LFCCgnD8tOOEwxzd8ThLr7oLh7pvX/jZJ1S+ QFS3hX4K8hmpwfYG7cTqSx5AMYLrjh5jXvsAr+ycch5YA94NapE70SYwTslqS6EF83LM8zbTU+3 vc+zgzM/l068pFFCWX4WQe2z3Sqrj0QJx9H4QG3+aVJXSBxyM+HsYGZjqVuDYYItvlDz5gLK4vF Y7ILQbR4HM8I4+bh1chaza2lFXNkonbwDnys2oGViXMohMBov4k= X-Google-Smtp-Source: AGHT+IF1qE/zHzbCjcUPKzxu2EF7d2M6EHxN2mOeI3DSl2MiUOCit0EFC8STjWGDHvLLP+YOPU3o4Q== X-Received: by 2002:a17:906:7314:b0:aae:e684:cc75 with SMTP id a640c23a62f3a-ab38b503573mr1085913566b.13.1737843942788; Sat, 25 Jan 2025 14:25:42 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:42 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 08/17] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Sat, 25 Jan 2025 23:25:21 +0100 Message-ID: <20250125222530.45944-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> SDL -> Linux API translation, and this value can be incorrect. This can lead to partial/complete loss of Force Feedback or even unexpected force reversal. Sadly, this quirk can't be detected automatically without sending out effects that would move an axis. This fixes FFB on Moza Racing devices and others where effect direction is not simply ignored. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 12 +++++++++--- include/linux/hid.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 298a971c63fd..9e03dfb2b1e7 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; @@ -337,9 +340,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 e6e9081d7dac..856bed149246 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_PERMISSIVE_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 Sat Jan 25 22:25: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: 859989 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D10A2066E5; Sat, 25 Jan 2025 22:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843947; cv=none; b=Ai2paFIeLywk4EHeiklNem6okaMLxdkdsiwk6Xmo/Hg7G0Y2Moe2EF17rxJ9i8BziVsGvF307HMDHTzh7mWemguSlipvbYRLSkuXRA9EHJZ+R43t4al8LoVHfMoxvYk/f0nQcd6PF1V/jyurDM10DK4N5covSspsnFp08STRCPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843947; c=relaxed/simple; bh=4K6Ktazg8UjZRyNjmJVyYZQUmtkSr7vSe5kY4mMQ1Lg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e7PjiLHApWaMCq+Xhses8OKRSKfXZHOR8HhF+npUaht3vQRNV3kG9oB3mDXm3AoX9ygG3Psrl31Gwc9ZxrJ4NqKySaxi8V4L40QupUqzUxXye/yrhWl0bYIXGTyfBV6gNCdYURjtqGMeN9jzA8kEUsQzG9DCWMmZptjksF+thP0= 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=K0roP/ya; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K0roP/ya" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-aa676e4f36cso38239166b.2; Sat, 25 Jan 2025 14:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843944; x=1738448744; 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=X7Al4YBblnhD6mAXZvY6iETyAjHehfO4Vpa6xV+iv+c=; b=K0roP/yaViQ5l8YMOLDdiiYwcphxuvWghWyPCRpDzSdigdHO9oWoLPpHGPHBFvMlet 0y7vpR+2E+6FaYXwYYIYYDU68EiXF0QLX5jHh2KjqOKy5rEJMiGPxo38uFD5lej0ljuV Pu+o7uWLuTvDTV0Z1fCbzZldYAFs9WFLv5AzvQ4XKLlfIM1HCKHQ+4BzcwTChlJVGbMS uEIkm0g49jqo5fX2sI9bMizppOD+A4KNItPQVKQsHsnrzD1K0yKdF44x5u5VQUbWWyVY U9wp0xte7FHTFjXsmhwaX/AWSMQx1oGIoM0r6SmOJlbiqTLmPXhBg5ObllsD/a53kH9G Pv6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843944; x=1738448744; 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=X7Al4YBblnhD6mAXZvY6iETyAjHehfO4Vpa6xV+iv+c=; b=HpevTRVkrUBVHpf4kMZ26CwY77jwGhxilWjdQSwCFIJdqaP7eD6yH7sI2jS8buiLEY OTHzcWEf7rUgxfPMOEadsARF5rTFGLieAfg0F7Mn/HWrmc4dpfE/8iutpfhmPBsMNrLs ZjXweV/rNf8JQPBAwKsuomk40ScrQCU2PvMH5aoexXNSSZQ5roOaN8R5ez3JtbUh0Jku ygX0/DqjsOZetb1DIQ57AGQTg6E5tjbW+4IH5lvbnrr9GhUSmINXf9WR4Wh0yDd1fG+y xCGfeAfqcfLmA0E6NH2kIm5BMasQsPllIwNU9etw4SVsy9z0007mqJZyfU1sEIZ7w29b c8eQ== X-Forwarded-Encrypted: i=1; AJvYcCWur/R/IwCBu4SIwExUdHVeb8j5PHy6yYZSQ89oThdYCq/4xaCB+go5Gb5HjBA9M5s2WsU9jWghiquE1w==@vger.kernel.org, AJvYcCX3oyvtUr5zRdoxAC918f+YYX3zTUD6Af24ENxNHtjIiljI1xOoW2fQQbZAoONovTvDbUrk2EqUnyd9@vger.kernel.org X-Gm-Message-State: AOJu0Yx5/6BxBDn6wNXx4lR4GOcTqQCo64v573vL/eOG4wAIYKaNDqsG 0qOeIWMqjyE26521eGTndQ885zhCPUOUSUoI1ucaHqY/e7JfvZ1e X-Gm-Gg: ASbGnctmLuCv1s6m3j9DDNvSsbKlvp/RNKDG8uAcCtL/KzziCSI6mJ5Jk6pHzoOe2gO ZWp8OX1fUVxMTrA0NTqYKk4I2Kbl3AoReVaHP26a9BN3WjzBeod46HyoyMEsK2n0M69tE6anQrX 3fnL0wrfdW5OMG+4b6R76/xBi+iz8AHwL6KV+mElNbqVanzWHu24k1d4GRwSZOvb+3mETCFeQfw d+nEP5w1ZYr+RwJ9trZGK4AjqDGG6uW2jgUkZcTK91Bkz6bpiRdcmWsylUTp2vKaH4nw1xI8qDT iL8VKh7kZyD6yU3i5pZCv6q/P7IfLG+W8TETY88FFwvdJ1LDdqY= X-Google-Smtp-Source: AGHT+IF/1541SngmeRXbjOSd9/HXoG7lEzbVtMEQBy3YWECJJ3j/fNEp6XMkSq2Rh/6YUdsHBRQjzg== X-Received: by 2002:a17:907:72cf:b0:aa6:91ca:3674 with SMTP id a640c23a62f3a-ab38b240583mr1277545566b.4.1737843943778; Sat, 25 Jan 2025 14:25:43 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:43 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 09/17] HID: pidff: Stop all effects before enabling actuators Date: Sat, 25 Jan 2025 23:25:22 +0100 Message-ID: <20250125222530.45944-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some PID compliant devices automatically play effects after boot (i.e. autocenter spring) that prevent the rendering of other effects since it is done outside the kernel driver. This makes sure all the effects currently played are stopped after resetting the device. It brings compatibility to the Brunner CLS-P joystick and others Reported-by: Jules Noirant 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 9e03dfb2b1e7..c125f029b6d6 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 @@ -1222,6 +1223,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 Sat Jan 25 22:25: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: 860146 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1550207658; Sat, 25 Jan 2025 22:25:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843948; cv=none; b=HW6mEL6N2wg63aB8X9EI1yNbXjU/Z7FebP5FxXSuVSsu901+6ktfeHQH93ejmRBOptoNcnxaNhwB2KJfkzsfwwneQ53uSUm/21g840x/VqAzM2zJmFbBh4oZvw9nr8/SXZGNrf4xkqzLW5kUDGxkYdCFIidbC5XqMkPT5G81+qw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843948; c=relaxed/simple; bh=9xYejbTsMqPSOXn2VRkpXTwV9QuCSouHSLTY1kVq0MQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hjDyLblPg2fyPlnCW4fOesMyI7lDOM/MTpxYXtUKE8xMWKzwkdMaU48r2oB20YgpZeQWTZ1d1iOntRrHyxIPV+KKJG9bIUmhMjx/tk6iLs+6Z33XSM4Cmq4MPrBpsca95+YHXydMAcktJcHUFpQaS7YYV4U0heSt7SuAAjr8Wl0= 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=BSsIqsks; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BSsIqsks" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5dbf65c0c4fso688286a12.0; Sat, 25 Jan 2025 14:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843945; x=1738448745; 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=0LLPfMMYnBwvIdSToQLkDYYTjQ1B/ayImtWoWj8Jx2M=; b=BSsIqsksmwCidDhzr2zNp4oRdlfo1mKeV868g/33XZCnFE7xOM5Bp0cK243Bt5z5oA 35c3lI+qPbhcNbrqQ/ESQCMRWyXTnTAfUy8w8RrnTiUULS2Q1SRycpG5StCn4kx2yK2/ FiUIElmLjwvsEzqQl76JbYBXffcEI6qJXx/WQnw8Uslp1qk3qdOB94WtSEcpyQNNtsDr Ra/kz6N4k3iHrP26haPI3w69auXr8ZYjY+DQRdlVqm6ywdKaD5LPzDwUjIFE/AyjD3B8 XXXbw105Ik0BX+5Ob4c/8hWznajyA8ZGu6+WkBHtgcIuHN+dGDFeqHW5pOZ0hBJn5Un8 tT/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843945; x=1738448745; 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=0LLPfMMYnBwvIdSToQLkDYYTjQ1B/ayImtWoWj8Jx2M=; b=G+NTG5vodz3L/IxY0VSQ+6bWaUXxAN5f7+ufRfljDsxMx+5f0+HByHPQcw/xYRiEWS shAUT9sKNbS9fT0kTWacimhj8N+BpngXWRuHNfaQNXORYFW4FEVVnMO9zwwkItHLsnaL YC+YAD4G6Varshc6irKuy4aejeaHI3dKE++piEJr99kcPZsV/Z+RAAN1Sry8+ImtTQt5 kAduOWdSZLgRp6p8Nx/wx1UEZelAefrrKaOIoELyjEB4Lk4WDn3c6Zq5wgA3021FHt5u zeMmagzfIi4wVOD1oruN3GO/YWjaz8+7oLuuT+/S+kSoVUYrgtFW+323y3YU5oA9NHiy Kj3A== X-Forwarded-Encrypted: i=1; AJvYcCULxcaZZCZRK1iwAORuSVb/XpYYIoyWI0VoR7viJkZEywgurcoZo20J/XBuKhywmDHrTkD4LvR2PxShdQ==@vger.kernel.org, AJvYcCWGKCCMg4hHKyJsxqexgWaZedN6zolFu2dTNFgBm2XXvH5ZfSzwvm4+P6dBIhlyhnxE/yWjvHv5HDLE@vger.kernel.org X-Gm-Message-State: AOJu0YwP4bnoxi2OffZpwoPOtgaZpX9mMuKw9aP2GyUSRDEfdRN6btqu yGhCLqDMkNJRMfUN6gb/goE4a5hzHIeoqTq0mvXiIKGXdetChKoW0efPnU8D X-Gm-Gg: ASbGncsV24dTQHLj+YtWKtFGXawPzaZIle2U/RLenUdxsDt96MHXOkgyfqgjTs06ceS 08haE2lH+651n+YkeuhCnOcrt0L3CBYTn6bvy9Zv/hogGbUbhQc/iu+BA56YOfSb+gxJvH3sbfk 2M1p4eNFC5y/Y4d8TqYyppOiC2KJByWI9jyMOb6nV58lsw52sFw2OE2+iUlD6Nodxc/8oQyvEmN 9RoxV0D9O6qcCdDNwBDVIHV2OzddFGusqo+ARNK3Od6Ii0lVnB4dHdXkyGLR7R0AJXgkVqMiC8s bdmvbqcrWAm/37fbJEfFFjrrMbIhHbyjBsVFrfUZK9n7zI9InjM= X-Google-Smtp-Source: AGHT+IGEp2wEabFUjHAe7xqN40DD6q8nhW3/KZjM0nmUyGQ47gFursyOoy7Vv6jpRhQn0ikFJcI28A== X-Received: by 2002:a17:907:3ea3:b0:aa5:a36c:88f0 with SMTP id a640c23a62f3a-ab38b3d71a6mr1184254566b.12.1737843944830; Sat, 25 Jan 2025 14:25:44 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:44 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 10/17] HID: Add hid-universal-pidff driver and supported device ids Date: Sat, 25 Jan 2025 23:25:23 +0100 Message-ID: <20250125222530.45944-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend pidff compatibility, usable button range, manage pidff quirks and set improved fuzz/flat default for high precision devices. Possibility of fixing device descriptors in the future if such needs arises. 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. Changes in v6: - Support "split" devices with a separate "input device" for buttons - Fixed comment styling 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 | 31 +++++ drivers/hid/hid-universal-pidff.c | 192 ++++++++++++++++++++++++++++++ 4 files changed, 238 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..4870811aa2c8 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,13 @@ #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_V10 0x3245 +#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_DEVICE_LITE_STAR_GT987_FF 0x2141 + #define USB_VENDOR_ID_LOGITECH 0x046d #define USB_DEVICE_ID_LOGITECH_Z_10_SPK 0x0a07 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e @@ -964,6 +980,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_R3_2 0x0015 +#define USB_DEVICE_ID_MOZA_R5 0x0004 +#define USB_DEVICE_ID_MOZA_R5_2 0x0014 +#define USB_DEVICE_ID_MOZA_R9 0x0002 +#define USB_DEVICE_ID_MOZA_R9_2 0x0012 +#define USB_DEVICE_ID_MOZA_R12 0x0006 +#define USB_DEVICE_ID_MOZA_R12_2 0x0016 +#define USB_DEVICE_ID_MOZA_R16_R21 0x0000 +#define USB_DEVICE_ID_MOZA_R16_R21_2 0x0010 + #define USB_VENDOR_ID_MSI 0x1770 #define USB_DEVICE_ID_MSI_GT683R_LED_PANEL 0xff00 @@ -1373,6 +1401,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..55aad2e4ac1b --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,192 @@ +// 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, 2025 Makarenko Oleg + * Copyright (c) 2024, 2025 Tomasz Pakuła + */ + +#include +#include +#include +#include +#include "hid-ids.h" + +#define JOY_RANGE (BTN_DEAD - BTN_JOYSTICK + 1) + +/* + * Map buttons manually to extend the default joystick button 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) +{ + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) + return 0; + + if (field->application != HID_GD_JOYSTICK) + return 0; + + int button = ((usage->hid - 1) & HID_USAGE); + int code = button + BTN_JOYSTICK; + + /* Detect the end of JOYSTICK buttons range */ + 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 i, 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 device contains PID usage page */ + error = 1; + for (i = 0; i < hdev->collection_size; i++) + if ((hdev->collection[i].usage & HID_USAGE_PAGE) == HID_UP_PID) { + error = 0; + hid_dbg(hdev, "PID usage page found\n"); + break; + } + + /* + * Do not fail as this might be the second "device" + * just for additional buttons/axes. Exit cleanly if force + * feedback usage page wasn't found (included devices were + * tested and confirmed to be USB PID after all). + */ + if (error) { + hid_dbg(hdev, "PID usage page not found in the descriptor\n"); + return 0; + } + + /* 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, "Error initialising force feedback\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) +{ + int axis; + struct input_dev *input = hidinput->input; + + if (!input->absinfo) + return 0; + + /* Decrease fuzz and deadzone on available axes */ + for (axis = ABS_X; 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, + axis == ABS_X ? 0 : 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_R3_2), + .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_R5_2), + .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_R9_2), + .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_R12_2), + .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_R16_R21_2), + .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_PERMISSIVE_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_V10) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_LITE_STAR_GT987_FF) }, + { } +}; +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 +}; +module_hid_driver(universal_pidff); + +MODULE_DESCRIPTION("Universal driver for USB PID Force Feedback devices"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Makarenko Oleg "); +MODULE_AUTHOR("Tomasz Pakuła "); From patchwork Sat Jan 25 22:25:24 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: 859988 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B66D207A0F; Sat, 25 Jan 2025 22:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843949; cv=none; b=ZJ7PCo49NrGnI81+fcIkXSlX/yL/b5dS1kleDChAtS2eO6r2H3X+vHJk6mzCrPQuGyjwjvcCXEBvw8CxzEFxt4EeO54vyW3TrGfxqPsufsOgBHv/s9LOf66IlaFU8uAL05GyRpxzvvkmUiNHk4HQDA1O9UyV+hBm10g2zXqdHLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843949; c=relaxed/simple; bh=DVgZ83PVL6NnJFKcDjkzIhQs2MWgZtlclRk4R9cyUPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OK0/3ZSDJKUXvjVvpFrgnvUnGx1NMzeE/qBFLAxTE4XmPukcC0/9qVpShWwZ4ODiT21AV0yoW7diSS2P48IDMw4BlGQCkGPRZf6x426eck0IBbjhsIWZzrLB2Osq3iSh/QVS311+0uW/kpGm1uj7Li9kCf4DxSL22bvHPbHpTfQ= 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=hM0kkHsz; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hM0kkHsz" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d3e5c225aaso687848a12.3; Sat, 25 Jan 2025 14:25:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843946; x=1738448746; 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=uPl4w6umobhEqf9EmYNSdxjaWz+J0Z6puIKS9uYnr3A=; b=hM0kkHsz2ftjSiroSJQmvnJcRFdT1BdOKnTrvdVTnqpzIrU8mvdQkWKZCzMs1kag5b //eD6uzg6VbYR08olyNuHfbqSM5aeULRwlUz2JMSRrW6r5uvBXgzE0W2T3OuZJy6cBxO JtTYnhfgHP8ZRDeWUM9rViVO+njSi32BnagtAWWKDSNAadmsjCOMp2t4uLOTNFo2/ST8 9GP2Su3EU0Zlua6nJljBJfDbOXWqN8mfTbOOBEeUf3xT6RNecfX9ezTkfsDxwrj/GKVO 1iNr7wm/FI0BYYFhUSZPI2QP3uzHIi1hRpdzF3Kpe2leT1DXjIIwscqkJMRlaVpoj1i3 ysRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843946; x=1738448746; 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=uPl4w6umobhEqf9EmYNSdxjaWz+J0Z6puIKS9uYnr3A=; b=mde8F1BgVQkVzY/IAAbJqTmQ+1n55skful1kss0ERWzK3h87gWp8rr7EKb/Jw5R6O1 U4beR6/DvkzhG1vWDlezObJY9REuqeeCElkmVD2GU3u7heasDmGxtxpY1ifnD01sg7dU rwg6P+jJvSkcGW0bCe2hzuvXizrpO/JcTel0DQKzirxKnaVG2dwxY6GMBCZ7MlUDUjpd kn3iNRwR7mnD1jsRW82/aeN9q/gxULiMKb3KPJ5+TduBd+MnAbjzWFiCuATu7Rix3QAC t8he1hIfjx/30H6wpdp+IgEPfr4K5oEpxsYjLTx8FRja7bwTjiRq45RIP/rMBM6HZfKD ZEhA== X-Forwarded-Encrypted: i=1; AJvYcCUDc/6UyiBlTt303uw+aguFgyIy8AyqcB52Ni3SO8Ss3tO1FDXmxqwi3Gbo7JfyzssVS7Sy/qeU3FNmQQ==@vger.kernel.org, AJvYcCUxRhdGA9PXgnLlEjhJ9KizJuWlvRVKagqYlK4AwCGjICnIAmFOXJkOmOrkUbmFWuBXhy3l49p+mRHD@vger.kernel.org X-Gm-Message-State: AOJu0YwiapH1Kq8FsZz1ofVvFGKdGIM1knc2jqx2s9Mk+xsG+3sDqBEw t9SEybA2RyWNuF7j6bscwDEL+oLzRMz4uR/HSj/Yl3YTty/JSs4b3M3HRSSt X-Gm-Gg: ASbGncuCVbmQr+UbH0OJerERobBq/pfT8w4GcfOtQjt0ZQ0vKwR7xVJ8EFuNB/0sgfy +6JP3GNnNtfnQpNPHYpbCgXhianCUaudgBn5O3y102kzMk34+k1Z5X6OF8DAZ9So+sY7Fgf8PE/ aJGV3RvKiK6YAtjXDI37DZ6z49vKFdbuooBYf2T5eoGVQMMPlpK0D2857H7vVVeXTAyjgdydB6K c0tZXnGuVFBt/WTvufNbBBjJF04CBT3KhOuCT+M7mt2VqI9vCayfpVl/e3satjHEWIAspctZalW YJzXK/ziaBr+IQPRt3KnhCYVN0sUaoJcqyoI3Jh/fg863ynwvFU= X-Google-Smtp-Source: AGHT+IGn8WKOuXdOks9KkEU1eyVnluu02ZHzQqmozqDcfFL1m93bLEHCppAYGdAIKiE42JkMTutFEw== X-Received: by 2002:a17:907:3e1d:b0:aa6:6e2e:b7b with SMTP id a640c23a62f3a-ab38b1b4679mr1242277666b.1.1737843946380; Sat, 25 Jan 2025 14:25:46 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:45 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 11/17] MAINTAINERS: Add entry for hid-universal-pidff driver Date: Sat, 25 Jan 2025 23:25:24 +0100 Message-ID: <20250125222530.45944-12-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the MAINTAINERS entries for the driver Signed-off-by: Tomasz Pakuła --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0fa7c5728f1e..810046532e0d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10209,6 +10209,13 @@ 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 +B: https://github.com/Lawstorant/hid-universal-pidff/issues +F: drivers/hid/hid-universal-pidff.c + HID VRC-2 CAR CONTROLLER DRIVER M: Marcus Folkesson L: linux-input@vger.kernel.org From patchwork Sat Jan 25 22:25:25 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: 860145 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32BFF207A23; Sat, 25 Jan 2025 22:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843951; cv=none; b=DtbvIrXTCnbo9SMLM3Fyc0utl1npEYI3UZR5DDf+5MDUuLgdqGWnJUO48fJPwag1WWhVHtJ2R6wv9etDLyM6xyYqn5oR7G2t7mdsSbsEZo6kJt/68A9FeT0PjBJtyBpGPiuexngiNBMr8OuOtM0Hta+adhiySXNDMGv/9BF3Uzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843951; c=relaxed/simple; bh=ZaZAk1C2xIJCkzjhRvpDAUxa7JWqiqQUSb6ApMEF6n8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s1s3OhO3NNUImJzcMzoGqIhgxfv65zBGRvj97IWNREiARqj7Hmii0Na79hKIYy2M5qA+8lKyiMUGF2OFufkmdfCQ7kpLKpbg31bPLbPIw/TK1xMaIulBp2YOS2o1i1x2kjtgpQpRwZhXxfOKaLdCR9Pwh3FRC8F9ACxy1I2CIvg= 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=DvbMkS2R; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DvbMkS2R" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ab69712eaffso8521566b.3; Sat, 25 Jan 2025 14:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843947; x=1738448747; 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=T39P56OhkmFQzv19vK4YQ7IqiF3JTzwVZZZdGJECCxI=; b=DvbMkS2RtSorz8mtU8/va+wJRxUS7UsJJib93/72dS2nas1MTraefTFW+vqt5T+Sfn CvX4pGCyYsZLJ9m7kkPsGCz6FiFuOjf7qpNKKrecvDf7140fEzieOzsB8HUtGiNvXOHM Iwe3slCp5swmtaa4m+jS19cvI9aWf779bPSZ3aRkQceCrrx0B0KnNBF3iVVhiSXmDk3I iIo3aLKCbGcLEvoTYyO4bqhupOaSW+DmSXtOs2zLH/TACjmYSwWmBMpzFVlE/a+Ob9jQ mq/axRCKv34j602BRIodXZb1CDYKULEKjf7xpei0aauvXWlbgbCLKLw0l8a/3sSTG6zD +XWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843947; x=1738448747; 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=T39P56OhkmFQzv19vK4YQ7IqiF3JTzwVZZZdGJECCxI=; b=jWkaQZXTYCG7Vp8i5Vet+F7WHxLpf3krG8Akl54ct2ujIfBvMMtULMLgb99kUBeG+k Z03Q/orWM6Ex3sfL0h/PuzKZkCI9ugugZWnjtO/5nDHuxuFDTjxOIi8P/K5r5WrFE8P3 zrZ01HG/4ovn9SE6woc2rklT8j7GTBrXgTJcEgVGap7CDguk2ez1CJAGu57tOQRx8MhW ATEp7pypUpMt0yoi2m8ClD0ltZrE8hWRA31rsoewNmfL5+n4EiZufRxrj8giWsKn8Msg M1Tw/pGZqv62L6zBOumXJQY3tpqvUzmb4CRtgtACr7J+DaMZqc7Ha1pytTy+9uD+N7R5 wb/Q== X-Forwarded-Encrypted: i=1; AJvYcCUYm/uK8gpphb3opceujWABI21z5/Qt1PZZvYyMnkpfa6o70zWcD0iD8hRmKqBKcNB85Vz4yv/s85JAOg==@vger.kernel.org, AJvYcCW3FG/03VNBsDJhU3ip5QyZ4pqAD3ifhvVr6e9Ql40IlzsXjPcNMvEzG6ZQKjXO2BWDMysN14GhBQjy@vger.kernel.org X-Gm-Message-State: AOJu0Ywcf55Xg+jOvNzYOygKtPPNTWcMva3jqjq8JRFTVNMT4UP8Q92o C+Mzy841dLG1t/fTYR5VXu9Dkac6hpNtb4ukgGg2VgVQ6kYR4BYh X-Gm-Gg: ASbGncvA3WW321YcFuJw5c9DDQ/yuA7aFJmH8rqC81keYCAkIefE7zPsFEvysqnYTY0 S40tYH98ifTubE4OmTdnq5Jz3moC5/InMuHT6T9jW/ok/rgO2iRZEONsT+9JA/9iW0icjlhk/I0 EmClOe1TtSbPA6ZfQ+llDj3/v66zWIaq8RqZxhjVz+7UWSlMRehZ05Ay3Dm8IfDFkFPXU82ThPV Iwi6zPTCqN9B/5E973CnsZWWHDiZfTEZam+5xGapSpsYITxtuI3p1Q/Q9kYs3hhsoAa4QfVHXfG Ts0x5hL2jGoHpaUXg0GGh6MSIoWOdyU85mARJdqg0kbFVD77Wro= X-Google-Smtp-Source: AGHT+IH8VYcTj1pf2OBwdw+KZKoDrj2QiaBQVOAzaX2BuK7bCTlwyUB4k8UPxuhaeba9ee9PwfRIjA== X-Received: by 2002:a17:907:3e0d:b0:aac:619:6411 with SMTP id a640c23a62f3a-ab65167653cmr618345466b.11.1737843947411; Sat, 25 Jan 2025 14:25:47 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:47 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 12/17] HID: pidff: Add PERIODIC_SINE_ONLY quirk Date: Sat, 25 Jan 2025 23:25:25 +0100 Message-ID: <20250125222530.45944-13-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices only support SINE periodic effect although they advertise support for all PERIODIC effect in their HID descriptor. Some just do nothing when trying to play such an effect (upload goes fine), some express undefined behavior like turning to one side. This quirk forces all the periodic effects to be uploaded as SINE. This is acceptable as all these effects are similar in nature and are mostly used as rumble. SINE is the most popular with others seldom used (especially SAW_UP and SAW_DOWN). Fixes periodic effects for PXN and LITE STAR wheels Signed-off-by: Tomasz Pakuła --- drivers/hid/hid-universal-pidff.c | 15 ++++++++++----- drivers/hid/usbhid/hid-pidff.c | 3 +++ include/linux/hid.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c index 55aad2e4ac1b..7ef5ab9146b1 100644 --- a/drivers/hid/hid-universal-pidff.c +++ b/drivers/hid/hid-universal-pidff.c @@ -168,11 +168,16 @@ static const struct hid_device_id universal_pidff_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V10) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_LITE_STAR_GT987_FF) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V10), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_LITE_STAR_GT987_FF), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, { } }; MODULE_DEVICE_TABLE(hid, universal_pidff_devices); diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index c125f029b6d6..e6224e797dc6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -651,6 +651,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, return -EINVAL; } + if (pidff->quirks & HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY) + type_id = PID_SINE; + error = pidff_request_effect_upload(pidff, pidff->type_id[type_id]); if (error) diff --git a/include/linux/hid.h b/include/linux/hid.h index 856bed149246..c6beb01ab00c 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1234,6 +1234,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_PERMISSIVE_CONTROL BIT(2) #define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) +#define HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY BIT(4) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sat Jan 25 22:25:26 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: 859987 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 56B412066E2; Sat, 25 Jan 2025 22:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843952; cv=none; b=g7ChCn//QqCBHNT+Lz9YU0b9bVRFexSsV3ZJLpYRUx++uMDaZ1Egs9TrJne9ImuSNvEDJXhZe0mb2mwElx4nGVZ6iA9hQCD55UTatNPgliX7MhXoi7QIJ0VTxLmVVU0HXqBVF1s/44+YV2iavnevYysEStLS/d0FOOL7Wc+YdG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843952; c=relaxed/simple; bh=qxd9mWeHk06PwUuhqRFs8xF2iGsgst6bNefZ/BWNDQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q1LqAv7C2+EFFXWiZoCqyBkTeUnut5bG8EErYPSZouFsIrrxKba68S0Q1rFAKu4K4geK+N7u9Io6LKKX+FUCiECpuRaDOk5rmuvbQcdA1UfmR2buqe9L08/Z1TFlzqM0pKVoMaQBwAdCAVG1hQN/RFgpFV0+e9o6E+SS4H4xP9o= 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=fb75JMvn; arc=none smtp.client-ip=209.85.208.49 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="fb75JMvn" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d3e5c225aaso687854a12.3; Sat, 25 Jan 2025 14:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843949; x=1738448749; 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=nnbFZzECsexvmY3/x8I8GG9kNQnLCxxOnzANN8WXTnI=; b=fb75JMvnyUyXlgdcmSAydHLFRQdRey4CqT0f5sRuvCSW88DTb+pi2N9N6yDuO0eYFT KZbKRIGL2JsVOEVOgzZtPhVOMWOQlNrxiwhfhCqZ2MS2IRZEiyiA4rzw5BXk2ArlEAac rXoKMKw1d+566QslWRVJm+uDsyo0Mn6khLlsvMMywk3tRRN7N+2gJLiccwLTwtqutxdD MEAEMq6VarFsPKBh+sZ3QGSvgdhTD9ZNbtlNd+XtY3OapPwREt/wB3bjfci3HmOFuKky DUUZGLNyIe6GY98Yf6VwGtaA2LkT8UvRMcDURTTVJOJrZI6AoKZ5Qcjfc83SA4DwN+qR XQFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843949; x=1738448749; 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=nnbFZzECsexvmY3/x8I8GG9kNQnLCxxOnzANN8WXTnI=; b=Vsq7amGb4kVpQRRNtaPlNmk5nfRPgA60n9vStW1MzJerFaANnx6gpkT2NsBcW35VpB 8Zrzgrjjaeo/pAxc+ezmGQ208XabO40KzUF7zOEYwEvSkLoL4rsGvvQvzbAkuyigpwtq ZpwfjI9IZ/e9phlcIFzI1wB0By+gwfXheKNhMyWO404f4EAqH6duHAv9fYzR9oIzm2qd ftZ8Dclele+gwr2GX1jwDeBuCgrLOa+OSXOJggZTbQEWVpDgaa+O06wfn4ak76TqA5rV 7bjEYyyTgy/1DGRtkcrMr7tUjizBXSV+v5kSTT/l+Arn7ZvGESlyF4aX5f28CQ9HB/Yr 8HiA== X-Forwarded-Encrypted: i=1; AJvYcCVQJn16uX+f9WjzCLk6iBbza+vDlnBYC2DYo5cjTab3ufPHnpulSinttfUTyEAb8+JoVCh8TGx5pLfMeg==@vger.kernel.org, AJvYcCXrye/5gRGnTmsct3DdoQiWnwAs94E/qIsFHwcEp9WYPKXkKKOcWIVefi2XPreHhbSa1y1ZbLLPY5An@vger.kernel.org X-Gm-Message-State: AOJu0YwScbipwEZrN0LFsB4+lX+AbCPLvZsxQruclBJfoJJ4CR1g0Cd8 PtFfbItLPG60cPIzaLgbpyJou4W6geen4xPKspTjNNvhao1ZlPW7 X-Gm-Gg: ASbGnctpihyLXyhg0oCmD0ZvtMme9GQeXveqlHZl6h+TBNglvcbqIWYgVG4FWSu287Z BTJ1/gY2oAuk1nT74p6XMoHqFNPlmjUzObbBP7h3L5ocYZeEvv0dswUNruOFweL+LNVc1PpvpNa xDDr9zxF/XULzvZdE4760sg/dyIokrM7r5uuVFG+vYcK0ZP47//8+JpMRIJm1JQXibpJckX8RDZ G//CW5Md08fkONnVriTc8yg4HmpCBzZCFt1v77jwvezszT6dbN+9Yf3AbNOcSlmwx4oeSHj3xc/ Z7CbT81HDhOrGyEG7imjK4hX9Ck9ZO5R4adqpOL3z4dgJY0kYYo= X-Google-Smtp-Source: AGHT+IGZWR1nAQGCcTHx2RxRSTF+ih8MJP3R3AcwdNMaTyv7EFmuLxQg5x/JqxHSMVS8ZrXqkNQQEA== X-Received: by 2002:a17:907:d0b:b0:a9a:2afc:e4ef with SMTP id a640c23a62f3a-ab38b2cecccmr1377418866b.7.1737843948421; Sat, 25 Jan 2025 14:25:48 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:48 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 13/17] HID: pidff: Completely rework and fix pidff_reset function Date: Sat, 25 Jan 2025 23:25:26 +0100 Message-ID: <20250125222530.45944-14-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previously, it was assumed that DEVICE_CONTROL usage is always an array but a lot of devices implements it as a bitmask variable. This led to the pidff_reset function not working and causing errors in such cases. Selectors can come in three types. One selection of a set, N selections and Any selection in form of bitmask as from USB Hid Usage Tables v1.5, subsection 3.4.2.1 Added pidff_send_device_control which handles usage flag check which decides whether DEVICE_CONTROL should be handled as "One selection of a set" or "Any selection of a set". Reset was triggered once, on device initialization. Now, it's triggered every time when uploading an effect to an empty device (no currently stored effects), tracked by pidff->effect_count variable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 139 +++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 49 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index e6224e797dc6..689bf516ec55 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -109,9 +109,10 @@ 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_STOP_ALL_EFFECTS 1 -#define PID_RESET 2 -static const u8 pidff_device_control[] = { 0x97, 0x99, 0x9a }; +#define PID_DISABLE_ACTUATORS 1 +#define PID_STOP_ALL_EFFECTS 2 +#define PID_RESET 3 +static const u8 pidff_device_control[] = { 0x97, 0x98, 0x99, 0x9a }; #define PID_CONSTANT 0 #define PID_RAMP 1 @@ -190,6 +191,7 @@ struct pidff_device { int pid_id[PID_EFFECTS_MAX]; u32 quirks; + u8 effect_count; }; /* @@ -490,9 +492,84 @@ static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old) effect->u.ramp.end_level != old->u.ramp.end_level; } +/* + * Clear device control report + */ +static void pidff_send_device_control(struct pidff_device *pidff, int field) +{ + int i, tmp; + int field_index = pidff->control_id[field]; + + /* Detect if the field is a bitmask variable or an array */ + if (pidff->device_control->flags & HID_MAIN_ITEM_VARIABLE) { + hid_dbg(pidff->hid, "DEVICE_CONTROL is a bitmask\n"); + /* Clear current bitmask */ + for(i = 0; i < sizeof(pidff_device_control); i++) { + tmp = pidff_device_control[i]; + tmp = pidff->control_id[tmp]; + pidff->device_control->value[tmp] = 0; + } + pidff->device_control->value[field_index - 1] = 1; + } else { + hid_dbg(pidff->hid, "DEVICE_CONTROL is an array\n"); + pidff->device_control->value[0] = field_index; + } + + hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); + hid_hw_wait(pidff->hid); +} + +/* + * Modify actuators state + */ +static void pidff_modify_actuators_state(struct pidff_device *pidff, bool enable) +{ + hid_dbg(pidff->hid, "%s actuators\n", enable ? "Enable" : "Disable"); + pidff_send_device_control(pidff, + enable ? PID_ENABLE_ACTUATORS : PID_DISABLE_ACTUATORS); +} + +/* + * Reset the device, stop all effects, enable actuators + * Refetch pool report + */ +static void pidff_reset(struct pidff_device *pidff) +{ + int i = 0; + + /* We reset twice as sometimes hid_wait_io isn't waiting long enough */ + pidff_send_device_control(pidff, PID_RESET); + pidff_send_device_control(pidff, PID_RESET); + pidff->effect_count = 0; + + pidff_send_device_control(pidff, PID_STOP_ALL_EFFECTS); + pidff_modify_actuators_state(pidff, 1); + + /* pool report is sometimes messed up, refetch it */ + hid_hw_request(pidff->hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT); + hid_hw_wait(pidff->hid); + + if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { + while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) { + if (i++ > 20) { + hid_warn(pidff->hid, + "device reports %d simultaneous effects\n", + pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); + break; + } + hid_dbg(pidff->hid, "pid_pool requested again\n"); + hid_hw_request(pidff->hid, pidff->reports[PID_POOL], + HID_REQ_GET_REPORT); + hid_hw_wait(pidff->hid); + } + } +} + /* * Send a request for effect upload to the device * + * Reset and enable actuators if no effects were present on the device + * * Returns 0 if device reported success, -ENOSPC if the device reported memory * is full. Upon unknown response the function will retry for 60 times, if * still unsuccessful -EIO is returned. @@ -501,6 +578,9 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum) { int j; + if (!pidff->effect_count) + pidff_reset(pidff); + pidff->create_new_effect_type->value[0] = efnum; hid_hw_request(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT], HID_REQ_SET_REPORT); @@ -520,6 +600,8 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum) hid_dbg(pidff->hid, "device reported free memory: %d bytes\n", pidff->block_load[PID_RAM_POOL_AVAILABLE].value ? pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); + + pidff->effect_count++; return 0; } if (pidff->block_load_status->value[0] == @@ -568,12 +650,16 @@ static int pidff_playback(struct input_dev *dev, int effect_id, int value) /* * Erase effect with PID id + * Decrease the device effect counter */ static void pidff_erase_pid(struct pidff_device *pidff, int pid_id) { pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id; hid_hw_request(pidff->hid, pidff->reports[PID_BLOCK_FREE], HID_REQ_SET_REPORT); + + if (pidff->effect_count > 0) + pidff->effect_count--; } /* @@ -1211,50 +1297,6 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) return 0; } -/* - * Reset the device - */ -static void pidff_reset(struct pidff_device *pidff) -{ - struct hid_device *hid = pidff->hid; - int i = 0; - - pidff->device_control->value[0] = pidff->control_id[PID_RESET]; - /* We reset twice as sometimes hid_wait_io isn't waiting long enough */ - hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); - hid_hw_wait(hid); - 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); - hid_hw_wait(hid); - - /* pool report is sometimes messed up, refetch it */ - hid_hw_request(hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT); - hid_hw_wait(hid); - - if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { - while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) { - if (i++ > 20) { - hid_warn(pidff->hid, - "device reports %d simultaneous effects\n", - pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); - break; - } - hid_dbg(pidff->hid, "pid_pool requested again\n"); - hid_hw_request(hid, pidff->reports[PID_POOL], - HID_REQ_GET_REPORT); - hid_hw_wait(hid); - } - } -} - /* * Test if autocenter modification is using the supported method */ @@ -1320,6 +1362,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) pidff->hid = hid; pidff->quirks = initial_quirks; + pidff->effect_count = 0; hid_device_io_start(hid); @@ -1336,8 +1379,6 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) if (error) goto fail; - pidff_reset(pidff); - if (test_bit(FF_GAIN, dev->ffbit)) { pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff); hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN], From patchwork Sat Jan 25 22:25:27 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: 860144 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6696A207E15; Sat, 25 Jan 2025 22:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843953; cv=none; b=OPStf94CmZ8QJaDSNDdL4OCyuKQM6HsmPPgCOJw1zrie7UQGAesbFJDgIfblO3b97Kn4ot33HDipneysSLnfphr3kIBIjm/ZPiTHW9TqbL/2rMfAzw4tIRscDYBMNY4bRPAynOtqhl8hBqfAciQwcZM6bqf7kNoZA4s3ZL6THG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843953; c=relaxed/simple; bh=77PSDrwLmmq4FWQbrc+YH5RAdDh5nE1TbHTRgCw3ejQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dMWYLvs3DJLuEnxY3upDGDXdPLqBDdOTPMUm0lbzAF2vTPtdSBf7Ifk0SAKRZfn/Vh/k7eePvG3MHJwhOs9LfIFRawYwkFDWCqwB6A0ybpBKq8XHrlgHCsyK+e1s0s12rU3Qn6HkzT9wmrSMh3HKwbPj0dmAqi06fil0YuPvbTk= 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=IabFdap8; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IabFdap8" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-ab30614c1d6so61135866b.1; Sat, 25 Jan 2025 14:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843950; x=1738448750; 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=4eXjXRn/HZloxKfWmPvwvQzBKEFXRB7blnXKlca1NLg=; b=IabFdap8HdLjTGqaGpjfV/cNteXCklRb40KXbWSrZOitwSBGdIc7cfMBfiPG6EhI8Z G+jUu1Y/BLPSCj/c0tNiqIRDiehGrKL584rgTw28JXNA4C7L+ae2xsvBKQnIoRQmpGPx /WF2JumUbhTZYVeVFZILxyrn1Cmp5FvgAvYGAxZ7kMzzT04aVukHnfxYqLLnLrOwaFiw YaQgxc35Faava23OSu3HsMNnsVN4IAbev+Fm6/UQMCUdKgdfl05XlH22CAIZUN7cMVaA Kz01kSWJTWNVYrbnW4IMtUDJ5A6sCtq+S9s9mtgrIh8L6gPFG0bLqtHeHdLYLfQJ+dFk wE8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843950; x=1738448750; 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=4eXjXRn/HZloxKfWmPvwvQzBKEFXRB7blnXKlca1NLg=; b=CjWlF/KOk15CadPr3e0XkNMydHJUESU3R+1s43Z6ya6Y5f0Sj3TQVZhzzjSFDAA5tC T+Ptu7dRndgOgSG807WLypVBjvF0t/vfvRv3Saxdw6igBK8rOyTTw3G43PS+oW4wqJGo nTNLidZJRF9rlKZj437iWtFFaUKhTbxz9xvD6bu7uenqPwbtKrX1/5P4I5QkFYOovweM T8mvE/66Tpfz93bkUX9umQcdkWmodf89uzitEJUEPg0JOpWF/7DBoVhdKM3Hzp93BAAx 3i5B4pboUoCQ1TP9LWiV7xNz0FOnSwfzDY8eds/5ZZxanA/B7SbaC3n34jHbSbbmU3D6 3VVA== X-Forwarded-Encrypted: i=1; AJvYcCUtx4ouKOlmuNX22KC78Mzy7CFrFy+AXVYtS9yJ421pHwO4fgYZR05FKdQvS9EbVJB7r2Voo2ZM7lBLmg==@vger.kernel.org, AJvYcCXUaDUmPPlKo+gURgsIfTSN/ZpMN2IPB//AOw6gB00j/T8boo2eX1wDGe8V5jlNcOqYKShTaiS1mmwe@vger.kernel.org X-Gm-Message-State: AOJu0YxaLIErXVFRUJyNUlGq3XzbaI+UX4LN3EbAjRsA/qk1FaQndj02 DRP6Sj6isQnEepsbT/rmaGJBWAEuO0kEGv6QvzptSbouBIg0LrLG X-Gm-Gg: ASbGncvBQBipoKTrVI/5Nllx7Nn+8WEWmGYdIUCiJNPP5sskbKgHZ4n1kmvCNOwRZnA T26N5slFWuE2LNLiSG2xKn+Q0pX4qCgG4p/0Mur4YgZo0syc0gaAm9NZbiZh7JetWFGnWFkHYvH BQUxRHEXFwJZESzR+qPZvuocVepkJY339HnJz7xYc2xPWZ5f7Av26uyYoKoU6MX2gJX5LD0FNp7 Q2B8NUlNknU/Zio2OMfGIR/HvP/o/qv8JiG1OPNno8CLgF9Df30vbUoMCSRp/bM1wx+HrSTSwvC 5qtHLmNBbOFzJbl3y39DT4CO1RWi+xvaWRw3YerPennksY0HxnA= X-Google-Smtp-Source: AGHT+IG0kIth/bfnOxkKTu/sp7T1xrIDdxcL+sdb83Pc0JsZSHbGlPWJ/NtGbfaaWyjNAjdUCsWg1w== X-Received: by 2002:a17:907:7d92:b0:aae:c058:b8d5 with SMTP id a640c23a62f3a-ab651653889mr670144266b.10.1737843949517; Sat, 25 Jan 2025 14:25:49 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:49 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 14/17] HID: pidff: Simplify pidff_upload_effect function Date: Sat, 25 Jan 2025 23:25:27 +0100 Message-ID: <20250125222530.45944-15-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Merge a bit of code that reqeusts conditional effects upload. Makes it clear, that effect handling should be identical for SPRING, DAMPER, INERTIA and FRICTION. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 54 ++++++++++------------------------ 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 689bf516ec55..f6dc6db0b59e 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -771,48 +771,26 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, break; case FF_SPRING: - if (!old) { - error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_SPRING]); - if (error) - return error; - } - if (!old || pidff_needs_set_effect(effect, old)) - pidff_set_effect_report(pidff, effect); - if (!old || pidff_needs_set_condition(effect, old)) - pidff_set_condition_report(pidff, effect); - break; - - case FF_FRICTION: - if (!old) { - error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_FRICTION]); - if (error) - return error; - } - if (!old || pidff_needs_set_effect(effect, old)) - pidff_set_effect_report(pidff, effect); - if (!old || pidff_needs_set_condition(effect, old)) - pidff_set_condition_report(pidff, effect); - break; - case FF_DAMPER: - if (!old) { - error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_DAMPER]); - if (error) - return error; - } - if (!old || pidff_needs_set_effect(effect, old)) - pidff_set_effect_report(pidff, effect); - if (!old || pidff_needs_set_condition(effect, old)) - pidff_set_condition_report(pidff, effect); - break; - case FF_INERTIA: + case FF_FRICTION: if (!old) { + switch(effect->type) { + case FF_SPRING: + type_id = PID_SPRING; + break; + case FF_DAMPER: + type_id = PID_DAMPER; + break; + case FF_INERTIA: + type_id = PID_INERTIA; + break; + case FF_FRICTION: + type_id = PID_FRICTION; + break; + } error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_INERTIA]); + pidff->type_id[type_id]); if (error) return error; } From patchwork Sat Jan 25 22:25:28 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: 859986 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56CDD207A23; Sat, 25 Jan 2025 22:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843954; cv=none; b=jNUv20iLuCs2Ei5T4tL+zoZ4TXKA0Kd6wPv84MhBG8b2FlOsz553sgdcPYfe3opMJh3Tr1dwZ3ZVxc38h6UHLQhXqFnJEVHX1kwFnYNgNf+QlnM6lXHwY1JYVj61r1/FfS2VhgycXn8wpM0F2v9nzgZJSwLZvy19xeVN8KLn1xk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843954; c=relaxed/simple; bh=czFo3ZdNRhdH5Wqqju9Ed8/gfHuPubW6sMBfyGq7+Ak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t3q+XuFtE58mLxuU1l6CSBJiQIcEG7ZcwjlEfUCFEjV6uJriAxXCB+SKjQ7sFigjUFdeXup83unyTwephtgdkHknKXq6+pKEg7kr/sKQSv6L4pFXJReQOR25M+JzkT3ICBhTq0HtuYhvQX5DVieNdjy3seCvO8D/Jmae975w634= 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=SMr4E5l1; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SMr4E5l1" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d3cd821c60so682895a12.3; Sat, 25 Jan 2025 14:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843951; x=1738448751; 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=hcrUmuW546Nve81KKGIZzMNKIw4a92ChiOh5+g10Y7E=; b=SMr4E5l17k9CZ4Pfog6mCCt1vyAbz4179y+RbuhY8IOikKq8K0Rzxz2mhjKPU0QnUh UTvDzvlcXoD+TSSFn670q3dO1B/LvsuTcUz9gDo7ep6B3auYcLQp8oS718zrLDyL7kX6 XYbwiWFhQtbqtxoa98sAF6UdsQNfbxhIDjRL+r9JaWLD9jx149wPhkP3ANEkC5q5/0Z5 4MDVIvpAS2QetYP6Bus3L9kqVLv/XoC+yzWJzzMLoYY4kc4ByHdFhxgiUefDzcVODVK9 b9F4Sqtl5EmNX74g9FoFx/BDrRuSzr+fxar1tqQE3+qU06dGptFtDr01Y0eRgibWMO0P Nytw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843951; x=1738448751; 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=hcrUmuW546Nve81KKGIZzMNKIw4a92ChiOh5+g10Y7E=; b=nvu/5kCR5brsBo2kK6+62rOZbQKvwE3RliCDW5mSbkaF+eUvVqEla4PvZ4TW2lCV1U bJZS/x5MCRwcHqQECvWttGd7jclLnVAp8Z2HQWSx95PG4rJ8eUZIj6gEoFOLJxfdZ3De /jNnXAPRdOvHtze1g46pmVnvi2GlWpk+DvXaENZdm3x2tcYbdj2v+SiIwVlfUZttVaM2 ng5buKUdVWKRNC2l1Wk7HDFmZDoF1pvd25TxSZwXNd//UQAN5o9fgrGuEKCw6ukZRZtG uPAmoJyfHpEps7IEoTeALrQSwlpJBrJi/LPXg37qHRauD+S8BXnsIrMfNPw09wTbFrTR KpLQ== X-Forwarded-Encrypted: i=1; AJvYcCV4Yko4E9d2oLIPLhE8rULFJ7+F+EnqQ49OJ2gsycBQBdB7AybV0+vH4RR4QSjUqSFunpigdOny2WqbaA==@vger.kernel.org, AJvYcCXjk9VKyH8GD9mmms5utRDiPni/IgDpepR7qEj+yXIErBF5XBTeLh2MwF/efYA+luieuwWKXBXvPbqv@vger.kernel.org X-Gm-Message-State: AOJu0YxfSFNBRngbC26EiYCFmkQi4NUgnPvN/Jd6AP9QEhHRziV/4gQY a+6dAm9n7Sotsnqo6FgSiaKk6xkUiF8+yNDpNKTfcWQlW/hX6ZQJ X-Gm-Gg: ASbGncuoXFhdeu+rLgwdX4q5ymz5aCWwgeB2tVkmv6jsvHRJHudE0fDR/ycQQTT1xAa YPbLECacAKDT+uSziaCFeYDp/3LYm/D4d0V+3g8iJiCNZ8zjhRvqeuZ8DIX9cmn8eZp0u+hT+Mp QRgu4PGZ4Ux4E+c6MTRb/rAFHYVujtE1BNTq5rD6890Hh2YRuizdkoJSmUO3qrKOZ/Z9ikERErV gsqhf839eaO11VUqpdSKToUxvivtqkurKovdHX4KJu11xQ+SBl55hHKlg4Dl9EQBGDfWdx5F0qi 9fLEww8hqZNb+uKtER17Ix++BKWGeZssX/i5FS7JBgG4xLqNIfo= X-Google-Smtp-Source: AGHT+IFNN0OXy0gqmDXMwHxOqlDTXEW08tMiia3rYSa/Bc7bOs8b6ApZsNOvos34mR68TTWOdgahXg== X-Received: by 2002:a17:907:3ea3:b0:aa5:a36c:88f0 with SMTP id a640c23a62f3a-ab38b3d71a6mr1184258366b.12.1737843950530; Sat, 25 Jan 2025 14:25:50 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:50 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 15/17] HID: pidff: Define values used in pidff_find_special_fields Date: Sat, 25 Jan 2025 23:25:28 +0100 Message-ID: <20250125222530.45944-16-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Makes it clear where did these values came from Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index f6dc6db0b59e..575f24610269 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -48,6 +48,14 @@ static const u8 pidff_reports[] = { /* device_control is really 0x95, but 0x96 specified as it is the usage of the only field in that report */ +/* PID special fields */ + +#define PID_EFFECT_TYPE 0x25 +#define PID_DIRECTION 0x57 +#define PID_EFFECT_OPERATION_ARRAY 0x78 +#define PID_BLOCK_LOAD_STATUS 0x8b +#define PID_DEVICE_CONTROL_ARRAY 0x96 + /* Value usage tables used to put fields and values into arrays */ #define PID_EFFECT_BLOCK_INDEX 0 @@ -1047,23 +1055,24 @@ static int pidff_find_special_fields(struct pidff_device *pidff) pidff->create_new_effect_type = pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT], - 0x25, 1); + PID_EFFECT_TYPE, 1); pidff->set_effect_type = pidff_find_special_field(pidff->reports[PID_SET_EFFECT], - 0x25, 1); + PID_EFFECT_TYPE, 1); pidff->effect_direction = pidff_find_special_field(pidff->reports[PID_SET_EFFECT], - 0x57, 0); + PID_DIRECTION, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, !(pidff->quirks & HID_PIDFF_QUIRK_PERMISSIVE_CONTROL)); + PID_DEVICE_CONTROL_ARRAY, + !(pidff->quirks & HID_PIDFF_QUIRK_PERMISSIVE_CONTROL)); pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], - 0x8b, 1); + PID_BLOCK_LOAD_STATUS, 1); pidff->effect_operation_status = pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION], - 0x78, 1); + PID_EFFECT_OPERATION_ARRAY, 1); hid_dbg(pidff->hid, "search done\n"); From patchwork Sat Jan 25 22:25:29 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: 860143 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D56B2080F4; Sat, 25 Jan 2025 22:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843955; cv=none; b=S+Dd8T/24kwBpj57pGo0HxzGkixu+AQYz9cybgA/rGc81Jtv/AlBkwIvzY8/jSJxXG8zFl7EfioPOBLOa46JSrGL0xwK+YinTXViauNT4vnFJmV/mvK5q/FVCjTjDRkGTKmQxss0snoTeWRix5sYRm0E7gyLmUIZ88VpompXIj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843955; c=relaxed/simple; bh=lokyW7mWWwsidFcyItEG80wDDtCDOSCH2VJ73wHzZow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CzCRX/HKB+faBc+dZR2Nj0ivXzYl/AEcJbM4o+gUTjSyYRiYCVSlflNLGoG1KDiitrJD/fPpjPl6BACeZdB7OQGv17FqOEa/7VF+VLYxXqlKFxthdr+Gazucm9W7IhJGYYVYAygMJlB9gzBtsP08Rz1F8VLWPgPSFpchxGyVllw= 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=Of9Xzjfo; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Of9Xzjfo" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-ab6915fed7bso13027666b.3; Sat, 25 Jan 2025 14:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843952; x=1738448752; 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=GFgZ4QIuflhn/jvNWM6BMtC4DnnhM2UgXT91NawIeEQ=; b=Of9XzjfoW32ao7uegv2R9MZdClzdr4zE+ooZfR3y0rzEHEkSZEuTG/Mt+H6L1JLZ0t dIFrgOMlRL1tAb9QWbWUuCM45sFxPNGbPpIXtb+43kr2QFHOofJADn/cmlTiOz1dqb2U o5lV2KrqSErkf5bGqt6G0NS11rKCO8AF8T6Wow9REPS9yjKRYuFNctzmi6uOfie3cwv9 52F5rL9p8//HYtfoIKY2ZtNnCo8CWtIm2Og2UR5roKoOsmBdyZH+C0nA/L+BFhLgNCn3 S94Vxsz5RRvpBmdoEbElU7s94G4OkfRdVkCSSggf5u8KmNwReyQC/Ci3m+cQhskSeqMj +WNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843952; x=1738448752; 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=GFgZ4QIuflhn/jvNWM6BMtC4DnnhM2UgXT91NawIeEQ=; b=hsWhpWwF/2sN4sADvcDGt2WXu1Go6pshqSZ8b/ICuk3Zj+TxzQxral9NmmTJIqFfyL RcQ86Z+OOVDQZKIrTe98JgFKNO+2FrOytzH+evuv74ROnWp/V4ChihO0pFbuoSKo9tk7 jY54TsHdI7SEnSYgDTsimJ8zASCbz12gEGJzlWfZuOII7qj/uYlfOULtHCeCl2vx05W4 Unots91IxHhON2j22U4A5RrdeZuctVQxouBKKiZfmFlM0R2LCEdW6zTIY0kKdMUNnyPM Ts5Bq0JXdtNycHaPB5TbV5Z9z/NR5xTptpnRbs7qCsA8F1qzKHCHd5E9nt9JMvQmaxK3 xdpQ== X-Forwarded-Encrypted: i=1; AJvYcCV673PvXmBjivu6rrA0ZjARsT+Zvz+uLAKTxU8Baq2JCXASM0e+gT7pHuYmAcz364eBeK3cLjnoY+jg@vger.kernel.org, AJvYcCVJr1ric/yfeH63wdTNanWhb5fFH9uIzSj41Ds46z+xV5/FtuK08hAnXUEAhb+7cJKNdbCmNn1qHrAx+w==@vger.kernel.org X-Gm-Message-State: AOJu0YxlZ+cjrFUTWGEvEZo+RC9hW61iZk7+Rj2wCGP/m9WoglPUzK4y 3IEeRyh/o6nsKGUkGvB+ZrW9VIPXgALvANUQr4KZjbu71lcbusca X-Gm-Gg: ASbGncvQ1CmlzmHrHiPD2uLE2EU01oQKOzVMjZD1C27UJl7hJmlyVSWXuL8SqoJqKRJ Puf3XolHcFJIzobhqBc1wW4SPK9LLSKgsxvhSH9VcBj5NcsOeMsAe0dTs3aguxjOJO8vrCiXBVQ Hm/BqZli7QbIo6ShQ4zatTEwegczKs/IefqATektbWxEmfNLLJc4WknpH3imU1fXjO1eQ2NTP6/ WcW8LT17/97bqxqXcohWoWmDjmkiVa62HC7TabPaznSQKTmofF1IvGYpgbrz5VkwcRdHKNoSnEn Bh75rPmDsTiumJmxv4AftV4bbQT8qexrFpRh5WipHJso+c+49vc= X-Google-Smtp-Source: AGHT+IGPt8ptDf2tFiE8DEJJUSz7emZz4RpNu4Cbl2YSY0eXnGAAuNjm3m8XAjmlfm8xb5KbXDkAZw== X-Received: by 2002:a05:6402:1ec7:b0:5d0:8e70:cf86 with SMTP id 4fb4d7f45d1cf-5db7db19c6amr11982404a12.7.1737843951930; Sat, 25 Jan 2025 14:25:51 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:51 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 16/17] HID: pidff: Rescale period value to match device units Date: Sat, 25 Jan 2025 23:25:29 +0100 Message-ID: <20250125222530.45944-17-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 PID devices can use plethora of units for PERIODIC type effect period while Linux Force Feedback API only supports miliseconds. Read the exponent of the period field and scale period value accordingly. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 37 ++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 575f24610269..c8a60034d477 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -22,6 +22,9 @@ #define PID_EFFECTS_MAX 64 #define PID_INFINITE 0xffff +/* Linux Force Feedback API only supports miliseconds as period unit */ +#define FF_PERIOD_EXPONENT -3 + /* Report usage table used to put reports into an array */ #define PID_SET_EFFECT 0 @@ -231,6 +234,24 @@ static int pidff_rescale_signed(int i, struct hid_field *field) field->logical_minimum / -0x8000; } +/* + * Scale period value to device's units from Linux default (ms) + */ +static s32 pidff_rescale_period(u16 period, struct hid_field *field) +{ + s32 scaled_period = period; + int exponent = field->unit_exponent; + pr_debug("period exponent: %d\n", exponent); + + for (;exponent < FF_PERIOD_EXPONENT; exponent++) + scaled_period *= 10; + for (;exponent > FF_PERIOD_EXPONENT; exponent--) + scaled_period /= 10; + + pr_debug("period calculated from %d to %d\n", period, scaled_period); + return scaled_period; +} + static void pidff_set(struct pidff_usage *usage, u16 value) { usage->value[0] = pidff_rescale(value, 0xffff, usage->field); @@ -252,6 +273,14 @@ static void pidff_set_signed(struct pidff_usage *usage, s16 value) pr_debug("calculated from %d to %d\n", value, usage->value[0]); } +static void pidff_set_period(struct pidff_usage *usage, u16 period) +{ + s32 modified_period; + modified_period = pidff_rescale_period(period, usage->field); + modified_period = pidff_clamp(modified_period, usage->field); + usage->value[0] = modified_period; +} + /* * Send envelope report to the device */ @@ -392,15 +421,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); - - /* 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); + pidff_set_period(&pidff->set_periodic[PID_PERIOD], + effect->u.periodic.period); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], HID_REQ_SET_REPORT); - } /* From patchwork Sat Jan 25 22:25:30 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: 859985 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1094C207A23; Sat, 25 Jan 2025 22:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843956; cv=none; b=HuD/B+iDlYb8wmGgWtMdE0QsjBWtumpJA0cluNvqdmBrUSBrhR3B4LZ2/rqz5EiQUtYVAu6dB6R6eitKK/dQY0WLKWvocuy4Bez0JWYIfFttO2OvtbXY8XqAmwrHbMcweZOucQrS+VJ/F9sxELurzLaGb4/9zDH2yAQA7ZYza8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737843956; c=relaxed/simple; bh=JTNbyozYkpU8RaFUopr3EBgmhUc8+MO5AXGhpGgAFWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GJiBadIP16TCtBT2HKfkk1FGVIY1NbQXwKFMIt5/BxCnQca5lHToSo6jVJNh8GyCT3vcxSwiooL1w9Tx6OFrpv7CiGfLl8b6l3a1kJuLN8dZR/eaPcwBFUaE8bgXEcsIhKuPaUFzbpkWxnyAIzGfOn62aSl6O4IVAK/Wv+XuwCs= 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=jf+3xXTc; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jf+3xXTc" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ab6915fed7bso13028166b.3; Sat, 25 Jan 2025 14:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737843953; x=1738448753; 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=nz4kW3+ysmUKWE68LmWWdv531YWnomtX2sQ2+SoiL0Y=; b=jf+3xXTcA4/GfghBoerUMly4bQdZ6j32VNKPKWDE5j3uJm04Hi+Tr93Ugc3RvSPY2f pOlSyQEfzLjTOYCXHvRd67lsJ67XzogT/N6HiMuKCzgb2l4cigATmUPULkiJXXAPDBV5 EhTXdUs/7Ryfey2rmUdfKTFX4NX3RfbyzNJZvFlxwvSjw3AMKvqa27wyD7y16RI0DXuM bE/qey4krWX6qOl9zbn7NIsxXx4V0Qa8HdidDslf2mGrTV6I9byS3nLhyxiAAtvVBOVO h208oRkowJiy3C2yL3UlqetmsfYP92aBmxRFswlkRZjjv0iqBa2gStGuUFp80AiXhTXv SE5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737843953; x=1738448753; 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=nz4kW3+ysmUKWE68LmWWdv531YWnomtX2sQ2+SoiL0Y=; b=XbbMk240FUUhIFEHeGk+cjhFFoxZLeC7w8+MAokhfLtjWAVhcqgL2FcCqz6/c/2ABd Br5IT0tQhfpHz9q3tVw5wi1y4Kdf7Sdorz44y5L/o8tMzNvDyJohoVv+kWuWXFanNnjq VFkUV5S49W6+ezM3RtaTdRmDMJLXwutDPfhsVPpCZpYfOD7AKdqOZarCKzZpXepTMrsL vzvooVbfOSUJUuoNsLN9EWu0QxNWnpopNwIRk+OU4SUYlj74qP2iFnUpS8jKEp3smtfL Ar4nEQoJMCX6mw36WP5zr7hafaOKI5PP3ZhDPpj0/WkCqveC9pcL1ELycbd/xCgdp8hx URvA== X-Forwarded-Encrypted: i=1; AJvYcCVkEh7KUJZA9TCVPsuENyXAIHcJJDy70urrjztFtVBkFMOWsJWxBlbxQMj3EPlaZeNY9izIZvwbKT6v1Q==@vger.kernel.org, AJvYcCWmURWzeyAiDaML/J6NT2DfY5f2L/wPzEFD3kW4DkKXLofxk/A3wQZcjpOOxrdff1Ou5cCMzLxoHL5S@vger.kernel.org X-Gm-Message-State: AOJu0Yz+MrPB/sZYx72f18W014kVzIFZdyhkTNZbTga1LHc5NTYgPPT+ lqaDCEfrH5Jhn5Wdkx1fc1JjXy40s0Vr9FL63651GdA2HCYK2qy+ X-Gm-Gg: ASbGncsohfy3Z6h6QiELHvBnWK5ZPqST3tZa8XF9LGvWs8xUdZnWGFzijfItQ9eiAhg cHRL0/pow5IrBQIbNs0oSCc8LkSGy7KnTE7SmXh0RUEuyjXF2nulPP4xuwJ3ztkzj8xn7m/1/Rl EeZPOD8bJrhD6MuzecrK+jKLdftLGknSFpeV+RIDW12qVjkVv3wdLbM6WcueJPdnWN3PEhMAlhS KiJJOKb72opEC8l3icvqN/rSaieT2L4PFSfSm9sNPNuAT8eVAAb6L9R3YSdhYfvPz29JaLUm8tv 8SRn+bhozhEK/J+xVqpsx9CEXwPC+yaFn8LKp2fQ+faM8eqDJ2U= X-Google-Smtp-Source: AGHT+IHRLykiGTDbib10tG2EJCzaSkx30k9VH7+qqxp1YzvqWRd30yvUc7C3/BfPKK6wRjARcjInVw== X-Received: by 2002:a17:906:3454:b0:ab3:17d:bbd5 with SMTP id a640c23a62f3a-ab38b4c6b25mr990660166b.11.1737843953224; Sat, 25 Jan 2025 14:25:53 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab68f1ef7besm136540166b.62.2025.01.25.14.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 14:25:52 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v7 17/17] HID: pidff: Improve ff gain handling Date: Sat, 25 Jan 2025 23:25:30 +0100 Message-ID: <20250125222530.45944-18-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125222530.45944-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Makes it easier to set gain from inside hid-pidff.c Changes in v7: - Check if device gain field exists before setting device gain Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index c8a60034d477..436b8e9b37af 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -525,6 +525,19 @@ static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old) effect->u.ramp.end_level != old->u.ramp.end_level; } +/* + * Set device gain + */ +static void pidff_set_gain_report(struct pidff_device *pidff, u16 gain) +{ + if (!pidff->device_gain[PID_DEVICE_GAIN_FIELD].field) + return; + + pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain); + hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN], + HID_REQ_SET_REPORT); +} + /* * Clear device control report */ @@ -852,11 +865,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, */ static void pidff_set_gain(struct input_dev *dev, u16 gain) { - struct pidff_device *pidff = dev->ff->private; - - pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain); - hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN], - HID_REQ_SET_REPORT); + pidff_set_gain_report(dev->ff->private, gain); } static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) @@ -1391,12 +1400,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) if (error) goto fail; - if (test_bit(FF_GAIN, dev->ffbit)) { - pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff); - hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN], - HID_REQ_SET_REPORT); - } - + pidff_set_gain_report(pidff, 0xffff); error = pidff_check_autocenter(pidff, dev); if (error) goto fail;