From patchwork Sun Apr 30 18:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Weiss X-Patchwork-Id: 88944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2275180vqo; Sun, 30 Apr 2023 11:29:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6y6rqRRHho8ZdJlbwGkwEXlaIbk/o6y6e2kxuIt/M2fOW7Gsc1kNJ3PCAQ8Qxd/8zrKs1o X-Received: by 2002:a05:6a20:a10d:b0:f0:d50c:4ac5 with SMTP id q13-20020a056a20a10d00b000f0d50c4ac5mr15169588pzk.51.1682879380443; Sun, 30 Apr 2023 11:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682879380; cv=none; d=google.com; s=arc-20160816; b=pVSoOkw5+FYL5mE1WWKSVxrbWZGNH2burOuCHHWSfLpXjONfck9EXL5nSdlwvlVWBL 5idGfN8mK3jjUBDUXmIUQ4/pRfR91yg5EHiH0s7B01GqaB6DJ6pV0fukHd/PVkO1YI24 tIW9LS9bWb2O7mRcLh+JqrwAY2zpJCaQTAcpgawfkeb+gITICDOOPxOput3R8SDlBaIw YnIMfgT4cVyz9KjzyvuDQNk8U7hFkvQR4jonZwxCTyE7Fyl966ogIcitdCpvj5SyQDmP Ka+dwrC3tIFyFHjxivfReyTiEq6BTqV9LYgXDtxbHuvvEJfu10fwJEsz8fMDx2UoI/Ec wzyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Gks007o2fPTJkwx2gMpd0MRNmDcA77hoF5X8QsV4Le4=; b=LmDpksItM7qJdqahURNkWqOHYFXHWO7VXI3qUTiPVHTtvedKYM4Ne3w/ENo1w3GzcB 60/V/aiJIBt5Sxs76yRlCx6+F4jxkRBkzpzIUtj7TybEvvc0XayobptuVJiafxi3ZY1/ FrVM44mWEX3OOqve0ysgpLmuxnxqlevOiesy8cPljDezWak5+NInq/bFcMCadzqkwnsl UQkaNj5Us2/Un0T+qoWEPdLSURnpYxj8pa8mCOTj6xR6k/chfr4quWVmshm7cfF1QUG9 NoMINmBAqMqhQYMU7yOGPei64XvethluZXg5MWd1oYnXyErI3aeqx1xkiQzWb9nxjluR H5gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@z3ntu.xyz header.s=z3ntu header.b=WADf2dd1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=z3ntu.xyz Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y184-20020a638ac1000000b005139bc2e38dsi27162910pgd.507.2023.04.30.11.29.26; Sun, 30 Apr 2023 11:29:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@z3ntu.xyz header.s=z3ntu header.b=WADf2dd1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=z3ntu.xyz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjD3SVi (ORCPT + 99 others); Sun, 30 Apr 2023 14:21:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbjD3SVf (ORCPT ); Sun, 30 Apr 2023 14:21:35 -0400 Received: from mail.z3ntu.xyz (mail.z3ntu.xyz [128.199.32.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E9171735; Sun, 30 Apr 2023 11:21:34 -0700 (PDT) Received: from [192.168.178.23] (unknown [62.108.10.64]) by mail.z3ntu.xyz (Postfix) with ESMTPSA id 941D2CEC7B; Sun, 30 Apr 2023 18:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=z3ntu.xyz; s=z3ntu; t=1682878892; bh=EZ5Rl1sRU/1EQS0k2DDIMWm8qZwGVK/duzJDHMh9kC0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=WADf2dd18dVdmfXoeHoeYASPOfcjoNL2GBf3mbQUfOU6BIZ/kmc/M8kK9eLNy3CLx UrCklO1iH3o8nHiD2xJ3WRG0rbwfsr8ewLdjiEe6ztucoMkjpM6bZx3YAKUn6s4aXN c8ZkDtbsw6q6tAZ3Vw37jitXWwig+OciR7oNxMJk= From: Luca Weiss Date: Sun, 30 Apr 2023 20:20:56 +0200 Subject: [PATCH 4/5] Input: drv260x - fix magnitude handling MIME-Version: 1.0 Message-Id: <20230430-drv260x-improvements-v1-4-1fb28b4cc698@z3ntu.xyz> References: <20230430-drv260x-improvements-v1-0-1fb28b4cc698@z3ntu.xyz> In-Reply-To: <20230430-drv260x-improvements-v1-0-1fb28b4cc698@z3ntu.xyz> To: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, Dmitry Torokhov , Dan Murphy , Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Raffaele Tranquillini , Yassine Oudjana Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, Luca Weiss X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3279; i=luca@z3ntu.xyz; h=from:subject:message-id; bh=EZ5Rl1sRU/1EQS0k2DDIMWm8qZwGVK/duzJDHMh9kC0=; b=owEBbQKS/ZANAwAIAXLYQ7idTddWAcsmYgBkTrGpFTH1r2XTDSQoOggy0k37nDYdgmhMHY8io +kbTgYBwjWJAjMEAAEIAB0WIQQ5utIvCCzakboVj/py2EO4nU3XVgUCZE6xqQAKCRBy2EO4nU3X Vp7uD/wP8XraDh/XqKDzUTo1JaxFCo/o8Q3S3iSlvep48xHb2HU2/AHSnJNlT/6osYanqta5V4P fRJR3QKt2BzYtBPwyBvaJxyrlG0lG5b4Kzpm3TY/PPzVVcWYj+uF1GauyAB2OJOLL/UU9I4/HjF g0FCNKtEUL2oQkGazD323lcD9gRwhijP6625vM3Xrqan/MihHkH/k22gt2rRfsk9iTctXTNfxH2 Q/i9gJwayvQUVD1uIfMw0glbEwjpcxVOpn1w9/rqeE2OstoS96cwkxkQUeOenFRbO1H0wmYRR2m ruTlRgNZwViC4fNKPfqJqcI5WounrCo3V5BGJOY3Xdv1FIXuuoZeImdCimK5Hr9uZTNDvcFeK66 VnNDGzyZ/41cklfT4S8h56w4OTOsPG7sScUwI+WAF9sZbemdigPBtf1/LwArRxgM7l/vbOo5O5f fCeKFK8MWlIliML/I/xqiFpAoA6pZ8QZ5cCOpsYHvfrK6gKNsrkAIKC4fyHVlBS+4wjZDBSs6Mz DvmWTb+3mYuAmm0Y9WVFUI5vPMXizhJjGgeMlzXAayzxt/c751kTME6seR/0oLc/yeLJAjLGwt0 uOQwoHptjTivwZX3b/IIylq1MDPzYLS5zJNLygRurNoIZ1Vj5oKPhmPmw6x/r9WovWGKWBe5UNG TdilpRwndiil81w== X-Developer-Key: i=luca@z3ntu.xyz; a=openpgp; fpr=BD04DA24C971B8D587B2B8D7FAF69CF6CD2D02CD X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764626928918764170?= X-GMAIL-MSGID: =?utf-8?q?1764626928918764170?= First of all, previously the 16-bit magnitude was written as-is to the device which actually discarded the upper 8 bits since the device has 8-bit registers only. This meant that a strong_magnitude of 0xFF00 would result in 0. To correct this shift the strong_magnitude / weak_magnitude input values so we discard the lower 8 bits and keep the upper bits instead. Secondly the RTP mode that is used by default interprets the values as signed (2s complement), so 0x81 = 0%, 0x00 = 50%, 0x7F = 100%. This doesn't match the FF_RUMBLE interface at all, so let's tell the device to interpret the data as unsigned instead which gets us 0x00 = 0% and 0xFF = 100%. As last change switch ERM to using "Closed-Loop Mode, Unidirectional" instead of "Open-Loop Mode" since it's recommended by the datasheet compared to open loop and better matches our use case of 0% - 100% vibration. Signed-off-by: Luca Weiss --- drivers/input/misc/drv260x.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/input/misc/drv260x.c b/drivers/input/misc/drv260x.c index a7e3120bdc13..f5e96b36acda 100644 --- a/drivers/input/misc/drv260x.c +++ b/drivers/input/misc/drv260x.c @@ -186,7 +186,7 @@ struct drv260x_data { struct work_struct work; struct gpio_desc *enable_gpio; struct regulator *regulator; - u32 magnitude; + u8 magnitude; u32 mode; u32 library; int rated_voltage; @@ -237,10 +237,11 @@ static int drv260x_haptics_play(struct input_dev *input, void *data, haptics->mode = DRV260X_LRA_NO_CAL_MODE; + /* Scale u16 magnitude into u8 register value */ if (effect->u.rumble.strong_magnitude > 0) - haptics->magnitude = effect->u.rumble.strong_magnitude; + haptics->magnitude = effect->u.rumble.strong_magnitude >> 8; else if (effect->u.rumble.weak_magnitude > 0) - haptics->magnitude = effect->u.rumble.weak_magnitude; + haptics->magnitude = effect->u.rumble.weak_magnitude >> 8; else haptics->magnitude = 0; @@ -266,7 +267,7 @@ static void drv260x_close(struct input_dev *input) static const struct reg_sequence drv260x_lra_cal_regs[] = { { DRV260X_MODE, DRV260X_AUTO_CAL }, - { DRV260X_CTRL3, DRV260X_NG_THRESH_2 }, + { DRV260X_CTRL3, DRV260X_NG_THRESH_2 | DRV260X_RTP_UNSIGNED_DATA }, { DRV260X_FEEDBACK_CTRL, DRV260X_FB_REG_LRA_MODE | DRV260X_BRAKE_FACTOR_4X | DRV260X_LOOP_GAIN_HIGH }, }; @@ -284,7 +285,7 @@ static const struct reg_sequence drv260x_lra_init_regs[] = { DRV260X_BEMF_GAIN_3 }, { DRV260X_CTRL1, DRV260X_STARTUP_BOOST }, { DRV260X_CTRL2, DRV260X_SAMP_TIME_250 }, - { DRV260X_CTRL3, DRV260X_NG_THRESH_2 | DRV260X_ANALOG_IN }, + { DRV260X_CTRL3, DRV260X_NG_THRESH_2 | DRV260X_RTP_UNSIGNED_DATA | DRV260X_ANALOG_IN }, { DRV260X_CTRL4, DRV260X_AUTOCAL_TIME_500MS }, }; @@ -299,7 +300,7 @@ static const struct reg_sequence drv260x_erm_cal_regs[] = { { DRV260X_CTRL1, DRV260X_STARTUP_BOOST }, { DRV260X_CTRL2, DRV260X_SAMP_TIME_250 | DRV260X_BLANK_TIME_75 | DRV260X_IDISS_TIME_75 }, - { DRV260X_CTRL3, DRV260X_NG_THRESH_2 | DRV260X_ERM_OPEN_LOOP }, + { DRV260X_CTRL3, DRV260X_NG_THRESH_2 | DRV260X_RTP_UNSIGNED_DATA }, { DRV260X_CTRL4, DRV260X_AUTOCAL_TIME_500MS }, };