2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (C) 2012 Intel, Inc.
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.
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.
16 #include <linux/module.h>
17 #include <linux/interrupt.h>
18 #include <linux/types.h>
19 #include <linux/input.h>
20 #include <linux/input/mt.h>
21 #include <linux/kernel.h>
22 #include <linux/platform_device.h>
23 #include <linux/slab.h>
24 #include <linux/irq.h>
26 #include <linux/acpi.h>
28 #define GOLDFISH_MAX_FINGERS 5
37 PAGE_EVBITS = 0x10000,
38 PAGE_ABSDATA = 0x20000 | EV_ABS,
42 struct input_dev *input;
48 static irqreturn_t events_interrupt(int irq, void *dev_id)
50 struct event_dev *edev = dev_id;
51 unsigned type, code, value;
53 type = __raw_readl(edev->addr + REG_READ);
54 code = __raw_readl(edev->addr + REG_READ);
55 value = __raw_readl(edev->addr + REG_READ);
57 input_event(edev->input, type, code, value);
58 // Send an extra (EV_SYN, SYN_REPORT, 0x0) event
59 // if a key was pressed. Some keyboard device
60 // drivers may only send the EV_KEY event and
62 // Note that sending an extra SYN_REPORT is not
63 // necessary nor correct protocol with other
64 // devices such as touchscreens, which will send
65 // their own SYN_REPORT's when sufficient event
66 // information has been collected (e.g., for
67 // touchscreens, when pressure and X/Y coordinates
68 // have been received). Hence, we will only send
69 // this extra SYN_REPORT if type == EV_KEY.
71 input_sync(edev->input);
76 static void events_import_bits(struct event_dev *edev,
77 unsigned long bits[], unsigned type, size_t count)
79 void __iomem *addr = edev->addr;
84 __raw_writel(PAGE_EVBITS | type, addr + REG_SET_PAGE);
86 size = __raw_readl(addr + REG_LEN) * 8;
91 for (i = 0; i < count; i += 8) {
92 val = __raw_readb(addr++);
93 for (j = 0; j < 8; j++)
99 static void events_import_abs_params(struct event_dev *edev)
101 struct input_dev *input_dev = edev->input;
102 void __iomem *addr = edev->addr;
107 __raw_writel(PAGE_ABSDATA, addr + REG_SET_PAGE);
109 count = __raw_readl(addr + REG_LEN) / sizeof(val);
113 for (i = 0; i < count; i++) {
114 if (!test_bit(i, input_dev->absbit))
117 for (j = 0; j < ARRAY_SIZE(val); j++) {
118 int offset = (i * ARRAY_SIZE(val) + j) * sizeof(u32);
119 val[j] = __raw_readl(edev->addr + REG_DATA + offset);
122 input_set_abs_params(input_dev, i,
123 val[0], val[1], val[2], val[3]);
127 static int events_probe(struct platform_device *pdev)
129 struct input_dev *input_dev;
130 struct event_dev *edev;
131 struct resource *res;
132 unsigned keymapnamelen;
138 irq = platform_get_irq(pdev, 0);
142 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146 addr = devm_ioremap(&pdev->dev, res->start, 4096);
150 __raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
151 keymapnamelen = __raw_readl(addr + REG_LEN);
153 edev = devm_kzalloc(&pdev->dev,
154 sizeof(struct event_dev) + keymapnamelen + 1,
159 input_dev = devm_input_allocate_device(&pdev->dev);
163 edev->input = input_dev;
167 for (i = 0; i < keymapnamelen; i++)
168 edev->name[i] = __raw_readb(edev->addr + REG_DATA + i);
170 pr_debug("events_probe() keymap=%s\n", edev->name);
172 input_dev->name = edev->name;
173 input_dev->id.bustype = BUS_HOST;
174 // Set the Goldfish Device to be multi-touch.
175 // In the Ranchu kernel, there is multi-touch-specific
176 // code for handling ABS_MT_SLOT events.
177 // See drivers/input/input.c:input_handle_abs_event.
178 // If we do not issue input_mt_init_slots,
179 // the kernel will filter out needed ABS_MT_SLOT
180 // events when we touch the screen in more than one place,
181 // preventing multi-touch with more than one finger from working.
182 input_mt_init_slots(input_dev, GOLDFISH_MAX_FINGERS, 0);
184 events_import_bits(edev, input_dev->evbit, EV_SYN, EV_MAX);
185 events_import_bits(edev, input_dev->keybit, EV_KEY, KEY_MAX);
186 events_import_bits(edev, input_dev->relbit, EV_REL, REL_MAX);
187 events_import_bits(edev, input_dev->absbit, EV_ABS, ABS_MAX);
188 events_import_bits(edev, input_dev->mscbit, EV_MSC, MSC_MAX);
189 events_import_bits(edev, input_dev->ledbit, EV_LED, LED_MAX);
190 events_import_bits(edev, input_dev->sndbit, EV_SND, SND_MAX);
191 events_import_bits(edev, input_dev->ffbit, EV_FF, FF_MAX);
192 events_import_bits(edev, input_dev->swbit, EV_SW, SW_MAX);
194 events_import_abs_params(edev);
196 error = devm_request_irq(&pdev->dev, edev->irq, events_interrupt, 0,
197 "goldfish-events-keypad", edev);
201 error = input_register_device(input_dev);
208 static const struct of_device_id goldfish_events_of_match[] = {
209 { .compatible = "google,goldfish-events-keypad", },
212 MODULE_DEVICE_TABLE(of, goldfish_events_of_match);
215 static const struct acpi_device_id goldfish_events_acpi_match[] = {
219 MODULE_DEVICE_TABLE(acpi, goldfish_events_acpi_match);
222 static struct platform_driver events_driver = {
223 .probe = events_probe,
225 .name = "goldfish_events",
226 .of_match_table = goldfish_events_of_match,
227 .acpi_match_table = ACPI_PTR(goldfish_events_acpi_match),
231 module_platform_driver(events_driver);
233 MODULE_AUTHOR("Brian Swetland");
234 MODULE_DESCRIPTION("Goldfish Event Device");
235 MODULE_LICENSE("GPL");