18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/slab.h>
22 #include <linux/input.h>
31 #define DRV_NAME "gpio-keys-polled"
47 static void gpio_keys_polled_check_state(
struct input_dev *
input,
69 static void gpio_keys_polled_poll(
struct input_polled_dev *
dev)
73 struct input_dev *input = dev->input;
76 for (i = 0; i < pdata->
nbuttons; i++) {
82 gpio_keys_polled_check_state(input, &pdata->
buttons[i],
87 static void gpio_keys_polled_open(
struct input_polled_dev *dev)
96 static void gpio_keys_polled_close(
struct input_polled_dev *dev)
107 gpio_keys_polled_get_devtree_pdata(
struct device *dev)
120 nbuttons = of_get_child_count(node);
124 pdata = kzalloc(
sizeof(*pdata) + nbuttons * (
sizeof *button),
135 of_property_read_u32(node,
"poll-interval", &pdata->
poll_interval);
143 dev_warn(dev,
"Found button without gpios\n");
149 button->
gpio = of_get_gpio_flags(pp, 0, &flags);
152 if (of_property_read_u32(pp,
"linux,code", &button->
code)) {
153 dev_err(dev,
"Button without keycode: 0x%x\n",
161 if (of_property_read_u32(pp,
"linux,input-type", &button->
type))
166 if (of_property_read_u32(pp,
"debounce-interval",
181 return ERR_PTR(error);
184 static struct of_device_id gpio_keys_polled_of_match[] = {
193 gpio_keys_polled_get_devtree_pdata(
struct device *dev)
204 struct input_polled_dev *poll_dev;
205 struct input_dev *
input;
210 pdata = gpio_keys_polled_get_devtree_pdata(dev);
212 return PTR_ERR(pdata);
214 dev_err(dev,
"missing platform data\n");
220 dev_err(dev,
"missing poll_interval value\n");
229 dev_err(dev,
"no memory for private data\n");
236 dev_err(dev,
"no memory for polled device\n");
241 poll_dev->private = bdev;
242 poll_dev->poll = gpio_keys_polled_poll;
244 poll_dev->open = gpio_keys_polled_open;
245 poll_dev->close = gpio_keys_polled_close;
247 input = poll_dev->input;
250 input->name = pdev->
name;
252 input->dev.parent = &pdev->
dev;
255 input->id.vendor = 0x0001;
256 input->id.product = 0x0001;
257 input->id.version = 0x0100;
259 for (i = 0; i < pdata->
nbuttons; i++) {
274 dev_err(dev,
"unable to claim gpio %u, err=%d\n",
282 "unable to set direction on gpio %u, err=%d\n",
292 input_set_capability(input, type, button->
code);
298 platform_set_drvdata(pdev, bdev);
302 dev_err(dev,
"unable to register polled device, err=%d\n",
308 for (i = 0; i < pdata->
nbuttons; i++)
309 gpio_keys_polled_check_state(input, &pdata->
buttons[i],
322 platform_set_drvdata(pdev,
NULL);
326 if (!dev_get_platdata(&pdev->
dev))
340 for (i = 0; i < pdata->
nbuttons; i++)
349 if (!dev_get_platdata(&pdev->
dev))
353 platform_set_drvdata(pdev,
NULL);
359 .probe = gpio_keys_polled_probe,
364 .of_match_table =
of_match_ptr(gpio_keys_polled_of_match),