[PATCH] DVB: Update documentation and credits
[linux-2.6/history.git] / drivers / isdn / hisax / elsa.c
blob219374604e7c062e837d1ef5ed2df094bc57939f
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
5 * Author Karsten Keil
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
7 *
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>
23 #include "hisax.h"
24 #include "arcofi.h"
25 #include "isac.h"
26 #include "ipac.h"
27 #include "hscx.h"
28 #include "isdnl1.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",
41 "PCMCIA-IPAC" };
43 const char *ITACVer[] =
44 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
45 "B1", "A1"};
47 #define byteout(addr,val) outb(val,addr)
48 #define bytein(addr) inb(addr)
50 #define ELSA_ISAC 0
51 #define ELSA_ISAC_PCM 1
52 #define ELSA_ITAC 1
53 #define ELSA_HSCX 2
54 #define ELSA_ALE 3
55 #define ELSA_ALE_PCM 4
56 #define ELSA_CONTROL 4
57 #define ELSA_CONFIG 5
58 #define ELSA_START_TIMER 6
59 #define ELSA_TRIG_IRQ 7
61 #define ELSA_PC 1
62 #define ELSA_PCC8 2
63 #define ELSA_PCC16 3
64 #define ELSA_PCF 4
65 #define ELSA_PCFPRO 5
66 #define ELSA_PCMCIA 6
67 #define ELSA_QS1000 7
68 #define ELSA_QS3000 8
69 #define ELSA_QS1000PCI 9
70 #define ELSA_QS3000PCI 10
71 #define ELSA_PCMCIA_IPAC 11
73 /* PCI stuff */
74 #define ELSA_PCI_IRQ_MASK 0x04
76 /* ITAC Registeradressen (only Microlink PC) */
77 #define ITAC_SYS 0x34
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
84 /*** ***
85 *** Makros als Befehle fuer die Kartenregister ***
86 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
87 *** ***/
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 */
106 /* Status Flags */
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
113 /* IPAC AUX */
114 #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
115 #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
117 #if ARCOFI_USE
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 */
144 static inline u8
145 readreg(struct IsdnCardState *cs, unsigned int adr, u8 off)
147 u8 ret;
148 unsigned long flags;
150 spin_lock_irqsave(&elsa_lock, flags);
151 byteout(cs->hw.elsa.ale, off);
152 ret = bytein(adr);
153 spin_unlock_irqrestore(&elsa_lock, flags);
154 return ret;
157 static inline void
158 writereg(struct IsdnCardState *cs, unsigned int adr, u8 off, u8 data)
160 unsigned long flags;
162 spin_lock_irqsave(&elsa_lock, flags);
163 byteout(cs->hw.elsa.ale, off);
164 byteout(adr, data);
165 spin_unlock_irqrestore(&elsa_lock, flags);
168 static inline void
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);
175 static inline void
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);
182 static u8
183 isac_read(struct IsdnCardState *cs, u8 offset)
185 return readreg(cs, cs->hw.elsa.isac, offset);
188 static void
189 isac_write(struct IsdnCardState *cs, u8 offset, u8 value)
191 writereg(cs, cs->hw.elsa.isac, offset, value);
194 static void
195 isac_read_fifo(struct IsdnCardState *cs, u8 *data, int size)
197 readfifo(cs, cs->hw.elsa.isac, 0, data, size);
200 static void
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,
213 static u8
214 hscx_read(struct IsdnCardState *cs, int hscx, u8 offset)
216 return readreg(cs, cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0));
219 static void
220 hscx_write(struct IsdnCardState *cs, int hscx, u8 offset, u8 value)
222 writereg(cs, cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
225 static void
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);
231 static void
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,
244 static inline u8
245 ipac_read(struct IsdnCardState *cs, u8 offset)
247 return readreg(cs, cs->hw.elsa.isac, offset);
250 static inline void
251 ipac_write(struct IsdnCardState *cs, u8 offset, u8 value)
253 writereg(cs, cs->hw.elsa.isac, offset, value);
256 static inline void
257 ipac_readfifo(struct IsdnCardState *cs, u8 offset, u8 *data, int size)
259 readfifo(cs, cs->hw.elsa.isac, offset, data, size);
262 static inline void
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
269 * above */
271 BUILD_IPAC_OPS(ipac);
273 static inline u8
274 readitac(struct IsdnCardState *cs, u8 off)
276 u8 ret;
277 unsigned long flags;
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);
283 return ret;
286 static inline void
287 writeitac(struct IsdnCardState *cs, u8 off, u8 data)
289 unsigned long flags;
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);
297 static inline int
298 TimerRun(struct IsdnCardState *cs)
300 register u8 v;
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);
310 static irqreturn_t
311 elsa_interrupt(int intno, void *dev_id, struct pt_regs *regs)
313 struct IsdnCardState *cs = dev_id;
314 u8 val;
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");
320 return IRQ_NONE;
322 #if ARCOFI_USE
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);
332 #endif
333 hscxisac_irq(intno, dev_id, regs);
335 if (cs->hw.elsa.status & ELSA_TIMER_AKTIV) {
336 if (!TimerRun(cs)) {
337 /* Timer Restart */
338 byteout(cs->hw.elsa.timer, 0);
339 cs->hw.elsa.counter++;
342 #if ARCOFI_USE
343 if (cs->hw.elsa.MFlag) {
344 val = serial_inp(cs, UART_MCR);
345 val ^= 0x8;
346 serial_outp(cs, UART_MCR, val);
347 val = serial_inp(cs, UART_MCR);
348 val ^= 0x8;
349 serial_outp(cs, UART_MCR, val);
351 #endif
352 if (cs->hw.elsa.trig)
353 byteout(cs->hw.elsa.trig, 0x00);
354 return IRQ_HANDLED;
357 static irqreturn_t
358 elsa_interrupt_ipac(int intno, void *dev_id, struct pt_regs *regs)
360 struct IsdnCardState *cs = dev_id;
361 u8 val;
363 if (!cs) {
364 printk(KERN_WARNING "Elsa: Spurious interrupt!\n");
365 return IRQ_NONE;
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))
371 return IRQ_NONE;
373 #if ARCOFI_USE
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);
383 #endif
384 return ipac_irq(intno, dev_id, regs);
387 static void
388 elsa_release(struct IsdnCardState *cs)
390 del_timer(&cs->hw.elsa.tl);
391 #if ARCOFI_USE
392 clear_arcofi(cs);
393 #endif
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);
407 #if ARCOFI_USE
408 if ((cs->subtyp == ELSA_PCFPRO) ||
409 (cs->subtyp == ELSA_QS3000) ||
410 (cs->subtyp == ELSA_PCF) ||
411 (cs->subtyp == ELSA_QS3000PCI)) {
412 release_modem(cs);
414 #endif
415 hisax_release_resources(cs);
418 static int
419 elsa_reset(struct IsdnCardState *cs)
421 if (cs->hw.elsa.timer) {
422 /* Wait 1 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);
428 /* Wait 1 Timer */
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);
433 /* Wait 1 Timer */
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);
450 } else {
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 */
461 return 0;
464 #if ARCOFI_USE
466 static void
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);
473 static int
474 check_arcofi(struct IsdnCardState *cs)
476 int arcofi_present = 0;
477 char tmp[40];
478 char *t;
479 u8 *p;
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!");
485 return(0);
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;
493 t = tmp;
494 t += sprintf(tmp, "Arcofi data");
495 QuickHex(t, p, cs->dc.isac.mon_rxp);
496 debugl1(cs, tmp);
497 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
498 switch(cs->dc.isac.mon_rx[1]) {
499 case 0x80:
500 debugl1(cs, "Arcofi 2160 detected");
501 arcofi_present = 1;
502 break;
503 case 0x82:
504 debugl1(cs, "Arcofi 2165 detected");
505 arcofi_present = 2;
506 break;
507 case 0x84:
508 debugl1(cs, "Arcofi 2163 detected");
509 arcofi_present = 3;
510 break;
511 default:
512 debugl1(cs, "unknown Arcofi response");
513 break;
515 } else
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;
524 printk(KERN_INFO
525 "Elsa: %s detected modem at 0x%lx\n",
526 Elsa_Types[cs->subtyp],
527 cs->hw.elsa.base+8);
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;
531 printk(KERN_INFO
532 "Elsa: %s detected modem at 0x%lx\n",
533 Elsa_Types[cs->subtyp],
534 cs->hw.elsa.base+8);
535 request_io(&cs->rs, cs->hw.elsa.base+8, 8, "elsa isdn modem");
536 } else
537 printk(KERN_INFO
538 "Elsa: %s detected modem at 0x%lx\n",
539 Elsa_Types[cs->subtyp],
540 cs->hw.elsa.base+8);
541 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
542 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
543 return(1);
545 return(0);
547 #endif /* ARCOFI_USE */
549 static void
550 elsa_led_handler(struct IsdnCardState *cs)
552 int blink = 0;
554 if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
555 return;
557 if (cs->typ == ISDN_CTYPE_ELSA) {
558 int pwr = bytein(cs->hw.elsa.ale);
559 if (pwr & 0x08)
560 cs->hw.elsa.status |= ELSA_BAD_PWR;
561 else
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;
568 else {
569 cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
570 blink = 250;
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;
576 blink = 500;
577 } else
578 cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
580 if ((cs->subtyp == ELSA_QS1000PCI) ||
581 (cs->subtyp == ELSA_QS3000PCI)) {
582 u8 led = 0xff;
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);
588 } else
589 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
591 if (blink)
592 mod_timer(&cs->hw.elsa.tl, jiffies + (blink * HZ) / 1000);
595 #if ARCOFI_USE
596 static void
597 elsa_aux_ind(struct IsdnCardState *cs, void *arg)
599 if (cs->hw.elsa.MFlag) {
600 int len;
601 u8 *msg;
603 if (!arg)
604 return;
605 msg = arg;
606 len = *msg;
607 msg++;
608 modem_write_cmd(cs, msg, len);
611 #else
612 #define elsa_aux_ind NULL
613 #endif
615 static void
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);
624 inithscxisac(cs);
627 static void
628 elsa_ipac_init(struct IsdnCardState *cs)
630 if (cs->hw.elsa.trig)
631 byteout(cs->hw.elsa.trig, 0xff);
633 ipac_init(cs);
636 static void
637 elsa_test(struct IsdnCardState *cs)
639 if ((cs->subtyp == ELSA_PCMCIA) ||
640 (cs->subtyp == ELSA_PCMCIA_IPAC) ||
641 (cs->subtyp == ELSA_QS1000PCI)) {
642 return;
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");
660 } else {
661 printk(KERN_WARNING
662 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
663 cs->hw.elsa.counter, cs->irq);
666 #if ARCOFI_USE
667 if (check_arcofi(cs)) {
668 init_modem(cs);
670 #endif
671 elsa_led_handler(cs);
674 static struct card_ops elsa_ops = {
675 .init = elsa_init,
676 .test = elsa_test,
677 .reset = elsa_reset,
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,
686 .test = elsa_test,
687 .reset = elsa_reset,
688 .release = elsa_release,
689 .aux_ind = elsa_aux_ind,
690 .led_handler = elsa_led_handler,
691 .irq_func = elsa_interrupt_ipac,
694 static void __init
695 elsa_arcofi_init(struct IsdnCardState *cs)
697 #if ARCOFI_USE
698 init_arcofi(cs);
699 #endif
702 static void __init
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);
710 static int __init
711 elsa_timer_test(struct IsdnCardState *cs)
713 /* test timer */
714 byteout(cs->hw.elsa.trig, 0xff);
715 byteout(cs->hw.elsa.timer, 0);
716 if (!TimerRun(cs)) {
717 byteout(cs->hw.elsa.timer, 0); /* second attempt */
718 if (!TimerRun(cs)) {
719 printk(KERN_WARNING "Elsa: timer does not start\n");
720 goto err;
723 HZDELAY(10 * HZ / 1000); /* wait >=10 ms */
724 if (TimerRun(cs)) {
725 printk(KERN_WARNING "Elsa: timer does not run\n");
726 goto err;
728 printk(KERN_INFO "Elsa: timer OK; resetting card\n");
729 return 0;
730 err:
731 return -EBUSY;
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);
745 return 0;
747 for (i = 0; i < 16; i++) {
748 in1 = inb(adr + ELSA_CONFIG); /* 'toggels' at */
749 in2 = inb(adr + ELSA_CONFIG); /* each access */
750 p16_1 += 0x04 & in1;
751 p16_2 += 0x04 & in2;
752 p8_1 += 0x02 & in1;
753 p8_2 += 0x02 & in2;
754 pc_1 += 0x01 & in1;
755 pc_2 += 0x01 & in2;
756 pfp_1 += 0x40 & in1;
757 pfp_2 += 0x40 & in2;
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");
763 return (ELSA_PCC16);
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");
769 return (ELSA_PCC8);
770 } else if (17 == ++pc_1 * ++pc_2) {
771 printk(" PC found\n");
772 return (ELSA_PC);
773 } else {
774 printk(" failed\n");
775 return (0);
779 static int __init
780 elsa_probe(struct IsdnCardState *cs, struct IsdnCard *card)
782 u8 val;
783 int i, bytecnt = 8;
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);
790 if (!cs->subtyp) {
791 printk(KERN_WARNING "Elsa: no Microlink at %#lx\n",
792 cs->hw.elsa.base);
793 goto err;
795 } else {
796 for (i = 0; CARD_portlist[i]; i++) {
797 cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ);
798 if (cs->subtyp)
799 cs->hw.elsa.base = CARD_portlist[i];
800 break;
803 if (!cs->hw.elsa.base)
804 goto err;
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];
821 } else {
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;
826 if (val < 3)
827 val |= 8;
828 val += 'A' - 3;
829 if (val == 'B' || val == 'C')
830 val ^= 1;
831 if ((cs->subtyp == ELSA_PCFPRO) && (val = 'G'))
832 val = 'C';
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;
836 if (val) {
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"))
844 goto err;
845 elsa_arcofi_init(cs);
846 elsa_timer_init(cs);
847 if (elsa_timer_test(cs))
848 goto err;
849 elsa_reset(cs);
850 cs->card_ops = &elsa_ops;
851 if (hscxisac_setup(cs, &isac_ops, &hscx_ops))
852 goto err;
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);
862 return 0;
863 err:
864 elsa_release(cs);
865 return -EBUSY;
868 static int __init
869 elsa_qs_probe(struct IsdnCardState *cs, struct IsdnCard *card)
871 int bytecnt = 8;
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"))
888 goto err;
889 elsa_arcofi_init(cs);
890 elsa_timer_init(cs);
891 if (elsa_timer_test(cs))
892 goto err;
893 elsa_reset(cs);
894 cs->card_ops = &elsa_ops;
895 if (hscxisac_setup(cs, &isac_ops, &hscx_ops))
896 goto err;
897 return 0;
898 err:
899 elsa_release(cs);
900 return -EBUSY;
903 static int __init
904 elsa_qs1000_probe(struct IsdnCardState *cs, struct IsdnCard *card)
906 cs->subtyp = ELSA_QS1000;
907 return elsa_qs_probe(cs, card);
910 static int __init
911 elsa_qs3000_probe(struct IsdnCardState *cs, struct IsdnCard *card)
913 cs->subtyp = ELSA_QS3000;
914 return elsa_qs_probe(cs, card);
917 static int __init
918 elsa_pcmcia_probe(struct IsdnCardState *cs, struct IsdnCard *card)
920 u8 val;
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;
929 } else {
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);
941 elsa_reset(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))
945 goto err;
946 } else {
947 cs->card_ops = &elsa_ops;
948 if (hscxisac_setup(cs, &isac_ops, &hscx_ops))
949 goto err;
951 return 0;
952 err:
953 elsa_release(cs);
954 return -EBUSY;
957 static int __init
958 elsa_qs_pci_probe(struct IsdnCardState *cs, struct pci_dev *pdev,
959 int subtyp)
961 int bytecnt = 2;
962 u8 pci_rev;
964 if (pci_enable_device(pdev))
965 goto err;
967 cs->subtyp = subtyp;
968 cs->irq = pdev->irq;
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,
982 cs->irq);
983 switch (cs->subtyp) {
984 case ELSA_QS3000PCI: bytecnt = 16; break;
986 if (!request_io(&cs->rs, cs->hw.elsa.base, bytecnt, "elsa isdn"))
987 goto err;
988 if (!request_io(&cs->rs, cs->hw.elsa.cfg, 0x80, "elsa isdn pci"))
989 goto err;
990 elsa_arcofi_init(cs);
991 elsa_timer_init(cs);
992 elsa_reset(cs);
993 cs->card_ops = &elsa_ipac_ops;
994 if (ipac_setup(cs, &ipac_dc_ops, &ipac_bc_ops))
995 goto err;
996 return 0;
997 err:
998 elsa_release(cs);
999 return -EBUSY;
1002 static struct pci_dev *dev_qs1000 __devinitdata = NULL;
1003 static struct pci_dev *dev_qs3000 __devinitdata = NULL;
1005 #ifdef __ISAPNP__
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" },
1013 { 0, }
1016 static struct isapnp_device_id *pdev = &elsa_ids[0];
1017 static struct pnp_card *pnp_c __devinitdata = NULL;
1018 #endif
1020 int __devinit
1021 setup_elsa(struct IsdnCard *card)
1023 char tmp[64];
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))
1030 return 0;
1031 return 1;
1032 } else if (card->typ == ISDN_CTYPE_ELSA_PNP) {
1033 #ifdef __ISAPNP__
1034 if (!card->para[1] && isapnp_present()) {
1035 struct pnp_card *pb;
1036 struct pnp_dev *pd;
1038 while(pdev->card_vendor) {
1039 if ((pb = pnp_find_card(pdev->card_vendor,
1040 pdev->card_device,
1041 pnp_c))) {
1042 pnp_c = pb;
1043 pd = NULL;
1044 if ((pd = pnp_find_dev(pnp_c,
1045 pdev->vendor,
1046 pdev->function,
1047 pd))) {
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");
1052 return 0;
1054 if (pnp_activate_dev(pd) < 0) {
1055 pnp_device_detach(pd);
1056 printk(KERN_ERR "Elsa PnP: activate failed\n");
1057 return 0;
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);
1064 return(0);
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))
1070 return 0;
1071 return 1;
1072 } else {
1073 if (elsa_qs3000_probe(card->cs, card))
1074 return 0;
1075 return 1;
1077 break;
1078 } else {
1079 printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
1080 return(0);
1083 pdev++;
1084 pnp_c=NULL;
1086 if (!pdev->card_vendor) {
1087 printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
1088 return(0);
1091 #endif
1092 if (elsa_qs1000_probe(card->cs, card))
1093 return 0;
1094 return 1;
1096 } else if (card->typ == ISDN_CTYPE_ELSA_PCMCIA) {
1097 if (elsa_pcmcia_probe(card->cs, card))
1098 return 0;
1099 return 1;
1100 } else if (card->typ == ISDN_CTYPE_ELSA_PCI) {
1101 #ifdef CONFIG_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,
1105 ELSA_QS1000PCI))
1106 return 0;
1107 return 1;
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,
1111 ELSA_QS3000PCI))
1112 return 0;
1113 return 1;
1114 } else {
1115 printk(KERN_WARNING "Elsa: No PCI card found\n");
1116 return 0;
1118 #endif /* CONFIG_PCI */
1120 return 0;