1/*	$OpenBSD: hidkbdsc.h,v 1.3 2022/11/09 10:05:18 robert Exp $	*/
2/*      $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $        */
3
4/*
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#define MAXKEYCODE 6
35#define MAXVARS 128
36
37#define MAXKEYS (MAXVARS+2*MAXKEYCODE)
38
39/* quirks */
40#define HIDKBD_SPUR_BUT_UP 0x001 /* spurious button up events */
41
42struct hidkbd_variable {
43	struct hid_location loc;
44	u_int8_t	mask;
45	u_int8_t	key;
46};
47
48struct hidkbd_data {
49	u_int8_t	keycode[MAXKEYCODE];
50	u_int8_t	var[MAXVARS];
51};
52
53struct hidkbd {
54	/* stored data */
55	struct hidkbd_data sc_ndata;
56	struct hidkbd_data sc_odata;
57
58	/* input reports */
59	u_int sc_nvar;
60	struct hidkbd_variable *sc_var;
61
62	struct hid_location sc_keycodeloc;
63	u_int sc_nkeycode;
64
65	/* output reports */
66	struct hid_location sc_numloc;
67	struct hid_location sc_capsloc;
68	struct hid_location sc_scroloc;
69	struct hid_location sc_compose;
70	int sc_leds;
71
72	/* optional extra input source used by sc_munge */
73	struct hid_location sc_fn;
74
75	/* state information */
76	struct device *sc_device;
77	struct device *sc_wskbddev;
78	char sc_enabled;
79
80	char sc_console_keyboard;	/* we are the console keyboard */
81
82	char sc_debounce;		/* for quirk handling */
83	struct timeout sc_delay;	/* for quirk handling */
84	struct hidkbd_data sc_data;	/* for quirk handling */
85
86	/* key repeat logic */
87#if defined(WSDISPLAY_COMPAT_RAWKBD)
88	int sc_rawkbd;
89#endif /* defined(WSDISPLAY_COMPAT_RAWKBD) */
90
91	int sc_polling;
92	int sc_npollchar;
93	u_int16_t sc_pollchars[MAXKEYS];
94
95	void (*sc_munge)(void *, uint8_t *, u_int);
96};
97
98struct hidkbd_translation {
99	uint8_t original;
100	uint8_t translation;
101};
102
103int	hidkbd_attach(struct device *, struct hidkbd *, int, uint32_t,
104	    int, void *, int);
105void	hidkbd_attach_wskbd(struct hidkbd *, kbd_t,
106	    const struct wskbd_accessops *);
107void	hidkbd_bell(u_int, u_int, u_int, int);
108void	hidkbd_cngetc(struct hidkbd *, u_int *, int *);
109int	hidkbd_detach(struct hidkbd *, int);
110int	hidkbd_enable(struct hidkbd *, int);
111void	hidkbd_input(struct hidkbd *, uint8_t *, u_int);
112int	hidkbd_ioctl(struct hidkbd *, u_long, caddr_t, int, struct proc *);
113int	hidkbd_set_leds(struct hidkbd *, int, uint8_t *);
114uint8_t	hidkbd_translate(const struct hidkbd_translation *, size_t, uint8_t);
115void	hidkbd_apple_munge(void *, uint8_t *, u_int);
116void	hidkbd_apple_tb_munge(void *, uint8_t *, u_int);
117void	hidkbd_apple_iso_munge(void *, uint8_t *, u_int);
118void	hidkbd_apple_mba_munge(void *, uint8_t *, u_int);
119void	hidkbd_apple_iso_mba_munge(void *, uint8_t *, u_int);
120
121extern int hidkbd_is_console;
122