1 /* $Id: avm_pci.c,v 1.29.2.4 2004/02/11 13:21:32 keil Exp $
3 * low level stuff for AVM Fritz!PCI and ISA PnP isdn cards
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * Thanks to AVM, Berlin for information
15 #include <linux/init.h>
19 #include <linux/pci.h>
20 #include <linux/isapnp.h>
21 #include <linux/interrupt.h>
23 static const char *avm_pci_rev
= "$Revision: 1.29.2.4 $";
25 #define AVM_FRITZ_PCI 1
26 #define AVM_FRITZ_PNP 2
29 #define HDLC_STATUS 0x4
31 #define AVM_HDLC_1 0x00
32 #define AVM_HDLC_2 0x01
33 #define AVM_ISAC_FIFO 0x02
34 #define AVM_ISAC_REG_LOW 0x04
35 #define AVM_ISAC_REG_HIGH 0x06
37 #define AVM_STATUS0_IRQ_ISAC 0x01
38 #define AVM_STATUS0_IRQ_HDLC 0x02
39 #define AVM_STATUS0_IRQ_TIMER 0x04
40 #define AVM_STATUS0_IRQ_MASK 0x07
42 #define AVM_STATUS0_RESET 0x01
43 #define AVM_STATUS0_DIS_TIMER 0x02
44 #define AVM_STATUS0_RES_TIMER 0x04
45 #define AVM_STATUS0_ENA_IRQ 0x08
46 #define AVM_STATUS0_TESTBIT 0x10
48 #define AVM_STATUS1_INT_SEL 0x0f
49 #define AVM_STATUS1_ENA_IOM 0x80
51 #define HDLC_MODE_ITF_FLG 0x01
52 #define HDLC_MODE_TRANS 0x02
53 #define HDLC_MODE_CCR_7 0x04
54 #define HDLC_MODE_CCR_16 0x08
55 #define HDLC_MODE_TESTLOOP 0x80
57 #define HDLC_INT_XPR 0x80
58 #define HDLC_INT_XDU 0x40
59 #define HDLC_INT_RPR 0x20
60 #define HDLC_INT_MASK 0xE0
62 #define HDLC_STAT_RME 0x01
63 #define HDLC_STAT_RDO 0x10
64 #define HDLC_STAT_CRCVFRRAB 0x0E
65 #define HDLC_STAT_CRCVFR 0x06
66 #define HDLC_STAT_RML_MASK 0x3f00
68 #define HDLC_CMD_XRS 0x80
69 #define HDLC_CMD_XME 0x01
70 #define HDLC_CMD_RRS 0x20
71 #define HDLC_CMD_XML_MASK 0x3f00
74 /* Interface functions */
77 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
79 register u_char idx
= (offset
> 0x2f) ? AVM_ISAC_REG_HIGH
: AVM_ISAC_REG_LOW
;
82 outb(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
83 val
= inb(cs
->hw
.avm
.isac
+ (offset
& 0xf));
88 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
90 register u_char idx
= (offset
> 0x2f) ? AVM_ISAC_REG_HIGH
: AVM_ISAC_REG_LOW
;
92 outb(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
93 outb(value
, cs
->hw
.avm
.isac
+ (offset
& 0xf));
97 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
99 outb(AVM_ISAC_FIFO
, cs
->hw
.avm
.cfg_reg
+ 4);
100 insb(cs
->hw
.avm
.isac
, data
, size
);
104 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
106 outb(AVM_ISAC_FIFO
, cs
->hw
.avm
.cfg_reg
+ 4);
107 outsb(cs
->hw
.avm
.isac
, data
, size
);
111 ReadHDLCPCI(struct IsdnCardState
*cs
, int chan
, u_char offset
)
113 register u_int idx
= chan
? AVM_HDLC_2
: AVM_HDLC_1
;
116 outl(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
117 val
= inl(cs
->hw
.avm
.isac
+ offset
);
122 WriteHDLCPCI(struct IsdnCardState
*cs
, int chan
, u_char offset
, u_int value
)
124 register u_int idx
= chan
? AVM_HDLC_2
: AVM_HDLC_1
;
126 outl(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
127 outl(value
, cs
->hw
.avm
.isac
+ offset
);
131 ReadHDLCPnP(struct IsdnCardState
*cs
, int chan
, u_char offset
)
133 register u_char idx
= chan
? AVM_HDLC_2
: AVM_HDLC_1
;
136 outb(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
137 val
= inb(cs
->hw
.avm
.isac
+ offset
);
142 WriteHDLCPnP(struct IsdnCardState
*cs
, int chan
, u_char offset
, u_char value
)
144 register u_char idx
= chan
? AVM_HDLC_2
: AVM_HDLC_1
;
146 outb(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
147 outb(value
, cs
->hw
.avm
.isac
+ offset
);
151 ReadHDLC_s(struct IsdnCardState
*cs
, int chan
, u_char offset
)
153 return(0xff & ReadHDLCPCI(cs
, chan
, offset
));
157 WriteHDLC_s(struct IsdnCardState
*cs
, int chan
, u_char offset
, u_char value
)
159 WriteHDLCPCI(cs
, chan
, offset
, value
);
163 struct BCState
*Sel_BCS(struct IsdnCardState
*cs
, int channel
)
165 if (cs
->bcs
[0].mode
&& (cs
->bcs
[0].channel
== channel
))
167 else if (cs
->bcs
[1].mode
&& (cs
->bcs
[1].channel
== channel
))
174 write_ctrl(struct BCState
*bcs
, int which
) {
176 if (bcs
->cs
->debug
& L1_DEB_HSCX
)
177 debugl1(bcs
->cs
, "hdlc %c wr%x ctrl %x",
178 'A' + bcs
->channel
, which
, bcs
->hw
.hdlc
.ctrl
.ctrl
);
179 if (bcs
->cs
->subtyp
== AVM_FRITZ_PCI
) {
180 WriteHDLCPCI(bcs
->cs
, bcs
->channel
, HDLC_STATUS
, bcs
->hw
.hdlc
.ctrl
.ctrl
);
183 WriteHDLCPnP(bcs
->cs
, bcs
->channel
, HDLC_STATUS
+ 2,
184 bcs
->hw
.hdlc
.ctrl
.sr
.mode
);
186 WriteHDLCPnP(bcs
->cs
, bcs
->channel
, HDLC_STATUS
+ 1,
187 bcs
->hw
.hdlc
.ctrl
.sr
.xml
);
189 WriteHDLCPnP(bcs
->cs
, bcs
->channel
, HDLC_STATUS
,
190 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
);
195 modehdlc(struct BCState
*bcs
, int mode
, int bc
)
197 struct IsdnCardState
*cs
= bcs
->cs
;
198 int hdlc
= bcs
->channel
;
200 if (cs
->debug
& L1_DEB_HSCX
)
201 debugl1(cs
, "hdlc %c mode %d --> %d ichan %d --> %d",
202 'A' + hdlc
, bcs
->mode
, mode
, hdlc
, bc
);
203 bcs
->hw
.hdlc
.ctrl
.ctrl
= 0;
205 case (-1): /* used for init */
210 if (bcs
->mode
== L1_MODE_NULL
)
212 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= HDLC_CMD_XRS
| HDLC_CMD_RRS
;
213 bcs
->hw
.hdlc
.ctrl
.sr
.mode
= HDLC_MODE_TRANS
;
215 bcs
->mode
= L1_MODE_NULL
;
218 case (L1_MODE_TRANS
):
221 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= HDLC_CMD_XRS
| HDLC_CMD_RRS
;
222 bcs
->hw
.hdlc
.ctrl
.sr
.mode
= HDLC_MODE_TRANS
;
224 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= HDLC_CMD_XRS
;
226 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= 0;
227 schedule_event(bcs
, B_XMTBUFREADY
);
232 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= HDLC_CMD_XRS
| HDLC_CMD_RRS
;
233 bcs
->hw
.hdlc
.ctrl
.sr
.mode
= HDLC_MODE_ITF_FLG
;
235 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= HDLC_CMD_XRS
;
237 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
= 0;
238 schedule_event(bcs
, B_XMTBUFREADY
);
244 hdlc_empty_fifo(struct BCState
*bcs
, int count
)
248 u_char idx
= bcs
->channel
? AVM_HDLC_2
: AVM_HDLC_1
;
250 struct IsdnCardState
*cs
= bcs
->cs
;
252 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
253 debugl1(cs
, "hdlc_empty_fifo %d", count
);
254 if (bcs
->hw
.hdlc
.rcvidx
+ count
> HSCX_BUFMAX
) {
255 if (cs
->debug
& L1_DEB_WARN
)
256 debugl1(cs
, "hdlc_empty_fifo: incoming packet too large");
259 p
= bcs
->hw
.hdlc
.rcvbuf
+ bcs
->hw
.hdlc
.rcvidx
;
261 bcs
->hw
.hdlc
.rcvidx
+= count
;
262 if (cs
->subtyp
== AVM_FRITZ_PCI
) {
263 outl(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
264 while (cnt
< count
) {
266 *ptr
++ = in_be32((unsigned *)(cs
->hw
.avm
.isac
+_IO_BASE
));
268 *ptr
++ = inl(cs
->hw
.avm
.isac
);
269 #endif /* __powerpc__ */
273 outb(idx
, cs
->hw
.avm
.cfg_reg
+ 4);
274 while (cnt
< count
) {
275 *p
++ = inb(cs
->hw
.avm
.isac
);
279 if (cs
->debug
& L1_DEB_HSCX_FIFO
) {
282 if (cs
->subtyp
== AVM_FRITZ_PNP
)
284 t
+= sprintf(t
, "hdlc_empty_fifo %c cnt %d",
285 bcs
->channel
? 'B' : 'A', count
);
286 QuickHex(t
, p
, count
);
287 debugl1(cs
, bcs
->blog
);
292 hdlc_fill_fifo(struct BCState
*bcs
)
294 struct IsdnCardState
*cs
= bcs
->cs
;
300 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
301 debugl1(cs
, "hdlc_fill_fifo");
304 if (bcs
->tx_skb
->len
<= 0)
307 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
&= ~HDLC_CMD_XME
;
308 if (bcs
->tx_skb
->len
> fifo_size
) {
311 count
= bcs
->tx_skb
->len
;
312 if (bcs
->mode
!= L1_MODE_TRANS
)
313 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
|= HDLC_CMD_XME
;
315 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
316 debugl1(cs
, "hdlc_fill_fifo %d/%ld", count
, bcs
->tx_skb
->len
);
317 p
= bcs
->tx_skb
->data
;
319 skb_pull(bcs
->tx_skb
, count
);
320 bcs
->tx_cnt
-= count
;
321 bcs
->hw
.hdlc
.count
+= count
;
322 bcs
->hw
.hdlc
.ctrl
.sr
.xml
= ((count
== fifo_size
) ? 0 : count
);
323 write_ctrl(bcs
, 3); /* sets the correct index too */
324 if (cs
->subtyp
== AVM_FRITZ_PCI
) {
327 out_be32((unsigned *)(cs
->hw
.avm
.isac
+_IO_BASE
), *ptr
++);
329 outl(*ptr
++, cs
->hw
.avm
.isac
);
330 #endif /* __powerpc__ */
335 outb(*p
++, cs
->hw
.avm
.isac
);
339 if (cs
->debug
& L1_DEB_HSCX_FIFO
) {
342 if (cs
->subtyp
== AVM_FRITZ_PNP
)
344 t
+= sprintf(t
, "hdlc_fill_fifo %c cnt %d",
345 bcs
->channel
? 'B' : 'A', count
);
346 QuickHex(t
, p
, count
);
347 debugl1(cs
, bcs
->blog
);
352 HDLC_irq(struct BCState
*bcs
, u_int stat
) {
356 if (bcs
->cs
->debug
& L1_DEB_HSCX
)
357 debugl1(bcs
->cs
, "ch%d stat %#x", bcs
->channel
, stat
);
358 if (stat
& HDLC_INT_RPR
) {
359 if (stat
& HDLC_STAT_RDO
) {
360 if (bcs
->cs
->debug
& L1_DEB_HSCX
)
361 debugl1(bcs
->cs
, "RDO");
363 debugl1(bcs
->cs
, "ch%d stat %#x", bcs
->channel
, stat
);
364 bcs
->hw
.hdlc
.ctrl
.sr
.xml
= 0;
365 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
|= HDLC_CMD_RRS
;
367 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
&= ~HDLC_CMD_RRS
;
369 bcs
->hw
.hdlc
.rcvidx
= 0;
371 if (!(len
= (stat
& HDLC_STAT_RML_MASK
)>>8))
373 hdlc_empty_fifo(bcs
, len
);
374 if ((stat
& HDLC_STAT_RME
) || (bcs
->mode
== L1_MODE_TRANS
)) {
375 if (((stat
& HDLC_STAT_CRCVFRRAB
)==HDLC_STAT_CRCVFR
) ||
376 (bcs
->mode
== L1_MODE_TRANS
)) {
377 if (!(skb
= dev_alloc_skb(bcs
->hw
.hdlc
.rcvidx
)))
378 printk(KERN_WARNING
"HDLC: receive out of memory\n");
380 memcpy(skb_put(skb
, bcs
->hw
.hdlc
.rcvidx
),
381 bcs
->hw
.hdlc
.rcvbuf
, bcs
->hw
.hdlc
.rcvidx
);
382 skb_queue_tail(&bcs
->rqueue
, skb
);
384 bcs
->hw
.hdlc
.rcvidx
= 0;
385 schedule_event(bcs
, B_RCVBUFREADY
);
387 if (bcs
->cs
->debug
& L1_DEB_HSCX
)
388 debugl1(bcs
->cs
, "invalid frame");
390 debugl1(bcs
->cs
, "ch%d invalid frame %#x", bcs
->channel
, stat
);
391 bcs
->hw
.hdlc
.rcvidx
= 0;
396 if (stat
& HDLC_INT_XDU
) {
397 /* Here we lost an TX interrupt, so
398 * restart transmitting the whole frame.
401 skb_push(bcs
->tx_skb
, bcs
->hw
.hdlc
.count
);
402 bcs
->tx_cnt
+= bcs
->hw
.hdlc
.count
;
403 bcs
->hw
.hdlc
.count
= 0;
404 if (bcs
->cs
->debug
& L1_DEB_WARN
)
405 debugl1(bcs
->cs
, "ch%d XDU", bcs
->channel
);
406 } else if (bcs
->cs
->debug
& L1_DEB_WARN
)
407 debugl1(bcs
->cs
, "ch%d XDU without skb", bcs
->channel
);
408 bcs
->hw
.hdlc
.ctrl
.sr
.xml
= 0;
409 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
|= HDLC_CMD_XRS
;
411 bcs
->hw
.hdlc
.ctrl
.sr
.cmd
&= ~HDLC_CMD_XRS
;
414 } else if (stat
& HDLC_INT_XPR
) {
416 if (bcs
->tx_skb
->len
) {
420 if (test_bit(FLG_LLI_L1WAKEUP
,&bcs
->st
->lli
.flag
) &&
421 (PACKET_NOACK
!= bcs
->tx_skb
->pkt_type
)) {
423 spin_lock_irqsave(&bcs
->aclock
, flags
);
424 bcs
->ackcnt
+= bcs
->hw
.hdlc
.count
;
425 spin_unlock_irqrestore(&bcs
->aclock
, flags
);
426 schedule_event(bcs
, B_ACKPENDING
);
428 dev_kfree_skb_irq(bcs
->tx_skb
);
429 bcs
->hw
.hdlc
.count
= 0;
433 if ((bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
))) {
434 bcs
->hw
.hdlc
.count
= 0;
435 test_and_set_bit(BC_FLG_BUSY
, &bcs
->Flag
);
438 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
439 schedule_event(bcs
, B_XMTBUFREADY
);
445 HDLC_irq_main(struct IsdnCardState
*cs
)
450 if (cs
->subtyp
== AVM_FRITZ_PCI
) {
451 stat
= ReadHDLCPCI(cs
, 0, HDLC_STATUS
);
453 stat
= ReadHDLCPnP(cs
, 0, HDLC_STATUS
);
454 if (stat
& HDLC_INT_RPR
)
455 stat
|= (ReadHDLCPnP(cs
, 0, HDLC_STATUS
+1))<<8;
457 if (stat
& HDLC_INT_MASK
) {
458 if (!(bcs
= Sel_BCS(cs
, 0))) {
460 debugl1(cs
, "hdlc spurious channel 0 IRQ");
464 if (cs
->subtyp
== AVM_FRITZ_PCI
) {
465 stat
= ReadHDLCPCI(cs
, 1, HDLC_STATUS
);
467 stat
= ReadHDLCPnP(cs
, 1, HDLC_STATUS
);
468 if (stat
& HDLC_INT_RPR
)
469 stat
|= (ReadHDLCPnP(cs
, 1, HDLC_STATUS
+1))<<8;
471 if (stat
& HDLC_INT_MASK
) {
472 if (!(bcs
= Sel_BCS(cs
, 1))) {
474 debugl1(cs
, "hdlc spurious channel 1 IRQ");
481 hdlc_l2l1(struct PStack
*st
, int pr
, void *arg
)
483 struct BCState
*bcs
= st
->l1
.bcs
;
484 struct sk_buff
*skb
= arg
;
488 case (PH_DATA
| REQUEST
):
489 spin_lock_irqsave(&bcs
->cs
->lock
, flags
);
491 skb_queue_tail(&bcs
->squeue
, skb
);
494 test_and_set_bit(BC_FLG_BUSY
, &bcs
->Flag
);
495 bcs
->hw
.hdlc
.count
= 0;
496 bcs
->cs
->BC_Send_Data(bcs
);
498 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
500 case (PH_PULL
| INDICATION
):
501 spin_lock_irqsave(&bcs
->cs
->lock
, flags
);
503 printk(KERN_WARNING
"hdlc_l2l1: this shouldn't happen\n");
505 test_and_set_bit(BC_FLG_BUSY
, &bcs
->Flag
);
507 bcs
->hw
.hdlc
.count
= 0;
508 bcs
->cs
->BC_Send_Data(bcs
);
510 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
512 case (PH_PULL
| REQUEST
):
514 test_and_clear_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
515 st
->l1
.l1l2(st
, PH_PULL
| CONFIRM
, NULL
);
517 test_and_set_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
519 case (PH_ACTIVATE
| REQUEST
):
520 spin_lock_irqsave(&bcs
->cs
->lock
, flags
);
521 test_and_set_bit(BC_FLG_ACTIV
, &bcs
->Flag
);
522 modehdlc(bcs
, st
->l1
.mode
, st
->l1
.bc
);
523 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
524 l1_msg_b(st
, pr
, arg
);
526 case (PH_DEACTIVATE
| REQUEST
):
527 l1_msg_b(st
, pr
, arg
);
529 case (PH_DEACTIVATE
| CONFIRM
):
530 spin_lock_irqsave(&bcs
->cs
->lock
, flags
);
531 test_and_clear_bit(BC_FLG_ACTIV
, &bcs
->Flag
);
532 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
533 modehdlc(bcs
, 0, st
->l1
.bc
);
534 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
535 st
->l1
.l1l2(st
, PH_DEACTIVATE
| CONFIRM
, NULL
);
541 close_hdlcstate(struct BCState
*bcs
)
544 if (test_and_clear_bit(BC_FLG_INIT
, &bcs
->Flag
)) {
545 kfree(bcs
->hw
.hdlc
.rcvbuf
);
546 bcs
->hw
.hdlc
.rcvbuf
= NULL
;
549 skb_queue_purge(&bcs
->rqueue
);
550 skb_queue_purge(&bcs
->squeue
);
552 dev_kfree_skb_any(bcs
->tx_skb
);
554 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
560 open_hdlcstate(struct IsdnCardState
*cs
, struct BCState
*bcs
)
562 if (!test_and_set_bit(BC_FLG_INIT
, &bcs
->Flag
)) {
563 if (!(bcs
->hw
.hdlc
.rcvbuf
= kmalloc(HSCX_BUFMAX
, GFP_ATOMIC
))) {
565 "HiSax: No memory for hdlc.rcvbuf\n");
568 if (!(bcs
->blog
= kmalloc(MAX_BLOG_SPACE
, GFP_ATOMIC
))) {
570 "HiSax: No memory for bcs->blog\n");
571 test_and_clear_bit(BC_FLG_INIT
, &bcs
->Flag
);
572 kfree(bcs
->hw
.hdlc
.rcvbuf
);
573 bcs
->hw
.hdlc
.rcvbuf
= NULL
;
576 skb_queue_head_init(&bcs
->rqueue
);
577 skb_queue_head_init(&bcs
->squeue
);
580 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
582 bcs
->hw
.hdlc
.rcvidx
= 0;
588 setstack_hdlc(struct PStack
*st
, struct BCState
*bcs
)
590 bcs
->channel
= st
->l1
.bc
;
591 if (open_hdlcstate(st
->l1
.hardware
, bcs
))
594 st
->l2
.l2l1
= hdlc_l2l1
;
595 setstack_manager(st
);
603 clear_pending_hdlc_ints(struct IsdnCardState
*cs
)
607 if (cs
->subtyp
== AVM_FRITZ_PCI
) {
608 val
= ReadHDLCPCI(cs
, 0, HDLC_STATUS
);
609 debugl1(cs
, "HDLC 1 STA %x", val
);
610 val
= ReadHDLCPCI(cs
, 1, HDLC_STATUS
);
611 debugl1(cs
, "HDLC 2 STA %x", val
);
613 val
= ReadHDLCPnP(cs
, 0, HDLC_STATUS
);
614 debugl1(cs
, "HDLC 1 STA %x", val
);
615 val
= ReadHDLCPnP(cs
, 0, HDLC_STATUS
+ 1);
616 debugl1(cs
, "HDLC 1 RML %x", val
);
617 val
= ReadHDLCPnP(cs
, 0, HDLC_STATUS
+ 2);
618 debugl1(cs
, "HDLC 1 MODE %x", val
);
619 val
= ReadHDLCPnP(cs
, 0, HDLC_STATUS
+ 3);
620 debugl1(cs
, "HDLC 1 VIN %x", val
);
621 val
= ReadHDLCPnP(cs
, 1, HDLC_STATUS
);
622 debugl1(cs
, "HDLC 2 STA %x", val
);
623 val
= ReadHDLCPnP(cs
, 1, HDLC_STATUS
+ 1);
624 debugl1(cs
, "HDLC 2 RML %x", val
);
625 val
= ReadHDLCPnP(cs
, 1, HDLC_STATUS
+ 2);
626 debugl1(cs
, "HDLC 2 MODE %x", val
);
627 val
= ReadHDLCPnP(cs
, 1, HDLC_STATUS
+ 3);
628 debugl1(cs
, "HDLC 2 VIN %x", val
);
634 inithdlc(struct IsdnCardState
*cs
)
636 cs
->bcs
[0].BC_SetStack
= setstack_hdlc
;
637 cs
->bcs
[1].BC_SetStack
= setstack_hdlc
;
638 cs
->bcs
[0].BC_Close
= close_hdlcstate
;
639 cs
->bcs
[1].BC_Close
= close_hdlcstate
;
640 modehdlc(cs
->bcs
, -1, 0);
641 modehdlc(cs
->bcs
+ 1, -1, 1);
645 avm_pcipnp_interrupt(int intno
, void *dev_id
)
647 struct IsdnCardState
*cs
= dev_id
;
652 spin_lock_irqsave(&cs
->lock
, flags
);
653 sval
= inb(cs
->hw
.avm
.cfg_reg
+ 2);
654 if ((sval
& AVM_STATUS0_IRQ_MASK
) == AVM_STATUS0_IRQ_MASK
) {
655 /* possible a shared IRQ reqest */
656 spin_unlock_irqrestore(&cs
->lock
, flags
);
659 if (!(sval
& AVM_STATUS0_IRQ_ISAC
)) {
660 val
= ReadISAC(cs
, ISAC_ISTA
);
661 isac_interrupt(cs
, val
);
663 if (!(sval
& AVM_STATUS0_IRQ_HDLC
)) {
666 WriteISAC(cs
, ISAC_MASK
, 0xFF);
667 WriteISAC(cs
, ISAC_MASK
, 0x0);
668 spin_unlock_irqrestore(&cs
->lock
, flags
);
673 reset_avmpcipnp(struct IsdnCardState
*cs
)
675 printk(KERN_INFO
"AVM PCI/PnP: reset\n");
676 outb(AVM_STATUS0_RESET
| AVM_STATUS0_DIS_TIMER
, cs
->hw
.avm
.cfg_reg
+ 2);
678 outb(AVM_STATUS0_DIS_TIMER
| AVM_STATUS0_RES_TIMER
| AVM_STATUS0_ENA_IRQ
, cs
->hw
.avm
.cfg_reg
+ 2);
679 outb(AVM_STATUS1_ENA_IOM
| cs
->irq
, cs
->hw
.avm
.cfg_reg
+ 3);
681 printk(KERN_INFO
"AVM PCI/PnP: S1 %x\n", inb(cs
->hw
.avm
.cfg_reg
+ 3));
685 AVM_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
691 spin_lock_irqsave(&cs
->lock
, flags
);
693 spin_unlock_irqrestore(&cs
->lock
, flags
);
696 outb(0, cs
->hw
.avm
.cfg_reg
+ 2);
697 release_region(cs
->hw
.avm
.cfg_reg
, 32);
700 spin_lock_irqsave(&cs
->lock
, flags
);
702 clear_pending_isac_ints(cs
);
705 outb(AVM_STATUS0_DIS_TIMER
| AVM_STATUS0_RES_TIMER
,
706 cs
->hw
.avm
.cfg_reg
+ 2);
707 WriteISAC(cs
, ISAC_MASK
, 0);
708 outb(AVM_STATUS0_DIS_TIMER
| AVM_STATUS0_RES_TIMER
|
709 AVM_STATUS0_ENA_IRQ
, cs
->hw
.avm
.cfg_reg
+ 2);
710 /* RESET Receiver and Transmitter */
711 WriteISAC(cs
, ISAC_CMDR
, 0x41);
712 spin_unlock_irqrestore(&cs
->lock
, flags
);
720 static int __devinit
avm_setup_rest(struct IsdnCardState
*cs
)
724 cs
->hw
.avm
.isac
= cs
->hw
.avm
.cfg_reg
+ 0x10;
725 if (!request_region(cs
->hw
.avm
.cfg_reg
, 32,
726 (cs
->subtyp
== AVM_FRITZ_PCI
) ? "avm PCI" : "avm PnP")) {
728 "HiSax: Fritz!PCI/PNP config port %x-%x already in use\n",
730 cs
->hw
.avm
.cfg_reg
+ 31);
733 switch (cs
->subtyp
) {
735 val
= inl(cs
->hw
.avm
.cfg_reg
);
736 printk(KERN_INFO
"AVM PCI: stat %#x\n", val
);
737 printk(KERN_INFO
"AVM PCI: Class %X Rev %d\n",
738 val
& 0xff, (val
>>8) & 0xff);
739 cs
->BC_Read_Reg
= &ReadHDLC_s
;
740 cs
->BC_Write_Reg
= &WriteHDLC_s
;
743 val
= inb(cs
->hw
.avm
.cfg_reg
);
744 ver
= inb(cs
->hw
.avm
.cfg_reg
+ 1);
745 printk(KERN_INFO
"AVM PnP: Class %X Rev %d\n", val
, ver
);
746 cs
->BC_Read_Reg
= &ReadHDLCPnP
;
747 cs
->BC_Write_Reg
= &WriteHDLCPnP
;
750 printk(KERN_WARNING
"AVM unknown subtype %d\n", cs
->subtyp
);
753 printk(KERN_INFO
"HiSax: %s config irq:%d base:0x%X\n",
754 (cs
->subtyp
== AVM_FRITZ_PCI
) ? "AVM Fritz!PCI" : "AVM Fritz!PnP",
755 cs
->irq
, cs
->hw
.avm
.cfg_reg
);
758 cs
->readisac
= &ReadISAC
;
759 cs
->writeisac
= &WriteISAC
;
760 cs
->readisacfifo
= &ReadISACfifo
;
761 cs
->writeisacfifo
= &WriteISACfifo
;
762 cs
->BC_Send_Data
= &hdlc_fill_fifo
;
763 cs
->cardmsg
= &AVM_card_msg
;
764 cs
->irq_func
= &avm_pcipnp_interrupt
;
765 cs
->writeisac(cs
, ISAC_MASK
, 0xFF);
766 ISACVersion(cs
, (cs
->subtyp
== AVM_FRITZ_PCI
) ? "AVM PCI:" : "AVM PnP:");
772 static int __devinit
avm_pnp_setup(struct IsdnCardState
*cs
)
774 return(1); /* no-op: success */
779 static struct pnp_card
*pnp_avm_c __devinitdata
= NULL
;
781 static int __devinit
avm_pnp_setup(struct IsdnCardState
*cs
)
783 struct pnp_dev
*pnp_avm_d
= NULL
;
785 if (!isapnp_present())
786 return(1); /* no-op: success */
788 if ((pnp_avm_c
= pnp_find_card(
789 ISAPNP_VENDOR('A', 'V', 'M'),
790 ISAPNP_FUNCTION(0x0900), pnp_avm_c
))) {
791 if ((pnp_avm_d
= pnp_find_dev(pnp_avm_c
,
792 ISAPNP_VENDOR('A', 'V', 'M'),
793 ISAPNP_FUNCTION(0x0900), pnp_avm_d
))) {
796 pnp_disable_dev(pnp_avm_d
);
797 err
= pnp_activate_dev(pnp_avm_d
);
799 printk(KERN_WARNING
"%s: pnp_activate_dev ret(%d)\n",
804 pnp_port_start(pnp_avm_d
, 0);
805 cs
->irq
= pnp_irq(pnp_avm_d
, 0);
807 printk(KERN_ERR
"FritzPnP:No IRQ\n");
810 if (!cs
->hw
.avm
.cfg_reg
) {
811 printk(KERN_ERR
"FritzPnP:No IO address\n");
814 cs
->subtyp
= AVM_FRITZ_PNP
;
816 return (2); /* goto 'ready' label */
823 #endif /* __ISAPNP__ */
827 static int __devinit
avm_pci_setup(struct IsdnCardState
*cs
)
829 return(1); /* no-op: success */
834 static struct pci_dev
*dev_avm __devinitdata
= NULL
;
836 static int __devinit
avm_pci_setup(struct IsdnCardState
*cs
)
838 if ((dev_avm
= hisax_find_pci_device(PCI_VENDOR_ID_AVM
,
839 PCI_DEVICE_ID_AVM_A1
, dev_avm
))) {
841 if (pci_enable_device(dev_avm
))
844 cs
->irq
= dev_avm
->irq
;
846 printk(KERN_ERR
"FritzPCI: No IRQ for PCI card found\n");
850 cs
->hw
.avm
.cfg_reg
= pci_resource_start(dev_avm
, 1);
851 if (!cs
->hw
.avm
.cfg_reg
) {
852 printk(KERN_ERR
"FritzPCI: No IO-Adr for PCI card found\n");
856 cs
->subtyp
= AVM_FRITZ_PCI
;
858 printk(KERN_WARNING
"FritzPCI: No PCI card found\n");
862 cs
->irq_flags
|= IRQF_SHARED
;
867 #endif /* CONFIG_PCI */
870 setup_avm_pcipnp(struct IsdnCard
*card
)
872 struct IsdnCardState
*cs
= card
->cs
;
876 strcpy(tmp
, avm_pci_rev
);
877 printk(KERN_INFO
"HiSax: AVM PCI driver Rev. %s\n", HiSax_getrev(tmp
));
879 if (cs
->typ
!= ISDN_CTYPE_FRITZPCI
)
883 /* old manual method */
884 cs
->hw
.avm
.cfg_reg
= card
->para
[1];
885 cs
->irq
= card
->para
[0];
886 cs
->subtyp
= AVM_FRITZ_PNP
;
890 rc
= avm_pnp_setup(cs
);
896 rc
= avm_pci_setup(cs
);
901 return avm_setup_rest(cs
);