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>
22 #include <linux/config.h>
29 #include <linux/pci.h>
30 #include <linux/isapnp.h>
31 #include <linux/serial.h>
32 #include <linux/serial_reg.h>
34 extern const char *CardType
[];
36 const char *Elsa_revision
= "$Revision: 2.32.2.4 $";
37 const char *Elsa_Types
[] =
38 {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
39 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
42 const char *ITACVer
[] =
43 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
46 #define byteout(addr,val) outb(val,addr)
47 #define bytein(addr) inb(addr)
50 #define ELSA_ISAC_PCM 1
54 #define ELSA_ALE_PCM 4
55 #define ELSA_CONTROL 4
57 #define ELSA_START_TIMER 6
58 #define ELSA_TRIG_IRQ 7
68 #define ELSA_QS1000PCI 9
69 #define ELSA_QS3000PCI 10
70 #define ELSA_PCMCIA_IPAC 11
73 #define ELSA_PCI_IRQ_MASK 0x04
75 /* ITAC Registeradressen (only Microlink PC) */
77 #define ITAC_ISEN 0x48
78 #define ITAC_RFIE 0x4A
79 #define ITAC_XFIE 0x4C
80 #define ITAC_SCIE 0x4E
81 #define ITAC_STIE 0x46
84 *** Makros als Befehle fuer die Kartenregister ***
85 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
88 /* Config-Register (Read) */
89 #define ELSA_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
90 #define ELSA_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
91 #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
92 #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
93 #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
95 /* Control-Register (Write) */
96 #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
97 #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
98 #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
99 #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
101 /* ALE-Register (Read) */
102 #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
103 #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
106 #define ELSA_TIMER_AKTIV 1
107 #define ELSA_BAD_PWR 2
108 #define ELSA_ASSIGN 4
110 #define RS_ISR_PASS_LIMIT 256
111 #define _INLINE_ inline
112 #define FLG_MODEM_ACTIVE 1
114 #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
115 #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
118 static struct arcofi_msg ARCOFI_XOP_F
=
119 {NULL
,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
120 static struct arcofi_msg ARCOFI_XOP_1
=
121 {&ARCOFI_XOP_F
,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
122 static struct arcofi_msg ARCOFI_SOP_F
=
123 {&ARCOFI_XOP_1
,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
124 static struct arcofi_msg ARCOFI_COP_9
=
125 {&ARCOFI_SOP_F
,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
126 static struct arcofi_msg ARCOFI_COP_8
=
127 {&ARCOFI_COP_9
,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
128 static struct arcofi_msg ARCOFI_COP_7
=
129 {&ARCOFI_COP_8
,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
130 static struct arcofi_msg ARCOFI_COP_6
=
131 {&ARCOFI_COP_7
,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
132 static struct arcofi_msg ARCOFI_COP_5
=
133 {&ARCOFI_COP_6
,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
134 static struct arcofi_msg ARCOFI_VERSION
=
135 {NULL
,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
136 static struct arcofi_msg ARCOFI_XOP_0
=
137 {NULL
,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
139 static void set_arcofi(struct IsdnCardState
*cs
, int bc
);
141 #include "elsa_ser.c"
142 #endif /* ARCOFI_USE */
145 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
155 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
158 insb(adr
, data
, size
);
163 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
170 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
173 outsb(adr
, data
, size
);
176 /* Interface functions */
179 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
181 return (readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
));
185 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
187 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
, value
);
191 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
193 readfifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0, data
, size
);
197 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
199 writefifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0, data
, size
);
203 ReadISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
)
205 return (readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
+0x80));
209 WriteISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
211 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
|0x80, value
);
215 ReadISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
217 readfifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0x80, data
, size
);
221 WriteISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
223 writefifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0x80, data
, size
);
227 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
229 return (readreg(cs
->hw
.elsa
.ale
,
230 cs
->hw
.elsa
.hscx
, offset
+ (hscx
? 0x40 : 0)));
234 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
236 writereg(cs
->hw
.elsa
.ale
,
237 cs
->hw
.elsa
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
241 readitac(struct IsdnCardState
*cs
, u_char off
)
245 byteout(cs
->hw
.elsa
.ale
, off
);
246 ret
= bytein(cs
->hw
.elsa
.itac
);
251 writeitac(struct IsdnCardState
*cs
, u_char off
, u_char data
)
253 byteout(cs
->hw
.elsa
.ale
, off
);
254 byteout(cs
->hw
.elsa
.itac
, data
);
258 TimerRun(struct IsdnCardState
*cs
)
262 v
= bytein(cs
->hw
.elsa
.cfg
);
263 if ((cs
->subtyp
== ELSA_QS1000
) || (cs
->subtyp
== ELSA_QS3000
))
264 return (0 == (v
& ELSA_TIMER_RUN
));
265 else if (cs
->subtyp
== ELSA_PCC8
)
266 return (v
& ELSA_TIMER_RUN_PCC8
);
267 return (v
& ELSA_TIMER_RUN
);
270 * fast interrupt HSCX stuff goes here
273 #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
274 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
275 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
276 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
278 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
279 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
281 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
282 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
284 #include "hscx_irq.c"
287 elsa_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
289 struct IsdnCardState
*cs
= dev_id
;
294 if ((cs
->typ
== ISDN_CTYPE_ELSA_PCMCIA
) && (*cs
->busy_flag
== 1)) {
295 /* The card tends to generate interrupts while being removed
296 causing us to just crash the kernel. bad. */
297 printk(KERN_WARNING
"Elsa: card not available!\n");
300 spin_lock_irqsave(&cs
->lock
, flags
);
302 if (cs
->hw
.elsa
.MFlag
) {
303 val
= serial_inp(cs
, UART_IIR
);
304 if (!(val
& UART_IIR_NO_INT
)) {
305 debugl1(cs
,"IIR %02x", val
);
306 rs_interrupt_elsa(intno
, cs
);
310 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_ISTA
+ 0x40);
313 hscx_int_main(cs
, val
);
315 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_ISTA
);
318 isac_interrupt(cs
, val
);
320 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_ISTA
+ 0x40);
322 if (cs
->debug
& L1_DEB_HSCX
)
323 debugl1(cs
, "HSCX IntStat after IntRoutine");
327 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_ISTA
);
329 if (cs
->debug
& L1_DEB_ISAC
)
330 debugl1(cs
, "ISAC IntStat after IntRoutine");
335 printk(KERN_WARNING
"ELSA IRQ LOOP\n");
336 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
, 0xFF);
337 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
338 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_MASK
, 0xFF);
339 if (cs
->hw
.elsa
.status
& ELSA_TIMER_AKTIV
) {
342 byteout(cs
->hw
.elsa
.timer
, 0);
343 cs
->hw
.elsa
.counter
++;
347 if (cs
->hw
.elsa
.MFlag
) {
348 val
= serial_inp(cs
, UART_MCR
);
350 serial_outp(cs
, UART_MCR
, val
);
351 val
= serial_inp(cs
, UART_MCR
);
353 serial_outp(cs
, UART_MCR
, val
);
356 if (cs
->hw
.elsa
.trig
)
357 byteout(cs
->hw
.elsa
.trig
, 0x00);
358 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
, 0x0);
359 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
+ 0x40, 0x0);
360 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_MASK
, 0x0);
361 spin_unlock_irqrestore(&cs
->lock
, flags
);
366 elsa_interrupt_ipac(int intno
, void *dev_id
, struct pt_regs
*regs
)
368 struct IsdnCardState
*cs
= dev_id
;
373 spin_lock_irqsave(&cs
->lock
, flags
);
374 if (cs
->subtyp
== ELSA_QS1000PCI
|| cs
->subtyp
== ELSA_QS3000PCI
) {
375 val
= bytein(cs
->hw
.elsa
.cfg
+ 0x4c); /* PCI IRQ */
376 if (!(val
& ELSA_PCI_IRQ_MASK
)) {
377 spin_unlock_irqrestore(&cs
->lock
, flags
);
382 if (cs
->hw
.elsa
.MFlag
) {
383 val
= serial_inp(cs
, UART_IIR
);
384 if (!(val
& UART_IIR_NO_INT
)) {
385 debugl1(cs
,"IIR %02x", val
);
386 rs_interrupt_elsa(intno
, cs
);
390 ista
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ISTA
);
392 if (cs
->debug
& L1_DEB_IPAC
)
393 debugl1(cs
, "IPAC ISTA %02X", ista
);
395 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_ISTA
+ 0x40);
403 hscx_int_main(cs
, val
);
406 val
= 0xfe & readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_ISTA
+ 0x80);
408 isac_interrupt(cs
, val
);
413 isac_interrupt(cs
, val
);
415 ista
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ISTA
);
416 if ((ista
& 0x3f) && icnt
) {
421 printk(KERN_WARNING
"ELSA IRQ LOOP\n");
422 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xFF);
423 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xC0);
424 spin_unlock_irqrestore(&cs
->lock
, flags
);
429 release_io_elsa(struct IsdnCardState
*cs
)
433 del_timer(&cs
->hw
.elsa
.tl
);
437 if (cs
->hw
.elsa
.ctrl
)
438 byteout(cs
->hw
.elsa
.ctrl
, 0); /* LEDs Out */
439 if (cs
->subtyp
== ELSA_QS1000PCI
) {
440 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x01); /* disable IRQ */
441 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
443 release_region(cs
->hw
.elsa
.cfg
, 0x80);
445 if (cs
->subtyp
== ELSA_QS3000PCI
) {
446 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x03); /* disable ELSA PCI IRQ */
447 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
448 release_region(cs
->hw
.elsa
.cfg
, 0x80);
450 if (cs
->subtyp
== ELSA_PCMCIA_IPAC
) {
451 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
453 if ((cs
->subtyp
== ELSA_PCFPRO
) ||
454 (cs
->subtyp
== ELSA_QS3000
) ||
455 (cs
->subtyp
== ELSA_PCF
) ||
456 (cs
->subtyp
== ELSA_QS3000PCI
)) {
462 if (cs
->hw
.elsa
.base
)
463 release_region(cs
->hw
.elsa
.base
, bytecnt
);
467 reset_elsa(struct IsdnCardState
*cs
)
469 if (cs
->hw
.elsa
.timer
) {
471 byteout(cs
->hw
.elsa
.timer
, 0);
472 while (TimerRun(cs
));
473 cs
->hw
.elsa
.ctrl_reg
|= 0x50;
474 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_ISDN_RESET
; /* Reset On */
475 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
477 byteout(cs
->hw
.elsa
.timer
, 0);
478 while (TimerRun(cs
));
479 cs
->hw
.elsa
.ctrl_reg
|= ELSA_ISDN_RESET
; /* Reset Off */
480 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
482 byteout(cs
->hw
.elsa
.timer
, 0);
483 while (TimerRun(cs
));
484 if (cs
->hw
.elsa
.trig
)
485 byteout(cs
->hw
.elsa
.trig
, 0xff);
487 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
) || (cs
->subtyp
== ELSA_PCMCIA_IPAC
)) {
488 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_POTA2
, 0x20);
490 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_POTA2
, 0x00);
491 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xc0);
493 if (cs
->subtyp
!= ELSA_PCMCIA_IPAC
) {
494 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ACFG
, 0x0);
495 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_AOE
, 0x3c);
497 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_PCFG
, 0x10);
498 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ACFG
, 0x4);
499 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_AOE
, 0xf8);
501 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
502 if (cs
->subtyp
== ELSA_QS1000PCI
)
503 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x41); /* enable ELSA PCI IRQ */
504 else if (cs
->subtyp
== ELSA_QS3000PCI
)
505 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x43); /* enable ELSA PCI IRQ */
512 set_arcofi(struct IsdnCardState
*cs
, int bc
) {
513 cs
->dc
.isac
.arcofi_bc
= bc
;
514 arcofi_fsm(cs
, ARCOFI_START
, &ARCOFI_COP_5
);
515 interruptible_sleep_on(&cs
->dc
.isac
.arcofi_wait
);
519 check_arcofi(struct IsdnCardState
*cs
)
521 int arcofi_present
= 0;
526 if (!cs
->dc
.isac
.mon_tx
)
527 if (!(cs
->dc
.isac
.mon_tx
=kmalloc(MAX_MON_FRAME
, GFP_ATOMIC
))) {
528 if (cs
->debug
& L1_DEB_WARN
)
529 debugl1(cs
, "ISAC MON TX out of buffers!");
532 cs
->dc
.isac
.arcofi_bc
= 0;
533 arcofi_fsm(cs
, ARCOFI_START
, &ARCOFI_VERSION
);
534 interruptible_sleep_on(&cs
->dc
.isac
.arcofi_wait
);
535 if (!test_and_clear_bit(FLG_ARCOFI_ERROR
, &cs
->HW_Flags
)) {
536 debugl1(cs
, "Arcofi response received %d bytes", cs
->dc
.isac
.mon_rxp
);
537 p
= cs
->dc
.isac
.mon_rx
;
539 t
+= sprintf(tmp
, "Arcofi data");
540 QuickHex(t
, p
, cs
->dc
.isac
.mon_rxp
);
542 if ((cs
->dc
.isac
.mon_rxp
== 2) && (cs
->dc
.isac
.mon_rx
[0] == 0xa0)) {
543 switch(cs
->dc
.isac
.mon_rx
[1]) {
545 debugl1(cs
, "Arcofi 2160 detected");
549 debugl1(cs
, "Arcofi 2165 detected");
553 debugl1(cs
, "Arcofi 2163 detected");
557 debugl1(cs
, "unknown Arcofi response");
561 debugl1(cs
, "undefined Monitor response");
562 cs
->dc
.isac
.mon_rxp
= 0;
563 } else if (cs
->dc
.isac
.mon_tx
) {
564 debugl1(cs
, "Arcofi not detected");
566 if (arcofi_present
) {
567 if (cs
->subtyp
==ELSA_QS1000
) {
568 cs
->subtyp
= ELSA_QS3000
;
570 "Elsa: %s detected modem at 0x%lx\n",
571 Elsa_Types
[cs
->subtyp
],
573 release_region(cs
->hw
.elsa
.base
, 8);
574 if (!request_region(cs
->hw
.elsa
.base
, 16, "elsa isdn modem")) {
576 "HiSax: %s config port %lx-%lx already in use\n",
577 Elsa_Types
[cs
->subtyp
],
578 cs
->hw
.elsa
.base
+ 8,
579 cs
->hw
.elsa
.base
+ 16);
581 } else if (cs
->subtyp
==ELSA_PCC16
) {
582 cs
->subtyp
= ELSA_PCF
;
584 "Elsa: %s detected modem at 0x%lx\n",
585 Elsa_Types
[cs
->subtyp
],
587 release_region(cs
->hw
.elsa
.base
, 8);
588 if (!request_region(cs
->hw
.elsa
.base
, 16, "elsa isdn modem")) {
590 "HiSax: %s config port %lx-%lx already in use\n",
591 Elsa_Types
[cs
->subtyp
],
592 cs
->hw
.elsa
.base
+ 8,
593 cs
->hw
.elsa
.base
+ 16);
597 "Elsa: %s detected modem at 0x%lx\n",
598 Elsa_Types
[cs
->subtyp
],
600 arcofi_fsm(cs
, ARCOFI_START
, &ARCOFI_XOP_0
);
601 interruptible_sleep_on(&cs
->dc
.isac
.arcofi_wait
);
606 #endif /* ARCOFI_USE */
609 elsa_led_handler(struct IsdnCardState
*cs
)
613 if (cs
->subtyp
== ELSA_PCMCIA
|| cs
->subtyp
== ELSA_PCMCIA_IPAC
)
615 del_timer(&cs
->hw
.elsa
.tl
);
616 if (cs
->hw
.elsa
.status
& ELSA_ASSIGN
)
617 cs
->hw
.elsa
.ctrl_reg
|= ELSA_STAT_LED
;
618 else if (cs
->hw
.elsa
.status
& ELSA_BAD_PWR
)
619 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_STAT_LED
;
621 cs
->hw
.elsa
.ctrl_reg
^= ELSA_STAT_LED
;
624 if (cs
->hw
.elsa
.status
& 0xf000)
625 cs
->hw
.elsa
.ctrl_reg
|= ELSA_LINE_LED
;
626 else if (cs
->hw
.elsa
.status
& 0x0f00) {
627 cs
->hw
.elsa
.ctrl_reg
^= ELSA_LINE_LED
;
630 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_LINE_LED
;
632 if ((cs
->subtyp
== ELSA_QS1000PCI
) ||
633 (cs
->subtyp
== ELSA_QS3000PCI
)) {
635 if (cs
->hw
.elsa
.ctrl_reg
& ELSA_LINE_LED
)
636 led
^= ELSA_IPAC_LINE_LED
;
637 if (cs
->hw
.elsa
.ctrl_reg
& ELSA_STAT_LED
)
638 led
^= ELSA_IPAC_STAT_LED
;
639 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, led
);
641 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
643 init_timer(&cs
->hw
.elsa
.tl
);
644 cs
->hw
.elsa
.tl
.expires
= jiffies
+ ((blink
* HZ
) / 1000);
645 add_timer(&cs
->hw
.elsa
.tl
);
650 Elsa_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
657 spin_lock_irqsave(&cs
->lock
, flags
);
659 spin_unlock_irqrestore(&cs
->lock
, flags
);
665 spin_lock_irqsave(&cs
->lock
, flags
);
666 cs
->debug
|= L1_DEB_IPAC
;
669 if ((cs
->subtyp
== ELSA_QS1000
) ||
670 (cs
->subtyp
== ELSA_QS3000
))
672 byteout(cs
->hw
.elsa
.timer
, 0);
674 if (cs
->hw
.elsa
.trig
)
675 byteout(cs
->hw
.elsa
.trig
, 0xff);
677 spin_unlock_irqrestore(&cs
->lock
, flags
);
680 if ((cs
->subtyp
== ELSA_PCMCIA
) ||
681 (cs
->subtyp
== ELSA_PCMCIA_IPAC
) ||
682 (cs
->subtyp
== ELSA_QS1000PCI
)) {
684 } else if (cs
->subtyp
== ELSA_QS3000PCI
) {
687 spin_lock_irqsave(&cs
->lock
, flags
);
688 cs
->hw
.elsa
.counter
= 0;
689 cs
->hw
.elsa
.ctrl_reg
|= ELSA_ENA_TIMER_INT
;
690 cs
->hw
.elsa
.status
|= ELSA_TIMER_AKTIV
;
691 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
692 byteout(cs
->hw
.elsa
.timer
, 0);
693 spin_unlock_irqrestore(&cs
->lock
, flags
);
695 spin_lock_irqsave(&cs
->lock
, flags
);
696 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_ENA_TIMER_INT
;
697 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
698 cs
->hw
.elsa
.status
&= ~ELSA_TIMER_AKTIV
;
699 spin_unlock_irqrestore(&cs
->lock
, flags
);
700 printk(KERN_INFO
"Elsa: %d timer tics in 110 msek\n",
701 cs
->hw
.elsa
.counter
);
702 if ((cs
->hw
.elsa
.counter
> 10) &&
703 (cs
->hw
.elsa
.counter
< 16)) {
704 printk(KERN_INFO
"Elsa: timer and irq OK\n");
708 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
709 cs
->hw
.elsa
.counter
, cs
->irq
);
714 if (check_arcofi(cs
)) {
718 elsa_led_handler(cs
);
720 case (MDL_REMOVE
| REQUEST
):
721 cs
->hw
.elsa
.status
&= 0;
723 case (MDL_ASSIGN
| REQUEST
):
724 cs
->hw
.elsa
.status
|= ELSA_ASSIGN
;
728 cs
->hw
.elsa
.status
|= 0x0200;
730 cs
->hw
.elsa
.status
|= 0x0100;
734 cs
->hw
.elsa
.status
|= 0x2000;
736 cs
->hw
.elsa
.status
|= 0x1000;
740 cs
->hw
.elsa
.status
&= ~0x2000;
741 cs
->hw
.elsa
.status
&= ~0x0200;
743 cs
->hw
.elsa
.status
&= ~0x1000;
744 cs
->hw
.elsa
.status
&= ~0x0100;
749 if (cs
->hw
.elsa
.MFlag
) {
758 modem_write_cmd(cs
, msg
, len
);
763 if (cs
->typ
== ISDN_CTYPE_ELSA
) {
764 int pwr
= bytein(cs
->hw
.elsa
.ale
);
766 cs
->hw
.elsa
.status
|= ELSA_BAD_PWR
;
768 cs
->hw
.elsa
.status
&= ~ELSA_BAD_PWR
;
770 elsa_led_handler(cs
);
775 probe_elsa_adr(unsigned int adr
, int typ
)
777 int i
, in1
, in2
, p16_1
= 0, p16_2
= 0, p8_1
= 0, p8_2
= 0, pc_1
= 0,
778 pc_2
= 0, pfp_1
= 0, pfp_2
= 0;
780 /* In case of the elsa pcmcia card, this region is in use,
781 reserved for us by the card manager. So we do not check it
782 here, it would fail. */
783 if (typ
!= ISDN_CTYPE_ELSA_PCMCIA
) {
784 if (request_region(adr
, 8, "elsa card")) {
785 release_region(adr
, 8);
788 "Elsa: Probing Port 0x%x: already in use\n", adr
);
792 for (i
= 0; i
< 16; i
++) {
793 in1
= inb(adr
+ ELSA_CONFIG
); /* 'toggelt' bei */
794 in2
= inb(adr
+ ELSA_CONFIG
); /* jedem Zugriff */
804 printk(KERN_INFO
"Elsa: Probing IO 0x%x", adr
);
805 if (65 == ++p16_1
* ++p16_2
) {
806 printk(" PCC-16/PCF found\n");
808 } else if (1025 == ++pfp_1
* ++pfp_2
) {
809 printk(" PCF-Pro found\n");
810 return (ELSA_PCFPRO
);
811 } else if (33 == ++p8_1
* ++p8_2
) {
812 printk(" PCC8 found\n");
814 } else if (17 == ++pc_1
* ++pc_2
) {
815 printk(" PC found\n");
824 probe_elsa(struct IsdnCardState
*cs
)
827 unsigned int CARD_portlist
[] =
828 {0x160, 0x170, 0x260, 0x360, 0};
830 for (i
= 0; CARD_portlist
[i
]; i
++) {
831 if ((cs
->subtyp
= probe_elsa_adr(CARD_portlist
[i
], cs
->typ
)))
834 return (CARD_portlist
[i
]);
837 static struct pci_dev
*dev_qs1000 __devinitdata
= NULL
;
838 static struct pci_dev
*dev_qs3000 __devinitdata
= NULL
;
841 static struct isapnp_device_id elsa_ids
[] __devinitdata
= {
842 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
843 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
844 (unsigned long) "Elsa QS1000" },
845 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
846 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
847 (unsigned long) "Elsa QS3000" },
851 static struct isapnp_device_id
*ipid __devinitdata
= &elsa_ids
[0];
852 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
856 setup_elsa(struct IsdnCard
*card
)
860 struct IsdnCardState
*cs
= card
->cs
;
863 strcpy(tmp
, Elsa_revision
);
864 printk(KERN_INFO
"HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp
));
865 cs
->hw
.elsa
.ctrl_reg
= 0;
866 cs
->hw
.elsa
.status
= 0;
867 cs
->hw
.elsa
.MFlag
= 0;
869 if (cs
->typ
== ISDN_CTYPE_ELSA
) {
870 cs
->hw
.elsa
.base
= card
->para
[0];
871 printk(KERN_INFO
"Elsa: Microlink IO probing\n");
872 if (cs
->hw
.elsa
.base
) {
873 if (!(cs
->subtyp
= probe_elsa_adr(cs
->hw
.elsa
.base
,
876 "Elsa: no Elsa Microlink at %#lx\n",
881 cs
->hw
.elsa
.base
= probe_elsa(cs
);
882 if (cs
->hw
.elsa
.base
) {
883 cs
->hw
.elsa
.cfg
= cs
->hw
.elsa
.base
+ ELSA_CONFIG
;
884 cs
->hw
.elsa
.ctrl
= cs
->hw
.elsa
.base
+ ELSA_CONTROL
;
885 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE
;
886 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC
;
887 cs
->hw
.elsa
.itac
= cs
->hw
.elsa
.base
+ ELSA_ITAC
;
888 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
889 cs
->hw
.elsa
.trig
= cs
->hw
.elsa
.base
+ ELSA_TRIG_IRQ
;
890 cs
->hw
.elsa
.timer
= cs
->hw
.elsa
.base
+ ELSA_START_TIMER
;
891 val
= bytein(cs
->hw
.elsa
.cfg
);
892 if (cs
->subtyp
== ELSA_PC
) {
893 const u_char CARD_IrqTab
[8] =
894 {7, 3, 5, 9, 0, 0, 0, 0};
895 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX_PC
) >> 2];
896 } else if (cs
->subtyp
== ELSA_PCC8
) {
897 const u_char CARD_IrqTab
[8] =
898 {7, 3, 5, 9, 0, 0, 0, 0};
899 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX_PCC8
) >> 4];
901 const u_char CARD_IrqTab
[8] =
902 {15, 10, 15, 3, 11, 5, 11, 9};
903 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX
) >> 3];
905 val
= bytein(cs
->hw
.elsa
.ale
) & ELSA_HW_RELEASE
;
909 if (val
== 'B' || val
== 'C')
911 if ((cs
->subtyp
== ELSA_PCFPRO
) && (val
= 'G'))
914 "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
915 Elsa_Types
[cs
->subtyp
],
918 val
= bytein(cs
->hw
.elsa
.ale
) & ELSA_S0_POWER_BAD
;
921 "Elsa: Microlink S0 bus power bad\n");
922 cs
->hw
.elsa
.status
|= ELSA_BAD_PWR
;
926 "No Elsa Microlink found\n");
929 } else if (cs
->typ
== ISDN_CTYPE_ELSA_PNP
) {
931 if (!card
->para
[1] && isapnp_present()) {
932 struct pnp_dev
*pnp_d
;
933 while(ipid
->card_vendor
) {
934 if ((pnp_c
= pnp_find_card(ipid
->card_vendor
,
935 ipid
->card_device
, pnp_c
))) {
937 if ((pnp_d
= pnp_find_dev(pnp_c
,
938 ipid
->vendor
, ipid
->function
, pnp_d
))) {
941 printk(KERN_INFO
"HiSax: %s detected\n",
942 (char *)ipid
->driver_data
);
943 pnp_disable_dev(pnp_d
);
944 err
= pnp_activate_dev(pnp_d
);
946 printk(KERN_WARNING
"%s: pnp_activate_dev ret(%d)\n",
950 card
->para
[1] = pnp_port_start(pnp_d
, 0);
951 card
->para
[0] = pnp_irq(pnp_d
, 0);
953 if (!card
->para
[0] || !card
->para
[1]) {
954 printk(KERN_ERR
"Elsa PnP:some resources are missing %ld/%lx\n",
955 card
->para
[0], card
->para
[1]);
956 pnp_disable_dev(pnp_d
);
959 if (ipid
->function
== ISAPNP_FUNCTION(0x133))
960 cs
->subtyp
= ELSA_QS1000
;
962 cs
->subtyp
= ELSA_QS3000
;
965 printk(KERN_ERR
"Elsa PnP: PnP error card found, no device\n");
972 if (!ipid
->card_vendor
) {
973 printk(KERN_INFO
"Elsa PnP: no ISAPnP card found\n");
978 if (card
->para
[1] && card
->para
[0]) {
979 cs
->hw
.elsa
.base
= card
->para
[1];
980 cs
->irq
= card
->para
[0];
982 cs
->subtyp
= ELSA_QS1000
;
984 printk(KERN_ERR
"Elsa PnP: no parameter\n");
986 cs
->hw
.elsa
.cfg
= cs
->hw
.elsa
.base
+ ELSA_CONFIG
;
987 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE
;
988 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC
;
989 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
990 cs
->hw
.elsa
.trig
= cs
->hw
.elsa
.base
+ ELSA_TRIG_IRQ
;
991 cs
->hw
.elsa
.timer
= cs
->hw
.elsa
.base
+ ELSA_START_TIMER
;
992 cs
->hw
.elsa
.ctrl
= cs
->hw
.elsa
.base
+ ELSA_CONTROL
;
994 "Elsa: %s defined at %#lx IRQ %d\n",
995 Elsa_Types
[cs
->subtyp
],
998 } else if (cs
->typ
== ISDN_CTYPE_ELSA_PCMCIA
) {
999 cs
->hw
.elsa
.base
= card
->para
[1];
1000 cs
->irq
= card
->para
[0];
1001 val
= readreg(cs
->hw
.elsa
.base
+ 0, cs
->hw
.elsa
.base
+ 2, IPAC_ID
);
1002 if ((val
== 1) || (val
== 2)) { /* IPAC version 1.1/1.2 */
1003 cs
->subtyp
= ELSA_PCMCIA_IPAC
;
1004 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ 0;
1005 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ 2;
1006 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ 2;
1007 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
1009 cs
->subtyp
= ELSA_PCMCIA
;
1010 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE_PCM
;
1011 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC_PCM
;
1012 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
1014 cs
->hw
.elsa
.timer
= 0;
1015 cs
->hw
.elsa
.trig
= 0;
1016 cs
->hw
.elsa
.ctrl
= 0;
1017 cs
->irq_flags
|= SA_SHIRQ
;
1019 "Elsa: %s defined at %#lx IRQ %d\n",
1020 Elsa_Types
[cs
->subtyp
],
1023 } else if (cs
->typ
== ISDN_CTYPE_ELSA_PCI
) {
1026 if ((dev_qs1000
= pci_find_device(PCI_VENDOR_ID_ELSA
,
1027 PCI_DEVICE_ID_ELSA_MICROLINK
, dev_qs1000
))) {
1028 if (pci_enable_device(dev_qs1000
))
1030 cs
->subtyp
= ELSA_QS1000PCI
;
1031 cs
->irq
= dev_qs1000
->irq
;
1032 cs
->hw
.elsa
.cfg
= pci_resource_start(dev_qs1000
, 1);
1033 cs
->hw
.elsa
.base
= pci_resource_start(dev_qs1000
, 3);
1034 } else if ((dev_qs3000
= pci_find_device(PCI_VENDOR_ID_ELSA
,
1035 PCI_DEVICE_ID_ELSA_QS3000
, dev_qs3000
))) {
1036 if (pci_enable_device(dev_qs3000
))
1038 cs
->subtyp
= ELSA_QS3000PCI
;
1039 cs
->irq
= dev_qs3000
->irq
;
1040 cs
->hw
.elsa
.cfg
= pci_resource_start(dev_qs3000
, 1);
1041 cs
->hw
.elsa
.base
= pci_resource_start(dev_qs3000
, 3);
1043 printk(KERN_WARNING
"Elsa: No PCI card found\n");
1047 printk(KERN_WARNING
"Elsa: No IRQ for PCI card found\n");
1051 if (!(cs
->hw
.elsa
.base
&& cs
->hw
.elsa
.cfg
)) {
1052 printk(KERN_WARNING
"Elsa: No IO-Adr for PCI card found\n");
1055 if ((cs
->hw
.elsa
.cfg
& 0xff) || (cs
->hw
.elsa
.base
& 0xf)) {
1056 printk(KERN_WARNING
"Elsa: You may have a wrong PCI bios\n");
1057 printk(KERN_WARNING
"Elsa: If your system hangs now, read\n");
1058 printk(KERN_WARNING
"Elsa: Documentation/isdn/README.HiSax\n");
1060 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
;
1061 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+1;
1062 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+1;
1063 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
1064 cs
->hw
.elsa
.timer
= 0;
1065 cs
->hw
.elsa
.trig
= 0;
1066 cs
->irq_flags
|= SA_SHIRQ
;
1068 "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
1069 Elsa_Types
[cs
->subtyp
],
1074 printk(KERN_WARNING
"Elsa: Elsa PCI and NO_PCI_BIOS\n");
1075 printk(KERN_WARNING
"Elsa: unable to config Elsa PCI\n");
1077 #endif /* CONFIG_PCI */
1081 switch (cs
->subtyp
) {
1087 case ELSA_PCMCIA_IPAC
:
1093 case ELSA_QS3000PCI
:
1096 case ELSA_QS1000PCI
:
1101 "Unknown ELSA subtype %d\n", cs
->subtyp
);
1104 /* In case of the elsa pcmcia card, this region is in use,
1105 reserved for us by the card manager. So we do not check it
1106 here, it would fail. */
1107 if (cs
->typ
!= ISDN_CTYPE_ELSA_PCMCIA
&& !request_region(cs
->hw
.elsa
.base
, bytecnt
, "elsa isdn")) {
1109 "HiSax: %s config port %#lx-%#lx already in use\n",
1110 CardType
[card
->typ
],
1112 cs
->hw
.elsa
.base
+ bytecnt
);
1115 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
)) {
1116 if (!request_region(cs
->hw
.elsa
.cfg
, 0x80, "elsa isdn pci")) {
1118 "HiSax: %s pci port %x-%x already in use\n",
1119 CardType
[card
->typ
],
1121 cs
->hw
.elsa
.cfg
+ 0x80);
1122 release_region(cs
->hw
.elsa
.base
, bytecnt
);
1130 cs
->hw
.elsa
.tl
.function
= (void *) elsa_led_handler
;
1131 cs
->hw
.elsa
.tl
.data
= (long) cs
;
1132 init_timer(&cs
->hw
.elsa
.tl
);
1134 if (cs
->hw
.elsa
.timer
) {
1135 byteout(cs
->hw
.elsa
.trig
, 0xff);
1136 byteout(cs
->hw
.elsa
.timer
, 0);
1137 if (!TimerRun(cs
)) {
1138 byteout(cs
->hw
.elsa
.timer
, 0); /* 2. Versuch */
1139 if (!TimerRun(cs
)) {
1141 "Elsa: timer do not start\n");
1142 release_io_elsa(cs
);
1146 HZDELAY((HZ
/100) + 1); /* wait >=10 ms */
1148 printk(KERN_WARNING
"Elsa: timer do not run down\n");
1149 release_io_elsa(cs
);
1152 printk(KERN_INFO
"Elsa: timer OK; resetting card\n");
1154 cs
->BC_Read_Reg
= &ReadHSCX
;
1155 cs
->BC_Write_Reg
= &WriteHSCX
;
1156 cs
->BC_Send_Data
= &hscx_fill_fifo
;
1157 cs
->cardmsg
= &Elsa_card_msg
;
1158 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
) || (cs
->subtyp
== ELSA_PCMCIA_IPAC
)) {
1159 cs
->readisac
= &ReadISAC_IPAC
;
1160 cs
->writeisac
= &WriteISAC_IPAC
;
1161 cs
->readisacfifo
= &ReadISACfifo_IPAC
;
1162 cs
->writeisacfifo
= &WriteISACfifo_IPAC
;
1163 cs
->irq_func
= &elsa_interrupt_ipac
;
1164 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ID
);
1165 printk(KERN_INFO
"Elsa: IPAC version %x\n", val
);
1167 cs
->readisac
= &ReadISAC
;
1168 cs
->writeisac
= &WriteISAC
;
1169 cs
->readisacfifo
= &ReadISACfifo
;
1170 cs
->writeisacfifo
= &WriteISACfifo
;
1171 cs
->irq_func
= &elsa_interrupt
;
1172 ISACVersion(cs
, "Elsa:");
1173 if (HscxVersion(cs
, "Elsa:")) {
1175 "Elsa: wrong HSCX versions check IO address\n");
1176 release_io_elsa(cs
);
1180 if (cs
->subtyp
== ELSA_PC
) {
1181 val
= readitac(cs
, ITAC_SYS
);
1182 printk(KERN_INFO
"Elsa: ITAC version %s\n", ITACVer
[val
& 7]);
1183 writeitac(cs
, ITAC_ISEN
, 0);
1184 writeitac(cs
, ITAC_RFIE
, 0);
1185 writeitac(cs
, ITAC_XFIE
, 0);
1186 writeitac(cs
, ITAC_SCIE
, 0);
1187 writeitac(cs
, ITAC_STIE
, 0);