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