com_pcmcia.c revision 1.13 1 1.13 mycroft /* $NetBSD: com_pcmcia.c,v 1.13 1998/08/15 17:47:17 mycroft Exp $ */
2 1.13 mycroft
3 1.13 mycroft /*-
4 1.13 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.13 mycroft * All rights reserved.
6 1.13 mycroft *
7 1.13 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.13 mycroft * by Charles M. Hannum.
9 1.13 mycroft *
10 1.13 mycroft * Redistribution and use in source and binary forms, with or without
11 1.13 mycroft * modification, are permitted provided that the following conditions
12 1.13 mycroft * are met:
13 1.13 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.13 mycroft * notice, this list of conditions and the following disclaimer.
15 1.13 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.13 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.13 mycroft * documentation and/or other materials provided with the distribution.
18 1.13 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.13 mycroft * must display the following acknowledgement:
20 1.13 mycroft * This product includes software developed by the NetBSD
21 1.13 mycroft * Foundation, Inc. and its contributors.
22 1.13 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.13 mycroft * contributors may be used to endorse or promote products derived
24 1.13 mycroft * from this software without specific prior written permission.
25 1.13 mycroft *
26 1.13 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.13 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.13 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.13 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.13 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.13 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.13 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.13 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.13 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.13 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.13 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.13 mycroft */
38 1.2 thorpej
39 1.2 thorpej /*-
40 1.2 thorpej * Copyright (c) 1991 The Regents of the University of California.
41 1.2 thorpej * All rights reserved.
42 1.2 thorpej *
43 1.2 thorpej * Redistribution and use in source and binary forms, with or without
44 1.2 thorpej * modification, are permitted provided that the following conditions
45 1.2 thorpej * are met:
46 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
47 1.2 thorpej * notice, this list of conditions and the following disclaimer.
48 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
49 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
50 1.2 thorpej * documentation and/or other materials provided with the distribution.
51 1.2 thorpej * 3. All advertising materials mentioning features or use of this software
52 1.2 thorpej * must display the following acknowledgement:
53 1.2 thorpej * This product includes software developed by the University of
54 1.2 thorpej * California, Berkeley and its contributors.
55 1.2 thorpej * 4. Neither the name of the University nor the names of its contributors
56 1.2 thorpej * may be used to endorse or promote products derived from this software
57 1.2 thorpej * without specific prior written permission.
58 1.2 thorpej *
59 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.2 thorpej * SUCH DAMAGE.
70 1.2 thorpej *
71 1.2 thorpej * @(#)com.c 7.5 (Berkeley) 5/16/91
72 1.2 thorpej */
73 1.2 thorpej
74 1.2 thorpej #include <sys/param.h>
75 1.2 thorpej #include <sys/systm.h>
76 1.2 thorpej #include <sys/ioctl.h>
77 1.2 thorpej #include <sys/select.h>
78 1.2 thorpej #include <sys/tty.h>
79 1.2 thorpej #include <sys/proc.h>
80 1.2 thorpej #include <sys/user.h>
81 1.2 thorpej #include <sys/conf.h>
82 1.2 thorpej #include <sys/file.h>
83 1.2 thorpej #include <sys/uio.h>
84 1.2 thorpej #include <sys/kernel.h>
85 1.2 thorpej #include <sys/syslog.h>
86 1.2 thorpej #include <sys/types.h>
87 1.2 thorpej #include <sys/device.h>
88 1.2 thorpej
89 1.2 thorpej #include <machine/intr.h>
90 1.2 thorpej #include <machine/bus.h>
91 1.2 thorpej
92 1.2 thorpej #include <dev/pcmcia/pcmciavar.h>
93 1.2 thorpej #include <dev/pcmcia/pcmciareg.h>
94 1.9 christos #include <dev/pcmcia/pcmciadevs.h>
95 1.2 thorpej
96 1.2 thorpej #include <dev/ic/comreg.h>
97 1.2 thorpej #include <dev/ic/comvar.h>
98 1.2 thorpej
99 1.2 thorpej #include <dev/isa/isareg.h>
100 1.2 thorpej
101 1.5 christos struct com_dev {
102 1.5 christos char *name;
103 1.5 christos int manufacturer;
104 1.5 christos int product;
105 1.5 christos char *cis1_info[4];
106 1.5 christos };
107 1.5 christos
108 1.5 christos static struct com_dev com_devs[] = {
109 1.9 christos { PCMCIA_STR_3COM_3C562,
110 1.9 christos PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C562,
111 1.9 christos PCMCIA_CIS_3COM_3C562 },
112 1.9 christos
113 1.9 christos { PCMCIA_STR_MOTOROLA_POWER144,
114 1.9 christos PCMCIA_VENDOR_MOTOROLA, PCMCIA_PRODUCT_MOTOROLA_POWER144,
115 1.9 christos PCMCIA_CIS_MOTOROLA_POWER144 },
116 1.9 christos
117 1.9 christos { PCMCIA_STR_IBM_HOME_AND_AWAY,
118 1.9 christos PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_HOME_AND_AWAY,
119 1.9 christos PCMCIA_CIS_IBM_HOME_AND_AWAY },
120 1.9 christos
121 1.9 christos { PCMCIA_STR_MEGAHERTZ_XJ4288,
122 1.9 christos PCMCIA_VENDOR_MEGAHERTZ, PCMCIA_PRODUCT_MEGAHERTZ_XJ4288,
123 1.9 christos PCMCIA_CIS_MEGAHERTZ_XJ4288 },
124 1.9 christos
125 1.9 christos { PCMCIA_STR_MEGAHERTZ_XJ4288,
126 1.9 christos PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_MEGAHERTZ_XJ4288,
127 1.9 christos PCMCIA_CIS_MEGAHERTZ_XJ4288 },
128 1.9 christos
129 1.9 christos { PCMCIA_STR_USROBOTICS_WORLDPORT144,
130 1.9 christos PCMCIA_VENDOR_USROBOTICS, PCMCIA_PRODUCT_USROBOTICS_WORLDPORT144,
131 1.9 christos PCMCIA_CIS_USROBOTICS_WORLDPORT144 },
132 1.9 christos
133 1.9 christos { PCMCIA_STR_SOCKET_PAGECARD,
134 1.9 christos PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_PAGECARD,
135 1.9 christos PCMCIA_CIS_SOCKET_PAGECARD },
136 1.9 christos
137 1.9 christos { PCMCIA_STR_MOTOROLA_PM100C,
138 1.9 christos PCMCIA_VENDOR_MOTOROLA, PCMCIA_PRODUCT_MOTOROLA_PM100C,
139 1.10 thorpej PCMCIA_CIS_MOTOROLA_PM100C },
140 1.10 thorpej
141 1.10 thorpej { PCMCIA_STR_SIMPLETECH_COMMUNICATOR288,
142 1.10 thorpej PCMCIA_VENDOR_SIMPLETECH, PCMCIA_PRODUCT_SIMPLETECH_COMMUNICATOR288,
143 1.10 thorpej PCMCIA_CIS_SIMPLETECH_COMMUNICATOR288 },
144 1.5 christos };
145 1.5 christos
146 1.5 christos
147 1.5 christos static int com_devs_size = sizeof(com_devs) / sizeof(com_devs[0]);
148 1.5 christos static struct com_dev *com_dev_match __P((struct pcmcia_card *));
149 1.5 christos
150 1.2 thorpej int com_pcmcia_match __P((struct device *, struct cfdata *, void *));
151 1.2 thorpej void com_pcmcia_attach __P((struct device *, struct device *, void *));
152 1.2 thorpej void com_pcmcia_cleanup __P((void *));
153 1.2 thorpej
154 1.3 marc int com_pcmcia_enable __P((struct com_softc *));
155 1.3 marc void com_pcmcia_disable __P((struct com_softc *));
156 1.5 christos int com_pcmcia_enable1 __P((struct com_softc *));
157 1.5 christos void com_pcmcia_disable1 __P((struct com_softc *));
158 1.3 marc
159 1.2 thorpej struct com_pcmcia_softc {
160 1.2 thorpej struct com_softc sc_com; /* real "com" softc */
161 1.2 thorpej
162 1.2 thorpej /* PCMCIA-specific goo */
163 1.2 thorpej struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
164 1.2 thorpej int sc_io_window; /* our i/o window */
165 1.2 thorpej struct pcmcia_function *sc_pf; /* our PCMCIA function */
166 1.2 thorpej void *sc_ih; /* interrupt handler */
167 1.2 thorpej };
168 1.2 thorpej
169 1.2 thorpej struct cfattach com_pcmcia_ca = {
170 1.2 thorpej sizeof(struct com_pcmcia_softc), com_pcmcia_match, com_pcmcia_attach
171 1.2 thorpej };
172 1.2 thorpej
173 1.5 christos static struct com_dev *
174 1.5 christos com_dev_match(card)
175 1.5 christos struct pcmcia_card *card;
176 1.5 christos {
177 1.5 christos int i;
178 1.5 christos
179 1.5 christos /* 1. check our table */
180 1.5 christos for (i = 0; i < com_devs_size; i++) {
181 1.11 nathanw if (com_devs[i].manufacturer != PCMCIA_VENDOR_INVALID) {
182 1.5 christos /* manufacturer/product match */
183 1.5 christos if (com_devs[i].manufacturer == card->manufacturer &&
184 1.5 christos com_devs[i].product == card->product)
185 1.5 christos return &com_devs[i];
186 1.5 christos } else {
187 1.5 christos /* cis strings match */
188 1.5 christos int j;
189 1.5 christos
190 1.11 nathanw if (com_devs[i].cis1_info[0] == NULL)
191 1.11 nathanw continue;
192 1.5 christos for (j = 0; j < 4; j++)
193 1.5 christos if (com_devs[i].cis1_info[j] &&
194 1.5 christos strcmp(com_devs[i].cis1_info[j],
195 1.5 christos card->cis1_info[j]))
196 1.5 christos break;
197 1.5 christos if (j == 4)
198 1.5 christos return &com_devs[i];
199 1.5 christos }
200 1.5 christos }
201 1.5 christos
202 1.5 christos return NULL;
203 1.5 christos }
204 1.3 marc
205 1.3 marc
206 1.2 thorpej int
207 1.2 thorpej com_pcmcia_match(parent, match, aux)
208 1.2 thorpej struct device *parent;
209 1.2 thorpej struct cfdata *match;
210 1.2 thorpej void *aux;
211 1.2 thorpej {
212 1.11 nathanw int comportmask;
213 1.2 thorpej struct pcmcia_attach_args *pa = aux;
214 1.2 thorpej struct pcmcia_config_entry *cfe;
215 1.2 thorpej
216 1.11 nathanw /* 1. Does it claim to be a serial device? */
217 1.11 nathanw if (pa->pf->function == PCMCIA_FUNCTION_SERIAL)
218 1.11 nathanw return 1;
219 1.11 nathanw
220 1.11 nathanw /* 2. Does it have all four 'standard' port ranges? */
221 1.11 nathanw comportmask = 0;
222 1.2 thorpej for (cfe = pa->pf->cfe_head.sqh_first; cfe;
223 1.11 nathanw cfe = cfe->cfe_list.sqe_next) {
224 1.11 nathanw switch (cfe->iospace[0].start) {
225 1.11 nathanw case IO_COM1:
226 1.11 nathanw comportmask |= 1;
227 1.11 nathanw break;
228 1.11 nathanw case IO_COM2:
229 1.11 nathanw comportmask |= 2;
230 1.11 nathanw break;
231 1.11 nathanw case IO_COM3:
232 1.11 nathanw comportmask |= 4;
233 1.11 nathanw break;
234 1.11 nathanw case IO_COM4:
235 1.11 nathanw comportmask |= 8;
236 1.11 nathanw break;
237 1.11 nathanw }
238 1.11 nathanw }
239 1.11 nathanw
240 1.11 nathanw if (comportmask == 15)
241 1.11 nathanw return 1;
242 1.11 nathanw
243 1.11 nathanw /* 3. Is this a card we know about? */
244 1.11 nathanw if (com_dev_match(pa->card) != NULL)
245 1.11 nathanw return 1;
246 1.2 thorpej
247 1.11 nathanw return 0;
248 1.2 thorpej }
249 1.2 thorpej
250 1.2 thorpej void
251 1.2 thorpej com_pcmcia_attach(parent, self, aux)
252 1.2 thorpej struct device *parent, *self;
253 1.2 thorpej void *aux;
254 1.2 thorpej {
255 1.2 thorpej struct com_pcmcia_softc *psc = (void *) self;
256 1.2 thorpej struct com_softc *sc = &psc->sc_com;
257 1.2 thorpej struct pcmcia_attach_args *pa = aux;
258 1.2 thorpej struct pcmcia_config_entry *cfe;
259 1.3 marc struct com_dev *comdev;
260 1.2 thorpej
261 1.2 thorpej psc->sc_pf = pa->pf;
262 1.2 thorpej
263 1.2 thorpej /* find a cfe we can use */
264 1.2 thorpej
265 1.2 thorpej for (cfe = pa->pf->cfe_head.sqh_first; cfe;
266 1.2 thorpej cfe = cfe->cfe_list.sqe_next) {
267 1.12 thorpej #if 0
268 1.12 thorpej /*
269 1.12 thorpej * Some modem cards (e.g. Xircom CM33) also have
270 1.12 thorpej * mem space. Don't bother with this check.
271 1.12 thorpej */
272 1.2 thorpej if (cfe->num_memspace != 0)
273 1.2 thorpej continue;
274 1.12 thorpej #endif
275 1.12 thorpej
276 1.2 thorpej if (cfe->num_iospace != 1)
277 1.2 thorpej continue;
278 1.2 thorpej
279 1.2 thorpej if (cfe->iomask == 3) {
280 1.2 thorpej if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
281 1.2 thorpej cfe->iospace[0].length, &psc->sc_pcioh)) {
282 1.2 thorpej continue;
283 1.2 thorpej }
284 1.2 thorpej } else {
285 1.2 thorpej if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
286 1.2 thorpej cfe->iospace[0].length, 0, &psc->sc_pcioh)) {
287 1.2 thorpej continue;
288 1.2 thorpej }
289 1.2 thorpej }
290 1.2 thorpej
291 1.2 thorpej break;
292 1.2 thorpej }
293 1.2 thorpej
294 1.2 thorpej if (!cfe) {
295 1.2 thorpej printf(": can't allocate i/o space\n");
296 1.2 thorpej return;
297 1.2 thorpej }
298 1.2 thorpej
299 1.2 thorpej sc->sc_iot = psc->sc_pcioh.iot;
300 1.2 thorpej sc->sc_ioh = psc->sc_pcioh.ioh;
301 1.2 thorpej
302 1.2 thorpej /* Enable the card. */
303 1.2 thorpej pcmcia_function_init(pa->pf, cfe);
304 1.5 christos if (com_pcmcia_enable1(sc))
305 1.2 thorpej printf(": function enable failed\n");
306 1.2 thorpej
307 1.3 marc sc->enabled = 1;
308 1.2 thorpej
309 1.2 thorpej /* map in the io space */
310 1.2 thorpej
311 1.2 thorpej if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
312 1.2 thorpej PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), 0, psc->sc_pcioh.size,
313 1.2 thorpej &psc->sc_pcioh, &psc->sc_io_window)) {
314 1.2 thorpej printf(": can't map i/o space\n");
315 1.2 thorpej return;
316 1.2 thorpej }
317 1.2 thorpej
318 1.2 thorpej sc->sc_iobase = -1;
319 1.2 thorpej sc->sc_frequency = COM_FREQ;
320 1.2 thorpej
321 1.3 marc sc->enable = com_pcmcia_enable;
322 1.3 marc sc->disable = com_pcmcia_disable;
323 1.3 marc
324 1.5 christos if ((comdev = com_dev_match(pa->card)) != NULL)
325 1.5 christos printf(": %s", comdev->name);
326 1.11 nathanw else
327 1.11 nathanw printf(": Generic serial device");
328 1.5 christos
329 1.2 thorpej com_attach_subr(sc);
330 1.2 thorpej
331 1.3 marc sc->enabled = 0;
332 1.3 marc
333 1.5 christos com_pcmcia_disable1(sc);
334 1.3 marc }
335 1.3 marc
336 1.5 christos int
337 1.5 christos com_pcmcia_enable(sc)
338 1.5 christos struct com_softc *sc;
339 1.3 marc {
340 1.3 marc struct com_pcmcia_softc *psc = (struct com_pcmcia_softc *) sc;
341 1.3 marc struct pcmcia_function *pf = psc->sc_pf;
342 1.2 thorpej
343 1.2 thorpej /* establish the interrupt. */
344 1.3 marc psc->sc_ih = pcmcia_intr_establish(pf, IPL_SERIAL, comintr, sc);
345 1.2 thorpej if (psc->sc_ih == NULL) {
346 1.2 thorpej printf("%s: couldn't establish interrupt\n",
347 1.2 thorpej sc->sc_dev.dv_xname);
348 1.3 marc return (1);
349 1.3 marc }
350 1.5 christos return com_pcmcia_enable1(sc);
351 1.5 christos }
352 1.5 christos
353 1.5 christos int
354 1.5 christos com_pcmcia_enable1(sc)
355 1.5 christos struct com_softc *sc;
356 1.5 christos {
357 1.5 christos struct com_pcmcia_softc *psc = (struct com_pcmcia_softc *) sc;
358 1.5 christos struct pcmcia_function *pf = psc->sc_pf;
359 1.5 christos int ret;
360 1.3 marc
361 1.3 marc if ((ret = pcmcia_function_enable(pf)))
362 1.3 marc return(ret);
363 1.3 marc
364 1.3 marc if (psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3C562) {
365 1.3 marc int reg;
366 1.3 marc
367 1.3 marc /* turn off the ethernet-disable bit */
368 1.3 marc
369 1.3 marc reg = pcmcia_ccr_read(pf, PCMCIA_CCR_OPTION);
370 1.3 marc if (reg & 0x08) {
371 1.3 marc reg &= ~0x08;
372 1.3 marc pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
373 1.3 marc }
374 1.2 thorpej }
375 1.3 marc
376 1.3 marc return(ret);
377 1.3 marc }
378 1.3 marc
379 1.5 christos void
380 1.5 christos com_pcmcia_disable(sc)
381 1.5 christos struct com_softc *sc;
382 1.5 christos {
383 1.5 christos struct com_pcmcia_softc *psc = (struct com_pcmcia_softc *) sc;
384 1.5 christos
385 1.5 christos com_pcmcia_disable1(sc);
386 1.5 christos pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
387 1.5 christos }
388 1.5 christos
389 1.5 christos void
390 1.5 christos com_pcmcia_disable1(sc)
391 1.5 christos struct com_softc *sc;
392 1.3 marc {
393 1.3 marc struct com_pcmcia_softc *psc = (struct com_pcmcia_softc *) sc;
394 1.3 marc
395 1.3 marc pcmcia_function_disable(psc->sc_pf);
396 1.2 thorpej }
397