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