Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp430456lqg; Thu, 11 Apr 2024 07:18:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtZuse+zGEhZ1AltvYRvB4TKvXsLoDFHA62+HVTpz4gwN5wLwzxUBM6EHpw2PVH5KB774gb2ju6PywGBG1GyISkPBADhL9cm/ph3o8tg== X-Google-Smtp-Source: AGHT+IFDDhSLgCkC1Y4K0yLw3YC6B2Xk4FaMZL2kSgS20rP6x4DtDN8xDsLx2HKO69itDeix4cnJ X-Received: by 2002:a05:6a20:9f0f:b0:1a9:5b1d:f46d with SMTP id mk15-20020a056a209f0f00b001a95b1df46dmr4561227pzb.23.1712845103147; Thu, 11 Apr 2024 07:18:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712845103; cv=pass; d=google.com; s=arc-20160816; b=z8/FAQz2ce0Uw1ckOw51XEng0bm40Bf8zFk3LAqgHWzIuAgYOCDVe/IgHPht9honRJ oeKdnIlT53loCzh4pAhlq5PUczAoRC1UxrB0QrFvtwD5AJgP3zvU9AYhsW5Iqrnoy0mH C9iNMfNNjHV/m6TLzOmJjHeVW4E9E4ACNP5ZZV9V56WZ5Dh1hCGVc24LLDbc/2FX9Ivo Zw8TXc72zE5SvqbpEcSHfiRCZRfcKQQf0HsZJ+s3VQ8cFm4kifztyHPuRD4Iqex+iAOJ 06VsF068qxXjmVxJNK1NEaz4iDBcxDLCzqrZ66/8wABP3efsbp9RXxlHrh72EZly7VRv Ix+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=PJrPJzI9tZWalVF2HGIgb7pQcW9btb7ItvIvDtE5NqY=; fh=iTzJ2H1wEvTp9arzqKHkEO9GdQjFyUydq3lgST85mjE=; b=X9cMxOnYLuynuO/k3mHKJcApoQaJTAChkJJCR6+WL1f88V1Hi7Y29vAntftKPD2TlP dO9fFFzDzf0lWlF1+/jiP8UFSLeC7/4gd8BRaFSk3pFz05eVcvIVDNki9llb+WGjPK5Y ruQROjYctt54SB0cfubUy804GCFAP9dfs34gAw8RFEClyZipzuj0GYmgtFjjaG/Q6w7d 1bp1Uqe27TSO+8EkAzNF5a9L8hIPzIsLTRGeftilCB9eN+cMbRnhbFWZ95x2xgq75iyV 9CgpB2ayljPeut4C3LLfECcaphn2M/FDY/I0k3I6ArfirhFXfxRoybVPh+3RNp9A5x2M C4Zw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UeP0lrov; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-140570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u64-20020a637943000000b005ceea21d9ccsi1293198pgc.771.2024.04.11.07.18.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 07:18:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UeP0lrov; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-140570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5A9A2B25B60 for ; Thu, 11 Apr 2024 13:51:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E997C14D712; Thu, 11 Apr 2024 13:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="UeP0lrov" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4694214D6E0; Thu, 11 Apr 2024 13:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712843485; cv=none; b=JIiPqhtgb8K2qBKU6GtwFEUb0sPmhTGz/AGyORcKd/0bXsEOfzzFuTzbH633pnZR/HhSi0WxyiAGD0iMZ3fIvplEVXTyrBML+2HKPRj65gnh6gizmckZp8zQLlf2XkfzUoSgWE6RTHMFzoZWCzxlj8pFLARQ8x/YDOE6ffvNguo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712843485; c=relaxed/simple; bh=w3MAx7X4BvLaSfA0z3x3zJFYsikqJJHu1cquCWRQvD0=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=ubmc27AneQMffEbpm9h0EDHAdAVBYGLRfknfgJbGCPQeQd78MeqHnQxiqiUCKRokAyF6GaXbX3HaR0ZeQfn+Y722Wf7ejWd4RllJPy1Rwfx7zdm98R6r3c5Z3YeO8qjEuJ5lLURUrC7qhO/G2AnAS2DyjnZRRe5uDDuHSEL8658= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=UeP0lrov; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 43BCdOeu003345; Thu, 11 Apr 2024 13:51:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=PJrPJzI9tZWalVF2HGIgb7pQcW9btb7ItvIvDtE5NqY=; b=Ue P0lrovih7tNWWmVLd7KvhrKW5uWvjjli+LJa+NCNIFkn5ejy/My6UKhxNnS9Zgl4 vddHyGm9NGAhKCHDjo2NJr6lu07Usmljr8L2mOE75F+zeKLOhzvqZkxHmJnpGWsB oRhSMdPZwzbt4MAF0DiprrRnh9w8jdZAaxXbyJ5LA9EtN7syQQjvd9zXr4Va9ZUr JNtMjC4BK1v3KpPXMGus/MkKXdHrDWOC/OTgAmiB60c3t6D3llLmjWZQajw2g1/8 QDBkmr7Tx7gE87PdHyWzShiWXH61r9deXuRlBmr9WEGu7phNt3afM3FwY483yQQK moJQF3pGTjZIvnLyedfg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xe99jt4n1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Apr 2024 13:51:19 +0000 (GMT) Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 43BDpI0K019351 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Apr 2024 13:51:18 GMT Received: from [10.253.34.126] (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.1544.4; Thu, 11 Apr 2024 06:51:12 -0700 Message-ID: Date: Thu, 11 Apr 2024 21:51:10 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH v9 4/4] input: pm8xxx-vibrator: add new SPMI vibrator support Content-Language: en-US To: Dmitry Baryshkov CC: , Andy Gross , Bjorn Andersson , Konrad Dybcio , "Dmitry Torokhov" , Rob Herring , Krzysztof Kozlowski , , , , References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> <20240411-pm8xxx-vibrator-new-design-v9-4-7bf56cb92b28@quicinc.com> From: Fenglin Wu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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: AadPOHqKIiv8VDR3qAno4-5VC-o6Shqj X-Proofpoint-GUID: AadPOHqKIiv8VDR3qAno4-5VC-o6Shqj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-11_07,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 impostorscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404110100 On 2024/4/11 19:02, Dmitry Baryshkov wrote: > On Thu, 11 Apr 2024 at 11:32, Fenglin Wu via B4 Relay > wrote: >> >> From: Fenglin Wu >> >> Add support for a new SPMI vibrator module which is very similar >> to the vibrator module inside PM8916 but has a finer drive voltage >> step and different output voltage range, its drive level control >> is expanded across 2 registers. The vibrator module can be found >> in following Qualcomm PMICs: PMI632, PM7250B, PM7325B, PM7550BA. >> >> Signed-off-by: Fenglin Wu >> --- >> drivers/input/misc/pm8xxx-vibrator.c | 51 +++++++++++++++++++++++++++++------- >> 1 file changed, 42 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c >> index 2959edca8eb9..35bb6f450fd2 100644 >> --- a/drivers/input/misc/pm8xxx-vibrator.c >> +++ b/drivers/input/misc/pm8xxx-vibrator.c >> @@ -12,10 +12,10 @@ >> #include >> #include >> >> -#define VIB_MAX_LEVEL_mV (3100) >> -#define VIB_MIN_LEVEL_mV (1200) >> -#define VIB_PER_STEP_mV (100) >> -#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV + VIB_PER_STEP_mV) >> +#define VIB_MAX_LEVEL_mV(vib) (vib->drv2_addr ? 3544 : 3100) >> +#define VIB_MIN_LEVEL_mV(vib) (vib->drv2_addr ? 1504 : 1200) >> +#define VIB_PER_STEP_mV(vib) (vib->drv2_addr ? 8 : 100) >> +#define VIB_MAX_LEVELS(vib) (VIB_MAX_LEVEL_mV(vib) - VIB_MIN_LEVEL_mV(vib) + VIB_PER_STEP_mV(vib)) >> >> #define MAX_FF_SPEED 0xff >> >> @@ -26,6 +26,9 @@ struct pm8xxx_regs { >> unsigned int drv_offset; >> unsigned int drv_mask; >> unsigned int drv_shift; >> + unsigned int drv2_offset; >> + unsigned int drv2_mask; >> + unsigned int drv2_shift; >> unsigned int drv_en_manual_mask; >> }; >> >> @@ -45,6 +48,18 @@ static struct pm8xxx_regs pm8916_regs = { >> .drv_en_manual_mask = 0, >> }; >> >> +static struct pm8xxx_regs pmi632_regs = { >> + .enable_offset = 0x46, >> + .enable_mask = BIT(7), >> + .drv_offset = 0x40, >> + .drv_mask = GENMASK(7, 0), >> + .drv_shift = 0, >> + .drv2_offset = 0x41, >> + .drv2_mask = GENMASK(3, 0), >> + .drv2_shift = 8, >> + .drv_en_manual_mask = 0, >> +}; >> + >> /** >> * struct pm8xxx_vib - structure to hold vibrator data >> * @vib_input_dev: input device supporting force feedback >> @@ -53,6 +68,7 @@ static struct pm8xxx_regs pm8916_regs = { >> * @regs: registers' info >> * @enable_addr: vibrator enable register >> * @drv_addr: vibrator drive strength register >> + * @drv2_addr: vibrator drive strength upper byte register >> * @speed: speed of vibration set from userland >> * @active: state of vibrator >> * @level: level of vibration to set in the chip >> @@ -65,6 +81,7 @@ struct pm8xxx_vib { >> const struct pm8xxx_regs *regs; >> unsigned int enable_addr; >> unsigned int drv_addr; >> + unsigned int drv2_addr; >> int speed; >> int level; >> bool active; >> @@ -82,6 +99,10 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) >> unsigned int val = vib->reg_vib_drv; >> const struct pm8xxx_regs *regs = vib->regs; >> >> + /* vibrator without drv2_addr needs be programmed in step increments */ > > How are these two items related? Are you using vib->drv2_addr as a > marker for 'particular generation'? In such a case please use a flag > instead. > > The rest looks good to me. > Are you suggesting to add a flag in pm8xxx_vib as a discriminator for the new generation? I actually tried to avoid that because of this comment: https://lore.kernel.org/linux-arm-msm/ZgXSBiQcBEbwF060@google.com/#t >> + if (!vib->drv2_addr) >> + vib->level /= VIB_PER_STEP_mV(vib); >> + >> if (on) >> val |= (vib->level << regs->drv_shift) & regs->drv_mask; >> else >> @@ -93,6 +114,17 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) >> >> vib->reg_vib_drv = val; >> >> + if (regs->drv2_mask) { >> + if (on) >> + val = (vib->level << regs->drv2_shift) & regs->drv2_mask; >> + else >> + val = 0; >> + >> + rc = regmap_write_bits(vib->regmap, vib->drv2_addr, regs->drv2_mask, val); >> + if (rc < 0) >> + return rc; >> + } >> + >> if (regs->enable_mask) >> rc = regmap_update_bits(vib->regmap, vib->enable_addr, >> regs->enable_mask, on ? regs->enable_mask : 0); >> @@ -115,17 +147,16 @@ static void pm8xxx_work_handler(struct work_struct *work) >> return; >> >> /* >> - * pmic vibrator supports voltage ranges from 1.2 to 3.1V, so >> + * pmic vibrator supports voltage ranges from MIN_LEVEL to MAX_LEVEL, so >> * scale the level to fit into these ranges. >> */ >> if (vib->speed) { >> vib->active = true; >> - vib->level = ((VIB_MAX_LEVELS * vib->speed) / MAX_FF_SPEED) + >> - VIB_MIN_LEVEL_mV; >> - vib->level /= VIB_PER_STEP_mV; >> + vib->level = VIB_MIN_LEVEL_mV(vib); >> + vib->level += mult_frac(VIB_MAX_LEVELS(vib), vib->speed, MAX_FF_SPEED); >> } else { >> vib->active = false; >> - vib->level = VIB_MIN_LEVEL_mV / VIB_PER_STEP_mV; >> + vib->level = VIB_MIN_LEVEL_mV(vib); >> } >> >> pm8xxx_vib_set(vib, vib->active); >> @@ -203,6 +234,7 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) >> >> vib->enable_addr = reg_base + regs->enable_offset; >> vib->drv_addr = reg_base + regs->drv_offset; >> + vib->drv2_addr = reg_base + regs->drv2_offset; >> >> /* operate in manual mode */ >> error = regmap_read(vib->regmap, vib->drv_addr, &val); >> @@ -257,6 +289,7 @@ static const struct of_device_id pm8xxx_vib_id_table[] = { >> { .compatible = "qcom,pm8058-vib", .data = &pm8058_regs }, >> { .compatible = "qcom,pm8921-vib", .data = &pm8058_regs }, >> { .compatible = "qcom,pm8916-vib", .data = &pm8916_regs }, >> + { .compatible = "qcom,pmi632-vib", .data = &pmi632_regs }, >> { } >> }; >> MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table); >> >> -- >> 2.25.1 >> >> > >