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 extern const char *CardType[];
24 static const char *avm_pci_rev = "$Revision: 1.29.2.4 $";
26 #define AVM_FRITZ_PCI 1
27 #define AVM_FRITZ_PNP 2
30 #define HDLC_STATUS 0x4
32 #define AVM_HDLC_1 0x00
33 #define AVM_HDLC_2 0x01
34 #define AVM_ISAC_FIFO 0x02
35 #define AVM_ISAC_REG_LOW 0x04
36 #define AVM_ISAC_REG_HIGH 0x06
38 #define AVM_STATUS0_IRQ_ISAC 0x01
39 #define AVM_STATUS0_IRQ_HDLC 0x02
40 #define AVM_STATUS0_IRQ_TIMER 0x04
41 #define AVM_STATUS0_IRQ_MASK 0x07
43 #define AVM_STATUS0_RESET 0x01
44 #define AVM_STATUS0_DIS_TIMER 0x02
45 #define AVM_STATUS0_RES_TIMER 0x04
46 #define AVM_STATUS0_ENA_IRQ 0x08
47 #define AVM_STATUS0_TESTBIT 0x10
49 #define AVM_STATUS1_INT_SEL 0x0f
50 #define AVM_STATUS1_ENA_IOM 0x80
52 #define HDLC_MODE_ITF_FLG 0x01
53 #define HDLC_MODE_TRANS 0x02
54 #define HDLC_MODE_CCR_7 0x04
55 #define HDLC_MODE_CCR_16 0x08
56 #define HDLC_MODE_TESTLOOP 0x80
58 #define HDLC_INT_XPR 0x80
59 #define HDLC_INT_XDU 0x40
60 #define HDLC_INT_RPR 0x20
61 #define HDLC_INT_MASK 0xE0
63 #define HDLC_STAT_RME 0x01
64 #define HDLC_STAT_RDO 0x10
65 #define HDLC_STAT_CRCVFRRAB 0x0E
66 #define HDLC_STAT_CRCVFR 0x06
67 #define HDLC_STAT_RML_MASK 0x3f00
69 #define HDLC_CMD_XRS 0x80
70 #define HDLC_CMD_XME 0x01
71 #define HDLC_CMD_RRS 0x20
72 #define HDLC_CMD_XML_MASK 0x3f00
75 /* Interface functions */
78 ReadISAC(struct IsdnCardState *cs, u_char offset)
80 register u_char idx = (offset > 0x2f) ? AVM_ISAC_REG_HIGH : AVM_ISAC_REG_LOW;
83 outb(idx, cs->hw.avm.cfg_reg + 4);
84 val = inb(cs->hw.avm.isac + (offset & 0xf));
89 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
91 register u_char idx = (offset > 0x2f) ? AVM_ISAC_REG_HIGH : AVM_ISAC_REG_LOW;
93 outb(idx, cs->hw.avm.cfg_reg + 4);
94 outb(value, cs->hw.avm.isac + (offset & 0xf));
98 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
100 outb(AVM_ISAC_FIFO, cs->hw.avm.cfg_reg + 4);
101 insb(cs->hw.avm.isac, data, size);
105 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
107 outb(AVM_ISAC_FIFO, cs->hw.avm.cfg_reg + 4);
108 outsb(cs->hw.avm.isac, data, size);
112 ReadHDLCPCI(struct IsdnCardState *cs, int chan, u_char offset)
114 register u_int idx = chan ? AVM_HDLC_2 : AVM_HDLC_1;
117 outl(idx, cs->hw.avm.cfg_reg + 4);
118 val = inl(cs->hw.avm.isac + offset);
123 WriteHDLCPCI(struct IsdnCardState *cs, int chan, u_char offset, u_int value)
125 register u_int idx = chan ? AVM_HDLC_2 : AVM_HDLC_1;
127 outl(idx, cs->hw.avm.cfg_reg + 4);
128 outl(value, cs->hw.avm.isac + offset);
132 ReadHDLCPnP(struct IsdnCardState *cs, int chan, u_char offset)
134 register u_char idx = chan ? AVM_HDLC_2 : AVM_HDLC_1;
137 outb(idx, cs->hw.avm.cfg_reg + 4);
138 val = inb(cs->hw.avm.isac + offset);
143 WriteHDLCPnP(struct IsdnCardState *cs, int chan, u_char offset, u_char value)
145 register u_char idx = chan ? AVM_HDLC_2 : AVM_HDLC_1;
147 outb(idx, cs->hw.avm.cfg_reg + 4);
148 outb(value, cs->hw.avm.isac + offset);
152 ReadHDLC_s(struct IsdnCardState *cs, int chan, u_char offset)
154 return(0xff & ReadHDLCPCI(cs, chan, offset));
158 WriteHDLC_s(struct IsdnCardState *cs, int chan, u_char offset, u_char value)
160 WriteHDLCPCI(cs, chan, offset, value);
164 struct BCState *Sel_BCS(struct IsdnCardState *cs, int channel)
166 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
168 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
175 write_ctrl(struct BCState *bcs, int which) {
177 if (bcs->cs->debug & L1_DEB_HSCX)
178 debugl1(bcs->cs, "hdlc %c wr%x ctrl %x",
179 'A' + bcs->channel, which, bcs->hw.hdlc.ctrl.ctrl);
180 if (bcs->cs->subtyp == AVM_FRITZ_PCI) {
181 WriteHDLCPCI(bcs->cs, bcs->channel, HDLC_STATUS, bcs->hw.hdlc.ctrl.ctrl);
184 WriteHDLCPnP(bcs->cs, bcs->channel, HDLC_STATUS + 2,
185 bcs->hw.hdlc.ctrl.sr.mode);
187 WriteHDLCPnP(bcs->cs, bcs->channel, HDLC_STATUS + 1,
188 bcs->hw.hdlc.ctrl.sr.xml);
190 WriteHDLCPnP(bcs->cs, bcs->channel, HDLC_STATUS,
191 bcs->hw.hdlc.ctrl.sr.cmd);
196 modehdlc(struct BCState *bcs, int mode, int bc)
198 struct IsdnCardState *cs = bcs->cs;
199 int hdlc = bcs->channel;
201 if (cs->debug & L1_DEB_HSCX)
202 debugl1(cs, "hdlc %c mode %d --> %d ichan %d --> %d",
203 'A' + hdlc, bcs->mode, mode, hdlc, bc);
204 bcs->hw.hdlc.ctrl.ctrl = 0;
206 case (-1): /* used for init */
211 if (bcs->mode == L1_MODE_NULL)
213 bcs->hw.hdlc.ctrl.sr.cmd = HDLC_CMD_XRS | HDLC_CMD_RRS;
214 bcs->hw.hdlc.ctrl.sr.mode = HDLC_MODE_TRANS;
216 bcs->mode = L1_MODE_NULL;
219 case (L1_MODE_TRANS):
222 bcs->hw.hdlc.ctrl.sr.cmd = HDLC_CMD_XRS | HDLC_CMD_RRS;
223 bcs->hw.hdlc.ctrl.sr.mode = HDLC_MODE_TRANS;
225 bcs->hw.hdlc.ctrl.sr.cmd = HDLC_CMD_XRS;
227 bcs->hw.hdlc.ctrl.sr.cmd = 0;
228 schedule_event(bcs, B_XMTBUFREADY);
233 bcs->hw.hdlc.ctrl.sr.cmd = HDLC_CMD_XRS | HDLC_CMD_RRS;
234 bcs->hw.hdlc.ctrl.sr.mode = HDLC_MODE_ITF_FLG;
236 bcs->hw.hdlc.ctrl.sr.cmd = HDLC_CMD_XRS;
238 bcs->hw.hdlc.ctrl.sr.cmd = 0;
239 schedule_event(bcs, B_XMTBUFREADY);
245 hdlc_empty_fifo(struct BCState *bcs, int count)
249 u_char idx = bcs->channel ? AVM_HDLC_2 : AVM_HDLC_1;
251 struct IsdnCardState *cs = bcs->cs;
253 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
254 debugl1(cs, "hdlc_empty_fifo %d", count);
255 if (bcs->hw.hdlc.rcvidx + count > HSCX_BUFMAX) {
256 if (cs->debug & L1_DEB_WARN)
257 debugl1(cs, "hdlc_empty_fifo: incoming packet too large");
260 p = bcs->hw.hdlc.rcvbuf + bcs->hw.hdlc.rcvidx;
262 bcs->hw.hdlc.rcvidx += count;
263 if (cs->subtyp == AVM_FRITZ_PCI) {
264 outl(idx, cs->hw.avm.cfg_reg + 4);
265 while (cnt < count) {
268 *ptr++ = in_le32((unsigned *)(cs->hw.avm.isac +_IO_BASE));
270 *ptr++ = in_be32((unsigned *)(cs->hw.avm.isac +_IO_BASE));
271 #endif /* CONFIG_APUS */
273 *ptr++ = inl(cs->hw.avm.isac);
274 #endif /* __powerpc__ */
278 outb(idx, cs->hw.avm.cfg_reg + 4);
279 while (cnt < count) {
280 *p++ = inb(cs->hw.avm.isac);
284 if (cs->debug & L1_DEB_HSCX_FIFO) {
287 if (cs->subtyp == AVM_FRITZ_PNP)
289 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
290 bcs->channel ? 'B' : 'A', count);
291 QuickHex(t, p, count);
292 debugl1(cs, bcs->blog);
297 hdlc_fill_fifo(struct BCState *bcs)
299 struct IsdnCardState *cs = bcs->cs;
305 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
306 debugl1(cs, "hdlc_fill_fifo");
309 if (bcs->tx_skb->len <= 0)
312 bcs->hw.hdlc.ctrl.sr.cmd &= ~HDLC_CMD_XME;
313 if (bcs->tx_skb->len > fifo_size) {
316 count = bcs->tx_skb->len;
317 if (bcs->mode != L1_MODE_TRANS)
318 bcs->hw.hdlc.ctrl.sr.cmd |= HDLC_CMD_XME;
320 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
321 debugl1(cs, "hdlc_fill_fifo %d/%ld", count, bcs->tx_skb->len);
322 p = bcs->tx_skb->data;
324 skb_pull(bcs->tx_skb, count);
325 bcs->tx_cnt -= count;
326 bcs->hw.hdlc.count += count;
327 bcs->hw.hdlc.ctrl.sr.xml = ((count == fifo_size) ? 0 : count);
328 write_ctrl(bcs, 3); /* sets the correct index too */
329 if (cs->subtyp == AVM_FRITZ_PCI) {
333 out_le32((unsigned *)(cs->hw.avm.isac +_IO_BASE), *ptr++);
335 out_be32((unsigned *)(cs->hw.avm.isac +_IO_BASE), *ptr++);
336 #endif /* CONFIG_APUS */
338 outl(*ptr++, cs->hw.avm.isac);
339 #endif /* __powerpc__ */
344 outb(*p++, cs->hw.avm.isac);
348 if (cs->debug & L1_DEB_HSCX_FIFO) {
351 if (cs->subtyp == AVM_FRITZ_PNP)
353 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
354 bcs->channel ? 'B' : 'A', count);
355 QuickHex(t, p, count);
356 debugl1(cs, bcs->blog);
361 HDLC_irq(struct BCState *bcs, u_int stat) {
365 if (bcs->cs->debug & L1_DEB_HSCX)
366 debugl1(bcs->cs, "ch%d stat %#x", bcs->channel, stat);
367 if (stat & HDLC_INT_RPR) {
368 if (stat & HDLC_STAT_RDO) {
369 if (bcs->cs->debug & L1_DEB_HSCX)
370 debugl1(bcs->cs, "RDO");
372 debugl1(bcs->cs, "ch%d stat %#x", bcs->channel, stat);
373 bcs->hw.hdlc.ctrl.sr.xml = 0;
374 bcs->hw.hdlc.ctrl.sr.cmd |= HDLC_CMD_RRS;
376 bcs->hw.hdlc.ctrl.sr.cmd &= ~HDLC_CMD_RRS;
378 bcs->hw.hdlc.rcvidx = 0;
380 if (!(len = (stat & HDLC_STAT_RML_MASK)>>8))
382 hdlc_empty_fifo(bcs, len);
383 if ((stat & HDLC_STAT_RME) || (bcs->mode == L1_MODE_TRANS)) {
384 if (((stat & HDLC_STAT_CRCVFRRAB)==HDLC_STAT_CRCVFR) ||
385 (bcs->mode == L1_MODE_TRANS)) {
386 if (!(skb = dev_alloc_skb(bcs->hw.hdlc.rcvidx)))
387 printk(KERN_WARNING "HDLC: receive out of memory\n");
389 memcpy(skb_put(skb, bcs->hw.hdlc.rcvidx),
390 bcs->hw.hdlc.rcvbuf, bcs->hw.hdlc.rcvidx);
391 skb_queue_tail(&bcs->rqueue, skb);
393 bcs->hw.hdlc.rcvidx = 0;
394 schedule_event(bcs, B_RCVBUFREADY);
396 if (bcs->cs->debug & L1_DEB_HSCX)
397 debugl1(bcs->cs, "invalid frame");
399 debugl1(bcs->cs, "ch%d invalid frame %#x", bcs->channel, stat);
400 bcs->hw.hdlc.rcvidx = 0;
405 if (stat & HDLC_INT_XDU) {
406 /* Here we lost an TX interrupt, so
407 * restart transmitting the whole frame.
410 skb_push(bcs->tx_skb, bcs->hw.hdlc.count);
411 bcs->tx_cnt += bcs->hw.hdlc.count;
412 bcs->hw.hdlc.count = 0;
413 if (bcs->cs->debug & L1_DEB_WARN)
414 debugl1(bcs->cs, "ch%d XDU", bcs->channel);
415 } else if (bcs->cs->debug & L1_DEB_WARN)
416 debugl1(bcs->cs, "ch%d XDU without skb", bcs->channel);
417 bcs->hw.hdlc.ctrl.sr.xml = 0;
418 bcs->hw.hdlc.ctrl.sr.cmd |= HDLC_CMD_XRS;
420 bcs->hw.hdlc.ctrl.sr.cmd &= ~HDLC_CMD_XRS;
423 } else if (stat & HDLC_INT_XPR) {
425 if (bcs->tx_skb->len) {
429 if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag) &&
430 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
432 spin_lock_irqsave(&bcs->aclock, flags);
433 bcs->ackcnt += bcs->hw.hdlc.count;
434 spin_unlock_irqrestore(&bcs->aclock, flags);
435 schedule_event(bcs, B_ACKPENDING);
437 dev_kfree_skb_irq(bcs->tx_skb);
438 bcs->hw.hdlc.count = 0;
442 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
443 bcs->hw.hdlc.count = 0;
444 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
447 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
448 schedule_event(bcs, B_XMTBUFREADY);
454 HDLC_irq_main(struct IsdnCardState *cs)
459 if (cs->subtyp == AVM_FRITZ_PCI) {
460 stat = ReadHDLCPCI(cs, 0, HDLC_STATUS);
462 stat = ReadHDLCPnP(cs, 0, HDLC_STATUS);
463 if (stat & HDLC_INT_RPR)
464 stat |= (ReadHDLCPnP(cs, 0, HDLC_STATUS+1))<<8;
466 if (stat & HDLC_INT_MASK) {
467 if (!(bcs = Sel_BCS(cs, 0))) {
469 debugl1(cs, "hdlc spurious channel 0 IRQ");
473 if (cs->subtyp == AVM_FRITZ_PCI) {
474 stat = ReadHDLCPCI(cs, 1, HDLC_STATUS);
476 stat = ReadHDLCPnP(cs, 1, HDLC_STATUS);
477 if (stat & HDLC_INT_RPR)
478 stat |= (ReadHDLCPnP(cs, 1, HDLC_STATUS+1))<<8;
480 if (stat & HDLC_INT_MASK) {
481 if (!(bcs = Sel_BCS(cs, 1))) {
483 debugl1(cs, "hdlc spurious channel 1 IRQ");
490 hdlc_l2l1(struct PStack *st, int pr, void *arg)
492 struct BCState *bcs = st->l1.bcs;
493 struct sk_buff *skb = arg;
497 case (PH_DATA | REQUEST):
498 spin_lock_irqsave(&bcs->cs->lock, flags);
500 skb_queue_tail(&bcs->squeue, skb);
503 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
504 bcs->hw.hdlc.count = 0;
505 bcs->cs->BC_Send_Data(bcs);
507 spin_unlock_irqrestore(&bcs->cs->lock, flags);
509 case (PH_PULL | INDICATION):
510 spin_lock_irqsave(&bcs->cs->lock, flags);
512 printk(KERN_WARNING "hdlc_l2l1: this shouldn't happen\n");
514 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
516 bcs->hw.hdlc.count = 0;
517 bcs->cs->BC_Send_Data(bcs);
519 spin_unlock_irqrestore(&bcs->cs->lock, flags);
521 case (PH_PULL | REQUEST):
523 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
524 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
526 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
528 case (PH_ACTIVATE | REQUEST):
529 spin_lock_irqsave(&bcs->cs->lock, flags);
530 test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
531 modehdlc(bcs, st->l1.mode, st->l1.bc);
532 spin_unlock_irqrestore(&bcs->cs->lock, flags);
533 l1_msg_b(st, pr, arg);
535 case (PH_DEACTIVATE | REQUEST):
536 l1_msg_b(st, pr, arg);
538 case (PH_DEACTIVATE | CONFIRM):
539 spin_lock_irqsave(&bcs->cs->lock, flags);
540 test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
541 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
542 modehdlc(bcs, 0, st->l1.bc);
543 spin_unlock_irqrestore(&bcs->cs->lock, flags);
544 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
550 close_hdlcstate(struct BCState *bcs)
553 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
554 kfree(bcs->hw.hdlc.rcvbuf);
555 bcs->hw.hdlc.rcvbuf = NULL;
558 skb_queue_purge(&bcs->rqueue);
559 skb_queue_purge(&bcs->squeue);
561 dev_kfree_skb_any(bcs->tx_skb);
563 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
569 open_hdlcstate(struct IsdnCardState *cs, struct BCState *bcs)
571 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
572 if (!(bcs->hw.hdlc.rcvbuf = kmalloc(HSCX_BUFMAX, GFP_ATOMIC))) {
574 "HiSax: No memory for hdlc.rcvbuf\n");
577 if (!(bcs->blog = kmalloc(MAX_BLOG_SPACE, GFP_ATOMIC))) {
579 "HiSax: No memory for bcs->blog\n");
580 test_and_clear_bit(BC_FLG_INIT, &bcs->Flag);
581 kfree(bcs->hw.hdlc.rcvbuf);
582 bcs->hw.hdlc.rcvbuf = NULL;
585 skb_queue_head_init(&bcs->rqueue);
586 skb_queue_head_init(&bcs->squeue);
589 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
591 bcs->hw.hdlc.rcvidx = 0;
597 setstack_hdlc(struct PStack *st, struct BCState *bcs)
599 bcs->channel = st->l1.bc;
600 if (open_hdlcstate(st->l1.hardware, bcs))
603 st->l2.l2l1 = hdlc_l2l1;
604 setstack_manager(st);
612 clear_pending_hdlc_ints(struct IsdnCardState *cs)
616 if (cs->subtyp == AVM_FRITZ_PCI) {
617 val = ReadHDLCPCI(cs, 0, HDLC_STATUS);
618 debugl1(cs, "HDLC 1 STA %x", val);
619 val = ReadHDLCPCI(cs, 1, HDLC_STATUS);
620 debugl1(cs, "HDLC 2 STA %x", val);
622 val = ReadHDLCPnP(cs, 0, HDLC_STATUS);
623 debugl1(cs, "HDLC 1 STA %x", val);
624 val = ReadHDLCPnP(cs, 0, HDLC_STATUS + 1);
625 debugl1(cs, "HDLC 1 RML %x", val);
626 val = ReadHDLCPnP(cs, 0, HDLC_STATUS + 2);
627 debugl1(cs, "HDLC 1 MODE %x", val);
628 val = ReadHDLCPnP(cs, 0, HDLC_STATUS + 3);
629 debugl1(cs, "HDLC 1 VIN %x", val);
630 val = ReadHDLCPnP(cs, 1, HDLC_STATUS);
631 debugl1(cs, "HDLC 2 STA %x", val);
632 val = ReadHDLCPnP(cs, 1, HDLC_STATUS + 1);
633 debugl1(cs, "HDLC 2 RML %x", val);
634 val = ReadHDLCPnP(cs, 1, HDLC_STATUS + 2);
635 debugl1(cs, "HDLC 2 MODE %x", val);
636 val = ReadHDLCPnP(cs, 1, HDLC_STATUS + 3);
637 debugl1(cs, "HDLC 2 VIN %x", val);
643 inithdlc(struct IsdnCardState *cs)
645 cs->bcs[0].BC_SetStack = setstack_hdlc;
646 cs->bcs[1].BC_SetStack = setstack_hdlc;
647 cs->bcs[0].BC_Close = close_hdlcstate;
648 cs->bcs[1].BC_Close = close_hdlcstate;
649 modehdlc(cs->bcs, -1, 0);
650 modehdlc(cs->bcs + 1, -1, 1);
654 avm_pcipnp_interrupt(int intno, void *dev_id, struct pt_regs *regs)
656 struct IsdnCardState *cs = dev_id;
661 spin_lock_irqsave(&cs->lock, flags);
662 sval = inb(cs->hw.avm.cfg_reg + 2);
663 if ((sval & AVM_STATUS0_IRQ_MASK) == AVM_STATUS0_IRQ_MASK) {
664 /* possible a shared IRQ reqest */
665 spin_unlock_irqrestore(&cs->lock, flags);
668 if (!(sval & AVM_STATUS0_IRQ_ISAC)) {
669 val = ReadISAC(cs, ISAC_ISTA);
670 isac_interrupt(cs, val);
672 if (!(sval & AVM_STATUS0_IRQ_HDLC)) {
675 WriteISAC(cs, ISAC_MASK, 0xFF);
676 WriteISAC(cs, ISAC_MASK, 0x0);
677 spin_unlock_irqrestore(&cs->lock, flags);
682 reset_avmpcipnp(struct IsdnCardState *cs)
684 printk(KERN_INFO "AVM PCI/PnP: reset\n");
685 outb(AVM_STATUS0_RESET | AVM_STATUS0_DIS_TIMER, cs->hw.avm.cfg_reg + 2);
687 outb(AVM_STATUS0_DIS_TIMER | AVM_STATUS0_RES_TIMER | AVM_STATUS0_ENA_IRQ, cs->hw.avm.cfg_reg + 2);
688 outb(AVM_STATUS1_ENA_IOM | cs->irq, cs->hw.avm.cfg_reg + 3);
690 printk(KERN_INFO "AVM PCI/PnP: S1 %x\n", inb(cs->hw.avm.cfg_reg + 3));
694 AVM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
700 spin_lock_irqsave(&cs->lock, flags);
702 spin_unlock_irqrestore(&cs->lock, flags);
705 outb(0, cs->hw.avm.cfg_reg + 2);
706 release_region(cs->hw.avm.cfg_reg, 32);
709 spin_lock_irqsave(&cs->lock, flags);
711 clear_pending_isac_ints(cs);
714 outb(AVM_STATUS0_DIS_TIMER | AVM_STATUS0_RES_TIMER,
715 cs->hw.avm.cfg_reg + 2);
716 WriteISAC(cs, ISAC_MASK, 0);
717 outb(AVM_STATUS0_DIS_TIMER | AVM_STATUS0_RES_TIMER |
718 AVM_STATUS0_ENA_IRQ, cs->hw.avm.cfg_reg + 2);
719 /* RESET Receiver and Transmitter */
720 WriteISAC(cs, ISAC_CMDR, 0x41);
721 spin_unlock_irqrestore(&cs->lock, flags);
730 static struct pci_dev *dev_avm __devinitdata = NULL;
733 static struct pnp_card *pnp_avm_c __devinitdata = NULL;
737 setup_avm_pcipnp(struct IsdnCard *card)
740 struct IsdnCardState *cs = card->cs;
743 strcpy(tmp, avm_pci_rev);
744 printk(KERN_INFO "HiSax: AVM PCI driver Rev. %s\n", HiSax_getrev(tmp));
745 if (cs->typ != ISDN_CTYPE_FRITZPCI)
748 /* old manual method */
749 cs->hw.avm.cfg_reg = card->para[1];
750 cs->irq = card->para[0];
751 cs->subtyp = AVM_FRITZ_PNP;
755 if (isapnp_present()) {
756 struct pnp_dev *pnp_avm_d = NULL;
757 if ((pnp_avm_c = pnp_find_card(
758 ISAPNP_VENDOR('A', 'V', 'M'),
759 ISAPNP_FUNCTION(0x0900), pnp_avm_c))) {
760 if ((pnp_avm_d = pnp_find_dev(pnp_avm_c,
761 ISAPNP_VENDOR('A', 'V', 'M'),
762 ISAPNP_FUNCTION(0x0900), pnp_avm_d))) {
765 pnp_disable_dev(pnp_avm_d);
766 err = pnp_activate_dev(pnp_avm_d);
768 printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
773 pnp_port_start(pnp_avm_d, 0);
774 cs->irq = pnp_irq(pnp_avm_d, 0);
776 printk(KERN_ERR "FritzPnP:No IRQ\n");
779 if (!cs->hw.avm.cfg_reg) {
780 printk(KERN_ERR "FritzPnP:No IO address\n");
783 cs->subtyp = AVM_FRITZ_PNP;
788 printk(KERN_INFO "FritzPnP: no ISA PnP present\n");
792 if ((dev_avm = pci_find_device(PCI_VENDOR_ID_AVM,
793 PCI_DEVICE_ID_AVM_A1, dev_avm))) {
794 if (pci_enable_device(dev_avm))
796 cs->irq = dev_avm->irq;
798 printk(KERN_ERR "FritzPCI: No IRQ for PCI card found\n");
801 cs->hw.avm.cfg_reg = pci_resource_start(dev_avm, 1);
802 if (!cs->hw.avm.cfg_reg) {
803 printk(KERN_ERR "FritzPCI: No IO-Adr for PCI card found\n");
806 cs->subtyp = AVM_FRITZ_PCI;
808 printk(KERN_WARNING "FritzPCI: No PCI card found\n");
811 cs->irq_flags |= IRQF_SHARED;
813 printk(KERN_WARNING "FritzPCI: NO_PCI_BIOS\n");
815 #endif /* CONFIG_PCI */
817 cs->hw.avm.isac = cs->hw.avm.cfg_reg + 0x10;
818 if (!request_region(cs->hw.avm.cfg_reg, 32,
819 (cs->subtyp == AVM_FRITZ_PCI) ? "avm PCI" : "avm PnP")) {
821 "HiSax: %s config port %x-%x already in use\n",
824 cs->hw.avm.cfg_reg + 31);
827 switch (cs->subtyp) {
829 val = inl(cs->hw.avm.cfg_reg);
830 printk(KERN_INFO "AVM PCI: stat %#x\n", val);
831 printk(KERN_INFO "AVM PCI: Class %X Rev %d\n",
832 val & 0xff, (val>>8) & 0xff);
833 cs->BC_Read_Reg = &ReadHDLC_s;
834 cs->BC_Write_Reg = &WriteHDLC_s;
837 val = inb(cs->hw.avm.cfg_reg);
838 ver = inb(cs->hw.avm.cfg_reg + 1);
839 printk(KERN_INFO "AVM PnP: Class %X Rev %d\n", val, ver);
840 cs->BC_Read_Reg = &ReadHDLCPnP;
841 cs->BC_Write_Reg = &WriteHDLCPnP;
844 printk(KERN_WARNING "AVM unknown subtype %d\n", cs->subtyp);
847 printk(KERN_INFO "HiSax: %s config irq:%d base:0x%X\n",
848 (cs->subtyp == AVM_FRITZ_PCI) ? "AVM Fritz!PCI" : "AVM Fritz!PnP",
849 cs->irq, cs->hw.avm.cfg_reg);
852 cs->readisac = &ReadISAC;
853 cs->writeisac = &WriteISAC;
854 cs->readisacfifo = &ReadISACfifo;
855 cs->writeisacfifo = &WriteISACfifo;
856 cs->BC_Send_Data = &hdlc_fill_fifo;
857 cs->cardmsg = &AVM_card_msg;
858 cs->irq_func = &avm_pcipnp_interrupt;
859 cs->writeisac(cs, ISAC_MASK, 0xFF);
860 ISACVersion(cs, (cs->subtyp == AVM_FRITZ_PCI) ? "AVM PCI:" : "AVM PnP:");