From patchwork Thu Apr 11 08:30:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu via B4 Relay X-Patchwork-Id: 13625594 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D7A714659E; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; cv=none; b=HHgpWNRAGHHL9eW3d1Lr102Um1g2nobulR/evM+nT2VS3OFFFHY+QARyWL/a6wYQM0HUvINx+x+BsEpj3x33r2K9HpAkrhHbhxbvLy9OqT5x3yZ+eswMkjObMOYGLma+/WFw+33SLaJI0WJjEpwc0rLOqgGcsXPZZsFL8xsvD6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; c=relaxed/simple; bh=4TU/zftz2/VHnWzV3r9cBoeolRMOB6be9XResQyxXNw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qcd48NDfXihgrPh09g7jkBUwoKyeZJhZOrl0NIMO/XEODfIaqEVRhzRFyelXKJLAayslbjuuryTZWmeDFIQFYq/HRXWUAZQEJY6zXThiWLvFns8Gz3U8kH8WyqLxM7pyTLYEMq+siy524oOZIuzYu5HO7MozCTcbd61hS8G4EjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VOg5Nnn0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VOg5Nnn0" Received: by smtp.kernel.org (Postfix) with ESMTPS id E00E9C43399; Thu, 11 Apr 2024 08:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712824326; bh=4TU/zftz2/VHnWzV3r9cBoeolRMOB6be9XResQyxXNw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=VOg5Nnn0XLASgyj0MK6huHrdw6waf1y0yuC+oblarqy429PvIdQQhqbC+SnEww80X zVlb30yNyivgdsMwyCu1RW4vXAaIj6MntbyYjoukpPOjacIEGeOJ2b+34KngNZq+km 28RbGCvlW4sA970rsoi3pj9RjyjBWvoukrt89hlGOBp50qMnXJ056YkPQ3o+JR+BLv ARP5s5xsYvSA/a3rXtkNkNLEp7TnC98HrvYJhymMLBuEh89myZT1Dohlc5d2YlIBuz 6k3hSQhdR18p264tXhayF2jjLw5WrAzlRBHk9WrG99l+qION4XU2aAAH0+40qcrfJG P7lf9k+0gkFgQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0309CD1292; Thu, 11 Apr 2024 08:32:06 +0000 (UTC) From: Fenglin Wu via B4 Relay Date: Thu, 11 Apr 2024 16:30:57 +0800 Subject: [PATCH v9 1/4] input: pm8xxx-vibrator: correct VIB_MAX_LEVELS calculation Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240411-pm8xxx-vibrator-new-design-v9-1-7bf56cb92b28@quicinc.com> References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> In-Reply-To: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> To: kernel@quicinc.com, Andy Gross , Bjorn Andersson , Konrad Dybcio , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Dmitry Baryshkov Cc: linux-arm-msm@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Fenglin Wu X-Mailer: b4 0.13-dev-83828 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712824325; l=1231; i=quic_fenglinw@quicinc.com; s=20240327; h=from:subject:message-id; bh=XkZnFbyEclgfZYkpfzfPCbadhXwXzt48J68H2vEZT+g=; b=TT6XRoITbYVVVhdgUixCMPRemA7UdNfcjUqCgfwIwiEaNpsvUjDchxv0aIz4se5E8QC2TGwBS 44bYehx2zFYA4kyAGQQ9wEQa6hFCWBCfackEp6DGSPjrGRvSWXyI+3C X-Developer-Key: i=quic_fenglinw@quicinc.com; a=ed25519; pk=BF8SA4IVDk8/EBCwlBehKtn2hp6kipuuAuDAHh9s+K4= X-Endpoint-Received: by B4 Relay for quic_fenglinw@quicinc.com/20240327 with auth_id=146 X-Original-From: Fenglin Wu Reply-To: quic_fenglinw@quicinc.com From: Fenglin Wu The output voltage is inclusive hence the max level calculation is off-by-one-step. Correct it. Signed-off-by: Fenglin Wu --- drivers/input/misc/pm8xxx-vibrator.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 04cb87efd799..89f0f1c810d8 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -14,7 +14,8 @@ #define VIB_MAX_LEVEL_mV (3100) #define VIB_MIN_LEVEL_mV (1200) -#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV) +#define VIB_PER_STEP_mV (100) +#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV + VIB_PER_STEP_mV) #define MAX_FF_SPEED 0xff @@ -118,10 +119,10 @@ static void pm8xxx_work_handler(struct work_struct *work) vib->active = true; vib->level = ((VIB_MAX_LEVELS * vib->speed) / MAX_FF_SPEED) + VIB_MIN_LEVEL_mV; - vib->level /= 100; + vib->level /= VIB_PER_STEP_mV; } else { vib->active = false; - vib->level = VIB_MIN_LEVEL_mV / 100; + vib->level = VIB_MIN_LEVEL_mV / VIB_PER_STEP_mV; } pm8xxx_vib_set(vib, vib->active); From patchwork Thu Apr 11 08:30:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu via B4 Relay X-Patchwork-Id: 13625597 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 855C3146A85; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; cv=none; b=oVDBL3tet9hrCs8Y04hniLOV4DIgWdSIZu9vfD6D8xAmAa01k+yjiLlk297Wn/gYOo9PE2lvbveKCELrI1MBF898cXROZdqFsewLjIJ0LI3OttyZCwVwW8x3M/VVe4EYl+Tqb2m0oiAgJA1voNXH+tot/dugUxXTWd/vqtIDRuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; c=relaxed/simple; bh=awcXiHlY45RRTD8/mgYlpukV/VJjGSgPy2Oj5Qablns=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u9BSKz5x1WFZ3b+z04LRw7X5dU70k+/ca3vbFzwBbQWDqVI8JTrWqlToErc/OGx/PPA8FdWiJKeUTAQAatNmfHMW5Ebgs5rKPi/bkgrYVs9P4XRao3WG9yw/xTZ0ItRuPF7fDh8O5G3xKyySmCZB9iQibz2QTecjUTjClpMkYy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HrKnZSjW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HrKnZSjW" Received: by smtp.kernel.org (Postfix) with ESMTPS id EF96BC433A6; Thu, 11 Apr 2024 08:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712824327; bh=awcXiHlY45RRTD8/mgYlpukV/VJjGSgPy2Oj5Qablns=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HrKnZSjW4HhBRx6U8g1kevAQ/Mgrgv4mcLc28fKC0i3FYit1yd3GljRXoYESnVFgi Br7RnPi4c3svW1Jz4slB37pyPWYtoKlAXEmA2wxddm/s7YR+e5vkO+/DAOH5igaC9F /yCUnPfiHiS5/+OQSdZQclKdHfmoTbiUnTwCQQH6lBeSpHObaVOj8yVbcrIgbysHvu bseB1Uqx0VT2pXqgv9XQz7VU+QGzGlbmie6hHZx6W5W7Ds4aemOPW8hGBj61D6EInO udOUhdbG0gEwdv7tKlMyuDGS8eJVbGW/kWFRcJ9ApV8CFGjtIrSiYCYl2Ao2XRRwFb ZMwrHgqgLloow== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1346CD1299; Thu, 11 Apr 2024 08:32:06 +0000 (UTC) From: Fenglin Wu via B4 Relay Date: Thu, 11 Apr 2024 16:30:58 +0800 Subject: [PATCH v9 2/4] input: pm8xxx-vibrator: refactor to support new SPMI vibrator Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240411-pm8xxx-vibrator-new-design-v9-2-7bf56cb92b28@quicinc.com> References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> In-Reply-To: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> To: kernel@quicinc.com, Andy Gross , Bjorn Andersson , Konrad Dybcio , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Dmitry Baryshkov Cc: linux-arm-msm@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Fenglin Wu X-Mailer: b4 0.13-dev-83828 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712824325; l=4271; i=quic_fenglinw@quicinc.com; s=20240327; h=from:subject:message-id; bh=5iLyWd/zr4xemra0cdRKHCPkeXfpcSHYnUInjuL/7l8=; b=USbW4RlGW9KjPBeUeWn+w70DL7kdlAef+iqSXxeCojJc8ZjkAXNroettdOjh31AzRzRBTPkw6 wi5jwRnrCt5A07uXDtkUCG/mc5Y1bvTScF11lYtRpRff6NmgvrlqL7I X-Developer-Key: i=quic_fenglinw@quicinc.com; a=ed25519; pk=BF8SA4IVDk8/EBCwlBehKtn2hp6kipuuAuDAHh9s+K4= X-Endpoint-Received: by B4 Relay for quic_fenglinw@quicinc.com/20240327 with auth_id=146 X-Original-From: Fenglin Wu Reply-To: quic_fenglinw@quicinc.com From: Fenglin Wu Currently, vibrator control register addresses are hard coded, including the base address and offsets, it's not flexible to support new SPMI vibrator module which is usually included in different PMICs with different base address. Refactor it by using the base address defined in devicetree. Signed-off-by: Fenglin Wu --- drivers/input/misc/pm8xxx-vibrator.c | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 89f0f1c810d8..2959edca8eb9 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -20,26 +20,26 @@ #define MAX_FF_SPEED 0xff struct pm8xxx_regs { - unsigned int enable_addr; + unsigned int enable_offset; unsigned int enable_mask; - unsigned int drv_addr; + unsigned int drv_offset; unsigned int drv_mask; unsigned int drv_shift; unsigned int drv_en_manual_mask; }; static const struct pm8xxx_regs pm8058_regs = { - .drv_addr = 0x4A, + .drv_offset = 0x4A, .drv_mask = 0xf8, .drv_shift = 3, .drv_en_manual_mask = 0xfc, }; static struct pm8xxx_regs pm8916_regs = { - .enable_addr = 0xc046, + .enable_offset = 0x46, .enable_mask = BIT(7), - .drv_addr = 0xc041, + .drv_offset = 0x41, .drv_mask = 0x1F, .drv_shift = 0, .drv_en_manual_mask = 0, @@ -51,6 +51,8 @@ static struct pm8xxx_regs pm8916_regs = { * @work: work structure to set the vibration parameters * @regmap: regmap for register read/write * @regs: registers' info + * @enable_addr: vibrator enable register + * @drv_addr: vibrator drive strength register * @speed: speed of vibration set from userland * @active: state of vibrator * @level: level of vibration to set in the chip @@ -61,6 +63,8 @@ struct pm8xxx_vib { struct work_struct work; struct regmap *regmap; const struct pm8xxx_regs *regs; + unsigned int enable_addr; + unsigned int drv_addr; int speed; int level; bool active; @@ -83,15 +87,15 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) else val &= ~regs->drv_mask; - rc = regmap_write(vib->regmap, regs->drv_addr, val); + rc = regmap_write(vib->regmap, vib->drv_addr, val); if (rc < 0) return rc; vib->reg_vib_drv = val; if (regs->enable_mask) - rc = regmap_update_bits(vib->regmap, regs->enable_addr, - regs->enable_mask, on ? ~0 : 0); + rc = regmap_update_bits(vib->regmap, vib->enable_addr, + regs->enable_mask, on ? regs->enable_mask : 0); return rc; } @@ -103,11 +107,10 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) static void pm8xxx_work_handler(struct work_struct *work) { struct pm8xxx_vib *vib = container_of(work, struct pm8xxx_vib, work); - const struct pm8xxx_regs *regs = vib->regs; - int rc; unsigned int val; + int rc; - rc = regmap_read(vib->regmap, regs->drv_addr, &val); + rc = regmap_read(vib->regmap, vib->drv_addr, &val); if (rc < 0) return; @@ -170,7 +173,7 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) struct pm8xxx_vib *vib; struct input_dev *input_dev; int error; - unsigned int val; + unsigned int val, reg_base = 0; const struct pm8xxx_regs *regs; vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL); @@ -190,13 +193,24 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) regs = of_device_get_match_data(&pdev->dev); + if (regs->enable_offset != 0) { + error = fwnode_property_read_u32(pdev->dev.fwnode, "reg", ®_base); + if (error < 0) { + dev_err(&pdev->dev, "Failed to read reg address, rc=%d\n", error); + return error; + } + } + + vib->enable_addr = reg_base + regs->enable_offset; + vib->drv_addr = reg_base + regs->drv_offset; + /* operate in manual mode */ - error = regmap_read(vib->regmap, regs->drv_addr, &val); + error = regmap_read(vib->regmap, vib->drv_addr, &val); if (error < 0) return error; val &= regs->drv_en_manual_mask; - error = regmap_write(vib->regmap, regs->drv_addr, val); + error = regmap_write(vib->regmap, vib->drv_addr, val); if (error < 0) return error; From patchwork Thu Apr 11 08:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu via B4 Relay X-Patchwork-Id: 13625598 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85751146A8C; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; cv=none; b=B15EfP+EVwq5ATgkUiQk5w7EgoPiY07NS+EFTr/FcqS2BjUobGpJVrB200UEtlpaiHgD8Ifq1DQ0vbLBI4tFTCqJF6jrTLmWFsAi1667Zb7dMGlqMKtgupovcYcaqVoKFUbJUDd6c9/H3u3YRP008+L+4K0ki0z8veXbVWVBqd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; c=relaxed/simple; bh=2pSJ5RtkTJUIWZtuMClF1MziyBCDcsQTg8O2HQnpmqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CLNAf0XdTokiSDTujS6ROgM9bzUbJYHFTNTxN4F24JBZFlWzR5+99wweW1ekwd3bpu3nu2t/qbvsLzxmxHL1BT4FZ6geJM9IX990UVn60temrYE+he17JV3jd29xUQ3SRBriI5Og3xlwp06sDjBpmg02r/D+k+K0SRZDvwUh7sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A1TxZ7Hj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A1TxZ7Hj" Received: by smtp.kernel.org (Postfix) with ESMTPS id 07894C433B1; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712824327; bh=2pSJ5RtkTJUIWZtuMClF1MziyBCDcsQTg8O2HQnpmqY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=A1TxZ7Hj6II42OysevajMY6o3hNAwyYleYDBdZEJReniV5AypzzOQ6MqUcBOAztKF +qjckBplSIC2GlQeLqHX0CqnEb9S1JjeW8jblQeahn82NWoQtaH4TGQIbYNLff9PK2 l/D/S+++UbRvRWEYxkK27aPgdSSePgwqhVD0RIIgz0gwBun+km6ulnWKR/4RuxygaJ fLzrAb7GLWc8jNidp+Hm5rX62dvtKUkduKjRr2+X9wsCqYxALfChIVntyFyJ6KxMtC b0ZaxEjGnqufpLpHd7+rFkNTUOJGLHkOhJWviQyZ2RKOxS/xCj2t3U9QtPRvoUYdXs sVhtsgvcGVszA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED88ACD128A; Thu, 11 Apr 2024 08:32:06 +0000 (UTC) From: Fenglin Wu via B4 Relay Date: Thu, 11 Apr 2024 16:30:59 +0800 Subject: [PATCH v9 3/4] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240411-pm8xxx-vibrator-new-design-v9-3-7bf56cb92b28@quicinc.com> References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> In-Reply-To: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> To: kernel@quicinc.com, Andy Gross , Bjorn Andersson , Konrad Dybcio , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Dmitry Baryshkov Cc: linux-arm-msm@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Fenglin Wu , Krzysztof Kozlowski X-Mailer: b4 0.13-dev-83828 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712824325; l=1205; i=quic_fenglinw@quicinc.com; s=20240327; h=from:subject:message-id; bh=SwnogURbBf0S1flEa633BZvpsevy5nBnFae6M+y7bFo=; b=2lEkdbrPEw81OD95Z9DZiCTOC2ragbnwcYnsSVGs1egINyGATNjqy2mHHE0QtSL+ecbEecMkS y89PApfOMQZBPW+RwXtdMVhKLa9oUfFCOlvrJ8h/v5ifPQ+w12GtZPz X-Developer-Key: i=quic_fenglinw@quicinc.com; a=ed25519; pk=BF8SA4IVDk8/EBCwlBehKtn2hp6kipuuAuDAHh9s+K4= X-Endpoint-Received: by B4 Relay for quic_fenglinw@quicinc.com/20240327 with auth_id=146 X-Original-From: Fenglin Wu Reply-To: quic_fenglinw@quicinc.com From: Fenglin Wu Add compatible strings to support vibrator module inside PMI632, PMI7250B, PM7325B, PM7550BA. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Fenglin Wu --- .../devicetree/bindings/input/qcom,pm8xxx-vib.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml b/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml index c8832cd0d7da..2025d6a5423e 100644 --- a/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml +++ b/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml @@ -11,10 +11,18 @@ maintainers: properties: compatible: - enum: - - qcom,pm8058-vib - - qcom,pm8916-vib - - qcom,pm8921-vib + oneOf: + - enum: + - qcom,pm8058-vib + - qcom,pm8916-vib + - qcom,pm8921-vib + - qcom,pmi632-vib + - items: + - enum: + - qcom,pm7250b-vib + - qcom,pm7325b-vib + - qcom,pm7550ba-vib + - const: qcom,pmi632-vib reg: maxItems: 1 From patchwork Thu Apr 11 08:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu via B4 Relay X-Patchwork-Id: 13625596 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 856A3146A89; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; cv=none; b=OT7cChLBKZlyUE4g4zVWN3Fc34eUOttyIaHvse9Q6SbNZsyjApvWgz3GiFJ1eZ75WxIknexKZfFrmfXR2cCmqOSCFzDBZhTtuohu3si2V14tnQg9hwe8YvbLih8i7sEOyaSGWZW182EP+sl09hvp04zQ0lATV9/rUkAtrEyhgtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824327; c=relaxed/simple; bh=t0BFVQH3c9KhLWbAWpY27qKlp18EmcbQmBMeJCcdds8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NjcQtc9HXo0zrKeJmqA98wt+NYEgP5sJpiOFVa9cSvlM4n6VYv32VpETtOTibpQfyxY9ZQUGyqteNJdKL5SK3AWX5CP/PYuxnlfoDGeMcO72LVdGuXGkA6egFVFDs58YN6PS3bP/RwFXf3T3ZNFkKKg2JaD4Ua1c7IIu9dZtf38= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rMmMevMo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rMmMevMo" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0EC5EC43143; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712824327; bh=t0BFVQH3c9KhLWbAWpY27qKlp18EmcbQmBMeJCcdds8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rMmMevMoH0eC3QDGUSgOXDZhUZVPpHPAo3mpIl+uqvsxIkZ4gGjkvvk74OLdzibYa 9YELC7frhPh3b7VVwA/JEEJNgUGRvnMxLuZIQcak8PWK6twlw/A959wYPZxrMxMBJr +92CQ5hOB75TYajF20u3k1sn8kOE4nVytlkXqk1mbqk3RS6Oy/MK4ibGOw+kNL6zgG k9HS8WoSnXf7nSypO1HAQRQO4JlItCoSs7vTXvY1tp5jGoOjCgcEE4d2etffAVzFng DlulDaMKxXSzKwzUaSgudrmiH9GQ1GOOl2C/IRdI+dNbNayOssDiYgrJGWs2dlxEuA fDG4JS0n+LgTQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0729ECD129D; Thu, 11 Apr 2024 08:32:07 +0000 (UTC) From: Fenglin Wu via B4 Relay Date: Thu, 11 Apr 2024 16:31:00 +0800 Subject: [PATCH v9 4/4] input: pm8xxx-vibrator: add new SPMI vibrator support Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240411-pm8xxx-vibrator-new-design-v9-4-7bf56cb92b28@quicinc.com> References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> In-Reply-To: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> To: kernel@quicinc.com, Andy Gross , Bjorn Andersson , Konrad Dybcio , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Dmitry Baryshkov Cc: linux-arm-msm@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Fenglin Wu X-Mailer: b4 0.13-dev-83828 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712824325; l=5033; i=quic_fenglinw@quicinc.com; s=20240327; h=from:subject:message-id; bh=pTrC3cQoxz8pNZ4KpoF3OkEKSt7RYrt88MbWTTuCxL8=; b=TIEmWRFBPPnL83zharf5f0HHXbluRZMLc0eHt4/Lk+TBjGNhrYdxoj/1mo83UJyaUdCFlnWZa OahhOq+XR31DswuGEuPgOZCz8ovvvyM3c56rs3R4g2B/TiYXJ2Ww60s X-Developer-Key: i=quic_fenglinw@quicinc.com; a=ed25519; pk=BF8SA4IVDk8/EBCwlBehKtn2hp6kipuuAuDAHh9s+K4= X-Endpoint-Received: by B4 Relay for quic_fenglinw@quicinc.com/20240327 with auth_id=146 X-Original-From: Fenglin Wu Reply-To: quic_fenglinw@quicinc.com From: Fenglin Wu Add support for a new SPMI vibrator module which is very similar to the vibrator module inside PM8916 but has a finer drive voltage step and different output voltage range, its drive level control is expanded across 2 registers. The vibrator module can be found in following Qualcomm PMICs: PMI632, PM7250B, PM7325B, PM7550BA. Signed-off-by: Fenglin Wu --- drivers/input/misc/pm8xxx-vibrator.c | 51 +++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 2959edca8eb9..35bb6f450fd2 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -12,10 +12,10 @@ #include #include -#define VIB_MAX_LEVEL_mV (3100) -#define VIB_MIN_LEVEL_mV (1200) -#define VIB_PER_STEP_mV (100) -#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV + VIB_PER_STEP_mV) +#define VIB_MAX_LEVEL_mV(vib) (vib->drv2_addr ? 3544 : 3100) +#define VIB_MIN_LEVEL_mV(vib) (vib->drv2_addr ? 1504 : 1200) +#define VIB_PER_STEP_mV(vib) (vib->drv2_addr ? 8 : 100) +#define VIB_MAX_LEVELS(vib) (VIB_MAX_LEVEL_mV(vib) - VIB_MIN_LEVEL_mV(vib) + VIB_PER_STEP_mV(vib)) #define MAX_FF_SPEED 0xff @@ -26,6 +26,9 @@ struct pm8xxx_regs { unsigned int drv_offset; unsigned int drv_mask; unsigned int drv_shift; + unsigned int drv2_offset; + unsigned int drv2_mask; + unsigned int drv2_shift; unsigned int drv_en_manual_mask; }; @@ -45,6 +48,18 @@ static struct pm8xxx_regs pm8916_regs = { .drv_en_manual_mask = 0, }; +static struct pm8xxx_regs pmi632_regs = { + .enable_offset = 0x46, + .enable_mask = BIT(7), + .drv_offset = 0x40, + .drv_mask = GENMASK(7, 0), + .drv_shift = 0, + .drv2_offset = 0x41, + .drv2_mask = GENMASK(3, 0), + .drv2_shift = 8, + .drv_en_manual_mask = 0, +}; + /** * struct pm8xxx_vib - structure to hold vibrator data * @vib_input_dev: input device supporting force feedback @@ -53,6 +68,7 @@ static struct pm8xxx_regs pm8916_regs = { * @regs: registers' info * @enable_addr: vibrator enable register * @drv_addr: vibrator drive strength register + * @drv2_addr: vibrator drive strength upper byte register * @speed: speed of vibration set from userland * @active: state of vibrator * @level: level of vibration to set in the chip @@ -65,6 +81,7 @@ struct pm8xxx_vib { const struct pm8xxx_regs *regs; unsigned int enable_addr; unsigned int drv_addr; + unsigned int drv2_addr; int speed; int level; bool active; @@ -82,6 +99,10 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) unsigned int val = vib->reg_vib_drv; const struct pm8xxx_regs *regs = vib->regs; + /* vibrator without drv2_addr needs be programmed in step increments */ + if (!vib->drv2_addr) + vib->level /= VIB_PER_STEP_mV(vib); + if (on) val |= (vib->level << regs->drv_shift) & regs->drv_mask; else @@ -93,6 +114,17 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) vib->reg_vib_drv = val; + if (regs->drv2_mask) { + if (on) + val = (vib->level << regs->drv2_shift) & regs->drv2_mask; + else + val = 0; + + rc = regmap_write_bits(vib->regmap, vib->drv2_addr, regs->drv2_mask, val); + if (rc < 0) + return rc; + } + if (regs->enable_mask) rc = regmap_update_bits(vib->regmap, vib->enable_addr, regs->enable_mask, on ? regs->enable_mask : 0); @@ -115,17 +147,16 @@ static void pm8xxx_work_handler(struct work_struct *work) return; /* - * pmic vibrator supports voltage ranges from 1.2 to 3.1V, so + * pmic vibrator supports voltage ranges from MIN_LEVEL to MAX_LEVEL, so * scale the level to fit into these ranges. */ if (vib->speed) { vib->active = true; - vib->level = ((VIB_MAX_LEVELS * vib->speed) / MAX_FF_SPEED) + - VIB_MIN_LEVEL_mV; - vib->level /= VIB_PER_STEP_mV; + vib->level = VIB_MIN_LEVEL_mV(vib); + vib->level += mult_frac(VIB_MAX_LEVELS(vib), vib->speed, MAX_FF_SPEED); } else { vib->active = false; - vib->level = VIB_MIN_LEVEL_mV / VIB_PER_STEP_mV; + vib->level = VIB_MIN_LEVEL_mV(vib); } pm8xxx_vib_set(vib, vib->active); @@ -203,6 +234,7 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) vib->enable_addr = reg_base + regs->enable_offset; vib->drv_addr = reg_base + regs->drv_offset; + vib->drv2_addr = reg_base + regs->drv2_offset; /* operate in manual mode */ error = regmap_read(vib->regmap, vib->drv_addr, &val); @@ -257,6 +289,7 @@ static const struct of_device_id pm8xxx_vib_id_table[] = { { .compatible = "qcom,pm8058-vib", .data = &pm8058_regs }, { .compatible = "qcom,pm8921-vib", .data = &pm8058_regs }, { .compatible = "qcom,pm8916-vib", .data = &pm8916_regs }, + { .compatible = "qcom,pmi632-vib", .data = &pmi632_regs }, { } }; MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table);