aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorKristoffer Ericson <kristoffer.ericson@gmail.com>2007-09-26 00:02:35 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2007-09-26 00:02:35 -0400
commit2aa2cb9e7a20910d890f874e16a43a81b725ec54 (patch)
treeed96a4766d05bdd28374d2c1f55499bd756b9627 /drivers/input
parent1788180eec4a9444249b0cbe788b1fac6592976c (diff)
Input: add support for HP Jornada onboard keyboard (HP6XX)
Signed-off-by: Kristoffer Ericson <kristoffer.ericson@gmail.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/Kconfig11
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/jornada680_kbd.c277
3 files changed, 289 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index c97d5eb0075d..1881900f24c8 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -208,6 +208,17 @@ config KEYBOARD_HIL
208 This driver implements support for HIL-keyboards attached 208 This driver implements support for HIL-keyboards attached
209 to your machine, so normally you should say Y here. 209 to your machine, so normally you should say Y here.
210 210
211config KEYBOARD_HP6XX
212 tristate "HP Jornada 6XX Keyboard support"
213 depends on SH_HP6XX
214 select INPUT_POLLDEV
215 help
216 This adds support for the onboard keyboard found on
217 HP Jornada 620/660/680/690.
218
219 To compile this driver as a module, choose M here: the
220 module will be called jornada680_kbd.
221
211config KEYBOARD_OMAP 222config KEYBOARD_OMAP
212 tristate "TI OMAP keypad support" 223 tristate "TI OMAP keypad support"
213 depends on (ARCH_OMAP1 || ARCH_OMAP2) 224 depends on (ARCH_OMAP1 || ARCH_OMAP2)
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 28d211b87b14..7ecd2b05a28a 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
21obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keyboard.o 21obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keyboard.o
22obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o 22obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
23obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 23obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
24obj-$(CONFIG_KEYBOARD_HP6XX) += jornada680_kbd.o
24 25
diff --git a/drivers/input/keyboard/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c
new file mode 100644
index 000000000000..bec1cf483723
--- /dev/null
+++ b/drivers/input/keyboard/jornada680_kbd.c
@@ -0,0 +1,277 @@
1/*
2 * drivers/input/keyboard/jornada680_kbd.c
3 *
4 * HP Jornada 620/660/680/690 scan keyboard platform driver
5 * Copyright (C) 2007 Kristoffer Ericson <Kristoffer.Ericson@gmail.com>
6 *
7 * Based on hp680_keyb.c
8 * Copyright (C) 2006 Paul Mundt
9 * Copyright (C) 2005 Andriy Skulysh
10 * Split from drivers/input/keyboard/hp600_keyb.c
11 * Copyright (C) 2000 Yaegashi Takeshi (hp6xx kbd scan routine and translation table)
12 * Copyright (C) 2000 Niibe Yutaka (HP620 Keyb translation table)
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/input.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/input-polldev.h>
24#include <linux/jiffies.h>
25#include <linux/platform_device.h>
26#include <linux/interrupt.h>
27
28#include <asm/delay.h>
29#include <asm/io.h>
30
31#define PCCR 0xa4000104
32#define PDCR 0xa4000106
33#define PECR 0xa4000108
34#define PFCR 0xa400010a
35#define PCDR 0xa4000124
36#define PDDR 0xa4000126
37#define PEDR 0xa4000128
38#define PFDR 0xa400012a
39#define PGDR 0xa400012c
40#define PHDR 0xa400012e
41#define PJDR 0xa4000130
42#define PKDR 0xa4000132
43#define PLDR 0xa4000134
44
45static const unsigned short jornada_scancodes[] = {
46/* PTD1 */ KEY_CAPSLOCK, KEY_MACRO, KEY_LEFTCTRL, 0, KEY_ESC, 0, 0, 0, /* 1 -> 8 */
47 KEY_F1, KEY_F2, KEY_F3, KEY_F8, KEY_F7, KEY_F2, KEY_F4, KEY_F5, /* 9 -> 16 */
48/* PTD5 */ KEY_SLASH, KEY_APOSTROPHE, KEY_ENTER, 0, KEY_Z, 0, 0, 0, /* 17 -> 24 */
49 KEY_X, KEY_C, KEY_V, KEY_DOT, KEY_COMMA, KEY_M, KEY_B, KEY_N, /* 25 -> 32 */
50/* PTD7 */ KEY_KP2, KEY_KP6, 0, 0, 0, 0, 0, 0, /* 33 -> 40 */
51 0, 0, 0, KEY_KP4, 0, 0, KEY_LEFTALT, KEY_HANJA, /* 41 -> 48 */
52/* PTE0 */ 0, 0, 0, 0, KEY_FINANCE, 0, 0, 0, /* 49 -> 56 */
53 KEY_LEFTCTRL, 0, KEY_SPACE, KEY_KPDOT, KEY_VOLUMEUP, 249, 0, 0, /* 57 -> 64 */
54/* PTE1 */ KEY_SEMICOLON, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, KEY_A, 0, 0, 0,/* 65 -> 72 */
55 KEY_S, KEY_D, KEY_F, KEY_L, KEY_K, KEY_J, KEY_G, KEY_H, /* 73 -> 80 */
56/* PTE3 */ KEY_KP8, KEY_LEFTMETA, KEY_RIGHTSHIFT, 0, KEY_TAB, 0, 0,0, /* 81 -> 88 */
57 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, 0, /* 89 -> 96 */
58/* PTE6 */ KEY_P, KEY_LEFTBRACE, KEY_BACKSPACE, 0, KEY_Q, 0, 0, 0, /* 97 -> 104 */
59 KEY_W, KEY_E, KEY_R, KEY_O, KEY_I, KEY_U, KEY_T, KEY_R, /* 105 -> 112 */
60/* PTE7 */ KEY_0, KEY_MINUS, KEY_EQUAL, 0, KEY_1, 0, 0, 0, /* 113 -> 120 */
61 KEY_2, KEY_3, KEY_4, KEY_9, KEY_8, KEY_7, KEY_5, KEY_6, /* 121 -> 128 */
62/* **** */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 0
64};
65
66#define JORNADA_SCAN_SIZE 18
67
68struct jornadakbd {
69 struct input_polled_dev *poll_dev;
70 unsigned short keymap[ARRAY_SIZE(jornada_scancodes)];
71 unsigned char length;
72 unsigned char old_scan[JORNADA_SCAN_SIZE];
73 unsigned char new_scan[JORNADA_SCAN_SIZE];
74};
75
76static void jornada_parse_kbd(struct jornadakbd *jornadakbd)
77{
78 struct input_dev *input_dev = jornadakbd->poll_dev->input;
79 unsigned short *keymap = jornadakbd->keymap;
80 unsigned int sync_me = 0;
81 unsigned int i, j;
82
83 for (i = 0; i < JORNADA_SCAN_SIZE; i++) {
84 unsigned char new = jornadakbd->new_scan[i];
85 unsigned char old = jornadakbd->old_scan[i];
86 unsigned int xor = new ^ old;
87
88 if (xor == 0)
89 continue;
90
91 for (j = 0; j < 8; j++) {
92 unsigned int bit = 1 << j;
93 if (xor & bit) {
94 unsigned int scancode = (i << 3) + j;
95 input_event(input_dev,
96 EV_MSC, MSC_SCAN, scancode);
97 input_report_key(input_dev,
98 keymap[scancode],
99 !(new & bit));
100 sync_me = 1;
101 }
102 }
103 }
104
105 if (sync_me)
106 input_sync(input_dev);
107}
108
109static void jornada_scan_keyb(unsigned char *s)
110{
111 int i;
112 unsigned short ec_static, dc_static; /* = UINT16_t */
113 unsigned char matrix_switch[] = {
114 0xfd, 0xff, /* PTD1 PD(1) */
115 0xdf, 0xff, /* PTD5 PD(5) */
116 0x7f, 0xff, /* PTD7 PD(7) */
117 0xff, 0xfe, /* PTE0 PE(0) */
118 0xff, 0xfd, /* PTE1 PE(1) */
119 0xff, 0xf7, /* PTE3 PE(3) */
120 0xff, 0xbf, /* PTE6 PE(6) */
121 0xff, 0x7f, /* PTE7 PE(7) */
122 }, *t = matrix_switch;
123 /* PD(x) :
124 1. 0xcc0c & (1~(1 << (2*(x)+1)))))
125 2. (0xf0cf & 0xfffff) */
126 /* PE(x) :
127 1. 0xcc0c & 0xffff
128 2. 0xf0cf & (1~(1 << (2*(x)+1))))) */
129 unsigned short matrix_PDE[] = {
130 0xcc04, 0xf0cf, /* PD(1) */
131 0xc40c, 0xf0cf, /* PD(5) */
132 0x4c0c, 0xf0cf, /* PD(7) */
133 0xcc0c, 0xf0cd, /* PE(0) */
134 0xcc0c, 0xf0c7, /* PE(1) */
135 0xcc0c, 0xf04f, /* PE(3) */
136 0xcc0c, 0xd0cf, /* PE(6) */
137 0xcc0c, 0x70cf, /* PE(7) */
138 }, *y = matrix_PDE;
139
140 /* Save these control reg bits */
141 dc_static = (ctrl_inw(PDCR) & (~0xcc0c));
142 ec_static = (ctrl_inw(PECR) & (~0xf0cf));
143
144 for (i = 0; i < 8; i++) {
145 /* disable output for all but the one we want to scan */
146 ctrl_outw((dc_static | *y++), PDCR);
147 ctrl_outw((ec_static | *y++), PECR);
148 udelay(5);
149
150 /* Get scanline row */
151 ctrl_outb(*t++, PDDR);
152 ctrl_outb(*t++, PEDR);
153 udelay(50);
154
155 /* Read data */
156 *s++ = ctrl_inb(PCDR);
157 *s++ = ctrl_inb(PFDR);
158 }
159 /* Scan no lines */
160 ctrl_outb(0xff, PDDR);
161 ctrl_outb(0xff, PEDR);
162
163 /* Enable all scanlines */
164 ctrl_outw((dc_static | (0x5555 & 0xcc0c)),PDCR);
165 ctrl_outw((ec_static | (0x5555 & 0xf0cf)),PECR);
166
167 /* Ignore extra keys and events */
168 *s++ = ctrl_inb(PGDR);
169 *s++ = ctrl_inb(PHDR);
170}
171
172static void jornadakbd680_poll(struct input_polled_dev *dev)
173{
174 struct jornadakbd *jornadakbd = dev->private;
175
176 jornada_scan_keyb(jornadakbd->new_scan);
177 jornada_parse_kbd(jornadakbd);
178 memcpy(jornadakbd->old_scan, jornadakbd->new_scan, JORNADA_SCAN_SIZE);
179}
180
181static int __devinit jornada680kbd_probe(struct platform_device *pdev)
182{
183 struct jornadakbd *jornadakbd;
184 struct input_polled_dev *poll_dev;
185 struct input_dev *input_dev;
186 int i, error;
187
188 jornadakbd = kzalloc(sizeof(struct jornadakbd), GFP_KERNEL);
189 if (!jornadakbd)
190 return -ENOMEM;
191
192 poll_dev = input_allocate_polled_device();
193 if (!poll_dev) {
194 error = -ENOMEM;
195 goto failed;
196 }
197
198 platform_set_drvdata(pdev, jornadakbd);
199
200 jornadakbd->poll_dev = poll_dev;
201
202 memcpy(jornadakbd->keymap, jornada_scancodes,
203 sizeof(jornadakbd->keymap));
204
205 poll_dev->private = jornadakbd;
206 poll_dev->poll = jornadakbd680_poll;
207 poll_dev->poll_interval = 50; /* msec */
208
209 input_dev = poll_dev->input;
210 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
211 input_dev->name = "HP Jornada 680 keyboard";
212 input_dev->phys = "jornadakbd/input0";
213 input_dev->keycode = jornadakbd->keymap;
214 input_dev->keycodesize = sizeof(unsigned short);
215 input_dev->keycodemax = ARRAY_SIZE(jornada_scancodes);
216 input_dev->dev.parent = &pdev->dev;
217 input_dev->id.bustype = BUS_HOST;
218
219 for (i = 0; i < 128; i++)
220 if (jornadakbd->keymap[i])
221 __set_bit(jornadakbd->keymap[i], input_dev->keybit);
222 __clear_bit(KEY_RESERVED, input_dev->keybit);
223
224 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
225
226 error = input_register_polled_device(jornadakbd->poll_dev);
227 if (error)
228 goto failed;
229
230 return 0;
231
232 failed:
233 printk(KERN_ERR "Jornadakbd: failed to register driver, error: %d\n",
234 error);
235 platform_set_drvdata(pdev, NULL);
236 input_free_polled_device(poll_dev);
237 kfree(jornadakbd);
238 return error;
239
240}
241
242static int __devexit jornada680kbd_remove(struct platform_device *pdev)
243{
244 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
245
246 platform_set_drvdata(pdev, NULL);
247 input_unregister_polled_device(jornadakbd->poll_dev);
248 input_free_polled_device(jornadakbd->poll_dev);
249 kfree(jornadakbd);
250
251 return 0;
252}
253
254static struct platform_driver jornada680kbd_driver = {
255 .driver = {
256 .name = "jornada680_kbd",
257 },
258 .probe = jornada680kbd_probe,
259 .remove = __devexit_p(jornada680kbd_remove),
260};
261
262static int __init jornada680kbd_init(void)
263{
264 return platform_driver_register(&jornada680kbd_driver);
265}
266
267static void __exit jornada680kbd_exit(void)
268{
269 platform_driver_unregister(&jornada680kbd_driver);
270}
271
272module_init(jornada680kbd_init);
273module_exit(jornada680kbd_exit);
274
275MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
276MODULE_DESCRIPTION("HP Jornada 620/660/680/690 Keyboard Driver");
277MODULE_LICENSE("GPLv2");