linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>
Cc: David Lechner <david@lechnology.com>,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] Input: pwm-beeper: add optional enable gpio
Date: Thu,  5 Jan 2017 20:43:54 -0600	[thread overview]
Message-ID: <1483670635-25060-4-git-send-email-david@lechnology.com> (raw)
In-Reply-To: <1483670635-25060-1-git-send-email-david@lechnology.com>

This adds an optional enable gpio to the pwm-beeper device. This gpio is
used in cases where the beeper needs to be switched on before using it. For
example, there may be an amplifier that is not always powered on.

Tested on LEGO MINDSTORMS EV3, which has a speaker connected to PWM through
an amplifier. The amplifier has an enable pin that is connected to a gpio.

Signed-off-by: David Lechner <david@lechnology.com>
---
 drivers/input/misc/pwm-beeper.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index e76b710..4379ceb 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -14,6 +14,7 @@
  */
 
 #include <linux/input.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/of.h>
@@ -25,6 +26,7 @@
 struct pwm_beeper {
 	struct input_dev *input;
 	struct pwm_device *pwm;
+	struct gpio_desc *enable_gpio;
 	struct work_struct work;
 	unsigned long period;
 };
@@ -38,8 +40,13 @@ static void __pwm_beeper_set(struct pwm_beeper *beeper)
 	if (period) {
 		pwm_config(beeper->pwm, period / 2, period);
 		pwm_enable(beeper->pwm);
-	} else
+		if (beeper->enable_gpio)
+			gpiod_direction_output(beeper->enable_gpio, 1);
+	} else {
+		if (beeper->enable_gpio)
+			gpiod_direction_output(beeper->enable_gpio, 0);
 		pwm_disable(beeper->pwm);
+	}
 }
 
 static void pwm_beeper_work(struct work_struct *work)
@@ -82,6 +89,8 @@ static void pwm_beeper_stop(struct pwm_beeper *beeper)
 {
 	cancel_work_sync(&beeper->work);
 
+	if (beeper->enable_gpio)
+		gpiod_direction_output(beeper->enable_gpio, 0);
 	if (beeper->period)
 		pwm_disable(beeper->pwm);
 }
@@ -116,6 +125,15 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 		goto err_free;
 	}
 
+	beeper->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
+						      GPIOD_OUT_LOW);
+	error = PTR_ERR_OR_ZERO(beeper->enable_gpio);
+	if (error) {
+		if (error != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Failed to get enable gpio\n");
+		goto err_pwm_free;
+	}
+
 	/*
 	 * FIXME: pwm_apply_args() should be removed when switching to
 	 * the atomic PWM API.
-- 
2.7.4

  parent reply	other threads:[~2017-01-06  2:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06  2:43 [PATCH 0/3] Input: add optional enable gpio to pwm-beeper David Lechner
2017-01-06  2:43 ` [PATCH 1/3] Input: pwm-beeper: suppress error message on probe defer David Lechner
2017-01-06  2:43 ` [PATCH 2/3] dt-bindings: Input: Add enable-gpios to pwm-beeper David Lechner
2017-01-06  2:43 ` David Lechner [this message]
2017-01-06 17:28   ` [PATCH 3/3] Input: pwm-beeper: add optional enable gpio Andy Shevchenko
2017-01-06 17:45     ` David Lechner

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=1483670635-25060-4-git-send-email-david@lechnology.com \
    --to=david@lechnology.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --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;
as well as URLs for NNTP newsgroup(s).