com_pioc.c revision 1.2.2.3 1 /* $NetBSD: com_pioc.c,v 1.2.2.3 2002/03/16 15:55:26 jdolecek 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
76 __KERNEL_RCSID(0, "$NetBSD: com_pioc.c,v 1.2.2.3 2002/03/16 15:55:26 jdolecek Exp $");
77
78 #include <sys/systm.h>
79 #include <sys/tty.h>
80 #include <sys/proc.h>
81 #include <sys/conf.h>
82 #include <sys/kernel.h>
83 #include <sys/device.h>
84
85 #include <machine/intr.h>
86 #include <machine/bus.h>
87 #include <machine/io.h>
88
89 #include <acorn32/mainbus/piocvar.h>
90 #include <dev/ic/comreg.h>
91 #include <dev/ic/comvar.h>
92
93 #include <dev/cons.h>
94
95 #include "locators.h"
96
97 struct com_pioc_softc {
98 struct com_softc sc_com; /* real "com" softc */
99 void *sc_ih; /* interrupt handler */
100 };
101
102 /* Prototypes for functions */
103
104 cons_decl(com);
105
106 static int com_pioc_probe __P((struct device *, struct cfdata *, void *));
107 static void com_pioc_attach __P((struct device *, struct device *, void *));
108 static void com_pioc_cleanup __P((void *));
109
110 /* device attach structure */
111
112 struct cfattach com_pioc_ca = {
113 sizeof(struct com_pioc_softc), com_pioc_probe, com_pioc_attach
114 };
115
116 extern bus_space_tag_t comconstag; /* From pioc.c */
117
118 /*
119 * int com_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
120 *
121 * Make sure we are trying to attach a com device and then
122 * probe for one.
123 */
124
125 static int
126 com_pioc_probe(parent, cf, aux)
127 struct device *parent;
128 struct cfdata *cf;
129 void *aux;
130 {
131 bus_space_tag_t iot;
132 bus_space_handle_t ioh;
133 int iobase;
134 int rv = 1;
135 struct pioc_attach_args *pa = aux;
136
137 /* We need an offset */
138 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
139 return(0);
140
141 iot = pa->pa_iot;
142 iobase = pa->pa_iobase + pa->pa_offset;
143
144 /* if it's in use as console, it's there. */
145 if (!com_is_console(iot, iobase, 0)) {
146 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
147 return 0;
148 }
149 rv = comprobe1(iot, ioh);
150 bus_space_unmap(iot, ioh, COM_NPORTS);
151 }
152
153 if (rv) {
154 pa->pa_iosize = COM_NPORTS;
155 }
156 return (rv);
157 }
158
159 /*
160 * void com_pioc_attach(struct device *parent, struct device *self, void *aux)
161 *
162 * attach the com device
163 */
164
165 static void
166 com_pioc_attach(parent, self, aux)
167 struct device *parent, *self;
168 void *aux;
169 {
170 struct com_pioc_softc *psc = (void *)self;
171 struct com_softc *sc = &psc->sc_com;
172 u_int iobase;
173 bus_space_tag_t iot;
174 struct pioc_attach_args *pa = aux;
175 int count;
176
177 iot = sc->sc_iot = pa->pa_iot;
178 iobase = sc->sc_iobase = pa->pa_iobase + pa->pa_offset;
179
180 /*
181 printf(" (iot = %p, iobase = 0x%08x) ", iot, iobase);
182 */
183 if (!com_is_console(iot, iobase, &sc->sc_ioh)
184 && bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh))
185 panic("comattach: io mapping failed");
186
187 sc->sc_frequency = COM_FREQ;
188
189 com_attach_subr(sc);
190
191 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
192 psc->sc_ih = intr_claim(pa->pa_irq, IPL_SERIAL, "com",
193 comintr, sc);
194 }
195
196 /*
197 * Shutdown hook for buggy BIOSs that don't recognize the UART
198 * without a disabled FIFO.
199 */
200 if (shutdownhook_establish(com_pioc_cleanup, sc) == NULL)
201 panic("%s: could not establish shutdown hook",
202 sc->sc_dev.dv_xname);
203
204 /*
205 * This is a patch for bugged revision 1-4 SMC FDC37C665
206 * I/O controllers.
207 * If there is RX data pending when the FIFO in turned on
208 * the RX register cannot be emptied.
209 *
210 * Solution:
211 * Make sure FIFO is off.
212 * Read pending data / int status etc.
213 */
214 bus_space_write_1(iot, sc->sc_ioh, com_fifo, 0);
215 for (count = 0; count < 8; ++count)
216 (void)bus_space_read_1(iot, sc->sc_ioh, count);
217
218 }
219
220 /*
221 * void com_pioc_cleanup(void *arg)
222 *
223 * clean up driver
224 */
225
226 static void
227 com_pioc_cleanup(arg)
228 void *arg;
229 {
230 struct com_softc *sc = arg;
231
232 if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
233 bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
234 }
235
236 /*
237 * Console attachment functions
238 */
239
240 void
241 comcnprobe(cp)
242 struct consdev *cp;
243 {
244
245 #ifdef COMCONSOLE
246 cp->cn_pri = CN_REMOTE; /* Force a serial port console */
247 #else
248 cp->cn_pri = CN_NORMAL;
249 #endif
250 }
251
252 void
253 comcninit(cp)
254 struct consdev *cp;
255 {
256 int result;
257
258 #ifndef CONMODE
259 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
260 #endif
261 #ifndef CONSPEED
262 #define CONSPEED 38400
263 #endif
264 #ifndef CONADDR
265 #define CONADDR 0x3f8
266 #endif
267
268 result = comcnattach(comconstag, (IO_CONF_BASE + CONADDR), CONSPEED, COM_FREQ, CONMODE);
269 if (result) {
270 printf("initialising serial; got errornr %d\n", result);
271 panic("can't init serial console @%x", CONADDR);
272 };
273 }
274
275
276 /* End of com_pioc.c */
277