magmareg.h revision 1.2
1/* $OpenBSD: magmareg.h,v 1.2 2002/01/12 21:30:56 jason Exp $ */ 2 3/* magmareg.h 4 * 5 * Copyright (c) 1998 Iain Hibbert 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 Iain Hibbert 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 */ 34 35#ifdef MAGMA_DEBUG 36#define dprintf(x) printf x 37#else 38#define dprintf(x) 39#endif 40 41/* The mapping of minor device number -> card and port is done as 42 * follows by default: 43 * 44 * +---+---+---+---+---+---+---+---+ 45 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 46 * +---+---+---+---+---+---+---+---+ 47 * | | | | | | | | 48 * | | | | +---+---+---+---> port number 49 * | | | | 50 * | | | +-------------------> dialout (on tty ports) 51 * | | | 52 * | | +-----------------------> unused 53 * | | 54 * +---+---------------------------> card number 55 * 56 */ 57 58#define MAGMA_MAX_CARDS 4 59#define MAGMA_MAX_TTY 16 60#define MAGMA_MAX_BPP 2 61#define MAGMA_MAX_CD1400 4 62#define MAGMA_MAX_CD1190 2 63 64#define MAGMA_CARD(x) ((minor(x) >> 6) & 0x03) 65#define MAGMA_PORT(x) (minor(x) & 0x0f) 66 67#define MTTY_DIALOUT(x) (minor(x) & 0x10) 68 69/* 70 * Supported Card Types 71 */ 72struct magma_board_info { 73 char *mb_name; /* cardname to match against */ 74 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 */ 89struct cd1400 { 90 bus_space_handle_t cd_regh; /* chip register handle */ 91 bus_space_tag_t cd_regt; /* chip register tag */ 92 int cd_chiprev; /* chip revision */ 93 int cd_clock; /* clock speed in Mhz */ 94 int cd_parmode; /* parallel mode operation */ 95}; 96 97/* 98 * cd1190 chip data 99 */ 100struct cd1190 { 101 bus_space_handle_t cd_regh; /* chip register handle */ 102 bus_space_tag_t cd_regt; /* chip register tag */ 103 int cd_chiprev; /* chip revision */ 104}; 105 106/* software state for each card */ 107struct magma_softc { 108 struct device ms_dev; /* required. must be first in softc */ 109 110 bus_space_tag_t sc_bustag; /* our bus tag */ 111 bus_space_handle_t sc_iohandle; /* whole card registers */ 112 void *sc_ih; /* interrupt vector */ 113 void *sc_sih; /* softintr vector */ 114 115 /* cd1400 chip info */ 116 int ms_ncd1400; 117 struct cd1400 ms_cd1400[MAGMA_MAX_CD1400]; 118 bus_space_handle_t sc_svcackrh; /* CD1400 service acknowledge receive */ 119 bus_space_handle_t sc_svcackth; /* CD1400 service acknowledge transmit */ 120 bus_space_handle_t sc_svcackmh; /* CD1400 service acknowledge modem */ 121 122 123 /* cd1190 chip info */ 124 int ms_ncd1190; 125 struct cd1190 ms_cd1190[MAGMA_MAX_CD1190]; 126 127 struct magma_board_info *ms_board; /* what am I? */ 128 129 struct mtty_softc *ms_mtty; 130 struct mbpp_softc *ms_mbpp; 131 132 struct intrhand ms_hardint; /* hard interrupt handler */ 133 struct intrhand ms_softint; /* soft interrupt handler */ 134}; 135 136#define MTTY_RBUF_SIZE (2 * 512) 137#define MTTY_RX_FIFO_THRESHOLD 6 138#define MTTY_RX_DTR_THRESHOLD 9 139 140struct mtty_port { 141 struct cd1400 *mp_cd1400; /* ptr to chip */ 142 int mp_channel; /* and channel */ 143 struct tty *mp_tty; 144 145 int mp_openflags; /* default tty flags */ 146 int mp_flags; /* port flags */ 147 int mp_carrier; /* state of carrier */ 148 149 u_char *mp_rbuf; /* ring buffer start */ 150 u_char *mp_rend; /* ring buffer end */ 151 u_char *mp_rget; /* ring buffer read pointer */ 152 u_char *mp_rput; /* ring buffer write pointer */ 153 154 u_char *mp_txp; /* transmit character pointer */ 155 int mp_txc; /* transmit character counter */ 156}; 157 158#define MTTYF_CARRIER_CHANGED (1<<0) 159#define MTTYF_SET_BREAK (1<<1) 160#define MTTYF_CLR_BREAK (1<<2) 161#define MTTYF_DONE (1<<3) 162#define MTTYF_STOP (1<<4) 163#define MTTYF_RING_OVERFLOW (1<<5) 164 165struct mtty_softc { 166 struct device ms_dev; /* device info */ 167 int ms_nports; /* tty ports */ 168 struct mtty_port ms_port[MAGMA_MAX_TTY]; 169}; 170 171#define MBPP_RX_FIFO_THRESHOLD 25 172 173struct mbpp_port { 174 struct cd1400 *mp_cd1400; /* for LC2+1Sp card */ 175 struct cd1190 *mp_cd1190; /* all the others */ 176 177 int mp_flags; 178 179 struct bpp_param mp_param; 180#define mp_burst mp_param.bp_burst 181#define mp_timeout mp_param.bp_timeout 182#define mp_delay mp_param.bp_delay 183 184 u_char *mp_ptr; /* pointer to io data */ 185 int mp_cnt; /* count of io chars */ 186 187 struct timeout mp_timeout_tmo; /* for mbpp_timeout() */ 188 struct timeout mp_start_tmo; /* for mbpp_start() */ 189}; 190 191#define MBPPF_OPEN (1<<0) 192#define MBPPF_TIMEOUT (1<<1) 193#define MBPPF_UIO (1<<2) 194#define MBPPF_DELAY (1<<3) 195#define MBPPF_WAKEUP (1<<4) 196 197struct mbpp_softc { 198 struct device ms_dev; /* device info */ 199 int ms_nports; /* parallel ports */ 200 struct mbpp_port ms_port[MAGMA_MAX_BPP]; 201}; 202 203/* 204 * useful macros 205 */ 206#define SET(t, f) ((t) |= (f)) 207#define CLR(t, f) ((t) &= ~(f)) 208#define ISSET(t, f) ((t) & (f)) 209 210/* internal function prototypes */ 211 212int cd1400_compute_baud __P((speed_t, int, int *, int *)); 213__inline void cd1400_write_ccr __P((struct cd1400 *, u_char)); 214__inline u_char cd1400_read_reg __P((struct cd1400 *, int)); 215__inline void cd1400_write_reg __P((struct cd1400 *, int, u_char)); 216void cd1400_enable_transmitter __P((struct cd1400 *, int)); 217 218int magma_match __P((struct device *, void *, void *)); 219void magma_attach __P((struct device *, struct device *, void *)); 220int magma_hard __P((void *)); 221void magma_soft __P((void *)); 222 223int mtty_match __P((struct device *, void *, void *)); 224void mtty_attach __P((struct device *, struct device *, void *)); 225int mtty_modem_control __P((struct mtty_port *, int, int)); 226int mtty_param __P((struct tty *, struct termios *)); 227void mtty_start __P((struct tty *)); 228 229int mbpp_match __P((struct device *, void *, void *)); 230void mbpp_attach __P((struct device *, struct device *, void *)); 231int mbpp_rw __P((dev_t, struct uio *)); 232void mbpp_timeout __P((void *)); 233void mbpp_start __P((void *)); 234int mbpp_send __P((struct mbpp_port *, caddr_t, int)); 235int mbpp_recv __P((struct mbpp_port *, caddr_t, int)); 236int mbpp_hztoms __P((int)); 237int mbpp_mstohz __P((int)); 238 239#define CD1400_REGMAPSIZE 0x80 240