1 /*
2  *	$Id$
3  *	Copyright (C) 2000 YAEGASHI Takeshi
4  *	HP600 keyboard scan routine and translation table
5  *	Copyright (C) 2000 Niibe Yutaka
6  *	HP620 keyboard translation table
7  */
8 
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/init.h>
12 
13 #include <asm/machvec.h>
14 #include <asm/delay.h>
15 #include <asm/io.h>
16 #include "scan_keyb.h"
17 
18 #define PCDR 0xa4000124
19 #define PDDR 0xa4000126
20 #define PEDR 0xa4000128
21 #define PFDR 0xa400012a
22 #define PGDR 0xa400012c
23 #define PHDR 0xa400012e
24 #define PJDR 0xa4000130
25 #define PKDR 0xa4000132
26 #define PLDR 0xa4000134
27 
28 static const unsigned char hp620_japanese_table[] = {
29 	/* PTD1 */
30 	0x0a, 0x0b, 0x0c, 0x00, 0x00, 0x0e, 0x00, 0x00,
31 	0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
32 	/* PTD5 */
33 	0x18, 0x19, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
34 	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
35 	/* PTD7 */
36 	0x26, 0x1a, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00,
37 	0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
38 	/* PTE0 */
39 	0x27, 0x1b, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00,
40 	0x2a, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
41 	/* PTE1 */
42 	0x35, 0x28, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
43 	0x70, 0x3a, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x34,
44 	/* PTE3 */
45 	0x48, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 	0x00, 0x2d, 0x2e, 0x7b, 0x30, 0x31, 0x32, 0x33,
47 	/* PTE6 */
48 	0x4b, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 	0x00, 0x2c, 0x38, 0x00, 0x39, 0x79, 0x7d, 0x73,
50 	/* PTE7 */
51 	0x41, 0x42, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00,
52 	0x00, 0x00, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
53 	/* **** */
54 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56 };
57 
58 
59 static const unsigned char hp680_japanese_table[] = {
60 	/* PTD1 */
61 	0x3a, 0x70, 0x29, 0x00, 0x01, 0x00, 0x00, 0x00,
62 	0x3b, 0x3c, 0x3d, 0x42, 0x41, 0x40, 0x3e, 0x3f,
63 	/* PTD5 */
64 	0x35, 0x28, 0x1c, 0x00, 0x2c, 0x00, 0x00, 0x00,
65 	0x2d, 0x2e, 0x2f, 0x34, 0x33, 0x32, 0x30, 0x31,
66 	/* PTD7 */
67 	0x50, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 	0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x38, 0x7b,
69 	/* PTE0 */
70 	0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00,
71 	0x1d, 0x00, 0x39, 0x53, 0x73, 0xf9, 0x00, 0x00,
72 	/* PTE1 */
73 	0x27, 0x1b, 0x2b, 0x00, 0x1e, 0x00, 0x00, 0x00,
74 	0x1f, 0x20, 0x21, 0x26, 0x25, 0x24, 0x22, 0x23,
75 	/* PTE3 */
76 	0x48, 0x7d, 0x36, 0x00, 0x0f, 0x00, 0x00, 0x00,
77 	0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 	/* PTE6 */
79 	0x19, 0x1a, 0x0e, 0x00, 0x10, 0x00, 0x00, 0x00,
80 	0x11, 0x12, 0x13, 0x18, 0x17, 0x16, 0x14, 0x15,
81 	/* PTE7 */
82 	0x0b, 0x0c, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x00,
83 	0x03, 0x04, 0x05, 0x0a, 0x09, 0x08, 0x06, 0x07,
84 	/* **** */
85 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 };
88 
89 
hp620_japanese_scan_kbd(unsigned char * s)90 static int hp620_japanese_scan_kbd(unsigned char *s)
91 {
92 	int i;
93 	unsigned char matrix_switch[] = {
94 		0xfd, 0xff,	/* PTD1 */
95 		0xdf, 0xff,	/* PTD5 */
96 		0x7f, 0xff,	/* PTD7 */
97 		0xff, 0xfe,	/* PTE0 */
98 		0xff, 0xfd,	/* PTE1 */
99 		0xff, 0xf7,	/* PTE3 */
100 		0xff, 0xbf,	/* PTE6 */
101 		0xff, 0x7f,	/* PTE7 */
102 	}, *t=matrix_switch;
103 
104 	for(i=0; i<8; i++) {
105 		ctrl_outb(*t++, PDDR);
106 		ctrl_outb(*t++, PEDR);
107 		udelay(50);
108 		*s++=ctrl_inb(PCDR);
109 		*s++=ctrl_inb(PFDR);
110 	}
111 
112 	ctrl_outb(0xff, PDDR);
113 	ctrl_outb(0xff, PEDR);
114 
115 	*s++=ctrl_inb(PGDR);
116 	*s++=ctrl_inb(PHDR);
117 
118 	return 0;
119 }
120 
121 
hp680_japanese_scan_kbd(unsigned char * s)122 static int hp680_japanese_scan_kbd(unsigned char *s)
123 {
124 	int i;
125 	unsigned char matrix_switch[] = {
126 		0xfd, 0xff,	/* PTD1 */
127 		0xdf, 0xff,	/* PTD5 */
128 		0x7f, 0xff,	/* PTD7 */
129 		0xff, 0xfe,	/* PTE0 */
130 		0xff, 0xfd,	/* PTE1 */
131 		0xff, 0xf7,	/* PTE3 */
132 		0xff, 0xbf,	/* PTE6 */
133 		0xff, 0x7f,	/* PTE7 */
134 	}, *t=matrix_switch;
135 
136 	for(i=0; i<8; i++) {
137 		ctrl_outb(*t++, PDDR);
138 		ctrl_outb(*t++, PEDR);
139 		*s++=ctrl_inb(PCDR);
140 		*s++=ctrl_inb(PFDR);
141 	}
142 
143 	ctrl_outb(0xff, PDDR);
144 	ctrl_outb(0xff, PEDR);
145 
146 	*s++=ctrl_inb(PGDR);
147 	*s++=ctrl_inb(PHDR);
148 
149 	return 0;
150 }
151 
152 
hp600_kbd_init_hw(void)153 void __init hp600_kbd_init_hw(void)
154 {
155 	scan_kbd_init();
156 
157 	if (MACH_HP620)
158 		register_scan_keyboard(hp620_japanese_scan_kbd,
159 				       hp620_japanese_table, 18);
160 	else if (MACH_HP680 || MACH_HP690)
161 		register_scan_keyboard(hp680_japanese_scan_kbd,
162 				       hp680_japanese_table, 18);
163 
164 	printk(KERN_INFO "HP600 matrix scan keyboard registered\n");
165 }
166 
167 /****************************************************************
168 HP Jornada 690(Japanese version) keyboard scan matrix
169 
170 	PTC7	PTC6	PTC5	PTC4	PTC3	PTC2	PTC1	PTC0
171 PTD1	REC			Escape	on/off	Han/Zen	Hira	Eisu
172 PTD5	REC			Z	on/off	Enter	:	/
173 PTD7	REC						Right	Down
174 PTE0	REC			Windows	on/off
175 PTE1	REC			A	on/off	]	[	;
176 PTE3	REC			Tab	on/off	ShirtR	\	Up
177 PTE6	REC			Q	on/off	BS	@	P
178 PTE7	REC			1	on/off	^	-	0
179 
180 	PTF7	PTF6	PTF5	PTF4	PTF3	PTF2	PTF1	PTF0
181 PTD1	F5	F4	F6	F7	F8	F3	F2	F1
182 PTD5	N	B	M	,	.	V	C	X
183 PTD7	Muhen	Alt			Left
184 PTE0			Henkan	_	Del	Space		Ctrl
185 PTE1	H	G	J	K	L	F	D	S
186 PTE3							ShiftL
187 PTE6	Y	T	U	I	O	R	E	W
188 PTE7	6	5	7	8	9	4	3	2
189 
190 	PTG5	PTG4	PTG3	PTG0	PTH0
191 *	REC	REW	FWW	Cover	on/off
192 
193 
194 		7	6	5	4	3	2	1	0
195 C: 0xffff 0xdf	IP	IP	IP	IP	IP	IP	IP	IP
196 D: 0x6786 0x59	O	I	O	IP	I	F	O	I
197 E: 0x5045 0x00	O	O	F	F	O	F	O	O
198 F: 0xffff 0xff	IP	IP	IP	IP	IP	IP	IP	IP
199 G: 0xaffe 0xfd	I	I	IP	IP	IP	IP	IP	I
200 H: 0x70f2 0x49	O	IP	F	F	IP	IP	F	I
201 J: 0x0704 0x22	F	F	O	IP	F	F	O	F
202 K: 0x0100 0x10	F	F	F	O	F	F	F	F
203 L: 0x0c3c 0x26	F	F	IP	F	F	IP	IP	F
204 
205 ****************************************************************/
206 
207 /****************************************************************
208 HP Jornada 620(Japanese version) keyboard scan matrix
209 
210 	PTC7	PTC6	PTC5	PTC4	PTC3	PTC2	PTC1	PTC0
211 PTD1	EREC		BS	Ctrl	on/off	-	0	9
212 PTD5	EREC		BS	Ctrl	on/off	^	P	O
213 PTD7	EREC		BS	Ctrl	on/off	]	@	L
214 PTE0	EREC		BS	Ctrl	on/off	Han/Zen [	;
215 PTE1	EREC		BS	Ctrl	on/off	Enter	:	/
216 PTE3	EREC		BS	Ctrl	on/off		Right	Up
217 PTE6	EREC		BS	Ctrl	on/off		Down	Left
218 PTE7	EREC		BS	Ctrl	on/off		F8	F7
219 
220 	PTF7	PTF6	PTF5	PTF4	PTF3	PTF2	PTF1	PTF0
221 PTD1	8	7	6	5	4	3	2	1
222 PTD5	I	U	Y	T	R	E	W	Q
223 PTD7	K	J	H	G	F	D	S	A
224 PTE0						ESC	Tab	Shift
225 PTE1	.			V			Caps	Hira
226 PTE3	,	M	N	B	Muhen	C	X
227 PTE6	_	\	Henkan	Space		Alt	Z
228 PTE7	F6	F5	F4	F3	F2	F1		REC
229 
230 	PTH0
231 *	on/off
232 
233 		7	6	5	4	3	2	1	0
234 C: 0xffff 0xff	IP	IP	IP	IP	IP	IP	IP	IP
235 D: 0x4404 0xaf	O	F	O	F	F	F	O	F
236 E: 0x5045 0xff	O	O	F	F	O	F	O	O
237 F: 0xffff 0xff	IP	IP	IP	IP	IP	IP	IP	IP
238 G: 0xd5ff 0x00	IP	O	O	O	IP	IP	IP	IP
239 H: 0x63ff 0xd1	O	I	F	IP	IP	IP	IP	IP
240 J: 0x0004 0x02	F	F	F	F	F	F	O	F
241 K: 0x0401 0xff	F	F	O	F	F	F	F	O
242 L: 0x0c00 0x20	F	F	IP	F	F	F	F	F
243 
244 ADCSR: 0x08
245 ADCR: 0x3f
246 
247  ****************************************************************/
248 
249 /****************************************************************
250 Japanese 109 keyboard scan code layout
251 
252                                               E02A-     E1-
253 01    3B 3C 3D 3E  3F 40 41 42  43 44 57 58   E037  46  1045
254 
255 29 02 03 04 05 06 07 08 09 0A 0B 0C 0D 7D 0E  E052 E047 E049   45 E035 37  4A
256 0F  10 11 12 13 14 15 16 17 18 19 1A 1B   1C  E053 E04F E051   47  48  49  4E
257 3A   1E 1F 20 21 22 23 24 25 26 27 28 2B                       4B  4C  4D
258 2A    2C 2D 2E 2F 30 31 32 33 34 35 73    36       E048        4F  50  51  E0-
259 1D  DB  38  7B   39   79 70  E038 DC DD E01D  E04B E050 E04D     52    53  1C
260 
261 ****************************************************************/
262 
263 #if 0
264 int __init hp620_keyboard_test(void)
265 {
266 	int i;
267 	unsigned char s[18];
268 	unsigned long a, b, c, d;
269 
270 	printk("PCCR: %04lx, PCDR: %02lx\n",
271 	       ctrl_inw(0xa4000104), ctrl_inb(0xa4000124));
272 	printk("PDCR: %04lx, PDDR: %02lx\n",
273 	       ctrl_inw(0xa4000106), ctrl_inb(0xa4000126));
274 	printk("PECR: %04lx, PEDR: %02lx\n",
275 	       ctrl_inw(0xa4000108), ctrl_inb(0xa4000128));
276 	printk("PFCR: %04lx, PFDR: %02lx\n",
277 	       ctrl_inw(0xa400010a), ctrl_inb(0xa400012a));
278 	printk("PGCR: %04lx, PGDR: %02lx\n",
279 	       ctrl_inw(0xa400010c), ctrl_inb(0xa400012c));
280 	printk("PHCR: %04lx, PHDR: %02lx\n",
281 	       ctrl_inw(0xa400010e), ctrl_inb(0xa400012e));
282 	printk("PJCR: %04lx, PJDR: %02lx\n",
283 	       ctrl_inw(0xa4000110), ctrl_inb(0xa4000130));
284 	printk("PKCR: %04lx, PKDR: %02lx\n",
285 	       ctrl_inw(0xa4000112), ctrl_inb(0xa4000132));
286 	printk("PLCR: %04lx, PLDR: %02lx\n",
287 	       ctrl_inw(0xa4000114), ctrl_inb(0xa4000134));
288 
289 	printk("ADCSR: %02lx, ADCR: %02lx\n",
290 	       ctrl_inb(0xa4000090), ctrl_inb(0xa4000092));
291 
292 	ctrl_inb(0xa4000004);
293 	ctrl_inb(0xa4000006);
294 	ctrl_inb(0xa4000008);
295 	ctrl_outb(0, 0xa4000004);
296 	ctrl_outb(0, 0xa4000006);
297 	ctrl_outb(0, 0xa4000008);
298 	ctrl_outb(0, 0xa4000090);
299 	ctrl_outb(0x3b, 0xa4000090);
300 
301 	while(1) {
302 		hp620_japanese_scan_kbd(s);
303 		for(i=0; i<18; i+=2)
304 			printk("%02x%02x ", s[i], s[i+1]);
305 
306 #if 0
307 		ctrl_outb(~2, PJDR);
308 		printk("%02lx%02lx ", ctrl_inb(PCDR), ctrl_inb(PFDR));
309 		ctrl_outb(0xff, PJDR);
310 		ctrl_outb(~1, PKDR);
311 		printk("%02lx%02lx ", ctrl_inb(PCDR), ctrl_inb(PFDR));
312 		ctrl_outb(~32, PKDR);
313 		printk("%02lx%02lx ", ctrl_inb(PCDR), ctrl_inb(PFDR));
314 		ctrl_outb(0xff, PKDR);
315 #endif
316 
317 		printk("%02lx%02lx%02lx%02lx ", a, b, c, d);
318 		if(ctrl_inb(0xa4000090)&0x80) {
319 			a=ctrl_inb(0xa4000080);
320 			b=ctrl_inb(0xa4000084);
321 			c=ctrl_inb(0xa4000088);
322 			d=ctrl_inb(0xa400008c);
323 			ctrl_outb(0x3b, 0xa4000090);
324 		}
325 		printk("%02lx%02lx%02lx ",
326 		       ctrl_inb(0xa4000004),
327 		       ctrl_inb(0xa4000006),
328 		       ctrl_inb(0xa4000008));
329 
330 		printk("\n");
331 	}
332 
333 	return 0;
334 }
335 module_init(keyboard_probe);
336 #endif
337 
338 
339 MODULE_LICENSE("GPL");
340