update to latest 2.6.27 and 2.6.30 kernels
[openwrt/svn-archive/archive.git] / target / linux / goldfish / patches-2.6.30 / 0123--ARM-goldfish-events-Add-event-driver-for-goldfis.patch
1 From 226fd290dc2d052e5cd437cc8464e1424e7ebf2c Mon Sep 17 00:00:00 2001
2 From: Brian Swetland <swetland@google.com>
3 Date: Sun, 13 Aug 2006 21:50:14 +0700
4 Subject: [PATCH 123/134] [ARM] goldfish: events: Add event driver for goldfish
5
6 this device is a direct pipe from "hardware" to the input
7 event subsystem, allowing us to avoid having to route
8 "keypad" style events through an AT keyboard driver (gross!)
9
10 Signed-off-by: Mike A. Chan <mikechan@google.com>
11 ---
12 drivers/input/keyboard/Kconfig | 5 +
13 drivers/input/keyboard/Makefile | 1 +
14 drivers/input/keyboard/goldfish_events.c | 190 ++++++++++++++++++++++++++++++
15 3 files changed, 196 insertions(+), 0 deletions(-)
16 create mode 100644 drivers/input/keyboard/goldfish_events.c
17
18 --- a/drivers/input/keyboard/Kconfig
19 +++ b/drivers/input/keyboard/Kconfig
20 @@ -304,6 +304,11 @@ config KEYBOARD_GPIO
21 To compile this driver as a module, choose M here: the
22 module will be called gpio-keys.
23
24 +config KEYBOARD_GOLDFISH_EVENTS
25 + tristate "Generic Input Event device for Goldfish"
26 + help
27 + no help
28 +
29 config KEYBOARD_MAPLE
30 tristate "Maple bus keyboard"
31 depends on SH_DREAMCAST && MAPLE
32 --- a/drivers/input/keyboard/Makefile
33 +++ b/drivers/input/keyboard/Makefile
34 @@ -23,6 +23,7 @@ obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x
35 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
36 obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
37 obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
38 +obj-$(CONFIG_KEYBOARD_GOLDFISH_EVENTS) += goldfish_events.o
39 obj-$(CONFIG_KEYBOARD_HP6XX) += jornada680_kbd.o
40 obj-$(CONFIG_KEYBOARD_HP7XX) += jornada720_kbd.o
41 obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
42 --- /dev/null
43 +++ b/drivers/input/keyboard/goldfish_events.c
44 @@ -0,0 +1,190 @@
45 +/* drivers/input/keyboard/goldfish-events.c
46 +**
47 +** Copyright (C) 2007 Google, Inc.
48 +**
49 +** This software is licensed under the terms of the GNU General Public
50 +** License version 2, as published by the Free Software Foundation, and
51 +** may be copied, distributed, and modified under those terms.
52 +**
53 +** This program is distributed in the hope that it will be useful,
54 +** but WITHOUT ANY WARRANTY; without even the implied warranty of
55 +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 +** GNU General Public License for more details.
57 +**
58 +*/
59 +
60 +#include <linux/module.h>
61 +#include <linux/init.h>
62 +#include <linux/interrupt.h>
63 +#include <linux/types.h>
64 +#include <linux/input.h>
65 +#include <linux/kernel.h>
66 +#include <linux/platform_device.h>
67 +
68 +#include <mach/hardware.h>
69 +#include <asm/irq.h>
70 +#include <asm/io.h>
71 +
72 +enum {
73 + REG_READ = 0x00,
74 + REG_SET_PAGE = 0x00,
75 + REG_LEN = 0x04,
76 + REG_DATA = 0x08,
77 +
78 + PAGE_NAME = 0x00000,
79 + PAGE_EVBITS = 0x10000,
80 + PAGE_ABSDATA = 0x20000 | EV_ABS,
81 +};
82 +
83 +struct event_dev {
84 + struct input_dev *input;
85 + int irq;
86 + unsigned addr;
87 + char name[0];
88 +};
89 +
90 +static irqreturn_t events_interrupt(int irq, void *dev_id)
91 +{
92 + struct event_dev *edev = dev_id;
93 + unsigned type, code, value;
94 +
95 + type = __raw_readl(edev->addr + REG_READ);
96 + code = __raw_readl(edev->addr + REG_READ);
97 + value = __raw_readl(edev->addr + REG_READ);
98 +
99 + input_event(edev->input, type, code, value);
100 + return IRQ_HANDLED;
101 +}
102 +
103 +static void events_import_bits(struct event_dev *edev, unsigned long bits[], unsigned type, size_t count)
104 +{
105 + int i, j;
106 + size_t size;
107 + uint8_t val;
108 + unsigned addr = edev->addr;
109 + __raw_writel(PAGE_EVBITS | type, addr + REG_SET_PAGE);
110 + size = __raw_readl(addr + REG_LEN) * 8;
111 + if (size < count)
112 + count = size;
113 + addr = addr + REG_DATA;
114 + for (i = 0; i < count; i += 8) {
115 + val = __raw_readb(addr++);
116 + for (j = 0; j < 8; j++)
117 + if(val & 1 << j)
118 + set_bit(i + j, bits);
119 + }
120 +}
121 +
122 +static int events_probe(struct platform_device *pdev)
123 +{
124 + struct input_dev *input_dev;
125 + struct event_dev *edev = NULL;
126 + struct resource *res;
127 + unsigned keymapnamelen;
128 + int i;
129 + int count;
130 + int irq;
131 + unsigned addr;
132 + int ret;
133 +
134 + printk("*** events probe ***\n");
135 +
136 + input_dev = input_allocate_device();
137 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
138 + if(!input_dev || !res) goto fail;
139 +
140 + addr = (unsigned) ioremap(res->start, 4096);
141 + irq = platform_get_irq(pdev, 0);
142 +
143 + printk("events_probe() addr=0x%08x irq=%d\n", addr, irq);
144 +
145 + if(!addr) goto fail;
146 + if(irq < 0) goto fail;
147 +
148 + __raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
149 + keymapnamelen = __raw_readl(addr + REG_LEN);
150 +
151 + edev = kzalloc(sizeof(struct event_dev) + keymapnamelen + 1, GFP_KERNEL);
152 + if (!edev) goto fail;
153 +
154 + edev->input = input_dev;
155 + edev->addr = addr;
156 + edev->irq = irq;
157 +
158 + for (i = 0; i < keymapnamelen; i++) {
159 + edev->name[i] = __raw_readb(edev->addr + REG_DATA + i);
160 + }
161 + printk("events_probe() keymap=%s\n", edev->name);
162 +
163 + events_import_bits(edev, input_dev->evbit, EV_SYN, EV_MAX);
164 + events_import_bits(edev, input_dev->keybit, EV_KEY, KEY_MAX);
165 + events_import_bits(edev, input_dev->relbit, EV_REL, REL_MAX);
166 + events_import_bits(edev, input_dev->absbit, EV_ABS, ABS_MAX);
167 + events_import_bits(edev, input_dev->mscbit, EV_MSC, MSC_MAX);
168 + events_import_bits(edev, input_dev->ledbit, EV_LED, LED_MAX);
169 + events_import_bits(edev, input_dev->sndbit, EV_SND, SND_MAX);
170 + events_import_bits(edev, input_dev->ffbit, EV_FF, FF_MAX);
171 + events_import_bits(edev, input_dev->swbit, EV_SW, SW_MAX);
172 +
173 + __raw_writel(PAGE_ABSDATA, addr + REG_SET_PAGE);
174 + count = __raw_readl(addr + REG_LEN) / (4 * 4);
175 + if (count > ABS_MAX)
176 + count = ABS_MAX;
177 + for(i = 0; i < count; i++) {
178 + int val[4];
179 + int j;
180 + if (!test_bit(i, input_dev->absbit))
181 + continue;
182 + for(j = 0; j < ARRAY_SIZE(val); j++)
183 + val[j] = __raw_readl(edev->addr + REG_DATA + (i * ARRAY_SIZE(val) + j) * 4);
184 + input_set_abs_params(input_dev, i, val[0], val[1], val[2], val[3]);
185 + }
186 +
187 + platform_set_drvdata(pdev, edev);
188 +
189 + input_dev->name = edev->name;
190 + input_set_drvdata(input_dev, edev);
191 +
192 + ret = input_register_device(input_dev);
193 + if (ret)
194 + goto fail;
195 +
196 + if(request_irq(edev->irq, events_interrupt, 0,
197 + "goldfish-events-keypad", edev) < 0) {
198 + input_unregister_device(input_dev);
199 + kfree(edev);
200 + return -EINVAL;
201 + }
202 +
203 + return 0;
204 +
205 +fail:
206 + kfree(edev);
207 + input_free_device(input_dev);
208 +
209 + return -EINVAL;
210 +}
211 +
212 +static struct platform_driver events_driver = {
213 + .probe = events_probe,
214 + .driver = {
215 + .name = "goldfish_events",
216 + },
217 +};
218 +
219 +static int __devinit events_init(void)
220 +{
221 + return platform_driver_register(&events_driver);
222 +}
223 +
224 +
225 +static void __exit events_exit(void)
226 +{
227 +}
228 +
229 +module_init(events_init);
230 +module_exit(events_exit);
231 +
232 +MODULE_AUTHOR("Brian Swetland");
233 +MODULE_DESCRIPTION("Goldfish Event Device");
234 +MODULE_LICENSE("GPL");