1*6d487047Sthorpej /* $NetBSD: com_cpcbus.c,v 1.12 2018/12/08 17:46:13 thorpej Exp $ */
254bb400aSaugustss
354bb400aSaugustss /*
454bb400aSaugustss * Copyright (c) 2002 The NetBSD Foundation, Inc.
554bb400aSaugustss * All rights reserved.
654bb400aSaugustss *
754bb400aSaugustss * This code is derived from software contributed to The NetBSD Foundation
854bb400aSaugustss * by Lennart Augustsson (lennart@augustsson.net) at Sandburst Corp.
954bb400aSaugustss *
1054bb400aSaugustss * Redistribution and use in source and binary forms, with or without
1154bb400aSaugustss * modification, are permitted provided that the following conditions
1254bb400aSaugustss * are met:
1354bb400aSaugustss * 1. Redistributions of source code must retain the above copyright
1454bb400aSaugustss * notice, this list of conditions and the following disclaimer.
1554bb400aSaugustss * 2. Redistributions in binary form must reproduce the above copyright
1654bb400aSaugustss * notice, this list of conditions and the following disclaimer in the
1754bb400aSaugustss * documentation and/or other materials provided with the distribution.
1854bb400aSaugustss *
1954bb400aSaugustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2054bb400aSaugustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2154bb400aSaugustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2254bb400aSaugustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2354bb400aSaugustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2454bb400aSaugustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2554bb400aSaugustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2654bb400aSaugustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2754bb400aSaugustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2854bb400aSaugustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2954bb400aSaugustss * POSSIBILITY OF SUCH DAMAGE.
3054bb400aSaugustss */
3154bb400aSaugustss
32365cbd94Slukem #include <sys/cdefs.h>
33*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_cpcbus.c,v 1.12 2018/12/08 17:46:13 thorpej Exp $");
34365cbd94Slukem
3554bb400aSaugustss #include <sys/param.h>
3654bb400aSaugustss #include <sys/device.h>
3754bb400aSaugustss #include <sys/tty.h>
3854bb400aSaugustss #include <sys/systm.h>
3954bb400aSaugustss
40a2a38285Sad #include <sys/bus.h>
4154bb400aSaugustss
4254bb400aSaugustss #include <dev/ic/cpc700reg.h>
4354bb400aSaugustss #include <dev/ic/cpc700var.h>
4454bb400aSaugustss
4554bb400aSaugustss #include <dev/ic/comreg.h>
4654bb400aSaugustss #include <dev/ic/comvar.h>
4754bb400aSaugustss
4854bb400aSaugustss struct com_cpc_softc {
4954bb400aSaugustss struct com_softc sc_com;
5054bb400aSaugustss void *sc_ih;
5154bb400aSaugustss };
5254bb400aSaugustss
53607ead0eScube static int com_cpc_match(device_t, cfdata_t , void *);
54607ead0eScube static void com_cpc_attach(device_t, device_t, void *);
5554bb400aSaugustss
56607ead0eScube CFATTACH_DECL_NEW(com_cpcbus, sizeof(struct com_cpc_softc),
57c9b3657cSthorpej com_cpc_match, com_cpc_attach, NULL, NULL);
5854bb400aSaugustss
5954bb400aSaugustss int
com_cpc_match(device_t parent,cfdata_t cf,void * aux)60607ead0eScube com_cpc_match(device_t parent, cfdata_t cf, void *aux)
6154bb400aSaugustss {
6254bb400aSaugustss struct cpcbus_attach_args *caa = aux;
6354bb400aSaugustss
6454bb400aSaugustss return (strcmp(caa->cpca_name, "com") == 0);
6554bb400aSaugustss }
6654bb400aSaugustss
6754bb400aSaugustss void
com_cpc_attach(device_t parent,device_t self,void * aux)68607ead0eScube com_cpc_attach(device_t parent, device_t self, void *aux)
6954bb400aSaugustss {
7054bb400aSaugustss struct cpcbus_attach_args *caa = aux;
71607ead0eScube struct com_cpc_softc *sc = device_private(self);
7254bb400aSaugustss int iobase = caa->cpca_addr;
7354bb400aSaugustss int irq = caa->cpca_irq;
7434537908Sgdamore bus_space_handle_t ioh;
7554bb400aSaugustss
76607ead0eScube sc->sc_com.sc_dev = self;
77607ead0eScube
7834537908Sgdamore if (!com_is_console(caa->cpca_tag, iobase, &ioh) &&
7934537908Sgdamore bus_space_map(caa->cpca_tag, iobase, COM_NPORTS, 0, &ioh)) {
80607ead0eScube aprint_error_dev(self, "can't map i/o space\n");
8154bb400aSaugustss return;
8254bb400aSaugustss }
83*6d487047Sthorpej com_init_regs(&sc->sc_com.sc_regs, caa->cpca_tag, ioh, iobase);
8454bb400aSaugustss
8554bb400aSaugustss sc->sc_com.sc_frequency = CPC_COM_SPEED(caa->cpca_freq);
8654bb400aSaugustss
8754bb400aSaugustss com_attach_subr(&sc->sc_com);
8854bb400aSaugustss
8954bb400aSaugustss sc->sc_ih = intr_establish(irq, IST_LEVEL, IPL_SERIAL, comintr,
9054bb400aSaugustss &sc->sc_com);
9154bb400aSaugustss }
92