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