--- /dev/null
+/*
+ * Driver for buttons on GPIO lines not capable of generating interrupts
+ *
+ * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
+ *
+ * This file was based on: /drivers/input/misc/cobalt_btns.c
+ * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
+ *
+ * also was based on: /drivers/input/keyboard/gpio_keys.c
+ * Copyright 2005 Phil Blundell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/input-polldev.h>
+#include <linux/ioport.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/platform_device.h>
+#include <mach/hardware.h>
+
+#define DRV_NAME "n2100-copy-button"
+
+struct gpio_keys_polled_device {
+ struct input_polled_dev *poll_dev;
+ struct device *dev;
+ int gpio;
+ int last_state;
+ int count;
+ int threshold;
+};
+
+static struct gpio_keys_polled_device bdev;
+
+static void gpio_keys_polled_check_state(struct input_dev *input,
+ struct gpio_keys_polled_device *bdata)
+{
+ int state;
+ state = !!gpio_get_value(bdata->gpio);
+
+ if (state != bdata->last_state) {
+ input_event(input, EV_KEY, KEY_COPY,
+ !state);
+ input_sync(input);
+ bdata->count = 0;
+ bdata->last_state = state;
+ }
+}
+
+static void gpio_keys_polled_poll(struct input_polled_dev *dev)
+{
+ struct gpio_keys_polled_device *bdev = dev->private;
+ struct input_dev *input = dev->input;
+
+ gpio_keys_polled_check_state(input, bdev);
+}
+
+static int __devinit gpio_keys_polled_init(void)
+{
+ struct input_polled_dev *poll_dev;
+ struct input_dev *input;
+ int error;
+ unsigned int gpio = N2100_COPY_BUTTON;
+
+ poll_dev = input_allocate_polled_device();
+ if (!poll_dev) {
+ pr_err("no memory for polled device\n");
+ error = -ENOMEM;
+ goto err_free_bdev;
+ }
+
+ poll_dev->private = &bdev;
+ poll_dev->poll = gpio_keys_polled_poll;
+ poll_dev->poll_interval = 100;
+
+ input = poll_dev->input;
+
+ input->evbit[0] = BIT(EV_KEY);
+ input->name = "copy-button";
+ input->phys = DRV_NAME"/input0";
+// input->dev.parent = &pdev->dev;
+
+ input->id.bustype = BUS_HOST;
+ input->id.vendor = 0x0001;
+ input->id.product = 0x0001;
+ input->id.version = 0x0100;
+
+ error = gpio_request(gpio,
+ "N2100 copy button");
+ if (error) {
+ pr_err("unable to claim gpio %u, err=%d\n",
+ gpio, error);
+ goto err_free_gpio;
+ }
+
+ error = gpio_direction_input(gpio);
+ if (error) {
+ pr_err("unable to set direction on gpio %u, err=%d\n",
+ gpio, error);
+ goto err_free_gpio;
+ }
+
+ bdev.last_state = -1;
+ bdev.threshold = 2;
+
+ input_set_capability(input, EV_KEY, KEY_COPY);
+
+ bdev.poll_dev = poll_dev;
+
+ error = input_register_polled_device(poll_dev);
+ if (error) {
+ pr_err("unable to register polled device, err=%d\n",
+ error);
+ goto err_free_gpio;
+ }
+
+ /* report initial state of the buttons */
+ gpio_keys_polled_check_state(input, &bdev);
+
+ return 0;
+
+err_free_gpio:
+ gpio_free(N2100_COPY_BUTTON);
+ input_free_polled_device(poll_dev);
+
+err_free_bdev:
+ return error;
+}
+
+static void __devexit gpio_keys_polled_exit(void)
+{
+ input_unregister_polled_device(bdev.poll_dev);
+ gpio_free(N2100_COPY_BUTTON);
+ input_free_polled_device(bdev.poll_dev);
+}
+
+module_init(gpio_keys_polled_init);
+module_exit(gpio_keys_polled_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Roman Bazalevskiy <rvb@rvb.name>, Gabor Juhos <juhosg@openwrt.org>");
+MODULE_DESCRIPTION("Polled GPIO Copy Buttons driver for Thecus N2100");
+MODULE_ALIAS("platform:" DRV_NAME);