25 #include <linux/pci.h>
28 static const char *Diva_revision =
"$Revision: 1.33.2.6 $";
30 #define byteout(addr, val) outb(val, addr)
31 #define bytein(addr) inb(addr)
33 #define DIVA_HSCX_DATA 0
34 #define DIVA_HSCX_ADR 4
35 #define DIVA_ISA_ISAC_DATA 2
36 #define DIVA_ISA_ISAC_ADR 6
37 #define DIVA_ISA_CTRL 7
38 #define DIVA_IPAC_ADR 0
39 #define DIVA_IPAC_DATA 1
41 #define DIVA_PCI_ISAC_DATA 8
42 #define DIVA_PCI_ISAC_ADR 0xc
43 #define DIVA_PCI_CTRL 0x10
48 #define DIVA_IPAC_ISA 3
49 #define DIVA_IPAC_PCI 4
50 #define DIVA_IPACX_PCI 5
53 #define DIVA_IRQ_STAT 0x01
54 #define DIVA_EEPROM_SDA 0x02
57 #define DIVA_IRQ_REQ 0x01
58 #define DIVA_RESET 0x08
59 #define DIVA_EEPROM_CLK 0x40
60 #define DIVA_PCI_LED_A 0x10
61 #define DIVA_PCI_LED_B 0x20
62 #define DIVA_ISA_LED_A 0x20
63 #define DIVA_ISA_LED_B 0x40
64 #define DIVA_IRQ_CLR 0x80
67 #define PITA_MISC_REG 0x1c
69 #define PITA_PARA_SOFTRESET 0x00000001
70 #define PITA_SER_SOFTRESET 0x00000002
71 #define PITA_PARA_MPX_MODE 0x00000004
72 #define PITA_INT0_ENABLE 0x00000200
74 #define PITA_PARA_SOFTRESET 0x01000000
75 #define PITA_SER_SOFTRESET 0x02000000
76 #define PITA_PARA_MPX_MODE 0x04000000
77 #define PITA_INT0_ENABLE 0x00020000
79 #define PITA_INT0_STATUS 0x02
95 insb(adr, data, size);
110 outsb(adr, data, size);
114 memreadreg(
unsigned long adr,
u_char off)
116 return (*((
unsigned char *)
117 (((
unsigned int *)adr) + off)));
125 p = (
unsigned char *)(((
unsigned int *)adr) + off);
134 return (
readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset));
140 writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset, value);
144 ReadISACfifo(
struct IsdnCardState *cs,
u_char *data,
int size)
146 readfifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0, data, size);
150 WriteISACfifo(
struct IsdnCardState *cs,
u_char *data,
int size)
152 writefifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0, data, size);
156 ReadISAC_IPAC(
struct IsdnCardState *cs,
u_char offset)
158 return (
readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset + 0x80));
164 writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset | 0x80, value);
168 ReadISACfifo_IPAC(
struct IsdnCardState *cs,
u_char *data,
int size)
170 readfifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0x80, data, size);
174 WriteISACfifo_IPAC(
struct IsdnCardState *cs,
u_char *data,
int size)
176 writefifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0x80, data, size);
182 return (
readreg(cs->hw.diva.hscx_adr,
183 cs->hw.diva.hscx, offset + (hscx ? 0x40 : 0)));
190 cs->hw.diva.hscx, offset + (hscx ? 0x40 : 0), value);
194 MemReadISAC_IPAC(
struct IsdnCardState *cs,
u_char offset)
196 return (memreadreg(cs->hw.diva.cfg_reg, offset + 0x80));
202 memwritereg(cs->hw.diva.cfg_reg, offset | 0x80, value);
206 MemReadISACfifo_IPAC(
struct IsdnCardState *cs,
u_char *data,
int size)
209 *data++ = memreadreg(cs->hw.diva.cfg_reg, 0x80);
213 MemWriteISACfifo_IPAC(
struct IsdnCardState *cs,
u_char *data,
int size)
216 memwritereg(cs->hw.diva.cfg_reg, 0x80, *data++);
220 MemReadHSCX(
struct IsdnCardState *cs,
int hscx,
u_char offset)
222 return (memreadreg(cs->hw.diva.cfg_reg, offset + (hscx ? 0x40 : 0)));
228 memwritereg(cs->hw.diva.cfg_reg, offset + (hscx ? 0x40 : 0), value);
233 MemReadISAC_IPACX(
struct IsdnCardState *cs,
u_char offset)
235 return (memreadreg(cs->hw.diva.cfg_reg, offset));
241 memwritereg(cs->hw.diva.cfg_reg, offset, value);
245 MemReadISACfifo_IPACX(
struct IsdnCardState *cs,
u_char *data,
int size)
248 *data++ = memreadreg(cs->hw.diva.cfg_reg, 0);
252 MemWriteISACfifo_IPACX(
struct IsdnCardState *cs,
u_char *data,
int size)
255 memwritereg(cs->hw.diva.cfg_reg, 0, *data++);
259 MemReadHSCX_IPACX(
struct IsdnCardState *cs,
int hscx,
u_char offset)
261 return (memreadreg(cs->hw.diva.cfg_reg, offset +
266 MemWriteHSCX_IPACX(
struct IsdnCardState *cs,
int hscx,
u_char offset,
u_char value)
268 memwritereg(cs->hw.diva.cfg_reg, offset +
276 #define READHSCX(cs, nr, reg) readreg(cs->hw.diva.hscx_adr, \
277 cs->hw.diva.hscx, reg + (nr ? 0x40 : 0))
278 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.diva.hscx_adr, \
279 cs->hw.diva.hscx, reg + (nr ? 0x40 : 0), data)
281 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.diva.hscx_adr, \
282 cs->hw.diva.hscx, (nr ? 0x40 : 0), ptr, cnt)
284 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.diva.hscx_adr, \
285 cs->hw.diva.hscx, (nr ? 0x40 : 0), ptr, cnt)
290 diva_interrupt(
int intno,
void *
dev_id)
292 struct IsdnCardState *cs =
dev_id;
301 hscx_int_main(cs, val);
315 spin_unlock_irqrestore(&cs->lock, flags);
320 diva_irq_ipac_isa(
int intno,
void *
dev_id)
322 struct IsdnCardState *cs =
dev_id;
330 if (cs->debug & L1_DEB_IPAC)
331 debugl1(cs,
"IPAC ISTA %02X", ista);
341 hscx_int_main(cs, val);
344 val = 0xfe &
readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac,
ISAC_ISTA + 0x80);
354 if ((ista & 0x3f) && icnt) {
362 spin_unlock_irqrestore(&cs->lock, flags);
367 MemwaitforCEC(
struct IsdnCardState *cs,
int hscx)
371 while ((MemReadHSCX(cs, hscx,
HSCX_STAR) & 0x04) && to) {
381 MemwaitforXFW(
struct IsdnCardState *cs,
int hscx)
385 while (((MemReadHSCX(cs, hscx,
HSCX_STAR) & 0x44) != 0x40) && to) {
394 MemWriteHSCXCMDR(
struct IsdnCardState *cs,
int hscx,
u_char data)
396 MemwaitforCEC(cs, hscx);
401 Memhscx_empty_fifo(
struct BCState *bcs,
int count)
404 struct IsdnCardState *cs = bcs->cs;
407 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
408 debugl1(cs,
"hscx_empty_fifo");
411 if (cs->debug & L1_DEB_WARN)
412 debugl1(cs,
"hscx_empty_fifo: incoming packet too large");
413 MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x80);
414 bcs->hw.hscx.rcvidx = 0;
417 ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
420 *ptr++ = memreadreg(cs->hw.diva.cfg_reg, bcs->hw.hscx.hscx ? 0x40 : 0);
421 MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x80);
422 ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
423 bcs->hw.hscx.rcvidx +=
count;
424 if (cs->debug & L1_DEB_HSCX_FIFO) {
427 t +=
sprintf(t,
"hscx_empty_fifo %c cnt %d",
428 bcs->hw.hscx.hscx ?
'B' :
'A', count);
435 Memhscx_fill_fifo(
struct BCState *bcs)
437 struct IsdnCardState *cs = bcs->cs;
442 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
447 if (bcs->tx_skb->len <= 0)
451 if (bcs->tx_skb->len > fifo_size) {
455 count = bcs->tx_skb->len;
457 MemwaitforXFW(cs, bcs->hw.hscx.hscx);
458 p = ptr = bcs->tx_skb->data;
460 bcs->tx_cnt -=
count;
461 bcs->hw.hscx.count +=
count;
463 memwritereg(cs->hw.diva.cfg_reg, bcs->hw.hscx.hscx ? 0x40 : 0,
465 MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, more ? 0x8 : 0xa);
466 if (cs->debug & L1_DEB_HSCX_FIFO) {
469 t +=
sprintf(t,
"hscx_fill_fifo %c cnt %d",
470 bcs->hw.hscx.hscx ?
'B' :
'A', count);
477 Memhscx_interrupt(
struct IsdnCardState *cs,
u_char val,
u_char hscx)
480 struct BCState *bcs = cs->bcs + hscx;
482 int fifo_size =
test_bit(HW_IPAC, &cs->HW_Flags) ? 64 : 32;
485 if (!
test_bit(BC_FLG_INIT, &bcs->Flag))
490 if ((r & 0xf0) != 0xa0) {
492 if (cs->debug & L1_DEB_WARN)
493 debugl1(cs,
"HSCX invalid frame");
494 if ((r & 0x40) && bcs->mode)
495 if (cs->debug & L1_DEB_WARN)
496 debugl1(cs,
"HSCX RDO mode=%d",
499 if (cs->debug & L1_DEB_WARN)
501 MemWriteHSCXCMDR(cs, hscx, 0x80);
503 count = MemReadHSCX(cs, hscx,
HSCX_RBCL) & (
504 test_bit(HW_IPAC, &cs->HW_Flags) ? 0x3f : 0x1f);
507 Memhscx_empty_fifo(bcs, count);
508 if ((count = bcs->hw.hscx.rcvidx - 1) > 0) {
509 if (cs->debug & L1_DEB_HSCX_FIFO)
510 debugl1(cs,
"HX Frame %d", count);
511 if (!(skb = dev_alloc_skb(count)))
519 bcs->hw.hscx.rcvidx = 0;
523 Memhscx_empty_fifo(bcs, fifo_size);
526 if (!(skb = dev_alloc_skb(fifo_size)))
529 memcpy(
skb_put(skb, fifo_size), bcs->hw.hscx.rcvbuf, fifo_size);
532 bcs->hw.hscx.rcvidx = 0;
538 if (bcs->tx_skb->len) {
539 Memhscx_fill_fifo(bcs);
542 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
543 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
546 bcs->ackcnt += bcs->hw.hscx.count;
547 spin_unlock_irqrestore(&bcs->aclock, flags);
551 bcs->hw.hscx.count = 0;
556 bcs->hw.hscx.count = 0;
558 Memhscx_fill_fifo(bcs);
567 Memhscx_int_main(
struct IsdnCardState *cs,
u_char val)
578 Memhscx_fill_fifo(bcs);
584 skb_push(bcs->tx_skb, bcs->hw.hscx.count);
585 bcs->tx_cnt += bcs->hw.hscx.count;
586 bcs->hw.hscx.count = 0;
588 MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x01);
589 if (cs->debug & L1_DEB_WARN)
590 debugl1(cs,
"HSCX B EXIR %x Lost TX", exval);
592 }
else if (cs->debug & L1_DEB_HSCX)
593 debugl1(cs,
"HSCX B EXIR %x", exval);
596 if (cs->debug & L1_DEB_HSCX)
597 debugl1(cs,
"HSCX B interrupt %x", val);
598 Memhscx_interrupt(cs, val, 1);
605 Memhscx_fill_fifo(bcs);
611 skb_push(bcs->tx_skb, bcs->hw.hscx.count);
612 bcs->tx_cnt += bcs->hw.hscx.count;
613 bcs->hw.hscx.count = 0;
615 MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x01);
616 if (cs->debug & L1_DEB_WARN)
617 debugl1(cs,
"HSCX A EXIR %x Lost TX", exval);
619 }
else if (cs->debug & L1_DEB_HSCX)
620 debugl1(cs,
"HSCX A EXIR %x", exval);
624 if (cs->debug & L1_DEB_HSCX)
625 debugl1(cs,
"HSCX A interrupt %x", exval);
626 Memhscx_interrupt(cs, exval, 0);
631 diva_irq_ipac_pci(
int intno,
void *dev_id)
633 struct IsdnCardState *cs =
dev_id;
640 cfg = (
u_char *) cs->hw.diva.pci_cfg;
643 spin_unlock_irqrestore(&cs->lock, flags);
647 ista = memreadreg(cs->hw.diva.cfg_reg,
IPAC_ISTA);
649 if (cs->debug & L1_DEB_IPAC)
650 debugl1(cs,
"IPAC ISTA %02X", ista);
652 val = memreadreg(cs->hw.diva.cfg_reg,
HSCX_ISTA + 0x40);
660 Memhscx_int_main(cs, val);
663 val = 0xfe & memreadreg(cs->hw.diva.cfg_reg,
ISAC_ISTA + 0x80);
672 ista = memreadreg(cs->hw.diva.cfg_reg,
IPAC_ISTA);
673 if ((ista & 0x3f) && icnt) {
679 memwritereg(cs->hw.diva.cfg_reg,
IPAC_MASK, 0xFF);
680 memwritereg(cs->hw.diva.cfg_reg,
IPAC_MASK, 0xC0);
681 spin_unlock_irqrestore(&cs->lock, flags);
686 diva_irq_ipacx_pci(
int intno,
void *dev_id)
688 struct IsdnCardState *cs =
dev_id;
694 cfg = (
u_char *) cs->hw.diva.pci_cfg;
696 if (!(val & PITA_INT0_STATUS)) {
697 spin_unlock_irqrestore(&cs->lock, flags);
702 spin_unlock_irqrestore(&cs->lock, flags);
707 release_io_diva(
struct IsdnCardState *cs)
713 u_int *cfg = (
unsigned int *)cs->hw.diva.pci_cfg;
717 if (cs->hw.diva.cfg_reg)
718 iounmap((
void *)cs->hw.diva.cfg_reg);
719 if (cs->hw.diva.pci_cfg)
720 iounmap((
void *)cs->hw.diva.pci_cfg);
724 if (cs->hw.diva.cfg_reg)
731 if (cs->hw.diva.cfg_reg) {
737 iounmap_diva(
struct IsdnCardState *cs)
740 if (cs->hw.diva.cfg_reg) {
741 iounmap((
void *)cs->hw.diva.cfg_reg);
742 cs->hw.diva.cfg_reg = 0;
744 if (cs->hw.diva.pci_cfg) {
745 iounmap((
void *)cs->hw.diva.pci_cfg);
746 cs->hw.diva.pci_cfg = 0;
754 reset_diva(
struct IsdnCardState *cs)
763 unsigned int *ireg = (
unsigned int *)(cs->hw.diva.pci_cfg +
769 memwritereg(cs->hw.diva.cfg_reg,
IPAC_MASK, 0xc0);
771 unsigned int *ireg = (
unsigned int *)(cs->hw.diva.pci_cfg +
779 cs->hw.diva.ctrl_reg = 0;
780 byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
783 byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
789 byteout(cs->hw.diva.pci_cfg + 0x69, 9);
792 byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
796 #define DIVA_ASSIGN 1
799 diva_led_handler(
struct IsdnCardState *cs)
809 cs->hw.diva.ctrl_reg |= (
DIVA_ISA == cs->subtyp) ?
812 cs->hw.diva.ctrl_reg ^= (
DIVA_ISA == cs->subtyp) ?
816 if (cs->hw.diva.status & 0xf000)
817 cs->hw.diva.ctrl_reg |= (
DIVA_ISA == cs->subtyp) ?
819 else if (cs->hw.diva.status & 0x0f00) {
820 cs->hw.diva.ctrl_reg ^= (
DIVA_ISA == cs->subtyp) ?
824 cs->hw.diva.ctrl_reg &= ~((
DIVA_ISA == cs->subtyp) ?
827 byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
830 cs->hw.diva.tl.expires =
jiffies + ((blink *
HZ) / 1000);
836 Diva_card_msg(
struct IsdnCardState *cs,
int mt,
void *
arg)
845 spin_unlock_irqrestore(&cs->lock, flags);
854 ireg = (
unsigned int *)cs->hw.diva.pci_cfg;
857 spin_unlock_irqrestore(&cs->lock, flags);
861 ireg = (
unsigned int *)cs->hw.diva.pci_cfg;
865 spin_unlock_irqrestore(&cs->lock, flags);
870 cs->hw.diva.status = 0;
877 cs->hw.diva.status |= 0x0200;
879 cs->hw.diva.status |= 0x0100;
883 cs->hw.diva.status |= 0x2000;
885 cs->hw.diva.status |= 0x1000;
889 cs->hw.diva.status &= ~0x2000;
890 cs->hw.diva.status &= ~0x0200;
892 cs->hw.diva.status &= ~0x1000;
893 cs->hw.diva.status &= ~0x0100;
901 diva_led_handler(cs);
902 spin_unlock_irqrestore(&cs->lock, flags);
907 static int __devinit setup_diva_common(
struct IsdnCardState *cs)
918 "Diva: %s card configured at %#lx IRQ %d\n",
923 cs->hw.diva.cfg_reg, cs->irq);
930 cs->hw.diva.pci_cfg);
935 "HiSax: %s config port %lx-%lx already in use\n",
938 cs->hw.diva.cfg_reg + bytecnt);
945 cs->BC_Send_Data = &hscx_fill_fifo;
946 cs->cardmsg = &Diva_card_msg;
949 cs->readisac = &ReadISAC_IPAC;
950 cs->writeisac = &WriteISAC_IPAC;
951 cs->readisacfifo = &ReadISACfifo_IPAC;
952 cs->writeisacfifo = &WriteISACfifo_IPAC;
953 cs->irq_func = &diva_irq_ipac_isa;
957 cs->readisac = &MemReadISAC_IPAC;
958 cs->writeisac = &MemWriteISAC_IPAC;
959 cs->readisacfifo = &MemReadISACfifo_IPAC;
960 cs->writeisacfifo = &MemWriteISACfifo_IPAC;
961 cs->BC_Read_Reg = &MemReadHSCX;
962 cs->BC_Write_Reg = &MemWriteHSCX;
963 cs->BC_Send_Data = &Memhscx_fill_fifo;
964 cs->irq_func = &diva_irq_ipac_pci;
965 val = memreadreg(cs->hw.diva.cfg_reg,
IPAC_ID);
968 cs->readisac = &MemReadISAC_IPACX;
969 cs->writeisac = &MemWriteISAC_IPACX;
970 cs->readisacfifo = &MemReadISACfifo_IPACX;
971 cs->writeisacfifo = &MemWriteISACfifo_IPACX;
972 cs->BC_Read_Reg = &MemReadHSCX_IPACX;
973 cs->BC_Write_Reg = &MemWriteHSCX_IPACX;
974 cs->BC_Send_Data =
NULL;
975 cs->irq_func = &diva_irq_ipacx_pci;
977 MemReadISAC_IPACX(cs,
IPACX_ID) & 0x3F);
979 cs->hw.diva.tl.function = (
void *) diva_led_handler;
980 cs->hw.diva.tl.data = (
long) cs;
984 cs->readisacfifo = &ReadISACfifo;
985 cs->writeisacfifo = &WriteISACfifo;
986 cs->irq_func = &diva_interrupt;
990 "Diva: wrong HSCX versions check IO address\n");
1002 struct IsdnCardState *cs = card->
cs;
1008 cs->hw.diva.ctrl_reg = 0;
1009 cs->hw.diva.cfg_reg = card->
para[1];
1013 if ((val == 1) || (val == 2)) {
1015 cs->hw.diva.ctrl = 0;
1029 cs->irq = card->
para[0];
1047 (
unsigned long)
"Diva picola" },
1050 (
unsigned long)
"Diva picola" },
1053 (
unsigned long)
"Diva 2.0" },
1056 (
unsigned long)
"Diva 2.0" },
1059 (
unsigned long)
"Diva 2.01" },
1062 (
unsigned long)
"Diva 2.01" },
1071 struct IsdnCardState *cs = card->
cs;
1077 while (ipid->card_vendor) {
1079 ipid->card_device, pnp_c))) {
1082 ipid->vendor, ipid->function, pnp_d))) {
1086 (
char *)ipid->driver_data);
1094 card->
para[1] = pnp_port_start(pnp_d, 0);
1096 if (!card->
para[0] || !card->
para[1]) {
1102 cs->hw.diva.cfg_reg = card->
para[1];
1103 cs->irq = card->
para[0];
1106 cs->hw.diva.ctrl = 0;
1111 cs->hw.diva.isac_adr =
1113 cs->hw.diva.hscx_adr =
1124 cs->hw.diva.isac_adr =
1126 cs->hw.diva.hscx_adr =
1152 static struct pci_dev *dev_diva __devinitdata =
NULL;
1153 static struct pci_dev *dev_diva_u __devinitdata =
NULL;
1154 static struct pci_dev *dev_diva201 __devinitdata =
NULL;
1155 static struct pci_dev *dev_diva202 __devinitdata =
NULL;
1159 struct IsdnCardState *cs = card->
cs;
1167 cs->irq = dev_diva->irq;
1174 cs->irq = dev_diva_u->irq;
1181 cs->irq = dev_diva201->irq;
1182 cs->hw.diva.pci_cfg =
1184 cs->hw.diva.cfg_reg =
1191 cs->irq = dev_diva202->irq;
1192 cs->hw.diva.pci_cfg =
1194 cs->hw.diva.cfg_reg =
1206 if (!cs->hw.diva.cfg_reg) {
1215 cs->hw.diva.ctrl = 0;
1216 cs->hw.diva.isac = 0;
1217 cs->hw.diva.hscx = 0;
1218 cs->hw.diva.isac_adr = 0;
1219 cs->hw.diva.hscx_adr = 0;
1244 int rc, have_card = 0;
1245 struct IsdnCardState *cs = card->
cs;
1248 strcpy(tmp, Diva_revision);
1252 cs->hw.diva.status = 0;
1254 rc = setup_diva_isa(card);
1262 rc = setup_diva_isapnp(card);
1270 rc = setup_diva_pci(card);
1282 return setup_diva_common(card->
cs);