Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Driver for buttons on GPIO lines not capable of generating interrupts
4 *
5 * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
7 *
8 * This file was based on: /drivers/input/misc/cobalt_btns.c
9 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
10 *
11 * also was based on: /drivers/input/keyboard/gpio_keys.c
12 * Copyright 2005 Phil Blundell
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/slab.h>
18#include <linux/input.h>
19#include <linux/ioport.h>
20#include <linux/platform_device.h>
21#include <linux/gpio.h>
22#include <linux/gpio/consumer.h>
23#include <linux/gpio_keys.h>
24#include <linux/property.h>
25
26#define DRV_NAME "gpio-keys-polled"
27
28struct gpio_keys_button_data {
29 struct gpio_desc *gpiod;
30 int last_state;
31 int count;
32 int threshold;
33};
34
35struct gpio_keys_polled_dev {
36 struct input_dev *input;
37 struct device *dev;
38 const struct gpio_keys_platform_data *pdata;
39 unsigned long rel_axis_seen[BITS_TO_LONGS(REL_CNT)];
40 unsigned long abs_axis_seen[BITS_TO_LONGS(ABS_CNT)];
41 struct gpio_keys_button_data data[];
42};
43
44static void gpio_keys_button_event(struct input_dev *input,
45 const struct gpio_keys_button *button,
46 int state)
47{
48 struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
49 unsigned int type = button->type ?: EV_KEY;
50
51 if (type == EV_REL) {
52 if (state) {
53 input_event(input, type, button->code, button->value);
54 __set_bit(button->code, bdev->rel_axis_seen);
55 }
56 } else if (type == EV_ABS) {
57 if (state) {
58 input_event(input, type, button->code, button->value);
59 __set_bit(button->code, bdev->abs_axis_seen);
60 }
61 } else {
62 input_event(input, type, button->code, state);
63 input_sync(input);
64 }
65}
66
67static void gpio_keys_polled_check_state(struct input_dev *input,
68 const struct gpio_keys_button *button,
69 struct gpio_keys_button_data *bdata)
70{
71 int state;
72
73 state = gpiod_get_value_cansleep(bdata->gpiod);
74 if (state < 0) {
75 dev_err(input->dev.parent,
76 "failed to get gpio state: %d\n", state);
77 } else {
78 gpio_keys_button_event(input, button, state);
79
80 if (state != bdata->last_state) {
81 bdata->count = 0;
82 bdata->last_state = state;
83 }
84 }
85}
86
87static void gpio_keys_polled_poll(struct input_dev *input)
88{
89 struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
90 const struct gpio_keys_platform_data *pdata = bdev->pdata;
91 int i;
92
93 memset(bdev->rel_axis_seen, 0, sizeof(bdev->rel_axis_seen));
94 memset(bdev->abs_axis_seen, 0, sizeof(bdev->abs_axis_seen));
95
96 for (i = 0; i < pdata->nbuttons; i++) {
97 struct gpio_keys_button_data *bdata = &bdev->data[i];
98
99 if (bdata->count < bdata->threshold) {
100 bdata->count++;
101 gpio_keys_button_event(input, &pdata->buttons[i],
102 bdata->last_state);
103 } else {
104 gpio_keys_polled_check_state(input, &pdata->buttons[i],
105 bdata);
106 }
107 }
108
109 for_each_set_bit(i, input->relbit, REL_CNT) {
110 if (!test_bit(i, bdev->rel_axis_seen))
111 input_event(input, EV_REL, i, 0);
112 }
113
114 for_each_set_bit(i, input->absbit, ABS_CNT) {
115 if (!test_bit(i, bdev->abs_axis_seen))
116 input_event(input, EV_ABS, i, 0);
117 }
118
119 input_sync(input);
120}
121
122static int gpio_keys_polled_open(struct input_dev *input)
123{
124 struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
125 const struct gpio_keys_platform_data *pdata = bdev->pdata;
126
127 if (pdata->enable)
128 pdata->enable(bdev->dev);
129
130 return 0;
131}
132
133static void gpio_keys_polled_close(struct input_dev *input)
134{
135 struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
136 const struct gpio_keys_platform_data *pdata = bdev->pdata;
137
138 if (pdata->disable)
139 pdata->disable(bdev->dev);
140}
141
142static struct gpio_keys_platform_data *
143gpio_keys_polled_get_devtree_pdata(struct device *dev)
144{
145 struct gpio_keys_platform_data *pdata;
146 struct gpio_keys_button *button;
147 struct fwnode_handle *child;
148 int nbuttons;
149
150 nbuttons = device_get_child_node_count(dev);
151 if (nbuttons == 0)
152 return ERR_PTR(-EINVAL);
153
154 pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * sizeof(*button),
155 GFP_KERNEL);
156 if (!pdata)
157 return ERR_PTR(-ENOMEM);
158
159 button = (struct gpio_keys_button *)(pdata + 1);
160
161 pdata->buttons = button;
162 pdata->nbuttons = nbuttons;
163
164 pdata->rep = device_property_present(dev, "autorepeat");
165 device_property_read_u32(dev, "poll-interval", &pdata->poll_interval);
166
167 device_property_read_string(dev, "label", &pdata->name);
168
169 device_for_each_child_node(dev, child) {
170 if (fwnode_property_read_u32(child, "linux,code",
171 &button->code)) {
172 dev_err(dev, "button without keycode\n");
173 fwnode_handle_put(child);
174 return ERR_PTR(-EINVAL);
175 }
176
177 fwnode_property_read_string(child, "label", &button->desc);
178
179 if (fwnode_property_read_u32(child, "linux,input-type",
180 &button->type))
181 button->type = EV_KEY;
182
183 if (fwnode_property_read_u32(child, "linux,input-value",
184 (u32 *)&button->value))
185 button->value = 1;
186
187 button->wakeup =
188 fwnode_property_read_bool(child, "wakeup-source") ||
189 /* legacy name */
190 fwnode_property_read_bool(child, "gpio-key,wakeup");
191
192 if (fwnode_property_read_u32(child, "debounce-interval",
193 &button->debounce_interval))
194 button->debounce_interval = 5;
195
196 button++;
197 }
198
199 return pdata;
200}
201
202static void gpio_keys_polled_set_abs_params(struct input_dev *input,
203 const struct gpio_keys_platform_data *pdata, unsigned int code)
204{
205 int i, min = 0, max = 0;
206
207 for (i = 0; i < pdata->nbuttons; i++) {
208 const struct gpio_keys_button *button = &pdata->buttons[i];
209
210 if (button->type != EV_ABS || button->code != code)
211 continue;
212
213 if (button->value < min)
214 min = button->value;
215 if (button->value > max)
216 max = button->value;
217 }
218
219 input_set_abs_params(input, code, min, max, 0, 0);
220}
221
222static const struct of_device_id gpio_keys_polled_of_match[] = {
223 { .compatible = "gpio-keys-polled", },
224 { },
225};
226MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
227
228static int gpio_keys_polled_probe(struct platform_device *pdev)
229{
230 struct device *dev = &pdev->dev;
231 struct fwnode_handle *child = NULL;
232 const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
233 struct gpio_keys_polled_dev *bdev;
234 struct input_dev *input;
235 int error;
236 int i;
237
238 if (!pdata) {
239 pdata = gpio_keys_polled_get_devtree_pdata(dev);
240 if (IS_ERR(pdata))
241 return PTR_ERR(pdata);
242 }
243
244 if (!pdata->poll_interval) {
245 dev_err(dev, "missing poll_interval value\n");
246 return -EINVAL;
247 }
248
249 bdev = devm_kzalloc(dev, struct_size(bdev, data, pdata->nbuttons),
250 GFP_KERNEL);
251 if (!bdev) {
252 dev_err(dev, "no memory for private data\n");
253 return -ENOMEM;
254 }
255
256 input = devm_input_allocate_device(dev);
257 if (!input) {
258 dev_err(dev, "no memory for input device\n");
259 return -ENOMEM;
260 }
261
262 input_set_drvdata(input, bdev);
263
264 input->name = pdata->name ?: pdev->name;
265 input->phys = DRV_NAME"/input0";
266
267 input->id.bustype = BUS_HOST;
268 input->id.vendor = 0x0001;
269 input->id.product = 0x0001;
270 input->id.version = 0x0100;
271
272 input->open = gpio_keys_polled_open;
273 input->close = gpio_keys_polled_close;
274
275 __set_bit(EV_KEY, input->evbit);
276 if (pdata->rep)
277 __set_bit(EV_REP, input->evbit);
278
279 for (i = 0; i < pdata->nbuttons; i++) {
280 const struct gpio_keys_button *button = &pdata->buttons[i];
281 struct gpio_keys_button_data *bdata = &bdev->data[i];
282 unsigned int type = button->type ?: EV_KEY;
283
284 if (button->wakeup) {
285 dev_err(dev, DRV_NAME " does not support wakeup\n");
286 fwnode_handle_put(child);
287 return -EINVAL;
288 }
289
290 if (!dev_get_platdata(dev)) {
291 /* No legacy static platform data */
292 child = device_get_next_child_node(dev, child);
293 if (!child) {
294 dev_err(dev, "missing child device node\n");
295 return -EINVAL;
296 }
297
298 bdata->gpiod = devm_fwnode_gpiod_get(dev, child,
299 NULL, GPIOD_IN,
300 button->desc);
301 if (IS_ERR(bdata->gpiod)) {
302 fwnode_handle_put(child);
303 return dev_err_probe(dev, PTR_ERR(bdata->gpiod),
304 "failed to get gpio\n");
305 }
306 } else if (gpio_is_valid(button->gpio)) {
307 /*
308 * Legacy GPIO number so request the GPIO here and
309 * convert it to descriptor.
310 */
311 unsigned flags = GPIOF_IN;
312
313 if (button->active_low)
314 flags |= GPIOF_ACTIVE_LOW;
315
316 error = devm_gpio_request_one(dev, button->gpio,
317 flags, button->desc ? : DRV_NAME);
318 if (error)
319 return dev_err_probe(dev, error,
320 "unable to claim gpio %u\n",
321 button->gpio);
322
323 bdata->gpiod = gpio_to_desc(button->gpio);
324 if (!bdata->gpiod) {
325 dev_err(dev,
326 "unable to convert gpio %u to descriptor\n",
327 button->gpio);
328 return -EINVAL;
329 }
330 }
331
332 bdata->last_state = -1;
333 bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
334 pdata->poll_interval);
335
336 input_set_capability(input, type, button->code);
337 if (type == EV_ABS)
338 gpio_keys_polled_set_abs_params(input, pdata,
339 button->code);
340 }
341
342 fwnode_handle_put(child);
343
344 bdev->input = input;
345 bdev->dev = dev;
346 bdev->pdata = pdata;
347
348 error = input_setup_polling(input, gpio_keys_polled_poll);
349 if (error) {
350 dev_err(dev, "unable to set up polling, err=%d\n", error);
351 return error;
352 }
353
354 input_set_poll_interval(input, pdata->poll_interval);
355
356 error = input_register_device(input);
357 if (error) {
358 dev_err(dev, "unable to register polled device, err=%d\n",
359 error);
360 return error;
361 }
362
363 /* report initial state of the buttons */
364 for (i = 0; i < pdata->nbuttons; i++)
365 gpio_keys_polled_check_state(input, &pdata->buttons[i],
366 &bdev->data[i]);
367
368 input_sync(input);
369
370 return 0;
371}
372
373static struct platform_driver gpio_keys_polled_driver = {
374 .probe = gpio_keys_polled_probe,
375 .driver = {
376 .name = DRV_NAME,
377 .of_match_table = gpio_keys_polled_of_match,
378 },
379};
380module_platform_driver(gpio_keys_polled_driver);
381
382MODULE_LICENSE("GPL v2");
383MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
384MODULE_DESCRIPTION("Polled GPIO Buttons driver");
385MODULE_ALIAS("platform:" DRV_NAME);
1/*
2 * Driver for buttons on GPIO lines not capable of generating interrupts
3 *
4 * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
6 *
7 * This file was based on: /drivers/input/misc/cobalt_btns.c
8 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
9 *
10 * also was based on: /drivers/input/keyboard/gpio_keys.c
11 * Copyright 2005 Phil Blundell
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/input.h>
22#include <linux/input-polldev.h>
23#include <linux/ioport.h>
24#include <linux/platform_device.h>
25#include <linux/gpio.h>
26#include <linux/gpio/consumer.h>
27#include <linux/gpio_keys.h>
28#include <linux/property.h>
29
30#define DRV_NAME "gpio-keys-polled"
31
32struct gpio_keys_button_data {
33 int last_state;
34 int count;
35 int threshold;
36 int can_sleep;
37};
38
39struct gpio_keys_polled_dev {
40 struct input_polled_dev *poll_dev;
41 struct device *dev;
42 const struct gpio_keys_platform_data *pdata;
43 unsigned long rel_axis_seen[BITS_TO_LONGS(REL_CNT)];
44 unsigned long abs_axis_seen[BITS_TO_LONGS(ABS_CNT)];
45 struct gpio_keys_button_data data[0];
46};
47
48static void gpio_keys_button_event(struct input_polled_dev *dev,
49 struct gpio_keys_button *button,
50 int state)
51{
52 struct gpio_keys_polled_dev *bdev = dev->private;
53 struct input_dev *input = dev->input;
54 unsigned int type = button->type ?: EV_KEY;
55
56 if (type == EV_REL) {
57 if (state) {
58 input_event(input, type, button->code, button->value);
59 __set_bit(button->code, bdev->rel_axis_seen);
60 }
61 } else if (type == EV_ABS) {
62 if (state) {
63 input_event(input, type, button->code, button->value);
64 __set_bit(button->code, bdev->abs_axis_seen);
65 }
66 } else {
67 input_event(input, type, button->code, state);
68 input_sync(input);
69 }
70}
71
72static void gpio_keys_polled_check_state(struct input_polled_dev *dev,
73 struct gpio_keys_button *button,
74 struct gpio_keys_button_data *bdata)
75{
76 int state;
77
78 if (bdata->can_sleep)
79 state = !!gpiod_get_value_cansleep(button->gpiod);
80 else
81 state = !!gpiod_get_value(button->gpiod);
82
83 gpio_keys_button_event(dev, button, state);
84
85 if (state != bdata->last_state) {
86 bdata->count = 0;
87 bdata->last_state = state;
88 }
89}
90
91static void gpio_keys_polled_poll(struct input_polled_dev *dev)
92{
93 struct gpio_keys_polled_dev *bdev = dev->private;
94 const struct gpio_keys_platform_data *pdata = bdev->pdata;
95 struct input_dev *input = dev->input;
96 int i;
97
98 memset(bdev->rel_axis_seen, 0, sizeof(bdev->rel_axis_seen));
99 memset(bdev->abs_axis_seen, 0, sizeof(bdev->abs_axis_seen));
100
101 for (i = 0; i < pdata->nbuttons; i++) {
102 struct gpio_keys_button_data *bdata = &bdev->data[i];
103
104 if (bdata->count < bdata->threshold) {
105 bdata->count++;
106 gpio_keys_button_event(dev, &pdata->buttons[i],
107 bdata->last_state);
108 } else {
109 gpio_keys_polled_check_state(dev, &pdata->buttons[i],
110 bdata);
111 }
112 }
113
114 for_each_set_bit(i, input->relbit, REL_CNT) {
115 if (!test_bit(i, bdev->rel_axis_seen))
116 input_event(input, EV_REL, i, 0);
117 }
118
119 for_each_set_bit(i, input->absbit, ABS_CNT) {
120 if (!test_bit(i, bdev->abs_axis_seen))
121 input_event(input, EV_ABS, i, 0);
122 }
123
124 input_sync(input);
125}
126
127static void gpio_keys_polled_open(struct input_polled_dev *dev)
128{
129 struct gpio_keys_polled_dev *bdev = dev->private;
130 const struct gpio_keys_platform_data *pdata = bdev->pdata;
131
132 if (pdata->enable)
133 pdata->enable(bdev->dev);
134}
135
136static void gpio_keys_polled_close(struct input_polled_dev *dev)
137{
138 struct gpio_keys_polled_dev *bdev = dev->private;
139 const struct gpio_keys_platform_data *pdata = bdev->pdata;
140
141 if (pdata->disable)
142 pdata->disable(bdev->dev);
143}
144
145static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev)
146{
147 struct gpio_keys_platform_data *pdata;
148 struct gpio_keys_button *button;
149 struct fwnode_handle *child;
150 int error;
151 int nbuttons;
152
153 nbuttons = device_get_child_node_count(dev);
154 if (nbuttons == 0)
155 return NULL;
156
157 pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * sizeof(*button),
158 GFP_KERNEL);
159 if (!pdata)
160 return ERR_PTR(-ENOMEM);
161
162 pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
163
164 pdata->rep = device_property_present(dev, "autorepeat");
165 device_property_read_u32(dev, "poll-interval", &pdata->poll_interval);
166
167 device_for_each_child_node(dev, child) {
168 struct gpio_desc *desc;
169
170 desc = devm_get_gpiod_from_child(dev, NULL, child);
171 if (IS_ERR(desc)) {
172 error = PTR_ERR(desc);
173 if (error != -EPROBE_DEFER)
174 dev_err(dev,
175 "Failed to get gpio flags, error: %d\n",
176 error);
177 fwnode_handle_put(child);
178 return ERR_PTR(error);
179 }
180
181 button = &pdata->buttons[pdata->nbuttons++];
182 button->gpiod = desc;
183
184 if (fwnode_property_read_u32(child, "linux,code", &button->code)) {
185 dev_err(dev, "Button without keycode: %d\n",
186 pdata->nbuttons - 1);
187 fwnode_handle_put(child);
188 return ERR_PTR(-EINVAL);
189 }
190
191 fwnode_property_read_string(child, "label", &button->desc);
192
193 if (fwnode_property_read_u32(child, "linux,input-type",
194 &button->type))
195 button->type = EV_KEY;
196
197 if (fwnode_property_read_u32(child, "linux,input-value",
198 (u32 *)&button->value))
199 button->value = 1;
200
201 button->wakeup =
202 fwnode_property_read_bool(child, "wakeup-source") ||
203 /* legacy name */
204 fwnode_property_read_bool(child, "gpio-key,wakeup");
205
206 if (fwnode_property_read_u32(child, "debounce-interval",
207 &button->debounce_interval))
208 button->debounce_interval = 5;
209 }
210
211 if (pdata->nbuttons == 0)
212 return ERR_PTR(-EINVAL);
213
214 return pdata;
215}
216
217static void gpio_keys_polled_set_abs_params(struct input_dev *input,
218 const struct gpio_keys_platform_data *pdata, unsigned int code)
219{
220 int i, min = 0, max = 0;
221
222 for (i = 0; i < pdata->nbuttons; i++) {
223 struct gpio_keys_button *button = &pdata->buttons[i];
224
225 if (button->type != EV_ABS || button->code != code)
226 continue;
227
228 if (button->value < min)
229 min = button->value;
230 if (button->value > max)
231 max = button->value;
232 }
233 input_set_abs_params(input, code, min, max, 0, 0);
234}
235
236static const struct of_device_id gpio_keys_polled_of_match[] = {
237 { .compatible = "gpio-keys-polled", },
238 { },
239};
240MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
241
242static int gpio_keys_polled_probe(struct platform_device *pdev)
243{
244 struct device *dev = &pdev->dev;
245 const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
246 struct gpio_keys_polled_dev *bdev;
247 struct input_polled_dev *poll_dev;
248 struct input_dev *input;
249 size_t size;
250 int error;
251 int i;
252
253 if (!pdata) {
254 pdata = gpio_keys_polled_get_devtree_pdata(dev);
255 if (IS_ERR(pdata))
256 return PTR_ERR(pdata);
257 if (!pdata) {
258 dev_err(dev, "missing platform data\n");
259 return -EINVAL;
260 }
261 }
262
263 if (!pdata->poll_interval) {
264 dev_err(dev, "missing poll_interval value\n");
265 return -EINVAL;
266 }
267
268 size = sizeof(struct gpio_keys_polled_dev) +
269 pdata->nbuttons * sizeof(struct gpio_keys_button_data);
270 bdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
271 if (!bdev) {
272 dev_err(dev, "no memory for private data\n");
273 return -ENOMEM;
274 }
275
276 poll_dev = devm_input_allocate_polled_device(&pdev->dev);
277 if (!poll_dev) {
278 dev_err(dev, "no memory for polled device\n");
279 return -ENOMEM;
280 }
281
282 poll_dev->private = bdev;
283 poll_dev->poll = gpio_keys_polled_poll;
284 poll_dev->poll_interval = pdata->poll_interval;
285 poll_dev->open = gpio_keys_polled_open;
286 poll_dev->close = gpio_keys_polled_close;
287
288 input = poll_dev->input;
289
290 input->name = pdev->name;
291 input->phys = DRV_NAME"/input0";
292
293 input->id.bustype = BUS_HOST;
294 input->id.vendor = 0x0001;
295 input->id.product = 0x0001;
296 input->id.version = 0x0100;
297
298 __set_bit(EV_KEY, input->evbit);
299 if (pdata->rep)
300 __set_bit(EV_REP, input->evbit);
301
302 for (i = 0; i < pdata->nbuttons; i++) {
303 struct gpio_keys_button *button = &pdata->buttons[i];
304 struct gpio_keys_button_data *bdata = &bdev->data[i];
305 unsigned int type = button->type ?: EV_KEY;
306
307 if (button->wakeup) {
308 dev_err(dev, DRV_NAME " does not support wakeup\n");
309 return -EINVAL;
310 }
311
312 /*
313 * Legacy GPIO number so request the GPIO here and
314 * convert it to descriptor.
315 */
316 if (!button->gpiod && gpio_is_valid(button->gpio)) {
317 unsigned flags = GPIOF_IN;
318
319 if (button->active_low)
320 flags |= GPIOF_ACTIVE_LOW;
321
322 error = devm_gpio_request_one(&pdev->dev, button->gpio,
323 flags, button->desc ? : DRV_NAME);
324 if (error) {
325 dev_err(dev, "unable to claim gpio %u, err=%d\n",
326 button->gpio, error);
327 return error;
328 }
329
330 button->gpiod = gpio_to_desc(button->gpio);
331 }
332
333 if (IS_ERR(button->gpiod))
334 return PTR_ERR(button->gpiod);
335
336 bdata->can_sleep = gpiod_cansleep(button->gpiod);
337 bdata->last_state = -1;
338 bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
339 pdata->poll_interval);
340
341 input_set_capability(input, type, button->code);
342 if (type == EV_ABS)
343 gpio_keys_polled_set_abs_params(input, pdata,
344 button->code);
345 }
346
347 bdev->poll_dev = poll_dev;
348 bdev->dev = dev;
349 bdev->pdata = pdata;
350 platform_set_drvdata(pdev, bdev);
351
352 error = input_register_polled_device(poll_dev);
353 if (error) {
354 dev_err(dev, "unable to register polled device, err=%d\n",
355 error);
356 return error;
357 }
358
359 /* report initial state of the buttons */
360 for (i = 0; i < pdata->nbuttons; i++)
361 gpio_keys_polled_check_state(poll_dev, &pdata->buttons[i],
362 &bdev->data[i]);
363
364 input_sync(input);
365
366 return 0;
367}
368
369static struct platform_driver gpio_keys_polled_driver = {
370 .probe = gpio_keys_polled_probe,
371 .driver = {
372 .name = DRV_NAME,
373 .of_match_table = gpio_keys_polled_of_match,
374 },
375};
376module_platform_driver(gpio_keys_polled_driver);
377
378MODULE_LICENSE("GPL v2");
379MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
380MODULE_DESCRIPTION("Polled GPIO Buttons driver");
381MODULE_ALIAS("platform:" DRV_NAME);