1 /* $NetBSD: com_pcmcia.c,v 1.60 2009/11/12 20:29:30 dyoung Exp $ */
4 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1991 The Regents of the University of California.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)com.c 7.5 (Berkeley) 5/16/91
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: com_pcmcia.c,v 1.60 2009/11/12 20:29:30 dyoung Exp $");
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/ioctl.h>
69 #include <sys/select.h>
75 #include <sys/kernel.h>
76 #include <sys/syslog.h>
77 #include <sys/device.h>
82 #include <dev/pcmcia/pcmciavar.h>
83 #include <dev/pcmcia/pcmciareg.h>
84 #include <dev/pcmcia/pcmciadevs.h>
86 #include <dev/ic/comreg.h>
87 #include <dev/ic/comvar.h>
89 #include <dev/isa/isareg.h>
91 int com_pcmcia_match(device_t
, cfdata_t
, void *);
92 int com_pcmcia_validate_config(struct pcmcia_config_entry
*);
93 void com_pcmcia_attach(device_t
, device_t
, void *);
94 int com_pcmcia_detach(device_t
, int);
96 int com_pcmcia_enable(struct com_softc
*);
97 void com_pcmcia_disable(struct com_softc
*);
99 struct com_pcmcia_softc
{
100 struct com_softc sc_com
; /* real "com" softc */
102 /* PCMCIA-specific goo */
103 struct pcmcia_function
*sc_pf
; /* our PCMCIA function */
104 void *sc_ih
; /* interrupt handler */
108 CFATTACH_DECL_NEW(com_pcmcia
, sizeof(struct com_pcmcia_softc
),
109 com_pcmcia_match
, com_pcmcia_attach
, com_pcmcia_detach
, NULL
);
111 static const struct pcmcia_product com_pcmcia_products
[] = {
112 { PCMCIA_VENDOR_INVALID
, PCMCIA_PRODUCT_INVALID
,
113 PCMCIA_CIS_MEGAHERTZ_XJ2288
},
114 { PCMCIA_VENDOR_TDK
, PCMCIA_PRODUCT_TDK_BLUETOOTH_PCCARD
,
115 PCMCIA_CIS_INVALID
},
117 static const size_t com_pcmcia_nproducts
=
118 sizeof(com_pcmcia_products
) / sizeof(com_pcmcia_products
[0]);
121 com_pcmcia_match(device_t parent
, cfdata_t match
, void *aux
)
124 struct pcmcia_attach_args
*pa
= aux
;
125 struct pcmcia_config_entry
*cfe
;
127 /* 1. Does it claim to be a serial device? */
128 if (pa
->pf
->function
== PCMCIA_FUNCTION_SERIAL
)
131 /* 2. Does it have all four 'standard' port ranges? */
133 SIMPLEQ_FOREACH(cfe
, &pa
->pf
->cfe_head
, cfe_list
) {
134 switch (cfe
->iospace
[0].start
) {
150 if (comportmask
== 15)
153 /* 3. Is this a card we know about? */
154 if (pcmcia_product_lookup(pa
, com_pcmcia_products
, com_pcmcia_nproducts
,
155 sizeof(com_pcmcia_products
[0]), NULL
))
162 com_pcmcia_validate_config(struct pcmcia_config_entry
*cfe
)
164 if (cfe
->iftype
!= PCMCIA_IFTYPE_IO
||
165 cfe
->num_iospace
!= 1)
167 /* Some cards have a memory space, but we don't use it. */
168 cfe
->num_memspace
= 0;
173 com_pcmcia_attach(device_t parent
, device_t self
, void *aux
)
175 struct com_pcmcia_softc
*psc
= device_private(self
);
176 struct com_softc
*sc
= &psc
->sc_com
;
177 struct pcmcia_attach_args
*pa
= aux
;
178 struct pcmcia_config_entry
*cfe
;
184 error
= pcmcia_function_configure(pa
->pf
, com_pcmcia_validate_config
);
186 aprint_error_dev(self
, "configure failed, error=%d\n", error
);
191 COM_INIT_REGS(sc
->sc_regs
, cfe
->iospace
[0].handle
.iot
,
192 cfe
->iospace
[0].handle
.ioh
, -1);
194 error
= com_pcmcia_enable(sc
);
200 sc
->sc_frequency
= COM_FREQ
;
202 sc
->enable
= com_pcmcia_enable
;
203 sc
->disable
= com_pcmcia_disable
;
205 aprint_normal("%s", device_xname(self
));
209 if (!pmf_device_register1(self
, com_suspend
, com_resume
,
211 aprint_error_dev(self
, "couldn't establish power handler\n");
215 psc
->sc_attached
= 1;
216 com_pcmcia_disable(sc
);
220 pcmcia_function_unconfigure(pa
->pf
);
224 com_pcmcia_detach(device_t self
, int flags
)
226 struct com_pcmcia_softc
*psc
= device_private(self
);
229 if (!psc
->sc_attached
)
232 if ((error
= com_detach(self
, flags
)) != 0)
235 pmf_device_deregister(self
);
237 pcmcia_function_unconfigure(psc
->sc_pf
);
242 com_pcmcia_enable(struct com_softc
*sc
)
244 struct com_pcmcia_softc
*psc
= (struct com_pcmcia_softc
*) sc
;
245 struct pcmcia_function
*pf
= psc
->sc_pf
;
248 /* establish the interrupt. */
249 psc
->sc_ih
= pcmcia_intr_establish(pf
, IPL_SERIAL
, comintr
, sc
);
250 if (psc
->sc_ih
== NULL
) {
251 aprint_error_dev(sc
->sc_dev
, "couldn't establish interrupt\n");
255 if ((error
= pcmcia_function_enable(pf
)) != 0) {
256 pcmcia_intr_disestablish(pf
, psc
->sc_ih
);
261 if ((psc
->sc_pf
->sc
->card
.product
== PCMCIA_PRODUCT_3COM_3C562
) ||
262 (psc
->sc_pf
->sc
->card
.product
== PCMCIA_PRODUCT_3COM_3CXEM556
) ||
263 (psc
->sc_pf
->sc
->card
.product
== PCMCIA_PRODUCT_3COM_3CXEM556INT
)) {
266 /* turn off the ethernet-disable bit */
267 reg
= pcmcia_ccr_read(pf
, PCMCIA_CCR_OPTION
);
270 pcmcia_ccr_write(pf
, PCMCIA_CCR_OPTION
, reg
);
278 com_pcmcia_disable(struct com_softc
*sc
)
280 struct com_pcmcia_softc
*psc
= (struct com_pcmcia_softc
*) sc
;
282 pcmcia_function_disable(psc
->sc_pf
);
283 pcmcia_intr_disestablish(psc
->sc_pf
, psc
->sc_ih
);