From: Fenglin Wu <quic_fenglinw@quicinc.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: <kernel@quicinc.com>, Andy Gross <agross@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
<linux-arm-msm@vger.kernel.org>, <linux-input@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH v9 2/4] input: pm8xxx-vibrator: refactor to support new SPMI vibrator
Date: Fri, 12 Apr 2024 11:40:53 +0800 [thread overview]
Message-ID: <00b8cea6-fed2-4224-8aeb-c731dc1b666f@quicinc.com> (raw)
In-Reply-To: <CAA8EJpqa=5yaTRHuEiYynTDFy53YPFk4R3q_EV8rmsBN1iR5fA@mail.gmail.com>
On 4/11/2024 10:05 PM, Dmitry Baryshkov wrote:
> On Thu, 11 Apr 2024 at 16:45, Fenglin Wu <quic_fenglinw@quicinc.com> wrote:
>>
>>
>>
>> On 2024/4/11 18:58, Dmitry Baryshkov wrote:
>>> On Thu, 11 Apr 2024 at 11:32, Fenglin Wu via B4 Relay
>>> <devnull+quic_fenglinw.quicinc.com@kernel.org> wrote:
>>>>
>>>> From: Fenglin Wu <quic_fenglinw@quicinc.com>
>>>>
>>>> Currently, vibrator control register addresses are hard coded,
>>>> including the base address and offsets, it's not flexible to
>>>> support new SPMI vibrator module which is usually included in
>>>> different PMICs with different base address. Refactor it by using
>>>> the base address defined in devicetree.
>>>>
>>>> Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
>>>> ---
>>>> drivers/input/misc/pm8xxx-vibrator.c | 42 ++++++++++++++++++++++++------------
>>>> 1 file changed, 28 insertions(+), 14 deletions(-)
>>>>
>>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
>>>> index 89f0f1c810d8..2959edca8eb9 100644
>>>> --- a/drivers/input/misc/pm8xxx-vibrator.c
>>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c
>>>> @@ -20,26 +20,26 @@
>>>> #define MAX_FF_SPEED 0xff
>>>>
>>>> struct pm8xxx_regs {
>>>> - unsigned int enable_addr;
>>>> + unsigned int enable_offset;
>>>> unsigned int enable_mask;
>>>>
>>>> - unsigned int drv_addr;
>>>> + unsigned int drv_offset;
>>>> unsigned int drv_mask;
>>>> unsigned int drv_shift;
>>>> unsigned int drv_en_manual_mask;
>>>> };
>>>>
>>>> static const struct pm8xxx_regs pm8058_regs = {
>>>> - .drv_addr = 0x4A,
>>>> + .drv_offset = 0x4A,
>>>
>>> If the DT already has reg = <0x4a> and you add drv_offset = 0x4a,
>>> which register will be used by the driver?
>>>
>>> Also, while we are at it, please downcase all the hex numbers that you
>>> are touching.
>>>
>> For SSBI vibrator, the "reg" value defined in DT is not used, see below.
>>
>>
>>>> .drv_mask = 0xf8,
>>>> .drv_shift = 3,
>>>> .drv_en_manual_mask = 0xfc,
>>>> };
>>>>
>>>> static struct pm8xxx_regs pm8916_regs = {
>>>> - .enable_addr = 0xc046,
>>>> + .enable_offset = 0x46,
>>
>> [...]
>>
>>>> @@ -170,7 +173,7 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
>>>> struct pm8xxx_vib *vib;
>>>> struct input_dev *input_dev;
>>>> int error;
>>>> - unsigned int val;
>>>> + unsigned int val, reg_base = 0;
>>>> const struct pm8xxx_regs *regs;
>>>>
>>>> vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL);
>>>> @@ -190,13 +193,24 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
>>>>
>>>> regs = of_device_get_match_data(&pdev->dev);
>>>>
>>>> + if (regs->enable_offset != 0) {
>>>> + error = fwnode_property_read_u32(pdev->dev.fwnode, "reg", ®_base);
>>>> + if (error < 0) {
>>>> + dev_err(&pdev->dev, "Failed to read reg address, rc=%d\n", error);
>>>> + return error;
>>>> + }
>>>> + }
>>>> +
>>>> + vib->enable_addr = reg_base + regs->enable_offset;
>>>> + vib->drv_addr = reg_base + regs->drv_offset;
>>
>> The reg_base is initialized as 0 and it is assigned as the "reg" value
>> defined in DT only for SPMI vibrators.
>
> Please don't. This is counterintuitive. We have reg in DT. We should
> be using it.
>
Hmm, the original driver doesn't use the reg value defined in DT at all,
Anyway, I can make the SSBI offset to 0, so the base address defined in
the DT will be always added regardless of SSBI or SPMI vibrator. Let me
know.
Thanks
>>
>>>> +
>>>> /* operate in manual mode */
>>>> - error = regmap_read(vib->regmap, regs->drv_addr, &val);
>>>> + error = regmap_read(vib->regmap, vib->drv_addr, &val);
>>>> if (error < 0)
>>>> return error;
>>>>
>>>> val &= regs->drv_en_manual_mask;
>>>> - error = regmap_write(vib->regmap, regs->drv_addr, val);
>>>> + error = regmap_write(vib->regmap, vib->drv_addr, val);
>>>> if (error < 0)
>>>> return error;
>>>>
>>>>
>>>> --
>>>> 2.25.1
>>>>
>>>>
>>>
>>>
>
>
>
next prev parent reply other threads:[~2024-04-12 3:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 8:30 [PATCH v9 0/4] Add support for vibrator in multiple PMICs Fenglin Wu via B4 Relay
2024-04-11 8:30 ` [PATCH v9 1/4] input: pm8xxx-vibrator: correct VIB_MAX_LEVELS calculation Fenglin Wu via B4 Relay
2024-04-11 10:56 ` Dmitry Baryshkov
2024-04-11 8:30 ` [PATCH v9 2/4] input: pm8xxx-vibrator: refactor to support new SPMI vibrator Fenglin Wu via B4 Relay
2024-04-11 10:58 ` Dmitry Baryshkov
2024-04-11 13:43 ` Fenglin Wu
2024-04-11 14:05 ` Dmitry Baryshkov
2024-04-12 3:40 ` Fenglin Wu [this message]
2024-04-12 11:36 ` Dmitry Baryshkov
2024-04-11 8:30 ` [PATCH v9 3/4] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module Fenglin Wu via B4 Relay
2024-04-11 8:31 ` [PATCH v9 4/4] input: pm8xxx-vibrator: add new SPMI vibrator support Fenglin Wu via B4 Relay
2024-04-11 11:02 ` Dmitry Baryshkov
2024-04-11 13:51 ` Fenglin Wu
2024-04-11 14:21 ` Dmitry Baryshkov
2024-04-12 4:04 ` Fenglin Wu
2024-04-12 11:35 ` Dmitry Baryshkov
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=00b8cea6-fed2-4224-8aeb-c731dc1b666f@quicinc.com \
--to=quic_fenglinw@quicinc.com \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kernel@quicinc.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=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