From patchwork Tue Dec 31 15:47:22 2024 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: 854482 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.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 37C4A14375C; Tue, 31 Dec 2024 15:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660061; cv=none; b=gc1ZLEfubF+abgn5Wqup5Sy0RLw0dPdGTi25s/7CXvYslOma7i1mvoYAHK0y5UZ8eoachAxW2wGlrRwJhes+ZgTZEkcopPmxqXu5S+D1lfHoxltzJMU6RgOc9OxKe2eB9Pm0EEp5LEaRLJG0gFEBuJCPDrwpgqHOxwg1CGctaFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660061; c=relaxed/simple; bh=eym8vWrp0YSLA8gK3wUKIgM2ZMuV3+Np7Jdh6F3rDdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X0XEsbLWAcytnVehIySfrx47JAOGJexJ2oiR3bPH04DvOF4h+C7jQTA47VAm+zQppjVADcZf7AFTjSSIFRrezSJmkJ9wv+kS5E7RKcWu7Ov1HkAQ+E9kd5qydXWh2duy0DIncomTRFdnNQDPkPQ/kLZGAayopRFajYahGLH8yOM= 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=gMOMSE0D; arc=none smtp.client-ip=209.85.167.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="gMOMSE0D" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-54019dfd772so1665407e87.0; Tue, 31 Dec 2024 07:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660058; x=1736264858; 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=xi9/tyl/eMDRqlY9iqLZTwxadrODXpgnAtwglkYl1Dg=; b=gMOMSE0DeChMc2ZtB38r/1CapACvD14q8ECFxUYmJefMThmJ3WcUCwjRi4msn7rjwv bBuVS1opCvudFNLCfGc3w85UJfAxJqGxeRHT/iGfPpnWhLZ6hwkCVsWva7pKqTc/HxQc aFYh2EICYd5LCNML09kHOBVvR1uP09ZwYVCHXUrQWvtFKjuaOJSiTPehzFXGjLVerGaS OQKdeDOuh+xKeUvWgP7DZFI13aCqlVdgTlNw+LmlMOhvtk8QFf6akK6sci29aZY32pdk GSJUarhsLtNuB+SPysJb0aKRpwpSrkc4T1a//mjfKMkQm2a25Sx/0YsUlmf/P+mPJ99w r4sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660058; x=1736264858; 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=xi9/tyl/eMDRqlY9iqLZTwxadrODXpgnAtwglkYl1Dg=; b=e4RgRahjBJwUEPI+6NIp0ERnT1gRo9sXsQne8yC6GruTKRSzZzMpLZZ69FmN/PXK5O bxaQgzJz6mO2C50xZcKiq3UZ/vMbOyN5eXGj90KJwUrM+bBCBBiFCiArOu3k1Hw7YFNx mgcQ99pqMQtopcs42e+fdKd0l6+PelFu+nX/rXGe57Vsoz5qMQluR7ziix/r8JnFFAqd kV/D2H4BZBOnPpQ8AkIr05899MzmmtJMORqe7eu6GW3+pawCWTFPC8puwZFRZ9l6w641 XCHEaTIyk4V6g7tkJp73PXtNOIdGk3P7Fmz37hRj/CU2IOnM1+ZULuKKHIjsY5kSky9T pzBw== X-Forwarded-Encrypted: i=1; AJvYcCXTvRhDKJhSZ1oh8I8nhYsWDgUbnZ05Yd8RAX0wj/EMI/zJNZ2SV/vwJ6CF6DhQtSV8IT0O9mfwRPQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyDWVoRIJASE/6zHMs38/AytKrTmiNW2aPj8M2/w9tv8PX6OAKW /32GX11hvHfnOyQcHvRbc5EfCh6nNWj60rFGpI6wIZpaD7p99qZ4 X-Gm-Gg: ASbGncuBbf+JFOF0TqfUVbk6WeO5/KtiLeuObM8PvzMvcABXDVr7V/l/J4B/H/ABr7F 12h+zqI+Tldci1EjdkpYIPo1f2cw99B5OBsJZX4FfLNfeRqQBPcyRfAL8hd4I9jprzYfhoBIAfz J6cksc5qeUK3XM93KmCA9PMLHGBfoTrF+yWJKn2tQEpjRjvPnb3v1fTn9sqMxfEfkD30j5TJY+G 07JImQBS0GXzgu3yjF5vIxTZkTjC0RYzQ2HGombw6CjVw1e+sYGrL7PcB9TNUouSK8jSaHTEyig kU7TtFkVwN0auIkT2MLXq1GnYDY= X-Google-Smtp-Source: AGHT+IGt+3vabpsGnBMsG8BS1/I5jLDbKWSqQC8qIbYutOI2z8hR1mb2Es9QT0d9bygOUGOqJYdHCA== X-Received: by 2002:a05:6512:1242:b0:540:c349:a80e with SMTP id 2adb3069b0e04-5422955ff22mr3919770e87.10.1735660058127; Tue, 31 Dec 2024 07:47:38 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:37 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 01/10] HID: pidff: Convert infinite length from Linux API to PID standard Date: Tue, 31 Dec 2024 16:47:22 +0100 Message-ID: <20241231154731.1719919-2-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux defines 0 length as infinite in its force feedback API while USB PID defines NULL (0xffff). Most PID devices do not expect a 0-length effect and can't interpret it as infinite. This change fixes Force Feedback for most PID compliant devices. As most games depend on updating the values of already playing infinite effects, this is crucial to ensure they will actually work. Previously, users had to rely on third-party software to do this conversion and make their PID devices usable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 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..1b5d3db62c09 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 lenght 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 Tue Dec 31 15:47:23 2024 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: 854556 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DF0619A2A2; Tue, 31 Dec 2024 15:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660063; cv=none; b=nmKr6NC8oHFseFLtxcKsvgNjbs3AXZ99gKJbDPKRKFxoUFc1Z3LdaZcIQTn+WZLug6jyue1bxBhjJ4r63JViIpyiXvMvIqkTteNmIIYl1bmG9sncoAXYopkRxpvSfJsWngV2lSKmSFHn+P+nrSVGT+t3yjvfTJHOL93kXvZq7Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660063; c=relaxed/simple; bh=UhMsn0/DlrC/lvUhCcs9yzYL/IQYukYL1yWlt9x9Sb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kng7Mm9Ze+rfBZ4AYD5W4J+cLRDCs8DaQFznughC66AOTzYxwWtqRUTMDLcFmv5ebbkkKj3LBRaBnBKP/8QlIdWWfDVym03jF354xxTp7j9F0cuDMFDVBqgfQjHvzkH+7m9U/LTG1JH9tblN9MFEHBues26dBBvY7Bm9jG6XaSc= 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=jIXn5Rye; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jIXn5Rye" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5401ba1fc38so1489852e87.3; Tue, 31 Dec 2024 07:47:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660059; x=1736264859; 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=P6tgFlyizCLz1LCfB8oi2179q+Dut3RfumOFQRmEEyI=; b=jIXn5RyeEj2N9/Fm7z3SYAJ2b5EvH1KM5p5IiE4dQDuCpQTorEWLhnWfNMSdhlfOR5 gto2ka1CZEKIOw/NY+LNIbzM7cqcL5A2JQZ6X2+XTSf9SZnu3rFqULRgt5RHlY+rl9nA lHEgoTnrNdqJnN3x8yrKJVceWQwG8VDL1z3kLnWW/Vh8ZTGt4F4HFxPTKFV9IKNqmmz1 KFrElRNllDJFfc4gHB86EvoU4oU3apL4mHlqgR7Ed1rZffq6Az+f0aBvTtB35G8CR+u5 h91GggObE8+ZRvx2oSts+b8KF4NtoLC7byLYoCySMeAubXyNKwFrnp9akcSZFHvLSr5m lcEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660059; x=1736264859; 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=P6tgFlyizCLz1LCfB8oi2179q+Dut3RfumOFQRmEEyI=; b=l6ceFk39liHqSwIQidI8+/yNB8FNJMaC5T1zFca37kkd9PMK6rLAme9elvDKGOSS5v pWKDVqhUMixysG+es3eD0alRWbk1gQ2wpQUMRPDjI0gONs1o8iXl0viOB65U0UrEWW/b vpRsPSI4cIRY02NJjoxnzvkQWOvYkXsaa4FkbTWuP3/ZvJnQLu941dI5woc/jBLPDQrh J14rKOMw5A6wWBkyCAXNjiUcgbtCaBbUt9vuSLhOBFK7VsbZKw7wTMFkgPtHgEsZR3fV Otc+Ng/acHSQidTnKL0B8w7hIIqrLmvGKW91/0gC+pp1rH5FKZq5IpbXdAN5wwt2WOBE oj3A== X-Forwarded-Encrypted: i=1; AJvYcCVFjYfm7xurzYLYhNnxI2fKlqzO3u+lM/hlx8II7n1/w7VyPMO+uowIxQWvUJJbPTFfVA6fTiAhyD0=@vger.kernel.org X-Gm-Message-State: AOJu0YyQLa9keAN/BKdtf7ilYDJeNS7kA+Y8xpQwj3esbOVN3YpdMqvX 6ONr8NL14K0WbK7FZtpbVLZE6soMPR/8gH488ktaB0NFvrblG6JZ X-Gm-Gg: ASbGncsAYWSv+X70SgpCJhbP//QZWHhqjOTwL2NJk0rEPJO8Tk0BXVDWitJwx2Nk99e IwQiLxCi9AFV1W0xPSgE7vzSww1XCfLI/wvYeMzQ6MDuUILhNxJjESijgZ6Bem8G7MNIqxTrCrS QLFo+BLLgukD6ZkkMrKD3W9Mcx4FgU6kEQyLtkCLcU2N1DWnrVbyZdlnAZBKLri5aINXPSpE4Gm EQFH0Qu4D4HdE7+xGxhfazr8dmTVa2Yi7hdFTBwbh+WKfHCthP1pbEaEW9Hk9/R+oj3vd1hf2jr vFZLuz8+BP8ltYYCKBchHqNYdFs= X-Google-Smtp-Source: AGHT+IGno+fa77AmTssdX4H67Hd63/OuJlqqzHcRWFRM16XBjfhRDi6DDMDapfZL7Ku1OBrm3gKDyg== X-Received: by 2002:a05:6512:124e:b0:540:2339:376e with SMTP id 2adb3069b0e04-542295512dbmr4683488e87.8.1735660059339; Tue, 31 Dec 2024 07:47:39 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:38 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 02/10] HID: pidff: Do not send effect envelope if it's empty Date: Tue, 31 Dec 2024 16:47:23 +0100 Message-ID: <20241231154731.1719919-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Envelope struct is always initialized, but the envelope itself is optional as described in USB PID Device class definition 1.0. 5.1.1.1 Type Specific Block Offsets ... 4) Effects that do not use Condition Blocks use 1 Parameter Block and an *optional* Envelope Block. Sending out "empty" envelope breaks force feedback on some devices with games that use SINE effect + offset to emulate constant force effect, as well as generally breaking Constant/Periodic effects. One of the affected brands is Moza Racing. This change prevents the envelope from being sent if it contains all 0 values while keeping the old behavior of only sending it, if it differs from the old one. 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 1b5d3db62c09..e78fd68edda3 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 Tue Dec 31 15:47:24 2024 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: 854481 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BA3419E99A; Tue, 31 Dec 2024 15:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660064; cv=none; b=hYQAB9WJx4HN5WZyIDH2JeZTtMSe+cm7IfClCVzNA5HOorGTnmcasDdeFdqyQhTw5F4QyVbs47nK9u0o1cv0Y/kCuumsiKDZ4KG0/1cPEvT3KFSFeeMrz6hR8VLphifA0XANfQXTbls7uxSVT91/JV823tPDG5B0vOqWhMydvzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660064; c=relaxed/simple; bh=E0h94hSIPqOd34Ao1TmITdkRH3Hv++DK7SU5sO3tn84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KCFRBaGCc3YSZbUFL3yOr1W5x/p3AxV8MfxiwLxXO2YAiCWMlowr7SDJ5CJmkXMVlCfKhxqSO6erAF0HPm1twNjFpypyPAvipP2HYR14+pKxSQdktar+gmvJ8vqVnsd04NYoLbmw0yfoeEE0N4Vi2zSXdcTJjN9FSKTy/aks48M= 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=IkyYF/wU; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IkyYF/wU" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53e395932c6so1671962e87.2; Tue, 31 Dec 2024 07:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660061; x=1736264861; 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=GgEW+UHxHwZOqasvpsQ09uLLCe7cyiXu2HdIVUfHgqI=; b=IkyYF/wUyjzw2hQrfwQ/NjLiS0jT1dke2k4SQbq5H18MrboPHJetJfCPByG+RRWc+s o3n+QT7nV/KURD8U6hE4NPRgsJ+KALbtpa7U/Kp53WWxP9hs/fuyWil6dLcbv35FeBo1 5chacGPiwe9hfhrnGRsjmZyN1kynTkgNDMWx53UX119bbD2b21ibsHZYYQMXfAqlP8jB 79gnvkE60mCcZB775d0JpqkIDmaRK8n3vpw6GS7tGkR024UcQru745kT/2DYJ9E6UKWW y+/0JCqWgVHII2I1rJb7T8x6eX4VYi89rSnZhvx7eaeSY77TcCLmeJad9IpbtgGtWCMa 80Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660061; x=1736264861; 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=GgEW+UHxHwZOqasvpsQ09uLLCe7cyiXu2HdIVUfHgqI=; b=L4hodJ0K7POqmZ3yMUgcy2bXZOWovUgfwArzN47TdKNxixr4Rgy0lBDPShrkB8wYgH UbrM5pYdRhenbyBZ5OYPt6wQiQRj7Cni6q6uy42R05RUGhgAoCG83rISf/lkGoOkhYQY uEmloGnAzDMclw/89+UabNY1KfelPpCqlcnMI4A65HP9Xj1bXdbg7T6LY+g6hWt/iwXp +wZVUiIVERc80+5QkTJfGTDUo+0PnO3FC1IRjEheZceeaqPqTzCH+UCcU1LOUiyhSXos +HKzQ5C1XluS3QifiCM+n0MplOxJj9OBex8Anuuo0028Y2+BJzIu8agKEnOJ/KO8YEyT f/Cg== X-Forwarded-Encrypted: i=1; AJvYcCXCGrPiT9r3mW/N/Sb9s7Mc7osDXyqenWBUsGKWJm4kNv//T6qwms6kBExMUluxi45C9TzhRAso/VU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+a/b+C5Vg5Lo91KIphzlHkoOjmnmkuNAWW8k+JMKzF6wSypi0 bJHrXZUwgC+K0lpFO4qu8v78w/jqW33g1/+dSxzxCMM7f1iquigQ X-Gm-Gg: ASbGncv+bZHV1XRVhICdrWdR2Aco3nfNktoy18jQZTZIXUxg0fsJxU2jQzieLZ1e3HO 87VmNAGYRGewslTBVAE0W5fsn9z4bj8nwFMg9+7pJn+B28LmUCYePNBoiaggDM8yeI0NyIeVbBr n78IdOFOJobYnm/hcxu0w/kCDhvxEvKX51YWH61mxdyDzTR4waO9o3MFKabCluWZ23gY6Jiufnc KmctjUV90NDHVH1sftWOwgfrJWc9Ltr4/2mBTVzv4lJDsGKN1ViR3SFj1NzBj+bpmSDa+or5MtH muZ3gisBRvSE46UDeBth08VjjEU= X-Google-Smtp-Source: AGHT+IFpfM/9nUaXOZszjFmWamDhsTwLkqGAobeDjB1u64LciM9NxCt8rh10kZPPRFKxhSgt0M92ZA== X-Received: by 2002:a05:6512:1042:b0:542:1137:6124 with SMTP id 2adb3069b0e04-5422952e2acmr5022832e87.5.1735660060907; Tue, 31 Dec 2024 07:47:40 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:40 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 03/10] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Tue, 31 Dec 2024 16:47:24 +0100 Message-ID: <20241231154731.1719919-4-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This ensures the effect can actually be played on the connected force feedback device. Adds clamping functions used instead of rescaling, as we don't want to change the characteristics of the periodic effects. Fixes edge cases found on Moza Racing and some other hardware where the effects would not play if the period is outside the defined logical range. 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 e78fd68edda3..76e934649ee8 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 Tue Dec 31 15:47:25 2024 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: 854555 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E0C41A4E77; Tue, 31 Dec 2024 15:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660066; cv=none; b=sSYGe+HcnNYfFDo/NFhOoulXlNyxFm1kN9cERTgokEu6gxmUqp+mj5nOJabW4YUPYSIlrtEeCpjGoWnwPBaIsc3UJr5x9WgWVKSUr+Qf+zWXqg94vyT+AgqwSALU6oXslITSnIdPW+EEjIwNpIuCtqH8UtyOxHKwCz5wXWc2yPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660066; c=relaxed/simple; bh=FzXR5ZIt1k1mMoS3zkft3ak/ZnXq3cAww8udD0d88z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JgTotA6bbi1THoIEFRXNAUHWlddU45d3L09/JZ7zA4+ZOWtLlA51wc60WCzpROCc4Eeg/EGE8qDFVuqD4LV0vovcmD1/O7x6m9Ye3hUpHBBAQTnN+1VODRY9apcXB0dpfnhmxUahForDd9UFFwkEGs4cEMq3G1X9z7a4pnzPsa4= 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=Djzdbi0u; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Djzdbi0u" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-53e395932c6so1671967e87.2; Tue, 31 Dec 2024 07:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660062; x=1736264862; 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=8CAKpJLWJjH/X69/jtfJ+1EDkQsYNvm4RceH3NbQhb8=; b=Djzdbi0uxySYNk1NLKwTAr/Jre2oir/Pg4LOYcvyQ3A5y/eMEnMGsoP9nV8rKpQIBp d05V668cIa8Gn5IRZV0tooMsieZ59walLqCPRv2taZZvib+yD+UUprn6ou+APez5Dp+i jFtAF45+jOfb1DL4BZSVyoqkSYiJVrzjuV18ZJXg+gzzVewrw4GjKFRPL92WCKMyectU i4xI0UUaq7Ta5wfKlW2Sgv8vTpQ7lVhNTyga2wnxvCuUIOtgQEz9SLKCC3JNMswOgE1s 2MvFc4VPPk+lm+oGNDYGbpMstc/WRfQ8wsFGwwzqAUxVlPD5GAgLHIIkhjWspOsaD4qM Q0Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660062; x=1736264862; 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=8CAKpJLWJjH/X69/jtfJ+1EDkQsYNvm4RceH3NbQhb8=; b=bcX+cyT8b3gvzKoLzzcOnufB9xPlkR62z72eUCaZelQuQqoQGB6A8ratwKhX2iEoGo HxxFr9iMSmlZA8wxmcKlVq7QFbahxbUG06D8yqB8kqNIguTDX8hNXIf1HZ782r+Xcxf2 QfmKAqWCY0LkU19//jyeeD6XpoQXobY8ei7/2fOjb7Gq0VUlIP+7aIBkSDABPzlrNXXD a3hPIiF/I+BAf8g6QwDxMBlvhLqVysCqn7XGWTpat5cTYr+S70FzLA6wFqLyKsqL/cIr DkK3EmmDHax2NfLkZuEqF8hqdZzmSBMK1hemBTviYcxzC2JXJgkIVi0g628UJGnbQh7X n50g== X-Forwarded-Encrypted: i=1; AJvYcCWrrdv9lcJgAhta8N2wHNtTAd1NYaVVH/s2JyoZl38tcd05Nq1rsxNA/zuXs1hbN+mmpvRRBJrWcig=@vger.kernel.org X-Gm-Message-State: AOJu0Yxk/7jra9tmTU8Ucehyh5uK3YRZmLkRlW+lorS5v0y6K/qXDMXS zdnpqyAl9bhXvykpn+dxHJPGIXaOF5lc82rjNN0ydjNaq/D3A6xP/q+w5VnZ X-Gm-Gg: ASbGncsEPgPW4OM70fjMv2AZQGOBsr6fpHCqgmcDBI3gKvFUOiu7FeAtYB3t8i0/MvL IO09tjqTMLCSPOSsV8OMJzUvbX55r0BNJZxH91nbZN0CyS5I/oYhFmRaze5l/Y4UCcwK+/pAwwJ ZrNThYvCbsGyLYN/baR4vD/iCIBFeNd+EWQxe1TbdgW+ExCVEeejgeexJIPlthan5bOAN3Glf6T BclpujE0GxcYiQFwuZeNKoufa41dHhULeQAyxYfQjIHWjDuY5WB56Sw/ihre09CPR/VdbeF2OM1 +hgJKotyrt5XUaSkc+uMoi4yRTc= X-Google-Smtp-Source: AGHT+IEKKzMQP+mHt0EySxGeMfQJaWeMMRH+fzu/TYz7hDJ5FMr9zllRYPKaS1uubKTC0VV2kKkbJA== X-Received: by 2002:a05:6512:2396:b0:542:2998:ac88 with SMTP id 2adb3069b0e04-5422998ad8cmr3747880e87.1.1735660062384; Tue, 31 Dec 2024 07:47:42 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:41 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 04/10] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Tue, 31 Dec 2024 16:47:25 +0100 Message-ID: <20241231154731.1719919-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 33 ++++++++++++++++++++++++++++----- include/linux/hid.h | 3 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 76e934649ee8..4c0aa2d9ed7a 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 Tue Dec 31 15:47:26 2024 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: 854480 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 9A2D41A8F97; Tue, 31 Dec 2024 15:47:45 +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=1735660067; cv=none; b=bEy5CyyFIQGoV0V9eMPAq8yfHbkb+3XhiIcG5azH6HPyCBUWNqpyXspkObNRTTADZeynv+n8j3hYcJYUD3mt2HbnR2YItd9gTCTDDHBOQSWS4B/c2kqKyjh2JQIyklEP8EJKft0BnwxzinjQVw24SIQ0jv328i59E01wPJONHtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660067; c=relaxed/simple; bh=U83jqWbQ5jwI987svOWPZ5chqByAy3YmkdcUu46o5OY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VKjfpt805nzRwhkpfmvaT3WUOayP01ixo4Hr0Yx/fK1EKXOwWf8xony2uncy2PnOrrSzXwBk1WK5tHd036iQL3DWYGTTZTvu4kJmGV9FRGvfeIOe89yVbU5Nm7zPIhnjYZop6yZ38o4NnjgEFv3qQMuE6xvCHRMC9ZCDv10vmyI= 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=m8Nic3qs; 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="m8Nic3qs" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-53de3ba3d39so1834695e87.1; Tue, 31 Dec 2024 07:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660064; x=1736264864; 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=kFFEubbksreAv93JMFTWcYywcrhWrDzoAG3F0NgiAnA=; b=m8Nic3qs5mSrsIKO8Dxs2tYcA4JXzI+qrJMfwY55C1A/P6QXfdO4oXIhZNWEUfdLPg BX09FQ1+9oAECqj+YWOxXjYRKWV7SK5JLzKPsY/nEKTHnXCdw/aW7BGnYRMMND91PNfK lXSo8OXnwPzuFdIrR2md4Mhf42JLqVwmGT7JunuPE01QSRxznTP8EGzZqfqe37fyk1cZ T/BsXJI7AUNFeXPCW3hQUzjODDdCp6qQ8xzZa9DtErJc/rJaCFNNdv7pHWjCBkepAQQ/ IMqKdF7v2OYAOW/N7YMV8nHNMYxwf8hXzU6NF4bcECnHGvSnseYyz42uFDmHE2/6S2HO ffGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660064; x=1736264864; 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=kFFEubbksreAv93JMFTWcYywcrhWrDzoAG3F0NgiAnA=; b=OCDqbVjwZPjCFc1FENZnDSUpb1yvmLKGUSFOo0uDU+S3AreHURbL7jI3ze5vDUxIuo FvkmgTyqw4nIZNreQu8ebwiBKFD4yABPx/JipLl4lGzeX9bcs0iy+Jq6CTWHp1c8/yFL QuAt+wWVwjhLxJkBdJd0c+reCb/GbNcxq32kwc29GbWM910X+JM/rukCiQj/gRNWPZVt TJn3DtY0D2M8saW3WahB6H7Pm5ZZk07jMyep6vhNnhmno8bYXxdmXKp/zB91I6JTOCDX RxCVHZuUnvsuqVIPsTAVkmEzaFt31M3ra5MyV6wi2kP6nF1GmFhoGGnd5sqw1aEam1J1 3grA== X-Forwarded-Encrypted: i=1; AJvYcCUQpiELlttnJkJ+Z1Trx8zbCSdNinBpz/Z5J82NkS3svpGdt3HUViH2pd06uqCz/ikw/8CCLYluy70=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1dkvyKGlZ+YpiE26H9UomDs2GmnxT1cmVVdbzrM8Drn0h6gAG SteV8lRJoTbg9WPrQsa8l6vgz7C0DbzxCU9UvDnclTUi78FB2EHk X-Gm-Gg: ASbGnctBNI6ZbqX8HuIufgzz1w7yAzIFdpUzzbP6wUhdW0krO8ZovgPOSxrah5FaMb3 vgg8CRc6s3xxM9zprXjm5kQCSZkCBw2dwIZ/UHsDO5iKPQS8ozU9pciLHJAey1/FZcQqVIhhm6B uA25/29AisfkMlSXVSoV1t7vHPM3l/g0j3R8g8Gyxzrvqzi2Sc6zQwpnKow3bLK5RlEP8pN11jY Nh65kOPXwUksvE21Ojwy/htHQsYy61+HXkhHrpmow8cpeDmBmEa3VLOrJvIIQQoExzlLgpF0UTK U6c8MLNWKQ+u1/EPGxrCPE3qNi8= X-Google-Smtp-Source: AGHT+IE7QyzDBcLbPoYsAaUzLct5E6w3hx0FXHBcwyuir/09pu68pomqZO542Ix6BIMYzfQ4dYPc4w== X-Received: by 2002:a05:6512:2826:b0:540:2300:25d2 with SMTP id 2adb3069b0e04-542295821c5mr4599169e87.14.1735660063521; Tue, 31 Dec 2024 07:47:43 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:42 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 05/10] HID: pidff: Add MISSING_PBO quirk and its detection Date: Tue, 31 Dec 2024 16:47:26 +0100 Message-ID: <20241231154731.1719919-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices with only one axis are missing PARAMETER_BLOCK_OFFSET field for conditional effects. They can only have one axis, so we're limiting the max_axis when setting the report for those effects. Automatic detection ensures compatibility even if such device won't be explicitly defined in the kernel. Fixes initialization of VRS DirectForce PRO and possibly other devices. 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 4c0aa2d9ed7a..0bc093ae1bb3 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 Tue Dec 31 15:47:27 2024 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: 854554 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.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 077701AAA32; Tue, 31 Dec 2024 15:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660068; cv=none; b=VXhELbuRVyzV/mO3Ewku96VAUaAZIYKyrgS1nA8nfbeGLToqM4rQAuWWksSdcK1oz08b6cE4pd5ycMbVv5WkpQ1JOhi04UGJK1TyvZQ1hScK4hBQJwwGHlzACorSb/CIuez9gdilokZAa95vwaWnYtpH+VISI2Iopac9MH5MMEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660068; c=relaxed/simple; bh=KCqDIocR6VSNW+kF+1pYcBY5/IqXQkv5wyifCzzA1S4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NP8u/dP9A82k9mMm0l5CzYP7dRp+2CQN4/7tYhBDmZzbmkEWjRoqtSjZprxSsidvU94+TRJ+XlOnqje+HZhbMW+tmMiSXsxlmZJSufb6DE+4D4cnV+VtxdiKbXbVmsRmQvp0HpIOceEk9+BO3Au8ZMwWjIbC8Wu80z3mDh1B7TY= 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=VR/sz2U7; arc=none smtp.client-ip=209.85.167.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="VR/sz2U7" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-53e395932c6so1671972e87.2; Tue, 31 Dec 2024 07:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660065; x=1736264865; 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=bseiL/nM6EMFEe+z8Ml4udYTl6QDi1PswIQ7XpZOADY=; b=VR/sz2U7bszqAq4ygpUbTj7Jr3Fg2GVeW67Un9bj0145SqUstkQWqxbrlFNvQ+fztu dkViq5tQ2QAQgusSIf4SGlk3J/8K/ZK7GSbMr1CPo2l3A4fta/S61FOplC27jo/MSSeS lAkbOT3sIr9bSRFIap7sZ35w1ASabKVrYywskUo/GqfU4uu8Y9e/2QeHiiZmbtaAE0RP SmSNQF3598cLo7e6ZYJ2NqJ4I5EN31S+hGYy6ZrrkuPN+Hk1jQoHPVBnFKMYCpohlepr qgbyEO3SWoeKF0TxZmRKZrWnDxGKIJHgFgBsMWF4f448mIQHJnj4xKJg0PcSbRiBio4b OvtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660065; x=1736264865; 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=bseiL/nM6EMFEe+z8Ml4udYTl6QDi1PswIQ7XpZOADY=; b=mUK1/OFxTRxIt+ZxXp5XFy1d6fclHnPxt7JmNQAJE4Ou8W/02y+ikX2Bax4mZu4Bdu 2JUp+1LXw2Jtu1LOFOLRPzCFagVilivGVdh/y8Gjy3jC2Mk8aEl9IFSfHaEeAfS9ixLm FLehMP9lKZCDULVFqdiTdF4LPfTQasQSsFFGXO3zJBWP1HtTvPOZ5pvQkSyaizvLntv4 O32ngGVhyM0kcXjDLsJbhWcWEdxrzYIKmnRJjMfG4VHDD3FDIvmc5mshzWoAcql0F6+q VyFx19EKhugVNdgwgXGXutBtyb/F0TpKyLZP3ioLDNb+Ae7tADZNstz9ODTMHR4Etui4 r6ag== X-Forwarded-Encrypted: i=1; AJvYcCXUvWgzPu/7paJoK87DWpQy8bLHGJGnowAOfBw1f3UbMn63aFlfIQQGx5I7WTEmTMgBx/e46Kxj3NQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzuqeD4uRlp94ejAoYTnkKUKop3IZyvtJ2BDK2DV/PAs4OkbL8a qlE/m4LfD2KjNaO9CmeYEz+ZRbIR/4JELvdgZdfHp/maTpxH1c0QSxx5bXNX X-Gm-Gg: ASbGncsUReqTouDMAoGywXzpIPx10KdzGpgf65fmswPqB5d45nZyGFmFcILixhCj9Qp RWUJBqcdvQMq52mHkuHl8/4NtBgt9NINkmDCE5FeZNp4XQHOjEGdokNDcz++IjRRojTG+z8C+iB fYaTduBBNomxEJ9EtPjw4Ktiq6ghAJ4fKTcmW/0fbB2OYc9YIZt3c8oeuPFVQM1fABsEVvJr767 jhZJM5EydxxB8rtmaSLw1a6xSowFZ5WpL2PAH2TQe8srLr7VmPdL5sj75/1CQPqGJ3MpXPg3Gea rSVV4Oq0rJfvZrLdiWkTEdT5H94= X-Google-Smtp-Source: AGHT+IFGOr8XyJvieBcR26zRjq+awHfzZ+v7lCjosaKGyu/e1HOnopOqPL1a32Bns/M+mYTvN6SppA== X-Received: by 2002:ac2:5681:0:b0:540:3593:9fd8 with SMTP id 2adb3069b0e04-5422953ac55mr4050945e87.7.1735660064999; Tue, 31 Dec 2024 07:47:44 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:44 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 06/10] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Tue, 31 Dec 2024 16:47:27 +0100 Message-ID: <20241231154731.1719919-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With this quirk, a PID device isn't required to have 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 0bc093ae1bb3..40265744019c 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 Tue Dec 31 15:47:28 2024 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: 854479 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F4FD1ACEC6; Tue, 31 Dec 2024 15:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660070; cv=none; b=S8cQUF4z9rKiDjL2vZCEjWuld+Am4Uq5pAH9hRZvsYfC9LQL2KVVmhAJrbz5HcKRmzQJcjlYoK5UCzbtAls2gxpHU80T5wut2yipHfLkOzZVarIJMff9o3R4neG7CVLWEkLDtB2cRWLaEqbm0owP3KemFuE4kVfKDHMlPahZfGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660070; c=relaxed/simple; bh=bNNWrHvrstpNkLISWDyYAYCpnkTyyXDOg58FtM48k84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MgBlBOjsGbGuuNdvtuH7ZCDi4MUb57qyUMO1tNdbB7FDthjYnviNaucGk6e7C/jxSWktw/tm+8X76TzoN8lXWoqPu2VuBzHC1gUQhytNA2cLD0fudq5artzdzOzBBOO15vlu8Wl5ZE+A0M1CwolsupazS64ROqhda3IB8wpCEJQ= 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=DlDumc/6; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DlDumc/6" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5402ec870b4so1534356e87.2; Tue, 31 Dec 2024 07:47:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660066; x=1736264866; 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=YTX8F3p4S40eatfHvwSuGkxjY16XjyhwFFVi3Zimu78=; b=DlDumc/6Y0rrUV3wTmgDcGyBalztg3AGeUqsVa/LrF/qDROcrvGEgQqUj4KGDFN05X wsTi+TZ231tSrESJ+wdAD2K56QFTIreyo8xuhOsimRk3Cf9Fn88phb6ZrHOwCJhSA8UD JVjOn2JJlzQ6l3YxznWBkqBSLQP7YdjeUEKR3QpGBw0gQNE8iwSKdtHYlYn8I+bW/tpi 64vuY6/S+3SxCYfRF7vQMgPOWt20e2loWizBbhxUXRCk0MKyIMw5PuC7owYZA6B5PzVb 5BlGVDzJ+dXQzrST/Fe7968OJhXO+iBw/u8WaTrrL+xWNbTKyAzGEz6cCsWCEf/OWOC1 3xOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660066; x=1736264866; 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=YTX8F3p4S40eatfHvwSuGkxjY16XjyhwFFVi3Zimu78=; b=eh4P/PHSdnRP6lds8dWkHSr2S5z0DH2zEOGMig0dI5joLaRA6AiLgzm8KSns8nYVyS Fiyf3NLLks8wcEaLAAB8sGuB8L9fccYS1ReOCrXA/A3cvcte+nZmFQlA82nf0pNI/DEo PGLS7uNs1TgH5oWJxfaA4zmkdOn51bo17nZMnI/URXe4IXxUzdmQUL/D0CjrCy/IxY0d UOOGRePXzPox9J9fsFYIUx0XDOMG3S9O5qiQe8PPzybNIvTF3sbO6ynfbQTjIUwTxvXY 8AtrhmvrgDfiEJECZWL5HUd3I8ajqF+Fon40MhyUkno2ArxiiJECicVlTBgiMUK8bTJu wiLA== X-Forwarded-Encrypted: i=1; AJvYcCVAZ2zrkUW6ftCyW9stdblGM4BuaEYOrzBJ2qn/aIQOU/WZc4Z/dV0YhTDJ0IeOR3JO8ErAZ5s8bcc=@vger.kernel.org X-Gm-Message-State: AOJu0YynFk5y8CcCuB3yvB95ithDmFVF/IaN9FZhBLQiZteg6uj+h9QI 8gQA3NS9Fv4sRtqqJZOUZnGwhFwkBMh0l3xIAcgqVTbtfv4cC2YS X-Gm-Gg: ASbGncuOwLtJJJvc0ZKTeEqe63hJs2ROO5lP32vJLbpGyVt3u/d7sisw2VSPYkXd3Tg cDJQZY8VOABxsF7Tg8C6odief7ho8b++WcGhl2YLH9d2cEhlmXZBTjZGVg14iTzswld+O5TVXc7 KbC9S8Cj504CijQywq1fWkU6FWjt2dEUPWdD9aibhteeztphIo9b3UkeXPk1TBTJbGBWfLA+Jf9 LLET1nyTEFUusExduNHN+/lzTLpNqK2Fa58rNR0B0qv8U3xiId001cqtvP9+8s5zM+or6dz+n2s sQDcjiaAK3QDjFs8FbfmpWA3Gec= X-Google-Smtp-Source: AGHT+IHiOPfwDMDAJ+2FJ95NX5jjn1NEDgAFy0cYvqMwpbK1G3JfslZQFc9IZ6cM8TWb6kR/0l1yDg== X-Received: by 2002:a05:651c:2204:b0:300:38ff:f8e1 with SMTP id 38308e7fff4ca-30468510d0dmr46966541fa.2.1735660066390; Tue, 31 Dec 2024 07:47:46 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:45 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 07/10] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Tue, 31 Dec 2024 16:47:28 +0100 Message-ID: <20241231154731.1719919-8-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 15 ++++++++++++++- include/linux/hid.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 40265744019c..c919e2db8dc0 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 Tue Dec 31 15:47:29 2024 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: 854553 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 D610A1B0416; Tue, 31 Dec 2024 15:47:49 +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=1735660071; cv=none; b=WbVT02DiEvr60WTOzgaIWP3yuhTVcEtq0yF1MwVnwylQzDQpEhoskv/NX601heeMFQRHikMrsbdZMPwcIKrQzQ0Jpu441/T/xPxqW1wakY3rnxoZsInevAdiyDAv5iHqs5f625dW63kP7zawcYU4ZvHDgD1sILENgERgirPj+m0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660071; c=relaxed/simple; bh=Oiuae5Cl2Hn9VDq8VlS/5r7/wNGQynu7R2EuPKE2sRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l2c7hjjJ+eGQyXGW+vptOsdkI5pJuixhZNSIqdkZQD1belTFFCdNLnEub/404jywHQGiwzCUJY2CEZsoihsvvCEFjg3qSwaAOtT2DguuBMRcWlo6uUNU1XC4O8eeYGqGh6S1fcoa2r19CBX6aYRfIs6jQJbtAuweEmoAkEBJZTc= 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=RqU/uYsA; 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="RqU/uYsA" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-53e38838026so1363019e87.3; Tue, 31 Dec 2024 07:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660068; x=1736264868; 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=SWk0zXmEn9co5az5Ci6nD0aZcMpWq63xhFJHEjDNB+g=; b=RqU/uYsA/CGqbKxiHGAckfnGtCo5T8WEXRT3XpFLMfO+kYng+il5McnUV/gu98WBmX JPe3dwixBoz+ykLepzH/JOqE6mLvTysTmOGTErQ7zRVa9jXDptVs/UW+8rVuWbYn7rrU lPtSG9oW93fY5YJe0YMUDczWmgAO+HBhH4enCx7yly6iOzZoQGaRpR895O4RoIzQvRsp g0WyBjZ+GmJ4vXiF0P0auV0UyUCn9xaEaD/LJvIyviSQ9ntaR227zvl/7VvOsgFRr40b 6KQSfYAEEObcQLqnhr3xyel9UcGZUU2lh2hP5ABX6nh1F5xclLCUyymhJjvH7seG05hb 2q+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660068; x=1736264868; 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=SWk0zXmEn9co5az5Ci6nD0aZcMpWq63xhFJHEjDNB+g=; b=tPIgMMcFRq2MRZQbCnY/SPyrDs0Us+k2CA4cIM+FfumijY9rf0tJe6wMPMXssKnAny A8UYyb0cqkV+vHcuR1NQxrO3kZyWc5XNWpCnWjT3Jg1v23v4eAEYuHht1quHQipubWoM LfhXhDjDcKYWBNqj9StUWA2q2mjoz9HPXNITegx7umE0lfK8ADcnnTcgqhAJtn7RmbFG qgSInfnMc5HH0aPhskm3+Ryp2+fCnDtGKwV38gVj11VQuGULED9jJsaGZHWWxj9ZYiaR vxrxVU8onfOlM+x2qC//e1Zuv0us6eq/qTzSlkfQ/EsHZCz7vgwDiefDxBHTmPRTpr8W 9Hpg== X-Forwarded-Encrypted: i=1; AJvYcCWp8rnlMCvxJpt7JdQHxv7ttD09beRekG8qDb33VbMHnZ/CPr2IdJkn7aYK5aXWrPi3o9uoXw1dBrE=@vger.kernel.org X-Gm-Message-State: AOJu0YyEt4ae1fVqprD0IlRoUzRfSMybcnAceaXPv/thHStDSoxezDzo 6t7HQX3gvLLURL6+hOidXHJgg9po0krIIvc/o+KAly4CSFkPhUcs X-Gm-Gg: ASbGncsOptdzKrV3wYXLsLmmv1VNeY9+JT3L3mDHLkCyRyoQuBKfSD+DEzJiertmJ4i 0Kn8NofZwr77by7NiGBdk4E6lp+DWxwugIKlQqnJtCkodmRZ5+qYOJ8IWx/T3I0JoYwrnJu/U7P fINGcEbGTO0XQHC31N8jkaOVvRGeufI5TODyFePpZb4mPD260R/xFAfVdZYeRZjDSJzmDyFGARD ZIJdfjicZhdDqC/hK4xKIz9JlGUiZggEX3QkOEe0zBYVe58+Gv0WOZ/jjRi5D9t8GW1wdZXobu+ vC1ICq6fi8pyrD3Fo4yqfC3QVbw= X-Google-Smtp-Source: AGHT+IF/6yKv86lJJDGNYxw33DSdZelTr2xEdVyEqf/THGDhV6uCfI7umRFmcCE7J1vlMJ2/dZzvlw== X-Received: by 2002:a05:6512:15a6:b0:53e:314e:6110 with SMTP id 2adb3069b0e04-54229568104mr4196874e87.11.1735660067851; Tue, 31 Dec 2024 07:47:47 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:47 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 08/10] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Tue, 31 Dec 2024 16:47:29 +0100 Message-ID: <20241231154731.1719919-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> SDL -> Linux API translation, and this value can be incorrect. This can lead to partial/complete loss of Force Feedback or even unexpected force reversal. Sadly, this quirk can't be detected automatically without sending out effects that would move an axis. This fixes FFB on Moza Racing devices and others where effect direction is not simply ignored. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 12 +++++++++--- include/linux/hid.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index c919e2db8dc0..cc02c5d1bd04 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 Tue Dec 31 15:47:30 2024 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: 854478 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 358421B0F0B; Tue, 31 Dec 2024 15:47:50 +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=1735660073; cv=none; b=a+KhpzihheeoVrJt1EjaSGJpq1F97y8OYFWZxMmK75ka0pOHWVlF9z12hsFBC0ZVZXg7hYVTs4KeFu7P11Ec9/pi3AAVfYM0bgePFKUD0yr9CdPCspY/GkyTVL2sZ7AK/DPC+i3OQ/fdPhfkeWQ4iZPTJ6R06XBKVsn3O0h/+LY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660073; c=relaxed/simple; bh=ag+0cxuK73zoYGsrfMXFvYFFR1YKGVjZHWh0GDKSSqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CzdsfDjV+nCNQEDCgIdVE6qeqd93j6olderXjzXubiIOvzCKrKMd4i019MgE72NTpU+KuApuynFAlx9mb586KUsH8Y9+AgQYpyckyuB+lYAoXe7YmE7LpQUuDgXnJeyt3THMo9YT6ryrmMeyXumuUzLE/WilhIrBKBnUAux+cMM= 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=TMYpF7Nm; 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="TMYpF7Nm" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53e15299724so1314280e87.2; Tue, 31 Dec 2024 07:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660069; x=1736264869; 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=CbYCK7GWBhW4MFt5ULHo5hCX5ObLdyz/1VYLg7hJlT8=; b=TMYpF7NmyZEj3NRv1ZvumJ8FwXzCmJ1kR5inSgSnbe8U8nNXD39RFVKMbAnKxmaFCz A+/0pL6CFmOIzFecmC65v8ZqeSoJv+dPScNRGpG/891WeLohfLIrww4Fnch6HWJq1nOW YlOAt9f9bQFCzNYkJBLGLtN18nP26eCNPJsbuvVkVEDqovdS/AoatmcBtW83sGfY+Cs7 xeQ+j5z+TIr6URZIpxEyHFsYm6EePtk5t47EzB5Iq8LukfQb29vtMdKLkGatpj8A8Dq2 r6Ze3n/Vc+0KyCl/byUQ59TIONHuTva8KdRXIl9kMk8dOkJ9C55aEVcEssZeVqc37lti Uq+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660069; x=1736264869; 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=CbYCK7GWBhW4MFt5ULHo5hCX5ObLdyz/1VYLg7hJlT8=; b=bJfIkUvxR91zwvEL/cuFTI7jDQMfKJbQi0DxIKmmYhZB6bUzy/8CGswbaz8lODKAD4 GTKAQKfFll1KAN712sP8u8/aB0U0mdsR1gt8Fh/YTMeJ8gSzum2Qb5qA7IETeo8He7RC YI7VTAeY4dSe77SDT7va61Ykbw8LasBfG/yb/dDfSrrE3wLN9i41bwNmPTQFk3HIgz4k 4H786ICERarGAOD+DncP5E9QsHNBCVPRjXGPFrchoqw1QdspLbBpeAx8KGpcRDdyNw2K +wbY/2DcihhmHTbfGJbWeUlTFtQKNvsNAppT5A9cXyy9AEaGY6vHGMOLrI2OCyfiv92Q xLvQ== X-Forwarded-Encrypted: i=1; AJvYcCVhnXz4c5sN3TQBhQIPKYDAS4oknUghF+wI0CHuqBzbGnB8XikMmS30MDZEfdI23ojSbNL78ZuKhxc=@vger.kernel.org X-Gm-Message-State: AOJu0YwDBfggRZO8iG7YqPxFnTsRnsDxqoOgfRYLYHzwOlQMSJ/Q+roi NW0PVQpkXDWvNsYXBGnhHVQzPJhrJzb3NgHL22mgD6JdaFu85rN3x3CNFT2P X-Gm-Gg: ASbGncts11OON6Ljp0kBqgTnNpOHigU2B6A5HEhbgw7lLwUWva5j8E0EQLLaVmvd4z3 PdkuQKy+3ePiMA3gOld5jXruDCt4alYzDYjdmnNseaW+o5t7CTEgi1n7BRt1j3k9/xmINxZHLBO A1HlZoDMPvaHyZloDVt88Ts6K/JAeG9GYhwSP6+KbD0FoiLfxnYYdn02U+ATfv0pfgPeB+yK7ih 6RGri2lEbJup1gPWk+ODb6wPJMth/nsYaV3irBW/XJoMoc/+YoX+HUt06Em2wNvLZPu/plEwEr3 1BrVBq+KQLMLBPh4evCISF3qYX8= X-Google-Smtp-Source: AGHT+IFE9pb2JKpTSVBH3YtD2Vh6jFjytZLI7D/N3CzdDVTyEcm5iRwtcLwG83OVdEwzLDSO9Pdwiw== X-Received: by 2002:ac2:5f1d:0:b0:542:2972:5778 with SMTP id 2adb3069b0e04-542297257d3mr3028276e87.10.1735660069127; Tue, 31 Dec 2024 07:47:49 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:48 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 09/10] HID: pidff: Stop all effects before enabling actuators Date: Tue, 31 Dec 2024 16:47:30 +0100 Message-ID: <20241231154731.1719919-10-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some PID compliant devices automatically play effects after boot (i.e. autocenter spring) that prevent the rendering of other effects since it is done outside the kernel driver. This makes sure all the effects currently played are stopped after resetting the device. It brings compatibility to the Brunner CLS-P joystick and others 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 cc02c5d1bd04..d5749020549c 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 Tue Dec 31 15:47:31 2024 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: 854552 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 4259A1B4122; Tue, 31 Dec 2024 15:47:52 +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=1735660074; cv=none; b=VZ8uT7J8EVo/Zwe0i0ohnFQtXy0DY1iVQNgoyumd0yp+UHz4yayiSOd5sZn/NSdwVGG7dcMIxjqDQKjGt/3j1qQUB/s7XDadVpAKcSYb3qBNonIFcjEa5JQoHUu8V+dGwcl8ommLDE8PTP++xNkFx2luQcusilwzieemPBBvtBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735660074; c=relaxed/simple; bh=xWpqaEsIadXF6Ky6qS49CmIFJPJmERZIHvExjcXMAjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HfRZfpkxoVb2m2AkBvhGvw1beCuKWZ1qf+rhhb02vV1ed8wSv2Gvz1W7SMX8g89MIjTyqb6l8kcXbma/A/hv0wyo3kLSOfq49Gj8KLllk836kwRKhyC+8/kn1gy3GgaClVOdQRNK3MB/lnUvwXTR7I02GDWrMgIq1HpDZ+mvR60= 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=UsmTTMyg; 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="UsmTTMyg" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-54019dfd6f1so1561727e87.0; Tue, 31 Dec 2024 07:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735660070; x=1736264870; 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=pqVwfloagYUm482MBInF8FR7ZXiywE0EMC7FeAdQz/0=; b=UsmTTMygFZDUEcHPrBwgjpbsh+Q2PpP5nCmKyU3bo+s1O6M9C3Xz2nskZIAliFTlRb U/lsU3oy0NvpzhgDtIJ2TB2oF/X9CKePz/aMQTy7/5AxzoIm55U3a/0LZ6hpmECqDLYq sJVSZ6WJtbQcHqGd5weu4fJUaNcpeErx0LsIBDYXMsdTe58WGDhUzS7zrDhXe+QhnOC1 XiiVYaq5Gsy6CtYC47WaAxxn4+xtfEcoyeOzAJBp4NrR/9Tw6hLsD4z35ifcMhYdexxv XlJMx0Xp9NLu5Z+bk2K+/j22fCinyzlk47SdtHZSFmpTdHY4daDtriizIJxuR6z5MbI5 3SzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735660070; x=1736264870; 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=pqVwfloagYUm482MBInF8FR7ZXiywE0EMC7FeAdQz/0=; b=dTtbZ0p2I7zoQ14xkMSQYgz0hWfPRb+k/D3zrrfqt456zAA3xgP2BGq/RT2qi0RBmy rgKH9KLc9xfCwQLBiEUTOT5U487rjTLO+UgwWeyUnSFpRjjQSZ14cwUZo7+urHKT2Q6v Ol0/7DiJv3mApXKucvb1PwcoWeGoAIyLC59q3sbFPBOFdgvK5Oal3P4ejxHcQE062vZR kbVLy3ll19j3b4CgzcFnV6nrU4tnnLWI9zkLo6lE0i9SABeWvqbyJ/Jt8xUOQaqaNpxE mLXlhSa+zPlnHFpy/6M7DpAWSsMgd9hz5sbwjHt7cVnr5BvE5YB05LRAPnyBLXOaP6MJ /7HQ== X-Forwarded-Encrypted: i=1; AJvYcCV6ksU5yYXOkeb31XHtbfiJRwl/L/jHY+7VCSV3hWuNQB0+cWV81KXqjeJ9GSVtaG126Nip3F5YerU=@vger.kernel.org X-Gm-Message-State: AOJu0YzuqOUmlWeY4AphLOgOFYttoTBwlcnXIBl+yb4H5ggo4eXLhCAV WS7uEg70u+PjBwaqG8b4ap1QQQiatLewez4pWPcmrD9iGPAgHIu6r8vJQ1gd X-Gm-Gg: ASbGncsBOqu1pjxgDmXJQZmFakHNSnQhWhmCU0lNLYT7JRlwY8TNqkunixQhQg2E6sB YrFpDc0cxcY0YwWyiYgS68C/68a+oYjzpzDyF/Y4IIXDBMEIWaXr7oF0OUGzpPCo1QgdgCmwXmt sGN3X3yhoK3PoXV3RbDMvMhyoOm66DZjesL3XLtr1FxgkSC5cij5aexCWHoGQJkMoD4EibRjXNG wfoR6OlFHDAdrY1RnKPtJbXq68gStGwp9hPD5QkZOBOH5nw50k1uSoSC9U8ntJkFbyLterIBq4E cWwRrHGLZYZGGFfAdWVpOy12pPs= X-Google-Smtp-Source: AGHT+IEbbq8uiMzc1SZgt1ccUzAKvIwDqaOoTjiA+x1KR5YCptgbvwljh3GpqZDcXXwQ4lyd8Zy57g== X-Received: by 2002:a05:6512:1391:b0:53e:3756:80ba with SMTP id 2adb3069b0e04-5422955e090mr4855233e87.9.1735660070269; Tue, 31 Dec 2024 07:47:50 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235ffe48sm3448869e87.73.2024.12.31.07.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 07:47:49 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, oleg@makarenk.ooo, paul@spacefreak18.xyz, f.kardame@manjaro.org, jules.noirant@orange.fr Subject: [PATCH 10/10] HID: Add hid-universal-pidff driver Date: Tue, 31 Dec 2024 16:47:31 +0100 Message-ID: <20241231154731.1719919-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend pidff compatibility, usable button range, 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 | 177 ++++++++++++++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 drivers/hid/hid-universal-pidff.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 4d2a89d65b65..ef03d80fe1b3 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 "Extend USB PID driver compatibility and usage" + depends on USB_HID + depends on HID_PID + help + Say Y here to enable 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..b1dbe2bbe29a 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..6906cfe4ef39 --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,177 @@ +// 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; + } + + u32 quirks = id->driver_data; + error = hid_pidff_init_with_quirks(hdev, quirks); + 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_X, + input->absinfo[ABS_X].minimum, + input->absinfo[ABS_X].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 ");