Input: add optional enable gpio to pwm-beeper
Subsystems (3)
cover Input: add optional enable gpio to pwm-beeper
This series adds an optional enable gpio to the pwm-beeper driver. This is for cases when the beeper needs to be "enabled", for example, if there is an amplifier that drives the speaker that is not always on.
David Lechner (3):
Input: pwm-beeper: suppress error message on probe defer
dt-bindings: Input: Add enable-gpios to pwm-beeper
Input: pwm-beeper: add optional enable gpio
.../devicetree/bindings/input/pwm-beeper.txt | 11 +++++++++ drivers/input/misc/pwm-beeper.c | 27 ++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 Input: pwm-beeper: suppress error message on probe defer
This suppress printing an error message when pwm_get/pwm_request returns -EPROBE_DEFER. Otherwise you get a bunch of noise in the kernel log.
--- drivers/input/misc/pwm-beeper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/input/misc/pwm-beeper.c +4 -3
@@ -109,9 +109,10 @@ static int pwm_beeper_probe(struct platform_device *pdev) beeper->pwm =pwm_request (pwm_id,"pwm beeper" ); } -if (IS_ERR (beeper->pwm)) { - error =PTR_ERR (beeper->pwm); -dev_err (&pdev->dev,"Failed to request pwm device: %d\n" , error); + error =PTR_ERR_OR_ZERO (beeper->pwm); +if (error) { +if (error != -EPROBE_DEFER ) +dev_err (&pdev->dev,"Failed to request pwm device\n" ); goto err_free; }
Signature · 1 line
2.7.4
PATCH 2/3 dt-bindings: Input: Add enable-gpios to pwm-beeper
In reply to David LechnerThis adds an optional enable-gpios property to pwm-beeper. This gpio is used to enable the beeper. For example, the beeper may have an amplifier that needs to be switched on.
--- Documentation/devicetree/bindings/input/pwm-beeper.txt | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/input/pwm-beeper.txt +11 -0
@@ -5,3 +5,14 @@ Registers a PWM device as beeper. Required properties: - compatible: should be "pwm-beeper" - pwms: phandle to the physical PWM device + +Optional properties: +- enable-gpios: phandle to gpio to enable the beeper + +Example: + +beeper { + compatible = "pwm-beeper"; + pwms = <&pwm0>; + enable-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>; +};
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 Input: pwm-beeper: add optional enable gpio
In reply to David LechnerThis 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.
--- drivers/input/misc/pwm-beeper.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/input/misc/pwm-beeper.c +19 -1
@@ -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.
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] Input: pwm-beeper: add optional enable gpio
Quoted 2 lines · David Lechner
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.
Isn't it a property of pin muxing?
Quoted 2 lines
For
example, there may be an amplifier that is not always powered on.
This looks like GPIO based fixed voltage regulator.
Quoted 3 lines
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] Input: pwm-beeper: add optional enable gpio
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · David Lechner
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.
Isn't it a property of pin muxing?
You may want to turn if off when not making a sound to save power.
Quoted 5 lines
Quoted 3 lines
For
example, there may be an amplifier that is not always powered on.This looks like GPIO based fixed voltage regulator.
Yes, I think a regulator could work here just as well.
Quoted 5 lines
Quoted 4 lines
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.