1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/input-polldev.h>
22#include <linux/interrupt.h>
23#include <linux/jiffies.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/slab.h>
28
29#include <asm/delay.h>
30#include <asm/io.h>
31
32#define PCCR 0xa4000104
33#define PDCR 0xa4000106
34#define PECR 0xa4000108
35#define PFCR 0xa400010a
36#define PCDR 0xa4000124
37#define PDDR 0xa4000126
38#define PEDR 0xa4000128
39#define PFDR 0xa400012a
40#define PGDR 0xa400012c
41#define PHDR 0xa400012e
42#define PJDR 0xa4000130
43#define PKDR 0xa4000132
44#define PLDR 0xa4000134
45
46static const unsigned short jornada_scancodes[] = {
47 KEY_CAPSLOCK, KEY_MACRO, KEY_LEFTCTRL, 0, KEY_ESC, KEY_KP5, 0, 0,
48 KEY_F1, KEY_F2, KEY_F3, KEY_F8, KEY_F7, KEY_F6, KEY_F4, KEY_F5,
49 KEY_SLASH, KEY_APOSTROPHE, KEY_ENTER, 0, KEY_Z, 0, 0, 0,
50 KEY_X, KEY_C, KEY_V, KEY_DOT, KEY_COMMA, KEY_M, KEY_B, KEY_N,
51 KEY_KP2, KEY_KP6, KEY_KP3, 0, 0, 0, 0, 0,
52 KEY_F10, KEY_RO, KEY_F9, KEY_KP4, KEY_NUMLOCK, KEY_SCROLLLOCK, KEY_LEFTALT, KEY_HANJA,
53 KEY_KATAKANA, KEY_KP0, KEY_GRAVE, 0, KEY_FINANCE, 0, 0, 0,
54 KEY_KPMINUS, KEY_HIRAGANA, KEY_SPACE, KEY_KPDOT, KEY_VOLUMEUP, 249, 0, 0,
55 KEY_SEMICOLON, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, KEY_A, 0, 0, 0,
56 KEY_S, KEY_D, KEY_F, KEY_L, KEY_K, KEY_J, KEY_G, KEY_H,
57 KEY_KP8, KEY_LEFTMETA, KEY_RIGHTSHIFT, 0, KEY_TAB, 0, 0, 0,
58 0, KEY_LEFTSHIFT, KEY_KP7, KEY_KP9, KEY_KP1, KEY_F11, KEY_KPPLUS, KEY_KPASTERISK,
59 KEY_P, KEY_LEFTBRACE, KEY_BACKSPACE, 0, KEY_Q, 0, 0, 0,
60 KEY_W, KEY_E, KEY_R, KEY_O, KEY_I, KEY_U, KEY_T, KEY_Y,
61 KEY_0, KEY_MINUS, KEY_EQUAL, 0, KEY_1, 0, 0, 0,
62 KEY_2, KEY_3, KEY_4, KEY_9, KEY_8, KEY_7, KEY_5, KEY_6,
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0
65};
66
67#define JORNADA_SCAN_SIZE 18
68
69struct jornadakbd {
70 struct input_polled_dev *poll_dev;
71 unsigned short keymap[ARRAY_SIZE(jornada_scancodes)];
72 unsigned char length;
73 unsigned char old_scan[JORNADA_SCAN_SIZE];
74 unsigned char new_scan[JORNADA_SCAN_SIZE];
75};
76
77static void jornada_parse_kbd(struct jornadakbd *jornadakbd)
78{
79 struct input_dev *input_dev = jornadakbd->poll_dev->input;
80 unsigned short *keymap = jornadakbd->keymap;
81 unsigned int sync_me = 0;
82 unsigned int i, j;
83
84 for (i = 0; i < JORNADA_SCAN_SIZE; i++) {
85 unsigned char new = jornadakbd->new_scan[i];
86 unsigned char old = jornadakbd->old_scan[i];
87 unsigned int xor = new ^ old;
88
89 if (xor == 0)
90 continue;
91
92 for (j = 0; j < 8; j++) {
93 unsigned int bit = 1 << j;
94 if (xor & bit) {
95 unsigned int scancode = (i << 3) + j;
96 input_event(input_dev,
97 EV_MSC, MSC_SCAN, scancode);
98 input_report_key(input_dev,
99 keymap[scancode],
100 !(new & bit));
101 sync_me = 1;
102 }
103 }
104 }
105
106 if (sync_me)
107 input_sync(input_dev);
108}
109
110static void jornada_scan_keyb(unsigned char *s)
111{
112 int i;
113 unsigned short ec_static, dc_static;
114 unsigned char matrix_switch[] = {
115 0xfd, 0xff,
116 0xdf, 0xff,
117 0x7f, 0xff,
118 0xff, 0xfe,
119 0xff, 0xfd,
120 0xff, 0xf7,
121 0xff, 0xbf,
122 0xff, 0x7f,
123 }, *t = matrix_switch;
124
125
126
127
128
129
130 unsigned short matrix_PDE[] = {
131 0xcc04, 0xf0cf,
132 0xc40c, 0xf0cf,
133 0x4c0c, 0xf0cf,
134 0xcc0c, 0xf0cd,
135 0xcc0c, 0xf0c7,
136 0xcc0c, 0xf04f,
137 0xcc0c, 0xd0cf,
138 0xcc0c, 0x70cf,
139 }, *y = matrix_PDE;
140
141
142 dc_static = (__raw_readw(PDCR) & (~0xcc0c));
143 ec_static = (__raw_readw(PECR) & (~0xf0cf));
144
145 for (i = 0; i < 8; i++) {
146
147 __raw_writew((dc_static | *y++), PDCR);
148 __raw_writew((ec_static | *y++), PECR);
149 udelay(5);
150
151
152 __raw_writeb(*t++, PDDR);
153 __raw_writeb(*t++, PEDR);
154 udelay(50);
155
156
157 *s++ = __raw_readb(PCDR);
158 *s++ = __raw_readb(PFDR);
159 }
160
161 __raw_writeb(0xff, PDDR);
162 __raw_writeb(0xff, PEDR);
163
164
165 __raw_writew((dc_static | (0x5555 & 0xcc0c)),PDCR);
166 __raw_writew((ec_static | (0x5555 & 0xf0cf)),PECR);
167
168
169 *s++ = __raw_readb(PGDR);
170 *s++ = __raw_readb(PHDR);
171}
172
173static void jornadakbd680_poll(struct input_polled_dev *dev)
174{
175 struct jornadakbd *jornadakbd = dev->private;
176
177 jornada_scan_keyb(jornadakbd->new_scan);
178 jornada_parse_kbd(jornadakbd);
179 memcpy(jornadakbd->old_scan, jornadakbd->new_scan, JORNADA_SCAN_SIZE);
180}
181
182static int jornada680kbd_probe(struct platform_device *pdev)
183{
184 struct jornadakbd *jornadakbd;
185 struct input_polled_dev *poll_dev;
186 struct input_dev *input_dev;
187 int i, error;
188
189 jornadakbd = devm_kzalloc(&pdev->dev, sizeof(struct jornadakbd),
190 GFP_KERNEL);
191 if (!jornadakbd)
192 return -ENOMEM;
193
194 poll_dev = devm_input_allocate_polled_device(&pdev->dev);
195 if (!poll_dev) {
196 dev_err(&pdev->dev, "failed to allocate polled input device\n");
197 return -ENOMEM;
198 }
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;
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 dev_err(&pdev->dev, "failed to register polled input device\n");
229 return error;
230 }
231
232 return 0;
233}
234
235static struct platform_driver jornada680kbd_driver = {
236 .driver = {
237 .name = "jornada680_kbd",
238 },
239 .probe = jornada680kbd_probe,
240};
241module_platform_driver(jornada680kbd_driver);
242
243MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
244MODULE_DESCRIPTION("HP Jornada 620/660/680/690 Keyboard Driver");
245MODULE_LICENSE("GPL v2");
246MODULE_ALIAS("platform:jornada680_kbd");
247