1 From 9deba66bfaf3a3293436e405830a666df8f36ed6 Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Sun, 13 Apr 2008 07:23:49 +0100
4 Subject: [PATCH] s3c2410-qt2410-buttons.patch
7 arch/arm/mach-s3c2410/mach-qt2410.c | 18 +++
8 drivers/input/keyboard/Kconfig | 5 +
9 drivers/input/keyboard/Makefile | 1 +
10 drivers/input/keyboard/qt2410kbd.c | 233 +++++++++++++++++++++++++++++++++++
11 4 files changed, 257 insertions(+), 0 deletions(-)
12 create mode 100644 drivers/input/keyboard/qt2410kbd.c
14 diff --git a/arch/arm/mach-s3c2410/mach-qt2410.c b/arch/arm/mach-s3c2410/mach-qt2410.c
15 index 6f7b56d..daf94cd 100644
16 --- a/arch/arm/mach-s3c2410/mach-qt2410.c
17 +++ b/arch/arm/mach-s3c2410/mach-qt2410.c
18 @@ -321,6 +321,24 @@ static int __init qt2410_tft_setup(char *str)
20 __setup("tft=", qt2410_tft_setup);
22 +static struct resource qt2410_button_resources[] = {
24 + .start = S3C2410_GPF0,
25 + .end = S3C2410_GPF0,
28 + .start = S3C2410_GPF2,
29 + .end = S3C2410_GPF2,
33 +struct platform_device qt2410_button_dev = {
34 + .name ="qt2410-button",
35 + .num_resources = ARRAY_SIZE(qt2410_button_resources),
36 + .resource = qt2410_button_resources,
40 static void __init qt2410_map_io(void)
42 s3c24xx_init_io(qt2410_iodesc, ARRAY_SIZE(qt2410_iodesc));
43 diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
44 index 3b9990e..a61ca45 100644
45 --- a/drivers/input/keyboard/Kconfig
46 +++ b/drivers/input/keyboard/Kconfig
47 @@ -304,5 +304,10 @@ config KEYBOARD_NEO1973
48 To compile this driver as a module, choose M here: the
49 module will be called neo1973kbd.
51 +config KEYBOARD_QT2410
52 + tristate "QT2410 buttons"
53 + depends on MACH_QT2410
58 diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
59 index 68ecfc5..34bfc33 100644
60 --- a/drivers/input/keyboard/Makefile
61 +++ b/drivers/input/keyboard/Makefile
62 @@ -15,6 +15,7 @@ obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
63 obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
64 obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
65 obj-$(CONFIG_KEYBOARD_NEO1973) += neo1973kbd.o
66 +obj-$(CONFIG_KEYBOARD_QT2410) += qt2410kbd.o
67 obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o
68 obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
69 obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
70 diff --git a/drivers/input/keyboard/qt2410kbd.c b/drivers/input/keyboard/qt2410kbd.c
72 index 0000000..4d497a3
74 +++ b/drivers/input/keyboard/qt2410kbd.c
77 + * Keyboard driver for Armzone QT2410
79 + * (C) 2006 by OpenMoko, Inc.
80 + * Author: Harald Welte <laforge@openmoko.org>
81 + * All rights reserved.
83 + * This program is free software; you can redistribute it and/or modify
84 + * it under the terms of the GNU General Public License version 2 as
85 + * published by the Free Software Foundation.
89 +#include <linux/delay.h>
90 +#include <linux/platform_device.h>
91 +#include <linux/init.h>
92 +#include <linux/input.h>
93 +#include <linux/interrupt.h>
94 +#include <linux/jiffies.h>
95 +#include <linux/module.h>
96 +#include <linux/slab.h>
98 +#include <asm/hardware.h>
99 +#include <asm/arch/gta01.h>
102 + struct input_dev *input;
103 + unsigned int suspended;
104 + unsigned long suspend_jiffies;
107 +static irqreturn_t gta01kbd_interrupt(int irq, void *dev_id)
109 + struct gta01kbd *gta01kbd_data = dev_id;
111 + /* FIXME: use GPIO from platform_dev resources */
112 + if (s3c2410_gpio_getpin(S3C2410_GPF0))
113 + input_report_key(gta01kbd_data->input, KEY_PHONE, 1);
115 + input_report_key(gta01kbd_data->input, KEY_PHONE, 0);
117 + input_sync(gta01kbd_data->input);
119 + return IRQ_HANDLED;
124 +static int gta01kbd_suspend(struct platform_device *dev, pm_message_t state)
126 + struct gta01kbd *gta01kbd = platform_get_drvdata(dev);
128 + gta01kbd->suspended = 1;
133 +static int gta01kbd_resume(struct platform_device *dev)
135 + struct gta01kbd *gta01kbd = platform_get_drvdata(dev);
137 + gta01kbd->suspended = 0;
142 +#define gta01kbd_suspend NULL
143 +#define gta01kbd_resume NULL
146 +static int gta01kbd_probe(struct platform_device *pdev)
148 + struct gta01kbd *gta01kbd;
149 + struct input_dev *input_dev;
153 + gta01kbd = kzalloc(sizeof(struct gta01kbd), GFP_KERNEL);
158 + input_dev = input_allocate_device();
159 + if (!gta01kbd || !input_dev) {
164 + if (pdev->resource[0].flags != 0) {\
166 + goto bail_free_dev;
169 + irq_911 = s3c2410_gpio_getirq(pdev->resource[0].start);
172 + goto bail_free_dev;
175 + platform_set_drvdata(pdev, gta01kbd);
177 + gta01kbd->input = input_dev;
180 + spin_lock_init(>a01kbd->lock);
181 + /* Init Keyboard rescan timer */
182 + init_timer(&corgikbd->timer);
183 + corgikbd->timer.function = corgikbd_timer_callback;
184 + corgikbd->timer.data = (unsigned long) corgikbd;
186 + /* Init Hinge Timer */
187 + init_timer(&corgikbd->htimer);
188 + corgikbd->htimer.function = corgikbd_hinge_timer;
189 + corgikbd->htimer.data = (unsigned long) corgikbd;
191 + corgikbd->suspend_jiffies=jiffies;
193 + memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode));
196 + input_dev->name = "QT2410 Buttons";
197 + input_dev->phys = "qt2410kbd/input0";
198 + input_dev->id.bustype = BUS_HOST;
199 + input_dev->id.vendor = 0x0001;
200 + input_dev->id.product = 0x0001;
201 + input_dev->id.version = 0x0100;
202 + input_dev->cdev.dev = &pdev->dev;
203 + input_dev->private = gta01kbd;
205 + input_dev->evbit[0] = BIT(EV_KEY);
207 + input_dev->keycode = gta01kbd->keycode;
208 + input_dev->keycodesize = sizeof(unsigned char);
209 + input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode);
211 + for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
212 + set_bit(corgikbd->keycode[i], input_dev->keybit);
213 + clear_bit(0, input_dev->keybit);
214 + set_bit(SW_LID, input_dev->swbit);
215 + set_bit(SW_TABLET_MODE, input_dev->swbit);
216 + set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
219 + rc = input_register_device(gta01kbd->input);
221 + goto bail_free_dev;
223 + s3c2410_gpio_cfgpin(S3C2410_GPF0, S3C2410_GPF0_EINT0);
224 + if (request_irq(irq_911, gta01kbd_interrupt,
225 + IRQF_DISABLED | IRQF_TRIGGER_RISING |
226 + IRQF_TRIGGER_FALLING, "qt2410kbd_eint0", gta01kbd))
227 + printk(KERN_WARNING "gta01kbd: Can't get IRQ\n");
228 + enable_irq_wake(irq_911);
230 + /* FIXME: headphone insert */
233 + mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
235 + /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
236 + for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) {
237 + pxa_gpio_mode(CORGI_GPIO_KEY_SENSE(i) | GPIO_IN);
238 + if (request_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd_interrupt,
239 + SA_INTERRUPT | SA_TRIGGER_RISING,
240 + "corgikbd", corgikbd))
241 + printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i);
244 + /* Set Strobe lines as outputs - set high */
245 + for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
246 + pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
248 + /* Setup the headphone jack as an input */
249 + pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
255 + input_free_device(input_dev);
262 +static int gta01kbd_remove(struct platform_device *pdev)
264 + struct gta01kbd *gta01kbd = platform_get_drvdata(pdev);
266 + free_irq(s3c2410_gpio_getirq(pdev->resource[0].start), gta01kbd);
270 + for (i = 0; i < CORGI_KEY_SENSE_NUM; i++)
271 + free_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd);
273 + del_timer_sync(&corgikbd->htimer);
274 + del_timer_sync(&corgikbd->timer);
276 + input_unregister_device(gta01kbd->input);
283 +static struct platform_driver gta01kbd_driver = {
284 + .probe = gta01kbd_probe,
285 + .remove = gta01kbd_remove,
286 + .suspend = gta01kbd_suspend,
287 + .resume = gta01kbd_resume,
289 + .name = "qt2410-button",
293 +static int __devinit gta01kbd_init(void)
295 + return platform_driver_register(>a01kbd_driver);
298 +static void __exit gta01kbd_exit(void)
300 + platform_driver_unregister(>a01kbd_driver);
303 +module_init(gta01kbd_init);
304 +module_exit(gta01kbd_exit);
306 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
307 +MODULE_DESCRIPTION("Armzone QT2410 Buttons Driver");
308 +MODULE_LICENSE("GPL");