com_supio.c revision 1.22.44.1 1 /* $NetBSD: com_supio.c,v 1.22.44.1 2008/04/03 12:42:11 mjf 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. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)com.c 7.5 (Berkeley) 5/16/91
68 */
69
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: com_supio.c,v 1.22.44.1 2008/04/03 12:42:11 mjf Exp $");
72
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/ioctl.h>
76 #include <sys/select.h>
77 #include <sys/tty.h>
78 #include <sys/proc.h>
79 #include <sys/user.h>
80 #include <sys/conf.h>
81 #include <sys/file.h>
82 #include <sys/uio.h>
83 #include <sys/kernel.h>
84 #include <sys/syslog.h>
85 #include <sys/types.h>
86 #include <sys/device.h>
87
88 #include <machine/intr.h>
89 #include <machine/bus.h>
90
91 /*#include <dev/isa/isavar.h>*/
92 #include <dev/ic/comreg.h>
93 #include <dev/ic/comvar.h>
94
95 #include <amiga/dev/supio.h>
96
97 struct comsupio_softc {
98 struct com_softc sc_com;
99 struct isr sc_isr;
100 };
101
102 int com_supio_match(device_t, cfdata_t , void *);
103 void com_supio_attach(device_t, device_t, void *);
104
105 CFATTACH_DECL_NEW(com_supio, sizeof(struct comsupio_softc),
106 com_supio_match, com_supio_attach, NULL, NULL);
107
108 int
109 com_supio_match(device_t parent, cfdata_t match, void *aux)
110 {
111 int rv = 1;
112 struct supio_attach_args *supa = aux;
113
114 if (strcmp(supa->supio_name,"com"))
115 return 0;
116
117 return (rv);
118 }
119
120 void
121 com_supio_attach(device_t parent, device_t self, void *aux)
122 {
123 struct comsupio_softc *sc = device_private(self);
124 struct com_softc *csc = &sc->sc_com;
125 int iobase;
126 bus_space_tag_t iot;
127 bus_space_handle_t ioh;
128 struct supio_attach_args *supa = aux;
129 u_int16_t needpsl;
130
131 csc->sc_dev = self;
132
133 /*
134 * We're living on a superio chip.
135 */
136 iobase = supa->supio_iobase;
137 iot = supa->supio_iot;
138 aprint_normal(" port 0x%04x ipl %d", iobase, supa->supio_ipl);
139
140 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
141 panic("comattach: io mapping failed");
142 COM_INIT_REGS(csc->sc_regs, iot, ioh, iobase);
143
144 csc->sc_frequency = supa->supio_arg;
145
146 com_attach_subr(csc);
147
148 /* XXX this should be really in the interrupt stuff */
149 needpsl = PSL_S | (supa->supio_ipl << 8);
150
151 if (ipl2spl_table[IPL_SERIAL] < needpsl) {
152 aprint_normal_dev(self, "raising ipl2spl_table[IPL_SERIAL] "
153 "from 0x%x to 0x%x\n", ipl2spl_table[IPL_SERIAL], needpsl);
154 ipl2spl_table[IPL_SERIAL] = needpsl;
155 }
156 sc->sc_isr.isr_intr = comintr;
157 sc->sc_isr.isr_arg = csc;
158 sc->sc_isr.isr_ipl = supa->supio_ipl;
159 add_isr(&sc->sc_isr);
160
161 if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
162 aprint_error_dev(self, "could not establish shutdown hook");
163 }
164 }
165