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