From patchwork Mon Jan 6 21:35: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: 13927839 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CFAB1DFE38; Mon, 6 Jan 2025 21:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199348; cv=none; b=F39lmxlKwpVIom+J6CGEcQsDXBBU1XtbrrmoczgokBeZ0hGsn9Y/z9Y9TlvbHGBw2ppS/YQSS8S/Ino+YIcYIEiQRFaEuh3colDHv8gbDKU1HsRw5yWsKr/DIQKT2Xt4ZnW+QTsPOTHzrovBmrJZmF0rtIm6OTof9JhtHdRbsJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199348; c=relaxed/simple; bh=60aSOMQx14zfMVGYITpU0cwL1JQM2IC1G8kgAFjv5ys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K2kL2NK0g/yFAHElzbvBFOewPIM3SAqMGparYNf3xfz3OcryRQO463TdAIhf+0KWTPrQjhDgom1JTv8MZ9DCVUa2bvbViGnud1P+szOItCD6ydNkFIYiGccddC72P5Oisa5GHKAB7V+oBiZF6e/StoSfGUMyjdyDOghxh75JEWo= 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=Hj0IrOJb; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hj0IrOJb" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d3cfa1da14so3133599a12.1; Mon, 06 Jan 2025 13:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199345; x=1736804145; 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=ZMTdGnyyJWXuH6aEDEPHe6IuTncIDqPC0Rg1e/KX1X8=; b=Hj0IrOJby189fvEKXMszYI5+r8/j07iOFh40fmuh7nrfMp2KSkRUKArV8irJr4jaxi iObQOSol/3vkLXqVaNhpLixDloePgBEPn92oFU98HlZbA4VZ+d1oCbQfCMfn+Zf3yu0w 4U2bwUPZwfF1r6BPL1cOsGfVQuarahAhnj3aIukXEtG0jWlvW91EGdC3O7nh6bN8tO40 u05kf2kCCRg9aSGlLRNXF1Pm+00HzFU24UC+hEElisBbyiGFVlppzkk4x3F3TUYygB3R 7OxO4oq8AU5BCwbHdUaye/Xrxo/lvQ0xp13veVG5duqkvXTP9aAmkWC4J37dYkzjHQX/ gLxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199345; x=1736804145; 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=ZMTdGnyyJWXuH6aEDEPHe6IuTncIDqPC0Rg1e/KX1X8=; b=DvhGw8h3vh7EkhhMx/Kt04MASKeyC4nG3SUO/eJNqoAI/7YOErfKtz2TS/3aGVNJIG 3IhtXya6bJDivK2UsGJl/v+j9IHZUS/1CPsLwmqXuKwFH1SmMXFcgVetc2D1yKQVy9Md 3m+rlnVSM2doUjJ+uZ1HH7/Tyzyp1WhbSJcKBgbMjmZzt42bk/BCkSQ3pi+p2hA7ke00 0wlu9Af+/x2GWEECMYoZV0giPk12jkKzQZkaj1nYSs+7c6S/+76F2W5+XnxMP2Y985Z5 ebCkY5g0M86jpMNhvyBwbpKHdpmQ2c2ES2f4D5U9dDUEpo1gL5Z4akngLosjMr7V8yzr JKcw== X-Forwarded-Encrypted: i=1; AJvYcCX90He3otxm40KAdipiCkSuOsf1m46SsalyeUPXBCcjoV3MYOxtTXzLDH9iC5owvfLslklu9Sc1ITU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7MJygeXOn56qN2wY+R1xfKmmqvkw25TLiNJC7LAaoyW0V9ZJf l5rD16JEeCQp6wyYNjD7PbXU9qWkzEwCFi1ee7E8zIG7vh/ml+p8Tfb3nNxG X-Gm-Gg: ASbGncuPi/dAnYVcTk6zWHFNi6SPzfC7T+bgLvv7CgsTgQBHxr31LwF3uvYA/CrLGDx xm1vqE36ArvfUIpyJ2KgfNCAWxk04kjF18uLnBYNIH6y6UufrnSQC60Nln9wCFGinOgZMeRUTvj aiAUz8jmVcI5Rhqvs41DZPcsDOi49l+0RrC/tmKYLl+mWIKxWJWgFeKJ0jE/jF/Hs8pi+OfQ61E lzkZNDoiD6XqeUQI3YvxjPwl6NZ9jvu1XC5kgeoV1EUcmttLdnTB1Dc9KfLNZxhGueoPIKCzplV XyUOTTX2FBqLYJMLy0unKZT5dbs= X-Google-Smtp-Source: AGHT+IEzCYYiNd745kQpx4ofP4CyvT4uBaER669kvtUAhW55t9aMvo8vYfBByQTR6sHxJ4psV+dT3g== X-Received: by 2002:a05:6402:274e:b0:5d0:d183:cc11 with SMTP id 4fb4d7f45d1cf-5d81dd6422amr19450229a12.2.1736199344696; Mon, 06 Jan 2025 13:35:44 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:44 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 01/10] HID: pidff: Convert infinite length from Linux API to PID standard Date: Mon, 6 Jan 2025 22:35:30 +0100 Message-ID: <20250106213539.77709-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux defines 0 length as infinite in its force feedback API while USB PID defines NULL (0xffff). Most PID devices do not expect a 0-length effect and can't interpret it as infinite. This change fixes Force Feedback for most PID compliant devices. As most games depend on updating the values of already playing infinite effects, this is crucial to ensure they will actually work. Previously, users had to rely on third-party software to do this conversion and make their PID devices usable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3b4ee21cd811..3899d72a0b02 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -301,7 +301,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; pidff->set_effect_type->value[0] = pidff->create_new_effect_type->value[0]; - pidff->set_effect[PID_DURATION].value[0] = effect->replay.length; + + // Convert infinite length from Linux API (0) + // to PID standard (NULL) if needed + pidff->set_effect[PID_DURATION].value[0] = + effect->replay.length == 0 ? 0xffff : effect->replay.length; + pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button; pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = effect->trigger.interval; From patchwork Mon Jan 6 21:35: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: 13927840 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE4271E0B72; Mon, 6 Jan 2025 21:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199350; cv=none; b=PVvUbZCsraikzmTMRDGDbpdCGn/9DHEb1tApzWHX9xUFc0JxqoG7owCF0GdoIjNrbnrLbtAGWx3XfXs3ApZYDktHBObg4MI7iPFWZ727fsvR0uEMdbw0WA2/Wb7Td/7y/y6EOdHhhAxMlc91XfUqiaYxPb7w9V7lss7pZLVrPUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199350; c=relaxed/simple; bh=tWq+ZnBjlOupEjtG5PBxOjtcCachtKjWc1EONIVj4X4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=awggVdDEbUYIZIIGIVyYsPRgoIc+8LQ/XQVP91jNqoxw/Rg1RNjqqDmnmTrZ/cVVWGu988szAJ79Sl8d0/ZFtml6K7gJqTZ/ws/lSRgalHxtA0348Hu3aoydzDPSvu21/wD/ZdSfWM7tmmoMDiPQXWqfMPhkqEKFnrn9SLXjVQ8= 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=jlLzrLyG; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jlLzrLyG" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d0ac3be718so3279925a12.1; Mon, 06 Jan 2025 13:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199346; x=1736804146; 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=2aG6QxwL2dLzIzlkegu/7XX/7ENaDG1aCgGKgLUZHrA=; b=jlLzrLyGfssYgj5YHObPUWpgCndmwnhtSz4eonMRTU9+EH9kDD3B+GjcWKjwXAzOI6 /ykeALujEHf21VbReE2hLZ1b9pLGwIhOtlWDllWtJjfTU1qbgYKe8FMoETppj9AJnffZ dfcQjAqIglH8mkYz1KPZcmsg0xy0d+O5WVEBth0g74LEbvdH7vM15kMMfe7HM1+iYPq9 FPZNtuwshO9s+y5cHkHHF1Kwx+JLmkjTH4FEzwyPmZFvesn1vg9PagVQ7dB2cViD/nz7 UC6NA7ZOHoQa/+S//OxvOfQonzByvHqpRbJSTo9xJgIW/iDd0xg91KSgEqVOOegqBDvn 1Qdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199346; x=1736804146; 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=2aG6QxwL2dLzIzlkegu/7XX/7ENaDG1aCgGKgLUZHrA=; b=QO0xbrt+Adu78mLXwk1FvcESRFRSSs2RGbp2yyoLZYskJ27M5e0Zq06XiM8HviENB+ ORH+RhnrioFZ+kYRTu+4Lvf7j5GIJuubM3pmsbwxViLwbw7lMoPAsS0eIFMEdsUQGwL4 LAjdhGjnvWRCVZW293Fs1KOihyaGS73bT1jQotIqQ33iKJHMoBTN2YdDn1OZUjpXeRMv txuUnTSGwKK2oMvtzHbWR/LZXjsIaWtXZWSmzF7DZvM6Q9kcumz5E9l+oJf8e/ky8rrM 7VVdY/vAOIiVYvpmCLd0AOv9CVyyo+rAGz11fe2C7TL6ANDlEee/kxowOzuigq2MPivZ GaoQ== X-Forwarded-Encrypted: i=1; AJvYcCWiTbyzj4/90MXLveOL749BDizihSduXAOfi1czHKXLZpyXLS11wz/czsurSGWOOL7TEZmTl+Y6Ttk=@vger.kernel.org X-Gm-Message-State: AOJu0YwvDDQIrUP9Bk1pO7oCjv3t+o9jVrtPCgDdvQjxNMRm5QkSrqtC ShbeWv1p56zFEBPAZVVWxM8gR/QDdul3lVjBX/qKaTg2UeEJlem4tS+cBO7a X-Gm-Gg: ASbGncv350ur/Uom6FoABlNyMd6fXhKFz6Y2UotehDq9I3eLrhx9UWvL+w+kLwYt25G BKEjiTs6t26hX5VFbEBkYtTwI/i9teiw9U9/Lm5PZCV+gR6K1dEiN8N7+DJfDzeoPaO9MyF5V+q gmDVFqC+4hSwi9onNwgBiCABkQGQyrGCVtV9si3MXfIwBPnsV2VAWox2QwcZrArAibC1FZdK0cP I85WKuEo6BH0kd4aHZ/d8c6FsmNaE8k0oLfg80UUqKOEx3tDsQEUcsxy5PpegU0AH5MRrys7j73 0wGqDa6JxqX0BDC1xEGJOU/KbUI= X-Google-Smtp-Source: AGHT+IGk84mkLY+gDCWva3727Y8Weq773UelfPge2HEn5EREpCwHdkyn3P82x/mw0iQjY3F/djz/aQ== X-Received: by 2002:a05:6402:5109:b0:5d0:bd3b:b9a9 with SMTP id 4fb4d7f45d1cf-5d81de1c38cmr21554449a12.8.1736199346071; Mon, 06 Jan 2025 13:35:46 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:45 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 02/10] HID: pidff: Do not send effect envelope if it's empty Date: Mon, 6 Jan 2025 22:35:31 +0100 Message-ID: <20250106213539.77709-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Envelope struct is always initialized, but the envelope itself is optional as described in USB PID Device class definition 1.0. 5.1.1.1 Type Specific Block Offsets ... 4) Effects that do not use Condition Blocks use 1 Parameter Block and an *optional* Envelope Block. Sending out "empty" envelope breaks force feedback on some devices with games that use SINE effect + offset to emulate constant force effect, as well as generally breaking Constant/Periodic effects. One of the affected brands is Moza Racing. This change prevents the envelope from being sent if it contains all 0 values while keeping the old behavior of only sending it, if it differs from the old one. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3899d72a0b02..cf8163d92ea4 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -261,10 +261,19 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, static int pidff_needs_set_envelope(struct ff_envelope *envelope, struct ff_envelope *old) { - return envelope->attack_level != old->attack_level || - envelope->fade_level != old->fade_level || + bool needs_new_envelope; + needs_new_envelope = envelope->attack_level != 0 || + envelope->fade_level != 0 || + envelope->attack_length != 0 || + envelope->fade_length != 0; + + if (!needs_new_envelope || !old) + return needs_new_envelope; + + return envelope->attack_level != old->attack_level || + envelope->fade_level != old->fade_level || envelope->attack_length != old->attack_length || - envelope->fade_length != old->fade_length; + envelope->fade_length != old->fade_length; } /* @@ -579,11 +588,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_constant(effect, old)) pidff_set_constant_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.constant.envelope, - &old->u.constant.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.constant.envelope); + if (pidff_needs_set_envelope(&effect->u.constant.envelope, + &old->u.constant.envelope)) + pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; case FF_PERIODIC: @@ -618,11 +625,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_periodic(effect, old)) pidff_set_periodic_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.periodic.envelope, - &old->u.periodic.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.periodic.envelope); + if (pidff_needs_set_envelope(&effect->u.periodic.envelope, + &old->u.periodic.envelope)) + pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; case FF_RAMP: @@ -636,11 +641,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_ramp(effect, old)) pidff_set_ramp_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.ramp.envelope, - &old->u.ramp.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.ramp.envelope); + if (pidff_needs_set_envelope(&effect->u.ramp.envelope, + &old->u.ramp.envelope)) + pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; case FF_SPRING: From patchwork Mon Jan 6 21:35: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: 13927841 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54D621E00AC; Mon, 6 Jan 2025 21:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199351; cv=none; b=j/OEVkKhlOOBuD6EWmeU5jV3QRLvMhJ56w/jm2y0pez4W0WrOfE3GAYj0Uung517llgXvEuR+FWfDZKE/3a4xZcKZesSKp28tI2C/1pe4jQq6VoQRkk7tFeV08K9wyuwvgukRY0TnIzFLRpz9V5kRz1PMj3FcihHbymkiH1lPZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199351; c=relaxed/simple; bh=eJ/IPvw5UT6F1TJJeyixqWwLsKzSSiRHTTNylaWJIo0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jq0i+yEKtXvMBWF1G/GhRWFaouitr9hM01vOWKpyNzoBkCiHXa9p0qI7iTs5mAz20zMxy07DuaaOR+nXX3OWPQ99+3iGXk/ioqZHJSb0fQBnTEMHRrQ4r4/UFqqzccOQrY7Xyyx5+zs7tl1sq+Z62FOQX2T+ui+8hgKxKmkUCSo= 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=VX95oteZ; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VX95oteZ" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d3ea2a5a9fso2221300a12.2; Mon, 06 Jan 2025 13:35:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199347; x=1736804147; 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=6ERMQSDSSP4kaB35zxEBbEdMyWN68eRlF2X7GLXmoNs=; b=VX95oteZxX104CjbS32lQplXiiJRE9185ZUToxXsx2dy69RYbqSDKh4UFA9woBf+Fx w+tCO5zj/+p+WmvQ8U34+Ps6Pv1IqdAcQkbv21Imxf0It+PytjMFmY0KDAMiZu4wch65 2iIG8cSJ/dth7cIWld2b+DLZdSAS+xQmNRpKNm4jn1DsYlgFDSO4jnmM/Jjx5cNdS02+ Yb//CAfe44nOuOplP+6WDid+KGdEsMmMgsET5lRCPGdFk83v8xHWpYLRqixt8kFdjHYN o3RV4N+9mZR3Fbo2fSwcSLutqPnTW8o5dokYaShF4E+z7bghPvd6sZ3nw+525fPA/iUa DpvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199347; x=1736804147; 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=6ERMQSDSSP4kaB35zxEBbEdMyWN68eRlF2X7GLXmoNs=; b=sR3ypJkyKTJlyrQNIxzMQJlfpWTfJS+0Cp2V7tzeV+EDajuYct6kyGkUlkiAyczpNe NflVVPYctDEyzhC0DCSw3erfl+icAtEvjvWL+oupYtt9Ot0TyWOwk1izd3D8jWegU3k1 MrSRd1YwwQaGAm8R3Ud2n1H87fPMU1wIHmFkH7MIC+/vBNx1RnsorM0/QKEYFqd7PJMJ 5p7A+HygzF68uWjdtaSBA8tCPXlNp0d9oEjoVSjQ1S7KiFnld+GGRWAvT5w5nuEbEoD+ e50eUwGQTqMuRO4S03tr0GSUQAYGXlQdlXpT1KpoxRO3E/HcWNswSbBJuAkeIaU74qnz WbaQ== X-Forwarded-Encrypted: i=1; AJvYcCUyODoEthuKPmsXUC4IdBwuMxFAY++II0A7h5M7GzpimUHePmaso0h80mWAzcOj/zdWLP+6C4YEfsg=@vger.kernel.org X-Gm-Message-State: AOJu0YyAg0aU7/HAdRoIrz+7OVUMQe00Bx7LXUvW5LG3sy2BrDEnb1ek 9pg1yAJ5TulOjwl1vLuEmw5mmKIwknx6d+53S4gUoJf5qYkpzhU4yN1vbJR/ X-Gm-Gg: ASbGncto3G+YBmg4sVvpvwcwPLb73OY10dcrnkH2/7Sw/LCfnpFG0cT7vmb5PeXu3GV rAMm3VDRfKguWWFUOc+wsyG7d4/qI6RSMNultxoeiYeieKVF7jaPV1enSta/fwYgL3tdhBMj284 OPOiTZD2tiGxFiQJEaM2Jr+O59WWtHOkNbSRxPDNXpcBD2uITeseXmgQNyWiOEfKHcvrz+Z91aE VQxYTzvOPFEpfhcWYz0d5LexsPXOH6FzNtIY49Ny1kRAwm/d50knsj73mVDGxaWoNOFidj8I71T e9+DdH2P9hghVpoK4fn3mZs/ZFs= X-Google-Smtp-Source: AGHT+IGkC0T67Noi5JaQ8ju/83mrKDBlN+hzKnLF8YwXNSZFgYcLrXRRlrGnKvwj2B8clvzeLPIH7g== X-Received: by 2002:a05:6402:2790:b0:5d0:e852:dca0 with SMTP id 4fb4d7f45d1cf-5d81de1c377mr21066376a12.11.1736199347450; Mon, 06 Jan 2025 13:35: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 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:46 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 03/10] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Mon, 6 Jan 2025 22:35:32 +0100 Message-ID: <20250106213539.77709-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This ensures the effect can actually be played on the connected force feedback device. Adds clamping functions used instead of rescaling, as we don't want to change the characteristics of the periodic effects. Fixes edge cases found on Moza Racing and some other hardware where the effects would not play if the period is outside the defined logical range. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index cf8163d92ea4..7af7744e3cf2 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -205,6 +205,36 @@ static int pidff_rescale_signed(int i, struct hid_field *field) field->logical_minimum / -0x8000; } +/* + * Clamp minimum value for the given field + */ +static int pidff_clamp_min(int i, struct hid_field *field) +{ + int ret = i < field->logical_minimum ? field->logical_minimum : i; + pr_debug("clamped min value from %d to %d\n", i, ret); + return ret; +} + +/* + * Clamp maximum value for the given field + */ +static int pidff_clamp_max(int i, struct hid_field *field) +{ + int ret = i > field->logical_maximum ? field->logical_maximum : i; + pr_debug("clamped max value from %d to %d\n", i, ret); + return ret; +} + +/* + * Clamp value for the given field + */ +static int pidff_clamp(int i, struct hid_field *field) +{ + i = pidff_clamp_min(i, field); + i = pidff_clamp_max(i, field); + return i; +} + static void pidff_set(struct pidff_usage *usage, u16 value) { usage->value[0] = pidff_rescale(value, 0xffff, usage->field); @@ -357,7 +387,11 @@ static void pidff_set_periodic_report(struct pidff_device *pidff, pidff_set_signed(&pidff->set_periodic[PID_OFFSET], effect->u.periodic.offset); pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); - pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period; + + // Clamp period to ensure the device can play the effect + pidff->set_periodic[PID_PERIOD].value[0] = + pidff_clamp(effect->u.periodic.period, + pidff->set_periodic[PID_PERIOD].field); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], HID_REQ_SET_REPORT); From patchwork Mon Jan 6 21:35: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: 13927842 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B3841E00BF; Mon, 6 Jan 2025 21:35:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199352; cv=none; b=fyhCL2foeanJApNpBvuaH+rNoNcQrmWBBREI0gmAdkwU6x+kEbBqYGRTub22N9QhsK6vletAv8TI5WqFgdkZpAWkVL0sEObKoGYLFrD5Krupku+wGLs00aTqdwtGlKTV0ZYHwaWLHIP4pR7fIeDEp2yYsKgIfywUWW+rBAaAGMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199352; c=relaxed/simple; bh=lwoYk8NIAbQoRUBh6t/sze22q7+oy0VMCbNV9NT2mq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qcHxbw76DguUEHe681KSrWtsN8d5UtKfRFxLChQNA8Tf26f0vHWnCpRYyHdft0z+cyDSFf3r2FeCAFjHTTAk9qELuFeZZ5XEt6tMD/7iseHCRsGCy1zeLiU6WLdp6S0xRvmQHh5hEXe4lURN5njT3TJ6Sah817+5xqyo8vpFsX4= 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=Qi6/+wbW; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qi6/+wbW" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d3ea2a5a9fso2221302a12.2; Mon, 06 Jan 2025 13:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199349; x=1736804149; 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=jf7d4JsYQjCJgLMIFYUd+vOjPbH4G49qGUq3EtsexA0=; b=Qi6/+wbWSVG2sNwrnjAgj+/pBYthix3aBJRFAPfNmKqHC0IZ4RgjsJ3KHwgS//mXhZ pSh65rZTmU4ATrDgfxD3M6okAErAuHzOTMuxOBGDDDadzGjpG2TaNZ95UKmEbwwGUTsv XdyRpd/13r4mqJ15l2zjOJv373YPgHHtSMZX+SwUBejDF6pyfh9yybfewbEoX9OoWIJX gESw6+9cgz02DN8bo4PBTVWqUhsC2hzoEd+jB/wS6vPjZUWfZXR4G5RP/yDd1KuVVqf2 Zz5+YyaWuzvADNJh1FDMFl5/s/gOXSX3YuBRN7HT9ulPHIdHHxMuEKc7jxL6MT8M5AgW 3eDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199349; x=1736804149; 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=jf7d4JsYQjCJgLMIFYUd+vOjPbH4G49qGUq3EtsexA0=; b=WVnpJkzCERhpY0QDSRJ2s2yBWqWOF8Hz7Qca8+trxP4UNY7UGs3zKvzmxQt+vDkA5d BpJfFI3bFHavHiVhluLBtUrpRrdAJcQyp3KVdcQhylXkNWaTn34D8y07yF0/b908FV06 s52MhV/62gGPhiVl2qcm3m9oaivumydLdkmDh3BnDNV1sBg5Pq/u5qFgGcmZI+ZcuH+h NQsvdqtacbBs0GVI3VREp0X9kYflORfZbFkNlTwQJykkUuTF2gVYnjhaZqk53R3kvGsf y5bm+MjkPqCpcNe8+Sz4diovA1dkzXq3HjdzgJXiXYF37GktLra/2FLsN15KJ6zigp6Y d5Gg== X-Forwarded-Encrypted: i=1; AJvYcCVXitfdXjx4gQR1Qz5JL4fJ7GU5OYd6pDWhWchmJN5apC8iRXXeM4TS4lKsmMT/M5PTiSwBAKzwbmY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz32L20gkF9YzQWDj/J67r4jjcs8iISy4eKud2n3PdIcfwurH/6 XycpDEALqmowMZIqXu5kzc8qH1vGFb2i7fcV6NI3WXoNHkKp5BOE7NMZxNr/ X-Gm-Gg: ASbGncuv1hoY/axz+y2nPoXiIcMYNKF/+DwvgFSbbtz/JH/eMwoSD8MMrDo7FJrPaZ+ t37tcFnqFrdBXEN/lP45nLvre1SyYbrbXBH36ag3Yk6cR6y91s4+dmdjYRNM6S/fXKexvwXRi0g 7mYXNOtKULEpWVk+aJ323u22KMF6JU1Mg4S+KNRQGoryrZ2AnbIprujMYyZFR/2kVegzzX6OVDX /Gr3b+htPoNANxLJF/zyGUCcy9FgFhmyMryVfw/O5xNfnaxxz3yzI66gkt2zOsr8Gj6a1eLxzLY bFzX2ejYmLSDdDBYe5WFutF5RdE= X-Google-Smtp-Source: AGHT+IE0xMmcVFLpaVFFxN8WlztBMD4MB/cWcBJNzcsucQgjxXJf+qnAr3XNmgUyu+QBUXtc64ECxQ== X-Received: by 2002:a05:6402:268c:b0:5d0:ccce:34b7 with SMTP id 4fb4d7f45d1cf-5d81ddf8113mr19712137a12.6.1736199348468; Mon, 06 Jan 2025 13:35: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 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:47 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 04/10] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Mon, 6 Jan 2025 22:35:33 +0100 Message-ID: <20250106213539.77709-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 33 ++++++++++++++++++++++++++++----- include/linux/hid.h | 3 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 7af7744e3cf2..28f42f30e2b3 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -184,6 +184,8 @@ struct pidff_device { int operation_id[sizeof(pidff_effect_operation_status)]; int pid_id[PID_EFFECTS_MAX]; + + u32 quirks; }; /* @@ -355,7 +357,10 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->effect_direction->value[0] = pidff_rescale(effect->direction, 0xffff, pidff->effect_direction); - pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -778,7 +783,10 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0; pidff_set(&pidff->set_effect[PID_GAIN], magnitude); pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->set_effect[PID_START_DELAY].value[0] = 0; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = 0; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -801,6 +809,7 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { int i, j, k, found; + int return_value = 0; for (k = 0; k < count; k++) { found = 0; @@ -825,12 +834,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, if (found) break; } - if (!found && strict) { + if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) { + pr_debug("Delay field not found, but that's OK\n"); + pr_debug("Setting MISSING_DELAY quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; + } + else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; } } - return 0; + return return_value; } /* @@ -1105,11 +1119,19 @@ static int pidff_find_effects(struct pidff_device *pidff, static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { int envelope_ok = 0; + int status = 0; - if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { + // Save info about the device not having the DELAY ffb field. + status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1); + if (status == -1) { hid_err(pidff->hid, "unknown set_effect report layout\n"); return -ENODEV; } + pidff->quirks |= status; + + if (status & HID_PIDFF_QUIRK_MISSING_DELAY) + hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n"); + PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { @@ -1353,6 +1375,7 @@ int hid_pidff_init(struct hid_device *hid) ff->playback = pidff_playback; hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula \n"); + hid_dbg(dev, "Active quirks mask: %x", pidff->quirks); hid_device_io_stop(hid); diff --git a/include/linux/hid.h b/include/linux/hid.h index d11e9c9a5f15..94ad5a510639 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1227,6 +1227,9 @@ int hid_pidff_init(struct hid_device *hid); #define hid_pidff_init NULL #endif +/* HID PIDFF quirks */ +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) + #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) #define hid_err(hid, fmt, ...) \ From patchwork Mon Jan 6 21:35: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: 13927843 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C92671D47A2; Mon, 6 Jan 2025 21:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199353; cv=none; b=WnUvkeGyTRjlfQZ4QDo6Zqhk1ptLbRjo5pFQIY4/h2RJ8JliLqwdsBj2U9G15VB71pHJilV4OCD3yA8AaxiOPdt34UUWSvr10CNf8r61fdEGtzq1Q3ka7G0HfzPPw8HUIJ0jL9VfTemY2XSgH/N3oxhV1XhpWafkrt98JOlzZLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199353; c=relaxed/simple; bh=Y01bZZyEKBS4Wp/QSV8+diqsxBe4MEehIrGd35l+14c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=deVzeGkF0YGgroFuogrWhmqpOXllVHBe+9qP9CNejCV4gRpwJLKJyO0CjyiPc42UYtlzEAL5459mQRccMbq1iqL4BW8ZJFW9ZZZ3+fnK44orADuq2fRPQ+MOunwwlgJl+rqnQlJEErZ/eIzUWY8Kk4273q4b2vbLR0WNiRHZpoQ= 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=dHX7MPhL; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dHX7MPhL" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5d3cd821c60so3451071a12.3; Mon, 06 Jan 2025 13:35:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199350; x=1736804150; 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=RMzq8PvIJV+z6yV01GtbnkWq1T0M+f9X2iY5dtwH21c=; b=dHX7MPhL6riV4tNF1NtTMmsK0X2jhQ+XYbLk9sRWVNG6/P45GvvTL+p119sSjBamaA piqrA1+1ANc7kHWyspyWcsWUAvXkAL0xs+jaxIdXYbyo6VOGgCUxXlwrO260fgr5lAGG 1j//uh/RLl8ga6xo1RK62GryF5GEPq2/81VxP9NytPwrKKyBW8JcFC06lZFFUQ1cZabB 7K94WsjVl8XRCO53llwBaqFh6wxiX7pghdiE/ca52YNupuFo5wPC3LzBh/3iH0PohQZr zKR+M4g2qYTwvVJ0wZG0Teg26IAiUYaCrE1sdKM1Tbq9lT8jQcazDAkLpKsVDejQoeMv /1fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199350; x=1736804150; 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=RMzq8PvIJV+z6yV01GtbnkWq1T0M+f9X2iY5dtwH21c=; b=vgEjeS2SLTO49vmg95slPVSxC+S357lUechxkJL5bxgN1LWCNH9mO4/1KNck7ox6xd zFB7zw39LtOMsRs3I51PAwVtyv5szUNZZU++dRR9a7tvEL/clcN3w4TR8mj2PzY62aq5 A8NSgICVv0A3B0C0BCEvvMA8lb9mCn1V1bF8B2GIc6e7rWxA4IYG/Su70OMpFDbUWSZI wfrEvQuz0AJO9pwwwPVmBvG5mKkMoLfA00so30SdzGc6Xp4f5WSNMlojJW08vuqQiVOZ q2+IRJ8uqZIh9qtplHQ93IBRLX0LiGnj64ZK7OeAHAez7mYTy5G8oVLwJkcZVmVuiJKX yltQ== X-Forwarded-Encrypted: i=1; AJvYcCXRLCWUy4n2x3+QV1prU77vUd96/ioR3GqHxESOk24MH3S03GISweD/K7qNJoi8cpEEvGLPVLJ0zAw=@vger.kernel.org X-Gm-Message-State: AOJu0YyoYLfZ6MoDyjD5iTBh4Hz4bGGgesdE/jhtiZLqpdfBZB5hnT8M i8+H4ooTSsbEsPFpuFxBXYY0Md3rC1NGMiQrpjbbH0hXGfeD+avHzDz6Ubac X-Gm-Gg: ASbGnctRi+key0ngAHw5nGbQZY6SuV0HM5KhjdWIVCx8F03XmYwN23X66u65slUnS9B Zf3U+oJrV7EOsJGMDpTIsy+3ytjK3ED187deFf6CDcxUrMLzIKPAbyDaf/mVgPvHNLKgrOXWh8R qKf3IJdMKDsltTO6BabX9ZmgjJrRS8QqBWgd2sSRT3JjuK/WxpgYtCyB6O/CkVttt0gIaxVn7YT Mc/UJLQLGIQPkAB7L35D4UXtP6gYUDaGZDEk/M51wRbAN3K3IIPa8vEbeXaxoyKj3NohUn5H4wY qSLgJBwzwwr7u6sNKrBJ8rxjib4= X-Google-Smtp-Source: AGHT+IGRWGu9lEj+TyUq1EHaVU1NUY201j+6/c3czWD4kUx/2wfUYrdW0AHgCtGORO+sOV7YbKWIAA== X-Received: by 2002:a05:6402:254f:b0:5d3:efcf:f163 with SMTP id 4fb4d7f45d1cf-5d81de38c3amr17957152a12.11.1736199349881; Mon, 06 Jan 2025 13:35:49 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:48 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 05/10] HID: pidff: Add MISSING_PBO quirk and its detection Date: Mon, 6 Jan 2025 22:35:34 +0100 Message-ID: <20250106213539.77709-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices with only one axis are missing PARAMETER_BLOCK_OFFSET field for conditional effects. They can only have one axis, so we're limiting the max_axis when setting the report for those effects. Automatic detection ensures compatibility even if such device won't be explicitly defined in the kernel. Fixes initialization of VRS DirectForce PRO and possibly other devices. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 46 +++++++++++++++++++++------------- include/linux/hid.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 28f42f30e2b3..d792a07b5a5d 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -421,12 +421,19 @@ static int pidff_needs_set_periodic(struct ff_effect *effect, static void pidff_set_condition_report(struct pidff_device *pidff, struct ff_effect *effect) { - int i; + unsigned char i; + + // Devices missing Parameter Block Offset can only have one axis + unsigned char max_axis = pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO ? 1 : 2; pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] = pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; - for (i = 0; i < 2; i++) { + for (i = 0; i < max_axis; i++) { + // Omit Parameter Block Offset if missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO)) + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET], effect->u.condition[i].center); @@ -839,6 +846,11 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, pr_debug("Setting MISSING_DELAY quirk\n"); return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; } + else if (!found && table[k] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) { + pr_debug("PBO field not found, but that's OK\n"); + pr_debug("Setting MISSING_PBO quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_PBO; + } else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; @@ -1118,7 +1130,6 @@ static int pidff_find_effects(struct pidff_device *pidff, */ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { - int envelope_ok = 0; int status = 0; // Save info about the device not having the DELAY ffb field. @@ -1149,13 +1160,10 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) return -ENODEV; } - if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) - envelope_ok = 1; - if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev)) return -ENODEV; - if (!envelope_ok) { + if (PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) { if (test_and_clear_bit(FF_CONSTANT, dev->ffbit)) hid_warn(pidff->hid, "has constant effect but no envelope\n"); @@ -1180,16 +1188,20 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) clear_bit(FF_RAMP, dev->ffbit); } - if ((test_bit(FF_SPRING, dev->ffbit) || - test_bit(FF_DAMPER, dev->ffbit) || - test_bit(FF_FRICTION, dev->ffbit) || - test_bit(FF_INERTIA, dev->ffbit)) && - PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) { - hid_warn(pidff->hid, "unknown condition effect layout\n"); - clear_bit(FF_SPRING, dev->ffbit); - clear_bit(FF_DAMPER, dev->ffbit); - clear_bit(FF_FRICTION, dev->ffbit); - clear_bit(FF_INERTIA, dev->ffbit); + if (test_bit(FF_SPRING, dev->ffbit) || + test_bit(FF_DAMPER, dev->ffbit) || + test_bit(FF_FRICTION, dev->ffbit) || + test_bit(FF_INERTIA, dev->ffbit)) { + status = PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1); + + if (status < 0) { + hid_warn(pidff->hid, "unknown condition effect layout\n"); + clear_bit(FF_SPRING, dev->ffbit); + clear_bit(FF_DAMPER, dev->ffbit); + clear_bit(FF_FRICTION, dev->ffbit); + clear_bit(FF_INERTIA, dev->ffbit); + } + pidff->quirks |= status; } if (test_bit(FF_PERIODIC, dev->ffbit) && diff --git a/include/linux/hid.h b/include/linux/hid.h index 94ad5a510639..29f0a91f505f 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1229,6 +1229,7 @@ int hid_pidff_init(struct hid_device *hid); /* HID PIDFF quirks */ #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Mon Jan 6 21:35: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: 13927844 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D87D61E0DCE; Mon, 6 Jan 2025 21:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199354; cv=none; b=GxZvTvBrdroXAb/trskKiTHXv8gK3CNBGyHrsiyjp04+k7fhfiidwBW1sWIED7nLv3b77QoTwIk/mEVM+K8tPFg9+fjUprItzfnvJpmAcK+Qo1mo0lXCR1qr+qG5qLq6ZkC3/WY27bWFXWBm/JnkOTL1tlDeHmGaeVZZN4Z5rmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199354; c=relaxed/simple; bh=pLph4SWz6y3xXJ9APCg1zZVx3sH1RCXAHG2RypKhgUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YMLkEOFxYY5hM3h6y+PSgi1+YaieEP/P+3r4/wA1X4njIyq7Fk6gz/X3WHbfcmePz8IphfUdIsS5L1lsOqGWkbG3/8aSQVCvIkm1X+tOmcEVZJ1fQXQWcDU0y9DBbtIb3Z2dALXIdIn3YFM5wot0aiqNld70nRYH2miOeA/sWio= 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=TSrNdLak; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TSrNdLak" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d8753e9e1fso2282055a12.1; Mon, 06 Jan 2025 13:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199351; x=1736804151; 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=Epp0wzlEdYadJ3qjQFjrGTOyGLfNXGUa8Cy33VmBBEQ=; b=TSrNdLakupYK/EBB11dRrwQDqNPBOx6CwzVJtqaASKC/K8t9/4zhhjI6ov1r4R5ZQr AyX0kM1bLdLDOSiTuk/zp6JnWlzCURI6SBTzCqmVtyl3be6SpxcYV5W2y2VBwG3/VkeG kAt0zj/BJoKraWwNZP0I7i+D33hFaFFe3uUkTHNR5FvF15zmQDlauFIwMBjRKTNS619v /zhdAPAfE4lNxBp85VGNe0UzfJP8CmZ8VvZNd08F2KJb48r0IXK+w498BSo7NDWX1Avd sbyWS2lqK/nyUaNYrI8lJZBfCBixY4gvSU3VKjDRETBiHpRjUxA+eGth7edExeeShka8 CHyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199351; x=1736804151; 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=Epp0wzlEdYadJ3qjQFjrGTOyGLfNXGUa8Cy33VmBBEQ=; b=A/EBqbT9S8+fc+wwqTynusb9ijWIgTL7rRDFGDw5B486dkMkrhrjsnI7IkLwJHwj7y W/PYMvoXBj1ds36XKc4YgSzmYIzaK+URSzPa1riOU6k/OMGSt9G9dp2H/ZFoRv8KcvHx 177zn6LpT0WEEJPfOL5hYoDFyNhT0KiacC5dqSy5A8KrwrOdkhrrHYXpJ1Qmsz7mULRe HQKw44lraC5U3XLSaFBS8WeNSZi7AY1kkeEd4Wv9MXgjdTf8N4fz+r/0C36CFojI5AAZ UHdv0rVMEG9xe01sMoTtdc8ZQKDUmf+Vnl0Zyt9Oi0ecHvFVymXG9tt9byuCejBNDjvj 2ZJQ== X-Forwarded-Encrypted: i=1; AJvYcCXaYoqpMPPLmH7W1gqXIOYckcwQHKB+GQbpHV62fqt2u40udzENof44u9+3NZjQW34iYXGTMLLTDXQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv/1YlWQ0pEi5gw28PtjejKF5bDH+0re+fAQpayQCSXvBPM3nL Q8772qrnqMK3Tq7zzHjFwUVq8mhb17bvYuRjLcob/zqbwQBzYNCa5fbwQ707 X-Gm-Gg: ASbGncs6dMctLBbekXrlkNCnRHkLu7NdnxcjBQLzM8bL2jQ3uL+xUjfXwYA2Xrm9RX9 WMgc0vRbyPyZVTDi1I2Jp1GyOlGcqEyYIONhY/4uwiyEUf7d3zmjBrXi0wSvJhVKuHReztf7PaY nnlHnJhglY02vYHPjPKWWwIrSRhjLBybJsVfLLaM3KhAMAjzC4XWQme6679e9kgwJhxDZymy82y T1MzZQDCPL7Tg15EDfC9HdJJMt6894Teb09W4CEK7agHOSGjrBjbqby/fHswvR8D6CTcF34BquB 6n+jNBcvWWoJrISp3Ikxtv8txHs= X-Google-Smtp-Source: AGHT+IFufXx+0W4p70WmQnlU7EfZXvOTo21+xcRSm7VsVMrLONAFqD/XFvHiIUel1pGZP8qErzDY+Q== X-Received: by 2002:a05:6402:4403:b0:5d0:b7c5:c40b with SMTP id 4fb4d7f45d1cf-5d81dd66e01mr20558882a12.1.1736199350946; Mon, 06 Jan 2025 13:35: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 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:50 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 06/10] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Mon, 6 Jan 2025 22:35:35 +0100 Message-ID: <20250106213539.77709-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With this quirk, a PID device isn't required to have the PID_DEVICE_CONTROL field available. Some devices like VRS Direct Force Pro do not implement PID_DEVICE_CONTROL in their descriptors while still having the necessary control fields like PID_ENABLE_ACTUATORS or PID_RESET. Fixes initialization of VRS Direct Force Pro Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 3 ++- include/linux/hid.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index d792a07b5a5d..53b16a4e54a6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1000,7 +1000,8 @@ static int pidff_find_special_fields(struct pidff_device *pidff) 0x57, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, 1); + 0x96, pidff->quirks & HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL ? 0 : 1); + pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], 0x8b, 1); diff --git a/include/linux/hid.h b/include/linux/hid.h index 29f0a91f505f..2af9db0296d1 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1228,8 +1228,9 @@ int hid_pidff_init(struct hid_device *hid); #endif /* HID PIDFF quirks */ -#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) -#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Mon Jan 6 21:35: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: 13927845 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08E951E0DDA; Mon, 6 Jan 2025 21:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199355; cv=none; b=U6EOzwtI6fAdiyep8lACVSAUk5yHklvhoQuRjaVl9I1x4oRyMXiZYiWIlrrQsFkBLONdJI9rF5lVi0x+/JKoNE8jZZ0W8oQingc+E/EwO///0Js/qbQbyvHAwNxzp2RS1elRVW7M4Vm6OCDf96JKO8CoiA6XamT424Ei/F5AdGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199355; c=relaxed/simple; bh=QpcFmZSNF3TCKbFLUHLW4V0YOIJt0/4SLo+cWhmfzTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fl5l9NkFQxktA4dO6aVxqQ69gD7znInSOjRrfGs0BR6qqoRuueis2BhsfjavQql0TdY26LtlNtraJoCGeJHSzhgyUKlaJbUYchuRxgfTNajC4ohOmqrOZJ5osiHc0iu5ngsNXy04itgK9qbyxnKAqaZkj/bZzGgRsga4CfKoIDo= 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=SfL5ksrF; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SfL5ksrF" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5d3cfa1da14so3133614a12.1; Mon, 06 Jan 2025 13:35:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199352; x=1736804152; 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=uL/zqFXHROf9ZEt+23hat/TCGZHaDdrfMcQYQykn+sQ=; b=SfL5ksrFxFYC6QR9Lub4IZ3330ZndWuP2fPy3u8JoZ2Na2JwcQz48OIHhQyC88FLe8 SReR0VqKtAwGNSdp8V2DZBiVsw4fVuv7LzL7BojUOn2Sj+ddOfA/i/dwqmId4b/fraa5 sEWZtv+FBOdmpT/ca7/kuhptB0akD9XL6gTdmrA9rqHFvVvfrbhP8XzppZKwNt1a9iIp PnonyAObyPKyuj7DYiwfOk7eVkZ0/wJ1rGtiqdK+uAhxtzXWvocoy011NqC5/vjmWH37 JlIuJqB1TjhMvHn20WFOumSq+6CryHI1TfIBI1tOHDYpjLzjRKpfCunSk2d27K+nkQ0L l7ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199352; x=1736804152; 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=uL/zqFXHROf9ZEt+23hat/TCGZHaDdrfMcQYQykn+sQ=; b=vGET2RUyOEAC5+o2vnweJhifBuEvLesHYOuxhGKXAEiE7PKlo3/X9rz07DIXYZ/ikl WETTm3KU6svlheJPmtfMyOyJ0AQtvS+bO/XW4u+90126sQ6ZK/tfShleEMTga7YNAkpf OrUZDkEyKWWvxsxmUhDdU6fPg284uMfkve/KTBk7bvOjiEmy4uYwjpGBTyJupY2RxcIu teu02Nj3BjfJlPXn+Mplv5TNrHd5gVcWjN/nfISg3vXNP6DDVhnIfnBWS8CkyJAciTbv ws3KZAN6VybCKn8E3oG3JLKG/0f/IIrjYtiA+7SIA+ga3QkqVP0uJjBY1xMs3KFaTjzL dY6w== X-Forwarded-Encrypted: i=1; AJvYcCVI5zHB1AKL4br66Nbbyhds3IRhzMFTMxTcB3zHJYFesjv0v9aATExGAs53Qt6g/ARCtIA/9u+caPM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5qjTKNmEx8PM1M5jgh619Lo4ZHFf8PlFuCPyPXUG1+0Oe5p96 G3Cj4axTR6QIzf491yCRvF17Hzvc9nKrIj08+txRGPfgHwwlXq+x3RtldOHX X-Gm-Gg: ASbGncuBY9vwMoLYHOm7/LHIPfaUmcMYfiqZL+NxVS/fSYKQ/2hLRQO+4X+OoGD86Uw dC+6n7k6vs7dCRT5Lj897+OKBWk0WVaISKZiT93MolKr4QWObEwc/68ZHyXTl7rdsh+KmcUOcBJ +VHU4OvkzcNNXA1CpOudo8iRr1BOtlriSgPsFM5b1028fm+e8o2x0GE/uD80pJglJ9mMR1Z3/Po Jz4KJ2ITwIp6Stu2f5EphMv6d0HB9qqtBEV91kWsgrwKfboKyrfXy1uwXUSh9XvbrdY4L6YSC+f 1hKynNS7k0VKwX0D2ML/gaAZMvI= X-Google-Smtp-Source: AGHT+IGMvCFVdT5qK9wrMt+xLqgscbsHuH5eO7aFMjBvyrLlO+XxMBjMQ+mpyTVK35pI7Hvm4u6S/w== X-Received: by 2002:a05:6402:348b:b0:5d3:fdf5:4b28 with SMTP id 4fb4d7f45d1cf-5d81de36c71mr19484232a12.10.1736199352156; Mon, 06 Jan 2025 13:35:52 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:51 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 07/10] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Mon, 6 Jan 2025 22:35:36 +0100 Message-ID: <20250106213539.77709-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 15 ++++++++++++++- include/linux/hid.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 53b16a4e54a6..5a328860685b 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1299,8 +1299,9 @@ static int pidff_check_autocenter(struct pidff_device *pidff, /* * Check if the device is PID and initialize it + * Set initial quirks */ -int hid_pidff_init(struct hid_device *hid) +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) { struct pidff_device *pidff; struct hid_input *hidinput = list_entry(hid->inputs.next, @@ -1322,6 +1323,7 @@ int hid_pidff_init(struct hid_device *hid) return -ENOMEM; pidff->hid = hid; + pidff->quirks = initial_quirks; hid_device_io_start(hid); @@ -1400,3 +1402,14 @@ int hid_pidff_init(struct hid_device *hid) kfree(pidff); return error; } +EXPORT_SYMBOL_GPL(hid_pidff_init_with_quirks); + +/* + * Check if the device is PID and initialize it + * Wrapper made to keep the compatibility with old + * init function + */ +int hid_pidff_init(struct hid_device *hid) +{ + return hid_pidff_init_with_quirks(hid, 0); +} diff --git a/include/linux/hid.h b/include/linux/hid.h index 2af9db0296d1..93233c5b75a6 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1223,8 +1223,10 @@ void hid_quirks_exit(__u16 bus); #ifdef CONFIG_HID_PID int hid_pidff_init(struct hid_device *hid); +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #else #define hid_pidff_init NULL +#define hid_pidff_init_with_quirks NULL #endif /* HID PIDFF quirks */ From patchwork Mon Jan 6 21:35: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: 13927846 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 094DB1E0DEB; Mon, 6 Jan 2025 21:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199356; cv=none; b=hV1OuA2/FSUIWA3tkLmvqJ0gza+KLHfoFt0UJdFbfDuWHP2pYIYEOtp1RXTIMJkW4CiRHMV8zpq+i2yzOAiDcLVMLXyLgCmlizOSe7mUunAutMQK68fSs1/nxPWiedutcOFsS0fcTD1InZB5K2D34okvW108PdEJuBwRUSY9aMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199356; c=relaxed/simple; bh=wInCUfzKfgycExALsayqK3naLt6eLNwTG2gebglTTow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I3K+i1EYFpf9FyC165A6BC3UtWJC2b/bWulZTgiXeL596WMPsfX7cF/igS0dOvPYxPAJ/TvH4YlJmF1QwmkPt4th2PLj113mMujYi3C1W94M6sykuWpo1lOyxhG59GX6RGPTH5ARgRNX3exic4i0akOZ5ydb5+G1+245guLsxlw= 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=PQlftDEE; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PQlftDEE" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5d8753e9e1fso2282062a12.1; Mon, 06 Jan 2025 13:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199353; x=1736804153; 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=quUUSX+k9WiW9LhDC88PMv/7wFZpf0XxRnFApYOjSAE=; b=PQlftDEEk1Ebj2VSw90ZHW2dCnXM3ljo9m4sJcptVym0/HTTWxYoZPOgxNsTueuG2Q Rw3W9kW9BkLIR5wSlcqX5veXBC5/XiwRRceGSE9sPiwhHoczQ8pvNUWqFBrrgOzFoJlL e7SCljMV5mqocexPMyFzpUPUyPKHat0UhtO3wWDhcOaJEUHRSTvzez9Cj/hQMgfSGUMA 5qcS8IrIbg0G7omkpC4bcpxrkJ1Esi8VJklX9jusM5arz+gfyYTKJiyLr7/be21mAmFI FfU3t9kKOnuOGIgwpnttv3Eau+74H/7m7S1JKS3srTYp1RIM4hPEhLlKOB8AEa5vu3uy tUWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199353; x=1736804153; 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=quUUSX+k9WiW9LhDC88PMv/7wFZpf0XxRnFApYOjSAE=; b=AVwOxSJivc1oUs53Tun9bCDq7eNVKCTX0229h1ve/mbEml74BmVJlkgx0m5TbqUOkk Ze0yUhQhEMmDHVT5KJB1CTw1JtKO33nYht8D41KMzjxlRU6ycsWj3Jj44TMcojNFgN5T 1Yls/ldkOa59bcyw8i2EoT3So1sEOk4Yhi0YKNFl7MHEs9h8CRohynj4N1B17wDcDy8S 0gSx0/nsoKMGgKh2HSjB6YPvmD1QOReh9JHz+U1ejyr58K+ucHIvzOq9g/FOw38uqO+H Z7Gs8eTBaP/oGaHXjRhKMlxxEHAN4UeCHrJ3gUR5fLyY0DET/hWn2QfCfMQLQBw2yEY4 HeUw== X-Forwarded-Encrypted: i=1; AJvYcCWkSl0tGLM7TdylEtIY3IJW0Sw8Nu5/UhhRWYPiycfyxTfQm4GvZxx7ryEBZEwtvpzOF0J//WBC6Yg=@vger.kernel.org X-Gm-Message-State: AOJu0YxEe7Lf8F0bLCnpmE9ilRx+jbr2AHs2/tgC8TdvEsmS1UOoiIul E0uYzN0XEq65HWGFacPznuvYgILaUjFrFWCA1InLFkk+XHuitOxy2muuwRcU X-Gm-Gg: ASbGncu2qBTFZPAusiuaL3waYKa4wdvy6eTDM0NkotHneL8OlqjQ6zQ/Y/rHIg75odd T2idLLvVCyfy9csgxWZZE+Zg0Jeji184dlMxM+vxXO80+eGMhBwnjNGtN+IconSz8/cNoydPkGW +Pz0B1yO2M4dchTQ91xRVqjsE1IBOn1twzyG5r8i0D0nHJM/W3mVdNy+O82bPyJxRTKtacw8t/1 yixZzoaug2AOgsWmG8SpNntDP+DEUce5OPDy8/5mKIEfgzj2fi07WfRCdmHT7LAUSq1lOywJ/aI IUqABR6dIPFv+WTO5Qb+pXltTYw= X-Google-Smtp-Source: AGHT+IFKjQ82BxtjNRZvEvZ14vKBPh5m5qoQTgiMcDT/kmQKDehZ7OhGUe2LXN4v5yMnucD4F6GZnA== X-Received: by 2002:a05:6402:524b:b0:5d3:d747:6496 with SMTP id 4fb4d7f45d1cf-5d81de2dcccmr19597513a12.10.1736199353267; Mon, 06 Jan 2025 13:35: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 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:52 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 08/10] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Mon, 6 Jan 2025 22:35:37 +0100 Message-ID: <20250106213539.77709-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> SDL -> Linux API translation, and this value can be incorrect. This can lead to partial/complete loss of Force Feedback or even unexpected force reversal. Sadly, this quirk can't be detected automatically without sending out effects that would move an axis. This fixes FFB on Moza Racing devices and others where effect direction is not simply ignored. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 12 +++++++++--- include/linux/hid.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 5a328860685b..6b4c4ecf4943 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -136,6 +136,9 @@ static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; #define PID_EFFECT_STOP 1 static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b }; +/* Polar direction 90 degrees (North) */ +#define PIDFF_FIXED_WHEEL_DIRECTION 0x4000 + struct pidff_usage { struct hid_field *field; s32 *value; @@ -354,9 +357,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->set_effect[PID_GAIN].value[0] = pidff->set_effect[PID_GAIN].field->logical_maximum; pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->effect_direction->value[0] = - pidff_rescale(effect->direction, 0xffff, - pidff->effect_direction); + + // Use fixed direction if needed + pidff->effect_direction->value[0] = pidff_rescale( + pidff->quirks & HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION ? + PIDFF_FIXED_WHEEL_DIRECTION : effect->direction, + 0xffff, pidff->effect_direction); // Omit setting delay field if it's missing if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) diff --git a/include/linux/hid.h b/include/linux/hid.h index 93233c5b75a6..5237f9040950 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1233,6 +1233,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) +#define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Mon Jan 6 21:35: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: 13927847 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 392B31E00A7; Mon, 6 Jan 2025 21:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199357; cv=none; b=UOs/7pe1scvc6w9VSlyAgrzR0J7AptCOejfRqi0494eCp0iYnAAcC4nLCsBdtkDQQ+H2AApPUwvMUu/CI1dmhP0O3NeiG9k0z+GpJWsd7b+Sf6U6niqmJuaIBtKjQokvgsY9dMfmyh1sc71ZfRl6Orv6mo8l0JXuy+3ladaXUv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199357; c=relaxed/simple; bh=b+zfvgwJH2RorKAcLzDD+FZq/xIErAzyO4/KBsNmong=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P+t3zY8LR0L8Wznt0N9YQQ9y7M0MH51/jLLPk8z7tpYXcOMkEYexmO/cwmEcq/Nk4RjOT7bYdVE/7BF7pXdRH6ZxSPhmh8/J7p1yf3q3rzuDV3o9Kpn9gvBb8pHE9vlg4QLRPSkBvulsaIgq1b+Ntc2KQf1JM1acyqeKm+fUVX0= 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=Sw+dJv8b; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sw+dJv8b" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5d0bf4ec53fso3098710a12.0; Mon, 06 Jan 2025 13:35:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199354; x=1736804154; 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=CIWbvhwfyoOTXpZRGFAZUIU+5fdfCWd5LhGB3garQ30=; b=Sw+dJv8bIND7AoxFPwLs2BgmmEEeP/jWBfcvDrrHHy0msjVGn1bBsRv23dGoBbilEg l/d0qFwecpLQSphJUBkDNDn917yatOdTUrn8USA+has3NGX7wHRlw5lq98Q8iAYZzCB8 rLJ94BwWfVSzrBs6N4Se5/vJ70mJjOA49AFi6kGrqmzn3jiodsswkl0tIR8tbwkUhLcs q9yV0KhayzNyEwEYxU0JnZhURfGhjnkD1E75LWCdlc/KJPT99d5PAQ8l1ZX1rRyNxT9f gMLdsDNiv8gaDl3Z2XbstTW0EaVNVPnUFZFbKSl71IHI9+g7nfyZqNq4kNzGRYePsY+S zw9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199354; x=1736804154; 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=CIWbvhwfyoOTXpZRGFAZUIU+5fdfCWd5LhGB3garQ30=; b=pHeiSWdESh73EPjyJuxeBO24Uxk6RX8Yb949Iml837cOSw3F9wpKT5amtTDOy+GzBz MpqGBvhfgfmDSz7lwdqxjfYhq2olX+43HZaH/W1gvvb9l24f1qGH/Kv998QX7fcEmG/D RVo+pTf/3J4yoiV72icmGmLHCVR78DcZWZnNsHhsiC3kMRIBpjHb280aLQuPFQqz+PHM q+xoGL475KFJAJtv8VbgJvRoa77+f714JNbD9zp83o85JsDDuvWQibDVHJ4aVR8I7qfU Au3Md++cd/XwWQZwt3c23eT8v2F73qVjGrncnQrovOu/DOrZbYtRGY7a/yqJD/EC8JIC bSbg== X-Forwarded-Encrypted: i=1; AJvYcCVAzoC5lVQzPEOQ/sB6qlhoXXjbmEgVvDebYmQ6KsuJmw7+Hq3vt78qwl7qc9Eu8wbdiDRSNpNHUgI=@vger.kernel.org X-Gm-Message-State: AOJu0YwshAcsM5nj8YJdFhcdzETroG74z7ZB0z2jqMKIzCcrjgBmhgms KTEXHmU2tsIKa7ICU4aw59BH7s6KuyRAwHD9nNr2jiz78x2mZXTuMceysmI0 X-Gm-Gg: ASbGncvnBTATmVTcQ+K+RcEssUJ6xEBwWGyUN73Y+6jmBymcRAI7gwFOuS87re6feci T/k74oDF+8wcBlINQVFvRS2q8vsun1lodXVsJkqSHEadIjj74DpZ9zbEK6GkosGHU9HGUz5cwOC gDbgJvBp7z3BW63snRwhCtISy25/YDSX8lp+ZxBt74a1xyoMOlIXxi35sTx/JYFQbfBrDCb2fuU 4FlGbPQA4GSGS+675D+XNquFZVRpgjvbEyLUBY7S3Tig8iKWTcbY6q3gmSH1gdE9v1Cui7zzJmx aQCWRBOtbLrxocWRA2ZHA+D7YaA= X-Google-Smtp-Source: AGHT+IEbm8CI6PSn1fYSqMr+ze0pUcK/B9DMBbMLgLF8TZL26BppdCyYLbZrMq5B/4KZeBWh0QsArw== X-Received: by 2002:a05:6402:524b:b0:5d3:d747:6496 with SMTP id 4fb4d7f45d1cf-5d81de2dcccmr19597530a12.10.1736199354351; Mon, 06 Jan 2025 13:35: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 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:53 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 09/10] HID: pidff: Stop all effects before enabling actuators Date: Mon, 6 Jan 2025 22:35:38 +0100 Message-ID: <20250106213539.77709-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some PID compliant devices automatically play effects after boot (i.e. autocenter spring) that prevent the rendering of other effects since it is done outside the kernel driver. This makes sure all the effects currently played are stopped after resetting the device. It brings compatibility to the Brunner CLS-P joystick and others Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 6b4c4ecf4943..25ae80f68507 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -109,8 +109,9 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; /* Special field key tables used to put special field keys into arrays */ #define PID_ENABLE_ACTUATORS 0 -#define PID_RESET 1 -static const u8 pidff_device_control[] = { 0x97, 0x9a }; +#define PID_STOP_ALL_EFFECTS 1 +#define PID_RESET 2 +static const u8 pidff_device_control[] = { 0x97, 0x99, 0x9a }; #define PID_CONSTANT 0 #define PID_RAMP 1 @@ -1240,6 +1241,10 @@ static void pidff_reset(struct pidff_device *pidff) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_STOP_ALL_EFFECTS]; + hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); + hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_ENABLE_ACTUATORS]; hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); From patchwork Mon Jan 6 21:35: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: 13927848 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6BB21E0DEB; Mon, 6 Jan 2025 21:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199359; cv=none; b=V8tmRQaVnxz5xpq0v7OtyzinsXxyRZHfqkJ7his2VkBexJ8quamtXh+MOC+mb8N2vvEtYNYtiq8XDxJPPXcVS2SPqg8FtzsgR0UmDSe0q7hyLYFdkV1ydoDEp+Zo7sOosmBdr1mpXm4ftZ0zIglEdFrrBaB6s6ds3KYKgL0LRbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199359; c=relaxed/simple; bh=thZObaPve25NtBG3jcnVjHg9Um0cKRGUkJwJKnTyNzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XeX8xWmdTPFL848tesRglSIp1jMvnK9ZpYYPtaFAj5wyKd+n2m/IC/SBYsypTCgk1z3o1fUKoIWt3/nMcSdlBSr1vsL7KiPV/B01B9hJk5Tjc9wfLzSTQqwJfIr07VYe8Y2LoJ7MdH7UFtmgQGWGgzinO0UVvW44un6pgR9q5Vs= 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=HPUKmP6z; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HPUKmP6z" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5d3be7f663cso3093595a12.2; Mon, 06 Jan 2025 13:35:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199356; x=1736804156; 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=Xg7gd5e/aYfvvOTa6WnC73IyJbYoHac2d0kgAimlDP4=; b=HPUKmP6zIHllk2CkpF+Kdw743KRKHQpzqan2/aNFJld+kpYxtPMKS7hVhMbe/sCD0h Du/Tcr43dp35H6AKVo2suXwKpVlNLRd0IsIh1VOKRIPAqGnnvY+GUGIH6KrzHLE8dPrG kRSuO/q/i+buD2LVCp+bvc/OJ33mnmseQdiVlSjYZDJP7uBadUxMNH9EndyPS/4sUaAO FLLZtCcC94hlveGqufUNRQuTPKMyXRFDAyr1G8VYuJY2R9nFvQM1aMc8eq1uA1oo1Qc+ In8mTNrAQ2AlITcrbA1ajNvISMP7rdnHncINGK3eFds5LTMuFvRX9pJwRT1sgQvtB8qS 9irg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199356; x=1736804156; 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=Xg7gd5e/aYfvvOTa6WnC73IyJbYoHac2d0kgAimlDP4=; b=cmuFxPR8WUEGuJe2Kfq+DdeMFVQrzvKPyIi6alPEjd2D2nM79aPuKSx0Ws1vfb2s55 d4PaefjLEs5TqYPnXcyDBZv2RFfea91DBCnnVBlHSklDrYwH4LZi6YntSZOsLMXLydtN 2PdOYUs8vGwEO7MAVfjHoMv1dG2DsxW21rDmxVw/c/kNn3VtC5UVUE5yl7RfUXTB0cFt IuMZ4HNEmoLsGVm2NXoavEs8ZTTHjKSDUoyMgl5CJXD8lGgEdd3wglRl1BooI3ollMad l5fowHF7mtPyv6YEhehnEX/Dgz6GpaxLCyjVoMqqCRwDbvrr0a+0gAvX0C+E3ORuwqNo 3iaQ== X-Forwarded-Encrypted: i=1; AJvYcCXohAINni+t01eR7ohkjW2rRK73Ib0oaZfx4fLh72LzjoR4IUZkc/eJg2yXdS3SVlXFFzmThhYSnvA=@vger.kernel.org X-Gm-Message-State: AOJu0YxInvIInj4itqiFXTO7D66hl73ILVruwTOQpM4lb2YfPHVInGJR /3EKUHRbPr27qWcC5IQ40S/Y0jNl6//xqGCLoRCisxHdxU2flRoIyxw4AZB4 X-Gm-Gg: ASbGncshUAQeaAh5au68pyjCn3lJNHvWwaiQnTqW1JWD7GDTV76ReSIMNYPS/FG+pjA ieT8OEliLwS2tAEUXkpbMsGDlzwVobo85NDAMnPIyepAtlRkb/W3FE0mpAXsJd4hJj+raFzqO6D 21ObjKCIx1foT7Qi4Q7cw2WLNAPtYwfWhBMcb0cmtzPS6kHQzSed94b1Qw+rMWp+w85d9NjLTvG W4jka7WLsMMsSgyDpmHzaFj9F68d8/ezt2AckGHBq/CDMXlNo8zp0CxlfuOq5/DLmNGqZsmQECy 57dk7ATZHuVpEgg0C2dsfptljQc= X-Google-Smtp-Source: AGHT+IFheAiEj+twn+ngCqjA4EgwQur170OdaHT64DGeYsJmwS2lKqBh05YSJYRtYPDyTJy4nnJ4iw== X-Received: by 2002:a05:6402:5109:b0:5d0:bd3b:b9a9 with SMTP id 4fb4d7f45d1cf-5d81de1c38cmr21554572a12.8.1736199355783; Mon, 06 Jan 2025 13:35:55 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:54 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 10/10] HID: Add hid-universal-pidff driver and supported device ids Date: Mon, 6 Jan 2025 22:35:39 +0100 Message-ID: <20250106213539.77709-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend pidff compatibility, usable button range, fix device descriptors, manage pidff quirks and set improved fuzz/flat default for high precision devices. As many of PID devices are quite similar and not dependent on custom drivers, this one can handle all of PID devices which need special care. Numerous sim racing/sim flight bases report a lot of buttons in excess of 100. Moza Racing exposes 128 of them and thus the need to extend the available range. All the included devices were tested and confirmed working with the help of the sim racing community. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/Kconfig | 14 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 24 ++++ drivers/hid/hid-universal-pidff.c | 185 ++++++++++++++++++++++++++++++ 4 files changed, 224 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..205dbb4ed6a3 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 @@ -964,6 +973,18 @@ #define USB_VENDOR_ID_MONTEREY 0x0566 #define USB_DEVICE_ID_GENIUS_KB29E 0x3004 +#define USB_VENDOR_ID_MOZA 0x346e +#define USB_DEVICE_ID_MOZA_R3 0x0005 +#define USB_DEVICE_ID_MOZA_R5 0x0004 +#define USB_DEVICE_ID_MOZA_R9 0x0002 +#define USB_DEVICE_ID_MOZA_R12 0x0006 +#define USB_DEVICE_ID_MOZA_R16_R21 0x0000 +#define USB_DEVICE_ID_MOZA_R3_ALT 0x0015 +#define USB_DEVICE_ID_MOZA_R5_ALT 0x0014 +#define USB_DEVICE_ID_MOZA_R9_ALT 0x0012 +#define USB_DEVICE_ID_MOZA_R12_ALT 0x0016 +#define USB_DEVICE_ID_MOZA_R16_R21_ALT 0x0010 + #define USB_VENDOR_ID_MSI 0x1770 #define USB_DEVICE_ID_MSI_GT683R_LED_PANEL 0xff00 @@ -1373,6 +1394,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..df0206f5e77d --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID UNIVERSAL PIDFF + * hid-pidff wrapper for PID-enabled devices + * Handles device reports, quirks and extends usable button range + * + * Copyright (c) 2024 Makarenko Oleg + * Copyright (c) 2024 Tomasz Pakuła + */ + +#include +#include +#include +#include +#include "hid-ids.h" + +#define JOY_RANGE (BTN_DEAD - BTN_JOYSTICK + 1) + +static const u8 *moza_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) +{ + // Fix data type on PID Device Control + if (rdesc[1002] == 0x91 && rdesc[1003] == 0x02) { + rdesc[1003] = 0x00; // Fix header, it needs to be Array. + } + return rdesc; +} + + +static const u8 *universal_pidff_report_fixup(struct hid_device *hdev, __u8 *rdesc, + unsigned int *rsize) +{ + if (hdev->vendor == USB_VENDOR_ID_MOZA) { + return moza_report_fixup(hdev, rdesc, rsize); + } + return rdesc; +} + +/* + * Map buttons manually to extend the default joystick buttn limit + */ +static int universal_pidff_input_mapping(struct hid_device *hdev, + struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + // Let the default behavior handle mapping if usage is not a button + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) + return 0; + + int button = ((usage->hid - 1) & HID_USAGE); + int code = button + BTN_JOYSTICK; + + // Detect the end of JOYSTICK buttons range + // KEY_NEXT_FAVORITE = 0x270 + if (code > BTN_DEAD) + code = button + KEY_NEXT_FAVORITE - JOY_RANGE; + + // Map overflowing buttons to KEY_RESERVED to not ignore + // them and let them still trigger MSC_SCAN + if (code > KEY_MAX) + code = KEY_RESERVED; + + hid_map_usage(hi, usage, bit, max, EV_KEY, code); + hid_dbg(hdev, "Button %d: usage %d", button, code); + return 1; +} + + +/* + * Check if the device is PID and initialize it + * Add quirks after initialisation + */ +static int universal_pidff_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + int error; + error = hid_parse(hdev); + if (error) { + hid_err(hdev, "HID parse failed\n"); + goto err; + } + + error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + if (error) { + hid_err(hdev, "HID hw start failed\n"); + goto err; + } + + // Check if HID_PID support is enabled + int (*init_function)(struct hid_device *, __u32); + init_function = hid_pidff_init_with_quirks; + + if (!init_function) { + hid_warn(hdev, "HID_PID support not enabled!\n"); + return 0; + } + + error = init_function(hdev, id->driver_data); + if (error) { + hid_warn(hdev, "Force Feedback initialization failed\n"); + goto err; + } + + hid_info(hdev, "Universal pidff driver loaded sucesfully!"); + + return 0; +err: + return error; +} + +static int universal_pidff_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + // Remove fuzz and deadzone from the wheel/joystick axis + struct input_dev *input = hidinput->input; + input_set_abs_params(input, ABS_X, + input->absinfo[ABS_X].minimum, input->absinfo[ABS_X].maximum, 0, 0); + + // Decrease fuzz and deadzone on additional axes + // Default Linux values are 255 for fuzz and 4096 for flat (deadzone) + int axis; + for (axis = ABS_Y; axis <= ABS_BRAKE; axis++) { + if (!test_bit(axis, input->absbit)) + continue; + + input_set_abs_params(input, axis, + input->absinfo[axis].minimum, + input->absinfo[axis].maximum, 8, 0); + } + + // Remove fuzz and deadzone from the second joystick axis + if (hdev->vendor == USB_VENDOR_ID_FFBEAST && + hdev->product == USB_DEVICE_ID_FFBEAST_JOYSTICK) + input_set_abs_params(input, ABS_Y, + input->absinfo[ABS_Y].minimum, + input->absinfo[ABS_Y].maximum, 0, 0); + + return 0; +} + +static const struct hid_device_id universal_pidff_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C5) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_VRS, USB_DEVICE_ID_VRS_DFP), + .driver_data = HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, + { } +}; +MODULE_DEVICE_TABLE(hid, universal_pidff_devices); + +static struct hid_driver universal_pidff = { + .name = "hid-universal-pidff", + .id_table = universal_pidff_devices, + .input_mapping = universal_pidff_input_mapping, + .probe = universal_pidff_probe, + .input_configured = universal_pidff_input_configured, + .report_fixup = universal_pidff_report_fixup +}; +module_hid_driver(universal_pidff); + +MODULE_DESCRIPTION("Universal driver for PID Force Feedback devices"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Makarenko Oleg "); +MODULE_AUTHOR("Tomasz Pakuła ");