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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
/*
* Copyright (c) 2000 Hans Petter Selasky. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
*---------------------------------------------------------------------------
*
* i4b_ihfc_pnp.c - common hfc ISA PnP-bus interface
* -------------------------------------------------
*
* - Everything which has got anything to to with "PnP" bus setup has
* been put here.
*
*
* last edit-date: [Wed Jul 19 09:41:07 2000]
*
* $Id: i4b_ihfc_pnp.c,v 1.9 2000/09/19 13:50:36 hm Exp $
*
* $FreeBSD$
*
*---------------------------------------------------------------------------*/
#include "ihfc.h"
#if (NIHFC > 0)
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/socket.h>
#include <net/if.h>
#include <i4b/include/i4b_global.h>
#include <machine/i4b_ioctl.h>
#include <machine/i4b_trace.h>
#include <i4b/layer1/i4b_l1.h>
#include <i4b/layer1/ihfc/i4b_ihfc.h>
#include <i4b/layer1/ihfc/i4b_ihfc_ext.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/bus.h>
#include <sys/rman.h>
#include <isa/isavar.h>
/*---------------------------------------------------------------------------*
* Softc
*---------------------------------------------------------------------------*/
ihfc_sc_t ihfc_softc[IHFC_MAXUNIT];
/*---------------------------------------------------------------------------*
* Prototypes
*---------------------------------------------------------------------------*/
static int ihfc_isa_probe (device_t dev);
static int ihfc_pnp_probe (device_t dev);
static int ihfc_pnp_attach (device_t dev);
static int ihfc_pnp_detach (device_t dev, u_int flag);
static int ihfc_pnp_shutdown (device_t dev);
const struct ihfc_pnp_ids
{
u_long vid; /* vendor id */
int flag; /* */
u_char hfc; /* chip type */
u_char iirq; /* internal irq */
u_short iio; /* internal io-address */
u_char stdel; /* S/T delay compensation */
}
ihfc_pnp_ids[] =
{
{ 0x10262750, FLAG_TELES_S0_163C, HFC_S , 2, 0x200 , 0xd},
{ 0x20262750, FLAG_TELES_S0_163C, HFC_SP, 0, 0x000 , 0xf},
{ 0x1411d805, FLAG_ACER_P10 , HFC_S , 1, 0x300 , 0xe},
{ 0 }
};
typedef const struct ihfc_pnp_ids ihfc_id_t;
/*---------------------------------------------------------------------------*
* PCB layout
*
* IIRQx: Internal IRQ cross reference for a card
* IRQx : Supported IRQ's for a card
* IOx : Supported IO-bases for a card
*
* IO0, IRQ0, IIRQ0: TELEINT ISDN SPEED No. 1
* IIRQ3: Teles 16.3c PnP (B version)
*---------------------------------------------------------------------------*/
/* IRQ -> 0 1 2 3 4 5 6 7 8 9 a b c d e f */
#define IIRQ0 ((const u_char []){ 0, 0, 0, 1, 2, 3, 0, 4, 0, 0, 5, 6, 0, 0, 0, 0 })
#define IRQ0 ((const u_char []){ 3, 4, 5, 7, 0xa, 0xb, 0 })
#define IO0 ((const u_long []){ 0x300, 0x330, 0x278, 0x2e8, 0 })
#define IIRQ3 ((const u_char []){ 0, 0, 0, 7, 0, 1, 0, 0, 0, 2, 3, 4, 5, 0, 0, 6 })
/*---------------------------------------------------------------------------*
* ISA PnP setup
*---------------------------------------------------------------------------*/
static device_method_t ihfc_pnp_methods[] =
{
DEVMETHOD(device_probe, ihfc_pnp_probe),
DEVMETHOD(device_attach, ihfc_pnp_attach),
DEVMETHOD(device_shutdown, ihfc_pnp_shutdown),
{ 0, 0 }
};
static driver_t ihfc_pnp_driver =
{
"ihfc",
ihfc_pnp_methods,
0,
};
static devclass_t ihfc_devclass;
DRIVER_MODULE(ihfcpnp, isa, ihfc_pnp_driver, ihfc_devclass, 0, 0);
/*---------------------------------------------------------------------------*
* probe for ISA "PnP" card
*---------------------------------------------------------------------------*/
int
ihfc_pnp_probe(device_t dev)
{
u_int unit = device_get_unit(dev); /* get unit */
u_int32_t vid = isa_get_vendorid(dev); /* vendor id */
ihfc_id_t *ids = &ihfc_pnp_ids[0]; /* ids ptr */
ihfc_sc_t *sc = &ihfc_softc[unit]; /* softc */
HFC_VAR;
if (unit >= IHFC_MAXUNIT)
{
printf("ihfc%d: Error, unit %d >= IHFC_MAXUNIT", unit, unit);
return ENXIO;
}
if (!vid) return ihfc_isa_probe(dev);
HFC_BEG;
for ( ;(ids->vid); ids++)
{
if (ids->vid == vid)
{
bzero(sc, sizeof(ihfc_sc_t)); /* reset data structure */
S_IOBASE[0] = bus_alloc_resource(
dev, SYS_RES_IOPORT, &S_IORID[0],
0UL, ~0UL, 2, RF_ACTIVE
);
S_IRQ = bus_alloc_resource(
dev, SYS_RES_IRQ, &S_IRQRID,
0UL, ~0UL, 1, RF_ACTIVE
);
S_DLP = IHFC_DLP; /* set D-priority */
S_HFC = ids->hfc; /* set chip type */
S_I4BFLAG = ids->flag; /* set flag */
S_NTMODE = IHFC_NTMODE; /* set mode */
S_STDEL = ids->stdel; /* set delay */
S_I4BUNIT = L0IHFCUNIT(unit); /* set "i4b" unit */
S_TRACE = TRACE_OFF; /* set trace mask */
S_UNIT = unit; /* set up unit numbers */
if (S_IOBASE[0] && S_IRQ)
{
if (ids->iio)
{
S_IIO = ids->iio;
S_IIRQ = ids->iirq;
}
else
{
S_IIO = rman_get_start(S_IOBASE[0]) & 0x3ff;
S_IIRQ = IIRQ3[rman_get_start(S_IRQ) & 0xf];
}
if (!HFC_CONTROL(sc, 1))
{
HFC_END;
return 0; /* success */
}
else
{
printf("ihfc%d: Chip seems corrupted. "
"Please hard reboot your computer!\n",
unit);
}
}
ihfc_pnp_detach(dev, 0);
}
}
HFC_END;
return ENXIO; /* failure */
}
/*---------------------------------------------------------------------------*
* probe for "ISA" cards
*---------------------------------------------------------------------------*/
int
ihfc_isa_probe(device_t dev)
{
u_int unit = device_get_unit(dev); /* get unit */
ihfc_sc_t *sc = &ihfc_softc[unit]; /* softc */
const u_char *irq = &IRQ0[0]; /* irq's to try */
const u_long *iobase = &IO0[0]; /* iobases to try */
HFC_VAR;
bzero(sc, sizeof(ihfc_sc_t)); /* reset data structure *
* We must reset the *
* datastructure here, *
* else we risk zero-out *
* our gotten resources. */
HFC_BEG;
j0: while(*irq) /* get supported IRQ */
{
if ((S_IRQ = bus_alloc_resource(
dev, SYS_RES_IRQ, &S_IRQRID,
*irq, *irq, 1, RF_ACTIVE
)
))
break;
else
irq++;
}
while(*iobase) /* get supported IO-PORT */
{
if ((S_IOBASE[0] = bus_alloc_resource(
dev, SYS_RES_IOPORT, &S_IORID[0],
*iobase, *iobase, 2, RF_ACTIVE
)
))
break;
else
iobase++;
}
if (*irq && *iobase) /* we got our resources, now test chip */
{
S_DLP = IHFC_DLP; /* set D-priority */
S_HFC = HFC_1; /* set chip type */
S_I4BFLAG = FLAG_TELEINT_NO_1; /* set flag */
S_NTMODE = IHFC_NTMODE; /* set mode */
S_STDEL = 0x00; /* set delay (not used) */
S_I4BUNIT = L0IHFCUNIT(unit); /* set "i4b" unit */
S_TRACE = TRACE_OFF; /* set trace mask */
S_UNIT = unit; /* set up unit numbers */
S_IIRQ = IIRQ0[*irq]; /* set internal irq */
S_IIO = *iobase; /* set internal iobase */
if (!HFC_CONTROL(sc, 1))
{
device_set_desc(dev, "TELEINT ISDN SPEED No. 1");
HFC_END;
return 0; /* success */
}
}
ihfc_pnp_detach(dev, 0);
if (*irq && *++iobase) goto j0; /* try again */
HFC_END;
printf("ihfc%d: Chip not found. "
"A hard reboot may help!\n", unit);
return ENXIO; /* failure */
}
/*---------------------------------------------------------------------------*
* attach ISA "PnP" card
*---------------------------------------------------------------------------*/
int
ihfc_pnp_attach(device_t dev)
{
u_int unit = device_get_unit(dev); /* get unit */
ihfc_sc_t *sc = &ihfc_softc[unit]; /* softc */
void *dummy = 0; /* a dummy */
HFC_VAR;
HFC_BEG;
ihfc_B_linkinit(sc); /* Setup B-Channel linktabs */
i4b_l1_mph_status_ind(S_I4BUNIT, STI_ATTACH, S_I4BFLAG, &ihfc_l1mux_func);
HFC_INIT(sc, 0, 0, 1); /* Setup D - Channel */
HFC_INIT(sc, 2, 0, 0); /* Init B1 - Channel */
HFC_INIT(sc, 4, 0, 0); /* Init B2 - Channel */
bus_setup_intr(dev, S_IRQ, INTR_TYPE_NET, (void(*)(void*))
HFC_INTR, sc, &dummy);
HFC_END;
return 0; /* success */
HFC_END;
return ENXIO; /* failure */
}
/*---------------------------------------------------------------------------*
* shutdown for our ISA PnP card
*---------------------------------------------------------------------------*/
int
ihfc_pnp_shutdown(device_t dev)
{
u_int unit = device_get_unit(dev); /* get unit */
ihfc_sc_t *sc = &ihfc_softc[unit]; /* softc */
HFC_VAR;
HFC_BEG;
if (unit >= IHFC_MAXUNIT)
{
printf("ihfc%d: Error, unit %d >= IHFC_MAXUNIT", unit, unit);
goto f0;
}
HFC_CONTROL(sc, 2); /* shutdown chip */
HFC_END;
return 0;
f0:
HFC_END;
return ENXIO;
}
/*---------------------------------------------------------------------------*
* detach for our ISA PnP card
*
* flag: bit[0] set: teardown interrupt handler too
*---------------------------------------------------------------------------*/
int
ihfc_pnp_detach (device_t dev, u_int flag)
{
u_int unit = device_get_unit(dev); /* get unit */
ihfc_sc_t *sc = &ihfc_softc[unit]; /* softc */
u_char i;
if (unit >= IHFC_MAXUNIT)
{
printf("ihfc%d: Error, unit %d >= IHFC_MAXUNIT", unit, unit);
return 0;
}
/* free interrupt resources */
if(S_IRQ)
{
if (flag & 1)
{
/* tear down interrupt handler */
bus_teardown_intr(dev, S_IRQ, (void(*)(void *))HFC_INTR);
}
/* free irq */
bus_release_resource(dev, SYS_RES_IRQ, S_IRQRID, S_IRQ);
S_IRQRID = 0;
S_IRQ = 0;
}
/* free iobases */
for (i = IHFC_IO_BASES; i--;)
{
if(S_IOBASE[i])
{
bus_release_resource(dev, SYS_RES_IOPORT,
S_IORID[i], S_IOBASE[i]);
S_IORID[i] = 0;
S_IOBASE[i] = 0;
}
}
return 0;
}
#endif /* NIHFC > 0 */
|