#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: gemini_com.c,v 1.4 2018/12/08 17:46:09 thorpej Exp $");
#include "opt_com.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/termios.h>
#include <machine/intr.h>
#include <sys/bus.h>
#include <arm/pic/picvar.h>
#include <dev/ic/comreg.h>
#include <dev/ic/comvar.h>
#include <arm/gemini/gemini_reg.h>
#include <arm/gemini/gemini_obiovar.h>
#include <arm/gemini/gemini_com.h>
#include "locators.h"
static int gemini_com_match(device_t, cfdata_t , void *);
static void gemini_com_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(gemini_com, sizeof(struct com_softc),
gemini_com_match, gemini_com_attach, NULL, NULL);
static int
gemini_com_match(device_t parent, cfdata_t cf, void *aux)
{
struct obio_attach_args *obio = aux;
bus_space_handle_t bh;
int rv;
if (obio->obio_addr == -1 || obio->obio_intr == -1)
panic("gemini_com must have addr and intr specified in config.");
if (obio->obio_size == 0)
obio->obio_size = GEMINI_UART_SIZE;
if (com_is_console(obio->obio_iot, obio->obio_addr, NULL))
return (1);
if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size,
0, &bh))
return (0);
rv = comprobe1(obio->obio_iot, bh);
bus_space_unmap(obio->obio_iot, bh, obio->obio_size);
return (rv);
}
static void
gemini_com_attach(device_t parent, device_t self, void *aux)
{
struct com_softc *sc = device_private(self);
struct obio_attach_args *obio = aux;
bus_space_tag_t iot;
bus_space_handle_t ioh;
bus_addr_t iobase;
sc->sc_dev = self;
iot = obio->obio_iot;
iobase = obio->obio_addr;
sc->sc_frequency = GEMINI_COM_FREQ;
sc->sc_type = COM_TYPE_16550_NOERS;
if (com_is_console(iot, iobase, &ioh) == 0 &&
bus_space_map(iot, iobase, obio->obio_size, 0, &ioh)) {
panic(": can't map registers\n");
return;
}
com_init_regs(&sc->sc_regs, iot, ioh, iobase);
com_attach_subr(sc);
aprint_naive("\n");
intr_establish(obio->obio_intr, IPL_SERIAL, IST_LEVEL_HIGH,
comintr, sc);
}