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