1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/* $NetBSD: com_pcmcia.c,v 1.62 2018/12/08 17:46:14 thorpej Exp $ */
/*-
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)com.c 7.5 (Berkeley) 5/16/91
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: com_pcmcia.c,v 1.62 2018/12/08 17:46:14 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/tty.h>
#include <sys/proc.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/syslog.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/bus.h>
#include <dev/pcmcia/pcmciavar.h>
#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciadevs.h>
#include <dev/ic/comreg.h>
#include <dev/ic/comvar.h>
#include <dev/isa/isareg.h>
int com_pcmcia_match(device_t, cfdata_t , void *);
int com_pcmcia_validate_config(struct pcmcia_config_entry *);
void com_pcmcia_attach(device_t, device_t, void *);
int com_pcmcia_detach(device_t, int);
int com_pcmcia_enable(struct com_softc *);
void com_pcmcia_disable(struct com_softc *);
struct com_pcmcia_softc {
struct com_softc sc_com; /* real "com" softc */
/* PCMCIA-specific goo */
struct pcmcia_function *sc_pf; /* our PCMCIA function */
void *sc_ih; /* interrupt handler */
int sc_attached;
};
CFATTACH_DECL_NEW(com_pcmcia, sizeof(struct com_pcmcia_softc),
com_pcmcia_match, com_pcmcia_attach, com_pcmcia_detach, NULL);
static const struct pcmcia_product com_pcmcia_products[] = {
{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
PCMCIA_CIS_MEGAHERTZ_XJ2288 },
{ PCMCIA_VENDOR_TDK, PCMCIA_PRODUCT_TDK_BLUETOOTH_PCCARD,
PCMCIA_CIS_INVALID },
};
static const size_t com_pcmcia_nproducts =
sizeof(com_pcmcia_products) / sizeof(com_pcmcia_products[0]);
int
com_pcmcia_match(device_t parent, cfdata_t match, void *aux)
{
int comportmask;
struct pcmcia_attach_args *pa = aux;
struct pcmcia_config_entry *cfe;
/* 1. Does it claim to be a serial device? */
if (pa->pf->function == PCMCIA_FUNCTION_SERIAL)
return 1;
/* 2. Does it have all four 'standard' port ranges? */
comportmask = 0;
SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
switch (cfe->iospace[0].start) {
case IO_COM1:
comportmask |= 1;
break;
case IO_COM2:
comportmask |= 2;
break;
case IO_COM3:
comportmask |= 4;
break;
case IO_COM4:
comportmask |= 8;
break;
}
}
if (comportmask == 15)
return 1;
/* 3. Is this a card we know about? */
if (pcmcia_product_lookup(pa, com_pcmcia_products, com_pcmcia_nproducts,
sizeof(com_pcmcia_products[0]), NULL))
return 1;
return 0;
}
int
com_pcmcia_validate_config(struct pcmcia_config_entry *cfe)
{
if (cfe->iftype != PCMCIA_IFTYPE_IO ||
cfe->num_iospace != 1)
return (EINVAL);
/* Some cards have a memory space, but we don't use it. */
cfe->num_memspace = 0;
return (0);
}
void
com_pcmcia_attach(device_t parent, device_t self, void *aux)
{
struct com_pcmcia_softc *psc = device_private(self);
struct com_softc *sc = &psc->sc_com;
struct pcmcia_attach_args *pa = aux;
struct pcmcia_config_entry *cfe;
int error;
sc->sc_dev = self;
psc->sc_pf = pa->pf;
error = pcmcia_function_configure(pa->pf, com_pcmcia_validate_config);
if (error) {
aprint_error_dev(self, "configure failed, error=%d\n", error);
return;
}
cfe = pa->pf->cfe;
com_init_regs(&sc->sc_regs, cfe->iospace[0].handle.iot,
cfe->iospace[0].handle.ioh, -1);
error = com_pcmcia_enable(sc);
if (error)
goto fail;
sc->enabled = 1;
sc->sc_frequency = COM_FREQ;
sc->enable = com_pcmcia_enable;
sc->disable = com_pcmcia_disable;
aprint_normal("%s", device_xname(self));
com_attach_subr(sc);
if (!pmf_device_register1(self, com_suspend, com_resume,
com_cleanup))
aprint_error_dev(self, "couldn't establish power handler\n");
sc->enabled = 0;
psc->sc_attached = 1;
com_pcmcia_disable(sc);
return;
fail:
pcmcia_function_unconfigure(pa->pf);
}
int
com_pcmcia_detach(device_t self, int flags)
{
struct com_pcmcia_softc *psc = device_private(self);
int error;
if (!psc->sc_attached)
return (0);
if ((error = com_detach(self, flags)) != 0)
return error;
pmf_device_deregister(self);
pcmcia_function_unconfigure(psc->sc_pf);
return (0);
}
int
com_pcmcia_enable(struct com_softc *sc)
{
struct com_pcmcia_softc *psc = (struct com_pcmcia_softc *) sc;
struct pcmcia_function *pf = psc->sc_pf;
int error;
/* establish the interrupt. */
psc->sc_ih = pcmcia_intr_establish(pf, IPL_SERIAL, comintr, sc);
if (psc->sc_ih == NULL) {
aprint_error_dev(sc->sc_dev, "couldn't establish interrupt\n");
return (1);
}
if ((error = pcmcia_function_enable(pf)) != 0) {
pcmcia_intr_disestablish(pf, psc->sc_ih);
psc->sc_ih = 0;
return (error);
}
if ((psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3C562) ||
(psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3CXEM556) ||
(psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3CXEM556INT)) {
int reg;
/* turn off the ethernet-disable bit */
reg = pcmcia_ccr_read(pf, PCMCIA_CCR_OPTION);
if (reg & 0x08) {
reg &= ~0x08;
pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
}
}
return (0);
}
void
com_pcmcia_disable(struct com_softc *sc)
{
struct com_pcmcia_softc *psc = (struct com_pcmcia_softc *) sc;
pcmcia_function_disable(psc->sc_pf);
pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
psc->sc_ih = 0;
}
|