1996-02-16 21:00:33 +03:00
|
|
|
/* $NetBSD: zs.c,v 1.33 1996/02/16 18:00:33 gwr Exp $ */
|
1994-10-26 12:07:55 +03:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Copyright (c) 1995 Gordon W. Ross
|
|
|
|
* All rights reserved.
|
1994-02-23 11:28:11 +03:00
|
|
|
*
|
|
|
|
* 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.
|
1996-01-25 01:39:48 +03:00
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
* 4. All advertising materials mentioning features or use of this software
|
1994-02-23 11:28:11 +03:00
|
|
|
* must display the following acknowledgement:
|
1996-01-25 01:39:48 +03:00
|
|
|
* This product includes software developed by Gordon Ross
|
1994-02-23 11:28:11 +03:00
|
|
|
*
|
1996-01-25 01:39:48 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Zilog Z8530 Dual UART driver (machine-dependent part)
|
1994-02-23 11:28:11 +03:00
|
|
|
*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Runs two serial lines per chip using slave drivers.
|
|
|
|
* Plain tty/async lines use the zs_async slave.
|
|
|
|
* Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-05-06 11:47:05 +04:00
|
|
|
#include <sys/systm.h>
|
1994-02-23 11:28:11 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
#include <dev/cons.h>
|
|
|
|
#include <dev/ic/z8530reg.h>
|
|
|
|
#include <machine/z8530var.h>
|
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/cpu.h>
|
1996-01-25 01:39:48 +03:00
|
|
|
#include <machine/eeprom.h>
|
1994-12-22 02:56:43 +03:00
|
|
|
#include <machine/isr.h>
|
1994-02-23 11:28:11 +03:00
|
|
|
#include <machine/obio.h>
|
1994-05-04 09:34:14 +04:00
|
|
|
#include <machine/mon.h>
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1994-12-15 07:34:06 +03:00
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* XXX: Hard code this to make console init easier...
|
1994-12-15 07:34:06 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
#define NZS 2 /* XXX */
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
|
1994-03-15 10:40:32 +03:00
|
|
|
/* The Sun3 provides a 4.9152 MHz clock to the ZS chips. */
|
|
|
|
#define PCLK (9600 * 512) /* PCLK pin input clock rate */
|
|
|
|
|
|
|
|
/*
|
1995-03-27 05:25:20 +04:00
|
|
|
* Define interrupt levels.
|
1994-03-15 10:40:32 +03:00
|
|
|
*/
|
|
|
|
#define ZSHARD_PRI 6 /* Wired on the CPU board... */
|
1995-03-27 05:25:20 +04:00
|
|
|
#define ZSSOFT_PRI 3 /* Want tty pri (4) but this is OK. */
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-02-16 21:00:33 +03:00
|
|
|
#define ZS_DELAY() delay(2)
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
/* The layout of this is hardware-dependent (padding, order). */
|
|
|
|
struct zschan {
|
|
|
|
volatile u_char zc_csr; /* ctrl,status, and indirect access */
|
|
|
|
u_char zc_xxx0;
|
|
|
|
volatile u_char zc_data; /* data */
|
|
|
|
u_char zc_xxx1;
|
|
|
|
};
|
|
|
|
struct zsdevice {
|
|
|
|
/* Yes, they are backwards. */
|
|
|
|
struct zschan zs_chan_b;
|
|
|
|
struct zschan zs_chan_a;
|
1994-02-23 11:28:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* Default OBIO addresses. */
|
|
|
|
static int zs_physaddr[NZS] = { OBIO_KEYBD_MS, OBIO_ZS };
|
|
|
|
/* Saved PROM mappings */
|
|
|
|
static struct zsdevice *zsaddr[NZS]; /* See zs_init() */
|
|
|
|
/* Flags from cninit() */
|
|
|
|
static int zs_hwflags[NZS][2];
|
|
|
|
/* Default speed for each channel */
|
|
|
|
static int zs_defspeed[NZS][2] = {
|
|
|
|
{ 1200, /* keyboard */
|
|
|
|
1200 }, /* mouse */
|
|
|
|
{ 9600, /* ttya */
|
|
|
|
9600 }, /* ttyb */
|
|
|
|
};
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* Find PROM mappings (for console support). */
|
|
|
|
void zs_init()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NZS; i++) {
|
|
|
|
zsaddr[i] = (struct zsdevice *)
|
|
|
|
obio_find_mapping(zs_physaddr[i], OBIO_ZS_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
struct zschan *
|
|
|
|
zs_get_chan_addr(zsc_unit, channel)
|
|
|
|
int zsc_unit, channel;
|
|
|
|
{
|
|
|
|
struct zsdevice *addr;
|
|
|
|
struct zschan *zc;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
if (zsc_unit >= NZS)
|
|
|
|
return NULL;
|
|
|
|
addr = zsaddr[zsc_unit];
|
|
|
|
if (addr == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (channel == 0) {
|
|
|
|
zc = &addr->zs_chan_a;
|
|
|
|
} else {
|
|
|
|
zc = &addr->zs_chan_b;
|
|
|
|
}
|
|
|
|
return (zc);
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1994-12-22 02:56:43 +03:00
|
|
|
|
|
|
|
static u_char zs_init_reg[16] = {
|
|
|
|
0, /* 0: CMD (reset, etc.) */
|
|
|
|
ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE,
|
|
|
|
0x18 + ZSHARD_PRI, /* IVECT */
|
|
|
|
ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
|
|
|
|
ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
|
|
|
|
ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
|
|
|
|
0, /* 6: TXSYNC/SYNCLO */
|
|
|
|
0, /* 7: RXSYNC/SYNCHI */
|
|
|
|
0, /* 8: alias for data port */
|
1996-01-25 01:39:48 +03:00
|
|
|
ZSWR9_MASTER_IE,
|
1994-12-22 02:56:43 +03:00
|
|
|
0, /*10: Misc. TX/RX control bits */
|
|
|
|
ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
|
1996-01-25 01:39:48 +03:00
|
|
|
14, /*12: BAUDLO (default=9600) */
|
|
|
|
0, /*13: BAUDHI (default=9600) */
|
1994-12-22 02:56:43 +03:00
|
|
|
ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
|
|
|
|
ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
|
|
|
|
};
|
1994-09-20 20:21:44 +04:00
|
|
|
|
1995-03-10 05:15:03 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/****************************************************************
|
|
|
|
* Autoconfig
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
/* Definition of the driver for autoconfig. */
|
|
|
|
static int zsc_match(struct device *, void *, void *);
|
|
|
|
static void zsc_attach(struct device *, struct device *, void *);
|
|
|
|
|
|
|
|
struct cfdriver zsccd = {
|
|
|
|
NULL, "zsc", zsc_match, zsc_attach,
|
|
|
|
DV_DULL, sizeof(struct zsc_softc), NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int zshard(void *);
|
|
|
|
static int zssoft(void *);
|
|
|
|
|
1994-09-20 20:21:44 +04:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Is the zs chip present?
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
|
|
|
static int
|
1996-01-25 01:39:48 +03:00
|
|
|
zsc_match(parent, vcf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *vcf;
|
|
|
|
void *aux;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1994-12-02 01:46:23 +03:00
|
|
|
struct cfdata *cf = vcf;
|
1996-01-25 01:39:48 +03:00
|
|
|
struct confargs *ca = aux;
|
1994-12-12 21:58:45 +03:00
|
|
|
int unit, x;
|
1995-03-10 05:15:03 +03:00
|
|
|
void *zsva;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
unit = cf->cf_unit;
|
|
|
|
if (unit < 0 || unit >= NZS)
|
|
|
|
return (0);
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* Make sure zs_init() found mappings. */
|
1995-03-10 05:15:03 +03:00
|
|
|
zsva = zsaddr[unit];
|
|
|
|
if (zsva == NULL)
|
|
|
|
return (0);
|
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
if (ca->ca_paddr == -1)
|
|
|
|
ca->ca_paddr = zs_physaddr[unit];
|
|
|
|
if (ca->ca_intpri == -1)
|
|
|
|
ca->ca_intpri = ZSHARD_PRI;
|
|
|
|
|
1995-03-10 05:15:03 +03:00
|
|
|
/* This returns -1 on a fault (bus error). */
|
|
|
|
x = peek_byte(zsva);
|
1994-12-13 21:26:39 +03:00
|
|
|
return (x != -1);
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
static int
|
|
|
|
zsc_print(aux, name)
|
|
|
|
void *aux;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
struct zsc_attach_args *args = aux;
|
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
printf("%s: ", name);
|
|
|
|
|
|
|
|
if (args->channel != -1)
|
|
|
|
printf(" channel %d", args->channel);
|
|
|
|
|
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
/*
|
|
|
|
* Attach a found zs.
|
|
|
|
*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Match slave number to zs unit number, so that misconfiguration will
|
|
|
|
* not set up the keyboard as ttya, etc.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
|
|
|
static void
|
1996-01-25 01:39:48 +03:00
|
|
|
zsc_attach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct zsc_softc *zsc = (void *) self;
|
|
|
|
struct confargs *ca = aux;
|
|
|
|
struct zsc_attach_args zsc_args;
|
|
|
|
volatile struct zschan *zc;
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
int zsc_unit, channel;
|
|
|
|
int reset, s;
|
1994-03-15 10:40:32 +03:00
|
|
|
static int didintr;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
zsc_unit = zsc->zsc_dev.dv_unit;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
printf(" softpri %d\n", ZSSOFT_PRI);
|
1994-03-15 10:40:32 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* Use the mapping setup by the Sun PROM. */
|
|
|
|
if (zsaddr[zsc_unit] == NULL)
|
|
|
|
panic("zs_attach: zs%d not mapped\n", zsc_unit);
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/*
|
|
|
|
* Initialize software state for each channel.
|
|
|
|
*/
|
|
|
|
for (channel = 0; channel < 2; channel++) {
|
|
|
|
cs = &zsc->zsc_cs[channel];
|
1994-03-15 10:40:32 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
zc = zs_get_chan_addr(zsc_unit, channel);
|
|
|
|
cs->cs_reg_csr = &zc->zc_csr;
|
|
|
|
cs->cs_reg_data = &zc->zc_data;
|
|
|
|
|
|
|
|
cs->cs_channel = channel;
|
|
|
|
cs->cs_private = NULL;
|
|
|
|
cs->cs_ops = &zsops_null;
|
|
|
|
|
|
|
|
/* Define BAUD rate clock for the MI code. */
|
|
|
|
cs->cs_pclk_div16 = PCLK / 16;
|
|
|
|
|
|
|
|
/* XXX: get defspeed from EEPROM instead? */
|
|
|
|
cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
|
|
|
|
|
|
|
|
bcopy(zs_init_reg, cs->cs_creg, 16);
|
|
|
|
bcopy(zs_init_reg, cs->cs_preg, 16);
|
1994-12-13 21:35:56 +03:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Clear the master interrupt enable.
|
|
|
|
* The INTENA is common to both channels,
|
|
|
|
* so just do it on the A channel.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
if (channel == 0) {
|
1996-01-31 01:34:52 +03:00
|
|
|
zs_write_reg(cs, 9, 0);
|
1996-01-25 01:39:48 +03:00
|
|
|
}
|
1994-12-13 21:35:56 +03:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Look for a child driver for this channel.
|
|
|
|
* The child attach will setup the hardware.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
zsc_args.channel = channel;
|
|
|
|
zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
|
|
|
|
if (!config_found(self, (void *) &zsc_args, zsc_print)) {
|
|
|
|
/* No sub-driver. Just reset it. */
|
|
|
|
reset = (channel == 0) ?
|
|
|
|
ZSWR9_A_RESET : ZSWR9_B_RESET;
|
|
|
|
s = splzs();
|
1996-01-31 01:34:52 +03:00
|
|
|
zs_write_reg(cs, 9, reset);
|
1996-01-25 01:39:48 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* Now safe to install interrupt handlers */
|
|
|
|
if (!didintr) {
|
|
|
|
didintr = 1;
|
|
|
|
isr_add_autovect(zssoft, NULL, ZSSOFT_PRI);
|
|
|
|
isr_add_autovect(zshard, NULL, ZSHARD_PRI);
|
|
|
|
}
|
1995-04-27 03:20:15 +04:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/*
|
|
|
|
* Set the master interrupt enable and interrupt vector.
|
|
|
|
* (common to both channels, do it on A)
|
|
|
|
*/
|
|
|
|
cs = &zsc->zsc_cs[0];
|
|
|
|
s = splzs();
|
|
|
|
/* interrupt vector */
|
1996-01-31 01:34:52 +03:00
|
|
|
zs_write_reg(cs, 2, zs_init_reg[2]);
|
1996-01-25 01:39:48 +03:00
|
|
|
/* master interrupt control (enable) */
|
1996-01-31 01:34:52 +03:00
|
|
|
zs_write_reg(cs, 9, zs_init_reg[9]);
|
1996-01-25 01:39:48 +03:00
|
|
|
splx(s);
|
1995-04-27 03:20:15 +04:00
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
static int
|
|
|
|
zshard(arg)
|
|
|
|
void *arg;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
struct zsc_softc *zsc;
|
|
|
|
int unit, rval;
|
|
|
|
|
|
|
|
/* Do ttya/ttyb first, because they go faster. */
|
|
|
|
rval = 0;
|
|
|
|
unit = zsccd.cd_ndevs;
|
|
|
|
while (--unit >= 0) {
|
|
|
|
zsc = zsccd.cd_devs[unit];
|
|
|
|
if (zsc != NULL) {
|
|
|
|
rval |= zsc_intr_hard(zsc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (rval);
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
int zssoftpending;
|
1994-03-15 10:40:32 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
zsc_req_softint(zsc)
|
|
|
|
struct zsc_softc *zsc;
|
|
|
|
{
|
|
|
|
if (zssoftpending == 0) {
|
|
|
|
/* We are at splzs here, so no need to lock. */
|
|
|
|
zssoftpending = ZSSOFT_PRI;
|
|
|
|
isr_soft_request(ZSSOFT_PRI);
|
1994-05-04 09:34:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1996-01-25 01:39:48 +03:00
|
|
|
zssoft(arg)
|
|
|
|
void *arg;
|
1994-05-04 09:34:14 +04:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
struct zsc_softc *zsc;
|
|
|
|
int unit;
|
1994-03-15 10:40:32 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* This is not the only ISR on this IPL. */
|
|
|
|
if (zssoftpending == 0)
|
|
|
|
return (0);
|
1994-05-04 09:34:14 +04:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/*
|
|
|
|
* The soft intr. bit will be set by zshard only if
|
|
|
|
* the variable zssoftpending is zero. The order of
|
|
|
|
* these next two statements prevents our clearing
|
|
|
|
* the soft intr bit just after zshard has set it.
|
|
|
|
*/
|
|
|
|
isr_soft_clear(ZSSOFT_PRI);
|
|
|
|
zssoftpending = 0;
|
|
|
|
|
|
|
|
/* Do ttya/ttyb first, because they go faster. */
|
|
|
|
unit = zsccd.cd_ndevs;
|
|
|
|
while (--unit >= 0) {
|
|
|
|
zsc = zsccd.cd_devs[unit];
|
|
|
|
if (zsc != NULL) {
|
|
|
|
(void) zsc_intr_soft(zsc);
|
|
|
|
}
|
1994-05-04 09:34:14 +04:00
|
|
|
}
|
1996-01-25 01:39:48 +03:00
|
|
|
return (1);
|
1994-03-15 10:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/*
|
|
|
|
* Read or write the chip with suitable delays.
|
|
|
|
*/
|
1994-03-15 10:40:32 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
u_char
|
|
|
|
zs_read_reg(cs, reg)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
u_char reg;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
u_char val;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
*cs->cs_reg_csr = reg;
|
|
|
|
ZS_DELAY();
|
|
|
|
val = *cs->cs_reg_csr;
|
|
|
|
ZS_DELAY();
|
|
|
|
return val;
|
1994-12-17 23:14:22 +03:00
|
|
|
}
|
1994-05-04 09:34:14 +04:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
zs_write_reg(cs, reg, val)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
u_char reg, val;
|
1994-12-17 23:14:22 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
*cs->cs_reg_csr = reg;
|
|
|
|
ZS_DELAY();
|
|
|
|
*cs->cs_reg_csr = val;
|
|
|
|
ZS_DELAY();
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
1994-05-04 09:34:14 +04:00
|
|
|
|
1996-01-31 01:34:52 +03:00
|
|
|
u_char zs_read_csr(cs)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
{
|
|
|
|
register u_char v;
|
|
|
|
|
|
|
|
v = *cs->cs_reg_csr;
|
|
|
|
ZS_DELAY();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_char zs_read_data(cs)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
{
|
|
|
|
register u_char v;
|
|
|
|
|
|
|
|
v = *cs->cs_reg_data;
|
|
|
|
ZS_DELAY();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void zs_write_csr(cs, val)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
u_char val;
|
|
|
|
{
|
|
|
|
*cs->cs_reg_csr = val;
|
|
|
|
ZS_DELAY();
|
|
|
|
}
|
|
|
|
|
|
|
|
void zs_write_data(cs, val)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
u_char val;
|
|
|
|
{
|
|
|
|
*cs->cs_reg_data = val;
|
|
|
|
ZS_DELAY();
|
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/****************************************************************
|
|
|
|
* Console support functions (Sun3 specific!)
|
|
|
|
****************************************************************/
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1994-03-15 10:40:32 +03:00
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Polled input char.
|
1994-03-15 10:40:32 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-01-25 01:39:48 +03:00
|
|
|
zs_getc(arg)
|
|
|
|
void *arg;
|
1994-03-15 10:40:32 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
register volatile struct zschan *zc = arg;
|
1995-06-14 02:11:33 +04:00
|
|
|
register int s, c, rr0;
|
1994-03-15 10:40:32 +03:00
|
|
|
|
|
|
|
s = splhigh();
|
1994-09-20 20:21:44 +04:00
|
|
|
/* Wait for a character to arrive. */
|
1995-06-14 02:11:33 +04:00
|
|
|
do {
|
|
|
|
rr0 = zc->zc_csr;
|
1994-05-04 09:34:14 +04:00
|
|
|
ZS_DELAY();
|
1995-06-14 02:11:33 +04:00
|
|
|
} while ((rr0 & ZSRR0_RX_READY) == 0);
|
1994-09-20 20:21:44 +04:00
|
|
|
|
1994-03-15 10:40:32 +03:00
|
|
|
c = zc->zc_data;
|
1994-09-20 20:21:44 +04:00
|
|
|
ZS_DELAY();
|
1994-03-15 10:40:32 +03:00
|
|
|
splx(s);
|
1994-12-17 23:14:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is used by the kd driver to read scan codes,
|
|
|
|
* so don't translate '\r' ==> '\n' here...
|
|
|
|
*/
|
1994-03-15 10:40:32 +03:00
|
|
|
return (c);
|
|
|
|
}
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Polled output char.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
zs_putc(arg, c)
|
|
|
|
void *arg;
|
1994-02-23 11:28:11 +03:00
|
|
|
int c;
|
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
register volatile struct zschan *zc = arg;
|
1995-06-14 02:11:33 +04:00
|
|
|
register int s, rr0;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
s = splhigh();
|
1994-09-20 20:21:44 +04:00
|
|
|
/* Wait for transmitter to become ready. */
|
1995-06-14 02:11:33 +04:00
|
|
|
do {
|
|
|
|
rr0 = zc->zc_csr;
|
1994-05-04 09:34:14 +04:00
|
|
|
ZS_DELAY();
|
1995-06-14 02:11:33 +04:00
|
|
|
} while ((rr0 & ZSRR0_TX_READY) == 0);
|
1994-09-20 20:21:44 +04:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
zc->zc_data = c;
|
1994-05-04 09:34:14 +04:00
|
|
|
ZS_DELAY();
|
1994-02-23 11:28:11 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
1994-03-15 10:40:32 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
extern struct consdev consdev_kd; /* keyboard/display */
|
|
|
|
extern struct consdev consdev_tty;
|
|
|
|
extern struct consdev *cn_tab; /* physical console device info */
|
|
|
|
extern void nullcnpollc();
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
void *zs_conschan;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* This function replaces sys/dev/cninit.c
|
|
|
|
* Determine which device is the console using
|
|
|
|
* the "console" byte from the EEPROM.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
cninit()
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
struct zschan *zc;
|
|
|
|
struct consdev *cn;
|
|
|
|
int zsc_unit, channel;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
switch (ee_console) {
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
case EE_CONS_TTYA:
|
|
|
|
case EE_CONS_TTYB:
|
|
|
|
zsc_unit = 1;
|
|
|
|
channel = (ee_console & 1);
|
|
|
|
cn = &consdev_tty;
|
|
|
|
cn->cn_dev = makedev(ZSTTY_MAJOR, channel);
|
|
|
|
cn->cn_pri = CN_REMOTE;
|
|
|
|
break;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
default:
|
|
|
|
mon_printf("cninit: unknown eeprom console setting\n");
|
|
|
|
/* assume keyboard/display */
|
|
|
|
/* fallthrough */
|
|
|
|
case EE_CONS_BW:
|
|
|
|
case EE_CONS_COLOR:
|
|
|
|
case EE_CONS_P4OPT:
|
|
|
|
zsc_unit = 0;
|
|
|
|
channel = 0;
|
|
|
|
cn = &consdev_kd;
|
|
|
|
/* Set cn_dev, cn_pri in kd.c */
|
|
|
|
break;
|
|
|
|
}
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
zc = zs_get_chan_addr(zsc_unit, channel);
|
|
|
|
if (zc == NULL) {
|
|
|
|
mon_printf("cninit: zs not mapped.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
zs_conschan = zc;
|
|
|
|
zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE;
|
|
|
|
cn_tab = cn;
|
|
|
|
(*cn->cn_init)(cn);
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* We never call this. */
|
|
|
|
void
|
|
|
|
nullcnprobe(cn)
|
|
|
|
struct consdev *cn;
|
|
|
|
{
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
zscninit(cn)
|
|
|
|
struct consdev *cn;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
int unit = minor(cn->cn_dev) & 1;
|
|
|
|
|
|
|
|
mon_printf("console is zstty%d (tty%c)\n",
|
|
|
|
unit, unit + 'a');
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Polled console input putchar.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-01-25 01:39:48 +03:00
|
|
|
zscngetc(dev)
|
1995-08-09 00:54:08 +04:00
|
|
|
dev_t dev;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
register volatile struct zschan *zc = zs_conschan;
|
|
|
|
register int c;
|
|
|
|
|
|
|
|
c = zs_getc(zc);
|
|
|
|
return (c);
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Polled console output putchar.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
zscnputc(dev, c)
|
1995-08-09 00:54:08 +04:00
|
|
|
dev_t dev;
|
1996-01-25 01:39:48 +03:00
|
|
|
int c;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
register volatile struct zschan *zc = zs_conschan;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
zs_putc(zc, c);
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
struct consdev consdev_tty = {
|
|
|
|
nullcnprobe,
|
|
|
|
zscninit,
|
|
|
|
zscngetc,
|
|
|
|
zscnputc,
|
|
|
|
nullcnpollc,
|
|
|
|
};
|
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
/*
|
1996-01-25 01:39:48 +03:00
|
|
|
* Handle user request to enter kernel debugger.
|
1994-02-23 11:28:11 +03:00
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
void
|
|
|
|
zs_abort()
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1996-01-25 01:39:48 +03:00
|
|
|
register volatile struct zschan *zc = zs_conschan;
|
|
|
|
int rr0;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* Wait for end of break to avoid PROM abort. */
|
|
|
|
/* XXX - Limit the wait? */
|
1995-06-14 02:11:33 +04:00
|
|
|
do {
|
|
|
|
rr0 = zc->zc_csr;
|
|
|
|
ZS_DELAY();
|
1996-01-25 01:39:48 +03:00
|
|
|
} while (rr0 & ZSRR0_BREAK);
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
/* XXX - Always available, but may be the PROM monitor. */
|
|
|
|
Debugger();
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|