22 #include <linux/slab.h>
29 #include <linux/pci.h>
31 #include <linux/serial.h>
34 static const char *Elsa_revision =
"$Revision: 2.32.2.4 $";
35 static const char *Elsa_Types[] =
36 {
"None",
"PC",
"PCC-8",
"PCC-16",
"PCF",
"PCF-Pro",
37 "PCMCIA",
"QS 1000",
"QS 3000",
"Microlink PCI",
"QS 3000 PCI",
40 static const char *ITACVer[] =
41 {
"?0?",
"?1?",
"?2?",
"?3?",
"?4?",
"V2.2",
44 #define byteout(addr, val) outb(val, addr)
45 #define bytein(addr) inb(addr)
48 #define ELSA_ISAC_PCM 1
52 #define ELSA_ALE_PCM 4
53 #define ELSA_CONTROL 4
55 #define ELSA_START_TIMER 6
56 #define ELSA_TRIG_IRQ 7
66 #define ELSA_QS1000PCI 9
67 #define ELSA_QS3000PCI 10
68 #define ELSA_PCMCIA_IPAC 11
71 #define ELSA_PCI_IRQ_MASK 0x04
75 #define ITAC_ISEN 0x48
76 #define ITAC_RFIE 0x4A
77 #define ITAC_XFIE 0x4C
78 #define ITAC_SCIE 0x4E
79 #define ITAC_STIE 0x46
87 #define ELIRQF_TIMER_RUN 0x02
88 #define ELIRQF_TIMER_RUN_PCC8 0x01
89 #define ELSA_IRQ_IDX 0x38
90 #define ELSA_IRQ_IDX_PCC8 0x30
91 #define ELSA_IRQ_IDX_PC 0x0c
94 #define ELSA_LINE_LED 0x02
95 #define ELSA_STAT_LED 0x08
96 #define ELSA_ISDN_RESET 0x20
97 #define ELSA_ENA_TIMER_INT 0x80
100 #define ELSA_HW_RELEASE 0x07
101 #define ELSA_S0_POWER_BAD 0x08
104 #define ELIRQF_TIMER_AKTIV 1
105 #define ELSA_BAD_PWR 2
106 #define ELSA_ASSIGN 4
108 #define RS_ISR_PASS_LIMIT 256
109 #define FLG_MODEM_ACTIVE 1
111 #define ELSA_IPAC_LINE_LED 0x40
112 #define ELSA_IPAC_STAT_LED 0x80
115 static struct arcofi_msg ARCOFI_XOP_F =
116 {
NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}};
117 static struct arcofi_msg ARCOFI_XOP_1 =
118 {&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}};
119 static struct arcofi_msg ARCOFI_SOP_F =
120 {&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
121 static struct arcofi_msg ARCOFI_COP_9 =
122 {&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}};
123 static struct arcofi_msg ARCOFI_COP_8 =
124 {&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}};
125 static struct arcofi_msg ARCOFI_COP_7 =
126 {&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}};
127 static struct arcofi_msg ARCOFI_COP_6 =
128 {&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}};
129 static struct arcofi_msg ARCOFI_COP_5 =
130 {&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}};
131 static struct arcofi_msg ARCOFI_VERSION =
132 {
NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
133 static struct arcofi_msg ARCOFI_XOP_0 =
134 {
NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}};
136 static void set_arcofi(
struct IsdnCardState *
cs,
int bc);
155 insb(adr, data, size);
170 outsb(adr, data, size);
178 return (
readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
184 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
190 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
196 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
200 ReadISAC_IPAC(
struct IsdnCardState *cs,
u_char offset)
202 return (
readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset + 0x80));
208 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset | 0x80, value);
212 ReadISACfifo_IPAC(
struct IsdnCardState *cs,
u_char *
data,
int size)
214 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
218 WriteISACfifo_IPAC(
struct IsdnCardState *cs,
u_char *
data,
int size)
220 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
226 return (
readreg(cs->hw.elsa.ale,
227 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
234 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
238 readitac(
struct IsdnCardState *cs,
u_char off)
243 ret =
bytein(cs->hw.elsa.itac);
251 byteout(cs->hw.elsa.itac, data);
255 TimerRun(
struct IsdnCardState *cs)
259 v =
bytein(cs->hw.elsa.cfg);
264 return (v & ELIRQF_TIMER_RUN);
270 #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
271 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
272 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
273 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
275 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
276 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
278 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
279 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
284 elsa_interrupt(
int intno,
void *
dev_id)
286 struct IsdnCardState *cs =
dev_id;
299 if (cs->hw.elsa.MFlag) {
303 rs_interrupt_elsa(cs);
310 hscx_int_main(cs, val);
319 if (cs->debug & L1_DEB_HSCX)
320 debugl1(cs,
"HSCX IntStat after IntRoutine");
326 if (cs->debug & L1_DEB_ISAC)
327 debugl1(cs,
"ISAC IntStat after IntRoutine");
340 cs->hw.elsa.counter++;
344 if (cs->hw.elsa.MFlag) {
353 if (cs->hw.elsa.trig)
354 byteout(cs->hw.elsa.trig, 0x00);
358 spin_unlock_irqrestore(&cs->lock, flags);
363 elsa_interrupt_ipac(
int intno,
void *
dev_id)
365 struct IsdnCardState *cs =
dev_id;
372 val =
bytein(cs->hw.elsa.cfg + 0x4c);
374 spin_unlock_irqrestore(&cs->lock, flags);
379 if (cs->hw.elsa.MFlag) {
383 rs_interrupt_elsa(cs);
389 if (cs->debug & L1_DEB_IPAC)
390 debugl1(cs,
"IPAC ISTA %02X", ista);
400 hscx_int_main(cs, val);
413 if ((ista & 0x3f) && icnt) {
421 spin_unlock_irqrestore(&cs->lock, flags);
426 release_io_elsa(
struct IsdnCardState *cs)
434 if (cs->hw.elsa.ctrl)
437 byteout(cs->hw.elsa.cfg + 0x4c, 0x01);
443 byteout(cs->hw.elsa.cfg + 0x4c, 0x03);
459 if (cs->hw.elsa.base)
464 reset_elsa(
struct IsdnCardState *cs)
466 if (cs->hw.elsa.timer) {
469 while (TimerRun(cs));
470 cs->hw.elsa.ctrl_reg |= 0x50;
472 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
475 while (TimerRun(cs));
477 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
480 while (TimerRun(cs));
481 if (cs->hw.elsa.trig)
482 byteout(cs->hw.elsa.trig, 0xff);
500 byteout(cs->hw.elsa.cfg + 0x4c, 0x41);
502 byteout(cs->hw.elsa.cfg + 0x4c, 0x43);
509 set_arcofi(
struct IsdnCardState *cs,
int bc) {
510 cs->dc.isac.arcofi_bc =
bc;
516 check_arcofi(
struct IsdnCardState *cs)
518 int arcofi_present = 0;
523 if (!cs->dc.isac.mon_tx)
525 if (cs->debug & L1_DEB_WARN)
526 debugl1(cs,
"ISAC MON TX out of buffers!");
529 cs->dc.isac.arcofi_bc = 0;
533 debugl1(cs,
"Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
534 p = cs->dc.isac.mon_rx;
536 t +=
sprintf(tmp,
"Arcofi data");
537 QuickHex(t, p, cs->dc.isac.mon_rxp);
539 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
540 switch (cs->dc.isac.mon_rx[1]) {
542 debugl1(cs,
"Arcofi 2160 detected");
546 debugl1(cs,
"Arcofi 2165 detected");
550 debugl1(cs,
"Arcofi 2163 detected");
554 debugl1(cs,
"unknown Arcofi response");
558 debugl1(cs,
"undefined Monitor response");
559 cs->dc.isac.mon_rxp = 0;
560 }
else if (cs->dc.isac.mon_tx) {
561 debugl1(cs,
"Arcofi not detected");
563 if (arcofi_present) {
567 "Elsa: %s detected modem at 0x%lx\n",
568 Elsa_Types[cs->subtyp],
569 cs->hw.elsa.base + 8);
573 "HiSax: %s config port %lx-%lx already in use\n",
574 Elsa_Types[cs->subtyp],
575 cs->hw.elsa.base + 8,
576 cs->hw.elsa.base + 16);
581 "Elsa: %s detected modem at 0x%lx\n",
582 Elsa_Types[cs->subtyp],
583 cs->hw.elsa.base + 8);
587 "HiSax: %s config port %lx-%lx already in use\n",
588 Elsa_Types[cs->subtyp],
589 cs->hw.elsa.base + 8,
590 cs->hw.elsa.base + 16);
594 "Elsa: %s detected modem at 0x%lx\n",
595 Elsa_Types[cs->subtyp],
596 cs->hw.elsa.base + 8);
606 elsa_led_handler(
struct IsdnCardState *cs)
621 if (cs->hw.elsa.status & 0xf000)
623 else if (cs->hw.elsa.status & 0x0f00) {
638 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
641 cs->hw.elsa.tl.expires =
jiffies + ((blink *
HZ) / 1000);
647 Elsa_card_msg(
struct IsdnCardState *cs,
int mt,
void *
arg)
656 spin_unlock_irqrestore(&cs->lock, flags);
663 cs->debug |= L1_DEB_IPAC;
671 if (cs->hw.elsa.trig)
672 byteout(cs->hw.elsa.trig, 0xff);
674 spin_unlock_irqrestore(&cs->lock, flags);
685 cs->hw.elsa.counter = 0;
688 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
690 spin_unlock_irqrestore(&cs->lock, flags);
694 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
696 spin_unlock_irqrestore(&cs->lock, flags);
698 cs->hw.elsa.counter);
699 if ((cs->hw.elsa.counter > 10) &&
700 (cs->hw.elsa.counter < 16)) {
705 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
706 cs->hw.elsa.counter, cs->irq);
711 if (check_arcofi(cs)) {
715 elsa_led_handler(cs);
718 cs->hw.elsa.status &= 0;
725 cs->hw.elsa.status |= 0x0200;
727 cs->hw.elsa.status |= 0x0100;
731 cs->hw.elsa.status |= 0x2000;
733 cs->hw.elsa.status |= 0x1000;
737 cs->hw.elsa.status &= ~0x2000;
738 cs->hw.elsa.status &= ~0x0200;
740 cs->hw.elsa.status &= ~0x1000;
741 cs->hw.elsa.status &= ~0x0100;
746 if (cs->hw.elsa.MFlag) {
755 modem_write_cmd(cs, msg, len);
761 int pwr =
bytein(cs->hw.elsa.ale);
767 elsa_led_handler(cs);
772 probe_elsa_adr(
unsigned int adr,
int typ)
774 int i,
in1,
in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
775 pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
785 "Elsa: Probing Port 0x%x: already in use\n", adr);
789 for (i = 0; i < 16; i++) {
802 if (65 == ++p16_1 * ++p16_2) {
803 printk(
" PCC-16/PCF found\n");
805 }
else if (1025 == ++pfp_1 * ++pfp_2) {
806 printk(
" PCF-Pro found\n");
808 }
else if (33 == ++p8_1 * ++p8_2) {
811 }
else if (17 == ++pc_1 * ++pc_2) {
821 probe_elsa(
struct IsdnCardState *cs)
824 unsigned int CARD_portlist[] =
825 {0x160, 0x170, 0x260, 0x360, 0};
827 for (i = 0; CARD_portlist[
i]; i++) {
828 if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
831 return (CARD_portlist[i]);
837 struct IsdnCardState *cs = card->
cs;
840 cs->hw.elsa.base = card->
para[0];
842 if (cs->hw.elsa.base) {
843 if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
846 "Elsa: no Elsa Microlink at %#lx\n",
851 cs->hw.elsa.base = probe_elsa(cs);
853 if (!cs->hw.elsa.base) {
855 "No Elsa Microlink found\n");
861 cs->hw.elsa.ale = cs->hw.elsa.base +
ELSA_ALE;
862 cs->hw.elsa.isac = cs->hw.elsa.base +
ELSA_ISAC;
863 cs->hw.elsa.itac = cs->hw.elsa.base +
ELSA_ITAC;
864 cs->hw.elsa.hscx = cs->hw.elsa.base +
ELSA_HSCX;
867 val =
bytein(cs->hw.elsa.cfg);
869 const u_char CARD_IrqTab[8] =
870 {7, 3, 5, 9, 0, 0, 0, 0};
873 const u_char CARD_IrqTab[8] =
874 {7, 3, 5, 9, 0, 0, 0, 0};
877 const u_char CARD_IrqTab[8] =
878 {15, 10, 15, 3, 11, 5, 11, 9};
885 if (val ==
'B' || val ==
'C')
890 "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
891 Elsa_Types[cs->subtyp],
897 "Elsa: Microlink S0 bus power bad\n");
908 (
unsigned long)
"Elsa QS1000" },
911 (
unsigned long)
"Elsa QS3000" },
920 setup_elsa_isapnp(
struct IsdnCard *card)
922 struct IsdnCardState *cs = card->
cs;
927 while (ipid->card_vendor) {
929 ipid->card_device, pnp_c))) {
932 ipid->vendor, ipid->function, pnp_d))) {
936 (
char *)ipid->driver_data);
944 card->
para[1] = pnp_port_start(pnp_d, 0);
947 if (!card->
para[0] || !card->
para[1]) {
966 if (!ipid->card_vendor) {
973 if (card->
para[1] && card->
para[0]) {
974 cs->hw.elsa.base = card->
para[1];
975 cs->irq = card->
para[0];
982 cs->hw.elsa.ale = cs->hw.elsa.base +
ELSA_ALE;
983 cs->hw.elsa.isac = cs->hw.elsa.base +
ELSA_ISAC;
984 cs->hw.elsa.hscx = cs->hw.elsa.base +
ELSA_HSCX;
989 "Elsa: %s defined at %#lx IRQ %d\n",
990 Elsa_Types[cs->subtyp],
998 setup_elsa_pcmcia(
struct IsdnCard *card)
1000 struct IsdnCardState *cs = card->
cs;
1003 cs->hw.elsa.base = card->
para[1];
1004 cs->irq = card->
para[0];
1005 val =
readreg(cs->hw.elsa.base + 0, cs->hw.elsa.base + 2,
IPAC_ID);
1006 if ((val == 1) || (val == 2)) {
1008 cs->hw.elsa.ale = cs->hw.elsa.base + 0;
1009 cs->hw.elsa.isac = cs->hw.elsa.base + 2;
1010 cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
1016 cs->hw.elsa.hscx = cs->hw.elsa.base +
ELSA_HSCX;
1018 cs->hw.elsa.timer = 0;
1019 cs->hw.elsa.trig = 0;
1020 cs->hw.elsa.ctrl = 0;
1023 "Elsa: %s defined at %#lx IRQ %d\n",
1024 Elsa_Types[cs->subtyp],
1030 static struct pci_dev *dev_qs1000 __devinitdata =
NULL;
1031 static struct pci_dev *dev_qs3000 __devinitdata =
NULL;
1034 setup_elsa_pci(
struct IsdnCard *card)
1036 struct IsdnCardState *cs = card->
cs;
1044 cs->irq = dev_qs1000->irq;
1052 cs->irq = dev_qs3000->irq;
1064 if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
1068 if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
1073 cs->hw.elsa.ale = cs->hw.elsa.base;
1074 cs->hw.elsa.isac = cs->hw.elsa.base + 1;
1075 cs->hw.elsa.hscx = cs->hw.elsa.base + 1;
1077 cs->hw.elsa.timer = 0;
1078 cs->hw.elsa.trig = 0;
1081 "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
1082 Elsa_Types[cs->subtyp],
1093 setup_elsa_pci(
struct IsdnCard *card)
1100 setup_elsa_common(
struct IsdnCard *card)
1102 struct IsdnCardState *cs = card->
cs;
1106 switch (cs->subtyp) {
1126 "Unknown ELSA subtype %d\n", cs->subtyp);
1134 "HiSax: ELSA config port %#lx-%#lx already in use\n",
1136 cs->hw.elsa.base + bytecnt);
1142 "HiSax: ELSA pci port %x-%x already in use\n",
1144 cs->hw.elsa.cfg + 0x80);
1153 cs->hw.elsa.tl.function = (
void *) elsa_led_handler;
1154 cs->hw.elsa.tl.data = (
long) cs;
1157 if (cs->hw.elsa.timer) {
1158 byteout(cs->hw.elsa.trig, 0xff);
1159 byteout(cs->hw.elsa.timer, 0);
1160 if (!TimerRun(cs)) {
1161 byteout(cs->hw.elsa.timer, 0);
1162 if (!TimerRun(cs)) {
1164 "Elsa: timer do not start\n");
1165 release_io_elsa(cs);
1172 release_io_elsa(cs);
1179 cs->BC_Send_Data = &hscx_fill_fifo;
1180 cs->cardmsg = &Elsa_card_msg;
1182 cs->readisac = &ReadISAC_IPAC;
1183 cs->writeisac = &WriteISAC_IPAC;
1184 cs->readisacfifo = &ReadISACfifo_IPAC;
1185 cs->writeisacfifo = &WriteISACfifo_IPAC;
1186 cs->irq_func = &elsa_interrupt_ipac;
1192 cs->readisacfifo = &ReadISACfifo;
1193 cs->writeisacfifo = &WriteISACfifo;
1194 cs->irq_func = &elsa_interrupt;
1198 "Elsa: wrong HSCX versions check IO address\n");
1199 release_io_elsa(cs);
1219 struct IsdnCardState *cs = card->
cs;
1222 strcpy(tmp, Elsa_revision);
1224 cs->hw.elsa.ctrl_reg = 0;
1225 cs->hw.elsa.status = 0;
1226 cs->hw.elsa.MFlag = 0;
1230 rc = setup_elsa_isa(card);
1235 rc = setup_elsa_isapnp(card);
1240 setup_elsa_pcmcia(card);
1243 rc = setup_elsa_pci(card);
1250 return setup_elsa_common(card);