1 /* $NetBSD: kbdsunvar.h,v 1.2 2002/10/21 15:36:35 uwe Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This software was developed by the Computer Systems Engineering group 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 * contributed to Berkeley. 10 * 11 * All advertising materials mentioning features or use of this software 12 * must display the following acknowledgement: 13 * This product includes software developed by the University of 14 * California, Lawrence Berkeley Laboratory. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution. 24 * 3. All advertising materials mentioning features or use of this software 25 * must display the following acknowledgement: 26 * This product includes software developed by the University of 27 * California, Berkeley and its contributors. 28 * 4. Neither the name of the University nor the names of its contributors 29 * may be used to endorse or promote products derived from this software 30 * without specific prior written permission. 31 * 32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 * SUCH DAMAGE. 43 * 44 * @(#)kbd.c 8.2 (Berkeley) 10/30/93 45 */ 46 47 /* 48 * Keyboard driver - middle layer for sun keyboard off a serial line. 49 * This code is used by kbd_zs and sunkbd (line discipline) drivers. 50 */ 51 52 53 /* 54 * How many input characters we can buffer. 55 * The port-specific var.h may override this. 56 * Note: must be a power of two! 57 */ 58 #define KBD_RX_RING_SIZE 256 59 #define KBD_RX_RING_MASK (KBD_RX_RING_SIZE - 1) 60 61 /* 62 * Output buffer. Only need a few chars. 63 */ 64 #define KBD_TX_RING_SIZE 16 65 #define KBD_TX_RING_MASK (KBD_TX_RING_SIZE - 1) 66 67 /* 68 * Keyboard serial line speed defaults to 1200 bps. 69 */ 70 #define KBD_DEFAULT_BPS 1200 71 72 #define KBD_RESET_TIMO 1000 /* mS. */ 73 74 75 struct kbd_sun_softc { 76 /* upper layer (also inherits struct device) */ 77 struct kbd_softc k_kbd; 78 79 union { 80 void *ku_priv; 81 struct zs_chanstate *ku_cs; 82 } k_u; 83 #define k_priv k_u.ku_priv 84 #define k_cs k_u.ku_cs 85 86 /* 87 * The deviopen and deviclose routines are provided by the 88 * underlying lower level driver and used as a back door when 89 * opening and closing the internal device. 90 */ 91 int (*k_deviopen)(struct device *, int); 92 int (*k_deviclose)(struct device *, int); 93 94 /* 95 * Callback provided by the lower layer (actual device driver). 96 * Middle layer uses it to send commands to sun keyboard. 97 */ 98 void (*k_write_data)(struct kbd_sun_softc *, int); 99 100 /* Was initialized once. */ 101 int k_isopen; 102 103 /* 104 * Magic sequence stuff (Stop-A, aka L1-A). 105 * XXX: convert to cnmagic(9). 106 */ 107 char k_magic1_down; 108 u_char k_magic1; /* L1 */ 109 u_char k_magic2; /* A */ 110 111 /* Expecting ID or layout byte from keyboard */ 112 int k_expect; 113 #define KBD_EXPECT_IDCODE 1 114 #define KBD_EXPECT_LAYOUT 2 115 116 /* Flags to communicate with kbd_softint() */ 117 volatile int k_intr_flags; 118 #define INTR_RX_OVERRUN 1 119 #define INTR_TX_EMPTY 2 120 #define INTR_ST_CHECK 4 121 122 /* Transmit state */ 123 volatile int k_txflags; 124 #define K_TXBUSY 1 125 #define K_TXWANT 2 126 127 /* 128 * The transmit ring buffer. 129 */ 130 volatile u_int k_tbget; /* transmit buffer `get' index */ 131 volatile u_int k_tbput; /* transmit buffer `put' index */ 132 u_char k_tbuf[KBD_TX_RING_SIZE]; /* data */ 133 134 /* 135 * The receive ring buffer. 136 */ 137 u_int k_rbget; /* ring buffer `get' index */ 138 volatile u_int k_rbput; /* ring buffer `put' index */ 139 u_short k_rbuf[KBD_RX_RING_SIZE]; /* rr1, data pairs */ 140 }; 141 142 /* Middle layer methods exported to the upper layer. */ 143 extern const struct kbd_ops kbd_ops_sun; 144 145 /* Methods for the lower layer to call. */ 146 extern void kbd_sun_input(struct kbd_sun_softc *k, int); 147 extern void kbd_sun_output(struct kbd_sun_softc *k, int c); 148 extern void kbd_sun_start_tx(struct kbd_sun_softc *k); 149