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 static const char *Elsa_revision = "$Revision: 2.32.2.4 $";
34 static const char *Elsa_Types[] =
35 {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
36 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
39 static const char *ITACVer[] =
40 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
43 #define byteout(addr,val) outb(val,addr)
44 #define bytein(addr) inb(addr)
47 #define ELSA_ISAC_PCM 1
51 #define ELSA_ALE_PCM 4
52 #define ELSA_CONTROL 4
54 #define ELSA_START_TIMER 6
55 #define ELSA_TRIG_IRQ 7
65 #define ELSA_QS1000PCI 9
66 #define ELSA_QS3000PCI 10
67 #define ELSA_PCMCIA_IPAC 11
70 #define ELSA_PCI_IRQ_MASK 0x04
72 /* ITAC Registeradressen (only Microlink PC) */
74 #define ITAC_ISEN 0x48
75 #define ITAC_RFIE 0x4A
76 #define ITAC_XFIE 0x4C
77 #define ITAC_SCIE 0x4E
78 #define ITAC_STIE 0x46
81 *** Makros als Befehle fuer die Kartenregister ***
82 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
85 /* Config-Register (Read) */
86 #define ELIRQF_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
87 #define ELIRQF_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
88 #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
89 #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
90 #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
92 /* Control-Register (Write) */
93 #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
94 #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
95 #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
96 #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
98 /* ALE-Register (Read) */
99 #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
100 #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
103 #define ELIRQF_TIMER_AKTIV 1
104 #define ELSA_BAD_PWR 2
105 #define ELSA_ASSIGN 4
107 #define RS_ISR_PASS_LIMIT 256
108 #define FLG_MODEM_ACTIVE 1
110 #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
111 #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
114 static struct arcofi_msg ARCOFI_XOP_F =
115 {NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
116 static struct arcofi_msg ARCOFI_XOP_1 =
117 {&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
118 static struct arcofi_msg ARCOFI_SOP_F =
119 {&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
120 static struct arcofi_msg ARCOFI_COP_9 =
121 {&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
122 static struct arcofi_msg ARCOFI_COP_8 =
123 {&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
124 static struct arcofi_msg ARCOFI_COP_7 =
125 {&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
126 static struct arcofi_msg ARCOFI_COP_6 =
127 {&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
128 static struct arcofi_msg ARCOFI_COP_5 =
129 {&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
130 static struct arcofi_msg ARCOFI_VERSION =
131 {NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
132 static struct arcofi_msg ARCOFI_XOP_0 =
133 {NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
135 static void set_arcofi(struct IsdnCardState *cs, int bc);
137 #include "elsa_ser.c"
138 #endif /* ARCOFI_USE */
141 readreg(unsigned int ale, unsigned int adr, u_char off)
151 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
154 insb(adr, data, size);
159 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
166 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
169 outsb(adr, data, size);
172 /* Interface functions */
175 ReadISAC(struct IsdnCardState *cs, u_char offset)
177 return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
181 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
183 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
187 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
189 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
193 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
195 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
199 ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
201 return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset+0x80));
205 WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
207 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset|0x80, value);
211 ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
213 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
217 WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
219 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
223 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
225 return (readreg(cs->hw.elsa.ale,
226 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
230 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
232 writereg(cs->hw.elsa.ale,
233 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
237 readitac(struct IsdnCardState *cs, u_char off)
241 byteout(cs->hw.elsa.ale, off);
242 ret = bytein(cs->hw.elsa.itac);
247 writeitac(struct IsdnCardState *cs, u_char off, u_char data)
249 byteout(cs->hw.elsa.ale, off);
250 byteout(cs->hw.elsa.itac, data);
254 TimerRun(struct IsdnCardState *cs)
258 v = bytein(cs->hw.elsa.cfg);
259 if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
260 return (0 == (v & ELIRQF_TIMER_RUN));
261 else if (cs->subtyp == ELSA_PCC8)
262 return (v & ELIRQF_TIMER_RUN_PCC8);
263 return (v & ELIRQF_TIMER_RUN);
266 * fast interrupt HSCX stuff goes here
269 #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
270 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
271 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
272 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
274 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
275 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
277 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
278 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
280 #include "hscx_irq.c"
283 elsa_interrupt(int intno, void *dev_id)
285 struct IsdnCardState *cs = dev_id;
290 if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
291 /* The card tends to generate interrupts while being removed
292 causing us to just crash the kernel. bad. */
293 printk(KERN_WARNING "Elsa: card not available!\n");
296 spin_lock_irqsave(&cs->lock, flags);
298 if (cs->hw.elsa.MFlag) {
299 val = serial_inp(cs, UART_IIR);
300 if (!(val & UART_IIR_NO_INT)) {
301 debugl1(cs,"IIR %02x", val);
302 rs_interrupt_elsa(intno, cs);
306 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
309 hscx_int_main(cs, val);
311 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
314 isac_interrupt(cs, val);
316 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
318 if (cs->debug & L1_DEB_HSCX)
319 debugl1(cs, "HSCX IntStat after IntRoutine");
323 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
325 if (cs->debug & L1_DEB_ISAC)
326 debugl1(cs, "ISAC IntStat after IntRoutine");
331 printk(KERN_WARNING"ELSA IRQ LOOP\n");
332 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0xFF);
333 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0xFF);
334 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0xFF);
335 if (cs->hw.elsa.status & ELIRQF_TIMER_AKTIV) {
338 byteout(cs->hw.elsa.timer, 0);
339 cs->hw.elsa.counter++;
343 if (cs->hw.elsa.MFlag) {
344 val = serial_inp(cs, UART_MCR);
346 serial_outp(cs, UART_MCR, val);
347 val = serial_inp(cs, UART_MCR);
349 serial_outp(cs, UART_MCR, val);
352 if (cs->hw.elsa.trig)
353 byteout(cs->hw.elsa.trig, 0x00);
354 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0x0);
355 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0x0);
356 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0x0);
357 spin_unlock_irqrestore(&cs->lock, flags);
362 elsa_interrupt_ipac(int intno, void *dev_id)
364 struct IsdnCardState *cs = dev_id;
369 spin_lock_irqsave(&cs->lock, flags);
370 if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
371 val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
372 if (!(val & ELSA_PCI_IRQ_MASK)) {
373 spin_unlock_irqrestore(&cs->lock, flags);
378 if (cs->hw.elsa.MFlag) {
379 val = serial_inp(cs, UART_IIR);
380 if (!(val & UART_IIR_NO_INT)) {
381 debugl1(cs,"IIR %02x", val);
382 rs_interrupt_elsa(intno, cs);
386 ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
388 if (cs->debug & L1_DEB_IPAC)
389 debugl1(cs, "IPAC ISTA %02X", ista);
391 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
399 hscx_int_main(cs, val);
402 val = 0xfe & readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA + 0x80);
404 isac_interrupt(cs, val);
409 isac_interrupt(cs, val);
411 ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
412 if ((ista & 0x3f) && icnt) {
417 printk(KERN_WARNING "ELSA IRQ LOOP\n");
418 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xFF);
419 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xC0);
420 spin_unlock_irqrestore(&cs->lock, flags);
425 release_io_elsa(struct IsdnCardState *cs)
429 del_timer(&cs->hw.elsa.tl);
433 if (cs->hw.elsa.ctrl)
434 byteout(cs->hw.elsa.ctrl, 0); /* LEDs Out */
435 if (cs->subtyp == ELSA_QS1000PCI) {
436 byteout(cs->hw.elsa.cfg + 0x4c, 0x01); /* disable IRQ */
437 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
439 release_region(cs->hw.elsa.cfg, 0x80);
441 if (cs->subtyp == ELSA_QS3000PCI) {
442 byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
443 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
444 release_region(cs->hw.elsa.cfg, 0x80);
446 if (cs->subtyp == ELSA_PCMCIA_IPAC) {
447 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
449 if ((cs->subtyp == ELSA_PCFPRO) ||
450 (cs->subtyp == ELSA_QS3000) ||
451 (cs->subtyp == ELSA_PCF) ||
452 (cs->subtyp == ELSA_QS3000PCI)) {
458 if (cs->hw.elsa.base)
459 release_region(cs->hw.elsa.base, bytecnt);
463 reset_elsa(struct IsdnCardState *cs)
465 if (cs->hw.elsa.timer) {
467 byteout(cs->hw.elsa.timer, 0);
468 while (TimerRun(cs));
469 cs->hw.elsa.ctrl_reg |= 0x50;
470 cs->hw.elsa.ctrl_reg &= ~ELSA_ISDN_RESET; /* Reset On */
471 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
473 byteout(cs->hw.elsa.timer, 0);
474 while (TimerRun(cs));
475 cs->hw.elsa.ctrl_reg |= ELSA_ISDN_RESET; /* Reset Off */
476 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
478 byteout(cs->hw.elsa.timer, 0);
479 while (TimerRun(cs));
480 if (cs->hw.elsa.trig)
481 byteout(cs->hw.elsa.trig, 0xff);
483 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
484 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
486 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
487 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
489 if (cs->subtyp != ELSA_PCMCIA_IPAC) {
490 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
491 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
493 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
494 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
495 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
497 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
498 if (cs->subtyp == ELSA_QS1000PCI)
499 byteout(cs->hw.elsa.cfg + 0x4c, 0x41); /* enable ELSA PCI IRQ */
500 else if (cs->subtyp == ELSA_QS3000PCI)
501 byteout(cs->hw.elsa.cfg + 0x4c, 0x43); /* enable ELSA PCI IRQ */
508 set_arcofi(struct IsdnCardState *cs, int bc) {
509 cs->dc.isac.arcofi_bc = bc;
510 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_COP_5);
511 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
515 check_arcofi(struct IsdnCardState *cs)
517 int arcofi_present = 0;
522 if (!cs->dc.isac.mon_tx)
523 if (!(cs->dc.isac.mon_tx=kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
524 if (cs->debug & L1_DEB_WARN)
525 debugl1(cs, "ISAC MON TX out of buffers!");
528 cs->dc.isac.arcofi_bc = 0;
529 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
530 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
531 if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
532 debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
533 p = cs->dc.isac.mon_rx;
535 t += sprintf(tmp, "Arcofi data");
536 QuickHex(t, p, cs->dc.isac.mon_rxp);
538 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
539 switch(cs->dc.isac.mon_rx[1]) {
541 debugl1(cs, "Arcofi 2160 detected");
545 debugl1(cs, "Arcofi 2165 detected");
549 debugl1(cs, "Arcofi 2163 detected");
553 debugl1(cs, "unknown Arcofi response");
557 debugl1(cs, "undefined Monitor response");
558 cs->dc.isac.mon_rxp = 0;
559 } else if (cs->dc.isac.mon_tx) {
560 debugl1(cs, "Arcofi not detected");
562 if (arcofi_present) {
563 if (cs->subtyp==ELSA_QS1000) {
564 cs->subtyp = ELSA_QS3000;
566 "Elsa: %s detected modem at 0x%lx\n",
567 Elsa_Types[cs->subtyp],
569 release_region(cs->hw.elsa.base, 8);
570 if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
572 "HiSax: %s config port %lx-%lx already in use\n",
573 Elsa_Types[cs->subtyp],
574 cs->hw.elsa.base + 8,
575 cs->hw.elsa.base + 16);
577 } else if (cs->subtyp==ELSA_PCC16) {
578 cs->subtyp = ELSA_PCF;
580 "Elsa: %s detected modem at 0x%lx\n",
581 Elsa_Types[cs->subtyp],
583 release_region(cs->hw.elsa.base, 8);
584 if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
586 "HiSax: %s config port %lx-%lx already in use\n",
587 Elsa_Types[cs->subtyp],
588 cs->hw.elsa.base + 8,
589 cs->hw.elsa.base + 16);
593 "Elsa: %s detected modem at 0x%lx\n",
594 Elsa_Types[cs->subtyp],
596 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
597 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
602 #endif /* ARCOFI_USE */
605 elsa_led_handler(struct IsdnCardState *cs)
609 if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
611 del_timer(&cs->hw.elsa.tl);
612 if (cs->hw.elsa.status & ELSA_ASSIGN)
613 cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
614 else if (cs->hw.elsa.status & ELSA_BAD_PWR)
615 cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
617 cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
620 if (cs->hw.elsa.status & 0xf000)
621 cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
622 else if (cs->hw.elsa.status & 0x0f00) {
623 cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
626 cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
628 if ((cs->subtyp == ELSA_QS1000PCI) ||
629 (cs->subtyp == ELSA_QS3000PCI)) {
631 if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
632 led ^= ELSA_IPAC_LINE_LED;
633 if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
634 led ^= ELSA_IPAC_STAT_LED;
635 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
637 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
639 init_timer(&cs->hw.elsa.tl);
640 cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
641 add_timer(&cs->hw.elsa.tl);
646 Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
653 spin_lock_irqsave(&cs->lock, flags);
655 spin_unlock_irqrestore(&cs->lock, flags);
661 spin_lock_irqsave(&cs->lock, flags);
662 cs->debug |= L1_DEB_IPAC;
665 if ((cs->subtyp == ELSA_QS1000) ||
666 (cs->subtyp == ELSA_QS3000))
668 byteout(cs->hw.elsa.timer, 0);
670 if (cs->hw.elsa.trig)
671 byteout(cs->hw.elsa.trig, 0xff);
673 spin_unlock_irqrestore(&cs->lock, flags);
676 if ((cs->subtyp == ELSA_PCMCIA) ||
677 (cs->subtyp == ELSA_PCMCIA_IPAC) ||
678 (cs->subtyp == ELSA_QS1000PCI)) {
680 } else if (cs->subtyp == ELSA_QS3000PCI) {
683 spin_lock_irqsave(&cs->lock, flags);
684 cs->hw.elsa.counter = 0;
685 cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
686 cs->hw.elsa.status |= ELIRQF_TIMER_AKTIV;
687 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
688 byteout(cs->hw.elsa.timer, 0);
689 spin_unlock_irqrestore(&cs->lock, flags);
691 spin_lock_irqsave(&cs->lock, flags);
692 cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
693 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
694 cs->hw.elsa.status &= ~ELIRQF_TIMER_AKTIV;
695 spin_unlock_irqrestore(&cs->lock, flags);
696 printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
697 cs->hw.elsa.counter);
698 if ((cs->hw.elsa.counter > 10) &&
699 (cs->hw.elsa.counter < 16)) {
700 printk(KERN_INFO "Elsa: timer and irq OK\n");
704 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
705 cs->hw.elsa.counter, cs->irq);
710 if (check_arcofi(cs)) {
714 elsa_led_handler(cs);
716 case (MDL_REMOVE | REQUEST):
717 cs->hw.elsa.status &= 0;
719 case (MDL_ASSIGN | REQUEST):
720 cs->hw.elsa.status |= ELSA_ASSIGN;
724 cs->hw.elsa.status |= 0x0200;
726 cs->hw.elsa.status |= 0x0100;
730 cs->hw.elsa.status |= 0x2000;
732 cs->hw.elsa.status |= 0x1000;
736 cs->hw.elsa.status &= ~0x2000;
737 cs->hw.elsa.status &= ~0x0200;
739 cs->hw.elsa.status &= ~0x1000;
740 cs->hw.elsa.status &= ~0x0100;
745 if (cs->hw.elsa.MFlag) {
754 modem_write_cmd(cs, msg, len);
759 if (cs->typ == ISDN_CTYPE_ELSA) {
760 int pwr = bytein(cs->hw.elsa.ale);
762 cs->hw.elsa.status |= ELSA_BAD_PWR;
764 cs->hw.elsa.status &= ~ELSA_BAD_PWR;
766 elsa_led_handler(cs);
771 probe_elsa_adr(unsigned int adr, int typ)
773 int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
774 pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
776 /* In case of the elsa pcmcia card, this region is in use,
777 reserved for us by the card manager. So we do not check it
778 here, it would fail. */
779 if (typ != ISDN_CTYPE_ELSA_PCMCIA) {
780 if (request_region(adr, 8, "elsa card")) {
781 release_region(adr, 8);
784 "Elsa: Probing Port 0x%x: already in use\n", adr);
788 for (i = 0; i < 16; i++) {
789 in1 = inb(adr + ELSA_CONFIG); /* 'toggelt' bei */
790 in2 = inb(adr + ELSA_CONFIG); /* jedem Zugriff */
800 printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
801 if (65 == ++p16_1 * ++p16_2) {
802 printk(" PCC-16/PCF found\n");
804 } else if (1025 == ++pfp_1 * ++pfp_2) {
805 printk(" PCF-Pro found\n");
806 return (ELSA_PCFPRO);
807 } else if (33 == ++p8_1 * ++p8_2) {
808 printk(" PCC8 found\n");
810 } else if (17 == ++pc_1 * ++pc_2) {
811 printk(" PC found\n");
820 probe_elsa(struct IsdnCardState *cs)
823 unsigned int CARD_portlist[] =
824 {0x160, 0x170, 0x260, 0x360, 0};
826 for (i = 0; CARD_portlist[i]; i++) {
827 if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
830 return (CARD_portlist[i]);
834 setup_elsa_isa(struct IsdnCard *card)
836 struct IsdnCardState *cs = card->cs;
839 cs->hw.elsa.base = card->para[0];
840 printk(KERN_INFO "Elsa: Microlink IO probing\n");
841 if (cs->hw.elsa.base) {
842 if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
845 "Elsa: no Elsa Microlink at %#lx\n",
850 cs->hw.elsa.base = probe_elsa(cs);
852 if (!cs->hw.elsa.base) {
854 "No Elsa Microlink found\n");
858 cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
859 cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
860 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
861 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
862 cs->hw.elsa.itac = cs->hw.elsa.base + ELSA_ITAC;
863 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
864 cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
865 cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
866 val = bytein(cs->hw.elsa.cfg);
867 if (cs->subtyp == ELSA_PC) {
868 const u_char CARD_IrqTab[8] =
869 {7, 3, 5, 9, 0, 0, 0, 0};
870 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
871 } else if (cs->subtyp == ELSA_PCC8) {
872 const u_char CARD_IrqTab[8] =
873 {7, 3, 5, 9, 0, 0, 0, 0};
874 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
876 const u_char CARD_IrqTab[8] =
877 {15, 10, 15, 3, 11, 5, 11, 9};
878 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
880 val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
884 if (val == 'B' || val == 'C')
886 if ((cs->subtyp == ELSA_PCFPRO) && (val = 'G'))
889 "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
890 Elsa_Types[cs->subtyp],
893 val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
896 "Elsa: Microlink S0 bus power bad\n");
897 cs->hw.elsa.status |= ELSA_BAD_PWR;
904 static struct isapnp_device_id elsa_ids[] __devinitdata = {
905 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
906 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
907 (unsigned long) "Elsa QS1000" },
908 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
909 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
910 (unsigned long) "Elsa QS3000" },
914 static struct isapnp_device_id *ipid __devinitdata = &elsa_ids[0];
915 static struct pnp_card *pnp_c __devinitdata = NULL;
916 #endif /* __ISAPNP__ */
919 setup_elsa_isapnp(struct IsdnCard *card)
921 struct IsdnCardState *cs = card->cs;
924 if (!card->para[1] && isapnp_present()) {
925 struct pnp_dev *pnp_d;
926 while(ipid->card_vendor) {
927 if ((pnp_c = pnp_find_card(ipid->card_vendor,
928 ipid->card_device, pnp_c))) {
930 if ((pnp_d = pnp_find_dev(pnp_c,
931 ipid->vendor, ipid->function, pnp_d))) {
934 printk(KERN_INFO "HiSax: %s detected\n",
935 (char *)ipid->driver_data);
936 pnp_disable_dev(pnp_d);
937 err = pnp_activate_dev(pnp_d);
939 printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
943 card->para[1] = pnp_port_start(pnp_d, 0);
944 card->para[0] = pnp_irq(pnp_d, 0);
946 if (!card->para[0] || !card->para[1]) {
947 printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
948 card->para[0], card->para[1]);
949 pnp_disable_dev(pnp_d);
952 if (ipid->function == ISAPNP_FUNCTION(0x133))
953 cs->subtyp = ELSA_QS1000;
955 cs->subtyp = ELSA_QS3000;
958 printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
965 if (!ipid->card_vendor) {
966 printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
970 #endif /* __ISAPNP__ */
972 if (card->para[1] && card->para[0]) {
973 cs->hw.elsa.base = card->para[1];
974 cs->irq = card->para[0];
976 cs->subtyp = ELSA_QS1000;
978 printk(KERN_ERR "Elsa PnP: no parameter\n");
980 cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
981 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
982 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
983 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
984 cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
985 cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
986 cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
988 "Elsa: %s defined at %#lx IRQ %d\n",
989 Elsa_Types[cs->subtyp],
996 static void __devinit
997 setup_elsa_pcmcia(struct IsdnCard *card)
999 struct IsdnCardState *cs = card->cs;
1002 cs->hw.elsa.base = card->para[1];
1003 cs->irq = card->para[0];
1004 val = readreg(cs->hw.elsa.base + 0, cs->hw.elsa.base + 2, IPAC_ID);
1005 if ((val == 1) || (val == 2)) { /* IPAC version 1.1/1.2 */
1006 cs->subtyp = ELSA_PCMCIA_IPAC;
1007 cs->hw.elsa.ale = cs->hw.elsa.base + 0;
1008 cs->hw.elsa.isac = cs->hw.elsa.base + 2;
1009 cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
1010 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1012 cs->subtyp = ELSA_PCMCIA;
1013 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE_PCM;
1014 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC_PCM;
1015 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
1017 cs->hw.elsa.timer = 0;
1018 cs->hw.elsa.trig = 0;
1019 cs->hw.elsa.ctrl = 0;
1020 cs->irq_flags |= IRQF_SHARED;
1022 "Elsa: %s defined at %#lx IRQ %d\n",
1023 Elsa_Types[cs->subtyp],
1029 static struct pci_dev *dev_qs1000 __devinitdata = NULL;
1030 static struct pci_dev *dev_qs3000 __devinitdata = NULL;
1032 static int __devinit
1033 setup_elsa_pci(struct IsdnCard *card)
1035 struct IsdnCardState *cs = card->cs;
1038 if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1039 PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1040 if (pci_enable_device(dev_qs1000))
1042 cs->subtyp = ELSA_QS1000PCI;
1043 cs->irq = dev_qs1000->irq;
1044 cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
1045 cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
1046 } else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1047 PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1048 if (pci_enable_device(dev_qs3000))
1050 cs->subtyp = ELSA_QS3000PCI;
1051 cs->irq = dev_qs3000->irq;
1052 cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
1053 cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
1055 printk(KERN_WARNING "Elsa: No PCI card found\n");
1059 printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
1063 if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
1064 printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
1067 if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
1068 printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
1069 printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
1070 printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
1072 cs->hw.elsa.ale = cs->hw.elsa.base;
1073 cs->hw.elsa.isac = cs->hw.elsa.base +1;
1074 cs->hw.elsa.hscx = cs->hw.elsa.base +1;
1075 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1076 cs->hw.elsa.timer = 0;
1077 cs->hw.elsa.trig = 0;
1078 cs->irq_flags |= IRQF_SHARED;
1080 "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
1081 Elsa_Types[cs->subtyp],
1091 static void __devinit
1092 setup_elsa_pci(struct IsdnCard *card)
1096 #endif /* CONFIG_PCI */
1098 static int __devinit
1099 setup_elsa_common(struct IsdnCard *card)
1101 struct IsdnCardState *cs = card->cs;
1105 switch (cs->subtyp) {
1111 case ELSA_PCMCIA_IPAC:
1117 case ELSA_QS3000PCI:
1120 case ELSA_QS1000PCI:
1125 "Unknown ELSA subtype %d\n", cs->subtyp);
1128 /* In case of the elsa pcmcia card, this region is in use,
1129 reserved for us by the card manager. So we do not check it
1130 here, it would fail. */
1131 if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(cs->hw.elsa.base, bytecnt, "elsa isdn")) {
1133 "HiSax: ELSA config port %#lx-%#lx already in use\n",
1135 cs->hw.elsa.base + bytecnt);
1138 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
1139 if (!request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci")) {
1141 "HiSax: ELSA pci port %x-%x already in use\n",
1143 cs->hw.elsa.cfg + 0x80);
1144 release_region(cs->hw.elsa.base, bytecnt);
1152 cs->hw.elsa.tl.function = (void *) elsa_led_handler;
1153 cs->hw.elsa.tl.data = (long) cs;
1154 init_timer(&cs->hw.elsa.tl);
1156 if (cs->hw.elsa.timer) {
1157 byteout(cs->hw.elsa.trig, 0xff);
1158 byteout(cs->hw.elsa.timer, 0);
1159 if (!TimerRun(cs)) {
1160 byteout(cs->hw.elsa.timer, 0); /* 2. Versuch */
1161 if (!TimerRun(cs)) {
1163 "Elsa: timer do not start\n");
1164 release_io_elsa(cs);
1168 HZDELAY((HZ/100) + 1); /* wait >=10 ms */
1170 printk(KERN_WARNING "Elsa: timer do not run down\n");
1171 release_io_elsa(cs);
1174 printk(KERN_INFO "Elsa: timer OK; resetting card\n");
1176 cs->BC_Read_Reg = &ReadHSCX;
1177 cs->BC_Write_Reg = &WriteHSCX;
1178 cs->BC_Send_Data = &hscx_fill_fifo;
1179 cs->cardmsg = &Elsa_card_msg;
1180 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
1181 cs->readisac = &ReadISAC_IPAC;
1182 cs->writeisac = &WriteISAC_IPAC;
1183 cs->readisacfifo = &ReadISACfifo_IPAC;
1184 cs->writeisacfifo = &WriteISACfifo_IPAC;
1185 cs->irq_func = &elsa_interrupt_ipac;
1186 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
1187 printk(KERN_INFO "Elsa: IPAC version %x\n", val);
1189 cs->readisac = &ReadISAC;
1190 cs->writeisac = &WriteISAC;
1191 cs->readisacfifo = &ReadISACfifo;
1192 cs->writeisacfifo = &WriteISACfifo;
1193 cs->irq_func = &elsa_interrupt;
1194 ISACVersion(cs, "Elsa:");
1195 if (HscxVersion(cs, "Elsa:")) {
1197 "Elsa: wrong HSCX versions check IO address\n");
1198 release_io_elsa(cs);
1202 if (cs->subtyp == ELSA_PC) {
1203 val = readitac(cs, ITAC_SYS);
1204 printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
1205 writeitac(cs, ITAC_ISEN, 0);
1206 writeitac(cs, ITAC_RFIE, 0);
1207 writeitac(cs, ITAC_XFIE, 0);
1208 writeitac(cs, ITAC_SCIE, 0);
1209 writeitac(cs, ITAC_STIE, 0);
1215 setup_elsa(struct IsdnCard *card)
1218 struct IsdnCardState *cs = card->cs;
1221 strcpy(tmp, Elsa_revision);
1222 printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
1223 cs->hw.elsa.ctrl_reg = 0;
1224 cs->hw.elsa.status = 0;
1225 cs->hw.elsa.MFlag = 0;
1228 if (cs->typ == ISDN_CTYPE_ELSA) {
1229 rc = setup_elsa_isa(card);
1233 } else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
1234 rc = setup_elsa_isapnp(card);
1238 } else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA)
1239 setup_elsa_pcmcia(card);
1241 else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
1242 rc = setup_elsa_pci(card);
1249 return setup_elsa_common(card);