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