1 /* $Id: diva.c,v 1.33.2.6 2004/02/11 13:21:33 keil Exp $
3 * low level stuff for Eicon.Diehl Diva Family 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 * For changes and modifications please read
12 * Documentation/isdn/HiSax.cert
14 * Thanks to Eicon Technology for documents and information
18 #include <linux/init.h>
19 #include <linux/config.h>
26 #include <linux/pci.h>
27 #include <linux/isapnp.h>
29 extern const char *CardType
[];
31 static const char *Diva_revision
= "$Revision: 1.33.2.6 $";
33 #define byteout(addr,val) outb(val,addr)
34 #define bytein(addr) inb(addr)
36 #define DIVA_HSCX_DATA 0
37 #define DIVA_HSCX_ADR 4
38 #define DIVA_ISA_ISAC_DATA 2
39 #define DIVA_ISA_ISAC_ADR 6
40 #define DIVA_ISA_CTRL 7
41 #define DIVA_IPAC_ADR 0
42 #define DIVA_IPAC_DATA 1
44 #define DIVA_PCI_ISAC_DATA 8
45 #define DIVA_PCI_ISAC_ADR 0xc
46 #define DIVA_PCI_CTRL 0x10
51 #define DIVA_IPAC_ISA 3
52 #define DIVA_IPAC_PCI 4
53 #define DIVA_IPACX_PCI 5
56 #define DIVA_IRQ_STAT 0x01
57 #define DIVA_EEPROM_SDA 0x02
60 #define DIVA_IRQ_REQ 0x01
61 #define DIVA_RESET 0x08
62 #define DIVA_EEPROM_CLK 0x40
63 #define DIVA_PCI_LED_A 0x10
64 #define DIVA_PCI_LED_B 0x20
65 #define DIVA_ISA_LED_A 0x20
66 #define DIVA_ISA_LED_B 0x40
67 #define DIVA_IRQ_CLR 0x80
70 #define PITA_MISC_REG 0x1c
72 #define PITA_PARA_SOFTRESET 0x00000001
73 #define PITA_SER_SOFTRESET 0x00000002
74 #define PITA_PARA_MPX_MODE 0x00000004
75 #define PITA_INT0_ENABLE 0x00000200
77 #define PITA_PARA_SOFTRESET 0x01000000
78 #define PITA_SER_SOFTRESET 0x02000000
79 #define PITA_PARA_MPX_MODE 0x04000000
80 #define PITA_INT0_ENABLE 0x00020000
82 #define PITA_INT0_STATUS 0x02
85 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
95 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
98 insb(adr
, data
, size
);
103 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
110 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
*data
, int size
)
113 outsb(adr
, data
, size
);
117 memreadreg(unsigned long adr
, u_char off
)
119 return(*((unsigned char *)
120 (((unsigned int *)adr
) + off
)));
124 memwritereg(unsigned long adr
, u_char off
, u_char data
)
128 p
= (unsigned char *)(((unsigned int *)adr
) + off
);
132 /* Interface functions */
135 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
137 return(readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, offset
));
141 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
143 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, offset
, value
);
147 ReadISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
149 readfifo(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, 0, data
, size
);
153 WriteISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
155 writefifo(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, 0, data
, size
);
159 ReadISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
)
161 return (readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, offset
+0x80));
165 WriteISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
167 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, offset
|0x80, value
);
171 ReadISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
173 readfifo(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, 0x80, data
, size
);
177 WriteISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
179 writefifo(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, 0x80, data
, size
);
183 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
185 return(readreg(cs
->hw
.diva
.hscx_adr
,
186 cs
->hw
.diva
.hscx
, offset
+ (hscx
? 0x40 : 0)));
190 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
192 writereg(cs
->hw
.diva
.hscx_adr
,
193 cs
->hw
.diva
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
197 MemReadISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
)
199 return (memreadreg(cs
->hw
.diva
.cfg_reg
, offset
+0x80));
203 MemWriteISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
205 memwritereg(cs
->hw
.diva
.cfg_reg
, offset
|0x80, value
);
209 MemReadISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
212 *data
++ = memreadreg(cs
->hw
.diva
.cfg_reg
, 0x80);
216 MemWriteISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
219 memwritereg(cs
->hw
.diva
.cfg_reg
, 0x80, *data
++);
223 MemReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
225 return(memreadreg(cs
->hw
.diva
.cfg_reg
, offset
+ (hscx
? 0x40 : 0)));
229 MemWriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
231 memwritereg(cs
->hw
.diva
.cfg_reg
, offset
+ (hscx
? 0x40 : 0), value
);
234 /* IO-Functions for IPACX type cards */
236 MemReadISAC_IPACX(struct IsdnCardState
*cs
, u_char offset
)
238 return (memreadreg(cs
->hw
.diva
.cfg_reg
, offset
));
242 MemWriteISAC_IPACX(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
244 memwritereg(cs
->hw
.diva
.cfg_reg
, offset
, value
);
248 MemReadISACfifo_IPACX(struct IsdnCardState
*cs
, u_char
* data
, int size
)
251 *data
++ = memreadreg(cs
->hw
.diva
.cfg_reg
, 0);
255 MemWriteISACfifo_IPACX(struct IsdnCardState
*cs
, u_char
* data
, int size
)
258 memwritereg(cs
->hw
.diva
.cfg_reg
, 0, *data
++);
262 MemReadHSCX_IPACX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
264 return(memreadreg(cs
->hw
.diva
.cfg_reg
, offset
+
265 (hscx
? IPACX_OFF_B2
: IPACX_OFF_B1
)));
269 MemWriteHSCX_IPACX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
271 memwritereg(cs
->hw
.diva
.cfg_reg
, offset
+
272 (hscx
? IPACX_OFF_B2
: IPACX_OFF_B1
), value
);
276 * fast interrupt HSCX stuff goes here
279 #define READHSCX(cs, nr, reg) readreg(cs->hw.diva.hscx_adr, \
280 cs->hw.diva.hscx, reg + (nr ? 0x40 : 0))
281 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.diva.hscx_adr, \
282 cs->hw.diva.hscx, reg + (nr ? 0x40 : 0), data)
284 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.diva.hscx_adr, \
285 cs->hw.diva.hscx, (nr ? 0x40 : 0), ptr, cnt)
287 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.diva.hscx_adr, \
288 cs->hw.diva.hscx, (nr ? 0x40 : 0), ptr, cnt)
290 #include "hscx_irq.c"
293 diva_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
295 struct IsdnCardState
*cs
= dev_id
;
300 spin_lock_irqsave(&cs
->lock
, flags
);
301 while (((sval
= bytein(cs
->hw
.diva
.ctrl
)) & DIVA_IRQ_REQ
) && cnt
) {
302 val
= readreg(cs
->hw
.diva
.hscx_adr
, cs
->hw
.diva
.hscx
, HSCX_ISTA
+ 0x40);
304 hscx_int_main(cs
, val
);
305 val
= readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, ISAC_ISTA
);
307 isac_interrupt(cs
, val
);
311 printk(KERN_WARNING
"Diva: IRQ LOOP\n");
312 writereg(cs
->hw
.diva
.hscx_adr
, cs
->hw
.diva
.hscx
, HSCX_MASK
, 0xFF);
313 writereg(cs
->hw
.diva
.hscx_adr
, cs
->hw
.diva
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
314 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, ISAC_MASK
, 0xFF);
315 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, ISAC_MASK
, 0x0);
316 writereg(cs
->hw
.diva
.hscx_adr
, cs
->hw
.diva
.hscx
, HSCX_MASK
, 0x0);
317 writereg(cs
->hw
.diva
.hscx_adr
, cs
->hw
.diva
.hscx
, HSCX_MASK
+ 0x40, 0x0);
318 spin_unlock_irqrestore(&cs
->lock
, flags
);
323 diva_irq_ipac_isa(int intno
, void *dev_id
, struct pt_regs
*regs
)
325 struct IsdnCardState
*cs
= dev_id
;
330 spin_lock_irqsave(&cs
->lock
, flags
);
331 ista
= readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_ISTA
);
333 if (cs
->debug
& L1_DEB_IPAC
)
334 debugl1(cs
, "IPAC ISTA %02X", ista
);
336 val
= readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, HSCX_ISTA
+ 0x40);
344 hscx_int_main(cs
, val
);
347 val
= 0xfe & readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, ISAC_ISTA
+ 0x80);
349 isac_interrupt(cs
, val
);
354 isac_interrupt(cs
, val
);
356 ista
= readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_ISTA
);
357 if ((ista
& 0x3f) && icnt
) {
362 printk(KERN_WARNING
"DIVA IPAC IRQ LOOP\n");
363 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_MASK
, 0xFF);
364 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_MASK
, 0xC0);
365 spin_unlock_irqrestore(&cs
->lock
, flags
);
370 MemwaitforCEC(struct IsdnCardState
*cs
, int hscx
)
374 while ((MemReadHSCX(cs
, hscx
, HSCX_STAR
) & 0x04) && to
) {
379 printk(KERN_WARNING
"HiSax: waitforCEC timeout\n");
384 MemwaitforXFW(struct IsdnCardState
*cs
, int hscx
)
388 while ((!(MemReadHSCX(cs
, hscx
, HSCX_STAR
) & 0x44) == 0x40) && to
) {
393 printk(KERN_WARNING
"HiSax: waitforXFW timeout\n");
397 MemWriteHSCXCMDR(struct IsdnCardState
*cs
, int hscx
, u_char data
)
399 MemwaitforCEC(cs
, hscx
);
400 MemWriteHSCX(cs
, hscx
, HSCX_CMDR
, data
);
404 Memhscx_empty_fifo(struct BCState
*bcs
, int count
)
407 struct IsdnCardState
*cs
= bcs
->cs
;
410 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
411 debugl1(cs
, "hscx_empty_fifo");
413 if (bcs
->hw
.hscx
.rcvidx
+ count
> HSCX_BUFMAX
) {
414 if (cs
->debug
& L1_DEB_WARN
)
415 debugl1(cs
, "hscx_empty_fifo: incoming packet too large");
416 MemWriteHSCXCMDR(cs
, bcs
->hw
.hscx
.hscx
, 0x80);
417 bcs
->hw
.hscx
.rcvidx
= 0;
420 ptr
= bcs
->hw
.hscx
.rcvbuf
+ bcs
->hw
.hscx
.rcvidx
;
423 *ptr
++ = memreadreg(cs
->hw
.diva
.cfg_reg
, bcs
->hw
.hscx
.hscx
? 0x40 : 0);
424 MemWriteHSCXCMDR(cs
, bcs
->hw
.hscx
.hscx
, 0x80);
425 ptr
= bcs
->hw
.hscx
.rcvbuf
+ bcs
->hw
.hscx
.rcvidx
;
426 bcs
->hw
.hscx
.rcvidx
+= count
;
427 if (cs
->debug
& L1_DEB_HSCX_FIFO
) {
430 t
+= sprintf(t
, "hscx_empty_fifo %c cnt %d",
431 bcs
->hw
.hscx
.hscx
? 'B' : 'A', count
);
432 QuickHex(t
, ptr
, count
);
433 debugl1(cs
, bcs
->blog
);
438 Memhscx_fill_fifo(struct BCState
*bcs
)
440 struct IsdnCardState
*cs
= bcs
->cs
;
441 int more
, count
, cnt
;
442 int fifo_size
= test_bit(HW_IPAC
, &cs
->HW_Flags
)? 64: 32;
445 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
446 debugl1(cs
, "hscx_fill_fifo");
450 if (bcs
->tx_skb
->len
<= 0)
453 more
= (bcs
->mode
== L1_MODE_TRANS
) ? 1 : 0;
454 if (bcs
->tx_skb
->len
> fifo_size
) {
458 count
= bcs
->tx_skb
->len
;
460 MemwaitforXFW(cs
, bcs
->hw
.hscx
.hscx
);
461 p
= ptr
= bcs
->tx_skb
->data
;
462 skb_pull(bcs
->tx_skb
, count
);
463 bcs
->tx_cnt
-= count
;
464 bcs
->hw
.hscx
.count
+= count
;
466 memwritereg(cs
->hw
.diva
.cfg_reg
, bcs
->hw
.hscx
.hscx
? 0x40 : 0,
468 MemWriteHSCXCMDR(cs
, bcs
->hw
.hscx
.hscx
, more
? 0x8 : 0xa);
469 if (cs
->debug
& L1_DEB_HSCX_FIFO
) {
472 t
+= sprintf(t
, "hscx_fill_fifo %c cnt %d",
473 bcs
->hw
.hscx
.hscx
? 'B' : 'A', count
);
474 QuickHex(t
, ptr
, count
);
475 debugl1(cs
, bcs
->blog
);
480 Memhscx_interrupt(struct IsdnCardState
*cs
, u_char val
, u_char hscx
)
483 struct BCState
*bcs
= cs
->bcs
+ hscx
;
485 int fifo_size
= test_bit(HW_IPAC
, &cs
->HW_Flags
)? 64: 32;
488 if (!test_bit(BC_FLG_INIT
, &bcs
->Flag
))
491 if (val
& 0x80) { /* RME */
492 r
= MemReadHSCX(cs
, hscx
, HSCX_RSTA
);
493 if ((r
& 0xf0) != 0xa0) {
495 if (cs
->debug
& L1_DEB_WARN
)
496 debugl1(cs
, "HSCX invalid frame");
497 if ((r
& 0x40) && bcs
->mode
)
498 if (cs
->debug
& L1_DEB_WARN
)
499 debugl1(cs
, "HSCX RDO mode=%d",
502 if (cs
->debug
& L1_DEB_WARN
)
503 debugl1(cs
, "HSCX CRC error");
504 MemWriteHSCXCMDR(cs
, hscx
, 0x80);
506 count
= MemReadHSCX(cs
, hscx
, HSCX_RBCL
) & (
507 test_bit(HW_IPAC
, &cs
->HW_Flags
)? 0x3f: 0x1f);
510 Memhscx_empty_fifo(bcs
, count
);
511 if ((count
= bcs
->hw
.hscx
.rcvidx
- 1) > 0) {
512 if (cs
->debug
& L1_DEB_HSCX_FIFO
)
513 debugl1(cs
, "HX Frame %d", count
);
514 if (!(skb
= dev_alloc_skb(count
)))
515 printk(KERN_WARNING
"HSCX: receive out of memory\n");
517 memcpy(skb_put(skb
, count
), bcs
->hw
.hscx
.rcvbuf
, count
);
518 skb_queue_tail(&bcs
->rqueue
, skb
);
522 bcs
->hw
.hscx
.rcvidx
= 0;
523 schedule_event(bcs
, B_RCVBUFREADY
);
525 if (val
& 0x40) { /* RPF */
526 Memhscx_empty_fifo(bcs
, fifo_size
);
527 if (bcs
->mode
== L1_MODE_TRANS
) {
528 /* receive audio data */
529 if (!(skb
= dev_alloc_skb(fifo_size
)))
530 printk(KERN_WARNING
"HiSax: receive out of memory\n");
532 memcpy(skb_put(skb
, fifo_size
), bcs
->hw
.hscx
.rcvbuf
, fifo_size
);
533 skb_queue_tail(&bcs
->rqueue
, skb
);
535 bcs
->hw
.hscx
.rcvidx
= 0;
536 schedule_event(bcs
, B_RCVBUFREADY
);
539 if (val
& 0x10) { /* XPR */
541 if (bcs
->tx_skb
->len
) {
542 Memhscx_fill_fifo(bcs
);
545 if (test_bit(FLG_LLI_L1WAKEUP
,&bcs
->st
->lli
.flag
) &&
546 (PACKET_NOACK
!= bcs
->tx_skb
->pkt_type
)) {
548 spin_lock_irqsave(&bcs
->aclock
, flags
);
549 bcs
->ackcnt
+= bcs
->hw
.hscx
.count
;
550 spin_unlock_irqrestore(&bcs
->aclock
, flags
);
551 schedule_event(bcs
, B_ACKPENDING
);
553 dev_kfree_skb_irq(bcs
->tx_skb
);
554 bcs
->hw
.hscx
.count
= 0;
558 if ((bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
))) {
559 bcs
->hw
.hscx
.count
= 0;
560 test_and_set_bit(BC_FLG_BUSY
, &bcs
->Flag
);
561 Memhscx_fill_fifo(bcs
);
563 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
564 schedule_event(bcs
, B_XMTBUFREADY
);
570 Memhscx_int_main(struct IsdnCardState
*cs
, u_char val
)
576 if (val
& 0x01) { // EXB
578 exval
= MemReadHSCX(cs
, 1, HSCX_EXIR
);
581 Memhscx_fill_fifo(bcs
);
583 /* Here we lost an TX interrupt, so
584 * restart transmitting the whole frame.
587 skb_push(bcs
->tx_skb
, bcs
->hw
.hscx
.count
);
588 bcs
->tx_cnt
+= bcs
->hw
.hscx
.count
;
589 bcs
->hw
.hscx
.count
= 0;
591 MemWriteHSCXCMDR(cs
, bcs
->hw
.hscx
.hscx
, 0x01);
592 if (cs
->debug
& L1_DEB_WARN
)
593 debugl1(cs
, "HSCX B EXIR %x Lost TX", exval
);
595 } else if (cs
->debug
& L1_DEB_HSCX
)
596 debugl1(cs
, "HSCX B EXIR %x", exval
);
599 if (cs
->debug
& L1_DEB_HSCX
)
600 debugl1(cs
, "HSCX B interrupt %x", val
);
601 Memhscx_interrupt(cs
, val
, 1);
603 if (val
& 0x02) { // EXA
605 exval
= MemReadHSCX(cs
, 0, HSCX_EXIR
);
607 if (bcs
->mode
== L1_MODE_TRANS
)
608 Memhscx_fill_fifo(bcs
);
610 /* Here we lost an TX interrupt, so
611 * restart transmitting the whole frame.
614 skb_push(bcs
->tx_skb
, bcs
->hw
.hscx
.count
);
615 bcs
->tx_cnt
+= bcs
->hw
.hscx
.count
;
616 bcs
->hw
.hscx
.count
= 0;
618 MemWriteHSCXCMDR(cs
, bcs
->hw
.hscx
.hscx
, 0x01);
619 if (cs
->debug
& L1_DEB_WARN
)
620 debugl1(cs
, "HSCX A EXIR %x Lost TX", exval
);
622 } else if (cs
->debug
& L1_DEB_HSCX
)
623 debugl1(cs
, "HSCX A EXIR %x", exval
);
625 if (val
& 0x04) { // ICA
626 exval
= MemReadHSCX(cs
, 0, HSCX_ISTA
);
627 if (cs
->debug
& L1_DEB_HSCX
)
628 debugl1(cs
, "HSCX A interrupt %x", exval
);
629 Memhscx_interrupt(cs
, exval
, 0);
634 diva_irq_ipac_pci(int intno
, void *dev_id
, struct pt_regs
*regs
)
636 struct IsdnCardState
*cs
= dev_id
;
642 spin_lock_irqsave(&cs
->lock
, flags
);
643 cfg
= (u_char
*) cs
->hw
.diva
.pci_cfg
;
645 if (!(val
& PITA_INT0_STATUS
)) {
646 spin_unlock_irqrestore(&cs
->lock
, flags
);
647 return IRQ_NONE
; /* other shared IRQ */
649 *cfg
= PITA_INT0_STATUS
; /* Reset pending INT0 */
650 ista
= memreadreg(cs
->hw
.diva
.cfg_reg
, IPAC_ISTA
);
652 if (cs
->debug
& L1_DEB_IPAC
)
653 debugl1(cs
, "IPAC ISTA %02X", ista
);
655 val
= memreadreg(cs
->hw
.diva
.cfg_reg
, HSCX_ISTA
+ 0x40);
663 Memhscx_int_main(cs
, val
);
666 val
= 0xfe & memreadreg(cs
->hw
.diva
.cfg_reg
, ISAC_ISTA
+ 0x80);
668 isac_interrupt(cs
, val
);
673 isac_interrupt(cs
, val
);
675 ista
= memreadreg(cs
->hw
.diva
.cfg_reg
, IPAC_ISTA
);
676 if ((ista
& 0x3f) && icnt
) {
681 printk(KERN_WARNING
"DIVA IPAC PCI IRQ LOOP\n");
682 memwritereg(cs
->hw
.diva
.cfg_reg
, IPAC_MASK
, 0xFF);
683 memwritereg(cs
->hw
.diva
.cfg_reg
, IPAC_MASK
, 0xC0);
684 spin_unlock_irqrestore(&cs
->lock
, flags
);
689 diva_irq_ipacx_pci(int intno
, void *dev_id
, struct pt_regs
*regs
)
691 struct IsdnCardState
*cs
= dev_id
;
696 spin_lock_irqsave(&cs
->lock
, flags
);
697 cfg
= (u_char
*) cs
->hw
.diva
.pci_cfg
;
699 if (!(val
&PITA_INT0_STATUS
)) {
700 spin_unlock_irqrestore(&cs
->lock
, flags
);
701 return IRQ_NONE
; // other shared IRQ
703 interrupt_ipacx(cs
); // handler for chip
704 *cfg
= PITA_INT0_STATUS
; // Reset PLX interrupt
705 spin_unlock_irqrestore(&cs
->lock
, flags
);
710 release_io_diva(struct IsdnCardState
*cs
)
714 if ((cs
->subtyp
== DIVA_IPAC_PCI
) ||
715 (cs
->subtyp
== DIVA_IPACX_PCI
) ) {
716 u_int
*cfg
= (unsigned int *)cs
->hw
.diva
.pci_cfg
;
718 *cfg
= 0; /* disable INT0/1 */
719 *cfg
= 2; /* reset pending INT0 */
720 iounmap((void *)cs
->hw
.diva
.cfg_reg
);
721 iounmap((void *)cs
->hw
.diva
.pci_cfg
);
723 } else if (cs
->subtyp
!= DIVA_IPAC_ISA
) {
724 del_timer(&cs
->hw
.diva
.tl
);
725 if (cs
->hw
.diva
.cfg_reg
)
726 byteout(cs
->hw
.diva
.ctrl
, 0); /* LED off, Reset */
728 if ((cs
->subtyp
== DIVA_ISA
) || (cs
->subtyp
== DIVA_IPAC_ISA
))
732 if (cs
->hw
.diva
.cfg_reg
) {
733 release_region(cs
->hw
.diva
.cfg_reg
, bytecnt
);
738 reset_diva(struct IsdnCardState
*cs
)
740 if (cs
->subtyp
== DIVA_IPAC_ISA
) {
741 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_POTA2
, 0x20);
743 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_POTA2
, 0x00);
745 writereg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_MASK
, 0xc0);
746 } else if (cs
->subtyp
== DIVA_IPAC_PCI
) {
747 unsigned int *ireg
= (unsigned int *)(cs
->hw
.diva
.pci_cfg
+
749 *ireg
= PITA_PARA_SOFTRESET
| PITA_PARA_MPX_MODE
;
751 *ireg
= PITA_PARA_MPX_MODE
;
753 memwritereg(cs
->hw
.diva
.cfg_reg
, IPAC_MASK
, 0xc0);
754 } else if (cs
->subtyp
== DIVA_IPACX_PCI
) {
755 unsigned int *ireg
= (unsigned int *)(cs
->hw
.diva
.pci_cfg
+
757 *ireg
= PITA_PARA_SOFTRESET
| PITA_PARA_MPX_MODE
;
759 *ireg
= PITA_PARA_MPX_MODE
| PITA_SER_SOFTRESET
;
761 MemWriteISAC_IPACX(cs
, IPACX_MASK
, 0xff); // Interrupts off
762 } else { /* DIVA 2.0 */
763 cs
->hw
.diva
.ctrl_reg
= 0; /* Reset On */
764 byteout(cs
->hw
.diva
.ctrl
, cs
->hw
.diva
.ctrl_reg
);
766 cs
->hw
.diva
.ctrl_reg
|= DIVA_RESET
; /* Reset Off */
767 byteout(cs
->hw
.diva
.ctrl
, cs
->hw
.diva
.ctrl_reg
);
769 if (cs
->subtyp
== DIVA_ISA
)
770 cs
->hw
.diva
.ctrl_reg
|= DIVA_ISA_LED_A
;
772 /* Workaround PCI9060 */
773 byteout(cs
->hw
.diva
.pci_cfg
+ 0x69, 9);
774 cs
->hw
.diva
.ctrl_reg
|= DIVA_PCI_LED_A
;
776 byteout(cs
->hw
.diva
.ctrl
, cs
->hw
.diva
.ctrl_reg
);
780 #define DIVA_ASSIGN 1
783 diva_led_handler(struct IsdnCardState
*cs
)
787 if ((cs
->subtyp
== DIVA_IPAC_ISA
) ||
788 (cs
->subtyp
== DIVA_IPAC_PCI
) ||
789 (cs
->subtyp
== DIVA_IPACX_PCI
) )
791 del_timer(&cs
->hw
.diva
.tl
);
792 if (cs
->hw
.diva
.status
& DIVA_ASSIGN
)
793 cs
->hw
.diva
.ctrl_reg
|= (DIVA_ISA
== cs
->subtyp
) ?
794 DIVA_ISA_LED_A
: DIVA_PCI_LED_A
;
796 cs
->hw
.diva
.ctrl_reg
^= (DIVA_ISA
== cs
->subtyp
) ?
797 DIVA_ISA_LED_A
: DIVA_PCI_LED_A
;
800 if (cs
->hw
.diva
.status
& 0xf000)
801 cs
->hw
.diva
.ctrl_reg
|= (DIVA_ISA
== cs
->subtyp
) ?
802 DIVA_ISA_LED_B
: DIVA_PCI_LED_B
;
803 else if (cs
->hw
.diva
.status
& 0x0f00) {
804 cs
->hw
.diva
.ctrl_reg
^= (DIVA_ISA
== cs
->subtyp
) ?
805 DIVA_ISA_LED_B
: DIVA_PCI_LED_B
;
808 cs
->hw
.diva
.ctrl_reg
&= ~((DIVA_ISA
== cs
->subtyp
) ?
809 DIVA_ISA_LED_B
: DIVA_PCI_LED_B
);
811 byteout(cs
->hw
.diva
.ctrl
, cs
->hw
.diva
.ctrl_reg
);
813 init_timer(&cs
->hw
.diva
.tl
);
814 cs
->hw
.diva
.tl
.expires
= jiffies
+ ((blink
* HZ
) / 1000);
815 add_timer(&cs
->hw
.diva
.tl
);
820 Diva_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
827 spin_lock_irqsave(&cs
->lock
, flags
);
829 spin_unlock_irqrestore(&cs
->lock
, flags
);
835 spin_lock_irqsave(&cs
->lock
, flags
);
837 if (cs
->subtyp
== DIVA_IPACX_PCI
) {
838 ireg
= (unsigned int *)cs
->hw
.diva
.pci_cfg
;
839 *ireg
= PITA_INT0_ENABLE
;
840 init_ipacx(cs
, 3); // init chip and enable interrupts
841 spin_unlock_irqrestore(&cs
->lock
, flags
);
844 if (cs
->subtyp
== DIVA_IPAC_PCI
) {
845 ireg
= (unsigned int *)cs
->hw
.diva
.pci_cfg
;
846 *ireg
= PITA_INT0_ENABLE
;
849 spin_unlock_irqrestore(&cs
->lock
, flags
);
853 case (MDL_REMOVE
| REQUEST
):
854 cs
->hw
.diva
.status
= 0;
856 case (MDL_ASSIGN
| REQUEST
):
857 cs
->hw
.diva
.status
|= DIVA_ASSIGN
;
861 cs
->hw
.diva
.status
|= 0x0200;
863 cs
->hw
.diva
.status
|= 0x0100;
867 cs
->hw
.diva
.status
|= 0x2000;
869 cs
->hw
.diva
.status
|= 0x1000;
873 cs
->hw
.diva
.status
&= ~0x2000;
874 cs
->hw
.diva
.status
&= ~0x0200;
876 cs
->hw
.diva
.status
&= ~0x1000;
877 cs
->hw
.diva
.status
&= ~0x0100;
881 if ((cs
->subtyp
!= DIVA_IPAC_ISA
) &&
882 (cs
->subtyp
!= DIVA_IPAC_PCI
) &&
883 (cs
->subtyp
!= DIVA_IPACX_PCI
)) {
884 spin_lock_irqsave(&cs
->lock
, flags
);
885 diva_led_handler(cs
);
886 spin_unlock_irqrestore(&cs
->lock
, flags
);
891 static struct pci_dev
*dev_diva __initdata
= NULL
;
892 static struct pci_dev
*dev_diva_u __initdata
= NULL
;
893 static struct pci_dev
*dev_diva201 __initdata
= NULL
;
894 static struct pci_dev
*dev_diva202 __initdata
= NULL
;
897 static struct isapnp_device_id diva_ids
[] __initdata
= {
898 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
899 ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
900 (unsigned long) "Diva picola" },
901 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
902 ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0x51),
903 (unsigned long) "Diva picola" },
904 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
905 ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
906 (unsigned long) "Diva 2.0" },
907 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
908 ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0x71),
909 (unsigned long) "Diva 2.0" },
910 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
911 ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
912 (unsigned long) "Diva 2.01" },
913 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
914 ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0xA1),
915 (unsigned long) "Diva 2.01" },
919 static struct isapnp_device_id
*ipid __initdata
= &diva_ids
[0];
920 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
925 setup_diva(struct IsdnCard
*card
)
929 struct IsdnCardState
*cs
= card
->cs
;
932 strcpy(tmp
, Diva_revision
);
933 printk(KERN_INFO
"HiSax: Eicon.Diehl Diva driver Rev. %s\n", HiSax_getrev(tmp
));
934 if (cs
->typ
!= ISDN_CTYPE_DIEHLDIVA
)
936 cs
->hw
.diva
.status
= 0;
938 cs
->hw
.diva
.ctrl_reg
= 0;
939 cs
->hw
.diva
.cfg_reg
= card
->para
[1];
940 val
= readreg(cs
->hw
.diva
.cfg_reg
+ DIVA_IPAC_ADR
,
941 cs
->hw
.diva
.cfg_reg
+ DIVA_IPAC_DATA
, IPAC_ID
);
942 printk(KERN_INFO
"Diva: IPAC version %x\n", val
);
943 if ((val
== 1) || (val
==2)) {
944 cs
->subtyp
= DIVA_IPAC_ISA
;
945 cs
->hw
.diva
.ctrl
= 0;
946 cs
->hw
.diva
.isac
= card
->para
[1] + DIVA_IPAC_DATA
;
947 cs
->hw
.diva
.hscx
= card
->para
[1] + DIVA_IPAC_DATA
;
948 cs
->hw
.diva
.isac_adr
= card
->para
[1] + DIVA_IPAC_ADR
;
949 cs
->hw
.diva
.hscx_adr
= card
->para
[1] + DIVA_IPAC_ADR
;
950 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
952 cs
->subtyp
= DIVA_ISA
;
953 cs
->hw
.diva
.ctrl
= card
->para
[1] + DIVA_ISA_CTRL
;
954 cs
->hw
.diva
.isac
= card
->para
[1] + DIVA_ISA_ISAC_DATA
;
955 cs
->hw
.diva
.hscx
= card
->para
[1] + DIVA_HSCX_DATA
;
956 cs
->hw
.diva
.isac_adr
= card
->para
[1] + DIVA_ISA_ISAC_ADR
;
957 cs
->hw
.diva
.hscx_adr
= card
->para
[1] + DIVA_HSCX_ADR
;
959 cs
->irq
= card
->para
[0];
962 if (isapnp_present()) {
963 struct pnp_dev
*pnp_d
;
964 while(ipid
->card_vendor
) {
965 if ((pnp_c
= pnp_find_card(ipid
->card_vendor
,
966 ipid
->card_device
, pnp_c
))) {
968 if ((pnp_d
= pnp_find_dev(pnp_c
,
969 ipid
->vendor
, ipid
->function
, pnp_d
))) {
972 printk(KERN_INFO
"HiSax: %s detected\n",
973 (char *)ipid
->driver_data
);
974 pnp_disable_dev(pnp_d
);
975 err
= pnp_activate_dev(pnp_d
);
977 printk(KERN_WARNING
"%s: pnp_activate_dev ret(%d)\n",
981 card
->para
[1] = pnp_port_start(pnp_d
, 0);
982 card
->para
[0] = pnp_irq(pnp_d
, 0);
983 if (!card
->para
[0] || !card
->para
[1]) {
984 printk(KERN_ERR
"Diva PnP:some resources are missing %ld/%lx\n",
985 card
->para
[0], card
->para
[1]);
986 pnp_disable_dev(pnp_d
);
989 cs
->hw
.diva
.cfg_reg
= card
->para
[1];
990 cs
->irq
= card
->para
[0];
991 if (ipid
->function
== ISAPNP_FUNCTION(0xA1)) {
992 cs
->subtyp
= DIVA_IPAC_ISA
;
993 cs
->hw
.diva
.ctrl
= 0;
995 card
->para
[1] + DIVA_IPAC_DATA
;
997 card
->para
[1] + DIVA_IPAC_DATA
;
998 cs
->hw
.diva
.isac_adr
=
999 card
->para
[1] + DIVA_IPAC_ADR
;
1000 cs
->hw
.diva
.hscx_adr
=
1001 card
->para
[1] + DIVA_IPAC_ADR
;
1002 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
1004 cs
->subtyp
= DIVA_ISA
;
1006 card
->para
[1] + DIVA_ISA_CTRL
;
1008 card
->para
[1] + DIVA_ISA_ISAC_DATA
;
1010 card
->para
[1] + DIVA_HSCX_DATA
;
1011 cs
->hw
.diva
.isac_adr
=
1012 card
->para
[1] + DIVA_ISA_ISAC_ADR
;
1013 cs
->hw
.diva
.hscx_adr
=
1014 card
->para
[1] + DIVA_HSCX_ADR
;
1018 printk(KERN_ERR
"Diva PnP: PnP error card found, no device\n");
1025 if (!ipid
->card_vendor
) {
1026 printk(KERN_INFO
"Diva PnP: no ISAPnP card found\n");
1032 if ((dev_diva
= pci_find_device(PCI_VENDOR_ID_EICON
,
1033 PCI_DEVICE_ID_EICON_DIVA20
, dev_diva
))) {
1034 if (pci_enable_device(dev_diva
))
1036 cs
->subtyp
= DIVA_PCI
;
1037 cs
->irq
= dev_diva
->irq
;
1038 cs
->hw
.diva
.cfg_reg
= pci_resource_start(dev_diva
, 2);
1039 } else if ((dev_diva_u
= pci_find_device(PCI_VENDOR_ID_EICON
,
1040 PCI_DEVICE_ID_EICON_DIVA20_U
, dev_diva_u
))) {
1041 if (pci_enable_device(dev_diva_u
))
1043 cs
->subtyp
= DIVA_PCI
;
1044 cs
->irq
= dev_diva_u
->irq
;
1045 cs
->hw
.diva
.cfg_reg
= pci_resource_start(dev_diva_u
, 2);
1046 } else if ((dev_diva201
= pci_find_device(PCI_VENDOR_ID_EICON
,
1047 PCI_DEVICE_ID_EICON_DIVA201
, dev_diva201
))) {
1048 if (pci_enable_device(dev_diva201
))
1050 cs
->subtyp
= DIVA_IPAC_PCI
;
1051 cs
->irq
= dev_diva201
->irq
;
1052 cs
->hw
.diva
.pci_cfg
=
1053 (ulong
) ioremap(pci_resource_start(dev_diva201
, 0), 4096);
1054 cs
->hw
.diva
.cfg_reg
=
1055 (ulong
) ioremap(pci_resource_start(dev_diva201
, 1), 4096);
1056 } else if ((dev_diva202
= pci_find_device(PCI_VENDOR_ID_EICON
,
1057 PCI_DEVICE_ID_EICON_DIVA202
, dev_diva202
))) {
1058 if (pci_enable_device(dev_diva202
))
1060 cs
->subtyp
= DIVA_IPACX_PCI
;
1061 cs
->irq
= dev_diva202
->irq
;
1062 cs
->hw
.diva
.pci_cfg
=
1063 (ulong
) ioremap(pci_resource_start(dev_diva202
, 0), 4096);
1064 cs
->hw
.diva
.cfg_reg
=
1065 (ulong
) ioremap(pci_resource_start(dev_diva202
, 1), 4096);
1067 printk(KERN_WARNING
"Diva: No PCI card found\n");
1072 printk(KERN_WARNING
"Diva: No IRQ for PCI card found\n");
1076 if (!cs
->hw
.diva
.cfg_reg
) {
1077 printk(KERN_WARNING
"Diva: No IO-Adr for PCI card found\n");
1080 cs
->irq_flags
|= SA_SHIRQ
;
1082 printk(KERN_WARNING
"Diva: cfgreg 0 and NO_PCI_BIOS\n");
1083 printk(KERN_WARNING
"Diva: unable to config DIVA PCI\n");
1085 #endif /* CONFIG_PCI */
1086 if ((cs
->subtyp
== DIVA_IPAC_PCI
) ||
1087 (cs
->subtyp
== DIVA_IPACX_PCI
) ) {
1088 cs
->hw
.diva
.ctrl
= 0;
1089 cs
->hw
.diva
.isac
= 0;
1090 cs
->hw
.diva
.hscx
= 0;
1091 cs
->hw
.diva
.isac_adr
= 0;
1092 cs
->hw
.diva
.hscx_adr
= 0;
1093 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
1096 cs
->hw
.diva
.ctrl
= cs
->hw
.diva
.cfg_reg
+ DIVA_PCI_CTRL
;
1097 cs
->hw
.diva
.isac
= cs
->hw
.diva
.cfg_reg
+ DIVA_PCI_ISAC_DATA
;
1098 cs
->hw
.diva
.hscx
= cs
->hw
.diva
.cfg_reg
+ DIVA_HSCX_DATA
;
1099 cs
->hw
.diva
.isac_adr
= cs
->hw
.diva
.cfg_reg
+ DIVA_PCI_ISAC_ADR
;
1100 cs
->hw
.diva
.hscx_adr
= cs
->hw
.diva
.cfg_reg
+ DIVA_HSCX_ADR
;
1106 "Diva: %s card configured at %#lx IRQ %d\n",
1107 (cs
->subtyp
== DIVA_PCI
) ? "PCI" :
1108 (cs
->subtyp
== DIVA_ISA
) ? "ISA" :
1109 (cs
->subtyp
== DIVA_IPAC_ISA
) ? "IPAC ISA" :
1110 (cs
->subtyp
== DIVA_IPAC_PCI
) ? "IPAC PCI" : "IPACX PCI",
1111 cs
->hw
.diva
.cfg_reg
, cs
->irq
);
1112 if ((cs
->subtyp
== DIVA_IPAC_PCI
) ||
1113 (cs
->subtyp
== DIVA_IPACX_PCI
) ||
1114 (cs
->subtyp
== DIVA_PCI
) )
1115 printk(KERN_INFO
"Diva: %s space at %#lx\n",
1116 (cs
->subtyp
== DIVA_PCI
) ? "PCI" :
1117 (cs
->subtyp
== DIVA_IPAC_PCI
) ? "IPAC PCI" : "IPACX PCI",
1118 cs
->hw
.diva
.pci_cfg
);
1119 if ((cs
->subtyp
!= DIVA_IPAC_PCI
) &&
1120 (cs
->subtyp
!= DIVA_IPACX_PCI
) ) {
1121 if (!request_region(cs
->hw
.diva
.cfg_reg
, bytecnt
, "diva isdn")) {
1123 "HiSax: %s config port %lx-%lx already in use\n",
1124 CardType
[card
->typ
],
1125 cs
->hw
.diva
.cfg_reg
,
1126 cs
->hw
.diva
.cfg_reg
+ bytecnt
);
1130 cs
->BC_Read_Reg
= &ReadHSCX
;
1131 cs
->BC_Write_Reg
= &WriteHSCX
;
1132 cs
->BC_Send_Data
= &hscx_fill_fifo
;
1133 cs
->cardmsg
= &Diva_card_msg
;
1135 if (cs
->subtyp
== DIVA_IPAC_ISA
) {
1136 cs
->readisac
= &ReadISAC_IPAC
;
1137 cs
->writeisac
= &WriteISAC_IPAC
;
1138 cs
->readisacfifo
= &ReadISACfifo_IPAC
;
1139 cs
->writeisacfifo
= &WriteISACfifo_IPAC
;
1140 cs
->irq_func
= &diva_irq_ipac_isa
;
1141 val
= readreg(cs
->hw
.diva
.isac_adr
, cs
->hw
.diva
.isac
, IPAC_ID
);
1142 printk(KERN_INFO
"Diva: IPAC version %x\n", val
);
1143 } else if (cs
->subtyp
== DIVA_IPAC_PCI
) {
1144 cs
->readisac
= &MemReadISAC_IPAC
;
1145 cs
->writeisac
= &MemWriteISAC_IPAC
;
1146 cs
->readisacfifo
= &MemReadISACfifo_IPAC
;
1147 cs
->writeisacfifo
= &MemWriteISACfifo_IPAC
;
1148 cs
->BC_Read_Reg
= &MemReadHSCX
;
1149 cs
->BC_Write_Reg
= &MemWriteHSCX
;
1150 cs
->BC_Send_Data
= &Memhscx_fill_fifo
;
1151 cs
->irq_func
= &diva_irq_ipac_pci
;
1152 val
= memreadreg(cs
->hw
.diva
.cfg_reg
, IPAC_ID
);
1153 printk(KERN_INFO
"Diva: IPAC version %x\n", val
);
1154 } else if (cs
->subtyp
== DIVA_IPACX_PCI
) {
1155 cs
->readisac
= &MemReadISAC_IPACX
;
1156 cs
->writeisac
= &MemWriteISAC_IPACX
;
1157 cs
->readisacfifo
= &MemReadISACfifo_IPACX
;
1158 cs
->writeisacfifo
= &MemWriteISACfifo_IPACX
;
1159 cs
->BC_Read_Reg
= &MemReadHSCX_IPACX
;
1160 cs
->BC_Write_Reg
= &MemWriteHSCX_IPACX
;
1161 cs
->BC_Send_Data
= NULL
; // function located in ipacx module
1162 cs
->irq_func
= &diva_irq_ipacx_pci
;
1163 printk(KERN_INFO
"Diva: IPACX Design Id: %x\n",
1164 MemReadISAC_IPACX(cs
, IPACX_ID
) &0x3F);
1165 } else { /* DIVA 2.0 */
1166 cs
->hw
.diva
.tl
.function
= (void *) diva_led_handler
;
1167 cs
->hw
.diva
.tl
.data
= (long) cs
;
1168 init_timer(&cs
->hw
.diva
.tl
);
1169 cs
->readisac
= &ReadISAC
;
1170 cs
->writeisac
= &WriteISAC
;
1171 cs
->readisacfifo
= &ReadISACfifo
;
1172 cs
->writeisacfifo
= &WriteISACfifo
;
1173 cs
->irq_func
= &diva_interrupt
;
1174 ISACVersion(cs
, "Diva:");
1175 if (HscxVersion(cs
, "Diva:")) {
1177 "Diva: wrong HSCX versions check IO address\n");
1178 release_io_diva(cs
);