com_mca.c revision 1.1 1 /* $NetBSD: com_mca.c,v 1.1 2001/03/19 21:56:43 jdolecek 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 /*
75 * This driver attaches serial port boards and internal modems.
76 */
77
78 #include <sys/param.h>
79 #include <sys/systm.h>
80 #include <sys/ioctl.h>
81 #include <sys/select.h>
82 #include <sys/tty.h>
83 #include <sys/proc.h>
84 #include <sys/user.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/ic/comreg.h>
96 #include <dev/ic/comvar.h>
97
98 #include <dev/mca/mcavar.h>
99 #include <dev/mca/mcadevs.h>
100
101 struct com_mca_softc {
102 struct com_softc sc_com; /* real "com" softc */
103
104 /* MCA-specific goo. */
105 void *sc_ih; /* interrupt handler */
106 };
107
108 int com_mca_probe __P((struct device *, struct cfdata *, void *));
109 void com_mca_attach __P((struct device *, struct device *, void *));
110 void com_mca_cleanup __P((void *));
111 static int ibm_modem_getcfg __P((struct mca_attach_args *, int *, int *));
112
113 struct cfattach com_mca_ca = {
114 sizeof(struct com_mca_softc), com_mca_probe, com_mca_attach
115 };
116
117 static const struct com_mca_product {
118 u_int32_t cp_prodid; /* MCA product ID */
119 const char *cp_name; /* device name */
120 int (*cp_getcfg) __P((struct mca_attach_args *, int *iobase, int *irq));
121 /* get device i/o base and irq */
122 } com_mca_products[] = {
123 { MCA_PRODUCT_IBM_MOD, "IBM Internal Modem", ibm_modem_getcfg },
124 { 0, NULL, NULL },
125 };
126
127 static const struct com_mca_product *com_mca_lookup __P((int));
128
129 static const struct com_mca_product *
130 com_mca_lookup(ma_id)
131 int ma_id;
132 {
133 const struct com_mca_product *cpp;
134
135 for (cpp = com_mca_products; cpp->cp_name != NULL; cpp++)
136 if (cpp->cp_prodid == ma_id)
137 return (cpp);
138
139 return (NULL);
140 }
141
142 int
143 com_mca_probe(parent, match, aux)
144 struct device *parent;
145 struct cfdata *match;
146 void *aux;
147 {
148 struct mca_attach_args *ma = aux;
149
150 if (com_mca_lookup(ma->ma_id))
151 return (1);
152
153 return (0);
154 }
155
156 void
157 com_mca_attach(parent, self, aux)
158 struct device *parent, *self;
159 void *aux;
160 {
161 struct com_mca_softc *isc = (void *)self;
162 struct com_softc *sc = &isc->sc_com;
163 int iobase, irq;
164 struct mca_attach_args *ma = aux;
165 const struct com_mca_product *cpp;
166
167 cpp = com_mca_lookup(ma->ma_id);
168
169 /* get iobase and irq */
170 if ((*cpp->cp_getcfg)(ma, &iobase, &irq)) {
171 printf(": com_mca_attach: could not get config\n");
172 return;
173 }
174
175 printf(" slot %d i/o %#x-%#x irq %d: %s\n", ma->ma_slot + 1,
176 iobase, iobase + COM_NPORTS - 1,
177 irq, cpp->cp_name);
178
179 printf("%s", sc->sc_dev.dv_xname);
180
181 if (bus_space_map(ma->ma_iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) {
182 printf(": can't map i/o space\n");
183 return;
184 }
185
186 sc->sc_frequency = COM_FREQ;
187 sc->sc_iot = ma->ma_iot;
188 sc->sc_iobase = iobase;
189
190 com_attach_subr(sc);
191
192 isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_SERIAL,
193 comintr, sc);
194 if (isc->sc_ih == NULL) {
195 printf("%s: couldn't establish interrupt handler\n",
196 sc->sc_dev.dv_xname);
197 return;
198 }
199
200 /*
201 * Shutdown hook for buggy BIOSs that don't recognize the UART
202 * without a disabled FIFO.
203 * XXX is this necessary on MCA ? --- jdolecek
204 */
205 if (shutdownhook_establish(com_mca_cleanup, sc) == NULL)
206 panic("com_mca_attach: could not establish shutdown hook");
207 }
208
209 void
210 com_mca_cleanup(arg)
211 void *arg;
212 {
213 struct com_softc *sc = arg;
214
215 if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
216 bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
217 }
218
219 /* map serial_X to iobase and irq */
220 static const struct {
221 int iobase;
222 int irq;
223 } MCA_SERIAL[] = {
224 { 0x03f8, 4 }, /* SERIAL_1 */
225 { 0x02f8, 3 }, /* SERIAL_2 */
226 { 0x3220, 3 }, /* SERIAL_3 */
227 { 0x3228, 3 }, /* SERIAL_4 */
228 { 0x4220, 3 }, /* SERIAL_5 */
229 { 0x4228, 3 }, /* SERIAL_6 */
230 { 0x5220, 3 }, /* SERIAL_7 */
231 { 0x5228, 3 }, /* SERIAL_8 */
232 };
233
234 /*
235 * Get config for IBM Internal Modem (ID 0xEDFF). This beast doesn't
236 * seem to support even AT commands, it's good as example for adding
237 * other stuff though.
238 */
239 static int
240 ibm_modem_getcfg(ma, iobasep, irqp)
241 struct mca_attach_args *ma;
242 int *iobasep, *irqp;
243 {
244 int pos2;
245 int snum;
246
247 pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
248
249 /*
250 * POS register 2: (adf pos0)
251 * 7 6 5 4 3 2 1 0
252 * \__/ \__ enable: 0=adapter disabled, 1=adapter enabled
253 * \_____ Serial Configuration: XX=SERIAL_XX
254 */
255
256 snum = (pos2 & 0x0e) >> 1;
257
258 *iobasep = MCA_SERIAL[snum].iobase;
259 *irqp = MCA_SERIAL[snum].irq;
260
261 return (0);
262 }
263