2005-02-27 03:26:58 +03:00
|
|
|
/* $NetBSD: dz.c,v 1.16 2005/02/27 00:26:59 perry Exp $ */
|
1999-05-27 20:02:32 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Ken C. Wellsch. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1999-05-27 20:02:32 +04:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:11:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: dz.c,v 1.16 2005/02/27 00:26:59 perry Exp $");
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1999-05-27 20:02:32 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2002-02-25 17:58:06 +03:00
|
|
|
#include <dev/dec/dzreg.h>
|
|
|
|
#include <dev/dec/dzvar.h>
|
1999-05-27 20:02:32 +04:00
|
|
|
|
2003-10-18 16:10:53 +04:00
|
|
|
#include <dev/cons.h>
|
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
#define DZ_READ_BYTE(adr) \
|
|
|
|
bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr)
|
|
|
|
#define DZ_READ_WORD(adr) \
|
|
|
|
bus_space_read_2(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr)
|
|
|
|
#define DZ_WRITE_BYTE(adr, val) \
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr, val)
|
|
|
|
#define DZ_WRITE_WORD(adr, val) \
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr, val)
|
2003-12-14 02:02:33 +03:00
|
|
|
#define DZ_BARRIER() \
|
|
|
|
bus_space_barrier(sc->sc_iot, sc->sc_ioh, sc->sc_dr.dr_firstreg, \
|
|
|
|
sc->sc_dr.dr_winsize, \
|
|
|
|
BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ)
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
#include "ioconf.h"
|
|
|
|
|
|
|
|
/* Flags used to monitor modem bits, make them understood outside driver */
|
|
|
|
|
|
|
|
#define DML_DTR TIOCM_DTR
|
|
|
|
#define DML_DCD TIOCM_CD
|
|
|
|
#define DML_RI TIOCM_RI
|
|
|
|
#define DML_BRK 0100000 /* no equivalent, we will mask */
|
|
|
|
|
2004-04-25 10:23:40 +04:00
|
|
|
static const struct speedtab dzspeedtab[] =
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
|
|
|
{ 0, 0 },
|
|
|
|
{ 50, DZ_LPR_B50 },
|
|
|
|
{ 75, DZ_LPR_B75 },
|
|
|
|
{ 110, DZ_LPR_B110 },
|
|
|
|
{ 134, DZ_LPR_B134 },
|
|
|
|
{ 150, DZ_LPR_B150 },
|
|
|
|
{ 300, DZ_LPR_B300 },
|
|
|
|
{ 600, DZ_LPR_B600 },
|
|
|
|
{ 1200, DZ_LPR_B1200 },
|
|
|
|
{ 1800, DZ_LPR_B1800 },
|
|
|
|
{ 2000, DZ_LPR_B2000 },
|
|
|
|
{ 2400, DZ_LPR_B2400 },
|
|
|
|
{ 3600, DZ_LPR_B3600 },
|
|
|
|
{ 4800, DZ_LPR_B4800 },
|
|
|
|
{ 7200, DZ_LPR_B7200 },
|
|
|
|
{ 9600, DZ_LPR_B9600 },
|
|
|
|
{ 19200, DZ_LPR_B19200 },
|
|
|
|
{ -1, -1 }
|
|
|
|
};
|
|
|
|
|
2000-06-05 04:09:17 +04:00
|
|
|
static void dzstart(struct tty *);
|
|
|
|
static int dzparam(struct tty *, struct termios *);
|
2000-04-30 15:46:49 +04:00
|
|
|
static unsigned dzmctl(struct dz_softc *, int, int, int);
|
2000-06-05 04:09:17 +04:00
|
|
|
static void dzscan(void *);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
dev_type_open(dzopen);
|
|
|
|
dev_type_close(dzclose);
|
|
|
|
dev_type_read(dzread);
|
|
|
|
dev_type_write(dzwrite);
|
|
|
|
dev_type_ioctl(dzioctl);
|
|
|
|
dev_type_stop(dzstop);
|
|
|
|
dev_type_tty(dztty);
|
|
|
|
dev_type_poll(dzpoll);
|
|
|
|
|
|
|
|
const struct cdevsw dz_cdevsw = {
|
|
|
|
dzopen, dzclose, dzread, dzwrite, dzioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
dzstop, dztty, dzpoll, nommap, ttykqfilter, D_TTY
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The DZ series doesn't interrupt on carrier transitions,
|
|
|
|
* so we have to use a timer to watch it.
|
|
|
|
*/
|
2000-03-23 10:01:25 +03:00
|
|
|
int dz_timer; /* true if timer started */
|
|
|
|
struct callout dzscan_ch;
|
2003-10-18 16:10:53 +04:00
|
|
|
static struct cnm_state dz_cnm_state;
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
void
|
2002-09-24 10:19:09 +04:00
|
|
|
dzattach(struct dz_softc *sc, struct evcnt *parent_evcnt, int consline)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
int n;
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
sc->sc_rxint = sc->sc_brk = 0;
|
2002-09-24 10:19:09 +04:00
|
|
|
sc->sc_consline = consline;
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
sc->sc_dr.dr_tcrw = sc->sc_dr.dr_tcr;
|
|
|
|
DZ_WRITE_WORD(dr_csr, DZ_CSR_MSE | DZ_CSR_RXIE | DZ_CSR_TXIE);
|
|
|
|
DZ_WRITE_BYTE(dr_dtr, 0);
|
|
|
|
DZ_WRITE_BYTE(dr_break, 0);
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
/* Initialize our softc structure. Should be done in open? */
|
|
|
|
|
2002-09-18 20:51:16 +04:00
|
|
|
for (n = 0; n < sc->sc_type; n++) {
|
2002-09-20 03:22:56 +04:00
|
|
|
sc->sc_dz[n].dz_sc = sc;
|
2002-09-18 20:51:16 +04:00
|
|
|
sc->sc_dz[n].dz_line = n;
|
1999-05-27 20:02:32 +04:00
|
|
|
sc->sc_dz[n].dz_tty = ttymalloc();
|
2002-09-18 20:51:16 +04:00
|
|
|
}
|
1999-05-27 20:02:32 +04:00
|
|
|
|
2000-06-05 04:09:17 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, parent_evcnt,
|
|
|
|
sc->sc_dev.dv_xname, "rintr");
|
|
|
|
evcnt_attach_dynamic(&sc->sc_tintrcnt, EVCNT_TYPE_INTR, parent_evcnt,
|
|
|
|
sc->sc_dev.dv_xname, "tintr");
|
2000-06-04 06:14:12 +04:00
|
|
|
|
2003-10-18 16:10:53 +04:00
|
|
|
/* Console magic keys */
|
|
|
|
cn_init_magic(&dz_cnm_state);
|
|
|
|
cn_set_magic("\047\001"); /* default magic is BREAK */
|
|
|
|
/* VAX will change it in MD code */
|
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
/* Alas no interrupt on modem bit changes, so we manually scan */
|
|
|
|
|
|
|
|
if (dz_timer == 0) {
|
|
|
|
dz_timer = 1;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&dzscan_ch);
|
|
|
|
callout_reset(&dzscan_ch, hz, dzscan, NULL);
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Receiver Interrupt */
|
|
|
|
|
|
|
|
void
|
2000-04-30 15:46:49 +04:00
|
|
|
dzrint(void *arg)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-01-24 05:40:28 +03:00
|
|
|
struct dz_softc *sc = arg;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct tty *tp;
|
2003-12-09 17:30:55 +03:00
|
|
|
int cc, mcc, line;
|
2000-03-30 16:41:09 +04:00
|
|
|
unsigned c;
|
1999-05-27 20:02:32 +04:00
|
|
|
int overrun = 0;
|
|
|
|
|
|
|
|
sc->sc_rxint++;
|
|
|
|
|
|
|
|
while ((c = DZ_READ_WORD(dr_rbuf)) & DZ_RBUF_DATA_VALID) {
|
|
|
|
cc = c & 0xFF;
|
|
|
|
line = DZ_PORT(c>>8);
|
|
|
|
tp = sc->sc_dz[line].dz_tty;
|
|
|
|
|
|
|
|
/* Must be caught early */
|
2000-12-31 01:11:46 +03:00
|
|
|
if (sc->sc_dz[line].dz_catch &&
|
|
|
|
(*sc->sc_dz[line].dz_catch)(sc->sc_dz[line].dz_private, cc))
|
1999-05-27 20:02:32 +04:00
|
|
|
continue;
|
|
|
|
|
2003-12-09 17:30:55 +03:00
|
|
|
if ((c & (DZ_RBUF_FRAMING_ERR | 0xff)) == DZ_RBUF_FRAMING_ERR)
|
|
|
|
mcc = CNC_BREAK;
|
|
|
|
else
|
|
|
|
mcc = cc;
|
|
|
|
|
|
|
|
cn_check_magic(tp->t_dev, mcc, dz_cnm_state);
|
2003-10-18 16:10:53 +04:00
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
if (!(tp->t_state & TS_ISOPEN)) {
|
|
|
|
wakeup((caddr_t)&tp->t_rawq);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((c & DZ_RBUF_OVERRUN_ERR) && overrun == 0) {
|
|
|
|
log(LOG_WARNING, "%s: silo overflow, line %d\n",
|
|
|
|
sc->sc_dev.dv_xname, line);
|
|
|
|
overrun = 1;
|
|
|
|
}
|
2003-12-09 17:30:55 +03:00
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
if (c & DZ_RBUF_FRAMING_ERR)
|
|
|
|
cc |= TTY_FE;
|
|
|
|
if (c & DZ_RBUF_PARITY_ERR)
|
|
|
|
cc |= TTY_PE;
|
|
|
|
|
2000-11-02 03:01:44 +03:00
|
|
|
(*tp->t_linesw->l_rint)(cc, tp);
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transmitter Interrupt */
|
|
|
|
|
|
|
|
void
|
2000-04-30 15:46:49 +04:00
|
|
|
dzxint(void *arg)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct dz_softc *sc = arg;
|
|
|
|
struct tty *tp;
|
|
|
|
struct clist *cl;
|
|
|
|
int line, ch, csr;
|
1999-05-27 20:02:32 +04:00
|
|
|
u_char tcr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch to POLLED mode.
|
|
|
|
* Some simple measurements indicated that even on
|
|
|
|
* one port, by freeing the scanner in the controller
|
|
|
|
* by either providing a character or turning off
|
|
|
|
* the port when output is complete, the transmitter
|
|
|
|
* was ready to accept more output when polled again.
|
|
|
|
* With just two ports running the game "worms,"
|
|
|
|
* almost every interrupt serviced both transmitters!
|
|
|
|
* Each UART is double buffered, so if the scanner
|
|
|
|
* is quick enough and timing works out, we can even
|
|
|
|
* feed the same port twice.
|
|
|
|
*
|
|
|
|
* Ragge 980517:
|
|
|
|
* Do not need to turn off interrupts, already at interrupt level.
|
|
|
|
* Remove the pdma stuff; no great need of it right now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (((csr = DZ_READ_WORD(dr_csr)) & DZ_CSR_TX_READY) != 0) {
|
|
|
|
|
|
|
|
line = DZ_PORT(csr>>8);
|
|
|
|
|
|
|
|
tp = sc->sc_dz[line].dz_tty;
|
|
|
|
cl = &tp->t_outq;
|
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
|
|
|
|
/* Just send out a char if we have one */
|
|
|
|
/* As long as we can fill the chip buffer, we just loop here */
|
|
|
|
if (cl->c_cc) {
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
ch = getc(cl);
|
|
|
|
DZ_WRITE_BYTE(dr_tbuf, ch);
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
continue;
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
1999-05-27 20:02:32 +04:00
|
|
|
/* Nothing to send; clear the scan bit */
|
|
|
|
/* Clear xmit scanner bit; dzstart may set it again */
|
|
|
|
tcr = DZ_READ_WORD(dr_tcrw);
|
|
|
|
tcr &= 255;
|
|
|
|
tcr &= ~(1 << line);
|
|
|
|
DZ_WRITE_BYTE(dr_tcr, tcr);
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
2000-12-31 01:11:46 +03:00
|
|
|
if (sc->sc_dz[line].dz_catch)
|
|
|
|
continue;
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
if (tp->t_state & TS_FLUSH)
|
|
|
|
tp->t_state &= ~TS_FLUSH;
|
|
|
|
else
|
|
|
|
ndflush (&tp->t_outq, cl->c_cc);
|
|
|
|
|
2001-03-31 04:35:21 +04:00
|
|
|
(*tp->t_linesw->l_start)(tp);
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-04-30 15:46:49 +04:00
|
|
|
dzopen(dev_t dev, int flag, int mode, struct proc *p)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit, line;
|
1999-05-27 20:02:32 +04:00
|
|
|
struct dz_softc *sc;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
unit = DZ_I2C(minor(dev));
|
|
|
|
line = DZ_PORT(minor(dev));
|
|
|
|
if (unit >= dz_cd.cd_ndevs || dz_cd.cd_devs[unit] == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
sc = dz_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
if (line >= sc->sc_type)
|
|
|
|
return ENXIO;
|
|
|
|
|
2000-12-31 01:11:46 +03:00
|
|
|
/* if some other device is using the line, it's busy */
|
|
|
|
if (sc->sc_dz[line].dz_catch)
|
|
|
|
return EBUSY;
|
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
tp = sc->sc_dz[line].dz_tty;
|
|
|
|
if (tp == NULL)
|
|
|
|
return (ENODEV);
|
|
|
|
tp->t_oproc = dzstart;
|
|
|
|
tp->t_param = dzparam;
|
|
|
|
tp->t_dev = dev;
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
ttychars(tp);
|
|
|
|
if (tp->t_ispeed == 0) {
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
|
|
|
|
}
|
|
|
|
(void) dzparam(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
|
|
|
} else if ((tp->t_state & TS_XCLUDE) && p->p_ucred->cr_uid != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
/* Use DMBIS and *not* DMSET or else we clobber incoming bits */
|
|
|
|
if (dzmctl(sc, line, DML_DTR, DMBIS) & DML_DCD)
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
|
|
|
s = spltty();
|
|
|
|
while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) &&
|
|
|
|
!(tp->t_state & TS_CARR_ON)) {
|
|
|
|
tp->t_wopen++;
|
|
|
|
error = ttysleep(tp, (caddr_t)&tp->t_rawq,
|
|
|
|
TTIPRI | PCATCH, ttopen, 0);
|
|
|
|
tp->t_wopen--;
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void) splx(s);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2000-11-02 03:01:44 +03:00
|
|
|
return ((*tp->t_linesw->l_open)(dev, tp));
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2000-04-30 15:46:49 +04:00
|
|
|
dzclose(dev_t dev, int flag, int mode, struct proc *p)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
|
|
|
struct dz_softc *sc;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit, line;
|
1999-05-27 20:02:32 +04:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
unit = DZ_I2C(minor(dev));
|
|
|
|
line = DZ_PORT(minor(dev));
|
|
|
|
sc = dz_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
tp = sc->sc_dz[line].dz_tty;
|
|
|
|
|
2000-11-02 03:01:44 +03:00
|
|
|
(*tp->t_linesw->l_close)(tp, flag);
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
/* Make sure a BREAK state is not left enabled. */
|
|
|
|
(void) dzmctl(sc, line, DML_BRK, DMBIC);
|
|
|
|
|
|
|
|
/* Do a hangup if so required. */
|
|
|
|
if ((tp->t_cflag & HUPCL) || tp->t_wopen || !(tp->t_state & TS_ISOPEN))
|
|
|
|
(void) dzmctl(sc, line, 0, DMSET);
|
|
|
|
|
|
|
|
return (ttyclose(tp));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-04-30 15:46:49 +04:00
|
|
|
dzread(dev_t dev, struct uio *uio, int flag)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct tty *tp;
|
1999-05-27 20:02:32 +04:00
|
|
|
struct dz_softc *sc;
|
|
|
|
|
|
|
|
sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
|
|
|
|
|
|
|
|
tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
|
2000-11-02 03:01:44 +03:00
|
|
|
return ((*tp->t_linesw->l_read)(tp, uio, flag));
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-04-30 15:46:49 +04:00
|
|
|
dzwrite(dev_t dev, struct uio *uio, int flag)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct tty *tp;
|
1999-05-27 20:02:32 +04:00
|
|
|
struct dz_softc *sc;
|
|
|
|
|
|
|
|
sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
|
|
|
|
|
|
|
|
tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
|
2000-11-02 03:01:44 +03:00
|
|
|
return ((*tp->t_linesw->l_write)(tp, uio, flag));
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
|
2001-05-02 14:32:08 +04:00
|
|
|
int
|
|
|
|
dzpoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
struct dz_softc *sc;
|
|
|
|
|
|
|
|
sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
|
|
|
|
|
|
|
|
tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
|
|
|
|
return ((*tp->t_linesw->l_poll)(tp, events, p));
|
|
|
|
}
|
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2000-04-30 15:46:49 +04:00
|
|
|
dzioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
|
|
|
struct dz_softc *sc;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit, line;
|
1999-05-27 20:02:32 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
unit = DZ_I2C(minor(dev));
|
|
|
|
line = DZ_PORT(minor(dev));
|
|
|
|
sc = dz_cd.cd_devs[unit];
|
|
|
|
tp = sc->sc_dz[line].dz_tty;
|
|
|
|
|
2000-11-02 03:01:44 +03:00
|
|
|
error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
|
1999-05-27 20:02:32 +04:00
|
|
|
if (error >= 0)
|
|
|
|
return (error);
|
2002-03-17 22:40:26 +03:00
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
error = ttioctl(tp, cmd, data, flag, p);
|
|
|
|
if (error >= 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case TIOCSBRK:
|
|
|
|
(void) dzmctl(sc, line, DML_BRK, DMBIS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCCBRK:
|
|
|
|
(void) dzmctl(sc, line, DML_BRK, DMBIC);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCSDTR:
|
|
|
|
(void) dzmctl(sc, line, DML_DTR, DMBIS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCCDTR:
|
|
|
|
(void) dzmctl(sc, line, DML_DTR, DMBIC);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMSET:
|
|
|
|
(void) dzmctl(sc, line, *(int *)data, DMSET);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMBIS:
|
|
|
|
(void) dzmctl(sc, line, *(int *)data, DMBIS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMBIC:
|
|
|
|
(void) dzmctl(sc, line, *(int *)data, DMBIC);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMGET:
|
|
|
|
*(int *)data = (dzmctl(sc, line, 0, DMGET) & ~DML_BRK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-03-17 22:40:26 +03:00
|
|
|
return (EPASSTHROUGH);
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct tty *
|
2000-04-30 15:46:49 +04:00
|
|
|
dztty(dev_t dev)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
|
|
|
struct dz_softc *sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
|
|
|
|
struct tty *tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
|
|
|
|
|
|
|
|
return (tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2000-04-30 15:46:49 +04:00
|
|
|
dzstop(struct tty *tp, int flag)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
|
|
|
if (tp->t_state & TS_BUSY)
|
|
|
|
if (!(tp->t_state & TS_TTSTOP))
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-30 15:46:49 +04:00
|
|
|
dzstart(struct tty *tp)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct dz_softc *sc;
|
|
|
|
struct clist *cl;
|
|
|
|
int unit, line, s;
|
1999-05-27 20:02:32 +04:00
|
|
|
char state;
|
|
|
|
|
|
|
|
unit = DZ_I2C(minor(tp->t_dev));
|
|
|
|
line = DZ_PORT(minor(tp->t_dev));
|
|
|
|
sc = dz_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
s = spltty();
|
2003-12-14 04:18:36 +03:00
|
|
|
if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
|
|
|
|
splx(s);
|
1999-05-27 20:02:32 +04:00
|
|
|
return;
|
2003-12-14 04:18:36 +03:00
|
|
|
}
|
1999-05-27 20:02:32 +04:00
|
|
|
cl = &tp->t_outq;
|
|
|
|
if (cl->c_cc <= tp->t_lowat) {
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
wakeup((caddr_t)cl);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
2003-12-14 04:18:36 +03:00
|
|
|
if (cl->c_cc == 0) {
|
|
|
|
splx(s);
|
1999-05-27 20:02:32 +04:00
|
|
|
return;
|
2003-12-14 04:18:36 +03:00
|
|
|
}
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
|
|
|
|
state = DZ_READ_WORD(dr_tcrw) & 255;
|
|
|
|
if ((state & (1 << line)) == 0) {
|
|
|
|
DZ_WRITE_BYTE(dr_tcr, state | (1 << line));
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
2000-01-24 05:40:28 +03:00
|
|
|
dzxint(sc);
|
1999-05-27 20:02:32 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-30 15:46:49 +04:00
|
|
|
dzparam(struct tty *tp, struct termios *t)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
|
|
|
struct dz_softc *sc;
|
2000-03-30 16:41:09 +04:00
|
|
|
int cflag = t->c_cflag;
|
1999-05-27 20:02:32 +04:00
|
|
|
int unit, line;
|
|
|
|
int ispeed = ttspeedtab(t->c_ispeed, dzspeedtab);
|
|
|
|
int ospeed = ttspeedtab(t->c_ospeed, dzspeedtab);
|
2000-03-30 16:41:09 +04:00
|
|
|
unsigned lpr;
|
1999-05-27 20:02:32 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
unit = DZ_I2C(minor(tp->t_dev));
|
|
|
|
line = DZ_PORT(minor(tp->t_dev));
|
|
|
|
sc = dz_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
/* check requested parameters */
|
|
|
|
if (ospeed < 0 || ispeed < 0 || ispeed != ospeed)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = cflag;
|
|
|
|
|
|
|
|
if (ospeed == 0) {
|
|
|
|
(void) dzmctl(sc, line, 0, DMSET); /* hang up line */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
lpr = DZ_LPR_RX_ENABLE | ((ispeed&0xF)<<8) | line;
|
|
|
|
|
|
|
|
switch (cflag & CSIZE)
|
|
|
|
{
|
|
|
|
case CS5:
|
|
|
|
lpr |= DZ_LPR_5_BIT_CHAR;
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
lpr |= DZ_LPR_6_BIT_CHAR;
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
lpr |= DZ_LPR_7_BIT_CHAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lpr |= DZ_LPR_8_BIT_CHAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cflag & PARENB)
|
|
|
|
lpr |= DZ_LPR_PARENB;
|
|
|
|
if (cflag & PARODD)
|
|
|
|
lpr |= DZ_LPR_OPAR;
|
|
|
|
if (cflag & CSTOPB)
|
|
|
|
lpr |= DZ_LPR_2_STOP;
|
|
|
|
|
|
|
|
DZ_WRITE_WORD(dr_lpr, lpr);
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
|
|
|
|
(void) splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
2000-04-30 15:46:49 +04:00
|
|
|
dzmctl(struct dz_softc *sc, int line, int bits, int how)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
unsigned status;
|
|
|
|
unsigned mbits;
|
|
|
|
unsigned bit;
|
1999-05-27 20:02:32 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
mbits = 0;
|
|
|
|
|
|
|
|
bit = (1 << line);
|
|
|
|
|
|
|
|
/* external signals as seen from the port */
|
|
|
|
|
|
|
|
status = DZ_READ_BYTE(dr_dcd) | sc->sc_dsr;
|
|
|
|
|
|
|
|
if (status & bit)
|
|
|
|
mbits |= DML_DCD;
|
|
|
|
|
|
|
|
status = DZ_READ_BYTE(dr_ring);
|
|
|
|
|
|
|
|
if (status & bit)
|
|
|
|
mbits |= DML_RI;
|
|
|
|
|
|
|
|
/* internal signals/state delivered to port */
|
|
|
|
|
|
|
|
status = DZ_READ_BYTE(dr_dtr);
|
|
|
|
|
|
|
|
if (status & bit)
|
|
|
|
mbits |= DML_DTR;
|
|
|
|
|
|
|
|
if (sc->sc_brk & bit)
|
|
|
|
mbits |= DML_BRK;
|
|
|
|
|
|
|
|
switch (how)
|
|
|
|
{
|
|
|
|
case DMSET:
|
|
|
|
mbits = bits;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMBIS:
|
|
|
|
mbits |= bits;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMBIC:
|
|
|
|
mbits &= ~bits;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMGET:
|
|
|
|
(void) splx(s);
|
|
|
|
return (mbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mbits & DML_DTR) {
|
|
|
|
DZ_WRITE_BYTE(dr_dtr, DZ_READ_BYTE(dr_dtr) | bit);
|
|
|
|
} else {
|
|
|
|
DZ_WRITE_BYTE(dr_dtr, DZ_READ_BYTE(dr_dtr) & ~bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mbits & DML_BRK) {
|
|
|
|
sc->sc_brk |= bit;
|
|
|
|
DZ_WRITE_BYTE(dr_break, sc->sc_brk);
|
|
|
|
} else {
|
|
|
|
sc->sc_brk &= ~bit;
|
|
|
|
DZ_WRITE_BYTE(dr_break, sc->sc_brk);
|
|
|
|
}
|
|
|
|
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
(void) splx(s);
|
|
|
|
return (mbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called by timeout() periodically.
|
|
|
|
* Check to see if modem status bits have changed.
|
|
|
|
*/
|
|
|
|
static void
|
2000-04-30 15:46:49 +04:00
|
|
|
dzscan(void *arg)
|
1999-05-27 20:02:32 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct dz_softc *sc;
|
|
|
|
struct tty *tp;
|
|
|
|
int n, bit, port;
|
1999-05-27 20:02:32 +04:00
|
|
|
unsigned csr;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
for (n = 0; n < dz_cd.cd_ndevs; n++) {
|
|
|
|
|
|
|
|
if (dz_cd.cd_devs[n] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sc = dz_cd.cd_devs[n];
|
|
|
|
|
|
|
|
for (port = 0; port < sc->sc_type; port++) {
|
|
|
|
|
|
|
|
tp = sc->sc_dz[port].dz_tty;
|
|
|
|
bit = (1 << port);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-05-27 20:02:32 +04:00
|
|
|
if ((DZ_READ_BYTE(dr_dcd) | sc->sc_dsr) & bit) {
|
|
|
|
if (!(tp->t_state & TS_CARR_ON))
|
2000-11-02 03:01:44 +03:00
|
|
|
(*tp->t_linesw->l_modem) (tp, 1);
|
1999-05-27 20:02:32 +04:00
|
|
|
} else if ((tp->t_state & TS_CARR_ON) &&
|
2000-11-02 03:01:44 +03:00
|
|
|
(*tp->t_linesw->l_modem)(tp, 0) == 0) {
|
2005-02-27 03:26:58 +03:00
|
|
|
DZ_WRITE_BYTE(dr_tcr,
|
1999-05-27 20:02:32 +04:00
|
|
|
(DZ_READ_WORD(dr_tcrw) & 255) & ~bit);
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the RX interrupt rate is this high, switch
|
|
|
|
* the controller to Silo Alarm - which means don't
|
|
|
|
* interrupt until the RX silo has 16 characters in
|
|
|
|
* it (the silo is 64 characters in all).
|
|
|
|
* Avoid oscillating SA on and off by not turning
|
|
|
|
* if off unless the rate is appropriately low.
|
|
|
|
*/
|
|
|
|
|
|
|
|
csr = DZ_READ_WORD(dr_csr);
|
|
|
|
|
|
|
|
if (sc->sc_rxint > (16*10)) {
|
|
|
|
if ((csr & DZ_CSR_SAE) == 0)
|
|
|
|
DZ_WRITE_WORD(dr_csr, csr | DZ_CSR_SAE);
|
|
|
|
} else if ((csr & DZ_CSR_SAE) != 0)
|
|
|
|
if (sc->sc_rxint < 10)
|
|
|
|
DZ_WRITE_WORD(dr_csr, csr & ~(DZ_CSR_SAE));
|
|
|
|
|
2003-12-14 02:02:33 +03:00
|
|
|
DZ_BARRIER();
|
1999-05-27 20:02:32 +04:00
|
|
|
sc->sc_rxint = 0;
|
|
|
|
}
|
|
|
|
(void) splx(s);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&dzscan_ch, hz, dzscan, NULL);
|
1999-05-27 20:02:32 +04:00
|
|
|
}
|
2000-04-30 15:46:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called after an ubareset. The DZ card is reset, but the only thing
|
|
|
|
* that must be done is to start the receiver and transmitter again.
|
|
|
|
* No DMA setup to care about.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dzreset(struct device *dev)
|
|
|
|
{
|
|
|
|
struct dz_softc *sc = (void *)dev;
|
|
|
|
struct tty *tp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->sc_type; i++) {
|
|
|
|
tp = sc->sc_dz[i].dz_tty;
|
|
|
|
|
|
|
|
if (((tp->t_state & TS_ISOPEN) == 0) || (tp->t_wopen == 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dzparam(tp, &tp->t_termios);
|
|
|
|
dzmctl(sc, i, DML_DTR, DMSET);
|
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
dzstart(tp); /* Kick off transmitter again */
|
|
|
|
}
|
|
|
|
}
|