mbox series

[0/4] Add haptics support to Nexus 5 using pwm-vibra driver

Message ID 20230427-hammerhead-vibra-v1-0-e87eeb94da51@z3ntu.xyz
Headers show
Series Add haptics support to Nexus 5 using pwm-vibra driver | expand

Message

Luca Weiss April 27, 2023, 8:34 p.m. UTC
A while ago Brian Masney sent some patches for a clk-vibrator which was
then succeeded by the idea of a clk-pwm driver that "converts" a clock
into a PWM and to use the existing pwm-vibra driver.

Since clk-pwm has landed last year we can finally add haptics support
upstream.

We just need to add support for an enable GPIO to the pwm-vibra driver
since that also needs to be high for the haptics to work on this device.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
Luca Weiss (4):
      dt-bindings: input: pwm-vibrator: Add enable-gpio
      Input: pwm-vibra - add newline to dev_err prints
      Input: pwm-vibra - add support for enable GPIO
      ARM: dts: qcom: msm8974-hammerhead: Add vibrator

 .../devicetree/bindings/input/pwm-vibrator.yaml    |  2 ++
 .../dts/qcom-msm8974-lge-nexus5-hammerhead.dts     | 35 +++++++++++++++++++++
 drivers/input/misc/pwm-vibra.c                     | 36 ++++++++++++++++------
 3 files changed, 63 insertions(+), 10 deletions(-)
---
base-commit: dec7f67a13c3270f9a38eba227a4fc15993f01b3
change-id: 20230427-hammerhead-vibra-06bd1bf771a3

Best regards,

Comments

Brian Masney April 27, 2023, 11:30 p.m. UTC | #1
On Thu, Apr 27, 2023 at 10:34:27PM +0200, Luca Weiss wrote:
> Make sure all printed messages end with a newline.
> 
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>

Reviewed-by: Brian Masney <bmasney@redhat.com>
Brian Masney April 27, 2023, 11:34 p.m. UTC | #2
On Thu, Apr 27, 2023 at 10:34:29PM +0200, Luca Weiss wrote:
> The Nexus 5 has a vibrator connected to the clock output of GP1_CLK
> which we can use with the clk-pwm driver, then we can use that pwm with
> pwm-vibrator to get haptics functionality.
> 
> This patch is based on Brian Masney's previous patch with clk-vibrator.
> 
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>

Reviewed-by: Brian Masney <bmasney@redhat.com>
Caleb Connolly April 28, 2023, 10:10 a.m. UTC | #3
On 27/04/2023 21:34, Luca Weiss wrote:
> Make sure all printed messages end with a newline.
> 
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>

Reviewed-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>   drivers/input/misc/pwm-vibra.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c
> index d0e58a7cdfa3..c08971c97ad6 100644
> --- a/drivers/input/misc/pwm-vibra.c
> +++ b/drivers/input/misc/pwm-vibra.c
> @@ -42,7 +42,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
>   	if (!vibrator->vcc_on) {
>   		err = regulator_enable(vibrator->vcc);
>   		if (err) {
> -			dev_err(pdev, "failed to enable regulator: %d", err);
> +			dev_err(pdev, "failed to enable regulator: %d\n", err);
>   			return err;
>   		}
>   		vibrator->vcc_on = true;
> @@ -54,7 +54,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
>   
>   	err = pwm_apply_state(vibrator->pwm, &state);
>   	if (err) {
> -		dev_err(pdev, "failed to apply pwm state: %d", err);
> +		dev_err(pdev, "failed to apply pwm state: %d\n", err);
>   		return err;
>   	}
>   
> @@ -65,7 +65,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
>   
>   		err = pwm_apply_state(vibrator->pwm_dir, &state);
>   		if (err) {
> -			dev_err(pdev, "failed to apply dir-pwm state: %d", err);
> +			dev_err(pdev, "failed to apply dir-pwm state: %d\n", err);
>   			pwm_disable(vibrator->pwm);
>   			return err;
>   		}
> @@ -137,7 +137,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>   	err = PTR_ERR_OR_ZERO(vibrator->vcc);
>   	if (err) {
>   		if (err != -EPROBE_DEFER)
> -			dev_err(&pdev->dev, "Failed to request regulator: %d",
> +			dev_err(&pdev->dev, "Failed to request regulator: %d\n",
>   				err);
>   		return err;
>   	}
> @@ -146,7 +146,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>   	err = PTR_ERR_OR_ZERO(vibrator->pwm);
>   	if (err) {
>   		if (err != -EPROBE_DEFER)
> -			dev_err(&pdev->dev, "Failed to request main pwm: %d",
> +			dev_err(&pdev->dev, "Failed to request main pwm: %d\n",
>   				err);
>   		return err;
>   	}
> @@ -158,7 +158,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>   	state.enabled = false;
>   	err = pwm_apply_state(vibrator->pwm, &state);
>   	if (err) {
> -		dev_err(&pdev->dev, "failed to apply initial PWM state: %d",
> +		dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n",
>   			err);
>   		return err;
>   	}
> @@ -172,7 +172,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>   		state.enabled = false;
>   		err = pwm_apply_state(vibrator->pwm_dir, &state);
>   		if (err) {
> -			dev_err(&pdev->dev, "failed to apply initial PWM state: %d",
> +			dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n",
>   				err);
>   			return err;
>   		}
> @@ -189,7 +189,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>   		break;
>   
>   	default:
> -		dev_err(&pdev->dev, "Failed to request direction pwm: %d", err);
> +		dev_err(&pdev->dev, "Failed to request direction pwm: %d\n", err);
>   		fallthrough;
>   
>   	case -EPROBE_DEFER:
> @@ -207,13 +207,13 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>   	err = input_ff_create_memless(vibrator->input, NULL,
>   				      pwm_vibrator_play_effect);
>   	if (err) {
> -		dev_err(&pdev->dev, "Couldn't create FF dev: %d", err);
> +		dev_err(&pdev->dev, "Couldn't create FF dev: %d\n", err);
>   		return err;
>   	}
>   
>   	err = input_register_device(vibrator->input);
>   	if (err) {
> -		dev_err(&pdev->dev, "Couldn't register input dev: %d", err);
> +		dev_err(&pdev->dev, "Couldn't register input dev: %d\n", err);
>   		return err;
>   	}
>   
>
Caleb Connolly April 28, 2023, 10:11 a.m. UTC | #4
On 27/04/2023 21:34, Luca Weiss wrote:
> The Nexus 5 has a vibrator connected to the clock output of GP1_CLK
> which we can use with the clk-pwm driver, then we can use that pwm with
> pwm-vibrator to get haptics functionality.
> 
> This patch is based on Brian Masney's previous patch with clk-vibrator.
> 
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>

Reviewed-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>   .../dts/qcom-msm8974-lge-nexus5-hammerhead.dts     | 35 ++++++++++++++++++++++
>   1 file changed, 35 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> index ab35f2d644c0..fea8a6be9021 100644
> --- a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> +++ b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> @@ -41,6 +41,25 @@ key-volume-down {
>   		};
>   	};
>   
> +	clk_pwm: pwm {
> +		compatible = "clk-pwm";
> +		clocks = <&mmcc CAMSS_GP1_CLK>;
> +
> +		pinctrl-0 = <&vibrator_pin>;
> +		pinctrl-names = "default";
> +
> +		#pwm-cells = <2>;
> +	};
> +
> +	vibrator {
> +		compatible = "pwm-vibrator";
> +		pwms = <&clk_pwm 0 100000>;
> +		pwm-names = "enable";
> +
> +		vcc-supply = <&pm8941_l19>;
> +		enable-gpios = <&tlmm 60 GPIO_ACTIVE_HIGH>;
> +	};
> +
>   	vreg_wlan: wlan-regulator {
>   		compatible = "regulator-fixed";
>   
> @@ -637,6 +656,22 @@ shutdown-pins {
>   			function = "gpio";
>   		};
>   	};
> +
> +	vibrator_pin: vibrator-state {
> +		core-pins {
> +			pins = "gpio27";
> +			function = "gp1_clk";
> +			drive-strength = <6>;
> +			bias-disable;
> +		};
> +
> +		enable-pins {
> +			pins = "gpio60";
> +			function = "gpio";
> +			drive-strength = <2>;
> +			bias-disable;
> +		};
> +	};
>   };
>   
>   &usb {
>
Sebastian Reichel April 29, 2023, 7:45 p.m. UTC | #5
Hi,

On Thu, Apr 27, 2023 at 10:34:27PM +0200, Luca Weiss wrote:
> Make sure all printed messages end with a newline.
> 
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
> ---

Reviewed-by: Sebastian Reichel <sre@kernel.org>

-- Sebastian

>  drivers/input/misc/pwm-vibra.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c
> index d0e58a7cdfa3..c08971c97ad6 100644
> --- a/drivers/input/misc/pwm-vibra.c
> +++ b/drivers/input/misc/pwm-vibra.c
> @@ -42,7 +42,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
>  	if (!vibrator->vcc_on) {
>  		err = regulator_enable(vibrator->vcc);
>  		if (err) {
> -			dev_err(pdev, "failed to enable regulator: %d", err);
> +			dev_err(pdev, "failed to enable regulator: %d\n", err);
>  			return err;
>  		}
>  		vibrator->vcc_on = true;
> @@ -54,7 +54,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
>  
>  	err = pwm_apply_state(vibrator->pwm, &state);
>  	if (err) {
> -		dev_err(pdev, "failed to apply pwm state: %d", err);
> +		dev_err(pdev, "failed to apply pwm state: %d\n", err);
>  		return err;
>  	}
>  
> @@ -65,7 +65,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
>  
>  		err = pwm_apply_state(vibrator->pwm_dir, &state);
>  		if (err) {
> -			dev_err(pdev, "failed to apply dir-pwm state: %d", err);
> +			dev_err(pdev, "failed to apply dir-pwm state: %d\n", err);
>  			pwm_disable(vibrator->pwm);
>  			return err;
>  		}
> @@ -137,7 +137,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>  	err = PTR_ERR_OR_ZERO(vibrator->vcc);
>  	if (err) {
>  		if (err != -EPROBE_DEFER)
> -			dev_err(&pdev->dev, "Failed to request regulator: %d",
> +			dev_err(&pdev->dev, "Failed to request regulator: %d\n",
>  				err);
>  		return err;
>  	}
> @@ -146,7 +146,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>  	err = PTR_ERR_OR_ZERO(vibrator->pwm);
>  	if (err) {
>  		if (err != -EPROBE_DEFER)
> -			dev_err(&pdev->dev, "Failed to request main pwm: %d",
> +			dev_err(&pdev->dev, "Failed to request main pwm: %d\n",
>  				err);
>  		return err;
>  	}
> @@ -158,7 +158,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>  	state.enabled = false;
>  	err = pwm_apply_state(vibrator->pwm, &state);
>  	if (err) {
> -		dev_err(&pdev->dev, "failed to apply initial PWM state: %d",
> +		dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n",
>  			err);
>  		return err;
>  	}
> @@ -172,7 +172,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>  		state.enabled = false;
>  		err = pwm_apply_state(vibrator->pwm_dir, &state);
>  		if (err) {
> -			dev_err(&pdev->dev, "failed to apply initial PWM state: %d",
> +			dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n",
>  				err);
>  			return err;
>  		}
> @@ -189,7 +189,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>  		break;
>  
>  	default:
> -		dev_err(&pdev->dev, "Failed to request direction pwm: %d", err);
> +		dev_err(&pdev->dev, "Failed to request direction pwm: %d\n", err);
>  		fallthrough;
>  
>  	case -EPROBE_DEFER:
> @@ -207,13 +207,13 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
>  	err = input_ff_create_memless(vibrator->input, NULL,
>  				      pwm_vibrator_play_effect);
>  	if (err) {
> -		dev_err(&pdev->dev, "Couldn't create FF dev: %d", err);
> +		dev_err(&pdev->dev, "Couldn't create FF dev: %d\n", err);
>  		return err;
>  	}
>  
>  	err = input_register_device(vibrator->input);
>  	if (err) {
> -		dev_err(&pdev->dev, "Couldn't register input dev: %d", err);
> +		dev_err(&pdev->dev, "Couldn't register input dev: %d\n", err);
>  		return err;
>  	}
>  
> 
> -- 
> 2.40.0
>
Bjorn Andersson May 25, 2023, 4:54 a.m. UTC | #6
On Thu, 27 Apr 2023 22:34:25 +0200, Luca Weiss wrote:
> A while ago Brian Masney sent some patches for a clk-vibrator which was
> then succeeded by the idea of a clk-pwm driver that "converts" a clock
> into a PWM and to use the existing pwm-vibra driver.
> 
> Since clk-pwm has landed last year we can finally add haptics support
> upstream.
> 
> [...]

Applied, thanks!

[4/4] ARM: dts: qcom: msm8974-hammerhead: Add vibrator
      commit: e0a6590d8ceb7d6c4e35b5b5eb368d9fb800487f

Best regards,