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