diff options
| author | Alexander Shiyan <shc_work@mail.ru> | 2014-04-26 02:45:05 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-05-14 19:39:51 -0400 |
| commit | c95dc0114bb66c7cbfa91b7bea898e07fcff5157 (patch) | |
| tree | 3f82bcea3bfd6adf99c900dfbaec06e0e0122fe7 /drivers/input/misc | |
| parent | 99e8325f55f2dfea32430fd71a546485a2aedbae (diff) | |
Input: gpio-beeper - simplify GPIO handling
This patch simplifies GPIO handling in the driver by using GPIO functions
based on descriptors. As a result this driver now can be used for boards
without DT support.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc')
| -rw-r--r-- | drivers/input/misc/Kconfig | 2 | ||||
| -rw-r--r-- | drivers/input/misc/gpio-beeper.c | 27 |
2 files changed, 13 insertions, 16 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index f772981bdcdb..05ae7e7cddde 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
| @@ -224,7 +224,7 @@ config INPUT_GP2A | |||
| 224 | 224 | ||
| 225 | config INPUT_GPIO_BEEPER | 225 | config INPUT_GPIO_BEEPER |
| 226 | tristate "Generic GPIO Beeper support" | 226 | tristate "Generic GPIO Beeper support" |
| 227 | depends on OF_GPIO | 227 | depends on GPIOLIB |
| 228 | help | 228 | help |
| 229 | Say Y here if you have a beeper connected to a GPIO pin. | 229 | Say Y here if you have a beeper connected to a GPIO pin. |
| 230 | 230 | ||
diff --git a/drivers/input/misc/gpio-beeper.c b/drivers/input/misc/gpio-beeper.c index b757435e2b3d..5ed50ddfacfc 100644 --- a/drivers/input/misc/gpio-beeper.c +++ b/drivers/input/misc/gpio-beeper.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Generic GPIO beeper driver | 2 | * Generic GPIO beeper driver |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru> | 4 | * Copyright (C) 2013-2014 Alexander Shiyan <shc_work@mail.ru> |
| 5 | * | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
| @@ -11,7 +11,8 @@ | |||
| 11 | 11 | ||
| 12 | #include <linux/input.h> | 12 | #include <linux/input.h> |
| 13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 14 | #include <linux/of_gpio.h> | 14 | #include <linux/gpio/consumer.h> |
| 15 | #include <linux/of.h> | ||
| 15 | #include <linux/workqueue.h> | 16 | #include <linux/workqueue.h> |
| 16 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
| 17 | 18 | ||
| @@ -19,14 +20,13 @@ | |||
| 19 | 20 | ||
| 20 | struct gpio_beeper { | 21 | struct gpio_beeper { |
| 21 | struct work_struct work; | 22 | struct work_struct work; |
| 22 | int gpio; | 23 | struct gpio_desc *desc; |
| 23 | bool active_low; | ||
| 24 | bool beeping; | 24 | bool beeping; |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on) | 27 | static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on) |
| 28 | { | 28 | { |
| 29 | gpio_set_value_cansleep(beep->gpio, on ^ beep->active_low); | 29 | gpiod_set_value_cansleep(beep->desc, on); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | static void gpio_beeper_work(struct work_struct *work) | 32 | static void gpio_beeper_work(struct work_struct *work) |
| @@ -65,18 +65,16 @@ static void gpio_beeper_close(struct input_dev *input) | |||
| 65 | static int gpio_beeper_probe(struct platform_device *pdev) | 65 | static int gpio_beeper_probe(struct platform_device *pdev) |
| 66 | { | 66 | { |
| 67 | struct gpio_beeper *beep; | 67 | struct gpio_beeper *beep; |
| 68 | enum of_gpio_flags flags; | ||
| 69 | struct input_dev *input; | 68 | struct input_dev *input; |
| 70 | unsigned long gflags; | ||
| 71 | int err; | 69 | int err; |
| 72 | 70 | ||
| 73 | beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL); | 71 | beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL); |
| 74 | if (!beep) | 72 | if (!beep) |
| 75 | return -ENOMEM; | 73 | return -ENOMEM; |
| 76 | 74 | ||
| 77 | beep->gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); | 75 | beep->desc = devm_gpiod_get(&pdev->dev, NULL); |
| 78 | if (!gpio_is_valid(beep->gpio)) | 76 | if (IS_ERR(beep->desc)) |
| 79 | return beep->gpio; | 77 | return PTR_ERR(beep->desc); |
| 80 | 78 | ||
| 81 | input = devm_input_allocate_device(&pdev->dev); | 79 | input = devm_input_allocate_device(&pdev->dev); |
| 82 | if (!input) | 80 | if (!input) |
| @@ -94,10 +92,7 @@ static int gpio_beeper_probe(struct platform_device *pdev) | |||
| 94 | 92 | ||
| 95 | input_set_capability(input, EV_SND, SND_BELL); | 93 | input_set_capability(input, EV_SND, SND_BELL); |
| 96 | 94 | ||
| 97 | beep->active_low = flags & OF_GPIO_ACTIVE_LOW; | 95 | err = gpiod_direction_output(beep->desc, 0); |
| 98 | gflags = beep->active_low ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
| 99 | |||
| 100 | err = devm_gpio_request_one(&pdev->dev, beep->gpio, gflags, pdev->name); | ||
| 101 | if (err) | 96 | if (err) |
| 102 | return err; | 97 | return err; |
| 103 | 98 | ||
| @@ -106,17 +101,19 @@ static int gpio_beeper_probe(struct platform_device *pdev) | |||
| 106 | return input_register_device(input); | 101 | return input_register_device(input); |
| 107 | } | 102 | } |
| 108 | 103 | ||
| 104 | #ifdef CONFIG_OF | ||
| 109 | static struct of_device_id gpio_beeper_of_match[] = { | 105 | static struct of_device_id gpio_beeper_of_match[] = { |
| 110 | { .compatible = BEEPER_MODNAME, }, | 106 | { .compatible = BEEPER_MODNAME, }, |
| 111 | { } | 107 | { } |
| 112 | }; | 108 | }; |
| 113 | MODULE_DEVICE_TABLE(of, gpio_beeper_of_match); | 109 | MODULE_DEVICE_TABLE(of, gpio_beeper_of_match); |
| 110 | #endif | ||
| 114 | 111 | ||
| 115 | static struct platform_driver gpio_beeper_platform_driver = { | 112 | static struct platform_driver gpio_beeper_platform_driver = { |
| 116 | .driver = { | 113 | .driver = { |
| 117 | .name = BEEPER_MODNAME, | 114 | .name = BEEPER_MODNAME, |
| 118 | .owner = THIS_MODULE, | 115 | .owner = THIS_MODULE, |
| 119 | .of_match_table = gpio_beeper_of_match, | 116 | .of_match_table = of_match_ptr(gpio_beeper_of_match), |
| 120 | }, | 117 | }, |
| 121 | .probe = gpio_beeper_probe, | 118 | .probe = gpio_beeper_probe, |
| 122 | }; | 119 | }; |
