Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp314244lqg; Thu, 11 Apr 2024 04:02:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0VZ66D2r0ZWAJRWSEJTeVtisuYY1AOBnxPz/xRJfDFS4mhBiUhvAzD+27pCU1NanZyIuA/b9Vfk0S6AHk6e8TyS0DOQrZu8shUXQnag== X-Google-Smtp-Source: AGHT+IGK3z4BRqd70HfytHqNkC+bY7KNdxt6H7pmCjvcpNkyz+rwm5ggztMFYeRAHGTHb+TPiQ7C X-Received: by 2002:a17:90a:d484:b0:2a2:fec9:1bbd with SMTP id s4-20020a17090ad48400b002a2fec91bbdmr3051186pju.17.1712833370372; Thu, 11 Apr 2024 04:02:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712833370; cv=pass; d=google.com; s=arc-20160816; b=rdam1Vs7R0n8xctP8vsjli4K4VTsd5hieGD3gODLpNvY668UP0EnDfSoOR0n46GYLm ltZlaUMpdCulKwb/3ZAptMMr3M7a+P7a9UDxtJPZ2Kia0UJ4K+ATdefUnICPN5CnOoOW i2+pX9jin5lGxEzHbcjtwcZMaNPzOtJz7Ol/yCoe/Y4owMZDMfA6sjrkxHAEO9XJS79G 2UJ7WGXyimsOr5eGwZ3l3ARn2UgSpgc91nYwh0lNT+oUA453XVe5ao6agah+VAcrTlgA 7SOwBOuPsRbjEOLtWErQOcT7LpeYxzt+4BmIEvZC3P48nG/Vx3TxJ3mYlT5Zj54RGs+Q 0M+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=2mHoLWByMG5hFDATGezwiAdEXftWUdi3XEvIaRp+Grs=; fh=G5qaT/HkG3BU5RT0ymuXGDoc3YASLCcnrYy8Ckd7GUs=; b=DDGuNkLufWhnzGscXw88bFjdHcr/SKow5fNC8wk09AQ2yHChrjij/PnNdqQL0LSrLU clrwDFlQVuacmaKkK3n3zVHRxmuW+apbCz52rXK+XGXZBI1ToPV+0ErNG3H3om+FFGJ/ fNnjNkj1N4wNVMQSQCw6jrKDDbgTlVFmXE8xhtWdlH2ndAzsPxsw+aATRE7yB0GhBu7I Frv/QAwc0bHZEZbK9RwU3WRtCiqfSQS9zo0ofTLSObCSyDMXguzMGC5lhFUaQzcmffWO GMk2rVVpkuQjk8c6SQtC6yOYS3WEQXF4tNaVJb5DvTCMAjZKoIR2AlXFUc1PPBVvkXqz OnbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J+ieevYi; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-140302-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140302-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gd1-20020a17090b0fc100b002a50f66351bsi3223859pjb.91.2024.04.11.04.02.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140302-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J+ieevYi; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-140302-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140302-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 078082830BA for ; Thu, 11 Apr 2024 11:02:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE2CF1474CD; Thu, 11 Apr 2024 11:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="J+ieevYi" Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 093641474BB for ; Thu, 11 Apr 2024 11:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712833361; cv=none; b=uI4UCODG64h/VAubVLE7R5SlE+XQBpNRP+gvTiYrGEOr7xVsA7DvFXOB2+B2zbCxLlZtnyRXxDjd/n6T3HCWrCujefOCKJ74TNeLDgm5aZEhJmdT7iylLxHQDtWIABfyBk9ffqXawsWlWUmGYZCUiz9jBmAXW4pc4HCN0hw/vu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712833361; c=relaxed/simple; bh=koAJ18xijCKpgh9Hxgs6EZ/agSJ7rjMVowQIHOKcihM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=t+X8oSpUJ5PqRjMI7crIfZGXIHKhpubOr0T8tCl5+acrVDXTY/xEa1NEmT4BaFvPTpdStLeJrm3KiBNSEtU7a3oTYteF0b5mcFyn0yRr2N+EgJ6166BrgTKiS7ZoACr8rDm/rWhS4oIbSWZeym9Z1YInoQVsk4jItLGRAd1KbmM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=J+ieevYi; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-61149e50602so5218397b3.0 for ; Thu, 11 Apr 2024 04:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712833359; x=1713438159; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2mHoLWByMG5hFDATGezwiAdEXftWUdi3XEvIaRp+Grs=; b=J+ieevYidQPN/OMZMFD+/oVAUd2FRm41CrCahvabNUOqk60ERdCEUAQX5nsi7W/ppt oxGhTQXMzvrBngTR5Age3zAectO1RQy2dE4XwMO6rcbRuppugtqHW0VOUntjrcDpS5bD byHS2hI8ymnMhOvmC/GEsQ1EfQnRaB8nqBuOghA5o3BBzCu6NdswwKQFhO9YYoTDYZBd xQxnEm7yRd1Qx9HWRS1yuzH2s38bcrMNTZ5HwEApJATkO08ODmSVgXYod11SdSSRwfs1 w5+Z5RspcvDYqXC07wzbvn65n+ylmRRZGduJT278EQ/qhsFvmOC0zdmO8pJ+H/8tw4PP rM9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712833359; x=1713438159; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2mHoLWByMG5hFDATGezwiAdEXftWUdi3XEvIaRp+Grs=; b=dWfHcC6x8KIRsDa4OJh1Yvv85zcZckQRo5K22UgkBMM+yQSs1T6EKHb3QetPFFytxE iaczoZ4aU7NrY4qLiQjsLzFF0WEBJJ84KOGHTpy4kIIIcXDBNVG9FtptpZ6UXLqagOrS G2YePyP92kmOmBXamgBA8qknd9GdnBSL1taF9yxYDMUNgwDMkxV4adhiOTFU30fPl70E XkvV/W4UJ28JZa0GwQqlVU1hl0hqwgGr+Me+X4PSK2U3CxvfeKWtEZEeglcA2VcV6Zb4 AplsmqidHoTtOc3+VIdHgHPYzCT9WcMfuM/QAtIGSpYcC+ChMOFO03trRxzlHDvihaTt cFdg== X-Forwarded-Encrypted: i=1; AJvYcCWGjCgHsSgkHeV4G0J95SI3X9Pzm8kr1X5y0Qc2AE2r5xW8qCAOvXq3XOL7IJi1YkzIMFnWpiIM6ouq16pMwPQJHPr2dMymCSejVLSP X-Gm-Message-State: AOJu0Yzcd54IMTiYeLpLZWZLBcRZDIzy+/QRMr95zshduZ2EZM2cQuvM FQDCg4mzEt59eidHeL9TfcvNMQOAjYnl+zUY2zf0DNOoZ74ZnIfHqSpjnJ2yOb45PnV5B3TtETN 0fOEEKvCaF9XBb9CI20tDcRVI3Kx67qGET7D4Ig== X-Received: by 2002:a05:690c:6a0e:b0:618:1eff:24e4 with SMTP id ih14-20020a05690c6a0e00b006181eff24e4mr1775777ywb.15.1712833358989; Thu, 11 Apr 2024 04:02:38 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> <20240411-pm8xxx-vibrator-new-design-v9-4-7bf56cb92b28@quicinc.com> In-Reply-To: <20240411-pm8xxx-vibrator-new-design-v9-4-7bf56cb92b28@quicinc.com> From: Dmitry Baryshkov Date: Thu, 11 Apr 2024 14:02:28 +0300 Message-ID: Subject: Re: [PATCH v9 4/4] input: pm8xxx-vibrator: add new SPMI vibrator support To: quic_fenglinw@quicinc.com Cc: kernel@quicinc.com, Andy Gross , Bjorn Andersson , Konrad Dybcio , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , linux-arm-msm@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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. > + 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 > > -- With best wishes Dmitry