Message ID | 20230718062639.2339589-3-quic_fenglinw@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1547180vqt; Mon, 17 Jul 2023 23:44:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlFhRPtITBeIVWtqxIh8m7AYDj1V8xhzbmYpIyEqOQVnw36aQFSYtMI+Ib+RCmC34L62Nx4O X-Received: by 2002:aa7:d852:0:b0:521:6275:c9af with SMTP id f18-20020aa7d852000000b005216275c9afmr13073800eds.7.1689662696333; Mon, 17 Jul 2023 23:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689662696; cv=none; d=google.com; s=arc-20160816; b=SntC1dpi4YNCliaNXuYOPdsorZHRBYOvUVJQxI2hRsoClnY5gFytlAqASrPDMgrCFm C1M7u/veTXk2g1lqrUhZ8f1kr+/4TySfBC7MOhTK3rkM1ccP/c0huBlRx6ryqTpY0nR8 8vQ4OZBcdF6Crzw5Vn9qUoEIz1Q4Csl8Q+MDljf6dows2Ex2O8hg3hOJsaNA/MHCQe8l PP9lsEX4xgb2EKv3urtDpejd4d+U8Oe2vBg3vzaBCI6gZL3u+h26DGMFBGn9271Jxn4r kMKz/C42b+dAjzMT0h2r+F2/Sb5PVvnXBRHgIpYcHtkd1nxvRfcljXpGfc4R2TEFhSTn yiEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0Uv4at9BAvzBcsEjqd9tVi9PFcSvrNPrjvYjLuySbXc=; fh=0ZabanOXnZSfxp21F3xHfNMk6WE3fh62eIWgACT9ymY=; b=D1OH65hUOkNasGlQ0ARfCXPX6WDfeVvcGFyvzcGjKPDkhOr3p9f6YqoUYAOgHrLl6T 0LKeRD09AMPF4m8Y4GzT7g+5SEXpXiVw+UpaNfYWH1QAE+3VSdU2AYMwqAa2y07ZEgz0 Z4aft07+hfgU8M/X9KN9/vSFd3whLDB86RZx7+F2aqbB+1YAX5HbB8svJJoXe7aDlyW5 slCpL0QJAsxjEp0QxHBhn/lKV7icB9504yBxJWrcVJv5PeE22itIxRcgSjBgOzO782CO GUfAN3/Vj65I0GqlitcAXIgGzBv5ThHCs0xZO968Nk0vs9/dLl9DJoZyDzeXDGxN2Az8 Z9qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XMAqwrfa; 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=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h26-20020aa7de1a000000b0051e0f234b41si759038edv.130.2023.07.17.23.44.32; Mon, 17 Jul 2023 23:44:56 -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=@quicinc.com header.s=qcppdkim1 header.b=XMAqwrfa; 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=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231245AbjGRG11 (ORCPT <rfc822;daweilics@gmail.com> + 99 others); Tue, 18 Jul 2023 02:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbjGRG1Q (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 18 Jul 2023 02:27:16 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED40172E; Mon, 17 Jul 2023 23:27:08 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36I59c7X021523; Tue, 18 Jul 2023 06:27:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=0Uv4at9BAvzBcsEjqd9tVi9PFcSvrNPrjvYjLuySbXc=; b=XMAqwrfa5lI/NclTA6OTdCHScH+SS70wya1AqKzb2lBuctXh7PP/pyBf14E0TzVPj+Pp n5VBQB567oLSSVImKrirnGmG2UKctIrEj0yPejEAUn4jAveRzTub7+7sV9O3G+Ivi3/s OD7qtDzMCMd8BXZitrg5B3LhHHIXIrJr87th1oLvhT7HmGHvswU+aRLd1XqxJJkR7nFy vZlywhR4qxotf1bR+A8uA8/4MAQNlMTXdUHF+916gB2tA8M/tPVFBG03R7Ook81U2DQn BHwUrh0U9aNeFzRtPLxSxxnFnwXB+27oavyBupOqJ48CCh9aClwYN/bZZWaLiO387d9I bA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rw289tj7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 06:27:04 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36I6R3Ce000737 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 06:27:03 GMT Received: from fenglinw2-gv.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Mon, 17 Jul 2023 23:27:00 -0700 From: Fenglin Wu <quic_fenglinw@quicinc.com> To: <linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>, "Andy Gross" <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, "Konrad Dybcio" <konrad.dybcio@linaro.org>, Dmitry Torokhov <dmitry.torokhov@gmail.com>, <linux-input@vger.kernel.org> CC: <quic_collinsd@quicinc.com>, <quic_subbaram@quicinc.com>, <quic_fenglinw@quicinc.com>, <quic_kamalw@quicinc.com>, <jestar@qti.qualcomm.com> Subject: [PATCH v2 2/2] Input: pm8xxx-vib - Add support for more PMICs Date: Tue, 18 Jul 2023 14:26:39 +0800 Message-ID: <20230718062639.2339589-3-quic_fenglinw@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230718062639.2339589-1-quic_fenglinw@quicinc.com> References: <20230718062639.2339589-1-quic_fenglinw@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: PA-Wvio-RJaHgjBE8o48brQz9DhmpoA5 X-Proofpoint-GUID: PA-Wvio-RJaHgjBE8o48brQz9DhmpoA5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-17_15,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxlogscore=953 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307180058 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771739751096656110 X-GMAIL-MSGID: 1771739751096656110 |
Series |
Add support for vibrator in multiple PMICs
|
|
Commit Message
Fenglin Wu
July 18, 2023, 6:26 a.m. UTC
Add support for vibrator module inside PMI632, PM7250B, PM7325B.
It is very similar to vibrator inside PM8xxx but just the drive
amplitude is controlled through 2 bytes registers.
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
---
drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
Comments
On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > > Add support for vibrator module inside PMI632, PM7250B, PM7325B. > It is very similar to vibrator inside PM8xxx but just the drive > amplitude is controlled through 2 bytes registers. > > Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> > --- > drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ > 1 file changed, 48 insertions(+) > > diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c > index 04cb87efd799..213fdfd47c7f 100644 > --- a/drivers/input/misc/pm8xxx-vibrator.c > +++ b/drivers/input/misc/pm8xxx-vibrator.c > @@ -25,6 +25,9 @@ struct pm8xxx_regs { > unsigned int drv_addr; > unsigned int drv_mask; > unsigned int drv_shift; > + unsigned int drv_addr2; > + unsigned int drv_mask2; > + unsigned int drv_shift2; > unsigned int drv_en_manual_mask; > }; > > @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { > .drv_en_manual_mask = 0, > }; > > +static struct pm8xxx_regs pmi632_regs = { > + .enable_addr = 0x5746, > + .enable_mask = BIT(7), > + .drv_addr = 0x5740, > + .drv_mask = 0xff, > + .drv_shift = 0, > + .drv_addr2 = 0x5741, > + .drv_mask2 = 0x0f, > + .drv_shift2 = 8, I see that you are just expanding what was done for SSBI PMICs and later expanded to support pm8916. However it might be better to drop the hardcoded .drv_addr (and drv_addr2) and read address from DT instead. > + .drv_en_manual_mask = 0, > +}; > + > +static struct pm8xxx_regs pm7250b_regs = { > + .enable_addr = 0x5346, > + .enable_mask = BIT(7), > + .drv_addr = 0x5340, > + .drv_mask = 0xff, > + .drv_shift = 0, > + .drv_addr2 = 0x5341, > + .drv_mask2 = 0x0f, > + .drv_shift2 = 8, > + .drv_en_manual_mask = 0, > +}; > + > +static struct pm8xxx_regs pm7325b_regs = { > + .enable_addr = 0xdf46, > + .enable_mask = BIT(7), > + .drv_addr = 0xdf40, > + .drv_mask = 0xff, > + .drv_shift = 0, > + .drv_addr2 = 0xdf41, > + .drv_mask2 = 0x0f, > + .drv_shift2 = 8, > + .drv_en_manual_mask = 0, > +}; > + > /** > * struct pm8xxx_vib - structure to hold vibrator data > * @vib_input_dev: input device supporting force feedback > @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) > return rc; > > vib->reg_vib_drv = val; > + if (regs->drv_addr2 != 0 && on) { > + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; > + rc = regmap_write(vib->regmap, regs->drv_addr2, val); > + if (rc < 0) > + return rc; > + } > > if (regs->enable_mask) > rc = regmap_update_bits(vib->regmap, regs->enable_addr, > @@ -242,6 +287,9 @@ 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 }, > + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, > + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, > { } > }; > MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); > -- > 2.25.1 >
On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: > On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >> >> Add support for vibrator module inside PMI632, PM7250B, PM7325B. >> It is very similar to vibrator inside PM8xxx but just the drive >> amplitude is controlled through 2 bytes registers. >> >> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> >> --- >> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ >> 1 file changed, 48 insertions(+) >> >> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c >> index 04cb87efd799..213fdfd47c7f 100644 >> --- a/drivers/input/misc/pm8xxx-vibrator.c >> +++ b/drivers/input/misc/pm8xxx-vibrator.c >> @@ -25,6 +25,9 @@ struct pm8xxx_regs { >> unsigned int drv_addr; >> unsigned int drv_mask; >> unsigned int drv_shift; >> + unsigned int drv_addr2; >> + unsigned int drv_mask2; >> + unsigned int drv_shift2; >> unsigned int drv_en_manual_mask; >> }; >> >> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { >> .drv_en_manual_mask = 0, >> }; >> >> +static struct pm8xxx_regs pmi632_regs = { >> + .enable_addr = 0x5746, >> + .enable_mask = BIT(7), >> + .drv_addr = 0x5740, >> + .drv_mask = 0xff, >> + .drv_shift = 0, >> + .drv_addr2 = 0x5741, >> + .drv_mask2 = 0x0f, >> + .drv_shift2 = 8, > > I see that you are just expanding what was done for SSBI PMICs and > later expanded to support pm8916. However it might be better to drop > the hardcoded .drv_addr (and drv_addr2) and read address from DT > instead. > Right, this is the simplest change without updating the code logic too much. If we decided to read .drv_addr and .drv_add2 from DT, we will have to read .enable_addr along with all other mask/shift for each register address from DT as well because they are not consistent from target to target. I don't know how would you suggest to add the DT properties for all of them, but if we end up to add a property for each of them, it won't be cleaner than hard-coding them. >> + .drv_en_manual_mask = 0, >> +}; >> + >> +static struct pm8xxx_regs pm7250b_regs = { >> + .enable_addr = 0x5346, >> + .enable_mask = BIT(7), >> + .drv_addr = 0x5340, >> + .drv_mask = 0xff, >> + .drv_shift = 0, >> + .drv_addr2 = 0x5341, >> + .drv_mask2 = 0x0f, >> + .drv_shift2 = 8, >> + .drv_en_manual_mask = 0, >> +}; >> + >> +static struct pm8xxx_regs pm7325b_regs = { >> + .enable_addr = 0xdf46, >> + .enable_mask = BIT(7), >> + .drv_addr = 0xdf40, >> + .drv_mask = 0xff, >> + .drv_shift = 0, >> + .drv_addr2 = 0xdf41, >> + .drv_mask2 = 0x0f, >> + .drv_shift2 = 8, >> + .drv_en_manual_mask = 0, >> +}; >> + >> /** >> * struct pm8xxx_vib - structure to hold vibrator data >> * @vib_input_dev: input device supporting force feedback >> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) >> return rc; >> >> vib->reg_vib_drv = val; >> + if (regs->drv_addr2 != 0 && on) { >> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; >> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); >> + if (rc < 0) >> + return rc; >> + } >> >> if (regs->enable_mask) >> rc = regmap_update_bits(vib->regmap, regs->enable_addr, >> @@ -242,6 +287,9 @@ 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 }, >> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, >> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, >> { } >> }; >> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); >> -- >> 2.25.1 >> > >
On Tue, 18 Jul 2023 at 09:58, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > > > > On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: > > On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > >> > >> Add support for vibrator module inside PMI632, PM7250B, PM7325B. > >> It is very similar to vibrator inside PM8xxx but just the drive > >> amplitude is controlled through 2 bytes registers. > >> > >> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> > >> --- > >> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ > >> 1 file changed, 48 insertions(+) > >> > >> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c > >> index 04cb87efd799..213fdfd47c7f 100644 > >> --- a/drivers/input/misc/pm8xxx-vibrator.c > >> +++ b/drivers/input/misc/pm8xxx-vibrator.c > >> @@ -25,6 +25,9 @@ struct pm8xxx_regs { > >> unsigned int drv_addr; > >> unsigned int drv_mask; > >> unsigned int drv_shift; > >> + unsigned int drv_addr2; > >> + unsigned int drv_mask2; > >> + unsigned int drv_shift2; > >> unsigned int drv_en_manual_mask; > >> }; > >> > >> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { > >> .drv_en_manual_mask = 0, > >> }; > >> > >> +static struct pm8xxx_regs pmi632_regs = { > >> + .enable_addr = 0x5746, > >> + .enable_mask = BIT(7), > >> + .drv_addr = 0x5740, > >> + .drv_mask = 0xff, > >> + .drv_shift = 0, > >> + .drv_addr2 = 0x5741, > >> + .drv_mask2 = 0x0f, > >> + .drv_shift2 = 8, > > > > I see that you are just expanding what was done for SSBI PMICs and > > later expanded to support pm8916. However it might be better to drop > > the hardcoded .drv_addr (and drv_addr2) and read address from DT > > instead. > > > > Right, this is the simplest change without updating the code logic too > much. If we decided to read .drv_addr and .drv_add2 from DT, we will > have to read .enable_addr along with all other mask/shift for each > register address from DT as well because they are not consistent from > target to target. I don't know how would you suggest to add the DT > properties for all of them, but if we end up to add a property for each > of them, it won't be cleaner than hard-coding them. No, we (correctly) have device compatibles for that. The issue with hardcoding register addresses is that it adds extra issues here. If I understand correctly, we have several 'generation': - SSBI PMIC, shifted 5-bit mask, en_manual_mask, no enable_register. - older SPMI PMIC, 5 bit drv_mask, 0 en_manual_mask, enable register at +6 - new SPMI PMIC, 12 bit drv_mask, 0 en_manual_mask, enable register at +6 For the last generation you are adding three independent entries, while the block looks the same. If you remove drv_addr (and get it from reg property), it would allow us to keep only the functional data in struct pm8xxxx_regs (masks / shifts). > > > >> + .drv_en_manual_mask = 0, > >> +}; > >> + > >> +static struct pm8xxx_regs pm7250b_regs = { > >> + .enable_addr = 0x5346, > >> + .enable_mask = BIT(7), > >> + .drv_addr = 0x5340, > >> + .drv_mask = 0xff, > >> + .drv_shift = 0, > >> + .drv_addr2 = 0x5341, > >> + .drv_mask2 = 0x0f, > >> + .drv_shift2 = 8, > >> + .drv_en_manual_mask = 0, > >> +}; > >> + > >> +static struct pm8xxx_regs pm7325b_regs = { > >> + .enable_addr = 0xdf46, > >> + .enable_mask = BIT(7), > >> + .drv_addr = 0xdf40, > >> + .drv_mask = 0xff, > >> + .drv_shift = 0, > >> + .drv_addr2 = 0xdf41, > >> + .drv_mask2 = 0x0f, > >> + .drv_shift2 = 8, > >> + .drv_en_manual_mask = 0, > >> +}; > >> + > >> /** > >> * struct pm8xxx_vib - structure to hold vibrator data > >> * @vib_input_dev: input device supporting force feedback > >> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) > >> return rc; > >> > >> vib->reg_vib_drv = val; > >> + if (regs->drv_addr2 != 0 && on) { > >> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; > >> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); > >> + if (rc < 0) > >> + return rc; > >> + } > >> > >> if (regs->enable_mask) > >> rc = regmap_update_bits(vib->regmap, regs->enable_addr, > >> @@ -242,6 +287,9 @@ 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 }, > >> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, > >> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, > >> { } > >> }; > >> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); > >> -- > >> 2.25.1 > >> > > > >
On 7/18/2023 5:41 PM, Dmitry Baryshkov wrote: > On Tue, 18 Jul 2023 at 09:58, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >> >> >> >> On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: >>> On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >>>> >>>> Add support for vibrator module inside PMI632, PM7250B, PM7325B. >>>> It is very similar to vibrator inside PM8xxx but just the drive >>>> amplitude is controlled through 2 bytes registers. >>>> >>>> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> >>>> --- >>>> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ >>>> 1 file changed, 48 insertions(+) >>>> >>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c >>>> index 04cb87efd799..213fdfd47c7f 100644 >>>> --- a/drivers/input/misc/pm8xxx-vibrator.c >>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c >>>> @@ -25,6 +25,9 @@ struct pm8xxx_regs { >>>> unsigned int drv_addr; >>>> unsigned int drv_mask; >>>> unsigned int drv_shift; >>>> + unsigned int drv_addr2; >>>> + unsigned int drv_mask2; >>>> + unsigned int drv_shift2; >>>> unsigned int drv_en_manual_mask; >>>> }; >>>> >>>> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { >>>> .drv_en_manual_mask = 0, >>>> }; >>>> >>>> +static struct pm8xxx_regs pmi632_regs = { >>>> + .enable_addr = 0x5746, >>>> + .enable_mask = BIT(7), >>>> + .drv_addr = 0x5740, >>>> + .drv_mask = 0xff, >>>> + .drv_shift = 0, >>>> + .drv_addr2 = 0x5741, >>>> + .drv_mask2 = 0x0f, >>>> + .drv_shift2 = 8, >>> >>> I see that you are just expanding what was done for SSBI PMICs and >>> later expanded to support pm8916. However it might be better to drop >>> the hardcoded .drv_addr (and drv_addr2) and read address from DT >>> instead. >>> >> >> Right, this is the simplest change without updating the code logic too >> much. If we decided to read .drv_addr and .drv_add2 from DT, we will >> have to read .enable_addr along with all other mask/shift for each >> register address from DT as well because they are not consistent from >> target to target. I don't know how would you suggest to add the DT >> properties for all of them, but if we end up to add a property for each >> of them, it won't be cleaner than hard-coding them. > > No, we (correctly) have device compatibles for that. The issue with > hardcoding register addresses is that it adds extra issues here. > > If I understand correctly, we have several 'generation': > - SSBI PMIC, shifted 5-bit mask, en_manual_mask, no enable_register. > - older SPMI PMIC, 5 bit drv_mask, 0 en_manual_mask, enable register at +6 > - new SPMI PMIC, 12 bit drv_mask, 0 en_manual_mask, enable register at +6 > > For the last generation you are adding three independent entries, > while the block looks the same. If you remove drv_addr (and get it > from reg property), it would allow us to keep only the functional data > in struct pm8xxxx_regs (masks / shifts). > Okay, let me know if I understood it correctly, this is what you are suggesting: - hard code the mask/shifts and still keep them in struct pm8xxx_regs, combine the drv_mask2 to the upper byte of the drv_mask, so we will have following data structure for the 3rd generation vibrator static struct pm8xxx_regs pm7250b_regs = { .enable_addr = 0x5346, .enable_mask = BIT(7), .drv_mask = 0xfff, .drv_shift = 0, .drv_en_manual_mask = 0, }; - move the drv_addr/drv_addr2 into DT, read them from 'reg' property. Because of 'mfd/qcom,spmi-pmic.yaml' has defined the 'address-cells' as 1 and the 'size-cells' as 0 for qcom spmi devices, we couldn't specify the address size to 2 even the drv_addr for the 3rd generation vibrator is 2 adjacent bytes. So we will end of having following DT scheme: For the 2nd generation which only has drv_addr vibrator@c041 { compatible = "qcom,pm8916-vib"; reg = <0xc041>; /* drv_addr */ ... }; For the 3rd generation which has both drv_addr and drv_addr2 vibrator@5340 { compatible = "qcom,pm7250b-vib"; reg = <0x5340>, /* drv_addr */ <0x5341>; /* drv_addr2 */ ... }; Not sure how do you feel, I actually don't see too much benefit than hard-coding them in the driver. We will end up having code to check how many u32 value in the 'reg' and only assign it to drv_addr2 when the 2nd is available, also when programming drv_addr2 register, the driver will always assume the mask is in the upper byte of the drv_mask and the shift to the drive level is 8 (this seems hacky to me and it was my biggest concern while I made this change, and it led me to defining drv_shift2/drv_mask2 along with drv_addr2). >> >> >>>> + .drv_en_manual_mask = 0, >>>> +}; >>>> + >>>> +static struct pm8xxx_regs pm7250b_regs = { >>>> + .enable_addr = 0x5346, >>>> + .enable_mask = BIT(7), >>>> + .drv_addr = 0x5340, >>>> + .drv_mask = 0xff, >>>> + .drv_shift = 0, >>>> + .drv_addr2 = 0x5341, >>>> + .drv_mask2 = 0x0f, >>>> + .drv_shift2 = 8, >>>> + .drv_en_manual_mask = 0, >>>> +}; >>>> + >>>> +static struct pm8xxx_regs pm7325b_regs = { >>>> + .enable_addr = 0xdf46, >>>> + .enable_mask = BIT(7), >>>> + .drv_addr = 0xdf40, >>>> + .drv_mask = 0xff, >>>> + .drv_shift = 0, >>>> + .drv_addr2 = 0xdf41, >>>> + .drv_mask2 = 0x0f, >>>> + .drv_shift2 = 8, >>>> + .drv_en_manual_mask = 0, >>>> +}; >>>> + >>>> /** >>>> * struct pm8xxx_vib - structure to hold vibrator data >>>> * @vib_input_dev: input device supporting force feedback >>>> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) >>>> return rc; >>>> >>>> vib->reg_vib_drv = val; >>>> + if (regs->drv_addr2 != 0 && on) { >>>> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; >>>> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); >>>> + if (rc < 0) >>>> + return rc; >>>> + } >>>> >>>> if (regs->enable_mask) >>>> rc = regmap_update_bits(vib->regmap, regs->enable_addr, >>>> @@ -242,6 +287,9 @@ 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 }, >>>> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, >>>> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, >>>> { } >>>> }; >>>> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); >>>> -- >>>> 2.25.1 >>>> >>> >>> > > >
On Tue, 18 Jul 2023 at 13:55, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > > > > On 7/18/2023 5:41 PM, Dmitry Baryshkov wrote: > > On Tue, 18 Jul 2023 at 09:58, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > >> > >> > >> > >> On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: > >>> On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > >>>> > >>>> Add support for vibrator module inside PMI632, PM7250B, PM7325B. > >>>> It is very similar to vibrator inside PM8xxx but just the drive > >>>> amplitude is controlled through 2 bytes registers. > >>>> > >>>> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> > >>>> --- > >>>> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ > >>>> 1 file changed, 48 insertions(+) > >>>> > >>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c > >>>> index 04cb87efd799..213fdfd47c7f 100644 > >>>> --- a/drivers/input/misc/pm8xxx-vibrator.c > >>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c > >>>> @@ -25,6 +25,9 @@ struct pm8xxx_regs { > >>>> unsigned int drv_addr; > >>>> unsigned int drv_mask; > >>>> unsigned int drv_shift; > >>>> + unsigned int drv_addr2; > >>>> + unsigned int drv_mask2; > >>>> + unsigned int drv_shift2; > >>>> unsigned int drv_en_manual_mask; > >>>> }; > >>>> > >>>> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { > >>>> .drv_en_manual_mask = 0, > >>>> }; > >>>> > >>>> +static struct pm8xxx_regs pmi632_regs = { > >>>> + .enable_addr = 0x5746, > >>>> + .enable_mask = BIT(7), > >>>> + .drv_addr = 0x5740, > >>>> + .drv_mask = 0xff, > >>>> + .drv_shift = 0, > >>>> + .drv_addr2 = 0x5741, > >>>> + .drv_mask2 = 0x0f, > >>>> + .drv_shift2 = 8, > >>> > >>> I see that you are just expanding what was done for SSBI PMICs and > >>> later expanded to support pm8916. However it might be better to drop > >>> the hardcoded .drv_addr (and drv_addr2) and read address from DT > >>> instead. > >>> > >> > >> Right, this is the simplest change without updating the code logic too > >> much. If we decided to read .drv_addr and .drv_add2 from DT, we will > >> have to read .enable_addr along with all other mask/shift for each > >> register address from DT as well because they are not consistent from > >> target to target. I don't know how would you suggest to add the DT > >> properties for all of them, but if we end up to add a property for each > >> of them, it won't be cleaner than hard-coding them. > > > > No, we (correctly) have device compatibles for that. The issue with > > hardcoding register addresses is that it adds extra issues here. > > > > If I understand correctly, we have several 'generation': > > - SSBI PMIC, shifted 5-bit mask, en_manual_mask, no enable_register. > > - older SPMI PMIC, 5 bit drv_mask, 0 en_manual_mask, enable register at +6 > > - new SPMI PMIC, 12 bit drv_mask, 0 en_manual_mask, enable register at +6 > > > > For the last generation you are adding three independent entries, > > while the block looks the same. If you remove drv_addr (and get it > > from reg property), it would allow us to keep only the functional data > > in struct pm8xxxx_regs (masks / shifts). > > > > Okay, let me know if I understood it correctly, this is what you are > suggesting: > > - hard code the mask/shifts and still keep them in struct pm8xxx_regs, > combine the drv_mask2 to the upper byte of the drv_mask, so we will > have following data structure for the 3rd generation vibrator > > static struct pm8xxx_regs pm7250b_regs = { > .enable_addr = 0x5346, > .enable_mask = BIT(7), > .drv_mask = 0xfff, > .drv_shift = 0, > .drv_en_manual_mask = 0, > }; > > > - move the drv_addr/drv_addr2 into DT, read them from 'reg' property. > Because of 'mfd/qcom,spmi-pmic.yaml' has defined the 'address-cells' > as 1 and the 'size-cells' as 0 for qcom spmi devices, we couldn't > specify the address size to 2 even the drv_addr for the 3rd > generation vibrator is 2 adjacent bytes. So we will end of having > following DT scheme: > > For the 2nd generation which only has drv_addr > vibrator@c041 { > compatible = "qcom,pm8916-vib"; > reg = <0xc041>; /* drv_addr */ No. This is <0xc000>. > ... > }; > > For the 3rd generation which has both drv_addr and drv_addr2 > vibrator@5340 { > compatible = "qcom,pm7250b-vib"; > reg = <0x5340>, /* drv_addr */ > <0x5341>; /* drv_addr2 */ > ... > }; > > Not sure how do you feel, I actually don't see too much benefit than > hard-coding them in the driver. > We will end up having code to check how many u32 value in the 'reg' and > only assign it to drv_addr2 when the 2nd is available, also when > programming drv_addr2 register, the driver will always assume the mask > is in the upper byte of the drv_mask and the shift to the drive level is > 8 (this seems hacky to me and it was my biggest concern while I made > this change, and it led me to defining drv_shift2/drv_mask2 along with > drv_addr2). We only need drv_addr2 if drv_mask has more than 8 bits. So you don't have to specify it in the DT. It is always equal to base_reg + 0x41. The same way drv_addr is always equal to base_reg + 0x40 for all SPMI-based PMIC vibrator devices. > > > > >> > >> > >>>> + .drv_en_manual_mask = 0, > >>>> +}; > >>>> + > >>>> +static struct pm8xxx_regs pm7250b_regs = { > >>>> + .enable_addr = 0x5346, > >>>> + .enable_mask = BIT(7), > >>>> + .drv_addr = 0x5340, > >>>> + .drv_mask = 0xff, > >>>> + .drv_shift = 0, > >>>> + .drv_addr2 = 0x5341, > >>>> + .drv_mask2 = 0x0f, > >>>> + .drv_shift2 = 8, > >>>> + .drv_en_manual_mask = 0, > >>>> +}; > >>>> + > >>>> +static struct pm8xxx_regs pm7325b_regs = { > >>>> + .enable_addr = 0xdf46, > >>>> + .enable_mask = BIT(7), > >>>> + .drv_addr = 0xdf40, > >>>> + .drv_mask = 0xff, > >>>> + .drv_shift = 0, > >>>> + .drv_addr2 = 0xdf41, > >>>> + .drv_mask2 = 0x0f, > >>>> + .drv_shift2 = 8, > >>>> + .drv_en_manual_mask = 0, > >>>> +}; > >>>> + > >>>> /** > >>>> * struct pm8xxx_vib - structure to hold vibrator data > >>>> * @vib_input_dev: input device supporting force feedback > >>>> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) > >>>> return rc; > >>>> > >>>> vib->reg_vib_drv = val; > >>>> + if (regs->drv_addr2 != 0 && on) { > >>>> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; > >>>> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); > >>>> + if (rc < 0) > >>>> + return rc; > >>>> + } > >>>> > >>>> if (regs->enable_mask) > >>>> rc = regmap_update_bits(vib->regmap, regs->enable_addr, > >>>> @@ -242,6 +287,9 @@ 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 }, > >>>> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, > >>>> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, > >>>> { } > >>>> }; > >>>> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); > >>>> -- > >>>> 2.25.1 > >>>> > >>> > >>> > > > > > >
On 7/18/2023 7:04 PM, Dmitry Baryshkov wrote: > On Tue, 18 Jul 2023 at 13:55, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >> >> >> >> On 7/18/2023 5:41 PM, Dmitry Baryshkov wrote: >>> On Tue, 18 Jul 2023 at 09:58, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >>>> >>>> >>>> >>>> On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: >>>>> On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >>>>>> >>>>>> Add support for vibrator module inside PMI632, PM7250B, PM7325B. >>>>>> It is very similar to vibrator inside PM8xxx but just the drive >>>>>> amplitude is controlled through 2 bytes registers. >>>>>> >>>>>> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> >>>>>> --- >>>>>> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ >>>>>> 1 file changed, 48 insertions(+) >>>>>> >>>>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c >>>>>> index 04cb87efd799..213fdfd47c7f 100644 >>>>>> --- a/drivers/input/misc/pm8xxx-vibrator.c >>>>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c >>>>>> @@ -25,6 +25,9 @@ struct pm8xxx_regs { >>>>>> unsigned int drv_addr; >>>>>> unsigned int drv_mask; >>>>>> unsigned int drv_shift; >>>>>> + unsigned int drv_addr2; >>>>>> + unsigned int drv_mask2; >>>>>> + unsigned int drv_shift2; >>>>>> unsigned int drv_en_manual_mask; >>>>>> }; >>>>>> >>>>>> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { >>>>>> .drv_en_manual_mask = 0, >>>>>> }; >>>>>> >>>>>> +static struct pm8xxx_regs pmi632_regs = { >>>>>> + .enable_addr = 0x5746, >>>>>> + .enable_mask = BIT(7), >>>>>> + .drv_addr = 0x5740, >>>>>> + .drv_mask = 0xff, >>>>>> + .drv_shift = 0, >>>>>> + .drv_addr2 = 0x5741, >>>>>> + .drv_mask2 = 0x0f, >>>>>> + .drv_shift2 = 8, >>>>> >>>>> I see that you are just expanding what was done for SSBI PMICs and >>>>> later expanded to support pm8916. However it might be better to drop >>>>> the hardcoded .drv_addr (and drv_addr2) and read address from DT >>>>> instead. >>>>> >>>> >>>> Right, this is the simplest change without updating the code logic too >>>> much. If we decided to read .drv_addr and .drv_add2 from DT, we will >>>> have to read .enable_addr along with all other mask/shift for each >>>> register address from DT as well because they are not consistent from >>>> target to target. I don't know how would you suggest to add the DT >>>> properties for all of them, but if we end up to add a property for each >>>> of them, it won't be cleaner than hard-coding them. >>> >>> No, we (correctly) have device compatibles for that. The issue with >>> hardcoding register addresses is that it adds extra issues here. >>> >>> If I understand correctly, we have several 'generation': >>> - SSBI PMIC, shifted 5-bit mask, en_manual_mask, no enable_register. >>> - older SPMI PMIC, 5 bit drv_mask, 0 en_manual_mask, enable register at +6 >>> - new SPMI PMIC, 12 bit drv_mask, 0 en_manual_mask, enable register at +6 >>> >>> For the last generation you are adding three independent entries, >>> while the block looks the same. If you remove drv_addr (and get it >>> from reg property), it would allow us to keep only the functional data >>> in struct pm8xxxx_regs (masks / shifts). >>> >> >> Okay, let me know if I understood it correctly, this is what you are >> suggesting: >> >> - hard code the mask/shifts and still keep them in struct pm8xxx_regs, >> combine the drv_mask2 to the upper byte of the drv_mask, so we will >> have following data structure for the 3rd generation vibrator >> >> static struct pm8xxx_regs pm7250b_regs = { >> .enable_addr = 0x5346, >> .enable_mask = BIT(7), >> .drv_mask = 0xfff, >> .drv_shift = 0, >> .drv_en_manual_mask = 0, >> }; >> >> >> - move the drv_addr/drv_addr2 into DT, read them from 'reg' property. >> Because of 'mfd/qcom,spmi-pmic.yaml' has defined the 'address-cells' >> as 1 and the 'size-cells' as 0 for qcom spmi devices, we couldn't >> specify the address size to 2 even the drv_addr for the 3rd >> generation vibrator is 2 adjacent bytes. So we will end of having >> following DT scheme: >> >> For the 2nd generation which only has drv_addr >> vibrator@c041 { >> compatible = "qcom,pm8916-vib"; >> reg = <0xc041>; /* drv_addr */ > > No. This is <0xc000>. > >> ... >> }; >> >> For the 3rd generation which has both drv_addr and drv_addr2 >> vibrator@5340 { >> compatible = "qcom,pm7250b-vib"; >> reg = <0x5340>, /* drv_addr */ >> <0x5341>; /* drv_addr2 */ >> ... >> }; >> >> Not sure how do you feel, I actually don't see too much benefit than >> hard-coding them in the driver. >> We will end up having code to check how many u32 value in the 'reg' and >> only assign it to drv_addr2 when the 2nd is available, also when >> programming drv_addr2 register, the driver will always assume the mask >> is in the upper byte of the drv_mask and the shift to the drive level is >> 8 (this seems hacky to me and it was my biggest concern while I made >> this change, and it led me to defining drv_shift2/drv_mask2 along with >> drv_addr2). > > We only need drv_addr2 if drv_mask has more than 8 bits. So you don't > have to specify it in the DT. It is always equal to base_reg + 0x41. > The same way drv_addr is always equal to base_reg + 0x40 for all > SPMI-based PMIC vibrator devices. > Thanks. I got it now, I agree this will be beneficial for the case that different PMICs have the same vibrator module but with different register base address. I am going to change it to this way, let me know if this is what you thought: @@ -25,6 +29,9 @@ struct pm8xxx_regs { unsigned int drv_addr; unsigned int drv_mask; unsigned int drv_shift; + unsigned int drv_addr2; + unsigned int drv_mask2; + unsigned int drv_shift2; unsigned int drv_en_manual_mask; }; +static struct pm8xxx_regs spmi_vib_regs = { + .enable_mask = BIT(7), + .drv_mask = 0xff, + .drv_shift = 0, + .drv_mask2 = 0xf, + .drv_shift2 = 8, + .drv_en_manual_mask = 0, +}; + +#define SPMI_VIB_VSET_LB_REG 0x40 +#define SPMI_VIB_VSET_UP_REG 0x41 +#define SPMI_VIB_EN_CTL_REG 0x46 + regs = of_device_get_match_data(&pdev->dev); + if (regs->drv_addr == 0) { + rc = fwnode_property_read_u32(pdev->dev.fwnode, + "reg", ®_base); + if (rc < 0) + return rc; + + regs->enable_addr = reg_base + SPMI_VIB_EN_CTL_REG; + regs->drv_addr = reg_base + SPMI_VIB_VSET_LB_REG; + regs->drv_addr2 = reg_base + SPMI_VIB_VSET_UP_REG; + } + @@ -242,6 +277,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 }, + ( .compabitle = "qcom,spmi-vib", .data = &spmi_vib_regs }, { } >> >> >> >>>> >>>> >>>>>> + .drv_en_manual_mask = 0, >>>>>> +}; >>>>>> + >>>>>> +static struct pm8xxx_regs pm7250b_regs = { >>>>>> + .enable_addr = 0x5346, >>>>>> + .enable_mask = BIT(7), >>>>>> + .drv_addr = 0x5340, >>>>>> + .drv_mask = 0xff, >>>>>> + .drv_shift = 0, >>>>>> + .drv_addr2 = 0x5341, >>>>>> + .drv_mask2 = 0x0f, >>>>>> + .drv_shift2 = 8, >>>>>> + .drv_en_manual_mask = 0, >>>>>> +}; >>>>>> + >>>>>> +static struct pm8xxx_regs pm7325b_regs = { >>>>>> + .enable_addr = 0xdf46, >>>>>> + .enable_mask = BIT(7), >>>>>> + .drv_addr = 0xdf40, >>>>>> + .drv_mask = 0xff, >>>>>> + .drv_shift = 0, >>>>>> + .drv_addr2 = 0xdf41, >>>>>> + .drv_mask2 = 0x0f, >>>>>> + .drv_shift2 = 8, >>>>>> + .drv_en_manual_mask = 0, >>>>>> +}; >>>>>> + >>>>>> /** >>>>>> * struct pm8xxx_vib - structure to hold vibrator data >>>>>> * @vib_input_dev: input device supporting force feedback >>>>>> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) >>>>>> return rc; >>>>>> >>>>>> vib->reg_vib_drv = val; >>>>>> + if (regs->drv_addr2 != 0 && on) { >>>>>> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; >>>>>> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); >>>>>> + if (rc < 0) >>>>>> + return rc; >>>>>> + } >>>>>> >>>>>> if (regs->enable_mask) >>>>>> rc = regmap_update_bits(vib->regmap, regs->enable_addr, >>>>>> @@ -242,6 +287,9 @@ 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 }, >>>>>> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, >>>>>> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, >>>>>> { } >>>>>> }; >>>>>> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); >>>>>> -- >>>>>> 2.25.1 >>>>>> >>>>> >>>>> >>> >>> >>> > > >
On Wed, 19 Jul 2023 at 07:09, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > > > > On 7/18/2023 7:04 PM, Dmitry Baryshkov wrote: > > On Tue, 18 Jul 2023 at 13:55, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > >> > >> > >> > >> On 7/18/2023 5:41 PM, Dmitry Baryshkov wrote: > >>> On Tue, 18 Jul 2023 at 09:58, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > >>>> > >>>> > >>>> > >>>> On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: > >>>>> On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: > >>>>>> > >>>>>> Add support for vibrator module inside PMI632, PM7250B, PM7325B. > >>>>>> It is very similar to vibrator inside PM8xxx but just the drive > >>>>>> amplitude is controlled through 2 bytes registers. > >>>>>> > >>>>>> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> > >>>>>> --- > >>>>>> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ > >>>>>> 1 file changed, 48 insertions(+) > >>>>>> > >>>>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c > >>>>>> index 04cb87efd799..213fdfd47c7f 100644 > >>>>>> --- a/drivers/input/misc/pm8xxx-vibrator.c > >>>>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c > >>>>>> @@ -25,6 +25,9 @@ struct pm8xxx_regs { > >>>>>> unsigned int drv_addr; > >>>>>> unsigned int drv_mask; > >>>>>> unsigned int drv_shift; > >>>>>> + unsigned int drv_addr2; Unused > >>>>>> + unsigned int drv_mask2; > >>>>>> + unsigned int drv_shift2; > >>>>>> unsigned int drv_en_manual_mask; > >>>>>> }; > >>>>>> > >>>>>> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { > >>>>>> .drv_en_manual_mask = 0, > >>>>>> }; > >>>>>> > >>>>>> +static struct pm8xxx_regs pmi632_regs = { > >>>>>> + .enable_addr = 0x5746, > >>>>>> + .enable_mask = BIT(7), > >>>>>> + .drv_addr = 0x5740, > >>>>>> + .drv_mask = 0xff, > >>>>>> + .drv_shift = 0, > >>>>>> + .drv_addr2 = 0x5741, > >>>>>> + .drv_mask2 = 0x0f, > >>>>>> + .drv_shift2 = 8, > >>>>> > >>>>> I see that you are just expanding what was done for SSBI PMICs and > >>>>> later expanded to support pm8916. However it might be better to drop > >>>>> the hardcoded .drv_addr (and drv_addr2) and read address from DT > >>>>> instead. > >>>>> > >>>> > >>>> Right, this is the simplest change without updating the code logic too > >>>> much. If we decided to read .drv_addr and .drv_add2 from DT, we will > >>>> have to read .enable_addr along with all other mask/shift for each > >>>> register address from DT as well because they are not consistent from > >>>> target to target. I don't know how would you suggest to add the DT > >>>> properties for all of them, but if we end up to add a property for each > >>>> of them, it won't be cleaner than hard-coding them. > >>> > >>> No, we (correctly) have device compatibles for that. The issue with > >>> hardcoding register addresses is that it adds extra issues here. > >>> > >>> If I understand correctly, we have several 'generation': > >>> - SSBI PMIC, shifted 5-bit mask, en_manual_mask, no enable_register. > >>> - older SPMI PMIC, 5 bit drv_mask, 0 en_manual_mask, enable register at +6 > >>> - new SPMI PMIC, 12 bit drv_mask, 0 en_manual_mask, enable register at +6 > >>> > >>> For the last generation you are adding three independent entries, > >>> while the block looks the same. If you remove drv_addr (and get it > >>> from reg property), it would allow us to keep only the functional data > >>> in struct pm8xxxx_regs (masks / shifts). > >>> > >> > >> Okay, let me know if I understood it correctly, this is what you are > >> suggesting: > >> > >> - hard code the mask/shifts and still keep them in struct pm8xxx_regs, > >> combine the drv_mask2 to the upper byte of the drv_mask, so we will > >> have following data structure for the 3rd generation vibrator > >> > >> static struct pm8xxx_regs pm7250b_regs = { > >> .enable_addr = 0x5346, > >> .enable_mask = BIT(7), > >> .drv_mask = 0xfff, > >> .drv_shift = 0, > >> .drv_en_manual_mask = 0, > >> }; > >> > >> > >> - move the drv_addr/drv_addr2 into DT, read them from 'reg' property. > >> Because of 'mfd/qcom,spmi-pmic.yaml' has defined the 'address-cells' > >> as 1 and the 'size-cells' as 0 for qcom spmi devices, we couldn't > >> specify the address size to 2 even the drv_addr for the 3rd > >> generation vibrator is 2 adjacent bytes. So we will end of having > >> following DT scheme: > >> > >> For the 2nd generation which only has drv_addr > >> vibrator@c041 { > >> compatible = "qcom,pm8916-vib"; > >> reg = <0xc041>; /* drv_addr */ > > > > No. This is <0xc000>. > > > >> ... > >> }; > >> > >> For the 3rd generation which has both drv_addr and drv_addr2 > >> vibrator@5340 { > >> compatible = "qcom,pm7250b-vib"; > >> reg = <0x5340>, /* drv_addr */ > >> <0x5341>; /* drv_addr2 */ > >> ... > >> }; > >> > >> Not sure how do you feel, I actually don't see too much benefit than > >> hard-coding them in the driver. > >> We will end up having code to check how many u32 value in the 'reg' and > >> only assign it to drv_addr2 when the 2nd is available, also when > >> programming drv_addr2 register, the driver will always assume the mask > >> is in the upper byte of the drv_mask and the shift to the drive level is > >> 8 (this seems hacky to me and it was my biggest concern while I made > >> this change, and it led me to defining drv_shift2/drv_mask2 along with > >> drv_addr2). > > > > We only need drv_addr2 if drv_mask has more than 8 bits. So you don't > > have to specify it in the DT. It is always equal to base_reg + 0x41. > > The same way drv_addr is always equal to base_reg + 0x40 for all > > SPMI-based PMIC vibrator devices. > > > > Thanks. I got it now, I agree this will be beneficial for the case that > different PMICs have the same vibrator module but with different > register base address. I am going to change it to this way, let me know > if this is what you thought: > > @@ -25,6 +29,9 @@ struct pm8xxx_regs { > unsigned int drv_addr; > unsigned int drv_mask; > unsigned int drv_shift; > + unsigned int drv_addr2; > + unsigned int drv_mask2; > + unsigned int drv_shift2; > unsigned int drv_en_manual_mask; > }; > > +static struct pm8xxx_regs spmi_vib_regs = { > + .enable_mask = BIT(7), > + .drv_mask = 0xff, > + .drv_shift = 0, > + .drv_mask2 = 0xf, > + .drv_shift2 = 8, > + .drv_en_manual_mask = 0, > +}; Ideally the static data should be const. I'd suggest moving drv_addr/drv_addr2 to struct pm8xxx_vib. > + > > +#define SPMI_VIB_VSET_LB_REG 0x40 > +#define SPMI_VIB_VSET_UP_REG 0x41 > +#define SPMI_VIB_EN_CTL_REG 0x46 > + > > regs = of_device_get_match_data(&pdev->dev); > > + if (regs->drv_addr == 0) { > + rc = fwnode_property_read_u32(pdev->dev.fwnode, > + "reg", ®_base); > + if (rc < 0) > + return rc; > + > + regs->enable_addr = reg_base + SPMI_VIB_EN_CTL_REG; > + regs->drv_addr = reg_base + SPMI_VIB_VSET_LB_REG; > + regs->drv_addr2 = reg_base + SPMI_VIB_VSET_UP_REG; Yes, this looks good (except s/regs->/vib->/). Moreover this also applies to pm8916. I'd suggest splitting this into two patches: first, refactor pm8916 support to use reg, then add support for new devices. > + } > + > > > @@ -242,6 +277,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 }, > + ( .compabitle = "qcom,spmi-vib", .data = &spmi_vib_regs }, > { } > > > >> > >> > >> > >>>> > >>>> > >>>>>> + .drv_en_manual_mask = 0, > >>>>>> +}; > >>>>>> + > >>>>>> +static struct pm8xxx_regs pm7250b_regs = { > >>>>>> + .enable_addr = 0x5346, > >>>>>> + .enable_mask = BIT(7), > >>>>>> + .drv_addr = 0x5340, > >>>>>> + .drv_mask = 0xff, > >>>>>> + .drv_shift = 0, > >>>>>> + .drv_addr2 = 0x5341, > >>>>>> + .drv_mask2 = 0x0f, > >>>>>> + .drv_shift2 = 8, > >>>>>> + .drv_en_manual_mask = 0, > >>>>>> +}; > >>>>>> + > >>>>>> +static struct pm8xxx_regs pm7325b_regs = { > >>>>>> + .enable_addr = 0xdf46, > >>>>>> + .enable_mask = BIT(7), > >>>>>> + .drv_addr = 0xdf40, > >>>>>> + .drv_mask = 0xff, > >>>>>> + .drv_shift = 0, > >>>>>> + .drv_addr2 = 0xdf41, > >>>>>> + .drv_mask2 = 0x0f, > >>>>>> + .drv_shift2 = 8, > >>>>>> + .drv_en_manual_mask = 0, > >>>>>> +}; > >>>>>> + > >>>>>> /** > >>>>>> * struct pm8xxx_vib - structure to hold vibrator data > >>>>>> * @vib_input_dev: input device supporting force feedback > >>>>>> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) > >>>>>> return rc; > >>>>>> > >>>>>> vib->reg_vib_drv = val; > >>>>>> + if (regs->drv_addr2 != 0 && on) { > >>>>>> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; > >>>>>> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); > >>>>>> + if (rc < 0) > >>>>>> + return rc; > >>>>>> + } > >>>>>> > >>>>>> if (regs->enable_mask) > >>>>>> rc = regmap_update_bits(vib->regmap, regs->enable_addr, > >>>>>> @@ -242,6 +287,9 @@ 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 }, > >>>>>> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, > >>>>>> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, > >>>>>> { } > >>>>>> }; > >>>>>> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); > >>>>>> -- > >>>>>> 2.25.1 > >>>>>> > >>>>> > >>>>> > >>> > >>> > >>> > > > > > >
On 7/19/2023 4:02 PM, Dmitry Baryshkov wrote: > On Wed, 19 Jul 2023 at 07:09, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >> >> >> >> On 7/18/2023 7:04 PM, Dmitry Baryshkov wrote: >>> On Tue, 18 Jul 2023 at 13:55, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >>>> >>>> >>>> >>>> On 7/18/2023 5:41 PM, Dmitry Baryshkov wrote: >>>>> On Tue, 18 Jul 2023 at 09:58, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >>>>>> >>>>>> >>>>>> >>>>>> On 7/18/2023 2:44 PM, Dmitry Baryshkov wrote: >>>>>>> On Tue, 18 Jul 2023 at 09:27, Fenglin Wu <quic_fenglinw@quicinc.com> wrote: >>>>>>>> >>>>>>>> Add support for vibrator module inside PMI632, PM7250B, PM7325B. >>>>>>>> It is very similar to vibrator inside PM8xxx but just the drive >>>>>>>> amplitude is controlled through 2 bytes registers. >>>>>>>> >>>>>>>> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com> >>>>>>>> --- >>>>>>>> drivers/input/misc/pm8xxx-vibrator.c | 48 ++++++++++++++++++++++++++++ >>>>>>>> 1 file changed, 48 insertions(+) >>>>>>>> >>>>>>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c >>>>>>>> index 04cb87efd799..213fdfd47c7f 100644 >>>>>>>> --- a/drivers/input/misc/pm8xxx-vibrator.c >>>>>>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c >>>>>>>> @@ -25,6 +25,9 @@ struct pm8xxx_regs { >>>>>>>> unsigned int drv_addr; >>>>>>>> unsigned int drv_mask; >>>>>>>> unsigned int drv_shift; >>>>>>>> + unsigned int drv_addr2; > > Unused > >>>>>>>> + unsigned int drv_mask2; >>>>>>>> + unsigned int drv_shift2; >>>>>>>> unsigned int drv_en_manual_mask; >>>>>>>> }; >>>>>>>> >>>>>>>> @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { >>>>>>>> .drv_en_manual_mask = 0, >>>>>>>> }; >>>>>>>> >>>>>>>> +static struct pm8xxx_regs pmi632_regs = { >>>>>>>> + .enable_addr = 0x5746, >>>>>>>> + .enable_mask = BIT(7), >>>>>>>> + .drv_addr = 0x5740, >>>>>>>> + .drv_mask = 0xff, >>>>>>>> + .drv_shift = 0, >>>>>>>> + .drv_addr2 = 0x5741, >>>>>>>> + .drv_mask2 = 0x0f, >>>>>>>> + .drv_shift2 = 8, >>>>>>> >>>>>>> I see that you are just expanding what was done for SSBI PMICs and >>>>>>> later expanded to support pm8916. However it might be better to drop >>>>>>> the hardcoded .drv_addr (and drv_addr2) and read address from DT >>>>>>> instead. >>>>>>> >>>>>> >>>>>> Right, this is the simplest change without updating the code logic too >>>>>> much. If we decided to read .drv_addr and .drv_add2 from DT, we will >>>>>> have to read .enable_addr along with all other mask/shift for each >>>>>> register address from DT as well because they are not consistent from >>>>>> target to target. I don't know how would you suggest to add the DT >>>>>> properties for all of them, but if we end up to add a property for each >>>>>> of them, it won't be cleaner than hard-coding them. >>>>> >>>>> No, we (correctly) have device compatibles for that. The issue with >>>>> hardcoding register addresses is that it adds extra issues here. >>>>> >>>>> If I understand correctly, we have several 'generation': >>>>> - SSBI PMIC, shifted 5-bit mask, en_manual_mask, no enable_register. >>>>> - older SPMI PMIC, 5 bit drv_mask, 0 en_manual_mask, enable register at +6 >>>>> - new SPMI PMIC, 12 bit drv_mask, 0 en_manual_mask, enable register at +6 >>>>> >>>>> For the last generation you are adding three independent entries, >>>>> while the block looks the same. If you remove drv_addr (and get it >>>>> from reg property), it would allow us to keep only the functional data >>>>> in struct pm8xxxx_regs (masks / shifts). >>>>> >>>> >>>> Okay, let me know if I understood it correctly, this is what you are >>>> suggesting: >>>> >>>> - hard code the mask/shifts and still keep them in struct pm8xxx_regs, >>>> combine the drv_mask2 to the upper byte of the drv_mask, so we will >>>> have following data structure for the 3rd generation vibrator >>>> >>>> static struct pm8xxx_regs pm7250b_regs = { >>>> .enable_addr = 0x5346, >>>> .enable_mask = BIT(7), >>>> .drv_mask = 0xfff, >>>> .drv_shift = 0, >>>> .drv_en_manual_mask = 0, >>>> }; >>>> >>>> >>>> - move the drv_addr/drv_addr2 into DT, read them from 'reg' property. >>>> Because of 'mfd/qcom,spmi-pmic.yaml' has defined the 'address-cells' >>>> as 1 and the 'size-cells' as 0 for qcom spmi devices, we couldn't >>>> specify the address size to 2 even the drv_addr for the 3rd >>>> generation vibrator is 2 adjacent bytes. So we will end of having >>>> following DT scheme: >>>> >>>> For the 2nd generation which only has drv_addr >>>> vibrator@c041 { >>>> compatible = "qcom,pm8916-vib"; >>>> reg = <0xc041>; /* drv_addr */ >>> >>> No. This is <0xc000>. >>> >>>> ... >>>> }; >>>> >>>> For the 3rd generation which has both drv_addr and drv_addr2 >>>> vibrator@5340 { >>>> compatible = "qcom,pm7250b-vib"; >>>> reg = <0x5340>, /* drv_addr */ >>>> <0x5341>; /* drv_addr2 */ >>>> ... >>>> }; >>>> >>>> Not sure how do you feel, I actually don't see too much benefit than >>>> hard-coding them in the driver. >>>> We will end up having code to check how many u32 value in the 'reg' and >>>> only assign it to drv_addr2 when the 2nd is available, also when >>>> programming drv_addr2 register, the driver will always assume the mask >>>> is in the upper byte of the drv_mask and the shift to the drive level is >>>> 8 (this seems hacky to me and it was my biggest concern while I made >>>> this change, and it led me to defining drv_shift2/drv_mask2 along with >>>> drv_addr2). >>> >>> We only need drv_addr2 if drv_mask has more than 8 bits. So you don't >>> have to specify it in the DT. It is always equal to base_reg + 0x41. >>> The same way drv_addr is always equal to base_reg + 0x40 for all >>> SPMI-based PMIC vibrator devices. >>> >> >> Thanks. I got it now, I agree this will be beneficial for the case that >> different PMICs have the same vibrator module but with different >> register base address. I am going to change it to this way, let me know >> if this is what you thought: >> >> @@ -25,6 +29,9 @@ struct pm8xxx_regs { >> unsigned int drv_addr; >> unsigned int drv_mask; >> unsigned int drv_shift; >> + unsigned int drv_addr2; >> + unsigned int drv_mask2; >> + unsigned int drv_shift2; >> unsigned int drv_en_manual_mask; >> }; >> >> +static struct pm8xxx_regs spmi_vib_regs = { >> + .enable_mask = BIT(7), >> + .drv_mask = 0xff, >> + .drv_shift = 0, >> + .drv_mask2 = 0xf, >> + .drv_shift2 = 8, >> + .drv_en_manual_mask = 0, >> +}; > > Ideally the static data should be const. I'd suggest moving > drv_addr/drv_addr2 to struct pm8xxx_vib. > >> + >> >> +#define SPMI_VIB_VSET_LB_REG 0x40 >> +#define SPMI_VIB_VSET_UP_REG 0x41 >> +#define SPMI_VIB_EN_CTL_REG 0x46 >> + >> >> regs = of_device_get_match_data(&pdev->dev); >> >> + if (regs->drv_addr == 0) { >> + rc = fwnode_property_read_u32(pdev->dev.fwnode, >> + "reg", ®_base); >> + if (rc < 0) >> + return rc; >> + >> + regs->enable_addr = reg_base + SPMI_VIB_EN_CTL_REG; >> + regs->drv_addr = reg_base + SPMI_VIB_VSET_LB_REG; >> + regs->drv_addr2 = reg_base + SPMI_VIB_VSET_UP_REG; > > Yes, this looks good (except s/regs->/vib->/). Moreover this also > applies to pm8916. I'd suggest splitting this into two patches: first, > refactor pm8916 support to use reg, then add support for new devices. Thanks. I will refactor this, test it, and send it out. The only problem is I don't have a pm8916 device with me, but I guess the change should be straightforward and I will rely on the test result on my PM7550BA device which has the vibrator with the latest generation. > >> + } >> + >> >> >> @@ -242,6 +277,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 }, >> + ( .compabitle = "qcom,spmi-vib", .data = &spmi_vib_regs }, >> { } >> >> >>>> >>>> >>>> >>>>>> >>>>>> >>>>>>>> + .drv_en_manual_mask = 0, >>>>>>>> +}; >>>>>>>> + >>>>>>>> +static struct pm8xxx_regs pm7250b_regs = { >>>>>>>> + .enable_addr = 0x5346, >>>>>>>> + .enable_mask = BIT(7), >>>>>>>> + .drv_addr = 0x5340, >>>>>>>> + .drv_mask = 0xff, >>>>>>>> + .drv_shift = 0, >>>>>>>> + .drv_addr2 = 0x5341, >>>>>>>> + .drv_mask2 = 0x0f, >>>>>>>> + .drv_shift2 = 8, >>>>>>>> + .drv_en_manual_mask = 0, >>>>>>>> +}; >>>>>>>> + >>>>>>>> +static struct pm8xxx_regs pm7325b_regs = { >>>>>>>> + .enable_addr = 0xdf46, >>>>>>>> + .enable_mask = BIT(7), >>>>>>>> + .drv_addr = 0xdf40, >>>>>>>> + .drv_mask = 0xff, >>>>>>>> + .drv_shift = 0, >>>>>>>> + .drv_addr2 = 0xdf41, >>>>>>>> + .drv_mask2 = 0x0f, >>>>>>>> + .drv_shift2 = 8, >>>>>>>> + .drv_en_manual_mask = 0, >>>>>>>> +}; >>>>>>>> + >>>>>>>> /** >>>>>>>> * struct pm8xxx_vib - structure to hold vibrator data >>>>>>>> * @vib_input_dev: input device supporting force feedback >>>>>>>> @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) >>>>>>>> return rc; >>>>>>>> >>>>>>>> vib->reg_vib_drv = val; >>>>>>>> + if (regs->drv_addr2 != 0 && on) { >>>>>>>> + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; >>>>>>>> + rc = regmap_write(vib->regmap, regs->drv_addr2, val); >>>>>>>> + if (rc < 0) >>>>>>>> + return rc; >>>>>>>> + } >>>>>>>> >>>>>>>> if (regs->enable_mask) >>>>>>>> rc = regmap_update_bits(vib->regmap, regs->enable_addr, >>>>>>>> @@ -242,6 +287,9 @@ 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 }, >>>>>>>> + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, >>>>>>>> + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, >>>>>>>> { } >>>>>>>> }; >>>>>>>> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); >>>>>>>> -- >>>>>>>> 2.25.1 >>>>>>>> >>>>>>> >>>>>>> >>>>> >>>>> >>>>> >>> >>> >>> > > >
diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 04cb87efd799..213fdfd47c7f 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -25,6 +25,9 @@ struct pm8xxx_regs { unsigned int drv_addr; unsigned int drv_mask; unsigned int drv_shift; + unsigned int drv_addr2; + unsigned int drv_mask2; + unsigned int drv_shift2; unsigned int drv_en_manual_mask; }; @@ -44,6 +47,42 @@ static struct pm8xxx_regs pm8916_regs = { .drv_en_manual_mask = 0, }; +static struct pm8xxx_regs pmi632_regs = { + .enable_addr = 0x5746, + .enable_mask = BIT(7), + .drv_addr = 0x5740, + .drv_mask = 0xff, + .drv_shift = 0, + .drv_addr2 = 0x5741, + .drv_mask2 = 0x0f, + .drv_shift2 = 8, + .drv_en_manual_mask = 0, +}; + +static struct pm8xxx_regs pm7250b_regs = { + .enable_addr = 0x5346, + .enable_mask = BIT(7), + .drv_addr = 0x5340, + .drv_mask = 0xff, + .drv_shift = 0, + .drv_addr2 = 0x5341, + .drv_mask2 = 0x0f, + .drv_shift2 = 8, + .drv_en_manual_mask = 0, +}; + +static struct pm8xxx_regs pm7325b_regs = { + .enable_addr = 0xdf46, + .enable_mask = BIT(7), + .drv_addr = 0xdf40, + .drv_mask = 0xff, + .drv_shift = 0, + .drv_addr2 = 0xdf41, + .drv_mask2 = 0x0f, + .drv_shift2 = 8, + .drv_en_manual_mask = 0, +}; + /** * struct pm8xxx_vib - structure to hold vibrator data * @vib_input_dev: input device supporting force feedback @@ -87,6 +126,12 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) return rc; vib->reg_vib_drv = val; + if (regs->drv_addr2 != 0 && on) { + val = (vib->level << regs->drv_shift2) & regs->drv_mask2; + rc = regmap_write(vib->regmap, regs->drv_addr2, val); + if (rc < 0) + return rc; + } if (regs->enable_mask) rc = regmap_update_bits(vib->regmap, regs->enable_addr, @@ -242,6 +287,9 @@ 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 }, + { .compatible = "qcom,pm7250b-vib", .data = &pm7250b_regs }, + { .compatible = "qcom,pm7325b-vib", .data = &pm7325b_regs }, { } }; MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table);