From patchwork Sat Jan 25 12:54: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: 13950359 X-Patchwork-Delegate: jikos@jikos.cz 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 C9E271FC7C3; Sat, 25 Jan 2025 12:54:47 +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=1737809689; cv=none; b=OfzcPTBHfXmNBW9zR8B0d77B3SqXhaOfN5dxYhYqjfgM+zUwU2o1yOyAZQ2POQ9ooZR4lkka2Uz7AWOHyhXd7EgV6gfVsWtO7d4J6BFKA7o4YUDeyUrBKP9XLYAeZHLY72xowrq/fBaFEq8esINeZt4lgu4ngSJEDxEbLxzizn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809689; c=relaxed/simple; bh=DhKOlDN0J91JsCofHQMVQCBR/3u/HEqZUulpq4EyNyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o16RHTEewUfy3L3pFp7ijMekc/Bu2zPyzNMr4jG8nO6GK9P8reckzbkXi79mBLBWf+veNpGFDSnOwuvEjLeqVFivro3rKttXqJHIvAZIozR1+RJa1/XpVmgpszzB1w6pmb5bK7BrjFRQnhk4uqThspbyQtgbTCuUjDMvHXdlFDw= 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=FU8vLbbL; 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="FU8vLbbL" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-542aae6ef6aso500079e87.3; Sat, 25 Jan 2025 04:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809686; x=1738414486; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ssFFA6NC5w0PkH/hxlG/5x9jpkiDdQm3Ywo45Mto8CY=; b=FU8vLbbLAzQq1xIgsRaVHajfeMcA+/buFGIb7+xsbkXcQYJ0PJte7rSn3EYekpnAsx G0V8qYr7nyL9QZvILXsuAI/9JCvlerpU8Tl6Ki8GgoRCzC1EkuP4qwP6oEMsuOH1v1Gf JJpWWVe5dQP2TB9rXjiy0c8gX9yxPVySIByGBLhOZ+E3igLUvsqECUMMDR0kWD3OURjU a71j/7t14cG2PlnMDWuCUKqcBU+AvVDzif34CX/5EgRCGlnG28wc5DxQpdtfL0O6ZDlH wbogZm05MoF/hDokD3L/9NdLG4VaOcmULypd6wqbmFbGNNU8T6XyiGU+AATvOGu8lTpB wgBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809686; x=1738414486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ssFFA6NC5w0PkH/hxlG/5x9jpkiDdQm3Ywo45Mto8CY=; b=ORDI42hx3rhCNMSwlvURqX4sS4yXdl1KVByM7+OHE1LsnKDiksK8zp4d2GloCU4X0s t+BZNJzrLLNVJLxCd6Cxy2gfBaCTNSuzodsF6hocRDe4cisV9i8qbcaMSVdaaGOwx88N 0D5nj3Elj+53cvQEOGyGQuIqTPru6cxZJCdfLhXkkT6jTao/7XmEQ3WnLOVJcAhWlcfn PEpFrJbL6Ji7uKKEjIcfd8AZ8CDZgJcTRZyA4q3inlPm8J2Xu6VkFGZLp4xXHxdWHNiZ CQUwL00Kbdgota09YypCiv6dNHU53laKYbu8oGvZ+p12+JH7k3zfVnvSBy6MKuPmk4wR vzIQ== X-Forwarded-Encrypted: i=1; AJvYcCVMhtFj2G4Q//msjRbTvU7a2Jwfc4O6W5AWoqTT8PTGTgY9Umnd4WQThqUr0RZ7REqfY9TR5cSyBjJkEQ==@vger.kernel.org, AJvYcCWK6iOX04h+Amg+J4YeI7s3hTvpYHGwU364+pyXimDEi1jpdntvzfY25VWi9xxh1Z6+2lmpRicctAGb@vger.kernel.org X-Gm-Message-State: AOJu0Yx0xAPxRkX8YOJ3zkBPV8KOhJtv3tozvvjTu0tBitMI4/tMxdtb lfTCv4KjB4Ei/9IbcsqzUW/pwIYCvUNLi0OG/97NLAWqoWtvMkBH X-Gm-Gg: ASbGncvSod7Id6HF/Vxo35HtBG/nAt1Wne4Wa4uxXEkRKRs9SUMr26cNYnLbf0Kzfi+ Fk/1jUeYE3IIVDVlEG78glKqeGwpJo4TTAR37Ijmf7dEJkk7zpMzCtRCPKPiruLgS6lTNJvKLW8 sHUB+40JOGXwj5MdHWmfu0eE7qNnWFr5WME1vGpRIxsDoSzUW0vO7JIKgYwGKP2dfSup0v/fEGz 919Rxy6hcj19mWumvKzlDFWse0LTCTobdfVUoaD6HmwQjJS+HfQ7+pHlu0lr8FC1V5vFzd3nSHz S1xSGC4r//lKkrimDe8W0s1p/f8jHaz6tEGt5ETAQWJX47SBDpI= X-Google-Smtp-Source: AGHT+IEmmvinTd5+6J9LDBzAgz82mIJ1VN6rMVsYWP7sIh1TdGPufRzM4/GIveS+P8DHRkFGbAcoGg== X-Received: by 2002:a05:651c:b29:b0:300:17a3:7ae1 with SMTP id 38308e7fff4ca-3072cb3d847mr42345571fa.9.1737809685723; Sat, 25 Jan 2025 04:54:45 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54:44 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v6 01/17] HID: pidff: Convert infinite length from Linux API to PID standard Date: Sat, 25 Jan 2025 13:54:23 +0100 Message-ID: <20250125125439.1428460-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux defines 0 length as infinite in its force feedback API while USB PID defines NULL (0xffff). Most PID devices do not expect a 0-length effect and can't interpret it as infinite. This change fixes Force Feedback for most PID compliant devices. As most games depend on updating the values of already playing infinite effects, this is crucial to ensure they will actually work. Previously, users had to rely on third-party software to do this conversion and make their PID devices usable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3b4ee21cd811..5fe4422bb5ba 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -21,6 +21,7 @@ #include "usbhid.h" #define PID_EFFECTS_MAX 64 +#define PID_INFINITE 0xffff /* Report usage table used to put reports into an array */ @@ -301,7 +302,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; pidff->set_effect_type->value[0] = pidff->create_new_effect_type->value[0]; - pidff->set_effect[PID_DURATION].value[0] = effect->replay.length; + + /* Convert infinite length from Linux API (0) + to PID standard (NULL) if needed */ + pidff->set_effect[PID_DURATION].value[0] = + effect->replay.length == 0 ? PID_INFINITE : effect->replay.length; + pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button; pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = effect->trigger.interval; From patchwork Sat Jan 25 12:54: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: 13950360 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 6C1F51E505; Sat, 25 Jan 2025 12:54:49 +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=1737809691; cv=none; b=tveLNUmB2BVQWdzW4gTtAoBiM2HKg15jno7I6qM8fFBZTHQNQi6VGGHMgKOiq7cwOdvBBDLhy3djop1S30piVPYA9amMyI1Qla+yYgYmNKqlveYaoWdC/TAMEs7exfZfEkQZMHZbFYY3dgpppKMWQxmY8Xav+8IQrwb/R/vs+Mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809691; c=relaxed/simple; bh=wrRItE2ic9yO01lxSjZ9vLP2VpN3f7PJWhO595t/Rq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B3KsWxUGQaPzil9yzzzjBPtQGNKRAqIPK3Amzp08gH9F5DKSSD12NZAmZnggvbqoZ64CdA9zJq5TY3+UkU4VeaIHPuvz5/M3192rgAzZq+lJ89Eqsu1yiwCCDdZTjYknDW0A+fHJSw1u1628Mx7dh4mgxIVcixgKvLwzEdg+IQ4= 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=WqYJxIx2; 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="WqYJxIx2" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5401c2bb7ccso299312e87.0; Sat, 25 Jan 2025 04:54:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809687; x=1738414487; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BiBNwqEUd/4ZH7tEeMX6WGp4FpHjqtvRbtcFv1yfMq4=; b=WqYJxIx2H+lXeKyBVhNQ5goMkXym37LlJHQfSF7jC7A9T/CYyfD6SDsDk7iCG/ady9 SyOIRJCqWvskQu+UERy7/F55//QOveqrSMnw1pVuoQN4aOfuRH5sKpjuC+4qM4vo3p/b wZZQB5BQg3zNth9pLaYic3mIt45GfmBuzsZbTLobPhOB1TsfH9nSMg/zhLk9JbvsmMle GkVvmNnmuYnEfiFE2pW7LW416DHcm2pJYcajbyM9KXVcpCvTufaI3lTCEIXAX7yqNJIc rLBkLKKZDr3pB+yLhy/7T3XLzj0mDc37XK5yYt/gAfpV5ojnIY1u4NOQ+ZID4y4qOsEF ISAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809687; x=1738414487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BiBNwqEUd/4ZH7tEeMX6WGp4FpHjqtvRbtcFv1yfMq4=; b=DKDEe9b0F1ZDIZkhCl+3jUbK4q1M6szSa2A8fLZj5FJYLKcVPLTS/OmaBfTsY9BioS rZ0Va/qrr5u6LAHhDfapYl1PU4yW/p4emwKsbkPZaPVpmFQXjLVlb6GgWFU22grnsruX UXsDlSrDzYNFEiklEEpKWaI1zSuYKPkgFU2z54UcF6RpB6B+Fu/4//ql0x6y6pRfWgwC g0QAbalkdsEuPAwZGqpz6vsC+CUdoZVCm6T4MgncvVK1hqRHJG2HNOE3/9rCNryocjMp 85eWBuOdQR4ywLUP8YZFK9UpyAyTObhm/biHGDyTITiNf6HKukoiQKRmjgFNZzpjPMEa g6ig== X-Forwarded-Encrypted: i=1; AJvYcCVMRczdCWvS5Mktw0qm4n3qGk6Mh/wSGm9BwpLBnQJCz7ipTSxa3iqHge5ra27qHK9c4Z8/Hdo/dBNijg==@vger.kernel.org, AJvYcCWIsjSF8IRyLDPxU3V9tEYA13B7smYQAimawAn3jdGKjr7dodOEmy+RTFbnsLeZ2PWlk5PewOUQSfke@vger.kernel.org X-Gm-Message-State: AOJu0Yy92yowp+tyky7NLVWY8V9qgXf7q+tv4YF3o2j+UNg84vzfwC0Q eikEhnD1ah8Umb+PHmp26GEN8jq8lAuENxL+XT6/IlFPqG5Xx6AA X-Gm-Gg: ASbGncu93vAifu929scQoWXqWbsGNWlge3/KBBVQsOhAOmEHvMO61Gxrgm1RUbESDf1 Xq//P6DFxzuvoE7EdMQheq2PRt4GKMyZgTTQOdOivDasEFAB/NW6HOHjx5KquFMM5VLvDkNTKSL AHC9CI54F5CtirDLVyWViyJCbBveOd3yj+UIkNDuEuK2hIQmn+INsBo3QV2DH+sohTaz0hYlcE4 o6e4G9mfbroa+UBl85lqaI7FPHYtXNQwzNFkpaWnK9p0+qJK2tF8hwQ60Sjp0lOSklu0zbXymK0 q3QgQNLoyNSpDnk1AHeAwERNEEbaa6pAwgxZLUQmG8lKxCZPzs0= X-Google-Smtp-Source: AGHT+IE3kKnSlD7WZ7EN+SZDMu5u7vKGxudVawtnuBJYVktNrW9GJCCRPHrGKd1cHNtoXvCgLaB2+Q== X-Received: by 2002:a2e:bc24:0:b0:302:1c90:58e0 with SMTP id 38308e7fff4ca-3072ca51eeemr44493171fa.1.1737809687241; Sat, 25 Jan 2025 04:54: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 02/17] HID: pidff: Do not send effect envelope if it's empty Date: Sat, 25 Jan 2025 13:54:24 +0100 Message-ID: <20250125125439.1428460-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 5fe4422bb5ba..a01c1b2ab2f4 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -262,10 +262,22 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, static int pidff_needs_set_envelope(struct ff_envelope *envelope, struct ff_envelope *old) { - return envelope->attack_level != old->attack_level || - envelope->fade_level != old->fade_level || + bool needs_new_envelope; + needs_new_envelope = envelope->attack_level != 0 || + envelope->fade_level != 0 || + envelope->attack_length != 0 || + envelope->fade_length != 0; + + if (!needs_new_envelope) + return false; + + if (!old) + return needs_new_envelope; + + return envelope->attack_level != old->attack_level || + envelope->fade_level != old->fade_level || envelope->attack_length != old->attack_length || - envelope->fade_length != old->fade_length; + envelope->fade_length != old->fade_length; } /* @@ -580,11 +592,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_constant(effect, old)) pidff_set_constant_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.constant.envelope, - &old->u.constant.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.constant.envelope); + if (pidff_needs_set_envelope(&effect->u.constant.envelope, + old ? &old->u.constant.envelope : NULL)) + pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; case FF_PERIODIC: @@ -619,11 +629,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_periodic(effect, old)) pidff_set_periodic_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.periodic.envelope, - &old->u.periodic.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.periodic.envelope); + if (pidff_needs_set_envelope(&effect->u.periodic.envelope, + old ? &old->u.periodic.envelope : NULL)) + pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; case FF_RAMP: @@ -637,11 +645,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_ramp(effect, old)) pidff_set_ramp_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.ramp.envelope, - &old->u.ramp.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.ramp.envelope); + if (pidff_needs_set_envelope(&effect->u.ramp.envelope, + old ? &old->u.ramp.envelope : NULL)) + pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; case FF_SPRING: From patchwork Sat Jan 25 12:54: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: 13950361 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 DC22A1FC7C3; Sat, 25 Jan 2025 12:54:50 +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=1737809692; cv=none; b=i5jaLZk7hlFb6q/+S6cljtf9SeKM4AXpq7WTas4wZtBmpXASCCyvP0+RUDZ9g9OQ39KrPAYlveE0bKFyLiJR4FBhiEwnwRnD+mN3Msnwl/e/4cp5+eA25UzTVyuqtf+2rcWh63w/TsVepS6JswnMYmJZdFt6PK9tLHNrtHp9FuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809692; c=relaxed/simple; bh=CGtZyHW/IhLJ8G2ImtmjQ9/dyeUyd5xFN1CHprzhZSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g0aUCCHFBuhV1v0cvtlOsRA7fr6zqMEESVHQqm+a/W0fqaprOxZ7o/iIMMrdZwCjl1u51CzwHU6eBDAMsF5wtPhx1NMJdgkhnj8TIkcZ91oyGD2ZpY1lY8lgvqOTfQvcFPx1eIegUki4A6LzT2DvrsLugyQKhozb+UgeVZG7mf8= 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=Tde4p20h; 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="Tde4p20h" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5402ec870b4so448672e87.2; Sat, 25 Jan 2025 04:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809689; x=1738414489; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bCzGE/w6ShAbewfgFQBX/+PHxEYx9n5v+vKkrVVffh0=; b=Tde4p20hKa3rJ5/rlitECbemb6x7EPziFgRuxl+lR6YcilK8hnfvb1V+6w1DDgB1HN Rrs4PDlKPViGe46aS4gC+BNTpIyvcqgj20VfZUR0VCga1CuotKCVPcAIGGmm+FXyJnli lH4AK5h5jnHSjEUIkT3dEf/SZRkIvUXWdS//UKjmHrc6JdNc0vHKO3DfVYe9Vg2Ay7/4 ZJ1aeMLZjSLD8hbWeGHlZQcDyT+YqjCGIZzxCSAVz3/0U5hckLA1IhKzhVJcsKYGtSb2 JH2WtM3Rh1R5/4S+F0kCfdSS/TYNGd8vxU/6alrepXqpuLakuMn8rA0UAGE53w0LRWnS kTvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809689; x=1738414489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bCzGE/w6ShAbewfgFQBX/+PHxEYx9n5v+vKkrVVffh0=; b=tEnScOQA4j3bnZqfQRPwJAUgrdC3dGSg1nSnouFVVf8nwBr1+B+FyfJ72ONbj/Hl9F NhmhSB7Vy/kM89kIbRSMdpAtGoPlZJ07EiQsxIltBJO2ueRMsxqDssebsRllN4sA68hu Ak249JCZ5CAJGFK57dyixLpVVbUU0hlsadT42Icn4I72F4jxwM067cSacWQF4CpJAG23 ZyYffOPMYbzfks2/bfh8svDPTZCKml2x2bgFnXTM0DwlEYRk4FRHnQ1y+wEmNeS58+u8 iaikrVBsjxzxeOkBXgnozbme3FDadjEtEp27kIQVQraFld68EuyfLX29aKrTiSxBPnEV srfQ== X-Forwarded-Encrypted: i=1; AJvYcCWfP3FQpsATkva1yXoc9L5lVJaSSNw3WzaF9+mjQ0jl/EUccDhNrr5dyU3EnyMIECCl1gZRgXAHM7tS@vger.kernel.org, AJvYcCXWb8yfhu4GvVathzaEYMeRVq637E5CrzZ+FDp/mYt5xKD1bsFknfSJ4nUtKjUnwGtsSsn4tOL5+lhvEQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yw2pd5+/nI8Cc4EeAAM3wilxxQFonlpOe80hwpC5LPuBUdtt+fd j6HHH6m8eCOJC48Nvk52F68EGhXbQMW0kv2hT0seHrAh1Ge5t4Zg X-Gm-Gg: ASbGncsnk8ieqWQ2HEogJptTLZrY4q5Y7doxcfZk4ytRdCIstdyGR5cRbos4vEfbp3i fQOQe+8P5Pf3BUHTp0i6sGFcOFZqRHVAtQ979fK2vIlrCaGXJztvYTSpRG5imttU09GzLVAqcsh 4/MRj4kWDqHhh7WncjuP30M+g4Udpz0Q+aDqPVgM+HAbn/jniz+xkbzDw/HEEDO2cn5PUSXr7UL LvJ1zO+nijjvxTYpWc7ubFM7LWXH6+61c685jSpyzPXeSl/b6FKvQLwyQqAYQb8DqSZpY+GeBD+ p2RMYVeklNjB6hGvKtllg0rXD7SAFqghXxGr0ZY8juXqUrHgDXY= X-Google-Smtp-Source: AGHT+IES/XqkiZAvgr50W6ol6h96HAO7MQJCF76mAJ88Kge6M/63Hh2Z+KFvHbqLo3uxRsf3Bx2RgQ== X-Received: by 2002:a2e:a9a4:0:b0:300:29ed:b7c1 with SMTP id 38308e7fff4ca-307587aa08emr22700041fa.7.1737809688715; Sat, 25 Jan 2025 04:54:48 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 03/17] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Sat, 25 Jan 2025 13:54:25 +0100 Message-ID: <20250125125439.1428460-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index a01c1b2ab2f4..488e6a6a14a6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -15,10 +15,9 @@ #include #include #include - #include +#include -#include "usbhid.h" #define PID_EFFECTS_MAX 64 #define PID_INFINITE 0xffff @@ -187,6 +186,16 @@ struct pidff_device { int pid_id[PID_EFFECTS_MAX]; }; +/* + * Clamp value for a given field + */ +static s32 pidff_clamp(s32 i, struct hid_field *field) +{ + s32 clamped = clamp(i, field->logical_minimum, field->logical_maximum); + pr_debug("clamped from %d to %d", i, clamped); + return clamped; +} + /* * Scale an unsigned value with range 0..max for the given field */ @@ -361,7 +370,11 @@ static void pidff_set_periodic_report(struct pidff_device *pidff, pidff_set_signed(&pidff->set_periodic[PID_OFFSET], effect->u.periodic.offset); pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); - pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period; + + /* Clamp period to ensure the device can play the effect */ + pidff->set_periodic[PID_PERIOD].value[0] = + pidff_clamp(effect->u.periodic.period, + pidff->set_periodic[PID_PERIOD].field); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], HID_REQ_SET_REPORT); From patchwork Sat Jan 25 12:54: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: 13950362 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 748221E505; Sat, 25 Jan 2025 12:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809694; cv=none; b=a6Ed/N3gNPeSkvpSqdukw/bjpiCaFFLzXlnfRQKC5h7UVGOMLki8WDOLafr0QPDDBQZR3fm+6+bPU5HOCewoBI0g5GVG4WCQ0HaNg6j2pvaIQezpuSCQmq6uQ9sFCd6Ih3AeKy7Eyn8lY76i+HJHdrQqIhkaLz5ZNmylZIi2q3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809694; c=relaxed/simple; bh=r2HpBPQDjRrVyhEvSIOGQAE936KzKNRVsJ73B7MzFOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IBAbRiU/TT3I5Jwn/LAUneoyOL/C818iAxy4LEZlq/Thx5BL5v6rBAmABzALCeBH93FlObakrprO4pvT0lvODtZAKn4w/yRResmBDsi3S8SG1qGHtq1s2Pf9LDCDR5UANN3FcEFexeGvzmobPn0OPYFfuqoLKPZ00DhZN9Lw9nI= 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=SEFQizv7; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SEFQizv7" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3021ab1f26cso2006761fa.0; Sat, 25 Jan 2025 04:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809690; x=1738414490; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CQvhEKzM5pHRizGyFJEW6UlDPPbtCBt3Q8hUG+OtEJw=; b=SEFQizv7/u0k2AEkvTjtzZINtd+GkqrPd2kVrnAI2aGlRdOe3dc3u9c0Kx94J4dpZZ eswIa8KvFV2Ff3X8Z3cXRyYrGWCU3sH8b01l9hGVfNX9mutEM85EiC+Zmd4MGqLk1xP+ X1msIyNU/5e0Z1Ov/yqfiqUXVwbQ1G9e910spNHy68YnK6D9GVkexMv/n8d9CG4CumOH lLBsBsRR/PapUN3382vRMOakkD8S0toWr3DqjATCmTurNGMAf3PIssWzadps6msKobuJ 3Z4pVQolF6uX6bC20nzwVFVYwEl/k4olKf5HY/qsfzWQ6SL/0QhA+3UqsGxnHkWRTQKO fX0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809690; x=1738414490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CQvhEKzM5pHRizGyFJEW6UlDPPbtCBt3Q8hUG+OtEJw=; b=agQN/TJ77u1r9WM0NXYhS82i4QfBbeXrlGhqni6/uVh4KBozdKzRQIcgKIvbZuIcOj v5aMWy8rEwPV/kYPYKREBOwWkWmf+xCM8gDy5ZEEPbPcjr3OjwffOHacFqR2YY2pVTg2 24pZoiYs5qSzZ23cT4/A1ZnZ9Lyk/P5kJ8EZrGA1yL9SSPrumxhLFuI+y4INUvFFTb1B qX8kCc4YlNlhpKYmv6buU3bdg3Y+A3kNx8Ioab/Da8qrlH++Xe3q0IOVcE/WZlCwVIPY tV9ys35oIqVHVIFWFuwhn4FqdLeFMrX/g01vvrjzSO1Cd5Kbi7TjUWjUX2BkZGKzGCsc tR/w== X-Forwarded-Encrypted: i=1; AJvYcCW5gt/rg3m+8haxlTO/zcRZ93qDphfEwLUxY5WNsPtEb7FIhImWwPoaPAZN9wd5vdRtQMQTIYyROKAE@vger.kernel.org, AJvYcCWtRUhqT6O22efbEm4lZHXe3gdey8saxyOsgfKUULFA34yHVRXU59JMJ5TQGZuE2IPhlvUTG378BMakjg==@vger.kernel.org X-Gm-Message-State: AOJu0Yz/a65TuOjBVp2qqkxUKlFYxUPNfk52XVOG5mXhxV3QVRvN0cVA 7l5hn0XOoQXk3zNQof4q9fuJoWLehT26SCIL7qzkV0ie0rgbYiiK X-Gm-Gg: ASbGncuilaESF4NWAF8kh6TJ6WzcJtC3f1/p0dhejQq7wPXL+w0azPXZGGeDrY1X7MO w4slRJEA9AVMF7eRsBa9DO9/tGiGMyzA4MaMBLjWnSuUPmD6iDhQGi6xk1a/PpogKV/dmBoProi +QulsnrGXQGUljV+Qo5mgVBt5/sN/xndNQAJeYjLFCYgRnkluA9Vv+Dyw5Q1dK+EMKPe0VcZiNn 8WsMS3P7Ot82KG2vRr5XRRCdlp0gDYKuK9mtcNE/YAXg/Xqo0tZQpn7D5pmyQIbw8VtV0AEC6E1 3bhHo3bwhKYtcl6eEmUCswAvIe4vLCaX+rkx9RcwxWR2dLlwZeE= X-Google-Smtp-Source: AGHT+IFxXxWLTmJMl3yyw9GfhOmcN9rLTyjr0bqwbqqJw6IW3o16bLH704e3BwXHv5sTBGhrTxXdfw== X-Received: by 2002:a05:651c:501:b0:302:2bd8:2685 with SMTP id 38308e7fff4ca-3072cb3cf6dmr42950671fa.8.1737809690406; Sat, 25 Jan 2025 04:54: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 04/17] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Sat, 25 Jan 2025 13:54:26 +0100 Message-ID: <20250125125439.1428460-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 33 ++++++++++++++++++++++++++++----- include/linux/hid.h | 3 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 488e6a6a14a6..e2e431dec936 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -184,6 +184,8 @@ struct pidff_device { int operation_id[sizeof(pidff_effect_operation_status)]; int pid_id[PID_EFFECTS_MAX]; + + u32 quirks; }; /* @@ -338,7 +340,10 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->effect_direction->value[0] = pidff_rescale(effect->direction, 0xffff, pidff->effect_direction); - pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; + + /* Omit setting delay field if it's missing */ + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -761,7 +766,10 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0; pidff_set(&pidff->set_effect[PID_GAIN], magnitude); pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->set_effect[PID_START_DELAY].value[0] = 0; + + /* Omit setting delay field if it's missing */ + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = 0; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -784,6 +792,7 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { int i, j, k, found; + int return_value = 0; for (k = 0; k < count; k++) { found = 0; @@ -808,12 +817,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, if (found) break; } - if (!found && strict) { + if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) { + pr_debug("Delay field not found, but that's OK\n"); + pr_debug("Setting MISSING_DELAY quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; + } + else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; } } - return 0; + return return_value; } /* @@ -1088,11 +1102,19 @@ static int pidff_find_effects(struct pidff_device *pidff, static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { int envelope_ok = 0; + int status = 0; - if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { + /* Save info about the device not having the DELAY ffb field. */ + status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1); + if (status == -1) { hid_err(pidff->hid, "unknown set_effect report layout\n"); return -ENODEV; } + pidff->quirks |= status; + + if (status & HID_PIDFF_QUIRK_MISSING_DELAY) + hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n"); + PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { @@ -1336,6 +1358,7 @@ int hid_pidff_init(struct hid_device *hid) ff->playback = pidff_playback; hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula \n"); + hid_dbg(dev, "Active quirks mask: 0x%x\n", pidff->quirks); hid_device_io_stop(hid); diff --git a/include/linux/hid.h b/include/linux/hid.h index d11e9c9a5f15..94ad5a510639 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1227,6 +1227,9 @@ int hid_pidff_init(struct hid_device *hid); #define hid_pidff_init NULL #endif +/* HID PIDFF quirks */ +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) + #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) #define hid_err(hid, fmt, ...) \ From patchwork Sat Jan 25 12:54: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: 13950363 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 F3BA51FC7C3; Sat, 25 Jan 2025 12:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809695; cv=none; b=Ki8Uv+yY1xXXHlhiCEinshPewZcvHTDzlsFv2/5PThYxU6ZbqklCEJSJwfXc7q8Gs1MUMRoCkxk4NgtiH7zx1hRNSldrmxhn+pU7/RNpx2expgmf8eYyByXnBp0c01s++FesLvYE24i1ipJU7PrrncPYZX6wxBiXwyDhIgFovek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809695; c=relaxed/simple; bh=8GmzhpaMxYiy8UkJ/MzDUSAv38faldGoZ9y5VIJO0dk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jAb7UcdBVnWIFvNK/X6WIIlfBWnQug8LVaBtZra6AJUbJx2VM7aQnHjWMIfaCurt/4sMHBNN/fGQvH3jGyaTsxTxSbtjkrxjEqfyXY0ncAQotuImcDykv1HzXv4+ruzwtNkGrPtoCCPpnGrLQafJs0oLHQVPmZeuPEvp5OVpsE8= 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=DHTl0F2o; arc=none smtp.client-ip=209.85.208.178 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="DHTl0F2o" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-30600722804so1776201fa.1; Sat, 25 Jan 2025 04:54:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809692; x=1738414492; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LxiAHTud/zEPLuazvDKVn1LXHelcgSwsXbJXagSiwyo=; b=DHTl0F2o2Bc+d+XPQIC6cHeDvw6f9baccyI8eFumXKa08IznoHOuxYJaXzSaCmMU// yFJtgmLjBtoZQzBSRIBZSYldhRMygDwSddzayz5GBo7TYmyVWrARdpVOwVTqLkRGi0Go abGRHFAkgxy7GutlM6UeZZk1NsBc2nT/yZcSQQmg5rW/2/LQGCOe9B+TbfKCY3l+mp5j WoYV7+xMTsSvq0yATgyQSNm923pbGknepAkn8HXSdooxWY0szE48dcVFMwLQkrdqVEtJ +jZOTSxqAbM/znQrzz4KNfRTFbG1N2ov6d9C65V+hbn/WDpJ2a2a6CKfn2IJ5AUeEf3i OreA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809692; x=1738414492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LxiAHTud/zEPLuazvDKVn1LXHelcgSwsXbJXagSiwyo=; b=SLR7M9CmXMM9LkRZsT4uC6oVaskXSsfNgoIWVxEL7YQRjr7q9b8IE2rE0ynw2siRT5 hmdfvM71aI/MS/cRuH/JF9wn2qhEF9Tss7qMfs3g+bLisJWRn2cqXg/YEFt4ZVq9UfDJ 6bg/6ulGenVYLIAh4+dOYX+n+Ip3ZXJnYB8mLiqmBDaWWibQ7Ll2zjVK5BcJDobSLWKd HlxO09msqdeDyJjDBFDO0tnyYoZ48lk+09deDX3TqLveSYkkfCwUQtorIfyW9zoe+fl/ KgBIBrOksH/ffeDizSnrZdeeOK8SkY0N0LjjG7z1l0ymDUkJa28rhemZxVhUWYUtiDom O1Eg== X-Forwarded-Encrypted: i=1; AJvYcCUeUqn6h8uK+Az6vi3w9fH8MB8+4+hYjrkp7uWnkbkk3MSXqDBf8PWO0vJbzYRUsyeprUYlk3NRMboeeQ==@vger.kernel.org, AJvYcCV77XqnapeGgBm+/OjVsYNm/BzQVJWMeGiQQ1908AOEUosCLM7nClqdT4BM8zWoHzD5lhJVVHta3Mbx@vger.kernel.org X-Gm-Message-State: AOJu0Yx3Qv8LpTqF+xvhZrVc1ROakN9y7zToondgjLWz+8K2GyP2lRgm E8ZYr4i2unIz5vyKWTPp6atTPab8Wsz/ypYUJmRViz8wWD4kAcDE1z9a1CsW X-Gm-Gg: ASbGncuVwMq1pyxI5Cb+IPbPd6WRo5G0fgtRUe64ViGGR7A4jks0imqErughNcgOvHE kCSuJb/onG/ll8LUVHLq3WyFnBaYEVo4HR+1E6Txe0T0Wt/me5OYhDX90ETTgSOUDS+WxWusAco n/oJOxm6EiPbbY2cZfSuPaw3Eh+kestrVMhnL6rKutd4chdQAwgRRVeaFUVjg6FF2/d9kHNREjd c86o2oNVFyDZFqEJCcjE4VgmkOnuLNjDAg92igpdTCj1RL/UpNqvc4av/pMiYRGtOGvhKVLL+/x 7XazJHLjPOuDw+7qHJEpnujkufnsu0I69/CgUZXzqtZK/uYeT8w= X-Google-Smtp-Source: AGHT+IFDMjLzpqsLULEA2I8aGeIAkRtX+gD/L2/oWpf+RpFXRcmScgy+FXACV5aE3CjHtbiGopPqXw== X-Received: by 2002:a05:651c:210b:b0:300:38ff:f8e1 with SMTP id 38308e7fff4ca-307586ed47dmr20095031fa.2.1737809691822; Sat, 25 Jan 2025 04:54: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54:51 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v6 05/17] HID: pidff: Add MISSING_PBO quirk and its detection Date: Sat, 25 Jan 2025 13:54:27 +0100 Message-ID: <20250125125439.1428460-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 47 +++++++++++++++++++++------------- include/linux/hid.h | 1 + 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index e2e431dec936..89a1b6a55c1b 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -404,13 +404,19 @@ static int pidff_needs_set_periodic(struct ff_effect *effect, static void pidff_set_condition_report(struct pidff_device *pidff, struct ff_effect *effect) { - int i; + int i, max_axis; + + /* Devices missing Parameter Block Offset can only have one axis */ + max_axis = pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO ? 1 : 2; pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] = pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; - for (i = 0; i < 2; i++) { - pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; + for (i = 0; i < max_axis; i++) { + /* Omit Parameter Block Offset if missing */ + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO)) + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; + pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET], effect->u.condition[i].center); pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT], @@ -822,6 +828,11 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, pr_debug("Setting MISSING_DELAY quirk\n"); return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; } + else if (!found && table[k] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) { + pr_debug("PBO field not found, but that's OK\n"); + pr_debug("Setting MISSING_PBO quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_PBO; + } else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; @@ -1101,7 +1112,6 @@ static int pidff_find_effects(struct pidff_device *pidff, */ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { - int envelope_ok = 0; int status = 0; /* Save info about the device not having the DELAY ffb field. */ @@ -1132,13 +1142,10 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) return -ENODEV; } - if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) - envelope_ok = 1; - if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev)) return -ENODEV; - if (!envelope_ok) { + if (PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) { if (test_and_clear_bit(FF_CONSTANT, dev->ffbit)) hid_warn(pidff->hid, "has constant effect but no envelope\n"); @@ -1163,16 +1170,20 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) clear_bit(FF_RAMP, dev->ffbit); } - if ((test_bit(FF_SPRING, dev->ffbit) || - test_bit(FF_DAMPER, dev->ffbit) || - test_bit(FF_FRICTION, dev->ffbit) || - test_bit(FF_INERTIA, dev->ffbit)) && - PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) { - hid_warn(pidff->hid, "unknown condition effect layout\n"); - clear_bit(FF_SPRING, dev->ffbit); - clear_bit(FF_DAMPER, dev->ffbit); - clear_bit(FF_FRICTION, dev->ffbit); - clear_bit(FF_INERTIA, dev->ffbit); + if (test_bit(FF_SPRING, dev->ffbit) || + test_bit(FF_DAMPER, dev->ffbit) || + test_bit(FF_FRICTION, dev->ffbit) || + test_bit(FF_INERTIA, dev->ffbit)) { + status = PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1); + + if (status < 0) { + hid_warn(pidff->hid, "unknown condition effect layout\n"); + clear_bit(FF_SPRING, dev->ffbit); + clear_bit(FF_DAMPER, dev->ffbit); + clear_bit(FF_FRICTION, dev->ffbit); + clear_bit(FF_INERTIA, dev->ffbit); + } + pidff->quirks |= status; } if (test_bit(FF_PERIODIC, dev->ffbit) && diff --git a/include/linux/hid.h b/include/linux/hid.h index 94ad5a510639..29f0a91f505f 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1229,6 +1229,7 @@ int hid_pidff_init(struct hid_device *hid); /* HID PIDFF quirks */ #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sat Jan 25 12:54: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: 13950364 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 811431E505; Sat, 25 Jan 2025 12:54:55 +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=1737809697; cv=none; b=b77Vhe0uT7nIJhAvRDRA9YJiVUJKyCQ0KYC2imBFf9rmWZ62qE10/skeeFTUTE91GmMTz3H8qnOBjrnTSE5rAWeaXtzlx8j6fXXDkXObbB8heHTJ2/qLZePa7MRW28r2dqh7ifA6m9WeUBW30RzoWwWFQGSn6cwERTnTBfwPgJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809697; c=relaxed/simple; bh=dwCcjto78uvhV6q6g4fAZmQ++Yk3NSDQ80/OcX+fJyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UG40RKyhHo2XKug5elAtcq0djatwh14I8dBoI/a3iyjQtJ81W518vv1AaGIfkHkR42W7f5CxbXrIki9wp1L7TUoVWxwslLhEoelMezO1zJ5tWZmE7jnc/T1o0qSW6Vv4ygssMFJ0C0yjqj6ffcgX77Mz6XtUADkz4eNZlfAZ8LY= 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=CmRduc80; 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="CmRduc80" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-542678284e3so514759e87.1; Sat, 25 Jan 2025 04:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809693; x=1738414493; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yn3SV24FXGrk6D9U/sonjVWTrzb/5doNCYeJXjxGMWM=; b=CmRduc80oB2GIQ2gXn3r/812v4RS8c5mJPSQK0VT+OTD/qDrqiie0E9cupTGvrbkl0 EKbpDnfLCxA6QGFAwTIJ+wIXgeJqhox+I7sQIc/2A1AxRkdJoLnSNM0CZfURs8i3aWGc lBLIhkFlTiM/ihfHNdd7cjGY2F4arOjS/2rTRqGWuGkmf8gKOVFGJ7lTDgA21KzS0QaM 1lI7Q7qfOzFXp9IugSrtCzqwgq4/tgAOYa2RFXtXyNdX0+z9mmYE5uDuGGJZG2hd1tEy TXfvk0k/7sORN7GIT6mUUjgX8Ipd47qZjGOpUSTZAtLrOneAh+ms/UH26p/5keKvf+Wv Ofvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809693; x=1738414493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yn3SV24FXGrk6D9U/sonjVWTrzb/5doNCYeJXjxGMWM=; b=lqwKlnyXPbYfvGbc2b7WUhSqvAnlvkhtynGQTQ0EJ0Ovl1nUQ34Cdm77G5xlqvSN5k lowLtd5dDoyH4ss8Ffn9IVgSHpGi6OuFYt57JOXDQRDuKc1JGg1k0wVDuojP7bxKJ+ee WCupupKlSaK/GrrT2lz5vVOurSl3IdYQbL4IioHBviaUWqiI7m+Lkql9SnlmL5TETgWo jtzS9FLhPXN8ORgqBfQVTpYzNvPRKP27r2X7eHfnEa61l0+fstAiXyZhoCYbcVSdawC4 WWWWo6jQXxcbKcpe59cr0YyjcifDMyV58cm9xR7JhfZzw+IaC8AfxHqOAXEgL9dHjNx8 U/Yg== X-Forwarded-Encrypted: i=1; AJvYcCUwVp7XMp+9sGEs34ST6wX79UWWh5lrzjZizTk/sJ7Ylo137MErthtX0VO1RQtD+LXSfsYUC0aBKZq4Lg==@vger.kernel.org, AJvYcCVODt2BZgHk9OkMR/Eg5HJh11b7kY8y9kLznLg8vs19EGtWKnaotF9UwU16LfbDXDWbbIX6G49be01s@vger.kernel.org X-Gm-Message-State: AOJu0YyqXqtISkClpxpBg8rH4AjGoIx04HSdI60P6B5L9VwdlKyjpHiW CbMqbELlRyxokKlPYAMHAcxzk3Ti527Tcnrdc+oSjmHMN1m5Dv7l X-Gm-Gg: ASbGncvQp0j0nozjgRhBKXaHGmFpZfcOa7MxIZKhX6CofIBvDlljXn0LTk5ngNyOf9h H1D+XQSholizCijqU3rLvfnaDO94Jg2lRbstMihfu+zgyTRHt+v8y+ExyRs2dfDLS54PIGvLCdl f7uNd96GmT/SuQ9x7kA18+78UysB3OhHig3w2cK12y1+nfLHYbmyxPvcVot0zp3MGPYjgHlLGHD ES7cNlIUNsFyNU5eIsloT41N64/iyrPcs9UhqQ7ABpdgPZvR/oa/6Zbop9tAuzoAIuYwQdhWUjT aARaxozzGRn+iJYPZ0htadJxtDJ88sYvxcNQRYfPteIgGUD6YwD7tIut+rOJVw== X-Google-Smtp-Source: AGHT+IEXoGtllTfwN8wj0XZoZ/yThGkaXoXZXmSLSoHiarudgfuzxFOQqJw/jP4OzA48Etvey3HwWA== X-Received: by 2002:a05:651c:a0a:b0:302:1c90:58fa with SMTP id 38308e7fff4ca-307587314c0mr16984371fa.5.1737809693371; Sat, 25 Jan 2025 04:54:53 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 06/17] HID: pidff: Add PERMISSIVE_CONTROL quirk Date: Sat, 25 Jan 2025 13:54:28 +0100 Message-ID: <20250125125439.1428460-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 3 ++- include/linux/hid.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 89a1b6a55c1b..3f429936d537 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -982,7 +982,8 @@ static int pidff_find_special_fields(struct pidff_device *pidff) 0x57, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, 1); + 0x96, !(pidff->quirks & HID_PIDFF_QUIRK_PERMISSIVE_CONTROL)); + pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], 0x8b, 1); diff --git a/include/linux/hid.h b/include/linux/hid.h index 29f0a91f505f..92a484f65a87 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1228,8 +1228,9 @@ int hid_pidff_init(struct hid_device *hid); #endif /* HID PIDFF quirks */ -#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) -#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_PERMISSIVE_CONTROL BIT(2) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sat Jan 25 12:54: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: 13950365 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 ADEF9209678; Sat, 25 Jan 2025 12:54:56 +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=1737809698; cv=none; b=S9R5Y+jmXrPbGuNWEK3q8xJKkscz+n9TLRkZdRUh0ohuF6jgivo1HgjSk6H2EF4T/bn2Pi+uR7uZYaM1o1M1p1Jp4GI5CDn4JqpEj0MF69rMBiY/pJWZ4ZpHOGvpfRvq95dYwitOkqte2cIUkT7cSgTjUsRECa+8kuBRW/Xmx3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809698; c=relaxed/simple; bh=lhNyDbqPT/A5BuGm77CZdSiqP3jG/Vu6qUEGM5mTO38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cb8lbtY6o2N05Wdlz1+y3cu7ZuAX8isJNbmlhQ/L7gxDBS7z8yLup11ylq8WO2iKE/pm5fal/4erNWzlbuCrOBIt8vNJ6j8IG56E8uK1w67WGwXHLkY3h2WiDUgj/eXzbTapMGEgFM0GgplshNGIVbcEsypqHSiI2+x93CeVN0o= 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=GRD0eNrx; 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="GRD0eNrx" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5426f715afeso413032e87.3; Sat, 25 Jan 2025 04:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809695; x=1738414495; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gmnykWrVlt0sJdJV1uVzbEe7K1M5/Cz3pmV3NtFHvbM=; b=GRD0eNrxpM1aAyXuSz5PSOwlphNxiUhWq86vcmBvOnEkjwv1ijSgjmGG7dfkeI8F0k ed31oFhycYcgzGo5TQo+NJSkYjs5GYjFpUtIEByMfBOn62B8f3NE20IzdxG2shgSkYHS QfaTxWyORaM4HDDlHJX6nP1Llue0u16gT6Z39Yc8x7mQvrFfg5UBA32Qy4OXtQvhdtP4 PQMie+fdCbeT03apzHaR98nEb/biEWXUlI9jbMtZlmmdKKBKmoXRkmBaHoz0BrIaHYQr TQIproI/q8jxvTQ7sp0U+v2XiAhPeRx72GLMDSNSHUptCqLgmLawCoRJvKVK57Swye9o KmKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809695; x=1738414495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gmnykWrVlt0sJdJV1uVzbEe7K1M5/Cz3pmV3NtFHvbM=; b=aZN0unA7qLpR+hmVPT+qul+2cw1PvC+GDlzfdjGQpLbIxrmThsWXDr06MaoI/CaYmD RhB0rPAQODQKfgpXtmnpsJsAjuCf5jJe+y/pTdQsB16ZuhMVfKXM7DMTKRdEMFbsb8HS IfT3d6HhC3fNmg6BDuMb0LrEc49CY3GKrCfXqEZcJcDDG2BBgb6sm9jmYAR8Mc1Y4VMP ZlTMNFepF8n6OsNXkg0GAXD6HRMcWy/qPUqPQzXDDZOxFFCogjYay1FlWraz67U4Uxe9 JeryUXN5KudPLutxQaX8xWH9ev+gL8NHbZS2xrfztxSnGtn3vgLjcUlFeHWJcdbY6pC2 Nfyw== X-Forwarded-Encrypted: i=1; AJvYcCVKwsLo7BvbZDEW7/dXiWYd99HTQMgBq+4ueBGRrYUorT/gdP2KpECQihp/xnqIm3+V3As88a+oycXu@vger.kernel.org, AJvYcCVrgrmHz/x5xojDwD5poLl+s/ankdWWBRzXgIpZrRKMJueb4OqqOXMOTgFirsDNhn/wsMd31R/fi4FCyw==@vger.kernel.org X-Gm-Message-State: AOJu0YwG4+RiteoASW2HTXPiAqlweyFOvx3QNPe+As+yg8k89cpN+mEM PAbBWFbdrazLrT3hWUc4+QOfFuSJpaUIilBewaIkxWxNAsbn2HjX X-Gm-Gg: ASbGncuIqYOZCyZH14gQdQsFpmAW22obb+rEDYZy8Y2aGFDcSDORKbJUWljUkAZdLMl I6d1Ww33KZBDWnR/Wf63lmSroB6iZ/urKsraAIJja5EwOyKAaxUBNH93gAb1ElEC+to9noR3uN0 ZPAUHokW1VO/EY4uSitbdoSzTWjQyS2z3aZm7Chzx0oaTIbpS+qN4z+mAKHppr83Av1V/oQd/VR UfbFTACJu35th7s4sUfXXH9WQHMlSvxN2Rma0G9dN8TI0MWyaIaREZSKc3u9nNDyI7zeUzuY/Ge ucsbKV8fRwO3YunIxm/gmBfAoweXAKxedEy+SnJatX66DwzfExg= X-Google-Smtp-Source: AGHT+IHlSX/Xfpgb3H5g+dUNlTeoj8yB7Ao8NpK7SRN7H0YambSJuJDNZ1ade1MAuKDm4s92vXzpNA== X-Received: by 2002:a05:651c:198b:b0:300:3a15:8f21 with SMTP id 38308e7fff4ca-3072cb20f5dmr39012411fa.8.1737809694735; Sat, 25 Jan 2025 04:54: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 07/17] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Sat, 25 Jan 2025 13:54:29 +0100 Message-ID: <20250125125439.1428460-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 15 ++++++++++++++- include/linux/hid.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3f429936d537..298a971c63fd 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1281,8 +1281,9 @@ static int pidff_check_autocenter(struct pidff_device *pidff, /* * Check if the device is PID and initialize it + * Set initial quirks */ -int hid_pidff_init(struct hid_device *hid) +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) { struct pidff_device *pidff; struct hid_input *hidinput = list_entry(hid->inputs.next, @@ -1304,6 +1305,7 @@ int hid_pidff_init(struct hid_device *hid) return -ENOMEM; pidff->hid = hid; + pidff->quirks = initial_quirks; hid_device_io_start(hid); @@ -1382,3 +1384,14 @@ int hid_pidff_init(struct hid_device *hid) kfree(pidff); return error; } +EXPORT_SYMBOL_GPL(hid_pidff_init_with_quirks); + +/* + * Check if the device is PID and initialize it + * Wrapper made to keep the compatibility with old + * init function + */ +int hid_pidff_init(struct hid_device *hid) +{ + return hid_pidff_init_with_quirks(hid, 0); +} diff --git a/include/linux/hid.h b/include/linux/hid.h index 92a484f65a87..e6e9081d7dac 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1223,8 +1223,10 @@ void hid_quirks_exit(__u16 bus); #ifdef CONFIG_HID_PID int hid_pidff_init(struct hid_device *hid); +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #else #define hid_pidff_init NULL +#define hid_pidff_init_with_quirks NULL #endif /* HID PIDFF quirks */ From patchwork Sat Jan 25 12:54: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: 13950366 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32518209684; Sat, 25 Jan 2025 12:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809699; cv=none; b=MN3Zqwb/M/Q9rTzYSzK7IyD1HRruY5Fpg1aR5yuNaPG4lZfzch9Dakn/ARmYEsLS5yRpkB77rVc5Mt4ew/qZmQZyoIQPdnmiplOGWyfuolL3ZTwyIxYiAlUpzBSs6OrTEjELJWNof1a8ycPKrLmnBxbdbS+fPdqE7sL2zpNezVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809699; c=relaxed/simple; bh=sfJp+cEStH0iOHMy+L5yy3UCQpbG3St448sBy3TIeoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ls9tMMW1yUdT2HO+YISaYTF0raKTAXJc68cOOVIzkVXjbWV3Lnac/LkBHDc5VO12Dk0qSXE738KgKL/6rCNUqMberyGsfLwTAebVtxUId0d/MRu+IROlAFIFcuUwztZOKpc7vG3okkW2bUcT4PWaQQ3+qgwzPD1EGKV5hlGvzhA= 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=lXVly/yX; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lXVly/yX" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5426f715afeso413037e87.3; Sat, 25 Jan 2025 04:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809696; x=1738414496; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D7ipsiTl1dRTYPh+Rs2vHcEMW70oojF4sOlian54NsU=; b=lXVly/yXixqg8MMST6qWTQmyXXvtu62Pma9lIH7nYyZu1Z3mzL+0Tpk9RH5llEx7by CBkKNyEyhPZdYWMlwZpmPnS24JglMSOAg134kXtoQGYqcPlrH+Ghuf3DwQuNSRs0qnTr hMRqMqYPTw6MtBWQHpUtTCfM7+uojPk1p/+TGvlgXl6up+jCTiyL3LbqfO9S8SnXy7DU o82fR0iJTOxQMpMkkVn6zv7aJor8GUsPFKL/fTpHomhn1/jZijbwWFdm1EiylYAcv+a8 R4LUUjiwag9pfbIEQwZfkgoz4l5/Lst1EfHEqcKgOeib1ClbLGQvMLcIMvMCIekQ1095 EPtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809696; x=1738414496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D7ipsiTl1dRTYPh+Rs2vHcEMW70oojF4sOlian54NsU=; b=JVyYn+EZ7dlNkBH0jFQ4NEs7aB0nNfHJL1dXONzp2ZxUlLCi1pIhyFsfXbdH1WezRK 5dPRBn0kIfyPUfGTveUmRPuHA9e2vJHMnb5vaQZM1SGTHvkmItRqI6kjA8ziEsh1ZG4G g4j8AiUGkPUcf9tn5fxVZpolrxhX58yiunr7+Rs56tGzst2wf+rhyVzJg5Q65HIFSCg9 Y2gmAGzXkF+vmceAGdqC7b00O6/734ovw/er4i2rdPrGENS5OhfGdw87YrNC4BqBvIoq pyzB81ZvPpbfRjkW6O2FZzOmer4Ok8MNb623tXtAoqLPcSQaF+qteTqg0Ob3MPWl6XE1 Odkw== X-Forwarded-Encrypted: i=1; AJvYcCUGPImYw7sq5Uu1HHMmIoXan95ZnVYbmklA04fSYUy/GsI3MmyL/5M0jkvdyFMh7b5CjobH7rcnsvRyuQ==@vger.kernel.org, AJvYcCUShtvH9I9C0uM+0nIFH1MKwZBw+NzoYjJhLhQzvCQSiXFARfPd4YNQg9Y4PLCX7SLCktyZ2+hPln2Z@vger.kernel.org X-Gm-Message-State: AOJu0Yw7Aube29MZsyasQ3gnGbJYIVf4iS2h7r6jVHTuVlwvKVTLZL9z J/tVzkSZ23MghzXsn0oIqecwjAxCjmV9T7IUDBeU6N9chCqqN2cd X-Gm-Gg: ASbGncsi87IuOjeKaD8oLMPF/3LIXdz94wWo8go9svUmcM+walW1fjILXpNfz6+WueY nU4Mwz9a6nEiQBYOAaanl0WkDky+y/y6qMb+sUJ9p2zylJnUiS53HwTH1sX8wEoMCDVh77Rxqgi LWhPSsEDuB75qGNSyAGznKDMZyG+ikdkL9NRyTMPKa3kqwjJd2U/kyuLYg5Y521Rp8bQRxUwCab bHNjfv7sNFWjrWrFiPuyaBKPb971MCjLhjnMQKNDKCgz89NqBs+eUfEZE7gN/nre6nZo0o93vdG jgwDR5jfg5c27vwwhJIYO8HyqlyiU3KWtK9ogZPB7aM7DE4AVto= X-Google-Smtp-Source: AGHT+IGCPSjNbHzFwI737UjJn+03f6FiqFKdr7fAZh7bUFtKbUUGhxrJbp0O41zwMiiKn6cm62aOLA== X-Received: by 2002:a2e:be9c:0:b0:302:27c6:fc98 with SMTP id 38308e7fff4ca-3072ca8c496mr37123141fa.4.1737809696185; Sat, 25 Jan 2025 04:54: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54:55 -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 v6 08/17] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Sat, 25 Jan 2025 13:54:30 +0100 Message-ID: <20250125125439.1428460-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> SDL -> Linux API translation, and this value can be incorrect. This can lead to partial/complete loss of Force Feedback or even unexpected force reversal. Sadly, this quirk can't be detected automatically without sending out effects that would move an axis. This fixes FFB on Moza Racing devices and others where effect direction is not simply ignored. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 12 +++++++++--- include/linux/hid.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 298a971c63fd..9e03dfb2b1e7 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -136,6 +136,9 @@ static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; #define PID_EFFECT_STOP 1 static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b }; +/* Polar direction 90 degrees (North) */ +#define PIDFF_FIXED_WHEEL_DIRECTION 0x4000 + struct pidff_usage { struct hid_field *field; s32 *value; @@ -337,9 +340,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->set_effect[PID_GAIN].value[0] = pidff->set_effect[PID_GAIN].field->logical_maximum; pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->effect_direction->value[0] = - pidff_rescale(effect->direction, 0xffff, - pidff->effect_direction); + + /* Use fixed direction if needed */ + pidff->effect_direction->value[0] = pidff_rescale( + pidff->quirks & HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION ? + PIDFF_FIXED_WHEEL_DIRECTION : effect->direction, + 0xffff, pidff->effect_direction); /* Omit setting delay field if it's missing */ if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) diff --git a/include/linux/hid.h b/include/linux/hid.h index e6e9081d7dac..856bed149246 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1233,6 +1233,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_PERMISSIVE_CONTROL BIT(2) +#define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sat Jan 25 12:54: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: 13950367 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 4C26A208964; Sat, 25 Jan 2025 12:54:59 +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=1737809701; cv=none; b=GvR0OT0FrPWWX8ZE4ItFB+EjdYagBdG9sEcfh1APAGIDV0GTJAEExiLoE2aaVj4Ox1sJvoZykFcWyoabYT9j6FGnR5C2hPA7IOgUz+mOfOVAQNQieQOB4qp7YxarpPFSbtaMVhZxH5Oz/DSR8i2QGRAiid6PYy7mmpdFhoPnIPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809701; c=relaxed/simple; bh=4K6Ktazg8UjZRyNjmJVyYZQUmtkSr7vSe5kY4mMQ1Lg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SN0PT4zbB8DLS+8qyVMTMCNJeTtIpZu7H/2ZXrRs4ed5aXRiPdGG0xPQzZg9y1Med55z9WBaGKMYbnXT1RV2MA9UpfuaD814lgc8kqHnUyLujyuZG8CcGnroj5ztDTi8i1cAK1grOsAXNRWQb6m4+jty/nyEFVQVBBtJwliCN1g= 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=lqDyG3WE; 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="lqDyG3WE" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5402ec870b4so448689e87.2; Sat, 25 Jan 2025 04:54:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809697; x=1738414497; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X7Al4YBblnhD6mAXZvY6iETyAjHehfO4Vpa6xV+iv+c=; b=lqDyG3WE+GIBdsRbCSLwaAskUAa2hEONtGcCBkUDdOjarHW7O/VPxoLSEUmvASsbt3 S4dxRK60z4cpMV8rflcuAkaT7rwMz8l80KKLz88CAWZLYmTu9t2EZ2DVPa8gPaosWuFZ Aguf7vbO69xkpqCp8GqdQd3/98ORe63uAvTRa+zx7v4GsfvVij2zD+pchSareRLSY7l2 +hGBlyfilC14Df7UY733pgMO6HDAP4RkdD/oJPmX1t6lx/TyZ/xViS+dduN/nC6nvSd6 RPBSAn84hUcdm1f9Ahq0+6DhDGlLUcf6v4wvSWd5iqikeLIe7RtZ1QGjiwzOqXdsoXKt lQUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809697; x=1738414497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X7Al4YBblnhD6mAXZvY6iETyAjHehfO4Vpa6xV+iv+c=; b=QoFFRBz72eR6wXO+UGbfhJrYNS53SpIWgu4zmKOft5MiuCSwGppnBv0r9Fojx5hCp9 Ux9NVuaA34fUCyrXMTZenRGtCxnlT5F5/vNDcsgRpyZ+7R7aKDpQuqZvQw7vC7ryXC8u DLBfy7rGJZra6UWwWTI+RCcwKZkdkseQSa7ZezNm4EEgUBJTFEG8kjpBDFQ60Xi8HJPD JbHTYj2pbH4Ya5MZypdNZQyUcsfzvNe/6Cn+q6moo/je+sm5VDlDr3qRIx3VBDQ9vtZi Uf6CV/OwFiettIJ4v9FkuVo0awMcc+yJIaocn+fnqWBhaUqg8Plg2gxMouSVXO0jV9m8 9utg== X-Forwarded-Encrypted: i=1; AJvYcCVxVqh5WLrbnxwL5rKN6jpI73eB9MkAmy9zfnlSlzNFmOho9ddQhm3w8yBNHT8TtSlX4SDyrqEU6OLa@vger.kernel.org, AJvYcCWHsumr6yUQoRodBXOWL4Xaofb9wLLywEmc9RCyQT3XVcHLuiozHFEqDrs9E6JEE6F6sg/lKF/EvUoM/w==@vger.kernel.org X-Gm-Message-State: AOJu0YxSDJfnTSUEjzLSultmS7MMlCY1zygqPXC77tVa2bsbJf59vGD+ dyZPiVJ09cXtClokD/vrKz3aCoFukvBJFEnRaccp+eGUVNT7VWTbvr2iUx2H X-Gm-Gg: ASbGncv9z5yDhu/5f89iug8B1DYLlRFtI1ThqWVoy8zX+QaT0FgUGwHrrM7xihgiYvb 2msQy8UsbY79TTqpJhLZoKy23nltOwi2791rQj400G0Ee4KYv8jwMJ+eN0Ga5oVunvd+LNSEVuH 6sfaH5PRdGA8ldeiI6RjMu+06SYtMhWei3/+30vHuGSzpGS3MZTFzWFq4tDYLw4dncyZ2kki40Z r1D55ajG/NrpWdLx6gR4jWLICFv5LR8rsKl6Brf32OFdpsAYTDpIpW45ufz+GTB/eydlkgqUoh5 GSRD/riLZTQ6hE0Tj0EN6/Mdubwvyqy54tPIZfjMmGHLlJOLiEs= X-Google-Smtp-Source: AGHT+IHz7RwK62kFFp70tDXbfYQ5LhTzdw2WhwnkSTMWPWMV9t+pKjbrHnfiXRKKQVH5dg8HqJXGhA== X-Received: by 2002:a05:651c:50e:b0:307:2aea:55a4 with SMTP id 38308e7fff4ca-307587d598fmr21555541fa.8.1737809697304; Sat, 25 Jan 2025 04:54:57 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 09/17] HID: pidff: Stop all effects before enabling actuators Date: Sat, 25 Jan 2025 13:54:31 +0100 Message-ID: <20250125125439.1428460-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 9e03dfb2b1e7..c125f029b6d6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -109,8 +109,9 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; /* Special field key tables used to put special field keys into arrays */ #define PID_ENABLE_ACTUATORS 0 -#define PID_RESET 1 -static const u8 pidff_device_control[] = { 0x97, 0x9a }; +#define PID_STOP_ALL_EFFECTS 1 +#define PID_RESET 2 +static const u8 pidff_device_control[] = { 0x97, 0x99, 0x9a }; #define PID_CONSTANT 0 #define PID_RAMP 1 @@ -1222,6 +1223,10 @@ static void pidff_reset(struct pidff_device *pidff) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_STOP_ALL_EFFECTS]; + hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); + hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_ENABLE_ACTUATORS]; hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); From patchwork Sat Jan 25 12:54: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: 13950368 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 CE5491DC19E; Sat, 25 Jan 2025 12:55:00 +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=1737809702; cv=none; b=fiwWPSRctz0/WkCvVqAbzJGgW3q9KOElnvCm3VZPoMqOBGp039UywR04i6lhNWKT7wGAMMsa2PUTRKd71RlDtoeKo4KVYzwm3GjYq9aCu/cbDMg1bJqFflcFmGOaUB4bZP2JiU5wDLbckJizozJ60uwM+oQjY60k3pIB9C+a5b4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809702; c=relaxed/simple; bh=YxkpUWxRHfEawsajqhC3tV/lK/+IfPpX3/nf4D7E8P0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ACkQHr6TZIv7m+p707Sa6MIgglANWDHQ+toPayEsOpo+iRMD/R0eWi6f2gQmv+IsO5HQ7RkxaHeG0O5JeV3O1FI84HJ2ZFgp6kE6fMY62DhHmvsHJezdodaQ4R9eMSN59i6rh8AiWFCr1WHwRCeX6qBCky+7mVpDYD1b/UkUhBY= 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=NMX45iE7; 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="NMX45iE7" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5426f715afeso413049e87.3; Sat, 25 Jan 2025 04:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809699; x=1738414499; 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=cAvGvb841qYJKsN+HcxPN6OUGD4TEaNpjmoRwdeGFDE=; b=NMX45iE7KUbb3tYstgKdg0QgqSJqocfUi2qxzfDbn80QS76/2sE7xx/cwsvyh4c3XB m18HjkQmU4jrrcvPmjXLjU+FtSHeiYGthA1TY1X2wLojA9LtCF/gU9rLnik8dhcCAM6/ 3xAs4Km5MosK1nQtrOF04jAYOFcuROc/srHv9exBGtDIycXwAH+3KSzYGtobnQwakTLu llc22JEpO2SMBje2QNaVw6XYxfIjzh1AfsM8KhBwGLyGixnqdPfTQ/BGB9hXcOVhT7Si Zlb+I4FbOOdM6Mm2QmTYTJ1goj6/pxD6VfO2+nCKbFTybBHBUlnOyYiuzpT1P7aVFDmU ITZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809699; x=1738414499; 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=cAvGvb841qYJKsN+HcxPN6OUGD4TEaNpjmoRwdeGFDE=; b=g26re1odnc1RvHGvXqTp5w516hGSmp8ad+x/TOkBmyN9EUQJaMPXUmI0Zn5N1F+lTr zv1XU3ByAwqbBesnXGm/NFwFQrt28sg/V4B81g1hkQ0NZFMh8dH18i07UoBi4sXqd+tl uG6S3XgF3/VVZCVV9WW7Unw0z6mkX0EgNWuukHym+KrCTmCjI0f8sG96pHLdjg8obJna DjGTfavqwq7RRMx2VRyZ5JVkuxY6QuQ5iBk+v9vIw4NHHZryttmYfZGnzAFrQC5BLJKE AtHzxfuatgkhK7d5om7QxRu3oPr+NpZp1bTcfpXlpYJJjjfkC6wBh8vksi++Pmrpyc9f wjRg== X-Forwarded-Encrypted: i=1; AJvYcCWn5yzUGD3OCuakorT4w80N4/1KqlAmgn8UWyGA4Hu3WaeT8DFFHo7PIayriu2XFrxlGoPV90XQFgdW@vger.kernel.org, AJvYcCX4TUADXi19vQ+lO/VBLTiOL0kWaPgscRvuKF94bI+zRI+1YhkRq0OoGQ4NuNj1N6UAjIElBxccuAiIOA==@vger.kernel.org X-Gm-Message-State: AOJu0YxLVpuxrBdzDTvku7dYxagT7tZeVXtyyAoN1BckbWlQesDKAVtE UIhAtkFEGWavEDLE8H9Wfz6EAliJRZ8VIGAH+0Q3T3zbrLqIJ+Jt X-Gm-Gg: ASbGncsnVq4YogtG/xGA8zeejDdr0Wvy6vuKexUiSbIMLUrpQ3ULmztnkmb0VtKRdfv 3AYhijyLrrKc6GXoM/H1o0bp36EoCgEVXXIDZjJP5gX0//Jw47OUf8YqCpxhCDHjOM5+SNvJ9iO nO9XyrqZsX+45UeWCd4+zi9dbfRkQFg9XOoZcQGFqovwZ+0Cu2ShtVx0xG9GW1w2BSn2NM9NvJv jLOVJW23hfvozaDFtJ2VWYd8ZZeh5m84iQdt3HtmKGgUKjqzrVgjxX9jFM2CePk/AdDOZYU0T+s 8CqdKTykl+acp7dMgORbKHXMyx7+7qlRl4MHNYvjir/E8WY4CWo= X-Google-Smtp-Source: AGHT+IEDZEmD2Yn/e6yuIhu43YYgUux1IMMVJ5uaJPKk+ktTKrnwc3b+X7gu8Fk+S12mDCrghIgRZQ== X-Received: by 2002:a05:651c:b0e:b0:302:4113:2023 with SMTP id 38308e7fff4ca-3072ca63992mr39794071fa.3.1737809698775; Sat, 25 Jan 2025 04:54: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54:58 -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 v6 10/17] HID: Add hid-universal-pidff driver and supported device ids Date: Sat, 25 Jan 2025 13:54:32 +0100 Message-ID: <20250125125439.1428460-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- 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..555c48f09dd4 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -261,6 +261,10 @@ #define USB_DEVICE_ID_BTC_EMPREX_REMOTE 0x5578 #define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577 +#define USB_VENDOR_ID_CAMMUS 0x3416 +#define USB_DEVICE_ID_CAMMUS_C5 0x0301 +#define USB_DEVICE_ID_CAMMUS_C12 0x0302 + #define USB_VENDOR_ID_CANDO 0x2087 #define USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH 0x0703 #define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01 @@ -452,6 +456,11 @@ #define USB_VENDOR_ID_EVISION 0x320f #define USB_DEVICE_ID_EVISION_ICL01 0x5041 +#define USB_VENDOR_ID_FFBEAST 0x045b +#define USB_DEVICE_ID_FFBEAST_JOYSTICK 0x58f9 +#define USB_DEVICE_ID_FFBEAST_RUDDER 0x5968 +#define USB_DEVICE_ID_FFBEAST_WHEEL 0x59d7 + #define USB_VENDOR_ID_FLATFROG 0x25b5 #define USB_DEVICE_ID_MULTITOUCH_3200 0x0002 @@ -817,6 +826,13 @@ #define I2C_DEVICE_ID_LG_8001 0x8001 #define I2C_DEVICE_ID_LG_7010 0x7010 +#define USB_VENDOR_ID_LITE_STAR 0x11ff +#define USB_DEVICE_ID_PXN_V10 0x3245 +#define USB_DEVICE_ID_PXN_V12 0x1212 +#define USB_DEVICE_ID_PXN_V12_LITE 0x1112 +#define USB_DEVICE_ID_PXN_V12_LITE_2 0x1211 +#define USB_DEVICE_LITE_STAR_GT987_FF 0x2141 + #define USB_VENDOR_ID_LOGITECH 0x046d #define USB_DEVICE_ID_LOGITECH_Z_10_SPK 0x0a07 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e @@ -964,6 +980,18 @@ #define USB_VENDOR_ID_MONTEREY 0x0566 #define USB_DEVICE_ID_GENIUS_KB29E 0x3004 +#define USB_VENDOR_ID_MOZA 0x346e +#define USB_DEVICE_ID_MOZA_R3 0x0005 +#define USB_DEVICE_ID_MOZA_R3_2 0x0015 +#define USB_DEVICE_ID_MOZA_R5 0x0004 +#define USB_DEVICE_ID_MOZA_R5_2 0x0014 +#define USB_DEVICE_ID_MOZA_R9 0x0002 +#define USB_DEVICE_ID_MOZA_R9_2 0x0012 +#define USB_DEVICE_ID_MOZA_R12 0x0006 +#define USB_DEVICE_ID_MOZA_R12_2 0x0016 +#define USB_DEVICE_ID_MOZA_R16_R21 0x0000 +#define USB_DEVICE_ID_MOZA_R16_R21_2 0x0010 + #define USB_VENDOR_ID_MSI 0x1770 #define USB_DEVICE_ID_MSI_GT683R_LED_PANEL 0xff00 @@ -1373,6 +1401,9 @@ #define USB_DEVICE_ID_VELLEMAN_K8061_FIRST 0x8061 #define USB_DEVICE_ID_VELLEMAN_K8061_LAST 0x8068 +#define USB_VENDOR_ID_VRS 0x0483 +#define USB_DEVICE_ID_VRS_DFP 0xa355 + #define USB_VENDOR_ID_VTL 0x0306 #define USB_DEVICE_ID_VTL_MULTITOUCH_FF3F 0xff3f diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c new file mode 100644 index 000000000000..55aad2e4ac1b --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID UNIVERSAL PIDFF + * hid-pidff wrapper for PID-enabled devices + * Handles device reports, quirks and extends usable button range + * + * Copyright (c) 2024, 2025 Makarenko Oleg + * Copyright (c) 2024, 2025 Tomasz Pakuła + */ + +#include +#include +#include +#include +#include "hid-ids.h" + +#define JOY_RANGE (BTN_DEAD - BTN_JOYSTICK + 1) + +/* + * Map buttons manually to extend the default joystick button limit + */ +static int universal_pidff_input_mapping(struct hid_device *hdev, + struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) + return 0; + + if (field->application != HID_GD_JOYSTICK) + return 0; + + int button = ((usage->hid - 1) & HID_USAGE); + int code = button + BTN_JOYSTICK; + + /* Detect the end of JOYSTICK buttons range */ + if (code > BTN_DEAD) + code = button + KEY_NEXT_FAVORITE - JOY_RANGE; + + /* + * Map overflowing buttons to KEY_RESERVED to not ignore + * them and let them still trigger MSC_SCAN + */ + if (code > KEY_MAX) + code = KEY_RESERVED; + + hid_map_usage(hi, usage, bit, max, EV_KEY, code); + hid_dbg(hdev, "Button %d: usage %d", button, code); + return 1; +} + +/* + * Check if the device is PID and initialize it + * Add quirks after initialisation + */ +static int universal_pidff_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + int i, error; + error = hid_parse(hdev); + if (error) { + hid_err(hdev, "HID parse failed\n"); + goto err; + } + + error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + if (error) { + hid_err(hdev, "HID hw start failed\n"); + goto err; + } + + /* Check if device contains PID usage page */ + error = 1; + for (i = 0; i < hdev->collection_size; i++) + if ((hdev->collection[i].usage & HID_USAGE_PAGE) == HID_UP_PID) { + error = 0; + hid_dbg(hdev, "PID usage page found\n"); + break; + } + + /* + * Do not fail as this might be the second "device" + * just for additional buttons/axes. Exit cleanly if force + * feedback usage page wasn't found (included devices were + * tested and confirmed to be USB PID after all). + */ + if (error) { + hid_dbg(hdev, "PID usage page not found in the descriptor\n"); + return 0; + } + + /* Check if HID_PID support is enabled */ + int (*init_function)(struct hid_device *, __u32); + init_function = hid_pidff_init_with_quirks; + + if (!init_function) { + hid_warn(hdev, "HID_PID support not enabled!\n"); + return 0; + } + + error = init_function(hdev, id->driver_data); + if (error) { + hid_warn(hdev, "Error initialising force feedback\n"); + goto err; + } + + hid_info(hdev, "Universal pidff driver loaded sucesfully!"); + + return 0; +err: + return error; +} + +static int universal_pidff_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + int axis; + struct input_dev *input = hidinput->input; + + if (!input->absinfo) + return 0; + + /* Decrease fuzz and deadzone on available axes */ + for (axis = ABS_X; axis <= ABS_BRAKE; axis++) { + if (!test_bit(axis, input->absbit)) + continue; + + input_set_abs_params(input, axis, + input->absinfo[axis].minimum, + input->absinfo[axis].maximum, + axis == ABS_X ? 0 : 8, 0); + } + + /* Remove fuzz and deadzone from the second joystick axis */ + if (hdev->vendor == USB_VENDOR_ID_FFBEAST && + hdev->product == USB_DEVICE_ID_FFBEAST_JOYSTICK) + input_set_abs_params(input, ABS_Y, + input->absinfo[ABS_Y].minimum, + input->absinfo[ABS_Y].maximum, 0, 0); + + return 0; +} + +static const struct hid_device_id universal_pidff_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3_2), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5_2), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9_2), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12_2), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21_2), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C5) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_VRS, USB_DEVICE_ID_VRS_DFP), + .driver_data = HID_PIDFF_QUIRK_PERMISSIVE_CONTROL }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V10) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_LITE_STAR_GT987_FF) }, + { } +}; +MODULE_DEVICE_TABLE(hid, universal_pidff_devices); + +static struct hid_driver universal_pidff = { + .name = "hid-universal-pidff", + .id_table = universal_pidff_devices, + .input_mapping = universal_pidff_input_mapping, + .probe = universal_pidff_probe, + .input_configured = universal_pidff_input_configured +}; +module_hid_driver(universal_pidff); + +MODULE_DESCRIPTION("Universal driver for USB PID Force Feedback devices"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Makarenko Oleg "); +MODULE_AUTHOR("Tomasz Pakuła "); From patchwork Sat Jan 25 12:54: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: 13950369 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47A71208964; Sat, 25 Jan 2025 12:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809703; cv=none; b=dFFFs6sjL0gn9Lcj9XKebwD0aX5qhBzM/p9Rqg8Yv3e8+5GT/xN8P9TjFHgtQD3WT36SgLAbv4ShfCpplXxNiGZugan3Q1UDNq4MXTUBhxONhbry2WhhbvlA7axsz3UK6Z99WbzmYomTkL8Wo0/tuPv0cWOo8RpoA4WAzFA1uy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809703; c=relaxed/simple; bh=VB+0BvEUUb1uF7HcMQ/oDMgtxEjHxIrZItGg7tGNsH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P1vNiW/PxfQuMgv5WAMYcPzfwSTeGFNk+VLeHmk4S6IFTYoeun2XMkZi3QroGR8qzB0TAt+0rn3kojWs6WI2+4v5nBHt1vpBqBlmGWdYg/WHLy7VkWBf/NRKS+wtbYEoEPez9WFH1cesGo1724Ny6C2YK5Lb2lhDBYgiRVEsBFY= 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=dKcs0X2g; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dKcs0X2g" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5402ec870b4so448694e87.2; Sat, 25 Jan 2025 04:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809700; x=1738414500; 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=A/jagm98BVwOGAW/sM/PsUGZoeqJdswnIQWjbLkDya8=; b=dKcs0X2gZqbG7o54CeT0JaETYsJncArRAXPOiE+LhBbIVTABiZULy2Fx9lGsjxPpB6 seX6x4MzBCidxsVpnLH9WFKZ4daPoW/+zqLtAHhQCB/gpQmXDKbX25j3EiavVD6+p3qu rXSYuc5q0kM+uBJGHOh8oX2Ipm86SJ4wsPObuHtvbgbA2KRWSrGl4sCPpa9G4e/3qnIX SkxXaR38qBBGsHUt0eyCcN7C0SMgFI9d+QMBCUCYtlBtwurz2cnEgt8DQeA83aHRxtQ5 EoJNilfKO42PwLAiSyY+hddodTjJ4WiUMJuOUT+niUwUq4qF8I8U1knP+dhPTixataiZ EmWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809700; x=1738414500; 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=A/jagm98BVwOGAW/sM/PsUGZoeqJdswnIQWjbLkDya8=; b=tWQQgKKHmcZ+tQiMy/Owp/nOrrLEioQ7uGPVAxqGFaSF6my9WfOGHR5hdCWQEjpLWC 9mxwxtuChAJXFv4IDCYAWPBfHcn8aSM2K9pceWX11vWehEbN4iMJ4rAueYcpSgDo/ruO UMUxCoNqv7H0mnydSmgLGt//lm48P3Mh9OPB5QSacLzDmGyvcoaNPGr3eIIj6+DV/TKi n7bnxwHcuToOHDF/8V9lGySC5TMuWH8r5F5kfzSq0z3zKgCjxD48X8RUNWlrg8J5FbYS g8KxGmA63rIZNqMwTCCuW2aRH/FO+Yw8hHAzBCffxgA5D0eHZPbXi4nOEaz6vCoP0YAV zYPw== X-Forwarded-Encrypted: i=1; AJvYcCW9Z9PAydvabR8y+ixCmObzjkm9NjOmFXg/B/aosJ4wsoX9R5l6XGziSHAqJ0aMhqBZvbkp+LCAYtxaDA==@vger.kernel.org, AJvYcCXBZCqvdnWGtFRznUoKwjK8bgKJ9pRAfXwoR5sk6LaDII41eCa4egqnI/336HShfUNjuesg544rWzq7@vger.kernel.org X-Gm-Message-State: AOJu0Yy/b2YMlY0+5KvQKkfkVeNA/B0Aq/N/imytNMXfHp/Yl9Po5xd/ Vpv3kBvFk+iJimE69KXEyG64PrQtTigODIiuyUiM934NJZ5xq0so X-Gm-Gg: ASbGncujSsdmrAqJSTfClAtSI22kI9XBwaQu7j3dYUE5YLi72M4IEY3M1Di5yrDLF1z l9I429NnMWnDGoUOyqFK0qJluMIhfKj7ak7rTAOgSWOJDQHE24OvgSye+5lvpmlBrGsOJlHy8IY sHNzMszlYdQTuGgkGJrCnKQTykuppJwXnSMCLBqEocCFHdZ+NYR+sPj39XJWZcL4vXvVyy84F0p Yg2EFwuyVQy+91dry7LzGMKWzXWBalgRqODxwYXyU+XgyZos3FxjQE8esRs+/o3qhqE6JUyiWP/ RiS+cppoW5k3GNrKBmcejs1bpNBZHi2Sf3xWJBnLCZ9sHo/LzPM= X-Google-Smtp-Source: AGHT+IG2kD6W3TpbJ2DGEVfIJLQaPTWf9UT1KZaNLXhwniUYuYhkCLVd2KMLxpg8fmk4WJwYWHcaoA== X-Received: by 2002:a05:651c:b0f:b0:300:3a15:8f18 with SMTP id 38308e7fff4ca-307586034dcmr19544621fa.0.1737809700244; Sat, 25 Jan 2025 04:55:00 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:54: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 v6 11/17] MAINTAINERS: Add entry for hid-universal-pidff driver Date: Sat, 25 Jan 2025 13:54:33 +0100 Message-ID: <20250125125439.1428460-12-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0fa7c5728f1e..c416ba133ea5 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/linux/issues +F: drivers/hid/hid-universal-pidff.c + HID VRC-2 CAR CONTROLLER DRIVER M: Marcus Folkesson L: linux-input@vger.kernel.org From patchwork Sat Jan 25 12:54: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: 13950370 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 B03D0209F32; Sat, 25 Jan 2025 12:55:03 +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=1737809705; cv=none; b=SbGJ9gymr40syx4/Y649YSJRaPYFKZfS7xleVOnYEpGiiL1Xa79PMbcL4QVlywnDSIQRDjP2Ln7htm8jCtPRe3QGl0BlW1JZRtZsU2er3djZ64WeXYvcY/nAp/XcCr5L8mx6UN3mtSSyeQNs7DPdY4MHa+58YyWh4rUx7Jg7TRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809705; c=relaxed/simple; bh=ZaZAk1C2xIJCkzjhRvpDAUxa7JWqiqQUSb6ApMEF6n8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=avC9HAN/wfKOVvWFGoN5pW9iDBFpn5NVViQWlEHl2VyJLf8AfSl4E64gURzNCsLo/rp1ye5ulwQ4SiYN+5F96UuG+YygZa2lhNKFmF5lQwCuHaevrOsDLR2tDK3K06ags/MJV0WzdSV7VuSdSlikdny6P0O6BlyC9yQT43hXZsc= 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=QHoo0cVA; 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="QHoo0cVA" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-54019dfd772so413301e87.0; Sat, 25 Jan 2025 04:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809702; x=1738414502; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T39P56OhkmFQzv19vK4YQ7IqiF3JTzwVZZZdGJECCxI=; b=QHoo0cVAEAo3QXIpOI4FgoD4BVLpfQSHIcY78nwQ1Q3dtuEopdEWqNSVEx9Sf/rDjl 7VZuM2BQrZaifJBC6KVydKWj5L2um2eknQS/4wwjytaoVgRc7qIl2ndvCVMWX3zMEeFq 5OxIW4Xmuq8bL19FJy9XlENg8fp1EfiWWD+Mla9ZX3pPxRiu8Xzz/CqQPC1lF2GL2oho j7oHpNJLkIEcqhx5r52V7gRBYZxmWHtEbQfSZYE8XA8YkHoGcvIlvMPHfH6JYywvowhP A3KVA8O/vqQtfCYvIbge51+uCb3U8n1XiiAZVU/FjyGUx9R6ZF8fjiEZBxMo098xfnDe E5nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809702; x=1738414502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T39P56OhkmFQzv19vK4YQ7IqiF3JTzwVZZZdGJECCxI=; b=uCN3whVKCAv8jSIHdTWPWJkSqoQIMMgoqP+F5GtercQCb81AcYAijtnSAXQCZ6EHcD tr5CBt0OpP84IeL0oYitxA9OPHj1uJ/SVfBtRNFQXLkgaeo3w0GV75pzmvlXpWT934x4 M7rLTl2nQWCL3SM/I4iqKVq1Q14ON/5/FtqzPMdxKW3G9wZJagLB3glBHx7/JRSfBlYF UmPxZFhOyQQlD88Nz5xtoj2itMcZLZeDue9VXJJHYkRdFzfA2zL9asCAO8IdAMMwRo5m 42Ry9bEENWe7dE8eKGmUCcJA4f4MpQ1rUQOTZM+FaPAjSIoMphM9HGTG8OY4eFXu1l+k RNQw== X-Forwarded-Encrypted: i=1; AJvYcCUPTa2+LXmN4V/AJBS+4LI+wIoN33pPz49w51ZPsQeH4taeBqE50QOSMeTBcCrIRzWIW4/6V5K5bp6X@vger.kernel.org, AJvYcCUpUg8ZDIad/Jp2lWnAnIJBei3zC6R/ZXx+by/6iYW0kyFgAxT6a/kM6NOxymB4sZNR/95W2XfUW8Eqgw==@vger.kernel.org X-Gm-Message-State: AOJu0YxyXsTnBavxTXNAjXwKjrpvqund2557Tm9Em+rm1+pDwdK6WihH RDzNKIvEnEHI8WXBf4BWLimjEDgOmpMwkH+aowx0BnehkQGE5YN2JcyHpSOz X-Gm-Gg: ASbGncsbC6iTRLV1oASY7td0jDQVcJBXwU0SikeYDwEDSoxIeP/gJy1+aVSoQVClMmL JTC9zgZWhoBmHpxxGEko91UIhDxKMeqb/7w5hcwetdrNn6c6wt0IskyvdeqCXaBbMeZp6e+P8sJ 6nE4uG3Bl0yliNOPIsaF/dbhlC889mJRuOTaeFZegA6HYkKWOaSjgZQ6Gxj22GTJ0CBW1ZeQtO+ 6ArE9gpAvqNkXQQ8A5wvOVG1JWLh3EkiGpH38xTOaJIL3AUKijG3mUuWIPEn4MJf5bA3DWXC8dF g09/w0tZVRU/PfjhEes6W4BRB3L4uz8hD9br/CP87If6B/+tYS8= X-Google-Smtp-Source: AGHT+IEgkhOD2Xx3fZ1qTdMkIWEJq6Q4wt1N9nNomMHOampjkDBHk8pJqFHCQU++cYQLdfHj8qoJ9A== X-Received: by 2002:a05:651c:541:b0:302:17e7:e17f with SMTP id 38308e7fff4ca-3072ca50a6emr44313211fa.1.1737809701694; Sat, 25 Jan 2025 04:55: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 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:55:01 -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 v6 12/17] HID: pidff: Add PERIODIC_SINE_ONLY quirk Date: Sat, 25 Jan 2025 13:54:34 +0100 Message-ID: <20250125125439.1428460-13-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/hid-universal-pidff.c | 15 ++++++++++----- drivers/hid/usbhid/hid-pidff.c | 3 +++ include/linux/hid.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c index 55aad2e4ac1b..7ef5ab9146b1 100644 --- a/drivers/hid/hid-universal-pidff.c +++ b/drivers/hid/hid-universal-pidff.c @@ -168,11 +168,16 @@ static const struct hid_device_id universal_pidff_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V10) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, - { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_LITE_STAR_GT987_FF) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V10), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_LITE_STAR_GT987_FF), + .driver_data = HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY }, { } }; MODULE_DEVICE_TABLE(hid, universal_pidff_devices); diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index c125f029b6d6..e6224e797dc6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -651,6 +651,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, return -EINVAL; } + if (pidff->quirks & HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY) + type_id = PID_SINE; + error = pidff_request_effect_upload(pidff, pidff->type_id[type_id]); if (error) diff --git a/include/linux/hid.h b/include/linux/hid.h index 856bed149246..c6beb01ab00c 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1234,6 +1234,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_PERMISSIVE_CONTROL BIT(2) #define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) +#define HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY BIT(4) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sat Jan 25 12:54: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: 13950371 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 5B6EC208988; Sat, 25 Jan 2025 12:55:13 +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=1737809715; cv=none; b=i8/vr++lWdnS0EOOxtu4NMyEsKPwetCnnVxrF70bpwnjuU17InRu2dB0heKsRPNWWg29s3tk/l7xbenFNUU6WQ6yTh47YKRkcvZWvCW/qtbo8E90gPw0cVKA7wS/2yXAk3X38eS8j/ZHiA+aSbXdYcFVQDmaXC7I6LlHli0VfjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809715; c=relaxed/simple; bh=K0eZ2ATSBpOzziwXP0DWdhA7E+MAtlufjDmC2e8p14s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Qd+xxeokFBwVCcvt3xzVy82Gce5rZcq8bgg9qaCYnI/knyEzQWyGZcc5efkn5/z+ry/1ouSl1T+arxS8LcJg9rF8C9+K8T44ALZMVDWrVw3gfxMq3GVGOJg7OlHimfWP8YUKVToEhe6Az4aMyWLIE2pcz2o6QbVO+XCns22/TQY= 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=SLfWIoUO; 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="SLfWIoUO" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-542678284e3so514801e87.1; Sat, 25 Jan 2025 04:55:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809711; x=1738414511; 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=Miz/p4/HPjb8+Jftb/H0T03+Avc1QDs38j+F9izqAXs=; b=SLfWIoUOqTxfWDc55fVyIAQRPOnvsqL42brgozN8vyt2mtDXL4+1l0u2mi+IufL2nM pIgSBvJ7ix2IZeV6gDXZHCj0Ao+2bnzjZaJCtXUi/McjsyiJN3Dq68YdCmA60/LqVejE Md4kxp+EAibYPadyqbCdW9H2IBHpzt7FMeINdrfYFwEzEJSZ2EUTvTjumGEZzkLhIklX /eu1apxnNKt9Fp6SrvDxgGu/oq3KrVcwE9gK9kAx2hRUhLUCvPVwh9ztiWdB4Kj0dgvD ns7viYYBeooZjHDsf+HFYQFeqAT7dDterJyHPv3yCnELz1QN4psNlo/08dxnrQvZEH4P BNww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809711; x=1738414511; 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=Miz/p4/HPjb8+Jftb/H0T03+Avc1QDs38j+F9izqAXs=; b=jMF4SVeLSvFFuEuBNXAgSY60MRr8Hhc0yQf40OY/I8MhAytK/MmFk1GyDCY7WzJw97 1V0szKcwMyyhRJKvE7LM5rgNXMrDe2iK0xRmfKPP5XJNYpj151Ypi8CNNmD+WE3nG+cH j/9GMpZud4uQh+Cuhhb77BX2Rv2n3ftk//89rP2Wb31sOwazuuY+U6S3Sz/pSoRWDi9J AwEf5qsV2n8RV5wCKu87j/T+g2exJGOs1zDHKueqdF3K6954HPvoqgZ0SFQTPkMmYueW kl/w78QnyfgALgD4Is5DyWP9TY0k94f7Ngjveryn2NExShMT8BP4wmDVRiXo5Bcx0FUV shxg== X-Forwarded-Encrypted: i=1; AJvYcCV4g075FZ3Tt53gTsSf0ADoXrpAHqd0qJ/HOxk8GShLyCrFQ2Yut37zw4svuBDEI+oflIo4y0ryUeqpRQ==@vger.kernel.org, AJvYcCX0Xrv0JEsFRouf4qWqaieGBw8kRsYOnBOpWQv5HLDy8WhK8chFCA0T0vZfMAinb9tscI3PrP6aCTQ8@vger.kernel.org X-Gm-Message-State: AOJu0YxpM3/rF9mKIbPdvUyVu8nb1omwacFrgzJNE+3j5OcMFBRc0zCT bhSn22Tambhg7Rf0wWIhMc6fMz/VI4lVi3B3uSIDUEjCynj7zZZN X-Gm-Gg: ASbGncuVuH/jo5uFTJTKNvvBAtkftqH6Yko1RTTNdXC3PlsRPE6GiMsIcBqq4JP30RV qis6XLrJhXO65nNIn7YpatS+zgcxV3pAPwhJLBVpa5GURxah1OaMZ/B0nZHcEvbfDbbJxTTUANJ kOLDS8Cm7pdtyOa9atfg79uM/nXZTCiGKa3reI9VvtntjEOwxkBKe7dQCjS3ulGeAW906F/+Yyr h9SF6uAkmR47X+n3xaESACqVj9RN5B6bCw+VzkQLiJfYA3Is/01znV1HdWwwmXt5vFx88fkwVPI vY08Eq2t1Qli6pbl4mnUO2dkAced+E4o6xRYkdFVu7FTDMAtSXM= X-Google-Smtp-Source: AGHT+IHY0wrTexNvOgHIbkqIbV3fwVx5ZnRCzrGj661ws7mxyM3ITZUJj9u/qxd350Y2TeRdPHSoNQ== X-Received: by 2002:a2e:b88e:0:b0:302:3356:54e2 with SMTP id 38308e7fff4ca-30758803088mr21490761fa.10.1737809711161; Sat, 25 Jan 2025 04:55:11 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:55:10 -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 v6 13/17] HID: pidff: Completely rework and fix pidff_reset function Date: Sat, 25 Jan 2025 13:54:35 +0100 Message-ID: <20250125125439.1428460-14-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 1.5 subsection 3.4.2.1 Added pidff_send_device_control which handles usage flag check which decides whethr DEVOCE_CONTROL should be handled as "One selection of a set" or "Any selection of a set". Reset was triggered once, on device initialization. Now, it's triggered every time when uploading an effect to an empty device (no currently stored effects), tracked by pidff->effect_count variable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 139 +++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 49 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index e6224e797dc6..689bf516ec55 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -109,9 +109,10 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; /* Special field key tables used to put special field keys into arrays */ #define PID_ENABLE_ACTUATORS 0 -#define PID_STOP_ALL_EFFECTS 1 -#define PID_RESET 2 -static const u8 pidff_device_control[] = { 0x97, 0x99, 0x9a }; +#define PID_DISABLE_ACTUATORS 1 +#define PID_STOP_ALL_EFFECTS 2 +#define PID_RESET 3 +static const u8 pidff_device_control[] = { 0x97, 0x98, 0x99, 0x9a }; #define PID_CONSTANT 0 #define PID_RAMP 1 @@ -190,6 +191,7 @@ struct pidff_device { int pid_id[PID_EFFECTS_MAX]; u32 quirks; + u8 effect_count; }; /* @@ -490,9 +492,84 @@ static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old) effect->u.ramp.end_level != old->u.ramp.end_level; } +/* + * Clear device control report + */ +static void pidff_send_device_control(struct pidff_device *pidff, int field) +{ + int i, tmp; + int field_index = pidff->control_id[field]; + + /* Detect if the field is a bitmask variable or an array */ + if (pidff->device_control->flags & HID_MAIN_ITEM_VARIABLE) { + hid_dbg(pidff->hid, "DEVICE_CONTROL is a bitmask\n"); + /* Clear current bitmask */ + for(i = 0; i < sizeof(pidff_device_control); i++) { + tmp = pidff_device_control[i]; + tmp = pidff->control_id[tmp]; + pidff->device_control->value[tmp] = 0; + } + pidff->device_control->value[field_index - 1] = 1; + } else { + hid_dbg(pidff->hid, "DEVICE_CONTROL is an array\n"); + pidff->device_control->value[0] = field_index; + } + + hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); + hid_hw_wait(pidff->hid); +} + +/* + * Modify actuators state + */ +static void pidff_modify_actuators_state(struct pidff_device *pidff, bool enable) +{ + hid_dbg(pidff->hid, "%s actuators\n", enable ? "Enable" : "Disable"); + pidff_send_device_control(pidff, + enable ? PID_ENABLE_ACTUATORS : PID_DISABLE_ACTUATORS); +} + +/* + * Reset the device, stop all effects, enable actuators + * Refetch pool report + */ +static void pidff_reset(struct pidff_device *pidff) +{ + int i = 0; + + /* We reset twice as sometimes hid_wait_io isn't waiting long enough */ + pidff_send_device_control(pidff, PID_RESET); + pidff_send_device_control(pidff, PID_RESET); + pidff->effect_count = 0; + + pidff_send_device_control(pidff, PID_STOP_ALL_EFFECTS); + pidff_modify_actuators_state(pidff, 1); + + /* pool report is sometimes messed up, refetch it */ + hid_hw_request(pidff->hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT); + hid_hw_wait(pidff->hid); + + if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { + while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) { + if (i++ > 20) { + hid_warn(pidff->hid, + "device reports %d simultaneous effects\n", + pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); + break; + } + hid_dbg(pidff->hid, "pid_pool requested again\n"); + hid_hw_request(pidff->hid, pidff->reports[PID_POOL], + HID_REQ_GET_REPORT); + hid_hw_wait(pidff->hid); + } + } +} + /* * Send a request for effect upload to the device * + * Reset and enable actuators if no effects were present on the device + * * Returns 0 if device reported success, -ENOSPC if the device reported memory * is full. Upon unknown response the function will retry for 60 times, if * still unsuccessful -EIO is returned. @@ -501,6 +578,9 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum) { int j; + if (!pidff->effect_count) + pidff_reset(pidff); + pidff->create_new_effect_type->value[0] = efnum; hid_hw_request(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT], HID_REQ_SET_REPORT); @@ -520,6 +600,8 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum) hid_dbg(pidff->hid, "device reported free memory: %d bytes\n", pidff->block_load[PID_RAM_POOL_AVAILABLE].value ? pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); + + pidff->effect_count++; return 0; } if (pidff->block_load_status->value[0] == @@ -568,12 +650,16 @@ static int pidff_playback(struct input_dev *dev, int effect_id, int value) /* * Erase effect with PID id + * Decrease the device effect counter */ static void pidff_erase_pid(struct pidff_device *pidff, int pid_id) { pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id; hid_hw_request(pidff->hid, pidff->reports[PID_BLOCK_FREE], HID_REQ_SET_REPORT); + + if (pidff->effect_count > 0) + pidff->effect_count--; } /* @@ -1211,50 +1297,6 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) return 0; } -/* - * Reset the device - */ -static void pidff_reset(struct pidff_device *pidff) -{ - struct hid_device *hid = pidff->hid; - int i = 0; - - pidff->device_control->value[0] = pidff->control_id[PID_RESET]; - /* We reset twice as sometimes hid_wait_io isn't waiting long enough */ - hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); - hid_hw_wait(hid); - hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); - hid_hw_wait(hid); - - pidff->device_control->value[0] = pidff->control_id[PID_STOP_ALL_EFFECTS]; - hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); - hid_hw_wait(hid); - - pidff->device_control->value[0] = - pidff->control_id[PID_ENABLE_ACTUATORS]; - hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); - hid_hw_wait(hid); - - /* pool report is sometimes messed up, refetch it */ - hid_hw_request(hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT); - hid_hw_wait(hid); - - if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { - while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) { - if (i++ > 20) { - hid_warn(pidff->hid, - "device reports %d simultaneous effects\n", - pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); - break; - } - hid_dbg(pidff->hid, "pid_pool requested again\n"); - hid_hw_request(hid, pidff->reports[PID_POOL], - HID_REQ_GET_REPORT); - hid_hw_wait(hid); - } - } -} - /* * Test if autocenter modification is using the supported method */ @@ -1320,6 +1362,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) pidff->hid = hid; pidff->quirks = initial_quirks; + pidff->effect_count = 0; hid_device_io_start(hid); @@ -1336,8 +1379,6 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) if (error) goto fail; - pidff_reset(pidff); - if (test_bit(FF_GAIN, dev->ffbit)) { pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff); hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN], From patchwork Sat Jan 25 12:54:36 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: 13950372 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 F39A42080E1; Sat, 25 Jan 2025 12:55:14 +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=1737809718; cv=none; b=ZVWnldgS7PYIStov3Y1a/j7TfxOrJAEYIVbRRmaPkVnkfZNWwEmktcg7OSFsM0UOKl942q3rypTS5Wr3kVxsM+qX9Lu7kHIg0/d6KdhaEu2MsrijvzLaOLV+QWFIxjMRu40dvn6fwNvVf5yNan9XYviDyO2b/DvMRB0lB1b8LAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809718; c=relaxed/simple; bh=77PSDrwLmmq4FWQbrc+YH5RAdDh5nE1TbHTRgCw3ejQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eZLAzgrXVi+Dg0qLyugjuug4IPG938SiweP3Q0/CTw7UtxBJVHwNfyHfrBBOBgPArKXniQGVMS/tAPbN2h7URqRvAFAJp+YbnMFu29+TDxw28zZD+Qr8SMkGGU2L8GpSeT52cNX46lhJ2exq8ANFY/+6GZSTnK1jsf0knFRztBA= 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=CXYg1kzC; 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="CXYg1kzC" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5402ec870b4so448722e87.2; Sat, 25 Jan 2025 04:55:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809713; x=1738414513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4eXjXRn/HZloxKfWmPvwvQzBKEFXRB7blnXKlca1NLg=; b=CXYg1kzCjz+SmkvpQmhw8rUAK6KHUwKwsvg5KpA5Cbax3tt45hud8Jv/eDubC3uRfP P+x1y5xb9fF9aBKQtctIC0eG3xbqkCPyznb3aG8ESs+yXFkZoz+3T5NqtVlh/3kd/9pY jDrVTZeocZle0AAZL9e7JSHWNYf3wBQnpHsaWZ4WMLCniclgElsw/wkcHapZROliM5VM e8m3n/rsIajXi2WlqDBTOAJetA4hZF+5EIHhBszYpB1Wl6THaeBFWET4X0yEh7NZXYxC mUTPI4od6NX45JaobcAyTwBKyxfWzBPdkdi23a1b534qjTD8y2aRjTqfQm8gz0o2fgeW JcFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809713; x=1738414513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4eXjXRn/HZloxKfWmPvwvQzBKEFXRB7blnXKlca1NLg=; b=iIQmTtQM07gN4y6T91id1z0LEK9MvuMcgghh6N/ai3H9hYiDsT8NgmwCm1IADbacIH QX4iGyImpjh/RcqyKA5zucBJNVh0xbGoSnQK74eCCjCFO6S1wO3ujVjT8h77wZv0kWRi jYx9+Ld/HljycihTyZ7rqOMHZgqr/kTxpwLpoo0ae9oUC9LQGnEGU2jpXmE1gllsbYs0 yik+VLE7aAmiBHb6P6xxS0WjHhq4SAz5Hg5VmI4R1ek+9oTiL/qHxfEc4SrEki7w2+c5 2oWI7zBUoXrre9xxb7quNkcR8aOA+05rTThsdA6JltSkds7CL83fQynRH3+ZTec41alt vbdQ== X-Forwarded-Encrypted: i=1; AJvYcCU2bfG14De/raXYYUWnj5IUPaqk8dWaocKWQht2zu0Al9pEqShxEJBRBx2QF8qFXolwAOjOXB6NB7rR@vger.kernel.org, AJvYcCUZZFHt9xMmirWRda2Yvy3Bsb/g2ayGVrPfBCRNo7RS+qfqpF+I7A/xIJ2WLju9qhKfSLqi/yADR5GzhA==@vger.kernel.org X-Gm-Message-State: AOJu0Ywgh0iHwphQxyZsTG9yeT9voYxuEVJzAUMrSR8rj3UXTjTjVhzS Tb1HiJbg3umqrF8s3WTGYsFBZf/A4Xrq3dMwCBmvkCsMQ8lNu+ZC X-Gm-Gg: ASbGncsAf/HX2iCwwAQzD1IuMd8APsg8u/0SgYdRHBNTbivHSVJAlWi7Ok7Yju2Urx8 xdmfR6iuTRX1FcS9kCQUIWswClcDgqMwERvYvjpiUlRejeBLWhKJjRRHdzMlsjmn9dHnzZSAHzm anM//Vl6fX3mVul8l6rv2/05rGnrqUMqhUzJ+8+v6SyWfv4gDTl2qjIaUZ1IZQ27DbWKtSaZl+L zLDaEhKRAZIzK+aIn3NvqdqzE3Y3RVA7sMpmktIheQhi03bfRsqJcsnd2nUgOQZ3MV993H3yVOu 0akOUel+R9QnKXQIi5ZJvJiHfRFQfSDATVmb1bKxyxYQgPo/PC0= X-Google-Smtp-Source: AGHT+IEU0g9uVUM5QqmogXn0w45VpJrTZoEbVf0PIhL6+xyN3OwcdYqdh6WXlLKtiKON4ZSmOLlW8A== X-Received: by 2002:a05:651c:b0f:b0:300:3a15:8f18 with SMTP id 38308e7fff4ca-307586034dcmr19545271fa.0.1737809712803; Sat, 25 Jan 2025 04:55:12 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:55:12 -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 v6 14/17] HID: pidff: Simplify pidff_upload_effect function Date: Sat, 25 Jan 2025 13:54:36 +0100 Message-ID: <20250125125439.1428460-15-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 54 ++++++++++------------------------ 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 689bf516ec55..f6dc6db0b59e 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -771,48 +771,26 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, break; case FF_SPRING: - if (!old) { - error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_SPRING]); - if (error) - return error; - } - if (!old || pidff_needs_set_effect(effect, old)) - pidff_set_effect_report(pidff, effect); - if (!old || pidff_needs_set_condition(effect, old)) - pidff_set_condition_report(pidff, effect); - break; - - case FF_FRICTION: - if (!old) { - error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_FRICTION]); - if (error) - return error; - } - if (!old || pidff_needs_set_effect(effect, old)) - pidff_set_effect_report(pidff, effect); - if (!old || pidff_needs_set_condition(effect, old)) - pidff_set_condition_report(pidff, effect); - break; - case FF_DAMPER: - if (!old) { - error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_DAMPER]); - if (error) - return error; - } - if (!old || pidff_needs_set_effect(effect, old)) - pidff_set_effect_report(pidff, effect); - if (!old || pidff_needs_set_condition(effect, old)) - pidff_set_condition_report(pidff, effect); - break; - case FF_INERTIA: + case FF_FRICTION: if (!old) { + switch(effect->type) { + case FF_SPRING: + type_id = PID_SPRING; + break; + case FF_DAMPER: + type_id = PID_DAMPER; + break; + case FF_INERTIA: + type_id = PID_INERTIA; + break; + case FF_FRICTION: + type_id = PID_FRICTION; + break; + } error = pidff_request_effect_upload(pidff, - pidff->type_id[PID_INERTIA]); + pidff->type_id[type_id]); if (error) return error; } From patchwork Sat Jan 25 12:54:37 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: 13950373 X-Patchwork-Delegate: jikos@jikos.cz 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 1AD0F208983; Sat, 25 Jan 2025 12:55:15 +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=1737809719; cv=none; b=pdQASH20saqowyOMWeE08pu08IDaZUmB5NY9POKjRczzsu9A24QxoxedVEiq8hlY7KgcvMTo+wCUMSwtMzlGDwGWOSqDrsKhoVWhlILzbmngYN6eMmjT8ELQ30YW//nFW44V8TmvIqgp75BR6nRT1KYv0rMpyXWCgcWYmUOZHR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809719; c=relaxed/simple; bh=Wgx/z114BCNIXJeltqTlAJtNMYqVVfI/6qj7EN01q7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rGXqo/kgvoCA0wYEqI1CmUV0+56sigX4Hy+f48n5MHjSRqmdRIFKsD7qvJWsHFFtNKyRAqKH+UPs26IsDF1iajHROHUbG6gYDzLUTIr5XcrurITgUabFI8mqr/3iQerQnjufbQcAEkomIXOaQSdBNMHQEijuocUtT553ZkKDimE= 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=R3zBapY8; 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="R3zBapY8" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-53e36a1cf4fso497424e87.0; Sat, 25 Jan 2025 04:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809714; x=1738414514; 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=9F0g5M+5UOOEmkYaBzky0xN1+z4m67WrZHskKFwI6VE=; b=R3zBapY8MuoB6LvEvW5eWA4/F+wx3inqrM77RmPLpOrfWhk4mmGS1nw3Jvd/Hqktul 87KDcTFtVGb9QItDWsxXwv2f2fyxSJBWmG6t1/O8cXfAnpDuew6r17kVyvWYD2+Y/Z28 nPz4TLOL9UcRHdjY1B7ohnzdq+Zc422dDMnI7IZAxiqnHRImNmoBLbQZHRVr9RV/tBSr 8ne7YcBfiy0dBx0wW0uG4baMsNbBhmXuMCtmaLMLn/KW3nfY8s5Rgb40JzARqBKvP8jr L9wD2k8Dple3hNxrF+VyYrlJm98/l0uQFtH+i0qMqHJeAFp8ZIk6ZkxszaXBoxc/9Ot3 GVIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809714; x=1738414514; 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=9F0g5M+5UOOEmkYaBzky0xN1+z4m67WrZHskKFwI6VE=; b=I3oCZM/67iId+JtJeYNTsbge+UfN9I30EhLfAl5suOzb0fnA/3p5otGyFr9C1Hy6z8 o3SqEnm0nZT3ykMPClKwTIeUYnI3pFCwoNQKaloUY0LIfl3DlqZwZDPTUY97Im+yqBUT oUSpA7okCzmCn+H0SKuNkaiMrwYH+LimaZuVk8ZCEKuQT/ZpUH+4hgeG5WRloP6PLqDv JFotgfwC2Og8zwlc23rMfhuKvYWZMCUzMFxMR19n5mg3akV92DTr6jAMdVz9YDZsJG+e d1a6bEOBOsFXb4ybdWdYIAhfA/SKGXSubrTlazlXOCOncf3irSw0uZvUi26SDx2+1yYO q0hQ== X-Forwarded-Encrypted: i=1; AJvYcCWRleQxUY1pS4V+bjMbMwpuTD76WBFUHw8wPkwYIe45YN+GmK/kauKhht8K2euqg1urs8JYbnOfwp/9BA==@vger.kernel.org, AJvYcCXUZ+NuxMYvgjDF7x+3ICyNNllIP/yVfSw2oQ+lnznli+yn8sT2MHcxkf2zr8I2ygK7LELUiidwi4jB@vger.kernel.org X-Gm-Message-State: AOJu0YwS9gJiRfsvmJT4PvLtrxpamC+6FxTDuFjCfnI7hGCKv66vpjw+ eSsH7AqSjyiqVXBZZswH96hHqp6sE+NzhI80XGN3Kv/2TrcjymKs X-Gm-Gg: ASbGncuEbGdHXRIg8w9I1KlrZTFGQu5hKjDodNbSTsVqF0Anr+QyEuWrCSG4qxCaMrM ewOnNLKq62nbXd0VR0wFDtel7dVccJ24l4Ki4sd5Xs8QfkaK9qOg3PUxE49gxY/mV0nXODiKshX Lv3qihtdANKZqJSVk87b7pnbZHdLEnWKqGETQxcVZ48D5bMVWyBQmkZv5iTVtHmVsViPottuHG2 A3nPI3G7hmQrvVyKHv92JtokzmVETQ1KdTYtWsp/qx7EKPlOUVyNFCpkwPSh7qn6lx27uh/XkRP zyBZgdSVuOomlwXFXQhCaCG2Uh6ThYQNpxWqmf93eX3s6xKaWvM= X-Google-Smtp-Source: AGHT+IEt52SjdRTKBTTtjGa4lxDSIC15hVlODiq0PPiqYS8zUxQKYQrR9XmM/XSZvW7Ix2Px3g9yog== X-Received: by 2002:a2e:a587:0:b0:300:33b1:f0c8 with SMTP id 38308e7fff4ca-3072cb55835mr41747491fa.11.1737809713996; Sat, 25 Jan 2025 04:55:13 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:55:13 -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 v6 15/17] HID: pidff: Define values used in pidff_find_special_fields Date: Sat, 25 Jan 2025 13:54:37 +0100 Message-ID: <20250125125439.1428460-16-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 --- drivers/hid/usbhid/hid-pidff.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index f6dc6db0b59e..c5bd4ca71e93 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -48,6 +48,14 @@ static const u8 pidff_reports[] = { /* device_control is really 0x95, but 0x96 specified as it is the usage of the only field in that report */ +/* PID special fields */ + +#define PID_EFFECT_TYPE 0x25 +#define PID_DIRECTION 0x57 +#define PID_EFFECT_OPERATION_ARRAY 0x78 +#define PID_BLOCK_LOAD_STATUS 0x8b +#define PID_DEVICE_CONTROL_ARRAY 0x96 + /* Value usage tables used to put fields and values into arrays */ #define PID_EFFECT_BLOCK_INDEX 0 @@ -1047,23 +1055,24 @@ static int pidff_find_special_fields(struct pidff_device *pidff) pidff->create_new_effect_type = pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT], - 0x25, 1); + PID_EFFECT_TYPE, 1); pidff->set_effect_type = pidff_find_special_field(pidff->reports[PID_SET_EFFECT], - 0x25, 1); + PID_EFFECT_TYPE, 1); pidff->effect_direction = pidff_find_special_field(pidff->reports[PID_SET_EFFECT], - 0x57, 0); + PID_DIRECTION, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, !(pidff->quirks & HID_PIDFF_QUIRK_PERMISSIVE_CONTROL)); + PID_DEVICE_CONTROL_ARRAY, + !(pidff->quirks & HID_PIDFF_QUIRK_PERMISSIVE_CONTROL)); pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], - 0x8b, 1); + PID_BLOCK_LOAD_STATUS, 1); pidff->effect_operation_status = pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION], - 0x78, 1); + PID_EFFECT_OPERATION_ARRAY, 1); hid_dbg(pidff->hid, "search done\n"); From patchwork Sat Jan 25 12:54:38 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: 13950374 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 2A30A208988; Sat, 25 Jan 2025 12:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809719; cv=none; b=mIA0ScE/iLrAc0hfJvkOU5IMdt9Kd/ZWydoibmNTipjai0Ua76xFCFNDcVUo0/SYoc8EPGyJEzP2MHb1J0CtXM0oLbei9fU09TS9FZCa5kyABSLhEblVNDohzQGm/7vDB4FnqF2mwDO60+hV+XiWIy5OhiPgHiBfHRO2HME3U04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809719; c=relaxed/simple; bh=M+MxB3qVQrAgmeCpTjvIljYDA6fCHx9U8AlzZrJ08kc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nWo6D0JFxnR4nzHUBgJo3RfuJnzuC2JSPfRRqsAb0J8N9K199YUWfFe/+7lilkRFMJ8uL4FEOMiZBH2gB0Q2L0z4MBfRzuUm6TcI4gpzMI3LA+1TtDy0u3LfcIpPwJfHKKasn1uokUgY93VAkLT3n3FHL3EpvwpZRp34d12jvAw= 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=LiVMmkwJ; arc=none smtp.client-ip=209.85.208.176 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="LiVMmkwJ" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-3021ab1f26cso2006841fa.0; Sat, 25 Jan 2025 04:55:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809715; x=1738414515; 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=a+r2Q6DSnwHv5omJtGfuLWqdgG8O2MQmmJqll2lu7xA=; b=LiVMmkwJr3mpKvSRW42VCVpYyolHPeivR1SCHgR84djkdHGCjiDBO5Vfg+LCna5YFZ 8aisKoLg5QX+pmbQM3KuDC8WgKLE0l00VQ4c6SZLzqem6Yx8DeQLglZY384aYOkpoT+T 4glcn0MQ1dCoQ5UlgMfJbAjUGqakwPp/pvhO2dIVwrw7R2fETlPuBqyS5O3OcGv061KA ObqFqqdfOwGKOjNvPsdRsQBaKAD+CpOa4YcKyU2K91QknvwyPZrGc1WK4OTSWKLzD1oi ZhRnvgu9INQYsQfS5CByCppm5Y13VbLbvHkKVG+1L26kN1WpQTzfpbkuN8+Th3nLCieJ YRmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809715; x=1738414515; 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=a+r2Q6DSnwHv5omJtGfuLWqdgG8O2MQmmJqll2lu7xA=; b=BcMqKLsfn6WRAXxRVS64i+ubgZTuA7kiJRtZUHygniSsS8O2bhfM517Vs9gpy8zg/H Hsr98c7OBoxCxsskuthIONcv1rQAHFUz1V3pguo8yl2Mzxl5btQsxqixluTLWxZxDk11 FDGUO9ezaIlz9a+Ct3YNXwEu+BT43rAgahwV4ldXgWEoUUMRcVig5JL8JV6QMAxcs/Pd 7ofFkk/tmUht3eZs88v0CTDkuWvV6YypcpmyPHrPFYXSQVQC24viNi95H7qiBUHFh4rz MkAlrPIRr84i0EkFqb9IWkdlk/9dCXZpnuHfxPT5khsywYEtzbJdD4+aj8Wd8W5d4koo kH0w== X-Forwarded-Encrypted: i=1; AJvYcCWPNzO7n26spMoYyu+qX5N5/E/1WWANL3BrYBZBkk4rF1qPDApGnH7ndE6bKXdtMZtxJViWdh9RN2/Qow==@vger.kernel.org, AJvYcCXshGxBkCm/yBrjYx5+JmMvtAMvCjSljUOGtzOe9XG9I7sb1qyITrXrrZuuCGiSQaZvL1OpwjPw3egc@vger.kernel.org X-Gm-Message-State: AOJu0YwHVe4K43aUH3yj+q8vJ7AHJn9X/bF3itfaMA2VAB/Bgw8LXjyb Khy9PGeWuRAx398U+WT43alEu04xXsPog5rQzpnEAFA9UdW7QOz+ X-Gm-Gg: ASbGncsr/CabAlX7QmdJENmQwKuUVM7zdz9vs9Pw2M0DluUBd+44cUHpYPvx6T280gP cdC9EFw1cu+MhStZRuY0HQXmBFellWl/QV1a85VRcICd3Uu97tP8s6aFaLK6xCSrwVHjIFU8Y5K Yln+7pjlrQuRXPi+taP7sbOZ/QPNScBESku9VnGkxrYiHcBwawKTJfPGKkyOQEhDxJVbuLLqtUt MxhPMmK/CGjq7Qb5qnhbHhs9ENoMQEXitO96+jdFvTlVitNhWfjqxC3lIWnXAViEOXwXrNVFqkb dtPz4pCd+LlBDDWFM9E9XeqP8dpUDDX0c+CJQaXsmaUUHDPXKec= X-Google-Smtp-Source: AGHT+IEtIg8/kWAmHihsS8YLxHAJmOQLrTPWA2wIPIlxwyt6gwqfml7EzfpiHwWzOfsyOyV974Pt/A== X-Received: by 2002:a2e:b8c7:0:b0:302:40ee:4c33 with SMTP id 38308e7fff4ca-3072ca6a302mr40729471fa.4.1737809715143; Sat, 25 Jan 2025 04:55:15 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:55:14 -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 v6 16/17] HID: pidff: Rescale period value to match device units Date: Sat, 25 Jan 2025 13:54:38 +0100 Message-ID: <20250125125439.1428460-17-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 plethore of units for PERIODIC type effect period while Linux Force Feedback API only supports miliseconds. Read the exponent of the period field and scale period value accordingly. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 37 ++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index c5bd4ca71e93..5ada097c967a 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -22,6 +22,9 @@ #define PID_EFFECTS_MAX 64 #define PID_INFINITE 0xffff +/* Linux Force Feedback API only supports miliseconds as period unit */ +#define FF_PERIOD_EXPONENT -3 + /* Report usage table used to put reports into an array */ #define PID_SET_EFFECT 0 @@ -231,6 +234,24 @@ static int pidff_rescale_signed(int i, struct hid_field *field) field->logical_minimum / -0x8000; } +/* + * Scale period value to device's units from Linux default (ms) + */ +static s32 pidff_rescale_period(u16 period, struct hid_field *field) +{ + s32 scaled_period = period; + int exponent = field->unit_exponent; + pr_debug("period exponent: %d\n", exponent); + + for (;exponent < FF_PERIOD_EXPONENT; exponent++) + scaled_period *= 10; + for (;exponent > FF_PERIOD_EXPONENT; exponent--) + scaled_period /= 10; + + pr_debug("period calculated from %d to %d\n", period, scaled_period); + return scaled_period; +} + static void pidff_set(struct pidff_usage *usage, u16 value) { usage->value[0] = pidff_rescale(value, 0xffff, usage->field); @@ -252,6 +273,14 @@ static void pidff_set_signed(struct pidff_usage *usage, s16 value) pr_debug("calculated from %d to %d\n", value, usage->value[0]); } +static void pidff_set_period(struct pidff_usage *usage, u16 period) +{ + s32 modified_period; + modified_period = pidff_rescale_period(period, usage->field); + modified_period = pidff_clamp(modified_period, usage->field); + usage->value[0] = modified_period; +} + /* * Send envelope report to the device */ @@ -392,15 +421,11 @@ static void pidff_set_periodic_report(struct pidff_device *pidff, pidff_set_signed(&pidff->set_periodic[PID_OFFSET], effect->u.periodic.offset); pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); - - /* Clamp period to ensure the device can play the effect */ - pidff->set_periodic[PID_PERIOD].value[0] = - pidff_clamp(effect->u.periodic.period, - pidff->set_periodic[PID_PERIOD].field); + pidff_set_period(&pidff->set_periodic[PID_PERIOD], + effect->u.periodic.period); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], HID_REQ_SET_REPORT); - } /* From patchwork Sat Jan 25 12:54:39 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: 13950375 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 9EA66208989; Sat, 25 Jan 2025 12:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809720; cv=none; b=eu4ZMhYxM7UMLbLDvY5OAawPwSYRAKHV+L8QpsdSgWHRdhg2cRSAkmHmbkSX5mPhF/bTaz5/I/kk4mq23W7eKwZekjzyK4NoCQucJDhQISdtX0fmfWz4JZM8HoqfBxudmxX8MVy8fX1j6aFq8J3RzOQ3MxUM554fNpurnpdthzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737809720; c=relaxed/simple; bh=BpcDj71JhMPvMyeASILOGmRF1KyRQ+8x/f2HGcPJcSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vCPf8+tnKlDhZXrAh9CZIGNHdUIqTWSEp9bVeIaibDVtPYuvsLx//Knai4sZOH8jgP4HBQccL9pd//iDguVpRfDE4CQpN/s804WFiQS24lY2eaE3DKfDeSdXDRD7/8Hs6N+wxoj+DKgVGj4U+mpyNZYHUIYw9wzP7ZRq4XFFhQw= 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=QPeNqB/A; arc=none smtp.client-ip=209.85.208.182 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="QPeNqB/A" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-3003ae21db4so3249051fa.1; Sat, 25 Jan 2025 04:55:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737809717; x=1738414517; 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=Ef1OPYDeIgI/wuc0omzhDlsfW60n85scRMgVKKIlzyU=; b=QPeNqB/AScauGt8W7be5b0T1poTJjpIkidap+ET8y9NdsMu7Vo33fwhFY+7pbMLPQs CvyqMLTTHmqq5Bhjzco2Cerqb27z7coiHhSgXvBOWZFy1vRdBOpCgtBWZmNnKy89npXk KOW25D3TqPOZOIP5rMIMsgFk5MGEvzTs97DD4IjBMrU6w1qTGoHyQIcx+sH7WFDAaZub EakxhamBrDWoYnbSOBFQRNq2V/crCM/kBJdgb1O6wwQE/i+VBYpZBBTp5mFNZlyh2TFq amyUzGBuJ1rw5I03FYFfdOiqj9BRCsZ7u4xS9lHLvDFAqdwWLyPr+5eS3KApw6lGBpIw xzkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737809717; x=1738414517; 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=Ef1OPYDeIgI/wuc0omzhDlsfW60n85scRMgVKKIlzyU=; b=M9Q1Sq2PAGvcU4navZ5kJdPyMMueEiwWMckqlHjkLSveKvUMAKrrUFHbQgJrfd1L5Q iITui71NUwhgN+gcknBjvRct+uRRtPI2cZNSSGjLinpt0KNs0CTlrZlkEpbUkaazrppj hbBLmn8DYY5XimPDzSvWcxa74zU08wmQ+OX/b7Am/4BmU4vExaCL+QN+7XK0XtonKe/X NzfmW/PcY8cp09NZ60kKyNLnopISYaXmxOAAqgzX+mmw/HPNtvQXrkHv6AhLmvoT3miO FGNmt8QhktGKviFMUk9myQS1JoTCYsMVxZq8oBSapmUSikGw1tQ9vjXv9wbd5v4/okHc Bdsw== X-Forwarded-Encrypted: i=1; AJvYcCW4po99kkImuCudseUd6cgsy6l7hdJjjoL/CU0hIhVGHdgy7GThIdJJHSt5slS37qC4F9ZVzplZ6BVU@vger.kernel.org, AJvYcCXWLJyhqp245Lci79aqkUCFccZdZlYxYRsh8oRevCaWgTs6H0pO8qlJVeq3ZeC/kf431JQheEcsRFoibw==@vger.kernel.org X-Gm-Message-State: AOJu0YwRBQftYTK0UKiI4Mn05yYiXYjOyXegOfHXPp8DRwbaXJ+Rt58l CIi9FOcSUyMNDmOqCAyebUx5LK0Gv1EGnaVme4qhYjs1bu+n/yb1 X-Gm-Gg: ASbGnctIxlVlxJVzzxWcO2HqaB/J7ZEYqKPPF6PR6bPcUNb4LaDLUK9rEnXzWf50X5N 4bk+p1WnolHI1XB2nVHKb8xqJWeo20p/zmfw3iqvTvIRJeUWkPF0t1mu3j/Uzbbcrn/3FOrJfqc 3KmNXJuf/mjn+T0jjQCvOb3cx7HjZumRjtmgPxwWMNfDUWGNjSOrrAs4BSMJIe2FNFtsk8clhcZ mpiLvDFcH9+bUZrMMjzm/b9MlIiE1w2td4lBzgAiLZYFeWw0lvjpG5lOGrBNnrpCH5yUPpXbesh 3CgnKGWlg6Jm/DJHlzKB79kFKl86BlNA2OKIFfqDOx5YuvxZhbqzYvla3YKe4g== X-Google-Smtp-Source: AGHT+IFsJSiSHeN/z8BfWQPszgzCywuNz/G9aJ5vcGDbxjP2XeB6jLQLIfKKCKKW6B9AvinvnMPjJA== X-Received: by 2002:a2e:a984:0:b0:300:1975:97c4 with SMTP id 38308e7fff4ca-3072ca63aafmr37981981fa.3.1737809716381; Sat, 25 Jan 2025 04:55:16 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3076bc1981esm6960701fa.75.2025.01.25.04.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 04:55:15 -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 v6 17/17] HID: pidff: Improve ff gain handling Date: Sat, 25 Jan 2025 13:54:39 +0100 Message-ID: <20250125125439.1428460-18-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125125439.1428460-1-tomasz.pakula.oficjalny@gmail.com> References: <20250125125439.1428460-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 easier to set gain from inside hid-pidff.c Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 5ada097c967a..9b8615197d5f 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -525,6 +525,16 @@ 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) +{ + pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain); + hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN], + HID_REQ_SET_REPORT); +} + /* * Clear device control report */ @@ -852,11 +862,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, */ static void pidff_set_gain(struct input_dev *dev, u16 gain) { - struct pidff_device *pidff = dev->ff->private; - - pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain); - hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN], - HID_REQ_SET_REPORT); + pidff_set_gain_report(dev->ff->private, gain); } static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) @@ -1391,12 +1397,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;