1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1996-1999 5 * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp) 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote 17 * products derived from this software without specific prior written 18 * permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $FreeBSD$ 33 * from kbdio.h,v 1.8 1998/09/25 11:55:46 yokota Exp 34 */ 35 36 #ifndef _DEV_ATKBDC_ATKBDCREG_H_ 37 #define _DEV_ATKBDC_ATKBDCREG_H_ 38 39 #include "opt_kbd.h" /* Structures depend on the value if KBDIO_DEBUG */ 40 41 /* constants */ 42 43 /* I/O ports */ 44 #define KBD_STATUS_PORT 4 /* status port, read */ 45 #define KBD_COMMAND_PORT 4 /* controller command port, write */ 46 #define KBD_DATA_PORT 0 /* data port, read/write 47 * also used as keyboard command 48 * and mouse command port 49 */ 50 51 /* controller commands (sent to KBD_COMMAND_PORT) */ 52 #define KBDC_SET_COMMAND_BYTE 0x0060 53 #define KBDC_GET_COMMAND_BYTE 0x0020 54 #define KBDC_WRITE_TO_AUX 0x00d4 55 #define KBDC_DISABLE_AUX_PORT 0x00a7 56 #define KBDC_ENABLE_AUX_PORT 0x00a8 57 #define KBDC_TEST_AUX_PORT 0x00a9 58 #define KBDC_DIAGNOSE 0x00aa 59 #define KBDC_TEST_KBD_PORT 0x00ab 60 #define KBDC_DISABLE_KBD_PORT 0x00ad 61 #define KBDC_ENABLE_KBD_PORT 0x00ae 62 63 /* controller command byte (set by KBDC_SET_COMMAND_BYTE) */ 64 #define KBD_TRANSLATION 0x0040 65 #define KBD_RESERVED_BITS 0x0004 66 #define KBD_OVERRIDE_KBD_LOCK 0x0008 67 #define KBD_ENABLE_KBD_PORT 0x0000 68 #define KBD_DISABLE_KBD_PORT 0x0010 69 #define KBD_ENABLE_AUX_PORT 0x0000 70 #define KBD_DISABLE_AUX_PORT 0x0020 71 #define KBD_ENABLE_AUX_INT 0x0002 72 #define KBD_DISABLE_AUX_INT 0x0000 73 #define KBD_ENABLE_KBD_INT 0x0001 74 #define KBD_DISABLE_KBD_INT 0x0000 75 #define KBD_KBD_CONTROL_BITS (KBD_DISABLE_KBD_PORT | KBD_ENABLE_KBD_INT) 76 #define KBD_AUX_CONTROL_BITS (KBD_DISABLE_AUX_PORT | KBD_ENABLE_AUX_INT) 77 78 /* keyboard device commands (sent to KBD_DATA_PORT) */ 79 #define KBDC_RESET_KBD 0x00ff 80 #define KBDC_ENABLE_KBD 0x00f4 81 #define KBDC_DISABLE_KBD 0x00f5 82 #define KBDC_SET_DEFAULTS 0x00f6 83 #define KBDC_SEND_DEV_ID 0x00f2 84 #define KBDC_SET_LEDS 0x00ed 85 #define KBDC_ECHO 0x00ee 86 #define KBDC_SET_SCANCODE_SET 0x00f0 87 #define KBDC_SET_TYPEMATIC 0x00f3 88 89 /* aux device commands (sent to KBD_DATA_PORT) */ 90 #define PSMC_RESET_DEV 0x00ff 91 #define PSMC_ENABLE_DEV 0x00f4 92 #define PSMC_DISABLE_DEV 0x00f5 93 #define PSMC_SET_DEFAULTS 0x00f6 94 #define PSMC_SEND_DEV_ID 0x00f2 95 #define PSMC_SEND_DEV_STATUS 0x00e9 96 #define PSMC_SEND_DEV_DATA 0x00eb 97 #define PSMC_SET_SCALING11 0x00e6 98 #define PSMC_SET_SCALING21 0x00e7 99 #define PSMC_SET_RESOLUTION 0x00e8 100 #define PSMC_SET_STREAM_MODE 0x00ea 101 #define PSMC_SET_REMOTE_MODE 0x00f0 102 #define PSMC_SET_SAMPLING_RATE 0x00f3 103 104 /* PSMC_SET_RESOLUTION argument */ 105 #define PSMD_RES_LOW 0 /* typically 25ppi */ 106 #define PSMD_RES_MEDIUM_LOW 1 /* typically 50ppi */ 107 #define PSMD_RES_MEDIUM_HIGH 2 /* typically 100ppi (default) */ 108 #define PSMD_RES_HIGH 3 /* typically 200ppi */ 109 #define PSMD_MAX_RESOLUTION PSMD_RES_HIGH 110 111 /* PSMC_SET_SAMPLING_RATE */ 112 #define PSMD_MAX_RATE 255 /* FIXME: not sure if it's possible */ 113 114 /* status bits (KBD_STATUS_PORT) */ 115 #define KBDS_BUFFER_FULL 0x0021 116 #define KBDS_ANY_BUFFER_FULL 0x0001 117 #define KBDS_KBD_BUFFER_FULL 0x0001 118 #define KBDS_AUX_BUFFER_FULL 0x0021 119 #define KBDS_INPUT_BUFFER_FULL 0x0002 120 121 /* return code */ 122 #define KBD_ACK 0x00fa 123 #define KBD_RESEND 0x00fe 124 #define KBD_RESET_DONE 0x00aa 125 #define KBD_RESET_FAIL 0x00fc 126 #define KBD_DIAG_DONE 0x0055 127 #define KBD_DIAG_FAIL 0x00fd 128 #define KBD_ECHO 0x00ee 129 130 #define PSM_ACK 0x00fa 131 #define PSM_RESEND 0x00fe 132 #define PSM_RESET_DONE 0x00aa 133 #define PSM_RESET_FAIL 0x00fc 134 135 /* aux device ID */ 136 #define PSM_MOUSE_ID 0 137 #define PSM_BALLPOINT_ID 2 138 #define PSM_INTELLI_ID 3 139 #define PSM_EXPLORER_ID 4 140 #define PSM_4DMOUSE_ID 6 141 #define PSM_4DPLUS_ID 8 142 #define PSM_4DPLUS_RFSW35_ID 24 143 144 #ifdef _KERNEL 145 146 #define ATKBDC_DRIVER_NAME "atkbdc" 147 148 /* 149 * driver specific options: the following options may be set by 150 * `options' statements in the kernel configuration file. 151 */ 152 153 /* retry count */ 154 #ifndef KBD_MAXRETRY 155 #define KBD_MAXRETRY 3 156 #endif 157 158 /* timing parameters */ 159 #ifndef KBD_RESETDELAY 160 #define KBD_RESETDELAY 200 /* wait 200msec after kbd/mouse reset */ 161 #endif 162 #ifndef KBD_MAXWAIT 163 #define KBD_MAXWAIT 5 /* wait 5 times at most after reset */ 164 #endif 165 166 /* I/O recovery time */ 167 #define KBDC_DELAYTIME 20 168 #define KBDD_DELAYTIME 7 169 170 /* debug option */ 171 #ifndef KBDIO_DEBUG 172 #define KBDIO_DEBUG 0 173 #endif 174 175 /* end of driver specific options */ 176 177 /* types/structures */ 178 179 #define KBDQ_BUFSIZE 32 180 181 typedef struct _kqueue { 182 int head; 183 int tail; 184 unsigned char q[KBDQ_BUFSIZE]; 185 #if KBDIO_DEBUG >= 2 186 int call_count; 187 int qcount; 188 int max_qcount; 189 #endif 190 } kqueue; 191 192 struct resource; 193 194 typedef struct atkbdc_softc { 195 struct resource *port0; /* data port */ 196 struct resource *port1; /* status port */ 197 struct resource *irq; 198 bus_space_tag_t iot; 199 bus_space_handle_t ioh0; 200 bus_space_handle_t ioh1; 201 int command_byte; /* current command byte value */ 202 int command_mask; /* command byte mask bits for kbd/aux devices */ 203 int lock; /* FIXME: XXX not quite a semaphore... */ 204 kqueue kbd; /* keyboard data queue */ 205 kqueue aux; /* auxiliary data queue */ 206 int retry; 207 int quirks; /* controller doesn't like deactivate */ 208 #define KBDC_QUIRK_KEEP_ACTIVATED (1 << 0) 209 #define KBDC_QUIRK_IGNORE_PROBE_RESULT (1 << 1) 210 #define KBDC_QUIRK_RESET_AFTER_PROBE (1 << 2) 211 #define KBDC_QUIRK_SETLEDS_ON_INIT (1 << 3) 212 } atkbdc_softc_t; 213 214 enum kbdc_device_ivar { 215 KBDC_IVAR_VENDORID, 216 KBDC_IVAR_SERIAL, 217 KBDC_IVAR_LOGICALID, 218 KBDC_IVAR_COMPATID, 219 }; 220 221 typedef caddr_t KBDC; 222 223 #define KBDC_RID_KBD 0 224 #define KBDC_RID_AUX 1 225 226 /* function prototypes */ 227 228 atkbdc_softc_t *atkbdc_get_softc(int unit); 229 int atkbdc_probe_unit(int unit, struct resource *port0, struct resource *port1); 230 int atkbdc_attach_unit(int unit, atkbdc_softc_t *sc, struct resource *port0, 231 struct resource *port1); 232 int atkbdc_configure(void); 233 234 KBDC atkbdc_open(int unit); 235 int kbdc_lock(KBDC kbdc, int lock); 236 int kbdc_data_ready(KBDC kbdc); 237 238 int write_controller_command(KBDC kbdc,int c); 239 int write_controller_data(KBDC kbdc,int c); 240 241 int write_kbd_command(KBDC kbdc,int c); 242 int write_aux_command(KBDC kbdc,int c); 243 int send_kbd_command(KBDC kbdc,int c); 244 int send_aux_command(KBDC kbdc,int c); 245 int send_kbd_command_and_data(KBDC kbdc,int c,int d); 246 int send_aux_command_and_data(KBDC kbdc,int c,int d); 247 248 int read_controller_data(KBDC kbdc); 249 int read_kbd_data(KBDC kbdc); 250 int read_kbd_data_no_wait(KBDC kbdc); 251 int read_aux_data(KBDC kbdc); 252 int read_aux_data_no_wait(KBDC kbdc); 253 254 void empty_kbd_buffer(KBDC kbdc, int t); 255 void empty_aux_buffer(KBDC kbdc, int t); 256 void empty_both_buffers(KBDC kbdc, int t); 257 258 int reset_kbd(KBDC kbdc); 259 int reset_aux_dev(KBDC kbdc); 260 261 int test_controller(KBDC kbdc); 262 int test_kbd_port(KBDC kbdc); 263 int test_aux_port(KBDC kbdc); 264 265 int kbdc_get_device_mask(KBDC kbdc); 266 void kbdc_set_device_mask(KBDC kbdc, int mask); 267 268 int get_controller_command_byte(KBDC kbdc); 269 int set_controller_command_byte(KBDC kbdc, int command, int flag); 270 271 #endif /* _KERNEL */ 272 273 #endif /* !_DEV_ATKBDC_ATKBDCREG_H_ */ 274