/*-
* Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Gordon W. Ross, Ken Hornstein, and by Jason R. Thorpe of the
* Numerical Aerospace Simulation Facility, NASA Ames Research Center.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Zilog Z8530 Dual UART driver (machine-dependent part). This driver
* handles Z8530 chips attached to the DECstation/Alpha IOASIC. Modified
* for NetBSD/alpha by Ken Hornstein and Jason R. Thorpe. NetBSD/pmax
* adaption by Mattias Drochner. Merge work by Tohru Nishimura.
*
* Runs two serial lines per chip using slave drivers.
* Plain tty/async lines use the zstty slave.
*/
/*
* Is the zs chip present?
*/
static int
zs_ioasic_match(device_t parent, cfdata_t cf, void *aux)
{
struct ioasicdev_attach_args *d = aux;
tc_addr_t zs_addr;
/*
* Make sure that we're looking for the right kind of device.
*/
if (strncmp(d->iada_modname, "z8530 ", TC_ROM_LLEN) != 0 &&
strncmp(d->iada_modname, "scc", TC_ROM_LLEN) != 0)
return (0);
/*
* Find out the device address, and check it for validity.
*/
zs_addr = TC_DENSE_TO_SPARSE((tc_addr_t)d->iada_addr);
if (tc_badaddr(zs_addr))
return (0);
/*
* DCD and CTS interrupts are only meaningful on
* SCC 0/B, and RTS and DTR only on B of SCC 0 & 1.
*
* XXX This is sorta gross.
*/
if (d->iada_offset == 0x00100000 && channel == 1) {
cs->cs_creg[15] |= ZSWR15_DCD_IE;
cs->cs_preg[15] |= ZSWR15_DCD_IE;
zflg = ZIP_FLAGS_DCDCTS;
} else
zflg = 0;
if (channel == 1)
zflg |= ZIP_FLAGS_DTRRTS;
cs->cs_private = (void *)zflg;
/*
* Clear the master interrupt enable.
* The INTENA is common to both channels,
* so just do it on the A channel.
*/
if (channel == 0) {
zs_write_reg(cs, 9, 0);
}
/*
* Set up the flow/modem control channel pointer to
* deal with the weird wiring on the TC Alpha and
* DECstation.
*/
if (channel == 1)
cs->cs_ctl_chan = zs->zsc_cs[0];
else
cs->cs_ctl_chan = NULL;
locs[ZSCCF_CHANNEL] = channel;
/*
* Look for a child driver for this channel.
* The child attach will setup the hardware.
*/
if (config_found(self, (void *)&zs_args, zs_ioasic_print,
CFARGS(.submatch = zs_ioasic_submatch,
.locators = locs)) == NULL) {
/* No sub-driver. Just reset it. */
uint8_t reset = (channel == 0) ?
ZSWR9_A_RESET : ZSWR9_B_RESET;
s = splhigh();
zs_write_reg(cs, 9, reset);
splx(s);
}
}
/*
* Set up the ioasic interrupt handler.
*/
ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_TTY,
zs_ioasic_hardintr, zs);
zs->zsc_sih = softint_establish(SOFTINT_SERIAL,
zs_ioasic_softintr, zs);
if (zs->zsc_sih == NULL)
panic("%s: unable to register softintr", __func__);
/*
* Set the master interrupt enable and interrupt vector. The
* Sun does this only on one channel. The old Alpha SCC driver
* did it on both. We'll do it on both.
*/
s = splhigh();
/* interrupt vector */
zs_write_reg(zs->zsc_cs[0], 2, zs_ioasic_init_reg[2]);
zs_write_reg(zs->zsc_cs[1], 2, zs_ioasic_init_reg[2]);
/*
* Call the upper-level MI hardware interrupt handler.
*/
zsc_intr_hard(zsc);
/*
* Check to see if we need to schedule any software-level
* processing interrupts.
*/
if (zsc->zsc_cs[0]->cs_softreq | zsc->zsc_cs[1]->cs_softreq)
softint_schedule(zsc->zsc_sih);
s = spltty();
(void)zsc_intr_soft(zsc);
splx(s);
}
/*
* MD functions for setting the baud rate and control modes.
*/
int
zs_set_speed(struct zs_chanstate *cs, int bps /*bits per second*/)
{
int tconst, real_bps;
if (bps == 0)
return (0);
#ifdef DIAGNOSTIC
if (cs->cs_brg_clk == 0)
panic("zs_set_speed");
#endif
tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
if (tconst < 0)
return (EINVAL);
/* Convert back to make sure we can do it. */
real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
/* XXX - Allow some tolerance here? */
if (real_bps != bps)
return (EINVAL);
/* Caller will stuff the pending registers. */
return (0);
}
/*
* Functions to read and write individual registers in a channel.
* The ZS chip requires a 1.6 uSec. recovery time between accesses,
* and the Alpha TC hardware does NOT take care of this for you.
* The delay is now handled inside the chip access functions.
* These could be inlines, but with the delay, speed is moot.
*/
#if defined(pmax)
#undef DELAY
#define DELAY(x)
#endif
/*
* zs_ioasic_cninit --
* Initialize the serial channel for either a keyboard or
* a serial console.
*/
static void
zs_ioasic_cninit(tc_addr_t ioasic_addr, tc_offset_t zs_offset, int channel)
{
struct zs_chanstate *cs;
tc_addr_t zs_addr;
struct zshan *zc;
u_long zflg;
/*
* Initialize the console finder helpers.
*/
zs_ioasic_console_offset = zs_offset;
zs_ioasic_console_channel = channel;
zs_ioasic_console = 1;
/*
* Pointer to channel state.
*/
cs = &zs_ioasic_conschanstate_store;
/*
* Compute the physical address of the chip, "map" it via
* K0SEG, and then get the address of the actual channel.
*/
#if defined(__alpha__)
zs_addr = ALPHA_PHYS_TO_K0SEG(ioasic_addr + zs_offset);
#endif
#if defined(pmax)
zs_addr = MIPS_PHYS_TO_KSEG1(ioasic_addr + zs_offset);
#endif
zc = zs_ioasic_get_chan_addr(zs_addr, channel);
/*
* DCD and CTS interrupts are only meaningful on
* SCC 0/B, and RTS and DTR only on B of SCC 0 & 1.
*
* XXX This is sorta gross.
*/
if (zs_offset == 0x00100000 && channel == 1)
zflg = ZIP_FLAGS_DCDCTS;
else
zflg = 0;
if (channel == 1)
zflg |= ZIP_FLAGS_DTRRTS;
cs->cs_private = (void *)zflg;
/* Clear the master interrupt enable. */
zs_write_reg(cs, 9, 0);
/* Reset the whole SCC chip. */
zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
/* Copy "pending" to "current" and H/W. */
zs_loadchannelregs(cs);
}
/*
* zs_ioasic_cnattach --
* Initialize and attach a serial console.
*/
void
zs_ioasic_cnattach(tc_addr_t ioasic_addr, tc_offset_t zs_offset, int channel)
{
struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
extern const struct cdevsw zstty_cdevsw;