aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-25 10:59:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-25 10:59:01 -0400
commit3a99c6319064af3f2e18eb929f638d555dbf7a62 (patch)
treee611927f41142123dc8efed7e07a3a91151edb01 /drivers/input/keyboard
parent1dfd166e93f98892aa4427069a23ed73259983c8 (diff)
parent49327ad2bbbaf1945d5ba431522201574219d150 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (75 commits) Input: wacom - specify Cinitq supported tools Input: ab8500-ponkey - fix IRQ freeing in error path Input: adp5588-keys - use more obvious i2c_device_id name string Input: ad7877 - switch to using threaded IRQ Input: ad7877 - use attribute group to control visibility of attributes Input: serio - add support for PS2Mult multiplexer protocol Input: wacom - properly enable runtime PM Input: ad7877 - filter events where pressure is beyond the maximum Input: ad7877 - implement EV_KEY:BTN_TOUCH reporting Input: ad7877 - implement specified chip select behavior Input: hp680_ts_input - use cancel_delayed_work_sync() Input: mousedev - correct lockdep annotation Input: ads7846 - switch to using threaded IRQ Input: serio - support multiple child devices per single parent Input: synaptics - simplify pass-through port handling Input: add ROHM BU21013 touch panel controller support Input: omap4-keypad - wake-up on events & long presses Input: omap4-keypad - fix interrupt line configuration Input: omap4-keypad - SYSCONFIG register configuration Input: omap4-keypad - use platform device helpers ...
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/Kconfig19
-rw-r--r--drivers/input/keyboard/Makefile2
-rw-r--r--drivers/input/keyboard/adp5588-keys.c2
-rw-r--r--drivers/input/keyboard/hil_kbd.c2
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c408
-rw-r--r--drivers/input/keyboard/omap4-keypad.c318
-rw-r--r--drivers/input/keyboard/twl4030_keypad.c7
7 files changed, 753 insertions, 5 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index aa037fec2f86..0426630f0e98 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -327,6 +327,16 @@ config KEYBOARD_NEWTON
327 To compile this driver as a module, choose M here: the 327 To compile this driver as a module, choose M here: the
328 module will be called newtonkbd. 328 module will be called newtonkbd.
329 329
330config KEYBOARD_NOMADIK
331 tristate "ST-Ericsson Nomadik SKE keyboard"
332 depends on PLAT_NOMADIK
333 help
334 Say Y here if you want to use a keypad provided on the SKE controller
335 used on the Ux500 and Nomadik platforms
336
337 To compile this driver as a module, choose M here: the
338 module will be called nmk-ske-keypad.
339
330config KEYBOARD_OPENCORES 340config KEYBOARD_OPENCORES
331 tristate "OpenCores Keyboard Controller" 341 tristate "OpenCores Keyboard Controller"
332 help 342 help
@@ -424,6 +434,15 @@ config KEYBOARD_OMAP
424 To compile this driver as a module, choose M here: the 434 To compile this driver as a module, choose M here: the
425 module will be called omap-keypad. 435 module will be called omap-keypad.
426 436
437config KEYBOARD_OMAP4
438 tristate "TI OMAP4 keypad support"
439 depends on ARCH_OMAP4
440 help
441 Say Y here if you want to use the OMAP4 keypad.
442
443 To compile this driver as a module, choose M here: the
444 module will be called omap4-keypad.
445
427config KEYBOARD_TWL4030 446config KEYBOARD_TWL4030
428 tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" 447 tristate "TI TWL4030/TWL5030/TPS659x0 keypad support"
429 depends on TWL4030_CORE 448 depends on TWL4030_CORE
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 504b591be0cd..c13809c5c3a7 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -28,7 +28,9 @@ obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
28obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 28obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
29obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o 29obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
30obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 30obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
31obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
31obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 32obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
33obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o
32obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o 34obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o
33obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o 35obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o
34obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o 36obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index d6918cb966c0..b92d1cd5cba1 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -660,7 +660,7 @@ static const struct dev_pm_ops adp5588_dev_pm_ops = {
660#endif 660#endif
661 661
662static const struct i2c_device_id adp5588_id[] = { 662static const struct i2c_device_id adp5588_id[] = {
663 { KBUILD_MODNAME, 0 }, 663 { "adp5588-keys", 0 },
664 { "adp5587-keys", 0 }, 664 { "adp5587-keys", 0 },
665 { } 665 { }
666}; 666};
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index 19fa94af207a..fed31e0947a1 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -570,6 +570,8 @@ static struct serio_device_id hil_dev_ids[] = {
570 { 0 } 570 { 0 }
571}; 571};
572 572
573MODULE_DEVICE_TABLE(serio, hil_dev_ids);
574
573static struct serio_driver hil_serio_drv = { 575static struct serio_driver hil_serio_drv = {
574 .driver = { 576 .driver = {
575 .name = "hil_dev", 577 .name = "hil_dev",
diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c
new file mode 100644
index 000000000000..6e0f23091360
--- /dev/null
+++ b/drivers/input/keyboard/nomadik-ske-keypad.c
@@ -0,0 +1,408 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
5 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
6 *
7 * License terms:GNU General Public License (GPL) version 2
8 *
9 * Keypad controller driver for the SKE (Scroll Key Encoder) module used in
10 * the Nomadik 8815 and Ux500 platforms.
11 */
12
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/spinlock.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18#include <linux/input.h>
19#include <linux/slab.h>
20#include <linux/clk.h>
21
22#include <plat/ske.h>
23
24/* SKE_CR bits */
25#define SKE_KPMLT (0x1 << 6)
26#define SKE_KPCN (0x7 << 3)
27#define SKE_KPASEN (0x1 << 2)
28#define SKE_KPASON (0x1 << 7)
29
30/* SKE_IMSC bits */
31#define SKE_KPIMA (0x1 << 2)
32
33/* SKE_ICR bits */
34#define SKE_KPICS (0x1 << 3)
35#define SKE_KPICA (0x1 << 2)
36
37/* SKE_RIS bits */
38#define SKE_KPRISA (0x1 << 2)
39
40#define SKE_KEYPAD_ROW_SHIFT 3
41#define SKE_KPD_KEYMAP_SIZE (8 * 8)
42
43/* keypad auto scan registers */
44#define SKE_ASR0 0x20
45#define SKE_ASR1 0x24
46#define SKE_ASR2 0x28
47#define SKE_ASR3 0x2C
48
49#define SKE_NUM_ASRX_REGISTERS (4)
50
51/**
52 * struct ske_keypad - data structure used by keypad driver
53 * @irq: irq no
54 * @reg_base: ske regsiters base address
55 * @input: pointer to input device object
56 * @board: keypad platform device
57 * @keymap: matrix scan code table for keycodes
58 * @clk: clock structure pointer
59 */
60struct ske_keypad {
61 int irq;
62 void __iomem *reg_base;
63 struct input_dev *input;
64 const struct ske_keypad_platform_data *board;
65 unsigned short keymap[SKE_KPD_KEYMAP_SIZE];
66 struct clk *clk;
67 spinlock_t ske_keypad_lock;
68};
69
70static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
71 u8 mask, u8 data)
72{
73 u32 ret;
74
75 spin_lock(&keypad->ske_keypad_lock);
76
77 ret = readl(keypad->reg_base + addr);
78 ret &= ~mask;
79 ret |= data;
80 writel(ret, keypad->reg_base + addr);
81
82 spin_unlock(&keypad->ske_keypad_lock);
83}
84
85/*
86 * ske_keypad_chip_init: init keypad controller configuration
87 *
88 * Enable Multi key press detection, auto scan mode
89 */
90static int __devinit ske_keypad_chip_init(struct ske_keypad *keypad)
91{
92 u32 value;
93 int timeout = 50;
94
95 /* check SKE_RIS to be 0 */
96 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
97 cpu_relax();
98
99 if (!timeout)
100 return -EINVAL;
101
102 /*
103 * set debounce value
104 * keypad dbounce is configured in DBCR[15:8]
105 * dbounce value in steps of 32/32.768 ms
106 */
107 spin_lock(&keypad->ske_keypad_lock);
108 value = readl(keypad->reg_base + SKE_DBCR);
109 value = value & 0xff;
110 value |= ((keypad->board->debounce_ms * 32000)/32768) << 8;
111 writel(value, keypad->reg_base + SKE_DBCR);
112 spin_unlock(&keypad->ske_keypad_lock);
113
114 /* enable multi key detection */
115 ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPMLT);
116
117 /*
118 * set up the number of columns
119 * KPCN[5:3] defines no. of keypad columns to be auto scanned
120 */
121 value = (keypad->board->kcol - 1) << 3;
122 ske_keypad_set_bits(keypad, SKE_CR, SKE_KPCN, value);
123
124 /* clear keypad interrupt for auto(and pending SW) scans */
125 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA | SKE_KPICS);
126
127 /* un-mask keypad interrupts */
128 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
129
130 /* enable automatic scan */
131 ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPASEN);
132
133 return 0;
134}
135
136static void ske_keypad_read_data(struct ske_keypad *keypad)
137{
138 struct input_dev *input = keypad->input;
139 u16 status;
140 int col = 0, row = 0, code;
141 int ske_asr, ske_ris, key_pressed, i;
142
143 /*
144 * Read the auto scan registers
145 *
146 * Each SKE_ASRx (x=0 to x=3) contains two row values.
147 * lower byte contains row value for column 2*x,
148 * upper byte contains row value for column 2*x + 1
149 */
150 for (i = 0; i < SKE_NUM_ASRX_REGISTERS; i++) {
151 ske_asr = readl(keypad->reg_base + SKE_ASR0 + (4 * i));
152 if (!ske_asr)
153 continue;
154
155 /* now that ASRx is zero, find out the column x and row y*/
156 if (ske_asr & 0xff) {
157 col = i * 2;
158 status = ske_asr & 0xff;
159 } else {
160 col = (i * 2) + 1;
161 status = (ske_asr & 0xff00) >> 8;
162 }
163
164 /* find out the row */
165 row = __ffs(status);
166
167 code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
168 ske_ris = readl(keypad->reg_base + SKE_RIS);
169 key_pressed = ske_ris & SKE_KPRISA;
170
171 input_event(input, EV_MSC, MSC_SCAN, code);
172 input_report_key(input, keypad->keymap[code], key_pressed);
173 input_sync(input);
174 }
175}
176
177static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
178{
179 struct ske_keypad *keypad = dev_id;
180 int retries = 20;
181
182 /* disable auto scan interrupt; mask the interrupt generated */
183 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
184 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
185
186 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --retries)
187 msleep(5);
188
189 if (retries) {
190 /* SKEx registers are stable and can be read */
191 ske_keypad_read_data(keypad);
192 }
193
194 /* enable auto scan interrupts */
195 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
196
197 return IRQ_HANDLED;
198}
199
200static int __devinit ske_keypad_probe(struct platform_device *pdev)
201{
202 const struct ske_keypad_platform_data *plat = pdev->dev.platform_data;
203 struct ske_keypad *keypad;
204 struct input_dev *input;
205 struct resource *res;
206 int irq;
207 int error;
208
209 if (!plat) {
210 dev_err(&pdev->dev, "invalid keypad platform data\n");
211 return -EINVAL;
212 }
213
214 irq = platform_get_irq(pdev, 0);
215 if (irq < 0) {
216 dev_err(&pdev->dev, "failed to get keypad irq\n");
217 return -EINVAL;
218 }
219
220 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
221 if (!res) {
222 dev_err(&pdev->dev, "missing platform resources\n");
223 return -EINVAL;
224 }
225
226 keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL);
227 input = input_allocate_device();
228 if (!keypad || !input) {
229 dev_err(&pdev->dev, "failed to allocate keypad memory\n");
230 error = -ENOMEM;
231 goto err_free_mem;
232 }
233
234 keypad->irq = irq;
235 keypad->board = plat;
236 keypad->input = input;
237 spin_lock_init(&keypad->ske_keypad_lock);
238
239 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
240 dev_err(&pdev->dev, "failed to request I/O memory\n");
241 error = -EBUSY;
242 goto err_free_mem;
243 }
244
245 keypad->reg_base = ioremap(res->start, resource_size(res));
246 if (!keypad->reg_base) {
247 dev_err(&pdev->dev, "failed to remap I/O memory\n");
248 error = -ENXIO;
249 goto err_free_mem_region;
250 }
251
252 keypad->clk = clk_get(&pdev->dev, NULL);
253 if (IS_ERR(keypad->clk)) {
254 dev_err(&pdev->dev, "failed to get clk\n");
255 error = PTR_ERR(keypad->clk);
256 goto err_iounmap;
257 }
258
259 input->id.bustype = BUS_HOST;
260 input->name = "ux500-ske-keypad";
261 input->dev.parent = &pdev->dev;
262
263 input->keycode = keypad->keymap;
264 input->keycodesize = sizeof(keypad->keymap[0]);
265 input->keycodemax = ARRAY_SIZE(keypad->keymap);
266
267 input_set_capability(input, EV_MSC, MSC_SCAN);
268
269 __set_bit(EV_KEY, input->evbit);
270 if (!plat->no_autorepeat)
271 __set_bit(EV_REP, input->evbit);
272
273 matrix_keypad_build_keymap(plat->keymap_data, SKE_KEYPAD_ROW_SHIFT,
274 input->keycode, input->keybit);
275
276 clk_enable(keypad->clk);
277
278 /* go through board initialization helpers */
279 if (keypad->board->init)
280 keypad->board->init();
281
282 error = ske_keypad_chip_init(keypad);
283 if (error) {
284 dev_err(&pdev->dev, "unable to init keypad hardware\n");
285 goto err_clk_disable;
286 }
287
288 error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq,
289 IRQF_ONESHOT, "ske-keypad", keypad);
290 if (error) {
291 dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq);
292 goto err_clk_disable;
293 }
294
295 error = input_register_device(input);
296 if (error) {
297 dev_err(&pdev->dev,
298 "unable to register input device: %d\n", error);
299 goto err_free_irq;
300 }
301
302 if (plat->wakeup_enable)
303 device_init_wakeup(&pdev->dev, true);
304
305 platform_set_drvdata(pdev, keypad);
306
307 return 0;
308
309err_free_irq:
310 free_irq(keypad->irq, keypad);
311err_clk_disable:
312 clk_disable(keypad->clk);
313 clk_put(keypad->clk);
314err_iounmap:
315 iounmap(keypad->reg_base);
316err_free_mem_region:
317 release_mem_region(res->start, resource_size(res));
318err_free_mem:
319 input_free_device(input);
320 kfree(keypad);
321 return error;
322}
323
324static int __devexit ske_keypad_remove(struct platform_device *pdev)
325{
326 struct ske_keypad *keypad = platform_get_drvdata(pdev);
327 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
328
329 free_irq(keypad->irq, keypad);
330
331 input_unregister_device(keypad->input);
332
333 clk_disable(keypad->clk);
334 clk_put(keypad->clk);
335
336 if (keypad->board->exit)
337 keypad->board->exit();
338
339 iounmap(keypad->reg_base);
340 release_mem_region(res->start, resource_size(res));
341 kfree(keypad);
342
343 return 0;
344}
345
346#ifdef CONFIG_PM
347static int ske_keypad_suspend(struct device *dev)
348{
349 struct platform_device *pdev = to_platform_device(dev);
350 struct ske_keypad *keypad = platform_get_drvdata(pdev);
351 int irq = platform_get_irq(pdev, 0);
352
353 if (device_may_wakeup(dev))
354 enable_irq_wake(irq);
355 else
356 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
357
358 return 0;
359}
360
361static int ske_keypad_resume(struct device *dev)
362{
363 struct platform_device *pdev = to_platform_device(dev);
364 struct ske_keypad *keypad = platform_get_drvdata(pdev);
365 int irq = platform_get_irq(pdev, 0);
366
367 if (device_may_wakeup(dev))
368 disable_irq_wake(irq);
369 else
370 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
371
372 return 0;
373}
374
375static const struct dev_pm_ops ske_keypad_dev_pm_ops = {
376 .suspend = ske_keypad_suspend,
377 .resume = ske_keypad_resume,
378};
379#endif
380
381struct platform_driver ske_keypad_driver = {
382 .driver = {
383 .name = "nmk-ske-keypad",
384 .owner = THIS_MODULE,
385#ifdef CONFIG_PM
386 .pm = &ske_keypad_dev_pm_ops,
387#endif
388 },
389 .probe = ske_keypad_probe,
390 .remove = __devexit_p(ske_keypad_remove),
391};
392
393static int __init ske_keypad_init(void)
394{
395 return platform_driver_probe(&ske_keypad_driver, ske_keypad_probe);
396}
397module_init(ske_keypad_init);
398
399static void __exit ske_keypad_exit(void)
400{
401 platform_driver_unregister(&ske_keypad_driver);
402}
403module_exit(ske_keypad_exit);
404
405MODULE_LICENSE("GPL v2");
406MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>");
407MODULE_DESCRIPTION("Nomadik Scroll-Key-Encoder Keypad Driver");
408MODULE_ALIAS("platform:nomadik-ske-keypad");
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
new file mode 100644
index 000000000000..45bd0977d006
--- /dev/null
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -0,0 +1,318 @@
1/*
2 * OMAP4 Keypad Driver
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * Author: Abraham Arce <x0066660@ti.com>
7 * Initial Code: Syed Rafiuddin <rafiuddin.syed@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/platform_device.h>
28#include <linux/errno.h>
29#include <linux/io.h>
30#include <linux/input.h>
31#include <linux/slab.h>
32
33#include <plat/omap4-keypad.h>
34
35/* OMAP4 registers */
36#define OMAP4_KBD_REVISION 0x00
37#define OMAP4_KBD_SYSCONFIG 0x10
38#define OMAP4_KBD_SYSSTATUS 0x14
39#define OMAP4_KBD_IRQSTATUS 0x18
40#define OMAP4_KBD_IRQENABLE 0x1C
41#define OMAP4_KBD_WAKEUPENABLE 0x20
42#define OMAP4_KBD_PENDING 0x24
43#define OMAP4_KBD_CTRL 0x28
44#define OMAP4_KBD_DEBOUNCINGTIME 0x2C
45#define OMAP4_KBD_LONGKEYTIME 0x30
46#define OMAP4_KBD_TIMEOUT 0x34
47#define OMAP4_KBD_STATEMACHINE 0x38
48#define OMAP4_KBD_ROWINPUTS 0x3C
49#define OMAP4_KBD_COLUMNOUTPUTS 0x40
50#define OMAP4_KBD_FULLCODE31_0 0x44
51#define OMAP4_KBD_FULLCODE63_32 0x48
52
53/* OMAP4 bit definitions */
54#define OMAP4_DEF_IRQENABLE_EVENTEN (1 << 0)
55#define OMAP4_DEF_IRQENABLE_LONGKEY (1 << 1)
56#define OMAP4_DEF_IRQENABLE_TIMEOUTEN (1 << 2)
57#define OMAP4_DEF_WUP_EVENT_ENA (1 << 0)
58#define OMAP4_DEF_WUP_LONG_KEY_ENA (1 << 1)
59#define OMAP4_DEF_CTRL_NOSOFTMODE (1 << 1)
60#define OMAP4_DEF_CTRLPTVVALUE (1 << 2)
61#define OMAP4_DEF_CTRLPTV (1 << 1)
62
63/* OMAP4 values */
64#define OMAP4_VAL_IRQDISABLE 0x00
65#define OMAP4_VAL_DEBOUNCINGTIME 0x07
66#define OMAP4_VAL_FUNCTIONALCFG 0x1E
67
68#define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
69
70struct omap4_keypad {
71 struct input_dev *input;
72
73 void __iomem *base;
74 int irq;
75
76 unsigned int rows;
77 unsigned int cols;
78 unsigned int row_shift;
79 unsigned char key_state[8];
80 unsigned short keymap[];
81};
82
83static void __devinit omap4_keypad_config(struct omap4_keypad *keypad_data)
84{
85 __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
86 keypad_data->base + OMAP4_KBD_CTRL);
87 __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
88 keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
89 __raw_writel(OMAP4_VAL_IRQDISABLE,
90 keypad_data->base + OMAP4_KBD_IRQSTATUS);
91 __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
92 keypad_data->base + OMAP4_KBD_IRQENABLE);
93 __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
94 keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
95}
96
97/* Interrupt handler */
98static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
99{
100 struct omap4_keypad *keypad_data = dev_id;
101 struct input_dev *input_dev = keypad_data->input;
102 unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)];
103 unsigned int col, row, code, changed;
104 u32 *new_state = (u32 *) key_state;
105
106 /* Disable interrupts */
107 __raw_writel(OMAP4_VAL_IRQDISABLE,
108 keypad_data->base + OMAP4_KBD_IRQENABLE);
109
110 *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
111 *(new_state + 1) = __raw_readl(keypad_data->base
112 + OMAP4_KBD_FULLCODE63_32);
113
114 for (row = 0; row < keypad_data->rows; row++) {
115 changed = key_state[row] ^ keypad_data->key_state[row];
116 if (!changed)
117 continue;
118
119 for (col = 0; col < keypad_data->cols; col++) {
120 if (changed & (1 << col)) {
121 code = MATRIX_SCAN_CODE(row, col,
122 keypad_data->row_shift);
123 input_event(input_dev, EV_MSC, MSC_SCAN, code);
124 input_report_key(input_dev,
125 keypad_data->keymap[code],
126 key_state[row] & (1 << col));
127 }
128 }
129 }
130
131 input_sync(input_dev);
132
133 memcpy(keypad_data->key_state, key_state,
134 sizeof(keypad_data->key_state));
135
136 /* clear pending interrupts */
137 __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
138 keypad_data->base + OMAP4_KBD_IRQSTATUS);
139
140 /* enable interrupts */
141 __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
142 keypad_data->base + OMAP4_KBD_IRQENABLE);
143
144 return IRQ_HANDLED;
145}
146
147static int __devinit omap4_keypad_probe(struct platform_device *pdev)
148{
149 const struct omap4_keypad_platform_data *pdata;
150 struct omap4_keypad *keypad_data;
151 struct input_dev *input_dev;
152 struct resource *res;
153 resource_size_t size;
154 unsigned int row_shift, max_keys;
155 int irq;
156 int error;
157
158 /* platform data */
159 pdata = pdev->dev.platform_data;
160 if (!pdata) {
161 dev_err(&pdev->dev, "no platform data defined\n");
162 return -EINVAL;
163 }
164
165 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
166 if (!res) {
167 dev_err(&pdev->dev, "no base address specified\n");
168 return -EINVAL;
169 }
170
171 irq = platform_get_irq(pdev, 0);
172 if (!irq) {
173 dev_err(&pdev->dev, "no keyboard irq assigned\n");
174 return -EINVAL;
175 }
176
177 if (!pdata->keymap_data) {
178 dev_err(&pdev->dev, "no keymap data defined\n");
179 return -EINVAL;
180 }
181
182 row_shift = get_count_order(pdata->cols);
183 max_keys = pdata->rows << row_shift;
184
185 keypad_data = kzalloc(sizeof(struct omap4_keypad) +
186 max_keys * sizeof(keypad_data->keymap[0]),
187 GFP_KERNEL);
188 if (!keypad_data) {
189 dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
190 return -ENOMEM;
191 }
192
193 size = resource_size(res);
194
195 res = request_mem_region(res->start, size, pdev->name);
196 if (!res) {
197 dev_err(&pdev->dev, "can't request mem region\n");
198 error = -EBUSY;
199 goto err_free_keypad;
200 }
201
202 keypad_data->base = ioremap(res->start, resource_size(res));
203 if (!keypad_data->base) {
204 dev_err(&pdev->dev, "can't ioremap mem resource\n");
205 error = -ENOMEM;
206 goto err_release_mem;
207 }
208
209 keypad_data->irq = irq;
210 keypad_data->row_shift = row_shift;
211 keypad_data->rows = pdata->rows;
212 keypad_data->cols = pdata->cols;
213
214 /* input device allocation */
215 keypad_data->input = input_dev = input_allocate_device();
216 if (!input_dev) {
217 error = -ENOMEM;
218 goto err_unmap;
219 }
220
221 input_dev->name = pdev->name;
222 input_dev->dev.parent = &pdev->dev;
223 input_dev->id.bustype = BUS_HOST;
224 input_dev->id.vendor = 0x0001;
225 input_dev->id.product = 0x0001;
226 input_dev->id.version = 0x0001;
227
228 input_dev->keycode = keypad_data->keymap;
229 input_dev->keycodesize = sizeof(keypad_data->keymap[0]);
230 input_dev->keycodemax = max_keys;
231
232 __set_bit(EV_KEY, input_dev->evbit);
233 __set_bit(EV_REP, input_dev->evbit);
234
235 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
236
237 input_set_drvdata(input_dev, keypad_data);
238
239 matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
240 input_dev->keycode, input_dev->keybit);
241
242 omap4_keypad_config(keypad_data);
243
244 error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
245 IRQF_TRIGGER_RISING,
246 "omap4-keypad", keypad_data);
247 if (error) {
248 dev_err(&pdev->dev, "failed to register interrupt\n");
249 goto err_free_input;
250 }
251
252 error = input_register_device(keypad_data->input);
253 if (error < 0) {
254 dev_err(&pdev->dev, "failed to register input device\n");
255 goto err_free_irq;
256 }
257
258
259 platform_set_drvdata(pdev, keypad_data);
260 return 0;
261
262err_free_irq:
263 free_irq(keypad_data->irq, keypad_data);
264err_free_input:
265 input_free_device(input_dev);
266err_unmap:
267 iounmap(keypad_data->base);
268err_release_mem:
269 release_mem_region(res->start, size);
270err_free_keypad:
271 kfree(keypad_data);
272 return error;
273}
274
275static int __devexit omap4_keypad_remove(struct platform_device *pdev)
276{
277 struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
278 struct resource *res;
279
280 free_irq(keypad_data->irq, keypad_data);
281 input_unregister_device(keypad_data->input);
282
283 iounmap(keypad_data->base);
284
285 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
286 release_mem_region(res->start, resource_size(res));
287
288 kfree(keypad_data);
289 platform_set_drvdata(pdev, NULL);
290
291 return 0;
292}
293
294static struct platform_driver omap4_keypad_driver = {
295 .probe = omap4_keypad_probe,
296 .remove = __devexit_p(omap4_keypad_remove),
297 .driver = {
298 .name = "omap4-keypad",
299 .owner = THIS_MODULE,
300 },
301};
302
303static int __init omap4_keypad_init(void)
304{
305 return platform_driver_register(&omap4_keypad_driver);
306}
307module_init(omap4_keypad_init);
308
309static void __exit omap4_keypad_exit(void)
310{
311 platform_driver_unregister(&omap4_keypad_driver);
312}
313module_exit(omap4_keypad_exit);
314
315MODULE_AUTHOR("Texas Instruments");
316MODULE_DESCRIPTION("OMAP4 Keypad Driver");
317MODULE_LICENSE("GPL");
318MODULE_ALIAS("platform:omap4-keypad");
diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c
index fb16b5e5ea13..09bef79d9da1 100644
--- a/drivers/input/keyboard/twl4030_keypad.c
+++ b/drivers/input/keyboard/twl4030_keypad.c
@@ -406,23 +406,22 @@ static int __devinit twl4030_kp_probe(struct platform_device *pdev)
406 if (error) { 406 if (error) {
407 dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n", 407 dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n",
408 kp->irq); 408 kp->irq);
409 goto err3; 409 goto err2;
410 } 410 }
411 411
412 /* Enable KP and TO interrupts now. */ 412 /* Enable KP and TO interrupts now. */
413 reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO); 413 reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO);
414 if (twl4030_kpwrite_u8(kp, reg, KEYP_IMR1)) { 414 if (twl4030_kpwrite_u8(kp, reg, KEYP_IMR1)) {
415 error = -EIO; 415 error = -EIO;
416 goto err4; 416 goto err3;
417 } 417 }
418 418
419 platform_set_drvdata(pdev, kp); 419 platform_set_drvdata(pdev, kp);
420 return 0; 420 return 0;
421 421
422err4: 422err3:
423 /* mask all events - we don't care about the result */ 423 /* mask all events - we don't care about the result */
424 (void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1); 424 (void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1);
425err3:
426 free_irq(kp->irq, NULL); 425 free_irq(kp->irq, NULL);
427err2: 426err2:
428 input_unregister_device(input); 427 input_unregister_device(input);