xref: /netbsd/sys/arch/amiga/dev/com_supio.c (revision c4a72b64)
1 /*	$NetBSD: com_supio.c,v 1.17 2002/10/02 04:55:49 thorpej 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. All advertising materials mentioning features or use of this software
52  *    must display the following acknowledgement:
53  *	This product includes software developed by the University of
54  *	California, Berkeley and its contributors.
55  * 4. Neither the name of the University nor the names of its contributors
56  *    may be used to endorse or promote products derived from this software
57  *    without specific prior written permission.
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  *
71  *	@(#)com.c	7.5 (Berkeley) 5/16/91
72  */
73 
74 #include <sys/cdefs.h>
75 __KERNEL_RCSID(0, "$NetBSD: com_supio.c,v 1.17 2002/10/02 04:55:49 thorpej Exp $");
76 
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/ioctl.h>
80 #include <sys/select.h>
81 #include <sys/tty.h>
82 #include <sys/proc.h>
83 #include <sys/user.h>
84 #include <sys/conf.h>
85 #include <sys/file.h>
86 #include <sys/uio.h>
87 #include <sys/kernel.h>
88 #include <sys/syslog.h>
89 #include <sys/types.h>
90 #include <sys/device.h>
91 
92 #include <machine/intr.h>
93 #include <machine/bus.h>
94 
95 /*#include <dev/isa/isavar.h>*/
96 #include <dev/ic/comreg.h>
97 #include <dev/ic/comvar.h>
98 
99 #include <amiga/dev/supio.h>
100 
101 struct comsupio_softc {
102 	struct com_softc sc_com;
103 	struct isr sc_isr;
104 };
105 
106 int com_supio_match(struct device *, struct cfdata *, void *);
107 void com_supio_attach(struct device *, struct device *, void *);
108 void com_supio_cleanup(void *);
109 
110 #if 0
111 static int      comconsaddr;
112 static bus_space_handle_t comconsioh;
113 static int      comconsattached;
114 static bus_space_tag_t comconstag;
115 static int comconsrate;
116 static tcflag_t comconscflag;
117 #endif
118 
119 CFATTACH_DECL(com_supio, sizeof(struct comsupio_softc),
120     com_supio_match, com_supio_attach, NULL, NULL);
121 
122 int
123 com_supio_match(struct device *parent, struct cfdata *match, void *aux)
124 {
125 	bus_space_tag_t iot;
126 	int iobase;
127 	int rv = 1;
128 	struct supio_attach_args *supa = aux;
129 
130 	iot = supa->supio_iot;
131 	iobase = supa->supio_iobase;
132 
133 	if (strcmp(supa->supio_name,"com"))
134 		return 0;
135 
136 	return (rv);
137 }
138 
139 void
140 com_supio_attach(struct device *parent, struct device *self, void *aux)
141 {
142 	struct comsupio_softc *sc = (void *)self;
143 	struct com_softc *csc = &sc->sc_com;
144 	int iobase;
145 	bus_space_tag_t iot;
146 	struct supio_attach_args *supa = aux;
147 	u_int16_t needpsl;
148 
149 	/*
150 	 * We're living on a superio chip.
151 	 */
152 	iobase = csc->sc_iobase = supa->supio_iobase;
153 	iot = csc->sc_iot = supa->supio_iot;
154 	printf(" port 0x%04x ipl %d", iobase, supa->supio_ipl);
155 
156 	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &csc->sc_ioh))
157 		panic("comattach: io mapping failed");
158 
159 	csc->sc_frequency = supa->supio_arg;
160 
161 	com_attach_subr(csc);
162 
163 	/* XXX this should be really in the interupt stuff */
164 	needpsl = PSL_S | (supa->supio_ipl << 8);
165 
166 	if (amiga_serialspl < needpsl) {
167 		printf("%s: raising amiga_serialspl from 0x%x to 0x%x\n",
168 		    csc->sc_dev.dv_xname, amiga_serialspl, needpsl);
169 		amiga_serialspl = needpsl;
170 	}
171 	sc->sc_isr.isr_intr = comintr;
172 	sc->sc_isr.isr_arg = csc;
173 	sc->sc_isr.isr_ipl = supa->supio_ipl;
174 	add_isr(&sc->sc_isr);
175 
176 	/*
177 	 * Shutdown hook for buggy BIOSs that don't recognize the UART
178 	 * without a disabled FIFO.
179 	 */
180 	if (shutdownhook_establish(com_supio_cleanup, csc) == NULL)
181 		panic("comsupio: could not establish shutdown hook");
182 }
183 
184 void
185 com_supio_cleanup(void *arg)
186 {
187 	struct com_softc *sc = arg;
188 
189 	if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
190 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
191 }
192