ARM: qcom: add vibrator support for various MSM SOCs
Subsystems (4)
v3 cover ARM: qcom: add vibrator support for various MSM SOCs
This patch set adds support for the vibrator found on various Qualcomm MSM SOCs. This is based on work from:
Jonathan Marek from qcom,pwm-vibrator.c in the PostmarketOS repo:
https://gitlab.com/postmarketOS/linux-postmarketos/commit/7647fb36cb1cbd060f8b52087a68ab93583292b5
Jongrak Kwon and Devin Kim from msm_pwm_vibrator.c in the downstream Android 3.4.0 sources:
https://android.googlesource.com/kernel/msm/+/android-msm-lenok-3.10-lollipop-wear-release/drivers/misc/msm_pwm_vibrator.c
Driver was tested on a LG Nexus 5 (hammerhead) phone using rumble-test:
https://git.collabora.com/cgit/user/sre/rumble-test.git/plain/rumble-test.c
Changes since v2
- Moved from pwm to input subsystem based on feedback from
https://lore.kernel.org/lkml/20181012114749.GC31561@ulmo/. I previously wired this into the input system via pwm-vibra.
Changes since v1
- Update device tree binding document based on feedback from Rob Herring.
- Changed the driver description to: Qualcomm PWM driver for the MSM vibrator.
Brian Masney (3):
dt-bindings: Input: new bindings for MSM vibrator
Input: add new vibrator driver for various MSM SOCs
ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for
vibrator
.../bindings/input/msm-vibrator.txt | 36 +++ .../qcom-msm8974-lge-nexus5-hammerhead.dts | 31 ++ drivers/input/misc/Kconfig | 10 + drivers/input/misc/Makefile | 1 + drivers/input/misc/msm-vibrator.c | 276 ++++++++++++++++++ 5 files changed, 354 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/msm-vibrator.txt create mode 100644 drivers/input/misc/msm-vibrator.c
Signature · 1 line
2.17.2
PATCH v3 1/3 dt-bindings: Input: new bindings for MSM vibrator
This patch adds the device tree bindings for the vibrator found on various Qualcomm MSM SOCs.
--- .../bindings/input/msm-vibrator.txt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/msm-vibrator.txt
Documentation/devicetree/bindings/input/msm-vibrator.txt new file +36 -0
@@ -0,0 +1,36 @@ +* Device tree bindings for the Qualcomm MSM vibrator + +Required properties: + + - compatible: Should be one of + "qcom,msm8226-vibrator" + "qcom,msm8974-vibrator" + - reg: the base address and length of the IO memory for the registers. + - pinctrl-names: set to default. + - pinctrl-0: phandles pointing to pin configuration nodes. See + Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt + - clock-names: set to pwm + - clocks: phandle of the clock. See + Documentation/devicetree/bindings/clock/clock-bindings.txt + - enable-gpios: GPIO that enables the vibrator. + +Optional properties: + + - vcc-supply: phandle to the regulator that provides power to the sensor. + +Example from a LG Nexus 5 (hammerhead) phone: + +vibrator@fd8c3450 { + reg = <0xfd8c3450 0x400>; + compatible = "qcom,msm8974-vibrator"; + + vcc-supply = <&pm8941_l19>; + + clocks = <&mmcc CAMSS_GP1_CLK>; + clock-names = "pwm"; + + enable-gpios = <&msmgpio 60 GPIO_ACTIVE_HIGH>; + + pinctrl-names = "default"; + pinctrl-0 = <&vibrator_pin>; +};
Signature · 1 line
2.17.2
Re: [PATCH v3 1/3] dt-bindings: Input: new bindings for MSM vibrator
Quoted 9 lines · Brian Masney
This patch adds the device tree bindings for the vibrator found on various Qualcomm MSM SOCs.
Signed-off-by Brian Masney <[email protected]>--- .../bindings/input/msm-vibrator.txt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/msm-vibrator.txt
PATCH v3 2/3 Input: add new vibrator driver for various MSM SOCs
In reply to Brian MasneyThis patch adds a new vibrator driver that supports various Qualcomm MSM SOCs. Driver was tested on a LG Nexus 5 (hammerhead) phone.
--- drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/msm-vibrator.c | 276 ++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 drivers/input/misc/msm-vibrator.c
drivers/input/misc/Kconfig +10 -0
@@ -117,6 +117,16 @@ config INPUT_E3X0_BUTTON To compile this driver as a module, choose M here: the module will be called e3x0_button. +config INPUT_MSM_VIBRATOR + tristate "Qualcomm MSM vibrator driver" + select INPUT_FF_MEMLESS + help + Support for the vibrator that is found on various Qualcomm MSM + SOCs. + + To compile this driver as a module, choose M here: the module + will be called msm_vibrator. + config INPUT_PCSPKR tristate "PC Speaker support" depends on PCSPKR_PLATFORM
drivers/input/misc/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o obj-$(CONFIG_INPUT_MMA8450) += mma8450.o +obj-$(CONFIG_INPUT_MSM_VIBRATOR) += msm-vibrator.o obj-$(CONFIG_INPUT_PALMAS_PWRBUTTON) += palmas-pwrbutton.o obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
drivers/input/misc/msm-vibrator.c new file +276 -0
276 lines not on this page · raw message
Signature · 1 line
2.17.2
Re: [PATCH v3 2/3] Input: add new vibrator driver for various MSM SOCs
Hi Dmitry,
Quoted 4 lines · Brian Masney
This patch adds a new vibrator driver that supports various Qualcomm MSM SOCs. Driver was tested on a LG Nexus 5 (hammerhead) phone.
Signed-off-by Brian Masney <[email protected]>
Any chance that I can get a review of this patch series? Let me know if you're not the right maintainer that I should send this series to.
Thanks,
Brian
Dmitry Torokhov
maintainerRe: [PATCH v3 2/3] Input: add new vibrator driver for various MSM SOCs
In reply to Brian MasneyHi Brian,
Quoted 3 lines · Brian Masney
This patch adds a new vibrator driver that supports various Qualcomm MSM SOCs. Driver was tested on a LG Nexus 5 (hammerhead) phone.
...
drivers/input/misc/msm-vibrator.c line 45
Quoted 3 lines
drivers/input/misc/msm-vibrator.c new file +3
-0+ +#define msm_vibrator_write (msm_vibrator, offset, value) \ + writel((value), (void __iomem *)((msm_vibrator)->base + (offset)))
Make in a function? It will be inlined anyways...
drivers/input/misc/msm-vibrator.c line 175
Quoted 12 lines
drivers/input/misc/msm-vibrator.c new file +12
-0+ + vibrator->vcc =devm_regulator_get (&pdev->dev,"vcc" ); +if (IS_ERR (vibrator->vcc)) { +if (PTR_ERR (vibrator->vcc) != -EPROBE_DEFER ) +dev_err (&pdev->dev,"Failed to get regulator: %ld\n" , +PTR_ERR (vibrator->vcc)); +return PTR_ERR (vibrator->vcc); + } + + vibrator->enable_gpio =devm_gpiod_get (&pdev->dev,"enable" , +GPIOD_OUT_LOW ); +if (IS_ERR (vibrator->enable_gpio)) {
You have explicit deferral handling for the regulator, but not gpio. I'd prefer if we did (or not) it consistently.
drivers/input/misc/msm-vibrator.c line 182
Quoted 7 lines
drivers/input/misc/msm-vibrator.c new file +7
-0+dev_err (&pdev->dev,"Failed to get enable gpio: %ld\n" , +PTR_ERR (vibrator->enable_gpio)); +return PTR_ERR (vibrator->enable_gpio); + } + + vibrator->clk =devm_clk_get (&pdev->dev,"pwm" ); +if (IS_ERR (vibrator->clk)) {
Same here.
Quoted 4 lines
drivers/input/misc/msm-vibrator.c new file +4
-0+dev_err (&pdev->dev,"Failed to lookup pwm clock: %ld\n" , +PTR_ERR (vibrator->clk)); +return PTR_ERR (vibrator->clk); + }
drivers/input/misc/msm-vibrator.c line 196
Quoted 10 lines
drivers/input/misc/msm-vibrator.c new file +10
-0+ + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Failed to get platform resource\n" ); +return -ENODEV ; + } + + vibrator->base =devm_ioremap (&pdev->dev, res->start, +resource_size (res)); +if (IS_ERR (vibrator->base)) {
devm_ioremap() returns NULL on error. You either need to check for NULL or see of you can use devm_ioremap_resource().
drivers/input/misc/msm-vibrator.c line 208
Quoted 12 lines
drivers/input/misc/msm-vibrator.c new file +12
-0+dev_err (&pdev->dev,"Failed to iomap resource: %ld\n" , +PTR_ERR (vibrator->base)); +return PTR_ERR (vibrator->base); + } + + vibrator->enabled = false; +mutex_init (&vibrator->mutex); +INIT_WORK (&vibrator->worker, msm_vibrator_worker); + + vibrator->input->name ="msm-vibrator" ; + vibrator->input->id.bustype =BUS_HOST ; + vibrator->input->dev.parent = &pdev->dev;
You allocated input device with devm so there is no need to set parent by hand.
Quoted 16 lines
drivers/input/misc/msm-vibrator.c new file +16
-0+ vibrator->input->close = msm_vibrator_close; + +input_set_drvdata (vibrator->input, vibrator); +input_set_capability (vibrator->input,EV_FF ,FF_RUMBLE ); + + ret =input_ff_create_memless (vibrator->input,NULL , + msm_vibrator_play_effect); +if (ret) { +dev_err (&pdev->dev,"Failed to create ff memless: %d" , ret); +return ret; + } + + ret =input_register_device (vibrator->input); +if (ret) { +dev_err (&pdev->dev,"Failed to register input device: %d" , ret); +return ret;
drivers/input/misc/msm-vibrator.c line 234
Quoted 10 lines
drivers/input/misc/msm-vibrator.c new file +10
-0+ } + +platform_set_drvdata (pdev, vibrator); + +return 0 ; +} + +static int __maybe_unused msm_vibrator_suspend (struct device *dev) +{ +struct msm_vibrator *vibrator =dev_get_drvdata (dev);
Prefer explicit platform_get_drvdata() since we are working with platform device (even though it resolves to the same thing).
drivers/input/misc/msm-vibrator.c line 246
Quoted 12 lines
drivers/input/misc/msm-vibrator.c new file +12
-0+ +cancel_work_sync (&vibrator->worker); + +if (vibrator->enabled) +msm_vibrator_stop (vibrator); + +return 0 ; +} + +static int __maybe_unused msm_vibrator_resume (struct device *dev) +{ +struct msm_vibrator *vibrator =dev_get_drvdata (dev);
Same here.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v3 2/3] Input: add new vibrator driver for various MSM SOCs
Quoted 9 lines · Dmitry Torokhov
Quoted 9 lines
drivers/input/misc/msm-vibrator.c new file +9
-0+dev_err (&pdev->dev,"Failed to lookup pwm clock: %ld\n" , +PTR_ERR (vibrator->clk)); +return PTR_ERR (vibrator->clk); + } + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Failed to get platform resource\n" ); +return -ENODEV ;
Quoted 8 lines
drivers/input/misc/msm-vibrator.c line 196
Quoted 5 lines
drivers/input/misc/msm-vibrator.c new file +5
-0+ } + + vibrator->base =devm_ioremap (&pdev->dev, res->start, +resource_size (res)); +if (IS_ERR (vibrator->base)) {
devm_ioremap()returns NULL on error. You either need to check for NULL or see of you can usedevm_ioremap_resource().
I originally tried to use devm_ioremap_resource() but the call to devm_request_mem_region() would fail. I'll go with the NULL check here for devm_ioremap().
Thanks for the review!
Brian
PATCH v3 3/3 ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for vibrator
In reply to Brian MasneyThis patch adds device device tree bindings for the vibrator found on the LG Nexus 5 (hammerhead) phone.
--- .../qcom-msm8974-lge-nexus5-hammerhead.dts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+)
arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts +31 -0
@@ -5,6 +5,7 @@ #include <dt-bindings/gpio/gpio.h> #include <dt-bindings/input/input.h> #include <dt-bindings/pinctrl/qcom,pmic-gpio.h> +#include <dt-bindings/clock/qcom,mmcc-msm8974.h> / { model = "LGE MSM 8974 HAMMERHEAD";
@@ -268,6 +269,36 @@ input-enable; }; }; + + vibrator_pin: vibrator { + pwm { + pins = "gpio27"; + function = "gp1_clk"; + + drive-strength = <6>; + bias-disable; + }; + + enable { + pins = "gpio60"; + function = "gpio"; + }; + }; + }; + + vibrator@fd8c3450 { + compatible = "qcom,msm8974-vibrator"; + reg = <0xfd8c3450 0x400>; + + vcc-supply = <&pm8941_l19>; + + clocks = <&mmcc CAMSS_GP1_CLK>; + clock-names = "pwm"; + + enable-gpios = <&msmgpio 60 GPIO_ACTIVE_HIGH>; + + pinctrl-names = "default"; + pinctrl-0 = <&vibrator_pin>; }; sdhci@f9824900 {
Signature · 1 line
2.17.2