From patchwork Sun Jan 5 19:36:19 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: 13926770 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 6DB951448C7; Sun, 5 Jan 2025 19:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105797; cv=none; b=iqkwqFccMJPiRSt+magfPMnaJth0Y+3IcpKERNhzY3O1Q0GRn8Toc2IhqoIUXVl/ohTB6+w2VxKiRBlm7ZK/2XICfHujwhh+aQJGwphUXvdWi/S9PiJNV3irRaOF0Ftna5pTBQEs8J2mSb5OOWghrNZhLzjqa7oFeIKGanGlFYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105797; c=relaxed/simple; bh=60aSOMQx14zfMVGYITpU0cwL1JQM2IC1G8kgAFjv5ys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u0yq8L/ACAfX3YjsGhYDXbp1mOg5tClJ5976UEWpYTXbdlu/7N+2LnUhQKygDlNuGsqbkx/5wTEaYKHng3fCeK5sssdxdmCwKvMkR1ZQn6wvIdWQEBtLNTTwSwAYHYTY4Q95cldI+evzCAgDMBO/gYiwc1krP1ObX/YZ2y2CZQs= 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=TaafEpj3; arc=none smtp.client-ip=209.85.208.181 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="TaafEpj3" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-3023fcface6so12675431fa.3; Sun, 05 Jan 2025 11:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105793; x=1736710593; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZMTdGnyyJWXuH6aEDEPHe6IuTncIDqPC0Rg1e/KX1X8=; b=TaafEpj3JPlKI3RMoytAFmwyzRFWFGHTQVUxXWelhNP5S7b24rMAPuSVCFx5FdBnie 90XOirIxhX/qkpgvbxzlO0mAI5803kVznri374I4/cUT+nfwHV/9weISTWxIMJHkqAII PECd2TGGj7Z1FcgAt15Y59LjnO3IOpf8J9BguB/kOLK7KqPEn9UG1vOZpKMzscmncbrj 7udWAkRckTW5xrGZpx0aT2zbGr1aOCVC7cjqR5WojZP5flNNoUAcjF+Iq8xzuJ/3cFad wuVFsdfbIQ92rkFSgaShxRhFOdGw2NfjhvGPmqzIXHpYiDPbV4LJEBeLXdOyEhIMXD2z C92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105793; x=1736710593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZMTdGnyyJWXuH6aEDEPHe6IuTncIDqPC0Rg1e/KX1X8=; b=pPCWUXRpsKRVCApamFzKi84tN1LX86jeUaafLep5hyuyL8E0PmzuhZMYHyLWdr1iJR i8p9zdwCFlcrGffKyuK/7rnZ80F/4NdQhq+f/snZ+udP0IDtHKIL5XTm+Pp6JU+WzvJr dTMq+j9D9Hf0OKwflE03PaEyR3vaJAw48Bi4f1S3pZtl7iZAe+ZAje7K7pxCC611dkeZ 4ne1YAA1JOYcgOqxCtFDaAZLw3jkRS/mtaMLd15iXNxXmuNOFC8r7zpT+7s+58rH5ss0 6+LbU5MlZZIgkMi5yRpM24qsPj6+zuFYG+4kGi/bOJ85ekS6gNf7yYAaoJUySiBbuQRT jsGw== X-Forwarded-Encrypted: i=1; AJvYcCXC9odXEQt7pkxNrpGoyPY64KDKdMdS1CRxZ2+b+x9FVx9+84aN/plpaUKvdT8aUVuAAIfYQmFcnjQ=@vger.kernel.org X-Gm-Message-State: AOJu0YygRdVD9H7SYKmxZHjDqR3O0/N5C+DfMF1e30t7oV3m6RpztIr7 NIvfC8hgvrqviFxxawyMCfFTXJRqg4NnV4WwtlBakyhAZrxBFJTYbQ9TsLTW X-Gm-Gg: ASbGncv11bMzGNIzJUiXnl7kPrPDsVSU8hXmY9kq5CIp+Mc51OahHoEqtPRoAE63pq+ VEe5PyfyhSX9ojcMIUO2Mqb88h1HKDed5dQfbAuNv8liO8Qq8W0XFcSuW4CweioMGg+2H8I47Mv sc4/HMb9aAsarK7DbmQa3UyFjA4TMuPGkVkzExk3tViQrK40psQZMqgjb24uqYZoQVATla2yCKC kFxmZRd5QgIPijvbNnMDDpHWDWVUkUyjyGUOoQ5Vz09H4Zvaczub6xYgIu6kc4uabKfY60zGMIT +ZlqvtysUme8T230VcbcHkBZw+E= X-Google-Smtp-Source: AGHT+IG+DVR98QmICO5mM8uucpLXQQXC9jvaOzH9WpJVnCt+8tshCXqvwp9X2OGqUM+TIwVWXnKkYg== X-Received: by 2002:a05:651c:1149:b0:302:2af9:f355 with SMTP id 38308e7fff4ca-304685f06cemr63586041fa.12.1736105793314; Sun, 05 Jan 2025 11:36:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:32 -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 01/10] HID: pidff: Convert infinite length from Linux API to PID standard Date: Sun, 5 Jan 2025 20:36:19 +0100 Message-ID: <20250105193628.296350-2-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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux defines 0 length as infinite in its force feedback API while USB PID defines NULL (0xffff). Most PID devices do not expect a 0-length effect and can't interpret it as infinite. This change fixes Force Feedback for most PID compliant devices. As most games depend on updating the values of already playing infinite effects, this is crucial to ensure they will actually work. Previously, users had to rely on third-party software to do this conversion and make their PID devices usable. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3b4ee21cd811..3899d72a0b02 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -301,7 +301,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; pidff->set_effect_type->value[0] = pidff->create_new_effect_type->value[0]; - pidff->set_effect[PID_DURATION].value[0] = effect->replay.length; + + // Convert infinite length from Linux API (0) + // to PID standard (NULL) if needed + pidff->set_effect[PID_DURATION].value[0] = + effect->replay.length == 0 ? 0xffff : effect->replay.length; + pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button; pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = effect->trigger.interval; From patchwork 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: 13926771 X-Patchwork-Delegate: jikos@jikos.cz 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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Envelope struct is always initialized, but the envelope itself is optional as described in USB PID Device class definition 1.0. 5.1.1.1 Type Specific Block Offsets ... 4) Effects that do not use Condition Blocks use 1 Parameter Block and an *optional* Envelope Block. Sending out "empty" envelope breaks force feedback on some devices with games that use SINE effect + offset to emulate constant force effect, as well as generally breaking Constant/Periodic effects. One of the affected brands is Moza Racing. This change prevents the envelope from being sent if it contains all 0 values while keeping the old behavior of only sending it, if it differs from the old one. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 3899d72a0b02..cf8163d92ea4 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -261,10 +261,19 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, static int pidff_needs_set_envelope(struct ff_envelope *envelope, struct ff_envelope *old) { - return envelope->attack_level != old->attack_level || - envelope->fade_level != old->fade_level || + bool needs_new_envelope; + needs_new_envelope = envelope->attack_level != 0 || + envelope->fade_level != 0 || + envelope->attack_length != 0 || + envelope->fade_length != 0; + + if (!needs_new_envelope || !old) + return needs_new_envelope; + + return envelope->attack_level != old->attack_level || + envelope->fade_level != old->fade_level || envelope->attack_length != old->attack_length || - envelope->fade_length != old->fade_length; + envelope->fade_length != old->fade_length; } /* @@ -579,11 +588,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_constant(effect, old)) pidff_set_constant_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.constant.envelope, - &old->u.constant.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.constant.envelope); + if (pidff_needs_set_envelope(&effect->u.constant.envelope, + &old->u.constant.envelope)) + pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; case FF_PERIODIC: @@ -618,11 +625,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_periodic(effect, old)) pidff_set_periodic_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.periodic.envelope, - &old->u.periodic.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.periodic.envelope); + if (pidff_needs_set_envelope(&effect->u.periodic.envelope, + &old->u.periodic.envelope)) + pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; case FF_RAMP: @@ -636,11 +641,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_ramp(effect, old)) pidff_set_ramp_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.ramp.envelope, - &old->u.ramp.envelope)) - pidff_set_envelope_report(pidff, - &effect->u.ramp.envelope); + if (pidff_needs_set_envelope(&effect->u.ramp.envelope, + &old->u.ramp.envelope)) + pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; case FF_SPRING: From patchwork Sun Jan 5 19:36:21 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: 13926772 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDD671CC8AD; Sun, 5 Jan 2025 19:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105799; cv=none; b=Ydq5llWv2R1ZThTJJuUxgLKaJFXTdDtbjwasBkyFZFBTtxgfE9XhSXyJtf6E38WhVauSkjU+i3fS9T4w/XWN9AtWUNODofNEeLCOwR6wpYet8MptPdpQW7lfGF/50s2tFamcpszAyKFxrGNGbcWtRUKPa2idhAQnmeNT+B+dxQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105799; c=relaxed/simple; bh=eJ/IPvw5UT6F1TJJeyixqWwLsKzSSiRHTTNylaWJIo0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MyWD5WyaT7iWFMhdU2X4GYpero/jhleXF/9o1YPn2kZqbfSgt8UTi2gXftHZKt0snyQo1ZbGDcRHywjCCqm/DtHOSlnmymEtZRaKJxr4/+0h3N4Dutk1NuK0F/WImmVOF0EqvhJz3epf6vuuoPo0MS2I/oTPelIB4wcDsQiEKJQ= 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=bKevc8PB; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bKevc8PB" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-3021ab1f26cso15368601fa.0; Sun, 05 Jan 2025 11:36:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105796; x=1736710596; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6ERMQSDSSP4kaB35zxEBbEdMyWN68eRlF2X7GLXmoNs=; b=bKevc8PBttJt6cEmXdWom0frtW+q0hBqD9m2rPg1Si5yA0YkqcVjdQT8Zgdwc8MjWf LHK+9Tce7MQRtg7kG/qcrLvfpqmSbgGJmCH9PIqGzsk51bunRZLTtsR/vAdxDBOxlabL NylkCll7nc+sxmOD2xho9Is2/gMCGhi7Ky9IhAS6bGtnGNlejCsw/VhqqCGtRU/d10RX GLcwBJ3QoBbKCFGSGMMwMx08I4EZF0lU6Z4w3ZThRH+Uj1PvwKT6cbigzbbFrVaTOvfk 1FIPCYzd74EULff8MU17KTxoGzm/e1nJVgRXp7wcb9Sbs8Wk5mvK2jWmjr+o88XFXRoM LPOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105796; x=1736710596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ERMQSDSSP4kaB35zxEBbEdMyWN68eRlF2X7GLXmoNs=; b=UVGZOoHbrL0KZTUH6Fr+7k5p/CrnkODV4k302bSfYAb1vYzhHQwlcv+ui+mLLBSWpy dBOQoYZ2e2wFeWjFEIJ/qk7HxamYYvtQOr94s8IxlZqYqp2s7CwlFid46vg5gI4NidN6 pjIO4MPqvZhksTwojmbIfYCoXl2Yxs3SgpGih7YxRAO3g4VJB3PKLsaNnifzdhtxDLoJ D4/WQ4Xhlt2CJHeVDjWAesGim5KqiE9qIK7NOUDTW4g3dgwWsnE6vXaZE6Mwses4dBC+ Rdl++3vPgR983AB1hPNmS7/zpP/Yi3M5jqa4St2PArrjgxHbBrfqHmqnh3huECthZuPy aXtg== X-Forwarded-Encrypted: i=1; AJvYcCVCFtYpqIExaoU46F7mFy3MtPTjV0ULlSS7UoJZLOx7ITZL/DTZxJVnr3kyoAKvrEOj9y9fgplVzGo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxq7DXjR7usPHJmLur1V18ZffYs9lyY7whEn5rmZTe09lFRPYSq CaOUzsNHRVTwAF2WoGgezXPi1lIuJc3vLlKLSIgz37NZuP5TVu6E1Hy3zPQf X-Gm-Gg: ASbGncsPYI6UjLHpAEznL/bUCCHHhNE/GFddbDXo6zrWUu09aMjSC8AgpW7iIVjRLI1 B0ggvBii3QCa6itBRk+u8S11MEC5Yo+ntzIkiYEcH8GTHDAbY31dOOCjUyXfbrv1e3PAehWRYpj Prj/IxbM/SkKxIg/iF3TsfENwSxmUrRXCqnIRg7XuauD2JE4i7wG5Fwq+71ONehr34+nYGRrn1r EzlC+pNDVsdol5v8Bu+5HLWzX1l4U2EZmf5viut1Figxs+32Vm53fU8iWUIi6cZl3wYtyj6caHf k5hglpBz9PXEDNgTNrhK1au7CUo= X-Google-Smtp-Source: AGHT+IFtjRclYDq8z07Hyfke0rgGhtfbF7FZRnVOBIEMHUVzEn2RvwkcWatqOogr64zfjbfAxd0gvg== X-Received: by 2002:a2e:a551:0:b0:300:38ff:f8ce with SMTP id 38308e7fff4ca-304685080c6mr71315581fa.2.1736105795757; Sun, 05 Jan 2025 11:36:35 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3045ad6c586sm53297321fa.11.2025.01.05.11.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:34 -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 03/10] HID: pidff: Clamp PERIODIC effect period to device's logical range Date: Sun, 5 Jan 2025 20:36:21 +0100 Message-ID: <20250105193628.296350-4-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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This ensures the effect can actually be played on the connected force feedback device. Adds clamping functions used instead of rescaling, as we don't want to change the characteristics of the periodic effects. Fixes edge cases found on Moza Racing and some other hardware where the effects would not play if the period is outside the defined logical range. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index cf8163d92ea4..7af7744e3cf2 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -205,6 +205,36 @@ static int pidff_rescale_signed(int i, struct hid_field *field) field->logical_minimum / -0x8000; } +/* + * Clamp minimum value for the given field + */ +static int pidff_clamp_min(int i, struct hid_field *field) +{ + int ret = i < field->logical_minimum ? field->logical_minimum : i; + pr_debug("clamped min value from %d to %d\n", i, ret); + return ret; +} + +/* + * Clamp maximum value for the given field + */ +static int pidff_clamp_max(int i, struct hid_field *field) +{ + int ret = i > field->logical_maximum ? field->logical_maximum : i; + pr_debug("clamped max value from %d to %d\n", i, ret); + return ret; +} + +/* + * Clamp value for the given field + */ +static int pidff_clamp(int i, struct hid_field *field) +{ + i = pidff_clamp_min(i, field); + i = pidff_clamp_max(i, field); + return i; +} + static void pidff_set(struct pidff_usage *usage, u16 value) { usage->value[0] = pidff_rescale(value, 0xffff, usage->field); @@ -357,7 +387,11 @@ static void pidff_set_periodic_report(struct pidff_device *pidff, pidff_set_signed(&pidff->set_periodic[PID_OFFSET], effect->u.periodic.offset); pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); - pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period; + + // Clamp period to ensure the device can play the effect + pidff->set_periodic[PID_PERIOD].value[0] = + pidff_clamp(effect->u.periodic.period, + pidff->set_periodic[PID_PERIOD].field); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], HID_REQ_SET_REPORT); From patchwork 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: 13926773 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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A lot of devices do not include this field, and it's seldom used in force feedback implementations. I tested about three dozen applications and none of them make use of the delay. This fixes initialization of a lot of PID wheels like Cammus, VRS, FFBeast This change has no effect on fully compliant devices Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 33 ++++++++++++++++++++++++++++----- include/linux/hid.h | 3 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 7af7744e3cf2..28f42f30e2b3 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -184,6 +184,8 @@ struct pidff_device { int operation_id[sizeof(pidff_effect_operation_status)]; int pid_id[PID_EFFECTS_MAX]; + + u32 quirks; }; /* @@ -355,7 +357,10 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->effect_direction->value[0] = pidff_rescale(effect->direction, 0xffff, pidff->effect_direction); - pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -778,7 +783,10 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0; pidff_set(&pidff->set_effect[PID_GAIN], magnitude); pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->set_effect[PID_START_DELAY].value[0] = 0; + + // Omit setting delay field if it's missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) + pidff->set_effect[PID_START_DELAY].value[0] = 0; hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT], HID_REQ_SET_REPORT); @@ -801,6 +809,7 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { int i, j, k, found; + int return_value = 0; for (k = 0; k < count; k++) { found = 0; @@ -825,12 +834,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, if (found) break; } - if (!found && strict) { + if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) { + pr_debug("Delay field not found, but that's OK\n"); + pr_debug("Setting MISSING_DELAY quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; + } + else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; } } - return 0; + return return_value; } /* @@ -1105,11 +1119,19 @@ static int pidff_find_effects(struct pidff_device *pidff, static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { int envelope_ok = 0; + int status = 0; - if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { + // Save info about the device not having the DELAY ffb field. + status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1); + if (status == -1) { hid_err(pidff->hid, "unknown set_effect report layout\n"); return -ENODEV; } + pidff->quirks |= status; + + if (status & HID_PIDFF_QUIRK_MISSING_DELAY) + hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n"); + PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { @@ -1353,6 +1375,7 @@ int hid_pidff_init(struct hid_device *hid) ff->playback = pidff_playback; hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula \n"); + hid_dbg(dev, "Active quirks mask: %x", pidff->quirks); hid_device_io_stop(hid); diff --git a/include/linux/hid.h b/include/linux/hid.h index d11e9c9a5f15..94ad5a510639 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1227,6 +1227,9 @@ int hid_pidff_init(struct hid_device *hid); #define hid_pidff_init NULL #endif +/* HID PIDFF quirks */ +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) + #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) #define hid_err(hid, fmt, ...) \ From patchwork Sun Jan 5 19:36:23 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: 13926774 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FAB81D435F; Sun, 5 Jan 2025 19:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105802; cv=none; b=MJpF2nSLLNsDpb+QjmgxLOOmSD36ORRwzRbv4bMeV/fFqiaqgQZOOopUNowauDiAy7E6bAHU4CTGVOg8limNHuAGKYaujHSm22b9UjlHHcHKlRzXTIWzHMKB9LO3IS79Ik82lQcapwAynwtyNmzd+IYTCvyr6OK5IEc9dJZKhKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105802; c=relaxed/simple; bh=Y01bZZyEKBS4Wp/QSV8+diqsxBe4MEehIrGd35l+14c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=okikpSn6VaTvWg9gHh9wWfuoOXw+7iNnVI/Ad6YqGMjZk1wy7FxafB6duMx6HvDMuO/g4sbIAIGQ0qRZN/Rer9+cLafxjcm+VdeBNxQs6wiFDkJCNwQhsu2jI/PYSIlWPeSaTZBQn4CSQ6vYFLY7NcHigSxZsrJQhr+kA6M8jxE= 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=iiF1oeOS; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iiF1oeOS" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-542678284e3so422972e87.1; Sun, 05 Jan 2025 11:36:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105798; x=1736710598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RMzq8PvIJV+z6yV01GtbnkWq1T0M+f9X2iY5dtwH21c=; b=iiF1oeOSyVXVvzB6PtFOgv3Xm9Wa9qy/3FjKkhBpviZ8LnNV3RPVDtUTjdm56RDGyS 5tC1Ans+yHZ6Lo4v53ZJ583C98iWmbOFXGaAVqckFEDQuxD3Kkdv/uROS2HxZYgV52RT +Dt+09TufRskoOi5WHGd9G9cyEZYkQYy4jcstyxlmmU2okMZxQi9yLXiRVCht5jSyLCG nmBzqsH3AayYMoa6oKHNpSt4FAr/yn7W5VJB+G/0KnYSfAlBkHXxzcPlR3i6RaX/lj70 h1oG90voUkTjRUW6JV+ZLRris9eziewN5XLZg4DBTbtdoA1Nmc73IdEKS/rgNz4enR94 Q1VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105798; x=1736710598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RMzq8PvIJV+z6yV01GtbnkWq1T0M+f9X2iY5dtwH21c=; b=kycLDmn6p1jWmesif7ev6G0hMznqcuVHo/uAj4KMFnOWbpXIW1UPoTgcxNY337K5X7 roz6PCGC9MvugtRGAQ3triWbS+8urwt1D0Z86EKEWemAQQUfma955+yd5oH6XgHFo1iT NTp9AKko6l+xb1VKy576Cvj4GB0QF0WvB1SGBpPRw30PnZ52ljd+rsIsz7RkOM/HwFH3 kOpGwrxh0c9yWfl/L6SeH7Csagt3IoMaOnp5I4gK5MJZFWWeFPoSsSUVVQYd3sh2BjHr DtE5WPFe4zXknv2ZJ1NeYtWeOovAidkbcPqQbgNgAwLqcj4Dv7joYnH7trn7EJOAtwV9 2KkQ== X-Forwarded-Encrypted: i=1; AJvYcCWHsE5K5/gx3g2r3FVTLIQEdNvARVkdWqQdRInMH2XQIJMqxG7VPZ+2wpZrhMXQ31R7C07uFNjBe2Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4tq/c7tj56i3ovTeArx/iehORar5pHB/nv9/yk72qpuxSw1qJ OO+hA0YRWx86zWj+Dzo863PUBEzpHrTe/tcQ6M4mj0jes4xo/snHl42g0CIe X-Gm-Gg: ASbGncuoqGZ7T4VRw9cnKzxsygjEzfuRBhDBle8jDXOGe5L/mkwODJg38XyEK9s8Deg MLi5ZLFyllowBk/wYJIRntU2ouSIyCoeIa4ERRVYhoQ936USChOtZFVNRV0VMhTx3sxoXVAewTa Ym804Veu8j8zcBsh8phT+hO4UwFvo4J2sVrYzXfP1As5Ig7zqdWWSH31LSwKgNkbCqbdj3YhB+l IaLuy/m6NRYadcc/DHDUQbpranRXY8rJtpsv2VLZ00IoONdVLRZ2QzJmugT7E4s+WhDfmtedLXg eKiBpJ6gUz6Iji1pfUuu89nDOmE= X-Google-Smtp-Source: AGHT+IFCBWtMn9YmBwXz2FwsNFhQ+uR0ERJM+fwTLmt2pWLDLBdaACQv3NsBijpU5e0Nt7GZOLWBzw== X-Received: by 2002:a2e:bd05:0:b0:305:d86a:4f1e with SMTP id 38308e7fff4ca-305d86a5175mr4472321fa.9.1736105798361; Sun, 05 Jan 2025 11:36:38 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3045ad6c586sm53297321fa.11.2025.01.05.11.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:37 -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 05/10] HID: pidff: Add MISSING_PBO quirk and its detection Date: Sun, 5 Jan 2025 20:36:23 +0100 Message-ID: <20250105193628.296350-6-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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices with only one axis are missing PARAMETER_BLOCK_OFFSET field for conditional effects. They can only have one axis, so we're limiting the max_axis when setting the report for those effects. Automatic detection ensures compatibility even if such device won't be explicitly defined in the kernel. Fixes initialization of VRS DirectForce PRO and possibly other devices. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 46 +++++++++++++++++++++------------- include/linux/hid.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 28f42f30e2b3..d792a07b5a5d 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -421,12 +421,19 @@ static int pidff_needs_set_periodic(struct ff_effect *effect, static void pidff_set_condition_report(struct pidff_device *pidff, struct ff_effect *effect) { - int i; + unsigned char i; + + // Devices missing Parameter Block Offset can only have one axis + unsigned char max_axis = pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO ? 1 : 2; pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] = pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; - for (i = 0; i < 2; i++) { + for (i = 0; i < max_axis; i++) { + // Omit Parameter Block Offset if missing + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_PBO)) + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; + pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET], effect->u.condition[i].center); @@ -839,6 +846,11 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, pr_debug("Setting MISSING_DELAY quirk\n"); return_value |= HID_PIDFF_QUIRK_MISSING_DELAY; } + else if (!found && table[k] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) { + pr_debug("PBO field not found, but that's OK\n"); + pr_debug("Setting MISSING_PBO quirk\n"); + return_value |= HID_PIDFF_QUIRK_MISSING_PBO; + } else if (!found && strict) { pr_debug("failed to locate %d\n", k); return -1; @@ -1118,7 +1130,6 @@ static int pidff_find_effects(struct pidff_device *pidff, */ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) { - int envelope_ok = 0; int status = 0; // Save info about the device not having the DELAY ffb field. @@ -1149,13 +1160,10 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) return -ENODEV; } - if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) - envelope_ok = 1; - if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev)) return -ENODEV; - if (!envelope_ok) { + if (PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) { if (test_and_clear_bit(FF_CONSTANT, dev->ffbit)) hid_warn(pidff->hid, "has constant effect but no envelope\n"); @@ -1180,16 +1188,20 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) clear_bit(FF_RAMP, dev->ffbit); } - if ((test_bit(FF_SPRING, dev->ffbit) || - test_bit(FF_DAMPER, dev->ffbit) || - test_bit(FF_FRICTION, dev->ffbit) || - test_bit(FF_INERTIA, dev->ffbit)) && - PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) { - hid_warn(pidff->hid, "unknown condition effect layout\n"); - clear_bit(FF_SPRING, dev->ffbit); - clear_bit(FF_DAMPER, dev->ffbit); - clear_bit(FF_FRICTION, dev->ffbit); - clear_bit(FF_INERTIA, dev->ffbit); + if (test_bit(FF_SPRING, dev->ffbit) || + test_bit(FF_DAMPER, dev->ffbit) || + test_bit(FF_FRICTION, dev->ffbit) || + test_bit(FF_INERTIA, dev->ffbit)) { + status = PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1); + + if (status < 0) { + hid_warn(pidff->hid, "unknown condition effect layout\n"); + clear_bit(FF_SPRING, dev->ffbit); + clear_bit(FF_DAMPER, dev->ffbit); + clear_bit(FF_FRICTION, dev->ffbit); + clear_bit(FF_INERTIA, dev->ffbit); + } + pidff->quirks |= status; } if (test_bit(FF_PERIODIC, dev->ffbit) && diff --git a/include/linux/hid.h b/include/linux/hid.h index 94ad5a510639..29f0a91f505f 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1229,6 +1229,7 @@ int hid_pidff_init(struct hid_device *hid); /* HID PIDFF quirks */ #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork 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: 13926775 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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With this quirk, a PID device isn't required to have the PID_DEVICE_CONTROL field available. Some devices like VRS Direct Force Pro do not implement PID_DEVICE_CONTROL in their descriptors while still having the necessary control fields like PID_ENABLE_ACTUATORS or PID_RESET. Fixes initialization of VRS Direct Force Pro Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 3 ++- include/linux/hid.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index d792a07b5a5d..53b16a4e54a6 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1000,7 +1000,8 @@ static int pidff_find_special_fields(struct pidff_device *pidff) 0x57, 0); pidff->device_control = pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], - 0x96, 1); + 0x96, pidff->quirks & HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL ? 0 : 1); + pidff->block_load_status = pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], 0x8b, 1); diff --git a/include/linux/hid.h b/include/linux/hid.h index 29f0a91f505f..2af9db0296d1 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1228,8 +1228,9 @@ int hid_pidff_init(struct hid_device *hid); #endif /* HID PIDFF quirks */ -#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) -#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) +#define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) +#define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sun Jan 5 19:36:25 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: 13926776 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 9E9E41D515B; Sun, 5 Jan 2025 19:36:42 +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=1736105804; cv=none; b=XgFLP0MS+l/8+NsB0LZmrrs9O9LxQHqCFQqW8yxjKAzfjjJYLB/bJW1xNgQ26V7YXTrkoJKaz8/IBLuWISP1JCfrASBG0FbrZF9ec4AExZ5aDpZ3PW635c/DxUSMxTYr+7mGVfwC0QVrpF6/a1Lm/3YMFyDtn90Kb6pEsThRmyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105804; c=relaxed/simple; bh=QpcFmZSNF3TCKbFLUHLW4V0YOIJt0/4SLo+cWhmfzTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SPT61Hleu2TEjtPd8osXrylSB90jgt5D8v3nQ05PmnTM8X6qfqh2Kcv7BYHirTyVG2TSXgZTQetvWY2WwOU/w0Zzx7RgHP8Dl9KVRIZ2K81m/Exbsdf+XGv/Zt1z9wx1mNRD+sY0UY6K7fNX8YNDOU2WrVPAZEEgh/yMwg695x8= 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=ZsL07ntB; 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="ZsL07ntB" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-3003a95a173so13819611fa.1; Sun, 05 Jan 2025 11:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736105801; x=1736710601; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uL/zqFXHROf9ZEt+23hat/TCGZHaDdrfMcQYQykn+sQ=; b=ZsL07ntBQr5K321CpxyYxgY/AXfYDkIhw1bsWMyXL9x3Z+zbIQeFCRc5//5pKf7UOh up9QTbNlF0GQj4YyISpAELVxgD1BmpNIH758YIXoDFrkeofuURqyUuT/ym1yoXqQLw3j IttRqjFUs7QGnD+GR1DmpT/PboF+VWG0jdgHcTrtV6ByG7sQronMoIm1oH4EAJ8NN0F8 YzzZt1cDzXwsGMMQofFREdYFrOMETmuaH7KdfAhJSUxAbxi+1Vgig34nDlhqlBIYzO8s 6SPVMXklEpuy83w8OCsIgdJDl+y1JoQsWXJBXqzFtlYsOyU9WVVtYBmBizbY/4f58Vqg Dm5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105801; x=1736710601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uL/zqFXHROf9ZEt+23hat/TCGZHaDdrfMcQYQykn+sQ=; b=R9c42cGRkc0cTnivgTl35oK1xyXR3ojaimyJT9exU7dIcIEJpcrH8I6RvDFO7pvd8L n1ZgRlhMELBjRInU+wbqKmROWMcbFrepEVilYjN5w4JPJlw3szj+Ys6q1T6aJw/Z9Vmi skePhKsYg3x81ZgV1V3hyScZPGLLvufALihDgCCHiB0F5mFmeW1Ux3wFMoyoW+AiXDnS /TPl22bd1cDWwy0wr6eyBdlCQ5K/bUlXpYVDSNDpaqALqFc7FmP0vjrz9T6BdWP/hCUz LokMlVku3wrsivD0XTYgiJmCTZmWVzRJbs5VZyLh+No0YOQBJzE/VBEvj4y70Bfks13S llXg== X-Forwarded-Encrypted: i=1; AJvYcCWSvYIB0Rfhyu6fgl49oPrH9dpBhN4JEDKj5psX1CJ8aZqd3/0Gq4AnCDN5Aaujxx4asXtyW5pyoYs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx07snOOyyroAbDdtOQSpsMQvKJ4sHTrvCC0FL9rhXQk9XH2AjK Fk9VDp4ymAt9tZHUhQu7iT9kZLuwmpK85oZ8zv45k6xUgZVtXhVP X-Gm-Gg: ASbGncvtMhLSVI7CEzN6OaoeySx5IKdbzEO0woXKQ0omWYytMJY2Aed5AC5nqSErAnZ UgGDR3g/f30TtluxjVBZDL6HarTonHGjSN0Tzwa586FHHE1fWSOik+3y9sNguJOSi4yZyz1Jon9 S9G73Q4qRDqawDUwWnvxb8QiFhf83bAGgcVgeYIGfAQxivUijtqjC65PSouPDxCaQ5XvibCokJn Jbjq8kRUCslYwKXfJRHZnvE8786/yzkfru4wae0CNaMY5WM1p6wDXVFHDCFkUIECzOZ+NTnE39w LOJCvYQnTan4AIce4HOM/l6jIKI= X-Google-Smtp-Source: AGHT+IFouwwt6HzhvqIxmA4ch7UvnkmJ9mBbYznyfioQomX0QwRXA0RK0gHHtocjaVm9XUf8bORtpQ== X-Received: by 2002:a2e:be25:0:b0:302:40ec:a1bf with SMTP id 38308e7fff4ca-3046861c063mr72547191fa.9.1736105800607; Sun, 05 Jan 2025 11:36:40 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3045ad6c586sm53297321fa.11.2025.01.05.11.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:39 -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 07/10] HID: pidff: Add hid_pidff_init_with_quirks and export as GPL symbol Date: Sun, 5 Jan 2025 20:36:25 +0100 Message-ID: <20250105193628.296350-8-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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lays out a way to provide an initial set of quirks to enable before device initialization takes place. GPL symbol export needed for the possibility of building HID drivers which use this function as modules. Adding a wrapper function to ensure compatibility with the old behavior of hid_pidff_init. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 15 ++++++++++++++- include/linux/hid.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 53b16a4e54a6..5a328860685b 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -1299,8 +1299,9 @@ static int pidff_check_autocenter(struct pidff_device *pidff, /* * Check if the device is PID and initialize it + * Set initial quirks */ -int hid_pidff_init(struct hid_device *hid) +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks) { struct pidff_device *pidff; struct hid_input *hidinput = list_entry(hid->inputs.next, @@ -1322,6 +1323,7 @@ int hid_pidff_init(struct hid_device *hid) return -ENOMEM; pidff->hid = hid; + pidff->quirks = initial_quirks; hid_device_io_start(hid); @@ -1400,3 +1402,14 @@ int hid_pidff_init(struct hid_device *hid) kfree(pidff); return error; } +EXPORT_SYMBOL_GPL(hid_pidff_init_with_quirks); + +/* + * Check if the device is PID and initialize it + * Wrapper made to keep the compatibility with old + * init function + */ +int hid_pidff_init(struct hid_device *hid) +{ + return hid_pidff_init_with_quirks(hid, 0); +} diff --git a/include/linux/hid.h b/include/linux/hid.h index 2af9db0296d1..93233c5b75a6 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1223,8 +1223,10 @@ void hid_quirks_exit(__u16 bus); #ifdef CONFIG_HID_PID int hid_pidff_init(struct hid_device *hid); +int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #else #define hid_pidff_init NULL +#define hid_pidff_init_with_quirks NULL #endif /* HID PIDFF quirks */ From patchwork 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: 13926777 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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most steering wheels simply ignore DIRECTION field, but some try to be compliant with the PID standard and use it in force calculations. Games often ignore setting this field properly and/or there can be issues with dinput8 -> SDL -> Linux API translation, and this value can be incorrect. This can lead to partial/complete loss of Force Feedback or even unexpected force reversal. Sadly, this quirk can't be detected automatically without sending out effects that would move an axis. This fixes FFB on Moza Racing devices and others where effect direction is not simply ignored. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 12 +++++++++--- include/linux/hid.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 5a328860685b..6b4c4ecf4943 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -136,6 +136,9 @@ static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; #define PID_EFFECT_STOP 1 static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b }; +/* Polar direction 90 degrees (North) */ +#define PIDFF_FIXED_WHEEL_DIRECTION 0x4000 + struct pidff_usage { struct hid_field *field; s32 *value; @@ -354,9 +357,12 @@ static void pidff_set_effect_report(struct pidff_device *pidff, pidff->set_effect[PID_GAIN].value[0] = pidff->set_effect[PID_GAIN].field->logical_maximum; pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; - pidff->effect_direction->value[0] = - pidff_rescale(effect->direction, 0xffff, - pidff->effect_direction); + + // Use fixed direction if needed + pidff->effect_direction->value[0] = pidff_rescale( + pidff->quirks & HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION ? + PIDFF_FIXED_WHEEL_DIRECTION : effect->direction, + 0xffff, pidff->effect_direction); // Omit setting delay field if it's missing if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DELAY)) diff --git a/include/linux/hid.h b/include/linux/hid.h index 93233c5b75a6..5237f9040950 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1233,6 +1233,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks); #define HID_PIDFF_QUIRK_MISSING_DELAY BIT(0) #define HID_PIDFF_QUIRK_MISSING_PBO BIT(1) #define HID_PIDFF_QUIRK_MISSING_DEVICE_CONTROL BIT(2) +#define HID_PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(3) #define dbg_hid(fmt, ...) pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__) From patchwork Sun Jan 5 19:36:27 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: 13926778 X-Patchwork-Delegate: jikos@jikos.cz Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3823C1D54E9; Sun, 5 Jan 2025 19:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105806; cv=none; b=IN49Oo95F7zlhQN1PriqGedJrdxketPka8xTgh0yx7ME4SUUYIfPMjCU/RsRVsY/zcjz2WWO8mVHpiUb/3Cu1jH4PulHMaiAJFZV6A0SBohnHypsf8h0vUVLgDfatgGO57rKrkdMFG42XDHrG/3PEzEBO6cUeaYne8QIveh1T8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736105806; c=relaxed/simple; bh=b+zfvgwJH2RorKAcLzDD+FZq/xIErAzyO4/KBsNmong=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CN3Dn92ZDtLrvQg39ww0h3rVudYCsCOT4bC8C53Q81vKTPWIGtEVCgeCA3/5KCWX9UpgHdZiAzn41lmKpOZXOYyE50OFMAf0ctFRiB9xCSS/mXPJV9tSFXohd8l7yY7Z5Y2Ut3InVuIhGR2GAtOpLd/mJOKkFK6pgOA6TXb+390= 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=KEfKLcNe; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KEfKLcNe" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-54019dfd6f1so2210982e87.0; 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=1736105803; x=1736710603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CIWbvhwfyoOTXpZRGFAZUIU+5fdfCWd5LhGB3garQ30=; b=KEfKLcNeNMZWf0RTZK0U4Dtk+YWIr5eUEdzH3MDsbTyA1MHC1PkYdzntWVf0hn4e9E xCkOMOCzkgM/qVJDyILOBcHshi7mO6YZzwkW7NlfXvX/hwtlVKZDyND2TEHQ9b+i4CjX 446KW7kq7rMExqycjbjfM7ZbJFsr260pmZwJq3TUrD+Hkk0rxe/+CNST2ZflE5/A3jDE DitSxsXlB2iQdxJzQbse3pZbEKmEVXb03kSwOG9hmstg9zLbZIWfGC2OszKDLVfVM0YT 9MXtyEuXw2voW8tdiZM0l4qEWdh1XXs3Lt2Kf1PZw4//a9j+k0wmexlBalMDRg4EuDfK x+cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736105803; x=1736710603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CIWbvhwfyoOTXpZRGFAZUIU+5fdfCWd5LhGB3garQ30=; b=NmptUGgGW3WQGhT3Q115XyuhHbZ8oO0Dk9AH+v/7RX6Jh5LGNjvoMwAowqlBekyHfN 3TsN3A3tdsb7I3bg9TnPv5deN5+D0JJPQ1DX2WKvOjG7/XmH7zI3Y9PKQTUmXhHDTYsJ M3H14CPgSxs5j0HomoRfv7xtky+O/G10cE8bAIBkUegD3qT16671iAc5IBjEQz63I4Eo CqYTGsjk0vxhzIbAqRZA+wlZuHAmunIt+h3Rll5D/Otwu/QclEsGihZYfFNK2kDNKZM2 uKiOjTAp3TeB79oZWTAk384pLbsVjDq0aAP7WmkeFkklHVAgxyabOuvopGa9JZ8qFbIz s5cQ== X-Forwarded-Encrypted: i=1; AJvYcCXVJItWJ0Vb4r3ZyQnj+h2CIt5ZBjbXpiO38+oueh417ouC6tiQXMsYv5GS7VjJBAr541hvc0Sqy3E=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0XgLmIwhbw33rqFZJ718JkHQX+Mdj0Ktv8e2QdF3tQyOSIzox g+lIDy3151UGFvksiPw3MAv8P5WlPQ0n8QrLVUG3tWoSToSfeAbvp4IGBw== X-Gm-Gg: ASbGncsCdgX+9y7F2L1sw9iUnz0i4lT/0DmEyowlcU4+d3Yuef614IKHqw81j8FqAnG 8TwRy4QJaaB9gNIiBZ0Auhx4OIOOxK5pDLN/hqeQH2CCKNIxhNjrDmhuldClYdSMO9DAdhTUMpG waMrky/Lk1HELJKon5jFx2N9eKX8QIJCjc5IYCj0uG0RZcB2ycpigV28JgFL7Ry03NXtiKqqmI0 gAZX1Q9rT8xiuiIGys8FrJj+ZxbEO4t9OLG9YuqYVaFTHJkTDmqXPWoQKqxgRxeJdBk9bSulkc8 bERU89Lhm63k9/qgZfUmvZO7T9E= X-Google-Smtp-Source: AGHT+IGdYne2v084esUxr9jffPl06M5Jol99RzsHx9TpoeJ5GIia9y6V9rhiYUXQQwLymSZk01A5Aw== X-Received: by 2002:a2e:a903:0:b0:305:d614:5188 with SMTP id 38308e7fff4ca-305d6145702mr5189821fa.12.1736105803202; Sun, 05 Jan 2025 11:36:43 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3045ad6c586sm53297321fa.11.2025.01.05.11.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 11:36:42 -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 09/10] HID: pidff: Stop all effects before enabling actuators Date: Sun, 5 Jan 2025 20:36:27 +0100 Message-ID: <20250105193628.296350-10-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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some PID compliant devices automatically play effects after boot (i.e. autocenter spring) that prevent the rendering of other effects since it is done outside the kernel driver. This makes sure all the effects currently played are stopped after resetting the device. It brings compatibility to the Brunner CLS-P joystick and others Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 6b4c4ecf4943..25ae80f68507 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -109,8 +109,9 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; /* Special field key tables used to put special field keys into arrays */ #define PID_ENABLE_ACTUATORS 0 -#define PID_RESET 1 -static const u8 pidff_device_control[] = { 0x97, 0x9a }; +#define PID_STOP_ALL_EFFECTS 1 +#define PID_RESET 2 +static const u8 pidff_device_control[] = { 0x97, 0x99, 0x9a }; #define PID_CONSTANT 0 #define PID_RAMP 1 @@ -1240,6 +1241,10 @@ static void pidff_reset(struct pidff_device *pidff) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_STOP_ALL_EFFECTS]; + hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); + hid_hw_wait(hid); + pidff->device_control->value[0] = pidff->control_id[PID_ENABLE_ACTUATORS]; hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT); From patchwork 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: 13926779 X-Patchwork-Delegate: jikos@jikos.cz 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-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend pidff compatibility, usable button range, fix device descriptors, manage pidff quirks and set improved fuzz/flat default for high precision devices. As many of PID devices are quite similar and not dependent on custom drivers, this one can handle all of PID devices which need special care. Numerous sim racing/sim flight bases report a lot of buttons in excess of 100. Moza Racing exposes 128 of them and thus the need to extend the available range. All the included devices were tested and confirmed working with the help of the sim racing community. Co-developed-by: Makarenko Oleg Signed-off-by: Makarenko Oleg Signed-off-by: Tomasz Pakuła --- drivers/hid/Kconfig | 14 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 24 ++++ drivers/hid/hid-universal-pidff.c | 185 ++++++++++++++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100644 drivers/hid/hid-universal-pidff.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 4d2a89d65b65..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 ");