1 /* $NetBSD: magmareg.h,v 1.4 2002/01/22 17:00:47 pk Exp $ */ 2 /* magmareg.h 3 * 4 * Copyright (c) 1998 Iain Hibbert 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Iain Hibbert 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * 32 */ 33 34 #ifdef MAGMA_DEBUG 35 #define dprintf(x) printf x 36 #else 37 #define dprintf(x) 38 #endif 39 40 /* The mapping of minor device number -> card and port is done as 41 * follows by default: 42 * 43 * +---+---+---+---+---+---+---+---+ 44 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 45 * +---+---+---+---+---+---+---+---+ 46 * | | | | | | | | 47 * | | | | +---+---+---+---> port number 48 * | | | | 49 * | | | +-------------------> dialout (on tty ports) 50 * | | | 51 * | | +-----------------------> unused 52 * | | 53 * +---+---------------------------> card number 54 * 55 */ 56 57 #define MAGMA_MAX_CARDS 4 58 #define MAGMA_MAX_TTY 16 59 #define MAGMA_MAX_BPP 2 60 #define MAGMA_MAX_CD1400 4 61 #define MAGMA_MAX_CD1190 2 62 63 #define MAGMA_CARD(x) ((minor(x) >> 6) & 0x03) 64 #define MAGMA_PORT(x) (minor(x) & 0x0f) 65 66 #define MTTY_DIALOUT(x) (minor(x) & 0x10) 67 68 /* 69 * Supported Card Types 70 */ 71 struct magma_board_info { 72 const char *mb_sbusname; /* sbus_attach_args.sa_name */ 73 const char *mb_name; /* cardname to match against */ 74 const char *mb_realname; /* english card name */ 75 int mb_nser; /* number of serial ports */ 76 int mb_npar; /* number of parallel ports */ 77 int mb_ncd1400; /* number of CD1400 chips */ 78 int mb_svcackr; /* svcackr offset */ 79 int mb_svcackt; /* svcackt offset */ 80 int mb_svcackm; /* svcackm offset */ 81 int mb_cd1400[MAGMA_MAX_CD1400];/* cd1400 chip register offsets */ 82 int mb_ncd1190; /* number of CD1190 chips */ 83 int mb_cd1190[MAGMA_MAX_CD1190];/* cd1190 chip register offsets */ 84 }; 85 86 /* 87 * cd1400 chip data 88 */ 89 struct cd1400 { 90 __volatile u_char *cd_reg; /* chip registers */ 91 int cd_chiprev; /* chip revision */ 92 int cd_clock; /* clock speed in Mhz */ 93 int cd_parmode; /* parallel mode operation */ 94 }; 95 96 /* 97 * cd1190 chip data 98 */ 99 struct cd1190 { 100 __volatile u_char *cd_reg; /* chip registers */ 101 int cd_chiprev; /* chip revision */ 102 }; 103 104 /* software state for each card */ 105 struct magma_softc { 106 struct device ms_dev; /* required. must be first in softc */ 107 struct sbusdev ms_sd; /* sbus device */ 108 struct evcnt ms_intrcnt; /* statistics */ 109 110 /* cd1400 chip info */ 111 int ms_ncd1400; 112 struct cd1400 ms_cd1400[MAGMA_MAX_CD1400]; 113 __volatile u_char *ms_svcackr; /* CD1400 service acknowledge receive */ 114 __volatile u_char *ms_svcackt; /* CD1400 service acknowledge transmit */ 115 __volatile u_char *ms_svcackm; /* CD1400 service acknowledge modem */ 116 117 /* cd1190 chip info */ 118 int ms_ncd1190; 119 struct cd1190 ms_cd1190[MAGMA_MAX_CD1190]; 120 121 struct magma_board_info *ms_board; /* what am I? */ 122 123 struct mtty_softc *ms_mtty; 124 struct mbpp_softc *ms_mbpp; 125 126 }; 127 128 #define MTTY_RBUF_SIZE (2 * 512) 129 #define MTTY_RX_FIFO_THRESHOLD 6 130 #define MTTY_RX_DTR_THRESHOLD 9 131 132 struct mtty_port { 133 struct cd1400 *mp_cd1400; /* ptr to chip */ 134 int mp_channel; /* and channel */ 135 struct tty *mp_tty; 136 137 int mp_openflags; /* default tty flags */ 138 int mp_flags; /* port flags */ 139 int mp_carrier; /* state of carrier */ 140 141 u_char *mp_rbuf; /* ring buffer start */ 142 u_char *mp_rend; /* ring buffer end */ 143 u_char *mp_rget; /* ring buffer read pointer */ 144 u_char *mp_rput; /* ring buffer write pointer */ 145 146 u_char *mp_txp; /* transmit character pointer */ 147 int mp_txc; /* transmit character counter */ 148 }; 149 150 #define MTTYF_CARRIER_CHANGED (1<<0) 151 #define MTTYF_SET_BREAK (1<<1) 152 #define MTTYF_CLR_BREAK (1<<2) 153 #define MTTYF_DONE (1<<3) 154 #define MTTYF_STOP (1<<4) 155 #define MTTYF_RING_OVERFLOW (1<<5) 156 157 struct mtty_softc { 158 struct device ms_dev; /* device info */ 159 int ms_nports; /* tty ports */ 160 struct mtty_port ms_port[MAGMA_MAX_TTY]; 161 }; 162 163 #define MBPP_RX_FIFO_THRESHOLD 25 164 165 struct mbpp_port { 166 struct cd1400 *mp_cd1400; /* for LC2+1Sp card */ 167 struct cd1190 *mp_cd1190; /* all the others */ 168 169 struct callout mp_timeout_ch; 170 struct callout mp_start_ch; 171 172 int mp_flags; 173 174 struct mbpp_param mp_param; 175 #define mp_burst mp_param.bp_burst 176 #define mp_timeout mp_param.bp_timeout 177 #define mp_delay mp_param.bp_delay 178 179 u_char *mp_ptr; /* pointer to I/O data */ 180 int mp_cnt; /* count of I/O chars */ 181 }; 182 183 #define MBPPF_OPEN (1<<0) 184 #define MBPPF_TIMEOUT (1<<1) 185 #define MBPPF_UIO (1<<2) 186 #define MBPPF_DELAY (1<<3) 187 #define MBPPF_WAKEUP (1<<4) 188 189 struct mbpp_softc { 190 struct device ms_dev; /* device info */ 191 int ms_nports; /* parallel ports */ 192 struct mbpp_port ms_port[MAGMA_MAX_BPP]; 193 }; 194 195 /* 196 * useful macros 197 */ 198 #define SET(t, f) ((t) |= (f)) 199 #define CLR(t, f) ((t) &= ~(f)) 200 #define ISSET(t, f) ((t) & (f)) 201 202 /* internal function prototypes */ 203 204 int cd1400_compute_baud __P((speed_t, int, int *, int *)); 205 __inline void cd1400_write_ccr __P((struct cd1400 *, u_char)); 206 __inline u_char cd1400_read_reg __P((struct cd1400 *, int)); 207 __inline void cd1400_write_reg __P((struct cd1400 *, int, u_char)); 208 void cd1400_enable_transmitter __P((struct cd1400 *, int)); 209 210 int magma_match __P((struct device *, struct cfdata *, void *)); 211 void magma_attach __P((struct device *, struct device *, void *)); 212 int magma_hard __P((void *)); 213 int magma_soft __P((void *)); 214 215 int mtty_match __P((struct device *, struct cfdata *, void *)); 216 void mtty_attach __P((struct device *, struct device *, void *)); 217 int mtty_modem_control __P((struct mtty_port *, int, int)); 218 int mtty_param __P((struct tty *, struct termios *)); 219 void mtty_start __P((struct tty *)); 220 221 int mbpp_match __P((struct device *, struct cfdata *, void *)); 222 void mbpp_attach __P((struct device *, struct device *, void *)); 223 int mbpp_rw __P((dev_t, struct uio *)); 224 void mbpp_timeout __P((void *)); 225 void mbpp_start __P((void *)); 226 int mbpp_send __P((struct mbpp_port *, caddr_t, int)); 227 int mbpp_recv __P((struct mbpp_port *, caddr_t, int)); 228 int mbpp_hztoms __P((int)); 229 int mbpp_mstohz __P((int)); 230