Home | History | Annotate | Line # | Download | only in sbus
magmareg.h revision 1.3
      1 /*	$NetBSD: magmareg.h,v 1.3 2000/03/23 07:01:43 thorpej 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_RX_FIFO_THRESHOLD	25
    163 
    164 struct mbpp_port {
    165 	struct cd1400 *mp_cd1400;	/* for LC2+1Sp card */
    166 	struct cd1190 *mp_cd1190;	/* all the others   */
    167 
    168 	struct callout mp_timeout_ch;
    169 	struct callout mp_start_ch;
    170 
    171 	int	mp_flags;
    172 
    173 	struct mbpp_param mp_param;
    174 #define mp_burst	mp_param.bp_burst
    175 #define mp_timeout	mp_param.bp_timeout
    176 #define mp_delay	mp_param.bp_delay
    177 
    178 	u_char	*mp_ptr;		/* pointer to I/O data */
    179 	int	mp_cnt;			/* count of I/O chars */
    180 };
    181 
    182 #define MBPPF_OPEN	(1<<0)
    183 #define MBPPF_TIMEOUT	(1<<1)
    184 #define MBPPF_UIO	(1<<2)
    185 #define MBPPF_DELAY	(1<<3)
    186 #define MBPPF_WAKEUP	(1<<4)
    187 
    188 struct mbpp_softc {
    189 	struct device ms_dev;		/* device info */
    190 	int ms_nports;			/* parallel ports */
    191 	struct mbpp_port ms_port[MAGMA_MAX_BPP];
    192 };
    193 
    194 /*
    195  * useful macros
    196  */
    197 #define SET(t, f)	((t) |= (f))
    198 #define CLR(t, f)	((t) &= ~(f))
    199 #define ISSET(t, f)	((t) & (f))
    200 
    201 /* internal function prototypes */
    202 
    203 int cd1400_compute_baud __P((speed_t, int, int *, int *));
    204 __inline void cd1400_write_ccr __P((struct cd1400 *, u_char));
    205 __inline u_char cd1400_read_reg __P((struct cd1400 *, int));
    206 __inline void cd1400_write_reg __P((struct cd1400 *, int, u_char));
    207 void cd1400_enable_transmitter __P((struct cd1400 *, int));
    208 
    209 int magma_match __P((struct device *, struct cfdata *, void *));
    210 void magma_attach __P((struct device *, struct device *, void *));
    211 int magma_hard __P((void *));
    212 int magma_soft __P((void *));
    213 
    214 int mtty_match __P((struct device *, struct cfdata *, void *));
    215 void mtty_attach __P((struct device *, struct device *, void *));
    216 int mtty_modem_control __P((struct mtty_port *, int, int));
    217 int mtty_param __P((struct tty *, struct termios *));
    218 void mtty_start __P((struct tty *));
    219 
    220 int mbpp_match __P((struct device *, struct cfdata *, void *));
    221 void mbpp_attach __P((struct device *, struct device *, void *));
    222 int mbpp_rw __P((dev_t, struct uio *));
    223 void mbpp_timeout __P((void *));
    224 void mbpp_start __P((void *));
    225 int mbpp_send __P((struct mbpp_port *, caddr_t, int));
    226 int mbpp_recv __P((struct mbpp_port *, caddr_t, int));
    227 int mbpp_hztoms __P((int));
    228 int mbpp_mstohz __P((int));
    229