Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / acorn32 / mainbus / com_pioc.c
blob3c359103d2cf9e2f5476d955f048a2b2a89a4d1e
1 /* $NetBSD: com_pioc.c,v 1.13 2008/03/14 15:09:09 cube Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 /*-
33 * Copyright (c) 1991 The Regents of the University of California.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
60 * @(#)com.c 7.5 (Berkeley) 5/16/91
63 #include <sys/param.h>
65 __KERNEL_RCSID(0, "$NetBSD: com_pioc.c,v 1.13 2008/03/14 15:09:09 cube Exp $");
67 #include <sys/systm.h>
68 #include <sys/tty.h>
69 #include <sys/proc.h>
70 #include <sys/conf.h>
71 #include <sys/kernel.h>
72 #include <sys/device.h>
74 #include <machine/intr.h>
75 #include <machine/bus.h>
76 #include <machine/io.h>
78 #include <acorn32/mainbus/piocvar.h>
79 #include <dev/ic/comreg.h>
80 #include <dev/ic/comvar.h>
82 #include <dev/cons.h>
84 #include "locators.h"
86 struct com_pioc_softc {
87 struct com_softc sc_com; /* real "com" softc */
88 void *sc_ih; /* interrupt handler */
91 /* Prototypes for functions */
93 cons_decl(com);
95 static int com_pioc_probe (device_t, cfdata_t , void *);
96 static void com_pioc_attach (device_t, device_t, void *);
98 /* device attach structure */
100 CFATTACH_DECL_NEW(com_pioc, sizeof(struct com_pioc_softc),
101 com_pioc_probe, com_pioc_attach, NULL, NULL);
103 extern bus_space_tag_t comconstag; /* From pioc.c */
106 * int com_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
108 * Make sure we are trying to attach a com device and then
109 * probe for one.
112 static int
113 com_pioc_probe(device_t parent, cfdata_t cf, void *aux)
115 bus_space_tag_t iot;
116 bus_space_handle_t ioh;
117 int iobase;
118 int rv = 1;
119 struct pioc_attach_args *pa = aux;
121 /* We need an offset */
122 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
123 return(0);
125 iot = pa->pa_iot;
126 iobase = pa->pa_iobase + pa->pa_offset;
128 /* if it's in use as console, it's there. */
129 if (!com_is_console(iot, iobase, 0)) {
130 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
131 return 0;
133 rv = comprobe1(iot, ioh);
134 bus_space_unmap(iot, ioh, COM_NPORTS);
137 if (rv) {
138 pa->pa_iosize = COM_NPORTS;
140 return (rv);
144 * void com_pioc_attach(struct device *parent, struct device *self, void *aux)
146 * attach the com device
149 static void
150 com_pioc_attach(device_t parent, device_t self, void *aux)
152 struct com_pioc_softc *psc = device_private(self);
153 struct com_softc *sc = &psc->sc_com;
154 u_int iobase;
155 bus_space_tag_t iot;
156 bus_space_handle_t ioh;
157 struct pioc_attach_args *pa = aux;
158 int count;
160 sc->sc_dev = self;
161 iot = pa->pa_iot;
162 iobase = pa->pa_iobase + pa->pa_offset;
165 printf(" (iot = %p, iobase = 0x%08x) ", iot, iobase);
167 if (!com_is_console(iot, iobase, &ioh)
168 && bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
169 panic("comattach: io mapping failed");
170 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
172 sc->sc_frequency = COM_FREQ;
174 com_attach_subr(sc);
176 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
177 psc->sc_ih = intr_claim(pa->pa_irq, IPL_SERIAL, "com",
178 comintr, sc);
181 if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
182 aprint_error_dev(self,
183 "could not establish shutdown hook");
187 * This is a patch for bugged revision 1-4 SMC FDC37C665
188 * I/O controllers.
189 * If there is RX data pending when the FIFO in turned on
190 * the RX register cannot be emptied.
192 * Solution:
193 * Make sure FIFO is off.
194 * Read pending data / int status etc.
196 bus_space_write_1(iot, ioh, com_fifo, 0);
197 for (count = 0; count < 8; ++count)
198 (void)bus_space_read_1(iot, ioh, count);
203 * Console attachment functions
206 void
207 comcnprobe(struct consdev *cp)
210 #ifdef COMCONSOLE
211 cp->cn_pri = CN_REMOTE; /* Force a serial port console */
212 #else
213 cp->cn_pri = CN_NORMAL;
214 #endif
217 void
218 comcninit(struct consdev *cp)
220 int result;
222 #ifndef CONMODE
223 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
224 #endif
225 #ifndef CONSPEED
226 #define CONSPEED 38400
227 #endif
228 #ifndef CONADDR
229 #define CONADDR 0x3f8
230 #endif
232 result = comcnattach(comconstag, (IO_CONF_BASE + CONADDR), CONSPEED,
233 COM_FREQ, COM_TYPE_NORMAL, CONMODE);
234 if (result) {
235 printf("initialising serial; got errornr %d\n", result);
236 panic("can't init serial console @%x", CONADDR);
241 /* End of com_pioc.c */