From patchwork Tue Apr 8 13:06:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Elias Vanderstuyft X-Patchwork-Id: 3948921 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 349CD9F369 for ; Tue, 8 Apr 2014 13:12:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40B93201DD for ; Tue, 8 Apr 2014 13:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 375962026C for ; Tue, 8 Apr 2014 13:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756665AbaDHNLH (ORCPT ); Tue, 8 Apr 2014 09:11:07 -0400 Received: from mail-ee0-f47.google.com ([74.125.83.47]:55296 "EHLO mail-ee0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756530AbaDHNLD (ORCPT ); Tue, 8 Apr 2014 09:11:03 -0400 Received: by mail-ee0-f47.google.com with SMTP id b15so660661eek.20 for ; Tue, 08 Apr 2014 06:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=sAY6xMEcveXCTGN7EBSBmJKDVCCRkTUmME3wwH6r0jA=; b=q0cgmwy/QBDISH79811+46DJDidBojJRmm8FMe6tSFrd9WUPbPQT0jFhKsvkhOwMOf MAbsc8JYauiqphf0Q4bhUAO7Ouey7tgZWQPBrZfnjUYGH+Nq8UoqLYkSZrGwlS0F3GcX KfNLCGsPdbxR18knijH234IiIHPidRaWoUBp47rpP8ehi9JeiecEMPWu0SGf9sl0IM8X Yf5gB5Lv50qp9DiD99ffmuBfvTdFcmjhM0wYe7qjypjhXuiR5Ra34tXQWaqzon2kcJHG Yqbjnut5NIEY121ZzzbmTFYVc0YObISPFl+Wx8o2aqWRByHMWdXIPiS7AVsiiKLnl1L/ 87Fw== X-Received: by 10.14.246.196 with SMTP id q44mr4548081eer.45.1396962661429; Tue, 08 Apr 2014 06:11:01 -0700 (PDT) Received: from localhost.localdomain (94-224-61-60.access.telenet.be. [94.224.61.60]) by mx.google.com with ESMTPSA id x3sm4573003eep.17.2014.04.08.06.10.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2014 06:11:00 -0700 (PDT) From: Elias Vanderstuyft To: Jiri Kosina Cc: Elias Vanderstuyft , Edgar Simo-Serra , =?UTF-8?q?Michal=20Mal=C3=BD?= , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: lg2ff: add rumble magnitude clamping quirk Date: Tue, 8 Apr 2014 15:06:07 +0200 Message-Id: <1396962367-6469-1-git-send-email-elias.vds@gmail.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a magnitude in the output report is lower than 2, i.e. 1 or 0, the corresponding rumble motor shakes irregularly, instead of being turned (almost) off like when magnitude 2 is used. On the other hand, if a magnitude is higher than 0xfd, i.e 0xfe or 0xff, the corresponding rumble motor shakes irregularly with a rotation speed lower than when magnitude 0xfd is used. From 0x02 to 0xfd, the device behaves well: a monotonic increase of rotation speed. This applies to both weak and strong rumble motor types. This patch fixes this issue by clamping magnitudes from 0x02 to 0xfd. This behaviour is observed on the Formula Vibration wheel (ca04). However it's not present on the Wingman Rumblepad (c20a) device, yet the clamping has no effect on the haptic side, so that special case handling is not needed. Discussion on http://www.spinics.net/lists/linux-input/msg30711.html Note: The same thing appears to happen in the Windows Logitech driver, except the max clamping bound is not 0xfd, but 0xfe. Experimentally, I proved this to be wrong. Tested-by: Hendrik Iben Signed-off-by: Elias Vanderstuyft Cc: Edgar Simo-Serra Cc: Michal MalĂ˝ Cc: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/hid/hid-lg2ff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c index 0e3fb1a..e180e1e 100644 --- a/drivers/hid/hid-lg2ff.c +++ b/drivers/hid/hid-lg2ff.c @@ -38,12 +38,17 @@ static int play_effect(struct input_dev *dev, void *data, struct lg2ff_device *lg2ff = data; int weak, strong; +#define CLAMP_QUIRK(x) do { if (x < 2) x = 2; else if (x > 0xfd) x = 0xfd; } \ + while (0) + strong = effect->u.rumble.strong_magnitude; weak = effect->u.rumble.weak_magnitude; if (weak || strong) { weak = weak * 0xff / 0xffff; strong = strong * 0xff / 0xffff; + CLAMP_QUIRK(weak); + CLAMP_QUIRK(strong); lg2ff->report->field[0]->value[0] = 0x51; lg2ff->report->field[0]->value[2] = weak;