NetBSD/sys/arch/mac68k/dev/ser.c

936 lines
22 KiB
C
Raw Normal View History

/* $NetBSD: ser.c,v 1.23 1995/06/08 12:52:02 briggs Exp $ */
1994-10-26 11:45:48 +03:00
/*
* Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
* All rights reserved.
*
* 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.
* 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.
*
*/
/*
* Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo,
* Michael L. Finch, Bradley A. Grantham, and
* Lawrence A. Kesteloot
* All rights reserved.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Alice Group.
* 4. The names of the Alice Group or any of its members may not be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``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 ALICE GROUP 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.
*
* Hacked by Brad Parker, <brad@fcr.com>
* added CTS input flow control
* added DCD event detection
* added software fifo's
*
* Mac II serial device interface
*
* Information used in this source was gleaned from low-memory
* global variables in MacOS and the Advanced Micro Devices
* 1992 Data Book/Handbook.
*/
#include "ser.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/proc.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>
1995-04-11 07:00:38 +04:00
#include <machine/cpu.h>
#include <machine/frame.h>
#include <dev/cons.h>
1995-04-11 07:00:38 +04:00
#include <dev/ic/z8530.h>
#include <mac68k/dev/serreg.h>
/*#define DEBUG*/
#undef DEBUG
struct ser_status {
1995-04-21 06:47:35 +04:00
unsigned char ddcd, dcts; /* delta (change) flags */
unsigned char dcd, cts; /* last state of signal */
unsigned char dtr, rts; /* current state of signal */
int oflo; /* s/w fifo over flow */
int over; /* h/w fifo over flow */
int flags;
#define SER_BUSY 0x01
};
#define INBUFLEN 128
#define OUTBUFLEN 512
struct ser_softc {
1995-04-21 06:47:35 +04:00
struct device sc_dev;
struct tty *sc_tty;
struct ser_status status;
/* private buffers used by driver at splscc() */
1995-04-21 06:47:35 +04:00
u_char inbuf[INBUFLEN];
volatile u_char inlen;
u_char intail;
1995-04-21 06:47:35 +04:00
u_char outbuf[OUTBUFLEN];
volatile u_int outlen;
volatile u_int outtail;
};
1995-04-21 06:47:35 +04:00
extern int matchbyname();
static void serattach(struct device * par, struct device * dev, void *aux);
static void serinit(int);
struct cfdriver sercd = {
NULL, "ser", matchbyname, serattach, DV_TTY, sizeof(struct ser_softc)
};
volatile unsigned char *sccA = (unsigned char *) 0x4000;
1995-04-21 06:47:35 +04:00
static void serstart __P((register struct tty *));
static int serparam __P((register struct tty *, register struct termios *));
static int serctl __P((dev_t dev, int bits, int how));
extern int ser_intr __P((void));
1995-04-21 06:47:35 +04:00
static int ser_active = 0;
static int nser = NSER;
static int serdefaultrate = TTYDEF_SPEED;
1995-04-21 06:47:35 +04:00
extern struct tty *constty;
#define UNIT(x) minor(x)
#define SER_TTY(unit) \
(((struct ser_softc *) sercd.cd_devs[unit])->sc_tty)
#define SCC_INT 10
#define SCC_SPEED 11
/* SCC initialization string from Steve Allen (wormey@eskimo.com) */
1995-04-21 06:47:35 +04:00
static unsigned char ser_init_bytes[] = {
4, 0x44, /* Transmit/Receive control. Select Async or
* Sync mode and clock multiplier. */
3, 0xc0, /* select receiver control. Bit d0 (rx
* enable) must be set to 0 at this time. */
5, 0xe2, /* select transmit control. Bit d3 (tx
* enable) must be set to 0 at this time. */
9, 0x06, /* select interrupt control. Bit d3 (mie)
* must be set to 0 at this time. */
10, 0x00, /* miscellaneous control. */
11, 0x50, /* clock control. */
12, 0x04, /* time constant LB. */
13, 0x00, /* time constant HB. */
14, 0x00, /* miscellaneous control. Bit d0 (BR gen
* enable) must be set to 0 at this time. */
3, 0xc1, /* set d0 (rx enable). */
5, 0xea, /* set d3 (tx enable). */
0, 0x80, /* reset txCRC. */
14, 0x01, /* BR gen enable. Enable DPLL. */
1, 0x00, /* make sure DMA not set. */
15, 0x00, /* disable external interrupts. */
0, 0x10, /* reset ext/status twice. */
0, 0x10,
1, 0x0a, /* enable rcv and xmit interrupts. */
9, 0x0e, /* enable master interrupt bit d3. */
};
static void
serinit(int running_interrupts)
{
1995-04-21 06:47:35 +04:00
static int initted = 0;
int bcount;
int i, s, spd;
/*
* Will be called twice if we're running a serial console.
*/
if (initted++)
return;
sccA = IOBase + sccA;
spd = SERBRD(serdefaultrate);
s = splhigh();
SER_DOCNTL(0, 9, 0xc0);
/*
* initialize ports, substituting proper speed.
*/
bcount = sizeof(ser_init_bytes);
1995-04-21 06:47:35 +04:00
for (i = 0; i < bcount; i += 2) {
if (ser_init_bytes[i] == 12) /* baud rate low byte */
1995-04-21 06:47:35 +04:00
ser_init_bytes[i + 1] = (spd & 0xff);
if (ser_init_bytes[i] == 13) /* baud rate high byte */
1995-04-21 06:47:35 +04:00
ser_init_bytes[i + 1] = ((spd >> 8) & 0xff);
if (!running_interrupts) {
1995-04-21 06:47:35 +04:00
if (ser_init_bytes[i] == 0x01
&& ser_init_bytes[i + 1] == 0x0a)
break;
}
SER_DOCNTL(0, ser_init_bytes[i], ser_init_bytes[i + 1]);
SER_DOCNTL(1, ser_init_bytes[i], ser_init_bytes[i + 1]);
}
splx(s);
}
static void
serattach(parent, dev, aux)
1995-04-21 06:47:35 +04:00
struct device *parent, *dev;
void *aux;
{
if (mac68k_machine.serial_boot_echo) {
printf(" (serial boot echo is on)\n");
}
printf("\n");
serinit(1);
}
/* ARGSUSED */
extern int
1995-04-21 06:47:35 +04:00
seropen(dev_t dev, int flag, int mode, struct proc * p)
{
struct ser_softc *sc;
register struct tty *tp;
register int unit = UNIT(dev);
1995-04-21 06:47:35 +04:00
int error = 0;
#if defined(DEBUG)
printf("ser: entered seropen(%d, %d, %d, xx)\n", dev, flag, mode);
#endif
if (unit >= sercd.cd_ndevs)
return ENXIO;
sc = sercd.cd_devs[unit];
if (sc == 0)
return ENXIO;
ser_active |= 1 << unit;
if (sc->sc_tty == NULL)
tp = sc->sc_tty = ttymalloc();
else
tp = sc->sc_tty;
tp->t_oproc = serstart;
tp->t_param = serparam;
tp->t_dev = dev;
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_WOPEN;
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 = serdefaultrate;
}
serparam(tp, &tp->t_termios);
ttsetwater(tp);
1995-04-21 06:47:35 +04:00
} else
if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
printf("ser%d: device is busy.\n", unit);
return EBUSY;
}
/* serial device open code */
1995-04-21 06:47:35 +04:00
bzero((char *) &sc->status, sizeof(struct ser_status));
/* turn on RTS & DTR */
1995-04-11 07:00:38 +04:00
serctl(unit, ZSWR5_RTS | ZSWR5_DTR, DMSET);
1995-04-21 06:47:35 +04:00
if (serctl(unit, 0, DMGET) & ZSRR0_DCD)
tp->t_state |= TS_CARR_ON;
/* enable interrupts */
serctl(unit, 1, SCC_INT);
/* end serial device open code */
(void) spltty();
1995-04-21 06:47:35 +04:00
while ((flag & O_NONBLOCK) == 0 && (tp->t_cflag & CLOCAL) == 0 &&
(tp->t_state & TS_CARR_ON) == 0) {
tp->t_state |= TS_WOPEN;
1995-04-21 06:47:35 +04:00
if (error = ttysleep(tp, (caddr_t) & tp->t_rawq, TTIPRI | PCATCH,
ttopen, 0))
break;
}
(void) spl0();
if (error == 0)
1995-04-21 06:47:35 +04:00
error = (*linesw[tp->t_line].l_open) (dev, tp);
#if defined(DEBUG)
printf("ser: exiting seropen()\n");
#endif
return (error);
}
/*ARGSUSED*/
extern int
1995-04-21 06:47:35 +04:00
serclose(dev_t dev, int flag, int mode, struct proc * p)
{
register int unit = UNIT(dev);
register struct tty *tp = SER_TTY(unit);
1995-04-21 06:47:35 +04:00
int s;
#if defined(DEBUG)
printf("ser: entered serclose()\n");
#endif
1995-04-21 06:47:35 +04:00
(*linesw[tp->t_line].l_close) (tp, flag);
/* serial device close code */
/* disable interrupts */
serctl(unit, 0, SCC_INT);
1995-04-21 06:47:35 +04:00
if (tp->t_cflag & HUPCL || tp->t_state & TS_WOPEN ||
(tp->t_state & TS_ISOPEN) == 0)
serctl(unit, 0, DMSET); /* turn RTS and DTR off */
ser_active &= ~(1 << unit);
/* end of serial device close code */
ttyclose(tp);
#ifdef broken
ttyfree(tp);
#endif
#if defined(DEBUG)
printf("ser: exiting serclose()\n");
#endif
return (0);
}
1995-04-21 06:47:35 +04:00
extern int
serread(dev, uio, flag)
1995-04-21 06:47:35 +04:00
dev_t dev;
struct uio *uio;
1995-04-21 06:47:35 +04:00
int flag;
{
register struct tty *tp = SER_TTY(UNIT(dev));
#if defined(DEBUG)
printf("ser: called serread()\n");
#endif
1995-04-21 06:47:35 +04:00
return ((*linesw[tp->t_line].l_read) (tp, uio, flag));
}
1995-04-21 06:47:35 +04:00
extern int
serwrite(dev, uio, flag)
1995-04-21 06:47:35 +04:00
dev_t dev;
struct uio *uio;
1995-04-21 06:47:35 +04:00
int flag;
{
register struct tty *tp = SER_TTY(UNIT(dev));
1995-04-21 06:47:35 +04:00
#if defined(DEBUG)
printf("ser: called serwrite()\n");
#endif
1995-04-21 06:47:35 +04:00
return ((*linesw[tp->t_line].l_write) (tp, uio, flag));
}
/*
1995-04-21 06:47:35 +04:00
* NOTE: This function is called by locore.s on a level 4 interrupt.
* since "splscc()" is level 4, and this is currently higher than
* anything except splhigh(), you can't call anything from this
* routine or you'll break the syncronization. basically we just
* do i/o from our local buffers and signal the upper layer with
* a software interrupt.
*/
/* serial interrupt code */
extern void
ser_intr(void)
{
1995-04-21 06:47:35 +04:00
register struct ser_softc *sc;
unsigned char reg0, reg1, ch, ch1, c, bits;
int s;
register int unit;
if (!initted) return;
1995-04-21 06:47:35 +04:00
/* read status to reset SCC state machine */
reg0 = SCCCNTL(0);
/* reset port B vector to see who interrupted us */
bits = SER_STATUS(1, 2) & 0x0e;
if (bits < 8)
unit = 1;
else
1995-04-21 06:47:35 +04:00
unit = 0;
sc = sercd.cd_devs[unit];
reg0 = SER_STATUS(unit, 0);
switch ((bits & 7) >> 1) {
case 0: /* tranmitter buffer empty */
if (sc->outlen > 0) {
c = sc->outbuf[sc->outtail];
sc->outtail = (sc->outtail + 1) % OUTBUFLEN;
SCCRDWR(unit) = c;
sc->outlen--;
} else {
SER_DOCNTL(unit, 0, ZSWR0_RESET_TXINT);
sc->status.flags &= ~SER_BUSY;
setsoftserial();
}
SER_DOCNTL(unit, 0, ZSWR0_CLR_INTR);
break;
case 1: /* ext/status change */
if ((reg0 & ZSRR0_DCD) && sc->status.dcd == 0)
sc->status.ddcd = 1;
1995-04-21 06:47:35 +04:00
else
if (!(reg0 & ZSRR0_DCD) && sc->status.dcd != 0)
sc->status.ddcd = 1;
sc->status.dcd = reg0 & ZSRR0_DCD;
1995-04-21 06:47:35 +04:00
if ((reg0 & ZSRR0_CTS) && sc->status.cts == 0)
sc->status.dcts = 1;
1995-04-21 06:47:35 +04:00
else
if (!(reg0 & ZSRR0_CTS) && sc->status.cts != 0)
sc->status.dcts = 1;
sc->status.cts = reg0 & ZSRR0_CTS;
if (reg0 & ZSRR0_TXUNDER)
SER_DOCNTL(unit, 0, ZSWR0_RESET_EOM);
SER_DOCNTL(unit, 0, ZSWR0_RESET_STATUS);
SER_DOCNTL(unit, 0, ZSWR0_CLR_INTR);
break;
case 2: /* recv char available */
ch = SCCRDWR(unit);
c = 1;
if (SER_STATUS(unit, 0) & ZSRR0_RX_READY) {
ch1 = SCCRDWR(unit);
c = 2;
}
if (sc->inlen < INBUFLEN)
sc->inbuf[(sc->intail + (sc->inlen++)) % INBUFLEN] = ch;
else
sc->status.oflo++;
if (c > 1) {
if (sc->inlen < INBUFLEN)
sc->inbuf[(sc->intail + (sc->inlen++)) % INBUFLEN] = ch1;
else
sc->status.oflo++;
}
setsoftserial();
1995-04-21 06:47:35 +04:00
SER_DOCNTL(unit, 0, ZSWR0_CLR_INTR);
break;
case 3: /* spec recv condition */
reg1 = SER_STATUS(unit, 1);
SCCRDWR(unit); /* flush fifo */
if (reg1 & ZSRR1_DO)
sc->status.over++;
SER_DOCNTL(unit, 0, ZSWR0_RESET_ERRORS);
SER_DOCNTL(unit, 0, ZSWR0_CLR_INTR);
break;
}
1995-04-21 06:47:35 +04:00
/* end of serial interrupt code */
}
/*
* serial software interrupt. do all the things we could
* not do at splscc();
*/
extern void
sersir(void)
{
register struct ser_softc *sc;
register struct tty *tp;
1995-04-21 06:47:35 +04:00
int unit, s, c;
for (unit = 0; unit < 2; unit++) {
sc = sercd.cd_devs[unit];
if ((tp = sc->sc_tty) == 0)
continue;
/* check for overflows */
if (sc->status.oflo || sc->status.over) {
s = splhigh();
sc->status.oflo = 0;
sc->status.over = 0;
splx(s);
if (tp->t_state & TS_ISOPEN)
1995-04-21 06:47:35 +04:00
(*linesw[tp->t_line].l_rint) ('#', tp);
}
/* check for change in DCD */
if (sc->status.ddcd) {
s = splhigh();
sc->status.ddcd = 0;
splx(s);
if (0) {
if (sc->status.dcd)
tp->t_state |= TS_CARR_ON;
else
tp->t_state &= ~TS_CARR_ON;
1995-04-21 06:47:35 +04:00
(*linesw[tp->t_line].l_modem) (tp,
sc->status.dcd ? 1 : 0);
}
}
/* check for change in CTS */
if (sc->status.dcts) {
s = splhigh();
sc->status.dcts = 0;
splx(s);
if ((tp->t_state & TS_ISOPEN) &&
(tp->t_flags & CRTSCTS)) {
tp->t_state &= ~TS_TTSTOP;
serstart(tp);
} else
tp->t_state |= TS_TTSTOP;
}
/* drain input fifo */
while (sc->inlen > 0) {
if (tp->t_rawq.c_cc + tp->t_canq.c_cc >= TTYHOG) {
setsoftserial();
break;
}
s = splhigh();
c = sc->inbuf[sc->intail];
sc->intail = (sc->intail + 1) % INBUFLEN;
sc->inlen--;
splx(s);
if (tp->t_state & TS_ISOPEN)
1995-04-21 06:47:35 +04:00
(*linesw[tp->t_line].l_rint) (c, tp);
}
/* fill output fifo */
if (sc->outlen == 0) {
if (tp->t_line)
1995-04-21 06:47:35 +04:00
(*linesw[tp->t_line].l_start) (tp);
else
1995-04-21 06:47:35 +04:00
serstart(tp);
}
}
}
extern int
1995-04-21 06:47:35 +04:00
serioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc * p)
{
register struct tty *tp = SER_TTY(UNIT(dev));
register int error;
1995-04-21 06:47:35 +04:00
#if defined(DEBUG)
printf("ser: entering ioctl()\n");
#endif
1995-04-21 06:47:35 +04:00
error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag, p);
if (error >= 0)
return (error);
1994-02-10 07:30:27 +03:00
error = ttioctl(tp, cmd, data, flag, p);
if (error >= 0)
return (error);
switch (cmd) {
#if 0
1995-04-21 06:47:35 +04:00
case TIOCSBRK: /* turn break on */
dca->dca_cfcr |= CFCR_SBREAK;
break;
1995-04-21 06:47:35 +04:00
case TIOCCBRK: /* turn break off */
dca->dca_cfcr &= ~CFCR_SBREAK;
break;
#endif
1995-04-21 06:47:35 +04:00
case TIOCSDTR: /* set DTR */
1995-04-11 07:00:38 +04:00
(void) serctl(dev, ZSWR5_DTR | ZSWR5_RTS, DMBIS);
break;
1995-04-21 06:47:35 +04:00
case TIOCCDTR: /* clear DTR */
1995-04-11 07:00:38 +04:00
(void) serctl(dev, ZSWR5_DTR | ZSWR5_RTS, DMBIC);
break;
1995-04-21 06:47:35 +04:00
case TIOCMSET: /* set modem control bits */
(void) serctl(dev, *(int *) data, DMSET);
break;
1995-04-21 06:47:35 +04:00
case TIOCMBIS: /* OR bits on */
(void) serctl(dev, *(int *) data, DMBIS);
break;
1995-04-21 06:47:35 +04:00
case TIOCMBIC: /* AND bits off */
(void) serctl(dev, *(int *) data, DMBIC);
break;
1995-04-21 06:47:35 +04:00
case TIOCMGET: /* get modem bits */
*(int *) data = serctl(dev, 0, DMGET);
break;
case TIOCGFLAGS:
{
1995-04-21 06:47:35 +04:00
int bits = 0;
1995-04-21 06:47:35 +04:00
*(int *) data = bits;
break;
}
case TIOCSFLAGS:
{
1995-04-21 06:47:35 +04:00
int userbits, driverbits = 0;
error = suser(p->p_ucred, &p->p_acflag);
if (error != 0)
return (EPERM);
1995-04-21 06:47:35 +04:00
userbits = *(int *) data;
break;
}
default:
#if defined(DEBUG)
printf("ser%d: unknown ioctl(,0x%x,)\n", UNIT(dev), cmd);
#endif
return (ENOTTY);
}
#if defined(DEBUG)
printf("ser: exiting ioctl()\n");
#endif
return (0);
}
static int
ser_calc_regs(int unit, int cflag, unsigned char *preg3, unsigned char *preg4,
1995-04-21 06:47:35 +04:00
unsigned char *preg5)
{
unsigned char r3, r4, r5;
struct ser_softc *sc = sercd.cd_devs[unit];
1995-04-11 07:00:38 +04:00
r3 = ZSWR3_RX_ENABLE;
r5 = ZSWR5_TX_ENABLE;
if (sc->status.dtr)
1995-04-11 07:00:38 +04:00
r5 |= ZSWR5_DTR;
if (sc->status.rts)
1995-04-11 07:00:38 +04:00
r5 |= ZSWR5_RTS;
1995-04-21 06:47:35 +04:00
switch (cflag & CSIZE) {
case CS5:
1995-04-11 07:00:38 +04:00
r3 |= ZSWR3_RX_5;
r5 |= ZSWR5_TX_5;
break;
1995-04-21 06:47:35 +04:00
case CS6:
1995-04-11 07:00:38 +04:00
r3 |= ZSWR3_RX_6;
r5 |= ZSWR5_TX_6;
break;
1995-04-21 06:47:35 +04:00
case CS7:
1995-04-11 07:00:38 +04:00
r3 |= ZSWR3_RX_7;
r5 |= ZSWR5_TX_7;
break;
1995-04-21 06:47:35 +04:00
case CS8:
1995-04-11 07:00:38 +04:00
r3 |= ZSWR3_RX_8;
r5 |= ZSWR5_TX_8;
break;
}
r4 = 0;
1995-04-11 07:00:38 +04:00
if ((cflag & PARODD) == 0)
1995-04-12 18:55:45 +04:00
r4 |= ZSWR4_EVENP;
1995-04-11 07:00:38 +04:00
if (cflag & PARENB)
r4 |= ZSWR4_PARENB;
if (cflag & CSTOPB)
r4 |= ZSWR4_TWOSB;
else
1995-04-11 07:00:38 +04:00
r4 |= ZSWR4_ONESB;
1995-04-21 06:47:35 +04:00
*preg3 = r3;
*preg4 = r4;
*preg5 = r5;
}
1995-04-21 06:47:35 +04:00
static int
1995-04-21 06:47:35 +04:00
serparam(register struct tty * tp, register struct termios * t)
{
register int cflag = t->c_cflag;
unsigned char reg3, reg4, reg5;
1995-04-21 06:47:35 +04:00
int unit = UNIT(tp->t_dev);
int ospeed = t->c_ospeed;
int s;
#if defined(DEBUG)
printf("ser: entering serparam()\n");
#endif
1995-04-21 06:47:35 +04:00
/* check requested parameters */
1995-04-21 06:47:35 +04:00
if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed)) {
printf("ser: serparam() returning EINVAL\n");
1995-04-21 06:47:35 +04:00
return (EINVAL);
}
1995-04-21 06:47:35 +04:00
/* and copy to tty */
tp->t_ispeed = t->c_ispeed;
tp->t_ospeed = t->c_ospeed;
tp->t_cflag = cflag;
/* Start of serial specific param code */
1995-04-21 06:47:35 +04:00
if (ospeed == 0) {
serctl(unit, 0, DMSET); /* hang up line */
1995-04-21 06:47:35 +04:00
return (0);
}
serctl(unit, ospeed, SCC_SPEED);
/*
ser_calc_regs(unit, cflag, &reg3, &reg4, &reg5);
s = splhigh();
SER_DOCNTL(unit, 3, reg3);
SER_DOCNTL(unit, 4, reg4);
SER_DOCNTL(unit, 5, reg5);
splx(s);
*/
serctl(unit, 1, SCC_INT);
1995-04-11 07:00:38 +04:00
serctl(unit, ZSWR5_DTR | ZSWR5_RTS, DMSET);
/* End of serial specific param code */
#if defined(DEBUG)
printf("ser: exiting serparam()\n");
#endif
return (0);
}
extern void
1995-04-21 06:47:35 +04:00
serstart(register struct tty * tp)
{
1995-04-21 06:47:35 +04:00
int s, s1;
int i, space, unit, c, need_start, first_char;
struct ser_softc *sc;
1995-04-21 06:47:35 +04:00
unit = UNIT(tp->t_dev);
sc = sercd.cd_devs[unit];
s = spltty();
1995-04-21 06:47:35 +04:00
if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
goto out;
}
if (tp->t_outq.c_cc <= tp->t_lowat) {
1995-04-21 06:47:35 +04:00
if (tp->t_state & TS_ASLEEP) {
tp->t_state &= ~TS_ASLEEP;
1995-04-21 06:47:35 +04:00
wakeup((caddr_t) & tp->t_outq);
}
selwakeup(&(tp->t_wsel));
}
if (tp->t_outq.c_cc == 0 || (tp->t_state & TS_BUSY) ||
(sc->status.flags & SER_BUSY))
goto out;
tp->t_state |= TS_BUSY;
1995-04-21 06:47:35 +04:00
if (sc->outlen == 0) {
first_char = (char) getc(&tp->t_outq);
need_start = 1;
} else
need_start = 0;
/* put characters into a buffer that ser_intr() will empty */
/* out on transmit-ready interrupts. */
/* get free space in s/w fifo - this will only get better */
s1 = splhigh();
space = OUTBUFLEN - sc->outlen;
splx(s1);
1995-04-21 06:47:35 +04:00
while (tp->t_outq.c_cc && space > 0) {
/* note that getc goes spltty() */
c = getc(&tp->t_outq);
/* protect s/w fifo at splhigh() */
s1 = splhigh();
sc->outbuf[(sc->outtail + (sc->outlen++))
1995-04-21 06:47:35 +04:00
% OUTBUFLEN] = (char) c;
splx(s1);
space--;
}
tp->t_state &= ~TS_BUSY;
if (need_start) {
s1 = splhigh();
sc->status.flags |= SER_BUSY;
SCCRDWR(unit) = first_char; /* to start chain */
splx(s1);
}
out:
splx(s);
}
/*
* Stop output on a line.
*/
/*ARGSUSED*/
extern int
1995-04-21 06:47:35 +04:00
serstop(register struct tty * tp, int flag)
{
register int s;
#if defined(DEBUG)
printf("ser: entering serstop()\n");
#endif
s = spltty();
if (tp->t_state & TS_BUSY) {
1995-04-21 06:47:35 +04:00
if ((tp->t_state & TS_TTSTOP) == 0)
tp->t_state |= TS_FLUSH;
}
#if defined(DEBUG)
printf("ser: exiting serstop()\n");
#endif
splx(s);
}
struct tty *
sertty(dev)
1995-04-21 06:47:35 +04:00
dev_t dev;
{
return (SER_TTY(UNIT(dev)));
}
static int
serctl(dev_t dev, int bits, int how)
{
struct ser_softc *sc;
1995-04-21 06:47:35 +04:00
int unit, s;
unit = UNIT(dev);
sc = sercd.cd_devs[unit];
/* run at splhigh so we don't get interrupted by i/o */
s = splhigh();
switch (how) {
case DMSET:
sc->status.dtr = bits & ZSWR5_DTR;
sc->status.rts = bits & ZSWR5_RTS;
SER_DOCNTL(unit, 5, bits | 0x68);
break;
case DMBIS:
break;
case DMBIC:
break;
case DMGET:
bits = SER_STATUS(unit, 0);
break;
1995-04-21 06:47:35 +04:00
/* */
case SCC_INT:
if (bits) {
1995-04-11 07:00:38 +04:00
SER_DOCNTL(unit, 0, ZSWR0_RESET_ERRORS);
SER_DOCNTL(unit, 0, ZSWR0_CLR_INTR);
SER_DOCNTL(unit, 1, ZSWR1_SIE | ZSWR1_RIE | ZSWR1_TIE);
} else
SER_DOCNTL(unit, 1, 0);
break;
case SCC_SPEED:
SER_DOCNTL(unit, 12, SERBRD(bits) & 0xff);
SER_DOCNTL(unit, 13, (SERBRD(bits) >> 8) & 0xff);
break;
}
(void) splx(s);
1995-04-21 06:47:35 +04:00
return (bits);
}
/*
* Console functions.
*/
1995-04-21 06:47:35 +04:00
dev_t mac68k_serdev;
1995-04-21 06:47:35 +04:00
sercnprobe(struct consdev * cp)
{
1995-04-21 06:47:35 +04:00
int maj, unit;
1995-04-21 06:47:35 +04:00
for (maj = 0; maj < nchrdev; maj++) {
if (cdevsw[maj].d_open == seropen) {
break;
}
}
if (maj == nchrdev)
goto nosercon;
1995-04-21 06:47:35 +04:00
cp->cn_pri = CN_NORMAL; /* Lower than CN_INTERNAL */
if (mac68k_machine.serial_console & 0x01)
cp->cn_pri = CN_REMOTE; /* Higher than CN_INTERNAL */
1995-04-21 06:47:35 +04:00
unit = (mac68k_machine.serial_console & 0x02) ? 1 : 0;
1995-04-21 06:47:35 +04:00
cp->cn_dev = makedev(maj, unit);
1995-04-21 06:47:35 +04:00
mac68k_machine.serial_boot_echo = 0;
return 0;
nosercon:
1995-04-21 06:47:35 +04:00
if (mac68k_machine.serial_boot_echo) {
/* major number doesn't really matter. */
mac68k_serdev = makedev(maj, 0);
serinit(1);
}
return 0;
}
1995-04-21 06:47:35 +04:00
sercninit(struct consdev * cp)
{
1995-04-21 06:47:35 +04:00
serinit(1);
}
sercngetc(dev_t dev)
{
1995-04-21 06:47:35 +04:00
int unit, c;
1995-04-21 06:47:35 +04:00
unit = UNIT(dev);
1995-04-21 06:47:35 +04:00
while (!(SER_STATUS(unit, 0) & ZSRR0_RX_READY));
c = SCCRDWR(unit);
SER_STATUS(unit, 0) = ZSWR0_RESET_STATUS;
1995-04-21 06:47:35 +04:00
return c;
}
sercnputc(dev_t dev, int c)
{
1995-04-21 06:47:35 +04:00
int unit;
1995-04-21 06:47:35 +04:00
unit = UNIT(dev);
1995-04-21 06:47:35 +04:00
while (!(SER_STATUS(unit, 0) & ZSRR0_TX_READY));
SCCRDWR(unit) = c;
}