aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/goldfish/patches-2.6.30/0123--ARM-goldfish-events-Add-event-driver-for-goldfis.patch
blob: fd9566e7a7e5d9296c73ea19d17f0f91171529a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
From 226fd290dc2d052e5cd437cc8464e1424e7ebf2c Mon Sep 17 00:00:00 2001
From: Brian Swetland <swetland@google.com>
Date: Sun, 13 Aug 2006 21:50:14 +0700
Subject: [PATCH 123/134] [ARM] goldfish: events: Add event driver for goldfish

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!)

Signed-off-by: Mike A. Chan <mikechan@google.com>
---
 drivers/input/keyboard/Kconfig           |    5 +
 drivers/input/keyboard/Makefile          |    1 +
 drivers/input/keyboard/goldfish_events.c |  190 ++++++++++++++++++++++++++++++
 3 files changed, 196 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/goldfish_events.c

--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -304,6 +304,11 @@ config KEYBOARD_GPIO
 	  To compile this driver as a module, choose M here: the
 	  module will be called gpio-keys.
 
+config KEYBOARD_GOLDFISH_EVENTS
+	tristate "Generic Input Event device for Goldfish"
+	help
+	  no help
+
 config KEYBOARD_MAPLE
 	tristate "Maple bus keyboard"
 	depends on SH_DREAMCAST && MAPLE
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
 obj-$(CONFIG_KEYBOARD_AAED2000)		+= aaed2000_kbd.o
 obj-$(CONFIG_KEYBOARD_GPIO)		+= gpio_keys.o
+obj-$(CONFIG_KEYBOARD_GOLDFISH_EVENTS)	+= goldfish_events.o
 obj-$(CONFIG_KEYBOARD_HP6XX)		+= jornada680_kbd.o
 obj-$(CONFIG_KEYBOARD_HP7XX)		+= jornada720_kbd.o
 obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
--- /dev/null
+++ b/drivers/input/keyboard/goldfish_events.c
@@ -0,0 +1,190 @@
+/* drivers/input/keyboard/goldfish-events.c
+**
+** Copyright (C) 2007 Google, Inc.
+**
+** This software is licensed under the terms of the GNU General Public
+** License version 2, as published by the Free Software Foundation, and
+** may be copied, distributed, and modified under those terms.
+**
+** 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.
+**
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/types.h>
+#include <linux/input.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <mach/hardware.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+
+enum {
+	REG_READ        = 0x00,
+	REG_SET_PAGE    = 0x00,
+	REG_LEN         = 0x04,
+	REG_DATA        = 0x08,
+
+	PAGE_NAME       = 0x00000,
+	PAGE_EVBITS     = 0x10000,
+	PAGE_ABSDATA    = 0x20000 | EV_ABS,
+};
+
+struct event_dev {
+    struct input_dev *input;
+    int irq;
+    unsigned addr;
+    char name[0];
+};
+
+static irqreturn_t events_interrupt(int irq, void *dev_id)
+{
+    struct event_dev *edev = dev_id;
+    unsigned type, code, value;
+
+    type = __raw_readl(edev->addr + REG_READ);
+    code = __raw_readl(edev->addr + REG_READ);
+    value = __raw_readl(edev->addr + REG_READ);
+
+    input_event(edev->input, type, code, value);
+    return IRQ_HANDLED;
+}
+
+static void events_import_bits(struct event_dev *edev, unsigned long bits[], unsigned type, size_t count)
+{
+	int i, j;
+	size_t size;
+	uint8_t val;
+	unsigned addr = edev->addr;
+	__raw_writel(PAGE_EVBITS | type, addr + REG_SET_PAGE);
+	size = __raw_readl(addr + REG_LEN) * 8;
+	if (size < count)
+		count = size;
+	addr = addr + REG_DATA;
+	for (i = 0; i < count; i += 8) {
+		val = __raw_readb(addr++);
+		for (j = 0; j < 8; j++)
+			if(val & 1 << j)
+				set_bit(i + j, bits);
+	}
+}
+
+static int events_probe(struct platform_device *pdev)
+{
+    struct input_dev *input_dev;
+    struct event_dev *edev = NULL;
+    struct resource *res;
+    unsigned keymapnamelen;
+    int i;
+    int count;
+    int irq;
+    unsigned addr;
+    int ret;
+    
+    printk("*** events probe ***\n");
+
+    input_dev = input_allocate_device();
+    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+    if(!input_dev || !res) goto fail;
+
+    addr = (unsigned) ioremap(res->start, 4096);
+    irq = platform_get_irq(pdev, 0);
+
+    printk("events_probe() addr=0x%08x irq=%d\n", addr, irq);
+
+    if(!addr) goto fail;
+    if(irq < 0) goto fail;
+
+    __raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
+    keymapnamelen = __raw_readl(addr + REG_LEN);
+
+    edev = kzalloc(sizeof(struct event_dev) + keymapnamelen + 1, GFP_KERNEL);
+    if (!edev) goto fail;
+
+    edev->input = input_dev;
+    edev->addr = addr;
+    edev->irq = irq;
+    
+    for (i = 0; i < keymapnamelen; i++) {
+        edev->name[i] = __raw_readb(edev->addr + REG_DATA + i);
+    }
+    printk("events_probe() keymap=%s\n", edev->name);
+
+    events_import_bits(edev, input_dev->evbit, EV_SYN, EV_MAX);
+    events_import_bits(edev, input_dev->keybit, EV_KEY, KEY_MAX);
+    events_import_bits(edev, input_dev->relbit, EV_REL, REL_MAX);
+    events_import_bits(edev, input_dev->absbit, EV_ABS, ABS_MAX);
+    events_import_bits(edev, input_dev->mscbit, EV_MSC, MSC_MAX);
+    events_import_bits(edev, input_dev->ledbit, EV_LED, LED_MAX);
+    events_import_bits(edev, input_dev->sndbit, EV_SND, SND_MAX);
+    events_import_bits(edev, input_dev->ffbit, EV_FF, FF_MAX);
+    events_import_bits(edev, input_dev->swbit, EV_SW, SW_MAX);
+
+    __raw_writel(PAGE_ABSDATA, addr + REG_SET_PAGE);
+    count = __raw_readl(addr + REG_LEN) / (4 * 4);
+    if (count > ABS_MAX)
+        count = ABS_MAX;
+    for(i = 0; i < count; i++) {
+        int val[4]; 
+        int j;
+        if (!test_bit(i, input_dev->absbit))
+            continue;
+        for(j = 0; j < ARRAY_SIZE(val); j++)
+            val[j] = __raw_readl(edev->addr + REG_DATA + (i * ARRAY_SIZE(val) + j) * 4);
+        input_set_abs_params(input_dev, i, val[0], val[1], val[2], val[3]);
+    }
+    
+    platform_set_drvdata(pdev, edev);
+
+    input_dev->name = edev->name;
+    input_set_drvdata(input_dev, edev);
+    
+    ret = input_register_device(input_dev);
+    if (ret)
+        goto fail;
+
+    if(request_irq(edev->irq, events_interrupt, 0,
+                   "goldfish-events-keypad", edev) < 0) {
+        input_unregister_device(input_dev);
+        kfree(edev);
+        return -EINVAL;
+    }
+
+    return 0;
+
+fail:
+    kfree(edev);
+    input_free_device(input_dev);
+    
+    return -EINVAL;
+}
+
+static struct platform_driver events_driver = {
+    .probe = events_probe,
+    .driver = {
+        .name = "goldfish_events",
+    },
+};
+
+static int __devinit events_init(void)
+{
+    return platform_driver_register(&events_driver);
+}
+
+
+static void __exit events_exit(void)
+{
+}
+
+module_init(events_init);
+module_exit(events_exit);
+
+MODULE_AUTHOR("Brian Swetland");
+MODULE_DESCRIPTION("Goldfish Event Device");
+MODULE_LICENSE("GPL");