Home | History | Annotate | Line # | Download | only in sbus
magmareg.h revision 1.1
      1 /*	$NetBSD: magmareg.h,v 1.1 1998/05/19 23:58:54 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 	char *mb_name;			/* cardname to match against */
     73 	char *mb_realname;		/* english card name */
     74 	int mb_nser;			/* number of serial ports */
     75 	int mb_npar;			/* number of parallel ports */
     76 	int mb_ncd1400;			/* number of CD1400 chips */
     77 	int mb_svcackr;			/* svcackr offset */
     78 	int mb_svcackt;			/* svcackt offset */
     79 	int mb_svcackm;			/* svcackm offset */
     80 	int mb_cd1400[MAGMA_MAX_CD1400];/* cd1400 chip register offsets */
     81 	int mb_ncd1190;			/* number of CD1190 chips */
     82 	int mb_cd1190[MAGMA_MAX_CD1190];/* cd1190 chip register offsets */
     83 };
     84 
     85 /*
     86  * cd1400 chip data
     87  */
     88 struct cd1400 {
     89 	__volatile u_char *cd_reg;	/* chip registers */
     90 	int cd_chiprev;			/* chip revision */
     91 	int cd_clock;			/* clock speed in Mhz */
     92 	int cd_parmode;			/* parallel mode operation */
     93 };
     94 
     95 /*
     96  * cd1190 chip data
     97  */
     98 struct cd1190 {
     99 	__volatile u_char *cd_reg;	/* chip registers */
    100 	int cd_chiprev;			/* chip revision */
    101 };
    102 
    103 /* software state for each card */
    104 struct magma_softc {
    105 	struct device	ms_dev;		/* required. must be first in softc */
    106 	struct sbusdev	ms_sd;		/* sbus device */
    107 	struct evcnt	ms_intrcnt;	/* statistics */
    108 
    109 	/* cd1400 chip info */
    110 	int	ms_ncd1400;
    111 	struct cd1400 ms_cd1400[MAGMA_MAX_CD1400];
    112 	__volatile u_char *ms_svcackr;	/* CD1400 service acknowledge receive */
    113 	__volatile u_char *ms_svcackt;	/* CD1400 service acknowledge transmit */
    114 	__volatile u_char *ms_svcackm;	/* CD1400 service acknowledge modem */
    115 
    116 	/* cd1190 chip info */
    117 	int ms_ncd1190;
    118 	struct cd1190 ms_cd1190[MAGMA_MAX_CD1190];
    119 
    120 	struct magma_board_info *ms_board;	/* what am I? */
    121 
    122 	struct mtty_softc *ms_mtty;
    123 	struct mbpp_softc *ms_mbpp;
    124 
    125 };
    126 
    127 #define MTTY_RBUF_SIZE		(2 * 512)
    128 #define MTTY_RX_FIFO_THRESHOLD	6
    129 #define MTTY_RX_DTR_THRESHOLD	9
    130 
    131 struct mtty_port {
    132 	struct cd1400 *mp_cd1400;	/* ptr to chip */
    133 	int mp_channel;			/* and channel */
    134 	struct tty *mp_tty;
    135 
    136 	int mp_openflags;	/* default tty flags */
    137 	int mp_flags;		/* port flags */
    138 	int mp_carrier;		/* state of carrier */
    139 
    140 	u_char *mp_rbuf;	/* ring buffer start */
    141 	u_char *mp_rend;	/* ring buffer end */
    142 	u_char *mp_rget;	/* ring buffer read pointer */
    143 	u_char *mp_rput;	/* ring buffer write pointer */
    144 
    145 	u_char *mp_txp;		/* transmit character pointer */
    146 	int mp_txc;		/* transmit character counter */
    147 };
    148 
    149 #define MTTYF_CARRIER_CHANGED	(1<<0)
    150 #define MTTYF_SET_BREAK		(1<<1)
    151 #define MTTYF_CLR_BREAK		(1<<2)
    152 #define MTTYF_DONE		(1<<3)
    153 #define MTTYF_STOP		(1<<4)
    154 #define MTTYF_RING_OVERFLOW	(1<<5)
    155 
    156 struct mtty_softc {
    157 	struct device ms_dev;		/* device info */
    158 	int ms_nports;			/* tty ports */
    159 	struct mtty_port ms_port[MAGMA_MAX_TTY];
    160 };
    161 
    162 #define MBPP_TXBUF_SIZE	(CD1400_PAR_FIFO_SIZE * 10)
    163 
    164 struct mbpp_port {
    165 	struct cd1400 *mp_cd1400;	/* for LC2+1Sp card */
    166 	struct cd1190 *mp_cd1190;	/* all the others   */
    167 
    168 	int mp_flags;
    169 
    170 	int mp_read_strobe;	/* strobe width in ns */
    171 	int mp_read_timeout;	/* timeout after this many seconds */
    172 
    173 	int mp_write_strobe;	/* strobe width in ns */
    174 	int mp_write_timeout;	/* timeout after this many seconds */
    175 
    176 	u_char *mp_txbuf;	/* transmit buffer */
    177 	u_char *mp_txp;		/* transmit pointer */
    178 	int mp_txc;		/* transmit counter */
    179 };
    180 
    181 #define MBPPF_OPEN	(1<<0)
    182 #define MBPPF_DONE	(1<<1)
    183 
    184 struct mbpp_softc {
    185 	struct device ms_dev;		/* device info */
    186 	int ms_nports;			/* parallel ports */
    187 	struct mbpp_port ms_port[MAGMA_MAX_BPP];
    188 };
    189 
    190 /*
    191  * useful macros
    192  */
    193 #define SET(t, f)	((t) |= (f))
    194 #define CLR(t, f)	((t) &= ~(f))
    195 #define ISSET(t, f)	((t) & (f))
    196 #define MIN(a, b)	((a) < (b) ? (a) : (b))
    197 
    198 /* internal function prototypes */
    199 
    200 int cd1400_compute_baud __P((speed_t, int, int *, int *));
    201 __inline void cd1400_write_ccr __P((struct cd1400 *, u_char));
    202 __inline u_char cd1400_read_reg __P((struct cd1400 *, int));
    203 __inline void cd1400_write_reg __P((struct cd1400 *, int, u_char));
    204 void cd1400_enable_transmitter __P((struct cd1400 *, int));
    205 
    206 int magma_match __P((struct device *, struct cfdata *, void *));
    207 void magma_attach __P((struct device *, struct device *, void *));
    208 int magma_hard __P((void *));
    209 int magma_soft __P((void *));
    210 
    211 int mtty_match __P((struct device *, struct cfdata *, void *));
    212 void mtty_attach __P((struct device *, struct device *, void *));
    213 int mtty_modem_control __P((struct mtty_port *, int, int));
    214 int mtty_param __P((struct tty *, struct termios *));
    215 void mtty_start __P((struct tty *));
    216 
    217 int mbpp_match __P((struct device *, struct cfdata *, void *));
    218 void mbpp_attach __P((struct device *, struct device *, void *));
    219