xref: /titanic_52/usr/src/uts/common/io/kb8042/kb8042.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
24 /*	  All Rights Reserved  	*/
25 
26 /*
27  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef	_KB8042_H
32 #define	_KB8042_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Messages from keyboard.
40  */
41 #define	KB_ERROR	0x00	/* Keyboard overrun or detection error */
42 #define	KB_POST_OK	0xAA	/* Sent at completion of poweron */
43 #define	KB_ECHO		0xEE	/* Response to Echo command (EE)  */
44 #define	KB_ACK		0xFA	/* Acknowledgement byte from keyboard */
45 #define	KB_POST_FAIL	0xFC	/* Power On Self Test failed */
46 #define	KB_RESEND	0xFE	/* response from keyboard to resend data */
47 #define	KB_REPLY_MAXLEN	8	/* Maximum # of bytes the keyboard can reply */
48 /*
49  * Commands to keyboard.
50  */
51 #define	KB_SET_LED	0xED	/* Tell kbd that following byte is led status */
52 #define	KB_READID	0xF2	/* command to read keyboard id */
53 #define	KB_ENABLE	0xF4	/* command to to enable keyboard */
54 #define	KB_RESET	0xFF	/* command to reset keyboard */
55 #define	KB_SET_TYPE	0xF3	/* command--next byte is typematic values */
56 #define	KB_SET_SCAN	0xF0	/* kbd command to set scan code set */
57 
58 /*
59  * LED bits
60  */
61 #define	LED_SCR		0x01	/* Flag bit for scroll lock */
62 #define	LED_CAP		0x04	/* Flag bit for cap lock */
63 #define	LED_NUM		0x02	/* Flag bit for num lock */
64 
65 /*
66  * Keyboard scan code prefixes
67  */
68 #define	KAT_BREAK	0xf0	/* first byte in two byte break sequence */
69 #define	KXT_EXTEND	0xe0	/* first byte in two byte extended sequence */
70 #define	KXT_EXTEND2	0xe1	/* Used in "Pause" sequence */
71 
72 /*
73  * Korean keyboard keys.  We handle these specially to avoid having to
74  * dramatically extend the table.
75  */
76 #define	KXT_HANGUL_HANJA	0xf1
77 #define	KXT_HANGUL		0xf2
78 
79 #ifdef _KERNEL
80 
81 struct kb8042 {
82 	kmutex_t	w_hw_mutex;	/* hardware mutex */
83 	int	w_init;		/* workstation has been initialized */
84 	queue_t	*w_qp;		/* pointer to queue for this minor device */
85 	int	w_kblayout;	/* keyboard layout code */
86 	dev_t	w_dev;		/* major/minor for this device */
87 	ddi_iblock_cookie_t	w_iblock;
88 	ddi_acc_handle_t	handle;
89 	uint8_t			*addr;
90 	int	kb_old_key_pos;	/* scancode for autorepeat filtering */
91 	struct {
92 		int desired;
93 		int commanded;
94 	}	leds;
95 	int	parse_scan_state;
96 	struct kbtrans	*hw_kbtrans;
97 	struct cons_polledio	polledio;
98 	struct {
99 		unsigned char mod1;
100 		unsigned char mod2;
101 		unsigned char trigger;
102 		boolean_t mod1_down;
103 		boolean_t mod2_down;
104 		boolean_t enabled;
105 	}		debugger;
106 	boolean_t	polled_synthetic_release_pending;
107 	int		polled_synthetic_release_key;
108 	int		simulated_kbd_type;
109 	uint32_t	init_state;
110 	int		break_received;
111 	boolean_t	suspended;
112 	int		ops;
113 	kcondvar_t	suspend_cv;
114 	kcondvar_t	ops_cv;
115 	int		acked;
116 	int		need_retry;
117 	kcondvar_t	cmd_cv;
118 };
119 
120 extern boolean_t KeyboardConvertScan(struct kb8042 *, unsigned char scan,
121 			int *keynum, enum keystate *, boolean_t *);
122 extern int KeyboardConvertScan_init(struct kb8042 *, int scanset);
123 
124 #if defined(__i386) || defined(__amd64)
125 /*
126  * We pick up the initial state of the keyboard from the BIOS state.
127  */
128 #define	BIOS_KB_FLAG		0x417	/* address of BIOS keyboard state */
129 #define	BIOS_SCROLL_STATE	0x10
130 #define	BIOS_NUM_STATE		0x20
131 #define	BIOS_CAPS_STATE		0x40
132 #endif
133 
134 /*
135  * Initialization states
136  */
137 #define	KB8042_UNINITIALIZED		0x00000000
138 #define	KB8042_MINOR_NODE_CREATED	0x00000001
139 #define	KB8042_REGS_MAPPED		0x00000002
140 #define	KB8042_HW_MUTEX_INITTED		0x00000004
141 #define	KB8042_INTR_ADDED		0x00000008
142 
143 /*
144  * Key values that map into the USB translation table in kb8042.c
145  */
146 #define	K8042_STOP	160
147 
148 #endif
149 
150 #ifdef	__cplusplus
151 }
152 #endif
153 
154 #endif /* _KB8042_H */
155