#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.21 2026/04/26 18:02:57 thorpej Exp $");
#ifdef __m68k__
#define _M68K_BUS_SPACE_PRIVATE
#endif
#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 <sys/cpu.h>
#include <sys/bus.h>
#include <sys/intr.h>
#include <dev/ic/clmpccvar.h>
#include <dev/mvme/pcctwovar.h>
#include <dev/mvme/pcctworeg.h>
#ifdef MVME68K
#include <mvme68k/dev/mainbus.h>
#define cons_space_tag m68k_simple_bus_space
#else
#error Need consiack hook
#endif
int clmpcc_pcctwo_match(device_t, cfdata_t, void *);
void clmpcc_pcctwo_attach(device_t, device_t, void *);
void clmpcc_pcctwo_iackhook(struct clmpcc_softc *, int);
void clmpcc_pcctwo_consiackhook(struct clmpcc_softc *, int);
CFATTACH_DECL_NEW(clmpcc_pcctwo, sizeof(struct clmpcc_softc),
clmpcc_pcctwo_match, clmpcc_pcctwo_attach, NULL, NULL);
extern struct cfdriver clmpcc_cd;
extern const struct cdevsw clmpcc_cdevsw;
cons_decl(clmpcc);
int
clmpcc_pcctwo_match(device_t parent, cfdata_t cf, void *aux)
{
struct pcctwo_attach_args *pa;
pa = aux;
if (strcmp(pa->pa_name, clmpcc_cd.cd_name))
return (0);
pa->pa_ipl = cf->pcctwocf_ipl;
return (1);
}
void
clmpcc_pcctwo_attach(device_t parent, device_t self, void *aux)
{
struct clmpcc_softc *sc;
struct pcctwo_attach_args *pa = aux;
int level = pa->pa_ipl;
sc = device_private(self);
sc->sc_dev = self;
level = pa->pa_ipl;
sc->sc_iot = pa->pa_bust;
bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh);
sc->sc_clk = 20000000;
sc->sc_byteswap = CLMPCC_BYTESWAP_LOW;
sc->sc_swaprtsdtr = 1;
sc->sc_iackhook = clmpcc_pcctwo_iackhook;
sc->sc_vector_base = PCCTWO_SCC_VECBASE;
sc->sc_rpilr = 0x03;
sc->sc_tpilr = 0x02;
sc->sc_mpilr = 0x01;
sc->sc_evcnt = pcctwointr_evcnt(level);
clmpcc_attach(sc);
pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL);
pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc,
NULL);
pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL);
pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL);
}
void
clmpcc_pcctwo_iackhook(struct clmpcc_softc *sc, int which)
{
bus_size_t offset;
volatile u_char foo;
switch (which) {
case CLMPCC_IACK_MODEM:
offset = PCC2REG_SCC_MODEM_PIACK;
break;
case CLMPCC_IACK_RX:
offset = PCC2REG_SCC_RX_PIACK;
break;
case CLMPCC_IACK_TX:
offset = PCC2REG_SCC_TX_PIACK;
break;
default:
#ifdef DEBUG
printf("%s: Invalid IACK number '%d'\n",
device_xname(sc->sc_dev), which);
#endif
panic("clmpcc_pcctwo_iackhook %d", which);
}
foo = pcc2_reg_read(sys_pcctwo, offset);
__USE(foo);
}
void
clmpcc_pcctwo_consiackhook(struct clmpcc_softc *sc, int which)
{
bus_space_handle_t bush;
bus_size_t offset;
volatile u_char foo;
switch (which) {
case CLMPCC_IACK_MODEM:
offset = PCC2REG_SCC_MODEM_PIACK;
break;
case CLMPCC_IACK_RX:
offset = PCC2REG_SCC_RX_PIACK;
break;
case CLMPCC_IACK_TX:
offset = PCC2REG_SCC_TX_PIACK;
break;
default:
#ifdef DEBUG
printf("%s: Invalid IACK number '%d'\n",
device_xname(sc->sc_dev), which);
panic("clmpcc_pcctwo_consiackhook");
#endif
panic("clmpcc_pcctwo_iackhook %d", which);
}
#ifdef MVME68K
bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
PCCTWO_REG_OFF]);
foo = bus_space_read_1(&cons_space_tag, bush, offset);
__USE(foo);
#else
#error Need consiack hook
#endif
}
void
clmpcccnprobe(struct consdev *cp)
{
int maj;
#if defined(MVME68K)
if (machineid != MVME_167 && machineid != MVME_177)
#elif defined(MVME88K)
if (machineid != MVME_187)
#endif
{
cp->cn_pri = CN_DEAD;
return;
}
maj = cdevsw_lookup_major(&clmpcc_cdevsw);
cp->cn_dev = makedev(maj, 0);
cp->cn_pri = CN_NORMAL;
}
void
clmpcccninit(struct consdev *cp)
{
static struct clmpcc_softc cons_sc;
cons_sc.sc_iot = &cons_space_tag;
bus_space_map(&cons_space_tag,
intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
cons_sc.sc_clk = 20000000;
cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
cons_sc.sc_swaprtsdtr = 1;
cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook;
cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE;
cons_sc.sc_rpilr = 0x03;
cons_sc.sc_tpilr = 0x02;
cons_sc.sc_mpilr = 0x01;
clmpcc_cnattach(&cons_sc, 0, 9600);
}