1 /* $Id: elsa.c,v 2.12 1998/11/15 23:54:35 keil Exp $
3 * elsa.c low level stuff for Elsa isdn cards
5 * Author Karsten Keil (keil@isdn4linux.de)
7 * This file is (c) under GNU PUBLIC LICENSE
8 * For changes and modifications please read
9 * ../../../Documentation/isdn/HiSax.cert
11 * Thanks to Elsa GmbH for documents and informations
13 * Klaus Lichtenwalder (Klaus.Lichtenwalder@WebForum.DE)
14 * for ELSA PCMCIA support
18 * Revision 2.12 1998/11/15 23:54:35 keil
21 * Revision 2.11 1998/08/20 13:50:34 keil
22 * More support for hybrid modem (not working yet)
24 * Revision 2.10 1998/08/13 23:36:22 keil
25 * HiSax 3.1 - don't work stable with current LinkLevel
27 * Revision 2.9 1998/05/25 12:57:48 keil
28 * HiSax golden code from certification, Don't use !!!
29 * No leased lines, no X75, but many changes.
31 * Revision 2.8 1998/04/15 16:41:42 keil
34 * new PCI init (2.1.94)
36 * Revision 2.7 1998/03/07 22:56:58 tsbogend
37 * made HiSax working on Linux/Alpha
39 * Revision 2.6 1998/02/02 13:29:40 keil
42 * Revision 2.5 1998/01/31 21:41:45 keil
43 * changes for newer 2.1 kernels
45 * Revision 2.4 1997/11/08 21:35:46 keil
48 * Revision 2.3 1997/11/06 17:15:09 keil
49 * New 2.1 init; PCMCIA wrapper changes
51 * Revision 2.2 1997/10/29 18:57:09 keil
52 * changes for 2.1.60, arcofi support
54 * Revision 2.1 1997/07/27 21:47:08 keil
55 * new interface structures
57 * Revision 2.0 1997/06/26 11:02:40 keil
58 * New Layer and card interface
60 * old changes removed KKe
64 #define __NO_VERSION__
65 #include <linux/config.h>
72 #include <linux/pci.h>
75 //#include "../kdebug.h"
77 extern const char *CardType
[];
79 static const char *Elsa_revision
= "$Revision: 2.12 $";
80 const char *Elsa_Types
[] =
81 {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
82 "PCMCIA", "QS 1000", "QS 3000", "QS 1000 PCI", "QS 3000 PCI"};
84 const char *ITACVer
[] =
85 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
88 #define byteout(addr,val) outb(val,addr)
89 #define bytein(addr) inb(addr)
92 #define ELSA_ISAC_PCM 1
96 #define ELSA_ALE_PCM 4
97 #define ELSA_CONTROL 4
99 #define ELSA_START_TIMER 6
100 #define ELSA_TRIG_IRQ 7
106 #define ELSA_PCFPRO 5
107 #define ELSA_PCMCIA 6
108 #define ELSA_QS1000 7
109 #define ELSA_QS3000 8
110 #define ELSA_QS1000PCI 9
111 #define ELSA_QS3000PCI 10
114 #define PCI_VENDOR_ELSA 0x1048
115 #define PCI_QS1000_ID 0x1000
116 #define PCI_QS3000_ID 0x3000
117 #define ELSA_PCI_IRQ_MASK 0x04
119 /* ITAC Registeradressen (only Microlink PC) */
120 #define ITAC_SYS 0x34
121 #define ITAC_ISEN 0x48
122 #define ITAC_RFIE 0x4A
123 #define ITAC_XFIE 0x4C
124 #define ITAC_SCIE 0x4E
125 #define ITAC_STIE 0x46
128 *** Makros als Befehle fuer die Kartenregister ***
129 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
132 /* Config-Register (Read) */
133 #define ELSA_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
134 #define ELSA_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
135 #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
136 #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
137 #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
139 /* Control-Register (Write) */
140 #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
141 #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
142 #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
143 #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
145 /* ALE-Register (Read) */
146 #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
147 #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
150 #define ELSA_TIMER_AKTIV 1
151 #define ELSA_BAD_PWR 2
152 #define ELSA_ASSIGN 4
154 #define RS_ISR_PASS_LIMIT 256
155 #define _INLINE_ inline
156 #define FLG_MODEM_ACTIVE 1
158 #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
159 #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
161 const u_char ARCOFI_VERSION
[] = {2,0xa0,0};
162 const u_char ARCOFI_COP_5
[] = {4,0xa1,0x25,0xbb,0x4a}; /* GTX */
163 const u_char ARCOFI_COP_6
[] = {6,0xa1,0x26,0,0,0x82,0x7c}; /* GRL GRH */
164 const u_char ARCOFI_COP_7
[] = {4,0xa1,0x27,0x80,0x80}; /* GZ */
165 const u_char ARCOFI_COP_8
[] = {10,0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}; /* TX */
166 const u_char ARCOFI_COP_9
[] = {10,0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}; /* RX */
167 const u_char ARCOFI_XOP_0
[] = {2,0xa1,0x30}; /* PWR Down */
168 const u_char ARCOFI_XOP_1
[] = {2,0xa1,0x31}; /* PWR UP */
169 const u_char ARCOFI_XOP_F
[] = {2,0xa1,0x3f}; /* Normal OP */
170 const u_char ARCOFI_SOP_F
[] = {10,0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12};
172 static void set_arcofi(struct IsdnCardState
*cs
, int bc
);
175 #include "elsa_ser.c"
179 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
188 restore_flags(flags
);
193 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
195 /* fifo read without cli because it's allready done */
198 insb(adr
, data
, size
);
203 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
211 restore_flags(flags
);
215 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
217 /* fifo write without cli because it's allready done */
219 outsb(adr
, data
, size
);
222 /* Interface functions */
225 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
227 return (readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
));
231 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
233 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
, value
);
237 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
239 readfifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0, data
, size
);
243 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
245 writefifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0, data
, size
);
249 ReadISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
)
251 return (readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
+0x80));
255 WriteISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
257 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, offset
|0x80, value
);
261 ReadISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
263 readfifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0x80, data
, size
);
267 WriteISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
269 writefifo(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, 0x80, data
, size
);
273 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
275 return (readreg(cs
->hw
.elsa
.ale
,
276 cs
->hw
.elsa
.hscx
, offset
+ (hscx
? 0x40 : 0)));
280 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
282 writereg(cs
->hw
.elsa
.ale
,
283 cs
->hw
.elsa
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
287 readitac(struct IsdnCardState
*cs
, u_char off
)
294 byteout(cs
->hw
.elsa
.ale
, off
);
295 ret
= bytein(cs
->hw
.elsa
.itac
);
296 restore_flags(flags
);
301 writeitac(struct IsdnCardState
*cs
, u_char off
, u_char data
)
307 byteout(cs
->hw
.elsa
.ale
, off
);
308 byteout(cs
->hw
.elsa
.itac
, data
);
309 restore_flags(flags
);
313 TimerRun(struct IsdnCardState
*cs
)
317 v
= bytein(cs
->hw
.elsa
.cfg
);
318 if ((cs
->subtyp
== ELSA_QS1000
) || (cs
->subtyp
== ELSA_QS3000
))
319 return (0 == (v
& ELSA_TIMER_RUN
));
320 else if (cs
->subtyp
== ELSA_PCC8
)
321 return (v
& ELSA_TIMER_RUN_PCC8
);
322 return (v
& ELSA_TIMER_RUN
);
325 * fast interrupt HSCX stuff goes here
328 #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
329 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
330 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
331 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
333 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
334 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
336 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
337 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
339 #include "hscx_irq.c"
342 elsa_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
344 struct IsdnCardState
*cs
= dev_id
;
349 printk(KERN_WARNING
"Elsa: Spurious interrupt!\n");
352 if ((cs
->typ
== ISDN_CTYPE_ELSA_PCMCIA
) && (*cs
->busy_flag
== 1)) {
353 /* The card tends to generate interrupts while being removed
354 causing us to just crash the kernel. bad. */
355 printk(KERN_WARNING
"Elsa: card not available!\n");
359 if (cs
->hw
.elsa
.MFlag
) {
360 val
= serial_inp(cs
, UART_IIR
);
361 if (!(val
& UART_IIR_NO_INT
)) {
362 debugl1(cs
,"IIR %02x", val
);
363 rs_interrupt_elsa(intno
, cs
);
367 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_ISTA
+ 0x40);
370 hscx_int_main(cs
, val
);
372 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_ISTA
);
375 isac_interrupt(cs
, val
);
377 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_ISTA
+ 0x40);
379 if (cs
->debug
& L1_DEB_HSCX
)
380 debugl1(cs
, "HSCX IntStat after IntRoutine");
384 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_ISTA
);
386 if (cs
->debug
& L1_DEB_ISAC
)
387 debugl1(cs
, "ISAC IntStat after IntRoutine");
392 printk(KERN_WARNING
"ELSA IRQ LOOP\n");
393 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
, 0xFF);
394 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
395 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_MASK
, 0xFF);
396 if (cs
->hw
.elsa
.status
& ELSA_TIMER_AKTIV
) {
399 byteout(cs
->hw
.elsa
.timer
, 0);
400 cs
->hw
.elsa
.counter
++;
403 if (cs
->hw
.elsa
.MFlag
) {
404 val
= serial_inp(cs
, UART_MCR
);
406 serial_outp(cs
, UART_MCR
, val
);
407 val
= serial_inp(cs
, UART_MCR
);
409 serial_outp(cs
, UART_MCR
, val
);
411 if (cs
->hw
.elsa
.trig
)
412 byteout(cs
->hw
.elsa
.trig
, 0x00);
413 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
, 0x0);
414 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_MASK
+ 0x40, 0x0);
415 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_MASK
, 0x0);
419 elsa_interrupt_ipac(int intno
, void *dev_id
, struct pt_regs
*regs
)
421 struct IsdnCardState
*cs
= dev_id
;
426 printk(KERN_WARNING
"Elsa: Spurious interrupt!\n");
429 val
= bytein(cs
->hw
.elsa
.cfg
+ 0x4c); /* PCI IRQ */
430 if (!(val
& ELSA_PCI_IRQ_MASK
))
433 if (cs
->hw
.elsa
.MFlag
) {
434 val
= serial_inp(cs
, UART_IIR
);
435 if (!(val
& UART_IIR_NO_INT
)) {
436 debugl1(cs
,"IIR %02x", val
);
437 rs_interrupt_elsa(intno
, cs
);
441 ista
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ISTA
);
443 if (cs
->debug
& L1_DEB_IPAC
)
444 debugl1(cs
, "IPAC ISTA %02X", ista
);
446 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.hscx
, HSCX_ISTA
+ 0x40);
454 hscx_int_main(cs
, val
);
457 val
= 0xfe & readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, ISAC_ISTA
+ 0x80);
459 isac_interrupt(cs
, val
);
464 isac_interrupt(cs
, val
);
466 ista
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ISTA
);
467 if ((ista
& 0x3f) && icnt
) {
472 printk(KERN_WARNING
"ELSA IRQ LOOP\n");
473 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xFF);
474 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xC0);
478 release_io_elsa(struct IsdnCardState
*cs
)
482 del_timer(&cs
->hw
.elsa
.tl
);
483 if (cs
->hw
.elsa
.ctrl
)
484 byteout(cs
->hw
.elsa
.ctrl
, 0); /* LEDs Out */
485 if (cs
->subtyp
== ELSA_QS1000PCI
) {
486 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x01); /* disable IRQ */
487 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
489 release_region(cs
->hw
.elsa
.cfg
, 0x80);
491 if (cs
->subtyp
== ELSA_QS3000PCI
) {
492 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x03); /* disable ELSA PCI IRQ */
493 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
494 release_region(cs
->hw
.elsa
.cfg
, 0x80);
496 if ((cs
->subtyp
== ELSA_PCFPRO
) ||
497 (cs
->subtyp
== ELSA_QS3000
) ||
498 (cs
->subtyp
== ELSA_PCF
) ||
499 (cs
->subtyp
== ELSA_QS3000PCI
)) {
503 if (cs
->hw
.elsa
.base
)
504 release_region(cs
->hw
.elsa
.base
, bytecnt
);
508 reset_elsa(struct IsdnCardState
*cs
)
512 if (cs
->hw
.elsa
.timer
) {
514 byteout(cs
->hw
.elsa
.timer
, 0);
515 while (TimerRun(cs
));
516 cs
->hw
.elsa
.ctrl_reg
|= 0x50;
517 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_ISDN_RESET
; /* Reset On */
518 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
520 byteout(cs
->hw
.elsa
.timer
, 0);
521 while (TimerRun(cs
));
522 cs
->hw
.elsa
.ctrl_reg
|= ELSA_ISDN_RESET
; /* Reset Off */
523 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
525 byteout(cs
->hw
.elsa
.timer
, 0);
526 while (TimerRun(cs
));
527 if (cs
->hw
.elsa
.trig
)
528 byteout(cs
->hw
.elsa
.trig
, 0xff);
530 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
)) {
533 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_POTA2
, 0x20);
534 current
->state
= TASK_INTERRUPTIBLE
;
535 schedule_timeout((10*HZ
)/1000); /* Timeout 10ms */
536 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_POTA2
, 0x00);
537 current
->state
= TASK_INTERRUPTIBLE
;
538 schedule_timeout((10*HZ
)/1000); /* Timeout 10ms */
539 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xc0);
540 restore_flags(flags
);
541 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ACFG
, 0x0);
542 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_AOE
, 0x3c);
543 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
544 if (cs
->subtyp
== ELSA_QS1000PCI
)
545 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x41); /* enable ELSA PCI IRQ */
546 else if (cs
->subtyp
== ELSA_QS3000PCI
)
547 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x43); /* enable ELSA PCI IRQ */
552 init_arcofi(struct IsdnCardState
*cs
) {
553 send_arcofi(cs
, ARCOFI_XOP_0
, 1, 0);
554 /* send_arcofi(cs, ARCOFI_XOP_F, 1);
561 set_arcofi(struct IsdnCardState
*cs
, int bc
) {
564 debugl1(cs
,"set_arcofi bc=%d", bc
);
567 send_arcofi(cs
, ARCOFI_XOP_0
, bc
, 0);
569 send_arcofi(cs
, ARCOFI_COP_5
, bc
, 0);
571 send_arcofi(cs
, ARCOFI_COP_6
, bc
, 0);
573 send_arcofi(cs
, ARCOFI_COP_7
, bc
, 0);
575 send_arcofi(cs
, ARCOFI_COP_8
, bc
, 0);
577 send_arcofi(cs
, ARCOFI_COP_9
, bc
, 0);
579 send_arcofi(cs
, ARCOFI_SOP_F
, bc
, 0);
581 send_arcofi(cs
, ARCOFI_XOP_1
, bc
, 0);
583 send_arcofi(cs
, ARCOFI_XOP_F
, bc
, 0);
584 restore_flags(flags
);
585 debugl1(cs
,"end set_arcofi bc=%d", bc
);
589 check_arcofi(struct IsdnCardState
*cs
)
592 int arcofi_present
= 0;
598 if (!(cs
->mon_tx
=kmalloc(MAX_MON_FRAME
, GFP_ATOMIC
))) {
599 if (cs
->debug
& L1_DEB_WARN
)
600 debugl1(cs
, "ISAC MON TX out of buffers!");
603 send_arcofi(cs
, ARCOFI_VERSION
, 0, 1);
604 if (test_and_clear_bit(HW_MON1_TX_END
, &cs
->HW_Flags
)) {
605 if (test_and_clear_bit(HW_MON1_RX_END
, &cs
->HW_Flags
)) {
606 debugl1(cs
, "Arcofi response received %d bytes", cs
->mon_rxp
);
609 t
+= sprintf(tmp
, "Arcofi data");
610 QuickHex(t
, p
, cs
->mon_rxp
);
612 if ((cs
->mon_rxp
== 2) && (cs
->mon_rx
[0] == 0xa0)) {
613 switch(cs
->mon_rx
[1]) {
615 debugl1(cs
, "Arcofi 2160 detected");
619 debugl1(cs
, "Arcofi 2165 detected");
623 debugl1(cs
, "Arcofi 2163 detected");
627 debugl1(cs
, "unknown Arcofi response");
631 debugl1(cs
, "undefined Monitor response");
634 } else if (cs
->mon_tx
) {
635 debugl1(cs
, "Arcofi not detected");
637 if (arcofi_present
) {
638 if (cs
->subtyp
==ELSA_QS1000
) {
639 cs
->subtyp
= ELSA_QS3000
;
641 "Elsa: %s detected modem at 0x%x\n",
642 Elsa_Types
[cs
->subtyp
],
644 release_region(cs
->hw
.elsa
.base
, 8);
645 if (check_region(cs
->hw
.elsa
.base
, 16)) {
647 "HiSax: %s config port %x-%x already in use\n",
648 Elsa_Types
[cs
->subtyp
],
649 cs
->hw
.elsa
.base
+ 8,
650 cs
->hw
.elsa
.base
+ 16);
652 request_region(cs
->hw
.elsa
.base
, 16,
654 } else if (cs
->subtyp
==ELSA_PCC16
) {
655 cs
->subtyp
= ELSA_PCF
;
657 "Elsa: %s detected modem at 0x%x\n",
658 Elsa_Types
[cs
->subtyp
],
660 release_region(cs
->hw
.elsa
.base
, 8);
661 if (check_region(cs
->hw
.elsa
.base
, 16)) {
663 "HiSax: %s config port %x-%x already in use\n",
664 Elsa_Types
[cs
->subtyp
],
665 cs
->hw
.elsa
.base
+ 8,
666 cs
->hw
.elsa
.base
+ 16);
668 request_region(cs
->hw
.elsa
.base
, 16,
672 "Elsa: %s detected modem at 0x%x\n",
673 Elsa_Types
[cs
->subtyp
],
683 elsa_led_handler(struct IsdnCardState
*cs
)
687 if (cs
->subtyp
== ELSA_PCMCIA
)
689 del_timer(&cs
->hw
.elsa
.tl
);
690 if (cs
->hw
.elsa
.status
& ELSA_ASSIGN
)
691 cs
->hw
.elsa
.ctrl_reg
|= ELSA_STAT_LED
;
692 else if (cs
->hw
.elsa
.status
& ELSA_BAD_PWR
)
693 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_STAT_LED
;
695 cs
->hw
.elsa
.ctrl_reg
^= ELSA_STAT_LED
;
698 if (cs
->hw
.elsa
.status
& 0xf000)
699 cs
->hw
.elsa
.ctrl_reg
|= ELSA_LINE_LED
;
700 else if (cs
->hw
.elsa
.status
& 0x0f00) {
701 cs
->hw
.elsa
.ctrl_reg
^= ELSA_LINE_LED
;
704 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_LINE_LED
;
706 if ((cs
->subtyp
== ELSA_QS1000PCI
) ||
707 (cs
->subtyp
== ELSA_QS3000PCI
)) {
709 if (cs
->hw
.elsa
.ctrl_reg
& ELSA_LINE_LED
)
710 led
^= ELSA_IPAC_LINE_LED
;
711 if (cs
->hw
.elsa
.ctrl_reg
& ELSA_STAT_LED
)
712 led
^= ELSA_IPAC_STAT_LED
;
713 writereg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ATX
, led
);
715 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
717 init_timer(&cs
->hw
.elsa
.tl
);
718 cs
->hw
.elsa
.tl
.expires
= jiffies
+ ((blink
* HZ
) / 1000);
719 add_timer(&cs
->hw
.elsa
.tl
);
724 Elsa_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
738 if ((cs
->subtyp
== ELSA_QS1000PCI
) ||
739 (cs
->subtyp
== ELSA_QS3000PCI
))
740 ret
= request_irq(cs
->irq
, &elsa_interrupt_ipac
,
741 I4L_IRQ_FLAG
| SA_SHIRQ
, "HiSax", cs
);
743 ret
= request_irq(cs
->irq
, &elsa_interrupt
,
744 I4L_IRQ_FLAG
, "HiSax", cs
);
747 cs
->debug
|= L1_DEB_IPAC
;
749 if ((cs
->subtyp
== ELSA_QS1000
) ||
750 (cs
->subtyp
== ELSA_QS3000
))
752 byteout(cs
->hw
.elsa
.timer
, 0);
754 if (cs
->hw
.elsa
.trig
)
755 byteout(cs
->hw
.elsa
.trig
, 0xff);
759 if ((cs
->subtyp
== ELSA_PCMCIA
) ||
760 (cs
->subtyp
== ELSA_QS1000PCI
)) {
762 } else if (cs
->subtyp
== ELSA_QS3000PCI
) {
766 cs
->hw
.elsa
.counter
= 0;
768 cs
->hw
.elsa
.ctrl_reg
|= ELSA_ENA_TIMER_INT
;
769 cs
->hw
.elsa
.status
|= ELSA_TIMER_AKTIV
;
770 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
771 byteout(cs
->hw
.elsa
.timer
, 0);
772 current
->state
= TASK_INTERRUPTIBLE
;
774 schedule_timeout((110*HZ
)/1000);
775 restore_flags(flags
);
776 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_ENA_TIMER_INT
;
777 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
778 cs
->hw
.elsa
.status
&= ~ELSA_TIMER_AKTIV
;
779 printk(KERN_INFO
"Elsa: %d timer tics in 110 msek\n",
780 cs
->hw
.elsa
.counter
);
781 if (abs(cs
->hw
.elsa
.counter
- 13) < 3) {
782 printk(KERN_INFO
"Elsa: timer and irq OK\n");
786 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
787 cs
->hw
.elsa
.counter
, cs
->irq
);
792 if (check_arcofi(cs
)) {
796 elsa_led_handler(cs
);
798 case (MDL_REMOVE
| REQUEST
):
799 cs
->hw
.elsa
.status
&= 0;
801 case (MDL_ASSIGN
| REQUEST
):
802 cs
->hw
.elsa
.status
|= ELSA_ASSIGN
;
806 cs
->hw
.elsa
.status
|= 0x0200;
808 cs
->hw
.elsa
.status
|= 0x0100;
812 cs
->hw
.elsa
.status
|= 0x2000;
814 cs
->hw
.elsa
.status
|= 0x1000;
818 cs
->hw
.elsa
.status
&= ~0x2000;
819 cs
->hw
.elsa
.status
&= ~0x0200;
821 cs
->hw
.elsa
.status
&= ~0x1000;
822 cs
->hw
.elsa
.status
&= ~0x0100;
826 if (cs
->hw
.elsa
.MFlag
) {
832 modem_write_cmd(cs
, msg
, len
);
836 if (cs
->typ
== ISDN_CTYPE_ELSA
) {
837 int pwr
= bytein(cs
->hw
.elsa
.ale
);
839 cs
->hw
.elsa
.status
|= ELSA_BAD_PWR
;
841 cs
->hw
.elsa
.status
&= ~ELSA_BAD_PWR
;
843 elsa_led_handler(cs
);
848 probe_elsa_adr(unsigned int adr
, int typ
)
850 int i
, in1
, in2
, p16_1
= 0, p16_2
= 0, p8_1
= 0, p8_2
= 0, pc_1
= 0,
851 pc_2
= 0, pfp_1
= 0, pfp_2
= 0;
854 /* In case of the elsa pcmcia card, this region is in use,
855 reserved for us by the card manager. So we do not check it
856 here, it would fail. */
857 if (typ
!= ISDN_CTYPE_ELSA_PCMCIA
&& check_region(adr
, 8)) {
859 "Elsa: Probing Port 0x%x: already in use\n",
865 for (i
= 0; i
< 16; i
++) {
866 in1
= inb(adr
+ ELSA_CONFIG
); /* 'toggelt' bei */
867 in2
= inb(adr
+ ELSA_CONFIG
); /* jedem Zugriff */
877 restore_flags(flags
);
878 printk(KERN_INFO
"Elsa: Probing IO 0x%x", adr
);
879 if (65 == ++p16_1
* ++p16_2
) {
880 printk(" PCC-16/PCF found\n");
882 } else if (1025 == ++pfp_1
* ++pfp_2
) {
883 printk(" PCF-Pro found\n");
884 return (ELSA_PCFPRO
);
885 } else if (33 == ++p8_1
* ++p8_2
) {
886 printk(" PCC8 found\n");
888 } else if (17 == ++pc_1
* ++pc_2
) {
889 printk(" PC found\n");
898 probe_elsa(struct IsdnCardState
*cs
)
901 unsigned int CARD_portlist
[] =
902 {0x160, 0x170, 0x260, 0x360, 0};
904 for (i
= 0; CARD_portlist
[i
]; i
++) {
905 if ((cs
->subtyp
= probe_elsa_adr(CARD_portlist
[i
], cs
->typ
)))
908 return (CARD_portlist
[i
]);
911 static struct pci_dev
*dev_qs1000 __initdata
= NULL
;
912 static struct pci_dev
*dev_qs3000 __initdata
= NULL
;
915 setup_elsa(struct IsdnCard
*card
)
920 struct IsdnCardState
*cs
= card
->cs
;
923 strcpy(tmp
, Elsa_revision
);
924 printk(KERN_INFO
"HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp
));
925 cs
->hw
.elsa
.ctrl_reg
= 0;
926 cs
->hw
.elsa
.status
= 0;
927 cs
->hw
.elsa
.MFlag
= 0;
928 if (cs
->typ
== ISDN_CTYPE_ELSA
) {
929 cs
->hw
.elsa
.base
= card
->para
[0];
930 printk(KERN_INFO
"Elsa: Microlink IO probing\n");
931 if (cs
->hw
.elsa
.base
) {
932 if (!(cs
->subtyp
= probe_elsa_adr(cs
->hw
.elsa
.base
,
935 "Elsa: no Elsa Microlink at 0x%x\n",
940 cs
->hw
.elsa
.base
= probe_elsa(cs
);
941 if (cs
->hw
.elsa
.base
) {
942 cs
->hw
.elsa
.cfg
= cs
->hw
.elsa
.base
+ ELSA_CONFIG
;
943 cs
->hw
.elsa
.ctrl
= cs
->hw
.elsa
.base
+ ELSA_CONTROL
;
944 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE
;
945 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC
;
946 cs
->hw
.elsa
.itac
= cs
->hw
.elsa
.base
+ ELSA_ITAC
;
947 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
948 cs
->hw
.elsa
.trig
= cs
->hw
.elsa
.base
+ ELSA_TRIG_IRQ
;
949 cs
->hw
.elsa
.timer
= cs
->hw
.elsa
.base
+ ELSA_START_TIMER
;
950 val
= bytein(cs
->hw
.elsa
.cfg
);
951 if (cs
->subtyp
== ELSA_PC
) {
952 const u_char CARD_IrqTab
[8] =
953 {7, 3, 5, 9, 0, 0, 0, 0};
954 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX_PC
) >> 2];
955 } else if (cs
->subtyp
== ELSA_PCC8
) {
956 const u_char CARD_IrqTab
[8] =
957 {7, 3, 5, 9, 0, 0, 0, 0};
958 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX_PCC8
) >> 4];
960 const u_char CARD_IrqTab
[8] =
961 {15, 10, 15, 3, 11, 5, 11, 9};
962 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX
) >> 3];
964 val
= bytein(cs
->hw
.elsa
.ale
) & ELSA_HW_RELEASE
;
968 if (val
== 'B' || val
== 'C')
970 if ((cs
->subtyp
== ELSA_PCFPRO
) && (val
= 'G'))
973 "Elsa: %s found at 0x%x Rev.:%c IRQ %d\n",
974 Elsa_Types
[cs
->subtyp
],
977 val
= bytein(cs
->hw
.elsa
.ale
) & ELSA_S0_POWER_BAD
;
980 "Elsa: Microlink S0 bus power bad\n");
981 cs
->hw
.elsa
.status
|= ELSA_BAD_PWR
;
985 "No Elsa Microlink found\n");
988 } else if (cs
->typ
== ISDN_CTYPE_ELSA_PNP
) {
989 cs
->hw
.elsa
.base
= card
->para
[1];
990 cs
->irq
= card
->para
[0];
991 cs
->subtyp
= ELSA_QS1000
;
992 cs
->hw
.elsa
.cfg
= cs
->hw
.elsa
.base
+ ELSA_CONFIG
;
993 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE
;
994 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC
;
995 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
996 cs
->hw
.elsa
.trig
= cs
->hw
.elsa
.base
+ ELSA_TRIG_IRQ
;
997 cs
->hw
.elsa
.timer
= cs
->hw
.elsa
.base
+ ELSA_START_TIMER
;
998 cs
->hw
.elsa
.ctrl
= cs
->hw
.elsa
.base
+ ELSA_CONTROL
;
1000 "Elsa: %s defined at 0x%x IRQ %d\n",
1001 Elsa_Types
[cs
->subtyp
],
1004 } else if (cs
->typ
== ISDN_CTYPE_ELSA_PCMCIA
) {
1005 cs
->hw
.elsa
.base
= card
->para
[1];
1006 cs
->irq
= card
->para
[0];
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
;
1011 cs
->hw
.elsa
.timer
= 0;
1012 cs
->hw
.elsa
.trig
= 0;
1013 cs
->hw
.elsa
.ctrl
= 0;
1015 "Elsa: %s defined at 0x%x IRQ %d\n",
1016 Elsa_Types
[cs
->subtyp
],
1019 } else if (cs
->typ
== ISDN_CTYPE_ELSA_PCI
) {
1021 if (!pci_present()) {
1022 printk(KERN_ERR
"Elsa: no PCI bus present\n");
1026 if ((dev_qs1000
= pci_find_device(PCI_VENDOR_ELSA
, PCI_QS1000_ID
,
1028 cs
->subtyp
= ELSA_QS1000PCI
;
1029 cs
->irq
= dev_qs1000
->irq
;
1030 cs
->hw
.elsa
.cfg
= dev_qs1000
->base_address
[1] &
1031 PCI_BASE_ADDRESS_IO_MASK
;
1032 cs
->hw
.elsa
.base
= dev_qs1000
->base_address
[3] &
1033 PCI_BASE_ADDRESS_IO_MASK
;
1034 } else if ((dev_qs3000
= pci_find_device(PCI_VENDOR_ELSA
,
1035 PCI_QS3000_ID
, dev_qs3000
))) {
1036 cs
->subtyp
= ELSA_QS3000PCI
;
1037 cs
->irq
= dev_qs3000
->irq
;
1038 cs
->hw
.elsa
.cfg
= dev_qs3000
->base_address
[1] &
1039 PCI_BASE_ADDRESS_IO_MASK
;
1040 cs
->hw
.elsa
.base
= dev_qs3000
->base_address
[3] &
1041 PCI_BASE_ADDRESS_IO_MASK
;
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 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
;
1056 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+1;
1057 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+1;
1058 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
1059 cs
->hw
.elsa
.timer
= 0;
1060 cs
->hw
.elsa
.trig
= 0;
1062 "Elsa: %s defined at 0x%x/0x%x IRQ %d\n",
1063 Elsa_Types
[cs
->subtyp
],
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");
1071 printk(KERN_WARNING
"Elsa: Waiting 5 sec to sync discs\n");
1074 HZDELAY(500); /* wait 500*10 ms */
1075 restore_flags(flags
);
1078 printk(KERN_WARNING
"Elsa: Elsa PCI and NO_PCI_BIOS\n");
1079 printk(KERN_WARNING
"Elsa: unable to config Elsa PCI\n");
1081 #endif /* CONFIG_PCI */
1085 switch (cs
->subtyp
) {
1095 case ELSA_QS3000PCI
:
1098 case ELSA_QS1000PCI
:
1103 "Unknown ELSA subtype %d\n", cs
->subtyp
);
1106 /* In case of the elsa pcmcia card, this region is in use,
1107 reserved for us by the card manager. So we do not check it
1108 here, it would fail. */
1109 if (cs
->typ
!= ISDN_CTYPE_ELSA_PCMCIA
&& check_region(cs
->hw
.elsa
.base
, bytecnt
)) {
1111 "HiSax: %s config port %x-%x already in use\n",
1112 CardType
[card
->typ
],
1114 cs
->hw
.elsa
.base
+ bytecnt
);
1117 request_region(cs
->hw
.elsa
.base
, bytecnt
, "elsa isdn");
1119 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
)) {
1120 if (check_region(cs
->hw
.elsa
.cfg
, 0x80)) {
1122 "HiSax: %s pci port %x-%x already in use\n",
1123 CardType
[card
->typ
],
1125 cs
->hw
.elsa
.cfg
+ 0x80);
1126 release_region(cs
->hw
.elsa
.base
, bytecnt
);
1129 request_region(cs
->hw
.elsa
.cfg
, 0x80, "elsa isdn pci");
1132 cs
->hw
.elsa
.tl
.function
= (void *) elsa_led_handler
;
1133 cs
->hw
.elsa
.tl
.data
= (long) cs
;
1134 init_timer(&cs
->hw
.elsa
.tl
);
1136 if (cs
->hw
.elsa
.timer
) {
1137 byteout(cs
->hw
.elsa
.trig
, 0xff);
1138 byteout(cs
->hw
.elsa
.timer
, 0);
1139 if (!TimerRun(cs
)) {
1140 byteout(cs
->hw
.elsa
.timer
, 0); /* 2. Versuch */
1141 if (!TimerRun(cs
)) {
1143 "Elsa: timer do not start\n");
1144 release_io_elsa(cs
);
1150 HZDELAY(1); /* wait >=10 ms */
1151 restore_flags(flags
);
1153 printk(KERN_WARNING
"Elsa: timer do not run down\n");
1154 release_io_elsa(cs
);
1157 printk(KERN_INFO
"Elsa: timer OK; resetting card\n");
1159 cs
->BC_Read_Reg
= &ReadHSCX
;
1160 cs
->BC_Write_Reg
= &WriteHSCX
;
1161 cs
->BC_Send_Data
= &hscx_fill_fifo
;
1162 cs
->cardmsg
= &Elsa_card_msg
;
1164 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
)) {
1165 cs
->readisac
= &ReadISAC_IPAC
;
1166 cs
->writeisac
= &WriteISAC_IPAC
;
1167 cs
->readisacfifo
= &ReadISACfifo_IPAC
;
1168 cs
->writeisacfifo
= &WriteISACfifo_IPAC
;
1169 val
= readreg(cs
->hw
.elsa
.ale
, cs
->hw
.elsa
.isac
, IPAC_ID
);
1170 printk(KERN_INFO
"Elsa: IPAC version %x\n", val
);
1172 cs
->readisac
= &ReadISAC
;
1173 cs
->writeisac
= &WriteISAC
;
1174 cs
->readisacfifo
= &ReadISACfifo
;
1175 cs
->writeisacfifo
= &WriteISACfifo
;
1176 ISACVersion(cs
, "Elsa:");
1177 if (HscxVersion(cs
, "Elsa:")) {
1179 "Elsa: wrong HSCX versions check IO address\n");
1180 release_io_elsa(cs
);
1184 if (cs
->subtyp
== ELSA_PC
) {
1185 val
= readitac(cs
, ITAC_SYS
);
1186 printk(KERN_INFO
"Elsa: ITAC version %s\n", ITACVer
[val
& 7]);
1187 writeitac(cs
, ITAC_ISEN
, 0);
1188 writeitac(cs
, ITAC_RFIE
, 0);
1189 writeitac(cs
, ITAC_XFIE
, 0);
1190 writeitac(cs
, ITAC_SCIE
, 0);
1191 writeitac(cs
, ITAC_STIE
, 0);