phone-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Weiss <luca@z3ntu.xyz>
To: ~postmarketos/upstreaming@lists.sr.ht,
	phone-devel@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Sebastian Reichel <sre@kernel.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Brian Masney <masneyb@onstation.org>
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	Luca Weiss <luca@z3ntu.xyz>
Subject: [PATCH 3/4] Input: pwm-vibra - add support for enable GPIO
Date: Thu, 27 Apr 2023 22:34:28 +0200	[thread overview]
Message-ID: <20230427-hammerhead-vibra-v1-3-e87eeb94da51@z3ntu.xyz> (raw)
In-Reply-To: <20230427-hammerhead-vibra-v1-0-e87eeb94da51@z3ntu.xyz>

Some pwm vibrators have a dedicated enable GPIO that needs to be set
high so that the vibrator works. Add support for that optionally.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
 drivers/input/misc/pwm-vibra.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c
index c08971c97ad6..2ba035299db8 100644
--- a/drivers/input/misc/pwm-vibra.c
+++ b/drivers/input/misc/pwm-vibra.c
@@ -11,6 +11,7 @@
  *  Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
  */
 
+#include <linux/gpio/consumer.h>
 #include <linux/input.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -23,6 +24,7 @@
 
 struct pwm_vibrator {
 	struct input_dev *input;
+	struct gpio_desc *enable_gpio;
 	struct pwm_device *pwm;
 	struct pwm_device *pwm_dir;
 	struct regulator *vcc;
@@ -48,6 +50,8 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
 		vibrator->vcc_on = true;
 	}
 
+	gpiod_set_value_cansleep(vibrator->enable_gpio, 1);
+
 	pwm_get_state(vibrator->pwm, &state);
 	pwm_set_relative_duty_cycle(&state, vibrator->level, 0xffff);
 	state.enabled = true;
@@ -80,6 +84,8 @@ static void pwm_vibrator_stop(struct pwm_vibrator *vibrator)
 		pwm_disable(vibrator->pwm_dir);
 	pwm_disable(vibrator->pwm);
 
+	gpiod_set_value_cansleep(vibrator->enable_gpio, 0);
+
 	if (vibrator->vcc_on) {
 		regulator_disable(vibrator->vcc);
 		vibrator->vcc_on = false;
@@ -142,6 +148,16 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
 		return err;
 	}
 
+	vibrator->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
+							GPIOD_OUT_LOW);
+	err = PTR_ERR_OR_ZERO(vibrator->enable_gpio);
+	if (err) {
+		if (err != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Failed to request enable gpio: %d\n",
+				err);
+		return err;
+	}
+
 	vibrator->pwm = devm_pwm_get(&pdev->dev, "enable");
 	err = PTR_ERR_OR_ZERO(vibrator->pwm);
 	if (err) {

-- 
2.40.0


  parent reply	other threads:[~2023-04-27 20:35 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27 20:34 [PATCH 0/4] Add haptics support to Nexus 5 using pwm-vibra driver Luca Weiss
2023-04-27 20:34 ` [PATCH 1/4] dt-bindings: input: pwm-vibrator: Add enable-gpio Luca Weiss
2023-04-27 23:29   ` Brian Masney
2023-04-28 10:10   ` Caleb Connolly
2023-04-29 19:44   ` Sebastian Reichel
2023-05-01  6:48   ` Krzysztof Kozlowski
2023-04-27 20:34 ` [PATCH 2/4] Input: pwm-vibra - add newline to dev_err prints Luca Weiss
2023-04-27 23:30   ` Brian Masney
2023-04-28 10:10   ` Caleb Connolly
2023-04-29 19:45   ` Sebastian Reichel
2023-04-27 20:34 ` Luca Weiss [this message]
2023-04-27 23:29   ` [PATCH 3/4] Input: pwm-vibra - add support for enable GPIO Brian Masney
2023-04-28 16:06     ` Luca Weiss
2023-04-28 16:11       ` Brian Masney
2023-05-02 10:39       ` Konrad Dybcio
2023-05-02 15:24         ` Luca Weiss
2023-04-28 10:11   ` Caleb Connolly
2023-04-29 19:47   ` Sebastian Reichel
2023-05-02  0:47   ` Dmitry Torokhov
2023-05-02 15:35     ` Luca Weiss
2023-04-27 20:34 ` [PATCH 4/4] ARM: dts: qcom: msm8974-hammerhead: Add vibrator Luca Weiss
2023-04-27 23:34   ` Brian Masney
2023-04-28 10:11   ` Caleb Connolly
2023-05-02 10:40   ` Konrad Dybcio
2023-05-02 15:28     ` Luca Weiss
2023-05-02 15:31       ` Konrad Dybcio
2023-05-08 16:44 ` [PATCH 0/4] Add haptics support to Nexus 5 using pwm-vibra driver Dmitry Torokhov
2023-05-25  4:54 ` (subset) " Bjorn Andersson

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=20230427-hammerhead-vibra-v1-3-e87eeb94da51@z3ntu.xyz \
    --to=luca@z3ntu.xyz \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.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=masneyb@onstation.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sre@kernel.org \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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).