1 /* $Id: elsa.c,v 2.26.6.6 2001/09/23 22:24:47 kai 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
[];
35 static spinlock_t elsa_lock
= SPIN_LOCK_UNLOCKED
;
37 const char *Elsa_revision
= "$Revision: 2.26.6.6 $";
38 const char *Elsa_Types
[] =
39 {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
40 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
43 const char *ITACVer
[] =
44 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
47 #define byteout(addr,val) outb(val,addr)
48 #define bytein(addr) inb(addr)
51 #define ELSA_ISAC_PCM 1
55 #define ELSA_ALE_PCM 4
56 #define ELSA_CONTROL 4
58 #define ELSA_START_TIMER 6
59 #define ELSA_TRIG_IRQ 7
69 #define ELSA_QS1000PCI 9
70 #define ELSA_QS3000PCI 10
71 #define ELSA_PCMCIA_IPAC 11
74 #define ELSA_PCI_IRQ_MASK 0x04
76 /* ITAC Registeradressen (only Microlink PC) */
78 #define ITAC_ISEN 0x48
79 #define ITAC_RFIE 0x4A
80 #define ITAC_XFIE 0x4C
81 #define ITAC_SCIE 0x4E
82 #define ITAC_STIE 0x46
85 *** Makros als Befehle fuer die Kartenregister ***
86 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
89 /* Config-Register (Read) */
90 #define ELSA_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
91 #define ELSA_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
92 #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
93 #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
94 #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
96 /* Control-Register (Write) */
97 #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
98 #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
99 #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
100 #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
102 /* ALE-Register (Read) */
103 #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
104 #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
107 #define ELSA_TIMER_AKTIV 1
108 #define ELSA_BAD_PWR 2
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(struct IsdnCardState
*cs
, unsigned int adr
, u8 off
)
150 spin_lock_irqsave(&elsa_lock
, flags
);
151 byteout(cs
->hw
.elsa
.ale
, off
);
153 spin_unlock_irqrestore(&elsa_lock
, flags
);
158 writereg(struct IsdnCardState
*cs
, unsigned int adr
, u8 off
, u8 data
)
162 spin_lock_irqsave(&elsa_lock
, flags
);
163 byteout(cs
->hw
.elsa
.ale
, off
);
165 spin_unlock_irqrestore(&elsa_lock
, flags
);
169 readfifo(struct IsdnCardState
*cs
, unsigned int adr
, u8 off
, u8
* data
, int size
)
171 byteout(cs
->hw
.elsa
.ale
, off
);
172 insb(adr
, data
, size
);
176 writefifo(struct IsdnCardState
*cs
, unsigned int adr
, u8 off
, u8
* data
, int size
)
178 byteout(cs
->hw
.elsa
.ale
, off
);
179 outsb(adr
, data
, size
);
183 isac_read(struct IsdnCardState
*cs
, u8 offset
)
185 return readreg(cs
, cs
->hw
.elsa
.isac
, offset
);
189 isac_write(struct IsdnCardState
*cs
, u8 offset
, u8 value
)
191 writereg(cs
, cs
->hw
.elsa
.isac
, offset
, value
);
195 isac_read_fifo(struct IsdnCardState
*cs
, u8
*data
, int size
)
197 readfifo(cs
, cs
->hw
.elsa
.isac
, 0, data
, size
);
201 isac_write_fifo(struct IsdnCardState
*cs
, u8
*data
, int size
)
203 writefifo(cs
, cs
->hw
.elsa
.isac
, 0, data
, size
);
206 static struct dc_hw_ops isac_ops
= {
207 .read_reg
= isac_read
,
208 .write_reg
= isac_write
,
209 .read_fifo
= isac_read_fifo
,
210 .write_fifo
= isac_write_fifo
,
214 hscx_read(struct IsdnCardState
*cs
, int hscx
, u8 offset
)
216 return readreg(cs
, cs
->hw
.elsa
.hscx
, offset
+ (hscx
? 0x40 : 0));
220 hscx_write(struct IsdnCardState
*cs
, int hscx
, u8 offset
, u8 value
)
222 writereg(cs
, cs
->hw
.elsa
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
226 hscx_read_fifo(struct IsdnCardState
*cs
, int hscx
, u8
*data
, int size
)
228 writefifo(cs
, cs
->hw
.elsa
.hscx
, hscx
? 0x40 : 0, data
, size
);
232 hscx_write_fifo(struct IsdnCardState
*cs
, int hscx
, u8
*data
, int size
)
234 writefifo(cs
, cs
->hw
.elsa
.hscx
, hscx
? 0x40 : 0, data
, size
);
237 static struct bc_hw_ops hscx_ops
= {
238 .read_reg
= hscx_read
,
239 .write_reg
= hscx_write
,
240 .read_fifo
= hscx_read_fifo
,
241 .write_fifo
= hscx_write_fifo
,
245 ipac_read(struct IsdnCardState
*cs
, u8 offset
)
247 return readreg(cs
, cs
->hw
.elsa
.isac
, offset
);
251 ipac_write(struct IsdnCardState
*cs
, u8 offset
, u8 value
)
253 writereg(cs
, cs
->hw
.elsa
.isac
, offset
, value
);
257 ipac_readfifo(struct IsdnCardState
*cs
, u8 offset
, u8
*data
, int size
)
259 readfifo(cs
, cs
->hw
.elsa
.isac
, offset
, data
, size
);
263 ipac_writefifo(struct IsdnCardState
*cs
, u8 offset
, u8
*data
, int size
)
265 writefifo(cs
, cs
->hw
.elsa
.isac
, offset
, data
, size
);
268 /* This will generate ipac_dc_ops and ipac_bc_ops using the functions
271 BUILD_IPAC_OPS(ipac
);
274 readitac(struct IsdnCardState
*cs
, u8 off
)
279 spin_lock_irqsave(&elsa_lock
, flags
);
280 byteout(cs
->hw
.elsa
.ale
, off
);
281 ret
= bytein(cs
->hw
.elsa
.itac
);
282 spin_unlock_irqrestore(&elsa_lock
, flags
);
287 writeitac(struct IsdnCardState
*cs
, u8 off
, u8 data
)
291 spin_lock_irqsave(&elsa_lock
, flags
);
292 byteout(cs
->hw
.elsa
.ale
, off
);
293 byteout(cs
->hw
.elsa
.itac
, data
);
294 spin_unlock_irqrestore(&elsa_lock
, flags
);
298 TimerRun(struct IsdnCardState
*cs
)
302 v
= bytein(cs
->hw
.elsa
.cfg
);
303 if ((cs
->subtyp
== ELSA_QS1000
) || (cs
->subtyp
== ELSA_QS3000
))
304 return (0 == (v
& ELSA_TIMER_RUN
));
305 else if (cs
->subtyp
== ELSA_PCC8
)
306 return (v
& ELSA_TIMER_RUN_PCC8
);
307 return (v
& ELSA_TIMER_RUN
);
311 elsa_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
313 struct IsdnCardState
*cs
= dev_id
;
316 if ((cs
->typ
== ISDN_CTYPE_ELSA_PCMCIA
) && (*cs
->busy_flag
== 1)) {
317 /* The card tends to generate interrupts while being removed
318 causing us to just crash the kernel. bad. */
319 printk(KERN_WARNING
"Elsa: card not available!\n");
323 if (cs
->hw
.elsa
.MFlag
) {
324 val
= serial_inp(cs
, UART_IIR
);
325 if (!(val
& UART_IIR_NO_INT
)) {
326 debugl1(cs
,"IIR %02x", val
);
327 spin_lock(&cs
->lock
);
328 rs_interrupt_elsa(intno
, cs
);
329 spin_unlock(&cs
->lock
);
333 hscxisac_irq(intno
, dev_id
, regs
);
335 if (cs
->hw
.elsa
.status
& ELSA_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);
358 elsa_interrupt_ipac(int intno
, void *dev_id
, struct pt_regs
*regs
)
360 struct IsdnCardState
*cs
= dev_id
;
364 printk(KERN_WARNING
"Elsa: Spurious interrupt!\n");
367 if (cs
->subtyp
== ELSA_QS1000PCI
|| cs
->subtyp
== ELSA_QS3000PCI
) {
368 val
= bytein(cs
->hw
.elsa
.cfg
+ 0x4c); /* PCI IRQ */
369 if (!test_bit(FLG_BUGGY_PLX9050
, &cs
->HW_Flags
) &&
370 !(val
& ELSA_PCI_IRQ_MASK
))
374 if (cs
->hw
.elsa
.MFlag
) {
375 val
= serial_inp(cs
, UART_IIR
);
376 if (!(val
& UART_IIR_NO_INT
)) {
377 debugl1(cs
,"IIR %02x", val
);
378 spin_lock(&cs
->lock
);
379 rs_interrupt_elsa(intno
, cs
);
380 spin_unlock(&cs
->lock
);
384 return ipac_irq(intno
, dev_id
, regs
);
388 elsa_release(struct IsdnCardState
*cs
)
390 del_timer(&cs
->hw
.elsa
.tl
);
394 if (cs
->hw
.elsa
.ctrl
)
395 byteout(cs
->hw
.elsa
.ctrl
, 0); /* LEDs Out */
396 if (cs
->subtyp
== ELSA_QS1000PCI
) {
397 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x01); /* disable IRQ */
398 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
400 if (cs
->subtyp
== ELSA_QS3000PCI
) {
401 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x03); /* disable ELSA PCI IRQ */
402 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
404 if (cs
->subtyp
== ELSA_PCMCIA_IPAC
) {
405 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
408 if ((cs
->subtyp
== ELSA_PCFPRO
) ||
409 (cs
->subtyp
== ELSA_QS3000
) ||
410 (cs
->subtyp
== ELSA_PCF
) ||
411 (cs
->subtyp
== ELSA_QS3000PCI
)) {
415 hisax_release_resources(cs
);
419 elsa_reset(struct IsdnCardState
*cs
)
421 if (cs
->hw
.elsa
.timer
) {
423 byteout(cs
->hw
.elsa
.timer
, 0);
424 while (TimerRun(cs
));
425 cs
->hw
.elsa
.ctrl_reg
|= 0x50;
426 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_ISDN_RESET
; /* Reset On */
427 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
429 byteout(cs
->hw
.elsa
.timer
, 0);
430 while (TimerRun(cs
));
431 cs
->hw
.elsa
.ctrl_reg
|= ELSA_ISDN_RESET
; /* Reset Off */
432 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
434 byteout(cs
->hw
.elsa
.timer
, 0);
435 while (TimerRun(cs
));
436 if (cs
->hw
.elsa
.trig
)
437 byteout(cs
->hw
.elsa
.trig
, 0xff);
439 if ((cs
->subtyp
== ELSA_QS1000PCI
) || (cs
->subtyp
== ELSA_QS3000PCI
) || (cs
->subtyp
== ELSA_PCMCIA_IPAC
)) {
440 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_POTA2
, 0x20);
441 set_current_state(TASK_UNINTERRUPTIBLE
);
442 schedule_timeout((10*HZ
)/1000); /* Timeout 10ms */
443 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_POTA2
, 0x00);
444 set_current_state(TASK_UNINTERRUPTIBLE
);
445 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_MASK
, 0xc0);
446 schedule_timeout((10*HZ
)/1000); /* Timeout 10ms */
447 if (cs
->subtyp
!= ELSA_PCMCIA_IPAC
) {
448 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ACFG
, 0x0);
449 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_AOE
, 0x3c);
451 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_PCFG
, 0x10);
452 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ACFG
, 0x4);
453 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_AOE
, 0xf8);
455 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ATX
, 0xff);
456 if (cs
->subtyp
== ELSA_QS1000PCI
)
457 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x41); /* enable ELSA PCI IRQ */
458 else if (cs
->subtyp
== ELSA_QS3000PCI
)
459 byteout(cs
->hw
.elsa
.cfg
+ 0x4c, 0x43); /* enable ELSA PCI IRQ */
467 set_arcofi(struct IsdnCardState
*cs
, int bc
) {
468 cs
->dc
.isac
.arcofi_bc
= bc
;
469 arcofi_fsm(cs
, ARCOFI_START
, &ARCOFI_COP_5
);
470 interruptible_sleep_on(&cs
->dc
.isac
.arcofi_wait
);
474 check_arcofi(struct IsdnCardState
*cs
)
476 int arcofi_present
= 0;
481 if (!cs
->dc
.isac
.mon_tx
)
482 if (!(cs
->dc
.isac
.mon_tx
=kmalloc(MAX_MON_FRAME
, GFP_ATOMIC
))) {
483 if (cs
->debug
& L1_DEB_WARN
)
484 debugl1(cs
, "ISAC MON TX out of buffers!");
487 cs
->dc
.isac
.arcofi_bc
= 0;
488 arcofi_fsm(cs
, ARCOFI_START
, &ARCOFI_VERSION
);
489 interruptible_sleep_on(&cs
->dc
.isac
.arcofi_wait
);
490 if (!test_and_clear_bit(FLG_ARCOFI_ERROR
, &cs
->HW_Flags
)) {
491 debugl1(cs
, "Arcofi response received %d bytes", cs
->dc
.isac
.mon_rxp
);
492 p
= cs
->dc
.isac
.mon_rx
;
494 t
+= sprintf(tmp
, "Arcofi data");
495 QuickHex(t
, p
, cs
->dc
.isac
.mon_rxp
);
497 if ((cs
->dc
.isac
.mon_rxp
== 2) && (cs
->dc
.isac
.mon_rx
[0] == 0xa0)) {
498 switch(cs
->dc
.isac
.mon_rx
[1]) {
500 debugl1(cs
, "Arcofi 2160 detected");
504 debugl1(cs
, "Arcofi 2165 detected");
508 debugl1(cs
, "Arcofi 2163 detected");
512 debugl1(cs
, "unknown Arcofi response");
516 debugl1(cs
, "undefined Monitor response");
517 cs
->dc
.isac
.mon_rxp
= 0;
518 } else if (cs
->dc
.isac
.mon_tx
) {
519 debugl1(cs
, "Arcofi not detected");
521 if (arcofi_present
) {
522 if (cs
->subtyp
==ELSA_QS1000
) {
523 cs
->subtyp
= ELSA_QS3000
;
525 "Elsa: %s detected modem at 0x%lx\n",
526 Elsa_Types
[cs
->subtyp
],
528 request_io(&cs
->rs
, cs
->hw
.elsa
.base
+8, 8, "elsa isdn modem");
529 } else if (cs
->subtyp
==ELSA_PCC16
) {
530 cs
->subtyp
= ELSA_PCF
;
532 "Elsa: %s detected modem at 0x%lx\n",
533 Elsa_Types
[cs
->subtyp
],
535 request_io(&cs
->rs
, cs
->hw
.elsa
.base
+8, 8, "elsa isdn modem");
538 "Elsa: %s detected modem at 0x%lx\n",
539 Elsa_Types
[cs
->subtyp
],
541 arcofi_fsm(cs
, ARCOFI_START
, &ARCOFI_XOP_0
);
542 interruptible_sleep_on(&cs
->dc
.isac
.arcofi_wait
);
547 #endif /* ARCOFI_USE */
550 elsa_led_handler(struct IsdnCardState
*cs
)
554 if (cs
->subtyp
== ELSA_PCMCIA
|| cs
->subtyp
== ELSA_PCMCIA_IPAC
)
557 if (cs
->typ
== ISDN_CTYPE_ELSA
) {
558 int pwr
= bytein(cs
->hw
.elsa
.ale
);
560 cs
->hw
.elsa
.status
|= ELSA_BAD_PWR
;
562 cs
->hw
.elsa
.status
&= ~ELSA_BAD_PWR
;
564 if (cs
->status
& 0x0001)
565 cs
->hw
.elsa
.ctrl_reg
|= ELSA_STAT_LED
;
566 else if (cs
->hw
.elsa
.status
& ELSA_BAD_PWR
)
567 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_STAT_LED
;
569 cs
->hw
.elsa
.ctrl_reg
^= ELSA_STAT_LED
;
572 if (cs
->status
& 0xf000)
573 cs
->hw
.elsa
.ctrl_reg
|= ELSA_LINE_LED
;
574 else if (cs
->status
& 0x0f00) {
575 cs
->hw
.elsa
.ctrl_reg
^= ELSA_LINE_LED
;
578 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_LINE_LED
;
580 if ((cs
->subtyp
== ELSA_QS1000PCI
) ||
581 (cs
->subtyp
== ELSA_QS3000PCI
)) {
583 if (cs
->hw
.elsa
.ctrl_reg
& ELSA_LINE_LED
)
584 led
^= ELSA_IPAC_LINE_LED
;
585 if (cs
->hw
.elsa
.ctrl_reg
& ELSA_STAT_LED
)
586 led
^= ELSA_IPAC_STAT_LED
;
587 writereg(cs
, cs
->hw
.elsa
.isac
, IPAC_ATX
, led
);
589 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
592 mod_timer(&cs
->hw
.elsa
.tl
, jiffies
+ (blink
* HZ
) / 1000);
597 elsa_aux_ind(struct IsdnCardState
*cs
, void *arg
)
599 if (cs
->hw
.elsa
.MFlag
) {
608 modem_write_cmd(cs
, msg
, len
);
612 #define elsa_aux_ind NULL
616 elsa_init(struct IsdnCardState
*cs
)
618 if (cs
->subtyp
== ELSA_QS1000
|| cs
->subtyp
== ELSA_QS3000
)
619 byteout(cs
->hw
.elsa
.timer
, 0);
621 if (cs
->hw
.elsa
.trig
)
622 byteout(cs
->hw
.elsa
.trig
, 0xff);
628 elsa_ipac_init(struct IsdnCardState
*cs
)
630 if (cs
->hw
.elsa
.trig
)
631 byteout(cs
->hw
.elsa
.trig
, 0xff);
637 elsa_test(struct IsdnCardState
*cs
)
639 if ((cs
->subtyp
== ELSA_PCMCIA
) ||
640 (cs
->subtyp
== ELSA_PCMCIA_IPAC
) ||
641 (cs
->subtyp
== ELSA_QS1000PCI
)) {
644 if (cs
->subtyp
!= ELSA_QS3000PCI
) {
645 cs
->hw
.elsa
.counter
= 0;
646 cs
->hw
.elsa
.ctrl_reg
|= ELSA_ENA_TIMER_INT
;
647 cs
->hw
.elsa
.status
|= ELSA_TIMER_AKTIV
;
648 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
649 byteout(cs
->hw
.elsa
.timer
, 0);
650 set_current_state(TASK_UNINTERRUPTIBLE
);
651 schedule_timeout((110*HZ
)/1000);
652 cs
->hw
.elsa
.ctrl_reg
&= ~ELSA_ENA_TIMER_INT
;
653 byteout(cs
->hw
.elsa
.ctrl
, cs
->hw
.elsa
.ctrl_reg
);
654 cs
->hw
.elsa
.status
&= ~ELSA_TIMER_AKTIV
;
655 printk(KERN_INFO
"Elsa: %d timer tics in 110 msek\n",
656 cs
->hw
.elsa
.counter
);
657 if ((cs
->hw
.elsa
.counter
> 10) &&
658 (cs
->hw
.elsa
.counter
< 16)) {
659 printk(KERN_INFO
"Elsa: timer and irq OK\n");
662 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
663 cs
->hw
.elsa
.counter
, cs
->irq
);
667 if (check_arcofi(cs
)) {
671 elsa_led_handler(cs
);
674 static struct card_ops elsa_ops
= {
678 .release
= elsa_release
,
679 .aux_ind
= elsa_aux_ind
,
680 .led_handler
= elsa_led_handler
,
681 .irq_func
= elsa_interrupt
,
684 static struct card_ops elsa_ipac_ops
= {
685 .init
= elsa_ipac_init
,
688 .release
= elsa_release
,
689 .aux_ind
= elsa_aux_ind
,
690 .led_handler
= elsa_led_handler
,
691 .irq_func
= elsa_interrupt_ipac
,
695 elsa_arcofi_init(struct IsdnCardState
*cs
)
703 elsa_timer_init(struct IsdnCardState
*cs
)
705 cs
->hw
.elsa
.tl
.function
= (void *) elsa_led_handler
;
706 cs
->hw
.elsa
.tl
.data
= (long) cs
;
707 init_timer(&cs
->hw
.elsa
.tl
);
711 elsa_timer_test(struct IsdnCardState
*cs
)
714 byteout(cs
->hw
.elsa
.trig
, 0xff);
715 byteout(cs
->hw
.elsa
.timer
, 0);
717 byteout(cs
->hw
.elsa
.timer
, 0); /* second attempt */
719 printk(KERN_WARNING
"Elsa: timer does not start\n");
723 HZDELAY(10 * HZ
/ 1000); /* wait >=10 ms */
725 printk(KERN_WARNING
"Elsa: timer does not run\n");
728 printk(KERN_INFO
"Elsa: timer OK; resetting card\n");
734 static unsigned char __init
735 probe_elsa_adr(unsigned int adr
, int typ
)
737 int i
, in1
, in2
, p16_1
= 0, p16_2
= 0, p8_1
= 0, p8_2
= 0, pc_1
= 0,
738 pc_2
= 0, pfp_1
= 0, pfp_2
= 0;
740 /* In case of the elsa pcmcia card, this region is in use,
741 reserved for us by the card manager. So we do not check it
742 here, it would fail. */
743 if (typ
!= ISDN_CTYPE_ELSA_PCMCIA
&& !request_region(adr
, 8, "elsa")) {
744 printk(KERN_WARNING
"Elsa: probing port 0x%x: in use\n", adr
);
747 for (i
= 0; i
< 16; i
++) {
748 in1
= inb(adr
+ ELSA_CONFIG
); /* 'toggels' at */
749 in2
= inb(adr
+ ELSA_CONFIG
); /* each access */
759 release_region(adr
, 8);
760 printk(KERN_INFO
"Elsa: Probing IO 0x%x", adr
);
761 if (65 == ++p16_1
* ++p16_2
) {
762 printk(" PCC-16/PCF found\n");
764 } else if (1025 == ++pfp_1
* ++pfp_2
) {
765 printk(" PCF-Pro found\n");
766 return (ELSA_PCFPRO
);
767 } else if (33 == ++p8_1
* ++p8_2
) {
768 printk(" PCC8 found\n");
770 } else if (17 == ++pc_1
* ++pc_2
) {
771 printk(" PC found\n");
780 elsa_probe(struct IsdnCardState
*cs
, struct IsdnCard
*card
)
784 unsigned int CARD_portlist
[] = {0x160, 0x170, 0x260, 0x360, 0};
786 cs
->hw
.elsa
.base
= card
->para
[0];
787 printk(KERN_INFO
"Elsa: Microlink IO probing\n");
788 if (cs
->hw
.elsa
.base
) {
789 cs
->subtyp
= probe_elsa_adr(cs
->hw
.elsa
.base
, cs
->typ
);
791 printk(KERN_WARNING
"Elsa: no Microlink at %#lx\n",
796 for (i
= 0; CARD_portlist
[i
]; i
++) {
797 cs
->subtyp
= probe_elsa_adr(CARD_portlist
[i
], cs
->typ
);
799 cs
->hw
.elsa
.base
= CARD_portlist
[i
];
803 if (!cs
->hw
.elsa
.base
)
806 cs
->hw
.elsa
.cfg
= cs
->hw
.elsa
.base
+ ELSA_CONFIG
;
807 cs
->hw
.elsa
.ctrl
= cs
->hw
.elsa
.base
+ ELSA_CONTROL
;
808 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE
;
809 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC
;
810 cs
->hw
.elsa
.itac
= cs
->hw
.elsa
.base
+ ELSA_ITAC
;
811 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
812 cs
->hw
.elsa
.trig
= cs
->hw
.elsa
.base
+ ELSA_TRIG_IRQ
;
813 cs
->hw
.elsa
.timer
= cs
->hw
.elsa
.base
+ ELSA_START_TIMER
;
814 val
= bytein(cs
->hw
.elsa
.cfg
);
815 if (cs
->subtyp
== ELSA_PC
) {
816 const u8 CARD_IrqTab
[8] = {7, 3, 5, 9, 0, 0, 0, 0};
817 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX_PC
) >> 2];
818 } else if (cs
->subtyp
== ELSA_PCC8
) {
819 const u8 CARD_IrqTab
[8] = {7, 3, 5, 9, 0, 0, 0, 0};
820 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX_PCC8
) >> 4];
822 const u8 CARD_IrqTab
[8] = {15, 10, 15, 3, 11, 5, 11, 9};
823 cs
->irq
= CARD_IrqTab
[(val
& ELSA_IRQ_IDX
) >> 3];
825 val
= bytein(cs
->hw
.elsa
.ale
) & ELSA_HW_RELEASE
;
829 if (val
== 'B' || val
== 'C')
831 if ((cs
->subtyp
== ELSA_PCFPRO
) && (val
= 'G'))
833 printk(KERN_INFO
"Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
834 Elsa_Types
[cs
->subtyp
], cs
->hw
.elsa
.base
, val
, cs
->irq
);
835 val
= bytein(cs
->hw
.elsa
.ale
) & ELSA_S0_POWER_BAD
;
837 printk(KERN_WARNING
"Elsa: Microlink S0 bus power bad\n");
838 cs
->hw
.elsa
.status
|= ELSA_BAD_PWR
;
840 switch (cs
->subtyp
) {
841 case ELSA_PCFPRO
: bytecnt
= 16; break;
843 if (!request_io(&cs
->rs
, cs
->hw
.elsa
.base
, bytecnt
, "elsa isdn"))
845 elsa_arcofi_init(cs
);
847 if (elsa_timer_test(cs
))
850 cs
->card_ops
= &elsa_ops
;
851 if (hscxisac_setup(cs
, &isac_ops
, &hscx_ops
))
853 if (cs
->subtyp
== ELSA_PC
) {
854 val
= readitac(cs
, ITAC_SYS
);
855 printk(KERN_INFO
"Elsa: ITAC version %s\n", ITACVer
[val
& 7]);
856 writeitac(cs
, ITAC_ISEN
, 0);
857 writeitac(cs
, ITAC_RFIE
, 0);
858 writeitac(cs
, ITAC_XFIE
, 0);
859 writeitac(cs
, ITAC_SCIE
, 0);
860 writeitac(cs
, ITAC_STIE
, 0);
869 elsa_qs_probe(struct IsdnCardState
*cs
, struct IsdnCard
*card
)
873 cs
->irq
= card
->para
[0];
874 cs
->hw
.elsa
.base
= card
->para
[1];
875 cs
->hw
.elsa
.cfg
= cs
->hw
.elsa
.base
+ ELSA_CONFIG
;
876 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE
;
877 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC
;
878 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
879 cs
->hw
.elsa
.trig
= cs
->hw
.elsa
.base
+ ELSA_TRIG_IRQ
;
880 cs
->hw
.elsa
.timer
= cs
->hw
.elsa
.base
+ ELSA_START_TIMER
;
881 cs
->hw
.elsa
.ctrl
= cs
->hw
.elsa
.base
+ ELSA_CONTROL
;
882 printk(KERN_INFO
"Elsa: %s defined at %#lx IRQ %d\n",
883 Elsa_Types
[cs
->subtyp
], cs
->hw
.elsa
.base
, cs
->irq
);
884 switch (cs
->subtyp
) {
885 case ELSA_QS3000
: bytecnt
= 16; break;
887 if (!request_io(&cs
->rs
, cs
->hw
.elsa
.base
, bytecnt
, "elsa isdn"))
889 elsa_arcofi_init(cs
);
891 if (elsa_timer_test(cs
))
894 cs
->card_ops
= &elsa_ops
;
895 if (hscxisac_setup(cs
, &isac_ops
, &hscx_ops
))
904 elsa_qs1000_probe(struct IsdnCardState
*cs
, struct IsdnCard
*card
)
906 cs
->subtyp
= ELSA_QS1000
;
907 return elsa_qs_probe(cs
, card
);
911 elsa_qs3000_probe(struct IsdnCardState
*cs
, struct IsdnCard
*card
)
913 cs
->subtyp
= ELSA_QS3000
;
914 return elsa_qs_probe(cs
, card
);
918 elsa_pcmcia_probe(struct IsdnCardState
*cs
, struct IsdnCard
*card
)
922 cs
->irq
= card
->para
[0];
923 cs
->hw
.elsa
.base
= card
->para
[1];
924 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ 0;
925 val
= readreg(cs
, cs
->hw
.elsa
.base
+ 2, IPAC_ID
);
926 if ((val
== 1) || (val
== 2)) { /* IPAC version 1.1/1.2 */
927 cs
->subtyp
= ELSA_PCMCIA_IPAC
;
928 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ 2;
930 cs
->subtyp
= ELSA_PCMCIA
;
931 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
+ ELSA_ALE_PCM
;
932 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+ ELSA_ISAC_PCM
;
933 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+ ELSA_HSCX
;
935 cs
->hw
.elsa
.timer
= 0;
936 cs
->hw
.elsa
.trig
= 0;
937 cs
->hw
.elsa
.ctrl
= 0;
938 printk(KERN_INFO
"Elsa: %s defined at %#lx IRQ %d\n",
939 Elsa_Types
[cs
->subtyp
], cs
->hw
.elsa
.base
, cs
->irq
);
940 elsa_arcofi_init(cs
);
942 if (cs
->subtyp
== ELSA_PCMCIA_IPAC
) {
943 cs
->card_ops
= &elsa_ipac_ops
;
944 if (ipac_setup(cs
, &ipac_dc_ops
, &ipac_bc_ops
))
947 cs
->card_ops
= &elsa_ops
;
948 if (hscxisac_setup(cs
, &isac_ops
, &hscx_ops
))
958 elsa_qs_pci_probe(struct IsdnCardState
*cs
, struct pci_dev
*pdev
,
964 if (pci_enable_device(pdev
))
969 cs
->irq_flags
|= SA_SHIRQ
;
970 cs
->hw
.elsa
.cfg
= pci_resource_start(pdev
, 1);
971 cs
->hw
.elsa
.base
= pci_resource_start(pdev
, 3);
972 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &pci_rev
);
973 if (cs
->hw
.elsa
.cfg
& 0x80 && pci_rev
== 1) {
974 printk(KERN_INFO
"Elsa: PLX9050 rev1 workaround activated\n");
975 __set_bit(FLG_BUGGY_PLX9050
, &cs
->HW_Flags
);
977 cs
->hw
.elsa
.ale
= cs
->hw
.elsa
.base
;
978 cs
->hw
.elsa
.isac
= cs
->hw
.elsa
.base
+1;
979 cs
->hw
.elsa
.hscx
= cs
->hw
.elsa
.base
+1;
980 printk(KERN_INFO
"Elsa: %s defined at %#lx/%#x IRQ %d\n",
981 Elsa_Types
[cs
->subtyp
], cs
->hw
.elsa
.base
, cs
->hw
.elsa
.cfg
,
983 switch (cs
->subtyp
) {
984 case ELSA_QS3000PCI
: bytecnt
= 16; break;
986 if (!request_io(&cs
->rs
, cs
->hw
.elsa
.base
, bytecnt
, "elsa isdn"))
988 if (!request_io(&cs
->rs
, cs
->hw
.elsa
.cfg
, 0x80, "elsa isdn pci"))
990 elsa_arcofi_init(cs
);
993 cs
->card_ops
= &elsa_ipac_ops
;
994 if (ipac_setup(cs
, &ipac_dc_ops
, &ipac_bc_ops
))
1002 static struct pci_dev
*dev_qs1000 __devinitdata
= NULL
;
1003 static struct pci_dev
*dev_qs3000 __devinitdata
= NULL
;
1006 static struct isapnp_device_id elsa_ids
[] __initdata
= {
1007 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
1008 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
1009 (unsigned long) "Elsa QS1000" },
1010 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
1011 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
1012 (unsigned long) "Elsa QS3000" },
1016 static struct isapnp_device_id
*pdev
= &elsa_ids
[0];
1017 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
1021 setup_elsa(struct IsdnCard
*card
)
1025 strcpy(tmp
, Elsa_revision
);
1026 printk(KERN_INFO
"HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp
));
1028 if (card
->typ
== ISDN_CTYPE_ELSA
) {
1029 if (elsa_probe(card
->cs
, card
))
1032 } else if (card
->typ
== ISDN_CTYPE_ELSA_PNP
) {
1034 if (!card
->para
[1] && isapnp_present()) {
1035 struct pnp_card
*pb
;
1038 while(pdev
->card_vendor
) {
1039 if ((pb
= pnp_find_card(pdev
->card_vendor
,
1044 if ((pd
= pnp_find_dev(pnp_c
,
1048 printk(KERN_INFO
"HiSax: %s detected\n",
1049 (char *)pdev
->driver_data
);
1050 if (pnp_device_attach(pd
) < 0) {
1051 printk(KERN_ERR
"Elsa PnP: attach failed\n");
1054 if (pnp_activate_dev(pd
) < 0) {
1055 pnp_device_detach(pd
);
1056 printk(KERN_ERR
"Elsa PnP: activate failed\n");
1059 if (!pnp_port_valid(pd
, 0) ||
1060 !pnp_irq_valid(pd
, 0)) {
1061 printk(KERN_ERR
"Elsa PnP:some resources are missing %ld/%lx\n",
1062 pnp_irq(pd
, 0), pnp_port_start(pd
, 0));
1063 pnp_device_detach(pd
);
1066 card
->para
[1] = pnp_port_start(pd
, 0);
1067 card
->para
[0] = pnp_irq(pd
, 0);
1068 if (pdev
->function
== ISAPNP_FUNCTION(0x133)) {
1069 if (elsa_qs1000_probe(card
->cs
, card
))
1073 if (elsa_qs3000_probe(card
->cs
, card
))
1079 printk(KERN_ERR
"Elsa PnP: PnP error card found, no device\n");
1086 if (!pdev
->card_vendor
) {
1087 printk(KERN_INFO
"Elsa PnP: no ISAPnP card found\n");
1092 if (elsa_qs1000_probe(card
->cs
, card
))
1096 } else if (card
->typ
== ISDN_CTYPE_ELSA_PCMCIA
) {
1097 if (elsa_pcmcia_probe(card
->cs
, card
))
1100 } else if (card
->typ
== ISDN_CTYPE_ELSA_PCI
) {
1102 if ((dev_qs1000
= pci_find_device(PCI_VENDOR_ID_ELSA
,
1103 PCI_DEVICE_ID_ELSA_MICROLINK
, dev_qs1000
))) {
1104 if (elsa_qs_pci_probe(card
->cs
, dev_qs1000
,
1108 } else if ((dev_qs3000
= pci_find_device(PCI_VENDOR_ID_ELSA
,
1109 PCI_DEVICE_ID_ELSA_QS3000
, dev_qs3000
))) {
1110 if (elsa_qs_pci_probe(card
->cs
, dev_qs3000
,
1115 printk(KERN_WARNING
"Elsa: No PCI card found\n");
1118 #endif /* CONFIG_PCI */