From patchwork Sun Jan 5 19:36: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: 855264 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 5CA93180A80; Sun, 5 Jan 2025 19:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105798; cv=none; b=VPf6q30UhKrniXXZRCfyyDMNN3wUCgG2lfjR4rg7EIcUlIiioPuNg4N76/L3mG4Li9JRAAxAxwfMg1JxXJ8Hmzdmd1s5W3vbIvXLgmlS7ssYAflJcQiHIq5RN9Dz5RDE1UDUlomaTp/3PlTAO+M3blN1rdPe0mlochI3LMT1Xw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105798; c=relaxed/simple; bh=tWq+ZnBjlOupEjtG5PBxOjtcCachtKjWc1EONIVj4X4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lGqlf9YC1wRwbWPUEXbtH547xDcLugjRSeNrHfu6e8TR4YZHqAXZNX3hUKiJtDz4VgcOH2+tDo/R/SRrz/Bllc4YIV5oirlXw8BTQRH0R4+ZXC+Pp88UZgl5PBntM39rUrzWgOyM7Tr04vGbHhGdBXTF4dUVz3xrfoQmSXokg3Y= 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=G2bHDC/y; arc=none smtp.client-ip=209.85.208.175 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="G2bHDC/y" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-303548a9332so15436991fa.1; Sun, 05 Jan 2025 11:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105794; x=1736710594; 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=G2bHDC/y8LHJp34CoBTYY2Zy/pGd/N96ePBG/nnzzZ3D751Y10SDKuYYi6nfFB3QKM ak6D0bmMwS7lH82pr8NY9uBhtkq0NK8q9IT8Vzm9HUrA8bfeoycPzjIdv/YWJVfITcyr mMxLj/wX8yyXSuOnRsmsYWiO99wsTnnNb9QMZYXBs8hcXXqmVBFiiNkdYeaqQop2iv8L j1uF4bUr0QYxNf3alaqtuiLkkcCbbn42+1qFzMQbRd23Ozc367iLRzZ6GeRV/cvznSaQ CFD2zZ3P8P/gfNcskMyk32vt1drQzqIgw4Eth04ArwqZABJcyrYbn7EddLDyq/PwiWUo H+WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105794; x=1736710594; 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=HHxWgNGrPaIWSuZSMoyWjVO8KBN4hMv+YkySHuJZvPe5UfCuP5DVwtqlq/lTnoxX+V S0VVF8aJNft/bG2kjyilhLSc+LkgxqCrTxze2O/ydkrBqPyLFZM3MOvAMhbFpgFGlU/0 ra1Z1ToPjZTkvZScyC3RRVQsGJ2erqyrEGL5JtDJKUc75HIFO2TLRRQ3/bNVvDdsfhIo 164ntLksPA8PXsbY/V4Nr4JthyAtWMfLHeyS3QoknzB5rPPMdcOPxSVEdwlFikigXg93 N2HrwNijuKe8t/2ipjzKeOUTL6/31hNj0y8C/P7eWeoK487YV6XGdRq/SQ2S2cl35iD5 dgVg== X-Forwarded-Encrypted: i=1; AJvYcCX05d12vxDN+PmYggQuAh4TYzN122HGyyfI3eSeeh2ODfDkr88uZ5eBEdQphp2A2lBXvk2P/zT8mIQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3Q6GVE+ZTBYJpFJOP1Gls3gq2ebwP3YCbRREaB4DrDzlxt3PJ t4y/ZQt85Egu+ISxMJI5tHEyUEczpxvPXea2+V9abe46vVl5UCcHiB5+lM4y X-Gm-Gg: ASbGnctgRTIWJ+9Lf02WVmylv/sO+Fw+seDGoN/7RazQ+yj9J6NazgX1CBfeQVuoUyp C5pyaFCjeXsRi6tHmEjjW+510hINm8DRT+4KmZWKr64flfhBMyDMBTQ7PRgeKBBGgAfimnhrfCg aqrUG9r+t8qjHC99HQmcaV8797x1+PQ8tdLme5m2S66ZW1zSK5pwG26jam7EX61tlQGU52Tcr/H XpNYOVXUaOClzCwJzCj/TeJZeu+jd9XyTf4vLE0wZIRjv+ezDwPGmYOsDvgtbBTQQScaMnPCA/p qK8kOQ846+FzR5/DVIKEEmJPc7E= X-Google-Smtp-Source: AGHT+IFOjjlWnbAvHn8/xNJOE19fw2nIvWBz0hstmvPllYcB6ubheoVe4ifJ5zQv8zsuH/YaRdCbAQ== X-Received: by 2002:a05:651c:1503:b0:300:17a3:7ae1 with SMTP id 38308e7fff4ca-304685b958cmr71224071fa.9.1736105794139; Sun, 05 Jan 2025 11:36:34 -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-3045ad6c586sm53297321fa.11.2025.01.05.11.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:33 -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 v2 02/10] HID: pidff: Do not send effect envelope if it's empty Date: Sun, 5 Jan 2025 20:36:20 +0100 Message-ID: <20250105193628.296350-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105193628.296350-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> <20250105193628.296350-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 Sun Jan 5 19:36: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: 855263 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 D89D11CEE86; Sun, 5 Jan 2025 19:36:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105800; cv=none; b=rlf9PSVMK6Nhm7RtP0s31T1w3mQc1m4rAUE1TNcG6jDjp/O1ssXRGQTPA0R5wwMiVXGqUN9p2KUJDFzDFqILRfVztbeq0QcYaL1FPY8Zv0eDCQSxNrCUrJodhcn+3I2POaUFEBye8zLu5A77x2U006h/4L3WvQ6CAereXzphd7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105800; c=relaxed/simple; bh=lwoYk8NIAbQoRUBh6t/sze22q7+oy0VMCbNV9NT2mq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jGxjDpHFybsV1PlM/uZGXbSOZM35WOXGYeAcjrS/4uiAReaemIRedGgcOBSen5cdeXV0huQgtfXt9PFD0gkHvyzAWSPV8CFcouBwBz/LMaGZekdj/185AbRcxxrpkF82VZdfccYUgTaWkcqqRBrZJWDsvwmLADj88yBw9Vx3ssI= 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=P7Hi01Xs; arc=none smtp.client-ip=209.85.208.175 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="P7Hi01Xs" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-3003ae21db4so13449561fa.1; Sun, 05 Jan 2025 11:36:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105797; x=1736710597; 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=P7Hi01Xsc1G6e9lPAJYhafuZwZw9fcMgtltxHkt17WY719+soLzRTtsSpyA50lCfAi KOAXWRsSIS4jEdInufDXckLGWIfNy9DkoMc5xyBZaA8waeqzPqsLZAPjgUZzleZIX4UD VDW4Y423p9XMXUiLhwp0QxetGxupxUxQC4EpDMp6Uw4Fubc55vrp4jxCaRoc5R8NPYsN aasAucK40lTp5NaTCUtUyVaw5Ch64INlX7gs3LQ4oFgR98HAoEw/fYaVpecKGT1Btvdz fOuZO/Yc0LvYxgeZ/r2DmL/TdeD6KQFnuvqibeGjDNtG/geZOIP6SmSSKOqOfeQCh2lU idTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105797; x=1736710597; 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=kQL0C0X+6vToLO55OPZc0C3moLee7qSDV0gbRTgu6KWrQh1Y/di7mJIPb1Nsar9f6h TpG5AozJ2bCO+5VSNvZByREs/QS20/3HrCDfbJZcGa/T0Ory/BEKX3d5ozA+lInbtrl9 oeBXkjmbEnbEMg0T1lagbZO6VIH8Mjki94694uVyFJOfz0UmwaDzajF0ae0IgzeP90gn GD8ftb/jb4mA4sRcYiS5/El6K+KTmuIy+Njwv2kQHF2gIyo/mvE6DXI3VTixjyL90ETs XlKDi6wzqlCOD9HwvpJYGqSbTyPSj2t7KYz94jDkGL1+sIceC+D4q3M2jHK8JQHDZr3g rEVQ== X-Forwarded-Encrypted: i=1; AJvYcCVY3qhHqSB3RY2XXOlameWSXAekNNDD6KOwXKetStrGrRZn2qOVP6sAjFFpKKbEZlDjjln0RvNkJ+Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9Ua7Sy7NQW5ZXSaLsJUDRz6+stCYgzy2Tyg3DoC4eMCHrUTs8 4scdCxnwIqcDIeZLrR2zm31sMLz+8jc7+lQypvzMRYPHQ5thl3PAfgGmtZ+7 X-Gm-Gg: ASbGncuaaemwJNHXwR6yKTAJvsqC7CZU5uzvOA4s1L+5DgBgER7RtOoADTKEgqsgI4B xHdLNUv3Q6GO4PUhg61ZdVos5T6N6Kkm3oYUL7CYBpctBc83Q/ytZUrCzIia22WtULecD9jJgcH miZL/okCSVhdEU9pRNdGlMU6jO2MQssyuUKfPkpYg9ix44P+NoUV02JG+jw7pKyFXRAUn1guZHW zHKR+XduYxv0MlZA6QLScucYQFp9Au7Z5zTufFz0Mq9yfWDahmrHzTy6HhiYcAUELJsnkgx+Ku9 bDi724lCnmqPKFDQguaqPtROW0c= X-Google-Smtp-Source: AGHT+IHxEuTPBkibtivuSfJdbrbqbD5ZWpTA1uQ8iUCrEXqugCWZDP2pmlcNk7lrzkZWIBS53qykJQ== X-Received: by 2002:a05:651c:1547:b0:300:33b1:f0df with SMTP id 38308e7fff4ca-30468547fbbmr62947151fa.4.1736105796895; Sun, 05 Jan 2025 11:36:36 -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-3045ad6c586sm53297321fa.11.2025.01.05.11.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:36 -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 v2 04/10] HID: pidff: Add MISSING_DELAY quirk and its detection Date: Sun, 5 Jan 2025 20:36:22 +0100 Message-ID: <20250105193628.296350-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105193628.296350-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> <20250105193628.296350-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 Sun Jan 5 19:36:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855262 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 91F1E1D5143; Sun, 5 Jan 2025 19:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105803; cv=none; b=MI/5uE+/YxT8KV+qAIsfnhof2zOIuTyZQuI1RhSnkKpVu2FuokZQpH0zOmlQA4nCA4FnmPCdRE8sBWRAvg0mnM8zDG86IQRjFOyLlRB1QOtRpucL7E27f6O6wGu9ohH6aCTuVSfB2Cm2ZwuV1phv1hSb6LN5IX0ksPe/uVV+SDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105803; c=relaxed/simple; bh=pLph4SWz6y3xXJ9APCg1zZVx3sH1RCXAHG2RypKhgUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gudc4HnEz3th1NxftM093pqUjc6QrM4RbhPf0Wod5vv6TjPofl2l5g+JwyXk1l7Rrd0GUlklbFQI892DO2+jIqeSYchAiIaiI4osOE8M9M1FJR3m01T+E32PG//LPkTR/OfCeX09jlNNwzFULIqsW6yTyc3K8ah/xAWnrrGyXhk= 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=G93yPhz+; arc=none smtp.client-ip=209.85.208.175 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="G93yPhz+" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-30223aa0b9bso12044611fa.0; Sun, 05 Jan 2025 11:36:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105800; x=1736710600; 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=G93yPhz+YQelE1bGYkhBErtM/20d5nnb9qIawpNJDrZjfk3duWTd5TeL5BXS+af23W HL9Di6tt7kAGLxpsHt4F6xz3Vfy6D5cy9OtgyT3r9HV8tMVk/L1QlRDtzNH1q5CUQOQF By2xlqUPq28EF/rwop1cbiJK0LtniJzRixj/aP3nCP8PMA9anSJWZDAKK0W+TyBz9Pjk wJPicvbKjt8KzYCmTje1CHt0ATTF16j4x/BtPb4WMITuu64+A1UavH4TsZMNfpDpjBt7 a3xy2Q99gbpg1R69GYC6sVsFtx//7pbLXcFJq3KeyZ+fArbYBQr7J4HMDQWLZtAcM0Qi GIWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105800; x=1736710600; 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=KcKc8KsDIkB0bem8K0nxxyBlPpvfAc/24NWuH/HgHalyrJ4O7/rL3U1cYBqdqJGWg5 CPdCNhUmj4UCOuYtD/4LNg1hjUIOXsGOW3AC8r0w/kKOqL5Ej1wdOJVTauUS+FfRPC1Q MWWOv5D8Sysaw/QrAVoNhlTnabfREFYmzkzcuVMBA+wUOrZUyVeFu4CSTv1G3UkuO2xx jno+avzwObCD/30IRVjjFebZZsab5Ro/S7A6qy1S/rxjZjGWO27KVsS3AOy6Wtqe7SEp R3bou7Swo5jtRuUefI6Puk/pmDYHYsiJ1kAuxioyrZC7ZeoetrwTalVAOxLthx6jD3uG GsFw== X-Forwarded-Encrypted: i=1; AJvYcCVFqQamLxEFf4g2ttP7ImiVhqoHEN022S13iFRZCjdbiNMA5h1ATrZ9kZNSKuhhOo8U/1F03+j8d8Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5R3ujS1QlxJ4zMlspzz2hCS9/dktSyD66s895Y/8nKGqnfUir FtMjy3u4eE+Q/nMddOWDpLfvrG/1bx2bA+FShrunMvTIbBcDJjb5YJ2YXNZ5 X-Gm-Gg: ASbGncvaLbyg1RZoWsYjTqAOqB3Lt7TvRx/CDh5adQj0DaCyb0GF+x5S2tmGDalN2eo SutDC+iHBPxW8xeTSMp6JvK7xjjFMW7UvNFzYkR4Ay5AJ6BgWzqEczWqwFGx14O4Hvac3bkWf0k X507buMf3wVn603/Um18MBonyiIjvtfhJ54QNZMBWtj3Swj4/l8piFKNmp48ijA5mVmu6SADjuk xdX7GDcXy59JEQi/K1Hw4e9dptCnttW2lNOQk26QfSv0h/7kq8WpoSfpog6tfLwN/a2poKPn9BD sqhgjZeCFvQctOyHclEwssFdCRU= X-Google-Smtp-Source: AGHT+IGD9KpkqSN1Cp4Da2f8ejRcbtC6YOufLls8NuM/J2cJUAvb6OxnAUg0KZzLfLMn2ETtOf+sLw== X-Received: by 2002:a2e:be9c:0:b0:300:1f12:bbc4 with SMTP id 38308e7fff4ca-30468670294mr61070941fa.12.1736105799551; Sun, 05 Jan 2025 11:36:39 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3045ad6c586sm53297321fa.11.2025.01.05.11.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:38 -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 v2 06/10] HID: pidff: Add MISSING_DEVICE_CONTROL quirk Date: Sun, 5 Jan 2025 20:36:24 +0100 Message-ID: <20250105193628.296350-7-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105193628.296350-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> <20250105193628.296350-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 Sun Jan 5 19:36:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855261 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0EA51D5172; Sun, 5 Jan 2025 19:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105805; cv=none; b=aF8LLFM0JNk5UGvnUyl5tUqv19GWX1xAw+dK8GI27X3Y8oU3JdnoDzYlo6vhqibILUfV9kpwe3PjoyUVY2ER1RSl0vhIOkN8nXrENSCyz/ps9w92NQGlqet0W0VCBVd+Z0ueLSgn0Jq8fSRhQoa6kSYzu1Pv3CdxvSVheL0HC3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105805; c=relaxed/simple; bh=wInCUfzKfgycExALsayqK3naLt6eLNwTG2gebglTTow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NYHGMOsQU2E/gNtwGkE1uZS0YdI0KbHrAiaRsgOkA3K67HMLdgo0Wl5JAZnj00laTwyd7tdxPHMwrK+tqz4AwanwoEyfR1CIO8pFHPwH9G0UsplheLvyzQENlqYG8BGemZfptIoZD7gXh7cWCKmneAd91t5DSPKS897nRj/+sJo= 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=jRQR9EzW; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jRQR9EzW" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5402ec870b4so2100224e87.2; Sun, 05 Jan 2025 11:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105802; x=1736710602; 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=jRQR9EzWXzmN55L8JRxo4giQxWA/8ZmoAuC6M4SjBpX24R6wKSuvD7BS/Bm9rdD57z Tuh3AhkiXQ445109yJoSSV44LekoS0ivZmCXCz9zbOU1RCWnKYsUllb1+8U9ngvbaQSO BWQBB4fTvWvBvq+cwduZ7JT+B/Js5TevB3Wy59fp2zbKCv0uF6Io6OvqPBReAHq6MDrU kLp4gdYu/Tua0mkPpvu8quhIyjoDEFAZAh2LF9gXY79QvTYmOknKrZKoKbs8WwkE64W9 pIX4j+t6kwcvzXteYmMS7ti7GwCcwv5HvjX1gW2dQ6wd6UVQVXqvbKReJ8iw3Zz4DBsp NOTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105802; x=1736710602; 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=QAqbptAZXjDm5LhqiELS6o8FP6WrwxudvEs3kFAUDbaXyt4jCg8Pvsbk05tjYCJ7q1 0UunSFHMn1S+JpbAn0wDlhNAAIBF6stwN0oOWCho1ZxgoDzWpLcUEJFZniteA72qbL/T IpxkYr7udunIg0KppVnINMOfYyf4Y6YjJDxwPo8gwEuCmQd8Lq0nXGQRQmTWwpHyHpCi sgHf+h4h8YphXn618pMkY9HDRp49WGa6+pxnxDJkyA4Awc36U/Aa6dMAlKwJJNRNs7Kf Q1UPfBGCRw25uWTAux9hUe5q0xreVvw82K+XohDz13h6yxk2tU3Ac82JrP9CWIo/nkhm 7kjw== X-Forwarded-Encrypted: i=1; AJvYcCVD/RFb2u+e8b9eINCE5nwldumYp9iLf3Af6SrQHUxYbpC5CGJSEX2KZ81ebHZMb6fC1XhwhoXrwXk=@vger.kernel.org X-Gm-Message-State: AOJu0YwhZz2nFdfP6q02XPUBCtyVb8y4Vfp/tYT3ahgWkMFDEuJ/x6Xh luVmPM8fZo/pKvBbYeeNLLbVwNmA4SAE1Bb24t82a5Y3UdAKCu3rrDZOzw== X-Gm-Gg: ASbGncuHlnhCeVqqvZGxJNy3UrhYWlH1pfKQ10uanlb92pWbtC1VYviFYPBFgRcM41z mcwfWo3/HrPEdcg3i/QgSIg7JxlOtxpNe+Tc91mNRM5jPm9oiqYr9Y8fA8GtMtkcejTkYzKYWe/ dYGgJmTppK7UNz58MBI5w5gAy+tJ4wRn6c+yb8Gey8YaJCwCBzKriJFituBHAwPcrP/qy3OzY9d CRZqlY9kZbIYEYHgEXFf0EXSnbbopjb6/ns5Qiete8NaEVyiENPzjgwDbO95J5WqC27k52CGdcP MpoPPpdLcB2VcA9uRu8Uax4QiVs= X-Google-Smtp-Source: AGHT+IF8/pKZFiofGc2vdnroI6kU1uA6M17Tp2EBXvBzzSiVQ9qjT284LMqugB0yUPj9RZoEi3JpUA== X-Received: by 2002:a05:651c:1a0c:b0:300:956:ccc9 with SMTP id 38308e7fff4ca-3046854bd51mr68762781fa.6.1736105801705; Sun, 05 Jan 2025 11:36:41 -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-3045ad6c586sm53297321fa.11.2025.01.05.11.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:41 -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 v2 08/10] HID: pidff: Add FIX_WHEEL_DIRECTION quirk Date: Sun, 5 Jan 2025 20:36:26 +0100 Message-ID: <20250105193628.296350-9-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105193628.296350-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> <20250105193628.296350-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 Sun Jan 5 19:36:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 855260 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 223511D5AA8; Sun, 5 Jan 2025 19:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105808; cv=none; b=F43a4kj9di9MtOzJwU7H6M4pfG/68yA2ppupO22LIxDiEAJVkHeukTi2VtxxWeopX6Q8lTcW+V34uWaW8+AbkXkAImN05ipQN4mUg6hDsDPKNk+E+q208l4pkpubzJbgPOIvCAXiKObRpGPckUnLworgC2ijKZwj+K54zbCI+yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105808; c=relaxed/simple; bh=2V+kiYLldKhnUoPHz3+BLINaU6r43FED71wTlzMAC/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I7PCwj6yfNooX+S+qqRHp4TbuA9PujugneebZC8sLBRdY14MSLWJqrtCyBb/+Wv8viYU4OEHF/qh9Ac6MBdg8oBSWaCe5LCNVtQzYTG7jf7HD29T3veAy2+VgItrV1riDf/5gHidZYWH+k7zNc3wyiC6VbFVGKak7nhhgfJO4zY= 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=BmJtBMLO; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BmJtBMLO" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5402ec870b4so2100241e87.2; Sun, 05 Jan 2025 11:36:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105804; x=1736710604; 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=N3l+1h6JEnc83pN1GtIx34ZdUwGl+pj89ZJE9T2Na4o=; b=BmJtBMLO98u90hn93mCUJ8U0dYgOF9+GsSNs9+L+tZ/f4BFtKPPMeVYFZHuFMX/7vt 58kOhPkwuYKlILPUxnb3hKMQwOan4Mc4H4ik7RnvHs/6qPaGk1s+9aBYBRJGiL0i8hQq uMe2Ia/7ETsA7yGsLPV1dmTiCvLh9dnOZZScPYBLXlFz+ftlmKjtQE3zZ0StOrfIKtj9 mJEa9b5VEu85HzqxaRMXv/7qJ8v5pfXfGCaGuz/0T42AmLp7eRTtfRNZiMI9bZXa8tln zRs7L3TshNIC8pwlsG85aUYYMvjucdeXN8BvjanR/wonBvKo0qDPvprBIkJ9PWOJIPXT ilew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105804; x=1736710604; 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=N3l+1h6JEnc83pN1GtIx34ZdUwGl+pj89ZJE9T2Na4o=; b=TWBhafvbKliuo3QjlQQdwO0xnhmHs9MWZIhMrfTbpT5WAtzx1Fj4gVn6ejadElhwVf kC5qCutrt9N5UhZbAdTGwc9uGIVnLmRmufQrIpQ1odIDoKmsEYebxtw9BnsNNL66wxjl +ycuYcYyrfX1mfCVRJyRhx+/YhA1DE+ZP0q1nWbFVBVhPc5UIy39bsYQJQLJU87DtONS iuUOt7SDJnC3Ylly+dqt2HJphI+of1n7FJNG413Qda9yC0O/md0lkT8ngqgcTsy6NpgX zWVeDaRvo7UrLZrNuSNPCM7cWNWU8xpSeX3FPFmrkwG28WiQ8Bm2m/IrZ1kdKh2mEFpn jpMg== X-Forwarded-Encrypted: i=1; AJvYcCWE1DtdSMbjBHOvl36qCV6Hr97hLWMgyV28Xg2QQ6p6A+ORnsuKEzFAY2cmBq0wTWYec9YDhf55VBA=@vger.kernel.org X-Gm-Message-State: AOJu0YxRF1OiSTYEjwnAlvmBx33gzKYjeyRQYPY4TBYKlLQXSQvYIdL4 NKtDGShvOV2GCXi3GMjf8CP9dE/WQoz/QYVVQgkkxWJpX32nWhGqfJLmCA== X-Gm-Gg: ASbGncu47LgVX9tmWAUrXAVOJUVdrYiwqhHtuUx++RSdPhlhlSEqDh1tm+GX/35/vM0 zCllvdHodNBnySYYeC9Yq3hHd8nxl2ZCvp74G2XaEUNVu9XOydbj3v0hoXQmmteFTRFBH5Afg2R II4r57nl1TLZHNKl40WQPeIxDzRcO0Ilu+OPGdkiSU+aNOPGkrhNKb4KiC982CXeqVIxWqUmysp hyd93aQpbGNb4uJ2mYQBo3dQin9cbbxQMYCOGa2MUS2lfeUzQzzQzh6Mn/Wxz0l/Lu8P3CgUguW 5/XCgMdQ9DqD2pcEPme1sgZ37BU= X-Google-Smtp-Source: AGHT+IFxCP5U38pEmJsvfO72O1jUtyNXx5IpvnZHzdF94x1RnYyaPS5XCHfZyUaVBWo0k9bEvP13+A== X-Received: by 2002:a05:651c:b10:b0:302:175e:5abf with SMTP id 38308e7fff4ca-304685b79c9mr70460141fa.8.1736105804034; Sun, 05 Jan 2025 11:36:44 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3045ad6c586sm53297321fa.11.2025.01.05.11.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:43 -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 v2 10/10] HID: Add hid-universal-pidff driver and supported device ids Date: Sun, 5 Jan 2025 20:36:28 +0100 Message-ID: <20250105193628.296350-11-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105193628.296350-1-tomasz.pakula.oficjalny@gmail.com> References: <20241231154731.1719919-1-tomasz.pakula.oficjalny@gmail.com> <20250105193628.296350-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..5b32c884e865 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -1217,6 +1217,20 @@ config HID_U2FZERO allow setting the brightness to anything but 1, which will trigger a single blink and immediately reset back to 0. +config HID_UNIVERSAL_PIDFF + tristate "Extend USB PID driver compatibility and usage" + depends on USB_HID + depends on HID_PID + help + 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..4f0cca6b81a8 --- /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 + void (*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 ");