com_pcmcia.c revision 1.1.2.3 1 1.1.2.3 thorpej /* $NetBSD: com_pcmcia.c,v 1.1.2.3 1997/07/30 18:00:27 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.1 marc #include <dev/isa/comvar.h>
62 1.1.2.1 marc
63 1.1.2.1 marc #define PCMCIA_MANUFACTURER_3COM 0x101
64 1.1.2.1 marc #define PCMCIA_PRODUCT_3COM_3C562 0x562
65 1.1.2.1 marc
66 1.1.2.1 marc #define PCMCIA_MANUFACTURER_MOTOROLA 0x109
67 1.1.2.1 marc #define PCMCIA_PRODUCT_MOTOROLA_POWER144 0x105
68 1.1.2.1 marc
69 1.1.2.3 thorpej #ifdef __BROKEN_INDIRECT_CONFIG
70 1.1.2.1 marc int com_pcmcia_match __P((struct device *, void *, void *));
71 1.1.2.1 marc #else
72 1.1.2.1 marc int com_pcmcia_match __P((struct device *, struct cfdata *, void *));
73 1.1.2.1 marc #endif
74 1.1.2.1 marc void com_pcmcia_attach __P((struct device *, struct device *, void *));
75 1.1.2.1 marc void com_pcmcia_cleanup __P((void *));
76 1.1.2.1 marc
77 1.1.2.1 marc struct cfattach com_pcmcia_ca = {
78 1.1.2.1 marc sizeof(struct com_softc), com_pcmcia_match, com_pcmcia_attach
79 1.1.2.1 marc };
80 1.1.2.1 marc
81 1.1.2.1 marc int
82 1.1.2.1 marc com_pcmcia_match(parent, match, aux)
83 1.1.2.1 marc struct device *parent;
84 1.1.2.3 thorpej #ifdef __BROKEN_INDIRECT_CONFIG
85 1.1.2.1 marc void *match;
86 1.1.2.1 marc #else
87 1.1.2.1 marc struct cfdata *match;
88 1.1.2.1 marc #endif
89 1.1.2.1 marc void *aux;
90 1.1.2.1 marc {
91 1.1.2.1 marc struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
92 1.1.2.1 marc
93 1.1.2.1 marc printf("com_pcmcia_match: %x %x %d\n", pa->manufacturer,
94 1.1.2.1 marc pa->product, pa->pf->number);
95 1.1.2.1 marc
96 1.1.2.1 marc if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
97 1.1.2.1 marc (pa->product == PCMCIA_PRODUCT_3COM_3C562) &&
98 1.1.2.1 marc (pa->pf->number == 1))
99 1.1.2.1 marc return(1);
100 1.1.2.1 marc
101 1.1.2.1 marc if ((pa->manufacturer == PCMCIA_MANUFACTURER_MOTOROLA) &&
102 1.1.2.1 marc (pa->product == PCMCIA_PRODUCT_MOTOROLA_POWER144) &&
103 1.1.2.1 marc (pa->pf->number == 0))
104 1.1.2.1 marc return(1);
105 1.1.2.1 marc
106 1.1.2.1 marc return(0);
107 1.1.2.1 marc }
108 1.1.2.1 marc
109 1.1.2.1 marc void
110 1.1.2.1 marc com_pcmcia_attach(parent, self, aux)
111 1.1.2.1 marc struct device *parent, *self;
112 1.1.2.1 marc void *aux;
113 1.1.2.1 marc {
114 1.1.2.1 marc struct com_softc *sc = (void *) self;
115 1.1.2.1 marc struct pcmcia_attach_args *pa = aux;
116 1.1.2.1 marc struct pcmcia_config_entry *cfe;
117 1.1.2.1 marc char *model;
118 1.1.2.1 marc
119 1.1.2.1 marc /* find a cfe we can use */
120 1.1.2.1 marc
121 1.1.2.1 marc for (cfe = pa->pf->cfe_head.sqh_first; cfe;
122 1.1.2.1 marc cfe = cfe->cfe_list.sqe_next) {
123 1.1.2.1 marc if (cfe->num_memspace != 0)
124 1.1.2.1 marc continue;
125 1.1.2.1 marc
126 1.1.2.1 marc if (cfe->num_iospace != 1)
127 1.1.2.1 marc continue;
128 1.1.2.1 marc
129 1.1.2.1 marc if (cfe->iomask == 3) {
130 1.1.2.1 marc if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
131 1.1.2.1 marc &sc->sc_iot, &sc->sc_ioh)) {
132 1.1.2.1 marc continue;
133 1.1.2.1 marc }
134 1.1.2.1 marc } else {
135 1.1.2.1 marc if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
136 1.1.2.1 marc cfe->iospace[0].length,
137 1.1.2.1 marc &sc->sc_iot, &sc->sc_ioh)) {
138 1.1.2.1 marc continue;
139 1.1.2.1 marc }
140 1.1.2.1 marc }
141 1.1.2.1 marc
142 1.1.2.1 marc break;
143 1.1.2.1 marc }
144 1.1.2.1 marc
145 1.1.2.1 marc if (!cfe) {
146 1.1.2.1 marc printf(": can't allocate i/o space\n");
147 1.1.2.1 marc return;
148 1.1.2.1 marc }
149 1.1.2.1 marc
150 1.1.2.1 marc /* Enable the card. */
151 1.1.2.1 marc if (pcmcia_enable_function(pa->pf, parent, cfe))
152 1.1.2.1 marc printf(": function enable failed\n");
153 1.1.2.1 marc
154 1.1.2.1 marc /* turn off the bit which disables the ethernet */
155 1.1.2.1 marc if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
156 1.1.2.1 marc int reg;
157 1.1.2.1 marc
158 1.1.2.1 marc reg = pcmcia_ccr_read(pa->pf, PCMCIA_CCR_OPTION);
159 1.1.2.1 marc reg &= ~0x08;
160 1.1.2.1 marc pcmcia_ccr_write(pa->pf, PCMCIA_CCR_OPTION, reg);
161 1.1.2.1 marc }
162 1.1.2.1 marc
163 1.1.2.1 marc /* map in the io space */
164 1.1.2.1 marc
165 1.1.2.1 marc if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16)?
166 1.1.2.1 marc PCMCIA_WIDTH_IO16:PCMCIA_WIDTH_IO8),
167 1.1.2.1 marc cfe->iospace[0].length,
168 1.1.2.1 marc sc->sc_iot, sc->sc_ioh, &sc->pcmcia_window)) {
169 1.1.2.1 marc printf(": can't map i/o space\n");
170 1.1.2.1 marc return;
171 1.1.2.1 marc }
172 1.1.2.1 marc
173 1.1.2.1 marc sc->sc_iobase = -1;
174 1.1.2.1 marc
175 1.1.2.1 marc com_attach_subr(sc);
176 1.1.2.1 marc
177 1.1.2.1 marc switch (pa->product) {
178 1.1.2.1 marc case PCMCIA_PRODUCT_3COM_3C562:
179 1.1.2.1 marc model = "3Com 3C562 Modem";
180 1.1.2.1 marc break;
181 1.1.2.1 marc case PCMCIA_PRODUCT_MOTOROLA_POWER144:
182 1.1.2.1 marc model = "Motorola Power 14.4 Modem";
183 1.1.2.1 marc break;
184 1.1.2.1 marc default:
185 1.1.2.1 marc model = "Unknown serial device";
186 1.1.2.1 marc break;
187 1.1.2.1 marc }
188 1.1.2.1 marc
189 1.1.2.1 marc printf(": %s\n", model);
190 1.1.2.1 marc
191 1.1.2.1 marc /* establish the interrupt. */
192 1.1.2.1 marc sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_SERIAL, comintr, sc);
193 1.1.2.1 marc if (sc->sc_ih == NULL) {
194 1.1.2.1 marc printf("%s: couldn't establish interrupt\n",
195 1.1.2.1 marc sc->sc_dev.dv_xname);
196 1.1.2.1 marc return;
197 1.1.2.1 marc }
198 1.1.2.1 marc }
199