2023-07-31 06:10:29

by Fenglin Wu

[permalink] [raw]
Subject: [PATCH v4 0/3] Add support for vibrator in multiple PMICs

Add SW support for the vibrator module inside PMI632, PM7250B, PM7325B, PM7550BA.
It is very similar to the vibrator module inside PM8916 which is supported in
pm8xxx-vib driver but just the drive amplitude is controlled with 2 registers,
and the register base offset in each PMIC is different.

Changes in v4:
1. Update to use the combination of the HW type and register offset
as the constant match data, the register base address defined in
'reg' property will be added when accessing SPMI registers using
regmap APIs.
2. Remove 'qcom,spmi-vib-gen1' generic compatible string.

Changes in v3:
1. Refactor the driver to support different type of the vibrators with
better flexibility by introducing the HW type with corresponding
register fields definitions.
2. Add 'qcom,spmi-vib-gen1' and 'qcom,spmi-vib-gen2' compatible
strings, and add PMI632, PM7250B, PM7325B, PM7550BA as compatbile as
spmi-vib-gen2.

Changes in v2:
Remove the "pm7550ba-vib" compatible string as it's compatible with pm7325b.

Fenglin Wu (3):
input: pm8xxx-vib: refactor to easily support new SPMI vibrator
dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module
input: pm8xxx-vibrator: add new SPMI vibrator support

.../bindings/input/qcom,pm8xxx-vib.yaml | 16 +-
drivers/input/misc/pm8xxx-vibrator.c | 171 ++++++++++++------
2 files changed, 132 insertions(+), 55 deletions(-)

--
2.25.1



2023-07-31 06:43:36

by Fenglin Wu

[permalink] [raw]
Subject: [PATCH v4 2/3] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module

Add compatible string 'qcom,spmi-vib-gen2' to support vibrator module
inside PMI632, PMI7250B, PM7325B, PM7550BA.

Signed-off-by: Fenglin Wu <[email protected]>
---
.../bindings/input/qcom,pm8xxx-vib.yaml | 16 ++++++++++++----
1 file changed, 12 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..4a2319fc1e3f 100644
--- a/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml
+++ b/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml
@@ -11,10 +11,18 @@ maintainers:

properties:
compatible:
- enum:
- - qcom,pm8058-vib
- - qcom,pm8916-vib
- - qcom,pm8921-vib
+ oneOf:
+ - enum:
+ - qcom,pm8058-vib
+ - qcom,pm8916-vib
+ - qcom,pm8921-vib
+ - items:
+ - enum:
+ - qcom,pmi632-vib
+ - qcom,pm7250b-vib
+ - qcom,pm7325b-vib
+ - qcom,pm7550b-vib
+ - const: qcom,spmi-vib-gen2

reg:
maxItems: 1
--
2.25.1


2023-07-31 08:19:19

by Fenglin Wu

[permalink] [raw]
Subject: [PATCH v4 3/3] input: pm8xxx-vibrator: add new SPMI vibrator support

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.

Signed-off-by: Fenglin Wu <[email protected]>
---
drivers/input/misc/pm8xxx-vibrator.c | 55 +++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 5 deletions(-)

diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
index d6b468324c77..9cfd3dec5366 100644
--- a/drivers/input/misc/pm8xxx-vibrator.c
+++ b/drivers/input/misc/pm8xxx-vibrator.c
@@ -21,6 +21,13 @@
#define SPMI_VIB_DRV_LEVEL_MASK GENMASK(4, 0)
#define SPMI_VIB_DRV_SHIFT 0

+#define SPMI_VIB_GEN2_DRV_REG 0x40
+#define SPMI_VIB_GEN2_DRV_MASK GENMASK(7, 0)
+#define SPMI_VIB_GEN2_DRV_SHIFT 0
+#define SPMI_VIB_GEN2_DRV2_REG 0x41
+#define SPMI_VIB_GEN2_DRV2_MASK GENMASK(3, 0)
+#define SPMI_VIB_GEN2_DRV2_SHIFT 8
+
#define SPMI_VIB_EN_REG 0x46
#define SPMI_VIB_EN_BIT BIT(7)

@@ -33,12 +40,14 @@
enum vib_hw_type {
SSBI_VIB,
SPMI_VIB,
+ SPMI_VIB_GEN2
};

struct pm8xxx_vib_data {
enum vib_hw_type hw_type;
unsigned int enable_addr;
unsigned int drv_addr;
+ unsigned int drv2_addr;
};

static const struct pm8xxx_vib_data ssbi_vib_data = {
@@ -52,6 +61,13 @@ static const struct pm8xxx_vib_data spmi_vib_data = {
.drv_addr = SPMI_VIB_DRV_REG,
};

+static const struct pm8xxx_vib_data spmi_vib_gen2_data = {
+ .hw_type = SPMI_VIB_GEN2,
+ .enable_addr = SPMI_VIB_EN_REG,
+ .drv_addr = SPMI_VIB_GEN2_DRV_REG,
+ .drv2_addr = SPMI_VIB_GEN2_DRV2_REG,
+};
+
/**
* struct pm8xxx_vib - structure to hold vibrator data
* @vib_input_dev: input device supporting force feedback
@@ -85,12 +101,24 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on)
{
int rc;
unsigned int val = vib->reg_vib_drv;
- u32 mask = SPMI_VIB_DRV_LEVEL_MASK;
- u32 shift = SPMI_VIB_DRV_SHIFT;
+ u32 mask, shift;

- if (vib->data->hw_type == SSBI_VIB) {
+
+ switch (vib->data->hw_type) {
+ case SSBI_VIB:
mask = SSBI_VIB_DRV_LEVEL_MASK;
shift = SSBI_VIB_DRV_SHIFT;
+ break;
+ case SPMI_VIB:
+ mask = SPMI_VIB_DRV_LEVEL_MASK;
+ shift = SPMI_VIB_DRV_SHIFT;
+ break;
+ case SPMI_VIB_GEN2:
+ mask = SPMI_VIB_GEN2_DRV_MASK;
+ shift = SPMI_VIB_GEN2_DRV_SHIFT;
+ break;
+ default:
+ return -EINVAL;
}

if (on)
@@ -104,6 +132,19 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on)

vib->reg_vib_drv = val;

+ if (vib->data->hw_type == SPMI_VIB_GEN2) {
+ mask = SPMI_VIB_GEN2_DRV2_MASK;
+ shift = SPMI_VIB_GEN2_DRV2_SHIFT;
+ if (on)
+ val = (vib->level >> shift) & mask;
+ else
+ val = 0;
+ rc = regmap_update_bits(vib->regmap,
+ vib->reg_base + vib->data->drv2_addr, mask, val);
+ if (rc < 0)
+ return rc;
+ }
+
if (vib->data->hw_type == SSBI_VIB)
return 0;

@@ -128,10 +169,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->data->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->data->hw_type != SPMI_VIB_GEN2)
+ vib->level /= 100;
}

pm8xxx_vib_set(vib, vib->active);
@@ -266,6 +310,7 @@ static const struct of_device_id pm8xxx_vib_id_table[] = {
{ .compatible = "qcom,pm8058-vib", .data = &ssbi_vib_data },
{ .compatible = "qcom,pm8921-vib", .data = &ssbi_vib_data },
{ .compatible = "qcom,pm8916-vib", .data = &spmi_vib_data },
+ { .compatible = "qcom,spmi-vib-gen2", .data = &spmi_vib_gen2_data },
{ }
};
MODULE_DEVICE_TABLE(of, pm8xxx_vib_id_table);
--
2.25.1


2023-08-11 19:06:39

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v4 2/3] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module


On Mon, 31 Jul 2023 13:37:07 +0800, Fenglin Wu wrote:
> Add compatible string 'qcom,spmi-vib-gen2' to support vibrator module
> inside PMI632, PMI7250B, PM7325B, PM7550BA.
>
> Signed-off-by: Fenglin Wu <[email protected]>
> ---
> .../bindings/input/qcom,pm8xxx-vib.yaml | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>

Acked-by: Rob Herring <[email protected]>


2023-08-14 10:32:27

by Luca Weiss

[permalink] [raw]
Subject: Re: [PATCH v4 0/3] Add support for vibrator in multiple PMICs

Hi Fenglin,

On Mon Jul 31, 2023 at 7:37 AM CEST, Fenglin Wu wrote:
> Add SW support for the vibrator module inside PMI632, PM7250B, PM7325B, PM7550BA.
> It is very similar to the vibrator module inside PM8916 which is supported in
> pm8xxx-vib driver but just the drive amplitude is controlled with 2 registers,
> and the register base offset in each PMIC is different.

Briefly tested on a SDM632+PMI632-based Fairphone 3.

I didn't really check for vibration strength or anything more detailed
but with the fftest tool the vibrator seems to work fine!

Diff is attached below. I can send the pmi632.dtsi change once this
series is merged (unless you send something first).

Many thanks for sending these patches!

Tested-by: Luca Weiss <[email protected]> # sdm632-fairphone-fp3 (pmi632)

Regards
Luca


diff --git a/arch/arm64/boot/dts/qcom/pmi632.dtsi b/arch/arm64/boot/dts/qcom/pmi632.dtsi
index 4eb79e0ce40a..41ef7dad508e 100644
--- a/arch/arm64/boot/dts/qcom/pmi632.dtsi
+++ b/arch/arm64/boot/dts/qcom/pmi632.dtsi
@@ -161,5 +161,11 @@ pmi632_lpg: pwm {

status = "disabled";
};
+
+ pmi632_vib: vibrator@5700 {
+ compatible = "qcom,pmi632-vib", "qcom,spmi-vib-gen2";
+ reg = <0x5700>;
+ status = "disabled";
+ };
};
};
diff --git a/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts b/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts
index 301eca9a4f31..0d89bc39f613 100644
--- a/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts
+++ b/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts
@@ -112,6 +112,10 @@ led@3 {
};
};

+&pmi632_vib {
+ status = "okay";
+};
+
&sdhc_1 {
status = "okay";
vmmc-supply = <&pm8953_l8>;

> Changes in v4:
> 1. Update to use the combination of the HW type and register offset
> as the constant match data, the register base address defined in
> 'reg' property will be added when accessing SPMI registers using
> regmap APIs.
> 2. Remove 'qcom,spmi-vib-gen1' generic compatible string.
>
> Changes in v3:
> 1. Refactor the driver to support different type of the vibrators with
> better flexibility by introducing the HW type with corresponding
> register fields definitions.
> 2. Add 'qcom,spmi-vib-gen1' and 'qcom,spmi-vib-gen2' compatible
> strings, and add PMI632, PM7250B, PM7325B, PM7550BA as compatbile as
> spmi-vib-gen2.
>
> Changes in v2:
> Remove the "pm7550ba-vib" compatible string as it's compatible with pm7325b.
>
> Fenglin Wu (3):
> input: pm8xxx-vib: refactor to easily support new SPMI vibrator
> dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module
> input: pm8xxx-vibrator: add new SPMI vibrator support
>
> .../bindings/input/qcom,pm8xxx-vib.yaml | 16 +-
> drivers/input/misc/pm8xxx-vibrator.c | 171 ++++++++++++------
> 2 files changed, 132 insertions(+), 55 deletions(-)


2023-08-14 10:38:58

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] input: pm8xxx-vibrator: add new SPMI vibrator support

On 31/07/2023 07:37, Fenglin Wu wrote:

...

>
> pm8xxx_vib_set(vib, vib->active);
> @@ -266,6 +310,7 @@ static const struct of_device_id pm8xxx_vib_id_table[] = {
> { .compatible = "qcom,pm8058-vib", .data = &ssbi_vib_data },
> { .compatible = "qcom,pm8921-vib", .data = &ssbi_vib_data },
> { .compatible = "qcom,pm8916-vib", .data = &spmi_vib_data },
> + { .compatible = "qcom,spmi-vib-gen2", .data = &spmi_vib_gen2_data },

No, don't introduce new style of compatibles. All of the other cases use
device-specific compatibles. Keep style consistent, especially that
device specific is preferred.

Best regards,
Krzysztof


2023-08-14 11:55:23

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v4 2/3] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module

On 31/07/2023 07:37, Fenglin Wu wrote:
> Add compatible string 'qcom,spmi-vib-gen2' to support vibrator module
> inside PMI632, PMI7250B, PM7325B, PM7550BA.
>
> Signed-off-by: Fenglin Wu <[email protected]>
> ---
> .../bindings/input/qcom,pm8xxx-vib.yaml | 16 ++++++++++++----
> 1 file changed, 12 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..4a2319fc1e3f 100644
> --- a/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml
> +++ b/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml
> @@ -11,10 +11,18 @@ maintainers:
>
> properties:
> compatible:
> - enum:
> - - qcom,pm8058-vib
> - - qcom,pm8916-vib
> - - qcom,pm8921-vib
> + oneOf:
> + - enum:
> + - qcom,pm8058-vib
> + - qcom,pm8916-vib
> + - qcom,pm8921-vib
> + - items:
> + - enum:
> + - qcom,pmi632-vib
> + - qcom,pm7250b-vib
> + - qcom,pm7325b-vib
> + - qcom,pm7550b-vib
> + - const: qcom,spmi-vib-gen2

This does not seem to implement my comment:

"Entirely remove qcom,spmi-vib-gen2 and
qcom,spmi-vib-gen1.

Use device specific compatibles names only. As fallback and as first
compatible."

It's nice to respond that you disagree with it. Therefore, I am not
going to Ack it.

Best regards,
Krzysztof


2023-08-19 13:29:49

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v4 2/3] dt-bindings: input: qcom,pm8xxx-vib: add new SPMI vibrator module

On 15/08/2023 04:20, Fenglin Wu wrote:
>
>
> On 8/14/2023 6:06 PM, Krzysztof Kozlowski wrote:
>> On 31/07/2023 07:37, Fenglin Wu wrote:
>>> Add compatible string 'qcom,spmi-vib-gen2' to support vibrator module
>>> inside PMI632, PMI7250B, PM7325B, PM7550BA.
>>>
>>> Signed-off-by: Fenglin Wu <[email protected]>
>>> ---
>>> .../bindings/input/qcom,pm8xxx-vib.yaml | 16 ++++++++++++----
>>> 1 file changed, 12 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..4a2319fc1e3f 100644
>>> --- a/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml
>>> +++ b/Documentation/devicetree/bindings/input/qcom,pm8xxx-vib.yaml
>>> @@ -11,10 +11,18 @@ maintainers:
>>>
>>> properties:
>>> compatible:
>>> - enum:
>>> - - qcom,pm8058-vib
>>> - - qcom,pm8916-vib
>>> - - qcom,pm8921-vib
>>> + oneOf:
>>> + - enum:
>>> + - qcom,pm8058-vib
>>> + - qcom,pm8916-vib
>>> + - qcom,pm8921-vib
>>> + - items:
>>> + - enum:
>>> + - qcom,pmi632-vib
>>> + - qcom,pm7250b-vib
>>> + - qcom,pm7325b-vib
>>> + - qcom,pm7550b-vib
>>> + - const: qcom,spmi-vib-gen2
>>
>> This does not seem to implement my comment:
>>
>> "Entirely remove qcom,spmi-vib-gen2 and
>> qcom,spmi-vib-gen1.
>>
>> Use device specific compatibles names only. As fallback and as first
>> compatible."
>>
>> It's nice to respond that you disagree with it. Therefore, I am not
>> going to Ack it.
>
> I saw your comments and I replied your later comments in v2:
> https://lore.kernel.org/linux-arm-msm/[email protected]/.
> It might not be a good place to follow the discussion though, I am
> pasting my last reply below:
>
> 'Sorry, I forgot to mention, in v3, I added the 'reg' value to the
> register offset and no longer hard code the 16-bit register address,
> that makes the vibrators inside PMI632/PM7250B/PM7325B/PM7550BA all
> compatible, and that was another motivation of adding a generic
> compatible string and make the others as the fallback.
>
> This will be still the case in v4, I might keep it similar in v3 but
> just drop "qcom,spmi-vib-gen1" '
>
> Anyway, if this is still not a good reason to add a generic compatible
> string, I can revert it back to use device specific compatible string
> only in next patch.

I just don't see how this argument is anyhow related to what I said. I
did not comment on removing the fallback. I said use specific compatible
as fallback.

Best regards,
Krzysztof