2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/kbd/kbdreg.h,v 1.9.2.2 2001/07/30 16:46:44 yokota Exp $
27 * $DragonFly: src/sys/dev/misc/kbd/kbdreg.h,v 1.6 2007/06/06 18:49:27 dillon Exp $
30 #ifndef _DEV_KBD_KBDREG_H_
31 #define _DEV_KBD_KBDREG_H_
33 /* forward declarations */
34 typedef struct keyboard keyboard_t
;
40 /* call back funcion */
41 typedef int kbd_callback_func_t(keyboard_t
*kbd
, int event
,
44 #define KBDIO_KEYINPUT 0
45 #define KBDIO_UNLOADING 1
47 typedef struct keyboard_callback
{
48 kbd_callback_func_t
*kc_func
;
50 } keyboard_callback_t
;
54 /* the following fields are managed by kbdio */
55 int kb_index
; /* kbdio index# */
56 int kb_minor
; /* minor number of the sub-device */
57 int kb_flags
; /* internal flags */
58 cdev_t kb_dev
; /* related devfs dev */
59 #define KB_VALID (1 << 16) /* this entry is valid */
60 #define KB_NO_DEVICE (1 << 17) /* device not present */
61 #define KB_PROBED (1 << 18) /* device probed */
62 #define KB_INITIALIZED (1 << 19) /* device initialized */
63 #define KB_REGISTERED (1 << 20) /* device registered to kbdio */
64 #define KB_BUSY (1 << 21) /* device used by a client */
65 int kb_active
; /* 0: inactive */
66 void *kb_token
; /* id of the current client */
67 keyboard_callback_t kb_callback
;/* callback function */
70 * Device configuration flags:
71 * The upper 16 bits are common between various keyboard devices.
72 * The lower 16 bits are device-specific.
75 #define KB_CONF_PROBE_ONLY (1 << 16) /* probe only, don't initialize */
77 /* the following fields are set up by the driver */
78 char *kb_name
; /* driver name */
79 int kb_unit
; /* unit # */
80 int kb_type
; /* KB_84, KB_101, KB_OTHER,... */
81 int kb_io_base
; /* port# if any */
82 int kb_io_size
; /* # of occupied port */
83 int kb_led
; /* LED status */
84 int kb_savemode
; /* device specific (used by usb) */
85 struct keymap
*kb_keymap
; /* key map */
86 struct accentmap
*kb_accentmap
; /* accent map */
87 struct fkeytab
*kb_fkeytab
; /* function key strings */
88 int kb_fkeytab_size
;/* # of function key strings */
89 void *kb_data
; /* the driver's private data */
94 unsigned long kb_count
; /* # of processed key strokes */
95 int kb_pref
; /* keyboard preference */
96 u_char kb_lastact
[NUM_KEYS
/2];
97 struct callout kb_atkbd_timeout_ch
;
100 #define KBD_IS_VALID(k) ((k)->kb_flags & KB_VALID)
101 #define KBD_VALID(k) ((k)->kb_flags |= KB_VALID)
102 #define KBD_INVALID(k) ((k)->kb_flags &= ~KB_VALID)
103 #define KBD_HAS_DEVICE(k) (!((k)->kb_flags & KB_NO_DEVICE))
104 #define KBD_FOUND_DEVICE(k) ((k)->kb_flags &= ~KB_NO_DEVICE)
105 #define KBD_LOST_DEVICE(k) ((k)->kb_flags |= KB_NO_DEVICE)
106 #define KBD_IS_PROBED(k) ((k)->kb_flags & KB_PROBED)
107 #define KBD_PROBE_DONE(k) ((k)->kb_flags |= KB_PROBED)
108 #define KBD_LOST_PROBE(k) ((k)->kb_flags &= ~KB_PROBED)
109 #define KBD_IS_INITIALIZED(k) ((k)->kb_flags & KB_INITIALIZED)
110 #define KBD_INIT_DONE(k) ((k)->kb_flags |= KB_INITIALIZED)
111 #define KBD_LOST_INIT(k) ((k)->kb_flags &= ~KB_INITIALIZED)
112 #define KBD_IS_CONFIGURED(k) ((k)->kb_flags & KB_REGISTERED)
113 #define KBD_CONFIG_DONE(k) ((k)->kb_flags |= KB_REGISTERED)
114 #define KBD_IS_BUSY(k) ((k)->kb_flags & KB_BUSY)
115 #define KBD_BUSY(k) ((k)->kb_flags |= KB_BUSY)
116 #define KBD_UNBUSY(k) ((k)->kb_flags &= ~KB_BUSY)
117 #define KBD_IS_ACTIVE(k) ((k)->kb_active)
118 #define KBD_ACTIVATE(k) (++(k)->kb_active)
119 #define KBD_DEACTIVATE(k) (--(k)->kb_active)
120 #define KBD_LED_VAL(k) ((k)->kb_led)
122 /* keyboard function table */
123 typedef int kbd_probe_t(int unit
, void *arg
, int flags
);
124 typedef int kbd_init_t(int unit
, keyboard_t
**kbdp
, void *arg
,
126 typedef int kbd_term_t(keyboard_t
*kbd
);
127 typedef int kbd_intr_t(keyboard_t
*kbd
, void *arg
);
128 typedef int kbd_test_if_t(keyboard_t
*kbd
);
129 typedef int kbd_enable_t(keyboard_t
*kbd
);
130 typedef int kbd_disable_t(keyboard_t
*kbd
);
131 typedef int kbd_read_t(keyboard_t
*kbd
, int wait
);
132 typedef int kbd_check_t(keyboard_t
*kbd
);
133 typedef u_int
kbd_read_char_t(keyboard_t
*kbd
, int wait
);
134 typedef int kbd_check_char_t(keyboard_t
*kbd
);
135 typedef int kbd_ioctl_t(keyboard_t
*kbd
, u_long cmd
, caddr_t data
);
136 typedef int kbd_lock_t(keyboard_t
*kbd
, int lock
);
137 typedef void kbd_clear_state_t(keyboard_t
*kbd
);
138 typedef int kbd_get_state_t(keyboard_t
*kbd
, void *buf
, size_t len
);
139 typedef int kbd_set_state_t(keyboard_t
*kbd
, void *buf
, size_t len
);
140 typedef u_char
*kbd_get_fkeystr_t(keyboard_t
*kbd
, int fkey
,
142 typedef int kbd_poll_mode_t(keyboard_t
*kbd
, int on
);
143 typedef void kbd_diag_t(keyboard_t
*kbd
, int level
);
145 typedef struct keyboard_switch
{
150 kbd_test_if_t
*test_if
;
151 kbd_enable_t
*enable
;
152 kbd_disable_t
*disable
;
155 kbd_read_char_t
*read_char
;
156 kbd_check_char_t
*check_char
;
159 kbd_clear_state_t
*clear_state
;
160 kbd_get_state_t
*get_state
;
161 kbd_set_state_t
*set_state
;
162 kbd_get_fkeystr_t
*get_fkeystr
;
163 kbd_poll_mode_t
*poll
;
167 /* keyboard driver */
168 typedef struct keyboard_driver
{
169 SLIST_ENTRY(keyboard_driver
) link
;
171 keyboard_switch_t
*kbdsw
;
172 int (*configure
)(int); /* backdoor for the console driver */
177 #define KEYBOARD_DRIVER(name, sw, config) \
178 static struct keyboard_driver name##_kbd_driver = { \
179 { NULL }, #name, &sw, config \
181 DATA_SET(kbddriver_set, name##_kbd_driver);
183 /* global variables */
184 extern keyboard_switch_t
**kbdsw
;
186 /* functions for the keyboard driver */
187 int kbd_add_driver(keyboard_driver_t
*driver
);
188 int kbd_delete_driver(keyboard_driver_t
*driver
);
189 int kbd_register(keyboard_t
*kbd
);
190 int kbd_unregister(keyboard_t
*kbd
);
191 keyboard_switch_t
*kbd_get_switch(char *driver
);
192 void kbd_init_struct(keyboard_t
*kbd
, char *name
, int type
,
193 int unit
, int config
, int pref
,
194 int port
, int port_size
);
195 void kbd_reinit_struct(keyboard_t
*kbd
,
196 int config
, int pref
);
197 void kbd_set_maps(keyboard_t
*kbd
, struct keymap
*keymap
,
198 struct accentmap
*accmap
,
199 struct fkeytab
*fkeymap
, int fkeymap_size
);
201 /* functions for the keyboard client */
202 int kbd_allocate(char *driver
, int unit
, void *id
,
203 kbd_callback_func_t
*func
, void *arg
);
204 int kbd_release(keyboard_t
*kbd
, void *id
);
205 int kbd_change_callback(keyboard_t
*kbd
, void *id
,
206 kbd_callback_func_t
*func
, void *arg
);
207 int kbd_find_keyboard(char *driver
, int unit
);
208 keyboard_t
*kbd_get_keyboard(int index
);
210 /* a back door for the console driver to tickle the keyboard driver XXX */
211 int kbd_configure(int flags
);
212 /* see `kb_config' above for flag bit definitions */
214 #ifdef KBD_INSTALL_CDEV
216 /* virtual keyboard cdev driver functions */
217 int kbd_attach(keyboard_t
*kbd
);
218 int kbd_detach(keyboard_t
*kbd
);
220 #endif /* KBD_INSTALL_CDEV */
222 /* generic low-level keyboard functions */
224 /* shift key state */
225 #define SHIFTS1 (1 << 16)
226 #define SHIFTS2 (1 << 17)
227 #define SHIFTS (SHIFTS1 | SHIFTS2)
228 #define CTLS1 (1 << 18)
229 #define CTLS2 (1 << 19)
230 #define CTLS (CTLS1 | CTLS2)
231 #define ALTS1 (1 << 20)
232 #define ALTS2 (1 << 21)
233 #define ALTS (ALTS1 | ALTS2)
234 #define AGRS1 (1 << 22)
235 #define AGRS2 (1 << 23)
236 #define AGRS (AGRS1 | AGRS2)
237 #define METAS1 (1 << 24)
238 #define METAS2 (1 << 25)
239 #define METAS (METAS1 | METAS2)
240 #define NLKDOWN (1 << 26)
241 #define SLKDOWN (1 << 27)
242 #define CLKDOWN (1 << 28)
243 #define ALKDOWN (1 << 29)
244 #define SHIFTAON (1 << 30)
245 /* lock key state (defined in machine/console.h) */
247 #define CLKED LED_CAP
248 #define NLKED LED_NUM
249 #define SLKED LED_SCR
250 #define ALKED (1 << 3)
251 #define LOCK_MASK (CLKED | NLKED | SLKED | ALKED)
252 #define LED_CAP (1 << 0)
253 #define LED_NUM (1 << 1)
254 #define LED_SCR (1 << 2)
255 #define LED_MASK (LED_CAP | LED_NUM | LED_SCR)
258 #define KB_PRI_ATKBD 50
259 #define KB_PRI_USB 60
261 kbd_get_fkeystr_t genkbd_get_fkeystr
;
262 kbd_diag_t genkbd_diag
;
264 int genkbd_commonioctl(keyboard_t
*kbd
, u_long cmd
, caddr_t arg
);
265 int genkbd_keyaction(keyboard_t
*kbd
, int keycode
, int up
,
266 int *shiftstate
, int *accents
);
270 #endif /* !_DEV_KBD_KBDREG_H_ */