From patchwork Mon Jan 13 12:49:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 857345 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F357B1C3BEA; Mon, 13 Jan 2025 12:49:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772572; cv=none; b=EyGkkkjzDNgaI5ApRJwt0attjTB6HbfLZHlOyvi54fkOgJ/0wVPLhibyP8lsclQN9/94mxiLrXdG8Q7FDXRFZheU+3+XvnogeAAE8NEVBGCCgBzjnmuhKQT5E7vVU0E09nJKVdFiLnzF3K4SXluYSfwoRy4NIihhpK7tNDrUgt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772572; c=relaxed/simple; bh=/+jLhZcLoQEgUQACr+Amn7gI2OvYFrMDEDkQ6DUX/ko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Eh0p4xHAqWhStw24GxgD9Q8o3iS2QUmU+JuGljwAi4mLBOEzbsZoovv4wcp9RyizUaAfNlC28XqzoiZaxtW1l/puq/1QLMaUrb8AcTjHQncjDzyLVoKH2bleARPCKLFguuL9PXAhaLHLQ11k5JW0xDVbz/w5jwK/8tNoeFOmu+w= 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=CcKwN8x/; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CcKwN8x/" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-303548a9332so1879911fa.1; Mon, 13 Jan 2025 04:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772568; x=1737377368; 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=3qGnSXpK3gnCtwYCvW+DUBbmmLGb3BYTBH7tqE4+zHo=; b=CcKwN8x/3EI3J+/vRjJTbcRsgOEXpLzQfi6pNBDiMRKlRx0HH2034cqB4dC7Xoz4jW LE61EfJzaAqI4vYaqNnCfOrfRY8z4AvT02AUzebw1XPnuwsPw7nz9oOeWWvwYNUB9i+k AX3wuF7kQzVHtqz9Ts+KDGnfOrY+P4usLzOmnX3Zwgnq2haVxtqD8tXDflftjAzxV0F/ DqU8Qu+dUDsM/1OvE3HNdVkz58hh3IQ7oSfJjVtfioX0qhp8VHhDKDhpsQNe/IH5gGO1 h/hpjgJNi/qn+bD6R01ZNopmVqwN1losbUkpS23jSI5QrCdk1topU5ND1JdBg33JVZw/ hF2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772568; x=1737377368; 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=3qGnSXpK3gnCtwYCvW+DUBbmmLGb3BYTBH7tqE4+zHo=; b=AKaQsUzShDMjcNhQ11QAOvMLj6PleMWLgxBnIaYogL2W/TrS5ggIpvhE0a2Zo+yjM5 iPFUSJJXqe9+IToXsNBKc5s58kenrDqNHpoxUDBgNnHknXiuvPZzv89cQTH4DnTxISK1 /SIeqOqj9IOSJZHSUJdsWoNq0wTQqnDYwsh/bOcQgZYo+3B65oDofd4bhKJ53SaznGSK gvolDeTPQ+Mozt0soFihTatDUXHriAeJq3duI9W7Ngi7ZIb3IzU+ybJy7+b8s8vW7JW8 zYzYkrJf1XyfsmWQKnNzA5/GdF83gzqn+LyeeWlNRtSzflebTORZXW/A+ixnEgG9sXLt aHtQ== X-Forwarded-Encrypted: i=1; AJvYcCV1MImRncI6olFup3+zMHeB6431+hrBWz7YjbrZo/9dt5KzbLdcF/1VsqmWQbZg00QcqMSfD4mX0YB4ng==@vger.kernel.org, AJvYcCXWpFe3Vv+qEfeNsUeCmSxc3xF7B3HI5dxl/O/8FsiBOULqhYNncgBItqlcxf4BUH2l19KXXEeXvppZ@vger.kernel.org X-Gm-Message-State: AOJu0YzD3lGw2aP2goIlkguCkd//5d6+YjxhU8XETVFfCzgXPB+vM9lo Mug3dO+9xKx8wbPIlYwMztslqjNV5Y61w9lz0ndqF+H2ydiowYk9 X-Gm-Gg: ASbGncvCbC9fEKXSt/HIChYWUvy61e/gll0rhSt/36rN35vmZmX6lEnwhK3ejMoxIP/ nkzWRtuuapq7XzYVMtpGCKpNfUe8iI10P0ApwewWrIBMCzDj4IM9PdA9eS6NegQGv+UksoSkrvs bEnh3XpIZGVlVLZXdn7Oh9e3SzFxHTCbtJgVHzSEhs4gRH24m/YnXxfDrbIRbFQGhHq6ITuP7z1 a7pkwblhovbLje12+dWp9DdBeBZwrYL5Crju+Re142szKRD3jvZKaaXZmSi7fJ3Tqyrar2cD8F+ IrJ1ODGOIzBWkZ5SBAr36zu5lNQ= X-Google-Smtp-Source: AGHT+IEf1gt4wTM7Wp6+h7CttpZ0BBPYilkBhC30/6Bb57FoZi/MxkP/pDxcaka/6S1WlkrEAQLfaw== X-Received: by 2002:a2e:a54b:0:b0:2ff:c3d2:b0a0 with SMTP id 38308e7fff4ca-305f45591d2mr22451381fa.5.1736772567947; Mon, 13 Jan 2025 04:49:27 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:27 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v4 02/11] HID: pidff: Do not send effect envelope if it's empty Date: Mon, 13 Jan 2025 13:49:14 +0100 Message-ID: <20250113124923.234060-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-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 13 12:49:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 857344 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 1A198231CA4; Mon, 13 Jan 2025 12:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772574; cv=none; b=LMmHg5k7xrEEDzJHyEgWcqp7h/2fhl5laZbjHHFiCOXTHjmYwqrAqyix6eLeKAanddi7X2L5Ie5/piomUoKxljQiuA71CPtFzpxrNTovQ2a+p/qlIpukvg/9/F183T36Txjgiib+cAgZVN+a+VEAJ72loYBS/i5jZM5zWonSn54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772574; c=relaxed/simple; bh=+d0HyMNOkMms/+4S3y7y1zKcr7KT2SdwpQQHRu+KIa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kbd5N7Jf0buI0IRsDvFcE9Fe4i18Cc77IWusTaVv646FN3Qp/X0PJ6hhu47mZk692RSzrSh/NUSBHNH6WiGtnUw/cViPxOJBxZl3zguh47Ra6EGDGbpMpZf8c/LN2sfGYG4gC6m5H/u5LY4/wrO8Br8ZkBcRAlmxH06N5/08w6g= 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=cXPYvudV; arc=none smtp.client-ip=209.85.208.174 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="cXPYvudV" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-30167f66717so2493891fa.2; Mon, 13 Jan 2025 04:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772570; x=1737377370; 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=zVDn/ZwrDtBQBWFoygwf2iIYwvUq1iC1Us9noUk0/hs=; b=cXPYvudVipuf2STufdhAULOwXwmeMO6XXaD+F15O6zdY/LsQOkIFT6jYJwc5T97wIn wGm77avcl3IzaQQUU2dIhH6iFCWk2ipqIbJsRLV3KIY6LJf5IlRTSLKsj0RGwLhSpmWk e9HROQc2G73jI6LtFdaLbKwkeXqTK3PTDShAoRJD008BtO5KcEjb9QOH1nWnALZgIpuV T6fZ6T8jwXI2FfW3AU+4uUtWRS3+9OzyWvyn7oeDBC5w/xeJ45LaBveVZpUg1Iut4uyj uxO0LFJ3Ofr97vloPqOmb1bBYoh+cgSjTHU1jtK5kBfvonWOTFqcU/DoPrXrAnBFWJQp g2tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772570; x=1737377370; 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=zVDn/ZwrDtBQBWFoygwf2iIYwvUq1iC1Us9noUk0/hs=; b=dJJ/eyzb7keLP7vLxk1XOwSLeBtcUiGzomWo/cJ/9cqnQWoUBa7Cp184CWy0F+O7qQ Nf69CqF1/Yt5X64uajlD5NKXBuLbTbiQL2n+KoHavk6GpHs1pzctB0/e6WH2oKlXBmpx zQA8W5N0uu1+LWQKKGYyl/MGvz3A8SxZkue/iOWoy9Gs1zxbByaibHCjOdTDEVpHIX6x tdUhht4JKD2vBclWTyNIMTm30qjBoZ/zb/DpVM0tMQJAc7sHrSVIvLfFEGttVtk6/frz YgdVhtUW3NO6SV1JxSb9GKbErzdrKBDI9DBLCs4eYP+TADXPKW9sL3q38aBjYWu6sxsD dK9w== X-Forwarded-Encrypted: i=1; AJvYcCW3eQdHr23X4Mq69sgqY2ABJBCIWGGiBGmABC5DnbiqHRtZhZdGiChKs4VJoqTN07C/YfrdcEubAGXv@vger.kernel.org, AJvYcCWo0Zeji/gc5Wx6/3pnF+P+uJUrEkgoNSkkrhN5lnT11erB1cn3zqpXnxasBzzOPGKjyg3iMB3H4RFuKQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzcFmLnQO13alp8VEGI2ZKDm7nndklEPhbLOcLvd75WeW1vWbqP 219RK+Qc47A3hier9V7vaVVAdtRiay+akMtpAQUlYbKMWsBnNFvEQlgD/E54 X-Gm-Gg: ASbGncseh/GYsedHFpQr5wMpbL96h5r8yyTMWTz8/1m+peW/YzCqGSagzHmxmxjJpmy 7jCiX+k4PWAh8wasXejNyxFQm0W82CWu3MFAoy/GzyjUqPJP9cA9n7FfTT2+Mi8CycFlnlJEOip ywDAa0SToLNs4S/+UiWf5gqn/lvM0v/rkOydjzTesiRsbmMxKOIQY2cqIBV88RhR/TREHH4YjwW H6X70ToBoSDtJ+hLMjqMAkFm72ZtAaTb0Q4bI9bRaq3k98vclu5g2ZlCxEGZkOebgdOId6urG27 B41JrUPokjkW0qRJxv496zWCqos= X-Google-Smtp-Source: AGHT+IEe3KYLwI5AcMsLKpiz+B9j/Zy1FZpvNCRe7DrMLW4zHeMF+P7TY8XVEbDZvRC1pFKyPDeGWQ== X-Received: by 2002:a2e:b8c8:0:b0:302:1c90:58e0 with SMTP id 38308e7fff4ca-305f45446e7mr24810411fa.1.1736772570018; Mon, 13 Jan 2025 04:49:30 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:29 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v4 04/11] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Mon, 13 Jan 2025 13:49:16 +0100 Message-ID: <20250113124923.234060-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-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 13 12:49:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 857343 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9280C2343AE; Mon, 13 Jan 2025 12:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772576; cv=none; b=G9fQMgztIDRJINOJn54RvFjVPgnzMQa8VLBlR/C0rY1lzaXGwqoWZJ0C56Dt3LFiR7cis8xwcbRcERQyXPQakzuOHXRTa7xeGTSog2zNl3ReKZivtTUHBzEh2pVhwNZ58eKk33kLi4STPX/0to+rHWByiN5cxfMmbyVt+vZiErw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772576; c=relaxed/simple; bh=mIV6vVTLgoqMdIh6ptgFHVykZQegUSWZ88SkxLdjZS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iajdJv3zNHaI66PHSengWqE4ILxTh0ruQyCrNj0vkL396abGEpeIwoISyANDVhIz4ZDp3KkDWl8WleJS1AqCrTnJl1rXpN3X5W2BHvrwUPLHDiTRjVVjBCk/eq3nLSL1J22HWMGaNVIznBiZ3DtdvMjD4WrW5eJSxIrqGM6VPGc= 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=etHV8lWa; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="etHV8lWa" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5401c2bb7ccso448208e87.0; Mon, 13 Jan 2025 04:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772573; x=1737377373; 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=5AmMrfDKAOcMysNhMtuiAGss7W3D6be+68Km4J+O6cE=; b=etHV8lWakQmo2CQvoOkj2k2zXTZJtV7/w0Xq9NZhMCH9XWarK/XmGg2I3Z5N7L3HA0 FNhiL0fbAuRwFRhnGZ3LMp6DiE0B+tCz62szoIoAqpBI31zxPrFzZLS6VZWGc8va6IdC lcDiq/e9oNxZ4FUZ+YHRPTFJMFgVOWVuoHQ7fuUHgC6dLTapAgVKMiSoLaXs/qy0RIDG V2MPdK/kKPq4OQsSlE+q62090FUjGP9UfFoer3MqwjxLkAGwCg4+iSpVCtVdciuLYnTw 7ilJ1fD/X+Vn4X9JGHieg4qJCRrP6OEY0jQjlodQOvBDHEYhc2nmgyapRdaPk3ZgHKFj 0dJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772573; x=1737377373; 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=5AmMrfDKAOcMysNhMtuiAGss7W3D6be+68Km4J+O6cE=; b=HKFgxGUMG5Pvb82f8ZWiRMZ3TV6MK8lgtO03P2PYebEPaXPv/rCu7vHvvd/Hc6jgg8 XrrfztBfD0JiT47Kb5qFqLG0SIKCTzJdo2vZ5rUN3T0neYjHbX8pmQFzA05H0vLo8gOp J1SV9VNmwUokz4o1CLorj6J5wlu8zwGbxbvI8o2Y+X0bQojgcuM+kbKU88lwLT6eb9fy 74F8hKNGyKvaG649ZdvwuKuDVJUMtivcD9lrPdx5yoe09NHqWldAvzbvfh+b3BuYJYge 2rcY5uEjRw+sBHsK9/OGApcTsu8zzhoJQHogsubx0vCf5qenH621OLDiCedz4N5c1GWc F2lQ== X-Forwarded-Encrypted: i=1; AJvYcCUCCLE0O/fId5GeU00+oTugjvL7gGn995B4MYtdFn90Ans8RaGRacs7ocI23LjOemznb7jOagi33T4WHA==@vger.kernel.org, AJvYcCXNDWN8zUCHoYomEWZgg2JyH0Ss6PiHMQH/kOFnnXKIIofog99b6xiCwMcBm92x/lz3vo/RtJZH1ylr@vger.kernel.org X-Gm-Message-State: AOJu0Yz4TlLXPCi1ojkMso5dkQBm8drH6W/27i5nUluFLZZ+CDLaXI1c Zl3tNChHd2aWZifxTSqIxoaVtSYUGaXCYFo7twqZWrsSBKz6tLNv X-Gm-Gg: ASbGncvpIw59ujkh0lkgXGtQ+9Xovfa80HZ16kj6WBj3TF9x16v74HzPP2GGzJ2uNn4 BJitqF29J21y2l9uqb3j07OZjklzz0hw24SPdFz8cDTdY3VPQh8KJB0lnx0V0vKlaKQtsgUXAld TrXC+wu9A7IWgZyKU05vCaAXPp6faP7RdbOEGDsu1Md81LB/zc+qi/vVeQumOCAi3vmIzjIArVR bxKTE094RqfvXVZpNMKcuQpws1zRWkYz/VDAZr63UPM7XcjS6075AJBhuVQTwhQ3l0r1dVNcZeZ 7NlHnGlJhQk3zClNVpntj925rK0= X-Google-Smtp-Source: AGHT+IE+QVxc/eMSAAQHH3siCOUD9cLG+hVBDAULZS0cs62WnoJ66dhfSz6BJbdIvMgnLki7ksZJgg== X-Received: by 2002:a05:6512:4013:b0:542:1137:6124 with SMTP id 2adb3069b0e04-54284546adamr2330911e87.5.1736772572463; Mon, 13 Jan 2025 04:49:32 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:31 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v4 06/11] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Mon, 13 Jan 2025 13:49:18 +0100 Message-ID: <20250113124923.234060-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-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 13 12:49:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 857342 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 3BF03235BFE; Mon, 13 Jan 2025 12:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772579; cv=none; b=g3X3lF4ZA5xuZ1lTaArZqNIjz32Khdwm5mr9LbwAkFufIeexxLmupYzigcci6WhQv3TtvGsjcz8AejkcBI3jDajwxHDUogcnAGZQA8LHYzEJ7uiYdtno1iQ5eWgXxno6fvV4PYuf5CUSRDfRwgDorCRBIGo+KMapSfqWuNzgx9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772579; c=relaxed/simple; bh=IaypjfdSOe8nS4otI9Be/27/cxLcxi0UpgFYsqF8KKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u3wEQtO/mzZZ0Or50AZ3va2sF7aJXuWGOaR97MMQ9X2RxuYPyMyg11v0D2ZKN3fIP0Fxd84JDzAy4KNO/uo1Z+bAwEiliZnr3uI2UgfCPz0QKvG2ej1UNEbq1bFxtHMoUHVM47UUX4e0DCjt0EhVJgBaVoTSSVkdpqp/Xb/J9s0= 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=N6ya6S1n; arc=none smtp.client-ip=209.85.208.177 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="N6ya6S1n" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-30600722804so2546921fa.1; Mon, 13 Jan 2025 04:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772575; x=1737377375; 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=sAkPBKIk6Eax1YHZili/NnZHZkLHuP8KZdGBQcPKewo=; b=N6ya6S1nkH14e6BoKvolnrpU6BLvC8TEvHKEg4ZYKJzcY2PNqf6DUf3jxdgb8yT5mW HsoQI0NUEgx6c6jJRgjZfaZo7wSeyOr/tMp8vU48Wh2TJbjpfbjCGOE4yBQmh5L3PsTT 3vUBd5QwwYcODgM4sZxfFaZB+/ZcNuLjl9EWv+S8nqEdUhxHqJWGRgvAP8t2K/A6SJHl YcdCaRnXDNGZyLpk0L9QCcz4gCKMe16OcDg8O29ak3ESN/KVa4iuSqaIz97AZ5TbWF3E oMXte1VdolM5NiZkKBwzQrH/r8BB4jcxlpHtDZjAi5kj5vecja/qeNNsa5TNN/lbOPin peVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772575; x=1737377375; 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=sAkPBKIk6Eax1YHZili/NnZHZkLHuP8KZdGBQcPKewo=; b=qUU1erOxJqj3Z9k5mS5yFT1GAVos99uk5vrTp1vSZgEyAVgktuGBdOyHbbTwsGppAr D8iNzvBPhh/sqCYuFzRon/D+Uux8sN5t6k+ixzdfxWJopfDNj7DUN32dgxvRp6ssY1cU jFpOZARzKIVkpcq34x1qBy2rftTX0UUwUMnJFoT+5NmtT06cKKZ7ZT3q8YBXyI/mC/D3 2iaDCziUeGnX+sJZL7gVbtCKAzfXKiGsn5ASbJalHCosaMSWTB0ijOh3JvsxeF8Owoea XZDbym0puClqVIv+wbVPHVuBNrYUASoRWa7HeZUeuLIQugRNCNMxvGNTv1Mg99FMykG2 FLpA== X-Forwarded-Encrypted: i=1; AJvYcCVBL5v2XMPilJu/+HD2fHlGatBVtIaI/CSqbt6pBFWqropnu+VckLT0IcCS4+qnPf/VBYePVsvgdi3zjw==@vger.kernel.org, AJvYcCXeLhGWOO3XMc6pjN1hYItWH/SBq25MVTdR5OxEGSaVHiLOIknSdOQlZvJhbunsT7YQBcpyacbdPr54@vger.kernel.org X-Gm-Message-State: AOJu0YxqF4DmYWqwZBBjPoojGMNcA0YFnH7nyIBG2B60K7iysrDPPP5M er06GkphSIFJQoC5UpoxzBgbn1hS5f7xPV2qQk7joqu+V9P30F15 X-Gm-Gg: ASbGncumlgKx3V8o8nSeWb0Sex2beiOOvkQZdjLbDDpy14afjiTdazkVsQjfoe+6Ynt gR5KVdOalqqgN16pLGTC7tOGoRsDwTZxaN98z0FXxPcLIxO6I0AVVsPl44JB7mkNo9RR1MX2chd kqbL2TxWoZ2FxjVc3QzX1UvtEHQzNAKU1b1epK8W6mDlNoN52Bbr2rca2PpkSAlhHYaQ+F07mZe xRU7AKuRYpY/oPQuMRp7u0liNyekLqZ52Zckh6eawY9uf9v6zKXWD8rUjrt9kDDFM3YeyCoD0rj RQ1gCDKVdg3uUU7yfe933hL3VRU= X-Google-Smtp-Source: AGHT+IG30YU4e24YJv9/9dVjXcMTLLOtQm5ebP8+gwTcC/nl+e+sCqpxFXJj547Pur75Pv/I9UHecQ== X-Received: by 2002:a05:651c:1544:b0:302:3356:54e2 with SMTP id 38308e7fff4ca-305f45f262amr23011861fa.10.1736772575130; Mon, 13 Jan 2025 04:49:35 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:34 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v4 08/11] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Mon, 13 Jan 2025 13:49:20 +0100 Message-ID: <20250113124923.234060-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-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 13 12:49:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 857341 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF251231C80; Mon, 13 Jan 2025 12:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772581; cv=none; b=pZi/LCOwTGCj6wnS8QUBk1ZBmI2QXSP7Rtb5QKjyVuUNpaKOv5Nb2v+YbPi3HwWx87P3yCpaVT8dJct6xUjzPveCu2vZ4XVnaS6vjyPy5LvHCdejWLvFg7uaqOjMqZscvfJG0MeKtVMPF8U47Ugd8w3saT7AsG8BMKtTbLsqCQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736772581; c=relaxed/simple; bh=8Ai6MHLLfUNdYTV4eukBW97XboF2ZkeyBx2Oclw6RsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gF6QkxGi0hQY9bN0ABgWcu4A1LsIt34OzJ4B00mUCAbwAEQuDJfuHvcCppAfxvfPUtILyLiIXp6GP2kMRy3XVakbnk1LcPFex9EHTx+gdirHZeyJUnS/EyzwNP8jvR1pZh5wBM1mlcnoIdThE18myzbHRtTuMBvZj/Fivb9nW9o= 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=KOD2jVot; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KOD2jVot" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-53e395932c6so430525e87.2; Mon, 13 Jan 2025 04:49:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736772578; x=1737377378; 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=ngugzYbBqdvyqcWs61z02MKyeKB0wNRHW1tziXtBtJo=; b=KOD2jVotO5FkNGugrnTrYVlJPZDVvRWIDkC+Cvon0ZCZfhxUBLVMamaGV1d74l5zDw 1w0Hazx7w6larkbf9/O4wc408y7PFaUXE3QHw7kA0ZV+GLyWl/P0ViE/MvTIkOepzyLL Pl3nHM4UFqoyIw6BpIt0j6BqmSsSHX0xs7VLa02/kWmnTTfyyUVa0OVafwBF7bhhavu0 jG+NHzdWThGVD034D57dg3WVRsf5uBeufU8ySzinxVCU5iix2cjpYwAa4Jg1Ae4qtt/a cncObnoPtM6DcspROnBEjvrFTtErEZmmMiY1munuM7r89nrgQ7A/FeZYz0U8haYq7r/1 fi9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736772578; x=1737377378; 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=ngugzYbBqdvyqcWs61z02MKyeKB0wNRHW1tziXtBtJo=; b=xQJWEObuh8MqWXXOJPusEi6idd+zuf13nE+78k0oWCS00z/jcRHnfaRTpYWnBB+Ftf qqfWRhas47tHKLEGt1WG36pdMYal0YF1UR3y9SqMNwVH7VTkoZ59/Vl1AoPVcMhkuBpU 1cgTQ1sX5ZR1oYvZ/FkFEftXTcxMJxJLQE/3PeW89vH1XoaBYOLSDnzzoaChzr/HO84t 555EfiTsQBUUiCAUySmb4DyRKi2b09aeUGJoWOh8TAmukxyok2QkKhenDLI9wZJJhjja wKrXwFt3G1hXU6fueEVWHvsproExWgYOTQ0mNmrZZiESeTBUyzyEj+XHVuJZl/HjUuAo c6ng== X-Forwarded-Encrypted: i=1; AJvYcCVy34t7IRob2RhFcg1OWHzaBEmvq+GbKHPumv+lYX2Uif6vpfmos9o3/iFMpHqh6GmqaS9sBjMB+iLu0g==@vger.kernel.org, AJvYcCVzWOC0hNte3Zi3YTJqCjSSuJyfqaSPgdEHSQtYeIw1zqI5XlgZ2qEsQv8BtFE8UzWFMAnpyeBl4X4Y@vger.kernel.org X-Gm-Message-State: AOJu0Yw4ciFcj+4Tu9FH4NjVpSMGpm3pwNzb9y1A/dRNNuDHtynwGpX4 LWYRhsZfJFzyHeNTX0RoI8oRZlkXwNNzqn6TpqNjl0jnzf1wcXZH X-Gm-Gg: ASbGncuDxQ1g7psy48VAXOR7a5v5z586MWUhhT0LWT/Z1gOZhl1JPFlxO7imCfI34h6 xbMqvwjF6KwXaPNcFEenqP/uJ27ePvK4RUkeDw8BqgHLEfGuxVWpp6c6+m5N0DNSV1/MvEYb6n8 NuHS+6mOf0H5sGAHbmcZGVT/y2LwgesO6KSBQRmRTAMr2/eg4riHVRnoj9pMEVn0GFRpqHxGNOv RdfUd0LwMMdTpdrNqDoUqI09BHGYlrcz0jxwRydkvoaxbbq3O815TNo4C3jH1NHWDy1H/00S+Ne YnhtRStNshbJxMF0nrNsIyQEug8= X-Google-Smtp-Source: AGHT+IFU+uAiO2DdeBkRhAGKP19tDPZB0a7bnA0zWQIIOEzwpIfsMBTTdkHCM7cUIqVwZr+F9SHvnQ== X-Received: by 2002:a05:6512:1081:b0:542:2998:ac88 with SMTP id 2adb3069b0e04-542845116eemr2282255e87.1.1736772577625; Mon, 13 Jan 2025 04:49:37 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec162sm14256181fa.101.2025.01.13.04.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 04:49:36 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v4 10/11] HID: Add hid-universal-pidff driver and supported device ids Date: Mon, 13 Jan 2025 13:49:22 +0100 Message-ID: <20250113124923.234060-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250113124923.234060-1-tomasz.pakula.oficjalny@gmail.com> References: <20250113124923.234060-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 | 29 +++++ drivers/hid/hid-universal-pidff.c | 188 ++++++++++++++++++++++++++++++ 4 files changed, 232 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..af74dbca69fd 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -261,6 +261,10 @@ #define USB_DEVICE_ID_BTC_EMPREX_REMOTE 0x5578 #define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577 +#define USB_VENDOR_ID_CAMMUS 0x3416 +#define USB_DEVICE_ID_CAMMUS_C5 0x0301 +#define USB_DEVICE_ID_CAMMUS_C12 0x0302 + #define USB_VENDOR_ID_CANDO 0x2087 #define USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH 0x0703 #define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01 @@ -452,6 +456,11 @@ #define USB_VENDOR_ID_EVISION 0x320f #define USB_DEVICE_ID_EVISION_ICL01 0x5041 +#define USB_VENDOR_ID_FFBEAST 0x045b +#define USB_DEVICE_ID_FFBEAST_JOYSTICK 0x58f9 +#define USB_DEVICE_ID_FFBEAST_RUDDER 0x5968 +#define USB_DEVICE_ID_FFBEAST_WHEEL 0x59d7 + #define USB_VENDOR_ID_FLATFROG 0x25b5 #define USB_DEVICE_ID_MULTITOUCH_3200 0x0002 @@ -817,6 +826,11 @@ #define I2C_DEVICE_ID_LG_8001 0x8001 #define I2C_DEVICE_ID_LG_7010 0x7010 +#define USB_VENDOR_ID_LITE_STAR 0x11ff +#define USB_DEVICE_ID_PXN_V12 0x1212 +#define USB_DEVICE_ID_PXN_V12_LITE 0x1112 +#define USB_DEVICE_ID_PXN_V12_LITE_2 0x1211 + #define USB_VENDOR_ID_LOGITECH 0x046d #define USB_DEVICE_ID_LOGITECH_Z_10_SPK 0x0a07 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e @@ -964,6 +978,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 +1399,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..0f81df9a019b --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,188 @@ +// 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) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LITE_STAR, USB_DEVICE_ID_PXN_V12_LITE_2) }, + { } +}; +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 ");