From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Fenglin Wu <quic_fenglinw@quicinc.com>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org,
agross@kernel.org, andersson@kernel.org,
dmitry.baryshkov@linaro.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_kamalw@quicinc.com, jestar@qti.qualcomm.com
Subject: Re: [PATCH v3 1/3] input: pm8xxx-vib: refactor to easily support new SPMI vibrator
Date: Tue, 25 Jul 2023 07:52:18 +0200 [thread overview]
Message-ID: <5dd56c31-7ca3-dd39-0623-e4fd18ac6f68@linaro.org> (raw)
In-Reply-To: <20230725054138.129497-2-quic_fenglinw@quicinc.com>
On 25/07/2023 07:41, Fenglin Wu wrote:
> 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 <quic_fenglinw@quicinc.com>
> ---
> 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 <linux/regmap.h>
> #include <linux/slab.h>
>
> +#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] = {
Change from const to non-const is wrong. How do you support multiple
devices? No, this is way too fragile now.
...
>
> /*
> * 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);
Not really related. Split cleanup from new features.
> 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)
> + {
That's not a Linux coding style.
Please run scripts/checkpatch.pl and fix reported warnings. Some
warnings can be ignored, but the code here looks like it needs a fix.
Feel free to get in touch if the warning is not clear.
> + dev_err(dev, "Failed to allocate regmap failed, rc=%d\n", error);
No need to print errors on allocation failures.
> 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;
Best regards,
Krzysztof
next prev parent reply other threads:[~2023-07-25 5:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230725054138.129497-1-quic_fenglinw@quicinc.com>
2023-07-25 5:41 ` [PATCH v3 1/3] input: pm8xxx-vib: refactor to easily support new SPMI vibrator Fenglin Wu
2023-07-25 5:52 ` Krzysztof Kozlowski [this message]
2023-07-25 6:16 ` Fenglin Wu
2023-07-27 7:07 ` Krzysztof Kozlowski
2023-07-27 7:43 ` Fenglin Wu
2023-07-27 9:22 ` Krzysztof Kozlowski
2023-07-27 9:40 ` Fenglin Wu
2023-07-25 10:01 ` kernel test robot
2023-07-27 7:07 ` Krzysztof Kozlowski
2023-07-25 5:41 ` [PATCH v3 2/3] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module Fenglin Wu
2023-07-25 5:53 ` Krzysztof Kozlowski
2023-07-25 6:26 ` Fenglin Wu
2023-07-27 7:09 ` Krzysztof Kozlowski
2023-07-25 5:41 ` [PATCH v3 3/3] input: pm8xxx-vibrator: add new SPMI vibrator support Fenglin Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5dd56c31-7ca3-dd39-0623-e4fd18ac6f68@linaro.org \
--to=krzysztof.kozlowski@linaro.org \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jestar@qti.qualcomm.com \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_collinsd@quicinc.com \
--cc=quic_fenglinw@quicinc.com \
--cc=quic_kamalw@quicinc.com \
--cc=quic_subbaram@quicinc.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).