1 /* $Id: elsa.c,v 2.32.2.4 2004/01/24 20:47:21 keil Exp $
3 * low level stuff for Elsa 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 Elsa GmbH for documents and information
16 * Klaus Lichtenwalder (Klaus.Lichtenwalder@WebForum.DE)
17 * for ELSA PCMCIA support
21 #include <linux/init.h>
28 #include <linux/pci.h>
29 #include <linux/isapnp.h>
30 #include <linux/serial.h>
31 #include <linux/serial_reg.h>
33 extern const char *CardType[];
35 static const char *Elsa_revision = "$Revision: 2.32.2.4 $";
36 static const char *Elsa_Types[] =
37 {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
38 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
41 static const char *ITACVer[] =
42 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
45 #define byteout(addr,val) outb(val,addr)
46 #define bytein(addr) inb(addr)
49 #define ELSA_ISAC_PCM 1
53 #define ELSA_ALE_PCM 4
54 #define ELSA_CONTROL 4
56 #define ELSA_START_TIMER 6
57 #define ELSA_TRIG_IRQ 7
67 #define ELSA_QS1000PCI 9
68 #define ELSA_QS3000PCI 10
69 #define ELSA_PCMCIA_IPAC 11
72 #define ELSA_PCI_IRQ_MASK 0x04
74 /* ITAC Registeradressen (only Microlink PC) */
76 #define ITAC_ISEN 0x48
77 #define ITAC_RFIE 0x4A
78 #define ITAC_XFIE 0x4C
79 #define ITAC_SCIE 0x4E
80 #define ITAC_STIE 0x46
83 *** Makros als Befehle fuer die Kartenregister ***
84 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
87 /* Config-Register (Read) */
88 #define ELIRQF_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
89 #define ELIRQF_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
90 #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
91 #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
92 #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
94 /* Control-Register (Write) */
95 #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
96 #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
97 #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
98 #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
100 /* ALE-Register (Read) */
101 #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
102 #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
105 #define ELIRQF_TIMER_AKTIV 1
106 #define ELSA_BAD_PWR 2
107 #define ELSA_ASSIGN 4
109 #define RS_ISR_PASS_LIMIT 256
110 #define FLG_MODEM_ACTIVE 1
112 #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
113 #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
116 static struct arcofi_msg ARCOFI_XOP_F =
117 {NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
118 static struct arcofi_msg ARCOFI_XOP_1 =
119 {&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
120 static struct arcofi_msg ARCOFI_SOP_F =
121 {&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
122 static struct arcofi_msg ARCOFI_COP_9 =
123 {&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
124 static struct arcofi_msg ARCOFI_COP_8 =
125 {&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
126 static struct arcofi_msg ARCOFI_COP_7 =
127 {&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
128 static struct arcofi_msg ARCOFI_COP_6 =
129 {&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
130 static struct arcofi_msg ARCOFI_COP_5 =
131 {&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
132 static struct arcofi_msg ARCOFI_VERSION =
133 {NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
134 static struct arcofi_msg ARCOFI_XOP_0 =
135 {NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
137 static void set_arcofi(struct IsdnCardState *cs, int bc);
139 #include "elsa_ser.c"
140 #endif /* ARCOFI_USE */
143 readreg(unsigned int ale, unsigned int adr, u_char off)
153 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
156 insb(adr, data, size);
161 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
168 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
171 outsb(adr, data, size);
174 /* Interface functions */
177 ReadISAC(struct IsdnCardState *cs, u_char offset)
179 return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
183 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
185 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
189 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
191 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
195 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
197 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
201 ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
203 return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset+0x80));
207 WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
209 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset|0x80, value);
213 ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
215 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
219 WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
221 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
225 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
227 return (readreg(cs->hw.elsa.ale,
228 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
232 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
234 writereg(cs->hw.elsa.ale,
235 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
239 readitac(struct IsdnCardState *cs, u_char off)
243 byteout(cs->hw.elsa.ale, off);
244 ret = bytein(cs->hw.elsa.itac);
249 writeitac(struct IsdnCardState *cs, u_char off, u_char data)
251 byteout(cs->hw.elsa.ale, off);
252 byteout(cs->hw.elsa.itac, data);
256 TimerRun(struct IsdnCardState *cs)
260 v = bytein(cs->hw.elsa.cfg);
261 if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
262 return (0 == (v & ELIRQF_TIMER_RUN));
263 else if (cs->subtyp == ELSA_PCC8)
264 return (v & ELIRQF_TIMER_RUN_PCC8);
265 return (v & ELIRQF_TIMER_RUN);
268 * fast interrupt HSCX stuff goes here
271 #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
272 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
273 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
274 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
276 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
277 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
279 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
280 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
282 #include "hscx_irq.c"
285 elsa_interrupt(int intno, void *dev_id)
287 struct IsdnCardState *cs = dev_id;
292 if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
293 /* The card tends to generate interrupts while being removed
294 causing us to just crash the kernel. bad. */
295 printk(KERN_WARNING "Elsa: card not available!\n");
298 spin_lock_irqsave(&cs->lock, flags);
300 if (cs->hw.elsa.MFlag) {
301 val = serial_inp(cs, UART_IIR);
302 if (!(val & UART_IIR_NO_INT)) {
303 debugl1(cs,"IIR %02x", val);
304 rs_interrupt_elsa(intno, cs);
308 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
311 hscx_int_main(cs, val);
313 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
316 isac_interrupt(cs, val);
318 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
320 if (cs->debug & L1_DEB_HSCX)
321 debugl1(cs, "HSCX IntStat after IntRoutine");
325 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
327 if (cs->debug & L1_DEB_ISAC)
328 debugl1(cs, "ISAC IntStat after IntRoutine");
333 printk(KERN_WARNING"ELSA IRQ LOOP\n");
334 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0xFF);
335 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0xFF);
336 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0xFF);
337 if (cs->hw.elsa.status & ELIRQF_TIMER_AKTIV) {
340 byteout(cs->hw.elsa.timer, 0);
341 cs->hw.elsa.counter++;
345 if (cs->hw.elsa.MFlag) {
346 val = serial_inp(cs, UART_MCR);
348 serial_outp(cs, UART_MCR, val);
349 val = serial_inp(cs, UART_MCR);
351 serial_outp(cs, UART_MCR, val);
354 if (cs->hw.elsa.trig)
355 byteout(cs->hw.elsa.trig, 0x00);
356 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0x0);
357 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0x0);
358 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0x0);
359 spin_unlock_irqrestore(&cs->lock, flags);
364 elsa_interrupt_ipac(int intno, void *dev_id)
366 struct IsdnCardState *cs = dev_id;
371 spin_lock_irqsave(&cs->lock, flags);
372 if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
373 val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
374 if (!(val & ELSA_PCI_IRQ_MASK)) {
375 spin_unlock_irqrestore(&cs->lock, flags);
380 if (cs->hw.elsa.MFlag) {
381 val = serial_inp(cs, UART_IIR);
382 if (!(val & UART_IIR_NO_INT)) {
383 debugl1(cs,"IIR %02x", val);
384 rs_interrupt_elsa(intno, cs);
388 ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
390 if (cs->debug & L1_DEB_IPAC)
391 debugl1(cs, "IPAC ISTA %02X", ista);
393 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
401 hscx_int_main(cs, val);
404 val = 0xfe & readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA + 0x80);
406 isac_interrupt(cs, val);
411 isac_interrupt(cs, val);
413 ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
414 if ((ista & 0x3f) && icnt) {
419 printk(KERN_WARNING "ELSA IRQ LOOP\n");
420 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xFF);
421 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xC0);
422 spin_unlock_irqrestore(&cs->lock, flags);
427 release_io_elsa(struct IsdnCardState *cs)
431 del_timer(&cs->hw.elsa.tl);
435 if (cs->hw.elsa.ctrl)
436 byteout(cs->hw.elsa.ctrl, 0); /* LEDs Out */
437 if (cs->subtyp == ELSA_QS1000PCI) {
438 byteout(cs->hw.elsa.cfg + 0x4c, 0x01); /* disable IRQ */
439 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
441 release_region(cs->hw.elsa.cfg, 0x80);
443 if (cs->subtyp == ELSA_QS3000PCI) {
444 byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
445 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
446 release_region(cs->hw.elsa.cfg, 0x80);
448 if (cs->subtyp == ELSA_PCMCIA_IPAC) {
449 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
451 if ((cs->subtyp == ELSA_PCFPRO) ||
452 (cs->subtyp == ELSA_QS3000) ||
453 (cs->subtyp == ELSA_PCF) ||
454 (cs->subtyp == ELSA_QS3000PCI)) {
460 if (cs->hw.elsa.base)
461 release_region(cs->hw.elsa.base, bytecnt);
465 reset_elsa(struct IsdnCardState *cs)
467 if (cs->hw.elsa.timer) {
469 byteout(cs->hw.elsa.timer, 0);
470 while (TimerRun(cs));
471 cs->hw.elsa.ctrl_reg |= 0x50;
472 cs->hw.elsa.ctrl_reg &= ~ELSA_ISDN_RESET; /* Reset On */
473 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
475 byteout(cs->hw.elsa.timer, 0);
476 while (TimerRun(cs));
477 cs->hw.elsa.ctrl_reg |= ELSA_ISDN_RESET; /* Reset Off */
478 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
480 byteout(cs->hw.elsa.timer, 0);
481 while (TimerRun(cs));
482 if (cs->hw.elsa.trig)
483 byteout(cs->hw.elsa.trig, 0xff);
485 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
486 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
488 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
489 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
491 if (cs->subtyp != ELSA_PCMCIA_IPAC) {
492 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
493 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
495 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
496 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
497 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
499 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
500 if (cs->subtyp == ELSA_QS1000PCI)
501 byteout(cs->hw.elsa.cfg + 0x4c, 0x41); /* enable ELSA PCI IRQ */
502 else if (cs->subtyp == ELSA_QS3000PCI)
503 byteout(cs->hw.elsa.cfg + 0x4c, 0x43); /* enable ELSA PCI IRQ */
510 set_arcofi(struct IsdnCardState *cs, int bc) {
511 cs->dc.isac.arcofi_bc = bc;
512 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_COP_5);
513 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
517 check_arcofi(struct IsdnCardState *cs)
519 int arcofi_present = 0;
524 if (!cs->dc.isac.mon_tx)
525 if (!(cs->dc.isac.mon_tx=kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
526 if (cs->debug & L1_DEB_WARN)
527 debugl1(cs, "ISAC MON TX out of buffers!");
530 cs->dc.isac.arcofi_bc = 0;
531 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
532 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
533 if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
534 debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
535 p = cs->dc.isac.mon_rx;
537 t += sprintf(tmp, "Arcofi data");
538 QuickHex(t, p, cs->dc.isac.mon_rxp);
540 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
541 switch(cs->dc.isac.mon_rx[1]) {
543 debugl1(cs, "Arcofi 2160 detected");
547 debugl1(cs, "Arcofi 2165 detected");
551 debugl1(cs, "Arcofi 2163 detected");
555 debugl1(cs, "unknown Arcofi response");
559 debugl1(cs, "undefined Monitor response");
560 cs->dc.isac.mon_rxp = 0;
561 } else if (cs->dc.isac.mon_tx) {
562 debugl1(cs, "Arcofi not detected");
564 if (arcofi_present) {
565 if (cs->subtyp==ELSA_QS1000) {
566 cs->subtyp = ELSA_QS3000;
568 "Elsa: %s detected modem at 0x%lx\n",
569 Elsa_Types[cs->subtyp],
571 release_region(cs->hw.elsa.base, 8);
572 if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
574 "HiSax: %s config port %lx-%lx already in use\n",
575 Elsa_Types[cs->subtyp],
576 cs->hw.elsa.base + 8,
577 cs->hw.elsa.base + 16);
579 } else if (cs->subtyp==ELSA_PCC16) {
580 cs->subtyp = ELSA_PCF;
582 "Elsa: %s detected modem at 0x%lx\n",
583 Elsa_Types[cs->subtyp],
585 release_region(cs->hw.elsa.base, 8);
586 if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
588 "HiSax: %s config port %lx-%lx already in use\n",
589 Elsa_Types[cs->subtyp],
590 cs->hw.elsa.base + 8,
591 cs->hw.elsa.base + 16);
595 "Elsa: %s detected modem at 0x%lx\n",
596 Elsa_Types[cs->subtyp],
598 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
599 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
604 #endif /* ARCOFI_USE */
607 elsa_led_handler(struct IsdnCardState *cs)
611 if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
613 del_timer(&cs->hw.elsa.tl);
614 if (cs->hw.elsa.status & ELSA_ASSIGN)
615 cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
616 else if (cs->hw.elsa.status & ELSA_BAD_PWR)
617 cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
619 cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
622 if (cs->hw.elsa.status & 0xf000)
623 cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
624 else if (cs->hw.elsa.status & 0x0f00) {
625 cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
628 cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
630 if ((cs->subtyp == ELSA_QS1000PCI) ||
631 (cs->subtyp == ELSA_QS3000PCI)) {
633 if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
634 led ^= ELSA_IPAC_LINE_LED;
635 if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
636 led ^= ELSA_IPAC_STAT_LED;
637 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
639 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
641 init_timer(&cs->hw.elsa.tl);
642 cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
643 add_timer(&cs->hw.elsa.tl);
648 Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
655 spin_lock_irqsave(&cs->lock, flags);
657 spin_unlock_irqrestore(&cs->lock, flags);
663 spin_lock_irqsave(&cs->lock, flags);
664 cs->debug |= L1_DEB_IPAC;
667 if ((cs->subtyp == ELSA_QS1000) ||
668 (cs->subtyp == ELSA_QS3000))
670 byteout(cs->hw.elsa.timer, 0);
672 if (cs->hw.elsa.trig)
673 byteout(cs->hw.elsa.trig, 0xff);
675 spin_unlock_irqrestore(&cs->lock, flags);
678 if ((cs->subtyp == ELSA_PCMCIA) ||
679 (cs->subtyp == ELSA_PCMCIA_IPAC) ||
680 (cs->subtyp == ELSA_QS1000PCI)) {
682 } else if (cs->subtyp == ELSA_QS3000PCI) {
685 spin_lock_irqsave(&cs->lock, flags);
686 cs->hw.elsa.counter = 0;
687 cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
688 cs->hw.elsa.status |= ELIRQF_TIMER_AKTIV;
689 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
690 byteout(cs->hw.elsa.timer, 0);
691 spin_unlock_irqrestore(&cs->lock, flags);
693 spin_lock_irqsave(&cs->lock, flags);
694 cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
695 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
696 cs->hw.elsa.status &= ~ELIRQF_TIMER_AKTIV;
697 spin_unlock_irqrestore(&cs->lock, flags);
698 printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
699 cs->hw.elsa.counter);
700 if ((cs->hw.elsa.counter > 10) &&
701 (cs->hw.elsa.counter < 16)) {
702 printk(KERN_INFO "Elsa: timer and irq OK\n");
706 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
707 cs->hw.elsa.counter, cs->irq);
712 if (check_arcofi(cs)) {
716 elsa_led_handler(cs);
718 case (MDL_REMOVE | REQUEST):
719 cs->hw.elsa.status &= 0;
721 case (MDL_ASSIGN | REQUEST):
722 cs->hw.elsa.status |= ELSA_ASSIGN;
726 cs->hw.elsa.status |= 0x0200;
728 cs->hw.elsa.status |= 0x0100;
732 cs->hw.elsa.status |= 0x2000;
734 cs->hw.elsa.status |= 0x1000;
738 cs->hw.elsa.status &= ~0x2000;
739 cs->hw.elsa.status &= ~0x0200;
741 cs->hw.elsa.status &= ~0x1000;
742 cs->hw.elsa.status &= ~0x0100;
747 if (cs->hw.elsa.MFlag) {
756 modem_write_cmd(cs, msg, len);
761 if (cs->typ == ISDN_CTYPE_ELSA) {
762 int pwr = bytein(cs->hw.elsa.ale);
764 cs->hw.elsa.status |= ELSA_BAD_PWR;
766 cs->hw.elsa.status &= ~ELSA_BAD_PWR;
768 elsa_led_handler(cs);
773 probe_elsa_adr(unsigned int adr, int typ)
775 int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
776 pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
778 /* In case of the elsa pcmcia card, this region is in use,
779 reserved for us by the card manager. So we do not check it
780 here, it would fail. */
781 if (typ != ISDN_CTYPE_ELSA_PCMCIA) {
782 if (request_region(adr, 8, "elsa card")) {
783 release_region(adr, 8);
786 "Elsa: Probing Port 0x%x: already in use\n", adr);
790 for (i = 0; i < 16; i++) {
791 in1 = inb(adr + ELSA_CONFIG); /* 'toggelt' bei */
792 in2 = inb(adr + ELSA_CONFIG); /* jedem Zugriff */
802 printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
803 if (65 == ++p16_1 * ++p16_2) {
804 printk(" PCC-16/PCF found\n");
806 } else if (1025 == ++pfp_1 * ++pfp_2) {
807 printk(" PCF-Pro found\n");
808 return (ELSA_PCFPRO);
809 } else if (33 == ++p8_1 * ++p8_2) {
810 printk(" PCC8 found\n");
812 } else if (17 == ++pc_1 * ++pc_2) {
813 printk(" PC found\n");
822 probe_elsa(struct IsdnCardState *cs)
825 unsigned int CARD_portlist[] =
826 {0x160, 0x170, 0x260, 0x360, 0};
828 for (i = 0; CARD_portlist[i]; i++) {
829 if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
832 return (CARD_portlist[i]);
835 static struct pci_dev *dev_qs1000 __devinitdata = NULL;
836 static struct pci_dev *dev_qs3000 __devinitdata = NULL;
839 static struct isapnp_device_id elsa_ids[] __devinitdata = {
840 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
841 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
842 (unsigned long) "Elsa QS1000" },
843 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
844 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
845 (unsigned long) "Elsa QS3000" },
849 static struct isapnp_device_id *ipid __devinitdata = &elsa_ids[0];
850 static struct pnp_card *pnp_c __devinitdata = NULL;
854 setup_elsa(struct IsdnCard *card)
858 struct IsdnCardState *cs = card->cs;
861 strcpy(tmp, Elsa_revision);
862 printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
863 cs->hw.elsa.ctrl_reg = 0;
864 cs->hw.elsa.status = 0;
865 cs->hw.elsa.MFlag = 0;
867 if (cs->typ == ISDN_CTYPE_ELSA) {
868 cs->hw.elsa.base = card->para[0];
869 printk(KERN_INFO "Elsa: Microlink IO probing\n");
870 if (cs->hw.elsa.base) {
871 if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
874 "Elsa: no Elsa Microlink at %#lx\n",
879 cs->hw.elsa.base = probe_elsa(cs);
880 if (cs->hw.elsa.base) {
881 cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
882 cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
883 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
884 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
885 cs->hw.elsa.itac = cs->hw.elsa.base + ELSA_ITAC;
886 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
887 cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
888 cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
889 val = bytein(cs->hw.elsa.cfg);
890 if (cs->subtyp == ELSA_PC) {
891 const u_char CARD_IrqTab[8] =
892 {7, 3, 5, 9, 0, 0, 0, 0};
893 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
894 } else if (cs->subtyp == ELSA_PCC8) {
895 const u_char CARD_IrqTab[8] =
896 {7, 3, 5, 9, 0, 0, 0, 0};
897 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
899 const u_char CARD_IrqTab[8] =
900 {15, 10, 15, 3, 11, 5, 11, 9};
901 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
903 val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
907 if (val == 'B' || val == 'C')
909 if ((cs->subtyp == ELSA_PCFPRO) && (val = 'G'))
912 "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
913 Elsa_Types[cs->subtyp],
916 val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
919 "Elsa: Microlink S0 bus power bad\n");
920 cs->hw.elsa.status |= ELSA_BAD_PWR;
924 "No Elsa Microlink found\n");
927 } else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
929 if (!card->para[1] && isapnp_present()) {
930 struct pnp_dev *pnp_d;
931 while(ipid->card_vendor) {
932 if ((pnp_c = pnp_find_card(ipid->card_vendor,
933 ipid->card_device, pnp_c))) {
935 if ((pnp_d = pnp_find_dev(pnp_c,
936 ipid->vendor, ipid->function, pnp_d))) {
939 printk(KERN_INFO "HiSax: %s detected\n",
940 (char *)ipid->driver_data);
941 pnp_disable_dev(pnp_d);
942 err = pnp_activate_dev(pnp_d);
944 printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
948 card->para[1] = pnp_port_start(pnp_d, 0);
949 card->para[0] = pnp_irq(pnp_d, 0);
951 if (!card->para[0] || !card->para[1]) {
952 printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
953 card->para[0], card->para[1]);
954 pnp_disable_dev(pnp_d);
957 if (ipid->function == ISAPNP_FUNCTION(0x133))
958 cs->subtyp = ELSA_QS1000;
960 cs->subtyp = ELSA_QS3000;
963 printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
970 if (!ipid->card_vendor) {
971 printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
976 if (card->para[1] && card->para[0]) {
977 cs->hw.elsa.base = card->para[1];
978 cs->irq = card->para[0];
980 cs->subtyp = ELSA_QS1000;
982 printk(KERN_ERR "Elsa PnP: no parameter\n");
984 cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
985 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
986 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
987 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
988 cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
989 cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
990 cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
992 "Elsa: %s defined at %#lx IRQ %d\n",
993 Elsa_Types[cs->subtyp],
996 } else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA) {
997 cs->hw.elsa.base = card->para[1];
998 cs->irq = card->para[0];
999 val = readreg(cs->hw.elsa.base + 0, cs->hw.elsa.base + 2, IPAC_ID);
1000 if ((val == 1) || (val == 2)) { /* IPAC version 1.1/1.2 */
1001 cs->subtyp = ELSA_PCMCIA_IPAC;
1002 cs->hw.elsa.ale = cs->hw.elsa.base + 0;
1003 cs->hw.elsa.isac = cs->hw.elsa.base + 2;
1004 cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
1005 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1007 cs->subtyp = ELSA_PCMCIA;
1008 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE_PCM;
1009 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC_PCM;
1010 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
1012 cs->hw.elsa.timer = 0;
1013 cs->hw.elsa.trig = 0;
1014 cs->hw.elsa.ctrl = 0;
1015 cs->irq_flags |= IRQF_SHARED;
1017 "Elsa: %s defined at %#lx IRQ %d\n",
1018 Elsa_Types[cs->subtyp],
1021 } else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
1024 if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1025 PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1026 if (pci_enable_device(dev_qs1000))
1028 cs->subtyp = ELSA_QS1000PCI;
1029 cs->irq = dev_qs1000->irq;
1030 cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
1031 cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
1032 } else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1033 PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1034 if (pci_enable_device(dev_qs3000))
1036 cs->subtyp = ELSA_QS3000PCI;
1037 cs->irq = dev_qs3000->irq;
1038 cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
1039 cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
1041 printk(KERN_WARNING "Elsa: No PCI card found\n");
1045 printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
1049 if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
1050 printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
1053 if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
1054 printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
1055 printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
1056 printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
1058 cs->hw.elsa.ale = cs->hw.elsa.base;
1059 cs->hw.elsa.isac = cs->hw.elsa.base +1;
1060 cs->hw.elsa.hscx = cs->hw.elsa.base +1;
1061 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1062 cs->hw.elsa.timer = 0;
1063 cs->hw.elsa.trig = 0;
1064 cs->irq_flags |= IRQF_SHARED;
1066 "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
1067 Elsa_Types[cs->subtyp],
1072 printk(KERN_WARNING "Elsa: Elsa PCI and NO_PCI_BIOS\n");
1073 printk(KERN_WARNING "Elsa: unable to config Elsa PCI\n");
1075 #endif /* CONFIG_PCI */
1079 switch (cs->subtyp) {
1085 case ELSA_PCMCIA_IPAC:
1091 case ELSA_QS3000PCI:
1094 case ELSA_QS1000PCI:
1099 "Unknown ELSA subtype %d\n", cs->subtyp);
1102 /* In case of the elsa pcmcia card, this region is in use,
1103 reserved for us by the card manager. So we do not check it
1104 here, it would fail. */
1105 if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(cs->hw.elsa.base, bytecnt, "elsa isdn")) {
1107 "HiSax: %s config port %#lx-%#lx already in use\n",
1108 CardType[card->typ],
1110 cs->hw.elsa.base + bytecnt);
1113 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
1114 if (!request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci")) {
1116 "HiSax: %s pci port %x-%x already in use\n",
1117 CardType[card->typ],
1119 cs->hw.elsa.cfg + 0x80);
1120 release_region(cs->hw.elsa.base, bytecnt);
1128 cs->hw.elsa.tl.function = (void *) elsa_led_handler;
1129 cs->hw.elsa.tl.data = (long) cs;
1130 init_timer(&cs->hw.elsa.tl);
1132 if (cs->hw.elsa.timer) {
1133 byteout(cs->hw.elsa.trig, 0xff);
1134 byteout(cs->hw.elsa.timer, 0);
1135 if (!TimerRun(cs)) {
1136 byteout(cs->hw.elsa.timer, 0); /* 2. Versuch */
1137 if (!TimerRun(cs)) {
1139 "Elsa: timer do not start\n");
1140 release_io_elsa(cs);
1144 HZDELAY((HZ/100) + 1); /* wait >=10 ms */
1146 printk(KERN_WARNING "Elsa: timer do not run down\n");
1147 release_io_elsa(cs);
1150 printk(KERN_INFO "Elsa: timer OK; resetting card\n");
1152 cs->BC_Read_Reg = &ReadHSCX;
1153 cs->BC_Write_Reg = &WriteHSCX;
1154 cs->BC_Send_Data = &hscx_fill_fifo;
1155 cs->cardmsg = &Elsa_card_msg;
1156 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
1157 cs->readisac = &ReadISAC_IPAC;
1158 cs->writeisac = &WriteISAC_IPAC;
1159 cs->readisacfifo = &ReadISACfifo_IPAC;
1160 cs->writeisacfifo = &WriteISACfifo_IPAC;
1161 cs->irq_func = &elsa_interrupt_ipac;
1162 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
1163 printk(KERN_INFO "Elsa: IPAC version %x\n", val);
1165 cs->readisac = &ReadISAC;
1166 cs->writeisac = &WriteISAC;
1167 cs->readisacfifo = &ReadISACfifo;
1168 cs->writeisacfifo = &WriteISACfifo;
1169 cs->irq_func = &elsa_interrupt;
1170 ISACVersion(cs, "Elsa:");
1171 if (HscxVersion(cs, "Elsa:")) {
1173 "Elsa: wrong HSCX versions check IO address\n");
1174 release_io_elsa(cs);
1178 if (cs->subtyp == ELSA_PC) {
1179 val = readitac(cs, ITAC_SYS);
1180 printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
1181 writeitac(cs, ITAC_ISEN, 0);
1182 writeitac(cs, ITAC_RFIE, 0);
1183 writeitac(cs, ITAC_XFIE, 0);
1184 writeitac(cs, ITAC_SCIE, 0);
1185 writeitac(cs, ITAC_STIE, 0);