aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/input/keyboard
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/Kconfig144
-rw-r--r--drivers/input/keyboard/Makefile12
-rw-r--r--drivers/input/keyboard/aaed2000_kbd.c186
-rw-r--r--drivers/input/keyboard/adp5588-keys.c76
-rw-r--r--drivers/input/keyboard/adp5589-keys.c771
-rw-r--r--drivers/input/keyboard/atakbd.c5
-rw-r--r--drivers/input/keyboard/atkbd.c12
-rw-r--r--drivers/input/keyboard/davinci_keyscan.c2
-rw-r--r--drivers/input/keyboard/gpio_keys.c17
-rw-r--r--drivers/input/keyboard/gpio_keys_polled.c261
-rw-r--r--drivers/input/keyboard/hil_kbd.c2
-rw-r--r--drivers/input/keyboard/jornada680_kbd.c28
-rw-r--r--drivers/input/keyboard/lm8323.c19
-rw-r--r--drivers/input/keyboard/max7359_keypad.c17
-rw-r--r--drivers/input/keyboard/mcs_touchkey.c57
-rw-r--r--drivers/input/keyboard/mpr121_touchkey.c339
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c408
-rw-r--r--drivers/input/keyboard/omap-keypad.c42
-rw-r--r--drivers/input/keyboard/omap4-keypad.c354
-rw-r--r--drivers/input/keyboard/pmic8xxx-keypad.c800
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c12
-rw-r--r--drivers/input/keyboard/qt1070.c277
-rw-r--r--drivers/input/keyboard/sh_keysc.c55
-rw-r--r--drivers/input/keyboard/spear-keyboard.c344
-rw-r--r--drivers/input/keyboard/tc3589x-keypad.c472
-rw-r--r--drivers/input/keyboard/tca6416-keypad.c41
-rw-r--r--drivers/input/keyboard/tegra-kbc.c799
-rw-r--r--drivers/input/keyboard/tnetv107x-keypad.c341
-rw-r--r--drivers/input/keyboard/twl4030_keypad.c13
29 files changed, 5545 insertions, 361 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 9cc488d21490..b4dee9d5a055 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -2,7 +2,7 @@
2# Input core configuration 2# Input core configuration
3# 3#
4menuconfig INPUT_KEYBOARD 4menuconfig INPUT_KEYBOARD
5 bool "Keyboards" if EMBEDDED || !X86 5 bool "Keyboards" if EXPERT || !X86
6 default y 6 default y
7 help 7 help
8 Say Y here, and a list of supported keyboards will be displayed. 8 Say Y here, and a list of supported keyboards will be displayed.
@@ -12,18 +12,6 @@ menuconfig INPUT_KEYBOARD
12 12
13if INPUT_KEYBOARD 13if INPUT_KEYBOARD
14 14
15config KEYBOARD_AAED2000
16 tristate "AAED-2000 keyboard"
17 depends on MACH_AAED2000
18 select INPUT_POLLDEV
19 default y
20 help
21 Say Y here to enable the keyboard on the Agilent AAED-2000
22 development board.
23
24 To compile this driver as a module, choose M here: the
25 module will be called aaed2000_kbd.
26
27config KEYBOARD_ADP5520 15config KEYBOARD_ADP5520
28 tristate "Keypad Support for ADP5520 PMIC" 16 tristate "Keypad Support for ADP5520 PMIC"
29 depends on PMIC_ADP5520 17 depends on PMIC_ADP5520
@@ -44,6 +32,16 @@ config KEYBOARD_ADP5588
44 To compile this driver as a module, choose M here: the 32 To compile this driver as a module, choose M here: the
45 module will be called adp5588-keys. 33 module will be called adp5588-keys.
46 34
35config KEYBOARD_ADP5589
36 tristate "ADP5589 I2C QWERTY Keypad and IO Expander"
37 depends on I2C
38 help
39 Say Y here if you want to use a ADP5589 attached to your
40 system I2C bus.
41
42 To compile this driver as a module, choose M here: the
43 module will be called adp5589-keys.
44
47config KEYBOARD_AMIGA 45config KEYBOARD_AMIGA
48 tristate "Amiga keyboard" 46 tristate "Amiga keyboard"
49 depends on AMIGA 47 depends on AMIGA
@@ -69,7 +67,7 @@ config KEYBOARD_ATARI
69 module will be called atakbd. 67 module will be called atakbd.
70 68
71config KEYBOARD_ATKBD 69config KEYBOARD_ATKBD
72 tristate "AT keyboard" if EMBEDDED || !X86 70 tristate "AT keyboard" if EXPERT || !X86
73 default y 71 default y
74 select SERIO 72 select SERIO
75 select SERIO_LIBPS2 73 select SERIO_LIBPS2
@@ -124,6 +122,16 @@ config KEYBOARD_ATKBD_RDI_KEYCODES
124 right-hand column will be interpreted as the key shown in the 122 right-hand column will be interpreted as the key shown in the
125 left-hand column. 123 left-hand column.
126 124
125config KEYBOARD_QT1070
126 tristate "Atmel AT42QT1070 Touch Sensor Chip"
127 depends on I2C
128 help
129 Say Y here if you want to use Atmel AT42QT1070 QTouch
130 Sensor chip as input device.
131
132 To compile this driver as a module, choose M here:
133 the module will be called qt1070
134
127config KEYBOARD_QT2160 135config KEYBOARD_QT2160
128 tristate "Atmel AT42QT2160 Touch Sensor Chip" 136 tristate "Atmel AT42QT2160 Touch Sensor Chip"
129 depends on I2C && EXPERIMENTAL 137 depends on I2C && EXPERIMENTAL
@@ -179,21 +187,39 @@ config KEYBOARD_GPIO
179 To compile this driver as a module, choose M here: the 187 To compile this driver as a module, choose M here: the
180 module will be called gpio_keys. 188 module will be called gpio_keys.
181 189
190config KEYBOARD_GPIO_POLLED
191 tristate "Polled GPIO buttons"
192 depends on GENERIC_GPIO
193 select INPUT_POLLDEV
194 help
195 This driver implements support for buttons connected
196 to GPIO pins that are not capable of generating interrupts.
197
198 Say Y here if your device has buttons connected
199 directly to such GPIO pins. Your board-specific
200 setup logic must also provide a platform device,
201 with configuration data saying which GPIOs are used.
202
203 To compile this driver as a module, choose M here: the
204 module will be called gpio_keys_polled.
205
182config KEYBOARD_TCA6416 206config KEYBOARD_TCA6416
183 tristate "TCA6416 Keypad Support" 207 tristate "TCA6416/TCA6408A Keypad Support"
184 depends on I2C 208 depends on I2C
185 help 209 help
186 This driver implements basic keypad functionality 210 This driver implements basic keypad functionality
187 for keys connected through TCA6416 IO expander 211 for keys connected through TCA6416/TCA6408A IO expanders.
188 212
189 Say Y here if your device has keys connected to 213 Say Y here if your device has keys connected to
190 TCA6416 IO expander. Your board-specific setup logic 214 TCA6416/TCA6408A IO expander. Your board-specific setup logic
191 must also provide pin-mask details(of which TCA6416 pins 215 must also provide pin-mask details(of which TCA6416 pins
192 are used for keypad). 216 are used for keypad).
193 217
194 If enabled the complete TCA6416 device will be managed through 218 If enabled the entire TCA6416 device will be managed through
195 this driver. 219 this driver.
196 220
221 To compile this driver as a module, choose M here: the
222 module will be called tca6416_keypad.
197 223
198config KEYBOARD_MATRIX 224config KEYBOARD_MATRIX
199 tristate "GPIO driven matrix keypad support" 225 tristate "GPIO driven matrix keypad support"
@@ -309,6 +335,18 @@ config KEYBOARD_MCS
309 To compile this driver as a module, choose M here: the 335 To compile this driver as a module, choose M here: the
310 module will be called mcs_touchkey. 336 module will be called mcs_touchkey.
311 337
338config KEYBOARD_MPR121
339 tristate "Freescale MPR121 Touchkey"
340 depends on I2C
341 help
342 Say Y here if you have Freescale MPR121 touchkey controller
343 chip in your system.
344
345 If unsure, say N.
346
347 To compile this driver as a module, choose M here: the
348 module will be called mpr121_touchkey.
349
312config KEYBOARD_IMX 350config KEYBOARD_IMX
313 tristate "IMX keypad support" 351 tristate "IMX keypad support"
314 depends on ARCH_MXC 352 depends on ARCH_MXC
@@ -327,6 +365,26 @@ config KEYBOARD_NEWTON
327 To compile this driver as a module, choose M here: the 365 To compile this driver as a module, choose M here: the
328 module will be called newtonkbd. 366 module will be called newtonkbd.
329 367
368config KEYBOARD_NOMADIK
369 tristate "ST-Ericsson Nomadik SKE keyboard"
370 depends on PLAT_NOMADIK
371 help
372 Say Y here if you want to use a keypad provided on the SKE controller
373 used on the Ux500 and Nomadik platforms
374
375 To compile this driver as a module, choose M here: the
376 module will be called nmk-ske-keypad.
377
378config KEYBOARD_TEGRA
379 tristate "NVIDIA Tegra internal matrix keyboard controller support"
380 depends on ARCH_TEGRA
381 help
382 Say Y here if you want to use a matrix keyboard connected directly
383 to the internal keyboard controller on Tegra SoCs.
384
385 To compile this driver as a module, choose M here: the
386 module will be called tegra-kbc.
387
330config KEYBOARD_OPENCORES 388config KEYBOARD_OPENCORES
331 tristate "OpenCores Keyboard Controller" 389 tristate "OpenCores Keyboard Controller"
332 help 390 help
@@ -338,7 +396,7 @@ config KEYBOARD_OPENCORES
338 396
339config KEYBOARD_PXA27x 397config KEYBOARD_PXA27x
340 tristate "PXA27x/PXA3xx keypad support" 398 tristate "PXA27x/PXA3xx keypad support"
341 depends on PXA27x || PXA3xx 399 depends on PXA27x || PXA3xx || ARCH_MMP
342 help 400 help
343 Enable support for PXA27x/PXA3xx keypad controller. 401 Enable support for PXA27x/PXA3xx keypad controller.
344 402
@@ -354,6 +412,17 @@ config KEYBOARD_PXA930_ROTARY
354 To compile this driver as a module, choose M here: the 412 To compile this driver as a module, choose M here: the
355 module will be called pxa930_rotary. 413 module will be called pxa930_rotary.
356 414
415config KEYBOARD_PMIC8XXX
416 tristate "Qualcomm PMIC8XXX keypad support"
417 depends on MFD_PM8XXX
418 help
419 Say Y here if you want to enable the driver for the PMIC8XXX
420 keypad provided as a reference design from Qualcomm. This is intended
421 to support upto 18x8 matrix based keypad design.
422
423 To compile this driver as a module, choose M here: the module will
424 be called pmic8xxx-keypad.
425
357config KEYBOARD_SAMSUNG 426config KEYBOARD_SAMSUNG
358 tristate "Samsung keypad support" 427 tristate "Samsung keypad support"
359 depends on SAMSUNG_DEV_KEYPAD 428 depends on SAMSUNG_DEV_KEYPAD
@@ -424,6 +493,43 @@ config KEYBOARD_OMAP
424 To compile this driver as a module, choose M here: the 493 To compile this driver as a module, choose M here: the
425 module will be called omap-keypad. 494 module will be called omap-keypad.
426 495
496config KEYBOARD_OMAP4
497 tristate "TI OMAP4 keypad support"
498 depends on ARCH_OMAP4
499 help
500 Say Y here if you want to use the OMAP4 keypad.
501
502 To compile this driver as a module, choose M here: the
503 module will be called omap4-keypad.
504
505config KEYBOARD_SPEAR
506 tristate "ST SPEAR keyboard support"
507 depends on PLAT_SPEAR
508 help
509 Say Y here if you want to use the SPEAR keyboard.
510
511 To compile this driver as a module, choose M here: the
512 module will be called spear-keboard.
513
514config KEYBOARD_TC3589X
515 tristate "TC3589X Keypad support"
516 depends on MFD_TC3589X
517 help
518 Say Y here if you want to use the keypad controller on
519 TC35892/3 I/O expander.
520
521 To compile this driver as a module, choose M here: the
522 module will be called tc3589x-keypad.
523
524config KEYBOARD_TNETV107X
525 tristate "TI TNETV107X keypad support"
526 depends on ARCH_DAVINCI_TNETV107X
527 help
528 Say Y here if you want to use the TNETV107X keypad.
529
530 To compile this driver as a module, choose M here: the
531 module will be called tnetv107x-keypad.
532
427config KEYBOARD_TWL4030 533config KEYBOARD_TWL4030
428 tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" 534 tristate "TI TWL4030/TWL5030/TPS659x0 keypad support"
429 depends on TWL4030_CORE 535 depends on TWL4030_CORE
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 504b591be0cd..ddde0fd476f7 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -4,9 +4,9 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
8obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o 7obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o
9obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o 8obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o
9obj-$(CONFIG_KEYBOARD_ADP5589) += adp5589-keys.o
10obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o 10obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
11obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o 11obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o
12obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o 12obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o
@@ -14,6 +14,7 @@ obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o
14obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o 14obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o
15obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o 15obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
17obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o
17obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o 18obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o
18obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 19obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
19obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 20obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
@@ -27,17 +28,26 @@ obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
27obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o 28obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
28obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 29obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
29obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o 30obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
31obj-$(CONFIG_KEYBOARD_MPR121) += mpr121_touchkey.o
30obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 32obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
33obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o
31obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 34obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
35obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o
32obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o 36obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o
37obj-$(CONFIG_KEYBOARD_PMIC8XXX) += pmic8xxx-keypad.o
33obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o 38obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o
34obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o 39obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
40obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o
35obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o 41obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o
36obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o 42obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o
37obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o 43obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
44obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o
38obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o 45obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o
39obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 46obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
40obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o 47obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
48obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o
49obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o
50obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o
41obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o 51obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o
42obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o 52obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
43obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o 53obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o
diff --git a/drivers/input/keyboard/aaed2000_kbd.c b/drivers/input/keyboard/aaed2000_kbd.c
deleted file mode 100644
index 18222a689a03..000000000000
--- a/drivers/input/keyboard/aaed2000_kbd.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/*
2 * Keyboard driver for the AAED-2000 dev board
3 *
4 * Copyright (c) 2006 Nicolas Bellido Y Ortega
5 *
6 * Based on corgikbd.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/delay.h>
15#include <linux/platform_device.h>
16#include <linux/init.h>
17#include <linux/input-polldev.h>
18#include <linux/interrupt.h>
19#include <linux/jiffies.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22
23#include <mach/hardware.h>
24#include <mach/aaed2000.h>
25
26#define KB_ROWS 12
27#define KB_COLS 8
28#define KB_ROWMASK(r) (1 << (r))
29#define SCANCODE(r,c) (((c) * KB_ROWS) + (r))
30#define NR_SCANCODES (KB_COLS * KB_ROWS)
31
32#define SCAN_INTERVAL (50) /* ms */
33#define KB_ACTIVATE_DELAY (20) /* us */
34
35static unsigned char aaedkbd_keycode[NR_SCANCODES] = {
36 KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, 0, KEY_SPACE, KEY_KP6, 0, KEY_KPDOT, 0, 0,
37 KEY_K, KEY_M, KEY_O, KEY_DOT, KEY_SLASH, 0, KEY_F, 0, 0, 0, KEY_LEFTSHIFT, 0,
38 KEY_I, KEY_P, KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, 0, 0, 0, 0, KEY_RIGHTSHIFT, 0,
39 KEY_8, KEY_L, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_ENTER, 0, 0, 0, 0, 0, 0, 0,
40 KEY_J, KEY_H, KEY_B, KEY_KP8, KEY_KP4, 0, KEY_C, KEY_D, KEY_S, KEY_A, 0, KEY_CAPSLOCK,
41 KEY_Y, KEY_U, KEY_N, KEY_T, 0, 0, KEY_R, KEY_E, KEY_W, KEY_Q, 0, KEY_TAB,
42 KEY_7, KEY_6, KEY_G, 0, KEY_5, 0, KEY_4, KEY_3, KEY_2, KEY_1, 0, KEY_GRAVE,
43 0, 0, KEY_COMMA, 0, KEY_KP2, 0, KEY_V, KEY_LEFTALT, KEY_X, KEY_Z, 0, KEY_LEFTCTRL
44};
45
46struct aaedkbd {
47 unsigned char keycode[ARRAY_SIZE(aaedkbd_keycode)];
48 struct input_polled_dev *poll_dev;
49 int kbdscan_state[KB_COLS];
50 int kbdscan_count[KB_COLS];
51};
52
53#define KBDSCAN_STABLE_COUNT 2
54
55static void aaedkbd_report_col(struct aaedkbd *aaedkbd,
56 unsigned int col, unsigned int rowd)
57{
58 unsigned int scancode, pressed;
59 unsigned int row;
60
61 for (row = 0; row < KB_ROWS; row++) {
62 scancode = SCANCODE(row, col);
63 pressed = rowd & KB_ROWMASK(row);
64
65 input_report_key(aaedkbd->poll_dev->input,
66 aaedkbd->keycode[scancode], pressed);
67 }
68}
69
70/* Scan the hardware keyboard and push any changes up through the input layer */
71static void aaedkbd_poll(struct input_polled_dev *dev)
72{
73 struct aaedkbd *aaedkbd = dev->private;
74 unsigned int col, rowd;
75
76 col = 0;
77 do {
78 AAEC_GPIO_KSCAN = col + 8;
79 udelay(KB_ACTIVATE_DELAY);
80 rowd = AAED_EXT_GPIO & AAED_EGPIO_KBD_SCAN;
81
82 if (rowd != aaedkbd->kbdscan_state[col]) {
83 aaedkbd->kbdscan_count[col] = 0;
84 aaedkbd->kbdscan_state[col] = rowd;
85 } else if (++aaedkbd->kbdscan_count[col] >= KBDSCAN_STABLE_COUNT) {
86 aaedkbd_report_col(aaedkbd, col, rowd);
87 col++;
88 }
89 } while (col < KB_COLS);
90
91 AAEC_GPIO_KSCAN = 0x07;
92 input_sync(dev->input);
93}
94
95static int __devinit aaedkbd_probe(struct platform_device *pdev)
96{
97 struct aaedkbd *aaedkbd;
98 struct input_polled_dev *poll_dev;
99 struct input_dev *input_dev;
100 int i;
101 int error;
102
103 aaedkbd = kzalloc(sizeof(struct aaedkbd), GFP_KERNEL);
104 poll_dev = input_allocate_polled_device();
105 if (!aaedkbd || !poll_dev) {
106 error = -ENOMEM;
107 goto fail;
108 }
109
110 platform_set_drvdata(pdev, aaedkbd);
111
112 aaedkbd->poll_dev = poll_dev;
113 memcpy(aaedkbd->keycode, aaedkbd_keycode, sizeof(aaedkbd->keycode));
114
115 poll_dev->private = aaedkbd;
116 poll_dev->poll = aaedkbd_poll;
117 poll_dev->poll_interval = SCAN_INTERVAL;
118
119 input_dev = poll_dev->input;
120 input_dev->name = "AAED-2000 Keyboard";
121 input_dev->phys = "aaedkbd/input0";
122 input_dev->id.bustype = BUS_HOST;
123 input_dev->id.vendor = 0x0001;
124 input_dev->id.product = 0x0001;
125 input_dev->id.version = 0x0100;
126 input_dev->dev.parent = &pdev->dev;
127
128 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
129 input_dev->keycode = aaedkbd->keycode;
130 input_dev->keycodesize = sizeof(unsigned char);
131 input_dev->keycodemax = ARRAY_SIZE(aaedkbd_keycode);
132
133 for (i = 0; i < ARRAY_SIZE(aaedkbd_keycode); i++)
134 set_bit(aaedkbd->keycode[i], input_dev->keybit);
135 clear_bit(0, input_dev->keybit);
136
137 error = input_register_polled_device(aaedkbd->poll_dev);
138 if (error)
139 goto fail;
140
141 return 0;
142
143 fail: kfree(aaedkbd);
144 input_free_polled_device(poll_dev);
145 return error;
146}
147
148static int __devexit aaedkbd_remove(struct platform_device *pdev)
149{
150 struct aaedkbd *aaedkbd = platform_get_drvdata(pdev);
151
152 input_unregister_polled_device(aaedkbd->poll_dev);
153 input_free_polled_device(aaedkbd->poll_dev);
154 kfree(aaedkbd);
155
156 return 0;
157}
158
159/* work with hotplug and coldplug */
160MODULE_ALIAS("platform:aaed2000-keyboard");
161
162static struct platform_driver aaedkbd_driver = {
163 .probe = aaedkbd_probe,
164 .remove = __devexit_p(aaedkbd_remove),
165 .driver = {
166 .name = "aaed2000-keyboard",
167 .owner = THIS_MODULE,
168 },
169};
170
171static int __init aaedkbd_init(void)
172{
173 return platform_driver_register(&aaedkbd_driver);
174}
175
176static void __exit aaedkbd_exit(void)
177{
178 platform_driver_unregister(&aaedkbd_driver);
179}
180
181module_init(aaedkbd_init);
182module_exit(aaedkbd_exit);
183
184MODULE_AUTHOR("Nicolas Bellido Y Ortega");
185MODULE_DESCRIPTION("AAED-2000 Keyboard Driver");
186MODULE_LICENSE("GPL v2");
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index d6918cb966c0..af45d275f686 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -4,7 +4,7 @@
4 * I2C QWERTY Keypad and IO Expander 4 * I2C QWERTY Keypad and IO Expander
5 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 5 * Bugs: Enter bugs at http://blackfin.uclinux.org/
6 * 6 *
7 * Copyright (C) 2008-2009 Analog Devices Inc. 7 * Copyright (C) 2008-2010 Analog Devices Inc.
8 * Licensed under the GPL-2 or later. 8 * Licensed under the GPL-2 or later.
9 */ 9 */
10 10
@@ -24,29 +24,6 @@
24 24
25#include <linux/i2c/adp5588.h> 25#include <linux/i2c/adp5588.h>
26 26
27 /* Configuration Register1 */
28#define AUTO_INC (1 << 7)
29#define GPIEM_CFG (1 << 6)
30#define OVR_FLOW_M (1 << 5)
31#define INT_CFG (1 << 4)
32#define OVR_FLOW_IEN (1 << 3)
33#define K_LCK_IM (1 << 2)
34#define GPI_IEN (1 << 1)
35#define KE_IEN (1 << 0)
36
37/* Interrupt Status Register */
38#define CMP2_INT (1 << 5)
39#define CMP1_INT (1 << 4)
40#define OVR_FLOW_INT (1 << 3)
41#define K_LCK_INT (1 << 2)
42#define GPI_INT (1 << 1)
43#define KE_INT (1 << 0)
44
45/* Key Lock and Event Counter Register */
46#define K_LCK_EN (1 << 6)
47#define LCK21 0x30
48#define KEC 0xF
49
50/* Key Event Register xy */ 27/* Key Event Register xy */
51#define KEY_EV_PRESSED (1 << 7) 28#define KEY_EV_PRESSED (1 << 7)
52#define KEY_EV_MASK (0x7F) 29#define KEY_EV_MASK (0x7F)
@@ -55,10 +32,6 @@
55 32
56#define KEYP_MAX_EVENT 10 33#define KEYP_MAX_EVENT 10
57 34
58#define MAXGPIO 18
59#define ADP_BANK(offs) ((offs) >> 3)
60#define ADP_BIT(offs) (1u << ((offs) & 0x7))
61
62/* 35/*
63 * Early pre 4.0 Silicon required to delay readout by at least 25ms, 36 * Early pre 4.0 Silicon required to delay readout by at least 25ms,
64 * since the Event Counter Register updated 25ms after the interrupt 37 * since the Event Counter Register updated 25ms after the interrupt
@@ -75,7 +48,7 @@ struct adp5588_kpad {
75 const struct adp5588_gpi_map *gpimap; 48 const struct adp5588_gpi_map *gpimap;
76 unsigned short gpimapsize; 49 unsigned short gpimapsize;
77#ifdef CONFIG_GPIOLIB 50#ifdef CONFIG_GPIOLIB
78 unsigned char gpiomap[MAXGPIO]; 51 unsigned char gpiomap[ADP5588_MAXGPIO];
79 bool export_gpio; 52 bool export_gpio;
80 struct gpio_chip gc; 53 struct gpio_chip gc;
81 struct mutex gpio_lock; /* Protect cached dir, dat_out */ 54 struct mutex gpio_lock; /* Protect cached dir, dat_out */
@@ -103,8 +76,8 @@ static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
103static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off) 76static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
104{ 77{
105 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 78 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
106 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 79 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
107 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 80 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
108 81
109 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit); 82 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit);
110} 83}
@@ -113,8 +86,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
113 unsigned off, int val) 86 unsigned off, int val)
114{ 87{
115 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 88 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
116 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 89 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
117 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 90 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
118 91
119 mutex_lock(&kpad->gpio_lock); 92 mutex_lock(&kpad->gpio_lock);
120 93
@@ -132,8 +105,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
132static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off) 105static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
133{ 106{
134 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 107 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
135 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 108 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
136 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 109 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
137 int ret; 110 int ret;
138 111
139 mutex_lock(&kpad->gpio_lock); 112 mutex_lock(&kpad->gpio_lock);
@@ -150,8 +123,8 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
150 unsigned off, int val) 123 unsigned off, int val)
151{ 124{
152 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 125 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
153 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 126 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
154 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 127 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
155 int ret; 128 int ret;
156 129
157 mutex_lock(&kpad->gpio_lock); 130 mutex_lock(&kpad->gpio_lock);
@@ -176,7 +149,7 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
176static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad, 149static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
177 const struct adp5588_kpad_platform_data *pdata) 150 const struct adp5588_kpad_platform_data *pdata)
178{ 151{
179 bool pin_used[MAXGPIO]; 152 bool pin_used[ADP5588_MAXGPIO];
180 int n_unused = 0; 153 int n_unused = 0;
181 int i; 154 int i;
182 155
@@ -191,7 +164,7 @@ static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
191 for (i = 0; i < kpad->gpimapsize; i++) 164 for (i = 0; i < kpad->gpimapsize; i++)
192 pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true; 165 pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true;
193 166
194 for (i = 0; i < MAXGPIO; i++) 167 for (i = 0; i < ADP5588_MAXGPIO; i++)
195 if (!pin_used[i]) 168 if (!pin_used[i])
196 kpad->gpiomap[n_unused++] = i; 169 kpad->gpiomap[n_unused++] = i;
197 170
@@ -234,7 +207,7 @@ static int __devinit adp5588_gpio_add(struct adp5588_kpad *kpad)
234 return error; 207 return error;
235 } 208 }
236 209
237 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) { 210 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
238 kpad->dat_out[i] = adp5588_read(kpad->client, 211 kpad->dat_out[i] = adp5588_read(kpad->client,
239 GPIO_DAT_OUT1 + i); 212 GPIO_DAT_OUT1 + i);
240 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i); 213 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i);
@@ -318,11 +291,11 @@ static void adp5588_work(struct work_struct *work)
318 291
319 status = adp5588_read(client, INT_STAT); 292 status = adp5588_read(client, INT_STAT);
320 293
321 if (status & OVR_FLOW_INT) /* Unlikely and should never happen */ 294 if (status & ADP5588_OVR_FLOW_INT) /* Unlikely and should never happen */
322 dev_err(&client->dev, "Event Overflow Error\n"); 295 dev_err(&client->dev, "Event Overflow Error\n");
323 296
324 if (status & KE_INT) { 297 if (status & ADP5588_KE_INT) {
325 ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & KEC; 298 ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & ADP5588_KEC;
326 if (ev_cnt) { 299 if (ev_cnt) {
327 adp5588_report_events(kpad, ev_cnt); 300 adp5588_report_events(kpad, ev_cnt);
328 input_sync(kpad->input); 301 input_sync(kpad->input);
@@ -360,7 +333,7 @@ static int __devinit adp5588_setup(struct i2c_client *client)
360 if (pdata->en_keylock) { 333 if (pdata->en_keylock) {
361 ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1); 334 ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
362 ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2); 335 ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
363 ret |= adp5588_write(client, KEY_LCK_EC_STAT, K_LCK_EN); 336 ret |= adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
364 } 337 }
365 338
366 for (i = 0; i < KEYP_MAX_EVENT; i++) 339 for (i = 0; i < KEYP_MAX_EVENT; i++)
@@ -384,7 +357,7 @@ static int __devinit adp5588_setup(struct i2c_client *client)
384 } 357 }
385 358
386 if (gpio_data) { 359 if (gpio_data) {
387 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) { 360 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
388 int pull_mask = gpio_data->pullup_dis_mask; 361 int pull_mask = gpio_data->pullup_dis_mask;
389 362
390 ret |= adp5588_write(client, GPIO_PULL1 + i, 363 ret |= adp5588_write(client, GPIO_PULL1 + i,
@@ -392,11 +365,14 @@ static int __devinit adp5588_setup(struct i2c_client *client)
392 } 365 }
393 } 366 }
394 367
395 ret |= adp5588_write(client, INT_STAT, CMP2_INT | CMP1_INT | 368 ret |= adp5588_write(client, INT_STAT,
396 OVR_FLOW_INT | K_LCK_INT | 369 ADP5588_CMP2_INT | ADP5588_CMP1_INT |
397 GPI_INT | KE_INT); /* Status is W1C */ 370 ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
371 ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
398 372
399 ret |= adp5588_write(client, CFG, INT_CFG | OVR_FLOW_IEN | KE_IEN); 373 ret |= adp5588_write(client, CFG, ADP5588_INT_CFG |
374 ADP5588_OVR_FLOW_IEN |
375 ADP5588_KE_IEN);
400 376
401 if (ret < 0) { 377 if (ret < 0) {
402 dev_err(&client->dev, "Write Error\n"); 378 dev_err(&client->dev, "Write Error\n");
@@ -660,7 +636,7 @@ static const struct dev_pm_ops adp5588_dev_pm_ops = {
660#endif 636#endif
661 637
662static const struct i2c_device_id adp5588_id[] = { 638static const struct i2c_device_id adp5588_id[] = {
663 { KBUILD_MODNAME, 0 }, 639 { "adp5588-keys", 0 },
664 { "adp5587-keys", 0 }, 640 { "adp5587-keys", 0 },
665 { } 641 { }
666}; 642};
diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
new file mode 100644
index 000000000000..631598663aab
--- /dev/null
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -0,0 +1,771 @@
1/*
2 * Description: keypad driver for ADP5589
3 * I2C QWERTY Keypad and IO Expander
4 * Bugs: Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2010-2011 Analog Devices Inc.
7 * Licensed under the GPL-2.
8 */
9
10#include <linux/module.h>
11#include <linux/version.h>
12#include <linux/init.h>
13#include <linux/interrupt.h>
14#include <linux/irq.h>
15#include <linux/workqueue.h>
16#include <linux/errno.h>
17#include <linux/pm.h>
18#include <linux/platform_device.h>
19#include <linux/input.h>
20#include <linux/i2c.h>
21#include <linux/gpio.h>
22#include <linux/slab.h>
23
24#include <linux/input/adp5589.h>
25
26/* GENERAL_CFG Register */
27#define OSC_EN (1 << 7)
28#define CORE_CLK(x) (((x) & 0x3) << 5)
29#define LCK_TRK_LOGIC (1 << 4)
30#define LCK_TRK_GPI (1 << 3)
31#define INT_CFG (1 << 1)
32#define RST_CFG (1 << 0)
33
34/* INT_EN Register */
35#define LOGIC2_IEN (1 << 5)
36#define LOGIC1_IEN (1 << 4)
37#define LOCK_IEN (1 << 3)
38#define OVRFLOW_IEN (1 << 2)
39#define GPI_IEN (1 << 1)
40#define EVENT_IEN (1 << 0)
41
42/* Interrupt Status Register */
43#define LOGIC2_INT (1 << 5)
44#define LOGIC1_INT (1 << 4)
45#define LOCK_INT (1 << 3)
46#define OVRFLOW_INT (1 << 2)
47#define GPI_INT (1 << 1)
48#define EVENT_INT (1 << 0)
49
50/* STATUS Register */
51
52#define LOGIC2_STAT (1 << 7)
53#define LOGIC1_STAT (1 << 6)
54#define LOCK_STAT (1 << 5)
55#define KEC 0xF
56
57/* PIN_CONFIG_D Register */
58#define C4_EXTEND_CFG (1 << 6) /* RESET2 */
59#define R4_EXTEND_CFG (1 << 5) /* RESET1 */
60
61/* LOCK_CFG */
62#define LOCK_EN (1 << 0)
63
64#define PTIME_MASK 0x3
65#define LTIME_MASK 0x3
66
67/* Key Event Register xy */
68#define KEY_EV_PRESSED (1 << 7)
69#define KEY_EV_MASK (0x7F)
70
71#define KEYP_MAX_EVENT 16
72
73#define MAXGPIO 19
74#define ADP_BANK(offs) ((offs) >> 3)
75#define ADP_BIT(offs) (1u << ((offs) & 0x7))
76
77struct adp5589_kpad {
78 struct i2c_client *client;
79 struct input_dev *input;
80 unsigned short keycode[ADP5589_KEYMAPSIZE];
81 const struct adp5589_gpi_map *gpimap;
82 unsigned short gpimapsize;
83 unsigned extend_cfg;
84#ifdef CONFIG_GPIOLIB
85 unsigned char gpiomap[MAXGPIO];
86 bool export_gpio;
87 struct gpio_chip gc;
88 struct mutex gpio_lock; /* Protect cached dir, dat_out */
89 u8 dat_out[3];
90 u8 dir[3];
91#endif
92};
93
94static int adp5589_read(struct i2c_client *client, u8 reg)
95{
96 int ret = i2c_smbus_read_byte_data(client, reg);
97
98 if (ret < 0)
99 dev_err(&client->dev, "Read Error\n");
100
101 return ret;
102}
103
104static int adp5589_write(struct i2c_client *client, u8 reg, u8 val)
105{
106 return i2c_smbus_write_byte_data(client, reg, val);
107}
108
109#ifdef CONFIG_GPIOLIB
110static int adp5589_gpio_get_value(struct gpio_chip *chip, unsigned off)
111{
112 struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
113 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
114 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
115
116 return !!(adp5589_read(kpad->client, ADP5589_GPI_STATUS_A + bank) &
117 bit);
118}
119
120static void adp5589_gpio_set_value(struct gpio_chip *chip,
121 unsigned off, int val)
122{
123 struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
124 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
125 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
126
127 mutex_lock(&kpad->gpio_lock);
128
129 if (val)
130 kpad->dat_out[bank] |= bit;
131 else
132 kpad->dat_out[bank] &= ~bit;
133
134 adp5589_write(kpad->client, ADP5589_GPO_DATA_OUT_A + bank,
135 kpad->dat_out[bank]);
136
137 mutex_unlock(&kpad->gpio_lock);
138}
139
140static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off)
141{
142 struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
143 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
144 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
145 int ret;
146
147 mutex_lock(&kpad->gpio_lock);
148
149 kpad->dir[bank] &= ~bit;
150 ret = adp5589_write(kpad->client, ADP5589_GPIO_DIRECTION_A + bank,
151 kpad->dir[bank]);
152
153 mutex_unlock(&kpad->gpio_lock);
154
155 return ret;
156}
157
158static int adp5589_gpio_direction_output(struct gpio_chip *chip,
159 unsigned off, int val)
160{
161 struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
162 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
163 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
164 int ret;
165
166 mutex_lock(&kpad->gpio_lock);
167
168 kpad->dir[bank] |= bit;
169
170 if (val)
171 kpad->dat_out[bank] |= bit;
172 else
173 kpad->dat_out[bank] &= ~bit;
174
175 ret = adp5589_write(kpad->client, ADP5589_GPO_DATA_OUT_A + bank,
176 kpad->dat_out[bank]);
177 ret |= adp5589_write(kpad->client, ADP5589_GPIO_DIRECTION_A + bank,
178 kpad->dir[bank]);
179
180 mutex_unlock(&kpad->gpio_lock);
181
182 return ret;
183}
184
185static int __devinit adp5589_build_gpiomap(struct adp5589_kpad *kpad,
186 const struct adp5589_kpad_platform_data *pdata)
187{
188 bool pin_used[MAXGPIO];
189 int n_unused = 0;
190 int i;
191
192 memset(pin_used, false, sizeof(pin_used));
193
194 for (i = 0; i < MAXGPIO; i++)
195 if (pdata->keypad_en_mask & (1 << i))
196 pin_used[i] = true;
197
198 for (i = 0; i < kpad->gpimapsize; i++)
199 pin_used[kpad->gpimap[i].pin - ADP5589_GPI_PIN_BASE] = true;
200
201 if (kpad->extend_cfg & R4_EXTEND_CFG)
202 pin_used[4] = true;
203
204 if (kpad->extend_cfg & C4_EXTEND_CFG)
205 pin_used[12] = true;
206
207 for (i = 0; i < MAXGPIO; i++)
208 if (!pin_used[i])
209 kpad->gpiomap[n_unused++] = i;
210
211 return n_unused;
212}
213
214static int __devinit adp5589_gpio_add(struct adp5589_kpad *kpad)
215{
216 struct device *dev = &kpad->client->dev;
217 const struct adp5589_kpad_platform_data *pdata = dev->platform_data;
218 const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
219 int i, error;
220
221 if (!gpio_data)
222 return 0;
223
224 kpad->gc.ngpio = adp5589_build_gpiomap(kpad, pdata);
225 if (kpad->gc.ngpio == 0) {
226 dev_info(dev, "No unused gpios left to export\n");
227 return 0;
228 }
229
230 kpad->export_gpio = true;
231
232 kpad->gc.direction_input = adp5589_gpio_direction_input;
233 kpad->gc.direction_output = adp5589_gpio_direction_output;
234 kpad->gc.get = adp5589_gpio_get_value;
235 kpad->gc.set = adp5589_gpio_set_value;
236 kpad->gc.can_sleep = 1;
237
238 kpad->gc.base = gpio_data->gpio_start;
239 kpad->gc.label = kpad->client->name;
240 kpad->gc.owner = THIS_MODULE;
241
242 mutex_init(&kpad->gpio_lock);
243
244 error = gpiochip_add(&kpad->gc);
245 if (error) {
246 dev_err(dev, "gpiochip_add failed, err: %d\n", error);
247 return error;
248 }
249
250 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
251 kpad->dat_out[i] = adp5589_read(kpad->client,
252 ADP5589_GPO_DATA_OUT_A + i);
253 kpad->dir[i] = adp5589_read(kpad->client,
254 ADP5589_GPIO_DIRECTION_A + i);
255 }
256
257 if (gpio_data->setup) {
258 error = gpio_data->setup(kpad->client,
259 kpad->gc.base, kpad->gc.ngpio,
260 gpio_data->context);
261 if (error)
262 dev_warn(dev, "setup failed, %d\n", error);
263 }
264
265 return 0;
266}
267
268static void __devexit adp5589_gpio_remove(struct adp5589_kpad *kpad)
269{
270 struct device *dev = &kpad->client->dev;
271 const struct adp5589_kpad_platform_data *pdata = dev->platform_data;
272 const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
273 int error;
274
275 if (!kpad->export_gpio)
276 return;
277
278 if (gpio_data->teardown) {
279 error = gpio_data->teardown(kpad->client,
280 kpad->gc.base, kpad->gc.ngpio,
281 gpio_data->context);
282 if (error)
283 dev_warn(dev, "teardown failed %d\n", error);
284 }
285
286 error = gpiochip_remove(&kpad->gc);
287 if (error)
288 dev_warn(dev, "gpiochip_remove failed %d\n", error);
289}
290#else
291static inline int adp5589_gpio_add(struct adp5589_kpad *kpad)
292{
293 return 0;
294}
295
296static inline void adp5589_gpio_remove(struct adp5589_kpad *kpad)
297{
298}
299#endif
300
301static void adp5589_report_switches(struct adp5589_kpad *kpad,
302 int key, int key_val)
303{
304 int i;
305
306 for (i = 0; i < kpad->gpimapsize; i++) {
307 if (key_val == kpad->gpimap[i].pin) {
308 input_report_switch(kpad->input,
309 kpad->gpimap[i].sw_evt,
310 key & KEY_EV_PRESSED);
311 break;
312 }
313 }
314}
315
316static void adp5589_report_events(struct adp5589_kpad *kpad, int ev_cnt)
317{
318 int i;
319
320 for (i = 0; i < ev_cnt; i++) {
321 int key = adp5589_read(kpad->client, ADP5589_FIFO_1 + i);
322 int key_val = key & KEY_EV_MASK;
323
324 if (key_val >= ADP5589_GPI_PIN_BASE &&
325 key_val <= ADP5589_GPI_PIN_END) {
326 adp5589_report_switches(kpad, key, key_val);
327 } else {
328 input_report_key(kpad->input,
329 kpad->keycode[key_val - 1],
330 key & KEY_EV_PRESSED);
331 }
332 }
333}
334
335static irqreturn_t adp5589_irq(int irq, void *handle)
336{
337 struct adp5589_kpad *kpad = handle;
338 struct i2c_client *client = kpad->client;
339 int status, ev_cnt;
340
341 status = adp5589_read(client, ADP5589_INT_STATUS);
342
343 if (status & OVRFLOW_INT) /* Unlikely and should never happen */
344 dev_err(&client->dev, "Event Overflow Error\n");
345
346 if (status & EVENT_INT) {
347 ev_cnt = adp5589_read(client, ADP5589_STATUS) & KEC;
348 if (ev_cnt) {
349 adp5589_report_events(kpad, ev_cnt);
350 input_sync(kpad->input);
351 }
352 }
353
354 adp5589_write(client, ADP5589_INT_STATUS, status); /* Status is W1C */
355
356 return IRQ_HANDLED;
357}
358
359static int __devinit adp5589_get_evcode(struct adp5589_kpad *kpad, unsigned short key)
360{
361 int i;
362
363 for (i = 0; i < ADP5589_KEYMAPSIZE; i++)
364 if (key == kpad->keycode[i])
365 return (i + 1) | KEY_EV_PRESSED;
366
367 dev_err(&kpad->client->dev, "RESET/UNLOCK key not in keycode map\n");
368
369 return -EINVAL;
370}
371
372static int __devinit adp5589_setup(struct adp5589_kpad *kpad)
373{
374 struct i2c_client *client = kpad->client;
375 const struct adp5589_kpad_platform_data *pdata =
376 client->dev.platform_data;
377 int i, ret;
378 unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
379 unsigned char pull_mask = 0;
380
381 ret = adp5589_write(client, ADP5589_PIN_CONFIG_A,
382 pdata->keypad_en_mask & 0xFF);
383 ret |= adp5589_write(client, ADP5589_PIN_CONFIG_B,
384 (pdata->keypad_en_mask >> 8) & 0xFF);
385 ret |= adp5589_write(client, ADP5589_PIN_CONFIG_C,
386 (pdata->keypad_en_mask >> 16) & 0xFF);
387
388 if (pdata->en_keylock) {
389 ret |= adp5589_write(client, ADP5589_UNLOCK1,
390 pdata->unlock_key1);
391 ret |= adp5589_write(client, ADP5589_UNLOCK2,
392 pdata->unlock_key2);
393 ret |= adp5589_write(client, ADP5589_UNLOCK_TIMERS,
394 pdata->unlock_timer & LTIME_MASK);
395 ret |= adp5589_write(client, ADP5589_LOCK_CFG, LOCK_EN);
396 }
397
398 for (i = 0; i < KEYP_MAX_EVENT; i++)
399 ret |= adp5589_read(client, ADP5589_FIFO_1 + i);
400
401 for (i = 0; i < pdata->gpimapsize; i++) {
402 unsigned short pin = pdata->gpimap[i].pin;
403
404 if (pin <= ADP5589_GPI_PIN_ROW_END) {
405 evt_mode1 |= (1 << (pin - ADP5589_GPI_PIN_ROW_BASE));
406 } else {
407 evt_mode2 |=
408 ((1 << (pin - ADP5589_GPI_PIN_COL_BASE)) & 0xFF);
409 evt_mode3 |=
410 ((1 << (pin - ADP5589_GPI_PIN_COL_BASE)) >> 8);
411 }
412 }
413
414 if (pdata->gpimapsize) {
415 ret |= adp5589_write(client, ADP5589_GPI_EVENT_EN_A, evt_mode1);
416 ret |= adp5589_write(client, ADP5589_GPI_EVENT_EN_B, evt_mode2);
417 ret |= adp5589_write(client, ADP5589_GPI_EVENT_EN_C, evt_mode3);
418 }
419
420 if (pdata->pull_dis_mask & pdata->pullup_en_100k &
421 pdata->pullup_en_300k & pdata->pulldown_en_300k)
422 dev_warn(&client->dev, "Conflicting pull resistor config\n");
423
424 for (i = 0; i < MAXGPIO; i++) {
425 unsigned val = 0;
426
427 if (pdata->pullup_en_300k & (1 << i))
428 val = 0;
429 else if (pdata->pulldown_en_300k & (1 << i))
430 val = 1;
431 else if (pdata->pullup_en_100k & (1 << i))
432 val = 2;
433 else if (pdata->pull_dis_mask & (1 << i))
434 val = 3;
435
436 pull_mask |= val << (2 * (i & 0x3));
437
438 if ((i & 0x3) == 0x3 || i == MAXGPIO - 1) {
439 ret |= adp5589_write(client,
440 ADP5589_RPULL_CONFIG_A + (i >> 2),
441 pull_mask);
442 pull_mask = 0;
443 }
444 }
445
446 if (pdata->reset1_key_1 && pdata->reset1_key_2 && pdata->reset1_key_3) {
447 ret |= adp5589_write(client, ADP5589_RESET1_EVENT_A,
448 adp5589_get_evcode(kpad,
449 pdata->reset1_key_1));
450 ret |= adp5589_write(client, ADP5589_RESET1_EVENT_B,
451 adp5589_get_evcode(kpad,
452 pdata->reset1_key_2));
453 ret |= adp5589_write(client, ADP5589_RESET1_EVENT_C,
454 adp5589_get_evcode(kpad,
455 pdata->reset1_key_3));
456 kpad->extend_cfg |= R4_EXTEND_CFG;
457 }
458
459 if (pdata->reset2_key_1 && pdata->reset2_key_2) {
460 ret |= adp5589_write(client, ADP5589_RESET2_EVENT_A,
461 adp5589_get_evcode(kpad,
462 pdata->reset2_key_1));
463 ret |= adp5589_write(client, ADP5589_RESET2_EVENT_B,
464 adp5589_get_evcode(kpad,
465 pdata->reset2_key_2));
466 kpad->extend_cfg |= C4_EXTEND_CFG;
467 }
468
469 if (kpad->extend_cfg) {
470 ret |= adp5589_write(client, ADP5589_RESET_CFG,
471 pdata->reset_cfg);
472 ret |= adp5589_write(client, ADP5589_PIN_CONFIG_D,
473 kpad->extend_cfg);
474 }
475
476 for (i = 0; i <= ADP_BANK(MAXGPIO); i++)
477 ret |= adp5589_write(client, ADP5589_DEBOUNCE_DIS_A + i,
478 pdata->debounce_dis_mask >> (i * 8));
479
480 ret |= adp5589_write(client, ADP5589_POLL_PTIME_CFG,
481 pdata->scan_cycle_time & PTIME_MASK);
482 ret |= adp5589_write(client, ADP5589_INT_STATUS, LOGIC2_INT |
483 LOGIC1_INT | OVRFLOW_INT | LOCK_INT |
484 GPI_INT | EVENT_INT); /* Status is W1C */
485
486 ret |= adp5589_write(client, ADP5589_GENERAL_CFG,
487 INT_CFG | OSC_EN | CORE_CLK(3));
488 ret |= adp5589_write(client, ADP5589_INT_EN,
489 OVRFLOW_IEN | GPI_IEN | EVENT_IEN);
490
491 if (ret < 0) {
492 dev_err(&client->dev, "Write Error\n");
493 return ret;
494 }
495
496 return 0;
497}
498
499static void __devinit adp5589_report_switch_state(struct adp5589_kpad *kpad)
500{
501 int gpi_stat1 = adp5589_read(kpad->client, ADP5589_GPI_STATUS_A);
502 int gpi_stat2 = adp5589_read(kpad->client, ADP5589_GPI_STATUS_B);
503 int gpi_stat3 = adp5589_read(kpad->client, ADP5589_GPI_STATUS_C);
504 int gpi_stat_tmp, pin_loc;
505 int i;
506
507 for (i = 0; i < kpad->gpimapsize; i++) {
508 unsigned short pin = kpad->gpimap[i].pin;
509
510 if (pin <= ADP5589_GPI_PIN_ROW_END) {
511 gpi_stat_tmp = gpi_stat1;
512 pin_loc = pin - ADP5589_GPI_PIN_ROW_BASE;
513 } else if ((pin - ADP5589_GPI_PIN_COL_BASE) < 8) {
514 gpi_stat_tmp = gpi_stat2;
515 pin_loc = pin - ADP5589_GPI_PIN_COL_BASE;
516 } else {
517 gpi_stat_tmp = gpi_stat3;
518 pin_loc = pin - ADP5589_GPI_PIN_COL_BASE - 8;
519 }
520
521 if (gpi_stat_tmp < 0) {
522 dev_err(&kpad->client->dev,
523 "Can't read GPIO_DAT_STAT switch"
524 " %d default to OFF\n", pin);
525 gpi_stat_tmp = 0;
526 }
527
528 input_report_switch(kpad->input,
529 kpad->gpimap[i].sw_evt,
530 !(gpi_stat_tmp & (1 << pin_loc)));
531 }
532
533 input_sync(kpad->input);
534}
535
536static int __devinit adp5589_probe(struct i2c_client *client,
537 const struct i2c_device_id *id)
538{
539 struct adp5589_kpad *kpad;
540 const struct adp5589_kpad_platform_data *pdata;
541 struct input_dev *input;
542 unsigned int revid;
543 int ret, i;
544 int error;
545
546 if (!i2c_check_functionality(client->adapter,
547 I2C_FUNC_SMBUS_BYTE_DATA)) {
548 dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
549 return -EIO;
550 }
551
552 pdata = client->dev.platform_data;
553 if (!pdata) {
554 dev_err(&client->dev, "no platform data?\n");
555 return -EINVAL;
556 }
557
558 if (!((pdata->keypad_en_mask & 0xFF) &&
559 (pdata->keypad_en_mask >> 8)) || !pdata->keymap) {
560 dev_err(&client->dev, "no rows, cols or keymap from pdata\n");
561 return -EINVAL;
562 }
563
564 if (pdata->keymapsize != ADP5589_KEYMAPSIZE) {
565 dev_err(&client->dev, "invalid keymapsize\n");
566 return -EINVAL;
567 }
568
569 if (!pdata->gpimap && pdata->gpimapsize) {
570 dev_err(&client->dev, "invalid gpimap from pdata\n");
571 return -EINVAL;
572 }
573
574 if (pdata->gpimapsize > ADP5589_GPIMAPSIZE_MAX) {
575 dev_err(&client->dev, "invalid gpimapsize\n");
576 return -EINVAL;
577 }
578
579 for (i = 0; i < pdata->gpimapsize; i++) {
580 unsigned short pin = pdata->gpimap[i].pin;
581
582 if (pin < ADP5589_GPI_PIN_BASE || pin > ADP5589_GPI_PIN_END) {
583 dev_err(&client->dev, "invalid gpi pin data\n");
584 return -EINVAL;
585 }
586
587 if ((1 << (pin - ADP5589_GPI_PIN_ROW_BASE)) &
588 pdata->keypad_en_mask) {
589 dev_err(&client->dev, "invalid gpi row/col data\n");
590 return -EINVAL;
591 }
592 }
593
594 if (!client->irq) {
595 dev_err(&client->dev, "no IRQ?\n");
596 return -EINVAL;
597 }
598
599 kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
600 input = input_allocate_device();
601 if (!kpad || !input) {
602 error = -ENOMEM;
603 goto err_free_mem;
604 }
605
606 kpad->client = client;
607 kpad->input = input;
608
609 ret = adp5589_read(client, ADP5589_ID);
610 if (ret < 0) {
611 error = ret;
612 goto err_free_mem;
613 }
614
615 revid = (u8) ret & ADP5589_DEVICE_ID_MASK;
616
617 input->name = client->name;
618 input->phys = "adp5589-keys/input0";
619 input->dev.parent = &client->dev;
620
621 input_set_drvdata(input, kpad);
622
623 input->id.bustype = BUS_I2C;
624 input->id.vendor = 0x0001;
625 input->id.product = 0x0001;
626 input->id.version = revid;
627
628 input->keycodesize = sizeof(kpad->keycode[0]);
629 input->keycodemax = pdata->keymapsize;
630 input->keycode = kpad->keycode;
631
632 memcpy(kpad->keycode, pdata->keymap,
633 pdata->keymapsize * input->keycodesize);
634
635 kpad->gpimap = pdata->gpimap;
636 kpad->gpimapsize = pdata->gpimapsize;
637
638 /* setup input device */
639 __set_bit(EV_KEY, input->evbit);
640
641 if (pdata->repeat)
642 __set_bit(EV_REP, input->evbit);
643
644 for (i = 0; i < input->keycodemax; i++)
645 __set_bit(kpad->keycode[i] & KEY_MAX, input->keybit);
646 __clear_bit(KEY_RESERVED, input->keybit);
647
648 if (kpad->gpimapsize)
649 __set_bit(EV_SW, input->evbit);
650 for (i = 0; i < kpad->gpimapsize; i++)
651 __set_bit(kpad->gpimap[i].sw_evt, input->swbit);
652
653 error = input_register_device(input);
654 if (error) {
655 dev_err(&client->dev, "unable to register input device\n");
656 goto err_free_mem;
657 }
658
659 error = request_threaded_irq(client->irq, NULL, adp5589_irq,
660 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
661 client->dev.driver->name, kpad);
662 if (error) {
663 dev_err(&client->dev, "irq %d busy?\n", client->irq);
664 goto err_unreg_dev;
665 }
666
667 error = adp5589_setup(kpad);
668 if (error)
669 goto err_free_irq;
670
671 if (kpad->gpimapsize)
672 adp5589_report_switch_state(kpad);
673
674 error = adp5589_gpio_add(kpad);
675 if (error)
676 goto err_free_irq;
677
678 device_init_wakeup(&client->dev, 1);
679 i2c_set_clientdata(client, kpad);
680
681 dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
682 return 0;
683
684err_free_irq:
685 free_irq(client->irq, kpad);
686err_unreg_dev:
687 input_unregister_device(input);
688 input = NULL;
689err_free_mem:
690 input_free_device(input);
691 kfree(kpad);
692
693 return error;
694}
695
696static int __devexit adp5589_remove(struct i2c_client *client)
697{
698 struct adp5589_kpad *kpad = i2c_get_clientdata(client);
699
700 adp5589_write(client, ADP5589_GENERAL_CFG, 0);
701 free_irq(client->irq, kpad);
702 input_unregister_device(kpad->input);
703 adp5589_gpio_remove(kpad);
704 kfree(kpad);
705
706 return 0;
707}
708
709#ifdef CONFIG_PM_SLEEP
710static int adp5589_suspend(struct device *dev)
711{
712 struct adp5589_kpad *kpad = dev_get_drvdata(dev);
713 struct i2c_client *client = kpad->client;
714
715 disable_irq(client->irq);
716
717 if (device_may_wakeup(&client->dev))
718 enable_irq_wake(client->irq);
719
720 return 0;
721}
722
723static int adp5589_resume(struct device *dev)
724{
725 struct adp5589_kpad *kpad = dev_get_drvdata(dev);
726 struct i2c_client *client = kpad->client;
727
728 if (device_may_wakeup(&client->dev))
729 disable_irq_wake(client->irq);
730
731 enable_irq(client->irq);
732
733 return 0;
734}
735#endif
736
737static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);
738
739static const struct i2c_device_id adp5589_id[] = {
740 {"adp5589-keys", 0},
741 {}
742};
743
744MODULE_DEVICE_TABLE(i2c, adp5589_id);
745
746static struct i2c_driver adp5589_driver = {
747 .driver = {
748 .name = KBUILD_MODNAME,
749 .owner = THIS_MODULE,
750 .pm = &adp5589_dev_pm_ops,
751 },
752 .probe = adp5589_probe,
753 .remove = __devexit_p(adp5589_remove),
754 .id_table = adp5589_id,
755};
756
757static int __init adp5589_init(void)
758{
759 return i2c_add_driver(&adp5589_driver);
760}
761module_init(adp5589_init);
762
763static void __exit adp5589_exit(void)
764{
765 i2c_del_driver(&adp5589_driver);
766}
767module_exit(adp5589_exit);
768
769MODULE_LICENSE("GPL");
770MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
771MODULE_DESCRIPTION("ADP5589 Keypad driver");
diff --git a/drivers/input/keyboard/atakbd.c b/drivers/input/keyboard/atakbd.c
index 1839194ea987..10bcd4ae5402 100644
--- a/drivers/input/keyboard/atakbd.c
+++ b/drivers/input/keyboard/atakbd.c
@@ -223,8 +223,9 @@ static int __init atakbd_init(void)
223 return -ENODEV; 223 return -ENODEV;
224 224
225 // need to init core driver if not already done so 225 // need to init core driver if not already done so
226 if (atari_keyb_init()) 226 error = atari_keyb_init();
227 return -ENODEV; 227 if (error)
228 return error;
228 229
229 atakbd_dev = input_allocate_device(); 230 atakbd_dev = input_allocate_device();
230 if (!atakbd_dev) 231 if (!atakbd_dev)
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index d358ef8623f4..11478eb2c27d 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -63,6 +63,10 @@ static bool atkbd_extra;
63module_param_named(extra, atkbd_extra, bool, 0); 63module_param_named(extra, atkbd_extra, bool, 0);
64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards"); 64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
65 65
66static bool atkbd_terminal;
67module_param_named(terminal, atkbd_terminal, bool, 0);
68MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2");
69
66/* 70/*
67 * Scancode to keycode tables. These are just the default setting, and 71 * Scancode to keycode tables. These are just the default setting, and
68 * are loadable via a userland utility. 72 * are loadable via a userland utility.
@@ -136,7 +140,8 @@ static const unsigned short atkbd_unxlate_table[128] = {
136#define ATKBD_CMD_ENABLE 0x00f4 140#define ATKBD_CMD_ENABLE 0x00f4
137#define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */ 141#define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */
138#define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */ 142#define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */
139#define ATKBD_CMD_SETALL_MBR 0x00fa 143#define ATKBD_CMD_SETALL_MB 0x00f8 /* Set all keys to give break codes */
144#define ATKBD_CMD_SETALL_MBR 0x00fa /* ... and repeat */
140#define ATKBD_CMD_RESET_BAT 0x02ff 145#define ATKBD_CMD_RESET_BAT 0x02ff
141#define ATKBD_CMD_RESEND 0x00fe 146#define ATKBD_CMD_RESEND 0x00fe
142#define ATKBD_CMD_EX_ENABLE 0x10ea 147#define ATKBD_CMD_EX_ENABLE 0x10ea
@@ -764,6 +769,11 @@ static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra
764 } 769 }
765 } 770 }
766 771
772 if (atkbd_terminal) {
773 ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MB);
774 return 3;
775 }
776
767 if (target_set != 3) 777 if (target_set != 3)
768 return 2; 778 return 2;
769 779
diff --git a/drivers/input/keyboard/davinci_keyscan.c b/drivers/input/keyboard/davinci_keyscan.c
index a91ee941b5c1..cd89d17162a3 100644
--- a/drivers/input/keyboard/davinci_keyscan.c
+++ b/drivers/input/keyboard/davinci_keyscan.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com> 6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
7 * 7 *
8 * Intial Code: Sandeep Paulraj <s-paulraj@ti.com> 8 * Initial Code: Sandeep Paulraj <s-paulraj@ti.com>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 6069abe31e42..6e6145b9a4c1 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -322,9 +322,14 @@ static void gpio_keys_report_event(struct gpio_button_data *bdata)
322 struct gpio_keys_button *button = bdata->button; 322 struct gpio_keys_button *button = bdata->button;
323 struct input_dev *input = bdata->input; 323 struct input_dev *input = bdata->input;
324 unsigned int type = button->type ?: EV_KEY; 324 unsigned int type = button->type ?: EV_KEY;
325 int state = (gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low; 325 int state = (gpio_get_value_cansleep(button->gpio) ? 1 : 0) ^ button->active_low;
326 326
327 input_event(input, type, button->code, !!state); 327 if (type == EV_ABS) {
328 if (state)
329 input_event(input, type, button->code, button->value);
330 } else {
331 input_event(input, type, button->code, !!state);
332 }
328 input_sync(input); 333 input_sync(input);
329} 334}
330 335
@@ -363,7 +368,7 @@ static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
363 struct gpio_button_data *bdata, 368 struct gpio_button_data *bdata,
364 struct gpio_keys_button *button) 369 struct gpio_keys_button *button)
365{ 370{
366 char *desc = button->desc ? button->desc : "gpio_keys"; 371 const char *desc = button->desc ? button->desc : "gpio_keys";
367 struct device *dev = &pdev->dev; 372 struct device *dev = &pdev->dev;
368 unsigned long irqflags; 373 unsigned long irqflags;
369 int irq, error; 374 int irq, error;
@@ -410,8 +415,8 @@ static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
410 if (!button->can_disable) 415 if (!button->can_disable)
411 irqflags |= IRQF_SHARED; 416 irqflags |= IRQF_SHARED;
412 417
413 error = request_irq(irq, gpio_keys_isr, irqflags, desc, bdata); 418 error = request_any_context_irq(irq, gpio_keys_isr, irqflags, desc, bdata);
414 if (error) { 419 if (error < 0) {
415 dev_err(dev, "Unable to claim irq %d; error %d\n", 420 dev_err(dev, "Unable to claim irq %d; error %d\n",
416 irq, error); 421 irq, error);
417 goto fail3; 422 goto fail3;
@@ -468,7 +473,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
468 platform_set_drvdata(pdev, ddata); 473 platform_set_drvdata(pdev, ddata);
469 input_set_drvdata(input, ddata); 474 input_set_drvdata(input, ddata);
470 475
471 input->name = pdev->name; 476 input->name = pdata->name ? : pdev->name;
472 input->phys = "gpio-keys/input0"; 477 input->phys = "gpio-keys/input0";
473 input->dev.parent = &pdev->dev; 478 input->dev.parent = &pdev->dev;
474 input->open = gpio_keys_open; 479 input->open = gpio_keys_open;
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
new file mode 100644
index 000000000000..4c17aff20657
--- /dev/null
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -0,0 +1,261 @@
1/*
2 * Driver for buttons on GPIO lines not capable of generating interrupts
3 *
4 * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
6 *
7 * This file was based on: /drivers/input/misc/cobalt_btns.c
8 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
9 *
10 * also was based on: /drivers/input/keyboard/gpio_keys.c
11 * Copyright 2005 Phil Blundell
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/input.h>
23#include <linux/input-polldev.h>
24#include <linux/ioport.h>
25#include <linux/platform_device.h>
26#include <linux/gpio.h>
27#include <linux/gpio_keys.h>
28
29#define DRV_NAME "gpio-keys-polled"
30
31struct gpio_keys_button_data {
32 int last_state;
33 int count;
34 int threshold;
35 int can_sleep;
36};
37
38struct gpio_keys_polled_dev {
39 struct input_polled_dev *poll_dev;
40 struct device *dev;
41 struct gpio_keys_platform_data *pdata;
42 struct gpio_keys_button_data data[0];
43};
44
45static void gpio_keys_polled_check_state(struct input_dev *input,
46 struct gpio_keys_button *button,
47 struct gpio_keys_button_data *bdata)
48{
49 int state;
50
51 if (bdata->can_sleep)
52 state = !!gpio_get_value_cansleep(button->gpio);
53 else
54 state = !!gpio_get_value(button->gpio);
55
56 if (state != bdata->last_state) {
57 unsigned int type = button->type ?: EV_KEY;
58
59 input_event(input, type, button->code,
60 !!(state ^ button->active_low));
61 input_sync(input);
62 bdata->count = 0;
63 bdata->last_state = state;
64 }
65}
66
67static void gpio_keys_polled_poll(struct input_polled_dev *dev)
68{
69 struct gpio_keys_polled_dev *bdev = dev->private;
70 struct gpio_keys_platform_data *pdata = bdev->pdata;
71 struct input_dev *input = dev->input;
72 int i;
73
74 for (i = 0; i < bdev->pdata->nbuttons; i++) {
75 struct gpio_keys_button_data *bdata = &bdev->data[i];
76
77 if (bdata->count < bdata->threshold)
78 bdata->count++;
79 else
80 gpio_keys_polled_check_state(input, &pdata->buttons[i],
81 bdata);
82 }
83}
84
85static void gpio_keys_polled_open(struct input_polled_dev *dev)
86{
87 struct gpio_keys_polled_dev *bdev = dev->private;
88 struct gpio_keys_platform_data *pdata = bdev->pdata;
89
90 if (pdata->enable)
91 pdata->enable(bdev->dev);
92}
93
94static void gpio_keys_polled_close(struct input_polled_dev *dev)
95{
96 struct gpio_keys_polled_dev *bdev = dev->private;
97 struct gpio_keys_platform_data *pdata = bdev->pdata;
98
99 if (pdata->disable)
100 pdata->disable(bdev->dev);
101}
102
103static int __devinit gpio_keys_polled_probe(struct platform_device *pdev)
104{
105 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
106 struct device *dev = &pdev->dev;
107 struct gpio_keys_polled_dev *bdev;
108 struct input_polled_dev *poll_dev;
109 struct input_dev *input;
110 int error;
111 int i;
112
113 if (!pdata || !pdata->poll_interval)
114 return -EINVAL;
115
116 bdev = kzalloc(sizeof(struct gpio_keys_polled_dev) +
117 pdata->nbuttons * sizeof(struct gpio_keys_button_data),
118 GFP_KERNEL);
119 if (!bdev) {
120 dev_err(dev, "no memory for private data\n");
121 return -ENOMEM;
122 }
123
124 poll_dev = input_allocate_polled_device();
125 if (!poll_dev) {
126 dev_err(dev, "no memory for polled device\n");
127 error = -ENOMEM;
128 goto err_free_bdev;
129 }
130
131 poll_dev->private = bdev;
132 poll_dev->poll = gpio_keys_polled_poll;
133 poll_dev->poll_interval = pdata->poll_interval;
134 poll_dev->open = gpio_keys_polled_open;
135 poll_dev->close = gpio_keys_polled_close;
136
137 input = poll_dev->input;
138
139 input->evbit[0] = BIT(EV_KEY);
140 input->name = pdev->name;
141 input->phys = DRV_NAME"/input0";
142 input->dev.parent = &pdev->dev;
143
144 input->id.bustype = BUS_HOST;
145 input->id.vendor = 0x0001;
146 input->id.product = 0x0001;
147 input->id.version = 0x0100;
148
149 for (i = 0; i < pdata->nbuttons; i++) {
150 struct gpio_keys_button *button = &pdata->buttons[i];
151 struct gpio_keys_button_data *bdata = &bdev->data[i];
152 unsigned int gpio = button->gpio;
153 unsigned int type = button->type ?: EV_KEY;
154
155 if (button->wakeup) {
156 dev_err(dev, DRV_NAME " does not support wakeup\n");
157 error = -EINVAL;
158 goto err_free_gpio;
159 }
160
161 error = gpio_request(gpio,
162 button->desc ? button->desc : DRV_NAME);
163 if (error) {
164 dev_err(dev, "unable to claim gpio %u, err=%d\n",
165 gpio, error);
166 goto err_free_gpio;
167 }
168
169 error = gpio_direction_input(gpio);
170 if (error) {
171 dev_err(dev,
172 "unable to set direction on gpio %u, err=%d\n",
173 gpio, error);
174 goto err_free_gpio;
175 }
176
177 bdata->can_sleep = gpio_cansleep(gpio);
178 bdata->last_state = -1;
179 bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
180 pdata->poll_interval);
181
182 input_set_capability(input, type, button->code);
183 }
184
185 bdev->poll_dev = poll_dev;
186 bdev->dev = dev;
187 bdev->pdata = pdata;
188 platform_set_drvdata(pdev, bdev);
189
190 error = input_register_polled_device(poll_dev);
191 if (error) {
192 dev_err(dev, "unable to register polled device, err=%d\n",
193 error);
194 goto err_free_gpio;
195 }
196
197 /* report initial state of the buttons */
198 for (i = 0; i < pdata->nbuttons; i++)
199 gpio_keys_polled_check_state(input, &pdata->buttons[i],
200 &bdev->data[i]);
201
202 return 0;
203
204err_free_gpio:
205 while (--i >= 0)
206 gpio_free(pdata->buttons[i].gpio);
207
208 input_free_polled_device(poll_dev);
209
210err_free_bdev:
211 kfree(bdev);
212
213 platform_set_drvdata(pdev, NULL);
214 return error;
215}
216
217static int __devexit gpio_keys_polled_remove(struct platform_device *pdev)
218{
219 struct gpio_keys_polled_dev *bdev = platform_get_drvdata(pdev);
220 struct gpio_keys_platform_data *pdata = bdev->pdata;
221 int i;
222
223 input_unregister_polled_device(bdev->poll_dev);
224
225 for (i = 0; i < pdata->nbuttons; i++)
226 gpio_free(pdata->buttons[i].gpio);
227
228 input_free_polled_device(bdev->poll_dev);
229
230 kfree(bdev);
231 platform_set_drvdata(pdev, NULL);
232
233 return 0;
234}
235
236static struct platform_driver gpio_keys_polled_driver = {
237 .probe = gpio_keys_polled_probe,
238 .remove = __devexit_p(gpio_keys_polled_remove),
239 .driver = {
240 .name = DRV_NAME,
241 .owner = THIS_MODULE,
242 },
243};
244
245static int __init gpio_keys_polled_init(void)
246{
247 return platform_driver_register(&gpio_keys_polled_driver);
248}
249
250static void __exit gpio_keys_polled_exit(void)
251{
252 platform_driver_unregister(&gpio_keys_polled_driver);
253}
254
255module_init(gpio_keys_polled_init);
256module_exit(gpio_keys_polled_exit);
257
258MODULE_LICENSE("GPL v2");
259MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
260MODULE_DESCRIPTION("Polled GPIO Buttons driver");
261MODULE_ALIAS("platform:" DRV_NAME);
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/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c
index 5fc976dbce0b..7197c5698747 100644
--- a/drivers/input/keyboard/jornada680_kbd.c
+++ b/drivers/input/keyboard/jornada680_kbd.c
@@ -139,35 +139,35 @@ static void jornada_scan_keyb(unsigned char *s)
139 }, *y = matrix_PDE; 139 }, *y = matrix_PDE;
140 140
141 /* Save these control reg bits */ 141 /* Save these control reg bits */
142 dc_static = (ctrl_inw(PDCR) & (~0xcc0c)); 142 dc_static = (__raw_readw(PDCR) & (~0xcc0c));
143 ec_static = (ctrl_inw(PECR) & (~0xf0cf)); 143 ec_static = (__raw_readw(PECR) & (~0xf0cf));
144 144
145 for (i = 0; i < 8; i++) { 145 for (i = 0; i < 8; i++) {
146 /* disable output for all but the one we want to scan */ 146 /* disable output for all but the one we want to scan */
147 ctrl_outw((dc_static | *y++), PDCR); 147 __raw_writew((dc_static | *y++), PDCR);
148 ctrl_outw((ec_static | *y++), PECR); 148 __raw_writew((ec_static | *y++), PECR);
149 udelay(5); 149 udelay(5);
150 150
151 /* Get scanline row */ 151 /* Get scanline row */
152 ctrl_outb(*t++, PDDR); 152 __raw_writeb(*t++, PDDR);
153 ctrl_outb(*t++, PEDR); 153 __raw_writeb(*t++, PEDR);
154 udelay(50); 154 udelay(50);
155 155
156 /* Read data */ 156 /* Read data */
157 *s++ = ctrl_inb(PCDR); 157 *s++ = __raw_readb(PCDR);
158 *s++ = ctrl_inb(PFDR); 158 *s++ = __raw_readb(PFDR);
159 } 159 }
160 /* Scan no lines */ 160 /* Scan no lines */
161 ctrl_outb(0xff, PDDR); 161 __raw_writeb(0xff, PDDR);
162 ctrl_outb(0xff, PEDR); 162 __raw_writeb(0xff, PEDR);
163 163
164 /* Enable all scanlines */ 164 /* Enable all scanlines */
165 ctrl_outw((dc_static | (0x5555 & 0xcc0c)),PDCR); 165 __raw_writew((dc_static | (0x5555 & 0xcc0c)),PDCR);
166 ctrl_outw((ec_static | (0x5555 & 0xf0cf)),PECR); 166 __raw_writew((ec_static | (0x5555 & 0xf0cf)),PECR);
167 167
168 /* Ignore extra keys and events */ 168 /* Ignore extra keys and events */
169 *s++ = ctrl_inb(PGDR); 169 *s++ = __raw_readb(PGDR);
170 *s++ = ctrl_inb(PHDR); 170 *s++ = __raw_readb(PHDR);
171} 171}
172 172
173static void jornadakbd680_poll(struct input_polled_dev *dev) 173static void jornadakbd680_poll(struct input_polled_dev *dev)
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index f7c2a166576b..71f744a8e686 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -30,6 +30,7 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/leds.h> 32#include <linux/leds.h>
33#include <linux/pm.h>
33#include <linux/i2c/lm8323.h> 34#include <linux/i2c/lm8323.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
35 36
@@ -802,12 +803,13 @@ static int __devexit lm8323_remove(struct i2c_client *client)
802 * We don't need to explicitly suspend the chip, as it already switches off 803 * We don't need to explicitly suspend the chip, as it already switches off
803 * when there's no activity. 804 * when there's no activity.
804 */ 805 */
805static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg) 806static int lm8323_suspend(struct device *dev)
806{ 807{
808 struct i2c_client *client = to_i2c_client(dev);
807 struct lm8323_chip *lm = i2c_get_clientdata(client); 809 struct lm8323_chip *lm = i2c_get_clientdata(client);
808 int i; 810 int i;
809 811
810 set_irq_wake(client->irq, 0); 812 irq_set_irq_wake(client->irq, 0);
811 disable_irq(client->irq); 813 disable_irq(client->irq);
812 814
813 mutex_lock(&lm->lock); 815 mutex_lock(&lm->lock);
@@ -821,8 +823,9 @@ static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg)
821 return 0; 823 return 0;
822} 824}
823 825
824static int lm8323_resume(struct i2c_client *client) 826static int lm8323_resume(struct device *dev)
825{ 827{
828 struct i2c_client *client = to_i2c_client(dev);
826 struct lm8323_chip *lm = i2c_get_clientdata(client); 829 struct lm8323_chip *lm = i2c_get_clientdata(client);
827 int i; 830 int i;
828 831
@@ -835,15 +838,14 @@ static int lm8323_resume(struct i2c_client *client)
835 led_classdev_resume(&lm->pwm[i].cdev); 838 led_classdev_resume(&lm->pwm[i].cdev);
836 839
837 enable_irq(client->irq); 840 enable_irq(client->irq);
838 set_irq_wake(client->irq, 1); 841 irq_set_irq_wake(client->irq, 1);
839 842
840 return 0; 843 return 0;
841} 844}
842#else
843#define lm8323_suspend NULL
844#define lm8323_resume NULL
845#endif 845#endif
846 846
847static SIMPLE_DEV_PM_OPS(lm8323_pm_ops, lm8323_suspend, lm8323_resume);
848
847static const struct i2c_device_id lm8323_id[] = { 849static const struct i2c_device_id lm8323_id[] = {
848 { "lm8323", 0 }, 850 { "lm8323", 0 },
849 { } 851 { }
@@ -852,11 +854,10 @@ static const struct i2c_device_id lm8323_id[] = {
852static struct i2c_driver lm8323_i2c_driver = { 854static struct i2c_driver lm8323_i2c_driver = {
853 .driver = { 855 .driver = {
854 .name = "lm8323", 856 .name = "lm8323",
857 .pm = &lm8323_pm_ops,
855 }, 858 },
856 .probe = lm8323_probe, 859 .probe = lm8323_probe,
857 .remove = __devexit_p(lm8323_remove), 860 .remove = __devexit_p(lm8323_remove),
858 .suspend = lm8323_suspend,
859 .resume = lm8323_resume,
860 .id_table = lm8323_id, 861 .id_table = lm8323_id,
861}; 862};
862MODULE_DEVICE_TABLE(i2c, lm8323_id); 863MODULE_DEVICE_TABLE(i2c, lm8323_id);
diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c
index 9091ff5ea808..5afe35ad24d3 100644
--- a/drivers/input/keyboard/max7359_keypad.c
+++ b/drivers/input/keyboard/max7359_keypad.c
@@ -17,6 +17,7 @@
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/pm.h>
20#include <linux/input.h> 21#include <linux/input.h>
21#include <linux/input/matrix_keypad.h> 22#include <linux/input/matrix_keypad.h>
22 23
@@ -271,8 +272,10 @@ static int __devexit max7359_remove(struct i2c_client *client)
271} 272}
272 273
273#ifdef CONFIG_PM 274#ifdef CONFIG_PM
274static int max7359_suspend(struct i2c_client *client, pm_message_t mesg) 275static int max7359_suspend(struct device *dev)
275{ 276{
277 struct i2c_client *client = to_i2c_client(dev);
278
276 max7359_fall_deepsleep(client); 279 max7359_fall_deepsleep(client);
277 280
278 if (device_may_wakeup(&client->dev)) 281 if (device_may_wakeup(&client->dev))
@@ -281,8 +284,10 @@ static int max7359_suspend(struct i2c_client *client, pm_message_t mesg)
281 return 0; 284 return 0;
282} 285}
283 286
284static int max7359_resume(struct i2c_client *client) 287static int max7359_resume(struct device *dev)
285{ 288{
289 struct i2c_client *client = to_i2c_client(dev);
290
286 if (device_may_wakeup(&client->dev)) 291 if (device_may_wakeup(&client->dev))
287 disable_irq_wake(client->irq); 292 disable_irq_wake(client->irq);
288 293
@@ -291,11 +296,10 @@ static int max7359_resume(struct i2c_client *client)
291 296
292 return 0; 297 return 0;
293} 298}
294#else
295#define max7359_suspend NULL
296#define max7359_resume NULL
297#endif 299#endif
298 300
301static SIMPLE_DEV_PM_OPS(max7359_pm, max7359_suspend, max7359_resume);
302
299static const struct i2c_device_id max7359_ids[] = { 303static const struct i2c_device_id max7359_ids[] = {
300 { "max7359", 0 }, 304 { "max7359", 0 },
301 { } 305 { }
@@ -305,11 +309,10 @@ MODULE_DEVICE_TABLE(i2c, max7359_ids);
305static struct i2c_driver max7359_i2c_driver = { 309static struct i2c_driver max7359_i2c_driver = {
306 .driver = { 310 .driver = {
307 .name = "max7359", 311 .name = "max7359",
312 .pm = &max7359_pm,
308 }, 313 },
309 .probe = max7359_probe, 314 .probe = max7359_probe,
310 .remove = __devexit_p(max7359_remove), 315 .remove = __devexit_p(max7359_remove),
311 .suspend = max7359_suspend,
312 .resume = max7359_resume,
313 .id_table = max7359_ids, 316 .id_table = max7359_ids,
314}; 317};
315 318
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 63b849d7e90b..af1aab324a4c 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * mcs_touchkey.c - Touchkey driver for MELFAS MCS5000/5080 controller 2 * Touchkey driver for MELFAS MCS5000/5080 controller
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd 4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: HeungJun Kim <riverful.kim@samsung.com> 5 * Author: HeungJun Kim <riverful.kim@samsung.com>
@@ -19,6 +19,7 @@
19#include <linux/input.h> 19#include <linux/input.h>
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/pm.h>
22 23
23/* MCS5000 Touchkey */ 24/* MCS5000 Touchkey */
24#define MCS5000_TOUCHKEY_STATUS 0x04 25#define MCS5000_TOUCHKEY_STATUS 0x04
@@ -45,6 +46,8 @@ struct mcs_touchkey_chip {
45}; 46};
46 47
47struct mcs_touchkey_data { 48struct mcs_touchkey_data {
49 void (*poweron)(bool);
50
48 struct i2c_client *client; 51 struct i2c_client *client;
49 struct input_dev *input_dev; 52 struct input_dev *input_dev;
50 struct mcs_touchkey_chip chip; 53 struct mcs_touchkey_chip chip;
@@ -169,6 +172,11 @@ static int __devinit mcs_touchkey_probe(struct i2c_client *client,
169 if (pdata->cfg_pin) 172 if (pdata->cfg_pin)
170 pdata->cfg_pin(); 173 pdata->cfg_pin();
171 174
175 if (pdata->poweron) {
176 data->poweron = pdata->poweron;
177 data->poweron(true);
178 }
179
172 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt, 180 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
173 IRQF_TRIGGER_FALLING, client->dev.driver->name, data); 181 IRQF_TRIGGER_FALLING, client->dev.driver->name, data);
174 if (error) { 182 if (error) {
@@ -196,12 +204,57 @@ static int __devexit mcs_touchkey_remove(struct i2c_client *client)
196 struct mcs_touchkey_data *data = i2c_get_clientdata(client); 204 struct mcs_touchkey_data *data = i2c_get_clientdata(client);
197 205
198 free_irq(client->irq, data); 206 free_irq(client->irq, data);
207 if (data->poweron)
208 data->poweron(false);
199 input_unregister_device(data->input_dev); 209 input_unregister_device(data->input_dev);
200 kfree(data); 210 kfree(data);
201 211
202 return 0; 212 return 0;
203} 213}
204 214
215static void mcs_touchkey_shutdown(struct i2c_client *client)
216{
217 struct mcs_touchkey_data *data = i2c_get_clientdata(client);
218
219 if (data->poweron)
220 data->poweron(false);
221}
222
223#ifdef CONFIG_PM_SLEEP
224static int mcs_touchkey_suspend(struct device *dev)
225{
226 struct mcs_touchkey_data *data = dev_get_drvdata(dev);
227 struct i2c_client *client = data->client;
228
229 /* Disable the work */
230 disable_irq(client->irq);
231
232 /* Finally turn off the power */
233 if (data->poweron)
234 data->poweron(false);
235
236 return 0;
237}
238
239static int mcs_touchkey_resume(struct device *dev)
240{
241 struct mcs_touchkey_data *data = dev_get_drvdata(dev);
242 struct i2c_client *client = data->client;
243
244 /* Enable the device first */
245 if (data->poweron)
246 data->poweron(true);
247
248 /* Enable irq again */
249 enable_irq(client->irq);
250
251 return 0;
252}
253#endif
254
255static SIMPLE_DEV_PM_OPS(mcs_touchkey_pm_ops,
256 mcs_touchkey_suspend, mcs_touchkey_resume);
257
205static const struct i2c_device_id mcs_touchkey_id[] = { 258static const struct i2c_device_id mcs_touchkey_id[] = {
206 { "mcs5000_touchkey", MCS5000_TOUCHKEY }, 259 { "mcs5000_touchkey", MCS5000_TOUCHKEY },
207 { "mcs5080_touchkey", MCS5080_TOUCHKEY }, 260 { "mcs5080_touchkey", MCS5080_TOUCHKEY },
@@ -213,9 +266,11 @@ static struct i2c_driver mcs_touchkey_driver = {
213 .driver = { 266 .driver = {
214 .name = "mcs_touchkey", 267 .name = "mcs_touchkey",
215 .owner = THIS_MODULE, 268 .owner = THIS_MODULE,
269 .pm = &mcs_touchkey_pm_ops,
216 }, 270 },
217 .probe = mcs_touchkey_probe, 271 .probe = mcs_touchkey_probe,
218 .remove = __devexit_p(mcs_touchkey_remove), 272 .remove = __devexit_p(mcs_touchkey_remove),
273 .shutdown = mcs_touchkey_shutdown,
219 .id_table = mcs_touchkey_id, 274 .id_table = mcs_touchkey_id,
220}; 275};
221 276
diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c
new file mode 100644
index 000000000000..0a9e81194888
--- /dev/null
+++ b/drivers/input/keyboard/mpr121_touchkey.c
@@ -0,0 +1,339 @@
1/*
2 * Touchkey driver for Freescale MPR121 Controllor
3 *
4 * Copyright (C) 2011 Freescale Semiconductor, Inc.
5 * Author: Zhang Jiejing <jiejing.zhang@freescale.com>
6 *
7 * Based on mcs_touchkey.c
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 version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/input.h>
18#include <linux/i2c.h>
19#include <linux/slab.h>
20#include <linux/delay.h>
21#include <linux/bitops.h>
22#include <linux/interrupt.h>
23#include <linux/i2c/mpr121_touchkey.h>
24
25/* Register definitions */
26#define ELE_TOUCH_STATUS_0_ADDR 0x0
27#define ELE_TOUCH_STATUS_1_ADDR 0X1
28#define MHD_RISING_ADDR 0x2b
29#define NHD_RISING_ADDR 0x2c
30#define NCL_RISING_ADDR 0x2d
31#define FDL_RISING_ADDR 0x2e
32#define MHD_FALLING_ADDR 0x2f
33#define NHD_FALLING_ADDR 0x30
34#define NCL_FALLING_ADDR 0x31
35#define FDL_FALLING_ADDR 0x32
36#define ELE0_TOUCH_THRESHOLD_ADDR 0x41
37#define ELE0_RELEASE_THRESHOLD_ADDR 0x42
38#define AFE_CONF_ADDR 0x5c
39#define FILTER_CONF_ADDR 0x5d
40
41/*
42 * ELECTRODE_CONF_ADDR: This register configures the number of
43 * enabled capacitance sensing inputs and its run/suspend mode.
44 */
45#define ELECTRODE_CONF_ADDR 0x5e
46#define AUTO_CONFIG_CTRL_ADDR 0x7b
47#define AUTO_CONFIG_USL_ADDR 0x7d
48#define AUTO_CONFIG_LSL_ADDR 0x7e
49#define AUTO_CONFIG_TL_ADDR 0x7f
50
51/* Threshold of touch/release trigger */
52#define TOUCH_THRESHOLD 0x0f
53#define RELEASE_THRESHOLD 0x0a
54/* Masks for touch and release triggers */
55#define TOUCH_STATUS_MASK 0xfff
56/* MPR121 has 12 keys */
57#define MPR121_MAX_KEY_COUNT 12
58
59struct mpr121_touchkey {
60 struct i2c_client *client;
61 struct input_dev *input_dev;
62 unsigned int key_val;
63 unsigned int statusbits;
64 unsigned int keycount;
65 u16 keycodes[MPR121_MAX_KEY_COUNT];
66};
67
68struct mpr121_init_register {
69 int addr;
70 u8 val;
71};
72
73static const struct mpr121_init_register init_reg_table[] __devinitconst = {
74 { MHD_RISING_ADDR, 0x1 },
75 { NHD_RISING_ADDR, 0x1 },
76 { MHD_FALLING_ADDR, 0x1 },
77 { NHD_FALLING_ADDR, 0x1 },
78 { NCL_FALLING_ADDR, 0xff },
79 { FDL_FALLING_ADDR, 0x02 },
80 { FILTER_CONF_ADDR, 0x04 },
81 { AFE_CONF_ADDR, 0x0b },
82 { AUTO_CONFIG_CTRL_ADDR, 0x0b },
83};
84
85static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
86{
87 struct mpr121_touchkey *mpr121 = dev_id;
88 struct i2c_client *client = mpr121->client;
89 struct input_dev *input = mpr121->input_dev;
90 unsigned int key_num, key_val, pressed;
91 int reg;
92
93 reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
94 if (reg < 0) {
95 dev_err(&client->dev, "i2c read error [%d]\n", reg);
96 goto out;
97 }
98
99 reg <<= 8;
100 reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
101 if (reg < 0) {
102 dev_err(&client->dev, "i2c read error [%d]\n", reg);
103 goto out;
104 }
105
106 reg &= TOUCH_STATUS_MASK;
107 /* use old press bit to figure out which bit changed */
108 key_num = ffs(reg ^ mpr121->statusbits) - 1;
109 pressed = reg & (1 << key_num);
110 mpr121->statusbits = reg;
111
112 key_val = mpr121->keycodes[key_num];
113
114 input_event(input, EV_MSC, MSC_SCAN, key_num);
115 input_report_key(input, key_val, pressed);
116 input_sync(input);
117
118 dev_dbg(&client->dev, "key %d %d %s\n", key_num, key_val,
119 pressed ? "pressed" : "released");
120
121out:
122 return IRQ_HANDLED;
123}
124
125static int __devinit mpr121_phys_init(const struct mpr121_platform_data *pdata,
126 struct mpr121_touchkey *mpr121,
127 struct i2c_client *client)
128{
129 const struct mpr121_init_register *reg;
130 unsigned char usl, lsl, tl;
131 int i, t, vdd, ret;
132
133 /* Set up touch/release threshold for ele0-ele11 */
134 for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
135 t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
136 ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
137 if (ret < 0)
138 goto err_i2c_write;
139 ret = i2c_smbus_write_byte_data(client, t + 1,
140 RELEASE_THRESHOLD);
141 if (ret < 0)
142 goto err_i2c_write;
143 }
144
145 /* Set up init register */
146 for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
147 reg = &init_reg_table[i];
148 ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
149 if (ret < 0)
150 goto err_i2c_write;
151 }
152
153
154 /*
155 * Capacitance on sensing input varies and needs to be compensated.
156 * The internal MPR121-auto-configuration can do this if it's
157 * registers are set properly (based on pdata->vdd_uv).
158 */
159 vdd = pdata->vdd_uv / 1000;
160 usl = ((vdd - 700) * 256) / vdd;
161 lsl = (usl * 65) / 100;
162 tl = (usl * 90) / 100;
163 ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
164 ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
165 ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
166 ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
167 mpr121->keycount);
168 if (ret != 0)
169 goto err_i2c_write;
170
171 dev_dbg(&client->dev, "set up with %x keys.\n", mpr121->keycount);
172
173 return 0;
174
175err_i2c_write:
176 dev_err(&client->dev, "i2c write error: %d\n", ret);
177 return ret;
178}
179
180static int __devinit mpr_touchkey_probe(struct i2c_client *client,
181 const struct i2c_device_id *id)
182{
183 const struct mpr121_platform_data *pdata = client->dev.platform_data;
184 struct mpr121_touchkey *mpr121;
185 struct input_dev *input_dev;
186 int error;
187 int i;
188
189 if (!pdata) {
190 dev_err(&client->dev, "no platform data defined\n");
191 return -EINVAL;
192 }
193
194 if (!pdata->keymap || !pdata->keymap_size) {
195 dev_err(&client->dev, "missing keymap data\n");
196 return -EINVAL;
197 }
198
199 if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) {
200 dev_err(&client->dev, "too many keys defined\n");
201 return -EINVAL;
202 }
203
204 if (!client->irq) {
205 dev_err(&client->dev, "irq number should not be zero\n");
206 return -EINVAL;
207 }
208
209 mpr121 = kzalloc(sizeof(struct mpr121_touchkey), GFP_KERNEL);
210 input_dev = input_allocate_device();
211 if (!mpr121 || !input_dev) {
212 dev_err(&client->dev, "Failed to allocate memory\n");
213 error = -ENOMEM;
214 goto err_free_mem;
215 }
216
217 mpr121->client = client;
218 mpr121->input_dev = input_dev;
219 mpr121->keycount = pdata->keymap_size;
220
221 input_dev->name = "Freescale MPR121 Touchkey";
222 input_dev->id.bustype = BUS_I2C;
223 input_dev->dev.parent = &client->dev;
224 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
225
226 input_dev->keycode = mpr121->keycodes;
227 input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
228 input_dev->keycodemax = mpr121->keycount;
229
230 for (i = 0; i < pdata->keymap_size; i++) {
231 input_set_capability(input_dev, EV_KEY, pdata->keymap[i]);
232 mpr121->keycodes[i] = pdata->keymap[i];
233 }
234
235 error = mpr121_phys_init(pdata, mpr121, client);
236 if (error) {
237 dev_err(&client->dev, "Failed to init register\n");
238 goto err_free_mem;
239 }
240
241 error = request_threaded_irq(client->irq, NULL,
242 mpr_touchkey_interrupt,
243 IRQF_TRIGGER_FALLING,
244 client->dev.driver->name, mpr121);
245 if (error) {
246 dev_err(&client->dev, "Failed to register interrupt\n");
247 goto err_free_mem;
248 }
249
250 error = input_register_device(input_dev);
251 if (error)
252 goto err_free_irq;
253
254 i2c_set_clientdata(client, mpr121);
255 device_init_wakeup(&client->dev, pdata->wakeup);
256
257 return 0;
258
259err_free_irq:
260 free_irq(client->irq, mpr121);
261err_free_mem:
262 input_free_device(input_dev);
263 kfree(mpr121);
264 return error;
265}
266
267static int __devexit mpr_touchkey_remove(struct i2c_client *client)
268{
269 struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client);
270
271 free_irq(client->irq, mpr121);
272 input_unregister_device(mpr121->input_dev);
273 kfree(mpr121);
274
275 return 0;
276}
277
278#ifdef CONFIG_PM_SLEEP
279static int mpr_suspend(struct device *dev)
280{
281 struct i2c_client *client = to_i2c_client(dev);
282
283 if (device_may_wakeup(&client->dev))
284 enable_irq_wake(client->irq);
285
286 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
287
288 return 0;
289}
290
291static int mpr_resume(struct device *dev)
292{
293 struct i2c_client *client = to_i2c_client(dev);
294 struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client);
295
296 if (device_may_wakeup(&client->dev))
297 disable_irq_wake(client->irq);
298
299 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
300 mpr121->keycount);
301
302 return 0;
303}
304#endif
305
306static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
307
308static const struct i2c_device_id mpr121_id[] = {
309 { "mpr121_touchkey", 0 },
310 { }
311};
312MODULE_DEVICE_TABLE(i2c, mpr121_id);
313
314static struct i2c_driver mpr_touchkey_driver = {
315 .driver = {
316 .name = "mpr121",
317 .owner = THIS_MODULE,
318 .pm = &mpr121_touchkey_pm_ops,
319 },
320 .id_table = mpr121_id,
321 .probe = mpr_touchkey_probe,
322 .remove = __devexit_p(mpr_touchkey_remove),
323};
324
325static int __init mpr_touchkey_init(void)
326{
327 return i2c_add_driver(&mpr_touchkey_driver);
328}
329module_init(mpr_touchkey_init);
330
331static void __exit mpr_touchkey_exit(void)
332{
333 i2c_del_driver(&mpr_touchkey_driver);
334}
335module_exit(mpr_touchkey_exit);
336
337MODULE_LICENSE("GPL");
338MODULE_AUTHOR("Zhang Jiejing <jiejing.zhang@freescale.com>");
339MODULE_DESCRIPTION("Touch Key driver for Freescale MPR121 Chip");
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/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c
index a72e61ddca91..33d0bdc837c0 100644
--- a/drivers/input/keyboard/omap-keypad.c
+++ b/drivers/input/keyboard/omap-keypad.c
@@ -65,7 +65,6 @@ struct omap_kp {
65 65
66static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0); 66static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
67 67
68static int *keymap;
69static unsigned int *row_gpios; 68static unsigned int *row_gpios;
70static unsigned int *col_gpios; 69static unsigned int *col_gpios;
71 70
@@ -162,20 +161,11 @@ static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state)
162 } 161 }
163} 162}
164 163
165static inline int omap_kp_find_key(int col, int row)
166{
167 int i, key;
168
169 key = KEY(col, row, 0);
170 for (i = 0; keymap[i] != 0; i++)
171 if ((keymap[i] & 0xff000000) == key)
172 return keymap[i] & 0x00ffffff;
173 return -1;
174}
175
176static void omap_kp_tasklet(unsigned long data) 164static void omap_kp_tasklet(unsigned long data)
177{ 165{
178 struct omap_kp *omap_kp_data = (struct omap_kp *) data; 166 struct omap_kp *omap_kp_data = (struct omap_kp *) data;
167 unsigned short *keycodes = omap_kp_data->input->keycode;
168 unsigned int row_shift = get_count_order(omap_kp_data->cols);
179 unsigned char new_state[8], changed, key_down = 0; 169 unsigned char new_state[8], changed, key_down = 0;
180 int col, row; 170 int col, row;
181 int spurious = 0; 171 int spurious = 0;
@@ -199,7 +189,7 @@ static void omap_kp_tasklet(unsigned long data)
199 row, (new_state[col] & (1 << row)) ? 189 row, (new_state[col] & (1 << row)) ?
200 "pressed" : "released"); 190 "pressed" : "released");
201#else 191#else
202 key = omap_kp_find_key(col, row); 192 key = keycodes[MATRIX_SCAN_CODE(row, col, row_shift)];
203 if (key < 0) { 193 if (key < 0) {
204 printk(KERN_WARNING 194 printk(KERN_WARNING
205 "omap-keypad: Spurious key event %d-%d\n", 195 "omap-keypad: Spurious key event %d-%d\n",
@@ -219,6 +209,7 @@ static void omap_kp_tasklet(unsigned long data)
219#endif 209#endif
220 } 210 }
221 } 211 }
212 input_sync(omap_kp_data->input);
222 memcpy(keypad_state, new_state, sizeof(keypad_state)); 213 memcpy(keypad_state, new_state, sizeof(keypad_state));
223 214
224 if (key_down) { 215 if (key_down) {
@@ -298,13 +289,18 @@ static int __devinit omap_kp_probe(struct platform_device *pdev)
298 struct input_dev *input_dev; 289 struct input_dev *input_dev;
299 struct omap_kp_platform_data *pdata = pdev->dev.platform_data; 290 struct omap_kp_platform_data *pdata = pdev->dev.platform_data;
300 int i, col_idx, row_idx, irq_idx, ret; 291 int i, col_idx, row_idx, irq_idx, ret;
292 unsigned int row_shift, keycodemax;
301 293
302 if (!pdata->rows || !pdata->cols || !pdata->keymap) { 294 if (!pdata->rows || !pdata->cols || !pdata->keymap_data) {
303 printk(KERN_ERR "No rows, cols or keymap from pdata\n"); 295 printk(KERN_ERR "No rows, cols or keymap_data from pdata\n");
304 return -EINVAL; 296 return -EINVAL;
305 } 297 }
306 298
307 omap_kp = kzalloc(sizeof(struct omap_kp), GFP_KERNEL); 299 row_shift = get_count_order(pdata->cols);
300 keycodemax = pdata->rows << row_shift;
301
302 omap_kp = kzalloc(sizeof(struct omap_kp) +
303 keycodemax * sizeof(unsigned short), GFP_KERNEL);
308 input_dev = input_allocate_device(); 304 input_dev = input_allocate_device();
309 if (!omap_kp || !input_dev) { 305 if (!omap_kp || !input_dev) {
310 kfree(omap_kp); 306 kfree(omap_kp);
@@ -320,7 +316,9 @@ static int __devinit omap_kp_probe(struct platform_device *pdev)
320 if (!cpu_is_omap24xx()) 316 if (!cpu_is_omap24xx())
321 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); 317 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
322 318
323 keymap = pdata->keymap; 319 input_dev->keycode = &omap_kp[1];
320 input_dev->keycodesize = sizeof(unsigned short);
321 input_dev->keycodemax = keycodemax;
324 322
325 if (pdata->rep) 323 if (pdata->rep)
326 __set_bit(EV_REP, input_dev->evbit); 324 __set_bit(EV_REP, input_dev->evbit);
@@ -374,8 +372,8 @@ static int __devinit omap_kp_probe(struct platform_device *pdev)
374 372
375 /* setup input device */ 373 /* setup input device */
376 __set_bit(EV_KEY, input_dev->evbit); 374 __set_bit(EV_KEY, input_dev->evbit);
377 for (i = 0; keymap[i] != 0; i++) 375 matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
378 __set_bit(keymap[i] & KEY_MAX, input_dev->keybit); 376 input_dev->keycode, input_dev->keybit);
379 input_dev->name = "omap-keypad"; 377 input_dev->name = "omap-keypad";
380 input_dev->phys = "omap-keypad/input0"; 378 input_dev->phys = "omap-keypad/input0";
381 input_dev->dev.parent = &pdev->dev; 379 input_dev->dev.parent = &pdev->dev;
@@ -416,7 +414,7 @@ static int __devinit omap_kp_probe(struct platform_device *pdev)
416 return 0; 414 return 0;
417err5: 415err5:
418 for (i = irq_idx - 1; i >=0; i--) 416 for (i = irq_idx - 1; i >=0; i--)
419 free_irq(row_gpios[i], 0); 417 free_irq(row_gpios[i], omap_kp);
420err4: 418err4:
421 input_unregister_device(omap_kp->input); 419 input_unregister_device(omap_kp->input);
422 input_dev = NULL; 420 input_dev = NULL;
@@ -447,11 +445,11 @@ static int __devexit omap_kp_remove(struct platform_device *pdev)
447 gpio_free(col_gpios[i]); 445 gpio_free(col_gpios[i]);
448 for (i = 0; i < omap_kp->rows; i++) { 446 for (i = 0; i < omap_kp->rows; i++) {
449 gpio_free(row_gpios[i]); 447 gpio_free(row_gpios[i]);
450 free_irq(gpio_to_irq(row_gpios[i]), 0); 448 free_irq(gpio_to_irq(row_gpios[i]), omap_kp);
451 } 449 }
452 } else { 450 } else {
453 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); 451 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
454 free_irq(omap_kp->irq, 0); 452 free_irq(omap_kp->irq, omap_kp);
455 } 453 }
456 454
457 del_timer_sync(&omap_kp->timer); 455 del_timer_sync(&omap_kp->timer);
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
new file mode 100644
index 000000000000..c51a3c4a7feb
--- /dev/null
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -0,0 +1,354 @@
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#include <linux/pm_runtime.h>
33
34#include <plat/omap4-keypad.h>
35
36/* OMAP4 registers */
37#define OMAP4_KBD_REVISION 0x00
38#define OMAP4_KBD_SYSCONFIG 0x10
39#define OMAP4_KBD_SYSSTATUS 0x14
40#define OMAP4_KBD_IRQSTATUS 0x18
41#define OMAP4_KBD_IRQENABLE 0x1C
42#define OMAP4_KBD_WAKEUPENABLE 0x20
43#define OMAP4_KBD_PENDING 0x24
44#define OMAP4_KBD_CTRL 0x28
45#define OMAP4_KBD_DEBOUNCINGTIME 0x2C
46#define OMAP4_KBD_LONGKEYTIME 0x30
47#define OMAP4_KBD_TIMEOUT 0x34
48#define OMAP4_KBD_STATEMACHINE 0x38
49#define OMAP4_KBD_ROWINPUTS 0x3C
50#define OMAP4_KBD_COLUMNOUTPUTS 0x40
51#define OMAP4_KBD_FULLCODE31_0 0x44
52#define OMAP4_KBD_FULLCODE63_32 0x48
53
54/* OMAP4 bit definitions */
55#define OMAP4_DEF_IRQENABLE_EVENTEN (1 << 0)
56#define OMAP4_DEF_IRQENABLE_LONGKEY (1 << 1)
57#define OMAP4_DEF_IRQENABLE_TIMEOUTEN (1 << 2)
58#define OMAP4_DEF_WUP_EVENT_ENA (1 << 0)
59#define OMAP4_DEF_WUP_LONG_KEY_ENA (1 << 1)
60#define OMAP4_DEF_CTRL_NOSOFTMODE (1 << 1)
61#define OMAP4_DEF_CTRLPTVVALUE (1 << 2)
62#define OMAP4_DEF_CTRLPTV (1 << 1)
63
64/* OMAP4 values */
65#define OMAP4_VAL_IRQDISABLE 0x00
66#define OMAP4_VAL_DEBOUNCINGTIME 0x07
67#define OMAP4_VAL_FUNCTIONALCFG 0x1E
68
69#define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
70
71struct omap4_keypad {
72 struct input_dev *input;
73
74 void __iomem *base;
75 int irq;
76
77 unsigned int rows;
78 unsigned int cols;
79 unsigned int row_shift;
80 unsigned char key_state[8];
81 unsigned short keymap[];
82};
83
84/* Interrupt handler */
85static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
86{
87 struct omap4_keypad *keypad_data = dev_id;
88 struct input_dev *input_dev = keypad_data->input;
89 unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)];
90 unsigned int col, row, code, changed;
91 u32 *new_state = (u32 *) key_state;
92
93 /* Disable interrupts */
94 __raw_writel(OMAP4_VAL_IRQDISABLE,
95 keypad_data->base + OMAP4_KBD_IRQENABLE);
96
97 *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
98 *(new_state + 1) = __raw_readl(keypad_data->base
99 + OMAP4_KBD_FULLCODE63_32);
100
101 for (row = 0; row < keypad_data->rows; row++) {
102 changed = key_state[row] ^ keypad_data->key_state[row];
103 if (!changed)
104 continue;
105
106 for (col = 0; col < keypad_data->cols; col++) {
107 if (changed & (1 << col)) {
108 code = MATRIX_SCAN_CODE(row, col,
109 keypad_data->row_shift);
110 input_event(input_dev, EV_MSC, MSC_SCAN, code);
111 input_report_key(input_dev,
112 keypad_data->keymap[code],
113 key_state[row] & (1 << col));
114 }
115 }
116 }
117
118 input_sync(input_dev);
119
120 memcpy(keypad_data->key_state, key_state,
121 sizeof(keypad_data->key_state));
122
123 /* clear pending interrupts */
124 __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
125 keypad_data->base + OMAP4_KBD_IRQSTATUS);
126
127 /* enable interrupts */
128 __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
129 keypad_data->base + OMAP4_KBD_IRQENABLE);
130
131 return IRQ_HANDLED;
132}
133
134static int omap4_keypad_open(struct input_dev *input)
135{
136 struct omap4_keypad *keypad_data = input_get_drvdata(input);
137
138 pm_runtime_get_sync(input->dev.parent);
139
140 disable_irq(keypad_data->irq);
141
142 __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
143 keypad_data->base + OMAP4_KBD_CTRL);
144 __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
145 keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
146 __raw_writel(OMAP4_VAL_IRQDISABLE,
147 keypad_data->base + OMAP4_KBD_IRQSTATUS);
148 __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
149 keypad_data->base + OMAP4_KBD_IRQENABLE);
150 __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
151 keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
152
153 enable_irq(keypad_data->irq);
154
155 return 0;
156}
157
158static void omap4_keypad_close(struct input_dev *input)
159{
160 struct omap4_keypad *keypad_data = input_get_drvdata(input);
161
162 disable_irq(keypad_data->irq);
163
164 /* Disable interrupts */
165 __raw_writel(OMAP4_VAL_IRQDISABLE,
166 keypad_data->base + OMAP4_KBD_IRQENABLE);
167
168 /* clear pending interrupts */
169 __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
170 keypad_data->base + OMAP4_KBD_IRQSTATUS);
171
172 enable_irq(keypad_data->irq);
173
174 pm_runtime_put_sync(input->dev.parent);
175}
176
177static int __devinit omap4_keypad_probe(struct platform_device *pdev)
178{
179 const struct omap4_keypad_platform_data *pdata;
180 struct omap4_keypad *keypad_data;
181 struct input_dev *input_dev;
182 struct resource *res;
183 resource_size_t size;
184 unsigned int row_shift, max_keys;
185 int irq;
186 int error;
187
188 /* platform data */
189 pdata = pdev->dev.platform_data;
190 if (!pdata) {
191 dev_err(&pdev->dev, "no platform data defined\n");
192 return -EINVAL;
193 }
194
195 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
196 if (!res) {
197 dev_err(&pdev->dev, "no base address specified\n");
198 return -EINVAL;
199 }
200
201 irq = platform_get_irq(pdev, 0);
202 if (!irq) {
203 dev_err(&pdev->dev, "no keyboard irq assigned\n");
204 return -EINVAL;
205 }
206
207 if (!pdata->keymap_data) {
208 dev_err(&pdev->dev, "no keymap data defined\n");
209 return -EINVAL;
210 }
211
212 row_shift = get_count_order(pdata->cols);
213 max_keys = pdata->rows << row_shift;
214
215 keypad_data = kzalloc(sizeof(struct omap4_keypad) +
216 max_keys * sizeof(keypad_data->keymap[0]),
217 GFP_KERNEL);
218 if (!keypad_data) {
219 dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
220 return -ENOMEM;
221 }
222
223 size = resource_size(res);
224
225 res = request_mem_region(res->start, size, pdev->name);
226 if (!res) {
227 dev_err(&pdev->dev, "can't request mem region\n");
228 error = -EBUSY;
229 goto err_free_keypad;
230 }
231
232 keypad_data->base = ioremap(res->start, resource_size(res));
233 if (!keypad_data->base) {
234 dev_err(&pdev->dev, "can't ioremap mem resource\n");
235 error = -ENOMEM;
236 goto err_release_mem;
237 }
238
239 keypad_data->irq = irq;
240 keypad_data->row_shift = row_shift;
241 keypad_data->rows = pdata->rows;
242 keypad_data->cols = pdata->cols;
243
244 /* input device allocation */
245 keypad_data->input = input_dev = input_allocate_device();
246 if (!input_dev) {
247 error = -ENOMEM;
248 goto err_unmap;
249 }
250
251 input_dev->name = pdev->name;
252 input_dev->dev.parent = &pdev->dev;
253 input_dev->id.bustype = BUS_HOST;
254 input_dev->id.vendor = 0x0001;
255 input_dev->id.product = 0x0001;
256 input_dev->id.version = 0x0001;
257
258 input_dev->open = omap4_keypad_open;
259 input_dev->close = omap4_keypad_close;
260
261 input_dev->keycode = keypad_data->keymap;
262 input_dev->keycodesize = sizeof(keypad_data->keymap[0]);
263 input_dev->keycodemax = max_keys;
264
265 __set_bit(EV_KEY, input_dev->evbit);
266 __set_bit(EV_REP, input_dev->evbit);
267
268 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
269
270 input_set_drvdata(input_dev, keypad_data);
271
272 matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
273 input_dev->keycode, input_dev->keybit);
274
275 error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
276 IRQF_TRIGGER_RISING,
277 "omap4-keypad", keypad_data);
278 if (error) {
279 dev_err(&pdev->dev, "failed to register interrupt\n");
280 goto err_free_input;
281 }
282
283 pm_runtime_enable(&pdev->dev);
284
285 error = input_register_device(keypad_data->input);
286 if (error < 0) {
287 dev_err(&pdev->dev, "failed to register input device\n");
288 goto err_pm_disable;
289 }
290
291 platform_set_drvdata(pdev, keypad_data);
292 return 0;
293
294err_pm_disable:
295 pm_runtime_disable(&pdev->dev);
296 free_irq(keypad_data->irq, keypad_data);
297err_free_input:
298 input_free_device(input_dev);
299err_unmap:
300 iounmap(keypad_data->base);
301err_release_mem:
302 release_mem_region(res->start, size);
303err_free_keypad:
304 kfree(keypad_data);
305 return error;
306}
307
308static int __devexit omap4_keypad_remove(struct platform_device *pdev)
309{
310 struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
311 struct resource *res;
312
313 free_irq(keypad_data->irq, keypad_data);
314
315 pm_runtime_disable(&pdev->dev);
316
317 input_unregister_device(keypad_data->input);
318
319 iounmap(keypad_data->base);
320
321 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
322 release_mem_region(res->start, resource_size(res));
323
324 kfree(keypad_data);
325 platform_set_drvdata(pdev, NULL);
326
327 return 0;
328}
329
330static struct platform_driver omap4_keypad_driver = {
331 .probe = omap4_keypad_probe,
332 .remove = __devexit_p(omap4_keypad_remove),
333 .driver = {
334 .name = "omap4-keypad",
335 .owner = THIS_MODULE,
336 },
337};
338
339static int __init omap4_keypad_init(void)
340{
341 return platform_driver_register(&omap4_keypad_driver);
342}
343module_init(omap4_keypad_init);
344
345static void __exit omap4_keypad_exit(void)
346{
347 platform_driver_unregister(&omap4_keypad_driver);
348}
349module_exit(omap4_keypad_exit);
350
351MODULE_AUTHOR("Texas Instruments");
352MODULE_DESCRIPTION("OMAP4 Keypad Driver");
353MODULE_LICENSE("GPL");
354MODULE_ALIAS("platform:omap4-keypad");
diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c
new file mode 100644
index 000000000000..6229c3e8e78b
--- /dev/null
+++ b/drivers/input/keyboard/pmic8xxx-keypad.c
@@ -0,0 +1,800 @@
1/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/kernel.h>
16#include <linux/interrupt.h>
17#include <linux/slab.h>
18#include <linux/input.h>
19#include <linux/bitops.h>
20#include <linux/delay.h>
21#include <linux/mutex.h>
22
23#include <linux/mfd/pm8xxx/core.h>
24#include <linux/mfd/pm8xxx/gpio.h>
25#include <linux/input/pmic8xxx-keypad.h>
26
27#define PM8XXX_MAX_ROWS 18
28#define PM8XXX_MAX_COLS 8
29#define PM8XXX_ROW_SHIFT 3
30#define PM8XXX_MATRIX_MAX_SIZE (PM8XXX_MAX_ROWS * PM8XXX_MAX_COLS)
31
32#define PM8XXX_MIN_ROWS 5
33#define PM8XXX_MIN_COLS 5
34
35#define MAX_SCAN_DELAY 128
36#define MIN_SCAN_DELAY 1
37
38/* in nanoseconds */
39#define MAX_ROW_HOLD_DELAY 122000
40#define MIN_ROW_HOLD_DELAY 30500
41
42#define MAX_DEBOUNCE_TIME 20
43#define MIN_DEBOUNCE_TIME 5
44
45#define KEYP_CTRL 0x148
46
47#define KEYP_CTRL_EVNTS BIT(0)
48#define KEYP_CTRL_EVNTS_MASK 0x3
49
50#define KEYP_CTRL_SCAN_COLS_SHIFT 5
51#define KEYP_CTRL_SCAN_COLS_MIN 5
52#define KEYP_CTRL_SCAN_COLS_BITS 0x3
53
54#define KEYP_CTRL_SCAN_ROWS_SHIFT 2
55#define KEYP_CTRL_SCAN_ROWS_MIN 5
56#define KEYP_CTRL_SCAN_ROWS_BITS 0x7
57
58#define KEYP_CTRL_KEYP_EN BIT(7)
59
60#define KEYP_SCAN 0x149
61
62#define KEYP_SCAN_READ_STATE BIT(0)
63#define KEYP_SCAN_DBOUNCE_SHIFT 1
64#define KEYP_SCAN_PAUSE_SHIFT 3
65#define KEYP_SCAN_ROW_HOLD_SHIFT 6
66
67#define KEYP_TEST 0x14A
68
69#define KEYP_TEST_CLEAR_RECENT_SCAN BIT(6)
70#define KEYP_TEST_CLEAR_OLD_SCAN BIT(5)
71#define KEYP_TEST_READ_RESET BIT(4)
72#define KEYP_TEST_DTEST_EN BIT(3)
73#define KEYP_TEST_ABORT_READ BIT(0)
74
75#define KEYP_TEST_DBG_SELECT_SHIFT 1
76
77/* bits of these registers represent
78 * '0' for key press
79 * '1' for key release
80 */
81#define KEYP_RECENT_DATA 0x14B
82#define KEYP_OLD_DATA 0x14C
83
84#define KEYP_CLOCK_FREQ 32768
85
86/**
87 * struct pmic8xxx_kp - internal keypad data structure
88 * @pdata - keypad platform data pointer
89 * @input - input device pointer for keypad
90 * @key_sense_irq - key press/release irq number
91 * @key_stuck_irq - key stuck notification irq number
92 * @keycodes - array to hold the key codes
93 * @dev - parent device pointer
94 * @keystate - present key press/release state
95 * @stuckstate - present state when key stuck irq
96 * @ctrl_reg - control register value
97 */
98struct pmic8xxx_kp {
99 const struct pm8xxx_keypad_platform_data *pdata;
100 struct input_dev *input;
101 int key_sense_irq;
102 int key_stuck_irq;
103
104 unsigned short keycodes[PM8XXX_MATRIX_MAX_SIZE];
105
106 struct device *dev;
107 u16 keystate[PM8XXX_MAX_ROWS];
108 u16 stuckstate[PM8XXX_MAX_ROWS];
109
110 u8 ctrl_reg;
111};
112
113static int pmic8xxx_kp_write_u8(struct pmic8xxx_kp *kp,
114 u8 data, u16 reg)
115{
116 int rc;
117
118 rc = pm8xxx_writeb(kp->dev->parent, reg, data);
119 return rc;
120}
121
122static int pmic8xxx_kp_read(struct pmic8xxx_kp *kp,
123 u8 *data, u16 reg, unsigned num_bytes)
124{
125 int rc;
126
127 rc = pm8xxx_read_buf(kp->dev->parent, reg, data, num_bytes);
128 return rc;
129}
130
131static int pmic8xxx_kp_read_u8(struct pmic8xxx_kp *kp,
132 u8 *data, u16 reg)
133{
134 int rc;
135
136 rc = pmic8xxx_kp_read(kp, data, reg, 1);
137 return rc;
138}
139
140static u8 pmic8xxx_col_state(struct pmic8xxx_kp *kp, u8 col)
141{
142 /* all keys pressed on that particular row? */
143 if (col == 0x00)
144 return 1 << kp->pdata->num_cols;
145 else
146 return col & ((1 << kp->pdata->num_cols) - 1);
147}
148
149/*
150 * Synchronous read protocol for RevB0 onwards:
151 *
152 * 1. Write '1' to ReadState bit in KEYP_SCAN register
153 * 2. Wait 2*32KHz clocks, so that HW can successfully enter read mode
154 * synchronously
155 * 3. Read rows in old array first if events are more than one
156 * 4. Read rows in recent array
157 * 5. Wait 4*32KHz clocks
158 * 6. Write '0' to ReadState bit of KEYP_SCAN register so that hw can
159 * synchronously exit read mode.
160 */
161static int pmic8xxx_chk_sync_read(struct pmic8xxx_kp *kp)
162{
163 int rc;
164 u8 scan_val;
165
166 rc = pmic8xxx_kp_read_u8(kp, &scan_val, KEYP_SCAN);
167 if (rc < 0) {
168 dev_err(kp->dev, "Error reading KEYP_SCAN reg, rc=%d\n", rc);
169 return rc;
170 }
171
172 scan_val |= 0x1;
173
174 rc = pmic8xxx_kp_write_u8(kp, scan_val, KEYP_SCAN);
175 if (rc < 0) {
176 dev_err(kp->dev, "Error writing KEYP_SCAN reg, rc=%d\n", rc);
177 return rc;
178 }
179
180 /* 2 * 32KHz clocks */
181 udelay((2 * DIV_ROUND_UP(USEC_PER_SEC, KEYP_CLOCK_FREQ)) + 1);
182
183 return rc;
184}
185
186static int pmic8xxx_kp_read_data(struct pmic8xxx_kp *kp, u16 *state,
187 u16 data_reg, int read_rows)
188{
189 int rc, row;
190 u8 new_data[PM8XXX_MAX_ROWS];
191
192 rc = pmic8xxx_kp_read(kp, new_data, data_reg, read_rows);
193 if (rc)
194 return rc;
195
196 for (row = 0; row < kp->pdata->num_rows; row++) {
197 dev_dbg(kp->dev, "new_data[%d] = %d\n", row,
198 new_data[row]);
199 state[row] = pmic8xxx_col_state(kp, new_data[row]);
200 }
201
202 return rc;
203}
204
205static int pmic8xxx_kp_read_matrix(struct pmic8xxx_kp *kp, u16 *new_state,
206 u16 *old_state)
207{
208 int rc, read_rows;
209 u8 scan_val;
210
211 if (kp->pdata->num_rows < PM8XXX_MIN_ROWS)
212 read_rows = PM8XXX_MIN_ROWS;
213 else
214 read_rows = kp->pdata->num_rows;
215
216 pmic8xxx_chk_sync_read(kp);
217
218 if (old_state) {
219 rc = pmic8xxx_kp_read_data(kp, old_state, KEYP_OLD_DATA,
220 read_rows);
221 if (rc < 0) {
222 dev_err(kp->dev,
223 "Error reading KEYP_OLD_DATA, rc=%d\n", rc);
224 return rc;
225 }
226 }
227
228 rc = pmic8xxx_kp_read_data(kp, new_state, KEYP_RECENT_DATA,
229 read_rows);
230 if (rc < 0) {
231 dev_err(kp->dev,
232 "Error reading KEYP_RECENT_DATA, rc=%d\n", rc);
233 return rc;
234 }
235
236 /* 4 * 32KHz clocks */
237 udelay((4 * DIV_ROUND_UP(USEC_PER_SEC, KEYP_CLOCK_FREQ)) + 1);
238
239 rc = pmic8xxx_kp_read_u8(kp, &scan_val, KEYP_SCAN);
240 if (rc < 0) {
241 dev_err(kp->dev, "Error reading KEYP_SCAN reg, rc=%d\n", rc);
242 return rc;
243 }
244
245 scan_val &= 0xFE;
246 rc = pmic8xxx_kp_write_u8(kp, scan_val, KEYP_SCAN);
247 if (rc < 0)
248 dev_err(kp->dev, "Error writing KEYP_SCAN reg, rc=%d\n", rc);
249
250 return rc;
251}
252
253static void __pmic8xxx_kp_scan_matrix(struct pmic8xxx_kp *kp, u16 *new_state,
254 u16 *old_state)
255{
256 int row, col, code;
257
258 for (row = 0; row < kp->pdata->num_rows; row++) {
259 int bits_changed = new_state[row] ^ old_state[row];
260
261 if (!bits_changed)
262 continue;
263
264 for (col = 0; col < kp->pdata->num_cols; col++) {
265 if (!(bits_changed & (1 << col)))
266 continue;
267
268 dev_dbg(kp->dev, "key [%d:%d] %s\n", row, col,
269 !(new_state[row] & (1 << col)) ?
270 "pressed" : "released");
271
272 code = MATRIX_SCAN_CODE(row, col, PM8XXX_ROW_SHIFT);
273
274 input_event(kp->input, EV_MSC, MSC_SCAN, code);
275 input_report_key(kp->input,
276 kp->keycodes[code],
277 !(new_state[row] & (1 << col)));
278
279 input_sync(kp->input);
280 }
281 }
282}
283
284static bool pmic8xxx_detect_ghost_keys(struct pmic8xxx_kp *kp, u16 *new_state)
285{
286 int row, found_first = -1;
287 u16 check, row_state;
288
289 check = 0;
290 for (row = 0; row < kp->pdata->num_rows; row++) {
291 row_state = (~new_state[row]) &
292 ((1 << kp->pdata->num_cols) - 1);
293
294 if (hweight16(row_state) > 1) {
295 if (found_first == -1)
296 found_first = row;
297 if (check & row_state) {
298 dev_dbg(kp->dev, "detected ghost key on row[%d]"
299 " and row[%d]\n", found_first, row);
300 return true;
301 }
302 }
303 check |= row_state;
304 }
305 return false;
306}
307
308static int pmic8xxx_kp_scan_matrix(struct pmic8xxx_kp *kp, unsigned int events)
309{
310 u16 new_state[PM8XXX_MAX_ROWS];
311 u16 old_state[PM8XXX_MAX_ROWS];
312 int rc;
313
314 switch (events) {
315 case 0x1:
316 rc = pmic8xxx_kp_read_matrix(kp, new_state, NULL);
317 if (rc < 0)
318 return rc;
319
320 /* detecting ghost key is not an error */
321 if (pmic8xxx_detect_ghost_keys(kp, new_state))
322 return 0;
323 __pmic8xxx_kp_scan_matrix(kp, new_state, kp->keystate);
324 memcpy(kp->keystate, new_state, sizeof(new_state));
325 break;
326 case 0x3: /* two events - eventcounter is gray-coded */
327 rc = pmic8xxx_kp_read_matrix(kp, new_state, old_state);
328 if (rc < 0)
329 return rc;
330
331 __pmic8xxx_kp_scan_matrix(kp, old_state, kp->keystate);
332 __pmic8xxx_kp_scan_matrix(kp, new_state, old_state);
333 memcpy(kp->keystate, new_state, sizeof(new_state));
334 break;
335 case 0x2:
336 dev_dbg(kp->dev, "Some key events were lost\n");
337 rc = pmic8xxx_kp_read_matrix(kp, new_state, old_state);
338 if (rc < 0)
339 return rc;
340 __pmic8xxx_kp_scan_matrix(kp, old_state, kp->keystate);
341 __pmic8xxx_kp_scan_matrix(kp, new_state, old_state);
342 memcpy(kp->keystate, new_state, sizeof(new_state));
343 break;
344 default:
345 rc = -EINVAL;
346 }
347 return rc;
348}
349
350/*
351 * NOTE: We are reading recent and old data registers blindly
352 * whenever key-stuck interrupt happens, because events counter doesn't
353 * get updated when this interrupt happens due to key stuck doesn't get
354 * considered as key state change.
355 *
356 * We are not using old data register contents after they are being read
357 * because it might report the key which was pressed before the key being stuck
358 * as stuck key because it's pressed status is stored in the old data
359 * register.
360 */
361static irqreturn_t pmic8xxx_kp_stuck_irq(int irq, void *data)
362{
363 u16 new_state[PM8XXX_MAX_ROWS];
364 u16 old_state[PM8XXX_MAX_ROWS];
365 int rc;
366 struct pmic8xxx_kp *kp = data;
367
368 rc = pmic8xxx_kp_read_matrix(kp, new_state, old_state);
369 if (rc < 0) {
370 dev_err(kp->dev, "failed to read keypad matrix\n");
371 return IRQ_HANDLED;
372 }
373
374 __pmic8xxx_kp_scan_matrix(kp, new_state, kp->stuckstate);
375
376 return IRQ_HANDLED;
377}
378
379static irqreturn_t pmic8xxx_kp_irq(int irq, void *data)
380{
381 struct pmic8xxx_kp *kp = data;
382 u8 ctrl_val, events;
383 int rc;
384
385 rc = pmic8xxx_kp_read(kp, &ctrl_val, KEYP_CTRL, 1);
386 if (rc < 0) {
387 dev_err(kp->dev, "failed to read keyp_ctrl register\n");
388 return IRQ_HANDLED;
389 }
390
391 events = ctrl_val & KEYP_CTRL_EVNTS_MASK;
392
393 rc = pmic8xxx_kp_scan_matrix(kp, events);
394 if (rc < 0)
395 dev_err(kp->dev, "failed to scan matrix\n");
396
397 return IRQ_HANDLED;
398}
399
400static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp)
401{
402 int bits, rc, cycles;
403 u8 scan_val = 0, ctrl_val = 0;
404 static const u8 row_bits[] = {
405 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7,
406 };
407
408 /* Find column bits */
409 if (kp->pdata->num_cols < KEYP_CTRL_SCAN_COLS_MIN)
410 bits = 0;
411 else
412 bits = kp->pdata->num_cols - KEYP_CTRL_SCAN_COLS_MIN;
413 ctrl_val = (bits & KEYP_CTRL_SCAN_COLS_BITS) <<
414 KEYP_CTRL_SCAN_COLS_SHIFT;
415
416 /* Find row bits */
417 if (kp->pdata->num_rows < KEYP_CTRL_SCAN_ROWS_MIN)
418 bits = 0;
419 else
420 bits = row_bits[kp->pdata->num_rows - KEYP_CTRL_SCAN_ROWS_MIN];
421
422 ctrl_val |= (bits << KEYP_CTRL_SCAN_ROWS_SHIFT);
423
424 rc = pmic8xxx_kp_write_u8(kp, ctrl_val, KEYP_CTRL);
425 if (rc < 0) {
426 dev_err(kp->dev, "Error writing KEYP_CTRL reg, rc=%d\n", rc);
427 return rc;
428 }
429
430 bits = (kp->pdata->debounce_ms / 5) - 1;
431
432 scan_val |= (bits << KEYP_SCAN_DBOUNCE_SHIFT);
433
434 bits = fls(kp->pdata->scan_delay_ms) - 1;
435 scan_val |= (bits << KEYP_SCAN_PAUSE_SHIFT);
436
437 /* Row hold time is a multiple of 32KHz cycles. */
438 cycles = (kp->pdata->row_hold_ns * KEYP_CLOCK_FREQ) / NSEC_PER_SEC;
439
440 scan_val |= (cycles << KEYP_SCAN_ROW_HOLD_SHIFT);
441
442 rc = pmic8xxx_kp_write_u8(kp, scan_val, KEYP_SCAN);
443 if (rc)
444 dev_err(kp->dev, "Error writing KEYP_SCAN reg, rc=%d\n", rc);
445
446 return rc;
447
448}
449
450static int __devinit pmic8xxx_kp_config_gpio(int gpio_start, int num_gpios,
451 struct pmic8xxx_kp *kp, struct pm_gpio *gpio_config)
452{
453 int rc, i;
454
455 if (gpio_start < 0 || num_gpios < 0)
456 return -EINVAL;
457
458 for (i = 0; i < num_gpios; i++) {
459 rc = pm8xxx_gpio_config(gpio_start + i, gpio_config);
460 if (rc) {
461 dev_err(kp->dev, "%s: FAIL pm8xxx_gpio_config():"
462 "for PM GPIO [%d] rc=%d.\n",
463 __func__, gpio_start + i, rc);
464 return rc;
465 }
466 }
467
468 return 0;
469}
470
471static int pmic8xxx_kp_enable(struct pmic8xxx_kp *kp)
472{
473 int rc;
474
475 kp->ctrl_reg |= KEYP_CTRL_KEYP_EN;
476
477 rc = pmic8xxx_kp_write_u8(kp, kp->ctrl_reg, KEYP_CTRL);
478 if (rc < 0)
479 dev_err(kp->dev, "Error writing KEYP_CTRL reg, rc=%d\n", rc);
480
481 return rc;
482}
483
484static int pmic8xxx_kp_disable(struct pmic8xxx_kp *kp)
485{
486 int rc;
487
488 kp->ctrl_reg &= ~KEYP_CTRL_KEYP_EN;
489
490 rc = pmic8xxx_kp_write_u8(kp, kp->ctrl_reg, KEYP_CTRL);
491 if (rc < 0)
492 return rc;
493
494 return rc;
495}
496
497static int pmic8xxx_kp_open(struct input_dev *dev)
498{
499 struct pmic8xxx_kp *kp = input_get_drvdata(dev);
500
501 return pmic8xxx_kp_enable(kp);
502}
503
504static void pmic8xxx_kp_close(struct input_dev *dev)
505{
506 struct pmic8xxx_kp *kp = input_get_drvdata(dev);
507
508 pmic8xxx_kp_disable(kp);
509}
510
511/*
512 * keypad controller should be initialized in the following sequence
513 * only, otherwise it might get into FSM stuck state.
514 *
515 * - Initialize keypad control parameters, like no. of rows, columns,
516 * timing values etc.,
517 * - configure rows and column gpios pull up/down.
518 * - set irq edge type.
519 * - enable the keypad controller.
520 */
521static int __devinit pmic8xxx_kp_probe(struct platform_device *pdev)
522{
523 const struct pm8xxx_keypad_platform_data *pdata =
524 dev_get_platdata(&pdev->dev);
525 const struct matrix_keymap_data *keymap_data;
526 struct pmic8xxx_kp *kp;
527 int rc;
528 u8 ctrl_val;
529
530 struct pm_gpio kypd_drv = {
531 .direction = PM_GPIO_DIR_OUT,
532 .output_buffer = PM_GPIO_OUT_BUF_OPEN_DRAIN,
533 .output_value = 0,
534 .pull = PM_GPIO_PULL_NO,
535 .vin_sel = PM_GPIO_VIN_S3,
536 .out_strength = PM_GPIO_STRENGTH_LOW,
537 .function = PM_GPIO_FUNC_1,
538 .inv_int_pol = 1,
539 };
540
541 struct pm_gpio kypd_sns = {
542 .direction = PM_GPIO_DIR_IN,
543 .pull = PM_GPIO_PULL_UP_31P5,
544 .vin_sel = PM_GPIO_VIN_S3,
545 .out_strength = PM_GPIO_STRENGTH_NO,
546 .function = PM_GPIO_FUNC_NORMAL,
547 .inv_int_pol = 1,
548 };
549
550
551 if (!pdata || !pdata->num_cols || !pdata->num_rows ||
552 pdata->num_cols > PM8XXX_MAX_COLS ||
553 pdata->num_rows > PM8XXX_MAX_ROWS ||
554 pdata->num_cols < PM8XXX_MIN_COLS) {
555 dev_err(&pdev->dev, "invalid platform data\n");
556 return -EINVAL;
557 }
558
559 if (!pdata->scan_delay_ms ||
560 pdata->scan_delay_ms > MAX_SCAN_DELAY ||
561 pdata->scan_delay_ms < MIN_SCAN_DELAY ||
562 !is_power_of_2(pdata->scan_delay_ms)) {
563 dev_err(&pdev->dev, "invalid keypad scan time supplied\n");
564 return -EINVAL;
565 }
566
567 if (!pdata->row_hold_ns ||
568 pdata->row_hold_ns > MAX_ROW_HOLD_DELAY ||
569 pdata->row_hold_ns < MIN_ROW_HOLD_DELAY ||
570 ((pdata->row_hold_ns % MIN_ROW_HOLD_DELAY) != 0)) {
571 dev_err(&pdev->dev, "invalid keypad row hold time supplied\n");
572 return -EINVAL;
573 }
574
575 if (!pdata->debounce_ms ||
576 ((pdata->debounce_ms % 5) != 0) ||
577 pdata->debounce_ms > MAX_DEBOUNCE_TIME ||
578 pdata->debounce_ms < MIN_DEBOUNCE_TIME) {
579 dev_err(&pdev->dev, "invalid debounce time supplied\n");
580 return -EINVAL;
581 }
582
583 keymap_data = pdata->keymap_data;
584 if (!keymap_data) {
585 dev_err(&pdev->dev, "no keymap data supplied\n");
586 return -EINVAL;
587 }
588
589 kp = kzalloc(sizeof(*kp), GFP_KERNEL);
590 if (!kp)
591 return -ENOMEM;
592
593 platform_set_drvdata(pdev, kp);
594
595 kp->pdata = pdata;
596 kp->dev = &pdev->dev;
597
598 kp->input = input_allocate_device();
599 if (!kp->input) {
600 dev_err(&pdev->dev, "unable to allocate input device\n");
601 rc = -ENOMEM;
602 goto err_alloc_device;
603 }
604
605 kp->key_sense_irq = platform_get_irq(pdev, 0);
606 if (kp->key_sense_irq < 0) {
607 dev_err(&pdev->dev, "unable to get keypad sense irq\n");
608 rc = -ENXIO;
609 goto err_get_irq;
610 }
611
612 kp->key_stuck_irq = platform_get_irq(pdev, 1);
613 if (kp->key_stuck_irq < 0) {
614 dev_err(&pdev->dev, "unable to get keypad stuck irq\n");
615 rc = -ENXIO;
616 goto err_get_irq;
617 }
618
619 kp->input->name = pdata->input_name ? : "PMIC8XXX keypad";
620 kp->input->phys = pdata->input_phys_device ? : "pmic8xxx_keypad/input0";
621
622 kp->input->dev.parent = &pdev->dev;
623
624 kp->input->id.bustype = BUS_I2C;
625 kp->input->id.version = 0x0001;
626 kp->input->id.product = 0x0001;
627 kp->input->id.vendor = 0x0001;
628
629 kp->input->evbit[0] = BIT_MASK(EV_KEY);
630
631 if (pdata->rep)
632 __set_bit(EV_REP, kp->input->evbit);
633
634 kp->input->keycode = kp->keycodes;
635 kp->input->keycodemax = PM8XXX_MATRIX_MAX_SIZE;
636 kp->input->keycodesize = sizeof(kp->keycodes);
637 kp->input->open = pmic8xxx_kp_open;
638 kp->input->close = pmic8xxx_kp_close;
639
640 matrix_keypad_build_keymap(keymap_data, PM8XXX_ROW_SHIFT,
641 kp->input->keycode, kp->input->keybit);
642
643 input_set_capability(kp->input, EV_MSC, MSC_SCAN);
644 input_set_drvdata(kp->input, kp);
645
646 /* initialize keypad state */
647 memset(kp->keystate, 0xff, sizeof(kp->keystate));
648 memset(kp->stuckstate, 0xff, sizeof(kp->stuckstate));
649
650 rc = pmic8xxx_kpd_init(kp);
651 if (rc < 0) {
652 dev_err(&pdev->dev, "unable to initialize keypad controller\n");
653 goto err_get_irq;
654 }
655
656 rc = pmic8xxx_kp_config_gpio(pdata->cols_gpio_start,
657 pdata->num_cols, kp, &kypd_sns);
658 if (rc < 0) {
659 dev_err(&pdev->dev, "unable to configure keypad sense lines\n");
660 goto err_gpio_config;
661 }
662
663 rc = pmic8xxx_kp_config_gpio(pdata->rows_gpio_start,
664 pdata->num_rows, kp, &kypd_drv);
665 if (rc < 0) {
666 dev_err(&pdev->dev, "unable to configure keypad drive lines\n");
667 goto err_gpio_config;
668 }
669
670 rc = request_any_context_irq(kp->key_sense_irq, pmic8xxx_kp_irq,
671 IRQF_TRIGGER_RISING, "pmic-keypad", kp);
672 if (rc < 0) {
673 dev_err(&pdev->dev, "failed to request keypad sense irq\n");
674 goto err_get_irq;
675 }
676
677 rc = request_any_context_irq(kp->key_stuck_irq, pmic8xxx_kp_stuck_irq,
678 IRQF_TRIGGER_RISING, "pmic-keypad-stuck", kp);
679 if (rc < 0) {
680 dev_err(&pdev->dev, "failed to request keypad stuck irq\n");
681 goto err_req_stuck_irq;
682 }
683
684 rc = pmic8xxx_kp_read_u8(kp, &ctrl_val, KEYP_CTRL);
685 if (rc < 0) {
686 dev_err(&pdev->dev, "failed to read KEYP_CTRL register\n");
687 goto err_pmic_reg_read;
688 }
689
690 kp->ctrl_reg = ctrl_val;
691
692 rc = input_register_device(kp->input);
693 if (rc < 0) {
694 dev_err(&pdev->dev, "unable to register keypad input device\n");
695 goto err_pmic_reg_read;
696 }
697
698 device_init_wakeup(&pdev->dev, pdata->wakeup);
699
700 return 0;
701
702err_pmic_reg_read:
703 free_irq(kp->key_stuck_irq, NULL);
704err_req_stuck_irq:
705 free_irq(kp->key_sense_irq, NULL);
706err_gpio_config:
707err_get_irq:
708 input_free_device(kp->input);
709err_alloc_device:
710 platform_set_drvdata(pdev, NULL);
711 kfree(kp);
712 return rc;
713}
714
715static int __devexit pmic8xxx_kp_remove(struct platform_device *pdev)
716{
717 struct pmic8xxx_kp *kp = platform_get_drvdata(pdev);
718
719 device_init_wakeup(&pdev->dev, 0);
720 free_irq(kp->key_stuck_irq, NULL);
721 free_irq(kp->key_sense_irq, NULL);
722 input_unregister_device(kp->input);
723 kfree(kp);
724
725 platform_set_drvdata(pdev, NULL);
726 return 0;
727}
728
729#ifdef CONFIG_PM_SLEEP
730static int pmic8xxx_kp_suspend(struct device *dev)
731{
732 struct platform_device *pdev = to_platform_device(dev);
733 struct pmic8xxx_kp *kp = platform_get_drvdata(pdev);
734 struct input_dev *input_dev = kp->input;
735
736 if (device_may_wakeup(dev)) {
737 enable_irq_wake(kp->key_sense_irq);
738 } else {
739 mutex_lock(&input_dev->mutex);
740
741 if (input_dev->users)
742 pmic8xxx_kp_disable(kp);
743
744 mutex_unlock(&input_dev->mutex);
745 }
746
747 return 0;
748}
749
750static int pmic8xxx_kp_resume(struct device *dev)
751{
752 struct platform_device *pdev = to_platform_device(dev);
753 struct pmic8xxx_kp *kp = platform_get_drvdata(pdev);
754 struct input_dev *input_dev = kp->input;
755
756 if (device_may_wakeup(dev)) {
757 disable_irq_wake(kp->key_sense_irq);
758 } else {
759 mutex_lock(&input_dev->mutex);
760
761 if (input_dev->users)
762 pmic8xxx_kp_enable(kp);
763
764 mutex_unlock(&input_dev->mutex);
765 }
766
767 return 0;
768}
769#endif
770
771static SIMPLE_DEV_PM_OPS(pm8xxx_kp_pm_ops,
772 pmic8xxx_kp_suspend, pmic8xxx_kp_resume);
773
774static struct platform_driver pmic8xxx_kp_driver = {
775 .probe = pmic8xxx_kp_probe,
776 .remove = __devexit_p(pmic8xxx_kp_remove),
777 .driver = {
778 .name = PM8XXX_KEYPAD_DEV_NAME,
779 .owner = THIS_MODULE,
780 .pm = &pm8xxx_kp_pm_ops,
781 },
782};
783
784static int __init pmic8xxx_kp_init(void)
785{
786 return platform_driver_register(&pmic8xxx_kp_driver);
787}
788module_init(pmic8xxx_kp_init);
789
790static void __exit pmic8xxx_kp_exit(void)
791{
792 platform_driver_unregister(&pmic8xxx_kp_driver);
793}
794module_exit(pmic8xxx_kp_exit);
795
796MODULE_LICENSE("GPL v2");
797MODULE_DESCRIPTION("PMIC8XXX keypad driver");
798MODULE_VERSION("1.0");
799MODULE_ALIAS("platform:pmic8xxx_keypad");
800MODULE_AUTHOR("Trilok Soni <tsoni@codeaurora.org>");
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index f32404f99189..4b0ec35259a1 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -32,7 +32,7 @@
32#include <asm/mach/map.h> 32#include <asm/mach/map.h>
33 33
34#include <mach/hardware.h> 34#include <mach/hardware.h>
35#include <mach/pxa27x_keypad.h> 35#include <plat/pxa27x_keypad.h>
36/* 36/*
37 * Keypad Controller registers 37 * Keypad Controller registers
38 */ 38 */
@@ -330,11 +330,21 @@ static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad)
330 keypad->direct_key_state = new_state; 330 keypad->direct_key_state = new_state;
331} 331}
332 332
333static void clear_wakeup_event(struct pxa27x_keypad *keypad)
334{
335 struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
336
337 if (pdata->clear_wakeup_event)
338 (pdata->clear_wakeup_event)();
339}
340
333static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) 341static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id)
334{ 342{
335 struct pxa27x_keypad *keypad = dev_id; 343 struct pxa27x_keypad *keypad = dev_id;
336 unsigned long kpc = keypad_readl(KPC); 344 unsigned long kpc = keypad_readl(KPC);
337 345
346 clear_wakeup_event(keypad);
347
338 if (kpc & KPC_DI) 348 if (kpc & KPC_DI)
339 pxa27x_keypad_scan_direct(keypad); 349 pxa27x_keypad_scan_direct(keypad);
340 350
diff --git a/drivers/input/keyboard/qt1070.c b/drivers/input/keyboard/qt1070.c
new file mode 100644
index 000000000000..ca7b89196ab7
--- /dev/null
+++ b/drivers/input/keyboard/qt1070.c
@@ -0,0 +1,277 @@
1/*
2 * Atmel AT42QT1070 QTouch Sensor Controller
3 *
4 * Copyright (C) 2011 Atmel
5 *
6 * Authors: Bo Shen <voice.shen@atmel.com>
7 *
8 * Base on AT42QT2160 driver by:
9 * Raphael Derosso Pereira <raphaelpereira@gmail.com>
10 * Copyright (C) 2009
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/i2c.h>
30#include <linux/input.h>
31#include <linux/slab.h>
32#include <linux/irq.h>
33#include <linux/interrupt.h>
34#include <linux/jiffies.h>
35#include <linux/delay.h>
36
37/* Address for each register */
38#define CHIP_ID 0x00
39#define QT1070_CHIP_ID 0x2E
40
41#define FW_VERSION 0x01
42#define QT1070_FW_VERSION 0x15
43
44#define DET_STATUS 0x02
45
46#define KEY_STATUS 0x03
47
48/* Calibrate */
49#define CALIBRATE_CMD 0x38
50#define QT1070_CAL_TIME 200
51
52/* Reset */
53#define RESET 0x39
54#define QT1070_RESET_TIME 255
55
56/* AT42QT1070 support up to 7 keys */
57static const unsigned short qt1070_key2code[] = {
58 KEY_0, KEY_1, KEY_2, KEY_3,
59 KEY_4, KEY_5, KEY_6,
60};
61
62struct qt1070_data {
63 struct i2c_client *client;
64 struct input_dev *input;
65 unsigned int irq;
66 unsigned short keycodes[ARRAY_SIZE(qt1070_key2code)];
67 u8 last_keys;
68};
69
70static int qt1070_read(struct i2c_client *client, u8 reg)
71{
72 int ret;
73
74 ret = i2c_smbus_read_byte_data(client, reg);
75 if (ret < 0)
76 dev_err(&client->dev,
77 "can not read register, returned %d\n", ret);
78
79 return ret;
80}
81
82static int qt1070_write(struct i2c_client *client, u8 reg, u8 data)
83{
84 int ret;
85
86 ret = i2c_smbus_write_byte_data(client, reg, data);
87 if (ret < 0)
88 dev_err(&client->dev,
89 "can not write register, returned %d\n", ret);
90
91 return ret;
92}
93
94static bool __devinit qt1070_identify(struct i2c_client *client)
95{
96 int id, ver;
97
98 /* Read Chip ID */
99 id = qt1070_read(client, CHIP_ID);
100 if (id != QT1070_CHIP_ID) {
101 dev_err(&client->dev, "ID %d not supported\n", id);
102 return false;
103 }
104
105 /* Read firmware version */
106 ver = qt1070_read(client, FW_VERSION);
107 if (ver < 0) {
108 dev_err(&client->dev, "could not read the firmware version\n");
109 return false;
110 }
111
112 dev_info(&client->dev, "AT42QT1070 firmware version %x\n", ver);
113
114 return true;
115}
116
117static irqreturn_t qt1070_interrupt(int irq, void *dev_id)
118{
119 struct qt1070_data *data = dev_id;
120 struct i2c_client *client = data->client;
121 struct input_dev *input = data->input;
122 int i;
123 u8 new_keys, keyval, mask = 0x01;
124
125 /* Read the detected status register, thus clearing interrupt */
126 qt1070_read(client, DET_STATUS);
127
128 /* Read which key changed */
129 new_keys = qt1070_read(client, KEY_STATUS);
130
131 for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
132 keyval = new_keys & mask;
133 if ((data->last_keys & mask) != keyval)
134 input_report_key(input, data->keycodes[i], keyval);
135 mask <<= 1;
136 }
137 input_sync(input);
138
139 data->last_keys = new_keys;
140 return IRQ_HANDLED;
141}
142
143static int __devinit qt1070_probe(struct i2c_client *client,
144 const struct i2c_device_id *id)
145{
146 struct qt1070_data *data;
147 struct input_dev *input;
148 int i;
149 int err;
150
151 err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE);
152 if (!err) {
153 dev_err(&client->dev, "%s adapter not supported\n",
154 dev_driver_string(&client->adapter->dev));
155 return -ENODEV;
156 }
157
158 if (!client->irq) {
159 dev_err(&client->dev, "please assign the irq to this device\n");
160 return -EINVAL;
161 }
162
163 /* Identify the qt1070 chip */
164 if (!qt1070_identify(client))
165 return -ENODEV;
166
167 data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL);
168 input = input_allocate_device();
169 if (!data || !input) {
170 dev_err(&client->dev, "insufficient memory\n");
171 err = -ENOMEM;
172 goto err_free_mem;
173 }
174
175 data->client = client;
176 data->input = input;
177 data->irq = client->irq;
178
179 input->name = "AT42QT1070 QTouch Sensor";
180 input->dev.parent = &client->dev;
181 input->id.bustype = BUS_I2C;
182
183 /* Add the keycode */
184 input->keycode = data->keycodes;
185 input->keycodesize = sizeof(data->keycodes[0]);
186 input->keycodemax = ARRAY_SIZE(qt1070_key2code);
187
188 __set_bit(EV_KEY, input->evbit);
189
190 for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
191 data->keycodes[i] = qt1070_key2code[i];
192 __set_bit(qt1070_key2code[i], input->keybit);
193 }
194
195 /* Calibrate device */
196 qt1070_write(client, CALIBRATE_CMD, 1);
197 msleep(QT1070_CAL_TIME);
198
199 /* Soft reset */
200 qt1070_write(client, RESET, 1);
201 msleep(QT1070_RESET_TIME);
202
203 err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
204 IRQF_TRIGGER_NONE, client->dev.driver->name, data);
205 if (err) {
206 dev_err(&client->dev, "fail to request irq\n");
207 goto err_free_mem;
208 }
209
210 /* Register the input device */
211 err = input_register_device(data->input);
212 if (err) {
213 dev_err(&client->dev, "Failed to register input device\n");
214 goto err_free_irq;
215 }
216
217 i2c_set_clientdata(client, data);
218
219 /* Read to clear the chang line */
220 qt1070_read(client, DET_STATUS);
221
222 return 0;
223
224err_free_irq:
225 free_irq(client->irq, data);
226err_free_mem:
227 input_free_device(input);
228 kfree(data);
229 return err;
230}
231
232static int __devexit qt1070_remove(struct i2c_client *client)
233{
234 struct qt1070_data *data = i2c_get_clientdata(client);
235
236 /* Release IRQ */
237 free_irq(client->irq, data);
238
239 input_unregister_device(data->input);
240 kfree(data);
241
242 i2c_set_clientdata(client, NULL);
243
244 return 0;
245}
246
247static const struct i2c_device_id qt1070_id[] = {
248 { "qt1070", 0 },
249 { },
250};
251MODULE_DEVICE_TABLE(i2c, qt1070_id);
252
253static struct i2c_driver qt1070_driver = {
254 .driver = {
255 .name = "qt1070",
256 .owner = THIS_MODULE,
257 },
258 .id_table = qt1070_id,
259 .probe = qt1070_probe,
260 .remove = __devexit_p(qt1070_remove),
261};
262
263static int __init qt1070_init(void)
264{
265 return i2c_add_driver(&qt1070_driver);
266}
267module_init(qt1070_init);
268
269static void __exit qt1070_exit(void)
270{
271 i2c_del_driver(&qt1070_driver);
272}
273module_exit(qt1070_exit);
274
275MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
276MODULE_DESCRIPTION("Driver for AT42QT1070 QTouch sensor");
277MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c
index d7dafd9425b6..6876700a4469 100644
--- a/drivers/input/keyboard/sh_keysc.c
+++ b/drivers/input/keyboard/sh_keysc.c
@@ -20,7 +20,7 @@
20#include <linux/input.h> 20#include <linux/input.h>
21#include <linux/input/sh_keysc.h> 21#include <linux/input/sh_keysc.h>
22#include <linux/bitmap.h> 22#include <linux/bitmap.h>
23#include <linux/clk.h> 23#include <linux/pm_runtime.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26 26
@@ -32,12 +32,11 @@ static const struct {
32 [SH_KEYSC_MODE_3] = { 2, 4, 7 }, 32 [SH_KEYSC_MODE_3] = { 2, 4, 7 },
33 [SH_KEYSC_MODE_4] = { 3, 6, 6 }, 33 [SH_KEYSC_MODE_4] = { 3, 6, 6 },
34 [SH_KEYSC_MODE_5] = { 4, 6, 7 }, 34 [SH_KEYSC_MODE_5] = { 4, 6, 7 },
35 [SH_KEYSC_MODE_6] = { 5, 7, 7 }, 35 [SH_KEYSC_MODE_6] = { 5, 8, 8 },
36}; 36};
37 37
38struct sh_keysc_priv { 38struct sh_keysc_priv {
39 void __iomem *iomem_base; 39 void __iomem *iomem_base;
40 struct clk *clk;
41 DECLARE_BITMAP(last_keys, SH_KEYSC_MAXKEYS); 40 DECLARE_BITMAP(last_keys, SH_KEYSC_MAXKEYS);
42 struct input_dev *input; 41 struct input_dev *input;
43 struct sh_keysc_info pdata; 42 struct sh_keysc_info pdata;
@@ -169,7 +168,6 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
169 struct sh_keysc_info *pdata; 168 struct sh_keysc_info *pdata;
170 struct resource *res; 169 struct resource *res;
171 struct input_dev *input; 170 struct input_dev *input;
172 char clk_name[8];
173 int i; 171 int i;
174 int irq, error; 172 int irq, error;
175 173
@@ -210,19 +208,11 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
210 goto err1; 208 goto err1;
211 } 209 }
212 210
213 snprintf(clk_name, sizeof(clk_name), "keysc%d", pdev->id);
214 priv->clk = clk_get(&pdev->dev, clk_name);
215 if (IS_ERR(priv->clk)) {
216 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
217 error = PTR_ERR(priv->clk);
218 goto err2;
219 }
220
221 priv->input = input_allocate_device(); 211 priv->input = input_allocate_device();
222 if (!priv->input) { 212 if (!priv->input) {
223 dev_err(&pdev->dev, "failed to allocate input device\n"); 213 dev_err(&pdev->dev, "failed to allocate input device\n");
224 error = -ENOMEM; 214 error = -ENOMEM;
225 goto err3; 215 goto err2;
226 } 216 }
227 217
228 input = priv->input; 218 input = priv->input;
@@ -241,10 +231,11 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
241 input->keycodesize = sizeof(pdata->keycodes[0]); 231 input->keycodesize = sizeof(pdata->keycodes[0]);
242 input->keycodemax = ARRAY_SIZE(pdata->keycodes); 232 input->keycodemax = ARRAY_SIZE(pdata->keycodes);
243 233
244 error = request_irq(irq, sh_keysc_isr, 0, pdev->name, pdev); 234 error = request_threaded_irq(irq, NULL, sh_keysc_isr, IRQF_ONESHOT,
235 dev_name(&pdev->dev), pdev);
245 if (error) { 236 if (error) {
246 dev_err(&pdev->dev, "failed to request IRQ\n"); 237 dev_err(&pdev->dev, "failed to request IRQ\n");
247 goto err4; 238 goto err3;
248 } 239 }
249 240
250 for (i = 0; i < SH_KEYSC_MAXKEYS; i++) 241 for (i = 0; i < SH_KEYSC_MAXKEYS; i++)
@@ -254,10 +245,11 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
254 error = input_register_device(input); 245 error = input_register_device(input);
255 if (error) { 246 if (error) {
256 dev_err(&pdev->dev, "failed to register input device\n"); 247 dev_err(&pdev->dev, "failed to register input device\n");
257 goto err5; 248 goto err4;
258 } 249 }
259 250
260 clk_enable(priv->clk); 251 pm_runtime_enable(&pdev->dev);
252 pm_runtime_get_sync(&pdev->dev);
261 253
262 sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) | 254 sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) |
263 pdata->scan_timing); 255 pdata->scan_timing);
@@ -267,12 +259,10 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
267 259
268 return 0; 260 return 0;
269 261
270 err5:
271 free_irq(irq, pdev);
272 err4: 262 err4:
273 input_free_device(input); 263 free_irq(irq, pdev);
274 err3: 264 err3:
275 clk_put(priv->clk); 265 input_free_device(input);
276 err2: 266 err2:
277 iounmap(priv->iomem_base); 267 iounmap(priv->iomem_base);
278 err1: 268 err1:
@@ -292,8 +282,8 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev)
292 free_irq(platform_get_irq(pdev, 0), pdev); 282 free_irq(platform_get_irq(pdev, 0), pdev);
293 iounmap(priv->iomem_base); 283 iounmap(priv->iomem_base);
294 284
295 clk_disable(priv->clk); 285 pm_runtime_put_sync(&pdev->dev);
296 clk_put(priv->clk); 286 pm_runtime_disable(&pdev->dev);
297 287
298 platform_set_drvdata(pdev, NULL); 288 platform_set_drvdata(pdev, NULL);
299 kfree(priv); 289 kfree(priv);
@@ -301,6 +291,7 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev)
301 return 0; 291 return 0;
302} 292}
303 293
294#if CONFIG_PM_SLEEP
304static int sh_keysc_suspend(struct device *dev) 295static int sh_keysc_suspend(struct device *dev)
305{ 296{
306 struct platform_device *pdev = to_platform_device(dev); 297 struct platform_device *pdev = to_platform_device(dev);
@@ -311,14 +302,13 @@ static int sh_keysc_suspend(struct device *dev)
311 value = sh_keysc_read(priv, KYCR1); 302 value = sh_keysc_read(priv, KYCR1);
312 303
313 if (device_may_wakeup(dev)) { 304 if (device_may_wakeup(dev)) {
314 value |= 0x80; 305 sh_keysc_write(priv, KYCR1, value | 0x80);
315 enable_irq_wake(irq); 306 enable_irq_wake(irq);
316 } else { 307 } else {
317 value &= ~0x80; 308 sh_keysc_write(priv, KYCR1, value & ~0x80);
309 pm_runtime_put_sync(dev);
318 } 310 }
319 311
320 sh_keysc_write(priv, KYCR1, value);
321
322 return 0; 312 return 0;
323} 313}
324 314
@@ -329,16 +319,17 @@ static int sh_keysc_resume(struct device *dev)
329 319
330 if (device_may_wakeup(dev)) 320 if (device_may_wakeup(dev))
331 disable_irq_wake(irq); 321 disable_irq_wake(irq);
322 else
323 pm_runtime_get_sync(dev);
332 324
333 return 0; 325 return 0;
334} 326}
327#endif
335 328
336static const struct dev_pm_ops sh_keysc_dev_pm_ops = { 329static SIMPLE_DEV_PM_OPS(sh_keysc_dev_pm_ops,
337 .suspend = sh_keysc_suspend, 330 sh_keysc_suspend, sh_keysc_resume);
338 .resume = sh_keysc_resume,
339};
340 331
341struct platform_driver sh_keysc_device_driver = { 332static struct platform_driver sh_keysc_device_driver = {
342 .probe = sh_keysc_probe, 333 .probe = sh_keysc_probe,
343 .remove = __devexit_p(sh_keysc_remove), 334 .remove = __devexit_p(sh_keysc_remove),
344 .driver = { 335 .driver = {
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
new file mode 100644
index 000000000000..d712dffd2157
--- /dev/null
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -0,0 +1,344 @@
1/*
2 * SPEAr Keyboard Driver
3 * Based on omap-keypad driver
4 *
5 * Copyright (C) 2010 ST Microelectronics
6 * Rajeev Kumar<rajeev-dlh.kumar@st.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/clk.h>
14#include <linux/errno.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/input.h>
18#include <linux/io.h>
19#include <linux/irq.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/pm_wakeup.h>
24#include <linux/slab.h>
25#include <linux/types.h>
26#include <plat/keyboard.h>
27
28/* Keyboard Registers */
29#define MODE_REG 0x00 /* 16 bit reg */
30#define STATUS_REG 0x0C /* 2 bit reg */
31#define DATA_REG 0x10 /* 8 bit reg */
32#define INTR_MASK 0x54
33
34/* Register Values */
35/*
36 * pclk freq mask = (APB FEQ -1)= 82 MHZ.Programme bit 15-9 in mode
37 * control register as 1010010(82MHZ)
38 */
39#define PCLK_FREQ_MSK 0xA400 /* 82 MHz */
40#define START_SCAN 0x0100
41#define SCAN_RATE_10 0x0000
42#define SCAN_RATE_20 0x0004
43#define SCAN_RATE_40 0x0008
44#define SCAN_RATE_80 0x000C
45#define MODE_KEYBOARD 0x0002
46#define DATA_AVAIL 0x2
47
48#define KEY_MASK 0xFF000000
49#define KEY_VALUE 0x00FFFFFF
50#define ROW_MASK 0xF0
51#define COLUMN_MASK 0x0F
52#define ROW_SHIFT 4
53
54struct spear_kbd {
55 struct input_dev *input;
56 struct resource *res;
57 void __iomem *io_base;
58 struct clk *clk;
59 unsigned int irq;
60 unsigned short last_key;
61 unsigned short keycodes[256];
62};
63
64static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
65{
66 struct spear_kbd *kbd = dev_id;
67 struct input_dev *input = kbd->input;
68 unsigned int key;
69 u8 sts, val;
70
71 sts = readb(kbd->io_base + STATUS_REG);
72 if (!(sts & DATA_AVAIL))
73 return IRQ_NONE;
74
75 if (kbd->last_key != KEY_RESERVED) {
76 input_report_key(input, kbd->last_key, 0);
77 kbd->last_key = KEY_RESERVED;
78 }
79
80 /* following reads active (row, col) pair */
81 val = readb(kbd->io_base + DATA_REG);
82 key = kbd->keycodes[val];
83
84 input_event(input, EV_MSC, MSC_SCAN, val);
85 input_report_key(input, key, 1);
86 input_sync(input);
87
88 kbd->last_key = key;
89
90 /* clear interrupt */
91 writeb(0, kbd->io_base + STATUS_REG);
92
93 return IRQ_HANDLED;
94}
95
96static int spear_kbd_open(struct input_dev *dev)
97{
98 struct spear_kbd *kbd = input_get_drvdata(dev);
99 int error;
100 u16 val;
101
102 kbd->last_key = KEY_RESERVED;
103
104 error = clk_enable(kbd->clk);
105 if (error)
106 return error;
107
108 /* program keyboard */
109 val = SCAN_RATE_80 | MODE_KEYBOARD | PCLK_FREQ_MSK;
110 writew(val, kbd->io_base + MODE_REG);
111 writeb(1, kbd->io_base + STATUS_REG);
112
113 /* start key scan */
114 val = readw(kbd->io_base + MODE_REG);
115 val |= START_SCAN;
116 writew(val, kbd->io_base + MODE_REG);
117
118 return 0;
119}
120
121static void spear_kbd_close(struct input_dev *dev)
122{
123 struct spear_kbd *kbd = input_get_drvdata(dev);
124 u16 val;
125
126 /* stop key scan */
127 val = readw(kbd->io_base + MODE_REG);
128 val &= ~START_SCAN;
129 writew(val, kbd->io_base + MODE_REG);
130
131 clk_disable(kbd->clk);
132
133 kbd->last_key = KEY_RESERVED;
134}
135
136static int __devinit spear_kbd_probe(struct platform_device *pdev)
137{
138 const struct kbd_platform_data *pdata = pdev->dev.platform_data;
139 const struct matrix_keymap_data *keymap;
140 struct spear_kbd *kbd;
141 struct input_dev *input_dev;
142 struct resource *res;
143 int irq;
144 int error;
145
146 if (!pdata) {
147 dev_err(&pdev->dev, "Invalid platform data\n");
148 return -EINVAL;
149 }
150
151 keymap = pdata->keymap;
152 if (!keymap) {
153 dev_err(&pdev->dev, "no keymap defined\n");
154 return -EINVAL;
155 }
156
157 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
158 if (!res) {
159 dev_err(&pdev->dev, "no keyboard resource defined\n");
160 return -EBUSY;
161 }
162
163 irq = platform_get_irq(pdev, 0);
164 if (irq < 0) {
165 dev_err(&pdev->dev, "not able to get irq for the device\n");
166 return irq;
167 }
168
169 kbd = kzalloc(sizeof(*kbd), GFP_KERNEL);
170 input_dev = input_allocate_device();
171 if (!kbd || !input_dev) {
172 dev_err(&pdev->dev, "out of memory\n");
173 error = -ENOMEM;
174 goto err_free_mem;
175 }
176
177 kbd->input = input_dev;
178 kbd->irq = irq;
179 kbd->res = request_mem_region(res->start, resource_size(res),
180 pdev->name);
181 if (!kbd->res) {
182 dev_err(&pdev->dev, "keyboard region already claimed\n");
183 error = -EBUSY;
184 goto err_free_mem;
185 }
186
187 kbd->io_base = ioremap(res->start, resource_size(res));
188 if (!kbd->io_base) {
189 dev_err(&pdev->dev, "ioremap failed for kbd_region\n");
190 error = -ENOMEM;
191 goto err_release_mem_region;
192 }
193
194 kbd->clk = clk_get(&pdev->dev, NULL);
195 if (IS_ERR(kbd->clk)) {
196 error = PTR_ERR(kbd->clk);
197 goto err_iounmap;
198 }
199
200 input_dev->name = "Spear Keyboard";
201 input_dev->phys = "keyboard/input0";
202 input_dev->dev.parent = &pdev->dev;
203 input_dev->id.bustype = BUS_HOST;
204 input_dev->id.vendor = 0x0001;
205 input_dev->id.product = 0x0001;
206 input_dev->id.version = 0x0100;
207 input_dev->open = spear_kbd_open;
208 input_dev->close = spear_kbd_close;
209
210 __set_bit(EV_KEY, input_dev->evbit);
211 if (pdata->rep)
212 __set_bit(EV_REP, input_dev->evbit);
213 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
214
215 input_dev->keycode = kbd->keycodes;
216 input_dev->keycodesize = sizeof(kbd->keycodes[0]);
217 input_dev->keycodemax = ARRAY_SIZE(kbd->keycodes);
218
219 matrix_keypad_build_keymap(keymap, ROW_SHIFT,
220 input_dev->keycode, input_dev->keybit);
221
222 input_set_drvdata(input_dev, kbd);
223
224 error = request_irq(irq, spear_kbd_interrupt, 0, "keyboard", kbd);
225 if (error) {
226 dev_err(&pdev->dev, "request_irq fail\n");
227 goto err_put_clk;
228 }
229
230 error = input_register_device(input_dev);
231 if (error) {
232 dev_err(&pdev->dev, "Unable to register keyboard device\n");
233 goto err_free_irq;
234 }
235
236 device_init_wakeup(&pdev->dev, 1);
237 platform_set_drvdata(pdev, kbd);
238
239 return 0;
240
241err_free_irq:
242 free_irq(kbd->irq, kbd);
243err_put_clk:
244 clk_put(kbd->clk);
245err_iounmap:
246 iounmap(kbd->io_base);
247err_release_mem_region:
248 release_mem_region(res->start, resource_size(res));
249err_free_mem:
250 input_free_device(input_dev);
251 kfree(kbd);
252
253 return error;
254}
255
256static int __devexit spear_kbd_remove(struct platform_device *pdev)
257{
258 struct spear_kbd *kbd = platform_get_drvdata(pdev);
259
260 free_irq(kbd->irq, kbd);
261 input_unregister_device(kbd->input);
262 clk_put(kbd->clk);
263 iounmap(kbd->io_base);
264 release_mem_region(kbd->res->start, resource_size(kbd->res));
265 kfree(kbd);
266
267 device_init_wakeup(&pdev->dev, 1);
268 platform_set_drvdata(pdev, NULL);
269
270 return 0;
271}
272
273#ifdef CONFIG_PM
274static int spear_kbd_suspend(struct device *dev)
275{
276 struct platform_device *pdev = to_platform_device(dev);
277 struct spear_kbd *kbd = platform_get_drvdata(pdev);
278 struct input_dev *input_dev = kbd->input;
279
280 mutex_lock(&input_dev->mutex);
281
282 if (input_dev->users)
283 clk_enable(kbd->clk);
284
285 if (device_may_wakeup(&pdev->dev))
286 enable_irq_wake(kbd->irq);
287
288 mutex_unlock(&input_dev->mutex);
289
290 return 0;
291}
292
293static int spear_kbd_resume(struct device *dev)
294{
295 struct platform_device *pdev = to_platform_device(dev);
296 struct spear_kbd *kbd = platform_get_drvdata(pdev);
297 struct input_dev *input_dev = kbd->input;
298
299 mutex_lock(&input_dev->mutex);
300
301 if (device_may_wakeup(&pdev->dev))
302 disable_irq_wake(kbd->irq);
303
304 if (input_dev->users)
305 clk_enable(kbd->clk);
306
307 mutex_unlock(&input_dev->mutex);
308
309 return 0;
310}
311
312static const struct dev_pm_ops spear_kbd_pm_ops = {
313 .suspend = spear_kbd_suspend,
314 .resume = spear_kbd_resume,
315};
316#endif
317
318static struct platform_driver spear_kbd_driver = {
319 .probe = spear_kbd_probe,
320 .remove = __devexit_p(spear_kbd_remove),
321 .driver = {
322 .name = "keyboard",
323 .owner = THIS_MODULE,
324#ifdef CONFIG_PM
325 .pm = &spear_kbd_pm_ops,
326#endif
327 },
328};
329
330static int __init spear_kbd_init(void)
331{
332 return platform_driver_register(&spear_kbd_driver);
333}
334module_init(spear_kbd_init);
335
336static void __exit spear_kbd_exit(void)
337{
338 platform_driver_unregister(&spear_kbd_driver);
339}
340module_exit(spear_kbd_exit);
341
342MODULE_AUTHOR("Rajeev Kumar");
343MODULE_DESCRIPTION("SPEAr Keyboard Driver");
344MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c
new file mode 100644
index 000000000000..99122f59e988
--- /dev/null
+++ b/drivers/input/keyboard/tc3589x-keypad.c
@@ -0,0 +1,472 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Jayeeta Banerjee <jayeeta.banerjee@stericsson.com>
5 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
6 *
7 * License Terms: GNU General Public License, version 2
8 *
9 * TC35893 MFD Keypad Controller driver
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/interrupt.h>
15#include <linux/input.h>
16#include <linux/platform_device.h>
17#include <linux/input/matrix_keypad.h>
18#include <linux/i2c.h>
19#include <linux/slab.h>
20#include <linux/mfd/tc3589x.h>
21
22/* Maximum supported keypad matrix row/columns size */
23#define TC3589x_MAX_KPROW 8
24#define TC3589x_MAX_KPCOL 12
25
26/* keypad related Constants */
27#define TC3589x_MAX_DEBOUNCE_SETTLE 0xFF
28#define DEDICATED_KEY_VAL 0xFF
29
30/* Pull up/down masks */
31#define TC3589x_NO_PULL_MASK 0x0
32#define TC3589x_PULL_DOWN_MASK 0x1
33#define TC3589x_PULL_UP_MASK 0x2
34#define TC3589x_PULLUP_ALL_MASK 0xAA
35#define TC3589x_IO_PULL_VAL(index, mask) ((mask)<<((index)%4)*2))
36
37/* Bit masks for IOCFG register */
38#define IOCFG_BALLCFG 0x01
39#define IOCFG_IG 0x08
40
41#define KP_EVCODE_COL_MASK 0x0F
42#define KP_EVCODE_ROW_MASK 0x70
43#define KP_RELEASE_EVT_MASK 0x80
44
45#define KP_ROW_SHIFT 4
46
47#define KP_NO_VALID_KEY_MASK 0x7F
48
49/* bit masks for RESTCTRL register */
50#define TC3589x_KBDRST 0x2
51#define TC3589x_IRQRST 0x10
52#define TC3589x_RESET_ALL 0x1B
53
54/* KBDMFS register bit mask */
55#define TC3589x_KBDMFS_EN 0x1
56
57/* CLKEN register bitmask */
58#define KPD_CLK_EN 0x1
59
60/* RSTINTCLR register bit mask */
61#define IRQ_CLEAR 0x1
62
63/* bit masks for keyboard interrupts*/
64#define TC3589x_EVT_LOSS_INT 0x8
65#define TC3589x_EVT_INT 0x4
66#define TC3589x_KBD_LOSS_INT 0x2
67#define TC3589x_KBD_INT 0x1
68
69/* bit masks for keyboard interrupt clear*/
70#define TC3589x_EVT_INT_CLR 0x2
71#define TC3589x_KBD_INT_CLR 0x1
72
73#define TC3589x_KBD_KEYMAP_SIZE 64
74
75/**
76 * struct tc_keypad - data structure used by keypad driver
77 * @input: pointer to input device object
78 * @board: keypad platform device
79 * @krow: number of rows
80 * @kcol: number of coloumns
81 * @keymap: matrix scan code table for keycodes
82 */
83struct tc_keypad {
84 struct tc3589x *tc3589x;
85 struct input_dev *input;
86 const struct tc3589x_keypad_platform_data *board;
87 unsigned int krow;
88 unsigned int kcol;
89 unsigned short keymap[TC3589x_KBD_KEYMAP_SIZE];
90 bool keypad_stopped;
91};
92
93static int __devinit tc3589x_keypad_init_key_hardware(struct tc_keypad *keypad)
94{
95 int ret;
96 struct tc3589x *tc3589x = keypad->tc3589x;
97 u8 settle_time = keypad->board->settle_time;
98 u8 dbounce_period = keypad->board->debounce_period;
99 u8 rows = keypad->board->krow & 0xf; /* mask out the nibble */
100 u8 column = keypad->board->kcol & 0xf; /* mask out the nibble */
101
102 /* validate platform configurations */
103 if (keypad->board->kcol > TC3589x_MAX_KPCOL ||
104 keypad->board->krow > TC3589x_MAX_KPROW ||
105 keypad->board->debounce_period > TC3589x_MAX_DEBOUNCE_SETTLE ||
106 keypad->board->settle_time > TC3589x_MAX_DEBOUNCE_SETTLE)
107 return -EINVAL;
108
109 /* configure KBDSIZE 4 LSbits for cols and 4 MSbits for rows */
110 ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSIZE,
111 (rows << KP_ROW_SHIFT) | column);
112 if (ret < 0)
113 return ret;
114
115 /* configure dedicated key config, no dedicated key selected */
116 ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_LSB, DEDICATED_KEY_VAL);
117 if (ret < 0)
118 return ret;
119
120 ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_MSB, DEDICATED_KEY_VAL);
121 if (ret < 0)
122 return ret;
123
124 /* Configure settle time */
125 ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSETTLE_REG, settle_time);
126 if (ret < 0)
127 return ret;
128
129 /* Configure debounce time */
130 ret = tc3589x_reg_write(tc3589x, TC3589x_KBDBOUNCE, dbounce_period);
131 if (ret < 0)
132 return ret;
133
134 /* Start of initialise keypad GPIOs */
135 ret = tc3589x_set_bits(tc3589x, TC3589x_IOCFG, 0x0, IOCFG_IG);
136 if (ret < 0)
137 return ret;
138
139 /* Configure pull-up resistors for all row GPIOs */
140 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_LSB,
141 TC3589x_PULLUP_ALL_MASK);
142 if (ret < 0)
143 return ret;
144
145 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_MSB,
146 TC3589x_PULLUP_ALL_MASK);
147 if (ret < 0)
148 return ret;
149
150 /* Configure pull-up resistors for all column GPIOs */
151 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_LSB,
152 TC3589x_PULLUP_ALL_MASK);
153 if (ret < 0)
154 return ret;
155
156 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_MSB,
157 TC3589x_PULLUP_ALL_MASK);
158 if (ret < 0)
159 return ret;
160
161 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG2_LSB,
162 TC3589x_PULLUP_ALL_MASK);
163
164 return ret;
165}
166
167#define TC35893_DATA_REGS 4
168#define TC35893_KEYCODE_FIFO_EMPTY 0x7f
169#define TC35893_KEYCODE_FIFO_CLEAR 0xff
170#define TC35893_KEYPAD_ROW_SHIFT 0x3
171
172static irqreturn_t tc3589x_keypad_irq(int irq, void *dev)
173{
174 struct tc_keypad *keypad = dev;
175 struct tc3589x *tc3589x = keypad->tc3589x;
176 u8 i, row_index, col_index, kbd_code, up;
177 u8 code;
178
179 for (i = 0; i < TC35893_DATA_REGS * 2; i++) {
180 kbd_code = tc3589x_reg_read(tc3589x, TC3589x_EVTCODE_FIFO);
181
182 /* loop till fifo is empty and no more keys are pressed */
183 if (kbd_code == TC35893_KEYCODE_FIFO_EMPTY ||
184 kbd_code == TC35893_KEYCODE_FIFO_CLEAR)
185 continue;
186
187 /* valid key is found */
188 col_index = kbd_code & KP_EVCODE_COL_MASK;
189 row_index = (kbd_code & KP_EVCODE_ROW_MASK) >> KP_ROW_SHIFT;
190 code = MATRIX_SCAN_CODE(row_index, col_index,
191 TC35893_KEYPAD_ROW_SHIFT);
192 up = kbd_code & KP_RELEASE_EVT_MASK;
193
194 input_event(keypad->input, EV_MSC, MSC_SCAN, code);
195 input_report_key(keypad->input, keypad->keymap[code], !up);
196 input_sync(keypad->input);
197 }
198
199 /* clear IRQ */
200 tc3589x_set_bits(tc3589x, TC3589x_KBDIC,
201 0x0, TC3589x_EVT_INT_CLR | TC3589x_KBD_INT_CLR);
202 /* enable IRQ */
203 tc3589x_set_bits(tc3589x, TC3589x_KBDMSK,
204 0x0, TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT);
205
206 return IRQ_HANDLED;
207}
208
209static int tc3589x_keypad_enable(struct tc_keypad *keypad)
210{
211 struct tc3589x *tc3589x = keypad->tc3589x;
212 int ret;
213
214 /* pull the keypad module out of reset */
215 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, TC3589x_KBDRST, 0x0);
216 if (ret < 0)
217 return ret;
218
219 /* configure KBDMFS */
220 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMFS, 0x0, TC3589x_KBDMFS_EN);
221 if (ret < 0)
222 return ret;
223
224 /* enable the keypad clock */
225 ret = tc3589x_set_bits(tc3589x, TC3589x_CLKEN, 0x0, KPD_CLK_EN);
226 if (ret < 0)
227 return ret;
228
229 /* clear pending IRQs */
230 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTINTCLR, 0x0, 0x1);
231 if (ret < 0)
232 return ret;
233
234 /* enable the IRQs */
235 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMSK, 0x0,
236 TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT);
237 if (ret < 0)
238 return ret;
239
240 keypad->keypad_stopped = false;
241
242 return ret;
243}
244
245static int tc3589x_keypad_disable(struct tc_keypad *keypad)
246{
247 struct tc3589x *tc3589x = keypad->tc3589x;
248 int ret;
249
250 /* clear IRQ */
251 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDIC,
252 0x0, TC3589x_EVT_INT_CLR | TC3589x_KBD_INT_CLR);
253 if (ret < 0)
254 return ret;
255
256 /* disable all interrupts */
257 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMSK,
258 ~(TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT), 0x0);
259 if (ret < 0)
260 return ret;
261
262 /* disable the keypad module */
263 ret = tc3589x_set_bits(tc3589x, TC3589x_CLKEN, 0x1, 0x0);
264 if (ret < 0)
265 return ret;
266
267 /* put the keypad module into reset */
268 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, TC3589x_KBDRST, 0x1);
269
270 keypad->keypad_stopped = true;
271
272 return ret;
273}
274
275static int tc3589x_keypad_open(struct input_dev *input)
276{
277 int error;
278 struct tc_keypad *keypad = input_get_drvdata(input);
279
280 /* enable the keypad module */
281 error = tc3589x_keypad_enable(keypad);
282 if (error < 0) {
283 dev_err(&input->dev, "failed to enable keypad module\n");
284 return error;
285 }
286
287 error = tc3589x_keypad_init_key_hardware(keypad);
288 if (error < 0) {
289 dev_err(&input->dev, "failed to configure keypad module\n");
290 return error;
291 }
292
293 return 0;
294}
295
296static void tc3589x_keypad_close(struct input_dev *input)
297{
298 struct tc_keypad *keypad = input_get_drvdata(input);
299
300 /* disable the keypad module */
301 tc3589x_keypad_disable(keypad);
302}
303
304static int __devinit tc3589x_keypad_probe(struct platform_device *pdev)
305{
306 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
307 struct tc_keypad *keypad;
308 struct input_dev *input;
309 const struct tc3589x_keypad_platform_data *plat;
310 int error, irq;
311
312 plat = tc3589x->pdata->keypad;
313 if (!plat) {
314 dev_err(&pdev->dev, "invalid keypad platform data\n");
315 return -EINVAL;
316 }
317
318 irq = platform_get_irq(pdev, 0);
319 if (irq < 0)
320 return irq;
321
322 keypad = kzalloc(sizeof(struct tc_keypad), GFP_KERNEL);
323 input = input_allocate_device();
324 if (!keypad || !input) {
325 dev_err(&pdev->dev, "failed to allocate keypad memory\n");
326 error = -ENOMEM;
327 goto err_free_mem;
328 }
329
330 keypad->board = plat;
331 keypad->input = input;
332 keypad->tc3589x = tc3589x;
333
334 input->id.bustype = BUS_I2C;
335 input->name = pdev->name;
336 input->dev.parent = &pdev->dev;
337
338 input->keycode = keypad->keymap;
339 input->keycodesize = sizeof(keypad->keymap[0]);
340 input->keycodemax = ARRAY_SIZE(keypad->keymap);
341
342 input->open = tc3589x_keypad_open;
343 input->close = tc3589x_keypad_close;
344
345 input_set_drvdata(input, keypad);
346
347 input_set_capability(input, EV_MSC, MSC_SCAN);
348
349 __set_bit(EV_KEY, input->evbit);
350 if (!plat->no_autorepeat)
351 __set_bit(EV_REP, input->evbit);
352
353 matrix_keypad_build_keymap(plat->keymap_data, 0x3,
354 input->keycode, input->keybit);
355
356 error = request_threaded_irq(irq, NULL,
357 tc3589x_keypad_irq, plat->irqtype,
358 "tc3589x-keypad", keypad);
359 if (error < 0) {
360 dev_err(&pdev->dev,
361 "Could not allocate irq %d,error %d\n",
362 irq, error);
363 goto err_free_mem;
364 }
365
366 error = input_register_device(input);
367 if (error) {
368 dev_err(&pdev->dev, "Could not register input device\n");
369 goto err_free_irq;
370 }
371
372 /* let platform decide if keypad is a wakeup source or not */
373 device_init_wakeup(&pdev->dev, plat->enable_wakeup);
374 device_set_wakeup_capable(&pdev->dev, plat->enable_wakeup);
375
376 platform_set_drvdata(pdev, keypad);
377
378 return 0;
379
380err_free_irq:
381 free_irq(irq, keypad);
382err_free_mem:
383 input_free_device(input);
384 kfree(keypad);
385 return error;
386}
387
388static int __devexit tc3589x_keypad_remove(struct platform_device *pdev)
389{
390 struct tc_keypad *keypad = platform_get_drvdata(pdev);
391 int irq = platform_get_irq(pdev, 0);
392
393 if (!keypad->keypad_stopped)
394 tc3589x_keypad_disable(keypad);
395
396 free_irq(irq, keypad);
397
398 input_unregister_device(keypad->input);
399
400 kfree(keypad);
401
402 return 0;
403}
404
405#ifdef CONFIG_PM_SLEEP
406static int tc3589x_keypad_suspend(struct device *dev)
407{
408 struct platform_device *pdev = to_platform_device(dev);
409 struct tc_keypad *keypad = platform_get_drvdata(pdev);
410 int irq = platform_get_irq(pdev, 0);
411
412 /* keypad is already off; we do nothing */
413 if (keypad->keypad_stopped)
414 return 0;
415
416 /* if device is not a wakeup source, disable it for powersave */
417 if (!device_may_wakeup(&pdev->dev))
418 tc3589x_keypad_disable(keypad);
419 else
420 enable_irq_wake(irq);
421
422 return 0;
423}
424
425static int tc3589x_keypad_resume(struct device *dev)
426{
427 struct platform_device *pdev = to_platform_device(dev);
428 struct tc_keypad *keypad = platform_get_drvdata(pdev);
429 int irq = platform_get_irq(pdev, 0);
430
431 if (!keypad->keypad_stopped)
432 return 0;
433
434 /* enable the device to resume normal operations */
435 if (!device_may_wakeup(&pdev->dev))
436 tc3589x_keypad_enable(keypad);
437 else
438 disable_irq_wake(irq);
439
440 return 0;
441}
442#endif
443
444static SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops,
445 tc3589x_keypad_suspend, tc3589x_keypad_resume);
446
447static struct platform_driver tc3589x_keypad_driver = {
448 .driver = {
449 .name = "tc3589x-keypad",
450 .owner = THIS_MODULE,
451 .pm = &tc3589x_keypad_dev_pm_ops,
452 },
453 .probe = tc3589x_keypad_probe,
454 .remove = __devexit_p(tc3589x_keypad_remove),
455};
456
457static int __init tc3589x_keypad_init(void)
458{
459 return platform_driver_register(&tc3589x_keypad_driver);
460}
461module_init(tc3589x_keypad_init);
462
463static void __exit tc3589x_keypad_exit(void)
464{
465 return platform_driver_unregister(&tc3589x_keypad_driver);
466}
467module_exit(tc3589x_keypad_exit);
468
469MODULE_LICENSE("GPL v2");
470MODULE_AUTHOR("Jayeeta Banerjee/Sundar Iyer");
471MODULE_DESCRIPTION("TC35893 Keypad Driver");
472MODULE_ALIAS("platform:tc3589x-keypad");
diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c
index 00137bebcf97..3afea3f89718 100644
--- a/drivers/input/keyboard/tca6416-keypad.c
+++ b/drivers/input/keyboard/tca6416-keypad.c
@@ -29,6 +29,7 @@
29 29
30static const struct i2c_device_id tca6416_id[] = { 30static const struct i2c_device_id tca6416_id[] = {
31 { "tca6416-keys", 16, }, 31 { "tca6416-keys", 16, },
32 { "tca6408-keys", 8, },
32 { } 33 { }
33}; 34};
34MODULE_DEVICE_TABLE(i2c, tca6416_id); 35MODULE_DEVICE_TABLE(i2c, tca6416_id);
@@ -46,8 +47,9 @@ struct tca6416_keypad_chip {
46 struct i2c_client *client; 47 struct i2c_client *client;
47 struct input_dev *input; 48 struct input_dev *input;
48 struct delayed_work dwork; 49 struct delayed_work dwork;
49 u16 pinmask; 50 int io_size;
50 int irqnum; 51 int irqnum;
52 u16 pinmask;
51 bool use_polling; 53 bool use_polling;
52 struct tca6416_button buttons[0]; 54 struct tca6416_button buttons[0];
53}; 55};
@@ -56,7 +58,9 @@ static int tca6416_write_reg(struct tca6416_keypad_chip *chip, int reg, u16 val)
56{ 58{
57 int error; 59 int error;
58 60
59 error = i2c_smbus_write_word_data(chip->client, reg << 1, val); 61 error = chip->io_size > 8 ?
62 i2c_smbus_write_word_data(chip->client, reg << 1, val) :
63 i2c_smbus_write_byte_data(chip->client, reg, val);
60 if (error < 0) { 64 if (error < 0) {
61 dev_err(&chip->client->dev, 65 dev_err(&chip->client->dev,
62 "%s failed, reg: %d, val: %d, error: %d\n", 66 "%s failed, reg: %d, val: %d, error: %d\n",
@@ -71,7 +75,9 @@ static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val)
71{ 75{
72 int retval; 76 int retval;
73 77
74 retval = i2c_smbus_read_word_data(chip->client, reg << 1); 78 retval = chip->io_size > 8 ?
79 i2c_smbus_read_word_data(chip->client, reg << 1) :
80 i2c_smbus_read_byte_data(chip->client, reg);
75 if (retval < 0) { 81 if (retval < 0) {
76 dev_err(&chip->client->dev, "%s failed, reg: %d, error: %d\n", 82 dev_err(&chip->client->dev, "%s failed, reg: %d, error: %d\n",
77 __func__, reg, retval); 83 __func__, reg, retval);
@@ -224,6 +230,7 @@ static int __devinit tca6416_keypad_probe(struct i2c_client *client,
224 230
225 chip->client = client; 231 chip->client = client;
226 chip->input = input; 232 chip->input = input;
233 chip->io_size = id->driver_data;
227 chip->pinmask = pdata->pinmask; 234 chip->pinmask = pdata->pinmask;
228 chip->use_polling = pdata->use_polling; 235 chip->use_polling = pdata->use_polling;
229 236
@@ -290,6 +297,7 @@ static int __devinit tca6416_keypad_probe(struct i2c_client *client,
290 } 297 }
291 298
292 i2c_set_clientdata(client, chip); 299 i2c_set_clientdata(client, chip);
300 device_init_wakeup(&client->dev, 1);
293 301
294 return 0; 302 return 0;
295 303
@@ -319,10 +327,37 @@ static int __devexit tca6416_keypad_remove(struct i2c_client *client)
319 return 0; 327 return 0;
320} 328}
321 329
330#ifdef CONFIG_PM_SLEEP
331static int tca6416_keypad_suspend(struct device *dev)
332{
333 struct i2c_client *client = to_i2c_client(dev);
334 struct tca6416_keypad_chip *chip = i2c_get_clientdata(client);
335
336 if (device_may_wakeup(dev))
337 enable_irq_wake(chip->irqnum);
338
339 return 0;
340}
341
342static int tca6416_keypad_resume(struct device *dev)
343{
344 struct i2c_client *client = to_i2c_client(dev);
345 struct tca6416_keypad_chip *chip = i2c_get_clientdata(client);
346
347 if (device_may_wakeup(dev))
348 disable_irq_wake(chip->irqnum);
349
350 return 0;
351}
352#endif
353
354static SIMPLE_DEV_PM_OPS(tca6416_keypad_dev_pm_ops,
355 tca6416_keypad_suspend, tca6416_keypad_resume);
322 356
323static struct i2c_driver tca6416_keypad_driver = { 357static struct i2c_driver tca6416_keypad_driver = {
324 .driver = { 358 .driver = {
325 .name = "tca6416-keypad", 359 .name = "tca6416-keypad",
360 .pm = &tca6416_keypad_dev_pm_ops,
326 }, 361 },
327 .probe = tca6416_keypad_probe, 362 .probe = tca6416_keypad_probe,
328 .remove = __devexit_p(tca6416_keypad_remove), 363 .remove = __devexit_p(tca6416_keypad_remove),
diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
new file mode 100644
index 000000000000..2b3b73ec6689
--- /dev/null
+++ b/drivers/input/keyboard/tegra-kbc.c
@@ -0,0 +1,799 @@
1/*
2 * Keyboard class input driver for the NVIDIA Tegra SoC internal matrix
3 * keyboard controller
4 *
5 * Copyright (c) 2009-2011, NVIDIA Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/input.h>
24#include <linux/platform_device.h>
25#include <linux/delay.h>
26#include <linux/io.h>
27#include <linux/interrupt.h>
28#include <linux/clk.h>
29#include <linux/slab.h>
30#include <mach/clk.h>
31#include <mach/kbc.h>
32
33#define KBC_MAX_DEBOUNCE_CNT 0x3ffu
34
35/* KBC row scan time and delay for beginning the row scan. */
36#define KBC_ROW_SCAN_TIME 16
37#define KBC_ROW_SCAN_DLY 5
38
39/* KBC uses a 32KHz clock so a cycle = 1/32Khz */
40#define KBC_CYCLE_USEC 32
41
42/* KBC Registers */
43
44/* KBC Control Register */
45#define KBC_CONTROL_0 0x0
46#define KBC_FIFO_TH_CNT_SHIFT(cnt) (cnt << 14)
47#define KBC_DEBOUNCE_CNT_SHIFT(cnt) (cnt << 4)
48#define KBC_CONTROL_FIFO_CNT_INT_EN (1 << 3)
49#define KBC_CONTROL_KBC_EN (1 << 0)
50
51/* KBC Interrupt Register */
52#define KBC_INT_0 0x4
53#define KBC_INT_FIFO_CNT_INT_STATUS (1 << 2)
54
55#define KBC_ROW_CFG0_0 0x8
56#define KBC_COL_CFG0_0 0x18
57#define KBC_INIT_DLY_0 0x28
58#define KBC_RPT_DLY_0 0x2c
59#define KBC_KP_ENT0_0 0x30
60#define KBC_KP_ENT1_0 0x34
61#define KBC_ROW0_MASK_0 0x38
62
63#define KBC_ROW_SHIFT 3
64
65struct tegra_kbc {
66 void __iomem *mmio;
67 struct input_dev *idev;
68 unsigned int irq;
69 spinlock_t lock;
70 unsigned int repoll_dly;
71 unsigned long cp_dly_jiffies;
72 bool use_fn_map;
73 bool use_ghost_filter;
74 const struct tegra_kbc_platform_data *pdata;
75 unsigned short keycode[KBC_MAX_KEY * 2];
76 unsigned short current_keys[KBC_MAX_KPENT];
77 unsigned int num_pressed_keys;
78 struct timer_list timer;
79 struct clk *clk;
80};
81
82static const u32 tegra_kbc_default_keymap[] = {
83 KEY(0, 2, KEY_W),
84 KEY(0, 3, KEY_S),
85 KEY(0, 4, KEY_A),
86 KEY(0, 5, KEY_Z),
87 KEY(0, 7, KEY_FN),
88
89 KEY(1, 7, KEY_LEFTMETA),
90
91 KEY(2, 6, KEY_RIGHTALT),
92 KEY(2, 7, KEY_LEFTALT),
93
94 KEY(3, 0, KEY_5),
95 KEY(3, 1, KEY_4),
96 KEY(3, 2, KEY_R),
97 KEY(3, 3, KEY_E),
98 KEY(3, 4, KEY_F),
99 KEY(3, 5, KEY_D),
100 KEY(3, 6, KEY_X),
101
102 KEY(4, 0, KEY_7),
103 KEY(4, 1, KEY_6),
104 KEY(4, 2, KEY_T),
105 KEY(4, 3, KEY_H),
106 KEY(4, 4, KEY_G),
107 KEY(4, 5, KEY_V),
108 KEY(4, 6, KEY_C),
109 KEY(4, 7, KEY_SPACE),
110
111 KEY(5, 0, KEY_9),
112 KEY(5, 1, KEY_8),
113 KEY(5, 2, KEY_U),
114 KEY(5, 3, KEY_Y),
115 KEY(5, 4, KEY_J),
116 KEY(5, 5, KEY_N),
117 KEY(5, 6, KEY_B),
118 KEY(5, 7, KEY_BACKSLASH),
119
120 KEY(6, 0, KEY_MINUS),
121 KEY(6, 1, KEY_0),
122 KEY(6, 2, KEY_O),
123 KEY(6, 3, KEY_I),
124 KEY(6, 4, KEY_L),
125 KEY(6, 5, KEY_K),
126 KEY(6, 6, KEY_COMMA),
127 KEY(6, 7, KEY_M),
128
129 KEY(7, 1, KEY_EQUAL),
130 KEY(7, 2, KEY_RIGHTBRACE),
131 KEY(7, 3, KEY_ENTER),
132 KEY(7, 7, KEY_MENU),
133
134 KEY(8, 4, KEY_RIGHTSHIFT),
135 KEY(8, 5, KEY_LEFTSHIFT),
136
137 KEY(9, 5, KEY_RIGHTCTRL),
138 KEY(9, 7, KEY_LEFTCTRL),
139
140 KEY(11, 0, KEY_LEFTBRACE),
141 KEY(11, 1, KEY_P),
142 KEY(11, 2, KEY_APOSTROPHE),
143 KEY(11, 3, KEY_SEMICOLON),
144 KEY(11, 4, KEY_SLASH),
145 KEY(11, 5, KEY_DOT),
146
147 KEY(12, 0, KEY_F10),
148 KEY(12, 1, KEY_F9),
149 KEY(12, 2, KEY_BACKSPACE),
150 KEY(12, 3, KEY_3),
151 KEY(12, 4, KEY_2),
152 KEY(12, 5, KEY_UP),
153 KEY(12, 6, KEY_PRINT),
154 KEY(12, 7, KEY_PAUSE),
155
156 KEY(13, 0, KEY_INSERT),
157 KEY(13, 1, KEY_DELETE),
158 KEY(13, 3, KEY_PAGEUP),
159 KEY(13, 4, KEY_PAGEDOWN),
160 KEY(13, 5, KEY_RIGHT),
161 KEY(13, 6, KEY_DOWN),
162 KEY(13, 7, KEY_LEFT),
163
164 KEY(14, 0, KEY_F11),
165 KEY(14, 1, KEY_F12),
166 KEY(14, 2, KEY_F8),
167 KEY(14, 3, KEY_Q),
168 KEY(14, 4, KEY_F4),
169 KEY(14, 5, KEY_F3),
170 KEY(14, 6, KEY_1),
171 KEY(14, 7, KEY_F7),
172
173 KEY(15, 0, KEY_ESC),
174 KEY(15, 1, KEY_GRAVE),
175 KEY(15, 2, KEY_F5),
176 KEY(15, 3, KEY_TAB),
177 KEY(15, 4, KEY_F1),
178 KEY(15, 5, KEY_F2),
179 KEY(15, 6, KEY_CAPSLOCK),
180 KEY(15, 7, KEY_F6),
181
182 /* Software Handled Function Keys */
183 KEY(20, 0, KEY_KP7),
184
185 KEY(21, 0, KEY_KP9),
186 KEY(21, 1, KEY_KP8),
187 KEY(21, 2, KEY_KP4),
188 KEY(21, 4, KEY_KP1),
189
190 KEY(22, 1, KEY_KPSLASH),
191 KEY(22, 2, KEY_KP6),
192 KEY(22, 3, KEY_KP5),
193 KEY(22, 4, KEY_KP3),
194 KEY(22, 5, KEY_KP2),
195 KEY(22, 7, KEY_KP0),
196
197 KEY(27, 1, KEY_KPASTERISK),
198 KEY(27, 3, KEY_KPMINUS),
199 KEY(27, 4, KEY_KPPLUS),
200 KEY(27, 5, KEY_KPDOT),
201
202 KEY(28, 5, KEY_VOLUMEUP),
203
204 KEY(29, 3, KEY_HOME),
205 KEY(29, 4, KEY_END),
206 KEY(29, 5, KEY_BRIGHTNESSDOWN),
207 KEY(29, 6, KEY_VOLUMEDOWN),
208 KEY(29, 7, KEY_BRIGHTNESSUP),
209
210 KEY(30, 0, KEY_NUMLOCK),
211 KEY(30, 1, KEY_SCROLLLOCK),
212 KEY(30, 2, KEY_MUTE),
213
214 KEY(31, 4, KEY_HELP),
215};
216
217static const struct matrix_keymap_data tegra_kbc_default_keymap_data = {
218 .keymap = tegra_kbc_default_keymap,
219 .keymap_size = ARRAY_SIZE(tegra_kbc_default_keymap),
220};
221
222static void tegra_kbc_report_released_keys(struct input_dev *input,
223 unsigned short old_keycodes[],
224 unsigned int old_num_keys,
225 unsigned short new_keycodes[],
226 unsigned int new_num_keys)
227{
228 unsigned int i, j;
229
230 for (i = 0; i < old_num_keys; i++) {
231 for (j = 0; j < new_num_keys; j++)
232 if (old_keycodes[i] == new_keycodes[j])
233 break;
234
235 if (j == new_num_keys)
236 input_report_key(input, old_keycodes[i], 0);
237 }
238}
239
240static void tegra_kbc_report_pressed_keys(struct input_dev *input,
241 unsigned char scancodes[],
242 unsigned short keycodes[],
243 unsigned int num_pressed_keys)
244{
245 unsigned int i;
246
247 for (i = 0; i < num_pressed_keys; i++) {
248 input_event(input, EV_MSC, MSC_SCAN, scancodes[i]);
249 input_report_key(input, keycodes[i], 1);
250 }
251}
252
253static void tegra_kbc_report_keys(struct tegra_kbc *kbc)
254{
255 unsigned char scancodes[KBC_MAX_KPENT];
256 unsigned short keycodes[KBC_MAX_KPENT];
257 u32 val = 0;
258 unsigned int i;
259 unsigned int num_down = 0;
260 unsigned long flags;
261 bool fn_keypress = false;
262 bool key_in_same_row = false;
263 bool key_in_same_col = false;
264
265 spin_lock_irqsave(&kbc->lock, flags);
266 for (i = 0; i < KBC_MAX_KPENT; i++) {
267 if ((i % 4) == 0)
268 val = readl(kbc->mmio + KBC_KP_ENT0_0 + i);
269
270 if (val & 0x80) {
271 unsigned int col = val & 0x07;
272 unsigned int row = (val >> 3) & 0x0f;
273 unsigned char scancode =
274 MATRIX_SCAN_CODE(row, col, KBC_ROW_SHIFT);
275
276 scancodes[num_down] = scancode;
277 keycodes[num_down] = kbc->keycode[scancode];
278 /* If driver uses Fn map, do not report the Fn key. */
279 if ((keycodes[num_down] == KEY_FN) && kbc->use_fn_map)
280 fn_keypress = true;
281 else
282 num_down++;
283 }
284
285 val >>= 8;
286 }
287
288 /*
289 * Matrix keyboard designs are prone to keyboard ghosting.
290 * Ghosting occurs if there are 3 keys such that -
291 * any 2 of the 3 keys share a row, and any 2 of them share a column.
292 * If so ignore the key presses for this iteration.
293 */
294 if ((kbc->use_ghost_filter) && (num_down >= 3)) {
295 for (i = 0; i < num_down; i++) {
296 unsigned int j;
297 u8 curr_col = scancodes[i] & 0x07;
298 u8 curr_row = scancodes[i] >> KBC_ROW_SHIFT;
299
300 /*
301 * Find 2 keys such that one key is in the same row
302 * and the other is in the same column as the i-th key.
303 */
304 for (j = i + 1; j < num_down; j++) {
305 u8 col = scancodes[j] & 0x07;
306 u8 row = scancodes[j] >> KBC_ROW_SHIFT;
307
308 if (col == curr_col)
309 key_in_same_col = true;
310 if (row == curr_row)
311 key_in_same_row = true;
312 }
313 }
314 }
315
316 /*
317 * If the platform uses Fn keymaps, translate keys on a Fn keypress.
318 * Function keycodes are KBC_MAX_KEY apart from the plain keycodes.
319 */
320 if (fn_keypress) {
321 for (i = 0; i < num_down; i++) {
322 scancodes[i] += KBC_MAX_KEY;
323 keycodes[i] = kbc->keycode[scancodes[i]];
324 }
325 }
326
327 spin_unlock_irqrestore(&kbc->lock, flags);
328
329 /* Ignore the key presses for this iteration? */
330 if (key_in_same_col && key_in_same_row)
331 return;
332
333 tegra_kbc_report_released_keys(kbc->idev,
334 kbc->current_keys, kbc->num_pressed_keys,
335 keycodes, num_down);
336 tegra_kbc_report_pressed_keys(kbc->idev, scancodes, keycodes, num_down);
337 input_sync(kbc->idev);
338
339 memcpy(kbc->current_keys, keycodes, sizeof(kbc->current_keys));
340 kbc->num_pressed_keys = num_down;
341}
342
343static void tegra_kbc_keypress_timer(unsigned long data)
344{
345 struct tegra_kbc *kbc = (struct tegra_kbc *)data;
346 unsigned long flags;
347 u32 val;
348 unsigned int i;
349
350 val = (readl(kbc->mmio + KBC_INT_0) >> 4) & 0xf;
351 if (val) {
352 unsigned long dly;
353
354 tegra_kbc_report_keys(kbc);
355
356 /*
357 * If more than one keys are pressed we need not wait
358 * for the repoll delay.
359 */
360 dly = (val == 1) ? kbc->repoll_dly : 1;
361 mod_timer(&kbc->timer, jiffies + msecs_to_jiffies(dly));
362 } else {
363 /* Release any pressed keys and exit the polling loop */
364 for (i = 0; i < kbc->num_pressed_keys; i++)
365 input_report_key(kbc->idev, kbc->current_keys[i], 0);
366 input_sync(kbc->idev);
367
368 kbc->num_pressed_keys = 0;
369
370 /* All keys are released so enable the keypress interrupt */
371 spin_lock_irqsave(&kbc->lock, flags);
372 val = readl(kbc->mmio + KBC_CONTROL_0);
373 val |= KBC_CONTROL_FIFO_CNT_INT_EN;
374 writel(val, kbc->mmio + KBC_CONTROL_0);
375 spin_unlock_irqrestore(&kbc->lock, flags);
376 }
377}
378
379static irqreturn_t tegra_kbc_isr(int irq, void *args)
380{
381 struct tegra_kbc *kbc = args;
382 u32 val, ctl;
383
384 /*
385 * Until all keys are released, defer further processing to
386 * the polling loop in tegra_kbc_keypress_timer
387 */
388 ctl = readl(kbc->mmio + KBC_CONTROL_0);
389 ctl &= ~KBC_CONTROL_FIFO_CNT_INT_EN;
390 writel(ctl, kbc->mmio + KBC_CONTROL_0);
391
392 /*
393 * Quickly bail out & reenable interrupts if the fifo threshold
394 * count interrupt wasn't the interrupt source
395 */
396 val = readl(kbc->mmio + KBC_INT_0);
397 writel(val, kbc->mmio + KBC_INT_0);
398
399 if (val & KBC_INT_FIFO_CNT_INT_STATUS) {
400 /*
401 * Schedule timer to run when hardware is in continuous
402 * polling mode.
403 */
404 mod_timer(&kbc->timer, jiffies + kbc->cp_dly_jiffies);
405 } else {
406 ctl |= KBC_CONTROL_FIFO_CNT_INT_EN;
407 writel(ctl, kbc->mmio + KBC_CONTROL_0);
408 }
409
410 return IRQ_HANDLED;
411}
412
413static void tegra_kbc_setup_wakekeys(struct tegra_kbc *kbc, bool filter)
414{
415 const struct tegra_kbc_platform_data *pdata = kbc->pdata;
416 int i;
417 unsigned int rst_val;
418
419 /* Either mask all keys or none. */
420 rst_val = (filter && !pdata->wakeup) ? ~0 : 0;
421
422 for (i = 0; i < KBC_MAX_ROW; i++)
423 writel(rst_val, kbc->mmio + KBC_ROW0_MASK_0 + i * 4);
424}
425
426static void tegra_kbc_config_pins(struct tegra_kbc *kbc)
427{
428 const struct tegra_kbc_platform_data *pdata = kbc->pdata;
429 int i;
430
431 for (i = 0; i < KBC_MAX_GPIO; i++) {
432 u32 r_shft = 5 * (i % 6);
433 u32 c_shft = 4 * (i % 8);
434 u32 r_mask = 0x1f << r_shft;
435 u32 c_mask = 0x0f << c_shft;
436 u32 r_offs = (i / 6) * 4 + KBC_ROW_CFG0_0;
437 u32 c_offs = (i / 8) * 4 + KBC_COL_CFG0_0;
438 u32 row_cfg = readl(kbc->mmio + r_offs);
439 u32 col_cfg = readl(kbc->mmio + c_offs);
440
441 row_cfg &= ~r_mask;
442 col_cfg &= ~c_mask;
443
444 if (pdata->pin_cfg[i].is_row)
445 row_cfg |= ((pdata->pin_cfg[i].num << 1) | 1) << r_shft;
446 else
447 col_cfg |= ((pdata->pin_cfg[i].num << 1) | 1) << c_shft;
448
449 writel(row_cfg, kbc->mmio + r_offs);
450 writel(col_cfg, kbc->mmio + c_offs);
451 }
452}
453
454static int tegra_kbc_start(struct tegra_kbc *kbc)
455{
456 const struct tegra_kbc_platform_data *pdata = kbc->pdata;
457 unsigned long flags;
458 unsigned int debounce_cnt;
459 u32 val = 0;
460
461 clk_enable(kbc->clk);
462
463 /* Reset the KBC controller to clear all previous status.*/
464 tegra_periph_reset_assert(kbc->clk);
465 udelay(100);
466 tegra_periph_reset_deassert(kbc->clk);
467 udelay(100);
468
469 tegra_kbc_config_pins(kbc);
470 tegra_kbc_setup_wakekeys(kbc, false);
471
472 writel(pdata->repeat_cnt, kbc->mmio + KBC_RPT_DLY_0);
473
474 /* Keyboard debounce count is maximum of 12 bits. */
475 debounce_cnt = min(pdata->debounce_cnt, KBC_MAX_DEBOUNCE_CNT);
476 val = KBC_DEBOUNCE_CNT_SHIFT(debounce_cnt);
477 val |= KBC_FIFO_TH_CNT_SHIFT(1); /* set fifo interrupt threshold to 1 */
478 val |= KBC_CONTROL_FIFO_CNT_INT_EN; /* interrupt on FIFO threshold */
479 val |= KBC_CONTROL_KBC_EN; /* enable */
480 writel(val, kbc->mmio + KBC_CONTROL_0);
481
482 /*
483 * Compute the delay(ns) from interrupt mode to continuous polling
484 * mode so the timer routine is scheduled appropriately.
485 */
486 val = readl(kbc->mmio + KBC_INIT_DLY_0);
487 kbc->cp_dly_jiffies = usecs_to_jiffies((val & 0xfffff) * 32);
488
489 kbc->num_pressed_keys = 0;
490
491 /*
492 * Atomically clear out any remaining entries in the key FIFO
493 * and enable keyboard interrupts.
494 */
495 spin_lock_irqsave(&kbc->lock, flags);
496 while (1) {
497 val = readl(kbc->mmio + KBC_INT_0);
498 val >>= 4;
499 if (!val)
500 break;
501
502 val = readl(kbc->mmio + KBC_KP_ENT0_0);
503 val = readl(kbc->mmio + KBC_KP_ENT1_0);
504 }
505 writel(0x7, kbc->mmio + KBC_INT_0);
506 spin_unlock_irqrestore(&kbc->lock, flags);
507
508 enable_irq(kbc->irq);
509
510 return 0;
511}
512
513static void tegra_kbc_stop(struct tegra_kbc *kbc)
514{
515 unsigned long flags;
516 u32 val;
517
518 spin_lock_irqsave(&kbc->lock, flags);
519 val = readl(kbc->mmio + KBC_CONTROL_0);
520 val &= ~1;
521 writel(val, kbc->mmio + KBC_CONTROL_0);
522 spin_unlock_irqrestore(&kbc->lock, flags);
523
524 disable_irq(kbc->irq);
525 del_timer_sync(&kbc->timer);
526
527 clk_disable(kbc->clk);
528}
529
530static int tegra_kbc_open(struct input_dev *dev)
531{
532 struct tegra_kbc *kbc = input_get_drvdata(dev);
533
534 return tegra_kbc_start(kbc);
535}
536
537static void tegra_kbc_close(struct input_dev *dev)
538{
539 struct tegra_kbc *kbc = input_get_drvdata(dev);
540
541 return tegra_kbc_stop(kbc);
542}
543
544static bool __devinit
545tegra_kbc_check_pin_cfg(const struct tegra_kbc_platform_data *pdata,
546 struct device *dev, unsigned int *num_rows)
547{
548 int i;
549
550 *num_rows = 0;
551
552 for (i = 0; i < KBC_MAX_GPIO; i++) {
553 const struct tegra_kbc_pin_cfg *pin_cfg = &pdata->pin_cfg[i];
554
555 if (pin_cfg->is_row) {
556 if (pin_cfg->num >= KBC_MAX_ROW) {
557 dev_err(dev,
558 "pin_cfg[%d]: invalid row number %d\n",
559 i, pin_cfg->num);
560 return false;
561 }
562 (*num_rows)++;
563 } else {
564 if (pin_cfg->num >= KBC_MAX_COL) {
565 dev_err(dev,
566 "pin_cfg[%d]: invalid column number %d\n",
567 i, pin_cfg->num);
568 return false;
569 }
570 }
571 }
572
573 return true;
574}
575
576static int __devinit tegra_kbc_probe(struct platform_device *pdev)
577{
578 const struct tegra_kbc_platform_data *pdata = pdev->dev.platform_data;
579 const struct matrix_keymap_data *keymap_data;
580 struct tegra_kbc *kbc;
581 struct input_dev *input_dev;
582 struct resource *res;
583 int irq;
584 int err;
585 int num_rows = 0;
586 unsigned int debounce_cnt;
587 unsigned int scan_time_rows;
588
589 if (!pdata)
590 return -EINVAL;
591
592 if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows))
593 return -EINVAL;
594
595 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
596 if (!res) {
597 dev_err(&pdev->dev, "failed to get I/O memory\n");
598 return -ENXIO;
599 }
600
601 irq = platform_get_irq(pdev, 0);
602 if (irq < 0) {
603 dev_err(&pdev->dev, "failed to get keyboard IRQ\n");
604 return -ENXIO;
605 }
606
607 kbc = kzalloc(sizeof(*kbc), GFP_KERNEL);
608 input_dev = input_allocate_device();
609 if (!kbc || !input_dev) {
610 err = -ENOMEM;
611 goto err_free_mem;
612 }
613
614 kbc->pdata = pdata;
615 kbc->idev = input_dev;
616 kbc->irq = irq;
617 spin_lock_init(&kbc->lock);
618 setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc);
619
620 res = request_mem_region(res->start, resource_size(res), pdev->name);
621 if (!res) {
622 dev_err(&pdev->dev, "failed to request I/O memory\n");
623 err = -EBUSY;
624 goto err_free_mem;
625 }
626
627 kbc->mmio = ioremap(res->start, resource_size(res));
628 if (!kbc->mmio) {
629 dev_err(&pdev->dev, "failed to remap I/O memory\n");
630 err = -ENXIO;
631 goto err_free_mem_region;
632 }
633
634 kbc->clk = clk_get(&pdev->dev, NULL);
635 if (IS_ERR(kbc->clk)) {
636 dev_err(&pdev->dev, "failed to get keyboard clock\n");
637 err = PTR_ERR(kbc->clk);
638 goto err_iounmap;
639 }
640
641 /*
642 * The time delay between two consecutive reads of the FIFO is
643 * the sum of the repeat time and the time taken for scanning
644 * the rows. There is an additional delay before the row scanning
645 * starts. The repoll delay is computed in milliseconds.
646 */
647 debounce_cnt = min(pdata->debounce_cnt, KBC_MAX_DEBOUNCE_CNT);
648 scan_time_rows = (KBC_ROW_SCAN_TIME + debounce_cnt) * num_rows;
649 kbc->repoll_dly = KBC_ROW_SCAN_DLY + scan_time_rows + pdata->repeat_cnt;
650 kbc->repoll_dly = ((kbc->repoll_dly * KBC_CYCLE_USEC) + 999) / 1000;
651
652 input_dev->name = pdev->name;
653 input_dev->id.bustype = BUS_HOST;
654 input_dev->dev.parent = &pdev->dev;
655 input_dev->open = tegra_kbc_open;
656 input_dev->close = tegra_kbc_close;
657
658 input_set_drvdata(input_dev, kbc);
659
660 input_dev->evbit[0] = BIT_MASK(EV_KEY);
661 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
662
663 input_dev->keycode = kbc->keycode;
664 input_dev->keycodesize = sizeof(kbc->keycode[0]);
665 input_dev->keycodemax = KBC_MAX_KEY;
666 if (pdata->use_fn_map)
667 input_dev->keycodemax *= 2;
668
669 kbc->use_fn_map = pdata->use_fn_map;
670 kbc->use_ghost_filter = pdata->use_ghost_filter;
671 keymap_data = pdata->keymap_data ?: &tegra_kbc_default_keymap_data;
672 matrix_keypad_build_keymap(keymap_data, KBC_ROW_SHIFT,
673 input_dev->keycode, input_dev->keybit);
674
675 err = request_irq(kbc->irq, tegra_kbc_isr, IRQF_TRIGGER_HIGH,
676 pdev->name, kbc);
677 if (err) {
678 dev_err(&pdev->dev, "failed to request keyboard IRQ\n");
679 goto err_put_clk;
680 }
681
682 disable_irq(kbc->irq);
683
684 err = input_register_device(kbc->idev);
685 if (err) {
686 dev_err(&pdev->dev, "failed to register input device\n");
687 goto err_free_irq;
688 }
689
690 platform_set_drvdata(pdev, kbc);
691 device_init_wakeup(&pdev->dev, pdata->wakeup);
692
693 return 0;
694
695err_free_irq:
696 free_irq(kbc->irq, pdev);
697err_put_clk:
698 clk_put(kbc->clk);
699err_iounmap:
700 iounmap(kbc->mmio);
701err_free_mem_region:
702 release_mem_region(res->start, resource_size(res));
703err_free_mem:
704 input_free_device(kbc->idev);
705 kfree(kbc);
706
707 return err;
708}
709
710static int __devexit tegra_kbc_remove(struct platform_device *pdev)
711{
712 struct tegra_kbc *kbc = platform_get_drvdata(pdev);
713 struct resource *res;
714
715 free_irq(kbc->irq, pdev);
716 clk_put(kbc->clk);
717
718 input_unregister_device(kbc->idev);
719 iounmap(kbc->mmio);
720 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
721 release_mem_region(res->start, resource_size(res));
722
723 kfree(kbc);
724
725 platform_set_drvdata(pdev, NULL);
726
727 return 0;
728}
729
730#ifdef CONFIG_PM_SLEEP
731static int tegra_kbc_suspend(struct device *dev)
732{
733 struct platform_device *pdev = to_platform_device(dev);
734 struct tegra_kbc *kbc = platform_get_drvdata(pdev);
735
736 if (device_may_wakeup(&pdev->dev)) {
737 tegra_kbc_setup_wakekeys(kbc, true);
738 enable_irq_wake(kbc->irq);
739 /* Forcefully clear the interrupt status */
740 writel(0x7, kbc->mmio + KBC_INT_0);
741 msleep(30);
742 } else {
743 mutex_lock(&kbc->idev->mutex);
744 if (kbc->idev->users)
745 tegra_kbc_stop(kbc);
746 mutex_unlock(&kbc->idev->mutex);
747 }
748
749 return 0;
750}
751
752static int tegra_kbc_resume(struct device *dev)
753{
754 struct platform_device *pdev = to_platform_device(dev);
755 struct tegra_kbc *kbc = platform_get_drvdata(pdev);
756 int err = 0;
757
758 if (device_may_wakeup(&pdev->dev)) {
759 disable_irq_wake(kbc->irq);
760 tegra_kbc_setup_wakekeys(kbc, false);
761 } else {
762 mutex_lock(&kbc->idev->mutex);
763 if (kbc->idev->users)
764 err = tegra_kbc_start(kbc);
765 mutex_unlock(&kbc->idev->mutex);
766 }
767
768 return err;
769}
770#endif
771
772static SIMPLE_DEV_PM_OPS(tegra_kbc_pm_ops, tegra_kbc_suspend, tegra_kbc_resume);
773
774static struct platform_driver tegra_kbc_driver = {
775 .probe = tegra_kbc_probe,
776 .remove = __devexit_p(tegra_kbc_remove),
777 .driver = {
778 .name = "tegra-kbc",
779 .owner = THIS_MODULE,
780 .pm = &tegra_kbc_pm_ops,
781 },
782};
783
784static void __exit tegra_kbc_exit(void)
785{
786 platform_driver_unregister(&tegra_kbc_driver);
787}
788module_exit(tegra_kbc_exit);
789
790static int __init tegra_kbc_init(void)
791{
792 return platform_driver_register(&tegra_kbc_driver);
793}
794module_init(tegra_kbc_init);
795
796MODULE_LICENSE("GPL");
797MODULE_AUTHOR("Rakesh Iyer <riyer@nvidia.com>");
798MODULE_DESCRIPTION("Tegra matrix keyboard controller driver");
799MODULE_ALIAS("platform:tegra-kbc");
diff --git a/drivers/input/keyboard/tnetv107x-keypad.c b/drivers/input/keyboard/tnetv107x-keypad.c
new file mode 100644
index 000000000000..c8f097a15d89
--- /dev/null
+++ b/drivers/input/keyboard/tnetv107x-keypad.c
@@ -0,0 +1,341 @@
1/*
2 * Texas Instruments TNETV107X Keypad Driver
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/kernel.h>
17#include <linux/err.h>
18#include <linux/errno.h>
19#include <linux/input.h>
20#include <linux/platform_device.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
23#include <linux/delay.h>
24#include <linux/io.h>
25#include <linux/clk.h>
26#include <linux/input/matrix_keypad.h>
27
28#define BITS(x) (BIT(x) - 1)
29
30#define KEYPAD_ROWS 9
31#define KEYPAD_COLS 9
32
33#define DEBOUNCE_MIN 0x400ul
34#define DEBOUNCE_MAX 0x3ffffffful
35
36struct keypad_regs {
37 u32 rev;
38 u32 mode;
39 u32 mask;
40 u32 pol;
41 u32 dclock;
42 u32 rclock;
43 u32 stable_cnt;
44 u32 in_en;
45 u32 out;
46 u32 out_en;
47 u32 in;
48 u32 lock;
49 u32 pres[3];
50};
51
52#define keypad_read(kp, reg) __raw_readl(&(kp)->regs->reg)
53#define keypad_write(kp, reg, val) __raw_writel(val, &(kp)->regs->reg)
54
55struct keypad_data {
56 struct input_dev *input_dev;
57 struct resource *res;
58 struct keypad_regs __iomem *regs;
59 struct clk *clk;
60 struct device *dev;
61 spinlock_t lock;
62 u32 irq_press;
63 u32 irq_release;
64 int rows, cols, row_shift;
65 int debounce_ms, active_low;
66 u32 prev_keys[3];
67 unsigned short keycodes[];
68};
69
70static irqreturn_t keypad_irq(int irq, void *data)
71{
72 struct keypad_data *kp = data;
73 int i, bit, val, row, col, code;
74 unsigned long flags;
75 u32 curr_keys[3];
76 u32 change;
77
78 spin_lock_irqsave(&kp->lock, flags);
79
80 memset(curr_keys, 0, sizeof(curr_keys));
81 if (irq == kp->irq_press)
82 for (i = 0; i < 3; i++)
83 curr_keys[i] = keypad_read(kp, pres[i]);
84
85 for (i = 0; i < 3; i++) {
86 change = curr_keys[i] ^ kp->prev_keys[i];
87
88 while (change) {
89 bit = fls(change) - 1;
90 change ^= BIT(bit);
91 val = curr_keys[i] & BIT(bit);
92 bit += i * 32;
93 row = bit / KEYPAD_COLS;
94 col = bit % KEYPAD_COLS;
95
96 code = MATRIX_SCAN_CODE(row, col, kp->row_shift);
97 input_event(kp->input_dev, EV_MSC, MSC_SCAN, code);
98 input_report_key(kp->input_dev, kp->keycodes[code],
99 val);
100 }
101 }
102 input_sync(kp->input_dev);
103 memcpy(kp->prev_keys, curr_keys, sizeof(curr_keys));
104
105 if (irq == kp->irq_press)
106 keypad_write(kp, lock, 0); /* Allow hardware updates */
107
108 spin_unlock_irqrestore(&kp->lock, flags);
109
110 return IRQ_HANDLED;
111}
112
113static int keypad_start(struct input_dev *dev)
114{
115 struct keypad_data *kp = input_get_drvdata(dev);
116 unsigned long mask, debounce, clk_rate_khz;
117 unsigned long flags;
118
119 clk_enable(kp->clk);
120 clk_rate_khz = clk_get_rate(kp->clk) / 1000;
121
122 spin_lock_irqsave(&kp->lock, flags);
123
124 /* Initialize device registers */
125 keypad_write(kp, mode, 0);
126
127 mask = BITS(kp->rows) << KEYPAD_COLS;
128 mask |= BITS(kp->cols);
129 keypad_write(kp, mask, ~mask);
130
131 keypad_write(kp, pol, kp->active_low ? 0 : 0x3ffff);
132 keypad_write(kp, stable_cnt, 3);
133
134 debounce = kp->debounce_ms * clk_rate_khz;
135 debounce = clamp(debounce, DEBOUNCE_MIN, DEBOUNCE_MAX);
136 keypad_write(kp, dclock, debounce);
137 keypad_write(kp, rclock, 4 * debounce);
138
139 keypad_write(kp, in_en, 1);
140
141 spin_unlock_irqrestore(&kp->lock, flags);
142
143 return 0;
144}
145
146static void keypad_stop(struct input_dev *dev)
147{
148 struct keypad_data *kp = input_get_drvdata(dev);
149
150 synchronize_irq(kp->irq_press);
151 synchronize_irq(kp->irq_release);
152 clk_disable(kp->clk);
153}
154
155static int __devinit keypad_probe(struct platform_device *pdev)
156{
157 const struct matrix_keypad_platform_data *pdata;
158 const struct matrix_keymap_data *keymap_data;
159 struct device *dev = &pdev->dev;
160 struct keypad_data *kp;
161 int error = 0, sz, row_shift;
162 u32 rev = 0;
163
164 pdata = pdev->dev.platform_data;
165 if (!pdata) {
166 dev_err(dev, "cannot find device data\n");
167 return -EINVAL;
168 }
169
170 keymap_data = pdata->keymap_data;
171 if (!keymap_data) {
172 dev_err(dev, "cannot find keymap data\n");
173 return -EINVAL;
174 }
175
176 row_shift = get_count_order(pdata->num_col_gpios);
177 sz = offsetof(struct keypad_data, keycodes);
178 sz += (pdata->num_row_gpios << row_shift) * sizeof(kp->keycodes[0]);
179 kp = kzalloc(sz, GFP_KERNEL);
180 if (!kp) {
181 dev_err(dev, "cannot allocate device info\n");
182 return -ENOMEM;
183 }
184
185 kp->dev = dev;
186 kp->rows = pdata->num_row_gpios;
187 kp->cols = pdata->num_col_gpios;
188 kp->row_shift = row_shift;
189 platform_set_drvdata(pdev, kp);
190 spin_lock_init(&kp->lock);
191
192 kp->irq_press = platform_get_irq_byname(pdev, "press");
193 kp->irq_release = platform_get_irq_byname(pdev, "release");
194 if (kp->irq_press < 0 || kp->irq_release < 0) {
195 dev_err(dev, "cannot determine device interrupts\n");
196 error = -ENODEV;
197 goto error_res;
198 }
199
200 kp->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201 if (!kp->res) {
202 dev_err(dev, "cannot determine register area\n");
203 error = -ENODEV;
204 goto error_res;
205 }
206
207 if (!request_mem_region(kp->res->start, resource_size(kp->res),
208 pdev->name)) {
209 dev_err(dev, "cannot claim register memory\n");
210 kp->res = NULL;
211 error = -EINVAL;
212 goto error_res;
213 }
214
215 kp->regs = ioremap(kp->res->start, resource_size(kp->res));
216 if (!kp->regs) {
217 dev_err(dev, "cannot map register memory\n");
218 error = -ENOMEM;
219 goto error_map;
220 }
221
222 kp->clk = clk_get(dev, NULL);
223 if (IS_ERR(kp->clk)) {
224 dev_err(dev, "cannot claim device clock\n");
225 error = PTR_ERR(kp->clk);
226 goto error_clk;
227 }
228
229 error = request_threaded_irq(kp->irq_press, NULL, keypad_irq, 0,
230 dev_name(dev), kp);
231 if (error < 0) {
232 dev_err(kp->dev, "Could not allocate keypad press key irq\n");
233 goto error_irq_press;
234 }
235
236 error = request_threaded_irq(kp->irq_release, NULL, keypad_irq, 0,
237 dev_name(dev), kp);
238 if (error < 0) {
239 dev_err(kp->dev, "Could not allocate keypad release key irq\n");
240 goto error_irq_release;
241 }
242
243 kp->input_dev = input_allocate_device();
244 if (!kp->input_dev) {
245 dev_err(dev, "cannot allocate input device\n");
246 error = -ENOMEM;
247 goto error_input;
248 }
249 input_set_drvdata(kp->input_dev, kp);
250
251 kp->input_dev->name = pdev->name;
252 kp->input_dev->dev.parent = &pdev->dev;
253 kp->input_dev->open = keypad_start;
254 kp->input_dev->close = keypad_stop;
255 kp->input_dev->evbit[0] = BIT_MASK(EV_KEY);
256 if (!pdata->no_autorepeat)
257 kp->input_dev->evbit[0] |= BIT_MASK(EV_REP);
258
259 clk_enable(kp->clk);
260 rev = keypad_read(kp, rev);
261 kp->input_dev->id.bustype = BUS_HOST;
262 kp->input_dev->id.product = ((rev >> 8) & 0x07);
263 kp->input_dev->id.version = ((rev >> 16) & 0xfff);
264 clk_disable(kp->clk);
265
266 kp->input_dev->keycode = kp->keycodes;
267 kp->input_dev->keycodesize = sizeof(kp->keycodes[0]);
268 kp->input_dev->keycodemax = kp->rows << kp->row_shift;
269
270 matrix_keypad_build_keymap(keymap_data, kp->row_shift, kp->keycodes,
271 kp->input_dev->keybit);
272
273 input_set_capability(kp->input_dev, EV_MSC, MSC_SCAN);
274
275 error = input_register_device(kp->input_dev);
276 if (error < 0) {
277 dev_err(dev, "Could not register input device\n");
278 goto error_reg;
279 }
280
281 return 0;
282
283
284error_reg:
285 input_free_device(kp->input_dev);
286error_input:
287 free_irq(kp->irq_release, kp);
288error_irq_release:
289 free_irq(kp->irq_press, kp);
290error_irq_press:
291 clk_put(kp->clk);
292error_clk:
293 iounmap(kp->regs);
294error_map:
295 release_mem_region(kp->res->start, resource_size(kp->res));
296error_res:
297 platform_set_drvdata(pdev, NULL);
298 kfree(kp);
299 return error;
300}
301
302static int __devexit keypad_remove(struct platform_device *pdev)
303{
304 struct keypad_data *kp = platform_get_drvdata(pdev);
305
306 free_irq(kp->irq_press, kp);
307 free_irq(kp->irq_release, kp);
308 input_unregister_device(kp->input_dev);
309 clk_put(kp->clk);
310 iounmap(kp->regs);
311 release_mem_region(kp->res->start, resource_size(kp->res));
312 platform_set_drvdata(pdev, NULL);
313 kfree(kp);
314
315 return 0;
316}
317
318static struct platform_driver keypad_driver = {
319 .probe = keypad_probe,
320 .remove = __devexit_p(keypad_remove),
321 .driver.name = "tnetv107x-keypad",
322 .driver.owner = THIS_MODULE,
323};
324
325static int __init keypad_init(void)
326{
327 return platform_driver_register(&keypad_driver);
328}
329
330static void __exit keypad_exit(void)
331{
332 platform_driver_unregister(&keypad_driver);
333}
334
335module_init(keypad_init);
336module_exit(keypad_exit);
337
338MODULE_AUTHOR("Cyril Chemparathy");
339MODULE_DESCRIPTION("TNETV107X Keypad Driver");
340MODULE_ALIAS("platform: tnetv107x-keypad");
341MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c
index fb16b5e5ea13..a26922cf0e84 100644
--- a/drivers/input/keyboard/twl4030_keypad.c
+++ b/drivers/input/keyboard/twl4030_keypad.c
@@ -332,18 +332,20 @@ static int __devinit twl4030_kp_program(struct twl4030_keypad *kp)
332static int __devinit twl4030_kp_probe(struct platform_device *pdev) 332static int __devinit twl4030_kp_probe(struct platform_device *pdev)
333{ 333{
334 struct twl4030_keypad_data *pdata = pdev->dev.platform_data; 334 struct twl4030_keypad_data *pdata = pdev->dev.platform_data;
335 const struct matrix_keymap_data *keymap_data = pdata->keymap_data; 335 const struct matrix_keymap_data *keymap_data;
336 struct twl4030_keypad *kp; 336 struct twl4030_keypad *kp;
337 struct input_dev *input; 337 struct input_dev *input;
338 u8 reg; 338 u8 reg;
339 int error; 339 int error;
340 340
341 if (!pdata || !pdata->rows || !pdata->cols || 341 if (!pdata || !pdata->rows || !pdata->cols || !pdata->keymap_data ||
342 pdata->rows > TWL4030_MAX_ROWS || pdata->cols > TWL4030_MAX_COLS) { 342 pdata->rows > TWL4030_MAX_ROWS || pdata->cols > TWL4030_MAX_COLS) {
343 dev_err(&pdev->dev, "Invalid platform_data\n"); 343 dev_err(&pdev->dev, "Invalid platform_data\n");
344 return -EINVAL; 344 return -EINVAL;
345 } 345 }
346 346
347 keymap_data = pdata->keymap_data;
348
347 kp = kzalloc(sizeof(*kp), GFP_KERNEL); 349 kp = kzalloc(sizeof(*kp), GFP_KERNEL);
348 input = input_allocate_device(); 350 input = input_allocate_device();
349 if (!kp || !input) { 351 if (!kp || !input) {
@@ -406,23 +408,22 @@ static int __devinit twl4030_kp_probe(struct platform_device *pdev)
406 if (error) { 408 if (error) {
407 dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n", 409 dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n",
408 kp->irq); 410 kp->irq);
409 goto err3; 411 goto err2;
410 } 412 }
411 413
412 /* Enable KP and TO interrupts now. */ 414 /* Enable KP and TO interrupts now. */
413 reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO); 415 reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO);
414 if (twl4030_kpwrite_u8(kp, reg, KEYP_IMR1)) { 416 if (twl4030_kpwrite_u8(kp, reg, KEYP_IMR1)) {
415 error = -EIO; 417 error = -EIO;
416 goto err4; 418 goto err3;
417 } 419 }
418 420
419 platform_set_drvdata(pdev, kp); 421 platform_set_drvdata(pdev, kp);
420 return 0; 422 return 0;
421 423
422err4: 424err3:
423 /* mask all events - we don't care about the result */ 425 /* mask all events - we don't care about the result */
424 (void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1); 426 (void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1);
425err3:
426 free_irq(kp->irq, NULL); 427 free_irq(kp->irq, NULL);
427err2: 428err2:
428 input_unregister_device(input); 429 input_unregister_device(input);