input: Add new driver for GPIO beeper
Subsystems (3)
PATCH v2 1/1 input: Add new driver for GPIO beeper
This patch adds a new driver for the beeper controlled via GPIO pin. The driver does not depend on the architecture and is positioned as a replacement for the specific drivers that are used for this function.
--- .../devicetree/bindings/input/gpio-beeper.txt | 13 +++ drivers/input/misc/Kconfig | 9 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/gpio-beeper.c | 127 +++++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/gpio-beeper.txt create mode 100644 drivers/input/misc/gpio-beeper.c
Documentation/devicetree/bindings/input/gpio-beeper.txt new file +13 -0
@@ -0,0 +1,13 @@ +* GPIO beeper device tree bindings + +Register a beeper connected to GPIO pin. + +Required properties: +- compatible: Should be "gpio-beeper". +- gpios: From common gpio binding; gpio connection to beeper enable pin. + +Example: + beeper: beeper { + compatible = "gpio-beeper"; + gpios = <&gpio3 23 GPIO_ACTIVE_HIGH>; + };
drivers/input/misc/Kconfig +9 -0
@@ -222,6 +222,15 @@ config INPUT_GP2A To compile this driver as a module, choose M here: the module will be called gp2ap002a00f. +config INPUT_GPIO_BEEPER + tristate "Generic GPIO Beeper support" + depends on OF_GPIO + help + Say Y here if you have a beeper connected to a GPIO pin. + + To compile this driver as a module, choose M here: the + module will be called gpio-beeper. + config INPUT_GPIO_TILT_POLLED tristate "Polled GPIO tilt switch" depends on GPIOLIB
drivers/input/misc/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_DA9052_ONKEY) += da9052_onkey.o obj-$(CONFIG_INPUT_DA9055_ONKEY) += da9055_onkey.o obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o +obj-$(CONFIG_INPUT_GPIO_BEEPER) += gpio-beeper.o obj-$(CONFIG_INPUT_GPIO_TILT_POLLED) += gpio_tilt_polled.o obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o obj-$(CONFIG_INPUT_IMS_PCU) += ims-pcu.o
drivers/input/misc/gpio-beeper.c new file +127 -0
127 lines not on this page · raw message
Signature · 6 lines
1.8.3.2 -- 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
Quoted 5 lines · Alexander Shiyan
This patch adds a new driver for the beeper controlled via GPIO pin. The driver does not depend on the architecture and is positioned as a replacement for the specific drivers that are used for this function.
Signed-off-by Alexander Shiyan <[email protected]>
Hi Alexander
I just tried this driver out on a board port i will soon be contributing. Works for me. Please add a
Has the Input maintainer picked it up for the next merge window?
Thanks
Andrew
Quoted 194 lines
---
.../devicetree/bindings/input/gpio-beeper.txt| 13 +++drivers/input/misc/Kconfig | 9 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/gpio-beeper.c | 127 +++++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/gpio-beeper.txt create mode 100644 drivers/input/misc/gpio-beeper.cDocumentation/devicetree/bindings/input/gpio-beeper.txt new file +13
-0@@ -0,0 +1,13 @@ +* GPIO beeper device tree bindings + +Register a beeper connected to GPIO pin. + +Required properties: +- compatible: Should be "gpio-beeper". +- gpios: From common gpio binding; gpio connection to beeper enable pin. + +Example: + beeper: beeper { + compatible = "gpio-beeper"; + gpios = <&gpio3 23 GPIO_ACTIVE_HIGH>; + };drivers/input/misc/Kconfig +9
-0@@ -222,6 +222,15 @@ config INPUT_GP2A To compile this driver as a module, choose M here: the module will be called gp2ap002a00f. +config INPUT_GPIO_BEEPER + tristate "Generic GPIO Beeper support" + depends on OF_GPIO + help + Say Y here if you have a beeper connected to a GPIO pin. + + To compile this driver as a module, choose M here: the + module will be called gpio-beeper. + config INPUT_GPIO_TILT_POLLED tristate "Polled GPIO tilt switch" depends on GPIOLIBdrivers/input/misc/Makefile +1
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_DA9052_ONKEY) += da9052_onkey.o obj-$(CONFIG_INPUT_DA9055_ONKEY) += da9055_onkey.o obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o +obj-$(CONFIG_INPUT_GPIO_BEEPER) += gpio-beeper.o obj-$(CONFIG_INPUT_GPIO_TILT_POLLED) += gpio_tilt_polled.o obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o obj-$(CONFIG_INPUT_IMS_PCU) += ims-pcu.odrivers/input/misc/gpio-beeper.c new file +127
-0@@ -0,0 +1,127 @@ +/* +* Generic GPIO beeper driver +* +* Copyright (C) 2013 Alexander Shiyan <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/input.h> +#include <linux/module.h> +#include <linux/of_gpio.h> +#include <linux/workqueue.h> +#include <linux/platform_device.h> + +#define BEEPER_MODNAME "gpio-beeper" + +struct gpio_beeper { +struct work_struct work; +int gpio; +bool active_low; +bool beeping; +}; + +static void gpio_beeper_toggle (struct gpio_beeper *beep,bool on) +{ +gpio_set_value_cansleep (beep->gpio, on ^ beep->active_low); +} + +static void gpio_beeper_work (struct work_struct *work) +{ + struct gpio_beeper *beep = container_of(work, struct gpio_beeper, work); + +gpio_beeper_toggle (beep, beep->beeping); +} + +static int gpio_beeper_event (struct input_dev *dev,unsigned int type, +unsigned int code,int value) +{ +struct gpio_beeper *beep =input_get_drvdata (dev); + +if (type !=EV_SND || code !=SND_BELL ) +return -ENOTSUPP ; + +if (value <0 ) +return -EINVAL ; + + beep->beeping = value; +/* Schedule work to actually turn the beeper on or off */ +schedule_work (&beep->work); + +return 0 ; +} + +static void gpio_beeper_close (struct input_dev *input) +{ +struct gpio_beeper *beep =input_get_drvdata (input); + +cancel_work_sync (&beep->work); +gpio_beeper_toggle (beep, false); +} + +static int gpio_beeper_probe (struct platform_device *pdev) +{ +struct gpio_beeper *beep; +enum of_gpio_flags flags; +struct input_dev *input; +unsigned long gflags; +int err; + + beep =devm_kzalloc (&pdev->dev,sizeof (*beep),GFP_KERNEL ); +if (!beep) +return -ENOMEM ; + + beep->gpio =of_get_gpio_flags (pdev->dev.of_node,0 , &flags); +if (!gpio_is_valid (beep->gpio)) +return beep->gpio; + + input =devm_input_allocate_device (&pdev->dev); +if (!input) +return -ENOMEM ; + +INIT_WORK (&beep->work, gpio_beeper_work); + + input->name = pdev->name; + input->id.bustype =BUS_HOST ; + input->id.vendor =0x0001 ; + input->id.product =0x0001 ; + input->id.version =0x0100 ; + input->close = gpio_beeper_close; + input->event = gpio_beeper_event; + +input_set_capability (input,EV_SND ,SND_BELL ); + + beep->active_low = flags &OF_GPIO_ACTIVE_LOW ; + gflags = beep->active_low ?GPIOF_OUT_INIT_HIGH :GPIOF_OUT_INIT_LOW ; + + err =devm_gpio_request_one (&pdev->dev, beep->gpio, gflags, pdev->name); +if (err) +return err; + +input_set_drvdata (input, beep); + +return input_register_device (input); +} + +static struct of_device_id gpio_beeper_of_match[] = { + { .compatible =BEEPER_MODNAME , }, + { } +}; +MODULE_DEVICE_TABLE (of, gpio_beeper_of_match); + +static struct platform_driver gpio_beeper_platform_driver = { + .driver = { + .name =BEEPER_MODNAME , + .owner =THIS_MODULE , + .of_match_table = gpio_beeper_of_match, + }, + .probe = gpio_beeper_probe, +}; +module_platform_driver (gpio_beeper_platform_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Alexander Shiyan <[email protected]>" ); +MODULE_DESCRIPTION ("Generic GPIO beeper driver" );
Hello.
Quoted 7 lines · Alexander Shiyan
Quoted 5 lines
This patch adds a new driver for the beeper controlled via GPIO pin. The driver does not depend on the architecture and is positioned as a replacement for the specific drivers that are used for this function.
Signed-off-by Alexander Shiyan <[email protected]>
Quoted 8 lines
Hi Alexander
I just tried this driver out on a board port i will soon be contributing. Works for me. Please add a
Tested-by Andrew Lunn <[email protected]>Has the Input maintainer picked it up for the next merge window?
AFAIK, this driver is already merged in the "-next" kernel tree.
---