Input: gpio-beeper: drive output by hrtimer
Subsystems (3)
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(-)
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
@@ -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
PATCH 2/2 Input: gpio-beeper: drive beeper pin by hrtimer
In reply to Ladislav MichlThis 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
@@ -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