1 /* $NetBSD: com_mainbus.c,v 1.22 2018/12/08 17:46:10 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.22 2018/12/08 17:46:10 thorpej Exp $");
30
31 #include <sys/param.h>
32 #include <sys/bus.h>
33 #include <sys/cpu.h>
34 #include <sys/device.h>
35 #include <sys/intr.h>
36 #include <sys/systm.h>
37 #include <sys/termios.h>
38
39 #include <machine/autoconf.h>
40
41 #include <dev/ic/comreg.h>
42 #include <dev/ic/comvar.h>
43
44 #include <cobalt/cobalt/console.h>
45 #include <cobalt/dev/com_mainbusvar.h>
46
47 struct com_mainbus_softc {
48 struct com_softc sc_com;
49 void *sc_ih;
50 };
51
52 #define COM_MAINBUS_FREQ (COM_FREQ * 10)
53 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
54
55 static int com_mainbus_probe(device_t, cfdata_t , void *);
56 static void com_mainbus_attach(device_t, device_t, void *);
57
58 CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
59 com_mainbus_probe, com_mainbus_attach, NULL, NULL);
60
61 int
com_mainbus_probe(device_t parent,cfdata_t match,void * aux)62 com_mainbus_probe(device_t parent, cfdata_t match, void *aux)
63 {
64
65 switch (cobalt_id) {
66 case COBALT_ID_RAQ:
67 case COBALT_ID_QUBE2:
68 case COBALT_ID_RAQ2:
69 return 1;
70 }
71
72 return 0;
73 }
74
75 void
com_mainbus_attach(device_t parent,device_t self,void * aux)76 com_mainbus_attach(device_t parent, device_t self, void *aux)
77 {
78 struct com_mainbus_softc *msc = device_private(self);
79 struct com_softc *sc = &msc->sc_com;
80 struct mainbus_attach_args *maa = aux;
81 bus_space_handle_t ioh;
82
83 sc->sc_dev = self;
84 if (!com_is_console(maa->ma_iot, maa->ma_addr, &ioh) &&
85 bus_space_map(maa->ma_iot, maa->ma_addr, COM_NPORTS, 0, &ioh)) {
86 aprint_error(": can't map i/o space\n");
87 return;
88 }
89 com_init_regs(&sc->sc_regs, maa->ma_iot, ioh, maa->ma_addr);
90
91 sc->sc_frequency = COM_MAINBUS_FREQ;
92
93 com_attach_subr(sc);
94
95 cpu_intr_establish(maa->ma_level, IPL_SERIAL, comintr, sc);
96
97 return;
98 }
99
100 void
com_mainbus_cnprobe(struct consdev * cn)101 com_mainbus_cnprobe(struct consdev *cn)
102 {
103
104 cn->cn_pri = (console_present != 0 && cobalt_id != COBALT_ID_QUBE2700)
105 ? CN_NORMAL : CN_DEAD;
106 }
107
108 extern struct mips_bus_space cobalt_bs;
109
110 void
com_mainbus_cninit(struct consdev * cn)111 com_mainbus_cninit(struct consdev *cn)
112 {
113
114 comcnattach(&cobalt_bs, COM_BASE, 115200, COM_MAINBUS_FREQ, COM_TYPE_NORMAL,
115 CONMODE);
116 }
117