1 /* $OpenBSD: hidkbdsc.h,v 1.3 2022/11/09 10:05:18 robert Exp $ */ 2 /* $NetBSD: hidkbdsc.h,v 1.1 2024/12/09 22:04:18 jmcneill 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 (at) 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 #include "opt_wsdisplay_compat.h" 35 36 #define MAXKEYCODE 6 37 #define MAXVARS 128 38 39 #define MAXKEYS (MAXVARS+2*MAXKEYCODE) 40 41 /* quirks */ 42 #define HIDKBD_SPUR_BUT_UP 0x001 /* spurious button up events */ 43 44 struct hidkbd_variable { 45 struct hid_location loc; 46 u_int8_t mask; 47 u_int8_t key; 48 }; 49 50 struct hidkbd_data { 51 u_int8_t keycode[MAXKEYCODE]; 52 u_int8_t var[MAXVARS]; 53 }; 54 55 struct hidkbd { 56 /* stored data */ 57 struct hidkbd_data sc_ndata; 58 struct hidkbd_data sc_odata; 59 60 /* input reports */ 61 u_int sc_nvar; 62 struct hidkbd_variable *sc_var; 63 64 struct hid_location sc_keycodeloc; 65 u_int sc_nkeycode; 66 67 /* output reports */ 68 struct hid_location sc_numloc; 69 struct hid_location sc_capsloc; 70 struct hid_location sc_scroloc; 71 struct hid_location sc_compose; 72 int sc_leds; 73 74 /* optional extra input source used by sc_munge */ 75 struct hid_location sc_fn; 76 77 /* state information */ 78 device_t sc_device; 79 device_t sc_wskbddev; 80 char sc_enabled; 81 82 char sc_console_keyboard; /* we are the console keyboard */ 83 84 char sc_debounce; /* for quirk handling */ 85 callout_t sc_delay; /* for quirk handling */ 86 struct hidkbd_data sc_data; /* for quirk handling */ 87 88 /* key repeat logic */ 89 #if defined(WSDISPLAY_COMPAT_RAWKBD) 90 int sc_rawkbd; 91 #endif /* defined(WSDISPLAY_COMPAT_RAWKBD) */ 92 93 int sc_polling; 94 int sc_npollchar; 95 u_int16_t sc_pollchars[MAXKEYS]; 96 97 void (*sc_munge)(void *, uint8_t *, u_int); 98 }; 99 100 struct hidkbd_translation { 101 uint8_t original; 102 uint8_t translation; 103 }; 104 105 int hidkbd_attach(struct device *, struct hidkbd *, int, uint32_t, 106 int, void *, int); 107 void hidkbd_attach_wskbd(struct hidkbd *, kbd_t, 108 const struct wskbd_accessops *); 109 void hidkbd_bell(u_int, u_int, u_int, int); 110 void hidkbd_cngetc(struct hidkbd *, u_int *, int *); 111 int hidkbd_detach(struct hidkbd *, int); 112 int hidkbd_enable(struct hidkbd *, int); 113 void hidkbd_input(struct hidkbd *, uint8_t *, u_int); 114 int hidkbd_ioctl(struct hidkbd *, u_long, void *, int, lwp_t *); 115 int hidkbd_set_leds(struct hidkbd *, int, uint8_t *); 116 uint8_t hidkbd_translate(const struct hidkbd_translation *, size_t, uint8_t); 117 void hidkbd_apple_munge(void *, uint8_t *, u_int); 118 void hidkbd_apple_tb_munge(void *, uint8_t *, u_int); 119 void hidkbd_apple_iso_munge(void *, uint8_t *, u_int); 120 void hidkbd_apple_mba_munge(void *, uint8_t *, u_int); 121 void hidkbd_apple_iso_mba_munge(void *, uint8_t *, u_int); 122 123 extern int hidkbd_is_console; 124