Home | History | Annotate | Line # | Download | only in dev
mfc.c revision 1.22.2.1
      1  1.22.2.1   nathanw /*	$NetBSD: mfc.c,v 1.22.2.1 2001/06/21 18:47:13 nathanw Exp $ */
      2       1.3    chopps 
      3       1.1    chopps /*
      4       1.1    chopps  * Copyright (c) 1994 Michael L. Hitch
      5       1.1    chopps  * Copyright (c) 1982, 1990 The Regents of the University of California.
      6       1.1    chopps  * All rights reserved.
      7       1.1    chopps  *
      8       1.1    chopps  * Redistribution and use in source and binary forms, with or without
      9       1.1    chopps  * modification, are permitted provided that the following conditions
     10       1.1    chopps  * are met:
     11       1.1    chopps  * 1. Redistributions of source code must retain the above copyright
     12       1.1    chopps  *    notice, this list of conditions and the following disclaimer.
     13       1.1    chopps  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1    chopps  *    notice, this list of conditions and the following disclaimer in the
     15       1.1    chopps  *    documentation and/or other materials provided with the distribution.
     16       1.1    chopps  * 3. All advertising materials mentioning features or use of this software
     17       1.1    chopps  *    must display the following acknowledgement:
     18       1.1    chopps  *	This product includes software developed by the University of
     19       1.1    chopps  *	California, Berkeley and its contributors.
     20       1.1    chopps  * 4. Neither the name of the University nor the names of its contributors
     21       1.1    chopps  *    may be used to endorse or promote products derived from this software
     22       1.1    chopps  *    without specific prior written permission.
     23       1.1    chopps  *
     24       1.1    chopps  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25       1.1    chopps  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26       1.1    chopps  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27       1.1    chopps  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28       1.1    chopps  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29       1.1    chopps  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30       1.1    chopps  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31       1.1    chopps  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32       1.1    chopps  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33       1.1    chopps  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34       1.1    chopps  * SUCH DAMAGE.
     35       1.1    chopps  */
     36       1.1    chopps 
     37  1.22.2.1   nathanw #include "opt_kgdb.h"
     38  1.22.2.1   nathanw 
     39       1.1    chopps #include <sys/param.h>
     40       1.1    chopps #include <sys/systm.h>
     41       1.1    chopps #include <sys/kernel.h>
     42       1.1    chopps #include <sys/device.h>
     43       1.1    chopps #include <sys/tty.h>
     44       1.1    chopps #include <sys/proc.h>
     45       1.1    chopps #include <sys/file.h>
     46       1.1    chopps #include <sys/malloc.h>
     47       1.1    chopps #include <sys/uio.h>
     48       1.1    chopps #include <sys/kernel.h>
     49       1.1    chopps #include <sys/syslog.h>
     50       1.1    chopps #include <sys/queue.h>
     51       1.1    chopps #include <machine/cpu.h>
     52       1.1    chopps #include <amiga/amiga/device.h>
     53       1.2    chopps #include <amiga/amiga/isr.h>
     54       1.1    chopps #include <amiga/amiga/custom.h>
     55       1.1    chopps #include <amiga/amiga/cia.h>
     56       1.1    chopps #include <amiga/amiga/cc.h>
     57       1.2    chopps #include <amiga/dev/zbusvar.h>
     58       1.1    chopps 
     59       1.1    chopps #include <dev/cons.h>
     60       1.1    chopps 
     61      1.12     veego #include <sys/conf.h>
     62      1.12     veego #include <machine/conf.h>
     63      1.12     veego 
     64       1.1    chopps #include "mfcs.h"
     65       1.1    chopps 
     66       1.7    chopps #ifndef SEROBUF_SIZE
     67       1.1    chopps #define SEROBUF_SIZE	128
     68       1.7    chopps #endif
     69       1.7    chopps #ifndef SERIBUF_SIZE
     70       1.1    chopps #define SERIBUF_SIZE	1024
     71       1.7    chopps #endif
     72       1.1    chopps 
     73       1.2    chopps #define splser()	spl6()
     74       1.2    chopps 
     75       1.2    chopps /*
     76       1.2    chopps  * 68581 DUART registers
     77       1.2    chopps  */
     78       1.1    chopps struct mfc_regs {
     79       1.1    chopps 	volatile u_char du_mr1a;
     80       1.1    chopps #define	du_mr2a		du_mr1a
     81       1.1    chopps 	u_char pad0;
     82       1.1    chopps 	volatile u_char du_csra;
     83       1.1    chopps #define	du_sra		du_csra
     84       1.1    chopps 	u_char pad2;
     85       1.1    chopps 	volatile u_char du_cra;
     86       1.1    chopps 	u_char pad4;
     87       1.1    chopps 	volatile u_char du_tba;
     88       1.1    chopps #define	du_rba		du_tba
     89       1.1    chopps 	u_char pad6;
     90       1.1    chopps 	volatile u_char du_acr;
     91       1.1    chopps #define	du_ipcr		du_acr
     92       1.1    chopps 	u_char pad8;
     93       1.1    chopps 	volatile u_char du_imr;
     94       1.1    chopps #define	du_isr		du_imr
     95       1.1    chopps 	u_char pad10;
     96       1.1    chopps 	volatile u_char du_ctur;
     97       1.1    chopps #define	du_cmsb		du_ctur
     98       1.1    chopps 	u_char pad12;
     99       1.1    chopps 	volatile u_char du_ctlr;
    100       1.1    chopps #define	du_clsb		du_ctlr
    101       1.1    chopps 	u_char pad14;
    102       1.1    chopps 	volatile u_char du_mr1b;
    103       1.1    chopps #define	du_mr2b		du_mr1b
    104       1.1    chopps 	u_char pad16;
    105       1.1    chopps 	volatile u_char du_csrb;
    106       1.1    chopps #define	du_srb		du_csrb
    107       1.1    chopps 	u_char pad18;
    108       1.1    chopps 	volatile u_char du_crb;
    109       1.1    chopps 	u_char pad20;
    110       1.1    chopps 	volatile u_char du_tbb;
    111       1.1    chopps #define	du_rbb		du_tbb
    112       1.1    chopps 	u_char pad22;
    113       1.1    chopps 	volatile u_char du_ivr;
    114       1.1    chopps 	u_char pad24;
    115       1.1    chopps 	volatile u_char du_opcr;
    116       1.1    chopps #define	du_ip		du_opcr
    117       1.1    chopps 	u_char pad26;
    118       1.1    chopps 	volatile u_char du_btst;
    119       1.1    chopps #define	du_strc		du_btst
    120       1.1    chopps 	u_char pad28;
    121       1.1    chopps 	volatile u_char du_btrst;
    122       1.1    chopps #define	du_stpc		du_btrst
    123       1.1    chopps 	u_char pad30;
    124       1.1    chopps };
    125       1.1    chopps 
    126       1.2    chopps /*
    127       1.2    chopps  * 68681 DUART serial port registers
    128       1.2    chopps  */
    129       1.1    chopps struct duart_regs {
    130       1.1    chopps 	volatile u_char ch_mr1;
    131       1.1    chopps #define	ch_mr2		ch_mr1
    132       1.1    chopps 	u_char pad0;
    133       1.1    chopps 	volatile u_char	ch_csr;
    134       1.1    chopps #define	ch_sr		ch_csr
    135       1.1    chopps 	u_char pad1;
    136       1.1    chopps 	volatile u_char	ch_cr;
    137       1.1    chopps 	u_char pad2;
    138       1.1    chopps 	volatile u_char	ch_tb;
    139       1.1    chopps #define	ch_rb		ch_tb
    140       1.1    chopps 	u_char pad3;
    141       1.1    chopps };
    142       1.1    chopps 
    143       1.1    chopps struct mfc_softc {
    144       1.1    chopps 	struct	device sc_dev;
    145       1.2    chopps 	struct	isr sc_isr;
    146       1.1    chopps 	struct	mfc_regs *sc_regs;
    147       1.1    chopps 	u_long	clk_frq;
    148       1.1    chopps 	u_short	ct_val;
    149       1.1    chopps 	u_char	ct_usecnt;
    150       1.1    chopps 	u_char	imask;
    151       1.1    chopps 	u_char	mfc_iii;
    152       1.1    chopps 	u_char	last_ip;
    153       1.1    chopps };
    154       1.1    chopps 
    155       1.2    chopps #if NMFCS > 0
    156       1.1    chopps struct mfcs_softc {
    157       1.1    chopps 	struct	device sc_dev;
    158       1.6    chopps 	struct	tty *sc_tty;
    159       1.1    chopps 	struct	duart_regs *sc_duart;
    160       1.1    chopps 	struct	mfc_regs *sc_regs;
    161       1.1    chopps 	struct	mfc_softc *sc_mfc;
    162       1.9       jtc 	int	swflags;
    163       1.1    chopps 	long	flags;			/* XXX */
    164       1.1    chopps #define CT_USED	1			/* CT in use */
    165       1.1    chopps 	u_short	*rptr, *wptr, incnt, ovfl;
    166       1.1    chopps 	u_short	inbuf[SERIBUF_SIZE];
    167       1.1    chopps 	char	*ptr, *end;
    168       1.1    chopps 	char	outbuf[SEROBUF_SIZE];
    169       1.9       jtc 	struct vbl_node vbl_node;
    170       1.1    chopps };
    171       1.2    chopps #endif
    172       1.2    chopps 
    173       1.2    chopps #if NMFCP > 0
    174       1.2    chopps struct mfcp_softc {
    175       1.2    chopps };
    176       1.2    chopps #endif
    177       1.1    chopps 
    178       1.1    chopps struct mfc_args {
    179       1.1    chopps 	struct zbus_args zargs;
    180       1.1    chopps 	char	*subdev;
    181       1.1    chopps 	char	unit;
    182       1.1    chopps };
    183       1.1    chopps 
    184      1.14       cgd int	mfcprint __P((void *auxp, const char *));
    185      1.12     veego void	mfcattach __P((struct device *, struct device *, void *));
    186      1.18     veego int	mfcmatch __P((struct device *, struct cfdata *, void *));
    187      1.12     veego 
    188       1.2    chopps #if NMFCS > 0
    189      1.18     veego int	mfcsmatch __P((struct device *, struct cfdata *, void *));
    190      1.12     veego void	mfcsattach __P((struct device *, struct device *, void *));
    191      1.12     veego int	mfcsparam __P(( struct tty *, struct termios *));
    192      1.12     veego int	mfcshwiflow __P((struct tty *, int));
    193      1.12     veego void	mfcsstart __P((struct tty *));
    194      1.12     veego int	mfcsmctl __P((dev_t, int, int));
    195      1.12     veego void	mfcsxintr __P((int));
    196      1.12     veego void	mfcseint __P((int, int));
    197      1.12     veego void	mfcsmint __P((register int));
    198       1.2    chopps #endif
    199      1.12     veego 
    200       1.2    chopps #if NMFCP > 0
    201       1.2    chopps void mfcpattach __P((struct device *, struct device *, void *));
    202      1.18     veego int mfcpmatch __P((struct device *, struct cfdata *, void *));
    203       1.2    chopps #endif
    204      1.12     veego int mfcintr __P((void *));
    205       1.1    chopps 
    206      1.11    mhitch struct cfattach mfc_ca = {
    207      1.10   thorpej 	sizeof(struct mfc_softc), mfcmatch, mfcattach
    208      1.10   thorpej };
    209      1.10   thorpej 
    210       1.2    chopps #if NMFCS > 0
    211      1.10   thorpej struct cfattach mfcs_ca = {
    212      1.10   thorpej 	sizeof(struct mfcs_softc), mfcsmatch, mfcsattach
    213      1.10   thorpej };
    214      1.10   thorpej 
    215      1.19   thorpej extern struct cfdriver mfcs_cd;
    216       1.2    chopps #endif
    217       1.2    chopps 
    218       1.2    chopps #if NMFCP > 0
    219      1.10   thorpej struct cfattach mfcp_ca = {
    220      1.10   thorpej 	sizeof(struct mfcp_softc, mfcpmatch, mfcpattach
    221      1.10   thorpej };
    222       1.2    chopps #endif
    223       1.1    chopps 
    224      1.12     veego 
    225       1.1    chopps int	mfcs_active;
    226       1.1    chopps int	mfcsdefaultrate = 38400 /*TTYDEF_SPEED*/;
    227       1.9       jtc #define SWFLAGS(dev) (sc->swflags | (((dev) & 0x80) == 0 ? TIOCFLAG_SOFTCAR : 0))
    228       1.1    chopps 
    229       1.4    chopps #ifdef notyet
    230       1.4    chopps /*
    231       1.4    chopps  * MultiFaceCard III, II+ (not supported yet), and
    232       1.4    chopps  * SerialMaster 500+ (not supported yet)
    233       1.4    chopps  * baud rate tables for BRG set 1 [not used yet]
    234       1.4    chopps  */
    235       1.4    chopps 
    236       1.4    chopps struct speedtab mfcs3speedtab1[] = {
    237      1.12     veego 	{ 0,		0	},
    238      1.12     veego 	{ 100,		0x00	},
    239      1.12     veego 	{ 220,		0x11	},
    240      1.12     veego 	{ 600,		0x44	},
    241      1.12     veego 	{ 1200,		0x55	},
    242      1.12     veego 	{ 2400,		0x66	},
    243      1.12     veego 	{ 4800,		0x88	},
    244      1.12     veego 	{ 9600,		0x99	},
    245      1.12     veego 	{ 19200,	0xbb	},
    246      1.12     veego 	{ 115200,	0xcc	},
    247      1.12     veego 	{ -1,		-1	}
    248       1.4    chopps };
    249       1.4    chopps 
    250       1.4    chopps /*
    251       1.4    chopps  * MultiFaceCard II, I, and SerialMaster 500
    252       1.4    chopps  * baud rate tables for BRG set 1 [not used yet]
    253       1.4    chopps  */
    254       1.4    chopps 
    255       1.4    chopps struct speedtab mfcs2speedtab1[] = {
    256      1.12     veego 	{ 0,		0	},
    257      1.12     veego 	{ 50,		0x00	},
    258      1.12     veego 	{ 110,		0x11	},
    259      1.12     veego 	{ 300,		0x44	},
    260      1.12     veego 	{ 600,		0x55	},
    261      1.12     veego 	{ 1200,		0x66	},
    262      1.12     veego 	{ 2400,		0x88	},
    263      1.12     veego  	{ 4800,		0x99	},
    264      1.12     veego 	{ 9600,		0xbb	},
    265      1.12     veego 	{ 38400,	0xcc	},
    266      1.12     veego 	{ -1,		-1	}
    267       1.4    chopps };
    268       1.4    chopps #endif
    269       1.4    chopps 
    270       1.4    chopps /*
    271       1.4    chopps  * MultiFaceCard III, II+ (not supported yet), and
    272       1.4    chopps  * SerialMaster 500+ (not supported yet)
    273       1.4    chopps  * baud rate tables for BRG set 2
    274       1.4    chopps  */
    275       1.4    chopps 
    276       1.4    chopps struct speedtab mfcs3speedtab2[] = {
    277      1.12     veego 	{ 0,		0	},
    278      1.12     veego 	{ 150,		0x00	},
    279      1.12     veego 	{ 200,		0x11	},
    280      1.12     veego 	{ 300,		0x33	},
    281      1.12     veego 	{ 600,		0x44	},
    282      1.12     veego 	{ 1200,		0x55	},
    283      1.12     veego 	{ 2400,		0x66	},
    284      1.12     veego 	{ 4800,		0x88	},
    285      1.12     veego 	{ 9600,		0x99	},
    286      1.12     veego 	{ 19200,	0xbb	},
    287      1.12     veego 	{ 38400,	0xcc	},
    288      1.12     veego 	{ -1,		-1	}
    289       1.1    chopps };
    290       1.1    chopps 
    291       1.4    chopps /*
    292       1.4    chopps  * MultiFaceCard II, I, and SerialMaster 500
    293       1.4    chopps  * baud rate tables for BRG set 2
    294       1.4    chopps  */
    295       1.4    chopps 
    296       1.4    chopps struct speedtab mfcs2speedtab2[] = {
    297      1.12     veego 	{ 0,		0	},
    298      1.12     veego 	{ 75,		0x00	},
    299      1.12     veego 	{ 100,		0x11	},
    300      1.12     veego 	{ 150,		0x33	},
    301      1.12     veego 	{ 300,		0x44	},
    302      1.12     veego 	{ 600,		0x55	},
    303      1.12     veego 	{ 1200,		0x66	},
    304      1.12     veego 	{ 2400,		0x88	},
    305      1.12     veego  	{ 4800,		0x99	},
    306      1.12     veego 	{ 9600,		0xbb	},
    307      1.12     veego 	{ 19200,	0xcc	},
    308      1.12     veego 	{ -1,		-1	}
    309       1.1    chopps };
    310       1.1    chopps 
    311       1.1    chopps /*
    312       1.1    chopps  * if we are an bsc/Alf Data MultFaceCard (I, II, and III)
    313       1.1    chopps  */
    314       1.1    chopps int
    315      1.18     veego mfcmatch(pdp, cfp, auxp)
    316       1.1    chopps 	struct device *pdp;
    317      1.18     veego 	struct cfdata *cfp;
    318      1.18     veego 	void *auxp;
    319       1.1    chopps {
    320       1.1    chopps 	struct zbus_args *zap;
    321       1.1    chopps 
    322       1.1    chopps 	zap = auxp;
    323       1.1    chopps 	if (zap->manid == 2092 &&
    324       1.1    chopps 	    (zap->prodid == 16 || zap->prodid == 17 || zap->prodid == 18))
    325       1.2    chopps 
    326       1.1    chopps 		return(1);
    327       1.1    chopps 	return(0);
    328       1.1    chopps }
    329       1.1    chopps 
    330       1.1    chopps void
    331       1.1    chopps mfcattach(pdp, dp, auxp)
    332       1.1    chopps 	struct device *pdp, *dp;
    333       1.1    chopps 	void *auxp;
    334       1.1    chopps {
    335       1.1    chopps 	struct mfc_softc *scc;
    336       1.1    chopps 	struct zbus_args *zap;
    337       1.1    chopps 	struct mfc_args ma;
    338       1.1    chopps 	int unit;
    339       1.1    chopps 	struct mfc_regs *rp;
    340       1.1    chopps 
    341       1.1    chopps 	zap = auxp;
    342       1.2    chopps 
    343      1.17  christos 	printf ("\n");
    344       1.1    chopps 
    345       1.1    chopps 	scc = (struct mfc_softc *)dp;
    346       1.1    chopps 	unit = scc->sc_dev.dv_unit;
    347       1.1    chopps 	scc->sc_regs = rp = zap->va;
    348       1.1    chopps 	if (zap->prodid == 18)
    349       1.1    chopps 		scc->mfc_iii = 3;
    350       1.1    chopps 	scc->clk_frq = scc->mfc_iii ? 230400 : 115200;
    351       1.1    chopps 
    352       1.1    chopps 	rp->du_opcr = 0x00;		/* configure output port? */
    353       1.1    chopps 	rp->du_btrst = 0x0f;		/* clear modem lines */
    354       1.1    chopps 	rp->du_ivr = 0;			/* IVR */
    355       1.1    chopps 	rp->du_imr = 0;			/* IMR */
    356       1.1    chopps 	rp->du_acr = 0xe0;		/* baud rate generate set 2 */
    357       1.1    chopps 	rp->du_ctur = 0;
    358       1.1    chopps 	rp->du_ctlr = 4;
    359       1.1    chopps 	rp->du_csra = 0xcc;		/* clock select = 38400 */
    360       1.1    chopps 	rp->du_cra = 0x10;		/* reset mode register ptr */
    361       1.1    chopps 	rp->du_cra = 0x20;
    362       1.1    chopps 	rp->du_cra = 0x30;
    363       1.1    chopps 	rp->du_cra = 0x40;
    364       1.1    chopps 	rp->du_mr1a = 0x93;		/* MRA1 */
    365       1.1    chopps 	rp->du_mr2a = 0x17;		/* MRA2 */
    366       1.1    chopps 	rp->du_csrb = 0xcc;		/* clock select = 38400 */
    367       1.1    chopps 	rp->du_crb = 0x10;		/* reset mode register ptr */
    368       1.1    chopps 	rp->du_crb = 0x20;
    369       1.1    chopps 	rp->du_crb = 0x30;
    370       1.1    chopps 	rp->du_crb = 0x40;
    371       1.1    chopps 	rp->du_mr1b = 0x93;		/* MRB1 */
    372       1.1    chopps 	rp->du_mr2b = 0x17;		/* MRB2 */
    373       1.1    chopps 	rp->du_cra = 0x05;		/* enable A Rx & Tx */
    374       1.1    chopps 	rp->du_crb = 0x05;		/* enable B Rx & Tx */
    375       1.1    chopps 
    376       1.2    chopps 	scc->sc_isr.isr_intr = mfcintr;
    377       1.2    chopps 	scc->sc_isr.isr_arg = scc;
    378       1.2    chopps 	scc->sc_isr.isr_ipl = 6;
    379       1.2    chopps 	add_isr(&scc->sc_isr);
    380       1.1    chopps 
    381       1.1    chopps 	/* configure ports */
    382       1.1    chopps 	bcopy(zap, &ma.zargs, sizeof(struct zbus_args));
    383       1.1    chopps 	ma.subdev = "mfcs";
    384       1.1    chopps 	ma.unit = unit * 2;
    385       1.1    chopps 	config_found(dp, &ma, mfcprint);
    386       1.1    chopps 	ma.unit = unit * 2 + 1;
    387       1.1    chopps 	config_found(dp, &ma, mfcprint);
    388       1.1    chopps 	ma.subdev = "mfcp";
    389       1.1    chopps 	ma.unit = unit;
    390       1.1    chopps 	config_found(dp, &ma, mfcprint);
    391       1.1    chopps }
    392       1.1    chopps 
    393       1.1    chopps /*
    394       1.2    chopps  *
    395       1.1    chopps  */
    396       1.1    chopps int
    397      1.18     veego mfcsmatch(pdp, cfp, auxp)
    398       1.1    chopps 	struct device *pdp;
    399      1.18     veego 	struct cfdata *cfp;
    400      1.18     veego 	void *auxp;
    401       1.1    chopps {
    402       1.1    chopps 	struct mfc_args *ma;
    403       1.1    chopps 
    404       1.1    chopps 	ma = auxp;
    405       1.1    chopps 	if (strcmp(ma->subdev, "mfcs") == 0)
    406       1.1    chopps 		return (1);
    407       1.1    chopps 	return (0);
    408       1.1    chopps }
    409       1.1    chopps 
    410       1.1    chopps void
    411       1.1    chopps mfcsattach(pdp, dp, auxp)
    412       1.1    chopps 	struct device *pdp, *dp;
    413       1.1    chopps 	void *auxp;
    414       1.1    chopps {
    415       1.1    chopps 	int unit;
    416       1.1    chopps 	struct mfcs_softc *sc;
    417       1.1    chopps 	struct mfc_softc *scc;
    418       1.1    chopps 	struct mfc_args *ma;
    419       1.1    chopps 	struct mfc_regs *rp;
    420       1.1    chopps 
    421       1.1    chopps 	sc = (struct mfcs_softc *) dp;
    422       1.1    chopps 	scc = (struct mfc_softc *) pdp;
    423       1.1    chopps 	ma = auxp;
    424       1.1    chopps 
    425       1.1    chopps 	if (dp) {
    426      1.17  christos 		printf (": input fifo %d output fifo %d\n", SERIBUF_SIZE,
    427       1.1    chopps 		    SEROBUF_SIZE);
    428       1.1    chopps 		alloc_sicallback();
    429       1.1    chopps 	}
    430       1.1    chopps 
    431       1.1    chopps 	unit = ma->unit;
    432       1.1    chopps 	mfcs_active |= 1 << unit;
    433       1.1    chopps 	sc->rptr = sc->wptr = sc->inbuf;
    434       1.1    chopps 	sc->sc_mfc = scc;
    435       1.1    chopps 	sc->sc_regs = rp = scc->sc_regs;
    436       1.1    chopps 	sc->sc_duart = (struct duart_regs *) ((unit & 1) ? &rp->du_mr1b :
    437       1.1    chopps 	    &rp->du_mr1a);
    438       1.1    chopps 	/*
    439       1.1    chopps 	 * should have only one vbl routine to handle all ports?
    440       1.1    chopps 	 */
    441       1.9       jtc 	sc->vbl_node.function = (void (*) (void *)) mfcsmint;
    442       1.9       jtc 	sc->vbl_node.data = (void *) unit;
    443       1.9       jtc 	add_vbl_function(&sc->vbl_node, 1, (void *) unit);
    444       1.1    chopps }
    445       1.1    chopps 
    446       1.1    chopps /*
    447       1.1    chopps  * print diag if pnp is NULL else just extra
    448       1.1    chopps  */
    449       1.1    chopps int
    450       1.1    chopps mfcprint(auxp, pnp)
    451       1.1    chopps 	void *auxp;
    452      1.14       cgd 	const char *pnp;
    453       1.1    chopps {
    454       1.1    chopps 	if (pnp == NULL)
    455       1.1    chopps 		return(UNCONF);
    456       1.1    chopps 	return(QUIET);
    457       1.1    chopps }
    458       1.1    chopps 
    459       1.1    chopps int
    460       1.1    chopps mfcsopen(dev, flag, mode, p)
    461       1.1    chopps 	dev_t dev;
    462       1.1    chopps 	int flag, mode;
    463       1.1    chopps 	struct proc *p;
    464       1.1    chopps {
    465       1.1    chopps 	struct tty *tp;
    466       1.6    chopps 	struct mfcs_softc *sc;
    467       1.1    chopps 	int unit, error, s;
    468       1.1    chopps 
    469       1.1    chopps 	error = 0;
    470       1.1    chopps 	unit = dev & 0x1f;
    471       1.1    chopps 
    472      1.10   thorpej 	if (unit >= mfcs_cd.cd_ndevs || (mfcs_active & (1 << unit)) == 0)
    473       1.1    chopps 		return (ENXIO);
    474      1.10   thorpej 	sc = mfcs_cd.cd_devs[unit];
    475       1.1    chopps 
    476       1.1    chopps 	s = spltty();
    477       1.1    chopps 
    478       1.6    chopps 	if (sc->sc_tty)
    479       1.6    chopps 		tp = sc->sc_tty;
    480      1.13    mhitch 	else {
    481       1.6    chopps 		tp = sc->sc_tty = ttymalloc();
    482      1.13    mhitch 		tty_attach(tp);
    483      1.13    mhitch 	}
    484       1.1    chopps 
    485       1.1    chopps 	tp->t_oproc = (void (*) (struct tty *)) mfcsstart;
    486       1.1    chopps 	tp->t_param = mfcsparam;
    487       1.1    chopps 	tp->t_dev = dev;
    488       1.1    chopps 	tp->t_hwiflow = mfcshwiflow;
    489       1.1    chopps 
    490      1.20    mhitch 	if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
    491       1.1    chopps 		ttychars(tp);
    492       1.1    chopps 		if (tp->t_ispeed == 0) {
    493       1.1    chopps 			/*
    494       1.1    chopps 			 * only when cleared do we reset to defaults.
    495       1.1    chopps 			 */
    496       1.1    chopps 			tp->t_iflag = TTYDEF_IFLAG;
    497       1.1    chopps 			tp->t_oflag = TTYDEF_OFLAG;
    498       1.1    chopps 			tp->t_cflag = TTYDEF_CFLAG;
    499       1.1    chopps 			tp->t_lflag = TTYDEF_LFLAG;
    500       1.1    chopps 			tp->t_ispeed = tp->t_ospeed = mfcsdefaultrate;
    501       1.1    chopps 		}
    502       1.1    chopps 		/*
    503       1.1    chopps 		 * do these all the time
    504       1.1    chopps 		 */
    505       1.9       jtc 		if (sc->swflags & TIOCFLAG_CLOCAL)
    506       1.1    chopps 			tp->t_cflag |= CLOCAL;
    507       1.9       jtc 		if (sc->swflags & TIOCFLAG_CRTSCTS)
    508       1.1    chopps 			tp->t_cflag |= CRTSCTS;
    509       1.9       jtc 		if (sc->swflags & TIOCFLAG_MDMBUF)
    510       1.1    chopps 			tp->t_cflag |= MDMBUF;
    511       1.1    chopps 		mfcsparam(tp, &tp->t_termios);
    512       1.1    chopps 		ttsetwater(tp);
    513       1.2    chopps 
    514       1.1    chopps 		(void)mfcsmctl(dev, TIOCM_DTR | TIOCM_RTS, DMSET);
    515       1.2    chopps 		if ((SWFLAGS(dev) & TIOCFLAG_SOFTCAR) ||
    516       1.1    chopps 		    (mfcsmctl(dev, 0, DMGET) & TIOCM_CD))
    517       1.1    chopps 			tp->t_state |= TS_CARR_ON;
    518       1.1    chopps 		else
    519       1.1    chopps 			tp->t_state &= ~TS_CARR_ON;
    520       1.1    chopps 	} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
    521       1.1    chopps 		splx(s);
    522       1.1    chopps 		return(EBUSY);
    523       1.1    chopps 	}
    524       1.1    chopps 
    525       1.1    chopps 	/*
    526       1.1    chopps 	 * if NONBLOCK requested, ignore carrier
    527       1.1    chopps 	 */
    528       1.1    chopps 	if (flag & O_NONBLOCK)
    529       1.1    chopps 		goto done;
    530       1.1    chopps 
    531       1.1    chopps 	/*
    532       1.1    chopps 	 * block waiting for carrier
    533       1.1    chopps 	 */
    534       1.1    chopps 	while ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0) {
    535      1.20    mhitch 		tp->t_wopen++;
    536       1.2    chopps 		error = ttysleep(tp, (caddr_t)&tp->t_rawq,
    537       1.1    chopps 		    TTIPRI | PCATCH, ttopen, 0);
    538      1.20    mhitch 		tp->t_wopen--;
    539       1.1    chopps 		if (error) {
    540       1.1    chopps 			splx(s);
    541       1.1    chopps 			return(error);
    542       1.1    chopps 		}
    543       1.1    chopps 	}
    544       1.1    chopps done:
    545       1.1    chopps 	/* This is a way to handle lost XON characters */
    546       1.1    chopps 	if ((flag & O_TRUNC) && (tp->t_state & TS_TTSTOP)) {
    547       1.1    chopps 		tp->t_state &= ~TS_TTSTOP;
    548       1.1    chopps 	        ttstart (tp);
    549       1.1    chopps 	}
    550       1.1    chopps 
    551       1.1    chopps 	splx(s);
    552       1.1    chopps 	/*
    553       1.1    chopps 	 * Reset the tty pointer, as there could have been a dialout
    554       1.1    chopps 	 * use of the tty with a dialin open waiting.
    555       1.1    chopps 	 */
    556       1.1    chopps 	tp->t_dev = dev;
    557      1.22   aymeric 	return tp->t_linesw->l_open(dev, tp);
    558       1.1    chopps }
    559       1.1    chopps 
    560       1.1    chopps /*ARGSUSED*/
    561       1.1    chopps int
    562       1.1    chopps mfcsclose(dev, flag, mode, p)
    563       1.1    chopps 	dev_t dev;
    564       1.1    chopps 	int flag, mode;
    565       1.1    chopps 	struct proc *p;
    566       1.1    chopps {
    567       1.1    chopps 	struct tty *tp;
    568       1.1    chopps 	int unit;
    569      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    570       1.1    chopps 	struct mfc_softc *scc= sc->sc_mfc;
    571       1.1    chopps 
    572       1.1    chopps 	unit = dev & 31;
    573       1.1    chopps 
    574       1.6    chopps 	tp = sc->sc_tty;
    575      1.22   aymeric 	tp->t_linesw->l_close(tp, flag);
    576       1.1    chopps 	sc->sc_duart->ch_cr = 0x70;			/* stop break */
    577       1.1    chopps 
    578       1.1    chopps 	scc->imask &= ~(0x7 << ((unit & 1) * 4));
    579       1.1    chopps 	scc->sc_regs->du_imr = scc->imask;
    580       1.1    chopps 	if (sc->flags & CT_USED) {
    581       1.1    chopps 		--scc->ct_usecnt;
    582       1.1    chopps 		sc->flags &= ~CT_USED;
    583       1.1    chopps 	}
    584       1.1    chopps 
    585       1.1    chopps 	/*
    586       1.1    chopps 	 * If the device is closed, it's close, no matter whether we deal with
    587       1.1    chopps 	 * modem control signals nor not.
    588       1.1    chopps 	 */
    589       1.1    chopps #if 0
    590      1.20    mhitch 	if (tp->t_cflag & HUPCL || tp->t_wopen != 0 ||
    591       1.1    chopps 	    (tp->t_state & TS_ISOPEN) == 0)
    592       1.1    chopps #endif
    593       1.1    chopps 		(void) mfcsmctl(dev, 0, DMSET);
    594       1.1    chopps 	ttyclose(tp);
    595       1.1    chopps #if not_yet
    596       1.1    chopps 	if (tp != &mfcs_cons) {
    597       1.9       jtc 		remove_vbl_function(&sc->vbl_node);
    598       1.1    chopps 		ttyfree(tp);
    599       1.6    chopps 		sc->sc_tty = (struct tty *) NULL;
    600       1.1    chopps 	}
    601       1.1    chopps #endif
    602       1.1    chopps 	return (0);
    603       1.1    chopps }
    604       1.1    chopps 
    605       1.1    chopps int
    606       1.1    chopps mfcsread(dev, uio, flag)
    607       1.1    chopps 	dev_t dev;
    608       1.1    chopps 	struct uio *uio;
    609       1.1    chopps 	int flag;
    610       1.1    chopps {
    611      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    612       1.6    chopps 	struct tty *tp = sc->sc_tty;
    613       1.6    chopps 	if (tp == NULL)
    614       1.1    chopps 		return(ENXIO);
    615      1.22   aymeric 	return tp->t_linesw->l_read(tp, uio, flag);
    616       1.1    chopps }
    617       1.1    chopps 
    618       1.1    chopps int
    619       1.1    chopps mfcswrite(dev, uio, flag)
    620       1.1    chopps 	dev_t dev;
    621       1.1    chopps 	struct uio *uio;
    622       1.1    chopps 	int flag;
    623       1.1    chopps {
    624      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    625       1.6    chopps 	struct tty *tp = sc->sc_tty;
    626       1.1    chopps 
    627       1.6    chopps 	if (tp == NULL)
    628       1.1    chopps 		return(ENXIO);
    629      1.22   aymeric 	return tp->t_linesw->l_write(tp, uio, flag);
    630  1.22.2.1   nathanw }
    631  1.22.2.1   nathanw 
    632  1.22.2.1   nathanw int
    633  1.22.2.1   nathanw mfcspoll(dev, events, p)
    634  1.22.2.1   nathanw 	dev_t dev;
    635  1.22.2.1   nathanw 	int events;
    636  1.22.2.1   nathanw 	struct proc *p;
    637  1.22.2.1   nathanw {
    638  1.22.2.1   nathanw 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    639  1.22.2.1   nathanw 	struct tty *tp = sc->sc_tty;
    640  1.22.2.1   nathanw 
    641  1.22.2.1   nathanw 	if (tp == NULL)
    642  1.22.2.1   nathanw 		return(ENXIO);
    643  1.22.2.1   nathanw 	return ((*tp->t_linesw->l_poll)(tp, events, p));
    644       1.1    chopps }
    645       1.5    chopps 
    646       1.5    chopps struct tty *
    647       1.5    chopps mfcstty(dev)
    648       1.5    chopps 	dev_t dev;
    649       1.5    chopps {
    650      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    651       1.6    chopps 
    652       1.6    chopps 	return (sc->sc_tty);
    653       1.5    chopps }
    654       1.5    chopps 
    655       1.1    chopps int
    656       1.1    chopps mfcsioctl(dev, cmd, data, flag, p)
    657       1.1    chopps 	dev_t	dev;
    658      1.12     veego 	u_long	cmd;
    659       1.1    chopps 	caddr_t data;
    660      1.12     veego 	int	flag;
    661       1.1    chopps 	struct proc *p;
    662       1.1    chopps {
    663       1.1    chopps 	register struct tty *tp;
    664       1.1    chopps 	register int error;
    665      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    666       1.1    chopps 
    667       1.6    chopps 	tp = sc->sc_tty;
    668       1.1    chopps 	if (!tp)
    669       1.1    chopps 		return ENXIO;
    670       1.1    chopps 
    671      1.22   aymeric 	error = tp->t_linesw->l_ioctl(tp, cmd, data, flag, p);
    672       1.1    chopps 	if (error >= 0)
    673       1.1    chopps 		return(error);
    674       1.1    chopps 
    675       1.1    chopps 	error = ttioctl(tp, cmd, data, flag, p);
    676       1.1    chopps 	if (error >= 0)
    677       1.1    chopps 		return(error);
    678       1.1    chopps 
    679       1.1    chopps 	switch (cmd) {
    680       1.1    chopps 	case TIOCSBRK:
    681       1.1    chopps 		sc->sc_duart->ch_cr = 0x60;		/* start break */
    682       1.1    chopps 		break;
    683       1.1    chopps 
    684       1.1    chopps 	case TIOCCBRK:
    685       1.1    chopps 		sc->sc_duart->ch_cr = 0x70;		/* stop break */
    686       1.1    chopps 		break;
    687       1.1    chopps 
    688       1.1    chopps 	case TIOCSDTR:
    689       1.1    chopps 		(void) mfcsmctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIS);
    690       1.1    chopps 		break;
    691       1.1    chopps 
    692       1.1    chopps 	case TIOCCDTR:
    693       1.1    chopps 		(void) mfcsmctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIC);
    694       1.1    chopps 		break;
    695       1.1    chopps 
    696       1.1    chopps 	case TIOCMSET:
    697       1.1    chopps 		(void) mfcsmctl(dev, *(int *) data, DMSET);
    698       1.1    chopps 		break;
    699       1.1    chopps 
    700       1.1    chopps 	case TIOCMBIS:
    701       1.1    chopps 		(void) mfcsmctl(dev, *(int *) data, DMBIS);
    702       1.1    chopps 		break;
    703       1.1    chopps 
    704       1.1    chopps 	case TIOCMBIC:
    705       1.1    chopps 		(void) mfcsmctl(dev, *(int *) data, DMBIC);
    706       1.1    chopps 		break;
    707       1.1    chopps 
    708       1.1    chopps 	case TIOCMGET:
    709       1.1    chopps 		*(int *)data = mfcsmctl(dev, 0, DMGET);
    710       1.1    chopps 		break;
    711       1.1    chopps 	case TIOCGFLAGS:
    712       1.1    chopps 		*(int *)data = SWFLAGS(dev);
    713       1.1    chopps 		break;
    714       1.1    chopps 	case TIOCSFLAGS:
    715       1.2    chopps 		error = suser(p->p_ucred, &p->p_acflag);
    716       1.1    chopps 		if (error != 0)
    717       1.2    chopps 			return(EPERM);
    718       1.1    chopps 
    719       1.9       jtc 		sc->swflags = *(int *)data;
    720       1.9       jtc                 sc->swflags &= /* only allow valid flags */
    721       1.1    chopps                   (TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL | TIOCFLAG_CRTSCTS);
    722       1.4    chopps 		/* XXXX need to change duart parameters? */
    723       1.1    chopps 		break;
    724       1.1    chopps 	default:
    725       1.1    chopps 		return(ENOTTY);
    726       1.1    chopps 	}
    727       1.1    chopps 
    728       1.1    chopps 	return(0);
    729       1.1    chopps }
    730       1.1    chopps 
    731       1.1    chopps int
    732       1.1    chopps mfcsparam(tp, t)
    733       1.1    chopps 	struct tty *tp;
    734       1.1    chopps 	struct termios *t;
    735       1.1    chopps {
    736      1.12     veego 	int cflag, unit, ospeed;
    737      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[tp->t_dev & 31];
    738       1.1    chopps 	struct mfc_softc *scc= sc->sc_mfc;
    739       1.2    chopps 
    740       1.1    chopps 	cflag = t->c_cflag;
    741       1.1    chopps 	unit = tp->t_dev & 31;
    742       1.1    chopps 	if (sc->flags & CT_USED) {
    743       1.1    chopps 		--scc->ct_usecnt;
    744       1.1    chopps 		sc->flags &= ~CT_USED;
    745       1.1    chopps 	}
    746       1.4    chopps 	ospeed = ttspeedtab(t->c_ospeed, scc->mfc_iii ? mfcs3speedtab2 :
    747       1.4    chopps 	    mfcs2speedtab2);
    748       1.1    chopps 
    749       1.1    chopps 	/*
    750       1.1    chopps 	 * If Baud Rate Generator can't generate requested speed,
    751       1.1    chopps 	 * try to use the counter/timer.
    752       1.1    chopps 	 */
    753       1.1    chopps 	if (ospeed < 0 && (scc->clk_frq % t->c_ospeed) == 0) {
    754       1.1    chopps 		ospeed = scc->clk_frq / t->c_ospeed;	/* divisor */
    755       1.1    chopps 		if (scc->ct_usecnt > 0 && scc->ct_val != ospeed)
    756       1.1    chopps 			ospeed = -1;
    757       1.1    chopps 		else {
    758       1.1    chopps 			scc->sc_regs->du_ctur = ospeed >> 8;
    759       1.1    chopps 			scc->sc_regs->du_ctlr = ospeed;
    760       1.1    chopps 			scc->ct_val = ospeed;
    761       1.1    chopps 			++scc->ct_usecnt;
    762       1.1    chopps 			sc->flags |= CT_USED;
    763       1.1    chopps 			ospeed = 0xdd;
    764       1.1    chopps 		}
    765       1.1    chopps 	}
    766       1.1    chopps 	/* XXXX 68681 duart could handle split speeds */
    767       1.1    chopps 	if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
    768       1.1    chopps 		return(EINVAL);
    769       1.1    chopps 
    770       1.4    chopps 	/* XXXX handle parity, character size, stop bits, flow control */
    771       1.4    chopps 
    772       1.2    chopps 	/*
    773       1.1    chopps 	 * copy to tty
    774       1.1    chopps 	 */
    775       1.1    chopps 	tp->t_ispeed = t->c_ispeed;
    776       1.1    chopps 	tp->t_ospeed = t->c_ospeed;
    777       1.1    chopps 	tp->t_cflag = cflag;
    778       1.1    chopps 
    779       1.1    chopps 	/*
    780       1.1    chopps 	 * enable interrupts
    781       1.1    chopps 	 */
    782       1.1    chopps 	scc->imask |= (0x2 << ((unit & 1) * 4)) | 0x80;
    783       1.1    chopps 	scc->sc_regs->du_imr = scc->imask;
    784       1.1    chopps #if defined(DEBUG) && 0
    785      1.17  christos 	printf("mfcsparam: speed %d => %x ct %d imask %x cflag %x\n",
    786       1.1    chopps 	    t->c_ospeed, ospeed, scc->ct_val, scc->imask, cflag);
    787       1.1    chopps #endif
    788       1.1    chopps 	if (ospeed == 0)
    789       1.1    chopps 		(void)mfcsmctl(tp->t_dev, 0, DMSET);	/* hang up line */
    790       1.1    chopps 	else {
    791       1.2    chopps 		/*
    792       1.1    chopps 		 * (re)enable DTR
    793       1.1    chopps 		 * and set baud rate. (8 bit mode)
    794       1.1    chopps 		 */
    795       1.1    chopps 		(void)mfcsmctl(tp->t_dev, TIOCM_DTR | TIOCM_RTS, DMSET);
    796       1.1    chopps 		sc->sc_duart->ch_csr = ospeed;
    797       1.1    chopps 	}
    798       1.1    chopps 	return(0);
    799       1.1    chopps }
    800       1.1    chopps 
    801      1.12     veego int
    802      1.12     veego mfcshwiflow(tp, flag)
    803       1.1    chopps         struct tty *tp;
    804       1.1    chopps         int flag;
    805       1.1    chopps {
    806      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[tp->t_dev & 31];
    807       1.1    chopps 	int unit = tp->t_dev & 1;
    808       1.1    chopps 
    809       1.1    chopps         if (flag)
    810       1.1    chopps 		sc->sc_regs->du_btrst = 1 << unit;
    811       1.1    chopps 	else
    812       1.1    chopps 		sc->sc_regs->du_btst = 1 << unit;
    813       1.1    chopps         return 1;
    814       1.1    chopps }
    815       1.1    chopps 
    816      1.12     veego void
    817       1.1    chopps mfcsstart(tp)
    818       1.1    chopps 	struct tty *tp;
    819       1.1    chopps {
    820       1.1    chopps 	int cc, s, unit;
    821      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[tp->t_dev & 31];
    822       1.1    chopps 	struct mfc_softc *scc= sc->sc_mfc;
    823       1.1    chopps 
    824       1.1    chopps 	if ((tp->t_state & TS_ISOPEN) == 0)
    825       1.1    chopps 		return;
    826       1.1    chopps 
    827       1.1    chopps 	unit = tp->t_dev & 1;
    828       1.1    chopps 
    829       1.2    chopps 	s = splser();
    830       1.1    chopps 	if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))
    831       1.1    chopps 		goto out;
    832       1.1    chopps 
    833       1.1    chopps 	cc = tp->t_outq.c_cc;
    834       1.1    chopps 	if (cc <= tp->t_lowat) {
    835       1.1    chopps 		if (tp->t_state & TS_ASLEEP) {
    836       1.1    chopps 			tp->t_state &= ~TS_ASLEEP;
    837       1.1    chopps 			wakeup((caddr_t) & tp->t_outq);
    838       1.1    chopps 		}
    839       1.1    chopps 		selwakeup(&tp->t_wsel);
    840       1.1    chopps 	}
    841       1.1    chopps 	if (cc == 0 || (tp->t_state & TS_BUSY))
    842       1.1    chopps 		goto out;
    843       1.1    chopps 
    844       1.1    chopps 	/*
    845       1.1    chopps 	 * We only do bulk transfers if using CTSRTS flow control, not for
    846       1.1    chopps 	 * (probably sloooow) ixon/ixoff devices.
    847       1.1    chopps 	 */
    848       1.1    chopps 	if ((tp->t_cflag & CRTSCTS) == 0)
    849       1.1    chopps 		cc = 1;
    850       1.1    chopps 
    851       1.1    chopps 	/*
    852       1.1    chopps 	 * Limit the amount of output we do in one burst
    853       1.1    chopps 	 * to prevent hogging the CPU.
    854       1.1    chopps 	 */
    855       1.1    chopps 	if (cc > SEROBUF_SIZE)
    856       1.1    chopps 		cc = SEROBUF_SIZE;
    857       1.1    chopps 	cc = q_to_b(&tp->t_outq, sc->outbuf, cc);
    858       1.1    chopps 	if (cc > 0) {
    859       1.1    chopps 		tp->t_state |= TS_BUSY;
    860       1.1    chopps 
    861       1.1    chopps 		sc->ptr = sc->outbuf;
    862       1.1    chopps 		sc->end = sc->outbuf + cc;
    863       1.1    chopps 
    864       1.1    chopps 		/*
    865       1.1    chopps 		 * Get first character out, then have TBE-interrupts blow out
    866       1.1    chopps 		 * further characters, until buffer is empty, and TS_BUSY gets
    867       1.2    chopps 		 * cleared.
    868       1.1    chopps 		 */
    869       1.1    chopps 		sc->sc_duart->ch_tb = *sc->ptr++;
    870       1.1    chopps 		scc->imask |= 1 << (unit * 4);
    871       1.1    chopps 		sc->sc_regs->du_imr = scc->imask;
    872       1.1    chopps 	}
    873       1.1    chopps out:
    874       1.1    chopps 	splx(s);
    875       1.1    chopps }
    876       1.1    chopps 
    877       1.1    chopps /*
    878       1.1    chopps  * Stop output on a line.
    879       1.1    chopps  */
    880       1.1    chopps /*ARGSUSED*/
    881      1.15   mycroft void
    882       1.1    chopps mfcsstop(tp, flag)
    883       1.1    chopps 	struct tty *tp;
    884      1.12     veego 	int flag;
    885       1.1    chopps {
    886       1.1    chopps 	int s;
    887       1.1    chopps 
    888       1.2    chopps 	s = splser();
    889       1.1    chopps 	if (tp->t_state & TS_BUSY) {
    890       1.1    chopps 		if ((tp->t_state & TS_TTSTOP) == 0)
    891       1.1    chopps 			tp->t_state |= TS_FLUSH;
    892       1.1    chopps 	}
    893       1.1    chopps 	splx(s);
    894       1.1    chopps }
    895       1.1    chopps 
    896       1.1    chopps int
    897       1.1    chopps mfcsmctl(dev, bits, how)
    898       1.1    chopps 	dev_t dev;
    899       1.1    chopps 	int bits, how;
    900       1.1    chopps {
    901       1.1    chopps 	int unit, s;
    902      1.12     veego 	u_char ub = 0;
    903      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
    904       1.1    chopps 
    905       1.1    chopps 	unit = dev & 1;
    906       1.1    chopps 
    907       1.1    chopps 	/*
    908       1.1    chopps 	 * convert TIOCM* mask into CIA mask
    909       1.1    chopps 	 * which is active low
    910       1.1    chopps 	 */
    911       1.1    chopps 	if (how != DMGET) {
    912       1.1    chopps 		/*
    913       1.1    chopps 		 * need to save current state of DTR & RTS ?
    914       1.1    chopps 		 */
    915       1.1    chopps 		if (bits & TIOCM_DTR)
    916       1.1    chopps 			ub |= 0x04 << unit;
    917       1.1    chopps 		if (bits & TIOCM_RTS)
    918       1.1    chopps 			ub |= 0x01 << unit;
    919       1.1    chopps 	}
    920       1.2    chopps 	s = splser();
    921       1.1    chopps 	switch (how) {
    922       1.1    chopps 	case DMSET:
    923       1.1    chopps 		sc->sc_regs->du_btst = ub;
    924       1.4    chopps 		sc->sc_regs->du_btrst = ub ^ (0x05 << unit);
    925       1.1    chopps 		break;
    926       1.1    chopps 
    927       1.1    chopps 	case DMBIC:
    928       1.1    chopps 		sc->sc_regs->du_btrst = ub;
    929       1.1    chopps 		ub = ~sc->sc_regs->du_ip;
    930       1.1    chopps 		break;
    931       1.1    chopps 
    932       1.1    chopps 	case DMBIS:
    933       1.1    chopps 		sc->sc_regs->du_btst = ub;
    934       1.1    chopps 		ub = ~sc->sc_regs->du_ip;
    935       1.1    chopps 		break;
    936       1.1    chopps 
    937       1.1    chopps 	case DMGET:
    938       1.1    chopps 		ub = ~sc->sc_regs->du_ip;
    939       1.1    chopps 		break;
    940       1.1    chopps 	}
    941       1.1    chopps 	(void)splx(s);
    942       1.1    chopps 
    943       1.4    chopps 	/* XXXX should keep DTR & RTS states in softc? */
    944       1.1    chopps 	bits = TIOCM_DTR | TIOCM_RTS;
    945       1.1    chopps 	if (ub & (1 << unit))
    946       1.1    chopps 		bits |= TIOCM_CTS;
    947       1.1    chopps 	if (ub & (4 << unit))
    948       1.1    chopps 		bits |= TIOCM_DSR;
    949       1.1    chopps 	if (ub & (0x10 << unit))
    950       1.1    chopps 		bits |= TIOCM_CD;
    951       1.4    chopps 	/* XXXX RI is not supported on all boards */
    952       1.1    chopps 	if (sc->sc_regs->pad26 & (1 << unit))
    953       1.1    chopps 		bits |= TIOCM_RI;
    954       1.1    chopps 
    955       1.1    chopps 	return(bits);
    956       1.1    chopps }
    957       1.1    chopps 
    958       1.1    chopps /*
    959       1.2    chopps  * Level 6 interrupt processing for the MultiFaceCard 68681 DUART
    960       1.1    chopps  */
    961       1.1    chopps 
    962       1.1    chopps int
    963      1.12     veego mfcintr(arg)
    964      1.12     veego 	void *arg;
    965       1.1    chopps {
    966      1.12     veego 	struct mfc_softc *scc = arg;
    967       1.1    chopps 	struct mfcs_softc *sc;
    968       1.1    chopps 	struct mfc_regs *regs;
    969       1.2    chopps 	struct tty *tp;
    970       1.2    chopps 	int istat, unit;
    971       1.2    chopps 	u_short c;
    972       1.1    chopps 
    973       1.2    chopps 	regs = scc->sc_regs;
    974       1.2    chopps 	istat = regs->du_isr & scc->imask;
    975       1.2    chopps 	if (istat == 0)
    976       1.2    chopps 		return (0);
    977       1.2    chopps 	unit = scc->sc_dev.dv_unit * 2;
    978       1.2    chopps 	if (istat & 0x02) {		/* channel A receive interrupt */
    979      1.10   thorpej 		sc = mfcs_cd.cd_devs[unit];
    980       1.2    chopps 		while (1) {
    981       1.2    chopps 			c = regs->du_sra << 8;
    982       1.2    chopps 			if ((c & 0x0100) == 0)
    983       1.2    chopps 				break;
    984       1.2    chopps 			c |= regs->du_rba;
    985       1.2    chopps 			if (sc->incnt == SERIBUF_SIZE)
    986       1.2    chopps 				++sc->ovfl;
    987       1.2    chopps 			else {
    988       1.2    chopps 				*sc->wptr++ = c;
    989       1.2    chopps 				if (sc->wptr == sc->inbuf + SERIBUF_SIZE)
    990       1.2    chopps 					sc->wptr = sc->inbuf;
    991       1.2    chopps 				++sc->incnt;
    992       1.2    chopps 				if (sc->incnt > SERIBUF_SIZE - 16)
    993       1.2    chopps 					regs->du_btrst = 1;
    994       1.1    chopps 			}
    995       1.2    chopps 			if (c & 0x1000)
    996       1.2    chopps 				regs->du_cra = 0x40;
    997       1.1    chopps 		}
    998       1.2    chopps 	}
    999       1.2    chopps 	if (istat & 0x20) {		/* channel B receive interrupt */
   1000      1.10   thorpej 		sc = mfcs_cd.cd_devs[unit + 1];
   1001       1.2    chopps 		while (1) {
   1002       1.2    chopps 			c = regs->du_srb << 8;
   1003       1.2    chopps 			if ((c & 0x0100) == 0)
   1004       1.2    chopps 				break;
   1005       1.2    chopps 			c |= regs->du_rbb;
   1006       1.2    chopps 			if (sc->incnt == SERIBUF_SIZE)
   1007       1.2    chopps 				++sc->ovfl;
   1008       1.2    chopps 			else {
   1009       1.2    chopps 				*sc->wptr++ = c;
   1010       1.2    chopps 				if (sc->wptr == sc->inbuf + SERIBUF_SIZE)
   1011       1.2    chopps 					sc->wptr = sc->inbuf;
   1012       1.2    chopps 				++sc->incnt;
   1013       1.2    chopps 				if (sc->incnt > SERIBUF_SIZE - 16)
   1014       1.2    chopps 					regs->du_btrst = 2;
   1015       1.1    chopps 			}
   1016       1.2    chopps 			if (c & 0x1000)
   1017       1.2    chopps 				regs->du_crb = 0x40;
   1018       1.1    chopps 		}
   1019       1.2    chopps 	}
   1020       1.2    chopps 	if (istat & 0x01) {		/* channel A transmit interrupt */
   1021      1.10   thorpej 		sc = mfcs_cd.cd_devs[unit];
   1022       1.6    chopps 		tp = sc->sc_tty;
   1023       1.2    chopps 		if (sc->ptr == sc->end) {
   1024       1.2    chopps 			tp->t_state &= ~(TS_BUSY | TS_FLUSH);
   1025       1.2    chopps 			scc->imask &= ~0x01;
   1026       1.2    chopps 			regs->du_imr = scc->imask;
   1027      1.22   aymeric 			add_sicallback (tp->t_linesw ?
   1028      1.21       eeh 			    (sifunc_t)tp->t_linesw->l_start
   1029       1.8    chopps 			    : (sifunc_t)mfcsstart, tp, NULL);
   1030       1.2    chopps 
   1031       1.1    chopps 		}
   1032       1.2    chopps 		else
   1033       1.2    chopps 			regs->du_tba = *sc->ptr++;
   1034       1.2    chopps 	}
   1035       1.2    chopps 	if (istat & 0x10) {		/* channel B transmit interrupt */
   1036      1.10   thorpej 		sc = mfcs_cd.cd_devs[unit + 1];
   1037       1.6    chopps 		tp = sc->sc_tty;
   1038       1.2    chopps 		if (sc->ptr == sc->end) {
   1039       1.2    chopps 			tp->t_state &= ~(TS_BUSY | TS_FLUSH);
   1040       1.2    chopps 			scc->imask &= ~0x10;
   1041       1.2    chopps 			regs->du_imr = scc->imask;
   1042      1.22   aymeric 			add_sicallback (tp->t_linesw ?
   1043      1.21       eeh 			    (sifunc_t)tp->t_linesw->l_start
   1044       1.8    chopps 			    : (sifunc_t)mfcsstart, tp, NULL);
   1045       1.1    chopps 		}
   1046       1.2    chopps 		else
   1047       1.2    chopps 			regs->du_tbb = *sc->ptr++;
   1048       1.2    chopps 	}
   1049       1.2    chopps 	if (istat & 0x80) {		/* input port change interrupt */
   1050       1.2    chopps 		c = regs->du_ipcr;
   1051      1.17  christos 		printf ("%s: ipcr %02x", scc->sc_dev.dv_xname, c);
   1052       1.1    chopps 	}
   1053       1.2    chopps 	return(1);
   1054       1.1    chopps }
   1055       1.1    chopps 
   1056      1.12     veego void
   1057       1.1    chopps mfcsxintr(unit)
   1058       1.1    chopps 	int unit;
   1059       1.1    chopps {
   1060       1.1    chopps 	int s1, s2, ovfl;
   1061      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[unit];
   1062       1.6    chopps 	struct tty *tp = sc->sc_tty;
   1063       1.1    chopps 
   1064       1.1    chopps 	/*
   1065       1.1    chopps 	 * Make sure we're not interrupted by another
   1066       1.1    chopps 	 * vbl, but allow level6 ints
   1067       1.1    chopps 	 */
   1068       1.1    chopps 	s1 = spltty();
   1069       1.1    chopps 
   1070       1.1    chopps 	/*
   1071       1.1    chopps 	 * pass along any acumulated information
   1072       1.1    chopps 	 * while input is not blocked
   1073       1.1    chopps 	 */
   1074       1.1    chopps 	while (sc->incnt && (tp->t_state & TS_TBLOCK) == 0) {
   1075       1.2    chopps 		/*
   1076       1.1    chopps 		 * no collision with ser_fastint()
   1077       1.1    chopps 		 */
   1078       1.1    chopps 		mfcseint(unit, *sc->rptr++);
   1079       1.1    chopps 
   1080       1.1    chopps 		ovfl = 0;
   1081       1.1    chopps 		/* lock against mfcs_fastint() */
   1082       1.2    chopps 		s2 = splser();
   1083       1.1    chopps 		--sc->incnt;
   1084       1.1    chopps 		if (sc->rptr == sc->inbuf + SERIBUF_SIZE)
   1085       1.1    chopps 			sc->rptr = sc->inbuf;
   1086       1.1    chopps 		if (sc->ovfl != 0) {
   1087       1.1    chopps 			ovfl = sc->ovfl;
   1088       1.1    chopps 			sc->ovfl = 0;
   1089       1.1    chopps 		}
   1090       1.1    chopps 		splx(s2);
   1091       1.1    chopps 		if (ovfl != 0)
   1092       1.1    chopps 			log(LOG_WARNING, "%s: %d buffer overflow!\n",
   1093       1.1    chopps 			    sc->sc_dev.dv_xname, ovfl);
   1094       1.1    chopps 	}
   1095       1.1    chopps 	if (sc->incnt == 0 && (tp->t_state & TS_TBLOCK) == 0) {
   1096       1.4    chopps 		sc->sc_regs->du_btst = 1 << unit;	/* XXXX */
   1097       1.1    chopps 	}
   1098       1.1    chopps 	splx(s1);
   1099       1.1    chopps }
   1100       1.1    chopps 
   1101      1.12     veego void
   1102       1.1    chopps mfcseint(unit, stat)
   1103       1.1    chopps 	int unit, stat;
   1104       1.1    chopps {
   1105      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[unit];
   1106       1.1    chopps 	struct tty *tp;
   1107       1.1    chopps 	u_char ch;
   1108       1.1    chopps 	int c;
   1109       1.1    chopps 
   1110       1.6    chopps 	tp = sc->sc_tty;
   1111       1.1    chopps 	ch = stat & 0xff;
   1112       1.1    chopps 	c = ch;
   1113       1.1    chopps 
   1114       1.1    chopps 	if ((tp->t_state & TS_ISOPEN) == 0) {
   1115       1.1    chopps #ifdef KGDB
   1116       1.1    chopps 		/* we don't care about parity errors */
   1117       1.1    chopps 		if (kgdb_dev == makedev(sermajor, unit) && c == FRAME_END)
   1118       1.1    chopps 			kgdb_connect(0);	/* trap into kgdb */
   1119       1.1    chopps #endif
   1120       1.1    chopps 		return;
   1121       1.1    chopps 	}
   1122       1.1    chopps 
   1123       1.1    chopps 	/*
   1124       1.1    chopps 	 * Check for break and (if enabled) parity error.
   1125       1.1    chopps 	 */
   1126       1.1    chopps 	if (stat & 0xc000)
   1127       1.1    chopps 		c |= TTY_FE;
   1128       1.1    chopps 	else if (stat & 0x2000)
   1129       1.1    chopps 			c |= TTY_PE;
   1130       1.1    chopps 
   1131       1.1    chopps 	if (stat & 0x1000)
   1132       1.2    chopps 		log(LOG_WARNING, "%s: fifo overflow\n",
   1133      1.10   thorpej 		    ((struct mfcs_softc *)mfcs_cd.cd_devs[unit])->sc_dev.dv_xname);
   1134       1.1    chopps 
   1135      1.22   aymeric 	tp->t_linesw->l_rint(c, tp);
   1136       1.1    chopps }
   1137       1.1    chopps 
   1138       1.1    chopps /*
   1139       1.1    chopps  * This interrupt is periodically invoked in the vertical blank
   1140       1.1    chopps  * interrupt.  It's used to keep track of the modem control lines
   1141       1.1    chopps  * and (new with the fast_int code) to move accumulated data
   1142       1.1    chopps  * up into the tty layer.
   1143       1.1    chopps  */
   1144       1.1    chopps void
   1145       1.1    chopps mfcsmint(unit)
   1146       1.1    chopps 	int unit;
   1147       1.1    chopps {
   1148       1.1    chopps 	struct tty *tp;
   1149      1.10   thorpej 	struct mfcs_softc *sc = mfcs_cd.cd_devs[unit];
   1150       1.1    chopps 	u_char stat, last, istat;
   1151       1.1    chopps 
   1152       1.6    chopps 	tp = sc->sc_tty;
   1153       1.1    chopps 	if (!tp)
   1154       1.1    chopps 		return;
   1155       1.1    chopps 
   1156      1.20    mhitch 	if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
   1157       1.1    chopps 		sc->rptr = sc->wptr = sc->inbuf;
   1158       1.1    chopps 		sc->incnt = 0;
   1159       1.1    chopps 		return;
   1160       1.1    chopps 	}
   1161       1.1    chopps 	/*
   1162       1.1    chopps 	 * empty buffer
   1163       1.1    chopps 	 */
   1164       1.1    chopps 	mfcsxintr(unit);
   1165       1.1    chopps 
   1166       1.1    chopps 	stat = ~sc->sc_regs->du_ip;
   1167       1.1    chopps 	last = sc->sc_mfc->last_ip;
   1168       1.1    chopps 	sc->sc_mfc->last_ip = stat;
   1169       1.1    chopps 
   1170       1.1    chopps 	/*
   1171       1.1    chopps 	 * check whether any interesting signal changed state
   1172       1.1    chopps 	 */
   1173       1.1    chopps 	istat = stat ^ last;
   1174       1.1    chopps 
   1175       1.1    chopps 	if ((istat & (0x10 << (unit & 1))) && 		/* CD changed */
   1176       1.1    chopps 	    (SWFLAGS(tp->t_dev) & TIOCFLAG_SOFTCAR) == 0) {
   1177       1.1    chopps 		if (stat & (0x10 << (unit & 1)))
   1178      1.22   aymeric 			tp->t_linesw->l_modem(tp, 1);
   1179      1.22   aymeric 		else if (tp->t_linesw->l_modem(tp, 0) == 0) {
   1180       1.1    chopps 			sc->sc_regs->du_btrst = 0x0a << (unit & 1);
   1181       1.1    chopps 		}
   1182       1.1    chopps 	}
   1183       1.1    chopps }
   1184