From patchwork Mon Jan 6 21:35:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855393 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE4271E0B72; Mon, 6 Jan 2025 21:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199350; cv=none; b=PVvUbZCsraikzmTMRDGDbpdCGn/9DHEb1tApzWHX9xUFc0JxqoG7owCF0GdoIjNrbnrLbtAGWx3XfXs3ApZYDktHBObg4MI7iPFWZ727fsvR0uEMdbw0WA2/Wb7Td/7y/y6EOdHhhAxMlc91XfUqiaYxPb7w9V7lss7pZLVrPUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199350; c=relaxed/simple; bh=tWq+ZnBjlOupEjtG5PBxOjtcCachtKjWc1EONIVj4X4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=awggVdDEbUYIZIIGIVyYsPRgoIc+8LQ/XQVP91jNqoxw/Rg1RNjqqDmnmTrZ/cVVWGu988szAJ79Sl8d0/ZFtml6K7gJqTZ/ws/lSRgalHxtA0348Hu3aoydzDPSvu21/wD/ZdSfWM7tmmoMDiPQXWqfMPhkqEKFnrn9SLXjVQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jlLzrLyG; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jlLzrLyG" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d0ac3be718so3279925a12.1; Mon, 06 Jan 2025 13:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199346; x=1736804146; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2aG6QxwL2dLzIzlkegu/7XX/7ENaDG1aCgGKgLUZHrA=; b=jlLzrLyGfssYgj5YHObPUWpgCndmwnhtSz4eonMRTU9+EH9kDD3B+GjcWKjwXAzOI6 /ykeALujEHf21VbReE2hLZ1b9pLGwIhOtlWDllWtJjfTU1qbgYKe8FMoETppj9AJnffZ dfcQjAqIglH8mkYz1KPZcmsg0xy0d+O5WVEBth0g74LEbvdH7vM15kMMfe7HM1+iYPq9 FPZNtuwshO9s+y5cHkHHF1Kwx+JLmkjTH4FEzwyPmZFvesn1vg9PagVQ7dB2cViD/nz7 UC6NA7ZOHoQa/+S//OxvOfQonzByvHqpRbJSTo9xJgIW/iDd0xg91KSgEqVOOegqBDvn 1Qdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199346; x=1736804146; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2aG6QxwL2dLzIzlkegu/7XX/7ENaDG1aCgGKgLUZHrA=; b=QO0xbrt+Adu78mLXwk1FvcESRFRSSs2RGbp2yyoLZYskJ27M5e0Zq06XiM8HviENB+ ORH+RhnrioFZ+kYRTu+4Lvf7j5GIJuubM3pmsbwxViLwbw7lMoPAsS0eIFMEdsUQGwL4 LAjdhGjnvWRCVZW293Fs1KOihyaGS73bT1jQotIqQ33iKJHMoBTN2YdDn1OZUjpXeRMv txuUnTSGwKK2oMvtzHbWR/LZXjsIaWtXZWSmzF7DZvM6Q9kcumz5E9l+oJf8e/ky8rrM 7VVdY/vAOIiVYvpmCLd0AOv9CVyyo+rAGz11fe2C7TL6ANDlEee/kxowOzuigq2MPivZ GaoQ== X-Forwarded-Encrypted: i=1; AJvYcCWiTbyzj4/90MXLveOL749BDizihSduXAOfi1czHKXLZpyXLS11wz/czsurSGWOOL7TEZmTl+Y6Ttk=@vger.kernel.org X-Gm-Message-State: AOJu0YwvDDQIrUP9Bk1pO7oCjv3t+o9jVrtPCgDdvQjxNMRm5QkSrqtC ShbeWv1p56zFEBPAZVVWxM8gR/QDdul3lVjBX/qKaTg2UeEJlem4tS+cBO7a X-Gm-Gg: ASbGncv350ur/Uom6FoABlNyMd6fXhKFz6Y2UotehDq9I3eLrhx9UWvL+w+kLwYt25G BKEjiTs6t26hX5VFbEBkYtTwI/i9teiw9U9/Lm5PZCV+gR6K1dEiN8N7+DJfDzeoPaO9MyF5V+q gmDVFqC+4hSwi9onNwgBiCABkQGQyrGCVtV9si3MXfIwBPnsV2VAWox2QwcZrArAibC1FZdK0cP I85WKuEo6BH0kd4aHZ/d8c6FsmNaE8k0oLfg80UUqKOEx3tDsQEUcsxy5PpegU0AH5MRrys7j73 0wGqDa6JxqX0BDC1xEGJOU/KbUI= X-Google-Smtp-Source: AGHT+IGk84mkLY+gDCWva3727Y8Weq773UelfPge2HEn5EREpCwHdkyn3P82x/mw0iQjY3F/djz/aQ== X-Received: by 2002:a05:6402:5109:b0:5d0:bd3b:b9a9 with SMTP id 4fb4d7f45d1cf-5d81de1c38cmr21554449a12.8.1736199346071; Mon, 06 Jan 2025 13:35:46 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:45 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 02/10] HID: pidff: Do not send effect envelope if it's empty Date: Mon, 6 Jan 2025 22:35:31 +0100 Message-ID: <20250106213539.77709-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-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 3899d72a0b02..cf8163d92ea4 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -261,10 +261,19 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, static int pidff_needs_set_envelope(struct ff_envelope *envelope, struct ff_envelope *old) { - return envelope->attack_level != old->attack_level || - envelope->fade_level != old->fade_level || + bool needs_new_envelope; + needs_new_envelope = envelope->attack_level != 0 || + envelope->fade_level != 0 || + envelope->attack_length != 0 || + envelope->fade_length != 0; + + if (!needs_new_envelope || !old) + return needs_new_envelope; + + return envelope->attack_level != old->attack_level || + envelope->fade_level != old->fade_level || envelope->attack_length != old->attack_length || - envelope->fade_length != old->fade_length; + envelope->fade_length != old->fade_length; } /* @@ -579,11 +588,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_constant(effect, old)) pidff_set_constant_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.constant.envelope, - &old->u.constant.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.constant.envelope); + if (pidff_needs_set_envelope(&effect->u.constant.envelope, + &old->u.constant.envelope)) + pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; case FF_PERIODIC: @@ -618,11 +625,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_periodic(effect, old)) pidff_set_periodic_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.periodic.envelope, - &old->u.periodic.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.periodic.envelope); + if (pidff_needs_set_envelope(&effect->u.periodic.envelope, + &old->u.periodic.envelope)) + pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; case FF_RAMP: @@ -636,11 +641,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_ramp(effect, old)) pidff_set_ramp_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.ramp.envelope, - &old->u.ramp.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.ramp.envelope); + if (pidff_needs_set_envelope(&effect->u.ramp.envelope, + &old->u.ramp.envelope)) + pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; case FF_SPRING: From patchwork Mon Jan 6 21:35:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855392 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B3841E00BF; Mon, 6 Jan 2025 21:35:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199352; cv=none; b=fyhCL2foeanJApNpBvuaH+rNoNcQrmWBBREI0gmAdkwU6x+kEbBqYGRTub22N9QhsK6vletAv8TI5WqFgdkZpAWkVL0sEObKoGYLFrD5Krupku+wGLs00aTqdwtGlKTV0ZYHwaWLHIP4pR7fIeDEp2yYsKgIfywUWW+rBAaAGMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199352; c=relaxed/simple; bh=lwoYk8NIAbQoRUBh6t/sze22q7+oy0VMCbNV9NT2mq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qcHxbw76DguUEHe681KSrWtsN8d5UtKfRFxLChQNA8Tf26f0vHWnCpRYyHdft0z+cyDSFf3r2FeCAFjHTTAk9qELuFeZZ5XEt6tMD/7iseHCRsGCy1zeLiU6WLdp6S0xRvmQHh5hEXe4lURN5njT3TJ6Sah817+5xqyo8vpFsX4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qi6/+wbW; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qi6/+wbW" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d3ea2a5a9fso2221302a12.2; Mon, 06 Jan 2025 13:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199349; x=1736804149; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jf7d4JsYQjCJgLMIFYUd+vOjPbH4G49qGUq3EtsexA0=; b=Qi6/+wbWSVG2sNwrnjAgj+/pBYthix3aBJRFAPfNmKqHC0IZ4RgjsJ3KHwgS//mXhZ pSh65rZTmU4ATrDgfxD3M6okAErAuHzOTMuxOBGDDDadzGjpG2TaNZ95UKmEbwwGUTsv XdyRpd/13r4mqJ15l2zjOJv373YPgHHtSMZX+SwUBejDF6pyfh9yybfewbEoX9OoWIJX gESw6+9cgz02DN8bo4PBTVWqUhsC2hzoEd+jB/wS6vPjZUWfZXR4G5RP/yDd1KuVVqf2 Zz5+YyaWuzvADNJh1FDMFl5/s/gOXSX3YuBRN7HT9ulPHIdHHxMuEKc7jxL6MT8M5AgW 3eDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199349; x=1736804149; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jf7d4JsYQjCJgLMIFYUd+vOjPbH4G49qGUq3EtsexA0=; b=WVnpJkzCERhpY0QDSRJ2s2yBWqWOF8Hz7Qca8+trxP4UNY7UGs3zKvzmxQt+vDkA5d BpJfFI3bFHavHiVhluLBtUrpRrdAJcQyp3KVdcQhylXkNWaTn34D8y07yF0/b908FV06 s52MhV/62gGPhiVl2qcm3m9oaivumydLdkmDh3BnDNV1sBg5Pq/u5qFgGcmZI+ZcuH+h NQsvdqtacbBs0GVI3VREp0X9kYflORfZbFkNlTwQJykkUuTF2gVYnjhaZqk53R3kvGsf y5bm+MjkPqCpcNe8+Sz4diovA1dkzXq3HjdzgJXiXYF37GktLra/2FLsN15KJ6zigp6Y d5Gg== X-Forwarded-Encrypted: i=1; AJvYcCVXitfdXjx4gQR1Qz5JL4fJ7GU5OYd6pDWhWchmJN5apC8iRXXeM4TS4lKsmMT/M5PTiSwBAKzwbmY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz32L20gkF9YzQWDj/J67r4jjcs8iISy4eKud2n3PdIcfwurH/6 XycpDEALqmowMZIqXu5kzc8qH1vGFb2i7fcV6NI3WXoNHkKp5BOE7NMZxNr/ X-Gm-Gg: ASbGncuv1hoY/axz+y2nPoXiIcMYNKF/+DwvgFSbbtz/JH/eMwoSD8MMrDo7FJrPaZ+ t37tcFnqFrdBXEN/lP45nLvre1SyYbrbXBH36ag3Yk6cR6y91s4+dmdjYRNM6S/fXKexvwXRi0g 7mYXNOtKULEpWVk+aJ323u22KMF6JU1Mg4S+KNRQGoryrZ2AnbIprujMYyZFR/2kVegzzX6OVDX /Gr3b+htPoNANxLJF/zyGUCcy9FgFhmyMryVfw/O5xNfnaxxz3yzI66gkt2zOsr8Gj6a1eLxzLY bFzX2ejYmLSDdDBYe5WFutF5RdE= X-Google-Smtp-Source: AGHT+IE0xMmcVFLpaVFFxN8WlztBMD4MB/cWcBJNzcsucQgjxXJf+qnAr3XNmgUyu+QBUXtc64ECxQ== X-Received: by 2002:a05:6402:268c:b0:5d0:ccce:34b7 with SMTP id 4fb4d7f45d1cf-5d81ddf8113mr19712137a12.6.1736199348468; Mon, 06 Jan 2025 13:35:48 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:47 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 04/10] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Mon, 6 Jan 2025 22:35:33 +0100 Message-ID: <20250106213539.77709-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-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 7af7744e3cf2..28f42f30e2b3 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -184,6 +184,8 @@ struct pidff_device { int operation_id[sizeof(pidff_effect_operation_status)]; int pid_id[PID_EFFECTS_MAX]; + + u32 quirks; }; /* @@ -355,7 +357,10 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->effect_direction->value[0] = pidff_rescale(effect->direction, 0xffff, pidff->effect_direction); - pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -778,7 +783,10 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0; pidff_set(&pidff->set_effect[PID_GAIN], magnitude); pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->set_effect[PID_START_DELAY].value[0] = 0; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = 0; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -801,6 +809,7 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { int i, j, k, found; + int return_value = 0; for (k = 0; k < count; k++) { found = 0; @@ -825,12 +834,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, if (found) break; } - if (!found && strict) { + if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) { + pr_debug("Delay field not found, but that's OK\n"); + pr_debug("Setting MISSING_DELAY quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; + } + else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; } } - return 0; + return return_value; } /* @@ -1105,11 +1119,19 @@ static int pidff_find_effects(struct pidff_device *pidff, static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { int envelope_ok = 0; + int status = 0; - if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { + // Save info about the device not having the DELAY ffb field. + status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1); + if (status == -1) { hid_err(pidff->hid, "unknown set_effect report layout\n"); return -ENODEV; } + pidff->quirks |= status; + + if (status & HID_PIDFF_QUIRK_MISSING_DELAY) + hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n"); + PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { @@ -1353,6 +1375,7 @@ int hid_pidff_init(struct hid_device *hid) ff->playback = pidff_playback; hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula \n"); + hid_dbg(dev, "Active quirks mask: %x", pidff->quirks); hid_device_io_stop(hid); diff --git a/include/linux/hid.h b/include/linux/hid.h index d11e9c9a5f15..94ad5a510639 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1227,6 +1227,9 @@ int hid_pidff_init(struct hid_device *hid); #define hid_pidff_init NULL #endif +/* HID PIDFF quirks */ +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) + #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) #define hid_err(hid, fmt, ...) \ From patchwork Mon Jan 6 21:35:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855391 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D87D61E0DCE; Mon, 6 Jan 2025 21:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199354; cv=none; b=GxZvTvBrdroXAb/trskKiTHXv8gK3CNBGyHrsiyjp04+k7fhfiidwBW1sWIED7nLv3b77QoTwIk/mEVM+K8tPFg9+fjUprItzfnvJpmAcK+Qo1mo0lXCR1qr+qG5qLq6ZkC3/WY27bWFXWBm/JnkOTL1tlDeHmGaeVZZN4Z5rmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199354; c=relaxed/simple; bh=pLph4SWz6y3xXJ9APCg1zZVx3sH1RCXAHG2RypKhgUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YMLkEOFxYY5hM3h6y+PSgi1+YaieEP/P+3r4/wA1X4njIyq7Fk6gz/X3WHbfcmePz8IphfUdIsS5L1lsOqGWkbG3/8aSQVCvIkm1X+tOmcEVZJ1fQXQWcDU0y9DBbtIb3Z2dALXIdIn3YFM5wot0aiqNld70nRYH2miOeA/sWio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TSrNdLak; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TSrNdLak" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d8753e9e1fso2282055a12.1; Mon, 06 Jan 2025 13:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199351; x=1736804151; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Epp0wzlEdYadJ3qjQFjrGTOyGLfNXGUa8Cy33VmBBEQ=; b=TSrNdLakupYK/EBB11dRrwQDqNPBOx6CwzVJtqaASKC/K8t9/4zhhjI6ov1r4R5ZQr AyX0kM1bLdLDOSiTuk/zp6JnWlzCURI6SBTzCqmVtyl3be6SpxcYV5W2y2VBwG3/VkeG kAt0zj/BJoKraWwNZP0I7i+D33hFaFFe3uUkTHNR5FvF15zmQDlauFIwMBjRKTNS619v /zhdAPAfE4lNxBp85VGNe0UzfJP8CmZ8VvZNd08F2KJb48r0IXK+w498BSo7NDWX1Avd sbyWS2lqK/nyUaNYrI8lJZBfCBixY4gvSU3VKjDRETBiHpRjUxA+eGth7edExeeShka8 CHyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199351; x=1736804151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Epp0wzlEdYadJ3qjQFjrGTOyGLfNXGUa8Cy33VmBBEQ=; b=A/EBqbT9S8+fc+wwqTynusb9ijWIgTL7rRDFGDw5B486dkMkrhrjsnI7IkLwJHwj7y W/PYMvoXBj1ds36XKc4YgSzmYIzaK+URSzPa1riOU6k/OMGSt9G9dp2H/ZFoRv8KcvHx 177zn6LpT0WEEJPfOL5hYoDFyNhT0KiacC5dqSy5A8KrwrOdkhrrHYXpJ1Qmsz7mULRe HQKw44lraC5U3XLSaFBS8WeNSZi7AY1kkeEd4Wv9MXgjdTf8N4fz+r/0C36CFojI5AAZ UHdv0rVMEG9xe01sMoTtdc8ZQKDUmf+Vnl0Zyt9Oi0ecHvFVymXG9tt9byuCejBNDjvj 2ZJQ== X-Forwarded-Encrypted: i=1; AJvYcCXaYoqpMPPLmH7W1gqXIOYckcwQHKB+GQbpHV62fqt2u40udzENof44u9+3NZjQW34iYXGTMLLTDXQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv/1YlWQ0pEi5gw28PtjejKF5bDH+0re+fAQpayQCSXvBPM3nL Q8772qrnqMK3Tq7zzHjFwUVq8mhb17bvYuRjLcob/zqbwQBzYNCa5fbwQ707 X-Gm-Gg: ASbGncs6dMctLBbekXrlkNCnRHkLu7NdnxcjBQLzM8bL2jQ3uL+xUjfXwYA2Xrm9RX9 WMgc0vRbyPyZVTDi1I2Jp1GyOlGcqEyYIONhY/4uwiyEUf7d3zmjBrXi0wSvJhVKuHReztf7PaY nnlHnJhglY02vYHPjPKWWwIrSRhjLBybJsVfLLaM3KhAMAjzC4XWQme6679e9kgwJhxDZymy82y T1MzZQDCPL7Tg15EDfC9HdJJMt6894Teb09W4CEK7agHOSGjrBjbqby/fHswvR8D6CTcF34BquB 6n+jNBcvWWoJrISp3Ikxtv8txHs= X-Google-Smtp-Source: AGHT+IFufXx+0W4p70WmQnlU7EfZXvOTo21+xcRSm7VsVMrLONAFqD/XFvHiIUel1pGZP8qErzDY+Q== X-Received: by 2002:a05:6402:4403:b0:5d0:b7c5:c40b with SMTP id 4fb4d7f45d1cf-5d81dd66e01mr20558882a12.1.1736199350946; Mon, 06 Jan 2025 13:35:50 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:50 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 06/10] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Mon, 6 Jan 2025 22:35:35 +0100 Message-ID: <20250106213539.77709-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-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 d792a07b5a5d..53b16a4e54a6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1000,7 +1000,8 @@ static int pidff_find_special_fields(struct pidff_device *pidff) 0x57, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, 1); + 0x96, pidff->quirks & HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL ? 0 : 1); + pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], 0x8b, 1); diff --git a/include/linux/hid.h b/include/linux/hid.h index 29f0a91f505f..2af9db0296d1 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1228,8 +1228,9 @@ int hid_pidff_init(struct hid_device *hid); #endif /* HID PIDFF quirks */ -#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) -#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Mon Jan 6 21:35:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855390 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 094DB1E0DEB; Mon, 6 Jan 2025 21:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199356; cv=none; b=hV1OuA2/FSUIWA3tkLmvqJ0gza+KLHfoFt0UJdFbfDuWHP2pYIYEOtp1RXTIMJkW4CiRHMV8zpq+i2yzOAiDcLVMLXyLgCmlizOSe7mUunAutMQK68fSs1/nxPWiedutcOFsS0fcTD1InZB5K2D34okvW108PdEJuBwRUSY9aMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199356; c=relaxed/simple; bh=wInCUfzKfgycExALsayqK3naLt6eLNwTG2gebglTTow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I3K+i1EYFpf9FyC165A6BC3UtWJC2b/bWulZTgiXeL596WMPsfX7cF/igS0dOvPYxPAJ/TvH4YlJmF1QwmkPt4th2PLj113mMujYi3C1W94M6sykuWpo1lOyxhG59GX6RGPTH5ARgRNX3exic4i0akOZ5ydb5+G1+245guLsxlw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PQlftDEE; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PQlftDEE" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5d8753e9e1fso2282062a12.1; Mon, 06 Jan 2025 13:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199353; x=1736804153; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=quUUSX+k9WiW9LhDC88PMv/7wFZpf0XxRnFApYOjSAE=; b=PQlftDEEk1Ebj2VSw90ZHW2dCnXM3ljo9m4sJcptVym0/HTTWxYoZPOgxNsTueuG2Q Rw3W9kW9BkLIR5wSlcqX5veXBC5/XiwRRceGSE9sPiwhHoczQ8pvNUWqFBrrgOzFoJlL e7SCljMV5mqocexPMyFzpUPUyPKHat0UhtO3wWDhcOaJEUHRSTvzez9Cj/hQMgfSGUMA 5qcS8IrIbg0G7omkpC4bcpxrkJ1Esi8VJklX9jusM5arz+gfyYTKJiyLr7/be21mAmFI FfU3t9kKOnuOGIgwpnttv3Eau+74H/7m7S1JKS3srTYp1RIM4hPEhLlKOB8AEa5vu3uy tUWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199353; x=1736804153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=quUUSX+k9WiW9LhDC88PMv/7wFZpf0XxRnFApYOjSAE=; b=AVwOxSJivc1oUs53Tun9bCDq7eNVKCTX0229h1ve/mbEml74BmVJlkgx0m5TbqUOkk Ze0yUhQhEMmDHVT5KJB1CTw1JtKO33nYht8D41KMzjxlRU6ycsWj3Jj44TMcojNFgN5T 1Yls/ldkOa59bcyw8i2EoT3So1sEOk4Yhi0YKNFl7MHEs9h8CRohynj4N1B17wDcDy8S 0gSx0/nsoKMGgKh2HSjB6YPvmD1QOReh9JHz+U1ejyr58K+ucHIvzOq9g/FOw38uqO+H Z7Gs8eTBaP/oGaHXjRhKMlxxEHAN4UeCHrJ3gUR5fLyY0DET/hWn2QfCfMQLQBw2yEY4 HeUw== X-Forwarded-Encrypted: i=1; AJvYcCWkSl0tGLM7TdylEtIY3IJW0Sw8Nu5/UhhRWYPiycfyxTfQm4GvZxx7ryEBZEwtvpzOF0J//WBC6Yg=@vger.kernel.org X-Gm-Message-State: AOJu0YxEe7Lf8F0bLCnpmE9ilRx+jbr2AHs2/tgC8TdvEsmS1UOoiIul E0uYzN0XEq65HWGFacPznuvYgILaUjFrFWCA1InLFkk+XHuitOxy2muuwRcU X-Gm-Gg: ASbGncu2qBTFZPAusiuaL3waYKa4wdvy6eTDM0NkotHneL8OlqjQ6zQ/Y/rHIg75odd T2idLLvVCyfy9csgxWZZE+Zg0Jeji184dlMxM+vxXO80+eGMhBwnjNGtN+IconSz8/cNoydPkGW +Pz0B1yO2M4dchTQ91xRVqjsE1IBOn1twzyG5r8i0D0nHJM/W3mVdNy+O82bPyJxRTKtacw8t/1 yixZzoaug2AOgsWmG8SpNntDP+DEUce5OPDy8/5mKIEfgzj2fi07WfRCdmHT7LAUSq1lOywJ/aI IUqABR6dIPFv+WTO5Qb+pXltTYw= X-Google-Smtp-Source: AGHT+IFKjQ82BxtjNRZvEvZ14vKBPh5m5qoQTgiMcDT/kmQKDehZ7OhGUe2LXN4v5yMnucD4F6GZnA== X-Received: by 2002:a05:6402:524b:b0:5d3:d747:6496 with SMTP id 4fb4d7f45d1cf-5d81de2dcccmr19597513a12.10.1736199353267; Mon, 06 Jan 2025 13:35:53 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:52 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 08/10] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Mon, 6 Jan 2025 22:35:37 +0100 Message-ID: <20250106213539.77709-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-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 5a328860685b..6b4c4ecf4943 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -136,6 +136,9 @@ static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; #define PID_EFFECT_STOP 1 static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b }; +/* Polar direction 90 degrees (North) */ +#define PIDFF_FIXED_WHEEL_DIRECTION 0x4000 + struct pidff_usage { struct hid_field *field; s32 *value; @@ -354,9 +357,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->set_effect[PID_GAIN].value[0] = pidff->set_effect[PID_GAIN].field->logical_maximum; pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->effect_direction->value[0] = - pidff_rescale(effect->direction, 0xffff, - pidff->effect_direction); + + // Use fixed direction if needed + pidff->effect_direction->value[0] = pidff_rescale( + pidff->quirks & HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION ? + PIDFF_FIXED_WHEEL_DIRECTION : effect->direction, + 0xffff, pidff->effect_direction); // Omit setting delay field if it's missing if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) diff --git a/include/linux/hid.h b/include/linux/hid.h index 93233c5b75a6..5237f9040950 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1233,6 +1233,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) +#define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Mon Jan 6 21:35:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855389 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6BB21E0DEB; Mon, 6 Jan 2025 21:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199359; cv=none; b=V8tmRQaVnxz5xpq0v7OtyzinsXxyRZHfqkJ7his2VkBexJ8quamtXh+MOC+mb8N2vvEtYNYtiq8XDxJPPXcVS2SPqg8FtzsgR0UmDSe0q7hyLYFdkV1ydoDEp+Zo7sOosmBdr1mpXm4ftZ0zIglEdFrrBaB6s6ds3KYKgL0LRbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736199359; c=relaxed/simple; bh=thZObaPve25NtBG3jcnVjHg9Um0cKRGUkJwJKnTyNzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XeX8xWmdTPFL848tesRglSIp1jMvnK9ZpYYPtaFAj5wyKd+n2m/IC/SBYsypTCgk1z3o1fUKoIWt3/nMcSdlBSr1vsL7KiPV/B01B9hJk5Tjc9wfLzSTQqwJfIr07VYe8Y2LoJ7MdH7UFtmgQGWGgzinO0UVvW44un6pgR9q5Vs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HPUKmP6z; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HPUKmP6z" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5d3be7f663cso3093595a12.2; Mon, 06 Jan 2025 13:35:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736199356; x=1736804156; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xg7gd5e/aYfvvOTa6WnC73IyJbYoHac2d0kgAimlDP4=; b=HPUKmP6zIHllk2CkpF+Kdw743KRKHQpzqan2/aNFJld+kpYxtPMKS7hVhMbe/sCD0h Du/Tcr43dp35H6AKVo2suXwKpVlNLRd0IsIh1VOKRIPAqGnnvY+GUGIH6KrzHLE8dPrG kRSuO/q/i+buD2LVCp+bvc/OJ33mnmseQdiVlSjYZDJP7uBadUxMNH9EndyPS/4sUaAO FLLZtCcC94hlveGqufUNRQuTPKMyXRFDAyr1G8VYuJY2R9nFvQM1aMc8eq1uA1oo1Qc+ In8mTNrAQ2AlITcrbA1ajNvISMP7rdnHncINGK3eFds5LTMuFvRX9pJwRT1sgQvtB8qS 9irg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736199356; x=1736804156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xg7gd5e/aYfvvOTa6WnC73IyJbYoHac2d0kgAimlDP4=; b=cmuFxPR8WUEGuJe2Kfq+DdeMFVQrzvKPyIi6alPEjd2D2nM79aPuKSx0Ws1vfb2s55 d4PaefjLEs5TqYPnXcyDBZv2RFfea91DBCnnVBlHSklDrYwH4LZi6YntSZOsLMXLydtN 2PdOYUs8vGwEO7MAVfjHoMv1dG2DsxW21rDmxVw/c/kNn3VtC5UVUE5yl7RfUXTB0cFt IuMZ4HNEmoLsGVm2NXoavEs8ZTTHjKSDUoyMgl5CJXD8lGgEdd3wglRl1BooI3ollMad l5fowHF7mtPyv6YEhehnEX/Dgz6GpaxLCyjVoMqqCRwDbvrr0a+0gAvX0C+E3ORuwqNo 3iaQ== X-Forwarded-Encrypted: i=1; AJvYcCXohAINni+t01eR7ohkjW2rRK73Ib0oaZfx4fLh72LzjoR4IUZkc/eJg2yXdS3SVlXFFzmThhYSnvA=@vger.kernel.org X-Gm-Message-State: AOJu0YxInvIInj4itqiFXTO7D66hl73ILVruwTOQpM4lb2YfPHVInGJR /3EKUHRbPr27qWcC5IQ40S/Y0jNl6//xqGCLoRCisxHdxU2flRoIyxw4AZB4 X-Gm-Gg: ASbGncshUAQeaAh5au68pyjCn3lJNHvWwaiQnTqW1JWD7GDTV76ReSIMNYPS/FG+pjA ieT8OEliLwS2tAEUXkpbMsGDlzwVobo85NDAMnPIyepAtlRkb/W3FE0mpAXsJd4hJj+raFzqO6D 21ObjKCIx1foT7Qi4Q7cw2WLNAPtYwfWhBMcb0cmtzPS6kHQzSed94b1Qw+rMWp+w85d9NjLTvG W4jka7WLsMMsSgyDpmHzaFj9F68d8/ezt2AckGHBq/CDMXlNo8zp0CxlfuOq5/DLmNGqZsmQECy 57dk7ATZHuVpEgg0C2dsfptljQc= X-Google-Smtp-Source: AGHT+IFheAiEj+twn+ngCqjA4EgwQur170OdaHT64DGeYsJmwS2lKqBh05YSJYRtYPDyTJy4nnJ4iw== X-Received: by 2002:a05:6402:5109:b0:5d0:bd3b:b9a9 with SMTP id 4fb4d7f45d1cf-5d81de1c38cmr21554572a12.8.1736199355783; Mon, 06 Jan 2025 13:35:55 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80676f9acsm23375991a12.31.2025.01.06.13.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 13:35:54 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 10/10] HID: Add hid-universal-pidff driver and supported device ids Date: Mon, 6 Jan 2025 22:35:39 +0100 Message-ID: <20250106213539.77709-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> References: <20250106213539.77709-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-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 | 185 ++++++++++++++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100644 drivers/hid/hid-universal-pidff.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 4d2a89d65b65..59d8da16f5b4 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -1217,6 +1217,20 @@ config HID_U2FZERO allow setting the brightness to anything but 1, which will trigger a single blink and immediately reset back to 0. +config HID_UNIVERSAL_PIDFF + tristate "universal-pidff: extended USB PID driver compatibility and usage" + depends on USB_HID + depends on HID_PID + help + Extended PID support for selected devices. + + Contains report fixups, extended usable button range and + pidff quirk management to extend compatibility with slightly + non-compliant USB PID devices and better fuzz/flat values for + high precision direct drive devices. + + Supports Moza Racing, Cammus, VRS, FFBeast and more. + config HID_WACOM tristate "Wacom Intuos/Graphire tablet support (USB)" depends on USB_HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 24de45f3677d..919d6a146077 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -140,6 +140,7 @@ hid-uclogic-objs := hid-uclogic-core.o \ hid-uclogic-params.o obj-$(CONFIG_HID_UCLOGIC) += hid-uclogic.o obj-$(CONFIG_HID_UDRAW_PS3) += hid-udraw-ps3.o +obj-$(CONFIG_HID_UNIVERSAL_PIDFF) += hid-universal-pidff.o obj-$(CONFIG_HID_LED) += hid-led.o obj-$(CONFIG_HID_XIAOMI) += hid-xiaomi.o obj-$(CONFIG_HID_XINMO) += hid-xinmo.o diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 1f47fda809b9..205dbb4ed6a3 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -261,6 +261,10 @@ #define USB_DEVICE_ID_BTC_EMPREX_REMOTE 0x5578 #define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577 +#define USB_VENDOR_ID_CAMMUS 0x3416 +#define USB_DEVICE_ID_CAMMUS_C5 0x0301 +#define USB_DEVICE_ID_CAMMUS_C12 0x0302 + #define USB_VENDOR_ID_CANDO 0x2087 #define USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH 0x0703 #define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01 @@ -452,6 +456,11 @@ #define USB_VENDOR_ID_EVISION 0x320f #define USB_DEVICE_ID_EVISION_ICL01 0x5041 +#define USB_VENDOR_ID_FFBEAST 0x045b +#define USB_DEVICE_ID_FFBEAST_JOYSTICK 0x58f9 +#define USB_DEVICE_ID_FFBEAST_RUDDER 0x5968 +#define USB_DEVICE_ID_FFBEAST_WHEEL 0x59d7 + #define USB_VENDOR_ID_FLATFROG 0x25b5 #define USB_DEVICE_ID_MULTITOUCH_3200 0x0002 @@ -964,6 +973,18 @@ #define USB_VENDOR_ID_MONTEREY 0x0566 #define USB_DEVICE_ID_GENIUS_KB29E 0x3004 +#define USB_VENDOR_ID_MOZA 0x346e +#define USB_DEVICE_ID_MOZA_R3 0x0005 +#define USB_DEVICE_ID_MOZA_R5 0x0004 +#define USB_DEVICE_ID_MOZA_R9 0x0002 +#define USB_DEVICE_ID_MOZA_R12 0x0006 +#define USB_DEVICE_ID_MOZA_R16_R21 0x0000 +#define USB_DEVICE_ID_MOZA_R3_ALT 0x0015 +#define USB_DEVICE_ID_MOZA_R5_ALT 0x0014 +#define USB_DEVICE_ID_MOZA_R9_ALT 0x0012 +#define USB_DEVICE_ID_MOZA_R12_ALT 0x0016 +#define USB_DEVICE_ID_MOZA_R16_R21_ALT 0x0010 + #define USB_VENDOR_ID_MSI 0x1770 #define USB_DEVICE_ID_MSI_GT683R_LED_PANEL 0xff00 @@ -1373,6 +1394,9 @@ #define USB_DEVICE_ID_VELLEMAN_K8061_FIRST 0x8061 #define USB_DEVICE_ID_VELLEMAN_K8061_LAST 0x8068 +#define USB_VENDOR_ID_VRS 0x0483 +#define USB_DEVICE_ID_VRS_DFP 0xa355 + #define USB_VENDOR_ID_VTL 0x0306 #define USB_DEVICE_ID_VTL_MULTITOUCH_FF3F 0xff3f diff --git a/drivers/hid/hid-universal-pidff.c b/drivers/hid/hid-universal-pidff.c new file mode 100644 index 000000000000..df0206f5e77d --- /dev/null +++ b/drivers/hid/hid-universal-pidff.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID UNIVERSAL PIDFF + * hid-pidff wrapper for PID-enabled devices + * Handles device reports, quirks and extends usable button range + * + * Copyright (c) 2024 Makarenko Oleg + * Copyright (c) 2024 Tomasz Pakuła + */ + +#include +#include +#include +#include +#include "hid-ids.h" + +#define JOY_RANGE (BTN_DEAD - BTN_JOYSTICK + 1) + +static const u8 *moza_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) +{ + // Fix data type on PID Device Control + if (rdesc[1002] == 0x91 && rdesc[1003] == 0x02) { + rdesc[1003] = 0x00; // Fix header, it needs to be Array. + } + return rdesc; +} + + +static const u8 *universal_pidff_report_fixup(struct hid_device *hdev, __u8 *rdesc, + unsigned int *rsize) +{ + if (hdev->vendor == USB_VENDOR_ID_MOZA) { + return moza_report_fixup(hdev, rdesc, rsize); + } + return rdesc; +} + +/* + * Map buttons manually to extend the default joystick buttn limit + */ +static int universal_pidff_input_mapping(struct hid_device *hdev, + struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + // Let the default behavior handle mapping if usage is not a button + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) + return 0; + + int button = ((usage->hid - 1) & HID_USAGE); + int code = button + BTN_JOYSTICK; + + // Detect the end of JOYSTICK buttons range + // KEY_NEXT_FAVORITE = 0x270 + if (code > BTN_DEAD) + code = button + KEY_NEXT_FAVORITE - JOY_RANGE; + + // Map overflowing buttons to KEY_RESERVED to not ignore + // them and let them still trigger MSC_SCAN + if (code > KEY_MAX) + code = KEY_RESERVED; + + hid_map_usage(hi, usage, bit, max, EV_KEY, code); + hid_dbg(hdev, "Button %d: usage %d", button, code); + return 1; +} + + +/* + * Check if the device is PID and initialize it + * Add quirks after initialisation + */ +static int universal_pidff_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + int error; + error = hid_parse(hdev); + if (error) { + hid_err(hdev, "HID parse failed\n"); + goto err; + } + + error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + if (error) { + hid_err(hdev, "HID hw start failed\n"); + goto err; + } + + // Check if HID_PID support is enabled + int (*init_function)(struct hid_device *, __u32); + init_function = hid_pidff_init_with_quirks; + + if (!init_function) { + hid_warn(hdev, "HID_PID support not enabled!\n"); + return 0; + } + + error = init_function(hdev, id->driver_data); + if (error) { + hid_warn(hdev, "Force Feedback initialization failed\n"); + goto err; + } + + hid_info(hdev, "Universal pidff driver loaded sucesfully!"); + + return 0; +err: + return error; +} + +static int universal_pidff_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + // Remove fuzz and deadzone from the wheel/joystick axis + struct input_dev *input = hidinput->input; + input_set_abs_params(input, ABS_X, + input->absinfo[ABS_X].minimum, input->absinfo[ABS_X].maximum, 0, 0); + + // Decrease fuzz and deadzone on additional axes + // Default Linux values are 255 for fuzz and 4096 for flat (deadzone) + int axis; + for (axis = ABS_Y; axis <= ABS_BRAKE; axis++) { + if (!test_bit(axis, input->absbit)) + continue; + + input_set_abs_params(input, axis, + input->absinfo[axis].minimum, + input->absinfo[axis].maximum, 8, 0); + } + + // Remove fuzz and deadzone from the second joystick axis + if (hdev->vendor == USB_VENDOR_ID_FFBEAST && + hdev->product == USB_DEVICE_ID_FFBEAST_JOYSTICK) + input_set_abs_params(input, ABS_Y, + input->absinfo[ABS_Y].minimum, + input->absinfo[ABS_Y].maximum, 0, 0); + + return 0; +} + +static const struct hid_device_id universal_pidff_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21_ALT), + .driver_data = HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C5) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C12) }, + { HID_USB_DEVICE(USB_VENDOR_ID_VRS, USB_DEVICE_ID_VRS_DFP), + .driver_data = HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_JOYSTICK), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_RUDDER), }, + { HID_USB_DEVICE(USB_VENDOR_ID_FFBEAST, USB_DEVICE_ID_FFBEAST_WHEEL) }, + { } +}; +MODULE_DEVICE_TABLE(hid, universal_pidff_devices); + +static struct hid_driver universal_pidff = { + .name = "hid-universal-pidff", + .id_table = universal_pidff_devices, + .input_mapping = universal_pidff_input_mapping, + .probe = universal_pidff_probe, + .input_configured = universal_pidff_input_configured, + .report_fixup = universal_pidff_report_fixup +}; +module_hid_driver(universal_pidff); + +MODULE_DESCRIPTION("Universal driver for PID Force Feedback devices"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Makarenko Oleg "); +MODULE_AUTHOR("Tomasz Pakuła ");