com_pioc.c revision 1.12 1 /* $NetBSD: com_pioc.c,v 1.12 2008/02/29 07:02:04 dyoung 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. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)com.c 7.5 (Berkeley) 5/16/91
68 */
69
70 #include <sys/param.h>
71
72 __KERNEL_RCSID(0, "$NetBSD: com_pioc.c,v 1.12 2008/02/29 07:02:04 dyoung Exp $");
73
74 #include <sys/systm.h>
75 #include <sys/tty.h>
76 #include <sys/proc.h>
77 #include <sys/conf.h>
78 #include <sys/kernel.h>
79 #include <sys/device.h>
80
81 #include <machine/intr.h>
82 #include <machine/bus.h>
83 #include <machine/io.h>
84
85 #include <acorn32/mainbus/piocvar.h>
86 #include <dev/ic/comreg.h>
87 #include <dev/ic/comvar.h>
88
89 #include <dev/cons.h>
90
91 #include "locators.h"
92
93 struct com_pioc_softc {
94 struct com_softc sc_com; /* real "com" softc */
95 void *sc_ih; /* interrupt handler */
96 };
97
98 /* Prototypes for functions */
99
100 cons_decl(com);
101
102 static int com_pioc_probe __P((struct device *, struct cfdata *, void *));
103 static void com_pioc_attach __P((struct device *, struct device *, void *));
104
105 /* device attach structure */
106
107 CFATTACH_DECL(com_pioc, sizeof(struct com_pioc_softc),
108 com_pioc_probe, com_pioc_attach, NULL, NULL);
109
110 extern bus_space_tag_t comconstag; /* From pioc.c */
111
112 /*
113 * int com_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
114 *
115 * Make sure we are trying to attach a com device and then
116 * probe for one.
117 */
118
119 static int
120 com_pioc_probe(parent, cf, aux)
121 struct device *parent;
122 struct cfdata *cf;
123 void *aux;
124 {
125 bus_space_tag_t iot;
126 bus_space_handle_t ioh;
127 int iobase;
128 int rv = 1;
129 struct pioc_attach_args *pa = aux;
130
131 /* We need an offset */
132 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
133 return(0);
134
135 iot = pa->pa_iot;
136 iobase = pa->pa_iobase + pa->pa_offset;
137
138 /* if it's in use as console, it's there. */
139 if (!com_is_console(iot, iobase, 0)) {
140 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
141 return 0;
142 }
143 rv = comprobe1(iot, ioh);
144 bus_space_unmap(iot, ioh, COM_NPORTS);
145 }
146
147 if (rv) {
148 pa->pa_iosize = COM_NPORTS;
149 }
150 return (rv);
151 }
152
153 /*
154 * void com_pioc_attach(struct device *parent, struct device *self, void *aux)
155 *
156 * attach the com device
157 */
158
159 static void
160 com_pioc_attach(parent, self, aux)
161 struct device *parent, *self;
162 void *aux;
163 {
164 struct com_pioc_softc *psc = (void *)self;
165 struct com_softc *sc = &psc->sc_com;
166 u_int iobase;
167 bus_space_tag_t iot;
168 bus_space_handle_t ioh;
169 struct pioc_attach_args *pa = aux;
170 int count;
171
172 iot = pa->pa_iot;
173 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, &ioh)
179 && bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
180 panic("comattach: io mapping failed");
181 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
182
183 sc->sc_frequency = COM_FREQ;
184
185 com_attach_subr(sc);
186
187 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
188 psc->sc_ih = intr_claim(pa->pa_irq, IPL_SERIAL, "com",
189 comintr, sc);
190 }
191
192 if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
193 aprint_error_dev(&sc->sc_dev,
194 "could not establish shutdown hook");
195 }
196
197 /*
198 * This is a patch for bugged revision 1-4 SMC FDC37C665
199 * I/O controllers.
200 * If there is RX data pending when the FIFO in turned on
201 * the RX register cannot be emptied.
202 *
203 * Solution:
204 * Make sure FIFO is off.
205 * Read pending data / int status etc.
206 */
207 bus_space_write_1(iot, ioh, com_fifo, 0);
208 for (count = 0; count < 8; ++count)
209 (void)bus_space_read_1(iot, ioh, count);
210
211 }
212
213 /*
214 * Console attachment functions
215 */
216
217 void
218 comcnprobe(cp)
219 struct consdev *cp;
220 {
221
222 #ifdef COMCONSOLE
223 cp->cn_pri = CN_REMOTE; /* Force a serial port console */
224 #else
225 cp->cn_pri = CN_NORMAL;
226 #endif
227 }
228
229 void
230 comcninit(cp)
231 struct consdev *cp;
232 {
233 int result;
234
235 #ifndef CONMODE
236 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
237 #endif
238 #ifndef CONSPEED
239 #define CONSPEED 38400
240 #endif
241 #ifndef CONADDR
242 #define CONADDR 0x3f8
243 #endif
244
245 result = comcnattach(comconstag, (IO_CONF_BASE + CONADDR), CONSPEED,
246 COM_FREQ, COM_TYPE_NORMAL, CONMODE);
247 if (result) {
248 printf("initialising serial; got errornr %d\n", result);
249 panic("can't init serial console @%x", CONADDR);
250 };
251 }
252
253
254 /* End of com_pioc.c */
255