1998-06-10 10:57:29 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Doug Rabson
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-06-10 10:57:29 +00:00
|
|
|
*/
|
|
|
|
/*
|
2000-03-18 07:46:05 +00:00
|
|
|
* This driver is a somewhat hack. A real driver might use the zs driver
|
|
|
|
* source from NetBSD, except that it's no real winner either.
|
1998-06-10 10:57:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
1999-08-09 10:35:05 +00:00
|
|
|
#include <sys/cons.h>
|
1998-06-10 10:57:29 +00:00
|
|
|
#include <machine/clock.h>
|
|
|
|
|
|
|
|
#include <alpha/tlsb/gbusvar.h>
|
2000-03-18 07:46:05 +00:00
|
|
|
#include <alpha/tlsb/tlsbreg.h>
|
1998-06-10 10:57:29 +00:00
|
|
|
#include <alpha/tlsb/zsreg.h>
|
1998-06-14 13:46:10 +00:00
|
|
|
#include <alpha/tlsb/zsvar.h>
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
#define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
|
|
|
|
|
|
|
|
static int zsc_get_channel(device_t dev);
|
|
|
|
static caddr_t zsc_get_base(device_t dev);
|
|
|
|
|
|
|
|
struct zs_softc {
|
2000-03-18 07:46:05 +00:00
|
|
|
struct tty * tp;
|
|
|
|
device_t dev;
|
1998-06-10 10:57:29 +00:00
|
|
|
int channel;
|
|
|
|
caddr_t base;
|
2000-03-18 07:46:05 +00:00
|
|
|
struct callout_handle zst;
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
|
|
|
#define ZS_SOFTC(unit) \
|
2000-03-18 07:46:05 +00:00
|
|
|
((struct zs_softc *) devclass_get_softc(zs_devclass, (unit)))
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
static d_open_t zsopen;
|
|
|
|
static d_close_t zsclose;
|
|
|
|
static d_ioctl_t zsioctl;
|
|
|
|
|
1999-11-18 04:20:23 +00:00
|
|
|
#define CDEV_MAJOR 135
|
1998-06-10 10:57:29 +00:00
|
|
|
static struct cdevsw zs_cdevsw = {
|
1999-05-30 16:53:49 +00:00
|
|
|
/* open */ zsopen,
|
|
|
|
/* close */ zsclose,
|
1999-09-28 11:45:31 +00:00
|
|
|
/* read */ ttyread,
|
|
|
|
/* write */ ttywrite,
|
1999-05-30 16:53:49 +00:00
|
|
|
/* ioctl */ zsioctl,
|
1999-09-25 16:21:39 +00:00
|
|
|
/* poll */ ttypoll,
|
1999-05-30 16:53:49 +00:00
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ nostrategy,
|
|
|
|
/* name */ "zs",
|
|
|
|
/* maj */ CDEV_MAJOR,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ 0,
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void zsstart __P((struct tty *));
|
|
|
|
static int zsparam __P((struct tty *, struct termios *));
|
1999-09-25 16:21:39 +00:00
|
|
|
static void zsstop __P((struct tty *tp, int flag));
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helpers for console support.
|
|
|
|
*/
|
|
|
|
|
1998-06-14 13:46:10 +00:00
|
|
|
static int zs_probe(device_t);
|
|
|
|
static int zs_attach(device_t);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
static devclass_t zs_devclass;
|
|
|
|
static devclass_t zsc_devclass;
|
|
|
|
|
1998-06-14 13:46:10 +00:00
|
|
|
static device_method_t zs_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, zs_probe),
|
|
|
|
DEVMETHOD(device_attach, zs_attach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t zs_driver = {
|
2000-01-29 16:39:21 +00:00
|
|
|
"zs", zs_methods, sizeof (struct zs_softc),
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
static void zs_poll_intr __P((void *));
|
|
|
|
static int zspolltime;
|
|
|
|
|
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
static int
|
1998-06-14 13:46:10 +00:00
|
|
|
zs_probe(device_t dev)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-06-14 13:46:10 +00:00
|
|
|
zs_attach(device_t dev)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
|
|
|
struct zs_softc *sc = device_get_softc(dev);
|
2000-03-18 07:46:05 +00:00
|
|
|
sc->dev = dev;
|
1998-06-10 10:57:29 +00:00
|
|
|
sc->channel = zsc_get_channel(dev);
|
|
|
|
sc->base = zsc_get_base(dev);
|
2000-03-18 07:46:05 +00:00
|
|
|
make_dev(&zs_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
"zs%d", device_get_unit(dev));
|
1998-06-10 10:57:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-07-05 12:16:55 +00:00
|
|
|
static caddr_t
|
|
|
|
zs_statusreg(caddr_t base, int chan)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
if (chan == 0)
|
|
|
|
return base + ZSC_CHANNELA + ZSC_STATUS;
|
|
|
|
if (chan == 1)
|
|
|
|
return base + ZSC_CHANNELB + ZSC_STATUS;
|
|
|
|
panic("zs_statusreg: bogus channel");
|
1998-07-05 12:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static caddr_t
|
|
|
|
zs_datareg(caddr_t base, int chan)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
if (chan == 0)
|
|
|
|
return base + ZSC_CHANNELA + ZSC_DATA;
|
|
|
|
if (chan == 1)
|
|
|
|
return base + ZSC_CHANNELB + ZSC_DATA;
|
|
|
|
panic("zs_statusreg: bogus channel");
|
1998-07-05 12:16:55 +00:00
|
|
|
}
|
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
static int
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_get_status(caddr_t base, int chan)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
return *(u_int32_t*) zs_statusreg(base, chan) & 0xff;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
#ifdef IF_RR3_WORKED
|
1998-06-10 10:57:29 +00:00
|
|
|
static void
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_put_status(caddr_t base, int chan, int v)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
*(u_int32_t*) zs_statusreg(base, chan) = v;
|
|
|
|
alpha_mb();
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_get_rr3(caddr_t base, int chan)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
if (chan != 0)
|
|
|
|
panic("zs_get_rr3: bad channel");
|
|
|
|
zs_put_status(base, chan, 3);
|
|
|
|
return zs_get_status(base, chan);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
2000-03-18 07:46:05 +00:00
|
|
|
#endif
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
static int
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_get_data(caddr_t base, int chan)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
return *(u_int32_t*) zs_datareg(base, chan) & 0xff;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_put_data(caddr_t base, int chan, int v)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
*(u_int32_t*) zs_datareg(base, chan) = v;
|
|
|
|
alpha_mb();
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_getc(caddr_t base, int chan)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
while (!(zs_get_status(base, chan) & 1))
|
|
|
|
DELAY(5);
|
|
|
|
return zs_get_data(base, chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zs_maygetc(caddr_t base, int chan)
|
|
|
|
{
|
|
|
|
if (zs_get_status(base, chan) & 1)
|
|
|
|
return zs_get_data(base, chan);
|
|
|
|
else
|
|
|
|
return (-1);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_putc(caddr_t base, int chan, int c)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
while (!(zs_get_status(base, chan) & 4))
|
|
|
|
DELAY(5);
|
|
|
|
zs_put_data(base, chan, c);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
/*
|
|
|
|
* Console support
|
|
|
|
*/
|
|
|
|
int zs_cngetc __P((dev_t));
|
|
|
|
int zs_cncheckc __P((dev_t));
|
|
|
|
void zs_cnputc __P((dev_t, int));
|
|
|
|
|
|
|
|
static caddr_t zs_console_addr;
|
|
|
|
CONS_DRIVER(zs, NULL, NULL, NULL, zs_cngetc, zs_cncheckc, zs_cnputc, NULL);
|
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
zs_cnattach(vm_offset_t base, vm_offset_t offset)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
/* should really bet part of ivars */
|
|
|
|
zs_console_addr = (caddr_t) ALPHA_PHYS_TO_K0SEG(base + offset);
|
|
|
|
|
|
|
|
zs_consdev.cn_dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
zs_consdev.cn_pri = CN_NORMAL;
|
|
|
|
cn_tab = &zs_consdev;
|
|
|
|
make_dev(&zs_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "zs0");
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
1998-07-05 12:16:55 +00:00
|
|
|
int
|
1998-06-10 10:57:29 +00:00
|
|
|
zs_cngetc(dev_t dev)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
int s = spltty();
|
|
|
|
int c = zs_getc(zs_console_addr, minor(dev));
|
|
|
|
splx(s);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zs_cncheckc(dev_t dev)
|
|
|
|
{
|
|
|
|
int s = spltty();
|
|
|
|
int c = zs_maygetc(zs_console_addr, minor(dev));
|
|
|
|
splx(s);
|
|
|
|
return c;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
1998-07-05 12:16:55 +00:00
|
|
|
void
|
1998-06-10 10:57:29 +00:00
|
|
|
zs_cnputc(dev_t dev, int c)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
int s = spltty();
|
|
|
|
zs_putc(zs_console_addr, minor(dev), c);
|
|
|
|
splx(s);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
zsopen(dev_t dev, int flag, int mode, struct proc *p)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zs_softc *sc = ZS_SOFTC(minor(dev));
|
1998-06-10 10:57:29 +00:00
|
|
|
struct tty *tp;
|
2000-03-18 07:46:05 +00:00
|
|
|
int error = 0, setuptimeout = 0;
|
1998-06-10 10:57:29 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
if (!sc)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
s = spltty();
|
2000-03-18 07:46:05 +00:00
|
|
|
tp = sc->tp = dev->si_tty = ttymalloc(sc->tp);
|
1998-06-10 10:57:29 +00:00
|
|
|
tp->t_oproc = zsstart;
|
|
|
|
tp->t_param = zsparam;
|
1999-09-25 16:21:39 +00:00
|
|
|
tp->t_stop = zsstop;
|
1998-06-10 10:57:29 +00:00
|
|
|
tp->t_dev = dev;
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
|
|
|
ttychars(tp);
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
1999-01-30 12:17:38 +00:00
|
|
|
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
|
1998-06-10 10:57:29 +00:00
|
|
|
ttsetwater(tp);
|
2000-03-18 07:46:05 +00:00
|
|
|
setuptimeout = 1;
|
|
|
|
} else if ((tp->t_state & TS_XCLUDE) && suser(p)) {
|
1998-06-10 10:57:29 +00:00
|
|
|
splx(s);
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
error = (*linesw[tp->t_line].l_open)(dev, tp);
|
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
if (error == 0 && setuptimeout) {
|
|
|
|
zspolltime = hz / 50;
|
|
|
|
if (zspolltime < 1)
|
|
|
|
zspolltime = 1;
|
|
|
|
/* XXX we're not set up to do interrupts yet */
|
|
|
|
sc->zst = timeout(zs_poll_intr, sc, zspolltime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zsclose(dev_t dev, int flag, int mode, struct proc *p)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zs_softc *sc = ZS_SOFTC(minor(dev));
|
|
|
|
struct tty *tp;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
tp = sc->tp;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
s = spltty();
|
|
|
|
untimeout(zs_poll_intr, sc, sc->zst);
|
1998-06-10 10:57:29 +00:00
|
|
|
(*linesw[tp->t_line].l_close)(tp, flag);
|
|
|
|
ttyclose(tp);
|
2000-03-18 07:46:05 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zsioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zs_softc *sc = ZS_SOFTC(minor(dev));
|
|
|
|
struct tty *tp;
|
1998-06-10 10:57:29 +00:00
|
|
|
int error;
|
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
tp = ZS_SOFTC(minor(dev))->tp;
|
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
|
2000-03-18 07:46:05 +00:00
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
if (error != ENOIOCTL)
|
2000-03-18 07:46:05 +00:00
|
|
|
return (error);
|
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
error = ttioctl(tp, cmd, data, flag);
|
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
if (error != ENOIOCTL)
|
|
|
|
return (error);
|
|
|
|
else
|
|
|
|
return (ENOTTY);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zsparam(struct tty *tp, struct termios *t)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zsstart(struct tty *tp)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zs_softc *sc = ZS_SOFTC(minor(tp->t_dev));
|
|
|
|
int s = spltty();
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
|
|
|
|
ttwwakeup(tp);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
while (tp->t_outq.c_cc != 0)
|
1998-07-05 12:16:55 +00:00
|
|
|
zs_putc(sc->base, minor(tp->t_dev), getc(&tp->t_outq));
|
1998-06-10 10:57:29 +00:00
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
|
|
|
|
ttwwakeup(tp);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop output on a line.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
zsstop(struct tty *tp, int flag)
|
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
int s = spltty();
|
1998-06-10 10:57:29 +00:00
|
|
|
if (tp->t_state & TS_BUSY)
|
|
|
|
if ((tp->t_state & TS_TTSTOP) == 0)
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1999-11-08 07:51:28 +00:00
|
|
|
DRIVER_MODULE(zs, zsc, zs_driver, zs_devclass, 0, 0);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The zsc bus holds two zs devices, one for channel A, one for channel B.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct zsc_softc {
|
|
|
|
caddr_t base;
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zs_softc *sc_a;
|
|
|
|
struct zs_softc *sc_b;
|
1998-11-15 18:25:17 +00:00
|
|
|
void *intr;
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
2000-03-18 07:46:05 +00:00
|
|
|
static driver_intr_t zsc_tlsb_intr;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
1998-06-14 13:46:10 +00:00
|
|
|
static int zsc_tlsb_probe(device_t dev);
|
|
|
|
static int zsc_tlsb_attach(device_t dev);
|
1999-07-29 01:03:04 +00:00
|
|
|
static int zsc_tlsb_print_child(device_t dev, device_t child);
|
1998-06-14 13:46:10 +00:00
|
|
|
|
|
|
|
static device_method_t zsc_tlsb_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, zsc_tlsb_probe),
|
|
|
|
DEVMETHOD(device_attach, zsc_tlsb_attach),
|
|
|
|
DEVMETHOD(device_detach, bus_generic_detach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, zsc_tlsb_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, bus_generic_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, bus_generic_write_ivar),
|
1998-11-15 18:25:17 +00:00
|
|
|
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
1998-06-10 10:57:29 +00:00
|
|
|
|
1998-06-14 13:46:10 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t zsc_tlsb_driver = {
|
2000-03-18 07:46:05 +00:00
|
|
|
"zsc", zsc_tlsb_methods, sizeof(struct zsc_softc),
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
zsc_get_channel(device_t dev)
|
|
|
|
{
|
|
|
|
return (long) device_get_ivars(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static caddr_t
|
|
|
|
zsc_get_base(device_t dev)
|
|
|
|
{
|
1998-06-14 13:46:10 +00:00
|
|
|
device_t bus = device_get_parent(dev);
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zsc_softc *sc = device_get_softc(bus);
|
1998-06-10 10:57:29 +00:00
|
|
|
return sc->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-06-14 13:46:10 +00:00
|
|
|
zsc_tlsb_probe(device_t dev)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
static int zs_unit = 0;
|
|
|
|
struct zsc_softc *sc = device_get_softc(dev);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
device_set_desc(dev, "Z8530 uart");
|
2000-03-18 07:46:05 +00:00
|
|
|
sc->base = (caddr_t)
|
|
|
|
ALPHA_PHYS_TO_K0SEG(TLSB_GBUS_BASE + gbus_get_offset(dev));
|
1998-06-10 10:57:29 +00:00
|
|
|
/*
|
1998-07-05 12:16:55 +00:00
|
|
|
* Add channel A and channel B
|
1998-06-10 10:57:29 +00:00
|
|
|
*/
|
2000-03-18 07:46:05 +00:00
|
|
|
device_add_child(dev, "zs", zs_unit++);
|
|
|
|
device_add_child(dev, "zs", zs_unit++);
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-06-14 13:46:10 +00:00
|
|
|
zsc_tlsb_attach(device_t dev)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
static int once = 1;
|
|
|
|
struct zsc_softc *sc = device_get_softc(dev);
|
1998-07-12 16:23:19 +00:00
|
|
|
device_t parent = device_get_parent(dev);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2000-03-18 07:46:05 +00:00
|
|
|
if (once) {
|
|
|
|
once = 0;
|
|
|
|
cdevsw_add(&zs_cdevsw);
|
|
|
|
}
|
1998-06-14 13:46:10 +00:00
|
|
|
bus_generic_attach(dev);
|
2000-03-18 07:46:05 +00:00
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
/* XXX */
|
2000-03-18 07:46:05 +00:00
|
|
|
sc->sc_a = ZS_SOFTC(device_get_unit(dev));
|
|
|
|
sc->sc_b = ZS_SOFTC(device_get_unit(dev)+1);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
1998-11-15 18:25:17 +00:00
|
|
|
/* XXX should use resource argument to communicate vector */
|
1999-05-08 21:59:43 +00:00
|
|
|
return BUS_SETUP_INTR(parent, dev, NULL, INTR_TYPE_TTY,
|
2000-03-18 07:46:05 +00:00
|
|
|
zsc_tlsb_intr, sc, &sc->intr);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
static int
|
1998-06-14 13:46:10 +00:00
|
|
|
zsc_tlsb_print_child(device_t bus, device_t dev)
|
|
|
|
{
|
1999-07-29 01:03:04 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
retval += bus_print_child_header(bus, dev);
|
|
|
|
retval += printf(" on %s channel %c\n", device_get_nameunit(bus),
|
|
|
|
'A' + (device_get_unit(dev) & 1));
|
|
|
|
|
|
|
|
return (retval);
|
1998-06-14 13:46:10 +00:00
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
static void
|
2000-03-18 07:46:05 +00:00
|
|
|
zs_poll_intr(void *arg)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2000-03-18 07:46:05 +00:00
|
|
|
struct zs_softc *sc = arg;
|
|
|
|
int s = spltty();
|
|
|
|
zsc_tlsb_intr(device_get_softc(device_get_parent(sc->dev)));
|
|
|
|
sc->zst = timeout(zs_poll_intr, sc, zspolltime);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zsc_tlsb_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct zsc_softc *sc = arg;
|
1998-06-10 10:57:29 +00:00
|
|
|
caddr_t base = sc->base;
|
2000-03-18 07:46:05 +00:00
|
|
|
int rr3;
|
|
|
|
|
|
|
|
if (base == NULL)
|
|
|
|
panic("null base in zsc_tlsb_intr");
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef IF_RR3_WORKED
|
|
|
|
rr3 = zs_get_rr3(base, 0);
|
|
|
|
#else
|
|
|
|
rr3 = 0x20;
|
|
|
|
#endif
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
if (rr3 & 0x20) {
|
2000-03-18 07:46:05 +00:00
|
|
|
struct tty *tp = sc->sc_a->tp;
|
1998-06-10 10:57:29 +00:00
|
|
|
int c;
|
|
|
|
|
1998-07-05 12:16:55 +00:00
|
|
|
while (zs_get_status(base, 0) & 1) {
|
|
|
|
c = zs_get_data(base, 0);
|
|
|
|
#ifdef DDB
|
|
|
|
if (c == CTRL('\\'))
|
|
|
|
Debugger("manual escape to debugger");
|
|
|
|
#endif
|
2000-03-18 07:46:05 +00:00
|
|
|
if (tp && (tp->t_state & TS_ISOPEN))
|
1998-07-05 12:16:55 +00:00
|
|
|
(*linesw[tp->t_line].l_rint)(c, tp);
|
|
|
|
DELAY(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rr3 & 0x04) {
|
2000-03-18 07:46:05 +00:00
|
|
|
struct tty *tp = sc->sc_b->tp;
|
1998-07-05 12:16:55 +00:00
|
|
|
int c;
|
|
|
|
|
|
|
|
while (zs_get_status(base, 1) & 1) {
|
|
|
|
c = zs_get_data(base, 1);
|
1998-06-10 10:57:29 +00:00
|
|
|
#ifdef DDB
|
|
|
|
if (c == CTRL('\\'))
|
|
|
|
Debugger("manual escape to debugger");
|
|
|
|
#endif
|
2000-03-18 07:46:05 +00:00
|
|
|
if (tp && (tp->t_state & TS_ISOPEN))
|
1998-06-10 10:57:29 +00:00
|
|
|
(*linesw[tp->t_line].l_rint)(c, tp);
|
|
|
|
DELAY(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-07-31 09:20:35 +00:00
|
|
|
DRIVER_MODULE(zsc, gbus, zsc_tlsb_driver, zsc_devclass, 0, 0);
|