com_pcmcia.c revision 1.1.2.5 1 /* $NetBSD: com_pcmcia.c,v 1.1.2.5 1997/08/02 04:30:38 matt Exp $ */
2
3 /*-
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Charles M. Hannum. All rights reserved.
6 * Copyright (c) 1991 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)com.c 7.5 (Berkeley) 5/16/91
38 */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/ioctl.h>
43 #include <sys/select.h>
44 #include <sys/tty.h>
45 #include <sys/proc.h>
46 #include <sys/user.h>
47 #include <sys/conf.h>
48 #include <sys/file.h>
49 #include <sys/uio.h>
50 #include <sys/kernel.h>
51 #include <sys/syslog.h>
52 #include <sys/types.h>
53 #include <sys/device.h>
54
55 #include <machine/intr.h>
56 #include <machine/bus.h>
57
58 #include <dev/pcmcia/pcmciavar.h>
59 #include <dev/pcmcia/pcmciareg.h>
60
61 #include <dev/isa/comvar.h>
62 #include <dev/isa/isareg.h>
63
64 #define PCMCIA_MANUFACTURER_3COM 0x101
65 #define PCMCIA_PRODUCT_3COM_3C562 0x562
66
67 #define PCMCIA_MANUFACTURER_MOTOROLA 0x109
68 #define PCMCIA_PRODUCT_MOTOROLA_POWER144 0x105
69
70 #ifdef __BROKEN_INDIRECT_CONFIG
71 int com_pcmcia_match __P((struct device *, void *, void *));
72 #else
73 int com_pcmcia_match __P((struct device *, struct cfdata *, void *));
74 #endif
75 void com_pcmcia_attach __P((struct device *, struct device *, void *));
76 void com_pcmcia_cleanup __P((void *));
77
78 struct cfattach com_pcmcia_ca = {
79 sizeof(struct com_softc), com_pcmcia_match, com_pcmcia_attach
80 };
81
82 int
83 com_pcmcia_match(parent, match, aux)
84 struct device *parent;
85 #ifdef __BROKEN_INDIRECT_CONFIG
86 void *match;
87 #else
88 struct cfdata *match;
89 #endif
90 void *aux;
91 {
92 struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
93 struct pcmcia_config_entry *cfe;
94
95 if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
96 (pa->product == PCMCIA_PRODUCT_3COM_3C562) &&
97 (pa->pf->number == 1))
98 return(1);
99
100 if ((pa->manufacturer == PCMCIA_MANUFACTURER_MOTOROLA) &&
101 (pa->product == PCMCIA_PRODUCT_MOTOROLA_POWER144) &&
102 (pa->pf->number == 0))
103 return(1);
104
105 /* find a cfe we can use (if it matches a standard COM port) */
106
107 for (cfe = pa->pf->cfe_head.sqh_first; cfe;
108 cfe = cfe->cfe_list.sqe_next) {
109 if (cfe->iospace[0].start == IO_COM1 ||
110 cfe->iospace[0].start == IO_COM2 ||
111 cfe->iospace[0].start == IO_COM3 ||
112 cfe->iospace[0].start == IO_COM4)
113 return(1);
114 }
115
116 return(0);
117 }
118
119 void
120 com_pcmcia_attach(parent, self, aux)
121 struct device *parent, *self;
122 void *aux;
123 {
124 struct com_softc *sc = (void *) self;
125 struct pcmcia_attach_args *pa = aux;
126 struct pcmcia_config_entry *cfe;
127 char *model;
128
129 /* find a cfe we can use */
130
131 for (cfe = pa->pf->cfe_head.sqh_first; cfe;
132 cfe = cfe->cfe_list.sqe_next) {
133 if (cfe->num_memspace != 0)
134 continue;
135
136 if (cfe->num_iospace != 1)
137 continue;
138
139 if (cfe->iomask == 3) {
140 if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
141 &sc->sc_iot, &sc->sc_ioh)) {
142 continue;
143 }
144 } else {
145 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
146 cfe->iospace[0].length,
147 &sc->sc_iot, &sc->sc_ioh)) {
148 continue;
149 }
150 }
151
152 break;
153 }
154
155 if (!cfe) {
156 printf(": can't allocate i/o space\n");
157 return;
158 }
159
160 /* Enable the card. */
161 if (pcmcia_enable_function(pa->pf, parent, cfe))
162 printf(": function enable failed\n");
163
164 /* turn off the bit which disables the ethernet */
165 if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
166 int reg;
167
168 reg = pcmcia_ccr_read(pa->pf, PCMCIA_CCR_OPTION);
169 reg &= ~0x08;
170 pcmcia_ccr_write(pa->pf, PCMCIA_CCR_OPTION, reg);
171 }
172
173 /* map in the io space */
174
175 if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16)?
176 PCMCIA_WIDTH_IO16:PCMCIA_WIDTH_IO8),
177 cfe->iospace[0].length,
178 sc->sc_iot, sc->sc_ioh, &sc->pcmcia_window)) {
179 printf(": can't map i/o space\n");
180 return;
181 }
182
183 sc->sc_iobase = -1;
184
185 com_attach_subr(sc);
186
187 switch (pa->product) {
188 case PCMCIA_PRODUCT_3COM_3C562:
189 model = "3Com 3C562 Modem";
190 break;
191 case PCMCIA_PRODUCT_MOTOROLA_POWER144:
192 model = "Motorola Power 14.4 Modem";
193 break;
194 default:
195 model = "Unknown serial device";
196 break;
197 }
198
199 printf(": %s\n", model);
200
201 /* establish the interrupt. */
202 sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_SERIAL, comintr, sc);
203 if (sc->sc_ih == NULL) {
204 printf("%s: couldn't establish interrupt\n",
205 sc->sc_dev.dv_xname);
206 return;
207 }
208 }
209