1617b9080SKazutaka YOKOTA /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4617b9080SKazutaka YOKOTA * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5617b9080SKazutaka YOKOTA * All rights reserved.
6617b9080SKazutaka YOKOTA *
7617b9080SKazutaka YOKOTA * Redistribution and use in source and binary forms, with or without
8617b9080SKazutaka YOKOTA * modification, are permitted provided that the following conditions
9617b9080SKazutaka YOKOTA * are met:
10617b9080SKazutaka YOKOTA * 1. Redistributions of source code must retain the above copyright
11617b9080SKazutaka YOKOTA * notice, this list of conditions and the following disclaimer as
12617b9080SKazutaka YOKOTA * the first lines of this file unmodified.
13617b9080SKazutaka YOKOTA * 2. Redistributions in binary form must reproduce the above copyright
14617b9080SKazutaka YOKOTA * notice, this list of conditions and the following disclaimer in the
15617b9080SKazutaka YOKOTA * documentation and/or other materials provided with the distribution.
16617b9080SKazutaka YOKOTA *
17617b9080SKazutaka YOKOTA * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18617b9080SKazutaka YOKOTA * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19617b9080SKazutaka YOKOTA * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20617b9080SKazutaka YOKOTA * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21617b9080SKazutaka YOKOTA * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22617b9080SKazutaka YOKOTA * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23617b9080SKazutaka YOKOTA * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24617b9080SKazutaka YOKOTA * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25617b9080SKazutaka YOKOTA * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26617b9080SKazutaka YOKOTA * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27617b9080SKazutaka YOKOTA */
28617b9080SKazutaka YOKOTA
29617b9080SKazutaka YOKOTA #ifndef _DEV_KBD_KBDREG_H_
30617b9080SKazutaka YOKOTA #define _DEV_KBD_KBDREG_H_
31617b9080SKazutaka YOKOTA
32cd29688eSWarner Losh #ifdef _KERNEL
33cd29688eSWarner Losh
34cd29688eSWarner Losh #include "opt_kbd.h" /* KBD_DELAY* */
35cd29688eSWarner Losh
36617b9080SKazutaka YOKOTA /* forward declarations */
37617b9080SKazutaka YOKOTA typedef struct keyboard keyboard_t;
38617b9080SKazutaka YOKOTA struct keymap;
39617b9080SKazutaka YOKOTA struct accentmap;
40617b9080SKazutaka YOKOTA struct fkeytab;
41800da3b2SKazutaka YOKOTA struct cdevsw;
42617b9080SKazutaka YOKOTA
43617b9080SKazutaka YOKOTA /* call back funcion */
44617b9080SKazutaka YOKOTA typedef int kbd_callback_func_t(keyboard_t *kbd, int event,
45617b9080SKazutaka YOKOTA void *arg);
4621d16631SKyle Evans
4721d16631SKyle Evans /* keyboard function table */
4821d16631SKyle Evans typedef int kbd_probe_t(int unit, void *arg, int flags);
4921d16631SKyle Evans typedef int kbd_init_t(int unit, keyboard_t **kbdp, void *arg,
5021d16631SKyle Evans int flags);
5121d16631SKyle Evans typedef int kbd_term_t(keyboard_t *kbd);
5221d16631SKyle Evans typedef int kbd_intr_t(keyboard_t *kbd, void *arg);
5321d16631SKyle Evans typedef int kbd_test_if_t(keyboard_t *kbd);
5421d16631SKyle Evans typedef int kbd_enable_t(keyboard_t *kbd);
5521d16631SKyle Evans typedef int kbd_disable_t(keyboard_t *kbd);
5621d16631SKyle Evans typedef int kbd_read_t(keyboard_t *kbd, int wait);
5721d16631SKyle Evans typedef int kbd_check_t(keyboard_t *kbd);
5821d16631SKyle Evans typedef u_int kbd_read_char_t(keyboard_t *kbd, int wait);
5921d16631SKyle Evans typedef int kbd_check_char_t(keyboard_t *kbd);
6021d16631SKyle Evans typedef int kbd_ioctl_t(keyboard_t *kbd, u_long cmd, caddr_t data);
6121d16631SKyle Evans typedef int kbd_lock_t(keyboard_t *kbd, int lock);
6221d16631SKyle Evans typedef void kbd_clear_state_t(keyboard_t *kbd);
6321d16631SKyle Evans typedef int kbd_get_state_t(keyboard_t *kbd, void *buf, size_t len);
6421d16631SKyle Evans typedef int kbd_set_state_t(keyboard_t *kbd, void *buf, size_t len);
6521d16631SKyle Evans typedef u_char *kbd_get_fkeystr_t(keyboard_t *kbd, int fkey,
6621d16631SKyle Evans size_t *len);
6721d16631SKyle Evans typedef int kbd_poll_mode_t(keyboard_t *kbd, int on);
6821d16631SKyle Evans typedef void kbd_diag_t(keyboard_t *kbd, int level);
6921d16631SKyle Evans
70617b9080SKazutaka YOKOTA /* event types */
71617b9080SKazutaka YOKOTA #define KBDIO_KEYINPUT 0
72617b9080SKazutaka YOKOTA #define KBDIO_UNLOADING 1
73617b9080SKazutaka YOKOTA
74617b9080SKazutaka YOKOTA typedef struct keyboard_callback {
75617b9080SKazutaka YOKOTA kbd_callback_func_t *kc_func;
76617b9080SKazutaka YOKOTA void *kc_arg;
77617b9080SKazutaka YOKOTA } keyboard_callback_t;
78617b9080SKazutaka YOKOTA
7921d16631SKyle Evans typedef struct keyboard_switch {
8021d16631SKyle Evans kbd_probe_t *probe;
8121d16631SKyle Evans kbd_init_t *init;
8221d16631SKyle Evans kbd_term_t *term;
8321d16631SKyle Evans kbd_intr_t *intr;
8421d16631SKyle Evans kbd_test_if_t *test_if;
8521d16631SKyle Evans kbd_enable_t *enable;
8621d16631SKyle Evans kbd_disable_t *disable;
8721d16631SKyle Evans kbd_read_t *read;
8821d16631SKyle Evans kbd_check_t *check;
8921d16631SKyle Evans kbd_read_char_t *read_char;
9021d16631SKyle Evans kbd_check_char_t *check_char;
9121d16631SKyle Evans kbd_ioctl_t *ioctl;
9221d16631SKyle Evans kbd_lock_t *lock;
9321d16631SKyle Evans kbd_clear_state_t *clear_state;
9421d16631SKyle Evans kbd_get_state_t *get_state;
9521d16631SKyle Evans kbd_set_state_t *set_state;
9621d16631SKyle Evans kbd_get_fkeystr_t *get_fkeystr;
9721d16631SKyle Evans kbd_poll_mode_t *poll;
9821d16631SKyle Evans kbd_diag_t *diag;
9921d16631SKyle Evans } keyboard_switch_t;
10021d16631SKyle Evans
10179876290SKyle Evans /*
10279876290SKyle Evans * Keyboard driver definition. Some of these be immutable after definition
10379876290SKyle Evans * time, e.g. one shouldn't be able to rename a driver or use a different kbdsw
10479876290SKyle Evans * entirely, but patching individual methods is acceptable.
10579876290SKyle Evans */
10621d16631SKyle Evans typedef struct keyboard_driver {
10721d16631SKyle Evans SLIST_ENTRY(keyboard_driver) link;
10879876290SKyle Evans const char * const name;
10979876290SKyle Evans keyboard_switch_t * const kbdsw;
11079876290SKyle Evans /* backdoor for the console driver */
11179876290SKyle Evans int (* const configure)(int);
1123ed7166aSKyle Evans int flags;
11321d16631SKyle Evans } keyboard_driver_t;
11421d16631SKyle Evans
1153ed7166aSKyle Evans #define KBDF_REGISTERED 0x0001
1163ed7166aSKyle Evans
117617b9080SKazutaka YOKOTA /* keyboard */
118617b9080SKazutaka YOKOTA struct keyboard {
119617b9080SKazutaka YOKOTA /* the following fields are managed by kbdio */
120617b9080SKazutaka YOKOTA int kb_index; /* kbdio index# */
121617b9080SKazutaka YOKOTA int kb_minor; /* minor number of the sub-device */
122617b9080SKazutaka YOKOTA int kb_flags; /* internal flags */
123617b9080SKazutaka YOKOTA #define KB_VALID (1 << 16) /* this entry is valid */
124617b9080SKazutaka YOKOTA #define KB_NO_DEVICE (1 << 17) /* device not present */
125617b9080SKazutaka YOKOTA #define KB_PROBED (1 << 18) /* device probed */
126617b9080SKazutaka YOKOTA #define KB_INITIALIZED (1 << 19) /* device initialized */
127617b9080SKazutaka YOKOTA #define KB_REGISTERED (1 << 20) /* device registered to kbdio */
128617b9080SKazutaka YOKOTA #define KB_BUSY (1 << 21) /* device used by a client */
129a449b18aSMaksim Yevmenkin #define KB_POLLED (1 << 22) /* device is polled */
130617b9080SKazutaka YOKOTA int kb_active; /* 0: inactive */
131617b9080SKazutaka YOKOTA void *kb_token; /* id of the current client */
132617b9080SKazutaka YOKOTA keyboard_callback_t kb_callback;/* callback function */
133617b9080SKazutaka YOKOTA
134617b9080SKazutaka YOKOTA /*
135617b9080SKazutaka YOKOTA * Device configuration flags:
136617b9080SKazutaka YOKOTA * The upper 16 bits are common between various keyboard devices.
137617b9080SKazutaka YOKOTA * The lower 16 bits are device-specific.
138617b9080SKazutaka YOKOTA */
139617b9080SKazutaka YOKOTA int kb_config;
140617b9080SKazutaka YOKOTA #define KB_CONF_PROBE_ONLY (1 << 16) /* probe only, don't initialize */
141617b9080SKazutaka YOKOTA
142617b9080SKazutaka YOKOTA /* the following fields are set up by the driver */
143617b9080SKazutaka YOKOTA char *kb_name; /* driver name */
144617b9080SKazutaka YOKOTA int kb_unit; /* unit # */
145617b9080SKazutaka YOKOTA int kb_type; /* KB_84, KB_101, KB_OTHER,... */
146617b9080SKazutaka YOKOTA int kb_io_base; /* port# if any */
147617b9080SKazutaka YOKOTA int kb_io_size; /* # of occupied port */
148617b9080SKazutaka YOKOTA int kb_led; /* LED status */
149617b9080SKazutaka YOKOTA struct keymap *kb_keymap; /* key map */
150617b9080SKazutaka YOKOTA struct accentmap *kb_accentmap; /* accent map */
151617b9080SKazutaka YOKOTA struct fkeytab *kb_fkeytab; /* function key strings */
152617b9080SKazutaka YOKOTA int kb_fkeytab_size;/* # of function key strings */
153617b9080SKazutaka YOKOTA void *kb_data; /* the driver's private data */
154e9deda23SKazutaka YOKOTA int kb_delay1;
155e9deda23SKazutaka YOKOTA int kb_delay2;
156c51978f4SMichael Paepcke #ifndef KBD_DELAY1
157c51978f4SMichael Paepcke #define KBD_DELAY1 500
158c51978f4SMichael Paepcke #endif
159c51978f4SMichael Paepcke #ifndef KBD_DELAY2
160c51978f4SMichael Paepcke #define KBD_DELAY2 100
161c51978f4SMichael Paepcke #endif
16282d654e8SKazutaka YOKOTA unsigned long kb_count; /* # of processed key strokes */
16376495257SKazutaka YOKOTA u_char kb_lastact[NUM_KEYS/2];
16489c9c53dSPoul-Henning Kamp struct cdev *kb_dev;
16521d16631SKyle Evans const keyboard_driver_t *kb_drv;
166617b9080SKazutaka YOKOTA };
167617b9080SKazutaka YOKOTA
168617b9080SKazutaka YOKOTA #define KBD_IS_VALID(k) ((k)->kb_flags & KB_VALID)
169617b9080SKazutaka YOKOTA #define KBD_VALID(k) ((k)->kb_flags |= KB_VALID)
170617b9080SKazutaka YOKOTA #define KBD_INVALID(k) ((k)->kb_flags &= ~KB_VALID)
171617b9080SKazutaka YOKOTA #define KBD_HAS_DEVICE(k) (!((k)->kb_flags & KB_NO_DEVICE))
172617b9080SKazutaka YOKOTA #define KBD_FOUND_DEVICE(k) ((k)->kb_flags &= ~KB_NO_DEVICE)
173617b9080SKazutaka YOKOTA #define KBD_IS_PROBED(k) ((k)->kb_flags & KB_PROBED)
174617b9080SKazutaka YOKOTA #define KBD_PROBE_DONE(k) ((k)->kb_flags |= KB_PROBED)
175617b9080SKazutaka YOKOTA #define KBD_IS_INITIALIZED(k) ((k)->kb_flags & KB_INITIALIZED)
176617b9080SKazutaka YOKOTA #define KBD_INIT_DONE(k) ((k)->kb_flags |= KB_INITIALIZED)
177617b9080SKazutaka YOKOTA #define KBD_IS_CONFIGURED(k) ((k)->kb_flags & KB_REGISTERED)
178617b9080SKazutaka YOKOTA #define KBD_CONFIG_DONE(k) ((k)->kb_flags |= KB_REGISTERED)
179617b9080SKazutaka YOKOTA #define KBD_IS_BUSY(k) ((k)->kb_flags & KB_BUSY)
180617b9080SKazutaka YOKOTA #define KBD_BUSY(k) ((k)->kb_flags |= KB_BUSY)
181617b9080SKazutaka YOKOTA #define KBD_UNBUSY(k) ((k)->kb_flags &= ~KB_BUSY)
182a449b18aSMaksim Yevmenkin #define KBD_IS_POLLED(k) ((k)->kb_flags & KB_POLLED)
183a449b18aSMaksim Yevmenkin #define KBD_POLL(k) ((k)->kb_flags |= KB_POLLED)
184a449b18aSMaksim Yevmenkin #define KBD_UNPOLL(k) ((k)->kb_flags &= ~KB_POLLED)
185617b9080SKazutaka YOKOTA #define KBD_IS_ACTIVE(k) ((k)->kb_active)
186617b9080SKazutaka YOKOTA #define KBD_ACTIVATE(k) (++(k)->kb_active)
187617b9080SKazutaka YOKOTA #define KBD_DEACTIVATE(k) (--(k)->kb_active)
188617b9080SKazutaka YOKOTA #define KBD_LED_VAL(k) ((k)->kb_led)
189617b9080SKazutaka YOKOTA
19058b22b9dSKyle Evans /*
19158b22b9dSKyle Evans * Keyboard disciplines: call actual handlers via kbdsw[].
19258b22b9dSKyle Evans */
19358b22b9dSKyle Evans static __inline int
kbdd_probe(keyboard_t * kbd,int unit,void * arg,int flags)19458b22b9dSKyle Evans kbdd_probe(keyboard_t *kbd, int unit, void *arg, int flags)
19558b22b9dSKyle Evans {
19658b22b9dSKyle Evans
19721d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->probe)(unit, arg, flags));
19858b22b9dSKyle Evans }
19958b22b9dSKyle Evans
20058b22b9dSKyle Evans static __inline int
kbdd_init(keyboard_t * kbd,int unit,keyboard_t ** kbdpp,void * arg,int flags)20158b22b9dSKyle Evans kbdd_init(keyboard_t *kbd, int unit, keyboard_t **kbdpp, void *arg, int flags)
20258b22b9dSKyle Evans {
20358b22b9dSKyle Evans
20421d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->init)(unit, kbdpp, arg, flags));
20558b22b9dSKyle Evans }
20658b22b9dSKyle Evans
20758b22b9dSKyle Evans static __inline int
kbdd_term(keyboard_t * kbd)20858b22b9dSKyle Evans kbdd_term(keyboard_t *kbd)
20958b22b9dSKyle Evans {
21058b22b9dSKyle Evans
21121d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->term)(kbd));
21258b22b9dSKyle Evans }
21358b22b9dSKyle Evans
21458b22b9dSKyle Evans static __inline int
kbdd_intr(keyboard_t * kbd,void * arg)21558b22b9dSKyle Evans kbdd_intr(keyboard_t *kbd, void *arg)
21658b22b9dSKyle Evans {
21758b22b9dSKyle Evans
21821d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->intr)(kbd, arg));
21958b22b9dSKyle Evans }
22058b22b9dSKyle Evans
22158b22b9dSKyle Evans static __inline int
kbdd_test_if(keyboard_t * kbd)22258b22b9dSKyle Evans kbdd_test_if(keyboard_t *kbd)
22358b22b9dSKyle Evans {
22458b22b9dSKyle Evans
22521d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->test_if)(kbd));
22658b22b9dSKyle Evans }
22758b22b9dSKyle Evans
22858b22b9dSKyle Evans static __inline int
kbdd_enable(keyboard_t * kbd)22958b22b9dSKyle Evans kbdd_enable(keyboard_t *kbd)
23058b22b9dSKyle Evans {
23158b22b9dSKyle Evans
23221d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->enable)(kbd));
23358b22b9dSKyle Evans }
23458b22b9dSKyle Evans
23558b22b9dSKyle Evans static __inline int
kbdd_disable(keyboard_t * kbd)23658b22b9dSKyle Evans kbdd_disable(keyboard_t *kbd)
23758b22b9dSKyle Evans {
23858b22b9dSKyle Evans
23921d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->disable)(kbd));
24058b22b9dSKyle Evans }
24158b22b9dSKyle Evans
24258b22b9dSKyle Evans static __inline int
kbdd_read(keyboard_t * kbd,int wait)24358b22b9dSKyle Evans kbdd_read(keyboard_t *kbd, int wait)
24458b22b9dSKyle Evans {
24558b22b9dSKyle Evans
24621d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->read)(kbd, wait));
24758b22b9dSKyle Evans }
24858b22b9dSKyle Evans
24958b22b9dSKyle Evans static __inline int
kbdd_check(keyboard_t * kbd)25058b22b9dSKyle Evans kbdd_check(keyboard_t *kbd)
25158b22b9dSKyle Evans {
25258b22b9dSKyle Evans
25321d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->check)(kbd));
25458b22b9dSKyle Evans }
25558b22b9dSKyle Evans
25658b22b9dSKyle Evans static __inline u_int
kbdd_read_char(keyboard_t * kbd,int wait)25758b22b9dSKyle Evans kbdd_read_char(keyboard_t *kbd, int wait)
25858b22b9dSKyle Evans {
25958b22b9dSKyle Evans
26021d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->read_char)(kbd, wait));
26158b22b9dSKyle Evans }
26258b22b9dSKyle Evans
26358b22b9dSKyle Evans static __inline int
kbdd_check_char(keyboard_t * kbd)26458b22b9dSKyle Evans kbdd_check_char(keyboard_t *kbd)
26558b22b9dSKyle Evans {
26658b22b9dSKyle Evans
26721d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->check_char)(kbd));
26858b22b9dSKyle Evans }
26958b22b9dSKyle Evans
27058b22b9dSKyle Evans static __inline int
kbdd_ioctl(keyboard_t * kbd,u_long cmd,caddr_t data)27158b22b9dSKyle Evans kbdd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data)
27258b22b9dSKyle Evans {
27358b22b9dSKyle Evans
27458b22b9dSKyle Evans if (kbd == NULL)
27558b22b9dSKyle Evans return (ENODEV);
27621d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->ioctl)(kbd, cmd, data));
27758b22b9dSKyle Evans }
27858b22b9dSKyle Evans
27958b22b9dSKyle Evans static __inline int
kbdd_lock(keyboard_t * kbd,int lock)28058b22b9dSKyle Evans kbdd_lock(keyboard_t *kbd, int lock)
28158b22b9dSKyle Evans {
28258b22b9dSKyle Evans
28321d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->lock)(kbd, lock));
28458b22b9dSKyle Evans }
28558b22b9dSKyle Evans
28658b22b9dSKyle Evans static __inline void
kbdd_clear_state(keyboard_t * kbd)28758b22b9dSKyle Evans kbdd_clear_state(keyboard_t *kbd)
28858b22b9dSKyle Evans {
28958b22b9dSKyle Evans
29021d16631SKyle Evans (*kbd->kb_drv->kbdsw->clear_state)(kbd);
29158b22b9dSKyle Evans }
29258b22b9dSKyle Evans
29358b22b9dSKyle Evans static __inline int
kbdd_get_state(keyboard_t * kbd,void * buf,int len)29458b22b9dSKyle Evans kbdd_get_state(keyboard_t *kbd, void *buf, int len)
29558b22b9dSKyle Evans {
29658b22b9dSKyle Evans
29721d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->get_state)(kbd, buf, len));
29858b22b9dSKyle Evans }
29958b22b9dSKyle Evans
30058b22b9dSKyle Evans static __inline int
kbdd_set_state(keyboard_t * kbd,void * buf,int len)30158b22b9dSKyle Evans kbdd_set_state(keyboard_t *kbd, void *buf, int len)
30258b22b9dSKyle Evans {
30358b22b9dSKyle Evans
30421d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->set_state)(kbd, buf, len));
30558b22b9dSKyle Evans }
30658b22b9dSKyle Evans
30758b22b9dSKyle Evans static __inline u_char *
kbdd_get_fkeystr(keyboard_t * kbd,int fkey,size_t * len)30858b22b9dSKyle Evans kbdd_get_fkeystr(keyboard_t *kbd, int fkey, size_t *len)
30958b22b9dSKyle Evans {
31058b22b9dSKyle Evans
31121d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->get_fkeystr)(kbd, fkey, len));
31258b22b9dSKyle Evans }
31358b22b9dSKyle Evans
31458b22b9dSKyle Evans static __inline int
kbdd_poll(keyboard_t * kbd,int on)31558b22b9dSKyle Evans kbdd_poll(keyboard_t *kbd, int on)
31658b22b9dSKyle Evans {
31758b22b9dSKyle Evans
31821d16631SKyle Evans return ((*kbd->kb_drv->kbdsw->poll)(kbd, on));
31958b22b9dSKyle Evans }
32058b22b9dSKyle Evans
32158b22b9dSKyle Evans static __inline void
kbdd_diag(keyboard_t * kbd,int level)32258b22b9dSKyle Evans kbdd_diag(keyboard_t *kbd, int level)
32358b22b9dSKyle Evans {
32458b22b9dSKyle Evans
32521d16631SKyle Evans (*kbd->kb_drv->kbdsw->diag)(kbd, level);
32658b22b9dSKyle Evans }
32758b22b9dSKyle Evans
328617b9080SKazutaka YOKOTA #define KEYBOARD_DRIVER(name, sw, config) \
329e9deda23SKazutaka YOKOTA static struct keyboard_driver name##_kbd_driver = { \
3307a4803c7SKazutaka YOKOTA { NULL }, #name, &sw, config \
331617b9080SKazutaka YOKOTA }; \
332e9deda23SKazutaka YOKOTA DATA_SET(kbddriver_set, name##_kbd_driver);
333617b9080SKazutaka YOKOTA
334617b9080SKazutaka YOKOTA /* functions for the keyboard driver */
3357a4803c7SKazutaka YOKOTA int kbd_add_driver(keyboard_driver_t *driver);
3367a4803c7SKazutaka YOKOTA int kbd_delete_driver(keyboard_driver_t *driver);
337617b9080SKazutaka YOKOTA int kbd_register(keyboard_t *kbd);
338617b9080SKazutaka YOKOTA int kbd_unregister(keyboard_t *kbd);
339617b9080SKazutaka YOKOTA keyboard_switch_t *kbd_get_switch(char *driver);
340617b9080SKazutaka YOKOTA void kbd_init_struct(keyboard_t *kbd, char *name, int type,
341617b9080SKazutaka YOKOTA int unit, int config, int port,
342617b9080SKazutaka YOKOTA int port_size);
343617b9080SKazutaka YOKOTA void kbd_set_maps(keyboard_t *kbd, struct keymap *keymap,
344617b9080SKazutaka YOKOTA struct accentmap *accmap,
345617b9080SKazutaka YOKOTA struct fkeytab *fkeymap, int fkeymap_size);
346617b9080SKazutaka YOKOTA
347617b9080SKazutaka YOKOTA /* functions for the keyboard client */
348617b9080SKazutaka YOKOTA int kbd_allocate(char *driver, int unit, void *id,
349617b9080SKazutaka YOKOTA kbd_callback_func_t *func, void *arg);
350617b9080SKazutaka YOKOTA int kbd_release(keyboard_t *kbd, void *id);
351617b9080SKazutaka YOKOTA int kbd_change_callback(keyboard_t *kbd, void *id,
352617b9080SKazutaka YOKOTA kbd_callback_func_t *func, void *arg);
353617b9080SKazutaka YOKOTA int kbd_find_keyboard(char *driver, int unit);
35404551c6cSMaksim Yevmenkin int kbd_find_keyboard2(char *driver, int unit, int index);
355617b9080SKazutaka YOKOTA keyboard_t *kbd_get_keyboard(int index);
356617b9080SKazutaka YOKOTA
357617b9080SKazutaka YOKOTA /* a back door for the console driver to tickle the keyboard driver XXX */
358617b9080SKazutaka YOKOTA int kbd_configure(int flags);
359617b9080SKazutaka YOKOTA /* see `kb_config' above for flag bit definitions */
360617b9080SKazutaka YOKOTA
36148f2b006SVladimir Kondratyev /* evdev2kbd mappings */
36248f2b006SVladimir Kondratyev void kbd_ev_event(keyboard_t *kbd, uint16_t type,
36348f2b006SVladimir Kondratyev uint16_t code, int32_t value);
36448f2b006SVladimir Kondratyev
365617b9080SKazutaka YOKOTA #ifdef KBD_INSTALL_CDEV
366617b9080SKazutaka YOKOTA
367617b9080SKazutaka YOKOTA /* virtual keyboard cdev driver functions */
368800da3b2SKazutaka YOKOTA int kbd_attach(keyboard_t *kbd);
369800da3b2SKazutaka YOKOTA int kbd_detach(keyboard_t *kbd);
370617b9080SKazutaka YOKOTA
371617b9080SKazutaka YOKOTA #endif /* KBD_INSTALL_CDEV */
372617b9080SKazutaka YOKOTA
373617b9080SKazutaka YOKOTA /* generic low-level keyboard functions */
374617b9080SKazutaka YOKOTA
375617b9080SKazutaka YOKOTA /* shift key state */
376617b9080SKazutaka YOKOTA #define SHIFTS1 (1 << 16)
377617b9080SKazutaka YOKOTA #define SHIFTS2 (1 << 17)
378617b9080SKazutaka YOKOTA #define SHIFTS (SHIFTS1 | SHIFTS2)
379617b9080SKazutaka YOKOTA #define CTLS1 (1 << 18)
380617b9080SKazutaka YOKOTA #define CTLS2 (1 << 19)
381617b9080SKazutaka YOKOTA #define CTLS (CTLS1 | CTLS2)
382617b9080SKazutaka YOKOTA #define ALTS1 (1 << 20)
383617b9080SKazutaka YOKOTA #define ALTS2 (1 << 21)
384617b9080SKazutaka YOKOTA #define ALTS (ALTS1 | ALTS2)
385617b9080SKazutaka YOKOTA #define AGRS1 (1 << 22)
386617b9080SKazutaka YOKOTA #define AGRS2 (1 << 23)
387617b9080SKazutaka YOKOTA #define AGRS (AGRS1 | AGRS2)
388617b9080SKazutaka YOKOTA #define METAS1 (1 << 24)
389617b9080SKazutaka YOKOTA #define METAS2 (1 << 25)
390617b9080SKazutaka YOKOTA #define METAS (METAS1 | METAS2)
391617b9080SKazutaka YOKOTA #define NLKDOWN (1 << 26)
392617b9080SKazutaka YOKOTA #define SLKDOWN (1 << 27)
393617b9080SKazutaka YOKOTA #define CLKDOWN (1 << 28)
394617b9080SKazutaka YOKOTA #define ALKDOWN (1 << 29)
3957642cc82SKazutaka YOKOTA #define SHIFTAON (1 << 30)
39600d25f51SPoul-Henning Kamp /* lock key state (defined in sys/kbio.h) */
397617b9080SKazutaka YOKOTA /*
398617b9080SKazutaka YOKOTA #define CLKED LED_CAP
399617b9080SKazutaka YOKOTA #define NLKED LED_NUM
400617b9080SKazutaka YOKOTA #define SLKED LED_SCR
401617b9080SKazutaka YOKOTA #define ALKED (1 << 3)
402617b9080SKazutaka YOKOTA #define LOCK_MASK (CLKED | NLKED | SLKED | ALKED)
403617b9080SKazutaka YOKOTA #define LED_CAP (1 << 0)
404617b9080SKazutaka YOKOTA #define LED_NUM (1 << 1)
405617b9080SKazutaka YOKOTA #define LED_SCR (1 << 2)
406617b9080SKazutaka YOKOTA #define LED_MASK (LED_CAP | LED_NUM | LED_SCR)
407617b9080SKazutaka YOKOTA */
408617b9080SKazutaka YOKOTA
4093ed7166aSKyle Evans /* Initialization for the kbd layer, performed by cninit. */
4103ed7166aSKyle Evans void kbdinit(void);
4113ed7166aSKyle Evans
412617b9080SKazutaka YOKOTA int genkbd_commonioctl(keyboard_t *kbd, u_long cmd, caddr_t arg);
4139a1d7da7SKazutaka YOKOTA int genkbd_keyaction(keyboard_t *kbd, int keycode, int up,
414617b9080SKazutaka YOKOTA int *shiftstate, int *accents);
415617b9080SKazutaka YOKOTA
416cd29688eSWarner Losh #endif
417617b9080SKazutaka YOKOTA #endif /* !_DEV_KBD_KBDREG_H_ */
418