From patchwork Wed Jan 29 21:29: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: 13954147 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5EDA1E3793; Wed, 29 Jan 2025 21:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186186; cv=none; b=T5D69Q5TovCtZO/Loye0hlpT3T3vwo/YRx3j9QMGLQ9neX3jM+Z6AJhSNId86kp1AxF3KdK9PRQmD6rV2+sS35d5szZmX84jmvdW2KCYwNdJDi1hdxF3oOqgHSz7Ynqaxh3D4HIP31vRuLg0R4NyvejX2R2amZsPMn5x48y7PhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186186; c=relaxed/simple; bh=PBSW4fuTwFIRCoXWqVpX+8v2HMvFjX6w5ecsvytNEnM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ixivqHWBuCOs+RkGK/DpUB82x6IoCb9ET0aEkHZlS9fkzBnfn47saIEdG8rmSmmL8M6Zv9wUXaCJdLZ/1JJPQQeK5TS7SVG5fwtzoprGCk1Y/x64jH3vlGw11RrVjFgZBCVw8FU4CXB04hF/jU/5mOwzCFCob08sjlNhZx03lwE= 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=KTiIsdCr; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KTiIsdCr" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-543e070cdd2so14980e87.0; Wed, 29 Jan 2025 13:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186182; x=1738790982; 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=pHWpDui6ndTWaDwIggrwI88oJ0Z65ncmkdvxeGqa1dA=; b=KTiIsdCrlQytbJgeduLuYnd8TFL7nVeU3CaB3i53YeSqNXkW27r3YIwaYv2u8pRnc/ 4tQBBFPJtKdYR0mzxxtz0fwnrPoq+L+oB+EZJVks1Z+7jXTOd/1PW2bxv/jnlZWhJssn Giy0IZsxRUU6QAStvR+OjtMuImKWiF9G2UuKU+gBoZl30a9g0G1Yu7Mj8/29C1FFxNEQ 70/FQ2oASC2/upBokHuJMJe7wb4LnF4HjhqTZ8fCm0dbbFJTyuX/WtUiGwSosVjF91U9 OLCz/4ZJlg5LKW+cFaovJ9p6rVv8oyuS5tDHkBr3AJIuqfZTQz35JmffUkB59JaNQzzC YwPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186182; x=1738790982; 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=pHWpDui6ndTWaDwIggrwI88oJ0Z65ncmkdvxeGqa1dA=; b=UurYvSS4MOqVn+jfY2g9pgYYoKlQRJy7dvg/YBC8syrrIz6D+EkkF/WGz/XTH5OO7F 3Lbvhq5D6KCuOEwiJ7jbKc6UvdHZr8W108gbrY9B9EVl6KmK4KuBn+jZuCBGHPNqkPTD vsiV2vCTaNpPOy8FFzVAZtNviOINraZqwQRA/uU7EsTS78zVZMualyAWV7xb2gaGcZ6/ zm0lGu6vHi6kUMT5TIRjc/NAPfqSiFfU4nrWdUEnFGeYNqVCv6DO2UaSRkIpGdF/1JYe FBICiFR7fDVwlXWLFA3Zb2nP3bcL+a9q08zhrp/oQyGoJy5kwu2CjAIXe+THqGsr1nUK CzGQ== X-Forwarded-Encrypted: i=1; AJvYcCWHAXFkIV9oHDMZkT1CduLNaU4+uo6RxJKXXJNDphxi+F0iiu+RmD6Jys30/4ICNBSHE5SIzatH1CyE@vger.kernel.org, AJvYcCXy0VFhECdAv/wF9mbXAxoYOXvbGhQAZXWmayoU1EQq5whNs5Y2Pb1Ylc548u05stIMATOrI6dqpjXNrQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxgjSW7iG/91gIh23SIyDBST3cNxTtsSLfhNiJK0A9HXeaAHClD oWlkXyVTR5qKd+8tKQsELWjxrTf/x1nZAd9tE+NJdpJgQz5GRQkm X-Gm-Gg: ASbGncvkf8Ldf1AfUQ+pPL8tT83fv/dZgtgfTBFg34Esx7L9G8amdNOlrgMqK/j3gq7 CRFrR2a/qoLEbMMTNjePXtLHByuww/JVNKWVedYGEIT+bnDC4eSafb8Rov4aGZ6hByIqK1N7HMn wXGvc/+SHgPYWTNmobg9/gjyJ+62RTfZHr9P0WMGfTM/zgDCgNoMox2YaLQYHgo/PXkRtV4qwNf SxFw8MbzV4m/prAbvbZ6/dETmvaTlkX4lcDaQNkjPrKXwhzeHFBlriurKM/H+myoh8WAGEmDTpH iMV8gz9BWXSwqmsgeH71oZbZjtGaexuFTy8ZB0GcrbLr0pEQp85D/Ah3z5nX0g== X-Google-Smtp-Source: AGHT+IES9brpqM+XCzSVy7WyDC9AOjiHcXNPqxTs84JzPGrmUMZyY3JBWKva5sKxvozRlBJ2BsAkhg== X-Received: by 2002:ac2:4e0e:0:b0:540:75d3:95ad with SMTP id 2adb3069b0e04-543e4be96f7mr595552e87.5.1738186181536; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 01/21] HID: pidff: Convert infinite length from Linux API to PID standard Date: Wed, 29 Jan 2025 22:29:15 +0100 Message-ID: <20250129212935.780998-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Software uses 0 as de-facto infinite lenght on Linux FF apis (SDL), Linux doesn't actually define anythi as of now, 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954148 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.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 3AF541E379B; Wed, 29 Jan 2025 21:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186187; cv=none; b=FcBGwbbTSM0o0QQs8R8lYXQepCYd/kKph08C0kevKbsAlxFBHvJmulyVrftsHakRZiB3aEb/1hNkBSatSEdXya+cScqhMdd+Gwa908vhgafxvW78MtulUKmS4hh5Mi4pFxr+O/fKvg6VchLslQVmH1t3rm1SpziJCa/ilNVU7OE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186187; c=relaxed/simple; bh=PvtOoVWhOvVoB7EdYAAxlUuxG61semvfPr/QFothM/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Xka7joZUbHRsRZ/xT1R/dvHHJmqCzQph8NZP49l6kNtqJOVi/F+D5C5TxhNko/v3NNwKGeU71ZAUk0nxeSQOAP7ojQv5cvyd8+vbw1QgknmkojZWX/GdiZvqVkjDE2VIKoCFGWhhal/skdet4CBi9w71L2P0Kq+d2YRYb85heuQ= 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=nmLGrngS; arc=none smtp.client-ip=209.85.167.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="nmLGrngS" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5426f48e501so18024e87.2; Wed, 29 Jan 2025 13:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186183; x=1738790983; 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=tQfJ49zNeFmYfkDuLKuSoElLRAh+aRQWxnmxtES8afw=; b=nmLGrngSPvaagENvVwcfKg8HZeIdeQ0RS6+HcQwqhDAK9q6HbfoIqcHAdZDLYts7u3 Q5+U8KQqWzxBqQjE0Potr/88k9RIPCTFxt8SvQUgcwzRYmIvUC0se4nm2pG8z7oq9OV0 LRg3Atl7IIv6RL2S/vIsvdxwxHdQwecreAV8JGatRN/U9S6mo03KoL61GpP/ApLy2zuL MkimsDd2wC+VmD6gwE6ZkMHXVC2tpQAMFNLuYZjzbU/iyWW9sgJxv78SPf76c4qDyj0L 1LVx6XNTf6hsL9Bs+C0SHUkaajWpG/Jl7tjhaZw+tPlx1UmxARmOy9YKhCM7ghOqNafu bYqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186183; x=1738790983; 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=tQfJ49zNeFmYfkDuLKuSoElLRAh+aRQWxnmxtES8afw=; b=rQqJevxayAnt51iDUV54Tp1iqfOVBSd4SxfO/QCskjLlNrA2z12lu6RiRzHN4mnxVD yCqJyyRdkfFyTUZ5T7YF+D6+cBWCjbcSBYKEiNLgxrhbdm+XvSDoeY4uTFuMAFutIx8d liE6US4GGhw7jatm8uEF/Se6CdYBVofmhlUChpyMRCuNIHyX5hXOiu1wNP3C4+Gc6Dcj W0gKMqLsfPLzh+2dN3MFuXwOuLdPXJYWTrwkg/D9fnJ3gSzY3rWR9CNpWox1+7LXHtDX Kbn2wSn7W0Hp/rpsyJbKGFHblKuA1mmkdqHQXO6R09Tm7xCFbggkw+wFmQY/g5w2CQfj 3AKg== X-Forwarded-Encrypted: i=1; AJvYcCU+tMAmZf0oKLZW7pBnRceP7Z+po7s1tgYahuB+XKtmU+/oGUppGvUYrKJtpsixhPIQW56gVucl+k28dQ==@vger.kernel.org, AJvYcCWZ/E0T1MHA/DV72ceBmQB/+bsOxxL8oyVEksbGCH19fWvIbggUeXqzXDiRB+aLNiiey0pHDHBUw0c1@vger.kernel.org X-Gm-Message-State: AOJu0YyH3WwQemNkeC1XNMlzgZ4suBIhIDDJ4PCgR3AwqgfPx1XBieMN 9VjHg5DQi9W4szU/gVFHlOXMH52GMu4lCeazsbHVC4pzoqs2kB9L X-Gm-Gg: ASbGncteU3D7sO65TSGhvqI6uMsSYgo0rP/AhXhhPVys3g0PO/RAi4d+rD7kWBeAmYS 1/Xm0rigvtRDLRqu9jvYXa2XUVaTdkSYWvJiulDmakt+8E8cWQIDZdLLlOGuUCyfAFVSAITbixk l9Vr/OK5zcti3hNr/QRoH74ErL6xXa5UT+h9nFe0OrKwsTxQ6anFmh97g3YV9dfMpN0R0rQMFdI jL3o7SzzzcmOA1MR0JaErM7FjgxHWFEHeHZMQuX+cSVjOaKtcBA3ZdK4cUzvsiW+cqCg3G4qNUY OJMKiJYyM6whot3ZEvLRdVXmS8f0CGB7faUDzptmZGOfTq9MABUZkj+qH5PtvQ== X-Google-Smtp-Source: AGHT+IFvhUAJPtVG2qCsgN1VXNVgDoHezEBC0yZk4KNUuz3PNlzeo71rAvnGXTYASa5SlzI8x4njMQ== X-Received: by 2002:a05:6512:4023:b0:542:297e:94e with SMTP id 2adb3069b0e04-543e4ba63b1mr622089e87.0.1738186183049; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 02/21] HID: pidff: Do not send effect envelope if it's empty Date: Wed, 29 Jan 2025 22:29:16 +0100 Message-ID: <20250129212935.780998-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Envelope struct is always initialized, but the envelope itself is optional as described in USB PID Device class definition 1.0. 5.1.1.1 Type Specific Block Offsets ... 4) Effects that do not use Condition Blocks use 1 Parameter Block and an *optional* Envelope Block. Sending out "empty" envelope breaks force feedback on some devices with games that use SINE effect + offset to emulate constant force effect, as well as generally breaking Constant/Periodic effects. One of the affected brands is Moza Racing. This change prevents the envelope from being sent if it contains all 0 values while keeping the old behavior of only sending it, if it differs from the old one. 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954149 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82D671E2843; Wed, 29 Jan 2025 21:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186188; cv=none; b=Pamk8XiRarp4ZXqRSTaiz8jBFxz8hqYl/IUYq1Kdcfz4Jy0+OXQONrD9HbuwwMHZ/vjbWxb6q6ezLlDZPQsTRXVpk2KQ31aMYfHwUURZSs0rQFmW3S3MCsevLZfdXyWM49Uwmr2elo3iXpJCcYtNwG5l8iCEI98VtAv7UFNxbKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186188; c=relaxed/simple; bh=qRDqb8/k5nq6eMle1qPeQQV3EN65UDGm60oGvk3aKmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jGrokdR9rLrCzCGQyC6CrHWeiwkeHvxzPa9HeAvd+DunkY/9x1abSvw/xzbMBF59uMGhm3ATuDIUss53gsW6DgbUgH+QLxZMWaMlOopz42tBfi6oxsq60SlmZzJg1qIWAOFmHjTL/Bnj/A7Kl+MVSskxQZzjTNo1+VS1RjYNFro= 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=gmPsYclV; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gmPsYclV" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-543e070cda6so14278e87.0; Wed, 29 Jan 2025 13:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186184; x=1738790984; 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=csgRzIKAQPXaTI2487b6us+Fd8yxvsmEH25L9GNEzxE=; b=gmPsYclVlfZoeNYWOrQIwXN6tIR3f6/6YiQxxBS5XVuKU9ihPQQjoHd2PQmr9X4RDJ OPGJDIHDDCnHmvGprtpM8dOvuTuJUSoF9Y0z5qZqgtfYFPmYUNmyCNWfFnDbuTEXsHvq aDOBA713lRj3fAK+BJgR6xSeZucFZ6ZuGdozCXeyqVnYc9bfyWarHFMuVNt4PpAmbLiU KqS7ckq85mGwVSkhKK3g7Q3/Kk2/U88ga3qzAweo+aTUuxa3dQM/WQ1BPN9j87u6FnC8 k5bTp025e5XzXuHxcpzHMKXr9XP4WgNR2Nd1RLI1zUgdVSiWV1ziYJDFcfxJlwCwCDxQ mSYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186184; x=1738790984; 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=csgRzIKAQPXaTI2487b6us+Fd8yxvsmEH25L9GNEzxE=; b=EoyYbf52TLmclfPIV7ebl8nli8t8m4VU+gFuRwBFfViw/5SWymVlMi4h6NQEZm1DxA utN+FIdnKI9DamJZVObZzaqilgn+LhHVlETx9TXfjk4HNgduskfIHommi50eHo+FE5ux SD7A3irhMBEC9i6DBvTnQ6kRjhWqOqtWqEDtrAc6OfGRQQSTsR64gJHeXw8E94HLzine JzzI65X+5v8gcgRUtjHUzuaslAlY3GUNW+JJXZEsECYB1XcU1I+ak+FwCJMMpIk4VE6S T3V5OSWzyMi87wOh6Vg/mgt8oIqxU75LKTYmGOXB0EinhBQnLg0NbznW+8PI7AX1xKuf ZAAA== X-Forwarded-Encrypted: i=1; AJvYcCUsNwB+sbhV7VtI5nOsEFzYoNqzeYfrOJcpT1GCBbjMaPj8zBjn8xKvlr42L3SG7NgwFQVfr9SRQlTdZA==@vger.kernel.org, AJvYcCXLHmE+l1n03O1nLm12Wt2AMO81oIPUA65cQlKZqx2tULDJT1PEkgKbpVnxb9QY+87IBntNIuYvOidD@vger.kernel.org X-Gm-Message-State: AOJu0YwzYHa+9lUc4Y5St8is1H68hac/Qysu8PdJ3L6X4nad2LrDs8V7 QhzQYA6NA87YGm0xGHnqhi2E29qbx1xo5EcWC55cNjbji6/U0pH/ X-Gm-Gg: ASbGncsxbZKP0R15yPSkTzUS4OzTFLqOF17CI+k7/rm91ri0Cf8J+5TqT7fKfh2L47P kUfn5C7vfDY/U1Rr9e08bSnXT9ST2tipqYHDkwaJLlbGpWIniLWUVkqZV0eI4sjmJMjrzpKqfrG nbPdB8DV2IzWaNrfuQ754uW4q7klgY1EW6yjhfxq6gDOGiRfJauEd39u5Rtxiu+g7L8N4XrRtbl xHoGLXjAbOA2b3X34sM9Rmy5Yyl8mm/MEv7JDo1Ss5GIU4+bX3tbEJtXxfjSJCz9DJZzMr9tC2S 45oJ2iuKG4TA2j0+7sIKaXycssBCfQJiYVWmTKkSy/1KXB7I3ocnRnE/DrpAGQ== X-Google-Smtp-Source: AGHT+IG4hNaIgmxt5zGs1ZyQwE7y1R25gWQMpnhq+wO5JHdOJ3W2LLdKPTF13Le3lhAu0JsuvDeEsA== X-Received: by 2002:a05:651c:54e:b0:302:1b18:2bff with SMTP id 38308e7fff4ca-307a120eccdmr917061fa.11.1738186184405; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 03/21] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Wed, 29 Jan 2025 22:29:17 +0100 Message-ID: <20250129212935.780998-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This ensures the effect can actually be played on the connected force feedback device. Adds clamping functions used instead of rescaling, as we don't want to change the characteristics of the periodic effects. Fixes edge cases found on Moza Racing and some other hardware where the effects would not play if the period is outside the defined logical range. Changes in v6: - Use in-kernel clamp macro instead of a custom solution Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954150 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.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 48C8D1E379B; Wed, 29 Jan 2025 21:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186190; cv=none; b=VDm5BNeCp0NqT6U+5mLjyTtrGl0YN+3ejCwMH4AItQiFLftrLT0VKbzaKGQajjL+E9rPM5HKmHarA2q4ELAA/DIOJQjIBWP4WkUs2ewSG6kNRM3XLVrbMx9gJN8Wak81T2Es6qyN+GgwWBDWjDfHFqicUQmnDQprrlBe7SMtRNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186190; c=relaxed/simple; bh=TBPKbPylZYsYYumVpVwp03Rwoyh/GKQoQdEU8jDnJ+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MVbuqvjaF+xpzikiLrko1L6ISsT5iQG1/urYhpFOhCbLtp6sJEJTTDBrxsVBCqL1bncSAuESrDYl84YqZHeyNdgbH/aDr98Y1Yq3+A6OLESfY1mMIA3IACte1FEzRjYqo032OpMDCRlZoaC9oCBVAFoFo4Rica3r3X6aO0N4RmQ= 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=cwOS+/x+; arc=none smtp.client-ip=209.85.167.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="cwOS+/x+" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5426a29c81dso16266e87.2; Wed, 29 Jan 2025 13:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186186; x=1738790986; 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=duHwhIto8jRwjl8oTveORRgHP/ZO7W7YuX3JE7ysk5g=; b=cwOS+/x+iWdxBKHeskEdxWSWV81LnZyxPfjFGxfxUA16vFMGd7ADDVbi9oPhJXX1ze f5QD1I9yPeNweqa1TerzImx7ErRA0/6UXb+LIRUvNOq0pkNYUDRRyqawqnkOM+z0H4UD F8Vn/NsGHkF8BZv5AnvAHeWwxpmzCRGA/Z6pAMxoGrBoABfgbWRiZc+lO2HYC1F7B3jP C22vpkZlburoL0N9YXlPInXh/t+aITLq8KaqdzxnOGQRoo9tqHu4SqGpGbrvwu8DuhIW 7EF+G03EG4uHeE6mtV4Bqco/dU6xgDiW+JkEGEnlXyNZSEiW17ImGxuOFlxocvwBRqGK hRjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186186; x=1738790986; 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=duHwhIto8jRwjl8oTveORRgHP/ZO7W7YuX3JE7ysk5g=; b=GCWzUiNc2LugJsneHo6ZJ6R69A2DpgxgR+qk4MVk/Htwu4JrGx90zVvYw+rDdTJ/zs hdukLjNMRsrxb9qsrf1Y8sFCm4LInwDrIedlWfoiheQeXJJu/0UOpjL4LeTsnrr7BPZg DVQv6/DuH6UwL56a+RDbI9grOSKfaOHzessyZpreaGyCRmknHzCxW3+yhCzqfR+tpvWy S/x+zpWHty8xGA+gF5UU/KcbHKeoEH0VE0fkZegeKKnTJDWxmbvRQQ579gDlNCe8qOvN WS9baBoZ1tXc//V9hnrfGoSUPYfXH5PU55vVznP1fdA4crT2BZdeaowfkhJGaIDJp6Rb 7ACw== X-Forwarded-Encrypted: i=1; AJvYcCWtmC/iHvV8ijY7Xt5LsX6tjv5CpbGgICoTDujakAri9voA5sfYBSR6P4uzadvSlE67PxKX8CviP5R+@vger.kernel.org, AJvYcCXB9dpEjrL0Pdzyewf0sKk8Q535YAFca1yhXVD24oJSNy/SKXJQryvUnWcif833ocxDT9Cc4ZEBHRLmnQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzR4P0sYLyRQDgzUPhzMor7rO/rrHJEVbUjQe17+FM2Ct5qR822 /X7Je8bRsXowGZYfv4GhcGA6Zk3DZiLE0+1A7qO4BaR3EJuStroVWmMD2MyD X-Gm-Gg: ASbGncuHNcbfbd8fGz7m8CaBy3usLgCLn9kbTdNuQR/ApxH0iDwTwKL1KYB9nlrsbMU M+H7VxDlZq0J7W7NKIhtUGctRbqASQkBOcEIeHOh3C1b1GLaolVGlhw3/x4UnKkwPkakrF/vXNe L3xkGxyATnf+SW9tqgCv67uiUfXXVrj+qGEtAU1e28zop5+B1yH5O5jdYnVTuzq7O75Ce0GMzsw p8kLYZSiLV5p3QRu+5UfJ12nETF6JSeqmphHdd/Qp3inemX7iGWb4ftAu+4mRjNPzDMwgh67NaH HzSuq62guZJIFtdAtKryPi3SZ9jgeTT3Z03LnkJMUsRDh0xuP+CNkY4RS0EqlSRUrd9kZziC X-Google-Smtp-Source: AGHT+IHWyzW+LitplVnXgeIIWVQtwyPcPmEUY4nEdYl6FjiSdqtUt21tTL850GPlX0mKToT5KM6dAg== X-Received: by 2002:a05:6512:1084:b0:540:3579:e4ed with SMTP id 2adb3069b0e04-543e4c3c099mr599319e87.11.1738186186009; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 04/21] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Wed, 29 Jan 2025 22:29:18 +0100 Message-ID: <20250129212935.780998-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954151 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A09B81E2843; Wed, 29 Jan 2025 21:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186191; cv=none; b=Xm8LbtV48WbLVWJ6vs2eD10SuRrihTJqTFjK4xa/t+3rwS12Zry8V3FdJ4hC5EeAJPBT36WeJctcJ0PghrtUoAmTJ2OTJGbpBsFfSpUh2ec3U1i4Vn8EW3qg3OAQ6rjTSJay1RhScc/31mc6c3IXzCAc3npz1sMIGvTUv0J/YtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186191; c=relaxed/simple; bh=DoUO+7K/jRRnR59LL7WsIieZR84dJSGaQNmf2dLlAl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZemTtj6T+pNthT8eastqsLbF/qTVAr92IR77GSqJPWmVdXKSrt1CYMt+jUKBkjSKoSj4KeNUoyI7PaEjeoSyP9VAkrBtQUzim6MhHzGs5OfSWqE2/hdCukD9ZudVlHos2J2dc5t8fmf1eJOf6HlTkSCO3mA44eYQG1+r2WYd6d0= 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=PIF+aFrF; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PIF+aFrF" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5401c2bb7ccso16567e87.0; Wed, 29 Jan 2025 13:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186188; x=1738790988; 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=KfnhpAmMLmN3ff0F4IaY7GBjLHMJ6om/M0H6/2z9b9A=; b=PIF+aFrFrtnD51bZ5ORCxOerhH+Cty/zUfrFy2ATvsYJk+E4QDi7FL885MTqylRnYN 4vxgkT7/2pDP4Qr0PdcCQDDDN2bV3l7JUrelt9Aw9hjgDU3Ic7YjuGS4lrPHjhjleARt oyyeAQSrfYs0fZU4wEoMLR+iMgbDyfX4ARFTUThM+tGmafiUohhhXqe4xr4ilt+83C40 x3HBIiP4c74426vLd3Ccq4KOuqTs1ZQptRAGoNJCw6PIHOLcy3JywF8/BE9JkzwD4Kwb nbngB1nZxvNgeY6KEYdc+VWn4/U7qdu0rLyNRLXVSMoGKlHjvmv+LuuaJ74IPWtTJqq5 EI1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186188; x=1738790988; 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=KfnhpAmMLmN3ff0F4IaY7GBjLHMJ6om/M0H6/2z9b9A=; b=YchJb90SYfUShVBq0sC6HDvsPlKErC3Qox78ioDK/dFpqNRCQcPDlE+TtV8BqKDY5B PNVPSSVaZFWrCGDMnyb4gS4npPka9lNZVb77NyvK0TDBwC6e8m3yHRK5d4nlv0TaEekT tkAv+8TfRFX7An/IMVx9MW2gzfbZSRA3XorndQY63wm34E+k3+eRBkHlbknZ2VBD4h4t bnn5E6DaExHhfHg3rdBQ/6av7e+Oq+6dPG5p6vJfKNb4FNvCxu3uLxeWMtt3zL8pyreE vTpidbhlFViLH4Pk7md4EPNIf+B8CTRre8MoVkIGPSYDBRKqwZw5IqsNo/ONdrM+YrJx R/FA== X-Forwarded-Encrypted: i=1; AJvYcCUK9JG+roo8sBDslta1beNJ452R3zoQ+pwWiiK6QcczqI7E1w4g0ql6TB2bQ4Fhug4yA4O/LspXMtCAqw==@vger.kernel.org, AJvYcCXuJnS74JuRIKbFFI/tnYPBo6cmTT95O+ddo4cAp1lhlGKRqPQxZ0PFsolj/xqPrKB0qrFE2BEZh7Ck@vger.kernel.org X-Gm-Message-State: AOJu0Yz4/ERBI4INFvvz8kFfZCdK1R/TNogQg6KLKVAIkQ9Hdl9zNHHB ApoO7O8oAxLOG4YmEa8LDpwJG1OGc9bhhb3b8cJkL4BfAhNLRjnT X-Gm-Gg: ASbGnctjvB/SlawCqr6Yug5YMt//keX00xRuqKiZ7St8MiOWn6ns6KcZy7m1Wtt57vw pKZ9qdLLnhC1FMBQTyHlU09AO8nPpydv31eHWJWb0XqX/SYtHXNHpSnXFfM6/uk20AAK5EMbGix udUv7kUjZPc5Um+Jr4Ge7D0FzRjNnkwUaTiZfWwPahZWvfr6hF5v1SA5OiCvCiZr273XfHT0M2r g/sN3S16ZEeVEWFiprRiifiT+gQtKWOpRW+7BDqfnlabbwqywAoTchh57qeKxcOiRQfTHLElW4n fDuZWtl61AslMeusBHr3f9XaxIwkrPZLAmGVZbBvnVyH+HBXXMdi3d9SCYeT5w== X-Google-Smtp-Source: AGHT+IFzs2lawNXCrxjb7H0cv08bZhZl4wFeZmyohRDy02BIvvCU0hma7etvVRkBlHpVRmx1Bxl2ZA== X-Received: by 2002:a05:6512:2389:b0:53e:398c:bf97 with SMTP id 2adb3069b0e04-543e4be9c11mr539043e87.6.1738186187445; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29:46 -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 v8 05/21] HID: pidff: Add MISSING_PBO quirk and its detection Date: Wed, 29 Jan 2025 22:29:19 +0100 Message-ID: <20250129212935.780998-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices with only one axis are missing PARAMETER_BLOCK_OFFSET field for conditional effects. They can only have one axis, so we're limiting the max_axis when setting the report for those effects. Automatic detection ensures compatibility even if such device won't be explicitly defined in the kernel. Fixes initialization of VRS DirectForce PRO and possibly other devices. 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954152 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ED4C1E376E; Wed, 29 Jan 2025 21:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186192; cv=none; b=QsBBeFPOv+N011wZozsIjWZC8t/awFeKqhqAQXE0pJVsT3d1OVUJoKMHidtUqWOWeObKVoWO+CyVRsp4+VqQ9ludg6AiZLdYHaPX8TtKmDIiaqSD3bVVFpXEjulYCx06+4+5lDWXsNVh+lSThHt5tm+jGcMHYsl++Y2aFMkMNUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186192; c=relaxed/simple; bh=7OK3kSXT8WXbIC+h689s0p7Orl1J24mMYIxRhrQmLSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZX09s45WqatPSOZhhBDmcjzOqu7Kii98nftT7HFc1dI6IDfVFmBYD68X+3/Ng1APPzs6RzXMdv4iVcesa/XvwHK3HXQcSfbM+65TyZKJ3tWMPpdGghYIe6B09x+xX1ecE0YSz+48xGMyASkQBNYNZcYATCI01xys+/vy/tKRon0= 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=dylGTqNs; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dylGTqNs" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-543e070cda6so14307e87.0; Wed, 29 Jan 2025 13:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186189; x=1738790989; 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=oAox7vgqHfqQyvbiR5yl/AP6DguG21dSsc6sjrWJibM=; b=dylGTqNsGk7yT+o0vqqU0TT/4YR4rXfXRYywyJDFGmidM2sIJ3SIhGQFQuo9Y+p37d TDfC7tW1qwV4sbW1a8TEju0DOkCIRrAH5R9LCQt6fBd52Ya0Hg5DDdfdOQji19Sop9Wd 0VXUXb+1I7JkAqeSSQpGDL0uYod0/yvx56xK7C2Y2xnCpk7PN99Ta+Q2OVq/dJWbg1Y1 TF1KTDozhFlg1gxERNbPZG0kyjllfVDAhYIzKIgq2Pvsmpkm7F16HGRko87X0yVZeAa/ 3kO5/L2hv3BWb1Xp7gywAKUwnejkJ3ILWwapBIfXaDdvehsk2SMHaCEIqVeVtMyNyuyk 95sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186189; x=1738790989; 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=oAox7vgqHfqQyvbiR5yl/AP6DguG21dSsc6sjrWJibM=; b=LbMaay9UZh2WG57VxBJLijdoi3ZpE+oVq4mz03C2qmVukf3Xg5K1iXeFCYckqtccQa CkPqdQZVLNu0NhX7dW/9pQHNxayxcS7TyhusSt++IYjeS0zOsbLh9HBC1+bnynsXGo04 PvNVa+9boOU+pm/SrfaRDiBVFC8wb0FF6zFhQVoevHb6DAnLuUjxdwyd5m7v/3AEEgqi P2Cvkk6P3gJufjDPbqqxZ/qLhM1hYJG05c7zr3tqn/fSNnGSCkPkj0iMzmBLy7yqBzRS dYPx5a1en8/l2PwEPf8hvdwSDhRNBjIytOyWnIWXc69m/2novovbwZgkrn2TPh3OhOI+ kLvw== X-Forwarded-Encrypted: i=1; AJvYcCUZf9XGPk/q7Wy/L718TNAILG69iR1j6O2fRm2Jz6DwQI6dLE+vNGZI+G4Hwe30xK3vhjLHcQVv4xX2hw==@vger.kernel.org, AJvYcCWgjLLam8e3lfQQstSsdXMvHHOS010eT7NdkVN+mPIRKs1suLtYKBFH6skD/Q6Wt/H8X76m/5vc6N0P@vger.kernel.org X-Gm-Message-State: AOJu0YyK/dV9eLgiYenjW4uIVLS8RwkNYWKlv0tiux4DvnDkgRx3apFD LWqfBLpzqFwUE8VBxGRqq/tufOAjNjpHxjwQaERwPLoPyx5IOaUbJdk3y6WE X-Gm-Gg: ASbGncuvo+fHPTU6qIKLSND+K+1ob5Hag0SXiwNuRAgkKU0mrzeN/D5S7AF8T/4tVof Bz7VV6OBqqArHA3Gl+dZA1pxY2b36efcg0ucv1BbtsWcUAPUvGgc2Y7kRJqxOhTw8Oi0iApGiYu qAAJKkdj4cq/XAQjW2JVOgTdy9bGIwIFTr2lxx01W49188dokthpet9XAjYPRFIiCc+vHlOuOZv PmLxaLBldprp6CgXHaWRyUqPDLIMHcQPjjAm5y7NAZisGPOKJkXcT6IeZ7eaSv4K/sSF5DAsEyW bcTalRnrNbgWP6xuhwb3d3Z63tAqZMJO4ESfCBJNeZcBK8HHpGBUXDLkBCWTXA== X-Google-Smtp-Source: AGHT+IGc12f9Zx1YQczPYLPJCN29rZm47XftBVaGtqotFS2QFk7/6bb8Jmun/0azbZtyW4QV+LuQ4g== X-Received: by 2002:a05:6512:15a5:b0:540:353a:a87b with SMTP id 2adb3069b0e04-543ea404074mr73968e87.7.1738186189015; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 06/21] HID: pidff: Add PERMISSIVE_CONTROL quirk Date: Wed, 29 Jan 2025 22:29:20 +0100 Message-ID: <20250129212935.780998-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With this quirk, a PID device isn't required to have 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954153 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.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 419171E47DD; Wed, 29 Jan 2025 21:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186194; cv=none; b=rm05/wqTW8k9gJYvQ5CbtWSchH3ucTTzmo3Kul5aR72Mp0q9c2+wC/Y7i3qNpBuMgC5NzQdZoR7JsJxZWw/QDfQzryEmNMcR7dzK+ApXyXKn+CeTUKcoGrdRcffCo2f34BA/AmZcoDGL+sSjUZ8yg9YtBzmtNGhhMQ+T7YJg4qY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186194; c=relaxed/simple; bh=XLm4V3Ze9t17wM+VoNs4tDLsZs8WPJADkXyUV7Nn4w8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZVaAD0fJ5OUI+16i1EpIT1nBGtq6sUZHPEwYIbIw0fVCLqWiPutzSrK0s0O1d9pkuA55Lxtr6fy6aCAssYZGaWEtxVelLp+xVyWZGrbKh8ip29zlySuw6xKFGXNRTYnmpRBZWUC+GYyCH18oiJ9D1o00wKFs0sCZR44wt0GoyAQ= 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=As/7MvSP; arc=none smtp.client-ip=209.85.167.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="As/7MvSP" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5426f48e501so18036e87.2; Wed, 29 Jan 2025 13:29:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186190; x=1738790990; 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=ktHgFkTVslflOhEjLg50+3HiEgbMXCVE0QKnjgwZ1VI=; b=As/7MvSP1Zug61GghUE5ozhmPYLQT6mtrrAOHAJ7p5X4qzYtOZbM6KA4rDXCgY+bz2 zMFGuQwE6AlV6T7tOgtwdoi0qKtXILVg5+X/98o2u63Hed1zexwWvNDzBP65F5R7zJRg rTIDXbbeemQmVwfdILSZ8deYl5dBqRLp16ezzZd0vj6A5tjLZjcmEDvLdVRfX4vgAl6N udNM3qq7t8rh1V4+uSSioV4PvlMYZHAIen8aOe765RxV22hyiUo6Zb0CEKfB7frZzvI6 LoON6w8QoFWZ0N27C5d9e5kLF3zaL9rUau0SnMhAg50n/xENTh0x6LMdtVNljdIkROot CEfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186190; x=1738790990; 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=ktHgFkTVslflOhEjLg50+3HiEgbMXCVE0QKnjgwZ1VI=; b=Y2XgGbcXjBgMsKviBcoeZWoXP0sGCkikQa6HA4ZCEyuhfvLFaiv6b24S3uN99mUvOV e4ss719LYFz/xRYWR0ouG9vTnmaFiMMUyadauFc/4ANp5HfmDXFtka+HnplMzrIvhHJW iWfyZfvrM6RA3tkaDvuxZviF3DEsLHvmPzE3z/aYuaCsDitlP+8FJwM/Hja/YEg2m7v6 Apf9IgckC4MhcMGYQphlTnE38zuhSg3GPyoYLub6sxDcQ9+2QxYIvfSmKrhXvY/2QDdY 4kGEpSP7a9H5+S+0c6ZWEdO58U4VotHAYX2v5VZnrn0QjJgIiiXk4RZxJfeFWP61GRJs sb7A== X-Forwarded-Encrypted: i=1; AJvYcCW7Qi+AeZvJXjjTDbIVOvsqP3YMeQzz7NewgosS+Fcs1I1WprZCPCKaCn34kSv2bMBDhZnCLaKGOFNi@vger.kernel.org, AJvYcCXgpQy+ffPnTjH4gGyUB6Gec3tvZ6ByS9jqOq2QhtwcW+XdynoCp5SWAqPmerhxENZkksVEmEgqeIPFGA==@vger.kernel.org X-Gm-Message-State: AOJu0Yx6BULbfsB4ba0PBbI4iMTiq0dttn+06Nr1WrSEsOZsXK299/lN 6lebfIZB1z+qyYTWtTX3537UkkZFJftdsoPIu1z6TEoxEFIlTtjs X-Gm-Gg: ASbGncuwW1JrlzcGQpkkeh/tjBJQ7GVYdgKsFA51eDa5caXapX/G9Rn9fYaZ2OHNLgm UeBUCig0NGqk4toHVGQrEIH3978gAGkfzynV33wbeiyVMr0bXZqrmg3zEHdkeAvcHxd9PHOgJGw VFkyQr7FMQkR0AWdC25PU4VvCA6m7/jZ7w4an56YJnPQtSumAMC65a7imuWdxcBKhCHCDP0rewu K2Eqe9mZCy3G9GqIQtDyXQSaT14aQtLwNMV/tJ0ZcYslfw7WfOoWo1D524/c2uhfS9marR5oGOQ tPZaytTkwZ7PdFtcQuToWUsIaPY5FmI7pC8CsPZkKSAiuFAKQq7FGz2A6pNK8A== X-Google-Smtp-Source: AGHT+IFmg/ioAkTa++LuIIL4+dQtB7e3EzFV8istwNO45PQcHo+eP9MIiLsvP1z9F1i9kmZROrsR4Q== X-Received: by 2002:a05:6512:4023:b0:542:297e:94e with SMTP id 2adb3069b0e04-543e4ba63b1mr622138e87.0.1738186190249; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 07/21] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Wed, 29 Jan 2025 22:29:21 +0100 Message-ID: <20250129212935.780998-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954154 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E5A11E5020; Wed, 29 Jan 2025 21:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186195; cv=none; b=qN8R9INtHV8EHaPqnbvnr1JkeB4PNOrLYvDU/xvKPH814EprZIx2mvw2KUTgSFgGl2q15ijGaCg9TU3eKwOjrfGvIooimhKq0b+dhsPDJPBju62zVvK6DHPdNhB69PgPPBicdO52zQkHPv2K68GWyNdNAjZFksDLpMVvQwViVP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186195; c=relaxed/simple; bh=pYTAXNODkP6Yob1RvogJD4zChtrr/2cpl+9O0i9/5OM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E9PPfM61yOBYgu8W/xsTnNzr5xjE1GMESeSsq1uJcoFPohdDCG4UNwv/7NXhasZ5qjEt3xw2WNh/Itt/NoKJCtPEkbyvhsMEHjld0W5Pg8Ph3WsZXwVDC2s7C48qdfnVuG8LgSEnMTtxOpVS8Tu87AytXChJ+nEaphorGs0YoE0= 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=WeD1grfJ; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WeD1grfJ" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5402ec870b4so11378e87.2; Wed, 29 Jan 2025 13:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186192; x=1738790992; 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=HFg2JOqecCladPQNQJTKLQ/Khyip6uEwSMoUfQW5Wyc=; b=WeD1grfJ0YT8W2u98+989LhJyP2npfZ7wLGGUC2wZF+bojjGYamZg6Ur51pcRyBlaF R10e/EQO88fFEacVfe/Wx/VN2H+Olw2hh82FW4BeVob8rHUSdWkqrAn+YkpIn/wD8Tu+ r2AlKOqbEXATFbdyt/ALj2JQF9S63+EVKhDqPTY3zwC6NiUJgr4dZ42lxMZYk55ao7rD ydMRHXzTPqcER/SAmzUX5kwyxXz194afF0Ms5rfCn8EhXoNztXnerxBFvf6DGEhG1JT6 f4e+FytT+XQM/bFqOJGkq/aXqJPOv/DkXkhqY3x02WbHeFhpMEtiZnE9KrA2apejPdwl GIIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186192; x=1738790992; 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=HFg2JOqecCladPQNQJTKLQ/Khyip6uEwSMoUfQW5Wyc=; b=A2dCOhCo66gu3j7Od60PYH0RB0ZgIRh32Xud1lJSum+TMQYMVcqnOD6CzaEF6W21oA tXYk3bZYa/DpgPr1lSklxZ0clhuFhvBj5iKfbZtgVsOWDgxxA6ywVzEgFgWeXfg42ay5 71xe4US1xschjSnWj4hXhP6xkY3qHmNEFdmvT4jvUEoZljs6JhItA6jwK2jalFcdDE51 x7fQvka9msvIyLqialiDI0uyxxLyio6PSQIDAehRDHoVIMqPjJgHQk65pNH4Q6jouwkD 6G5SH+BWDSqB5mOnyWCJuO3n09SJ6EEKFCoA4EkFK+4jpqDcgnYfdz0TuTzQp+luPPpG iedg== X-Forwarded-Encrypted: i=1; AJvYcCUIGLEAfdNGSO5W69/iGJa+CwCnBDdySm/c4Fr6nsIFePXy2RW6Wyfw0T9k14aP6JJcDB/tMaTSPxHXww==@vger.kernel.org, AJvYcCVdqQ+x20otU8YBsVvStqZvAWadJpu8c19I2VMcbp9cb85XePzj/AgcXRJwhRRhute/oAAIwX2FeQBO@vger.kernel.org X-Gm-Message-State: AOJu0Yx2GSmm0wtZgeOxewsVlM6PZUoe2pve7r5qi58+Ji5tjWXSft9F PpsXL8lG2Yz2U4tbIlYJUZp/6y365KKlXU8KnUyE0MeFSAmYeMpE X-Gm-Gg: ASbGncsi4JojSmka/feUhARrP7HQbymXa7DrzpCSlcJ3PeVP8q9mAwyDynlGIyGtqkU NrLopkNYMOG87zrV5yhpIwJFtp+yJrb+dsGe/yilsAdgsYoMzrO1MyXazTBO8ZY2EH57RqKUcwR ueRdcmQliR9IwO4/RGCtrmVqyXRicuE09I0ooiDawjD8wq84dyikNFFgW2PXs/GKrVwjiMI5j+d qabqJhEMwqQeY28CVe4J6iHhEGiyVt6RdajCvMX4Q0SAS7D6B3OJcR/kUuE209TB9EUnPeS3CKB Gaer6WQ2a7q9pWlTsC4RIknp6oQr3Iv9nAGfXDwuGSAYiVHroQalTCnKfKl0bQ== X-Google-Smtp-Source: AGHT+IFiFV4Q3hkCzpBATq/1QMdmSSHFHuBefVyza7QqRwEJ3YaDy9z8od7Gdbfd0YaTkMyYsgHNGw== X-Received: by 2002:a05:6512:2314:b0:543:baac:e9f5 with SMTP id 2adb3069b0e04-543ea3f86d4mr115508e87.5.1738186191422; Wed, 29 Jan 2025 13:29: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 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 08/21] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Wed, 29 Jan 2025 22:29:22 +0100 Message-ID: <20250129212935.780998-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> wine -> 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 Reviewed-by: Michał Kopeć --- 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 Wed Jan 29 21:29: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: 13954155 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.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 08FDF1E571A; Wed, 29 Jan 2025 21:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186196; cv=none; b=sxHbCjXiJ5a+qJx/6bHUxuCpKBkH/oYPxR6vVDwk2xc8b0lwpLuy5NvMIBqth3zZqp78Yo/nxG7utGs2E7JoAEo2k+LGhCv+pzyyFPkXeOKzsZtXRo+7062cSoobt2vs5odF+/COiNBnIdEilIpZSjNf0kxDijmmWG2jsVc8Noc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186196; c=relaxed/simple; bh=Dmf3lA3aRJ1G4Xn/CCbTrBcvMiTCnv7ZMSj2gfYWlQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lKlpergg3e0/4I4fEGKsfn7Q6+s+Q7JtcNMTeASbqZTqAmaOaItK2J+vykEPKAAIQpsf85Cs22e31Wnl+BgqnT6KDKZfRx08XlgNhVtnLv7gxN/1aK/MQvo8iWiS8wG0dHSv829IGITVCfgWstnKqbLO6l9TvpHEqHu4kbe/LTE= 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=JfjBj0X5; arc=none smtp.client-ip=209.85.167.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="JfjBj0X5" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5401c2bb7ccso16583e87.0; Wed, 29 Jan 2025 13:29:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186193; x=1738790993; 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=Fwz+pFtdjDe32aEt/94eKI6IYzS9quZ3LOoIZ3RV8ss=; b=JfjBj0X5RDQeM5xb/R0AVc5+QbHdqlfx6PR/wYsUWe4RvjvqSsU6v0sD0oOfG/458f 56nfFEyeVBHDqYd5+l+IolBUP1MGDBip5s1hVRiwYFGLEYtZE1Hs0qvypK8S3s+uiuEW nedk4KqEVhC14nJTzPiTqZC9fOi9mchApbGI2ZqBxot1ZhfMkSBZJ+AkcS9y64AfzPlB klxjTOws+92Y6KhP2MaODH8pN7ToPzWkg91WGZHV3ynGHlqunZaj5cgNklL8mvXDBqVL c13qDTP0VC01E7gD1Vh3Y0QnH6fWWHXzxCmC9br3zkPIEdEYlyI9zDSlKrixc5gHlxAQ B6Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186193; x=1738790993; 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=Fwz+pFtdjDe32aEt/94eKI6IYzS9quZ3LOoIZ3RV8ss=; b=UsN7sfZTudPckwqoQMPQXJ/OJeFpsWQnqUg99iVhEbBkheU39ilH5Ya6gLDqcL4CSu mozbvyf6QwhSuCm4j+kCACNrg27LI+s2Uqy50LZviKn3HO5tiTqs7mmNJZcRljP+JPca cqIJkkFy69QL0s8ajVfiTLc7VUxQ26m7UgqGwfi2dpIVgtocj/AiqCehjRRoHlPMj1Ee my7ubThLiwXiRU2o8O4PeD6t7WIT/1+RBqjm4I8jn5UZtT1TZRJyQvlRp2tM+kw23liP JMBNyLd5hjQv9gAtOUgLqCoXxrR0+beJZAmBUBXmcIGOYnxYf3WePRtrGd43ekuosoTI qe6Q== X-Forwarded-Encrypted: i=1; AJvYcCUFoM30394l7gARBbTZhoOotsrdyRPCSJcA0xKhf+emTAJFQhcJGXMhSl6A0qjlV8RlJ7slIfJogXYG@vger.kernel.org, AJvYcCUu5j+9atPnUwyz9VATolc0pGvI6gF36xafBrkgaRGQ3oOdSGZkIlpNFx5O5lpdf80BLZ5AOtTP73SiMQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yy6dyyVbpgPdVuy0m6A1hXmP90PjcmydIyjBgSteG5dzQLhvpbk tVsGDZQ3ZvfYGubta1FMLCsDUh5lo0LVisRl1P+0Vz+u32tB8xoQ X-Gm-Gg: ASbGncunCF3Hp2qK+rxlWFlGrftpZIf5NOsPpoz9ya+KUoAPFDofJTO5J+Gh4mZcJE6 q+4HqHrQ077qrpcBorKnCvr2jMGwmQ+9NvxWUssXqpFQne7Zb5fPkFv9FyiK2DGIMjPc8l8qQ+w Aohuq9NQwfRkmAhdneFu7m4n7cbl3MV4DSG5nPLCiS0b4kxuGM/8CrMkx8wjgqP/WcYLPshuJrX Gl5TIm3AHe55I8UOktVIb1em4nG7BgHijhW6/QJfgWjLmVT4jGooAgMIDX81WVbSTSzKqHAprcL 5Hzgf7zvvrTa4Y/Yzhwj0EH8ZBAFx+mMAunW5vz2RXR0kDhDay8MIOAdsCFjHA== X-Google-Smtp-Source: AGHT+IFGWYsUfktEv3Trv/cUWnhk/Evc+4ARetPF74+8YEZ8XKr+y+x6eX1JRhe1GMutuk4aH9nkzA== X-Received: by 2002:a05:6512:3ba2:b0:540:3593:9fd8 with SMTP id 2adb3069b0e04-543e4c02e48mr568192e87.7.1738186192978; Wed, 29 Jan 2025 13:29:52 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29: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 v8 09/21] HID: pidff: Stop all effects before enabling actuators Date: Wed, 29 Jan 2025 22:29:23 +0100 Message-ID: <20250129212935.780998-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some PID compliant devices automatically play effects after boot (i.e. autocenter spring) that prevent the rendering of other effects since it is done outside the kernel driver. This makes sure all the effects currently played are stopped after resetting the device. It brings compatibility to the Brunner CLS-P joystick and others Reported-by: Jules Noirant Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954156 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.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 32A791E5738; Wed, 29 Jan 2025 21:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186198; cv=none; b=HEvIhTZoq/aU/KyKtKYEvBxBefGAl64FXOc49WKsA4qv9sPhacT0vJYFUNnq+1GaPo+oyk7ZDMX9kfqUJgDkPIWBF3t1ooK6nuphUia+omZ3U059/t+7ctFSHXowcxjctxaN//JQl4Lr89tA0Uw0LtGruMpM9inFYvUM0xp3IHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186198; c=relaxed/simple; bh=AH/+LQlFM6qksel++KWSI+JDIbYZiANFMgwth/8FPh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VvYBQa5U2pIXnxqRb5S4RXw9Mhq27q1tc23jUz2zaYujiS6eNPsyxOPwC1o2ZqjQDh3+Vw+azaPTnz11hMA4aQ1NAfhlDHhixBrl8ERLYRhWGP7WeMQqcbojkoFVtX3oiV0ndcyTJHy8XB1WL9pFSd7kJJAGxuzEpkfrZul9AzM= 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=QlJw+oy1; arc=none smtp.client-ip=209.85.167.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="QlJw+oy1" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-53e3c3e38d0so15146e87.3; Wed, 29 Jan 2025 13:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186194; x=1738790994; 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=VE2M4p6TnJM8c4BCHMbaM2QSaKaUNezS2BMYrci6Qbw=; b=QlJw+oy1ab2cFm+MukSgXEFhioW4ZWLUS/qZlKubnFQdhm+dGyeUiB/yymnt7V1pHb K2tPsjAEH/GdF+5lLCjgM0u4xPZdX2V8Nc8YSJMFoJjkGJR7SF5yXLbeJ117KUdP3L6Y rlx0w1A6MFktdt8RKtoe3V85OOmzeOJJMvsswvNYwKjl4KU1OVNvLu9x/1lW5ijvBawY W0eU0i/NHGd4aBY0FmJsBlRFSdavxrn5+ysB80vyzzR8gKuEPJMzUXOIoN2DgZsAItEd Di7LAXrViJD9e3QoK5SGkGuMcxuT1qmCAQgllRnr8bDbvF2OSh/y1s3dxiM8qlfhbgeR pcWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186194; x=1738790994; 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=VE2M4p6TnJM8c4BCHMbaM2QSaKaUNezS2BMYrci6Qbw=; b=lMMh6Bq43Gj5OzaS8fpI+6iBfnGqRXVpp3zuXljTCVI8Q2ixSipMVfwSv0bMC41l/l ew4IkKVyxbMPZdnuhOTUOfk8yqOGgggQHOmuudaJ9IMDbP+zL6aLy2XlPCrfMyhRZct6 +ye6xK8jjr4YDq/pLEoPlM+CmcA6+g/3zoADvX7Nixc8JZOUJe8ZOHjxZ/7MngxzWtug Yj6vQ/QFOjAV1fcGeqjC8UFabyO/eXykAZGnRRCqoqCbXCPIiroO0cctf7rI5JDlx5FI 6KLIiPZy46B9jLs300ot7jt2UjeUuiYwnQHIwZ1/kfriNe5qta4agPR6Pz0Yih53QScY aykA== X-Forwarded-Encrypted: i=1; AJvYcCV9kXAnnC7NY/tRArrEkh4F1NZWpuHoi9NKX0kZcUrAmsaqrWKp+DCOpz4lZK02vCui7NSMLB11+Xtr@vger.kernel.org, AJvYcCWHf9N3azeD2BKxVdYLNC5gW/vXUSQz1y2qmloZKyQtxs6dq6icUPCJIFFnIzV9VdO0bIvHK5ps5DT2aA==@vger.kernel.org X-Gm-Message-State: AOJu0YxiSJ/Od38IxxUGkYRYl3+d9RoB2CnA3zlPpdVZMZN337iGG/iD bOhApM3xrod2mHDKeqxUegunE7Ck8sU29eW5C+Er2H13V6Is6uWQoDzRtLRg X-Gm-Gg: ASbGncsbY3J1HUanoyZOReNasREukGoh0XcHj3yUigaIIcQjKJ1cRZJQnKivBZO+CCf ANtUY6uSLz6guDYypBIj+p7nm7RRNHfBjdfPbJl+Pps8jn6WMfPfPDrrq3uK2bzH6pan1UvFxzy jYosN+6zuZibotZpZUTXyO+UraTJduv+mjUUcrI+HSlO65RTTzVuYxcehRGzeRji1EwGaI/ZmiU ZVgKfyXdz6S27TVvGjr+HgTiL5/nX3YDNbo/opZz2ZprtJeDzqVmNHQrqpki4UYzoA1brPm1obW 5jaEi42LDtIQuorVbFk7IY9OjDZVUctz7k9OoxJEDtILikrJAOTKVsRoHyGAB9tpAtlJaZtE X-Google-Smtp-Source: AGHT+IEA+ljG/OOCI2YjIKpojDGQ9UaacYTRfz2TU+AU+lRYBvVHOEz5gQnU6S1tfoojhJ/lmj/Zfg== X-Received: by 2002:a05:6512:3f20:b0:542:2990:5db6 with SMTP id 2adb3069b0e04-543e4ba667cmr616924e87.0.1738186194127; Wed, 29 Jan 2025 13:29:54 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29:53 -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 v8 10/21] HID: Add hid-universal-pidff driver and supported device ids Date: Wed, 29 Jan 2025 22:29:24 +0100 Message-ID: <20250129212935.780998-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend pidff compatibility, usable button range, 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954157 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.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 715271E7648; Wed, 29 Jan 2025 21:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186199; cv=none; b=jzS6fyLuhzfq3ZGI14Wui6nwxpkhV/zpJ82zUh7azLpvyq1seYtndllzTR5Mq4wsqm12MS1ICJfRoSRCpQHwC6lw8eFSFfI64o06IeMdU54CX2M4FdEXZrVuGhblfLArawOpJwJCKAF4rgWRWxIzcsMHvywH2lcKCe6P9qZIysY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186199; c=relaxed/simple; bh=u94tzlJBeeh1o0N3oAcI3ehsU+IVSPnmakK1VBt+T0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u6LQJLAx8jFDyL3UALJ5768KVXWxusNK9VorDdyOcxtue/GAhXz0O6ngZEn5GPrPJx/vXdsHhX65nTnqB3bRYu5XDfXEMmk2N4nu+Woiw5UcAkMVoQ2pp84WLOodzvCqcK9SuAI99v5b/svwKDCIvxfIlIJC5bUgXe/SXIPtuTE= 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=Mb5jsoA+; arc=none smtp.client-ip=209.85.167.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="Mb5jsoA+" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5426a29c81dso16290e87.2; Wed, 29 Jan 2025 13:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186195; x=1738790995; 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=BJu35yqnkA7n+3+y8BqSuaQXbB7YgLfXvINfiSbRaCE=; b=Mb5jsoA+VmKav+5he/To4v4qGiQHlcNyUR/WpgEzGi6LdqVb5fl1ECpIZ1hoZMoRCz 0sv9RrLXJDn/ghr2cHEJfdXOTkmE0OYo17BoN9ntHdzPAtM/45MOzrYgeQh7lYDcmOEA YEsIBOqfqpEG6YDqUrs2Qb71ElQbniGZ1BmZ4k9HxQP8T+RGSpmcrBTAzX3nAH23c9P+ cqCoYtizz3j4QUngChLg2us8NybODehUauKQ0Z5EXD6cyUCHwXSfnNdI4d/uOlDIOInh IE3nN0gjCMVWrfysbRiCuMNey2ML7vL+MZXb88pw0/GIvp0VvufFQs17nEpXcv2RLQpI gk3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186195; x=1738790995; 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=BJu35yqnkA7n+3+y8BqSuaQXbB7YgLfXvINfiSbRaCE=; b=vse7fIEa+4rhQLl3QnAndZogs+1i5h3PUmZpMLXfQ4qAHvElASiH2acYzHehcBbCRL P2zz4cmaB77Um/hxSyA4y2NMUo8U9RBQhqfUsVwy0zJ0BsvqXsOyQCiBqespPr9/GLel 4aoR1F7FsmzJfpXtSWOCQIQMJI3mMI9e2k/DD+w7gpTHK2T9o36w1ckzBubR6VQECFGj 1K3EOSOoEyyyuPxNuYbXYtJQnF47Aoef9NPWA6yhXx4F391ANvfhcd0luf4456kClBHt h8ugnh3MJB6atr0RkR2Bo2KbO8UWWJqmblNrGWqrBtCg0fn7egmeEMpa1BFJY6gKrIxP Oq/A== X-Forwarded-Encrypted: i=1; AJvYcCX/gGKczlhceGQSak7qjLQk2qy9XZeyUKZYxRhepyJefnGfbLbcilRmz2TNBUhSwTBPTBiXj//NgoxQ1A==@vger.kernel.org, AJvYcCXxNBxdCAQzGmYOWytOeLnoMHXNHNAX0dwD+hv1T3w3lA3NCuMzMyMkBbigkChZbKK6OhWGAj4naL74@vger.kernel.org X-Gm-Message-State: AOJu0Yxd1vIaMJXj3b9InP1fHnXoonrsYnoEKsoxRePkaAtUKHq4bKxr iHfYVfuxj/Cdx6pe2wKv7qz293msF+G80QtJHgb0DUAGkGAgiIlt X-Gm-Gg: ASbGncvk9VFwL14gfQh9r/dyNBvg/9vONRjhT45TgKZdo8vx89APzWwBWNw3X+Gc7gt ZQlyIV474X5Uiw3sGIzGneIcRXdF1W4ym5GmyUpv1CL94Zlz9XtTF7KAILBSqGQKJ/TqEltbcDc lVm1wjcAihYJScJnKozLvKFRIh32QJOa+dwia/kZpHItbvfgfVXWLcZDU9VL3ZZkl/+vcqDoBB0 wTsFT69JBw9PyYl7mHUcOpW+e5qCEMT9TBoXFbSjGFO8cp5juU9Ap911EuGF6ChPpnd2BoCB9pX DgND61wjDOkAQfx76hHKjWvdpJXDrlygJ8vTOMoW2bISHX6Y5VnFl3o8ZwjYRQ== X-Google-Smtp-Source: AGHT+IHueg9S/6JZAVk8Bcei3nKIf2eZqChw0OVwPKO7n73FiKKb5WHOLAtjzBtkFzm4n36yQXZNMA== X-Received: by 2002:a05:6512:b97:b0:542:1137:612e with SMTP id 2adb3069b0e04-543e4be9a14mr585983e87.6.1738186195378; Wed, 29 Jan 2025 13:29:55 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29:54 -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 v8 11/21] MAINTAINERS: Add entry for hid-universal-pidff driver Date: Wed, 29 Jan 2025 22:29:25 +0100 Message-ID: <20250129212935.780998-12-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the MAINTAINERS entries for the driver Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć --- 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 Wed Jan 29 21:29: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: 13954158 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C62AC1E7C2B; Wed, 29 Jan 2025 21:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186200; cv=none; b=pq/gyXHf/mLPPLCdGNwNHDIDLqBnHzi74gAUZcYBQuyhK23szcy3REinAtk/+7QC6dbyeWboF8ezgT8f4vedB0VUQFmRtoOLetS1QwB4zVbpHDM3EbJJPuaTeBfY7RGXPAFHFJqS7VUjL3qjnFcjfZhCpn5vi31utm0FGwmeMPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186200; c=relaxed/simple; bh=9Q25NIzuPD0ig/N8J2u5lpFKU0G93VvMuwTQCo0E/uA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GipRkDp5VZaSTa6yDRNZyGF5ifzTlceXeRhtxrrCNI9Vy7w57HoDdfhfKc5NzC9ji9QW2gRPfbriWowsTBNHdmk2bV6MJaC3dbLcviUCQKFTUEYGzTA+AYYUT73CFesa3Dqd0ZQKfaHGL4o0WY7Q7ylQRbUd1vajoIRB0V0ygb0= 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=Bo9mLp12; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bo9mLp12" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53e384d00f4so17551e87.1; Wed, 29 Jan 2025 13:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186197; x=1738790997; 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=81cdqFwXczLSBH4WMbPAIDCAYZcX/FsbCRIZWhq2ojs=; b=Bo9mLp127j8qpvvqFht9wPwYAWSoS2zO7EbEGTi+748OrbIKsCZLyRK8pGou9hL6FK ku/SN00/B72OJyj9dvMj/vvSRgltNeiISBSmMwYC/w4BzY5Zwkx8mUrfDeRu/+HBLpD5 BVRmmK/iT+Drp7QuD7NKhHL1/dt4Rq7o0QQe/6i8U7a1LWURC2MbzG6bOriaKf3Q4oF/ DfywG3JBXsyJfSuYm8TP4bApINb5khH85QbvueNSEAKsIXmYKGAI8A8s8EedefMKwoxZ iuyl7xLOwm9HIN0/IrGGDCkiP1iTplny5KN5osmSz7zSGcrHGCjXfda6ZuSnabVnO/tI wO/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186197; x=1738790997; 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=81cdqFwXczLSBH4WMbPAIDCAYZcX/FsbCRIZWhq2ojs=; b=NNXQ+Hc46Uf3lCbn6fdTqNCwWFpK27G8QVVE6avFXywOOL6qrUeZVo9EOpS7/ZeWMI 9252Z2HbLsoUPl0iTEMPkw2a5Ut0S4SJub9H4nFAXiLNL2xs4Z4EcDKI9I2VpITgES6T eUX8LZzjDcVSBntc4SYkRrRRDoySzIxurp2xqFmXsmoBvLqRIhC4QxK9PlSZgBJEoDF2 eJHALyUfkaqCmphkDk2NRO/KjzNs5/dVKX2CG0jOiiyvsqwDu89+AghOjaQqdE+iZpYX /4Q5KFgoZjPM626P3n8lVhXonRUWuIy6SQuRGrwiScudMUArWMb4U/X8GBi/B92YCxF6 j41A== X-Forwarded-Encrypted: i=1; AJvYcCUr6Jyum5KKivCY8+iRkzlqrIkbHrhfDK6blMj9t5Zvkr4wH3abLJI2hiKnhRpCCSvLSq2BYhJIUtrF@vger.kernel.org, AJvYcCVG18EMNIaE4RGNHBjm5WP5PvtxpTqpx6HmIDL7uUdKYifbd4/2Gh/apbjLmTFmoNuqaEExPUjJ9Z8DSw==@vger.kernel.org X-Gm-Message-State: AOJu0YwirU8/GK2jcAghQt7rydC8PeWVL44F2w7Lh8O65LP1H71VdEDc tgnEhEl0xXHo+5bemkanxH9zyR8Mz7QHaKaNmraFTRpwd/GaeOt2OhI9p/Mr X-Gm-Gg: ASbGncvydQa0mbYHWt9+VOcjcoczbAAw6RVvEilq6tlok54fXYlTeg2g+J9+qq3whU8 I6HhnNgnNo3ELEfm0MP8Bt8IZJarV/KkilGzXWzq6lGDzP/QgClJQwhSBH4gatpiHVShhnk+Gv3 iOsZUp5+viw2KkEu+9YYDZAwalW8/cHE/FGJeFzz67CmHjEi354z9uCUWUWTRrPnZCyg47FMEfS IRUqJK0W8cPJK5ElKdtbRxjZKRS7Jk6Lt/2R7G2WX8PLdJwiBg2GGoGWN0c7VvVf7OkkeQ+nRv6 gOfF7YtpukcbzgDcy90+mEJTUNEGaGGKRTeJCLYc9quZRdnvkkrbDIWBiajA9A== X-Google-Smtp-Source: AGHT+IEOqeBiEIfnqBDNO1KQ8OUDD+kvqLUFwCYvH57T7FWC15WOi9uo4YAarmGQMwrTDI8rh5ooCA== X-Received: by 2002:a05:6512:128e:b0:540:2339:376e with SMTP id 2adb3069b0e04-543e4c2e9bamr614779e87.8.1738186196668; Wed, 29 Jan 2025 13:29:56 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29:56 -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 v8 12/21] HID: pidff: Add PERIODIC_SINE_ONLY quirk Date: Wed, 29 Jan 2025 22:29:26 +0100 Message-ID: <20250129212935.780998-13-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 Wed Jan 29 21:29: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: 13954159 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.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 A99E01E8847; Wed, 29 Jan 2025 21:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186202; cv=none; b=aLFgI5wxtD2a8zM5l8Bv8rgLN9C+/VJ89BDXn4ywWo9/WKIqTBkXg0mBRnExzWV6dzPd2lap694YbcYd2a3OPszeND6JXKNyhPD+cnrLQvd2mm5X5cqANpJStrN/Eb3IfD1c9dLlv5GSOkfoqjpqe41yiphu6Swu+aP72+nqCMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186202; c=relaxed/simple; bh=sbJW1sK/3rVHF21xcyAObiLk/zuUC7xMTo3oRuKRRzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p+xG2A3VujApKKUZFWCWwpHCM8BYfqiz3pNr/4bA31Sl7Gfnoe4s+a6rJ1CUkOboiIKgsHRptcVN9hI8+0zPCnQfmQ2YOBBh+SvF9e9i/7PKcZFb3zzYU6dZ52t8ohNU8vcFlMQjI8sLYnttztd0YbhmWafYUnuIT+EYfPypxXU= 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=T8JK+4QD; arc=none smtp.client-ip=209.85.167.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="T8JK+4QD" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-53e384d00f4so17554e87.1; Wed, 29 Jan 2025 13:30:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186199; x=1738790999; 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=VCZldrUp2eoDRDCRmc8u1acPaDa0SUPYKuTn2MkbFJg=; b=T8JK+4QDcjYh55OsZfn9IdyZq7JusqaFxaHBsqAc5g03hkxCRzIRa8dPp00IVhOZGm 2MfKNLJUi5VJffbF4J3yteE3lXoVTFYYzpSxpdl4aKbE4RnWnFEZtp/milzO71QTtoGW TIpX5a7TtczjCFzjCGFDbfvap5779qoaeBLzs7pX6YBMo+SnL1NxBXN0XuDyQ+1Pg+Z5 dN6JVn1nj7EbiQ6lUQtFphp6wTmwep71215ayM5Unkqcrgv/brDesQ/iwbrhjD3/U3o/ jaRHtlry1vBLBxL782zcTAxttOOhXcEEY6Ty+RvRv6CSgKkF82KTcxfa2gAbAaNPO1PB VOBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186199; x=1738790999; 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=VCZldrUp2eoDRDCRmc8u1acPaDa0SUPYKuTn2MkbFJg=; b=B4wgZA9JJCxz0LWAdv213LKPeWQQbOnzmwcOWHaFgXiXxc4AeNC1udh/qYDsGHlQET uNTM3dExKLmuShgHNZDt+U3jeWRfuE7dr6mbHJxOcO/Cn+B1H/0TS6kC9WAcApXyxJTV vFmGpNYZigH2mZRj/BkGgGaga1spQB9rawpzs7VfVUxQlmb2bYJOoDXz4EVz1kq/RXc+ NOZbxTqEwonbA8ZwRiUDlzCnO1unEXgSvNM7qW7Mn/a/sZ7BMfUOfiu6Net5BCRjOMQX OQ/T9PYEW6RT1zIyjWuWasFVLqq2jLH81eDMH/geJ8HlQZGc/TR5e4Pa6Cfu8eUW45z7 Ww+w== X-Forwarded-Encrypted: i=1; AJvYcCWMrDzRBf1yubbhnvFBvk6EwTaqiANj0nXEOc6Uuv5xl4yUjz5768m+X52OdTEPZBN9Vv5m9aYDHfOBVw==@vger.kernel.org, AJvYcCWrUP2vS5pi4sOU5VOw78n2T+PsGV1+yxXDVOQjVOuLj2XLLonpl+cKO4fbW6ZjIrnxnHV/OABOO0nY@vger.kernel.org X-Gm-Message-State: AOJu0YyINhzI1j8jgeLUdYv6+mxmlnBigCMDiiTQSB6UFdCQWMgmt1Gu yfldh3YHQj0hbcu9oLhZaX8kcVuyhGRmTkZwQebUGSIOXYmgj3AW X-Gm-Gg: ASbGncuzfAHdp1fz9ox58YkRATQG3+rXdTiYZMqO6fC6N5dyboIaX4Fk9fqk8wgsp/c VE1ib7hrr8ExP4X8FErNg+PYSwtP7JDHJpftMhtc+BmZNPapX1IEXzv2+z06yGXQREE52CInbcb rLDFrSvyasnNk/BreSpvXlrNnNlTmSySF0EA2QzKlZDij15UT4pdrLPMdNAi4gc4b4uCXhUYB9+ xGTKApv1ijjzNCQayLuxmAzUtNDEqKrdsMbfQMHOCBTcJ9QULqqpPV68vSqFm5a1z/p8c7o9dOW WpU2QzV/zHrOCahCgV9uqBUeP5fDwe4i2tOuZfxSsIrcuHyhB8DAuBMjDW5ctQ== X-Google-Smtp-Source: AGHT+IG7BSRxf7Vy+7XjdJbwLV0+pdLhuHbNbYtUFHDzgAFFcdSsnaU24IsOHaaXBQ4csmmYfw17gQ== X-Received: by 2002:a05:6512:b97:b0:53f:8c46:42c8 with SMTP id 2adb3069b0e04-543e4c3a323mr534986e87.13.1738186198458; Wed, 29 Jan 2025 13:29:58 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29:57 -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 v8 13/21] HID: pidff: Completely rework and fix pidff_reset function Date: Wed, 29 Jan 2025 22:29:27 +0100 Message-ID: <20250129212935.780998-14-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- drivers/hid/usbhid/hid-pidff.c | 138 +++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 49 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index e6224e797dc6..7db63d686c62 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,83 @@ 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->control_id[i]; + 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 +577,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 +599,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 +649,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 +1296,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 +1361,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 +1378,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 Wed Jan 29 21:29: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: 13954160 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.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 C78CD1E7C2B; Wed, 29 Jan 2025 21:30:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186203; cv=none; b=XGxHtqGYAVJlgttVzx1dv0El6e8jh6gGzMMcZCzNpObmKZ5F7e1EIBAEqz4nDPa3hl//By9LhDfxo1MtXIO6TtgdO2+rzO8QETjwZ6mzbOmguI83Dakn7xXeL51+B+hOY1lrhnbFChAQNdGpvFlA6YBoBnBuXiO2BbwtiUKdP5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186203; c=relaxed/simple; bh=GgTvt0ZZFiWPJ+SrWBbsAPbjXKJXIS5uvyEeV/lNuVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ULJSZ974EULFaLrFkV/j0mjVF7JiEaxlBK2sOiNtKvE0ED9KxuVH2jD53inOiQVXVPf9+mPe0wDdoFIyzAXlR8putypkZ+/B7y35nFism8aiPCAP893vsmZbrOffn1+wRK/aPPIRUx7IK7G5T3iSUaYXS3SEMrl1mr/HIEjJXtM= 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=cqV+Byex; arc=none smtp.client-ip=209.85.167.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="cqV+Byex" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53e3c3e38d0so15160e87.3; Wed, 29 Jan 2025 13:30:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186200; x=1738791000; 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=5NLwULoE/xqSyQwC2UHRGTkQougCNUUqGiWkxil31jc=; b=cqV+Byexjn+ixpqtpLoKmKp5b5KG2uL62jMfy4SkC2WMAsLKYPDaqn7cPaEpegr9Ip b1YPcYv+8OMd8EbSGhHrHLHsYP1JKynI3eNiyWR5zekoQeXB2ktRASA3oD7veFT/VNHO GzpGcf2C0sVY9iaxvgmnZrdHsfVCNidN2qzHeMDytFcLXv375jwDhsfoOytJZvw+FduI jkLKbzL8jhIUiRZTHRMxFRmdLjHMRpX3exmwRmYA3fBFlMpzK1lC44EUBhIWleJCtw5z 9rlVMaVbM4KdP7Y5h2SE8HnDsVyKh7yL8O+oI4VB+5Y1ZkY3kL29/c7pQb2gZKRQNsTG yCHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186200; x=1738791000; 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=5NLwULoE/xqSyQwC2UHRGTkQougCNUUqGiWkxil31jc=; b=hB1KCai/5H2kcDgE+u8/hqYPeKzN43RZ5Glh0RKJGMHsgNqvez6sAFcgCJIYTsgYLh WMFkqwW3MHlcfqH4p7OTME0lpV7yE4pN8HlEqMaD1jgKnHTrT0b9T4pGj/9reUSEIeqE DrIQj/bWBGfIC2RrCIYsIEA+q47IiKs210+OZf94sQp8BSQq01pvP50t6UfaDquBbQus 18gpiuLjow8GPtvePAnRanzeES1cb9vXCka3XXAW91rgpXDCYsqJc5MvGQWdbb4WmxHz qNI/k1sN/98r8tFMEGDdNwXqIw67a5Pwkmhzll7iKHVPgNM+ouFUS35gVB1GmgV0au9J D4Kw== X-Forwarded-Encrypted: i=1; AJvYcCUp2j0qewCv8g3hIl7szW1xhuEARbsOWcPyrtJCfXJLXOfVi8XYRjRj5rS4m+lRHb6fPdbLz0PLIGae@vger.kernel.org, AJvYcCVmgJCoBuXR8pVJ7w2Y5gm0Eum2Su/XnzlHWmYJk0VwtWEzuNmUBR6mu4b2am8i2M23B2wxkkygKmv8KA==@vger.kernel.org X-Gm-Message-State: AOJu0Yxu5t7qK1hOlBH8Q2wjkNSA6bX1gYnBTZgNpISXQTr90LWiXIIu S80LBKNoXcEfdSUs/hVvSCGEZ+kxxqK+iQHLLnFMjiyqtNETT5wG X-Gm-Gg: ASbGnctfrAmORoO8aZMYzWkJF6hRMS8QLklcoFD3TQC9HCUTBoWiy7PRN1gndf0OHu4 U6cJmZeSFI/BYDw3pDgec2qcaGGO9mC3P5/tkWf5G9lY1gENyBNp54Qu+PAN1vkOVWrRAd2V3ww ruQpw4TQjJPesWpxYreZQmf148x8H1dvgpSfxnje7eNlEfSI6XKN5SmeftD3ojleKP3HCchuaWL M7AE3sfGPBAKfB8M8NOB13OfgRXuOqUasReNaoc48Jb56y0uABrULquPshqftKu+hXeaDlYCtQr tLY6O0ilok9Ke3njTbofmHDu+Hi6+kAjlGM6PScAFz4146ZWVrig9i2Fk1eaRg== X-Google-Smtp-Source: AGHT+IFdtOV+HGFgxbHDwv7y0BFdtLGXgeZc1NDnvBW/7UD9aMQqea5lBQWNemNfu0cmXSVGKwFLNg== X-Received: by 2002:a05:6512:3f20:b0:542:2990:5db6 with SMTP id 2adb3069b0e04-543e4ba667cmr616950e87.0.1738186199667; Wed, 29 Jan 2025 13:29:59 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:29:59 -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 v8 14/21] HID: pidff: Simplify pidff_upload_effect function Date: Wed, 29 Jan 2025 22:29:28 +0100 Message-ID: <20250129212935.780998-15-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 7db63d686c62..a8698593e432 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -770,48 +770,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 Wed Jan 29 21:29: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: 13954161 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13E861E4106; Wed, 29 Jan 2025 21:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186204; cv=none; b=ZhwGhSwOh/mFOmjOitc/tXsCi+Bq+fsPMXzTJqDCtnrtgkCgpq0flvxQZIPp0xj0YkT/ERp9dwZxeiur3gAg/pPa4Zj3aHyu6inFUxS2Wp0ku9C1ON4R1voCGtmRRZYLNEMS5sMmimMsM8EbrzAmsKjr5ZKNNRro7bL0Fxbuomg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186204; c=relaxed/simple; bh=eLUNB+4RlHA4Tq3rt6ZMV4vSxBclxw6o8dFzoRVq1+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=imnnUbOO6aBCqXUdShJsh7UV157gU1yFfRXngPiMHScPM8omI7L5y1mzgpor19K/n41DaPg6gFUrcC0sDSzd/z5KlWqIyIExsaR9w0caSrPieiSXSWeC2pqAQwWq+HAA0IeFd0Gj63wQEsXTfEHveXARWonLXIZBEdsob+B9hr0= 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=DjrJRYPk; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DjrJRYPk" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5426f715afeso16854e87.3; Wed, 29 Jan 2025 13:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186201; x=1738791001; 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=4/xJMyZ09aGkbfeQ3yyWVsxqsm6ay0kI5dasieVFCsQ=; b=DjrJRYPk59ROg//q4MXXzbnwmKyWOO9mVBMyGo9ZzPYGX9GCsVCYH4CZMu6WYSgNm6 hXYIudZzbprX5sw4kPzrNm3XmmVhYmmpr3B33Ybx6Qd9OpjFkgEJ2tKuH+exUGwlPjOP q1Hic4j8Po0R3Deiw2CC2L4kLG+7ap7YybB8T4pWAad76Y8P38Is060QaacJvMktXMRQ Brqjr0qHvak1IT9Ucr24/57BrMTlzV16dV+x/eYdtUEBQsyxeg80aDNydT/aGw4aC64V U7MIzKU2Yq7aKUtBMIvCn72H0SYTDTkCx3ImDp5lAwpR4ID10KY/HHZHLrpJsZKdMPMc 3zvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186201; x=1738791001; 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=4/xJMyZ09aGkbfeQ3yyWVsxqsm6ay0kI5dasieVFCsQ=; b=IMq6L+Hn5TtQjCB3dxMVf03IsJVhb7PZCiHMbtsJEWpax18Iz62DZtSnEGAevXwt81 Dhesvb+rnkf3M9EXfLARJBGSxVxMkG+CwlFz4GihHetnR3ESAtTEAqxwbpRY5r0rXCHb illJicsRpJevnoiAh8oWFb25lAh1BLNmb3iy6jRWu+1hNRItBUbSF4I+sR9SAeeWXIs9 23g5mzQW/7j9BKopGWeSeId64wsqZGViwZXTYD+L0TjYS8HmWKCLRwCeqbAIlWGx73fC IMjgVTSSAcYcR6TYMD9at36FUhWxgSvrxxpA+ChUvUDOgee1+WOsekiXwBXjxRldKVMT QU8w== X-Forwarded-Encrypted: i=1; AJvYcCVf8mTnkuc1g8lDNnaMl79lpnO/qiLGY/Q0w/y0YfTrKjsJMHlBkOjtc4Q+sn35nq+wUjaWOYQQQpBaKQ==@vger.kernel.org, AJvYcCXtN/2PvV7pmY3IE7iq+ARJVjHPtfw0kCWJG3X5nQZ8t9Z+iVgVKtAsItM7vxCecpVVPLfvWkqxkUxr@vger.kernel.org X-Gm-Message-State: AOJu0YwgxcfqOi7VpfDH7Jtbl6vj1eZ+H0zlMenvwGsH4lS/IfS4xnr0 M6f4U4SjIWm8mE5GJ4RmKxHUFogTUP+mUYnQtY+Ew/mhjhkDxPCI2OYP/naU X-Gm-Gg: ASbGnct+/HH6Z6Lls0cZWpKYkKazZ3Mpo63el/A2TYeB05MJNqV3uRoR8ID9FHdEZml iMZcuvrriEKetduhwZYzKKofsII8tpcwRCYMd9HNlWeLY+w0oXWUOeXvn/ldg7R4XrBCiIcfWyo XPi90pKTEGA2EotH7dI7ZLnQvdPPYbQ3SPDUmdj2PFMkT/NheWciiHvUz7Luexmf5p4wAvungJU zAaISFwg3Ejb6Jp0vViMMoYlOHKccnCsgT+pleZrArY3DzGqjtfNI1SdPTbzy2Y+bE3yUB7DzI1 3CEJGi5ejFRRsaui5tkbjo3a7J0AN27SZVbn1aHfyv2apbuRryn3yOLmlS9aU3uUo0pLkMIx X-Google-Smtp-Source: AGHT+IERHO8kxOpb5L5OjuAmlyMAHU2ATPQeSyfAlKNQVwllV/r27rarl2eo+0sRWoJLM228bgUkNA== X-Received: by 2002:ac2:4e0e:0:b0:540:75d3:95ad with SMTP id 2adb3069b0e04-543e4be96f7mr595638e87.5.1738186201210; Wed, 29 Jan 2025 13:30:01 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:00 -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 v8 15/21] HID: pidff: Define values used in pidff_find_special_fields Date: Wed, 29 Jan 2025 22:29:29 +0100 Message-ID: <20250129212935.780998-16-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Makes it clear where did these values came from Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 a8698593e432..fbb79179e02b 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 @@ -1046,23 +1054,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 Wed Jan 29 21:29: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: 13954162 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D74631E9B17; Wed, 29 Jan 2025 21:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186206; cv=none; b=uypIsSFW4Sszc/enml1dPyD67BPQV4HqREvEy5iJz3sW5Lzp0Z9T5hN2p4sT4bYIPwi0BEuTHfHsnDQZUSI5H186Jqb4SCUYYvpqoe+1z1/ruzKYPzHOkRdwHaFgzm4w0VOwlKGvm4MgUTPavGsF5sxLuNdwgDUbwxVj0EqqqJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186206; c=relaxed/simple; bh=iJ/1wezF7ezlL/JORpboMa8tBEduDl5uxy2LGcpk2yE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T3WJOF+M/XYjrOEnDiGvGTlyUE4RQ3enVyxBx6WpsA7vh+sSUXwFP0ii4uZPM/YylZUXJwtd7IA+y9XwobbLL4qwXDStoGMp4bJvyHXqtmBHARV0RCoUU9zmvCiBcGVEmFXfs/pcyH9nY/ESEI/uk3tdoVnsQCLEI4FpRugVRhw= 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=SJ/YqQe0; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SJ/YqQe0" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5401c2bb7ccso16606e87.0; Wed, 29 Jan 2025 13:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186203; x=1738791003; 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=nOtQHUVFtBKAN6mbtmWXvgmP48h7Jzc9jnO/6z9uN/Q=; b=SJ/YqQe0VugtRJPQjnemi7mowGHDCh+7J8m7t0Q/2P85yJkaKtA5frO2HlAt5XCgSk 12WACnhZ1owOfm01sd9sPb3UKsHxG+4IW2V1O+yKSjj6P0bMLtzjqIG7jNzB7j8+0GrY LPFXWuRIdHSqmJ5QK9sivPm4MzfePytR73rAL9ZNr15JuDKsS7SzEhyEUHUau0fpCn7P 2ay1yY3FK1jeDWlGRpTUiMf7Qee8P1Jl5rYKlExaElGJaSdOSzdIoIfiRn6mUwInzUQS Zd/LyK6iIbmXp5gvHw4Rneer0c6Vagp57ZNDlNM9E/Y9/AU3X7FtWFMmz7n2+xHup3xc B7hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186203; x=1738791003; 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=nOtQHUVFtBKAN6mbtmWXvgmP48h7Jzc9jnO/6z9uN/Q=; b=YQMIMkdZmSdRQtADT5iRPuVPXX3JrraRqqByT05n5ICeaZY/IUJ/ompdDJtXHWObUG cchf2m/VCd2+ifH+dKMw6L7SOPrloYIU/OJ03Qbzx6PnBuevS8PND6YdeZ7OYxW8cXA6 gL2n4Zm0Sugf2rwNaSshN6X4+apuG72ZxMBFJ66ERBye9SBpn5VOuqpAnFIF7PM/VztG z9EdFMm6AsEa1MevBqt/5dMDIxLMGth25OZrEKFTp8MRKejpxCgNxFs16Q60he2npPbk TelgxU7PZdNIx9HyWXpDzGR7AKPov0ntbYMkpVDLyCG53PFyQFGRv3BzmrlX7dslnQni gkeg== X-Forwarded-Encrypted: i=1; AJvYcCUB/FHga895HMZcB0zDNnLgBjnJPNM+reWpl5d4ubP2DCv0u0zHCOGc4YfhF0berjlJB9ged7EYy/rsgw==@vger.kernel.org, AJvYcCUG9XPasLNa+KDKBu/zwKw1Y0re4UizAUctXy0HZpuqE1fTCaPFWScDtiLcHSPX58uc3nBAi3iKZeaz@vger.kernel.org X-Gm-Message-State: AOJu0Yz6fSw5Gs1xV+IQy90W4VLiteJc+nHrtrliJeA9NiG1xV8+cM31 on54HiIF96wJRBdx1r8ahdg/F1f8KI8wOTyL8h11Tv9uAu5LpKSQUS9KC+At X-Gm-Gg: ASbGnctGUi5n08bA9+YWGyO1htbkCcxXRrsPJyUGmS1j4GUg4ft5tx6BgQ99d4CjHyd 2Fj6ywE6cB0ctAWJ00AKqFSmEwmY59BcnyKioqPlSo5S3DiavBHSAQUDMaLRW+1ZOJwxlXYCT90 HAU47rsVkKfm6YVW4oGoB8GSbs+jUMVbgJLQvSpEm2zFbKlt4+8zOCWAFb+InBZy/ArO5r7M8TQ CrlTeGNIprxMUhT6Q0wgWMnxh/N5y/1c96mv+voeP436ugJIA2hqh3dh7yTxeijm4YOiqBOtsWX QR6L7sw5lacng8quUlsgUw4ioGzxRROf2s9pg6nhy+RMc6DfeU1jfK87irMDpA== X-Google-Smtp-Source: AGHT+IEytPOx0OA8d/RHMGldoObD1kyIuIMh1MyzjHU3pO2evIpcKeADFulw3cpPqycmF4qb80FL9A== X-Received: by 2002:a05:6512:1083:b0:540:356b:8ee6 with SMTP id 2adb3069b0e04-543e4c3170amr566690e87.9.1738186202762; Wed, 29 Jan 2025 13:30:02 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:02 -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 v8 16/21] HID: pidff: Rescale time values to match field units Date: Wed, 29 Jan 2025 22:29:30 +0100 Message-ID: <20250129212935.780998-17-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 PID devices can use different exponents for time fields, while Linux Force Feedback API only supports miliseconds. Read the exponent of a given time field and scale its value accordingly. Changes in v7: - Rescale all time fields, not only period Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- drivers/hid/usbhid/hid-pidff.c | 69 ++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index fbb79179e02b..6fcced6348ec 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 uses miliseconds as time unit */ +#define FF_TIME_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 time value from Linux default (ms) to field units + */ +static u32 pidff_rescale_time(u16 time, struct hid_field *field) +{ + u32 scaled_time = time; + int exponent = field->unit_exponent; + pr_debug("time field exponent: %d\n", exponent); + + for (;exponent < FF_TIME_EXPONENT; exponent++) + scaled_time *= 10; + for (;exponent > FF_TIME_EXPONENT; exponent--) + scaled_time /= 10; + + pr_debug("time calculated from %d to %d\n", time, scaled_time); + return scaled_time; +} + static void pidff_set(struct pidff_usage *usage, u16 value) { usage->value[0] = pidff_rescale(value, 0xffff, usage->field); @@ -252,6 +273,27 @@ 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_time(struct pidff_usage *usage, u16 time) +{ + u32 modified_time = pidff_rescale_time(time, usage->field); + usage->value[0] = pidff_clamp(modified_time, usage->field); +} + +static void pidff_set_duration(struct pidff_usage *usage, u16 duration) +{ + /* Convert infinite length from Linux API (0) + to PID standard (NULL) if needed */ + if (duration == 0) + duration = PID_INFINITE; + + if (duration == PID_INFINITE) { + usage->value[0] = PID_INFINITE; + return; + } + + pidff_set_time(usage, duration); +} + /* * Send envelope report to the device */ @@ -270,8 +312,10 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, 0x7fff ? 0x7fff : envelope->fade_level, 0x7fff, pidff->set_envelope[PID_FADE_LEVEL].field); - pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length; - pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length; + pidff_set_time(&pidff->set_envelope[PID_ATTACK_TIME], + envelope->attack_length); + pidff_set_time(&pidff->set_envelope[PID_FADE_TIME], + envelope->attack_length); hid_dbg(pidff->hid, "attack %u => %d\n", envelope->attack_level, @@ -340,14 +384,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->set_effect_type->value[0] = pidff->create_new_effect_type->value[0]; - /* 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_duration(&pidff->set_effect[PID_DURATION], + 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; + pidff_set_time(&pidff->set_effect[PID_TRIGGER_REPEAT_INT], + effect->trigger.interval); pidff->set_effect[PID_GAIN].value[0] = pidff->set_effect[PID_GAIN].field->logical_maximum; pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; @@ -360,7 +402,8 @@ static void pidff_set_effect_report(struct pidff_device *pidff, /* 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; + pidff_set_time(&pidff->set_effect[PID_START_DELAY], + effect->replay.delay); hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -392,15 +435,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_time(&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 Wed Jan 29 21:29:31 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: 13954163 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AD081E4106; Wed, 29 Jan 2025 21:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186208; cv=none; b=Db2T1LOR7dCAo+Fn1ie6Xg4QGixx6HSRQEvetbxwqWagBtbjCPgc1+NeF/tbdqpFKi2MppeSAOVDBMI+H9mUNgGpZT8y0OLdufYWM1n08D/1x73T3K5iZ6M6CaUAgy7s6t+t3OINGRxqNkBQ43pYMHp94skjnVm0cZr8OW7Tr+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186208; c=relaxed/simple; bh=IULvgMh6Gm8M/CBBPKWDj1B7faBtRJpOAACroJbbql0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ipGd8pCTRSbvKRfPPj61IRoZA0KEed0YhIUIgYmhTH6ObaWzawVj0eOnxvn1IIRze5lY+jDxmIuQMSe7XehhneghbnJJxDCkTX7exsiKi17wfQo4X8lccCCZIfFevhep2VakvUVCaM/1nNpxQ7+gtJXq2U9sfGpthTFBkk8r9Wo= 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=X7lUwKYr; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X7lUwKYr" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5402ec870b4so11413e87.2; Wed, 29 Jan 2025 13:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186204; x=1738791004; 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=JfhlFcKIFUrmRUtlao8lSniPT3M/TUqDE9OlBqCjDY4=; b=X7lUwKYrOp768RC943xptintLy78O/iNtwMZ/9DkbbLhF83krlEbPgwqo7470kekWB tchhahP8/Ym8nkpi1Mr96tkC44EiacNN1ilnyYlmojvEAketQCpZcuvaYMHylaHQMowb V8BwdZaskR2f1EafYINr61UsNz9vsWczYQfpH9mELJqzhNRRBx4k8jBeRC+U1Xrzt+pL dsEtKCjSlfsCqhFhVvjKE6jb8xC2qSvR9lDQh3I04SNJDoBgrNNkSRFMUDHa6U9ot7XU L/aIvbmQbUMJUaWp+3uKLl31xtiFMezv3T2mJFXB9pQvmsP8Nvu/qNnbtiBKTLZmcK7g w4yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186204; x=1738791004; 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=JfhlFcKIFUrmRUtlao8lSniPT3M/TUqDE9OlBqCjDY4=; b=H+kjaVy0JSuu//UREjNXmI1GcNZuyBnaCgQ4SoaDKrx5+24KXzEFRyIHe/tQL5mE7d c2c/F+L2JyZbmdZdqSXFsMP9ep8Wobz0FE0vNPUm8nqF8hpboPsltvi/p/U2DCEhqIV7 ZIwDD6YbqHSpWXXqcq2JJsTD46DK97ZtRmJZYqK64p2+Zuu1mb3/Dm3i979gvkjepKCJ 7wUxQTlZlI5ragKHQfilEGcr4JCxYYA+SH2is1mUHadHh3w0A0plv3trGXrg66qroDn4 PU/EhcssNKHMhrhCgGSRJmn12xpZxZqrhMUazLmWjvoJorGqfQ+NXYoxxEhnCUVv3AH8 xMlw== X-Forwarded-Encrypted: i=1; AJvYcCUIZQtV/3VA7pUSSJ8uX0pVx2dWHcDLPqlf1HIOSc/mXatoeQ+/ebvHC3qQ2UuiJCu+V64ofQ4br98B@vger.kernel.org, AJvYcCVJMf+nxHBJWQ875gGMkFDYVJwD0h9XsQA4W70su7WDbVxxKgjPyJ4/3NvZjMli5aIMMzzJPy0lyjAYTQ==@vger.kernel.org X-Gm-Message-State: AOJu0Ywc41QIITGmKK7yxPpswWs7mBtBRjbSy8d8u59bHyTX/qulH1HH liuX+lz5STM8XKhbhNkGfibkJGqisWw8twmktSqgHlhwPDYWehgJ X-Gm-Gg: ASbGncuWMiNCyoLs/QNPqx8dkV4nNpWVq/qhIyhvU7AiwXlGE2hZWY0r0BWmRwukNTj 2zs7LsYSBpmvg+3lSbMp0qRc8ntdz4w6tXRxgv0e++00c/qc8KruIqt25iw2ILG+g9u+QUdsTOV KcPDOPN1qDzS1LPtpEJ9eYnrP9TVqXtCDgqPMScyFHVjHG9Nzss1KDbNxwiYkHDuupYvuekpeYN WTWOkpmxvqITEOYtj0fLUKtjvnFR5Q9j1Ew4oO9RMf0KdjDNQjHCCvkRKj9C920zlJGglY22Mu7 w19HBs1E5fPedp3FaLHed8ndv7vGLG3DnxNFM1QU1Zu7WGGdwkUFRp3bFFT/SraMcYUCJXnj X-Google-Smtp-Source: AGHT+IELECGkCkpU2yn3QycQh6oTwX8hO07ubbe+IaJSV1TCOj5amb1UhBTxmaE7+QGNrBVq2ztwkA== X-Received: by 2002:a05:6512:3f09:b0:542:1b97:b1d3 with SMTP id 2adb3069b0e04-543ea3d96d8mr79013e87.3.1738186204337; Wed, 29 Jan 2025 13:30:04 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:03 -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 v8 17/21] HID: pidff: Factor out code for setting gain Date: Wed, 29 Jan 2025 22:29:31 +0100 Message-ID: <20250129212935.780998-18-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Makes it possible to easily 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 Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- 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 6fcced6348ec..c518fcdeb6e8 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -539,6 +539,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 */ @@ -865,11 +878,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) @@ -1404,12 +1413,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; From patchwork Wed Jan 29 21:29:32 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: 13954164 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.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 201451E47B3; Wed, 29 Jan 2025 21:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186209; cv=none; b=or/fFx/3qHmDI0esUkosPPKkn5Giv/aAGN8sU4lJP5LzHAzQe9JeXNqVfqCPK/KeN5xHb6GJytJ/wqXX7vIO16dXvh0RU2Q0/1xtdpiMdJfqJ/eY3tKDSyGlKyIXpUjbOFuCfQogIKJ4E+1H+8VlpaOkMpNt2jdCTLyrSd+RmQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186209; c=relaxed/simple; bh=upc0huaMUErf1cPjnKu1oEXsWM2cicamvfM0Mh6YjGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nNk1H2NCMjDIrSZsOuEioQDLLy+TXNDi2Lx7mfdWsZrb1jOIEjWMYZrrSF5d6e+44/ccwTMbhoBL1CuqOxJpF3z8dEJ8zgQuFbOekJg6RYnvwSMnXam4r7IPGs3jmlhjfTPVqSJbdb0yx1gCBXI1/mTRpSCdg7m0Inn8nN83mxw= 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=RW7yxqeP; arc=none smtp.client-ip=209.85.167.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="RW7yxqeP" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-53e36a1cf4fso15287e87.0; Wed, 29 Jan 2025 13:30:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186206; x=1738791006; 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=LsJSUlcX/sY1UV/qhU+jMDcWcR1sDmY+0kNDCFcAE6w=; b=RW7yxqePdQm2GoYr7v+mC3LlwpoH79fyLKEVWJx3alasBTYm0vy0JGh6ZV+aiiBekI xaMGYutT7DXa9ZyqQRTq/Q4lpeNuM3Aw/uNTM6PGiAHgH2h3ete9QMAl4AiQDObslE+H m86zp366rKAt+LtZCZ9II82Tg2lKepp1b1BQWi/TCO5u9ZyTTM1oyuzMqIHMeVm+FzyO emoo8EZrEbTXGFA4CJGd8rxHbNZ8iYDIn3Jk3WSmWF4TY0Yi2PqG9/q6FVyzFV4eJ7rm j5D5REnpgbw7aKSZsodv89sGkftTrzNkzFeyDOORq1zees27pMPT6XB+rl5duTE3IHmZ SRXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186206; x=1738791006; 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=LsJSUlcX/sY1UV/qhU+jMDcWcR1sDmY+0kNDCFcAE6w=; b=oL9PUsID5CngQ17OTkjBn5oQekYqolFQG4yd7g7982MubmA2h0mMh0t/3JLEYB3KSD YSTZAHrPvhMFOAvvVG7ZOB1q/tA6qvf0eYlrdc4s0cIB3G8/ScZGQxjeRVluTTmlmpl4 5awnh7VMIfZGZT2iZvQwWugDIB0DvgINDxTuLdz2ereyvvgg5e6RF2G4x1BDnVDR0ayH UtlNEhiI0B5E+myvE1CKATnd0ni1+x7vuzIVy/QqjDkQAUkpu/YpCcboCRTfZ/gvlIJb HoM6E38qDcWCpO7nowXVtVzWbdCQ/O1I6bpVgk1Gm1N7ssU4ItrEMMIKBL2GDeIyoFt1 JyjQ== X-Forwarded-Encrypted: i=1; AJvYcCUsogEdO2nzl00C6h4CcT++fsMiFG6LCdrtyI/ZmBoySL5HyHwEZ6ua/MyxUQGQNNgYKHLD4cYdabNl@vger.kernel.org, AJvYcCXxElcJFYQ0Xw1iFGd1nYce+LVhVPTlhtcYQOwo6aXQGXCbK8LtJgq50ZfoWX0DOlhY/pwABkADIjlB3A==@vger.kernel.org X-Gm-Message-State: AOJu0Yz2ZSTf8eCfhcjwZ5S+045HyQ/Egp1AEXt+YNslWhiiRxCQNEOj c1aydcJ+6gFCO8HW0tpzMCVRmsHikraStZo2f4rAqwLIkNmgNAYL X-Gm-Gg: ASbGncuV3k5FFctZuwE4YeAPix18qV3Lu12OUpyQsBMzAHfWkVgX5C7EINMEau1reER Bo82SP25klkJhEr/JIUPumffQ4XFgYLlqROMy/Ho2kwg+i+ljBvdbI3PfNCAv0kCRFUVn/lGK0E 6q7FCHBiqf/VdhlCod25ylxXUhrbptFyMeFGlXwKXfRNuNBHrN8ExRq9wdyilxeyWCkglrGTH9N QhtcxdKjU4BcQ+qtg3JZK6BtOmAWf0JZKnwaKHSymq1H5nKBX+1tkKut2fpMfOPTu7K6j1yfjE6 B//WP8MOhxc80o98qZlmNbDWI/zIu/xS7k2uyvOxdb1Js+VUO8oh4m/4nXwNIg== X-Google-Smtp-Source: AGHT+IGB4g5CDahT5Jyl2GG2+UYumD9mBc0UaYBTXXyP0rc0nDzfF5jyl3a00o8XQKC5/AkSPYUDnQ== X-Received: by 2002:a05:6512:1042:b0:53e:3756:80b4 with SMTP id 2adb3069b0e04-543e4c3a317mr580027e87.12.1738186205852; Wed, 29 Jan 2025 13:30:05 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:05 -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 v8 18/21] HID: pidff: Fix null pointer dereference in pidff_find_fields Date: Wed, 29 Jan 2025 22:29:32 +0100 Message-ID: <20250129212935.780998-19-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Tomasz Pakuła This function triggered a null pointer dereference if used to search for a report that isn't implemented on the device. This happened both for optional and required reports alike. The same logic was applied to pidff_find_special_field and although pidff_init_fields should return an error earlier if one of the required reports is missing, future modifications could change this logic and resurface this possible null pointer dereference again. LKML bug report: https://lore.kernel.org/all/CAL-gK7f5=R0nrrQdPtaZZr1fd-cdAMbDMuZ_NLA8vM0SX+nGSw@mail.gmail.com Reported-by: Nolan Nicholson Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- drivers/hid/usbhid/hid-pidff.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index c518fcdeb6e8..b791e37e564c 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -926,6 +926,11 @@ static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude) static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { + if (!report) { + pr_debug("pidff_find_fields, null report\n"); + return -1; + } + int i, j, k, found; int return_value = 0; @@ -1050,6 +1055,11 @@ static int pidff_reports_ok(struct pidff_device *pidff) static struct hid_field *pidff_find_special_field(struct hid_report *report, int usage, int enforce_min) { + if (!report) { + pr_debug("pidff_find_special_field, null report\n"); + return NULL; + } + int i; for (i = 0; i < report->maxfield; i++) { From patchwork Wed Jan 29 21:29:33 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: 13954165 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DE8D1E9B2D; Wed, 29 Jan 2025 21:30:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186211; cv=none; b=WiRn4nutA0Z7jd2BiaekkkTDgA9AAsJAyylyhcHyNG7rTdI1aqqLXUa3vriGksOTglaznwKZSOeu1veqKFYdFJmrEoQ9lAVQW/k8mHe2Ll0X72qXpEBPOH3U/asO+QHmEmSKcF6y3indC8ZajHuVDI5H7DvupSmDLICWK9yDTuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186211; c=relaxed/simple; bh=y+8obkH0Eh3qwcw6Ctfs3SOHHpJV0mlLo6ifH1G2Llw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fd9WDMod2ZlhiaLWLRDQ3Zqw1z7O8UTCkTppFQzsQTg9BX0k2Ijg8obOEAbwxCXSnAI0iWvma2W4UM5v4EyxoQKRjAWOuX/xVV17EmgjuMZlCPM6+MvIRXfECL2e9IqNtikrIRK69TS2ajRsJCwBFEsHZcYIF3GgoQCXG/ENFFY= 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=PprMpKxH; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PprMpKxH" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-543e070cda6so14363e87.0; Wed, 29 Jan 2025 13:30:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186207; x=1738791007; 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=Yn5bRuRnrkNODA7opmd+9v1bidfHpg4rBmpMcyOxkZM=; b=PprMpKxHTieosJKvGJHdQVxElSy0C1fQFZbXsE77moY8Zstmt28+7VMZgrdEv8HhqW FheXzk+hbJ8zwvx7x1lv5f9GmkTNO8UGRaIBCNYTkZkZVAttTmAANDZEvwPoB6P6V5OT ckLpxBZmr6E3NdYQ5CfgDVFWjJdHwowWF7eSF5RVJJ49PhbY1gzXDKku+WNn6qQ9GWZo QjVs5x2HedhMs+WvJPx0zYy7JgYHoTyNMvFhCBi0brL1sJLThIOOjFmmQ4DnD0C7lpnm 28clEvWyIJwyKvnFkQ143Tr7s6ggG3TX9/M0KUIv7cYh0jMYD//8ZaQUE8lhrCIktydW wabQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186207; x=1738791007; 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=Yn5bRuRnrkNODA7opmd+9v1bidfHpg4rBmpMcyOxkZM=; b=Z44hQ2wGpCsfzs4/jytA/jw9WRTMcJhx1bmEjSZchP9DjSGmPqMZiO9Zr09Um2gNUA UsbO2+4/Jcgd+zZV8Xk7TfshRZ2w1z9MeCLM4KRoD6Y03Xp+yRQNsjub44nOCz08UaBo mR3mA+6mrOnmVX1PLVB77OEh6HCCAP1jLUEvd04DTba2zGQIsOvJObOoP9p33MtoiJIX qprRNXoKMF+h06kJkgmJh/c0xCRxiDefM7P1Q+FJmCRD9gX6jnhsmcrQqQZKG/D04eF5 f9nsMeLQW9229IzpHX3eJ24i/yjuOXfczsjGrM6br4YjGNZuj0hLSzJmliCpYKg/5v9d ussA== X-Forwarded-Encrypted: i=1; AJvYcCVC/jilANzFsV2sqd0WYsrFUlxIJFV95ATVGm2yd2LRg6tCkq8EzbSKFet8pPZ8Y9EccVqwoU4lTf+d@vger.kernel.org, AJvYcCVGdBnGNjsCCdr0cocpuy7lcJ3s6skcMnzRgsP9MG0SF3h0G1xxSKv0seWETUsTVRyoTzHp8yEcqC+ziQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yx2f2yKiNmSN8uDYI1OtIb1zZ4IzbSgbPvhnWcntbmwvc+wFI1l CvZOUwkrCIqkrl1WH6hxWOXaIJlsZz4J40r+Ts4ZeO5PzJEuikso X-Gm-Gg: ASbGncsqJo6tBdTjxDajRfCQTbLz7DS+Qp9t1M5INNlFoOkOQhMRUdaKeHK7mydtr81 10lK4rxlzybsAN8gIDkDHjnQE1gnNfK9S/G3c3CNSIiWiLHGlgsoJDdnC/XjMoYPzzQYrrI9bBb awlyaOGtrzGEf4vQoFUypRtEl96lUunlCRVl3IYhmdhU2KaK7uUTj7HAFlgw0Ltp1WJXqLy8zgu aQMsE+w9/jKmRSp8uUM7VVMAILys7R7obPL6KABOVfyUqMAFB74bc09GSnFou9ovV83u+RZKvKh x6iJO1Gv4tZQ6zD8JQixeIV4JeuSvUMcrqn4zMCwSyXWnMhzOCNTqTAfv3ifeg== X-Google-Smtp-Source: AGHT+IGEqLfNs4DpRAc5NOgxBx/SzHZXLyUHnCgN8XSrtCUliqkGF+pf5p3hGUbc6A8BG8WVQ9Cc/g== X-Received: by 2002:ac2:4f01:0:b0:542:9807:97b3 with SMTP id 2adb3069b0e04-543ea3f844dmr94016e87.4.1738186207293; Wed, 29 Jan 2025 13:30:07 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:06 -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 v8 19/21] HID: pidff: Move all hid-pidff definitions to a dedicated header Date: Wed, 29 Jan 2025 22:29:33 +0100 Message-ID: <20250129212935.780998-20-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not clutter hid includes with stuff not needed outside of the kernel. Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- drivers/hid/hid-universal-pidff.c | 3 ++- drivers/hid/usbhid/hid-core.c | 1 + drivers/hid/usbhid/hid-pidff.c | 3 ++- drivers/hid/usbhid/hid-pidff.h | 33 +++++++++++++++++++++++++++++++ include/linux/hid.h | 15 -------------- 5 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 drivers/hid/usbhid/hid-pidff.h diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c index 7ef5ab9146b1..1b713b741d19 100644 --- a/drivers/hid/hid-universal-pidff.c +++ b/drivers/hid/hid-universal-pidff.c @@ -13,6 +13,7 @@ #include #include #include "hid-ids.h" +#include "usbhid/hid-pidff.h" #define JOY_RANGE (BTN_DEAD - BTN_JOYSTICK + 1) @@ -89,7 +90,7 @@ static int universal_pidff_probe(struct hid_device *hdev, } /* Check if HID_PID support is enabled */ - int (*init_function)(struct hid_device *, __u32); + int (*init_function)(struct hid_device *, u32); init_function = hid_pidff_init_with_quirks; if (!init_function) { diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index a6eb6fe6130d..44c2351b870f 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -35,6 +35,7 @@ #include #include #include "usbhid.h" +#include "hid-pidff.h" /* * Version Information diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index b791e37e564c..cb044a239ab5 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include "hid-pidff.h" #include #include #include @@ -1383,7 +1384,7 @@ 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_with_quirks(struct hid_device *hid, __u32 initial_quirks) +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, diff --git a/drivers/hid/usbhid/hid-pidff.h b/drivers/hid/usbhid/hid-pidff.h new file mode 100644 index 000000000000..dda571e0a5bd --- /dev/null +++ b/drivers/hid/usbhid/hid-pidff.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __HID_PIDFF_H +#define __HID_PIDFF_H + +#include + +/* HID PIDFF quirks */ + +/* Delay field (0xA7) missing. Skip it during set effect report upload */ +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) + +/* Missing Paramter block offset (0x23). Skip it during SET_CONDITION + report upload */ +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) + +/* Initialise device control field even if logical_minimum != 1 */ +#define HID_PIDFF_QUIRK_PERMISSIVE_CONTROL BIT(2) + +/* Use fixed 0x4000 direction during SET_EFFECT report upload */ +#define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) + +/* Force all periodic effects to be uploaded as SINE */ +#define HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY BIT(4) + +#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 + +#endif diff --git a/include/linux/hid.h b/include/linux/hid.h index c6beb01ab00c..6d09b1763652 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1221,21 +1221,6 @@ unsigned long hid_lookup_quirk(const struct hid_device *hdev); int hid_quirks_init(char **quirks_param, __u16 bus, int count); 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 */ -#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 HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY BIT(4) - #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) #define hid_err(hid, fmt, ...) \ From patchwork Wed Jan 29 21:29:34 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: 13954166 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 997241E9B39; Wed, 29 Jan 2025 21:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186212; cv=none; b=kJz0dTMs66gKnLDQBZQFm/C8WOSmJFm6f2ReBAFU2F5V5ad2mFVk7tW+r75RciCGxQ15zM+3zEGH8OEYbwZngjlyCUaxmtXRiT9yk4eH4cXEmYvH/VekIc/qlRtPoEX6y62VL/fgBg3/9m87woKjWMBfbTXEBImre56nx/dLda8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186212; c=relaxed/simple; bh=nGlxgwNI+4XUAU76n2XwXoXNYdQEY+cofE9/d16VU1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V9zpxqPTO0YZo+mskU6QXKCLS2cJ5HBf9YXRg3jmPFvWrKC2DPOTE6R5BmjjviF3KCCz0jqnKoyKFP74ye4mdRFe0w7Wm11LQvZ0Uv5M9Yg6AV3+xL+AqHWXGynN+BhHi1wYGLwoeTbnjDDMt4r+G5b1CRSORxntTXEv0mrz4nw= 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=Oq9wWDnQ; arc=none smtp.client-ip=209.85.167.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="Oq9wWDnQ" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-542aae6ef6aso14905e87.3; Wed, 29 Jan 2025 13:30:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186209; x=1738791009; 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=arVVYQpYmE70vfH12qGw4QsMHoT6tNXR87uxBHDMgO8=; b=Oq9wWDnQuikEk1s2cfxgjRsZ8VkxSuhs3sqcs8EbD4vcseeb19SzI/sCdNnWPYoiRf O9TzqfjdZDSEV8Z0Yg0la3Jt5g5fRrWbojrB7PaDSwIAliqmynDob8fL3XOvvzD5ckKJ E/qSYK91/J3RPjoJsdb/SABAv4bC9vSNRLH9l1uZoxI8R/XPZAxksukMYLMsAy+1whkH aaGK4uTJoBKLkoTC/UKvWwhyaCf15gMPMspDy0PfjPIaqxGYtB+Hu0d9SIWxWk8FNBEV cnZKsfbcY3lfoGXFY55zeSdLoiL+XXqCP4gFXE0sFZn00ZmWq35/5Xa01NfypnWYB1jP lHOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186209; x=1738791009; 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=arVVYQpYmE70vfH12qGw4QsMHoT6tNXR87uxBHDMgO8=; b=vEKCWdoY8JWLtugeZQnMfQWoakk6AmS3hfyW5DgFeAHeOjVSpQYuT+CfyG3cvKhxGl T4B6O8eS9aCskDOpcSmSVn37XgAzxFJTf0H5VF93le9VGOECf4f8ApWdvIZVdLJPzqzA IXXQ+9MxhY7fTBVksqwwVOH0XDHNdAZecdl+5HFc9avPXsvlhH/zmQ2SPZiISXY/MbxQ 6mVc942OnfCLALYBPIWbkCTsqsuyoE8ogxCsw2MCSkV5r5jKtq7rspyYXUxILdIhCZ91 FIAXFqlt6kYUgoou25cZdKdwNp+Yq3OiwsjSIjIZhWPPSrUgdU6uLE04B4GHfYlOg+ci JWgQ== X-Forwarded-Encrypted: i=1; AJvYcCU4GZ4Zmpgu9xISvs9LbZL9ajS6w1P1bstTrAwp5XMzhOT5r38hd4MUkGAvVHhhn5wwGKhW9NLI6GOK@vger.kernel.org, AJvYcCVpKsLqUai7R11r02o11VpIZW0i5+bxs77aR8CD5Yd+NP59vjKv4Dq93mfvQ1JxzMYxH2BqzdeU5XD1OQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yw8HLaYk3g6sJbL93oyK91WKbs5vGH8m8jxWs4IYqWhAg5DBbvA l7DwP8nMm9NOj2cPKIr1nJwE1CO7ypitHbMP6SiqxyjRH2QEbwco X-Gm-Gg: ASbGncs7G81RpceLGzeY1kwKsj4DLVHz3QOQ//nRQo55S/lj50J9ivu1vd3P6Aj4PGH NBjuRTyz9tVPnHdZt9qBLcKKLkrlfsTg6vMRH6NvHfJkAClcJlnJXKaBG/0JGEITBGs50+IQAxf Vr9jlEcdSVqiXq3UExZGd6A1yZbOBXseblPgVTPDTmcNFgsVhwV3QSqo8vR66TXcbevA5XLB+1a 8NnkldHU6jVmNjNLxjwrlbvQYLLI40ZKtmifyaMl8/HV5RLHC9FV0QghBjqW0BrOOdoLGafBThy eQwKk+zOK/pWHylqWfZkLPEbVfwyL1hl6ojC95pTlqbm09Y2tKUK9Cjxiof7fw== X-Google-Smtp-Source: AGHT+IFbF1YsWBuWLxZpybTtRAuQfMh5MsuHyalzYid8Diwg11Re3So4mBLyNnJWRgbPEfjGL7yQ9A== X-Received: by 2002:a05:6512:130e:b0:542:9883:26e with SMTP id 2adb3069b0e04-543e4be967fmr560721e87.6.1738186208478; Wed, 29 Jan 2025 13:30:08 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:07 -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 v8 20/21] HID: pidff: Simplify pidff_rescale_signed Date: Wed, 29 Jan 2025 22:29:34 +0100 Message-ID: <20250129212935.780998-21-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function overrelies on ternary operators and makes it hard to parse it mentally. New version makes it very easy to understand. Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- drivers/hid/usbhid/hid-pidff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index cb044a239ab5..f478859682ad 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -230,9 +230,9 @@ static int pidff_rescale(int i, int max, struct hid_field *field) */ static int pidff_rescale_signed(int i, struct hid_field *field) { - return i == 0 ? 0 : i > - 0 ? i * field->logical_maximum / 0x7fff : i * - field->logical_minimum / -0x8000; + if (i > 0) return i * field->logical_maximum / 0x7fff; + if (i < 0) return i * field->logical_minimum / -0x8000; + return 0; } /* From patchwork Wed Jan 29 21:29:35 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: 13954167 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.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 0358F1E8837; Wed, 29 Jan 2025 21:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186213; cv=none; b=ltMbTTvTkRcdkgMGgyG47YOEUYZWruOsdMwICoG6frgb2f26pQMmfcxz2WQTrJj+PN5shlLiwmR2CwllixShDJTrTqavjSObrFTb4YwmRJpv56/BTbJTaFUiLbqVmpS8xJkKXePxRzyAah9+HIGkps7tjHZt5UHT0ToZuCL+Weo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738186213; c=relaxed/simple; bh=KYoulX0+pP4wf+LAn9laV9dVI2wRk7dBV0OdGBJcfRI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DbZjVezhAyal6tRmYpjbavwjdSQ8ItsSPVfsOQmrqXaKj3zR+VUx5fbwTKpG2rrSAEfxRRdNU8B8vn/OCzQeP9TETcpv2AMZ7PRnEq72NmGqKxjAgvhEvFPaqhfnjdwqXZu3LYKbwVU37KtMJBCmmvh+W9l6KhRcUZdVlgJy8ec= 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=EbYh+2FQ; arc=none smtp.client-ip=209.85.167.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="EbYh+2FQ" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-543e070cda6so14369e87.0; Wed, 29 Jan 2025 13:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738186210; x=1738791010; 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=1mihAfDvNPJNPt4/37fGLK1NIIAZsOCg7/uXaTRSIRs=; b=EbYh+2FQOn/LJF2uAl96ykjUBPL40gbIEaBmNI26xKN+7IEDwhGga/sSN1Y3UKtXi2 QgqaH/tkwtdPxsP8K7pLbZd/O8Nj0PYqnNIMXU4tUfwHVLHGn7mn87k79Aoj9GFEWhGo SaJBxri3fzMB5QE0Uhf+v7+gULEa/hTtFVlbCV91gDgvz6sEfHJsS+GvgwZQSPHy84z/ CIGSzEhKGXBccsJEfsM0WE3cuh9ky3/c1/ZXIl3z8skRPzqlnIlh7MN08ULwmhMKKJVt vI6nZTtTdDfaAnPc9VyNMg9osMkeNhGux/WjnuJETAnMCgrqoyAeBMl33yUArQDJ1mhJ G4Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738186210; x=1738791010; 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=1mihAfDvNPJNPt4/37fGLK1NIIAZsOCg7/uXaTRSIRs=; b=kJ1JVz29elVxIwm/TOwTlr4mhNIysa/EXGH6NqaGwM2zuQD83MJanNdykIItzsZajG 4qGMh0SCG4E7H9sl4fShqusJEC/NMxFvYphjntS8N5+WLmnYHn6EgjFQooCNmM5xupwA dTZ4ow3WHRp0u1klZ2e+n2GqLOdYU2D0EZk0/6Zy/jBGM/SKH/BMLX+wnhISJiu79pKi g3XSx0r6Dze47d5uSiOSn5Dp7DKzzQfvzgRlQmnW5Z5TkcVWIVPFN4iA/a+FkdyYue/P 4lOGi+O5vbjt3pW5EAVNUbtZ/GFiW/LHihZSLbydozFUj9AkM1KIF1GEru52mpaY/xFu 7A4Q== X-Forwarded-Encrypted: i=1; AJvYcCV+nPbZWnIKRw1sPX3y30f99M1Uv8fq0OYMTxPuC5Uj7u5MLGOCJBGBPh6yknn7ed36DjX1LJm/WR65fQ==@vger.kernel.org, AJvYcCVQYdzWRQ92uIwq59sFosJUcTOmhADjIoJ2YvX6F3QJbvPYogF5AzbxHBAShMuiqtJ/XKTvlThzbo50@vger.kernel.org X-Gm-Message-State: AOJu0YxL+WbEVa8WD+CwKKGzOoG/o+9LfIJV3H3WjIQiOCX2T+0U6wfX 7T2vOc17AVqvgqovet+SYEaHyEwgX7W/wJYvnt898J7QL6gGplEgCDvN7u+t X-Gm-Gg: ASbGnctfp+/93zT15LM1M2ar9PGd9eXw3NOLuc8IiUVs04SseSbMJ4rJjV+UEkdUBu8 oLMBO1QzYTAhCoTwjSoqDamIeRCyWmJ4jcmYicKGW5H48qk8aD9jZLx4MVOLLi5J6eBbwWQkb9l L5DQOsVZbMnW1x4sIV+cMB8poKNS2VuN5PpzLuubjbB/FyKAK5SaH2vmiAEiN0ISEhsxZkzlNhJ qhgNOw0PqQmNxv1XyElBugXkS26M/Trt4CVLBXR7LH6pqvoELgSo1dubcvjeCo/8iWGT2n0x6OG UBu3qZ+RAmaOacP2fMxX3xJAwA2Y4nEbLJoqJNMzErzBEolxsnm0zNSCfH5ZvQ== X-Google-Smtp-Source: AGHT+IE50LiBQHPUWZ2irtGbuI2jGpfNWcVYLFchhttIOzUZsQwW82oGOJA2BKQ8Elp+hqnwxpHVdw== X-Received: by 2002:a05:6512:3041:b0:542:2990:6e9a with SMTP id 2adb3069b0e04-543ea824592mr67958e87.12.1738186209789; Wed, 29 Jan 2025 13:30:09 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83799c0sm2100778e87.190.2025.01.29.13.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 13:30:09 -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 v8 21/21] HID: pidff: Use macros instead of hardcoded min/max values for shorts Date: Wed, 29 Jan 2025 22:29:35 +0100 Message-ID: <20250129212935.780998-22-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> References: <20250129212935.780998-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Makes it obvious these magic values ARE in fact derived from min and max values for s16 and u16 Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Tested-by: Cristóferson Bueno --- drivers/hid/usbhid/hid-pidff.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index f478859682ad..a223557de099 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -21,7 +21,7 @@ #define PID_EFFECTS_MAX 64 -#define PID_INFINITE 0xffff +#define PID_INFINITE U16_MAX /* Linux Force Feedback API uses miliseconds as time unit */ #define FF_TIME_EXPONENT -3 @@ -226,12 +226,12 @@ static int pidff_rescale(int i, int max, struct hid_field *field) } /* - * Scale a signed value in range -0x8000..0x7fff for the given field + * Scale a signed value in range S16_MIN..S16_MAX for the given field */ static int pidff_rescale_signed(int i, struct hid_field *field) { - if (i > 0) return i * field->logical_maximum / 0x7fff; - if (i < 0) return i * field->logical_minimum / -0x8000; + if (i > 0) return i * field->logical_maximum / S16_MAX; + if (i < 0) return i * field->logical_minimum / S16_MIN; return 0; } @@ -255,7 +255,7 @@ static u32 pidff_rescale_time(u16 time, struct hid_field *field) static void pidff_set(struct pidff_usage *usage, u16 value) { - usage->value[0] = pidff_rescale(value, 0xffff, usage->field); + usage->value[0] = pidff_rescale(value, U16_MAX, usage->field); pr_debug("calculated from %d to %d\n", value, usage->value[0]); } @@ -266,10 +266,10 @@ static void pidff_set_signed(struct pidff_usage *usage, s16 value) else { if (value < 0) usage->value[0] = - pidff_rescale(-value, 0x8000, usage->field); + pidff_rescale(-value, -S16_MIN, usage->field); else usage->value[0] = - pidff_rescale(value, 0x7fff, usage->field); + pidff_rescale(value, S16_MAX, usage->field); } pr_debug("calculated from %d to %d\n", value, usage->value[0]); } @@ -306,11 +306,11 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, pidff->set_envelope[PID_ATTACK_LEVEL].value[0] = pidff_rescale(envelope->attack_level > - 0x7fff ? 0x7fff : envelope->attack_level, 0x7fff, + S16_MAX ? S16_MAX : envelope->attack_level, S16_MAX, pidff->set_envelope[PID_ATTACK_LEVEL].field); pidff->set_envelope[PID_FADE_LEVEL].value[0] = pidff_rescale(envelope->fade_level > - 0x7fff ? 0x7fff : envelope->fade_level, 0x7fff, + S16_MAX ? S16_MAX : envelope->fade_level, S16_MAX, pidff->set_envelope[PID_FADE_LEVEL].field); pidff_set_time(&pidff->set_envelope[PID_ATTACK_TIME], @@ -399,7 +399,7 @@ static void pidff_set_effect_report(struct pidff_device *pidff, 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); + U16_MAX, pidff->effect_direction); /* Omit setting delay field if it's missing */ if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) @@ -1366,7 +1366,7 @@ static int pidff_check_autocenter(struct pidff_device *pidff, if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] == pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) { - pidff_autocenter(pidff, 0xffff); + pidff_autocenter(pidff, U16_MAX); set_bit(FF_AUTOCENTER, dev->ffbit); } else { hid_notice(pidff->hid, @@ -1424,7 +1424,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, u32 initial_quirks) if (error) goto fail; - pidff_set_gain_report(pidff, 0xffff); + pidff_set_gain_report(pidff, U16_MAX); error = pidff_check_autocenter(pidff, dev); if (error) goto fail;