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