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