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