summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary King <gking@nvidia.com>2010-05-28 16:47:26 -0700
committerGary King <gking@nvidia.com>2010-05-28 17:20:39 -0700
commit647a42515761a5a05bddf6cc438755adf64c1d06 (patch)
treec70c1063f8ce2a849ec0359b0ce03a59886d37ae
parent00686bd386d93d4b97016677f4cbea0045c07c8f (diff)
input: misc: add input driver for tegra scrollwheel ODM kit
Change-Id: I79ca91a26094567207eb55837b908086209cfcf2 Reviewed-on: http://git-master/r/1829 Reviewed-by: Gary King <gking@nvidia.com> Tested-by: Gary King <gking@nvidia.com>
-rw-r--r--arch/arm/mach-tegra/include/nvodm_scrollwheel.h147
-rw-r--r--drivers/input/misc/Kconfig7
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/tegra_odm_scroll.c174
4 files changed, 329 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/include/nvodm_scrollwheel.h b/arch/arm/mach-tegra/include/nvodm_scrollwheel.h
new file mode 100644
index 000000000000..e5380f26938d
--- /dev/null
+++ b/arch/arm/mach-tegra/include/nvodm_scrollwheel.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2006-2009 NVIDIA Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of the NVIDIA Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/**
+ * @file
+ * <b>NVIDIA Tegra ODM Kit:
+ * Scroll Wheel Interface</b>
+ *
+ * @b Description: Defines the ODM adaptation interface for scroll wheel devices.
+ *
+ */
+
+#ifndef INCLUDED_NVODM_SCROLLWHEEL_H
+#define INCLUDED_NVODM_SCROLLWHEEL_H
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+#include "nvodm_services.h"
+
+/**
+ * @defgroup nvodm_scrollwheel Scroll Wheel Adaptation Interface
+ *
+ * This is the scroll wheel ODM adaptation interface.
+ *
+ * @ingroup nvodm_adaptation
+ * @{
+ */
+
+/**
+ * Defines an opaque handle that exists for each scroll wheel device in the
+ * system, each of which is defined by the customer implementation.
+ */
+typedef struct NvOdmScrollWheelRec *NvOdmScrollWheelHandle;
+
+/**
+ * Defines the events generated by the scroll wheel.
+ */
+typedef enum
+{
+ /// Indicates no event.
+ NvOdmScrollWheelEvent_None = 0,
+
+ /// Indicates the scroll up event.
+ NvOdmScrollWheelEvent_RotateClockWise = 0x1,
+
+ /// Indicates the scroll down event.
+ NvOdmScrollWheelEvent_RotateAntiClockWise = 0x2,
+
+ /// Indicates the key press event.
+ NvOdmScrollWheelEvent_Press = 0x4,
+
+ /// Indicates the release event.
+ NvOdmScrollWheelEvent_Release = 0x8,
+
+ /// Indicates the scroll up event.
+ NvOdmScrollWheelEvent_Up = 0x10,
+
+ /// Indicates the scroll down event.
+ NvOdmScrollWheelEvent_Down = 0x20,
+
+ /// Indicates the scroll right event.
+ NvOdmScrollWheelEvent_Right = 0x40,
+
+ /// Indicates the scroll left event.
+ NvOdmScrollWheelEvent_Left = 0x80,
+
+ NvOdmScrollWheelEvent_Force32 = 0x7FFFFFFF
+} NvOdmScrollWheelEvent;
+
+
+
+/**
+ * Gets a handle to the scroll wheel device.
+ *
+ * @param hSema A handle to the semaphore to be signalled when
+ * there is an event.
+ * @param KeyEvents Specifies the ORed version of all the events for which
+ * the client wants to register.
+ *
+ * @return A handle to the scroll wheel device.
+ */
+NvOdmScrollWheelHandle
+NvOdmScrollWheelOpen(
+ NvOdmOsSemaphoreHandle hSema,
+ NvOdmScrollWheelEvent KeyEvents);
+
+/**
+ * Closes the scroll wheel handle.
+ *
+ * @param hOdmScrollWheel The scroll wheel handle to be closed.
+ */
+void NvOdmScrollWheelClose(NvOdmScrollWheelHandle hOdmScrollWheel);
+
+
+/**
+ * Gets the pending event information.
+ *
+ * This API should be called when the semaphore
+ * that the client is waiting on is signalled.
+ *
+ * @param hOdmScrollWheel A handle to the scroll wheel.
+ * @return The type of event. If there are no pending events,
+ * returns the 'none' event. If there are more than one events,
+ * returns the ORed version of the events.
+ *
+ */
+NvOdmScrollWheelEvent NvOdmScrollWheelGetEvent(NvOdmScrollWheelHandle hOdmScrollWheel);
+
+#if defined(__cplusplus)
+}
+#endif
+
+/** @} */
+
+#endif // INCLUDED_NVODM_SCROLLWHEEL_H
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 0b0b6182cadd..86d754feb241 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -333,4 +333,11 @@ config INPUT_PCAP
To compile this driver as a module, choose M here: the
module will be called pcap_keys.
+config INPUT_TEGRA_ODM_SCROLL
+ tristate "Scrollwheel for NVIDIA Tegra ODM kit"
+ depends on ARCH_TEGRA && TEGRA_ODM_KIT
+ 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 42a5a5a90e75..3e06619a88f3 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -32,4 +32,5 @@ obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.o
obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
obj-$(CONFIG_INPUT_YEALINK) += yealink.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..7f291e677e8c
--- /dev/null
+++ b/drivers/input/misc/tegra_odm_scroll.c
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+#define NV_DEBUG 0
+
+#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) {
+ 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 || scroll == 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(scroll);
+ return 0;
+}
+
+static struct platform_driver tegra_scroll_driver = {
+ .probe = tegra_scroll_probe,
+ .remove = tegra_scroll_remove,
+ .driver = {
+ .name = "tegra_scrollwheel",
+ },
+};
+
+static int __devinit tegra_scroll_init(void)
+{
+ return platform_driver_register(&tegra_scroll_driver);
+}
+
+static void __exit tegra_scroll_exit(void)
+{
+ platform_driver_unregister(&tegra_scroll_driver);
+}
+
+module_init(tegra_scroll_init);
+module_exit(tegra_scroll_exit);
+
+MODULE_DESCRIPTION("Tegra scrollwheel driver");