com_supio.c revision 1.11 1 1.11 mycroft /* $NetBSD: com_supio.c,v 1.11 1998/08/15 17:47:15 mycroft Exp $ */
2 1.11 mycroft
3 1.11 mycroft /*-
4 1.11 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.11 mycroft * All rights reserved.
6 1.11 mycroft *
7 1.11 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.11 mycroft * by Charles M. Hannum.
9 1.11 mycroft *
10 1.11 mycroft * Redistribution and use in source and binary forms, with or without
11 1.11 mycroft * modification, are permitted provided that the following conditions
12 1.11 mycroft * are met:
13 1.11 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.11 mycroft * notice, this list of conditions and the following disclaimer.
15 1.11 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.11 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.11 mycroft * documentation and/or other materials provided with the distribution.
18 1.11 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.11 mycroft * must display the following acknowledgement:
20 1.11 mycroft * This product includes software developed by the NetBSD
21 1.11 mycroft * Foundation, Inc. and its contributors.
22 1.11 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.11 mycroft * contributors may be used to endorse or promote products derived
24 1.11 mycroft * from this software without specific prior written permission.
25 1.11 mycroft *
26 1.11 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.11 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.11 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.11 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.11 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.11 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.11 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.11 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.11 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.11 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.11 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.11 mycroft */
38 1.1 is
39 1.1 is /*-
40 1.1 is * Copyright (c) 1991 The Regents of the University of California.
41 1.1 is * All rights reserved.
42 1.1 is *
43 1.1 is * Redistribution and use in source and binary forms, with or without
44 1.1 is * modification, are permitted provided that the following conditions
45 1.1 is * are met:
46 1.1 is * 1. Redistributions of source code must retain the above copyright
47 1.1 is * notice, this list of conditions and the following disclaimer.
48 1.1 is * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 is * notice, this list of conditions and the following disclaimer in the
50 1.1 is * documentation and/or other materials provided with the distribution.
51 1.1 is * 3. All advertising materials mentioning features or use of this software
52 1.1 is * must display the following acknowledgement:
53 1.1 is * This product includes software developed by the University of
54 1.1 is * California, Berkeley and its contributors.
55 1.1 is * 4. Neither the name of the University nor the names of its contributors
56 1.1 is * may be used to endorse or promote products derived from this software
57 1.1 is * without specific prior written permission.
58 1.1 is *
59 1.1 is * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 is * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 is * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 is * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 is * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 is * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 is * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 is * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 is * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 is * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 is * SUCH DAMAGE.
70 1.1 is *
71 1.1 is * @(#)com.c 7.5 (Berkeley) 5/16/91
72 1.1 is */
73 1.1 is
74 1.1 is #include <sys/param.h>
75 1.1 is #include <sys/systm.h>
76 1.1 is #include <sys/ioctl.h>
77 1.1 is #include <sys/select.h>
78 1.1 is #include <sys/tty.h>
79 1.1 is #include <sys/proc.h>
80 1.1 is #include <sys/user.h>
81 1.1 is #include <sys/conf.h>
82 1.1 is #include <sys/file.h>
83 1.1 is #include <sys/uio.h>
84 1.1 is #include <sys/kernel.h>
85 1.1 is #include <sys/syslog.h>
86 1.1 is #include <sys/types.h>
87 1.1 is #include <sys/device.h>
88 1.1 is
89 1.1 is #include <machine/intr.h>
90 1.1 is #include <machine/bus.h>
91 1.1 is
92 1.1 is /*#include <dev/isa/isavar.h>*/
93 1.5 thorpej #include <dev/ic/comreg.h>
94 1.5 thorpej #include <dev/ic/comvar.h>
95 1.1 is
96 1.1 is #include <amiga/dev/supio.h>
97 1.1 is
98 1.1 is struct comsupio_softc {
99 1.1 is struct com_softc sc_com;
100 1.1 is struct isr sc_isr;
101 1.1 is };
102 1.1 is
103 1.2 is int com_supio_match __P((struct device *, struct cfdata *, void *));
104 1.1 is void com_supio_attach __P((struct device *, struct device *, void *));
105 1.1 is void com_supio_cleanup __P((void *));
106 1.1 is
107 1.6 is #if 0
108 1.1 is static int comconsaddr;
109 1.1 is static bus_space_handle_t comconsioh;
110 1.1 is static int comconsattached;
111 1.1 is static bus_space_tag_t comconstag;
112 1.1 is static int comconsrate;
113 1.1 is static tcflag_t comconscflag;
114 1.1 is #endif
115 1.1 is
116 1.1 is struct cfattach com_supio_ca = {
117 1.2 is sizeof(struct comsupio_softc), com_supio_match, com_supio_attach
118 1.1 is };
119 1.1 is
120 1.1 is int
121 1.2 is com_supio_match(parent, match, aux)
122 1.1 is struct device *parent;
123 1.1 is struct cfdata *match;
124 1.1 is void *aux;
125 1.1 is {
126 1.1 is bus_space_tag_t iot;
127 1.1 is int iobase;
128 1.1 is int rv = 1;
129 1.1 is struct supio_attach_args *supa = aux;
130 1.1 is
131 1.1 is iot = supa->supio_iot;
132 1.1 is iobase = supa->supio_iobase;
133 1.1 is
134 1.4 is if (strcmp(supa->supio_name,"com"))
135 1.1 is return 0;
136 1.1 is #if 0
137 1.1 is /* if it's in use as console, it's there. */
138 1.1 is if (iobase != comconsaddr || comconsattached) {
139 1.1 is if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
140 1.1 is return 0;
141 1.1 is }
142 1.1 is rv = comprobe1(iot, ioh, iobase);
143 1.1 is bus_space_unmap(iot, ioh, COM_NPORTS);
144 1.1 is }
145 1.1 is #endif
146 1.1 is return (rv);
147 1.1 is }
148 1.1 is
149 1.1 is void
150 1.1 is com_supio_attach(parent, self, aux)
151 1.1 is struct device *parent, *self;
152 1.1 is void *aux;
153 1.1 is {
154 1.1 is struct comsupio_softc *sc = (void *)self;
155 1.1 is struct com_softc *csc = &sc->sc_com;
156 1.1 is int iobase;
157 1.1 is bus_space_tag_t iot;
158 1.1 is struct supio_attach_args *supa = aux;
159 1.4 is u_int16_t needpsl;
160 1.1 is
161 1.1 is /*
162 1.1 is * We're living on a superio chip.
163 1.1 is */
164 1.1 is iobase = csc->sc_iobase = supa->supio_iobase;
165 1.1 is iot = csc->sc_iot = supa->supio_iot;
166 1.6 is printf(" port 0x%x ipl %d", iobase, supa->supio_ipl);
167 1.6 is
168 1.6 is if (bus_space_map(iot, iobase, COM_NPORTS, 0, &csc->sc_ioh))
169 1.6 is panic("comattach: io mapping failed");
170 1.1 is
171 1.4 is csc->sc_frequency = supa->supio_arg;
172 1.4 is
173 1.1 is com_attach_subr(csc);
174 1.1 is
175 1.4 is /* XXX this should be really in the interupt stuff */
176 1.4 is needpsl = PSL_S | (supa->supio_ipl << 8);
177 1.4 is
178 1.7 is if (amiga_serialspl < needpsl) {
179 1.7 is printf("%s: raising amiga_serialspl from 0x%x to 0x%x\n",
180 1.7 is csc->sc_dev.dv_xname, amiga_serialspl, needpsl);
181 1.7 is amiga_serialspl = needpsl;
182 1.1 is }
183 1.1 is sc->sc_isr.isr_intr = comintr;
184 1.1 is sc->sc_isr.isr_arg = csc;
185 1.4 is sc->sc_isr.isr_ipl = supa->supio_ipl;
186 1.1 is add_isr(&sc->sc_isr);
187 1.1 is
188 1.1 is /*
189 1.1 is * Shutdown hook for buggy BIOSs that don't recognize the UART
190 1.1 is * without a disabled FIFO.
191 1.1 is */
192 1.1 is if (shutdownhook_establish(com_supio_cleanup, csc) == NULL)
193 1.1 is panic("comsupio: could not establish shutdown hook");
194 1.1 is }
195 1.1 is
196 1.1 is void
197 1.1 is com_supio_cleanup(arg)
198 1.1 is void *arg;
199 1.1 is {
200 1.1 is struct com_softc *sc = arg;
201 1.1 is
202 1.1 is if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
203 1.1 is bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
204 1.1 is }
205