atkbdcreg.h revision 55205
1139747Simp/*- 24Srgrimes * Copyright (c) 1996-1999 34Srgrimes * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp) 44Srgrimes * All rights reserved. 58876Srgrimes * 64Srgrimes * Redistribution and use in source and binary forms, with or without 74Srgrimes * modification, are permitted provided that the following conditions 84Srgrimes * are met: 94Srgrimes * 1. Redistributions of source code must retain the above copyright 104Srgrimes * notice, this list of conditions and the following disclaimer. 118876Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 128876Srgrimes * notice, this list of conditions and the following disclaimer in the 134Srgrimes * documentation and/or other materials provided with the distribution. 144Srgrimes * 3. The name of the author may not be used to endorse or promote 158876Srgrimes * products derived from this software without specific prior written 164Srgrimes * permission. 178876Srgrimes * 184Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 194Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 228876Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 234Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 244Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 254Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 264Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 274Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 284Srgrimes * SUCH DAMAGE. 294Srgrimes * 304Srgrimes * $FreeBSD: head/sys/dev/atkbdc/atkbdcreg.h 55205 1999-12-29 04:46:21Z peter $ 31116176Sobrien * from kbdio.h,v 1.8 1998/09/25 11:55:46 yokota Exp 32116176Sobrien */ 33116176Sobrien 342056Swollman#ifndef _DEV_KBD_ATKBDCREG_H_ 3547098Sbde#define _DEV_KBD_ATKBDCREG_H_ 3612734Sbde 372056Swollman/* constants */ 384Srgrimes 394Srgrimes/* I/O ports */ 404Srgrimes#define KBD_STATUS_PORT 4 /* status port, read */ 4192756Salfred#define KBD_COMMAND_PORT 4 /* controller command port, write */ 424Srgrimes#define KBD_DATA_PORT 0 /* data port, read/write 4312515Sphk * also used as keyboard command 444Srgrimes * and mouse command port 4537504Sbde */ 464Srgrimes 474Srgrimes/* controller commands (sent to KBD_COMMAND_PORT) */ 48137117Sjhb#define KBDC_SET_COMMAND_BYTE 0x0060 49195699Srwatson#define KBDC_GET_COMMAND_BYTE 0x0020 50195699Srwatson#define KBDC_WRITE_TO_AUX 0x00d4 51195699Srwatson#define KBDC_DISABLE_AUX_PORT 0x00a7 52195699Srwatson#define KBDC_ENABLE_AUX_PORT 0x00a8 53195699Srwatson#define KBDC_TEST_AUX_PORT 0x00a9 54195699Srwatson#define KBDC_DIAGNOSE 0x00aa 554Srgrimes#define KBDC_TEST_KBD_PORT 0x00ab 56131952Smarcel#define KBDC_DISABLE_KBD_PORT 0x00ad 57131952Smarcel#define KBDC_ENABLE_KBD_PORT 0x00ae 584Srgrimes 5912515Sphk/* controller command byte (set by KBDC_SET_COMMAND_BYTE) */ 60131952Smarcel#define KBD_TRANSLATION 0x0040 614Srgrimes#define KBD_RESERVED_BITS 0x0004 624Srgrimes#define KBD_OVERRIDE_KBD_LOCK 0x0008 63131952Smarcel#define KBD_ENABLE_KBD_PORT 0x0000 644Srgrimes#define KBD_DISABLE_KBD_PORT 0x0010 654Srgrimes#define KBD_ENABLE_AUX_PORT 0x0000 664Srgrimes#define KBD_DISABLE_AUX_PORT 0x0020 67131952Smarcel#define KBD_ENABLE_AUX_INT 0x0002 68131952Smarcel#define KBD_DISABLE_AUX_INT 0x0000 69131952Smarcel#define KBD_ENABLE_KBD_INT 0x0001 70131952Smarcel#define KBD_DISABLE_KBD_INT 0x0000 71131952Smarcel#define KBD_KBD_CONTROL_BITS (KBD_DISABLE_KBD_PORT | KBD_ENABLE_KBD_INT) 724Srgrimes#define KBD_AUX_CONTROL_BITS (KBD_DISABLE_AUX_PORT | KBD_ENABLE_AUX_INT) 73131952Smarcel 74131952Smarcel/* keyboard device commands (sent to KBD_DATA_PORT) */ 75131952Smarcel#define KBDC_RESET_KBD 0x00ff 76131952Smarcel#define KBDC_ENABLE_KBD 0x00f4 77131952Smarcel#define KBDC_DISABLE_KBD 0x00f5 784Srgrimes#define KBDC_SET_DEFAULTS 0x00f6 794Srgrimes#define KBDC_SEND_DEV_ID 0x00f2 804Srgrimes#define KBDC_SET_LEDS 0x00ed 814Srgrimes#define KBDC_ECHO 0x00ee 824Srgrimes#define KBDC_SET_SCANCODE_SET 0x00f0 834Srgrimes#define KBDC_SET_TYPEMATIC 0x00f3 844Srgrimes 85131952Smarcel/* aux device commands (sent to KBD_DATA_PORT) */ 864Srgrimes#define PSMC_RESET_DEV 0x00ff 874Srgrimes#define PSMC_ENABLE_DEV 0x00f4 884Srgrimes#define PSMC_DISABLE_DEV 0x00f5 894Srgrimes#define PSMC_SET_DEFAULTS 0x00f6 90131952Smarcel#define PSMC_SEND_DEV_ID 0x00f2 914Srgrimes#define PSMC_SEND_DEV_STATUS 0x00e9 92131952Smarcel#define PSMC_SEND_DEV_DATA 0x00eb 934Srgrimes#define PSMC_SET_SCALING11 0x00e6 944Srgrimes#define PSMC_SET_SCALING21 0x00e7 95131952Smarcel#define PSMC_SET_RESOLUTION 0x00e8 96131952Smarcel#define PSMC_SET_STREAM_MODE 0x00ea 974Srgrimes#define PSMC_SET_REMOTE_MODE 0x00f0 984Srgrimes#define PSMC_SET_SAMPLING_RATE 0x00f3 994Srgrimes 1004Srgrimes/* PSMC_SET_RESOLUTION argument */ 101131952Smarcel#define PSMD_RES_LOW 0 /* typically 25ppi */ 1024Srgrimes#define PSMD_RES_MEDIUM_LOW 1 /* typically 50ppi */ 103131952Smarcel#define PSMD_RES_MEDIUM_HIGH 2 /* typically 100ppi (default) */ 1044Srgrimes#define PSMD_RES_HIGH 3 /* typically 200ppi */ 1054Srgrimes#define PSMD_MAX_RESOLUTION PSMD_RES_HIGH 106131952Smarcel 107131952Smarcel/* PSMC_SET_SAMPLING_RATE */ 1084Srgrimes#define PSMD_MAX_RATE 255 /* FIXME: not sure if it's possible */ 109131952Smarcel 1104Srgrimes/* status bits (KBD_STATUS_PORT) */ 111131952Smarcel#define KBDS_BUFFER_FULL 0x0021 112131952Smarcel#define KBDS_ANY_BUFFER_FULL 0x0001 113131952Smarcel#define KBDS_KBD_BUFFER_FULL 0x0001 114131952Smarcel#define KBDS_AUX_BUFFER_FULL 0x0021 115131952Smarcel#define KBDS_INPUT_BUFFER_FULL 0x0002 1164Srgrimes 1174Srgrimes/* return code */ 118131952Smarcel#define KBD_ACK 0x00fa 119131952Smarcel#define KBD_RESEND 0x00fe 1204Srgrimes#define KBD_RESET_DONE 0x00aa 121131952Smarcel#define KBD_RESET_FAIL 0x00fc 1224Srgrimes#define KBD_DIAG_DONE 0x0055 123131952Smarcel#define KBD_DIAG_FAIL 0x00fd 124131952Smarcel#define KBD_ECHO 0x00ee 125131952Smarcel 126131952Smarcel#define PSM_ACK 0x00fa 127131952Smarcel#define PSM_RESEND 0x00fe 1284Srgrimes#define PSM_RESET_DONE 0x00aa 1294Srgrimes#define PSM_RESET_FAIL 0x00fc 1304Srgrimes 131283248Spfg/* aux device ID */ 1324Srgrimes#define PSM_MOUSE_ID 0 1334Srgrimes#define PSM_BALLPOINT_ID 2 134131952Smarcel#define PSM_INTELLI_ID 3 135131952Smarcel 1364Srgrimes#ifdef _KERNEL 1374Srgrimes 1384Srgrimes#define ATKBDC_DRIVER_NAME "atkbdc" 139131952Smarcel 140131952Smarcel/* 1414Srgrimes * driver specific options: the following options may be set by 1424Srgrimes * `options' statements in the kernel configuration file. 143131952Smarcel */ 144131952Smarcel 1454Srgrimes/* retry count */ 1464Srgrimes#ifndef KBD_MAXRETRY 1474Srgrimes#define KBD_MAXRETRY 3 1484Srgrimes#endif 149131952Smarcel 1504Srgrimes/* timing parameters */ 1514Srgrimes#ifndef KBD_RESETDELAY 152131952Smarcel#define KBD_RESETDELAY 200 /* wait 200msec after kbd/mouse reset */ 153131952Smarcel#endif 1544Srgrimes#ifndef KBD_MAXWAIT 155131952Smarcel#define KBD_MAXWAIT 5 /* wait 5 times at most after reset */ 156131952Smarcel#endif 1574Srgrimes 158131952Smarcel/* I/O recovery time */ 1594Srgrimes#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