com_obio.c revision 1.15 1 1.15 lukem /* $NetBSD: com_obio.c,v 1.15 2003/07/15 00:04:53 lukem Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Charles M. Hannum.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt * 3. All advertising materials mentioning features or use of this software
19 1.1 matt * must display the following acknowledgement:
20 1.1 matt * This product includes software developed by the NetBSD
21 1.1 matt * Foundation, Inc. and its contributors.
22 1.1 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 matt * contributors may be used to endorse or promote products derived
24 1.1 matt * from this software without specific prior written permission.
25 1.1 matt *
26 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
37 1.1 matt */
38 1.1 matt
39 1.1 matt /*-
40 1.1 matt * Copyright (c) 1991 The Regents of the University of California.
41 1.1 matt * All rights reserved.
42 1.1 matt *
43 1.1 matt * Redistribution and use in source and binary forms, with or without
44 1.1 matt * modification, are permitted provided that the following conditions
45 1.1 matt * are met:
46 1.1 matt * 1. Redistributions of source code must retain the above copyright
47 1.1 matt * notice, this list of conditions and the following disclaimer.
48 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 matt * notice, this list of conditions and the following disclaimer in the
50 1.1 matt * documentation and/or other materials provided with the distribution.
51 1.1 matt * 3. All advertising materials mentioning features or use of this software
52 1.1 matt * must display the following acknowledgement:
53 1.1 matt * This product includes software developed by the University of
54 1.1 matt * California, Berkeley and its contributors.
55 1.1 matt * 4. Neither the name of the University nor the names of its contributors
56 1.1 matt * may be used to endorse or promote products derived from this software
57 1.1 matt * without specific prior written permission.
58 1.1 matt *
59 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 matt * SUCH DAMAGE.
70 1.1 matt *
71 1.1 matt * @(#)com.c 7.5 (Berkeley) 5/16/91
72 1.1 matt */
73 1.15 lukem
74 1.15 lukem #include <sys/cdefs.h>
75 1.15 lukem __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.15 2003/07/15 00:04:53 lukem Exp $");
76 1.1 matt
77 1.1 matt #include <sys/param.h>
78 1.1 matt #include <sys/systm.h>
79 1.1 matt #include <sys/ioctl.h>
80 1.1 matt #include <sys/select.h>
81 1.1 matt #include <sys/tty.h>
82 1.1 matt #include <sys/proc.h>
83 1.1 matt #include <sys/user.h>
84 1.1 matt #include <sys/conf.h>
85 1.1 matt #include <sys/file.h>
86 1.1 matt #include <sys/uio.h>
87 1.1 matt #include <sys/kernel.h>
88 1.1 matt #include <sys/syslog.h>
89 1.1 matt #include <sys/types.h>
90 1.1 matt #include <sys/device.h>
91 1.8 uwe #include <sys/termios.h>
92 1.1 matt
93 1.6 pk #include <machine/bus.h>
94 1.1 matt #include <machine/autoconf.h>
95 1.6 pk #include <machine/intr.h>
96 1.1 matt
97 1.1 matt #include <dev/ic/comreg.h>
98 1.1 matt #include <dev/ic/comvar.h>
99 1.1 matt
100 1.3 matt #include <sparc/sparc/auxreg.h>
101 1.3 matt
102 1.1 matt struct com_obio_softc {
103 1.1 matt struct com_softc osc_com; /* real "com" softc */
104 1.1 matt
105 1.7 matt int osc_tadpole; /* is this on a tadpole */
106 1.1 matt /* OBIO-specific goo. */
107 1.1 matt struct evcnt osc_intrcnt; /* interrupt counting */
108 1.1 matt };
109 1.1 matt
110 1.1 matt static int com_obio_match __P((struct device *, struct cfdata *, void *));
111 1.1 matt static void com_obio_attach __P((struct device *, struct device *, void *));
112 1.1 matt static void com_obio_cleanup __P((void *));
113 1.1 matt
114 1.11 thorpej CFATTACH_DECL(com_obio, sizeof(struct com_obio_softc),
115 1.12 thorpej com_obio_match, com_obio_attach, NULL, NULL);
116 1.1 matt
117 1.1 matt static int
118 1.1 matt com_obio_match(parent, cf, aux)
119 1.1 matt struct device *parent;
120 1.1 matt struct cfdata *cf;
121 1.1 matt void *aux;
122 1.1 matt {
123 1.1 matt union obio_attach_args *uoba = aux;
124 1.1 matt struct sbus_attach_args *sa = &uoba->uoba_sbus;
125 1.7 matt int tadpole = 0;
126 1.7 matt int need_probe = 0;
127 1.7 matt int rv = 0;
128 1.7 matt u_int8_t auxregval;
129 1.1 matt
130 1.1 matt if (uoba->uoba_isobio4 != 0) {
131 1.1 matt return (0);
132 1.1 matt }
133 1.1 matt
134 1.1 matt /* Tadpole 3GX/3GS uses "modem" for a 16450 port
135 1.7 matt * (We need to enable it before probing)
136 1.1 matt */
137 1.1 matt if (strcmp("modem", sa->sa_name) == 0) {
138 1.7 matt auxregval = *AUXIO4M_REG;
139 1.7 matt *AUXIO4M_REG = auxregval | (AUXIO4M_LED|AUXIO4M_LTE);
140 1.7 matt DELAY(100);
141 1.7 matt tadpole = 1;
142 1.7 matt need_probe = 1;
143 1.7 matt }
144 1.7 matt
145 1.7 matt /* Sun JavaStation 1 uses "su" for a 16550 port
146 1.7 matt */
147 1.7 matt if (strcmp("su", sa->sa_name) == 0) {
148 1.7 matt need_probe = 1;
149 1.7 matt }
150 1.7 matt
151 1.7 matt if (need_probe) {
152 1.2 matt bus_space_handle_t ioh;
153 1.7 matt
154 1.9 pk if (sbus_bus_map(sa->sa_bustag,
155 1.9 pk sa->sa_slot, sa->sa_offset, sa->sa_size,
156 1.9 pk BUS_SPACE_MAP_LINEAR, &ioh) == 0) {
157 1.2 matt rv = comprobe1(sa->sa_bustag, ioh);
158 1.3 matt #if 0
159 1.3 matt printf("modem: probe: lcr=0x%02x iir=0x%02x\n",
160 1.3 matt bus_space_read_1(sa->sa_bustag, ioh, 3),
161 1.3 matt bus_space_read_1(sa->sa_bustag, ioh, 2));
162 1.3 matt #endif
163 1.3 matt bus_space_unmap(sa->sa_bustag, ioh, sa->sa_size);
164 1.2 matt }
165 1.7 matt }
166 1.7 matt
167 1.7 matt /* Disable the com port if tadpole */
168 1.7 matt if (tadpole)
169 1.3 matt *AUXIO4M_REG = auxregval;
170 1.7 matt
171 1.7 matt return (rv);
172 1.1 matt }
173 1.1 matt
174 1.1 matt static void
175 1.1 matt com_obio_attach(parent, self, aux)
176 1.1 matt struct device *parent, *self;
177 1.1 matt void *aux;
178 1.1 matt {
179 1.1 matt struct com_obio_softc *osc = (void *)self;
180 1.1 matt struct com_softc *sc = &osc->osc_com;
181 1.1 matt union obio_attach_args *uoba = aux;
182 1.1 matt struct sbus_attach_args *sa = &uoba->uoba_sbus;
183 1.1 matt
184 1.7 matt if (strcmp("modem", sa->sa_name) == 0) {
185 1.7 matt osc->osc_tadpole = 1;
186 1.7 matt }
187 1.7 matt
188 1.1 matt /*
189 1.3 matt * We're living on an obio that looks like an sbus slot.
190 1.1 matt */
191 1.1 matt sc->sc_iot = sa->sa_bustag;
192 1.1 matt sc->sc_iobase = sa->sa_offset;
193 1.8 uwe sc->sc_frequency = COM_FREQ;
194 1.8 uwe
195 1.8 uwe /*
196 1.8 uwe * XXX: It would be nice to be able to split console input and
197 1.8 uwe * output to different devices. For now switch to serial
198 1.8 uwe * console if PROM stdin is on serial (so that we can use DDB).
199 1.8 uwe */
200 1.8 uwe if (prom_instance_to_package(prom_stdin()) == sa->sa_node)
201 1.8 uwe comcnattach(sc->sc_iot, sc->sc_iobase,
202 1.14 thorpej B9600, sc->sc_frequency, COM_TYPE_NORMAL,
203 1.14 thorpej (CLOCAL | CREAD | CS8));
204 1.8 uwe
205 1.1 matt if (!com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) &&
206 1.9 pk sbus_bus_map(sc->sc_iot,
207 1.9 pk sa->sa_slot, sc->sc_iobase, sa->sa_size,
208 1.9 pk BUS_SPACE_MAP_LINEAR, &sc->sc_ioh) != 0) {
209 1.1 matt printf(": can't map registers\n");
210 1.1 matt return;
211 1.1 matt }
212 1.1 matt
213 1.7 matt if (osc->osc_tadpole) {
214 1.7 matt *AUXIO4M_REG |= (AUXIO4M_LED|AUXIO4M_LTE);
215 1.7 matt do {
216 1.7 matt DELAY(100);
217 1.7 matt } while (!comprobe1(sc->sc_iot, sc->sc_ioh));
218 1.3 matt #if 0
219 1.7 matt printf("modem: attach: lcr=0x%02x iir=0x%02x\n",
220 1.7 matt bus_space_read_1(sc->sc_iot, sc->sc_ioh, 3),
221 1.7 matt bus_space_read_1(sc->sc_iot, sc->sc_ioh, 2));
222 1.3 matt #endif
223 1.7 matt }
224 1.3 matt
225 1.1 matt com_attach_subr(sc);
226 1.1 matt
227 1.4 pk if (sa->sa_nintr != 0) {
228 1.6 pk (void)bus_intr_establish(sc->sc_iot, sa->sa_pri, IPL_SERIAL,
229 1.13 pk comintr, sc);
230 1.5 cgd evcnt_attach_dynamic(&osc->osc_intrcnt, EVCNT_TYPE_INTR, NULL,
231 1.5 cgd osc->osc_com.sc_dev.dv_xname, "intr");
232 1.4 pk }
233 1.1 matt
234 1.1 matt /*
235 1.1 matt * Shutdown hook for buggy BIOSs that don't recognize the UART
236 1.1 matt * without a disabled FIFO.
237 1.1 matt */
238 1.1 matt if (shutdownhook_establish(com_obio_cleanup, sc) == NULL) {
239 1.1 matt panic("com_obio_attach: could not establish shutdown hook");
240 1.1 matt }
241 1.1 matt }
242 1.1 matt
243 1.1 matt static void
244 1.1 matt com_obio_cleanup(arg)
245 1.1 matt void *arg;
246 1.1 matt {
247 1.1 matt struct com_softc *sc = arg;
248 1.1 matt
249 1.1 matt if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
250 1.1 matt bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
251 1.1 matt }
252