1*7cf29912Scegger /* $NetBSD: kbdsunvar.h,v 1.7 2009/05/12 14:46:39 cegger Exp $ */ 2af2a7554Suwe 3af2a7554Suwe /* 4af2a7554Suwe * Copyright (c) 1992, 1993 5af2a7554Suwe * The Regents of the University of California. All rights reserved. 6af2a7554Suwe * 7af2a7554Suwe * This software was developed by the Computer Systems Engineering group 8af2a7554Suwe * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9af2a7554Suwe * contributed to Berkeley. 10af2a7554Suwe * 11af2a7554Suwe * All advertising materials mentioning features or use of this software 12af2a7554Suwe * must display the following acknowledgement: 13af2a7554Suwe * This product includes software developed by the University of 14af2a7554Suwe * California, Lawrence Berkeley Laboratory. 15af2a7554Suwe * 16af2a7554Suwe * Redistribution and use in source and binary forms, with or without 17af2a7554Suwe * modification, are permitted provided that the following conditions 18af2a7554Suwe * are met: 19af2a7554Suwe * 1. Redistributions of source code must retain the above copyright 20af2a7554Suwe * notice, this list of conditions and the following disclaimer. 21af2a7554Suwe * 2. Redistributions in binary form must reproduce the above copyright 22af2a7554Suwe * notice, this list of conditions and the following disclaimer in the 23af2a7554Suwe * documentation and/or other materials provided with the distribution. 24aad01611Sagc * 3. Neither the name of the University nor the names of its contributors 25af2a7554Suwe * may be used to endorse or promote products derived from this software 26af2a7554Suwe * without specific prior written permission. 27af2a7554Suwe * 28af2a7554Suwe * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29af2a7554Suwe * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30af2a7554Suwe * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31af2a7554Suwe * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32af2a7554Suwe * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33af2a7554Suwe * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34af2a7554Suwe * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35af2a7554Suwe * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36af2a7554Suwe * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37af2a7554Suwe * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38af2a7554Suwe * SUCH DAMAGE. 39af2a7554Suwe * 40af2a7554Suwe * @(#)kbd.c 8.2 (Berkeley) 10/30/93 41af2a7554Suwe */ 42af2a7554Suwe 43191626f7Suwe /* 44191626f7Suwe * Keyboard driver - middle layer for sun keyboard off a serial line. 45af2a7554Suwe * This code is used by kbd_zs and sunkbd (line discipline) drivers. 46191626f7Suwe */ 47191626f7Suwe 48af2a7554Suwe 49191626f7Suwe /* 50191626f7Suwe * How many input characters we can buffer. 51191626f7Suwe * The port-specific var.h may override this. 52191626f7Suwe * Note: must be a power of two! 53191626f7Suwe */ 54191626f7Suwe #define KBD_RX_RING_SIZE 256 55191626f7Suwe #define KBD_RX_RING_MASK (KBD_RX_RING_SIZE - 1) 56191626f7Suwe 57191626f7Suwe /* 58191626f7Suwe * Output buffer. Only need a few chars. 59191626f7Suwe */ 60191626f7Suwe #define KBD_TX_RING_SIZE 16 61191626f7Suwe #define KBD_TX_RING_MASK (KBD_TX_RING_SIZE - 1) 62af2a7554Suwe 63191626f7Suwe /* 64191626f7Suwe * Keyboard serial line speed defaults to 1200 bps. 65191626f7Suwe */ 66191626f7Suwe #define KBD_DEFAULT_BPS 1200 67af2a7554Suwe 68191626f7Suwe #define KBD_RESET_TIMO 1000 /* mS. */ 69191626f7Suwe 70191626f7Suwe 71191626f7Suwe struct kbd_sun_softc { 7202cb47caStsutsui /* upper layer (also inherits device_t) */ 73191626f7Suwe struct kbd_softc k_kbd; 74191626f7Suwe 75191626f7Suwe union { 76191626f7Suwe void *ku_priv; 77191626f7Suwe struct zs_chanstate *ku_cs; 78191626f7Suwe } k_u; 79191626f7Suwe #define k_priv k_u.ku_priv 80191626f7Suwe #define k_cs k_u.ku_cs 81191626f7Suwe 82191626f7Suwe /* 83191626f7Suwe * The deviopen and deviclose routines are provided by the 84191626f7Suwe * underlying lower level driver and used as a back door when 85191626f7Suwe * opening and closing the internal device. 86191626f7Suwe */ 87*7cf29912Scegger int (*k_deviopen)(device_t, int); 88*7cf29912Scegger int (*k_deviclose)(device_t, int); 89191626f7Suwe 90191626f7Suwe /* 91191626f7Suwe * Callback provided by the lower layer (actual device driver). 92191626f7Suwe * Middle layer uses it to send commands to sun keyboard. 93191626f7Suwe */ 94191626f7Suwe void (*k_write_data)(struct kbd_sun_softc *, int); 95191626f7Suwe 96191626f7Suwe /* Was initialized once. */ 97191626f7Suwe int k_isopen; 98191626f7Suwe 99191626f7Suwe /* 100191626f7Suwe * Magic sequence stuff (Stop-A, aka L1-A). 101191626f7Suwe * XXX: convert to cnmagic(9). 102191626f7Suwe */ 103191626f7Suwe char k_magic1_down; 104191626f7Suwe u_char k_magic1; /* L1 */ 105191626f7Suwe u_char k_magic2; /* A */ 106191626f7Suwe 107191626f7Suwe /* Expecting ID or layout byte from keyboard */ 108191626f7Suwe int k_expect; 109191626f7Suwe #define KBD_EXPECT_IDCODE 1 110191626f7Suwe #define KBD_EXPECT_LAYOUT 2 111191626f7Suwe 112191626f7Suwe /* Flags to communicate with kbd_softint() */ 113191626f7Suwe volatile int k_intr_flags; 114191626f7Suwe #define INTR_RX_OVERRUN 1 115191626f7Suwe #define INTR_TX_EMPTY 2 116191626f7Suwe #define INTR_ST_CHECK 4 117191626f7Suwe 118191626f7Suwe /* Transmit state */ 119191626f7Suwe volatile int k_txflags; 120191626f7Suwe #define K_TXBUSY 1 121191626f7Suwe #define K_TXWANT 2 122191626f7Suwe 123191626f7Suwe /* 124191626f7Suwe * The transmit ring buffer. 125191626f7Suwe */ 126191626f7Suwe volatile u_int k_tbget; /* transmit buffer `get' index */ 127191626f7Suwe volatile u_int k_tbput; /* transmit buffer `put' index */ 128191626f7Suwe u_char k_tbuf[KBD_TX_RING_SIZE]; /* data */ 129191626f7Suwe 130191626f7Suwe /* 131191626f7Suwe * The receive ring buffer. 132191626f7Suwe */ 133191626f7Suwe u_int k_rbget; /* ring buffer `get' index */ 134191626f7Suwe volatile u_int k_rbput; /* ring buffer `put' index */ 135191626f7Suwe u_short k_rbuf[KBD_RX_RING_SIZE]; /* rr1, data pairs */ 136191626f7Suwe }; 137191626f7Suwe 138191626f7Suwe /* Middle layer methods exported to the upper layer. */ 139af2a7554Suwe extern const struct kbd_ops kbd_ops_sun; 140191626f7Suwe 141af2a7554Suwe /* Methods for the lower layer to call. */ 142d1400b88Sheas extern int kbd_sun_input(struct kbd_sun_softc *k, int); 143191626f7Suwe extern void kbd_sun_output(struct kbd_sun_softc *k, int c); 144191626f7Suwe extern void kbd_sun_start_tx(struct kbd_sun_softc *k); 145