aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc/gpio-beeper.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/misc/gpio-beeper.c')
-rw-r--r--drivers/input/misc/gpio-beeper.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/drivers/input/misc/gpio-beeper.c b/drivers/input/misc/gpio-beeper.c
index b757435e2b3d..8886af63eae3 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
20struct gpio_beeper { 21struct 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
27static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on) 27static 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
32static void gpio_beeper_work(struct work_struct *work) 32static void gpio_beeper_work(struct work_struct *work)
@@ -65,18 +65,16 @@ static void gpio_beeper_close(struct input_dev *input)
65static int gpio_beeper_probe(struct platform_device *pdev) 65static 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
109static struct of_device_id gpio_beeper_of_match[] = { 104#ifdef CONFIG_OF
105static const struct of_device_id gpio_beeper_of_match[] = {
110 { .compatible = BEEPER_MODNAME, }, 106 { .compatible = BEEPER_MODNAME, },
111 { } 107 { }
112}; 108};
113MODULE_DEVICE_TABLE(of, gpio_beeper_of_match); 109MODULE_DEVICE_TABLE(of, gpio_beeper_of_match);
110#endif
114 111
115static struct platform_driver gpio_beeper_platform_driver = { 112static 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};