1 /* $NetBSD: scnvar.h,v 1.2 2012/10/27 17:18:09 chs Exp $ */ 2 3 /* 4 * Copyright (c) 1996, 1997 Philip L. Budne. 5 * Copyright (c) 1993 Philip A. Nelson. 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. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Philip A. Nelson. 19 * 4. The name of Philip A. Nelson may not be used to endorse or promote 20 * products derived from this software without specific prior written 21 * permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * scnvar.h: definitions for pc532 2681/2692/26c96 duart driver 35 */ 36 37 /* Constants. */ 38 #ifdef COMDEF_SPEED 39 #undef TTYDEF_SPEED 40 #define TTYDEF_SPEED COMDEF_SPEED /* default baud rate */ 41 #endif 42 43 #define SCN_SIZE 0x8 /* address space for port */ 44 45 #define SCN_CONSOLE 0 /* minor number of console */ 46 #define SCN_CONSDUART 0 47 #define SCN_CONSCHAN 0 48 49 /* output port bits */ 50 #define OP_RTSA OP_OP0 51 #define OP_RTSB OP_OP1 52 #define OP_DTRA OP_OP2 53 #define OP_DTRB OP_OP3 54 /* OP4-7 not connected */ 55 56 /* input port bits */ 57 #define IP_CTSA IP_IP0 58 #define IP_CTSB IP_IP1 59 #define IP_DCDB IP_IP2 60 #define IP_DCDA IP_IP3 61 /* IP4-6 not connected */ 62 63 #define ACR_DELTA_CTSA ACR_DELTA_IP0 64 #define ACR_DELTA_CTSB ACR_DELTA_IP1 65 #define ACR_DELTA_DCDB ACR_DELTA_IP2 66 #define ACR_DELTA_DCDA ACR_DELTA_IP3 67 68 #define IPCR_CTSA IPCR_IP0 69 #define IPCR_CTSB IPCR_IP1 70 #define IPCR_DCDB IPCR_IP2 71 #define IPCR_DCDA IPCR_IP3 72 #define IPCR_DELTA_CTSA IPCR_DELTA_IP0 73 #define IPCR_DELTA_CTSB IPCR_DELTA_IP1 74 #define IPCR_DELTA_DCDB IPCR_DELTA_IP2 75 #define IPCR_DELTA_DCDA IPCR_DELTA_IP3 76 77 #define SCN_OP_BIS(SC,VAL) ((SC)->sc_duart->base[DU_OPSET] = (VAL)) 78 #define SCN_OP_BIC(SC,VAL) ((SC)->sc_duart->base[DU_OPCLR] = (VAL)) 79 80 #define SCN_DCD(SC) (((SC)->sc_duart->base[DU_IP] & (SC)->sc_ip_dcd) == 0) 81 82 /* pc532 duarts are auto-sized to byte-wide */ 83 #define CH_SZ 8 84 #define DUART_SZ 16 85 #define SCN_REG(n) (n << 4) /* 15 byte pad after each reg */ 86 87 /* The DUART description struct; for data common to both channels */ 88 struct duart { 89 volatile u_char *base; 90 struct chan { 91 struct scn_softc *sc; 92 struct tty *tty; 93 int32_t ispeed, ospeed; 94 u_char icode, ocode; 95 u_char mr0; /* MR0[7:3] */ 96 u_char new_mr1; /* held changes */ 97 u_char new_mr2; /* held changes */ 98 } chan[2]; 99 enum scntype { SCNUNK, SCN2681, SCN2692, SC26C92 } type; 100 uint16_t counter; /* C/T generated bps, or zero */ 101 uint16_t ocounter; /* last C/T generated bps, or zero */ 102 u_char mode; /* ACR[7] + MR0[2:0] */ 103 u_char acr; /* ACR[6:0]*/ 104 u_char imr; /* IMR bits */ 105 u_char opcr; /* OPCR bits */ 106 }; 107 108 #define SCN_RING_BITS 9 /* 512 byte buffers */ 109 #define SCN_RING_SIZE (1<<SCN_RING_BITS) /* must be a power of two */ 110 #define SCN_RING_MASK (SCN_RING_SIZE-1) 111 #define SCN_RING_THRESH (SCN_RING_SIZE/2) 112 #define SCN_RING_HIWAT (SCN_RING_SIZE - (SCN_RING_SIZE >> 2)) 113 114 /* scn channel state */ 115 struct scn_softc { 116 struct tty *sc_tty; 117 int sc_unit; /* unit number of this line (base 0) */ 118 int sc_channel; 119 int sc_isconsole; 120 int sc_iskgdb; 121 struct duart *sc_duart; /* pointer to duart struct */ 122 volatile u_char *sc_chbase; /* per-channel registers (CH_xxx) */ 123 u_char sc_swflags; /* from config / TIOCxFLAGS */ 124 #define SCN_SW_SOFTCAR 0x01 125 #define SCN_SW_CLOCAL 0x02 126 #define SCN_SW_CRTSCTS 0x04 127 #define SCN_SW_MDMBUF 0x08 /* not implemented */ 128 129 /* I wish there was a TS_DIALOUT flag! */ 130 u_char sc_dialout; /* set if open for dialout */ 131 #define SCN_DIALOUT(SCN) ((SCN)->sc_dialout) 132 #define SCN_SETDIALOUT(SCN) (SCN)->sc_dialout = 1 133 #define SCN_CLRDIALOUT(SCN) (SCN)->sc_dialout = 0 134 135 u_char sc_heldchanges; /* waiting for output done */ 136 137 /* bits in input port register */ 138 u_char sc_ip_dcd; 139 u_char sc_ip_cts; 140 141 /* bits in output port registers */ 142 u_char sc_op_rts; 143 u_char sc_op_dtr; 144 145 /* interrupt mask bits */ 146 u_char sc_tx_int; 147 u_char sc_rx_int; 148 149 /* counters */ 150 u_long sc_framing_errors; 151 u_long sc_parity_errors; 152 u_long sc_fifo_overruns; 153 u_long sc_breaks; 154 155 /* ring buffer for rxrdy interrupt */ 156 u_int sc_rbget; /* ring buffer `get' index */ 157 volatile u_int sc_rbput; /* ring buffer `put' index */ 158 int sc_rbhiwat; 159 short sc_rbuf[SCN_RING_SIZE]; /* status + data */ 160 long sc_fotime; /* last fifo overrun message */ 161 long sc_rotime; /* last ring overrun message */ 162 u_long sc_ring_overruns; /* number of ring buffer overruns */ 163 /* Flags to communicate with scntty_softint() */ 164 volatile char sc_rx_blocked; /* input block at ring */ 165 }; 166