xref: /illumos-gate/usr/src/uts/common/sys/usb/clients/usbkbm/usbkbm.h (revision 827f5d6bce8ec1c2fd4f4b5b6351acce7dbd41ca)
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 2009 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 	/* Boot protocol or report protocol */
156 	uint8_t	protocol;
157 } usbkbm_state_t;
158 
159 #define	USB_PRESSED	0x00	/* key was pressed */
160 #define	USB_RELEASED	0x01	/* key was released */
161 
162 /* Sun Japanese type6 and type7 keyboards layout numbers, vid and pid */
163 #define	SUN_JAPANESE_TYPE6		271
164 #define	SUN_JAPANESE_TYPE7		15
165 #define	HID_SUN_JAPANESE_TYPE6_KBD_VID	0x0430
166 #define	HID_SUN_JAPANESE_TYPE6_KBD_PID	0x0005
167 
168 
169 /* Number of entries in the keytable */
170 #define	KEYMAP_SIZE_USB		255
171 
172 /* Size in bytes of the keytable */
173 #define	USB_KEYTABLE_SIZE	(KEYMAP_SIZE_USB * sizeof (keymap_entry_t))
174 
175 /* structure to save global state */
176 typedef struct usbkbm_save_state {
177 	/* LED state */
178 	uchar_t		usbkbm_save_led;
179 	uchar_t		usbkbm_layout;
180 
181 	/* Keymap information */
182 	struct keyboard usbkbm_save_keyindex;
183 
184 } usbkbm_save_state_t;
185 
186 /*
187  * Masks for debug printing
188  */
189 #define	PRINT_MASK_ATTA		0x00000001
190 #define	PRINT_MASK_OPEN 	0x00000002
191 #define	PRINT_MASK_CLOSE	0x00000004
192 #define	PRINT_MASK_PACKET	0x00000008
193 #define	PRINT_MASK_ALL		0xFFFFFFFF
194 
195 #define	INDEXTO_PC	1	/* To PC table */
196 #define	INDEXTO_USB	0	/* To USB table */
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif	/* _SYS_USB_USBKBM_H */
203