com_frodo.c revision 1.7.2.1 1 /* $NetBSD: com_frodo.c,v 1.7.2.1 2008/05/18 12:31:55 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*-
33 * Copyright (c) 1991 The Regents of the University of California.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)com.c 7.5 (Berkeley) 5/16/91
61 */
62
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: com_frodo.c,v 1.7.2.1 2008/05/18 12:31:55 yamt Exp $");
65
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/device.h>
69 #include <sys/termios.h>
70 #include <sys/ttydefaults.h>
71
72 #include <machine/bus.h>
73
74 #include <dev/ic/comreg.h>
75 #include <dev/ic/comvar.h>
76
77 #include <hp300/dev/intiovar.h>
78 #include <hp300/dev/frodoreg.h>
79 #include <hp300/dev/frodovar.h>
80 #include <hp300/dev/com_frodovar.h>
81
82 #include "ioconf.h"
83
84 struct com_frodo_softc {
85 struct com_softc sc_com; /* real "com" softc */
86 };
87
88 static int com_frodo_match(device_t, cfdata_t , void *);
89 static void com_frodo_attach(device_t, device_t, void *);
90
91 CFATTACH_DECL_NEW(com_frodo, sizeof(struct com_frodo_softc),
92 com_frodo_match, com_frodo_attach, NULL, NULL);
93
94 static int com_frodo_speed = TTYDEF_SPEED;
95 static struct bus_space_tag comcntag;
96
97 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
98 #define COM_FRODO_FREQ 8006400
99
100 static int
101 com_frodo_match(device_t parent, cfdata_t match, void *aux)
102 {
103 struct frodo_attach_args *fa = aux;
104
105 if (strcmp(fa->fa_name, com_cd.cd_name) != 0)
106 return 0;
107
108 switch (fa->fa_offset) {
109 case FRODO_APCI_OFFSET(1):
110 case FRODO_APCI_OFFSET(2):
111 case FRODO_APCI_OFFSET(3):
112 return 1;
113 }
114
115 return 0;
116 }
117
118 static void
119 com_frodo_attach(device_t parent, device_t self, void *aux)
120 {
121 struct com_frodo_softc *fsc = device_private(self);
122 struct com_softc *sc = &fsc->sc_com;
123 struct frodo_attach_args *fa = aux;
124 bus_space_tag_t iot;
125 bus_space_handle_t ioh;
126 int isconsole;
127
128 sc->sc_dev = self;
129 isconsole = com_is_console(&comcntag, fa->fa_base + fa->fa_offset,
130 &ioh);
131
132 if (isconsole)
133 iot = &comcntag;
134 else
135 iot = fa->fa_bst;
136
137 if (!isconsole &&
138 bus_space_map(iot, fa->fa_base + fa->fa_offset, COM_NPORTS << 2,
139 0, &ioh)) {
140 aprint_error(": can't map i/o space\n");
141 return;
142 }
143 COM_INIT_REGS(sc->sc_regs, iot, ioh, fa->fa_base + fa->fa_offset);
144
145 sc->sc_frequency = COM_FRODO_FREQ;
146 SET(sc->sc_hwflags, COM_HW_NOIEN);
147
148 com_attach_subr(sc);
149
150 frodo_intr_establish(parent, comintr, sc, fa->fa_line, IPL_VM);
151 }
152
153 int
154 com_frodo_cnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
155 {
156 bus_space_tag_t iot = &comcntag;
157 bus_space_handle_t ioh;
158
159 if (machineid != HP_425 || mmuid != MMUID_425_E)
160 return 1;
161
162 frodo_init_bus_space(iot);
163
164 if (bus_space_map(iot, addr, INTIO_DEVSIZE, BUS_SPACE_MAP_LINEAR, &ioh))
165 return 1;
166
167 comcnattach(iot, addr, com_frodo_speed, COM_FRODO_FREQ,
168 COM_TYPE_NORMAL, CONMODE);
169
170 return 0;
171 }
172