Home | History | Annotate | Line # | Download | only in qbus
dl.c revision 1.9
      1  1.8    ragge /*	$NetBSD: dl.c,v 1.9 1999/05/27 16:00:45 ragge Exp $	*/
      2  1.2  thorpej 
      3  1.2  thorpej /*-
      4  1.2  thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  1.2  thorpej  * All rights reserved.
      6  1.2  thorpej  *
      7  1.2  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  thorpej  * by Jason R. Thorpe.
      9  1.2  thorpej  *
     10  1.2  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.2  thorpej  * modification, are permitted provided that the following conditions
     12  1.2  thorpej  * are met:
     13  1.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.2  thorpej  *    must display the following acknowledgement:
     20  1.2  thorpej  *	This product includes software developed by the NetBSD
     21  1.2  thorpej  *	Foundation, Inc. and its contributors.
     22  1.2  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.2  thorpej  *    from this software without specific prior written permission.
     25  1.2  thorpej  *
     26  1.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  thorpej  */
     38  1.2  thorpej 
     39  1.1    ragge /*
     40  1.1    ragge  * Copyright (c) 1997  Ben Harris.  All rights reserved.
     41  1.1    ragge  * Copyright (c) 1996  Ken C. Wellsch.  All rights reserved.
     42  1.1    ragge  * Copyright (c) 1982, 1986, 1990, 1992, 1993
     43  1.1    ragge  *	The Regents of the University of California.  All rights reserved.
     44  1.1    ragge  *
     45  1.1    ragge  * This code is derived from software contributed to Berkeley by
     46  1.1    ragge  * Ralph Campbell and Rick Macklem.
     47  1.1    ragge  *
     48  1.1    ragge  * Redistribution and use in source and binary forms, with or without
     49  1.1    ragge  * modification, are permitted provided that the following conditions
     50  1.1    ragge  * are met:
     51  1.1    ragge  * 1. Redistributions of source code must retain the above copyright
     52  1.1    ragge  *    notice, this list of conditions and the following disclaimer.
     53  1.1    ragge  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.1    ragge  *    notice, this list of conditions and the following disclaimer in the
     55  1.1    ragge  *    documentation and/or other materials provided with the distribution.
     56  1.1    ragge  * 3. All advertising materials mentioning features or use of this software
     57  1.1    ragge  *    must display the following acknowledgement:
     58  1.1    ragge  *	This product includes software developed by the University of
     59  1.1    ragge  *	California, Berkeley and its contributors.
     60  1.1    ragge  * 4. Neither the name of the University nor the names of its contributors
     61  1.1    ragge  *    may be used to endorse or promote products derived from this software
     62  1.1    ragge  *    without specific prior written permission.
     63  1.1    ragge  *
     64  1.1    ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65  1.1    ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66  1.1    ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67  1.1    ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68  1.1    ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69  1.1    ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70  1.1    ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71  1.1    ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72  1.1    ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73  1.1    ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74  1.1    ragge  * SUCH DAMAGE.
     75  1.1    ragge  */
     76  1.1    ragge 
     77  1.1    ragge /*
     78  1.1    ragge  * dl.c -- Device driver for the DL11 and DLV11 serial cards.
     79  1.1    ragge  *
     80  1.1    ragge  * OS-interface code derived from the dz and dca (hp300) drivers.
     81  1.1    ragge  */
     82  1.1    ragge 
     83  1.1    ragge #include <sys/param.h>
     84  1.1    ragge #include <sys/systm.h>
     85  1.1    ragge #include <sys/ioctl.h>
     86  1.1    ragge #include <sys/tty.h>
     87  1.1    ragge #include <sys/proc.h>
     88  1.1    ragge #include <sys/map.h>
     89  1.1    ragge #include <sys/buf.h>
     90  1.1    ragge #include <sys/conf.h>
     91  1.1    ragge #include <sys/file.h>
     92  1.1    ragge #include <sys/uio.h>
     93  1.1    ragge #include <sys/kernel.h>
     94  1.1    ragge #include <sys/syslog.h>
     95  1.1    ragge #include <sys/device.h>
     96  1.1    ragge 
     97  1.7    ragge #include <machine/bus.h>
     98  1.6    ragge #include <machine/scb.h>
     99  1.1    ragge 
    100  1.8    ragge #include <dev/dec/qbus/ubareg.h>
    101  1.8    ragge #include <dev/dec/qbus/ubavar.h>
    102  1.1    ragge 
    103  1.8    ragge #include <dev/dec/qbus/dlreg.h>
    104  1.1    ragge 
    105  1.7    ragge #include "ioconf.h"
    106  1.1    ragge 
    107  1.1    ragge struct dl_softc {
    108  1.1    ragge 	struct device	sc_dev;
    109  1.7    ragge 	bus_space_tag_t	sc_iot;
    110  1.7    ragge 	bus_space_handle_t sc_ioh;
    111  1.7    ragge 	struct tty	*sc_tty;
    112  1.1    ragge };
    113  1.1    ragge 
    114  1.4    ragge static	int	dl_match __P((struct device *, struct cfdata *, void *));
    115  1.1    ragge static	void	dl_attach __P((struct device *, struct device *, void *));
    116  1.1    ragge static	void	dlrint __P((int));
    117  1.1    ragge static	void	dlxint __P((int));
    118  1.1    ragge static	void	dlstart __P((struct tty *));
    119  1.1    ragge static	int	dlparam __P((struct tty *, struct termios *));
    120  1.1    ragge static	void	dlbrk __P((struct dl_softc *, int));
    121  1.1    ragge struct	tty *	dltty __P((dev_t));
    122  1.1    ragge 	int	dlopen __P((dev_t, int, int, struct proc *));
    123  1.1    ragge 	int	dlclose __P((dev_t, int, int, struct proc *));
    124  1.1    ragge 	int	dlread __P((dev_t, struct uio *, int));
    125  1.1    ragge 	int	dlwrite __P((dev_t, struct uio *, int));
    126  1.1    ragge 	int	dlioctl __P((dev_t, int, caddr_t, int, struct proc *));
    127  1.1    ragge 	void	dlstop __P((struct tty *, int));
    128  1.1    ragge 
    129  1.1    ragge struct cfattach dl_ca = {
    130  1.1    ragge 	sizeof(struct dl_softc), dl_match, dl_attach
    131  1.1    ragge };
    132  1.3  thorpej 
    133  1.7    ragge #define	DL_READ_WORD(reg) \
    134  1.7    ragge 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
    135  1.7    ragge #define	DL_WRITE_WORD(reg, val) \
    136  1.7    ragge 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
    137  1.7    ragge #define	DL_WRITE_BYTE(reg, val) \
    138  1.7    ragge 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, val)
    139  1.1    ragge 
    140  1.1    ragge /* Autoconfig handles: setup the controller to interrupt, */
    141  1.1    ragge /* then complete the housecleaning for full operation */
    142  1.1    ragge 
    143  1.1    ragge static int
    144  1.4    ragge dl_match (parent, cf, aux)
    145  1.1    ragge 	struct device * parent;
    146  1.4    ragge 	struct cfdata *cf;
    147  1.4    ragge 	void *aux;
    148  1.1    ragge {
    149  1.1    ragge 	struct uba_attach_args *ua = aux;
    150  1.1    ragge 
    151  1.1    ragge #ifdef DL_DEBUG
    152  1.7    ragge 	printf("Probing for dl at %lo ... ", (long)ua->ua_iaddr);
    153  1.1    ragge #endif
    154  1.1    ragge 
    155  1.7    ragge 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR, DL_XCSR_TXIE);
    156  1.7    ragge 	if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
    157  1.7    ragge 	    (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
    158  1.1    ragge #ifdef DL_DEBUG
    159  1.7    ragge 	        printf("failed (step 1; XCSR = %.4b)\n",
    160  1.7    ragge 		    bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
    161  1.7    ragge 		    DL_XCSR_BITS);
    162  1.1    ragge #endif
    163  1.1    ragge 		return 0;
    164  1.1    ragge 	}
    165  1.1    ragge 
    166  1.1    ragge 	/*
    167  1.1    ragge 	 * We have to force an interrupt so the uba driver can work
    168  1.1    ragge 	 * out where we are.  Unfortunately, the only way to make a
    169  1.1    ragge 	 * DL11 interrupt is to get it to send or receive a
    170  1.1    ragge 	 * character.  We'll send a NUL and hope it doesn't hurt
    171  1.1    ragge 	 * anything.
    172  1.1    ragge 	 */
    173  1.1    ragge 
    174  1.7    ragge 	bus_space_write_1(ua->ua_iot, ua->ua_ioh, DL_UBA_XBUFL, '\0');
    175  1.1    ragge #if 0 /* This test seems to fail 2/3 of the time :-( */
    176  1.1    ragge 	if (dladdr->dl_xcsr != (DL_XCSR_TXIE)) {
    177  1.1    ragge #ifdef DL_DEBUG
    178  1.1    ragge 	        printf("failed (step 2; XCSR = %.4b)\n", dladdr->dl_xcsr,
    179  1.1    ragge 		       DL_XCSR_BITS);
    180  1.1    ragge #endif
    181  1.1    ragge 		return 0;
    182  1.1    ragge 	}
    183  1.1    ragge #endif
    184  1.1    ragge 	DELAY(100000); /* delay 1/10 s for character to transmit */
    185  1.7    ragge 	if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
    186  1.7    ragge 	    (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
    187  1.1    ragge #ifdef DL_DEBUG
    188  1.7    ragge 	        printf("failed (step 3; XCSR = %.4b)\n",
    189  1.7    ragge 		    bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
    190  1.7    ragge 		    DL_XCSR_BITS);
    191  1.1    ragge #endif
    192  1.1    ragge 		return 0;
    193  1.1    ragge 	}
    194  1.1    ragge 
    195  1.1    ragge 	/* Register the TX interrupt handler */
    196  1.1    ragge 	ua->ua_ivec = dlxint;
    197  1.1    ragge 
    198  1.1    ragge         /* What else do I need to do? */
    199  1.1    ragge 
    200  1.1    ragge 	return 1;
    201  1.1    ragge 
    202  1.1    ragge }
    203  1.1    ragge 
    204  1.1    ragge static void
    205  1.1    ragge dl_attach (parent, self, aux)
    206  1.1    ragge 	struct device *parent, *self;
    207  1.1    ragge 	void *aux;
    208  1.1    ragge {
    209  1.1    ragge 	struct dl_softc *sc = (void *)self;
    210  1.1    ragge 	register struct uba_attach_args *ua = aux;
    211  1.1    ragge 
    212  1.7    ragge 	sc->sc_iot = ua->ua_iot;
    213  1.7    ragge 	sc->sc_ioh = ua->ua_ioh;
    214  1.1    ragge 
    215  1.1    ragge 	/* Tidy up the device */
    216  1.1    ragge 
    217  1.7    ragge 	DL_WRITE_WORD(DL_UBA_RCSR, DL_RCSR_RXIE);
    218  1.7    ragge 	DL_WRITE_WORD(DL_UBA_XCSR, DL_XCSR_TXIE);
    219  1.1    ragge 
    220  1.1    ragge 	/* Initialize our softc structure. Should be done in open? */
    221  1.1    ragge 
    222  1.1    ragge 	sc->sc_tty = ttymalloc();
    223  1.1    ragge 	tty_attach(sc->sc_tty);
    224  1.1    ragge 
    225  1.1    ragge 	/* Now register the RX interrupt handler */
    226  1.6    ragge 	scb_vecalloc(ua->ua_cvec - 4, dlrint, self->dv_unit, SCB_ISTACK);
    227  1.1    ragge 
    228  1.1    ragge 	printf("\n");
    229  1.1    ragge }
    230  1.1    ragge 
    231  1.1    ragge /* Receiver Interrupt Handler */
    232  1.1    ragge 
    233  1.1    ragge static void
    234  1.1    ragge dlrint(cntlr)
    235  1.1    ragge 	int cntlr;
    236  1.1    ragge {
    237  1.1    ragge 	struct	dl_softc *sc = dl_cd.cd_devs[cntlr];
    238  1.1    ragge 	register struct tty *tp;
    239  1.1    ragge 	register int cc;
    240  1.1    ragge 	register unsigned c;
    241  1.1    ragge 
    242  1.7    ragge 	if (DL_READ_WORD(DL_UBA_RCSR) & DL_RCSR_RX_DONE) {
    243  1.7    ragge 	        c = DL_READ_WORD(DL_UBA_RBUF);
    244  1.1    ragge 		cc = c & 0xFF;
    245  1.1    ragge 		tp = sc->sc_tty;
    246  1.1    ragge 
    247  1.1    ragge 		if (!(tp->t_state & TS_ISOPEN)) {
    248  1.1    ragge 			wakeup((caddr_t)&tp->t_rawq);
    249  1.1    ragge 			return;
    250  1.1    ragge 		}
    251  1.1    ragge 
    252  1.1    ragge 		if (c & DL_RBUF_OVERRUN_ERR)
    253  1.1    ragge 			/*
    254  1.1    ragge 			 * XXX: This should really be logged somwhere
    255  1.1    ragge 			 * else where we can afford the time.
    256  1.1    ragge 			 */
    257  1.1    ragge 			log(LOG_WARNING, "%s: rx overrun\n",
    258  1.1    ragge 			    sc->sc_dev.dv_xname);
    259  1.1    ragge 		if (c & DL_RBUF_FRAMING_ERR)
    260  1.1    ragge 			cc |= TTY_FE;
    261  1.1    ragge 		if (c & DL_RBUF_PARITY_ERR)
    262  1.1    ragge 			cc |= TTY_PE;
    263  1.1    ragge 
    264  1.1    ragge 		(*linesw[tp->t_line].l_rint)(cc, tp);
    265  1.1    ragge 	} else
    266  1.1    ragge 		log(LOG_WARNING, "%s: stray rx interrupt\n",
    267  1.1    ragge 		    sc->sc_dev.dv_xname);
    268  1.1    ragge 	return;
    269  1.1    ragge }
    270  1.1    ragge 
    271  1.1    ragge /* Transmitter Interrupt Handler */
    272  1.1    ragge 
    273  1.1    ragge static void
    274  1.1    ragge dlxint(cntlr)
    275  1.1    ragge 	int cntlr;
    276  1.1    ragge {
    277  1.1    ragge 	struct	dl_softc *sc = dl_cd.cd_devs[cntlr];
    278  1.1    ragge 	register struct tty *tp;
    279  1.1    ragge 
    280  1.1    ragge 	tp = sc->sc_tty;
    281  1.1    ragge 	tp->t_state &= ~(TS_BUSY | TS_FLUSH);
    282  1.1    ragge 	if (tp->t_line)
    283  1.1    ragge 		(*linesw[tp->t_line].l_start)(tp);
    284  1.1    ragge 	else
    285  1.1    ragge 		dlstart(tp);
    286  1.1    ragge 
    287  1.1    ragge 	return;
    288  1.1    ragge }
    289  1.1    ragge 
    290  1.1    ragge int
    291  1.1    ragge dlopen(dev, flag, mode, p)
    292  1.1    ragge 	dev_t dev;
    293  1.1    ragge 	int flag, mode;
    294  1.1    ragge 	struct proc *p;
    295  1.1    ragge {
    296  1.1    ragge 	register struct tty *tp;
    297  1.1    ragge 	register int unit;
    298  1.1    ragge 	struct dl_softc *sc;
    299  1.1    ragge 
    300  1.7    ragge 	unit = minor(dev);
    301  1.1    ragge 
    302  1.1    ragge 	if (unit >= dl_cd.cd_ndevs || dl_cd.cd_devs[unit] == NULL)
    303  1.1    ragge 		return ENXIO;
    304  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    305  1.1    ragge 
    306  1.1    ragge 	tp = sc->sc_tty;
    307  1.1    ragge 	if (tp == NULL)
    308  1.1    ragge 		return ENODEV;
    309  1.1    ragge 	tp->t_oproc = dlstart;
    310  1.1    ragge 	tp->t_param = dlparam;
    311  1.1    ragge 	tp->t_dev = dev;
    312  1.1    ragge 
    313  1.1    ragge 	if (!(tp->t_state & TS_ISOPEN)) {
    314  1.1    ragge 		ttychars(tp);
    315  1.1    ragge 		tp->t_iflag = TTYDEF_IFLAG;
    316  1.1    ragge 		tp->t_oflag = TTYDEF_OFLAG;
    317  1.1    ragge 		/* No modem control, so set CLOCAL. */
    318  1.1    ragge 		tp->t_cflag = TTYDEF_CFLAG | CLOCAL;
    319  1.1    ragge 		tp->t_lflag = TTYDEF_LFLAG;
    320  1.1    ragge 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    321  1.1    ragge 
    322  1.1    ragge 		dlparam(tp, &tp->t_termios);
    323  1.1    ragge 		ttsetwater(tp);
    324  1.1    ragge 
    325  1.1    ragge 	} else if ((tp->t_state & TS_XCLUDE) && p->p_ucred->cr_uid != 0)
    326  1.1    ragge 		return EBUSY;
    327  1.1    ragge 
    328  1.1    ragge 	return ((*linesw[tp->t_line].l_open)(dev, tp));
    329  1.1    ragge }
    330  1.1    ragge 
    331  1.1    ragge /*ARGSUSED*/
    332  1.1    ragge int
    333  1.1    ragge dlclose(dev, flag, mode, p)
    334  1.1    ragge 	dev_t dev;
    335  1.1    ragge 	int flag, mode;
    336  1.1    ragge 	struct proc *p;
    337  1.1    ragge {
    338  1.1    ragge 	struct dl_softc *sc;
    339  1.1    ragge 	register struct tty *tp;
    340  1.1    ragge 	register int unit;
    341  1.1    ragge 
    342  1.7    ragge 	unit = minor(dev);
    343  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    344  1.1    ragge       	tp = sc->sc_tty;
    345  1.1    ragge 
    346  1.1    ragge 	(*linesw[tp->t_line].l_close)(tp, flag);
    347  1.1    ragge 
    348  1.1    ragge 	/* Make sure a BREAK state is not left enabled. */
    349  1.1    ragge 	dlbrk(sc, 0);
    350  1.1    ragge 
    351  1.1    ragge 	return (ttyclose(tp));
    352  1.1    ragge }
    353  1.1    ragge 
    354  1.1    ragge int
    355  1.1    ragge dlread(dev, uio, flag)
    356  1.1    ragge 	dev_t dev;
    357  1.1    ragge 	struct uio *uio;
    358  1.1    ragge 	int flag;
    359  1.1    ragge {
    360  1.1    ragge 	register struct tty *tp;
    361  1.1    ragge 	struct dl_softc *sc;
    362  1.1    ragge 	register int unit;
    363  1.1    ragge 
    364  1.7    ragge 	unit = minor(dev);
    365  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    366  1.1    ragge 	tp = sc->sc_tty;
    367  1.1    ragge 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    368  1.1    ragge }
    369  1.1    ragge 
    370  1.1    ragge int
    371  1.1    ragge dlwrite(dev, uio, flag)
    372  1.1    ragge 	dev_t dev;
    373  1.1    ragge 	struct uio *uio;
    374  1.1    ragge 	int flag;
    375  1.1    ragge {
    376  1.1    ragge 	register struct tty *tp;
    377  1.1    ragge 	struct dl_softc *sc;
    378  1.1    ragge 	register int unit;
    379  1.1    ragge 
    380  1.7    ragge 	unit = minor(dev);
    381  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    382  1.1    ragge 	tp = sc->sc_tty;
    383  1.1    ragge 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    384  1.1    ragge }
    385  1.1    ragge 
    386  1.1    ragge int
    387  1.1    ragge dlioctl(dev, cmd, data, flag, p)
    388  1.1    ragge 	dev_t dev;
    389  1.1    ragge         int cmd;
    390  1.1    ragge         caddr_t data;
    391  1.1    ragge         int flag;
    392  1.1    ragge         struct proc *p;
    393  1.1    ragge {
    394  1.1    ragge 	struct dl_softc *sc;
    395  1.1    ragge         register struct tty *tp;
    396  1.1    ragge         register int unit;
    397  1.1    ragge         int error;
    398  1.1    ragge 
    399  1.7    ragge 	unit = minor(dev);
    400  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    401  1.1    ragge 	tp = sc->sc_tty;
    402  1.1    ragge 
    403  1.1    ragge         error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
    404  1.1    ragge         if (error >= 0)
    405  1.1    ragge                 return (error);
    406  1.1    ragge         error = ttioctl(tp, cmd, data, flag, p);
    407  1.1    ragge         if (error >= 0)
    408  1.1    ragge                 return (error);
    409  1.1    ragge 
    410  1.1    ragge 	switch (cmd) {
    411  1.1    ragge 
    412  1.1    ragge         case TIOCSBRK:
    413  1.1    ragge                 dlbrk(sc, 1);
    414  1.1    ragge                 break;
    415  1.1    ragge 
    416  1.1    ragge         case TIOCCBRK:
    417  1.1    ragge                 dlbrk(sc, 0);
    418  1.1    ragge                 break;
    419  1.1    ragge 
    420  1.1    ragge         case TIOCMGET:
    421  1.1    ragge 		/* No modem control, assume they're all low. */
    422  1.1    ragge                 *(int *)data = 0;
    423  1.1    ragge                 break;
    424  1.1    ragge 
    425  1.1    ragge         default:
    426  1.1    ragge                 return (ENOTTY);
    427  1.1    ragge         }
    428  1.1    ragge         return (0);
    429  1.1    ragge }
    430  1.1    ragge 
    431  1.1    ragge struct tty *
    432  1.1    ragge dltty(dev)
    433  1.1    ragge 	dev_t dev;
    434  1.1    ragge {
    435  1.1    ragge 	register struct dl_softc* sc;
    436  1.1    ragge 
    437  1.7    ragge 	sc = dl_cd.cd_devs[minor(dev)];
    438  1.1    ragge 	return sc->sc_tty;
    439  1.1    ragge }
    440  1.1    ragge 
    441  1.1    ragge void
    442  1.1    ragge dlstop(tp, flag)
    443  1.1    ragge 	register struct tty *tp;
    444  1.1    ragge 	int flag;
    445  1.1    ragge {
    446  1.1    ragge 	register struct dl_softc *sc;
    447  1.1    ragge 	int unit, s;
    448  1.1    ragge 
    449  1.7    ragge 	unit = minor(tp->t_dev);
    450  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    451  1.1    ragge 
    452  1.1    ragge 	s = spltty();
    453  1.1    ragge 
    454  1.1    ragge 	if (tp->t_state & TS_BUSY)
    455  1.1    ragge                 if (!(tp->t_state & TS_TTSTOP))
    456  1.1    ragge                         tp->t_state |= TS_FLUSH;
    457  1.1    ragge         splx(s);
    458  1.1    ragge }
    459  1.1    ragge 
    460  1.1    ragge static void
    461  1.1    ragge dlstart(tp)
    462  1.1    ragge 	register struct tty *tp;
    463  1.1    ragge {
    464  1.1    ragge 	register struct dl_softc *sc;
    465  1.5    ragge 	register int unit;
    466  1.1    ragge 	int s;
    467  1.1    ragge 
    468  1.7    ragge 	unit = minor(tp->t_dev);
    469  1.1    ragge 	sc = dl_cd.cd_devs[unit];
    470  1.1    ragge 
    471  1.1    ragge 	s = spltty();
    472  1.1    ragge         if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
    473  1.1    ragge                 goto out;
    474  1.1    ragge         if (tp->t_outq.c_cc <= tp->t_lowat) {
    475  1.1    ragge                 if (tp->t_state & TS_ASLEEP) {
    476  1.1    ragge                         tp->t_state &= ~TS_ASLEEP;
    477  1.1    ragge                         wakeup((caddr_t)&tp->t_outq);
    478  1.1    ragge                 }
    479  1.1    ragge                 selwakeup(&tp->t_wsel);
    480  1.1    ragge         }
    481  1.1    ragge         if (tp->t_outq.c_cc == 0)
    482  1.1    ragge                 goto out;
    483  1.1    ragge 
    484  1.1    ragge 
    485  1.7    ragge 	if (DL_READ_WORD(DL_UBA_XCSR) & DL_XCSR_TX_READY) {
    486  1.1    ragge 		tp->t_state |= TS_BUSY;
    487  1.7    ragge 		DL_WRITE_BYTE(DL_UBA_XBUFL, getc(&tp->t_outq));
    488  1.1    ragge 	}
    489  1.1    ragge out:
    490  1.1    ragge 	splx(s);
    491  1.1    ragge 	return;
    492  1.1    ragge }
    493  1.1    ragge 
    494  1.1    ragge /*ARGSUSED*/
    495  1.1    ragge static int
    496  1.1    ragge dlparam(tp, t)
    497  1.1    ragge         register struct tty *tp;
    498  1.1    ragge         register struct termios *t;
    499  1.1    ragge {
    500  1.1    ragge 	/*
    501  1.1    ragge 	 * All this kind of stuff (speed, character format, whatever)
    502  1.1    ragge 	 * is set by jumpers on the card.  Changing it is thus rather
    503  1.1    ragge 	 * tricky for a mere device driver.
    504  1.1    ragge 	 */
    505  1.1    ragge 	return 0;
    506  1.1    ragge }
    507  1.1    ragge 
    508  1.1    ragge static void
    509  1.1    ragge dlbrk(sc, state)
    510  1.1    ragge 	register struct dl_softc *sc;
    511  1.1    ragge 	int state;
    512  1.1    ragge {
    513  1.7    ragge 	int s = spltty();
    514  1.7    ragge 
    515  1.7    ragge 	if (state) {
    516  1.7    ragge 		DL_WRITE_WORD(DL_UBA_XCSR, DL_READ_WORD(DL_UBA_XCSR) |
    517  1.7    ragge 		    DL_XCSR_TX_BREAK);
    518  1.7    ragge 	} else {
    519  1.7    ragge 		DL_WRITE_WORD(DL_UBA_XCSR, DL_READ_WORD(DL_UBA_XCSR) &
    520  1.7    ragge 		    ~DL_XCSR_TX_BREAK);
    521  1.7    ragge 	}
    522  1.1    ragge 	splx(s);
    523  1.1    ragge }
    524