com_pioc.c revision 1.2.2.2 1 /* $NetBSD: com_pioc.c,v 1.2.2.2 2002/01/10 19:36:27 thorpej 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*-
40 * Copyright (c) 1991 The Regents of the University of California.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Berkeley and its contributors.
55 * 4. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)com.c 7.5 (Berkeley) 5/16/91
72 */
73
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/tty.h>
77 #include <sys/proc.h>
78 #include <sys/conf.h>
79 #include <sys/kernel.h>
80 #include <sys/device.h>
81
82 #include <machine/intr.h>
83 #include <machine/bus.h>
84 #include <machine/io.h>
85
86 #include <acorn32/mainbus/piocvar.h>
87 #include <dev/ic/comreg.h>
88 #include <dev/ic/comvar.h>
89
90 #include <dev/cons.h>
91
92 #include "locators.h"
93
94 struct com_pioc_softc {
95 struct com_softc sc_com; /* real "com" softc */
96 void *sc_ih; /* interrupt handler */
97 };
98
99 /* Prototypes for functions */
100
101 static int com_pioc_probe __P((struct device *, struct cfdata *, void *));
102 static void com_pioc_attach __P((struct device *, struct device *, void *));
103 static void com_pioc_cleanup __P((void *));
104
105 /* device attach structure */
106
107 struct cfattach com_pioc_ca = {
108 sizeof(struct com_pioc_softc), com_pioc_probe, com_pioc_attach
109 };
110
111 extern bus_space_tag_t comconstag; /* From pioc.c */
112
113 /*
114 * int com_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
115 *
116 * Make sure we are trying to attach a com device and then
117 * probe for one.
118 */
119
120 static int
121 com_pioc_probe(parent, cf, aux)
122 struct device *parent;
123 struct cfdata *cf;
124 void *aux;
125 {
126 bus_space_tag_t iot;
127 bus_space_handle_t ioh;
128 int iobase;
129 int rv = 1;
130 struct pioc_attach_args *pa = aux;
131
132 /* We need an offset */
133 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
134 return(0);
135
136 iot = pa->pa_iot;
137 iobase = pa->pa_iobase + pa->pa_offset;
138
139 /* if it's in use as console, it's there. */
140 if (!com_is_console(iot, iobase, 0)) {
141 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
142 return 0;
143 }
144 rv = comprobe1(iot, ioh);
145 bus_space_unmap(iot, ioh, COM_NPORTS);
146 }
147
148 if (rv) {
149 pa->pa_iosize = COM_NPORTS;
150 }
151 return (rv);
152 }
153
154 /*
155 * void com_pioc_attach(struct device *parent, struct device *self, void *aux)
156 *
157 * attach the com device
158 */
159
160 static void
161 com_pioc_attach(parent, self, aux)
162 struct device *parent, *self;
163 void *aux;
164 {
165 struct com_pioc_softc *psc = (void *)self;
166 struct com_softc *sc = &psc->sc_com;
167 u_int iobase;
168 bus_space_tag_t iot;
169 struct pioc_attach_args *pa = aux;
170 int count;
171
172 iot = sc->sc_iot = pa->pa_iot;
173 iobase = sc->sc_iobase = pa->pa_iobase + pa->pa_offset;
174
175 /*
176 printf(" (iot = %p, iobase = 0x%08x) ", iot, iobase);
177 */
178 if (!com_is_console(iot, iobase, &sc->sc_ioh)
179 && bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh))
180 panic("comattach: io mapping failed");
181
182 sc->sc_frequency = COM_FREQ;
183
184 com_attach_subr(sc);
185
186 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
187 psc->sc_ih = intr_claim(pa->pa_irq, IPL_SERIAL, "com",
188 comintr, sc);
189 }
190
191 /*
192 * Shutdown hook for buggy BIOSs that don't recognize the UART
193 * without a disabled FIFO.
194 */
195 if (shutdownhook_establish(com_pioc_cleanup, sc) == NULL)
196 panic("%s: could not establish shutdown hook",
197 sc->sc_dev.dv_xname);
198
199 /*
200 * This is a patch for bugged revision 1-4 SMC FDC37C665
201 * I/O controllers.
202 * If there is RX data pending when the FIFO in turned on
203 * the RX register cannot be emptied.
204 *
205 * Solution:
206 * Make sure FIFO is off.
207 * Read pending data / int status etc.
208 */
209 bus_space_write_1(iot, sc->sc_ioh, com_fifo, 0);
210 for (count = 0; count < 8; ++count)
211 (void)bus_space_read_1(iot, sc->sc_ioh, count);
212
213 }
214
215 /*
216 * void com_pioc_cleanup(void *arg)
217 *
218 * clean up driver
219 */
220
221 static void
222 com_pioc_cleanup(arg)
223 void *arg;
224 {
225 struct com_softc *sc = arg;
226
227 if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
228 bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
229 }
230
231 /*
232 * Console attachment functions
233 */
234
235 void
236 comcnprobe(cp)
237 struct consdev *cp;
238 {
239
240 #ifdef COMCONSOLE
241 cp->cn_pri = CN_REMOTE; /* Force a serial port console */
242 #else
243 cp->cn_pri = CN_NORMAL;
244 #endif
245 }
246
247 void
248 comcninit(cp)
249 struct consdev *cp;
250 {
251 int result;
252
253 #ifndef CONMODE
254 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
255 #endif
256 #ifndef CONSPEED
257 #define CONSPEED 38400
258 #endif
259 #ifndef CONADDR
260 #define CONADDR 0x3f8
261 #endif
262
263 result = comcnattach(comconstag, (IO_CONF_BASE + CONADDR), CONSPEED, COM_FREQ, CONMODE);
264 if (result) {
265 printf("initialising serial; got errornr %d\n", result);
266 panic("can't init serial console @%x", CONADDR);
267 };
268 }
269
270
271 /* End of com_pioc.c */
272