#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zs_pcctwo.c,v 1.15 2026/04/26 18:02:57 thorpej Exp $");
#define _M68K_BUS_SPACE_PRIVATE
#include <sys/param.h>
#include <sys/systm.h>
#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>
#include <dev/cons.h>
#include <dev/ic/z8530reg.h>
#include <machine/z8530var.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <dev/mvme/pcctworeg.h>
#include <dev/mvme/pcctwovar.h>
#include <mvme68k/dev/mainbus.h>
#include <mvme68k/dev/zsvar.h>
#include "ioconf.h"
static int zsc_pcctwo_match(device_t, cfdata_t, void *);
static void zsc_pcctwo_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(zsc_pcctwo, sizeof(struct zsc_softc),
zsc_pcctwo_match, zsc_pcctwo_attach, NULL, NULL);
cons_decl(zsc_pcctwo);
static int
zsc_pcctwo_match(device_t parent, cfdata_t cf, void *aux)
{
struct pcctwo_attach_args *pa = aux;
if (strcmp(pa->pa_name, zsc_cd.cd_name) ||
(machineid != MVME_162 && machineid != MVME_172))
return 0;
pa->pa_ipl = cf->pcctwocf_ipl;
if (pa->pa_ipl == -1)
pa->pa_ipl = ZSHARD_PRI;
return 1;
}
static void
zsc_pcctwo_attach(device_t parent, device_t self, void *aux)
{
struct zsc_softc *zsc = device_private(self);
struct pcctwo_attach_args *pa = aux;
struct zsdevice zs;
bus_space_handle_t bush;
int zs_level;
static int vector = MCCHIPV_ZS0;
zsc->zsc_dev = self;
bus_space_map(pa->pa_bust, pa->pa_offset, 8, 0, &bush);
zs_level = pa->pa_ipl;
zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush + 1;
zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 3;
zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 5;
zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 7;
zs_config(zsc, &zs, vector + PCCTWO_VECBASE, PCLK_162);
evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
pcctwointr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev));
pcctwointr_establish(vector++, zshard_unshared, zs_level, zsc, NULL);
zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
}
void
zsc_pcctwocnprobe(struct consdev *cp)
{
extern const struct cdevsw zstty_cdevsw;
if (machineid != MVME_162 && machineid != MVME_172) {
cp->cn_pri = CN_DEAD;
return;
}
cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
cp->cn_pri = CN_NORMAL;
}
void
zsc_pcctwocninit(struct consdev *cp)
{
bus_space_handle_t bush;
struct zsdevice zs;
bus_space_map(&m68k_simple_bus_space,
intiobase_phys + MAINBUS_PCCTWO_OFFSET + MCCHIP_ZS0_OFF, 8, 0,
&bush);
zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush + 1;
zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 3;
zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 5;
zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 7;
zs_cnconfig(0, 0, &zs, PCLK_162);
}