10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57127Ssethg * Common Development and Distribution License (the "License"). 67127Ssethg * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 229237SStrony.Zhang@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_USB_USBKBM_H 270Sstevel@tonic-gate #define _SYS_USB_USBKBM_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifdef __cplusplus 310Sstevel@tonic-gate extern "C" { 320Sstevel@tonic-gate #endif 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <sys/time.h> 350Sstevel@tonic-gate #include <sys/vuid_event.h> 360Sstevel@tonic-gate #include <sys/stream.h> 370Sstevel@tonic-gate #include <sys/kbd.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * USB keyboard LED masks (used to set LED's on USB keyboards) 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate #define USB_LED_NUM_LOCK 0x1 440Sstevel@tonic-gate #define USB_LED_CAPS_LOCK 0x2 450Sstevel@tonic-gate #define USB_LED_SCROLL_LOCK 0x4 460Sstevel@tonic-gate #define USB_LED_COMPOSE 0x8 470Sstevel@tonic-gate #define USB_LED_KANA 0x10 /* Valid only on Japanese layout */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* Modifier key masks */ 500Sstevel@tonic-gate #define USB_LCTLBIT 0x01 510Sstevel@tonic-gate #define USB_LSHIFTBIT 0x02 520Sstevel@tonic-gate #define USB_LALTBIT 0x04 530Sstevel@tonic-gate #define USB_LMETABIT 0x08 540Sstevel@tonic-gate #define USB_RCTLBIT 0x10 550Sstevel@tonic-gate #define USB_RSHIFTBIT 0x20 560Sstevel@tonic-gate #define USB_RALTBIT 0x40 570Sstevel@tonic-gate #define USB_RMETABIT 0x80 580Sstevel@tonic-gate 590Sstevel@tonic-gate #define USB_LSHIFTKEY 225 600Sstevel@tonic-gate #define USB_LCTLCKEY 224 610Sstevel@tonic-gate #define USB_LALTKEY 226 620Sstevel@tonic-gate #define USB_LMETAKEY 227 630Sstevel@tonic-gate #define USB_RCTLCKEY 228 640Sstevel@tonic-gate #define USB_RSHIFTKEY 229 650Sstevel@tonic-gate #define USB_RMETAKEY 231 660Sstevel@tonic-gate #define USB_RALTKEY 230 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * The keyboard would report ErrorRollOver in all array fields when 700Sstevel@tonic-gate * the number of non-modifier keys pressed exceeds the Report Count. 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate #define USB_ERRORROLLOVER 1 730Sstevel@tonic-gate 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * This defines the format of translation tables. 770Sstevel@tonic-gate * 780Sstevel@tonic-gate * A translation table is USB_KEYMAP_SIZE "entries", each of which is 2 790Sstevel@tonic-gate * bytes (unsigned shorts). The top 8 bits of each entry are decoded by 800Sstevel@tonic-gate * a case statement in getkey.c. If the entry is less than 0x100, it 810Sstevel@tonic-gate * is sent out as an EUC character (possibly with bucky bits 820Sstevel@tonic-gate * OR-ed in). "Special" entries are 0x100 or greater, and 830Sstevel@tonic-gate * invoke more complicated actions. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 877127Ssethg * HID-spec-defined report size (in bytes) for each USB HID boot-protocol 887127Ssethg * mode report. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate 917127Ssethg #define USB_KBD_BOOT_PROTOCOL_PACKET_SIZE 8 920Sstevel@tonic-gate 930Sstevel@tonic-gate /* definitions for various state machines */ 940Sstevel@tonic-gate #define USBKBM_OPEN 0x00000001 /* keyboard is open for business */ 950Sstevel@tonic-gate #define USBKBM_QWAIT 0x00000002 /* keyboard is waiting for a response */ 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * Polled key state 990Sstevel@tonic-gate */ 1000Sstevel@tonic-gate typedef struct poll_keystate { 1010Sstevel@tonic-gate int poll_key; /* scancode */ 1020Sstevel@tonic-gate enum keystate poll_state; /* pressed or released */ 1030Sstevel@tonic-gate } poll_keystate_t; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate #define USB_POLLED_BUFFER_SIZE 20 /* # of characters in poll buffer */ 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate #define USBKBM_MAXPKTSIZE 10 /* Maximum size of a packet */ 1080Sstevel@tonic-gate 109*9607SPengcheng.Chen@Sun.COM typedef struct usbkbm_report_format { 110*9607SPengcheng.Chen@Sun.COM uint8_t keyid; /* report id of keyboard input */ 111*9607SPengcheng.Chen@Sun.COM uint_t kpos; /* keycode offset in the keyboard data */ 112*9607SPengcheng.Chen@Sun.COM uint_t klen; /* length of keycodes */ 113*9607SPengcheng.Chen@Sun.COM uint_t tlen; /* length of the input report (inc. report id) */ 114*9607SPengcheng.Chen@Sun.COM } usbkbm_report_format_t; 115*9607SPengcheng.Chen@Sun.COM 1160Sstevel@tonic-gate /* state structure for usbkbm */ 1170Sstevel@tonic-gate typedef struct usbkbm_state { 1180Sstevel@tonic-gate struct kbtrans *usbkbm_kbtrans; 1190Sstevel@tonic-gate queue_t *usbkbm_readq; /* read queue */ 1200Sstevel@tonic-gate queue_t *usbkbm_writeq; /* write queue */ 1210Sstevel@tonic-gate int usbkbm_flags; 122*9607SPengcheng.Chen@Sun.COM 123*9607SPengcheng.Chen@Sun.COM /* Report format of keyboard data */ 124*9607SPengcheng.Chen@Sun.COM usbkbm_report_format_t usbkbm_report_format; 125*9607SPengcheng.Chen@Sun.COM 1260Sstevel@tonic-gate /* Pointer to the parser handle */ 1270Sstevel@tonic-gate hidparser_handle_t usbkbm_report_descr; 1280Sstevel@tonic-gate uint16_t usbkbm_layout; /* keyboard layout */ 1290Sstevel@tonic-gate /* 1300Sstevel@tonic-gate * Setting this indicates that the second IOCTL 1310Sstevel@tonic-gate * after KBD_CMD_SETLED follows 1320Sstevel@tonic-gate */ 1330Sstevel@tonic-gate int usbkbm_setled_second_byte; 1340Sstevel@tonic-gate /* Keyboard packets sent last */ 1350Sstevel@tonic-gate uchar_t usbkbm_lastusbpacket[USBKBM_MAXPKTSIZE]; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* Currently processed key events of the current keyboard packet */ 1380Sstevel@tonic-gate uchar_t usbkbm_pendingusbpacket[USBKBM_MAXPKTSIZE]; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate hid_polled_input_callback_t 1410Sstevel@tonic-gate usbkbm_hid_callback; /* poll information */ 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate mblk_t *usbkbm_pending_link; /* mp waiting response */ 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* "ioctl" awaiting buffer */ 1460Sstevel@tonic-gate mblk_t *usbkbm_streams_iocpending; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* id from qbufcall on allocb failure */ 1490Sstevel@tonic-gate bufcall_id_t usbkbm_streams_bufcallid; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* Polled input information */ 1520Sstevel@tonic-gate struct cons_polledio usbkbm_polled_info; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate int usbkbm_vkbd_type; 1550Sstevel@tonic-gate 156918Sqz150045 /* keyboard device info from hid */ 157918Sqz150045 hid_vid_pid_t usbkbm_vid_pid; 158918Sqz150045 1590Sstevel@tonic-gate /* These entries are for polled input */ 1600Sstevel@tonic-gate uint_t usbkbm_polled_buffer_num_characters; 1610Sstevel@tonic-gate poll_keystate_t usbkbm_polled_scancode_buffer[USB_POLLED_BUFFER_SIZE]; 1620Sstevel@tonic-gate poll_keystate_t *usbkbm_polled_buffer_head; 1630Sstevel@tonic-gate poll_keystate_t *usbkbm_polled_buffer_tail; 1640Sstevel@tonic-gate 1659237SStrony.Zhang@Sun.COM /* Boot protocol or report protocol */ 1669237SStrony.Zhang@Sun.COM uint8_t protocol; 1670Sstevel@tonic-gate } usbkbm_state_t; 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #define USB_PRESSED 0x00 /* key was pressed */ 1700Sstevel@tonic-gate #define USB_RELEASED 0x01 /* key was released */ 1710Sstevel@tonic-gate 172918Sqz150045 /* Sun Japanese type6 and type7 keyboards layout numbers, vid and pid */ 173918Sqz150045 #define SUN_JAPANESE_TYPE6 271 174918Sqz150045 #define SUN_JAPANESE_TYPE7 15 175918Sqz150045 #define HID_SUN_JAPANESE_TYPE6_KBD_VID 0x0430 176918Sqz150045 #define HID_SUN_JAPANESE_TYPE6_KBD_PID 0x0005 177918Sqz150045 178918Sqz150045 1790Sstevel@tonic-gate /* Number of entries in the keytable */ 1800Sstevel@tonic-gate #define KEYMAP_SIZE_USB 255 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* Size in bytes of the keytable */ 1830Sstevel@tonic-gate #define USB_KEYTABLE_SIZE (KEYMAP_SIZE_USB * sizeof (keymap_entry_t)) 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate /* structure to save global state */ 1860Sstevel@tonic-gate typedef struct usbkbm_save_state { 1870Sstevel@tonic-gate /* LED state */ 1880Sstevel@tonic-gate uchar_t usbkbm_save_led; 1890Sstevel@tonic-gate uchar_t usbkbm_layout; 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* Keymap information */ 1920Sstevel@tonic-gate struct keyboard usbkbm_save_keyindex; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate } usbkbm_save_state_t; 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate /* 1970Sstevel@tonic-gate * Masks for debug printing 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate #define PRINT_MASK_ATTA 0x00000001 2000Sstevel@tonic-gate #define PRINT_MASK_OPEN 0x00000002 2010Sstevel@tonic-gate #define PRINT_MASK_CLOSE 0x00000004 2020Sstevel@tonic-gate #define PRINT_MASK_PACKET 0x00000008 2030Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFF 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #define INDEXTO_PC 1 /* To PC table */ 2060Sstevel@tonic-gate #define INDEXTO_USB 0 /* To USB table */ 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate #ifdef __cplusplus 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate #endif 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate #endif /* _SYS_USB_USBKBM_H */ 213