From patchwork Tue Jul 25 05:41:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu X-Patchwork-Id: 125341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2268084vqg; Mon, 24 Jul 2023 23:18:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlF7Asw3ToKRr94QdWfhGh0WY45rUshzTiVPF37FpWtUgHhJ0yUmEO+aXo9RtvHaESX75URg X-Received: by 2002:ac2:5b83:0:b0:4f8:6dbf:401d with SMTP id o3-20020ac25b83000000b004f86dbf401dmr6330200lfn.57.1690265906084; Mon, 24 Jul 2023 23:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690265906; cv=none; d=google.com; s=arc-20160816; b=ghl6eQtuIVp/OlU50+XREN3Vifdk1UXxSYSyXrd3vRMox78Tm4favSMgVVjzCkuAM1 I/JC/dfGm82Mr3gGtYxorE7zB7vJObl6ipz6ZMbNxd6xrypaQQH7Vsa2Ne+PPs54lLhE OV4reCCedp0VECcbz9Db7m53mQD8mR4NmStJu1iMPyQJGLqvFHYXmPI7ClzOM6CqV3e6 9leWqmoz0n2/5PJXKCNHetx4lNROUB+05f+jsEP0A/pLzx1TrWmX0E19ATFpQcWGbHrm 9ZzHKVsD+LZ9KBOdEbM+OXeGUflvjpMuIofMK/kRuoj1wwILGqSB4XNM8Fp+jFBkMVgp 2Y5g== 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=VEz1l/R/ZiNzMPh3tMakQzdUDXnN/JlP7leK0rj4oaA=; fh=c7hs5bztSMxJasfF/LOoFTn6L6s2klt6cxwM+dZAPpg=; b=FEcCJ7vwL1LTPZRVkvYgRmoK7F7lDYqmJoz9bcU0lc2CsG/H034iatuqlbAb4Sp+cn ucFnesv0ep7WsvfN2xiJGRSoEBalkd6RsJGg9acv5bhq6mr3x5ZnBfTw9PDi03rP6LNe 1PU38b96msaKDSVPile5kzfAB8eohfECRkUNliIMHatmZJqI4Y2rm8bPM7daylQN9RMq TntaA9P9KlRQgWWmCJ7PM7MSwa9mSBbvjWIs3T3xjufcpfBrBf/nZPPGW8mD5EMT1els gIuvX6z3uKYvJCQNf6XoQSyk9xAY1tJmewWKfEKmvGOiFCEbuTPomR10RHvNDxgZDTAm wSEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=c5z6CM6H; 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 o15-20020aa7d3cf000000b005224718790asi553922edr.170.2023.07.24.23.18.01; Mon, 24 Jul 2023 23:18:26 -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=c5z6CM6H; 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 S231410AbjGYFnN (ORCPT + 99 others); Tue, 25 Jul 2023 01:43:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231447AbjGYFmw (ORCPT ); Tue, 25 Jul 2023 01:42:52 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0984E1BFD; Mon, 24 Jul 2023 22:42:43 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36P5L3Lm024702; Tue, 25 Jul 2023 05:42:39 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=VEz1l/R/ZiNzMPh3tMakQzdUDXnN/JlP7leK0rj4oaA=; b=c5z6CM6Hrzl3bG1yNT5IDCrkULG0GrxMow2c0oyKPMrIvmJ5QDwLUmP7KHE1H3Se0KDB 31Sjw07AiL1Y0J+H7m0TlHG227QQd9ppT/0u/EtJJ03wf9nvW+OU4JZA9x8mpjWEG86G gvL8OjoTmq5Msz/FdYgOv2vYmVTBvoGg51Qj5iIM67njZ0N+LE2+wVbwNhbJukSTd2Fh R405paOYDblqMSCtx3ugw18dSS0F450ZRn0A8eono44hPxpyLwVw09ZQjHFVk8Da5HF4 8psSfPx0lPk0+fUrYhFq/dFsp1ilyDC+RezagKa+oQ4sOggUmjLAQSX6Wp3J+qE8dtd3 aw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3s1y6m0yqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 05:42:39 +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 36P5gcYH031033 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 05:42:38 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, 24 Jul 2023 22:42:34 -0700 From: Fenglin Wu To: , , , , , , , Konrad Dybcio , Dmitry Torokhov , CC: , , , , Subject: [PATCH v3 1/3] input: pm8xxx-vib: refactor to easily support new SPMI vibrator Date: Tue, 25 Jul 2023 13:41:36 +0800 Message-ID: <20230725054138.129497-2-quic_fenglinw@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230725054138.129497-1-quic_fenglinw@quicinc.com> References: <20230725054138.129497-1-quic_fenglinw@quicinc.com> MIME-Version: 1.0 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-GUID: vw691Kb55XPsXH-tOKzQHH8CnZodqSYK X-Proofpoint-ORIG-GUID: vw691Kb55XPsXH-tOKzQHH8CnZodqSYK 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-25_02,2023-07-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 mlxlogscore=929 bulkscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307250051 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,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772372262348594555 X-GMAIL-MSGID: 1772372262348594555 Currently, all vibrator control register addresses are hard coded, including the base address and the offset, it's not flexible to support new SPMI vibrator module which is usually included in different PMICs with different base address. Refactor this by introducing the HW type terminology and contain the register offsets/masks/shifts in reg_filed data structures corresponding to each vibrator type, and the base address value defined in 'reg' property will be added for SPMI vibrators. Signed-off-by: Fenglin Wu --- drivers/input/misc/pm8xxx-vibrator.c | 130 ++++++++++++++++----------- 1 file changed, 77 insertions(+), 53 deletions(-) diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 04cb87efd799..77bb0018d4e1 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -12,36 +12,36 @@ #include #include +#define SSBI_VIB_DRV_EN_MANUAL_MASK 0xfc +#define SSBI_VIB_DRV_LEVEL_MASK 0xf8 +#define SSBI_VIB_DRV_SHIFT 3 +#define SPMI_VIB_DRV_LEVEL_MASK 0xff +#define SPMI_VIB_DRV_SHIFT 0 + #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 MAX_FF_SPEED 0xff -struct pm8xxx_regs { - unsigned int enable_addr; - unsigned int enable_mask; +enum pm8xxx_vib_type { + SSBI_VIB, + SPMI_VIB_GEN1, +}; - unsigned int drv_addr; - unsigned int drv_mask; - unsigned int drv_shift; - unsigned int drv_en_manual_mask; +enum { + VIB_DRV_REG, + VIB_EN_REG, + VIB_MAX_REG, }; -static const struct pm8xxx_regs pm8058_regs = { - .drv_addr = 0x4A, - .drv_mask = 0xf8, - .drv_shift = 3, - .drv_en_manual_mask = 0xfc, +static struct reg_field ssbi_vib_regs[VIB_MAX_REG] = { + REG_FIELD(0xf8, 0, 7), }; -static struct pm8xxx_regs pm8916_regs = { - .enable_addr = 0xc046, - .enable_mask = BIT(7), - .drv_addr = 0xc041, - .drv_mask = 0x1F, - .drv_shift = 0, - .drv_en_manual_mask = 0, +static struct reg_field spmi_vib_gen1_regs[VIB_MAX_REG] = { + REG_FIELD(0x41, 0, 4), + REG_FIELD(0x46, 7, 7), }; /** @@ -58,12 +58,12 @@ static struct pm8xxx_regs pm8916_regs = { struct pm8xxx_vib { struct input_dev *vib_input_dev; struct work_struct work; - struct regmap *regmap; - const struct pm8xxx_regs *regs; + struct regmap_field *r_fields[VIB_MAX_REG]; int speed; int level; bool active; u8 reg_vib_drv; + enum pm8xxx_vib_type hw_type; }; /** @@ -75,22 +75,27 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) { int rc; unsigned int val = vib->reg_vib_drv; - const struct pm8xxx_regs *regs = vib->regs; + u32 mask = SPMI_VIB_DRV_LEVEL_MASK; + u32 shift = SPMI_VIB_DRV_SHIFT; + + if (vib->hw_type == SSBI_VIB) { + mask = SSBI_VIB_DRV_LEVEL_MASK; + shift = SSBI_VIB_DRV_SHIFT; + } if (on) - val |= (vib->level << regs->drv_shift) & regs->drv_mask; + val |= (vib->level << shift) & mask; else - val &= ~regs->drv_mask; + val &= ~mask; - rc = regmap_write(vib->regmap, regs->drv_addr, val); + rc = regmap_field_write(vib->r_fields[VIB_DRV_REG], 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); + if (vib->hw_type != SSBI_VIB) + rc = regmap_field_write(vib->r_fields[VIB_EN_REG], on); return rc; } @@ -102,13 +107,6 @@ 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; - - rc = regmap_read(vib->regmap, regs->drv_addr, &val); - if (rc < 0) - return; /* * pmic vibrator supports voltage ranges from 1.2 to 3.1V, so @@ -168,38 +166,65 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) { struct pm8xxx_vib *vib; struct input_dev *input_dev; - int error; + struct device *dev = &pdev->dev; + struct regmap *regmap; + struct reg_field *regs; + int error, i; unsigned int val; - const struct pm8xxx_regs *regs; + u32 reg_base; - vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL); + vib = devm_kzalloc(dev, sizeof(*vib), GFP_KERNEL); if (!vib) return -ENOMEM; - vib->regmap = dev_get_regmap(pdev->dev.parent, NULL); - if (!vib->regmap) + regmap = dev_get_regmap(dev->parent, NULL); + if (!regmap) return -ENODEV; - input_dev = devm_input_allocate_device(&pdev->dev); + input_dev = devm_input_allocate_device(dev); if (!input_dev) return -ENOMEM; INIT_WORK(&vib->work, pm8xxx_work_handler); vib->vib_input_dev = input_dev; - regs = of_device_get_match_data(&pdev->dev); + vib->hw_type = (enum pm8xxx_vib_type)of_device_get_match_data(dev); - /* operate in manual mode */ - error = regmap_read(vib->regmap, regs->drv_addr, &val); + regs = ssbi_vib_regs; + if (vib->hw_type != SSBI_VIB) { + error = fwnode_property_read_u32(dev->fwnode, "reg", ®_base); + if (error < 0) { + dev_err(dev, "Failed to read reg address, rc=%d\n", error); + return error; + } + + if (vib->hw_type == SPMI_VIB_GEN1) + regs = spmi_vib_gen1_regs; + + for (i = 0; i < VIB_MAX_REG; i++) + if (regs[i].reg != 0) + regs[i].reg += reg_base; + } + + error = devm_regmap_field_bulk_alloc(dev, regmap, vib->r_fields, regs, VIB_MAX_REG); if (error < 0) + { + dev_err(dev, "Failed to allocate regmap failed, rc=%d\n", error); return error; + } - val &= regs->drv_en_manual_mask; - error = regmap_write(vib->regmap, regs->drv_addr, val); + error = regmap_field_read(vib->r_fields[VIB_DRV_REG], &val); if (error < 0) return error; - vib->regs = regs; + /* operate in manual mode */ + if (vib->hw_type == SSBI_VIB) { + val &= SSBI_VIB_DRV_EN_MANUAL_MASK; + error = regmap_field_write(vib->r_fields[VIB_DRV_REG], val); + if (error < 0) + return error; + } + vib->reg_vib_drv = val; input_dev->name = "pm8xxx_vib_ffmemless"; @@ -211,14 +236,13 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) error = input_ff_create_memless(input_dev, NULL, pm8xxx_vib_play_effect); if (error) { - dev_err(&pdev->dev, - "couldn't register vibrator as FF device\n"); + dev_err(dev, "couldn't register vibrator as FF device\n"); return error; } error = input_register_device(input_dev); if (error) { - dev_err(&pdev->dev, "couldn't register input device\n"); + dev_err(dev, "couldn't register input device\n"); return error; } @@ -239,9 +263,9 @@ static int pm8xxx_vib_suspend(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(pm8xxx_vib_pm_ops, pm8xxx_vib_suspend, NULL); 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,pm8058-vib", .data = (void *)SSBI_VIB }, + { .compatible = "qcom,pm8921-vib", .data = (void *)SSBI_VIB }, + { .compatible = "qcom,pm8916-vib", .data = (void *)SPMI_VIB_GEN1 }, { } }; MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); From patchwork Tue Jul 25 05:41:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu X-Patchwork-Id: 125333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2256016vqg; Mon, 24 Jul 2023 22:49:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHlB8hzmjIXJLNL2CtC7srQncvRtnrJbJ5fHYi0rrMoXzdZTVOIODfvrAZPHsMohhGW5OTY X-Received: by 2002:a17:907:7606:b0:994:522f:3f4a with SMTP id jx6-20020a170907760600b00994522f3f4amr11338590ejc.29.1690264150848; Mon, 24 Jul 2023 22:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690264150; cv=none; d=google.com; s=arc-20160816; b=StOW9WoHYbj6ygAFqh7mA1Fz6n41yVUas9blVTlafLLeJhe86MMB9tsDwzsHz09Xms bb8E/cppERWszPe1gchKDwmbBS2YvR1gWMkSYmPJs7N9B5cF03wydQbZLw9yF66O7pGs qmuSVEaIfb++ew/Ap7VgIpZNQM+DHbN1yV7ztn3jUDJZvcdxgocQCBpm++6S/8/y5+WF VpLINWnBAgGlrHCHwAfY0glNBoAmifJRY87wZODtXrtfheLszdBSq1UYrjRFXwm9xjxO 5rt1UHrgOHJk2Tkr3jxIx95PN4kCPUC1Kzgn00mzJZFwtPnupYPaavC7HjfqPIQ9g3Cv b2nw== 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=eFtPPFULX0eridZFtz92ch9JF2r4HqnmfLUWQvgwJFk=; fh=u7HwzU+Ta/yYxxHlFeCTp1suC6SGttoe0RPfdwIZBsM=; b=XKfJ6sSn0P6s69aZTK2s9w8DvY652Lszzkp2C0JHT5HSqAGm3Pwp7teBwfgw5IGYz9 4sKwsKBcxUbRPKvDYkjMBKp9nJRZLMatC31K0MnvR0wzFqGGtTTZxvu28Xc00EgNV+Lv sIq55uTaTR1UprSg5ImDHrm8mQrNyXPsRpZ3tVs9YRqlUmBCGq0rmKfJtRC8pRZ8r6pU E9sTiat2hbpLup1KBtmjyhIo3MpRmQiKZ/njWqjtWOXvkm1CFb6mcAzBXeUgQ3ZmXoXG zdSovxVxiAFjIyjnI0RDDe9bKP6iRbUsc3yqxn50UqOc3yHFuxkZEDapwXCB5hXIx3+d mUtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="cONkZ/Wx"; 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 v15-20020a170906564f00b00997b6bca284si7776801ejr.470.2023.07.24.22.48.47; Mon, 24 Jul 2023 22:49:10 -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="cONkZ/Wx"; 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 S231346AbjGYFnY (ORCPT + 99 others); Tue, 25 Jul 2023 01:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbjGYFm5 (ORCPT ); Tue, 25 Jul 2023 01:42:57 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642B01FC9; Mon, 24 Jul 2023 22:42:47 -0700 (PDT) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36P4lXnZ011836; Tue, 25 Jul 2023 05:42:43 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=eFtPPFULX0eridZFtz92ch9JF2r4HqnmfLUWQvgwJFk=; b=cONkZ/Wx/6a2YlRJOVR6OsIPP5KfH5Jwo4abkBHnEWJ3fbdYata/sVQXYj4+7R20aXfd qTgebQCzEthOZDjlV2Xyjmz7zdF1Ym9LLW5wYyvR9gvusiZKOvzd9mFrL9AMraSa7C8d nHX5hQNsfTbBfDfm69tUqbXUCniBF7srd4ze23B2AtCsdK17nfTYy615yvuiR71X+JNa bsHw6s77sNL4cvS4xcGbbTY7VDTfn4TWc59X/cpFyXxpnkj2LhPannLlEqIbBKZfR+Mk BCBteGJkRk1jxFtmNrhEm5p3x35GSJsU45xFWMpMMRA+jNetilHRpKZVgK3b0KZ6WEdP zg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3s1qcyt575-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 05:42:43 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36P5ggv7031251 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 05:42:42 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, 24 Jul 2023 22:42:38 -0700 From: Fenglin Wu To: , , , , , , , Konrad Dybcio , Dmitry Torokhov , , CC: , , , , Subject: [PATCH v3 2/3] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module Date: Tue, 25 Jul 2023 13:41:37 +0800 Message-ID: <20230725054138.129497-3-quic_fenglinw@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230725054138.129497-1-quic_fenglinw@quicinc.com> References: <20230725054138.129497-1-quic_fenglinw@quicinc.com> MIME-Version: 1.0 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: _TCHnzYNmfzfZRx_NvMEXvV7K1HdOP3D X-Proofpoint-GUID: _TCHnzYNmfzfZRx_NvMEXvV7K1HdOP3D 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-25_02,2023-07-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 mlxscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307250051 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,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772370422212003940 X-GMAIL-MSGID: 1772370422212003940 Add compatible string 'qcom,spmi-vib-gen2' for vibrator module inside PMI632, PMI7250B, PM7325B, PM7550BA. Also, add 'qcom,spmi-vib-gen1' string for the SPMI vibrator inside PM8916 to maintain the completeness of the hardware version history for SPMI vibrators. Signed-off-by: Fenglin Wu --- .../bindings/input/qcom,pm8xxx-vib.yaml | 18 ++++++++++++++---- 1 file changed, 14 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..ab778714ad29 100644 --- a/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml +++ b/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml @@ -11,10 +11,20 @@ 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,spmi-vib-gen1 + - qcom,spmi-vib-gen2 + - items: + - enum: + - qcom,pmi632-vib + - qcom,pm7250b-vib + - qcom,pm7325b-vib + - qcom,pm7550b-vib + - const: qcom,spmi-vib-gen2 reg: maxItems: 1 From patchwork Tue Jul 25 05:41:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenglin Wu X-Patchwork-Id: 125334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2256053vqg; Mon, 24 Jul 2023 22:49:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlGoG5JtSQW/wo6Z7EA76rjNRFEZameT9AfFsO6ukOSR3MTURGb46GSAs9DYsaYThyJFtL8z X-Received: by 2002:a05:6402:14c:b0:522:1cec:ca9f with SMTP id s12-20020a056402014c00b005221cecca9fmr7721250edu.19.1690264157559; Mon, 24 Jul 2023 22:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690264157; cv=none; d=google.com; s=arc-20160816; b=P3PLxxDNMzC9myboxSTfpWaRUwLYv3aQyv/Lf+BCQLRlg4qVGCjmbZ3HSl3V0sIM7y ceXcJNXKZ9qgtdrSPep3d6b177DCWenBhAbdypHhWftF8MPnZW6nSfEO3kB30rHdX+YC xkcJOO051sEDkUEK5ktyH4QuCsSBKSzeQYTej8YUiYqjvFVW4QsOj2xXG9IKGqUTeAwU JGwJjIDKZH5Bi+K6tiARkgZegKlOEvrYxArWi+ecRHjU1PKat/CkMyWm7IL94qj2N1PC zG9vN81++WDg/e4ESoRX9TA4YE9/fbcPbqI2fl2CRU1iiRufmO9GV2sTqglz7A/X7SaY hv5A== 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=XF8fJ8Hs4A8dq+beYbJXiUQ6DpD1XTf1Ro/4sa6Hq8k=; fh=c7hs5bztSMxJasfF/LOoFTn6L6s2klt6cxwM+dZAPpg=; b=dd2NiObVK3N1CpZb0f4ejbZ8ItyKL2n+efSjvD0F7C5sdYKAxULmgijFOjwyP6XfOE vCh0BnNuwiWKizicFmoCGsMagFLxGOaJ/jlHVHuOmX5pfw1QgK9dGDngttztOzY4bLkG VNMsGGxp7+5trock5iCNPahmBZl1QFeMCA1LG9/xMtoz2G7XNRVq+36118gbHW434/u7 YUqn1/w8MBcZSORb6+m17/cNnJtEttynv35pWkTOCPoBjq5jVeK1Ycx2sBsY+LWQSO+s wyxuJRmXjfBsGsI1OyUsEV6YVG9ih2tcDz9lONPWCF02WLmFa+QNb0HEYhpkuYV0yKyV tFaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=akfQGrME; 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 u16-20020aa7d890000000b0052229b7a961si3052541edq.476.2023.07.24.22.48.54; Mon, 24 Jul 2023 22:49:17 -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=akfQGrME; 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 S231635AbjGYFn2 (ORCPT + 99 others); Tue, 25 Jul 2023 01:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231916AbjGYFnB (ORCPT ); Tue, 25 Jul 2023 01:43:01 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2298B1FE5; Mon, 24 Jul 2023 22:42:51 -0700 (PDT) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36P2fmfx011210; Tue, 25 Jul 2023 05:42:47 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=XF8fJ8Hs4A8dq+beYbJXiUQ6DpD1XTf1Ro/4sa6Hq8k=; b=akfQGrMEJygvVAs+8YgPfQDMjCENKJ+3IXeWS55u9wwTwUZXbChCXBekjcim6DJZCBuI Qj3B2DpQCQdDPhVEOvPXOW70EWd/Z/AefWv75pER0PF6EknLTQeK4B0zeSxSBkImCH9O PqPgqKik9+t0HMGysvpiBeQVgAo0hHbzuktcSFn0cm5SN5coCMFwcU1vLoVy1dPdu4zg zumrVVSi4GbaRMz97UViLC7rf53NhUmqPXkwI38Gtt9RYel7zHDJFBROSgcCffM8toSn V3Bspp9yQrd2WGlaiH6dSb/YZAf62UtnntQKyBcOOSVfXE9AGwMAbBrIa8LsX5ja7jQ0 Vw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3s1qcyt579-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 05:42:47 +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 36P5gkQI031096 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 05:42:46 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, 24 Jul 2023 22:42:42 -0700 From: Fenglin Wu To: , , , , , , , Konrad Dybcio , Dmitry Torokhov , CC: , , , , Subject: [PATCH v3 3/3] input: pm8xxx-vibrator: add new SPMI vibrator support Date: Tue, 25 Jul 2023 13:41:38 +0800 Message-ID: <20230725054138.129497-4-quic_fenglinw@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230725054138.129497-1-quic_fenglinw@quicinc.com> References: <20230725054138.129497-1-quic_fenglinw@quicinc.com> MIME-Version: 1.0 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: 6nLixslO8TXaOp0HLlaGbPrIv-p7Vavh X-Proofpoint-GUID: 6nLixslO8TXaOp0HLlaGbPrIv-p7Vavh 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-25_02,2023-07-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 mlxscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307250051 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,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772370429105878824 X-GMAIL-MSGID: 1772370429105878824 Add new SPMI vibrator module which is very similar to the SPMI vibrator module inside PM8916 but just has a finer drive voltage step (1mV vs 100mV) hence its drive level control is expanded to across 2 registers. Name the module as 'qcom,spmi-vib-gen2', and it can be found in following Qualcomm PMICs: PMI632, PM7250B, PM7325B, PM7550BA. Also, add a compatible string 'qcom,spmi-vib-gen1' for SPMI vibrator inside PM8916 to maintain the completeness of the hardware version history. Signed-off-by: Fenglin Wu --- drivers/input/misc/pm8xxx-vibrator.c | 37 ++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 77bb0018d4e1..2cbccc5c6cf3 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -17,6 +17,8 @@ #define SSBI_VIB_DRV_SHIFT 3 #define SPMI_VIB_DRV_LEVEL_MASK 0xff #define SPMI_VIB_DRV_SHIFT 0 +#define SPMI_VIB_DRV2_LEVEL_MASK 0x0f +#define SPMI_VIB_DRV2_SHIFT 8 #define VIB_MAX_LEVEL_mV (3100) #define VIB_MIN_LEVEL_mV (1200) @@ -27,11 +29,13 @@ enum pm8xxx_vib_type { SSBI_VIB, SPMI_VIB_GEN1, + SPMI_VIB_GEN2, }; enum { VIB_DRV_REG, VIB_EN_REG, + VIB_DRV2_REG, VIB_MAX_REG, }; @@ -44,6 +48,12 @@ static struct reg_field spmi_vib_gen1_regs[VIB_MAX_REG] = { REG_FIELD(0x46, 7, 7), }; +static struct reg_field spmi_vib_gen2_regs[VIB_MAX_REG] = { + REG_FIELD(0x40, 0, 7), + REG_FIELD(0x46, 7, 7), + REG_FIELD(0x41, 0, 3), +}; + /** * struct pm8xxx_vib - structure to hold vibrator data * @vib_input_dev: input device supporting force feedback @@ -94,6 +104,22 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) vib->reg_vib_drv = val; + if (vib->hw_type == SPMI_VIB_GEN2) { + mask = SPMI_VIB_DRV2_LEVEL_MASK; + shift = SPMI_VIB_DRV2_SHIFT; + + if (on) + val = (vib->level >> shift) & mask; + else + val = 0; + + rc = regmap_field_write(vib->r_fields[VIB_DRV2_REG], val); + if (rc < 0) + return rc; + + vib->reg_vib_drv |= val << shift; + } + if (vib->hw_type != SSBI_VIB) rc = regmap_field_write(vib->r_fields[VIB_EN_REG], on); @@ -116,10 +142,13 @@ 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; + if (vib->hw_type != SPMI_VIB_GEN2) + vib->level /= 100; } else { vib->active = false; - vib->level = VIB_MIN_LEVEL_mV / 100; + vib->level = VIB_MIN_LEVEL_mV; + if (vib->hw_type != SPMI_VIB_GEN2) + vib->level /= 100; } pm8xxx_vib_set(vib, vib->active); @@ -200,6 +229,8 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) if (vib->hw_type == SPMI_VIB_GEN1) regs = spmi_vib_gen1_regs; + else + regs = spmi_vib_gen2_regs; for (i = 0; i < VIB_MAX_REG; i++) if (regs[i].reg != 0) @@ -266,6 +297,8 @@ static const struct of_device_id pm8xxx_vib_id_table[] = { { .compatible = "qcom,pm8058-vib", .data = (void *)SSBI_VIB }, { .compatible = "qcom,pm8921-vib", .data = (void *)SSBI_VIB }, { .compatible = "qcom,pm8916-vib", .data = (void *)SPMI_VIB_GEN1 }, + { .compatible = "qcom,spmi-vib-gen1", .data = (void *)SPMI_VIB_GEN1 }, + { .compatible = "qcom,spmi-vib-gen2", .data = (void *)SPMI_VIB_GEN2 }, { } }; MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table);