aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorBrian Swetland <swetland@google.com>2013-01-23 22:45:00 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-01-25 03:06:43 -0500
commit6f2ac009f29bcbd468a7a2017912dd090abd1348 (patch)
tree37ac4b24dc9b383da4ad8e8c3068157f0569efc3 /drivers/input
parentcb696e7cf261e2af323d49db8839dd1cc34709dd (diff)
Input: goldfish - virtual input event driver
This device is a direct pipe from "hardware" to the input event subsystem, allowing us to avoid having to route "keypad" style events through an AT keyboard driver (gross!). As with the other submissions this driver is cross architecture. Signed-off-by: Mike A. Chan <mikechan@google.com> [Tided up to work on x86] Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com> Signed-off-by: Xiaohui Xin <xiaohui.xin@intel.com> Signed-off-by: Jun Nakajima <jun.nakajima@intel.com> Signed-off-by: Bruce Beare <bruce.j.beare@intel.com> [Ported to 3.4] Signed-off-by: Tom Keel <thomas.keel@intel.com> [Cleaned up for 3.7 and submission] Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/goldfish_events.c194
3 files changed, 205 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 48309641b1b2..95b6d0335e8f 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -479,6 +479,16 @@ config KEYBOARD_SAMSUNG
479 To compile this driver as a module, choose M here: the 479 To compile this driver as a module, choose M here: the
480 module will be called samsung-keypad. 480 module will be called samsung-keypad.
481 481
482config KEYBOARD_GOLDFISH_EVENTS
483 depends on GOLDFISH
484 tristate "Generic Input Event device for Goldfish"
485 help
486 Say Y here to get an input event device for the Goldfish virtual
487 device emulator.
488
489 To compile this driver as a module, choose M here: the
490 module will be called goldfish-events.
491
482config KEYBOARD_STOWAWAY 492config KEYBOARD_STOWAWAY
483 tristate "Stowaway keyboard" 493 tristate "Stowaway keyboard"
484 select SERIO 494 select SERIO
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 44e76002f54b..49b16453d00e 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o
13obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o 13obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o
14obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o 14obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o
15obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o 15obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
16obj-$(CONFIG_KEYBOARD_GOLDFISH_EVENTS) += goldfish_events.o
16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 17obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
17obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o 18obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o
18obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o 19obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o
diff --git a/drivers/input/keyboard/goldfish_events.c b/drivers/input/keyboard/goldfish_events.c
new file mode 100644
index 000000000000..9f60a2ec88db
--- /dev/null
+++ b/drivers/input/keyboard/goldfish_events.c
@@ -0,0 +1,194 @@
1/*
2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (C) 2012 Intel, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/interrupt.h>
19#include <linux/types.h>
20#include <linux/input.h>
21#include <linux/kernel.h>
22#include <linux/platform_device.h>
23#include <linux/slab.h>
24#include <linux/irq.h>
25#include <linux/io.h>
26
27enum {
28 REG_READ = 0x00,
29 REG_SET_PAGE = 0x00,
30 REG_LEN = 0x04,
31 REG_DATA = 0x08,
32
33 PAGE_NAME = 0x00000,
34 PAGE_EVBITS = 0x10000,
35 PAGE_ABSDATA = 0x20000 | EV_ABS,
36};
37
38struct event_dev {
39 struct input_dev *input;
40 int irq;
41 void __iomem *addr;
42 char name[0];
43};
44
45static irqreturn_t events_interrupt(int irq, void *dev_id)
46{
47 struct event_dev *edev = dev_id;
48 unsigned type, code, value;
49
50 type = __raw_readl(edev->addr + REG_READ);
51 code = __raw_readl(edev->addr + REG_READ);
52 value = __raw_readl(edev->addr + REG_READ);
53
54 input_event(edev->input, type, code, value);
55 input_sync(edev->input);
56 return IRQ_HANDLED;
57}
58
59static void events_import_bits(struct event_dev *edev,
60 unsigned long bits[], unsigned type, size_t count)
61{
62 void __iomem *addr = edev->addr;
63 int i, j;
64 size_t size;
65 uint8_t val;
66
67 __raw_writel(PAGE_EVBITS | type, addr + REG_SET_PAGE);
68
69 size = __raw_readl(addr + REG_LEN) * 8;
70 if (size < count)
71 count = size;
72
73 addr += REG_DATA;
74 for (i = 0; i < count; i += 8) {
75 val = __raw_readb(addr++);
76 for (j = 0; j < 8; j++)
77 if (val & 1 << j)
78 set_bit(i + j, bits);
79 }
80}
81
82static void events_import_abs_params(struct event_dev *edev)
83{
84 struct input_dev *input_dev = edev->input;
85 void __iomem *addr = edev->addr;
86 u32 val[4];
87 int count;
88 int i, j;
89
90 __raw_writel(PAGE_ABSDATA, addr + REG_SET_PAGE);
91
92 count = __raw_readl(addr + REG_LEN) / sizeof(val);
93 if (count > ABS_MAX)
94 count = ABS_MAX;
95
96 for (i = 0; i < count; i++) {
97 if (!test_bit(i, input_dev->absbit))
98 continue;
99
100 for (j = 0; j < ARRAY_SIZE(val); j++) {
101 int offset = (i * ARRAY_SIZE(val) + j) * sizeof(u32);
102 val[j] = __raw_readl(edev->addr + REG_DATA + offset);
103 }
104
105 input_set_abs_params(input_dev, i,
106 val[0], val[1], val[2], val[3]);
107 }
108}
109
110static int events_probe(struct platform_device *pdev)
111{
112 struct input_dev *input_dev;
113 struct event_dev *edev;
114 struct resource *res;
115 unsigned keymapnamelen;
116 void __iomem *addr;
117 int irq;
118 int i;
119 int error;
120
121 irq = platform_get_irq(pdev, 0);
122 if (irq < 0)
123 return -EINVAL;
124
125 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
126 if (!res)
127 return -EINVAL;
128
129 addr = devm_ioremap(&pdev->dev, res->start, 4096);
130 if (!addr)
131 return -ENOMEM;
132
133 __raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
134 keymapnamelen = __raw_readl(addr + REG_LEN);
135
136 edev = devm_kzalloc(&pdev->dev,
137 sizeof(struct event_dev) + keymapnamelen + 1,
138 GFP_KERNEL);
139 if (!edev)
140 return -ENOMEM;
141
142 input_dev = devm_input_allocate_device(&pdev->dev);
143 if (!input_dev)
144 return -ENOMEM;
145
146 edev->input = input_dev;
147 edev->addr = addr;
148