xref: /illumos-gate/usr/src/uts/common/sys/usb/clients/usbkbm/usbkbm.h (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_USB_USBKBM_H
27 #define	_SYS_USB_USBKBM_H
28 
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/time.h>
35 #include <sys/vuid_event.h>
36 #include <sys/stream.h>
37 #include <sys/kbd.h>
38 
39 
40 /*
41  * USB keyboard LED masks (used to set LED's on USB keyboards)
42  */
43 #define	USB_LED_NUM_LOCK	0x1
44 #define	USB_LED_CAPS_LOCK	0x2
45 #define	USB_LED_SCROLL_LOCK	0x4
46 #define	USB_LED_COMPOSE		0x8
47 #define	USB_LED_KANA		0x10	/* Valid only on Japanese layout */
48 
49 /* Modifier key masks */
50 #define	USB_LCTLBIT   0x01
51 #define	USB_LSHIFTBIT 0x02
52 #define	USB_LALTBIT   0x04
53 #define	USB_LMETABIT  0x08
54 #define	USB_RCTLBIT   0x10
55 #define	USB_RSHIFTBIT 0x20
56 #define	USB_RALTBIT   0x40
57 #define	USB_RMETABIT  0x80
58 
59 #define	USB_LSHIFTKEY	225
60 #define	USB_LCTLCKEY	224
61 #define	USB_LALTKEY	226
62 #define	USB_LMETAKEY	227
63 #define	USB_RCTLCKEY	228
64 #define	USB_RSHIFTKEY	229
65 #define	USB_RMETAKEY	231
66 #define	USB_RALTKEY	230
67 
68 /*
69  * The keyboard would report ErrorRollOver in all array fields when
70  * the number of non-modifier keys pressed exceeds the Report Count.
71  */
72 #define	USB_ERRORROLLOVER 1
73 
74 
75 /*
76  * This defines the format of translation tables.
77  *
78  * A translation table is USB_KEYMAP_SIZE "entries", each of which is 2
79  * bytes (unsigned shorts).  The top 8 bits of each entry are decoded by
80  * a case statement in getkey.c.  If the entry is less than 0x100, it
81  * is sent out as an EUC character (possibly with bucky bits
82  * OR-ed in).  "Special" entries are 0x100 or greater, and
83  * invoke more complicated actions.
84  */
85 
86 /*
87  * HID-spec-defined report size (in bytes) for each USB HID boot-protocol
88  * mode report.
89  */
90 
91 #define	USB_KBD_BOOT_PROTOCOL_PACKET_SIZE	8
92 
93 /* definitions for various state machines */
94 #define	USBKBM_OPEN	0x00000001 /* keyboard is open for business */
95 #define	USBKBM_QWAIT	0x00000002 /* keyboard is waiting for a response */
96 
97 /*
98  * Polled key state
99  */
100 typedef struct poll_keystate {
101 	int		poll_key;		/* scancode */
102 	enum keystate   poll_state;		/* pressed or released */
103 } poll_keystate_t;
104 
105 #define	USB_POLLED_BUFFER_SIZE	20	/* # of characters in poll buffer */
106 
107 #define	USBKBM_MAXPKTSIZE	10	/* Maximum size of a packet */
108 
109 /* state structure for usbkbm */
110 typedef struct  usbkbm_state {
111 	struct kbtrans		*usbkbm_kbtrans;
112 	queue_t			*usbkbm_readq;		/* read queue */
113 	queue_t			*usbkbm_writeq;		/* write queue */
114 	int			usbkbm_flags;
115 	uint32_t		usbkbm_packet_size;	/* size usb packet */
116 	/* Pointer to the parser handle */
117 	hidparser_handle_t	usbkbm_report_descr;
118 	uint16_t		usbkbm_layout;		/* keyboard layout */
119 	/*
120 	 * Setting this indicates that the second IOCTL
121 	 * after KBD_CMD_SETLED follows
122 	 */
123 	int			usbkbm_setled_second_byte;
124 	/* Keyboard packets sent last */
125 	uchar_t			usbkbm_lastusbpacket[USBKBM_MAXPKTSIZE];
126 
127 	/* Currently processed key events of the current keyboard packet */
128 	uchar_t			usbkbm_pendingusbpacket[USBKBM_MAXPKTSIZE];
129 
130 	hid_polled_input_callback_t
131 				usbkbm_hid_callback;	/* poll information */
132 
133 	mblk_t			*usbkbm_pending_link; /* mp waiting response */
134 
135 	/* "ioctl" awaiting buffer */
136 	mblk_t			*usbkbm_streams_iocpending;
137 
138 	/* id from qbufcall on allocb failure */
139 	bufcall_id_t		usbkbm_streams_bufcallid;
140 
141 	/* Polled input information */
142 	struct cons_polledio	usbkbm_polled_info;
143 
144 	int			usbkbm_vkbd_type;
145 
146 	/* keyboard device info from hid */
147 	hid_vid_pid_t		usbkbm_vid_pid;
148 
149 	/* These entries are for polled input */
150 	uint_t		usbkbm_polled_buffer_num_characters;
151 	poll_keystate_t	usbkbm_polled_scancode_buffer[USB_POLLED_BUFFER_SIZE];
152 	poll_keystate_t	*usbkbm_polled_buffer_head;
153 	poll_keystate_t	*usbkbm_polled_buffer_tail;
154 
155 } usbkbm_state_t;
156 
157 #define	USB_PRESSED	0x00	/* key was pressed */
158 #define	USB_RELEASED	0x01	/* key was released */
159 
160 /* Sun Japanese type6 and type7 keyboards layout numbers, vid and pid */
161 #define	SUN_JAPANESE_TYPE6		271
162 #define	SUN_JAPANESE_TYPE7		15
163 #define	HID_SUN_JAPANESE_TYPE6_KBD_VID	0x0430
164 #define	HID_SUN_JAPANESE_TYPE6_KBD_PID	0x0005
165 
166 
167 /* Number of entries in the keytable */
168 #define	KEYMAP_SIZE_USB		255
169 
170 /* Size in bytes of the keytable */
171 #define	USB_KEYTABLE_SIZE	(KEYMAP_SIZE_USB * sizeof (keymap_entry_t))
172 
173 /* structure to save global state */
174 typedef struct usbkbm_save_state {
175 	/* LED state */
176 	uchar_t		usbkbm_save_led;
177 	uchar_t		usbkbm_layout;
178 
179 	/* Keymap information */
180 	struct keyboard usbkbm_save_keyindex;
181 
182 } usbkbm_save_state_t;
183 
184 /*
185  * Masks for debug printing
186  */
187 #define	PRINT_MASK_ATTA		0x00000001
188 #define	PRINT_MASK_OPEN 	0x00000002
189 #define	PRINT_MASK_CLOSE	0x00000004
190 #define	PRINT_MASK_PACKET	0x00000008
191 #define	PRINT_MASK_ALL		0xFFFFFFFF
192 
193 #define	INDEXTO_PC	1	/* To PC table */
194 #define	INDEXTO_USB	0	/* To USB table */
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif	/* _SYS_USB_USBKBM_H */
201