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
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!)
10 Signed-off-by: Mike A. Chan <mikechan@google.com>
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
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.
24 +config KEYBOARD_GOLDFISH_EVENTS
25 + tristate "Generic Input Event device for Goldfish"
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
43 +++ b/drivers/input/keyboard/goldfish_events.c
45 +/* drivers/input/keyboard/goldfish-events.c
47 +** Copyright (C) 2007 Google, Inc.
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.
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.
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>
68 +#include <mach/hardware.h>
74 + REG_SET_PAGE = 0x00,
78 + PAGE_NAME = 0x00000,
79 + PAGE_EVBITS = 0x10000,
80 + PAGE_ABSDATA = 0x20000 | EV_ABS,
84 + struct input_dev *input;
90 +static irqreturn_t events_interrupt(int irq, void *dev_id)
92 + struct event_dev *edev = dev_id;
93 + unsigned type, code, value;
95 + type = __raw_readl(edev->addr + REG_READ);
96 + code = __raw_readl(edev->addr + REG_READ);
97 + value = __raw_readl(edev->addr + REG_READ);
99 + input_event(edev->input, type, code, value);
100 + return IRQ_HANDLED;
103 +static void events_import_bits(struct event_dev *edev, unsigned long bits[], unsigned type, size_t count)
108 + unsigned addr = edev->addr;
109 + __raw_writel(PAGE_EVBITS | type, addr + REG_SET_PAGE);
110 + size = __raw_readl(addr + REG_LEN) * 8;
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++)
118 + set_bit(i + j, bits);
122 +static int events_probe(struct platform_device *pdev)
124 + struct input_dev *input_dev;
125 + struct event_dev *edev = NULL;
126 + struct resource *res;
127 + unsigned keymapnamelen;
134 + printk("*** events probe ***\n");
136 + input_dev = input_allocate_device();
137 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
138 + if(!input_dev || !res) goto fail;
140 + addr = (unsigned) ioremap(res->start, 4096);
141 + irq = platform_get_irq(pdev, 0);
143 + printk("events_probe() addr=0x%08x irq=%d\n", addr, irq);
145 + if(!addr) goto fail;
146 + if(irq < 0) goto fail;
148 + __raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
149 + keymapnamelen = __raw_readl(addr + REG_LEN);
151 + edev = kzalloc(sizeof(struct event_dev) + keymapnamelen + 1, GFP_KERNEL);
152 + if (!edev) goto fail;
154 + edev->input = input_dev;
158 + for (i = 0; i < keymapnamelen; i++) {
159 + edev->name[i] = __raw_readb(edev->addr + REG_DATA + i);
161 + printk("events_probe() keymap=%s\n", edev->name);
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);
173 + __raw_writel(PAGE_ABSDATA, addr + REG_SET_PAGE);
174 + count = __raw_readl(addr + REG_LEN) / (4 * 4);
175 + if (count > ABS_MAX)
177 + for(i = 0; i < count; i++) {
180 + if (!test_bit(i, input_dev->absbit))
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]);
187 + platform_set_drvdata(pdev, edev);
189 + input_dev->name = edev->name;
190 + input_set_drvdata(input_dev, edev);
192 + ret = input_register_device(input_dev);
196 + if(request_irq(edev->irq, events_interrupt, 0,
197 + "goldfish-events-keypad", edev) < 0) {
198 + input_unregister_device(input_dev);
207 + input_free_device(input_dev);
212 +static struct platform_driver events_driver = {
213 + .probe = events_probe,
215 + .name = "goldfish_events",
219 +static int __devinit events_init(void)
221 + return platform_driver_register(&events_driver);
225 +static void __exit events_exit(void)
229 +module_init(events_init);
230 +module_exit(events_exit);
232 +MODULE_AUTHOR("Brian Swetland");
233 +MODULE_DESCRIPTION("Goldfish Event Device");
234 +MODULE_LICENSE("GPL");