com_mainbus.c revision 1.1.4.2 1 1.1.4.2 thorpej /* $NetBSD: com_mainbus.c,v 1.1.4.2 2021/04/03 22:28:23 thorpej Exp $ */
2 1.1.4.2 thorpej
3 1.1.4.2 thorpej /*-
4 1.1.4.2 thorpej * Copyright (c) 2001, 2021 The NetBSD Foundation, Inc.
5 1.1.4.2 thorpej * All rights reserved.
6 1.1.4.2 thorpej *
7 1.1.4.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 thorpej * by Jason R. Thorpe and Simon Burge.
9 1.1.4.2 thorpej *
10 1.1.4.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 thorpej * modification, are permitted provided that the following conditions
12 1.1.4.2 thorpej * are met:
13 1.1.4.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.1.4.2 thorpej *
19 1.1.4.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.4.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.4.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.4.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.4.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.4.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.4.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.4.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.4.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.4.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.4.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1.4.2 thorpej */
31 1.1.4.2 thorpej
32 1.1.4.2 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 1.1.4.2 thorpej
34 1.1.4.2 thorpej __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.1.4.2 2021/04/03 22:28:23 thorpej Exp $");
35 1.1.4.2 thorpej
36 1.1.4.2 thorpej #include <sys/param.h>
37 1.1.4.2 thorpej #include <sys/bus.h>
38 1.1.4.2 thorpej #include <sys/conf.h>
39 1.1.4.2 thorpej #include <sys/device.h>
40 1.1.4.2 thorpej #include <sys/file.h>
41 1.1.4.2 thorpej #include <sys/tty.h>
42 1.1.4.2 thorpej
43 1.1.4.2 thorpej #include <evbmips/mipssim/autoconf.h>
44 1.1.4.2 thorpej
45 1.1.4.2 thorpej #include <dev/ic/comreg.h>
46 1.1.4.2 thorpej #include <dev/ic/comvar.h>
47 1.1.4.2 thorpej
48 1.1.4.2 thorpej struct com_mainbus_softc {
49 1.1.4.2 thorpej struct com_softc sc_com; /* real "com" softc */
50 1.1.4.2 thorpej
51 1.1.4.2 thorpej /* mainbus-specific goo. */
52 1.1.4.2 thorpej void *sc_ih; /* interrupt handler */
53 1.1.4.2 thorpej };
54 1.1.4.2 thorpej
55 1.1.4.2 thorpej static int com_mainbus_match(device_t, cfdata_t , void *);
56 1.1.4.2 thorpej static void com_mainbus_attach(device_t, device_t, void *);
57 1.1.4.2 thorpej
58 1.1.4.2 thorpej CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
59 1.1.4.2 thorpej com_mainbus_match, com_mainbus_attach, NULL, NULL);
60 1.1.4.2 thorpej
61 1.1.4.2 thorpej int
62 1.1.4.2 thorpej com_mainbus_match(device_t parent, cfdata_t match, void *aux)
63 1.1.4.2 thorpej {
64 1.1.4.2 thorpej struct mainbus_attach_args *ma = aux;
65 1.1.4.2 thorpej
66 1.1.4.2 thorpej /* Always present. */
67 1.1.4.2 thorpej if (strcmp(ma->ma_name, match->cf_name) == 0)
68 1.1.4.2 thorpej return (1);
69 1.1.4.2 thorpej
70 1.1.4.2 thorpej return (0);
71 1.1.4.2 thorpej }
72 1.1.4.2 thorpej
73 1.1.4.2 thorpej void
74 1.1.4.2 thorpej com_mainbus_attach(device_t parent, device_t self, void *aux)
75 1.1.4.2 thorpej {
76 1.1.4.2 thorpej struct com_mainbus_softc *msc = device_private(self);
77 1.1.4.2 thorpej struct com_softc *sc = &msc->sc_com;
78 1.1.4.2 thorpej struct mainbus_attach_args *ma = aux;
79 1.1.4.2 thorpej bus_space_handle_t ioh;
80 1.1.4.2 thorpej
81 1.1.4.2 thorpej sc->sc_dev = self;
82 1.1.4.2 thorpej if (com_is_console(ma->ma_iot, ma->ma_addr, &ioh) == 0 &&
83 1.1.4.2 thorpej bus_space_map(ma->ma_iot, ma->ma_addr, COM_NPORTS, 0, &ioh) != 0) {
84 1.1.4.2 thorpej aprint_error(": can't map i/o space\n");
85 1.1.4.2 thorpej return;
86 1.1.4.2 thorpej }
87 1.1.4.2 thorpej com_init_regs(&sc->sc_regs, ma->ma_iot, ioh, ma->ma_addr);
88 1.1.4.2 thorpej sc->sc_frequency = COM_FREQ;
89 1.1.4.2 thorpej
90 1.1.4.2 thorpej com_attach_subr(sc);
91 1.1.4.2 thorpej
92 1.1.4.2 thorpej msc->sc_ih = evbmips_intr_establish(ma->ma_irq, comintr, sc);
93 1.1.4.2 thorpej if (msc->sc_ih == NULL) {
94 1.1.4.2 thorpej aprint_error_dev(self, "unable to establish interrupt\n");
95 1.1.4.2 thorpej return;
96 1.1.4.2 thorpej }
97 1.1.4.2 thorpej }
98