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 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #include <sys/time.h> 36 #include <sys/vuid_event.h> 37 #include <sys/stream.h> 38 #include <sys/kbd.h> 39 40 41 /* 42 * USB keyboard LED masks (used to set LED's on USB keyboards) 43 */ 44 #define USB_LED_NUM_LOCK 0x1 45 #define USB_LED_CAPS_LOCK 0x2 46 #define USB_LED_SCROLL_LOCK 0x4 47 #define USB_LED_COMPOSE 0x8 48 #define USB_LED_KANA 0x10 /* Valid only on Japanese layout */ 49 50 /* Modifier key masks */ 51 #define USB_LCTLBIT 0x01 52 #define USB_LSHIFTBIT 0x02 53 #define USB_LALTBIT 0x04 54 #define USB_LMETABIT 0x08 55 #define USB_RCTLBIT 0x10 56 #define USB_RSHIFTBIT 0x20 57 #define USB_RALTBIT 0x40 58 #define USB_RMETABIT 0x80 59 60 #define USB_LSHIFTKEY 225 61 #define USB_LCTLCKEY 224 62 #define USB_LALTKEY 226 63 #define USB_LMETAKEY 227 64 #define USB_RCTLCKEY 228 65 #define USB_RSHIFTKEY 229 66 #define USB_RMETAKEY 231 67 #define USB_RALTKEY 230 68 69 /* 70 * The keyboard would report ErrorRollOver in all array fields when 71 * the number of non-modifier keys pressed exceeds the Report Count. 72 */ 73 #define USB_ERRORROLLOVER 1 74 75 76 /* 77 * This defines the format of translation tables. 78 * 79 * A translation table is USB_KEYMAP_SIZE "entries", each of which is 2 80 * bytes (unsigned shorts). The top 8 bits of each entry are decoded by 81 * a case statement in getkey.c. If the entry is less than 0x100, it 82 * is sent out as an EUC character (possibly with bucky bits 83 * OR-ed in). "Special" entries are 0x100 or greater, and 84 * invoke more complicated actions. 85 */ 86 87 /* 88 * HID-spec-defined report size (in bytes) for each USB HID boot-protocol 89 * mode report. 90 */ 91 92 #define USB_KBD_BOOT_PROTOCOL_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