1*6d487047Sthorpej /* $NetBSD: com_mainbus.c,v 1.15 2018/12/08 17:46:09 thorpej Exp $ */
271cb790fSthorpej
371cb790fSthorpej /*-
471cb790fSthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
571cb790fSthorpej * All rights reserved.
671cb790fSthorpej *
771cb790fSthorpej * This code is derived from software contributed to The NetBSD Foundation
871cb790fSthorpej * by Jason R. Thorpe.
971cb790fSthorpej *
1071cb790fSthorpej * Redistribution and use in source and binary forms, with or without
1171cb790fSthorpej * modification, are permitted provided that the following conditions
1271cb790fSthorpej * are met:
1371cb790fSthorpej * 1. Redistributions of source code must retain the above copyright
1471cb790fSthorpej * notice, this list of conditions and the following disclaimer.
1571cb790fSthorpej * 2. Redistributions in binary form must reproduce the above copyright
1671cb790fSthorpej * notice, this list of conditions and the following disclaimer in the
1771cb790fSthorpej * documentation and/or other materials provided with the distribution.
1871cb790fSthorpej *
1971cb790fSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2071cb790fSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2171cb790fSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2271cb790fSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2371cb790fSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471cb790fSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571cb790fSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671cb790fSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771cb790fSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871cb790fSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971cb790fSthorpej * POSSIBILITY OF SUCH DAMAGE.
3071cb790fSthorpej */
3171cb790fSthorpej
3271cb790fSthorpej #include "opt_algor_p4032.h"
3371cb790fSthorpej
3471cb790fSthorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
3571cb790fSthorpej
36*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.15 2018/12/08 17:46:09 thorpej Exp $");
3771cb790fSthorpej
3871cb790fSthorpej #include <sys/param.h>
39391925c7Sdyoung #include <sys/bus.h>
40f5439ed7Smatt #include <sys/conf.h>
41f5439ed7Smatt #include <sys/device.h>
42f5439ed7Smatt #include <sys/file.h>
43f5439ed7Smatt #include <sys/intr.h>
44f5439ed7Smatt #include <sys/ioctl.h>
45f5439ed7Smatt #include <sys/kernel.h>
46f5439ed7Smatt #include <sys/proc.h>
47f5439ed7Smatt #include <sys/select.h>
48f5439ed7Smatt #include <sys/syslog.h>
49f5439ed7Smatt #include <sys/systm.h>
50f5439ed7Smatt #include <sys/tty.h>
51f5439ed7Smatt #include <sys/uio.h>
52f5439ed7Smatt
53f5439ed7Smatt #include <algor/autoconf.h>
5471cb790fSthorpej
5571cb790fSthorpej #include <dev/ic/comreg.h>
5671cb790fSthorpej #include <dev/ic/comvar.h>
5771cb790fSthorpej
5871cb790fSthorpej struct com_mainbus_softc {
5971cb790fSthorpej struct com_softc sc_com; /* real "com" softc */
6071cb790fSthorpej
6171cb790fSthorpej /* mainbus-specific goo. */
6271cb790fSthorpej void *sc_ih; /* interrupt handler */
6371cb790fSthorpej };
6471cb790fSthorpej
65f5439ed7Smatt static int com_mainbus_match(device_t, cfdata_t , void *);
66f5439ed7Smatt static void com_mainbus_attach(device_t, device_t, void *);
6771cb790fSthorpej
68607ead0eScube CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
695a9ddc14Sthorpej com_mainbus_match, com_mainbus_attach, NULL, NULL);
7071cb790fSthorpej
7171cb790fSthorpej int
com_mainbus_match(device_t parent,cfdata_t match,void * aux)72607ead0eScube com_mainbus_match(device_t parent, cfdata_t match, void *aux)
7371cb790fSthorpej {
7471cb790fSthorpej struct mainbus_attach_args *ma = aux;
7571cb790fSthorpej
7671cb790fSthorpej /* Always present. */
77d1ad2ac4Sthorpej if (strcmp(ma->ma_name, match->cf_name) == 0)
7871cb790fSthorpej return (1);
7971cb790fSthorpej
8071cb790fSthorpej return (0);
8171cb790fSthorpej }
8271cb790fSthorpej
8371cb790fSthorpej void
com_mainbus_attach(device_t parent,device_t self,void * aux)84607ead0eScube com_mainbus_attach(device_t parent, device_t self, void *aux)
8571cb790fSthorpej {
86607ead0eScube struct com_mainbus_softc *msc = device_private(self);
8771cb790fSthorpej struct com_softc *sc = &msc->sc_com;
8871cb790fSthorpej struct mainbus_attach_args *ma = aux;
8934537908Sgdamore bus_space_handle_t ioh;
9071cb790fSthorpej
91607ead0eScube sc->sc_dev = self;
9234537908Sgdamore if (com_is_console(ma->ma_st, ma->ma_addr, &ioh) == 0 &&
9334537908Sgdamore bus_space_map(ma->ma_st, ma->ma_addr, COM_NPORTS, 0, &ioh) != 0) {
94607ead0eScube aprint_error(": can't map i/o space\n");
9571cb790fSthorpej return;
9671cb790fSthorpej }
97*6d487047Sthorpej com_init_regs(&sc->sc_regs, ma->ma_st, ioh, ma->ma_addr);
9871cb790fSthorpej sc->sc_frequency = COM_FREQ;
9971cb790fSthorpej
10071cb790fSthorpej com_attach_subr(sc);
10171cb790fSthorpej
102e51a0439Sthorpej msc->sc_ih = (*algor_intr_establish)(ma->ma_irq, comintr, sc);
10371cb790fSthorpej if (msc->sc_ih == NULL) {
104607ead0eScube aprint_error_dev(self, "unable to establish interrupt\n");
10571cb790fSthorpej return;
10671cb790fSthorpej }
10771cb790fSthorpej
108e4f38925Sdyoung if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
109607ead0eScube aprint_error_dev(self, "could not establish shutdown hook");
110e4f38925Sdyoung }
111e4f38925Sdyoung
11271cb790fSthorpej }
113