xref: /illumos-gate/usr/src/uts/common/io/kb8042/kb8042.h (revision fd9cb95c)
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 /*	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 2005 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 };
115 
116 #define	KB_COMMAND_STATE_IDLE	0
117 #define	KB_COMMAND_STATE_LED	1
118 #define	KB_COMMAND_STATE_WAIT	2
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(i86pc)
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