Skip to contentSkip to conversation

Input: gpio-beeper: drive output by hrtimer

RFC New Ladislav Michl 1 participant 3 messages Nov 29, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Input: gpio-beeper: drive output by hrtimer

I have board here, where beeper cannot by driven by PWM as its pin cannot be muxed there. This is an unfortunate result of evolution and fixing thousands boards in hardware would be too expensive.

So here we are. I'm not pushing for inclusion to mainline, but parhaps this could be usefull for others. You decide.

In case you'll find it usefull, I'm ready to solve any objections and comments.

Ladislav Michl (2):
Input: gpio-beeper: use helper variable to access device info
Input: gpio-beeper: drive beeper pin by hrtimer

 Documentation/devicetree/bindings/input/gpio-beeper.txt |    5 
 drivers/input/misc/gpio-beeper.c                        |   99 +++++++++++++---
 2 files changed, 91 insertions(+), 13 deletions(-)
#1 lore raw

PATCH 1/2 Input: gpio-beeper: use helper variable to access device info

Using explicit struct device variable makes code a bit more readable.

---
Note: and it become more usefull one patch later

 drivers/input/misc/gpio-beeper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/input/misc/gpio-beeper.c +4 -3
index 16272fffeb7e..409c85da71c3 100644
@@ -64,18 +64,19 @@ static void gpio_beeper_close(struct input_dev *input)
 
 static int gpio_beeper_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct gpio_beeper *beep;
 	struct input_dev *input;
 
-	beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL);
+	beep = devm_kzalloc(dev, sizeof(*beep), GFP_KERNEL);
 	if (!beep)
 		return -ENOMEM;
 
-	beep->desc = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW);
+	beep->desc = devm_gpiod_get(dev, NULL, GPIOD_OUT_LOW);
 	if (IS_ERR(beep->desc))
 		return PTR_ERR(beep->desc);
 
-	input = devm_input_allocate_device(&pdev->dev);
+	input = devm_input_allocate_device(dev);
 	if (!input)
 		return -ENOMEM;
 
Signature · 1 line
2.15.0
#2 lore raw

PATCH 2/2 Input: gpio-beeper: drive beeper pin by hrtimer

In reply to Ladislav Michl

This is poor man's solution for those who cannot use pwm-beeper. Beeper pin is driven by hrtimer, so hearable jitter is expected, but should be acceptable for frequencies under 1kHz. This mode is enabled by adding 'beeper-hz' node property.

---
 .../devicetree/bindings/input/gpio-beeper.txt      |  5 ++
 drivers/input/misc/gpio-beeper.c                   | 92 +++++++++++++++++++---
 2 files changed, 87 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/input/gpio-beeper.txt +5 -0
index a5086e37fce6..855f8cf8af10 100644
@@ -6,6 +6,11 @@ Required properties:
 - compatible:	Should be "gpio-beeper".
 - gpios:	From common gpio binding; gpio connection to beeper enable pin.
 
+Optional properties:
+- beeper-hz:	Bell frequency in Hz. This option enables hrtimer driven beeper
+		pin toggle. This is only good for poorly designed hardware
+		where PWM cannot be used as there always be hearable jitter.
+
 Example:
 	beeper: beeper {
 		compatible = "gpio-beeper";
drivers/input/misc/gpio-beeper.c +82 -10

143 lines not on this page · raw message

Signature · 1 line
2.15.0