summaryrefslogtreecommitdiff
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorGary King <gking@nvidia.com>2009-12-10 19:42:55 -0800
committerGary King <gking@nvidia.com>2009-12-11 15:13:22 -0800
commitca01b5b4ea188e1c39cdc5a57274294ad303375e (patch)
tree2dec976a198816914833bc8c40c07fd82bde02d2 /drivers/input/misc
parenta49c25cc750827b331014a108ae5aaa5a376235b (diff)
input: add misc input device for NVIDIA Tegra ODM scrollwheel
adds a miscellaneous input device for scrollwheels using the NVIDIA Tegra ODM kit adaptation interface for scrollwheels Change-Id: Ic2072010acd3f56a9a1333c90bbda4cdc935ce28
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/Kconfig7
-rw-r--r--drivers/input/misc/Makefile3
-rw-r--r--drivers/input/misc/tegra_odm_scroll.c175
3 files changed, 184 insertions, 1 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 976550107389..471c39aa0ef3 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -250,4 +250,11 @@ config INPUT_TEGRA_ODM_ACCEL
Say Y here if you want to enable an accelerometer input device node
using the NVIDIA Tegra ODM kit accelerometer adaptation interface
+config INPUT_TEGRA_ODM_SCROLL
+ boolean "Scrollwheel for NVIDIA Tegra ODM kit"
+ depends on ARCH_TEGRA && MACH_TEGRA_GENERIC
+ help
+ Say Y here if you want to enable a scrollwheel input device node
+ using the NVIDIA Tegra ODM kit scrollwheel adaptation interface
+
endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 412e573b0b3a..9290d798426a 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -24,4 +24,5 @@ obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
obj-$(CONFIG_INPUT_GPIO) += gpio_event.o gpio_matrix.o gpio_input.o gpio_output.o gpio_axis.o
obj-$(CONFIG_INPUT_KEYCHORD) += keychord.o
-obj-$(CONFIG_INPUT_TEGRA_ODM_ACCEL) += tegra_odm_accel.o \ No newline at end of file
+obj-$(CONFIG_INPUT_TEGRA_ODM_ACCEL) += tegra_odm_accel.o
+obj-$(CONFIG_INPUT_TEGRA_ODM_SCROLL) += tegra_odm_scroll.o
diff --git a/drivers/input/misc/tegra_odm_scroll.c b/drivers/input/misc/tegra_odm_scroll.c
new file mode 100644
index 000000000000..cf859c221f2e
--- /dev/null
+++ b/drivers/input/misc/tegra_odm_scroll.c
@@ -0,0 +1,175 @@
+/*
+ * drivers/input/misc/tegra_odm_scroll.c
+ *
+ * Scrollwheel input device using NVIDIA Tegra ODM kit
+ *
+ * Copyright (c) 2009, NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/input.h>
+#include <linux/platform_device.h>
+#include <linux/kthread.h>
+
+#include <mach/nvrm_linux.h>
+#include <nvos.h>
+
+#include <nvodm_scrollwheel.h>
+
+struct tegra_scroll_dev {
+ struct input_dev *input_dev;
+ struct task_struct *task;
+ NvOdmOsSemaphoreHandle sem;
+ NvOdmScrollWheelHandle odm_dev;
+};
+
+static int scroll_thread(void *pdata)
+{
+ struct tegra_scroll_dev *scroll = pdata;
+ NvOdmScrollWheelEvent Events;
+
+ /* FIXME add a terminating condition */
+ while(1) {
+ NvU32 value = 0;
+ NvOdmOsSemaphoreWait(scroll->sem);
+
+ Events = NvOdmScrollWheelGetEvent(scroll->odm_dev);
+ if (Events & NvOdmScrollWheelEvent_RotateAntiClockWise) {
+ input_report_key(scroll->input_dev, KEY_UP, 1);
+ input_report_key(scroll->input_dev, KEY_UP, 0);
+ }
+ if (Events & NvOdmScrollWheelEvent_RotateClockWise) {
+ input_report_key(scroll->input_dev, KEY_DOWN, 1);
+ input_report_key(scroll->input_dev, KEY_DOWN, 0);
+ }
+
+ if (Events & NvOdmScrollWheelEvent_Press)
+ input_report_key(scroll->input_dev, KEY_ENTER, 1);
+ else if (Events & NvOdmScrollWheelEvent_Release)
+ input_report_key(scroll->input_dev, KEY_ENTER, 0);
+ }
+ return 0;
+}
+
+
+static int __init tegra_scroll_probe(struct platform_device *pdev)
+{
+ struct tegra_scroll_dev *scroll = NULL;
+ struct input_dev *input_dev = NULL;
+ NvOdmOsSemaphoreHandle sem = NULL;
+ NvOdmScrollWheelHandle odm_dev = NULL;
+ int err;
+ NvOdmScrollWheelEvent events;
+
+ sem = NvOdmOsSemaphoreCreate(0);
+ if (!sem) {
+ pr_err("tegra_scroll_probe: Semaphore creation failed\n");
+ return -ENOMEM;
+ }
+
+ events = NvOdmScrollWheelEvent_Press |
+ NvOdmScrollWheelEvent_Release |
+ NvOdmScrollWheelEvent_RotateAntiClockWise |
+ NvOdmScrollWheelEvent_RotateClockWise;
+
+ odm_dev = NvOdmScrollWheelOpen(sem, events);
+ if (odm_dev == NULL) {
+ pr_err("tegra_scroll_probe: scroll wheel not found\n");
+ err = -ENXIO;
+ goto err_scrollWheelnotfound;
+ }
+
+ scroll = kzalloc(sizeof(struct tegra_scroll_dev), GFP_KERNEL);
+ input_dev = input_allocate_device();
+ if (input_dev == NULL || ScrollWheel == NULL) {
+ err = -ENOMEM;
+ pr_err("tegra_scroll_probe: Failed to allocate input device\n");
+ goto err_alloc_failed;
+ }
+
+ scroll->input_dev = input_dev;
+ scroll->sem = sem;
+ scroll->odm_dev = odm_dev;
+ scroll->task = kthread_create(scroll_thread, scroll, "tegra_scroll");
+ if (scroll->task == NULL) {
+ err = -1;
+ goto err_kthread_create_failed;
+ }
+ wake_up_process( scroll->task );
+
+ __set_bit(EV_KEY, input_dev->evbit);
+ __set_bit(KEY_ENTER, input_dev->keybit);
+ __set_bit(KEY_UP, input_dev->keybit);
+ __set_bit(KEY_DOWN, input_dev->keybit);
+
+ platform_set_drvdata(pdev, scroll);
+ err = input_register_device(input_dev);
+ if (err) {
+ pr_err("tegra_scroll_probe: Unable to register input device\n");
+ goto err_input_register_device_failed;
+ }
+
+ return 0;
+
+err_input_register_device_failed:
+ NvOdmScrollWheelClose(scroll->odm_dev);
+err_kthread_create_failed:
+ /* What to do? */
+err_alloc_failed:
+ kfree(scroll);
+ input_free_device(input_dev);
+ NvOdmScrollWheelClose(odm_dev);
+err_scrollWheelnotfound:
+ NvOdmOsSemaphoreDestroy(sem);
+ return err;
+}
+
+static int tegra_scroll_remove(struct platform_device *pdev)
+{
+ struct tegra_scroll_dev *scroll = platform_get_drvdata(pdev);
+
+ /* FIXME How to destroy the thread? Maybe we should use workqueues? */
+ input_unregister_device(scroll->input_dev);
+ NvOdmScrollWheelClose(scroll->odm_dev);
+ NvOdmOsSemaphoreDestroy(scroll->sem);
+ kfree(ScrollWheel);
+ return 0;
+}
+
+static struct platform_driver tegra_ScrollWheel_driver = {
+ .probe = tegra_scroll_probe,
+ .remove = tegra_scroll_remove,
+ .driver = {
+ .name = "tegra_scrollwheel",
+ },
+};
+
+static int __devinit tegra_ScrollWheel_init(void)
+{
+ return platform_driver_register(&tegra_ScrollWheel_driver);
+}
+
+static void __exit tegra_ScrollWheel_exit(void)
+{
+ platform_driver_unregister(&tegra_ScrollWheel_driver);
+}
+
+module_init(tegra_ScrollWheel_init);
+module_exit(tegra_ScrollWheel_exit);
+
+MODULE_DESCRIPTION("Tegra Key board controller driver");
+