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