summaryrefslogtreecommitdiff
path: root/target/linux/s3c24xx/patches-2.6.26/0009-gta01-inputdevice.patch.patch
blob: ef8cb7fce301987f0e3d2bd24d5ec11901efc8f7 (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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
From db36b757a45cf8d9088727d975d93917021b1171 Mon Sep 17 00:00:00 2001
From: mokopatches <mokopatches@openmoko.org>
Date: Wed, 16 Jul 2008 14:44:48 +0100
Subject: [PATCH] gta01-inputdevice.patch
 This provides support for the GTA01 keyboard

Signed-off-by: Harald Welte <laforge@openmoko.org>
---
 drivers/input/keyboard/Kconfig      |   12 ++
 drivers/input/keyboard/Makefile     |    1 +
 drivers/input/keyboard/neo1973kbd.c |  242 +++++++++++++++++++++++++++++++++++
 3 files changed, 255 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/neo1973kbd.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index efd70a9..b8ecca9 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -323,4 +323,16 @@ config KEYBOARD_SH_KEYSC
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called sh_keysc.
+config KEYBOARD_NEO1973
+	tristate "FIC Neo1973 buttons"
+	depends on MACH_NEO1973
+	default y
+	help
+	  Say Y here to enable the buttons on the FIC Neo1973
+	  GSM phone.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called neo1973kbd.
+
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 0edc8f2..b3aa339 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_KEYBOARD_LOCOMO)		+= locomokbd.o
 obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
 obj-$(CONFIG_KEYBOARD_STOWAWAY)		+= stowaway.o
 obj-$(CONFIG_KEYBOARD_CORGI)		+= corgikbd.o
+obj-$(CONFIG_KEYBOARD_NEO1973)		+= neo1973kbd.o
 obj-$(CONFIG_KEYBOARD_SPITZ)		+= spitzkbd.o
 obj-$(CONFIG_KEYBOARD_TOSA)		+= tosakbd.o
 obj-$(CONFIG_KEYBOARD_HIL)		+= hil_kbd.o
diff --git a/drivers/input/keyboard/neo1973kbd.c b/drivers/input/keyboard/neo1973kbd.c
new file mode 100644
index 0000000..917d5ae
--- /dev/null
+++ b/drivers/input/keyboard/neo1973kbd.c
@@ -0,0 +1,242 @@
+/*
+ * Keyboard driver for FIC Neo1973 GSM phone
+ *
+ * (C) 2006-2007 by OpenMoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ * All rights reserved.
+ *
+ * inspired by corkgbd.c by Richard Purdie
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include <asm/hardware.h>
+#include <asm/arch/gta01.h>
+#include <asm/mach-types.h>
+
+struct neo1973kbd {
+	struct input_dev *input;
+	unsigned int suspended;
+	unsigned long suspend_jiffies;
+};
+
+static irqreturn_t neo1973kbd_aux_irq(int irq, void *dev_id)
+{
+	struct neo1973kbd *neo1973kbd_data = dev_id;
+
+	/* FIXME: use GPIO from platform_dev resources */
+	if (s3c2410_gpio_getpin(GTA01_GPIO_AUX_KEY))
+		input_report_key(neo1973kbd_data->input, KEY_PHONE, 0);
+	else
+		input_report_key(neo1973kbd_data->input, KEY_PHONE, 1);
+
+	input_sync(neo1973kbd_data->input);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t neo1973kbd_hold_irq(int irq, void *dev_id)
+{
+	struct neo1973kbd *neo1973kbd_data = dev_id;
+
+	/* FIXME: use GPIO from platform_dev resources */
+	if (s3c2410_gpio_getpin(GTA01_GPIO_HOLD_KEY))
+		input_report_key(neo1973kbd_data->input, KEY_PAUSE, 1);
+	else
+		input_report_key(neo1973kbd_data->input, KEY_PAUSE, 0);
+
+	input_sync(neo1973kbd_data->input);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t neo1973kbd_headphone_irq(int irq, void *dev_id)
+{
+	struct neo1973kbd *neo1973kbd_data = dev_id;
+
+	/* FIXME: use GPIO from platform_dev resources */
+	if (s3c2410_gpio_getpin(GTA01_GPIO_JACK_INSERT))
+		input_report_switch(neo1973kbd_data->input,
+				    SW_HEADPHONE_INSERT, 1);
+	else
+		input_report_switch(neo1973kbd_data->input,
+				    SW_HEADPHONE_INSERT, 0);
+
+	input_sync(neo1973kbd_data->input);
+
+	return IRQ_HANDLED;
+}
+
+#ifdef CONFIG_PM
+static int neo1973kbd_suspend(struct platform_device *dev, pm_message_t state)
+{
+	struct neo1973kbd *neo1973kbd = platform_get_drvdata(dev);
+
+	neo1973kbd->suspended = 1;
+
+	return 0;
+}
+
+static int neo1973kbd_resume(struct platform_device *dev)
+{
+	struct neo1973kbd *neo1973kbd = platform_get_drvdata(dev);
+
+	neo1973kbd->suspended = 0;
+
+	return 0;
+}
+#else
+#define neo1973kbd_suspend	NULL
+#define neo1973kbd_resume	NULL
+#endif
+
+static int neo1973kbd_probe(struct platform_device *pdev)
+{
+	struct neo1973kbd *neo1973kbd;
+	struct input_dev *input_dev;
+	int rc, irq_aux, irq_hold, irq_jack;
+
+	neo1973kbd = kzalloc(sizeof(struct neo1973kbd), GFP_KERNEL);
+	input_dev = input_allocate_device();
+	if (!neo1973kbd || !input_dev) {
+		kfree(neo1973kbd);
+		input_free_device(input_dev);
+		return -ENOMEM;
+	}
+
+	if (pdev->resource[0].flags != 0)
+		return -EINVAL;
+
+	irq_aux = s3c2410_gpio_getirq(pdev->resource[0].start);
+	if (irq_aux < 0)
+		return -EINVAL;
+
+	irq_hold = s3c2410_gpio_getirq(pdev->resource[1].start);
+	if (irq_hold < 0)
+		return -EINVAL;
+
+	irq_jack = s3c2410_gpio_getirq(pdev->resource[2].start);
+	if (irq_jack < 0)
+		return -EINVAL;
+
+	platform_set_drvdata(pdev, neo1973kbd);
+
+	neo1973kbd->input = input_dev;
+
+	input_dev->name = "Neo1973 Buttons";
+	input_dev->phys = "neo1973kbd/input0";
+	input_dev->id.bustype = BUS_HOST;
+	input_dev->id.vendor = 0x0001;
+	input_dev->id.product = 0x0001;
+	input_dev->id.version = 0x0100;
+	input_dev->cdev.dev = &pdev->dev;
+	input_dev->private = neo1973kbd;
+
+	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_SW);
+	set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
+	set_bit(KEY_PHONE, input_dev->keybit);
+	set_bit(KEY_PAUSE, input_dev->keybit);
+
+	rc = input_register_device(neo1973kbd->input);
+	if (rc)
+		goto out_register;
+
+	if (request_irq(irq_aux, neo1973kbd_aux_irq, IRQF_DISABLED |
+			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+			"Neo1973 AUX button", neo1973kbd)) {
+		dev_err(&pdev->dev, "Can't get IRQ %u\n", irq_aux);
+		goto out_aux;
+	}
+
+	/*
+	 * GTA01 revisions before Bv4 can't be resumed by the PMU, so we use
+	 * resume by AUX.
+	 */
+	if (machine_is_neo1973_gta01())
+		enable_irq_wake(irq_aux);
+
+	if (request_irq(irq_hold, neo1973kbd_hold_irq, IRQF_DISABLED |
+			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+			"Neo1973 HOLD button", neo1973kbd)) {
+		dev_err(&pdev->dev, "Can't get IRQ %u\n", irq_hold);
+		goto out_hold;
+	}
+
+	if (request_irq(irq_jack, neo1973kbd_headphone_irq, IRQF_DISABLED |
+			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+			"Neo1973 Headphone Jack", neo1973kbd)) {
+		dev_err(&pdev->dev, "Can't get IRQ %u\n", irq_jack);
+		goto out_jack;
+	}
+	enable_irq_wake(irq_jack);
+
+	return 0;
+
+out_jack:
+	free_irq(irq_hold, neo1973kbd);
+out_hold:
+	free_irq(irq_aux, neo1973kbd);
+out_aux:
+	input_unregister_device(neo1973kbd->input);
+out_register:
+	input_free_device(neo1973kbd->input);
+	platform_set_drvdata(pdev, NULL);
+	kfree(neo1973kbd);
+
+	return -ENODEV;
+}
+
+static int neo1973kbd_remove(struct platform_device *pdev)
+{
+	struct neo1973kbd *neo1973kbd = platform_get_drvdata(pdev);
+
+	free_irq(s3c2410_gpio_getirq(pdev->resource[2].start), neo1973kbd);
+	free_irq(s3c2410_gpio_getirq(pdev->resource[1].start), neo1973kbd);
+	free_irq(s3c2410_gpio_getirq(pdev->resource[0].start), neo1973kbd);
+
+	input_unregister_device(neo1973kbd->input);
+	input_free_device(neo1973kbd->input);
+	platform_set_drvdata(pdev, NULL);
+	kfree(neo1973kbd);
+
+	return 0;
+}
+
+static struct platform_driver neo1973kbd_driver = {
+	.probe		= neo1973kbd_probe,
+	.remove		= neo1973kbd_remove,
+	.suspend	= neo1973kbd_suspend,
+	.resume		= neo1973kbd_resume,
+	.driver		= {
+		.name	= "neo1973-button",
+	},
+};
+
+static int __devinit neo1973kbd_init(void)
+{
+	return platform_driver_register(&neo1973kbd_driver);
+}
+
+static void __exit neo1973kbd_exit(void)
+{
+	platform_driver_unregister(&neo1973kbd_driver);
+}
+
+module_init(neo1973kbd_init);
+module_exit(neo1973kbd_exit);
+
+MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
+MODULE_DESCRIPTION("FIC Neo1973 buttons input driver");
+MODULE_LICENSE("GPL");
-- 
1.5.6.3