View | Details | Raw Unified | Return to bug 59698
Collapse All | Expand All

(-)/usr/src/sys/dev/usb/ukbd.c (-99 / +71 lines)
Lines 275-328 Link Here
275
	{ MOD_WIN_R,	 0xe7 },
275
	{ MOD_WIN_R,	 0xe7 },
276
};
276
};
277
277
278
#define NN 0			/* no translation */
278
279
#define NN 0x0000		/* no translation */
279
/*
280
/*
280
 * Translate USB keycodes to AT keyboard scancodes.
281
 * Translate USB keycodes to AT keyboard scancodes.
281
 */
282
 */
282
/*
283
Static u_int16_t ukbd_trtab[256] = {
283
 * FIXME: Mac USB keyboard generates:
284
	   NN,    NN,    NN,    NN, 0x01E, 0x030, 0x02E, 0x020, /* 00-07 */
284
 * 0x53: keypad NumLock/Clear
285
	0x012, 0x021, 0x022, 0x023, 0x017, 0x024, 0x025, 0x026, /* 08-0F */
285
 * 0x66: Power
286
	0x032, 0x031, 0x018, 0x019, 0x010, 0x013, 0x01F, 0x014, /* 10-17 */
286
 * 0x67: keypad =
287
	0x016, 0x02F, 0x011, 0x02D, 0x015, 0x02C, 0x002, 0x003, /* 18-1F */
287
 * 0x68: F13
288
	0x004, 0x005, 0x006, 0x007, 0x008, 0x009, 0x00A, 0x00B, /* 20-27 */
288
 * 0x69: F14
289
	0x01C, 0x001, 0x00E, 0x00F, 0x039, 0x00C, 0x00D, 0x01A, /* 28-2F */
289
 * 0x6a: F15
290
	0x01B, 0x02B, 0x02B, 0x027, 0x028, 0x029, 0x033, 0x034, /* 30-37 */
290
 */
291
	0x035, 0x03A, 0x03B, 0x03C, 0x03D, 0x03E, 0x03F, 0x040, /* 38-3F */
291
Static u_int8_t ukbd_trtab[256] = {
292
	0x041, 0x042, 0x043, 0x044, 0x057, 0x058, 0x137, 0x046, /* 40-47 */
292
	   0,   0,   0,   0,  30,  48,  46,  32, /* 00 - 07 */
293
	/* FIX BREAK, PAUSE (48): 0x0FF for handling later. */
293
	  18,  33,  34,  35,  23,  36,  37,  38, /* 08 - 0F */
294
	0x0FF, 0x152, 0x147, 0x149, 0x153, 0x14F, 0x151, 0x14D, /* 48-4F */
294
	  50,  49,  24,  25,  16,  19,  31,  20, /* 10 - 17 */
295
	0x14B, 0x150, 0x148, 0x045, 0x135, 0x037, 0x04A, 0x04E, /* 50-57 */
295
	  22,  47,  17,  45,  21,  44,   2,   3, /* 18 - 1F */
296
	0x11C, 0x04F, 0x050, 0x051, 0x04B, 0x04C, 0x04D, 0x047, /* 58-5F */
296
	   4,   5,   6,   7,   8,   9,  10,  11, /* 20 - 27 */
297
	0x048, 0x049, 0x052, 0x053, 0x056, 0x15D,    NN, 0x059, /* 60-67 */
297
	  28,   1,  14,  15,  57,  12,  13,  26, /* 28 - 2F */
298
	0x05D, 0x05E, 0x05F,    NN,    NN,    NN,    NN,    NN, /* 68-6F */
298
	  27,  43,  43,  39,  40,  41,  51,  52, /* 30 - 37 */
299
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* 70-77 */
299
	  53,  58,  59,  60,  61,  62,  63,  64, /* 38 - 3F */
300
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* 78-7F */
300
	  65,  66,  67,  68,  87,  88,  92,  70, /* 40 - 47 */
301
	   NN,    NN,    NN,    NN,    NN, 0x07E,    NN, 0x073, /* 80-87 */
301
	 104, 102,  94,  96, 103,  99, 101,  98, /* 48 - 4F */
302
	0x070, 0x07D, 0x079, 0x07B, 0x05C,    NN,    NN,    NN, /* 88-8F */
302
	  97, 100,  95,  69,  91,  55,  74,  78, /* 50 - 57 */
303
	/* FIX 90, 91: scancodes 0x0F? lost in translation to keycode.
303
	  89,  79,  80,  81,  75,  76,  77,  71, /* 58 - 5F */
304
	 * Hence we just make them no-ops.
304
          72,  73,  82,  83,  86, 107,  NN,  NN, /* 60 - 67 */
305
	 */
305
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* 68 - 6F */
306
	   NN,    NN, 0x078, 0x077, 0x076,    NN,    NN,    NN, /* 90-97 */
306
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* 70 - 77 */
307
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* 98-9F */
307
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* 78 - 7F */
308
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* A0-A7 */
308
          NN,  NN,  NN,  NN,  NN,  NN,  NN, 115, /* 80 - 87 */
309
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* A8-AF */
309
         112, 125, 121, 123,  NN,  NN,  NN,  NN, /* 88 - 8F */
310
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* B0-B7 */
310
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* 90 - 97 */
311
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* B8-BF */
311
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* 98 - 9F */
312
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* C0-C7 */
312
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* A0 - A7 */
313
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* C8-CF */
313
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* A8 - AF */
314
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* D0-D7 */
314
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* B0 - B7 */
315
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* D8-DF */
315
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* B8 - BF */
316
	0x01D, 0x02A, 0x038, 0x15B, 0x11D, 0x036, 0x138, 0x15C, /* E0-E7 */
316
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* C0 - C7 */
317
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* E8-EF */
317
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* C8 - CF */
318
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN, /* F0-F7 */
318
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* D0 - D7 */
319
	   NN,    NN,    NN,    NN,    NN,    NN,    NN,    NN  /* F8-FF */
319
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* D8 - DF */
320
          29,  42,  56, 105,  90,  54,  93, 106, /* E0 - E7 */
321
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* E8 - EF */
322
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* F0 - F7 */
323
          NN,  NN,  NN,  NN,  NN,  NN,  NN,  NN, /* F8 - FF */
324
};
320
};
325
321
322
#define PAUSEFIX(c,d) if (((c) == 0x0FF) && !((d) & (MOD_CONTROL_L | MOD_CONTROL_R))) { \
323
			(c) = 0x045 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL; }
324
#define SHIFTFIX(c,d) if ((d) & (MOD_SHIFT_L | MOD_SHIFT_R)) { \
325
			(c) &= ~SCAN_PREFIX_SHIFT; }
326
#define KEYUP(c,d) (c) |= ((d) ? SCAN_RELEASE : SCAN_PRESS)
327
326
typedef struct ukbd_state {
328
typedef struct ukbd_state {
327
	usbd_interface_handle ks_iface;	/* interface */
329
	usbd_interface_handle ks_iface;	/* interface */
328
	usbd_pipe_handle ks_intrpipe;	/* interrupt pipe */
330
	usbd_pipe_handle ks_intrpipe;	/* interrupt pipe */
Lines 413-421 Link Here
413
				      int flags);
415
				      int flags);
414
Static void		set_leds(ukbd_state_t *state, int leds);
416
Static void		set_leds(ukbd_state_t *state, int leds);
415
Static int		set_typematic(keyboard_t *kbd, int code);
417
Static int		set_typematic(keyboard_t *kbd, int code);
416
#ifdef UKBD_EMULATE_ATSCANCODE
417
Static int		keycode2scancode(int keycode, int shift, int up);
418
#endif
419
418
420
/* local variables */
419
/* local variables */
421
420
Lines 881-887 Link Here
881
	ukbd_state_t *state;
880
	ukbd_state_t *state;
882
	int usbcode;
881
	int usbcode;
883
#ifdef UKBD_EMULATE_ATSCANCODE
882
#ifdef UKBD_EMULATE_ATSCANCODE
884
	int keycode;
885
	int scancode;
883
	int scancode;
886
#endif
884
#endif
887
885
Lines 906-917 Link Here
906
		return -1;
904
		return -1;
907
	++kbd->kb_count;
905
	++kbd->kb_count;
908
#ifdef UKBD_EMULATE_ATSCANCODE
906
#ifdef UKBD_EMULATE_ATSCANCODE
909
	keycode = ukbd_trtab[KEY_INDEX(usbcode)];
907
	scancode = ukbd_trtab[KEY_INDEX(usbcode)];
910
	if (keycode == NN)
908
	if (scancode == NN)
911
		return -1;
909
		return -1;
912
910
913
	scancode = keycode2scancode(keycode, state->ks_ndata.modifiers,
911
	PAUSEFIX(scancode,state->ks_ndata.modifiers);
914
				    usbcode & KEY_RELEASE);
912
	SHIFTFIX(scancode,state->ks_ndata.modifiers);
913
	KEYUP(scancode,usbcode & KEY_RELEASE);
914
915
	if (scancode & SCAN_PREFIX) {
915
	if (scancode & SCAN_PREFIX) {
916
		if (scancode & SCAN_PREFIX_CTL) {
916
		if (scancode & SCAN_PREFIX_CTL) {
917
			state->ks_buffered_char[0] =
917
			state->ks_buffered_char[0] =
Lines 956-965 Link Here
956
	ukbd_state_t *state;
956
	ukbd_state_t *state;
957
	u_int action;
957
	u_int action;
958
	int usbcode;
958
	int usbcode;
959
	int keycode;
960
#ifdef UKBD_EMULATE_ATSCANCODE
961
	int scancode;
959
	int scancode;
962
#endif
963
960
964
	state = (ukbd_state_t *)kbd->kb_data;
961
	state = (ukbd_state_t *)kbd->kb_data;
965
next_code:
962
next_code:
Lines 1000-1013 Link Here
1000
997
1001
#ifdef UKBD_EMULATE_ATSCANCODE
998
#ifdef UKBD_EMULATE_ATSCANCODE
1002
	/* USB key index -> key code -> AT scan code */
999
	/* USB key index -> key code -> AT scan code */
1003
	keycode = ukbd_trtab[KEY_INDEX(usbcode)];
1000
	scancode = ukbd_trtab[KEY_INDEX(usbcode)];
1004
	if (keycode == NN)
1001
	if (scancode == NN)
1005
		return NOKEY;
1002
		return NOKEY;
1006
1003
1007
	/* return an AT scan code for the K_RAW mode */
1004
	/* return an AT scan code for the K_RAW mode */
1008
	if (state->ks_mode == K_RAW) {
1005
	if (state->ks_mode == K_RAW) {
1009
		scancode = keycode2scancode(keycode, state->ks_ndata.modifiers,
1006
		PAUSEFIX(scancode,state->ks_ndata.modifiers);
1010
					    usbcode & KEY_RELEASE);
1007
		SHIFTFIX(scancode,state->ks_ndata.modifiers);
1008
		KEYUP(scancode,usbcode & KEY_RELEASE);
1011
		if (scancode & SCAN_PREFIX) {
1009
		if (scancode & SCAN_PREFIX) {
1012
			if (scancode & SCAN_PREFIX_CTL) {
1010
			if (scancode & SCAN_PREFIX_CTL) {
1013
				state->ks_buffered_char[0] =
1011
				state->ks_buffered_char[0] =
Lines 1034-1045 Link Here
1034
		return usbcode;
1032
		return usbcode;
1035
1033
1036
	/* USB key index -> key code */
1034
	/* USB key index -> key code */
1037
	keycode = ukbd_trtab[KEY_INDEX(usbcode)];
1035
	scancode = ukbd_trtab[KEY_INDEX(usbcode)];
1038
	if (keycode == NN)
1036
	if (scancode == NN)
1039
		return NOKEY;
1037
		return NOKEY;
1040
#endif /* UKBD_EMULATE_ATSCANCODE */
1038
#endif /* UKBD_EMULATE_ATSCANCODE */
1041
1039
1042
	switch (keycode) {
1040
	switch (scancode) {
1043
	case 0x38:	/* left alt (compose key) */
1041
	case 0x38:	/* left alt (compose key) */
1044
		if (usbcode & KEY_RELEASE) {
1042
		if (usbcode & KEY_RELEASE) {
1045
			if (state->ks_flags & COMPOSE) {
1043
			if (state->ks_flags & COMPOSE) {
Lines 1055-1095 Link Here
1055
		}
1053
		}
1056
		break;
1054
		break;
1057
	/* XXX: I don't like these... */
1055
	/* XXX: I don't like these... */
1058
	case 0x5c:	/* print screen */
1056
	case 0x137:	/* print screen */
1059
		if (state->ks_flags & ALTS)
1057
		if (state->ks_flags & ALTS)
1060
			keycode = 0x54;	/* sysrq */
1058
			scancode = 0x54;	/* sysrq */
1061
		break;
1059
		break;
1062
	case 0x68:	/* pause/break */
1060
	case 0xFF:	/* pause/break */
1063
		if (state->ks_flags & CTLS)
1061
		if (state->ks_flags & CTLS)
1064
			keycode = 0x6c;	/* break */
1062
			scancode = 0x6c;	/* break */
1065
		break;
1063
		break;
1066
	}
1064
	}
1067
1065
1068
	/* return the key code in the K_CODE mode */
1066
	/* return the key code in the K_CODE mode */
1069
	if (usbcode & KEY_RELEASE)
1067
	if (usbcode & KEY_RELEASE)
1070
		keycode |= SCAN_RELEASE;
1068
		scancode |= SCAN_RELEASE;
1071
	if (state->ks_mode == K_CODE)
1069
	if (state->ks_mode == K_CODE)
1072
		return keycode;
1070
		return scancode;
1073
1071
1074
	/* compose a character code */
1072
	/* compose a character code */
1075
	if (state->ks_flags & COMPOSE) {
1073
	if (state->ks_flags & COMPOSE) {
1076
		switch (keycode) {
1074
		switch (scancode) {
1077
		/* key pressed, process it */
1075
		/* key pressed, process it */
1078
		case 0x47: case 0x48: case 0x49:	/* keypad 7,8,9 */
1076
		case 0x47: case 0x48: case 0x49:	/* keypad 7,8,9 */
1079
			state->ks_composed_char *= 10;
1077
			state->ks_composed_char *= 10;
1080
			state->ks_composed_char += keycode - 0x40;
1078
			state->ks_composed_char += scancode - 0x40;
1081
			if (state->ks_composed_char > UCHAR_MAX)
1079
			if (state->ks_composed_char > UCHAR_MAX)
1082
				return ERRKEY;
1080
				return ERRKEY;
1083
			goto next_code;
1081
			goto next_code;
1084
		case 0x4B: case 0x4C: case 0x4D:	/* keypad 4,5,6 */
1082
		case 0x4B: case 0x4C: case 0x4D:	/* keypad 4,5,6 */
1085
			state->ks_composed_char *= 10;
1083
			state->ks_composed_char *= 10;
1086
			state->ks_composed_char += keycode - 0x47;
1084
			state->ks_composed_char += scancode - 0x47;
1087
			if (state->ks_composed_char > UCHAR_MAX)
1085
			if (state->ks_composed_char > UCHAR_MAX)
1088
				return ERRKEY;
1086
				return ERRKEY;
1089
			goto next_code;
1087
			goto next_code;
1090
		case 0x4F: case 0x50: case 0x51:	/* keypad 1,2,3 */
1088
		case 0x4F: case 0x50: case 0x51:	/* keypad 1,2,3 */
1091
			state->ks_composed_char *= 10;
1089
			state->ks_composed_char *= 10;
1092
			state->ks_composed_char += keycode - 0x4E;
1090
			state->ks_composed_char += scancode - 0x4E;
1093
			if (state->ks_composed_char > UCHAR_MAX)
1091
			if (state->ks_composed_char > UCHAR_MAX)
1094
				return ERRKEY;
1092
				return ERRKEY;
1095
			goto next_code;
1093
			goto next_code;
Lines 1126-1133 Link Here
1126
	}
1124
	}
1127
1125
1128
	/* keycode to key action */
1126
	/* keycode to key action */
1129
	action = genkbd_keyaction(kbd, SCAN_CHAR(keycode),
1127
	action = genkbd_keyaction(kbd, SCAN_CHAR(scancode),
1130
				  keycode & SCAN_RELEASE, &state->ks_state,
1128
				  scancode & SCAN_RELEASE, &state->ks_state,
1131
				  &state->ks_accents);
1129
				  &state->ks_accents);
1132
	if (action == NOKEY)
1130
	if (action == NOKEY)
1133
		goto next_code;
1131
		goto next_code;
Lines 1437-1468 Link Here
1437
	kbd->kb_delay2 = rates[code & 0x1f];
1435
	kbd->kb_delay2 = rates[code & 0x1f];
1438
	return 0;
1436
	return 0;
1439
}
1437
}
1440
1441
#ifdef UKBD_EMULATE_ATSCANCODE
1442
Static int
1443
keycode2scancode(int keycode, int shift, int up)
1444
{
1445
	static int scan[] = {
1446
		0x1c, 0x1d, 0x35,
1447
		0x37 | SCAN_PREFIX_SHIFT, /* PrintScreen */
1448
		0x38, 0x47, 0x48, 0x49, 0x4b, 0x4d, 0x4f,
1449
		0x50, 0x51, 0x52, 0x53,
1450
		0x46, 	/* XXX Pause/Break */
1451
		0x5b, 0x5c, 0x5d,
1452
	};
1453
	int scancode;
1454
1455
	scancode = keycode;
1456
	if ((keycode >= 89) && (keycode < 89 + sizeof(scan)/sizeof(scan[0])))
1457
		scancode = scan[keycode - 89] | SCAN_PREFIX_E0;
1458
	/* Pause/Break */
1459
	if ((keycode == 104) && !(shift & (MOD_CONTROL_L | MOD_CONTROL_R)))
1460
		scancode = 0x45 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL;
1461
	if (shift & (MOD_SHIFT_L | MOD_SHIFT_R))
1462
		scancode &= ~SCAN_PREFIX_SHIFT;
1463
	return (scancode | (up ? SCAN_RELEASE : SCAN_PRESS));
1464
}
1465
#endif /* UKBD_EMULATE_ATSCANCODE */
1466
1438
1467
Static int
1439
Static int
1468
ukbd_driver_load(module_t mod, int what, void *arg)
1440
ukbd_driver_load(module_t mod, int what, void *arg)

Return to bug 59698